From 92af07d53e1222b9ce6764e504efa1f09b055f4a Mon Sep 17 00:00:00 2001 From: GAJ3T Date: Sat, 31 Oct 2026 06:43:08 -0400 Subject: [PATCH] After Step 11 --- README.md | 24 +- docs/README.md | 12 +- docs/architecture.md | 22 +- docs/build-and-test.md | 42 +- docs/calibration-rehearsal.md | 2 +- docs/runbooks-v1.md | 154 +++++ prompts/ROADMAP.md | 76 ++- prompts/STATE.md | 99 +++- prompts/Step-11-Report.md | 236 ++++++++ prompts/Step-12.md | 327 +++++++++++ .../Runbooks/RunbookPreviewService.cs | 294 ++++++++++ .../Features/Foundation/AddAutoForgeUi.cs | 2 + .../Features/Foundation/Home.razor | 1 + .../Vehicles/Runbooks/RunbookPage.razor | 179 ++++++ src/AutoForge.UI/Layout/MainLayout.razor | 1 + .../RunbookPreviewIsolationTests.cs | 124 ++++ .../RunbookPreviewTests.cs | 530 ++++++++++++++++++ .../RunbookPreviewUiTests.cs | 119 ++++ 18 files changed, 2192 insertions(+), 52 deletions(-) create mode 100644 docs/runbooks-v1.md create mode 100644 prompts/Step-11-Report.md create mode 100644 prompts/Step-12.md create mode 100644 src/AutoForge.Application/Features/Vehicles/Runbooks/RunbookPreviewService.cs create mode 100644 src/AutoForge.UI/Features/Vehicles/Runbooks/RunbookPage.razor create mode 100644 src/tests/AutoForge.IntegrationTests/RunbookPreviewIsolationTests.cs create mode 100644 src/tests/AutoForge.IntegrationTests/RunbookPreviewTests.cs create mode 100644 src/tests/AutoForge.IntegrationTests/RunbookPreviewUiTests.cs diff --git a/README.md b/README.md index cd9c9d6..ed6ca23 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ calibrations or applied model/device changes. See [Step-09 worker report](prompts/Step-09-Report.md). Step-09 was accepted on 2026-10-30. -### Implemented, pending manual review +### Accepted isolated programming rehearsal milestone Step-10 adds an explicit isolated Simulation rehearsal within `/calibration`. Its real mutable logical image supports independent volatile backup, @@ -115,15 +115,25 @@ source/head/revision-bound single-use approval, atomic CAS, full readback, read-only reconciliation and separately approved original Restore. It never applies authoring values to a dynamics configuration or a physical target. See [rehearsal contracts](docs/calibration-rehearsal.md) and the -[Step-10 worker report](prompts/Step-10-Report.md). Step-10 remains pending -manual orchestrator review. +[Step-10 worker report](prompts/Step-10-Report.md). Step-10A corrects close ownership while a new rehearsal factory return is pending: a newly admitted opening lifetime cannot reuse the previous close completion, and Close/disposal drains its actual owner before returning. The [corrective report](prompts/Step-10A-Report.md) records controlled -pre/post behavior and native recheck. Step-10 remains not accepted pending -manual review of the correction; no programming scope or limits were added. +pre/post behavior and native recheck. Corrected Step-10/10A was accepted on +2026-10-31; no programming scope or limits were added by the correction. + +### Implemented, pending manual review + +Step-11 adds `/runbooks`: strict manual schema-v1 JSON validation against an +explicit current synthetic authoring source/head, complete template rules +and exact read-only candidate/diff preview. Invalid input retains the last +successful preview, and source changes label it Stale without rebasing. +There is no model, retrieval, authoring Save, approval, target access or runbook +execution. See [runbook schema/preview contracts](docs/runbooks-v1.md) and the +[Step-11 worker report](prompts/Step-11-Report.md). Step-11 remains pending +manual orchestrator review. ### Planned @@ -148,7 +158,8 @@ The application slices provide explicit target metadata resolution, vehicle-profile metadata import/list/select/export, dynamics configuration catalog/import/export, simulation-only diagnostic sessions, bounded session recording, archive inspection, offline recorded replay, synthetic calibration -authoring, isolated simulated programming rehearsal and a shared display-unit preference with a +authoring, isolated simulated programming rehearsal, deterministic read-only +runbook preview and a shared display-unit preference with a native local-preference adapter. The Client composes separate static and dynamics synthetic providers through provider-neutral factory contracts and a session-lifetime in-memory profile/ @@ -264,6 +275,7 @@ acceptance remains the orchestrator's responsibility. - [Recorded telemetry replay](docs/telemetry-replay.md) - [Synthetic calibration authoring](docs/calibration-authoring.md) - [Verified simulated programming rehearsal](docs/calibration-rehearsal.md) +- [Manual runbook schema v1 and read-only preview](docs/runbooks-v1.md) - [Vehicle-profile schema v1 and usage](docs/vehicle-profile-schema-v1.md) - [Build, tests and native smoke guide](docs/build-and-test.md) - [ADR-0001: historical .NET foundation](docs/adr-0001-headless-foundation.md) diff --git a/docs/README.md b/docs/README.md index c25daba..2a2a9d0 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,9 +16,11 @@ Step-08 is accepted. Step-09 adds bounded synthetic scalar/table authoring with immutable source-bound proposals and exact diffs, without model/device changes. Step-09 is accepted. Step-10 adds isolated simulated image backup/approval/ CAS/readback/reconciliation/Restore, without dynamics or physical application. -Step-10 worker status remains pending manual orchestrator review. Step-10A corrects the pending-reopen close/disposal completion lifetime. -Original Step-10 evidence is preserved; acceptance awaits corrective review. +Corrected Step-10/10A is accepted. Step-11 adds strict deterministic manual +runbook JSON/source/head validation and immutable read-only previews. +Step-11 worker status remains pending manual orchestrator review; no inference +or execution feature is implemented. - [Architecture](architecture.md): actual nine-project graph, responsibilities, route ownership and provider/reference boundaries. @@ -45,6 +47,9 @@ Original Step-10 evidence is preserved; acceptance awaits corrective review. - [Verified simulated programming rehearsal](calibration-rehearsal.md): typed isolated target, independently verified supported-image backup, immutable single-use approval, exact readback/recovery and bounded volatile audit. +- [Manual runbook schema v1 and read-only preview](runbooks-v1.md): exact + allowlisted fields/limits, current authoring source/head/template validation, + canonical immutable diff, source staleness and no execution authority. - [ADR-0001: Headless .NET 10 foundation](adr-0001-headless-foundation.md): historical foundation decisions; dual-shell/deferred-host decision superseded. - [ADR-0002: Single native shell and feature slices](adr-0002-single-shell-vsa.md): @@ -81,5 +86,6 @@ historical/worker reports for their own execution evidence: [Step-08 worker report](../prompts/Step-08-Report.md) and [Step-09 worker report](../prompts/Step-09-Report.md) and [Step-10 worker report](../prompts/Step-10-Report.md) and -[Step-10A corrective report](../prompts/Step-10A-Report.md). +[Step-10A corrective report](../prompts/Step-10A-Report.md) and +[Step-11 worker report](../prompts/Step-11-Report.md). Handoffs are manual; acceptance remains the orchestrator's responsibility. diff --git a/docs/architecture.md b/docs/architecture.md index 3391a51..e672600 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -14,7 +14,9 @@ Step-08 adds archive-only recorded replay with exact prefix reduction and one page-owned cancellable clock and is accepted. Step-09 adds source-bound, process-memory synthetic calibration authoring and is accepted. Step-10 adds isolated simulated programming rehearsal with independent backup and full -readback/recovery. Step-10 remains pending manual review; execution is not acceptance. +readback/recovery and is accepted after Step-10A. Step-11 adds strict read-only +manual runbook validation/preview. Step-11 remains pending manual review; +execution evidence is not acceptance. ```mermaid flowchart TD @@ -49,7 +51,7 @@ All nine projects are in [AutoForge.slnx](../src/AutoForge.slnx): | [Core](../src/AutoForge.Core/AutoForge.Core.csproj) | `net10.0`; platform-neutral target/profile invariants, immutable dynamics contracts and bounded synthetic calibration definition/value/applicability validation | None | | [Diagnostics](../src/AutoForge.Diagnostics/AutoForge.Diagnostics.csproj) | `net10.0`; diagnostic contracts/protocol/trace plus a separate narrow typed simulated-calibration target port | Core | | [Simulation](../src/AutoForge.Simulation/AutoForge.Simulation.csproj) | `net10.0`; static/dynamic providers and a separate mutable logical calibration rehearsal image/CAS owner | Core, Diagnostics | -| [Application](../src/AutoForge.Application/AutoForge.Application.csproj) | `net10.0`; target/profile/diagnostics/dynamics coordination, units/dashboard/recording/replay, authoring and guarded rehearsal workflow | Core, Diagnostics | +| [Application](../src/AutoForge.Application/AutoForge.Application.csproj) | `net10.0`; target/profile/diagnostics/dynamics coordination, units/dashboard/recording/replay, authoring/rehearsal and strict read-only runbook preview | Core, Diagnostics | | [Components](../src/AutoForge.Components/AutoForge.Components.csproj) | `net10.0` RCL; generic `StatusNotice` and numeric/bar gauge with accessible state and safe rendering | None | | [UI](../src/AutoForge.UI/AutoForge.UI.csproj) | `net10.0` RCL; all application routes, navigation, layout and presentation, including shared dashboard and recording/archive inspection controls | Application, Components, Diagnostics | | [Client](../src/AutoForge.Client/AutoForge.Client.csproj) | `net10.0-windows10.0.26100.0`; only MAUI Blazor Hybrid application executable, native preference adapter and app-local archive root | Application, Simulation, UI | @@ -92,6 +94,7 @@ assembly, not the native Client assembly. | `/simulation` | `Features/Vehicles/Simulation/SimulationPage.razor` | Explicit profile/config/provider selection, JSON import/export, stopped-by-default dynamics session, lifecycle/step/pacing/scenario controls, source/unit/quality/model-time/config/run-aware telemetry over diagnostic protocol v2, and the same dashboard and recording/archive controls | | `/telemetry-replay` | `Features/Vehicles/Telemetry/Replay/TelemetryReplayPage.razor` | Strict saved capture selection/load, distinct RecordedReplay instance and immutable original metadata, exact time/ordinal prefix navigation, one cancellable clock, partial acknowledgement and shared recorded numeric/bar gauges | | `/calibration` | `Features/Vehicles/Calibration/CalibrationPage.razor` | Explicit configuration-derived synthetic baseline, immutable Proposed history, complete scalar/table validation, exact head/source tokens and diffs, pinned torque-unit drafts; no application or programming | +| `/runbooks` | `Features/Vehicles/Runbooks/RunbookPage.razor` | Manual schema-v1 input/template, explicit validation and immutable canonical preview/diff with current/Stale source status; no Save, approval, target/model/command access | | Any unmatched route | `Features/Foundation/NotFoundPage.razor` via UI `Routes.razor` | Explicit not-found page and supported navigation | The generic [StatusNotice](../src/AutoForge.Components/StatusNotice.razor) @@ -217,6 +220,21 @@ and [simulation guide](simulation.md). ## Honest limitations and safety boundaries +The runbook slice receives only `CalibrationAuthoringService`, using its +read-only immutable snapshot and narrow current-head guard. Application owns +the strict bounded allowlisted parser, complete template validation and pure +exact diff. All syntax/source/value checks precede last-success publication +under the actual current-head guard. The preview service retains only one +successful immutable result and computes source freshness from the actual +current snapshot, without rebasing. Snapshot reading releases the preview gate +before reading the source gate; no inverse lock ordering is introduced. +The UI separately owns manual input/errors and last-successful preview labels, +and source/unit notifications only rerender. It never validates on render. +The slice has no diagnostic/rehearsal/transport/model/archive/network dependency +or Save/approval/Execute control. Step-12 generated text must eventually use +this same strict boundary; inference/retrieval is not implemented. +See [runbook schema/preview contracts](runbooks-v1.md). + The authoring slice has only configuration/profile read dependencies. Core owns defensively copied applicability, definition and value contracts for the single synthetic engine template. Application's singleton diff --git a/docs/build-and-test.md b/docs/build-and-test.md index d07a3b7..b761784 100644 --- a/docs/build-and-test.md +++ b/docs/build-and-test.md @@ -45,12 +45,46 @@ dotnet test .\src\tests\AutoForge.IntegrationTests\AutoForge.IntegrationTests.cs dotnet test .\src\tests\AutoForge.IntegrationTests\AutoForge.IntegrationTests.csproj --configuration Release --no-restore --filter "FullyQualifiedName~CalibrationAuthoringTests" dotnet test .\src\tests\AutoForge.IntegrationTests\AutoForge.IntegrationTests.csproj --configuration Release --no-restore --filter "FullyQualifiedName~CalibrationRehearsalTests|FullyQualifiedName~RenderedRehearsal|FullyQualifiedName~RehearsalIsolation|FullyQualifiedName~CalibrationAuthoringTests" dotnet test .\src\tests\AutoForge.IntegrationTests\AutoForge.IntegrationTests.csproj --configuration Release --no-restore --filter "FullyQualifiedName~CalibrationRehearsalReopenTests|FullyQualifiedName~CalibrationRehearsalTests|FullyQualifiedName~RenderedRehearsal|FullyQualifiedName~RehearsalIsolation" +dotnet test .\src\tests\AutoForge.IntegrationTests\AutoForge.IntegrationTests.csproj --configuration Release --no-restore --filter "FullyQualifiedName~RunbookPreviewTests|FullyQualifiedName~RunbookUi_|FullyQualifiedName~RunbookIsolation_" ``` +## Step-11 deterministic runbook preview verification + +Corrected Step-10/10A is accepted; Step-11 remains pending manual review. +The focused runbook command passed **105 cases**, including exact source/head/ +candidate/diff vectors, every schema object's missing/duplicate/unknown fields, +wrong kinds/integers/allowlist/identity/unit/axis/full-shape vectors, defensive +copies, stale result retention, safe rendered rationale and no auto validation. +Input at exactly 131072 UTF-8 bytes succeeds; one more fails without replacing +the last preview. Rationale 2000/2001 and step-ID 128/129 UTF-16 boundaries, +supplementary Unicode, invalid encoding/escapes and parser depth 32/33 are +asserted separately. Tiny canonical differences are not rounded away. + +The required sequential nine-project Release build passed with **0 warnings, +0 errors**; the complete suite passed **179 unit + 368 integration = 547 cases**, +zero failed/skipped, preserving all 442 baseline cases. Real live diagnostics/ +dynamics, saved recording, validated replay and a pending approved rehearsal +remain unchanged across template/valid/invalid preview invocation. Counted +transport/model/archive-Save/rehearsal open/read/write deltas are zero; authoring +change notifications and history mutations are zero, with unchanged approval, +source export, trace/state, archive bytes and replay snapshot. + +Native smoke on the rebuilt Client verified empty-source rejection, explicit +source/template with no auto preview, NoChanges, exact 650->1250/+600 rpm and +360->350/-10 N*m candidate/diff, safe rationale text and display-only units. +Malformed, physical-target, wrong-head and invalid-value inputs visibly rejected +while retaining the previous preview ID and exact diff. An explicit authoring +head change marked that captured result Stale; old input rejected and a new +template still did not validate until the explicit action. Current Proposed +head revalidation produced NoChanges without another authoring version. +Source export stayed identical and original preferences/old routes worked. +This normal UI evidence is not headless exact-limit/coexistence proof. +See the [Step-11 worker report](../prompts/Step-11-Report.md). + ## Step-10A pending-reopen close ownership verification -Step-10 remains not accepted pending manual corrective review. Original -Step-10 results below and its worker report are preserved. +Corrected Step-10/10A is accepted. Original corrective results below and the +worker reports are preserved. Before the fix, the two `PendingReopenCloseOrDispose_DrainsCurrentOwnerWithoutPriorCompletionReplay` cases executed against the actual Simulation factory and failed with: @@ -86,8 +120,8 @@ Exact commands, observations, cleanup and limitations are in the ## Step-10 simulated programming rehearsal verification -Step-09 is accepted; Step-10 remains pending manual review. The final focused -command passed **86 cases**: 31 new rehearsal cases plus 55 accepted authoring +Step-09 and corrected Step-10/10A are accepted. The historical focused +Step-10 command passed **86 cases**: 31 new rehearsal cases plus 55 accepted authoring cases. They use actual Simulation target storage/CAS through typed Diagnostics ports, real authoring/configuration/profile services and controlled forwarding faults. Independent backup, complete scalar/table readback, immutable approval, diff --git a/docs/calibration-rehearsal.md b/docs/calibration-rehearsal.md index ae7914c..e4398de 100644 --- a/docs/calibration-rehearsal.md +++ b/docs/calibration-rehearsal.md @@ -152,7 +152,7 @@ values or dispatch commands. ## Verification status -Step-09 is accepted; Step-10 remains pending manual review. Real-port tests +Step-09 and corrected Step-10/10A are accepted. Real-port tests exercise independent backup, exact scalar/table/CAS/Restore, malformed/stale requests, real commit with lost acknowledgement/cancel/read failure, full unchanged-cell checks, reconciliation, held cleanup and exact 32/33 capacity. diff --git a/docs/runbooks-v1.md b/docs/runbooks-v1.md new file mode 100644 index 0000000..0431179 --- /dev/null +++ b/docs/runbooks-v1.md @@ -0,0 +1,154 @@ +# Manual runbook schema v1 and read-only preview + +## Preview only + +Open `/runbooks` from shared navigation. Supply manual structured JSON, then +choose **Validate / Preview explicitly**. Entry, rendering and unit changes do +not create a workspace, template or preview. There is no LLM/model/runtime, +retrieval/network/upload, authoring Save, approval, target read/write or runbook +execution. Validation produces no authorization token or saved authoring +revision. Rationale is informational text, never instructions or policy. + +First explicitly create a synthetic configuration-derived authoring workspace +through the existing simulation/calibration UI. **Create input template from +current authoring source** copies that actual immutable workspace/head and +complete canonical values into an input draft. It does not validate or save. +Missing source gives a visible error, not a seeded/default/live fallback. +Both current Baseline and current Proposed authoring heads can be preview sources. + +## Exact object fields + +All fields below are required, exact camelCase. Every schema object rejects +missing, duplicate or unknown properties, including escaped duplicate names. +Comments, trailing commas/data, incorrect JSON kinds and unsupported tokens +are handled typed errors. No SQL/script/frame/offset/approval/execution property +is allowed at any schema level. + +### Root + +| Field | Contract | +|---|---| +| `schemaVersion` | JSON Int32 integer exactly 1, not string/fraction/exponent syntax | +| `runbookIdentifier` | Lowercase GUID in `N` format, exactly 32 characters | +| `targetKind` | Exact string `simulation`; this is not target access/permission | +| `rationale` | String, empty permitted, at most 2000 UTF-16 code units | +| `steps` | Array with exactly one step | + +### Step + +| Field | Contract | +|---|---| +| `stepIdentifier` | Explicit nonblank trimmed string, 1..128 UTF-16 code units | +| `operation` | Exact `proposeCalibration`, read-only preview only | +| `source` | Complete source object below | +| `values` | Complete scalar/table value object below, not a partial patch | + +### Source + +Exactly: + +- `workspaceIdentifier`, `expectedHeadIdentifier` +- `profileIdentifier`, `profileRevision` +- `configurationIdentifier`, `moduleIdentifier` +- `modelIdentifier`, `modelVersion` +- `definitionIdentifier`, `definitionRevision` + +Revision/version fields are positive JSON Int32 integers. Other source fields +are explicit nonblank trimmed strings and must match the actual current +authoring workspace/head/applicability. Profile/module comparison retains +existing ordinal case-insensitive policy. Configuration fingerprint, model/ +definition identifiers, workspace/head identities, logical keys and units are +exact. No module role, catalogue, live feed or latest-head resolution can fill +or replace a supplied source field. + +### Values + +The values object contains exactly `scalars` and `tables` arrays. +Each scalar object contains exactly `logicalIdentifier`, `unit`, `value`. +Each table object contains exactly `logicalIdentifier`, `unit`, `axisUnit`, +`axis`, `cells`; axis/cells are arrays of finite JSON numbers. + +The existing full [synthetic authoring template](calibration-authoring.md) +validates the complete candidate: + +- Exactly one `engine.warm-idle-target` scalar in source rpm, finite and in the + inclusive selected model IdleSpeedRpm..MaximumEngineSpeedRpm range. +- Exactly one `engine.torque-curve` table, source N*m cells and fixed source + rpm axis copied exactly from the selected configuration. All 2..32 rows, + units and counts must match. Every cell is finite in inclusive [1,1000]. +- No axis edit/reordering/sorting/insertion/deletion, clipping, interpolation, + arbitrary key or display-unit conversion is performed. + +JSON is always canonical source units even when global display is Imperial. +For the warm example, 650->1250 rpm and 2000-rpm torque 360->350 N*m produce +exactly two diff entries: scalar +600 rpm and table -10 N*m. Unchanged cells/ +axes are omitted. Read-only display conversion can show lbf*ft alongside the +canonical candidate but never changes JSON, bounds or diff. + +## Exact bounds and handled errors + +| Limit | Maximum | +|---|---:| +| Original complete input, UTF-8 encoding | 131072 bytes (128 KiB) | +| JSON parser nesting depth | 32 | +| Rationale | 2000 UTF-16 code units | +| Step identifier | 128 trimmed UTF-16 code units, minimum 1 | + +Input size is not string.Length. Supplementary Unicode uses two UTF-16 code +units per character and its actual UTF-8 byte size for the independent payload +bound. Otherwise valid JSON with whitespace at exactly 131072 bytes is accepted; +one extra byte is rejected. Non-finite/invalid-number, invalid encoding, +malformed syntax and depth-overflow inputs never produce a healthy default. + +Errors expose a typed failure, JSON/source/value path and readable reason: +InvalidJson, LimitExceeded, UnsupportedSchema, SchemaViolation, +OperationNotAllowed, SourceUnavailable, StaleSource or InvalidValues. +The UI identifies rejected draft input separately from the preserved previous +successful preview. An invalid attempt does not replace valid source/head/ +history/candidate/diff state. + +## Immutable result and current versus Stale + +The last successful preview contains copied preview/runbook/step/source/head +identity, rationale, captured head kind/revision/content, complete canonical +candidate, deterministic exact logical-ID/axis-ordered diff and: + +- **NoChanges**: exact captured head content and empty diff; +- **ChangesProposed**: changed preview, not a saved Proposed revision or a + Tested/Approved/Applied result. + +Parsing, allowlist, source/reference and full template validation all precede +publication under the actual authoring current-head guard. Only one successful +result is retained in process memory; there is no runbook repository, history, +Git backup, disk persistence, branch or merge layer. Snapshots/collections are +defensive/read-only. Canonical double comparisons have no display tolerance, +so a tiny representable change still yields its exact signed delta. + +When shown, source freshness is compared separately with the actual current +workspace/head/applicability and captured content. A changed/replaced source +labels the immutable old preview **Stale**, without rewriting it or the draft, +running validation on render or granting current execution authority. +Supply explicit updated input and revalidate to obtain a new current preview. +A new template is only a draft and does not clear staleness by itself. + +The page owns its unsaved input/error state; source and global-unit +notifications only rerender. Leaving the route loses that draft, while the +bounded last-successful preview remains in the running app and is labeled +separately on re-entry. Restart loses the preview. A future executor would +need independent fresh checks/approval; no executor is implemented here. + +## Verification and next boundary + +Tests use actual authoring/profile/configuration services, independent exact +value/diff vectors, all schema/source/value/limit boundaries, defensive copies, +source staleness, actual rendered controls and safely escaped rationale. +Real live diagnostics/recording/replay/approved-rehearsal instances coexist +around feature invocation with zero unassigned calls or mutations. +Native normal UI evidence is separate from headless boundary/coexistence proof. +See [build/test evidence](build-and-test.md) and the +[Step-11 worker report](../prompts/Step-11-Report.md). + +Corrected Step-10/10A is accepted; Step-11 remains pending manual review. +Step-12 local inference/knowledge and later executor integration remain future +and unimplemented. Any future generated text must use this same strict +parser/validator, not a privileged alternate mutation path. diff --git a/prompts/ROADMAP.md b/prompts/ROADMAP.md index 8d7a9ad..468b93e 100644 --- a/prompts/ROADMAP.md +++ b/prompts/ROADMAP.md @@ -3,9 +3,9 @@ ## Status and authority - Initialized: 2026-10-28. -- Current phase: corrected programming rehearsal accepted; deterministic runbook validation/preview next. -- Active assignment: [Step-11](Step-11.md), ready for manual worker execution. -- Last accepted milestone: Step-10 with Step-10A, accepted 2026-10-31. +- Current phase: deterministic runbook preview accepted; bounded local-only AI generation next. +- Active assignment: [Step-12](Step-12.md), ready for manual worker execution. +- Last accepted milestone: Step-11, accepted 2026-10-31. - Last accepted correction: Step-10A; all Step-10 findings closed. - Outstanding corrections: none. - Step-05 status: ACCEPTED after Step-05A/Step-05B, 2026-10-29. @@ -14,8 +14,9 @@ - Step-08 status: ACCEPTED 2026-10-30; no Step-08A required. - Step-09 status: ACCEPTED 2026-10-30; no Step-09A required. - Step-10 status: ACCEPTED after Step-10A, 2026-10-31. -- Step-11 status: READY FOR WORKER; deterministic simulation runbook validation/preview only. -- Step-12 status: local AI/knowledge integration; BLOCKED / NOT ASSIGNED until the validation boundary is accepted. +- Step-11 status: ACCEPTED 2026-10-31; no Step-11A required. +- Step-12 status: READY FOR WORKER; local-only model-generated calibration preview with exact applicable synthetic context. +- Step-13 status: comparative demonstration; BLOCKED / NOT ASSIGNED until local generation acceptance. - Current state and handoff: [STATE.md](STATE.md). - Authority: the master charter, repository/handoff amendment, and the owner's 2026-10-28 architectural realignment. The latest decision cancels the dual-shell @@ -256,6 +257,28 @@ approve a mutation or execute a runbook. A valid preview is not an authorization token or target verification. Later inference may propose structured data; existing deterministic source/head/template and approval checks remain required. +### Step-12 first local inference provider + +Accepted Step-11 is now the authoritative generated-output validator. +Step-12 adds one opt-in local-only Ollama HTTP provider and a bounded synthetic +knowledge lookup for that same one-step calibration preview. The model is +explicitly selected from an existing installed catalogue; there is no default +cloud model, pull/install/update, tool execution or inference on page entry. + +Production HTTP stays on loopback, without proxy/redirect or cloud fallback. +Ollama itself supports cloud delegation, so loopback alone is insufficient: +the operator must configure local-only mode, and remote/cloud model metadata +must be rejected. Runtime/model prerequisites and real local-generation/native +evidence are required; a stub response cannot satisfy those checks. +No model runtime has been started or verified by the orchestrator. + +Knowledge is a small explicit source/definition-matched synthetic policy pack +plus actual source/head/values/bounds, not broad vehicle research or a vector +database. Generated text passes the existing strict validator unchanged; it +cannot approve/execute/save or overwrite a newer manual preview. +Larger diagnostic/scenario/knowledge capabilities remain future slices, not +claimed by this first provider. No future numbering changes in this handoff. + ## Architecture baseline ### Existing accepted foundation, preserved @@ -450,8 +473,10 @@ Step-09 authoring is accepted: exact source binding, immutable linear proposals, atomic validation/head checks, precise diffs and zero source side effects are supported. Corrected Step-10/10A is accepted: isolated target backup/approval/ CAS/readback/recovery and current-lifetime close drainage are supported. -Step-11 is the only active assignment for deterministic runbook preview; -local inference/knowledge is the following Step-12, not bundled into validation. +Step-11 deterministic runbook validation/preview is accepted: strict schema/ +limits/allowlist/source-head/template, exact immutable diff and no-side-effect +behavior are supported. Step-12 is the only active assignment for the first +local-only model/context-generated calibration preview; no executor is assigned. Dependencies indicate acceptance prerequisites, not permission for automatic handoff. Later assignments refine these scopes using actual implementation evidence; they must not silently discard required capabilities. @@ -480,9 +505,9 @@ evidence; they must not silently discard required capabilities. | 09 | Synthetic calibration authoring and immutable proposals | 08 accepted | ACCEPTED 2026-10-30 | Real configuration/profile binding, immutable scalar/table proposals, exact diffs/stale-head/limits and no source mutation; reported 179 unit/226 integration passes | | 10 | Verified simulated programming and recovery | 09 accepted | ACCEPTED 2026-10-31 AFTER 10A | Isolated supported-image backup, exact approval/CAS/full readback/reconcile/Restore and current close ownership; no physical writes/model application | | 10A | Close/disposal ownership during pending rehearsal reopen | 10 review C-07/C-11 | ACCEPTED 2026-10-31 | Old close task retired at admission, disposed/generation guards and atomic close completion; actual pre-fix/controlled cleanup plus reported 179 unit/263 integration passes | -| 11 | Deterministic simulation runbook validation and preview | 10 and corrections accepted | READY FOR WORKER | Strict bounded schema-v1/allowlist/source-head/template validation, immutable exact proposal preview and stale status; no model, save, approval or execution | -| 12 | Local AI and applicable knowledge integration | 11 accepted | BLOCKED / NOT ASSIGNED | Replaceable local inference/context returns structured data through the accepted validator; missing/disconnected/invalid outcomes explicit, no bypass of mutation approval | -| 13 | Comparative evaluation and complete synthetic demonstration | 12 | PLANNED | Complete demonstration below plus deterministic fault/regression matrix and independent verification of intended and unintended changes | +| 11 | Deterministic simulation runbook validation and preview | 10 and corrections accepted | ACCEPTED 2026-10-31 | Strict schema/limits/allowlist/source-head/template, immutable preview/diff/staleness and no execution; reported 179 unit/368 integration passes | +| 12 | Local AI and applicable knowledge integration | 11 accepted | READY FOR WORKER | Opt-in loopback-only installed Ollama model and matched synthetic context generate one unchanged-validator preview; no cloud/tool/write execution or late manual-preview overwrite | +| 13 | Comparative evaluation and complete synthetic demonstration | 12 accepted | BLOCKED / NOT ASSIGNED | Complete demonstration below plus deterministic fault/regression matrix and independent verification of intended and unintended changes | | 14 | Verified OBDX Pro GT read-only integration | 13 plus documented device research/access | PLANNED / HARDWARE GATE | Source-backed device support matrix, explicit physical target, real read-only identification/diagnostics/telemetry recording where supported; no write path | | 15 | Advanced dashboards, analysis, and comparisons | 13; 14 for real captures | PLANNED | Persist configurable layouts/thresholds, linked charts, larger-capture analysis, raw-data inspection and multi-run/multi-vehicle comparisons with lineage/uncertainty | | 16 | Broader diagnostic protocols and hardware adapters | 14 | PLANNED | Conformance-backed additional CAN/ISO-TP/UDS/KWP2000/J2534 or legacy adapters where verified; same application ports and capability restrictions | @@ -956,20 +981,39 @@ history, not repeated redesign without evidence. - Prepared [Step-11](Step-11.md), separating deterministic runbook validation/ preview from subsequent Step-12 local inference/knowledge. Only unassigned future envelopes/dependencies shifted; completed history is unchanged. +- Reviewed Step-11's entire parser/source/current-head/preview/staleness/UI flow, + all new tests, docs and Release artifacts. Worker reports 179 unit + + 368 integration passes (547 total, zero failed/skipped), clean complete Release + build and native exact preview/rejection/stale/no-source-mutation evidence. +- Accepted Step-11 against its frozen ten-case/five-criterion matrix without + Step-11A. The orchestrator ran no application checks; native and controlled + exact-limit/no-side-effect proof remain distinct. +- Prepared [Step-12](Step-12.md) for one local-only provider/context/validated + generation owner. Runtime prerequisites, remote-delegation exclusions, strict + output/source/manual-preview guards and real-model evidence are frozen. + No inference installation or future renumbering was performed. ### Remaining -- Worker execution of Step-11, then review its frozen schema/allowlist/source/ - head/template/preview/no-side-effect matrix and shared quality gate. - Correct genuine unmet requirements as Step-11A before local inference. -- Step-12 AI is blocked and not assigned. Runbook preview is assigned work, - not implemented functionality; programming rehearsal and earlier work are accepted. +- Worker execution of Step-12, then review its frozen local-only/model/context/ + generation/validator/owner matrix and shared quality gate. Correct genuine + unmet requirements as Step-12A before comparative demonstration. +- Step-13 demonstration is blocked and not assigned. AI generation/context is + assigned work, not implemented functionality; runbook validation and earlier + work are accepted. - Profile/module metadata, synthetic virtual-module communication and deterministic dynamics/v2 and corrected dashboard are accepted; later features remain planned. Preserve the complete sequence/safety gates. ### Known blockers and uncertainties +No blocking Step-11 deficiency was identified against its frozen contract. +Step-12 needs an existing operator-approved local-only Ollama runtime and local +completion model for real generation smoke. The orchestrator verified current +public API/cloud-local-only documentation, not runtime/model availability. +Absent prerequisites mean BLOCKED/INCOMPLETE model checks, not permission to +install/pull/update or substitute a mock/cloud inference service. + No blocking Step-10 deficiency remains. Its pending-reopen finding below is historical and closed by accepted Step-10A: @@ -1000,7 +1044,7 @@ Save-followup refresh is still pending during host navigation. That unchanged recording flow is outside Step-08; no replay check is claimed to cover/fix it. Native preparation was restarted and final-binary replay passed without the error overlay. Retain the issue for a separately scoped recording follow-up, -not a retrospective replay/authoring criterion or automatic Step-11 cleanup. +not a retrospective replay/authoring criterion or automatic Step-12 cleanup. No blocking Step-07 deficiency remains. Its source-close follow-up below is historical and closed by accepted Step-07B: diff --git a/prompts/STATE.md b/prompts/STATE.md index 5e4f766..e2d1752 100644 --- a/prompts/STATE.md +++ b/prompts/STATE.md @@ -5,13 +5,13 @@ | Field | Value | |---|---| | Updated | 2026-10-31 | -| Phase | Corrected programming rehearsal accepted; deterministic runbook preview next | -| Active step | Step-11 - Deterministic simulation runbook validation and preview | -| Assignment | [Step-11.md](Step-11.md) | +| Phase | Deterministic runbook preview accepted; bounded local-only AI generation next | +| Active step | Step-12 - Local AI and applicable knowledge integration | +| Assignment | [Step-12.md](Step-12.md) | | Assignment status | READY FOR WORKER / AWAITING MANUAL HANDOFF | -| Expected worker report | `prompts/Step-11-Report.md` - not yet created | +| Expected worker report | `prompts/Step-12-Report.md` - not yet created | | Last accepted correction | Step-10A - accepted 2026-10-31 | -| Last accepted major milestone | Step-10 with Step-10A - accepted 2026-10-31 | +| Last accepted major milestone | Step-11 - accepted 2026-10-31 | | Outstanding corrections | None | | Step-02 status | ACCEPTED after Step-02A | | Step-03 status | ACCEPTED after Step-03A/Step-03B | @@ -25,10 +25,11 @@ | Step-08 status | ACCEPTED 2026-10-30; no correction required | | Step-09 status | ACCEPTED 2026-10-30; no correction required | | Step-10 status | ACCEPTED after Step-10A | -| Step-11 status | READY FOR WORKER; deterministic simulation runbook preview only | -| Step-12 status | Local inference/knowledge; BLOCKED until validator acceptance | -| Worker execution | Step-10A returned and accepted; Step-11 not invoked | -| Immediate next action | User manually directs the worker to execute Step-11 and shared quality gate only | +| Step-11 status | ACCEPTED 2026-10-31; no correction required | +| Step-12 status | READY FOR WORKER; local-only one-step calibration generation/preview | +| Step-13 status | Comparative demonstration; BLOCKED until Step-12 acceptance | +| Worker execution | Step-11 returned and accepted; Step-12 not invoked | +| Immediate next action | User manually directs the worker to execute Step-12 and shared quality gate only | | Next orchestrator action | After manual return, inspect the assignment, report, implementation, tests, Git changes, documentation and recorded command evidence | ## Repository baseline at initialization @@ -1230,6 +1231,57 @@ implemented/assigned in this slice. Current domain source/head/target checks remain necessary; the earlier Git discussion did not authorize a persistence rewrite of the accepted volatile rehearsal. +## Step-11 acceptance + +Decision: **ACCEPTED**, 2026-10-31. Frozen C-01..C-10/AC-01..AC-05 are satisfied +on reviewed source and worker evidence. No Step-11A is required. + +Reviewed [Step-11](Step-11.md), its [report](Step-11-Report.md), the entire strict +parser/current-source/head/template/diff/publication/freshness implementation, +actual template/validation/error/stale UI, all three new test files, +docs/README, graph and existing Release outputs. + +| Criterion | Decision | Evidence | +|---|---|---| +| AC-01 | ACCEPTED | Required/duplicate/unknown/type/version/operation/target/source/full-template guards, exact UTF-8/UTF-16/depth limits and independent typed atomic negative vectors | +| AC-02 | ACCEPTED | Exact canonical scalar/table/multi-cell/reverse/tiny diffs, copied one-preview retention, current-head guarded publication and immutable prior preview with explicit Stale status | +| AC-03 | ACCEPTED | Actual rendered/native template/Validate/error/source/stale/safe-rationale/units path and counted real live/recording/replay/approved-rehearsal zero-call/state preservation | +| AC-04 | ACCEPTED ON WORKER EXECUTION EVIDENCE | Reported complete nine-project Release build zero warnings/errors; 179 unit + 368 integration passes (547 total, zero failed/skipped), native exact manual preview/rejection/source isolation | +| AC-05 | ACCEPTED | Executable matrix, own post-green source-path/Unicode/type/full-shape additions, aligned docs/history/protection/dependency/manual workflow preserved | + +The 105 added integration cases preserve all 442 prior cases. The service +depends only on actual authoring state, reuses complete template/diff/current- +head helpers and releases its own snapshot gate before reading authoring state. +It neither saves nor generates authority; invalid inputs retain prior success. + +The orchestrator ran no application builds/tests/native/workload commands. +Source-case inventory, unchanged graph and existing outputs corroborate worker +evidence, not independent runtime verification. Native limits/coexistence +claims remain separated from controlled tests. + +## Step-12 local-only generation handoff + +[Step-12](Step-12.md) introduces one explicit installed Ollama model over +loopback HTTP, a matched synthetic policy/context pack and one cancellable +generation owner. It produces only the existing read-only calibration runbook +preview, through the unchanged authoritative validator. + +The HTTP client must not use remote/cloud URLs, proxies, redirects, credentials +or tool calls. Ollama can relay cloud models even through its local API: +operator local-only configuration/acknowledgement and remote-model metadata +rejection are required. The orchestrator checked official API/local-only docs, +not installed runtime/model availability. +Use an existing approved runtime/model; do not install/pull/start/update shared +services or count stub HTTP output as real LLM/native evidence. + +Capture explicit source/head/model/digest/knowledge context and prior-preview +identity at request start. Cancellation, source changes, model eligibility/ +identity changes or a newer manual preview cannot yield stale successful +publication. No output repair/rebinding, proposal Save, approval, target write, +physics action or knowledge-based permission is introduced. +Missing/disconnected/invalid output remains a typed visible failure, while all +manual/core workflows remain available without a model. + ## Prerequisites, limitations, and known issues - Step-01A worker evidence establishes portable and native Windows compatibility @@ -1257,23 +1309,28 @@ rewrite of the accepted volatile rehearsal. 202-/207-case reports and original numerical/native evidence distinctly. - Profile metadata/UI, synthetic diagnostics, deterministic dynamics/v2 and the corrected dashboard/display units/recording archive/replay/authoring are accepted. - Corrected simulated programming is accepted. Runbook validation/preview, - local inference/knowledge and physical hardware operations remain unimplemented. + Corrected simulated programming and deterministic runbook preview are accepted. + Local inference/knowledge generation and physical hardware operations remain + unimplemented. +- Step-12 real-model smoke needs operator-provided local-only Ollama and an + installed local completion model. No runtime/model installation, pull, service + start/update or cloud use is authorized by this handoff. Report exact missing + prerequisites and BLOCKED/INCOMPLETE rather than replacing the real proof. - No application build or test has been executed by the orchestrator. ## Review and progression gate -On manual return, evaluate Step-11 and its frozen runbook-preview contract/shared gate using the +On manual return, evaluate Step-12 and its frozen local-generation contract/shared gate using the assignment, worker report, actual code/tests, dependency graph, Git changes, README/docs, and recorded build/test evidence. Do not accept solely on a success claim; do not claim independent runtime verification. -- Inspect strict schema/limits/allowlist, exact current source/head/template, - immutable preview/diff/staleness, real UI and zero save/approval/model effects. - Do not add deferred inference/retrieval/execution/persistence requirements. -- If accepted: accept Step-11, update roadmap/state, prepare a bounded Step-12 local-inference/knowledge assignment +- Inspect local-only eligibility/HTTP bounds, applicable context, untouched + validator, request/source/model/manual-preview identity, cancellation/drain, + real model/native evidence and zero mutation. Do not add broad RAG/execution. +- If accepted: accept Step-12, update roadmap/state, prepare a bounded Step-13 comparative-demonstration assignment and stop for manual handoff. -- If deficient: issue narrowly scoped Step-11A only for a material unmet contract/ +- If deficient: issue narrowly scoped Step-12A only for a material unmet contract/ regression, then stop. Planned new features are not corrections. - If blocked: retain the active step, document the prerequisite and required worker evidence; do not advance or mark unexecuted checks as successful. @@ -1357,12 +1414,14 @@ claim; do not claim independent runtime verification. | 2026-10-31 | Corrected Step-10 ACCEPTED | Original and 10A criteria closed; backup/approval/CAS/readback/restore/source safety preserved; no 10B | | 2026-10-31 | Runbook/inference envelope split prospectively | Step-11 deterministic validation/preview, Step-12 local inference/knowledge; former unassigned 12-23 become 13-24, completed history preserved | | 2026-10-31 | Step-11 prepared | One allowlisted simulation proposal, strict source/head/template/JSON validation and immutable no-execution preview; manual handoff pending | +| 2026-10-31 | Step-11 returned and ACCEPTED | Frozen validator/preview contract satisfied; reported 547-case/clean Release/native evidence, strict parser/source/head/limits/diff/staleness/no-side-effect and self-review inspected; no 11A | +| 2026-10-31 | Step-12 prepared | Opt-in local-only Ollama generation, one matched synthetic context and unchanged-validator preview; real runtime/model prerequisite, no cloud/write/executor or renumbering | ## Manual handoff instruction -Provide [Step-11.md](Step-11.md) and the shared +Provide [Step-12.md](Step-12.md) and the shared [worker gate](WORKER-QUALITY-GATE.md) to the separate worker and request execution -of that assignment only. The worker must produce `prompts/Step-11-Report.md` -and stop for review. Do not begin Step-12 local inference/knowledge. +of that assignment only. The worker must produce `prompts/Step-12-Report.md` +and stop for review. Do not begin Step-13 comparative demonstration. Return manually to the orchestrator for review. Reports, including final chat reports, must follow the single plain triple-backtick copy-window requirement. diff --git a/prompts/Step-11-Report.md b/prompts/Step-11-Report.md new file mode 100644 index 0000000..5c7e6e3 --- /dev/null +++ b/prompts/Step-11-Report.md @@ -0,0 +1,236 @@ +``` +# Step-11 - Deterministic simulation runbook validation and preview + +## Status + +COMPLETE. Strict bounded manual schema/source/head/template validation, +immutable exact preview/staleness, actual local UI, real-source no-side-effect +tests, post-green self-review, nine-project Release build/full regressions and +native smoke passed. + +Step-11 remains pending manual orchestrator review; this report grants no +acceptance or mutation authority. Corrected Step-10/10A remains accepted. +Step-12 local inference/knowledge and runbook execution were not started. +No model/runtime/retrieval/network feature, authoring Save, target command, +approval or app-level Git persistence was implemented. + +## Files, functions and interfaces + +- [RunbookPreviewService.cs](../src/AutoForge.Application/Features/Vehicles/Runbooks/RunbookPreviewService.cs): + typed RunbookPreviewException/failures, immutable source/result/snapshot + contracts, strict allowlisted parsing, Validate, CreateInputTemplate and + fresh Snapshot status. The only constructor dependency is the existing + CalibrationAuthoringService; validation reads its immutable snapshot and + publishes under its existing narrow current-head guard. +- Existing SyntheticEngineCalibration validates complete scalar/table values; + existing CalibrationValueDifferences supplies the pure exact diff. Neither + helper, authoring Save, rehearsal, target or source model implementation + was changed or duplicated. +- [RunbookPage.razor](../src/AutoForge.UI/Features/Vehicles/Runbooks/RunbookPage.razor): + /runbooks, manual JSON input, explicit source template/Validate actions, + typed input errors, previous successful result labels, current/Stale source + status, canonical candidate/diff and optional display-only units. + Authoring/preview notifications only schedule rendering; they never rebase + input, validate, save or execute. +- [AddAutoForgeUi.cs](../src/AutoForge.UI/Features/Foundation/AddAutoForgeUi.cs), + [MainLayout.razor](../src/AutoForge.UI/Layout/MainLayout.razor) and + [Home.razor](../src/AutoForge.UI/Features/Foundation/Home.razor): + minimal preview registration and shared navigation. Client DI and all + nine project references remain unchanged. + +Executable evidence: + +- [RunbookPreviewTests.cs](../src/tests/AutoForge.IntegrationTests/RunbookPreviewTests.cs) +- [RunbookPreviewUiTests.cs](../src/tests/AutoForge.IntegrationTests/RunbookPreviewUiTests.cs) +- [RunbookPreviewIsolationTests.cs](../src/tests/AutoForge.IntegrationTests/RunbookPreviewIsolationTests.cs) + +The initial frozen schema/source/value/limit/immutability/stale/UI/isolation +tests were written before production implementation. The post-green review +added exact exponent/Unicode/escaped-property/count/missing-source vectors. + +## Frozen C-01..C-10 matrix + +All rows below are PASSED. Named methods were executed tests, not proposals. + +| ID | Named evidence and exact result | +|---|---| +| C-01 | ExplicitSourceAndNoChanges_PreviewCopiesWholeHeadWithoutImplicitWorkspaceOrSave; MissingActualWorkspace_RejectsStructuredInputWithoutCreatingSourceOrPreview. No source/template/preview is created implicitly. Valid unchanged complete current-head input yields NoChanges, empty diff, exact copied workspace/head/applicability, scalar 650 and six original torque rows. Missing actual workspace rejects SourceUnavailable even for structured otherwise-valid input. Source/history remain the same immutable snapshot. Both Baseline and Proposed current heads are usable. | +| C-02 | ScalarTableMultiCellReverseAndTinyChanges_AreExactCanonicalDiffNotAuthoringSave. Independent candidate 1250 rpm plus 2000-rpm torque 350 yields exactly two ordered canonical entries: table before 360/after 350/delta -10 N*m/axis 2000 rpm; scalar before 650/after 1250/delta +600 rpm. Multiple-cell ordering, reverse +10/-600 and representable tiny differences are asserted without tolerance. No authoring/config/target is changed by preview. | +| C-03 | EverySchemaObject_RejectsMissingDuplicateUnknownFieldsAtomically (18 object/mutation vectors); WrongKindsAndIntegerSyntax_RejectWithoutReplacingPriorSuccessfulPreview (24 vectors); MalformedCommentsTrailingDataAndWrongRoot_AreHandledAtomicErrors; EscapedDuplicatePropertiesInvalidUnicodeAndNonJsonNumbers_AreTypedAtomicRejections. Root/step/source/values/scalar/table properties are all required, unique and allowlisted. Wrong kinds, fractional/exponent reference syntax, malformed/comments/trailing input, unsupported version, null input and invalid strings/numbers reject through typed failure/path/reason before replacement. Prior preview and source/head/history remain identical. | +| C-04 | OperationAllowlistAndSingleStep_RejectExecutionOrOtherTargets (10 vectors); ArbitraryCommandAndAuthorityFields_AreNeverInterpreted (6 vectors); safe rationale rendered test. Only exact simulation/proposeCalibration and one step are allowed. Physical/replay/undefined/case-changed target/operation, empty/multiple steps and SQL/script/frame/offset/approval/execute fields reject. Rationale is safely rendered informational text and never grants command or policy authority. | +| C-05 | EverySourceComponent_MustMatchActualWorkspaceAndCurrentHead (10 vectors); FieldSpecificCasePolicies_AcceptProfileModuleButNotFingerprintModelDefinitionKeyOrUnit. Every workspace/head/profile revision/config/module/model version/definition reference must match actual current source. Profile/module case variants preserve existing ordinal-insensitive policy; fingerprint/model/definition/key/unit stay exact. No catalogue, role or latest-head fallback occurs. | +| C-06 | FullTemplateInvalidNumbersKeysUnitsAxisAndShape_RejectAtomically (14 vectors); ExactTemplateBoundsAndNoOp_KeepCanonicalValuesWithoutClipping; SupplementaryStepIdentifierAndWholeCandidateCounts_FollowExactExistingLimits; exact tiny/reverse diff test. Full existing template validates finite scalar/cells, keys/units/fixed axes/counts. Out-of-range/non-finite/wrong-axis/shape/key/unit candidates reject atomically. Inclusive 650/5000 rpm and 1/1000 N*m boundaries remain exact; tiny canonical deltas are not rounded away and no sorting/clipping occurs. | +| C-07 | SourceChangeAndReplacement_MarkImmutableOldPreviewStaleUntilExplicitCorrectRevalidation; actual rendered stale/draft test. Old-head request rejects; source/head change/replacement after success marks the same immutable captured result Stale. Its before/candidate/diff/identity are not rebased. Explicit correct input/revalidation is required; source changes do not alter draft or invoke validation. Publication reuses the actual source/head guard. | +| C-08 | Utf8PayloadBoundary_IsExactly131072BytesIncludingMultibyteRationaleAndWhitespace; RationaleAndStepIdentifier_AreExactUtf16CodeUnitLimits; supplementary Unicode/depth tests. Valid original payload exactly 131072 UTF-8 bytes succeeds despite shorter string.Length; one more byte rejects with prior result retained. Rationale 2000 succeeds/2001 rejects; step 128 succeeds/129 rejects. Supplementary Unicode is counted in UTF-16 correctly. Depth 32 parses then receives appropriate schema rejection for the deliberately unknown structure; depth 33 is handled InvalidJson. Invalid UTF-8 encoding/escaped surrogate and non-JSON NaN are handled without fallback. | +| C-09 | PreviewCollectionsAndRetainedResult_AreDefensiveAndBoundedToOneSuccess; RunbookUi_TemplateValidateRejectedDraftStaleAndUnits_NeverAutoValidateOrRebase. Parsed collections/current-head values/diff are copied/read-only; mutation attempts reject and old preview contents survive a later success. Service retains one last success, invalid attempt preserves its identity, and UI separates old result from rejected/edited input. Units/rerenders/source notifications do not validate or modify canonical input/data/diff. | +| C-10 | RunbookUi_SafeRationaleUnavailableSourceAndNoExecutionControls_AreRealRenderedBehavior; RunbookIsolation_ActualLiveRecordingReplayAndApprovedRehearsalRemainUntouched; native evidence. Actual route/template/Validate/error/stale/rendering path works without Save/approval/Execute controls. Real live source/recording/replay/approved rehearsal coexist around invocation: transport/model/archive-Save/rehearsal open/read/write deltas=0, authoring changes/history mutation=0, approval remains same/unconsumed, and source export/trace/status/archive bytes/replay snapshot are unchanged. Constructor/source-path review confirms no Save/approval/network/model path. All 442 regressions plus 105 new cases, nine-project Release and native smoke pass. | + +## Acceptance criteria + +| ID | Result | Evidence | +|---|---|---| +| AC-01 | PASSED | C-03..C-06/C-08 independent strict schema/allowlist/kind/reference/full-template vectors, exact UTF-8/UTF-16/depth bounds and typed atomic rejection assertions. | +| AC-02 | PASSED | C-01/C-02/C-07/C-09 exact immutable before/candidate/source/head/diff, NoChanges/ChangesProposed, tiny changes, defensive copies, Stale versus current and bounded one-preview retention. | +| AC-03 | PASSED | C-10 real rendered/native controls, safely encoded rationale, unchanged approved real rehearsal/live/recording/replay/source counters/state, no execution or inference dependency/path. | +| AC-04 | PASSED | Final 547 passes with all 442 baseline cases preserved; all nine Release projects/native Client, 0 warnings/errors; required native normal preview/rejection/staleness/source/unit smoke passed. | +| AC-05 | PASSED | Frozen executable matrix, own post-green source-path review, exact schema/usage/docs/README, protection/history/manual gate preserved and this single fenced report saved. | + +## Final commands and outcomes + +SDK: dotnet --version -> 10.0.403 under the unchanged global.json policy. +Existing xUnit v2/VSTest is unchanged. No package/SDK/workload/tool install, +restore, update or repair occurred. + +Focused, required build and complete regressions ran sequentially: + +| Exact command | Exit | Result | +|---|---:|---| +| dotnet test .\src\tests\AutoForge.IntegrationTests\AutoForge.IntegrationTests.csproj --configuration Release --no-restore --filter "FullyQualifiedName~RunbookPreviewTests|FullyQualifiedName~RunbookUi_|FullyQualifiedName~RunbookIsolation_" | 0 | 105 new runbook cases passed, zero failed/skipped. | +| dotnet build .\src\AutoForge.slnx --configuration Release --no-restore | 0 | All nine projects/native Client; 0 warnings, 0 errors. MAUI XAML source-generation output was informational. | +| dotnet test .\src\AutoForge.slnx --configuration Release --no-build | 0 | 179 unit + 368 integration = 547 passed, zero failed/skipped. | +| git --no-pager diff --check | 0 | No whitespace errors; existing README/build-guide LF-to-CRLF notices only. | +| git --no-pager diff --exit-code -- prompts global.json Directory.Build.props Directory.Packages.props NuGet.Config src\AutoForge.Core src\AutoForge.Diagnostics src\AutoForge.Simulation src\AutoForge.Client src\AutoForge.Application\Features\Vehicles\Calibration src\AutoForge.Application\Features\Vehicles\Telemetry | 0 | Existing protected history/dependencies/core/ports/models/Client/authoring/rehearsal/recording/replay implementations unchanged before adding this report. | + +Per-project Release: AutoForge.Core, AutoForge.Diagnostics, +AutoForge.Simulation, AutoForge.Application, AutoForge.Components, +AutoForge.UI, AutoForge.Client, AutoForge.UnitTests and +AutoForge.IntegrationTests all PASSED. Portable projects remain net10.0; +Client remains net10.0-windows10.0.26100.0 / win-x64. + +The baseline is unchanged: 179 unit + 263 integration = 442 cases. This step +adds 105 integration cases; no baseline safety/source assertion was deleted +or weakened. Preview limits are 131072 original UTF-8 bytes, depth 32, +rationale 2000 UTF-16 units, step ID 1..128 trimmed UTF-16 units and one +allowlisted step. Existing authoring/rehearsal/archive/gauge limits remain. + +Iteration: + +- First executable focused run passed 99 cases without compilation/behavioral + failures. The post-green review added exponent/escaped-property/Unicode/ + full-count cases, yielding 104. A final independent missing-workspace + validator case raised the final count to 105. +- The full reviewed suite initially passed 546; final focused/build/full + checks passed 105/547 after that last test addition. Production source + was unchanged after the initial implementation/source-path review. +- Native automation initially matched the explanatory word ChangesProposed + in a NoChanges status before the actual diff rendered, causing a helper + null-DOM read. It was corrected to wait for the exact captured indication + and element presence. This was not a parser/app failure or a successful + observation. The actual native workflow then completed without an error + overlay. +- No pre-fix behavioral reproduction is claimed: this is a new feature, not + an existing validator bug correction. + +## Native normal evidence versus headless proof + +The actual rebuilt Windows Client was operated through task-owned WebView2 +data/local DevTools port 9382 with a temporary built-in Node/WebSocket helper. +No new application web host, runtime/model or dependency was added. + +Native observations: + +1. /runbooks entered with empty input/no preview. Explicit template attempt + without source gave SourceUnavailable and created no source/default result. +2. Explicitly created warm source through existing simulation/calibration UI. + Actual workspace f1b8740bd2414b7aa3e7be78ff35139f, baseline head + 60bc53bc58d04ae38ab208aecf4d8ced. Template copied that source without + validation; explicit Validate yielded NoChanges/current/empty diff. +3. Manual canonical edits 1250 rpm and torque 350 at 2000 rpm yielded preview + 493f4f636782496eb50df0e4294e5a9f, ChangesProposed/current, with exactly: + engine.torque-curve axis 2000 rpm, 360->350 N*m, signed delta -10 N*m; + engine.warm-idle-target 650->1250 rpm, signed delta +600 rpm. +4. Rationale "Manual preview only: this is not approval." rendered as + text. Its HTML used <b> and no b element was created. + Metric->Imperial changed optional torque display only; JSON draft, preview + identity and exact canonical diff stayed unchanged. +5. Malformed JSON, physicalHardware target, wrong expected head and scalar + 600 each yielded the appropriate InvalidJson/OperationNotAllowed/ + StaleSource/InvalidValues error with path/reason, while the previous + preview ID and diff remained exactly unchanged and explicitly labeled + Previous successful preview retained. +6. Returning to authoring confirmed history count 1 and original scalar 650; + rehearsal remained Inactive/audit 0. Preview created no saved proposal, + target or approval. +7. A separate explicit authoring Save changed current head to revision 2 / + c2cb7ddefe474f44a17754896b3fde9c. On runbooks re-entry the original preview + was visibly Stale, with its old identity/diff unchanged. Old JSON input + rejected StaleSource. A new template still did not validate/clear stale + result automatically; explicit Validate produced NoChanges/current for + the current Proposed head. History remained exactly 2, not 3. +8. Original source configuration export stayed exactly identical, fingerprint + sha256:v1:e8991ae139b54959ec53a4fe64b08dc9bfc03feb533496cf741f2c9f3a2342da. + No model/session/target execution was opened by this native preview smoke. + Original Metric/Road preferences were restored and observed; existing + replay/Home routes worked, with replay Unloaded. + +Native evidence is normal real-UI/source behavior, not exact-limit or +concurrency/coexistence proof. Actual active live/recording/replay/approved- +rehearsal coexistence and zero boundary calls are headless real-service/port +tests. Normal route cleanup is not attributed to validator invocation. +No inference, knowledge, physical target or programming was used. + +Cleanup PASSED: task Client PID 40340 completed after route cleanup. Transient +WebView PIDs 45756/44632 were checked against the task profile before any +specific-PID cleanup. No owned WebView/listener remained; port 9382 was closed. +Exact task-only profile/helper were removed. Native source/proposal/preview +data were process-memory only; the app-local recordings directory remained +empty. No unrelated file/archive/default WebView data/preferences were reset. + +## Own post-green producer/consumer review + +Reviewed manual JSON -> original strict UTF-8 bound -> JsonDocument depth/ +syntax/object/type/allowlist checks -> detached source/value contracts -> +actual authoring snapshot/component matching -> full existing template -> +pure exact diff -> current-head guarded publication -> copied last success -> +current versus Stale snapshot -> actual input/error/preview UI. + +Public entry points reviewed: Validate, CreateInputTemplate, Snapshot and +route template/Validate/subscription/render/disposal paths. Normal, rejected, +boundary, source-change/replacement, old-preview, draft/error and unit cases +were walked against C-01..C-10. + +All schema/source/template checks precede replacement. Publication is under +the existing exact source/head guard. Snapshot releases the preview gate +before reading the authoring gate, avoiding inverse lock order. Captured +values/source/head/diff remain immutable; later source data only determines +freshness, never rebasing. No method calls Save, Approve, target/model/store/ +network or arbitrary tool code. UI notifications only render, with separate +rejected/edited draft and previous successful labels. Rationale is plain safe +text. The retained state is one preview, not a version/history framework. + +Review strengthened actual integer syntax, escaped duplicate property, +invalid Unicode/NaN, supplementary-code-unit, duplicate whole-value-array +and missing-real-workspace assertions. No production defect required a +follow-up fix. Affected focused and full build/regressions were rerun to +105/547 passes. Native used the same unchanged production implementation. +No known unresolved assigned exit-contract defect remains. + +## Documentation and preservation + +Added [runbook schema-v1/preview guide](../docs/runbooks-v1.md); updated +[README.md](../README.md), [documentation index](../docs/README.md), +[architecture](../docs/architecture.md), [build/test guide](../docs/build-and-test.md) +and the directly related accepted-status note in +[rehearsal contracts](../docs/calibration-rehearsal.md). +They document exact fields/limits/allowlist, source/head/template/canonical +rules, defensive one-preview/current-Stale behavior, input versus old result, +manual/no-model/no-save/no-execution/no-authority scope and actual evidence. +Corrected Step-10/10A is accepted; Step-11 remains pending manual review. +Future generated Step-12 text must use this same boundary, not a privileged +path. Inference/knowledge and executor integration remain unimplemented. + +Worktree began clean on main at bccb797 and HEAD is unchanged. Existing +prompts/state/roadmap/assignments/shared gate/reports and protected files were +not edited; this is the only new prompts file. Index remains empty. +All nine projects/references/dependencies and existing Core/profile/config/ +Simulation/Diagnostics/authoring/rehearsal/recording/replay/physics contracts +are unchanged. Source/tests remain under src/src/tests; docs under docs. +The separately disclosed recording navigation issue was not modified. + +No new project/package/host/model/runtime/schema change to other features, +permission/version-control/backup framework, app Git persistence, agent, +automatic handoff, staging, commit, push, system installation or unrelated +cleanup occurred. + +STOP. +``` diff --git a/prompts/Step-12.md b/prompts/Step-12.md new file mode 100644 index 0000000..b1ce1c0 --- /dev/null +++ b/prompts/Step-12.md @@ -0,0 +1,327 @@ +# Step-12 - Local AI and applicable knowledge integration + +## STEP IDENTIFIER + +Step-12. Step-11 was accepted on 2026-10-31 with no correction. +This is the sole active implementation assignment. Step-13 demonstration is blocked. + +## STEP TITLE + +Generate one synthetic calibration runbook with an explicitly selected local-only +model and applicable context, then use the existing deterministic preview validator. + +## OBJECTIVE + +One user outcome: an explicit bounded natural-language calibration request +produces either a model-generated validated read-only preview or a precise error. +One primary new contract: a local-only, source/model/context-bound cancellable +generation whose untrusted output cannot bypass validation or mutation approval. + +No authoring Save, target open/write, runbook execution, cloud inference or +physical operation is assigned. Read [STATE.md](STATE.md), [ROADMAP.md](ROADMAP.md), +[runbooks v1](../docs/runbooks-v1.md) and [WORKER-QUALITY-GATE.md](WORKER-QUALITY-GATE.md). +Establish the frozen matrix before coding, self-review after first green, +write `prompts/Step-12-Report.md`, and STOP. + +## ARCHITECTURAL CONTEXT + +Keep all nine projects, one Client and independent Components. +Application owns a small replaceable inference port, matched context provider +and generation orchestration against actual authoring/preview contracts. +An Ollama HTTP implementation may live in the existing Application feature with +Client configuring the real transport; UI owns explicit selection/generation/ +cancel/context/output/error and page lifetime. No new project/package/host, +generic agent/tool/runtime framework or vector database. + +Reuse [RunbookPreviewService](../src/AutoForge.Application/Features/Vehicles/Runbooks/RunbookPreviewService.cs), +the actual [authoring service](../src/AutoForge.Application/Features/Vehicles/Calibration/CalibrationAuthoringService.cs) +and existing synthetic definition/diff/units. The deterministic validator stays +authoritative; do not implement a weaker model-only schema/source validator. +Source/tests remain under `src`, tests under `src/tests`. + +## CURRENT IMPLEMENTATION STATE AND PREREQUISITES + +Accepted manual runbooks allow one simulation/proposeCalibration step, exact +source/head/full scalar/table values, strict schema/limits, immutable preview/ +diff and Stale status. They save/approve/execute nothing. +Worker baseline: 179 unit + 368 integration passes (547 total, zero failed/ +skipped), clean nine-project Release build and native manual-preview checks. +The orchestrator did not run those commands. + +First provider: Ollama local HTTP at `http://127.0.0.1:11434`. +Use an **existing operator-approved runtime and installed local model**. +Do not install/pull/update models or runtimes, sign in, start/restart a shared +service or alter user/system settings automatically. Real model availability +was not verified by the orchestrator. Missing prerequisites block the assigned +real-generation/native checks; do not substitute a stub or cloud and declare COMPLETE. + +Verified public contracts, recheck against the installed runtime before coding: + +- [Chat API](https://docs.ollama.com/api/chat): POST `/api/chat`, explicit model/ + messages, `stream:false`, structured `format`; read `message.content`. +- [Model catalogue](https://docs.ollama.com/api/tags): GET `/api/tags`, local + model name/digest/size and optional remote_model/remote_host. +- [Model details](https://docs.ollama.com/api-reference/show-model-details): + POST `/api/show`, completion capabilities and model metadata. +- [Local-only configuration](https://docs.ollama.com/faq#how-do-i-disable-ollamas-cloud-features): + operator disables cloud with documented server configuration or + `OLLAMA_NO_CLOUD=1`, then verifies the runtime's cloud-disabled status. + +Use the actual documented anchor/path the installed docs expose if necessary; +do not invent unsupported APIs. A loopback URL alone does not prove the Ollama +model will not delegate to cloud. No API key/authentication is needed or allowed. + +## REQUIRED IMPLEMENTATION + +### Frozen contract matrix + +| ID | Input/precondition | Required result | +|---|---|---| +| C-01 | App/route entry or ordinary manual workflow without a model | No automatic network/generation/model/source action; manual validator/authoring/diagnostic/replay/rehearsal still works. Explicit catalogue refresh and opt-in/model selection are required. | +| C-02 | Eligible installed local model versus remote/cloud/ambiguous/stale metadata, absent runtime/model or redirect/proxy | Only loopback local-only eligible selection can generate; precise visible rejection before goal/context reaches an ineligible destination. No model substitution, pull/install/cloud/tool call. | +| C-03 | Actual current supported authoring source/head and matched synthetic knowledge | Capture exact immutable source/head/values/constraints, model name/digest, knowledge ID/revision/applicability and bounded goal. Missing/mismatched source/knowledge rejects before chat. | +| C-04 | Controlled valid response and real native goal from warm baseline | Original model content passes existing Step-11 validator; exact 1250 rpm and 2000-rpm torque 350 N*m yield +600/-10 diff with unchanged other cells. No saving/approval/write; real model evidence distinguishes intent accuracy from mere parse success. | +| C-05 | Invalid/refused/empty/markdown/truncated/tool-call/wrong-source/wrong-unit/unknown-key model output | Typed generation/validation error, no repaired/rebound/default candidate; previous successful preview remains intact. Unvalidated content is safely labeled/limited, never actionable authority. | +| C-06 | Source/head changes, newer manual preview or model selection/digest superseded while generation is pending | No stale overwrite or rebasing. Publish only for the current owner/source/head/selected model and captured prior-preview identity, through atomic validator publication checks. | +| C-07 | Repeated Generate, competing refresh/selection, Cancel/close/re-entry and delayed response | One owner; conflicts reject before mutation/request, cancellation/close drains outside required gates, no late preview/Ready state, fresh page lifetime does not reuse closed completion. | +| C-08 | HTTP errors/timeouts/invalid metadata/duplicate critical response fields/chunked oversized body | Typed visible failure; bounded actual reads/request sizes, no success-shaped empty catalogue/content or partial JSON publication. Preserve prior source/preview/core workflows. | +| C-09 | Prompt/rationale attempts to alter policy/source, global units/renders/hide | Quoted goal/context/model output remain untrusted data; deterministic allowlist/source/template still applies. No tool/write/model control, validation on render or unit-based source mutation. | +| C-10 | Real generation/coexistence and complete verification | All 547 baseline cases/new coverage and nine-project Release build pass; real installed local-model/native preview runs with cloud disabled; counted existing transport/model/archive/rehearsal/authoring mutations remain zero. | + +### A. Explicit local-only provider and transport + +Use a small replaceable typed inference port; implement Ollama first using built- +in .NET HTTP/JSON, not a new SDK dependency. Production base URI is fixed loopback +above; tests may inject a controlled loopback HTTP peer/handler below the provider. +Reject non-loopback destinations. Disable redirects, system proxies and default +credentials; requests cannot carry API keys or resolve an arbitrary model-supplied URL. +Allowed calls are catalogue/details/chat only, never pull/create/delete/push/ +cloud/search/tool execution. Do not stop or unload unrelated runtime/model work. + +Require explicit local-only operator acknowledgement before sending a goal or +source context. Native verification must record actual operator-configured cloud- +disabled runtime evidence, not a boolean checkbox claimed as cryptographic proof. +Do not modify the runtime configuration yourself without separate approval. + +Select an exact reported installed model, not freeform fallback/first model. +Eligibility requires usable name/digest, positive installed size, local model +details and completion capability. Reject remote_model/remote_host indicators, +cloud-tagged models and malformed/ambiguous eligibility data. Show rejected +models/reasons, not a misleading healthy empty catalogue. A failed refresh may +retain last-known display but never authorizes generation without fresh checks. +Recheck selected catalogue identity/digest/details before each explicit chat. +After completion, recheck that same local eligibility and catalogue digest before +validator publication. Changed/unavailable metadata rejects the result; a model +name in the chat response alone does not attest its digest or local execution. + +Use one non-streaming POST `/api/chat` per explicit Generate: +`stream:false`, structured JSON format for the accepted runbook shape, bounded +generation options such as temperature 0 and a finite output-token budget. +The format is a generation hint, not validation or a guarantee of determinism. +Supply the application-generated runbook/source template and require source/ +head/keys/units/axes unchanged. Do not grant tools or feed previous unbounded +chat history. Ignore reasoning fields as content; never interpret tool calls. + +Validate the completed response envelope: explicit requested model, assistant +message string content, actual finished state and non-truncated outcome. +Reject empty/refused/malformed/truncated or tool-call completion. +Handle additive API metadata compatibly, but reject duplicate/invalid critical +identity/completion/content/error fields. No silent defaults for those fields. + +Fixed bounds, not new user settings: goal <=2000 UTF-16 code units, complete +UTF-8 chat request <=131072 bytes, each catalogue/details/chat response <=1 MiB +(1,048,576 bytes), HTTP JSON depth <=64 and operation deadline <=180 seconds. +Read bodies bounded even without Content-Length; a one-byte-over/chunked response +cannot be buffered unboundedly before rejection. Distinguish timeout/cancel/ +HTTP/metadata/completion/validator failures; do not return fake success. +The decoded runbook must also meet all unchanged Step-11 limits. + +### B. Small applicable local knowledge and exact source snapshot + +Provide one local synthetic engine-authoring policy pack with explicit ID/revision +and exact model/definition applicability. Its authority is the accepted synthetic +template/owned contracts, not manufacturer or real-vehicle truth. +Retrieve by exact source model/version/definition/revision; no generic "nearest" +or role-based fallback. Missing/mismatched pack is a visible pre-chat failure. + +Context includes copied actual authoring workspace/head/applicability, canonical +whole values, scalar bounds, fixed rpm axis, torque-cell bounds/units, supported +operation and the pack's relevant synthetic restrictions. Keep the pack provenance +and included facts visible independently of anything the model claims. +Use a simple local provider/data definition, not embeddings/web retrieval/RAG/ +filesystem crawling or another schema/persistence subsystem. + +Capture the bounded explicit goal, selected model/digest and prior successful +preview ID at request start. Show source and selected context for deliberate user +review. Do not include arbitrary files, source code, raw diagnostic archives, +credentials, vehicle personal data or undocumented operating instructions. +Only bounded explicitly selected synthetic authoring data is supplied. + +System guidance restricts generation to synthetic warm-idle/fixed-axis torque +proposals, with no hardware programming, emissions/anti-theft/odometer/safety +bypass instructions, external tools or claims of approval/testing. Treat the +goal/pack/output as quoted untrusted data; model obedience is not the safeguard. +Existing deterministic schema/source/template validation is still mandatory. + +### C. One generation owner and unchanged validator publication + +Explicit Generate captures an immutable request/context; it never saves an +authoring revision or opens/approves/mutates a target. +At most one catalogue/generation operation is active in the page-owned feature. +Reject competing Generate/refresh/model-change actions visibly before starting +another request. Cancel/Close share a drainable cleanup as appropriate; no gate +is held across an await needed by cleanup. New page entry creates a fresh owner. + +After HTTP completion, enforce current owner/generation/cancellation/model/ +source/head and prior-preview identity before publication. A newer manual preview +must not be overwritten even if its authoring head is unchanged. +Make these checks atomic with accepted validator publication: minimally extend +the existing service with expected-preview/cancellation/current-request admission +if needed, reusing its strict parser/source/head/template/diff logic. +Do not merely precheck then call an unguarded publish that can race. +Preserve all existing manual Validate behavior and tests. + +Pass the original decoded `message.content` through the authoritative validator, +without stripping markdown fences, fixing syntax, injecting absent IDs, changing +unit/source/head, clipping values or replacing invalid output with a template. +No auto retry/correction loop. A retry is an explicit new request against fresh +current context. Valid JSON alone does not establish correct user intent; +show the original goal and exact candidate/diff for human review. + +Successful output is only an AI-generated read-only validated preview, still +unverified for intent/physical applicability/testing/approval. Retain model/digest/ +context/goal provenance separately from source facts; model rationale is safe +text, not evidence or policy. Existing staleness still applies after publication. +Keep only bounded latest generation evidence/prior success, not hidden history. + +Failures/cancellation/close/source or manual-preview replacement preserve prior +success and source state. Late callbacks cannot publish after owner close or a +new request. No fault becomes healthy "empty model result", Ready, Saved or +Applied. Manual/no-model workflows remain usable and errors are visible. + +### D. Real UI and real-model evidence + +Extend the existing runbook area with explicit local-only acknowledgement, +catalogue refresh, installed model selection/eligibility, bounded goal, source/ +knowledge preview, Generate/Cancel and separate model-output/error/provenance. +No network request on route entry/render/unit change. + +Show valid output through existing candidate/diff/current-Stale presentation. +Invalid output is labeled unvalidated/not an actionable preview, bounded and +escaped. Separate old successful preview from rejected/changed request data. +Global units only project human-readable values; requests/content/diffs stay +canonical and unchanged. No Save/Approve/Execute/Apply or tool control. +Page unmount cancels/drains its own request without touching shared Ollama. + +Native decisive goal on the actual warm baseline: +`Propose warm-idle target 1250 rpm and set torque at 2000 rpm to 350 N*m; keep every other value unchanged.` +Require a real local model response whose validated canonical candidate and +diff match that exact goal, not merely any parseable in-range result. +Report all attempts honestly. No request repair, canned native response or +hidden rule-based generator counts as local model success. + +## FILES OR PROJECTS EXPECTED TO CHANGE + +Focused Application inference/provider/context/generation and narrow guarded +preview publication, UI runbook generation/lifetime, Client HTTP DI only if +needed, tests and related README/docs. No new project/package/host or model +installation, existing template/authoring-save/rehearsal/physics/protocol change. +Only `prompts/Step-12-Report.md` under `prompts`. + +## INTERFACE AND DEPENDENCY REQUIREMENTS + +Keep nine projects/references, one Client, independent Components, immutable +source/runbook/authoring values and all template/schema/approval/CAS limits. +No public network/cloud/model pull, proxies/redirect fallback, source metadata +backfill, model tool execution, source code/credential upload or arbitrary raw +command. Generated knowledge cannot promote authority or bypass approval. +Do not fix the separate recording navigation issue or add Git/durable backups. +No SDK/workload/runtime/model/system install/update/repair/rollback, staging/ +commit/push or destructive Git; preserve existing work and protected history. + +## TESTING REQUIREMENTS + +Map C-01..C-10 to meaningful named tests before handoff: + +- Real provider over a controlled local HTTP peer/handler: catalogue/details/ + completion fields, model eligibility/digest, remote/cloud/redirect/proxy exclusion, + one actual chat request, structured options/context and error classification. + This proves HTTP integration, not that a real LLM generated the test response. +- Current-source/knowledge/no-match vectors and original validator negative + outputs, with exact previous-preview/source/head/history preservation. + Hold real workflow response/read publication to exercise cancel/source changes/ + newer manual preview/closed/new-owner races, with atomic rejection assertions. +- Fixed byte/depth/goal/deadline and missing/invalid/duplicate critical metadata/ + chunked response bounds; no broad catches or count-only claims. Release owned + helpers/barriers in finally; do not use sleep/polling as race proof. +- Actual rendered selection/opt-in/generation/cancel/error/stale/units controls, + no generation on render, and real diagnostics/recording/replay/approved- + rehearsal coexistence with counted zero unassigned business-source calls. +- Keep all 547 baseline cases (179 unit, 368 integration), including manual + validator/authoring/source/physical gates. Compare canonical request/output/ + source/config/archives and prove no mutation/execution. + +Run focused cases, then sequentially: + +- `dotnet build .\src\AutoForge.slnx --configuration Release --no-restore` +- `dotnet test .\src\AutoForge.slnx --configuration Release --no-build` + +Build all nine projects/native Client. Install/restore code dependencies only +after a genuine chosen-command missing dependency; this does not authorize +model/runtime installation or pulling. Recheck actual installed API behavior. + +Required native/real-model smoke: operator-approved local-only runtime already +running, verified cloud-disabled status and installed eligible model/digest; +explicit actual source/context, decisive goal above, original real response, +same-validator exact diff, no source/approval/target/dynamics-configuration/ +recording changes, +manual invalid/source-stale handling, cancel/unmount and old routes/units. +Record runtime/model/version/license/resource context honestly, without secrets +or thinking traces. Controlled faults are not native platform observations. +Absent runtime/model/local-only evidence or failure to produce the assigned +valid native response is BLOCKED/INCOMPLETE, not a waiver or stub-success. +Stop only task-owned test HTTP/native helpers; do not terminate a shared model +runtime or reset user data/preferences. No installation/download is automatic. + +## DOCUMENTATION REQUIREMENTS + +Update README/index/architecture/build guide and local-generation/runbook usage: +explicit local-only opt-in/eligible model, operator prerequisites, verified public +API contracts, cloud delegation caveat, matched synthetic pack/source/context, +strict unchanged-validator output, current-owner/manual-preview CAS/cancel/drain, +real-model versus stub evidence and no write/tool/physical authority. +Step-11 is accepted; Step-12 remains pending manual review. Broader diagnostics/ +scenario research/executors, vector knowledge and demonstration are future. + +## ACCEPTANCE CRITERIA + +| ID | Criterion | Evidence | +|---|---|---| +| AC-01 | C-01..C-03 explicit local-only transport/model eligibility and exact applicable context | Real HTTP boundary/metadata/remote-negative tests and operator/runtime local-only prerequisite evidence | +| AC-02 | C-04/C-05/C-09 original model content uses authoritative validation without repair/authority/side effects | Exact controlled outputs, unchanged negative-parser/source tests and actual real-model decisive goal | +| AC-03 | C-06..C-08 one owner, atomic source/model/manual-preview publication and bounded error/cancel/close handling | Controlled interleavings/limits/HTTP failures and rendered command/lifetime assertions | +| AC-04 | C-10 all 547 regressions/new coverage, real-model/native workflow and full nine-project Release build pass | Exact worker commands/exits/warnings/counts, zero business-source mutation and native/stub distinction | +| AC-05 | Matrix/self-review/docs/history/protection/manual gate accurately describe limits/prerequisites | Own post-green producer/consumer review, named evidence and `prompts/Step-12-Report.md` | + +## OUT-OF-SCOPE WORK + +Cloud/public inference, model/runtime installation/pull/update/agent hosting, +tool/runbook execution, proposal Save/approval/programming, broad diagnostic/ +scenario planning, embeddings/vector/RAG/web research, persistent chat/model/ +runbook/Git backup storage, new templates/unit families/project/package/host, +hardware/physics changes and unrelated cleanup. +No future assignment, agents, automatic handoff, orchestration/shared-gate edit, +staging, commit or push. + +## REPORTING REQUIREMENTS + +Save `prompts/Step-12-Report.md` wholly inside exactly one plain triple-backtick +fence, no language tag/outside text/nested fences. Include identifier/title/status, +functions/files/interfaces, C-01..C-10/AC-01..AC-05 mapping with named executed +evidence, exact local-only/model/digest/context/response/validator/publish/cancel/ +negative/limit/no-side-effect outcomes, commands/exits/warnings/per-project +counts, actual real-model/native versus stub/control evidence and prerequisites, +docs/README, own post-green source-path self-review, limitations/deviations/ +blockers and preservation. COMPLETE requires all assigned checks; otherwise +report INCOMPLETE/BLOCKED with the precise unmet criterion. +Save and STOP; do not begin Step-13. diff --git a/src/AutoForge.Application/Features/Vehicles/Runbooks/RunbookPreviewService.cs b/src/AutoForge.Application/Features/Vehicles/Runbooks/RunbookPreviewService.cs new file mode 100644 index 0000000..110fb1c --- /dev/null +++ b/src/AutoForge.Application/Features/Vehicles/Runbooks/RunbookPreviewService.cs @@ -0,0 +1,294 @@ +using System.Text; +using System.Text.Json; +using AutoForge.Application.Features.Vehicles.Calibration; +using AutoForge.Core.Calibration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace AutoForge.Application.Features.Vehicles.Runbooks; + +public enum RunbookPreviewFailure +{ + InvalidJson, LimitExceeded, UnsupportedSchema, SchemaViolation, + OperationNotAllowed, SourceUnavailable, StaleSource, InvalidValues +} +public sealed class RunbookPreviewException( + RunbookPreviewFailure failure, string path, string message, Exception? inner = null) + : Exception($"{path}: {message}", inner) +{ + public RunbookPreviewFailure Failure { get; } = failure; + public string Path { get; } = path; +} +public enum RunbookChangeKind { NoChanges, ChangesProposed } +public enum RunbookPreviewFreshness { None, Current, Stale } +public sealed record RunbookSourceToken( + string WorkspaceIdentifier, string ExpectedHeadIdentifier, CalibrationApplicability Applicability); + +public sealed class RunbookPreview +{ + internal RunbookPreview(string runbookIdentifier, string stepIdentifier, string rationale, RunbookSourceToken source, + CalibrationVersion head, CalibrationValues candidate, IReadOnlyList diff) + { + Identifier = Guid.NewGuid().ToString("N"); + RunbookIdentifier = runbookIdentifier; + StepIdentifier = stepIdentifier; + Rationale = rationale; + Source = source with { Applicability = source.Applicability with { } }; + HeadRevision = head.Revision; + HeadKind = head.Kind; + Before = new(head.Values.Scalars, head.Values.Tables); + Candidate = new(candidate.Scalars, candidate.Tables); + Diff = Array.AsReadOnly(diff.ToArray()); + Kind = Diff.Count == 0 ? RunbookChangeKind.NoChanges : RunbookChangeKind.ChangesProposed; + } + public string Identifier { get; } + public string RunbookIdentifier { get; } + public string StepIdentifier { get; } + public string Rationale { get; } + public RunbookSourceToken Source { get; } + public int HeadRevision { get; } + public CalibrationVersionKind HeadKind { get; } + public CalibrationValues Before { get; } + public CalibrationValues Candidate { get; } + public IReadOnlyList Diff { get; } + public RunbookChangeKind Kind { get; } +} +public sealed record RunbookPreviewSnapshot(RunbookPreview? Preview, RunbookPreviewFreshness Freshness); + +public sealed class RunbookPreviewService(CalibrationAuthoringService authoring) +{ + public const int MaximumInputBytes = 131072; + public const int MaximumRationaleLength = 2000; + public const int MaximumStepIdentifierLength = 128; + public const int MaximumDepth = 32; + private static readonly UTF8Encoding InputEncoding = new(false, true); + private readonly object _gate = new(); + private RunbookPreview? _preview; + public event Action? Changed; + + public RunbookPreviewSnapshot Snapshot + { + get + { + RunbookPreview? preview; + lock (_gate) preview = _preview; + var current = authoring.Snapshot; + var freshness = preview is null ? RunbookPreviewFreshness.None : + MatchesSource(current, preview.Source) && current!.Head.Values.ContentEquals(preview.Before) + ? RunbookPreviewFreshness.Current : RunbookPreviewFreshness.Stale; + return new(preview, freshness); + } + } + + public RunbookPreview Validate(string json) + { + var input = Parse(json); + var workspace = authoring.Snapshot ?? + throw Error(RunbookPreviewFailure.SourceUnavailable, "$.steps[0].source", "Explicitly create an authoring workspace before previewing a runbook."); + if (!MatchesSource(workspace, input.Source)) + throw Error(RunbookPreviewFailure.StaleSource, "$.steps[0].source", "Every source/head/applicability field must match the actual current authoring snapshot; no latest-head fallback is allowed."); + try { workspace.Definition.Validate(input.Values); } + catch (CalibrationAuthoringException exception) + { + throw Error(RunbookPreviewFailure.InvalidValues, "$.steps[0].values", exception.Message, exception); + } + var preview = new RunbookPreview(input.RunbookIdentifier, input.StepIdentifier, input.Rationale, input.Source, + workspace.Head, input.Values, CalibrationValueDifferences.Compare(workspace.Head.Values, input.Values)); + try + { + authoring.AtCurrentHead(input.Source.WorkspaceIdentifier, input.Source.ExpectedHeadIdentifier, () => + { + lock (_gate) _preview = preview; + return preview; + }); + } + catch (CalibrationAuthoringException exception) + { + throw Error(RunbookPreviewFailure.StaleSource, "$.steps[0].source", $"Source/head changed before preview publication: {exception.Message}", exception); + } + Changed?.Invoke(); + return preview; + } + + public string CreateInputTemplate() + { + var workspace = authoring.Snapshot ?? + throw Error(RunbookPreviewFailure.SourceUnavailable, "$.steps[0].source", "No current authoring source exists; create it explicitly on the calibration route."); + var source = workspace.Definition.Applicability; + return JsonSerializer.Serialize(new + { + schemaVersion = 1, runbookIdentifier = Guid.NewGuid().ToString("N"), targetKind = "simulation", rationale = "", + steps = new[] + { + new + { + stepIdentifier = "calibration-preview", operation = "proposeCalibration", + source = new + { + workspaceIdentifier = workspace.Identifier, expectedHeadIdentifier = workspace.Head.Identifier, + profileIdentifier = source.ProfileIdentifier, profileRevision = source.ProfileRevision, + configurationIdentifier = source.ConfigurationIdentifier, moduleIdentifier = source.ModuleIdentifier, + modelIdentifier = source.ModelIdentifier, modelVersion = source.ModelVersion, + definitionIdentifier = source.DefinitionIdentifier, definitionRevision = source.DefinitionRevision + }, + values = new + { + scalars = workspace.Head.Values.Scalars.Select(value => new { logicalIdentifier = value.LogicalIdentifier, unit = value.Unit, value = value.Value }), + tables = workspace.Head.Values.Tables.Select(value => new { logicalIdentifier = value.LogicalIdentifier, unit = value.Unit, axisUnit = value.AxisUnit, axis = value.Axis, cells = value.Cells }) + } + } + } + }, new JsonSerializerOptions { WriteIndented = true }); + } + + private static bool MatchesSource(CalibrationWorkspace? workspace, RunbookSourceToken source) => + workspace is not null && workspace.Identifier == source.WorkspaceIdentifier && + workspace.Head.Identifier == source.ExpectedHeadIdentifier && workspace.Definition.Applicability.Matches(source.Applicability); + + private static ParsedRunbook Parse(string json) + { + if (json is null) throw Error(RunbookPreviewFailure.InvalidJson, "$", "Runbook JSON input is required."); + try + { + if (InputEncoding.GetByteCount(json) > MaximumInputBytes) + throw Error(RunbookPreviewFailure.LimitExceeded, "$", "Original input exceeds 131072 UTF-8 bytes."); + using var document = JsonDocument.Parse(json, new JsonDocumentOptions + { + AllowTrailingCommas = false, CommentHandling = JsonCommentHandling.Disallow, MaxDepth = MaximumDepth + }); + var root = ReadObject(document.RootElement, "$", "schemaVersion", "runbookIdentifier", "targetKind", "rationale", "steps"); + var version = ReadInteger(root, "schemaVersion", "$"); + if (version != 1) throw Error(RunbookPreviewFailure.UnsupportedSchema, "$.schemaVersion", "Only runbook schema version 1 is supported."); + var identifier = ReadString(root, "runbookIdentifier", "$"); + if (identifier.Length != 32 || !Guid.TryParseExact(identifier, "N", out var id) || id.ToString("N") != identifier) + throw Error(RunbookPreviewFailure.SchemaViolation, "$.runbookIdentifier", "Runbook identifier must be a lowercase GUID in N format."); + if (ReadString(root, "targetKind", "$") != "simulation") + throw Error(RunbookPreviewFailure.OperationNotAllowed, "$.targetKind", "Only the exact simulation preview token is allowed; no target permission is granted."); + var rationale = ReadString(root, "rationale", "$"); + if (rationale.Length > MaximumRationaleLength) + throw Error(RunbookPreviewFailure.LimitExceeded, "$.rationale", "Rationale exceeds 2000 UTF-16 code units."); + var steps = ReadArray(root, "steps", "$"); + if (steps.GetArrayLength() != 1) + throw Error(RunbookPreviewFailure.OperationNotAllowed, "$.steps", "Exactly one proposeCalibration preview step is supported."); + var step = ReadObject(steps[0], "$.steps[0]", "stepIdentifier", "operation", "source", "values"); + var stepIdentifier = ReadIdentifier(step, "stepIdentifier", "$.steps[0]"); + if (stepIdentifier.Length > MaximumStepIdentifierLength) + throw Error(RunbookPreviewFailure.LimitExceeded, "$.steps[0].stepIdentifier", "Step identifier exceeds 128 UTF-16 code units."); + if (ReadString(step, "operation", "$.steps[0]") != "proposeCalibration") + throw Error(RunbookPreviewFailure.OperationNotAllowed, "$.steps[0].operation", "Only proposeCalibration is allowlisted, and it previews without execution."); + const string sourcePath = "$.steps[0].source"; + var source = ReadObject(step.GetProperty("source"), sourcePath, "workspaceIdentifier", "expectedHeadIdentifier", + "profileIdentifier", "profileRevision", "configurationIdentifier", "moduleIdentifier", + "modelIdentifier", "modelVersion", "definitionIdentifier", "definitionRevision"); + var token = new RunbookSourceToken(ReadIdentifier(source, "workspaceIdentifier", sourcePath), + ReadIdentifier(source, "expectedHeadIdentifier", sourcePath), + new(ReadIdentifier(source, "profileIdentifier", sourcePath), ReadPositiveInteger(source, "profileRevision", sourcePath), + ReadIdentifier(source, "configurationIdentifier", sourcePath), ReadIdentifier(source, "moduleIdentifier", sourcePath), + ReadIdentifier(source, "modelIdentifier", sourcePath), ReadPositiveInteger(source, "modelVersion", sourcePath), + ReadIdentifier(source, "definitionIdentifier", sourcePath), ReadPositiveInteger(source, "definitionRevision", sourcePath))); + var values = ReadValues(step.GetProperty("values"), "$.steps[0].values"); + return new(identifier, stepIdentifier, rationale, token, values); + } + catch (EncoderFallbackException exception) + { + throw Error(RunbookPreviewFailure.InvalidJson, "$", "Input cannot be encoded as valid UTF-8.", exception); + } + catch (JsonException exception) + { + throw Error(RunbookPreviewFailure.InvalidJson, exception.Path ?? "$", $"Input is not strict JSON within depth 32: {exception.Message}", exception); + } + catch (InvalidOperationException exception) + { + throw Error(RunbookPreviewFailure.InvalidJson, "$", $"Input contains an invalid JSON string/value: {exception.Message}", exception); + } + } + + private static CalibrationValues ReadValues(JsonElement element, string path) + { + var values = ReadObject(element, path, "scalars", "tables"); + var scalars = ReadArray(values, "scalars", path).EnumerateArray().Select((item, index) => + { + var itemPath = $"{path}.scalars[{index}]"; + var scalar = ReadObject(item, itemPath, "logicalIdentifier", "unit", "value"); + return new CalibrationScalarValue(ReadString(scalar, "logicalIdentifier", itemPath), + ReadString(scalar, "unit", itemPath), ReadNumber(scalar.GetProperty("value"), $"{itemPath}.value")); + }).ToArray(); + var tables = ReadArray(values, "tables", path).EnumerateArray().Select((item, index) => + { + var itemPath = $"{path}.tables[{index}]"; + var table = ReadObject(item, itemPath, "logicalIdentifier", "unit", "axisUnit", "axis", "cells"); + return new CalibrationTableValue(ReadString(table, "logicalIdentifier", itemPath), ReadString(table, "unit", itemPath), + ReadString(table, "axisUnit", itemPath), + ReadArray(table, "axis", itemPath).EnumerateArray().Select((number, i) => ReadNumber(number, $"{itemPath}.axis[{i}]")), + ReadArray(table, "cells", itemPath).EnumerateArray().Select((number, i) => ReadNumber(number, $"{itemPath}.cells[{i}]"))); + }).ToArray(); + return new(scalars, tables); + } + private static JsonElement ReadObject(JsonElement element, string path, params string[] properties) + { + if (element.ValueKind != JsonValueKind.Object) + throw Error(RunbookPreviewFailure.SchemaViolation, path, "Expected a schema object."); + var seen = new HashSet(StringComparer.Ordinal); + foreach (var property in element.EnumerateObject()) + { + if (!seen.Add(property.Name)) throw Error(RunbookPreviewFailure.SchemaViolation, $"{path}.{property.Name}", "Duplicate property."); + if (!properties.Contains(property.Name, StringComparer.Ordinal)) + throw Error(RunbookPreviewFailure.SchemaViolation, $"{path}.{property.Name}", "Unknown property is not allowlisted."); + } + foreach (var property in properties) + if (!seen.Contains(property)) throw Error(RunbookPreviewFailure.SchemaViolation, $"{path}.{property}", "Required property is missing."); + return element; + } + private static JsonElement ReadArray(JsonElement element, string property, string path) + { + var array = element.GetProperty(property); + if (array.ValueKind != JsonValueKind.Array) throw Error(RunbookPreviewFailure.SchemaViolation, $"{path}.{property}", "Expected an array."); + return array; + } + private static string ReadString(JsonElement element, string property, string path) + { + var value = element.GetProperty(property); + if (value.ValueKind != JsonValueKind.String) throw Error(RunbookPreviewFailure.SchemaViolation, $"{path}.{property}", "Expected a string."); + return value.GetString()!; + } + private static string ReadIdentifier(JsonElement element, string property, string path) + { + var value = ReadString(element, property, path); + if (string.IsNullOrWhiteSpace(value) || value != value.Trim()) + throw Error(RunbookPreviewFailure.SchemaViolation, $"{path}.{property}", "Identifier must be explicit, nonblank and trimmed."); + return value; + } + private static int ReadInteger(JsonElement element, string property, string path) + { + var value = element.GetProperty(property); + if (value.ValueKind != JsonValueKind.Number || !value.TryGetInt32(out var integer)) + throw Error(RunbookPreviewFailure.SchemaViolation, $"{path}.{property}", "Expected an Int32 JSON integer, not fractional/string syntax."); + return integer; + } + private static int ReadPositiveInteger(JsonElement element, string property, string path) + { + var value = ReadInteger(element, property, path); + if (value <= 0) throw Error(RunbookPreviewFailure.SchemaViolation, $"{path}.{property}", "Revision/version must be a positive JSON integer."); + return value; + } + private static double ReadNumber(JsonElement value, string path) + { + if (value.ValueKind != JsonValueKind.Number) + throw Error(RunbookPreviewFailure.SchemaViolation, path, "Expected a JSON number."); + if (!value.TryGetDouble(out var number) || !double.IsFinite(number)) + throw Error(RunbookPreviewFailure.InvalidValues, path, "Canonical number must be finite."); + return number; + } + private static RunbookPreviewException Error(RunbookPreviewFailure failure, string path, string message, Exception? inner = null) => + new(failure, path, message, inner); + private sealed record ParsedRunbook(string RunbookIdentifier, string StepIdentifier, string Rationale, RunbookSourceToken Source, CalibrationValues Values); +} + +public static class RunbookPreviewServiceCollectionExtensions +{ + public static IServiceCollection AddAutoForgeRunbookPreview(this IServiceCollection services) + { + services.TryAddSingleton(); + return services; + } +} diff --git a/src/AutoForge.UI/Features/Foundation/AddAutoForgeUi.cs b/src/AutoForge.UI/Features/Foundation/AddAutoForgeUi.cs index 94c29de..828268b 100644 --- a/src/AutoForge.UI/Features/Foundation/AddAutoForgeUi.cs +++ b/src/AutoForge.UI/Features/Foundation/AddAutoForgeUi.cs @@ -8,6 +8,7 @@ using AutoForge.Application.Features.Vehicles.Telemetry.Recording; using AutoForge.Application.Features.Vehicles.Telemetry.Replay; using AutoForge.Application.Features.DisplayUnits; using AutoForge.Application.Features.Vehicles.Calibration; +using AutoForge.Application.Features.Vehicles.Runbooks; using Microsoft.Extensions.DependencyInjection; namespace AutoForge.UI; @@ -25,6 +26,7 @@ public static class ServiceCollectionExtensions services.AddAutoForgeTelemetryReplay(); services.AddAutoForgeCalibrationAuthoring(); services.AddAutoForgeCalibrationRehearsal(); + services.AddAutoForgeRunbookPreview(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/AutoForge.UI/Features/Foundation/Home.razor b/src/AutoForge.UI/Features/Foundation/Home.razor index d64175a..1106542 100644 --- a/src/AutoForge.UI/Features/Foundation/Home.razor +++ b/src/AutoForge.UI/Features/Foundation/Home.razor @@ -17,4 +17,5 @@ Open vehicle simulation Replay saved telemetry offline (recorded, not live) Author synthetic calibration proposals (not applied) + Validate manual runbook JSON (preview only)

diff --git a/src/AutoForge.UI/Features/Vehicles/Runbooks/RunbookPage.razor b/src/AutoForge.UI/Features/Vehicles/Runbooks/RunbookPage.razor new file mode 100644 index 0000000..44e5bb2 --- /dev/null +++ b/src/AutoForge.UI/Features/Vehicles/Runbooks/RunbookPage.razor @@ -0,0 +1,179 @@ +@page "/runbooks" +@using AutoForge.Application.Features.Vehicles.Calibration +@using AutoForge.Application.Features.Vehicles.Runbooks +@implements IDisposable +@inject RunbookPreviewService PreviewService +@inject CalibrationAuthoringService Authoring + +Deterministic runbook preview +

Deterministic simulation runbook preview

+

+ Manual structured JSON, read-only preview only. No model/inference, retrieval, save-to-authoring, + target operation, execution or approval occurs. Validation grants no programming or physical authority. +

+

Create/select an actual authoring source explicitly. This route does not create one.

+@if (Authoring.Snapshot is { } current) +{ +

+ Actual current workspace @current.Identifier; head revision @current.Head.Revision / @current.Head.Identifier; + source @current.Definition.Applicability.ConfigurationIdentifier. +

+} +else +{ +

No authoring source is available. Source/head fields cannot fall back to a catalogue or live session.

+} +
+ + + +

One simulation / proposeCalibration step only. Rationale is informational text, never permission or code.

+ + @if (_error is { } error) + { + + } + @if (_status is not null) + { +

@_status

+ } +
+ +@{ + var snapshot = PreviewService.Snapshot; +} +@if (snapshot.Preview is { } preview) +{ +
+

Last successful preview (not a saved proposal)

+

+ Captured indication @preview.Kind; source freshness @snapshot.Freshness. + ChangesProposed is not an authoring revision, tested result, approval or command. +

+ @if (snapshot.Freshness == RunbookPreviewFreshness.Stale) + { + + } + @if (_error is not null) + { +

Previous successful preview retained; the current input action was rejected and did not replace this result.

+ } + else if (!ReferenceEquals(_acceptedPreview, preview) || _acceptedInput != _input) + { +

Current draft is not this accepted input. The displayed result is a previous successful preview, not validation of the edited draft.

+ } +

+ Preview @preview.Identifier; runbook @preview.RunbookIdentifier; step @preview.StepIdentifier; + captured workspace @preview.Source.WorkspaceIdentifier; + head @preview.Source.ExpectedHeadIdentifier / revision @preview.HeadRevision / @preview.HeadKind. +

+

+ Profile @preview.Source.Applicability.ProfileIdentifier revision @preview.Source.Applicability.ProfileRevision; + configuration @preview.Source.Applicability.ConfigurationIdentifier; + module @preview.Source.Applicability.ModuleIdentifier; + model @preview.Source.Applicability.ModelIdentifier v@(preview.Source.Applicability.ModelVersion); + definition @preview.Source.Applicability.DefinitionIdentifier revision @preview.Source.Applicability.DefinitionRevision. + Captured synthetic authoring metadata only, not current vehicle evidence. +

+

Informational rationale

+

@preview.Rationale

+

Exact canonical current-head-to-candidate diff

+ @if (preview.Diff.Count == 0) + { +

NoChanges: exact captured head content, empty diff. Nothing was saved or executed.

+ } + else + { +
    + @foreach (var entry in preview.Diff) + { +
  • + @entry.LogicalIdentifier: + @(entry.AxisCoordinate is { } axis ? $"axis {Exact(axis)} {entry.AxisUnit};" : "") + @Exact(entry.Before) -> @Exact(entry.After) @entry.Unit; signed delta @Signed(entry.Delta) @entry.Unit. +
  • + } +
+ } +

Complete canonical candidate and optional read-only display

+ @foreach (var scalar in preview.Candidate.Scalars) + { +

@scalar.LogicalIdentifier: @Exact(scalar.Value) @scalar.Unit (canonical source).

+ } + @foreach (var table in preview.Candidate.Tables) + { + + + + + @for (var index = 0; index < table.Cells.Count; index++) + { + var display = DisplayUnitConverter.Project(table.Cells[index], table.Unit, DisplaySelection); + + + + + + } + +
@table.LogicalIdentifier - immutable source axis/cells; display units do not change JSON or diff
Fixed canonical axisCanonical cellDisplay only
@Exact(table.Axis[index]) @table.AxisUnit@Exact(table.Cells[index]) @table.Unit + @DisplayUnitConverter.Format(display, 3) @display.Unit + @if (display.Error is { } displayError) { @displayError } +
+ } +
+} +else +{ +

No successful preview. Entry, template creation, render and unit changes do not validate input.

+} + +@code { + [CascadingParameter] public DisplayUnitSelection DisplaySelection { get; set; } = DisplayUnitSelection.Default; + private string _input = string.Empty; + private string? _acceptedInput; + private RunbookPreview? _acceptedPreview; + private RunbookPreviewException? _error; + private string? _status; + private bool _disposed; + + protected override void OnInitialized() + { + Authoring.Changed += OnChanged; + PreviewService.Changed += OnChanged; + } + private void CreateTemplate() + { + try + { + _input = PreviewService.CreateInputTemplate(); + _error = null; + _status = "Input draft copied from the captured current source. It has not been validated, saved or executed."; + } + catch (RunbookPreviewException exception) { _error = exception; _status = null; } + } + private void Validate() + { + try + { + _acceptedPreview = PreviewService.Validate(_input); + _acceptedInput = _input; + _error = null; + _status = "Read-only validation completed. No authoring version, approval, target operation or execution was created."; + } + catch (RunbookPreviewException exception) { _error = exception; _status = null; } + } + private void OnChanged() + { + if (_disposed) return; + _ = InvokeAsync(() => { if (!_disposed) StateHasChanged(); }); + } + private static string Exact(double value) => value.ToString("R", CultureInfo.InvariantCulture); + private static string Signed(double value) => value > 0 ? $"+{Exact(value)}" : Exact(value); + public void Dispose() + { + _disposed = true; + Authoring.Changed -= OnChanged; + PreviewService.Changed -= OnChanged; + } +} diff --git a/src/AutoForge.UI/Layout/MainLayout.razor b/src/AutoForge.UI/Layout/MainLayout.razor index e8428de..a235d4d 100644 --- a/src/AutoForge.UI/Layout/MainLayout.razor +++ b/src/AutoForge.UI/Layout/MainLayout.razor @@ -13,6 +13,7 @@ Vehicle simulation Recorded telemetry replay Synthetic calibration authoring + Read-only runbook preview
diff --git a/src/tests/AutoForge.IntegrationTests/RunbookPreviewIsolationTests.cs b/src/tests/AutoForge.IntegrationTests/RunbookPreviewIsolationTests.cs new file mode 100644 index 0000000..d4e8afc --- /dev/null +++ b/src/tests/AutoForge.IntegrationTests/RunbookPreviewIsolationTests.cs @@ -0,0 +1,124 @@ +using AutoForge.Application.Features.DisplayUnits; +using AutoForge.Application.Features.Vehicles.Calibration; +using AutoForge.Application.Features.Vehicles.Diagnostics; +using AutoForge.Application.Features.Vehicles.Profiles; +using AutoForge.Application.Features.Vehicles.Runbooks; +using AutoForge.Application.Features.Vehicles.Simulation; +using AutoForge.Application.Features.Vehicles.Telemetry.Recording; +using AutoForge.Application.Features.Vehicles.Telemetry.Replay; +using AutoForge.Core.Calibration; +using AutoForge.Core.ExecutionTargets; +using AutoForge.Core.Simulation; +using AutoForge.Diagnostics; +using AutoForge.Simulation; +using AutoForge.UI; +using Microsoft.Extensions.DependencyInjection; + +namespace AutoForge.IntegrationTests; + +public sealed partial class CalibrationAuthoringTests +{ + [Fact] + public async Task RunbookIsolation_ActualLiveRecordingReplayAndApprovedRehearsalRemainUntouched() + { + var directory = Path.Combine(Path.GetTempPath(), $"autoforge-step11-{Guid.NewGuid():N}"); + Directory.CreateDirectory(directory); + try + { + var counts = new SideEffectCounts(); + var targetCounts = new RunbookTargetCounts(); + var services = new ServiceCollection(); + services.AddLogging(); + services.AddAutoForgeVehicleProfiles(); + services.AddAutoForgeDiagnostics([new CountingCalibrationDynamicsFactory( + new DynamicsDiagnosticTransportFactory(SyntheticDiagnosticExamples.CreateDefinitions()), counts)]); + services.AddAutoForgeUi(); + services.AddSingleton(new CountingCalibrationStore(new FileTelemetryArchiveStore(directory), counts)); + services.AddSingleton(new RunbookCountingTargetFactory(targetCounts)); + services.AddSingleton(); + using var provider = services.BuildServiceProvider(); + var warm = CreateWarm(provider); + var config = provider.GetRequiredService(); + var exported = config.Export(warm.ConfigurationIdentifier); + await using var live = await provider.GetRequiredService().OpenDynamicsAsync( + ProfileId, 1, DynamicsDiagnosticTransportFactory.ProviderIdentifier, ExecutionTargetKind.Simulation, warm); + await live.DynamicsControl!.StepAsync(7); + var recording = provider.GetRequiredService(); + recording.Start(live); + Assert.True((await live.ReadSignalsAsync(live.ExpectedEndpoints.Single(endpoint => endpoint.ModuleIdentifier == EngineId))).IsSuccess); + recording.Stop(); + Assert.True(await recording.SaveAsync(false)); + var capture = recording.CurrentCapture!; + var path = Path.Combine(directory, capture.Header.CaptureId + ".json"); + var bytes = await File.ReadAllBytesAsync(path); + await using var replay = provider.GetRequiredService().Create(); + await replay.LoadAsync(capture.Header.CaptureId); + replay.SeekOrdinal(1); + var authoring = provider.GetRequiredService(); + var baseline = authoring.CreateBaseline(warm.ConfigurationIdentifier); + var head = authoring.Save(Request(baseline, Values(baseline, scalar: 1250))); + await using var rehearsal = provider.GetRequiredService().Create(); + await rehearsal.OpenAsync(rehearsal.NewOperationId(), "autoforge.simulation.calibration-rehearsal", + ExecutionTargetKind.Simulation, baseline.Identifier); + await rehearsal.PrepareBackupAsync(rehearsal.NewOperationId()); + var preparation = await rehearsal.PrepareApplyAsync(rehearsal.NewOperationId(), baseline.Identifier, head.Identifier); + rehearsal.Approve(preparation.Identifier, true); + + var sourceBefore = authoring.Snapshot; + var rehearsalBefore = rehearsal.Snapshot; + var replayBefore = replay.Snapshot; + var liveBefore = live.DynamicsControl.Status; + var traceBefore = live.Trace.Entries.ToArray(); + var countBefore = (counts.Transport, counts.Model, counts.Save, targetCounts.Open, targetCounts.Read, targetCounts.Write); + var authoringChanges = 0; + authoring.Changed += () => authoringChanges++; + var service = provider.GetRequiredService(); + var template = service.CreateInputTemplate(); + var input = System.Text.Json.Nodes.JsonNode.Parse(template)!.AsObject(); + RunbookPreviewTests.Step(input)["values"]!["scalars"]![0]!["value"] = 1300; + RunbookPreviewTests.Step(input)["values"]!["tables"]![0]!["cells"]![2] = 350; + var preview = service.Validate(input.ToJsonString()); + Assert.Equal(2, preview.Diff.Count); + Assert.Throws(() => service.Validate("{broken")); + var units = provider.GetRequiredService(); + Assert.True(units.TrySet(new(DisplayUnitSystem.Metric, SpeedDisplayMode.Road))); + Assert.True(units.TrySet(DisplayUnitSelection.Default)); + Assert.Same(preview, service.Snapshot.Preview); + Assert.Equal(countBefore, (counts.Transport, counts.Model, counts.Save, targetCounts.Open, targetCounts.Read, targetCounts.Write)); + Assert.Equal(0, authoringChanges); + Assert.Same(sourceBefore, authoring.Snapshot); + Assert.Same(rehearsalBefore, rehearsal.Snapshot); + Assert.False(rehearsal.Snapshot.Approval!.Consumed); + Assert.Empty(rehearsal.Snapshot.Audit); + Assert.Same(replayBefore, replay.Snapshot); + Assert.Equal(liveBefore, live.DynamicsControl.Status); + Assert.Equal(traceBefore, live.Trace.Entries); + Assert.Equal(exported, config.Export(warm.ConfigurationIdentifier)); + Assert.Equal(bytes, await File.ReadAllBytesAsync(path)); + } + finally { Directory.Delete(directory, recursive: true); } + } + + private sealed class RunbookTargetCounts + { + public int Open { get; set; } + public int Read { get; set; } + public int Write { get; set; } + } + private sealed class RunbookCountingTargetFactory(RunbookTargetCounts counts) : ISimulatedCalibrationTargetFactory + { + private readonly SimulatedCalibrationTargetFactory _inner = new(); + public ExecutionTargetDescriptor Descriptor => _inner.Descriptor; + public ISimulatedCalibrationTarget Open(DynamicsConfiguration configuration, SyntheticEngineCalibration definition) + { counts.Open++; return new CountedTarget(_inner.Open(configuration, definition), counts); } + private sealed class CountedTarget(ISimulatedCalibrationTarget target, RunbookTargetCounts counts) : ISimulatedCalibrationTarget + { + public CalibrationTargetIdentity Identity => target.Identity; + public Task ReadAsync(CancellationToken cancellationToken = default) + { counts.Read++; return target.ReadAsync(cancellationToken); } + public Task CommitAsync(CalibrationTargetCommit request, CancellationToken cancellationToken = default) + { counts.Write++; return target.CommitAsync(request, cancellationToken); } + public ValueTask DisposeAsync() => target.DisposeAsync(); + } + } +} diff --git a/src/tests/AutoForge.IntegrationTests/RunbookPreviewTests.cs b/src/tests/AutoForge.IntegrationTests/RunbookPreviewTests.cs new file mode 100644 index 0000000..df1d4ef --- /dev/null +++ b/src/tests/AutoForge.IntegrationTests/RunbookPreviewTests.cs @@ -0,0 +1,530 @@ +using System.Text; +using System.Text.Encodings.Web; +using System.Text.Json; +using System.Text.Json.Nodes; +using AutoForge.Application.Features.Vehicles.Calibration; +using AutoForge.Application.Features.Vehicles.Profiles; +using AutoForge.Application.Features.Vehicles.Runbooks; +using AutoForge.Application.Features.Vehicles.Simulation; +using AutoForge.Core.Calibration; +using AutoForge.UI; +using Microsoft.Extensions.DependencyInjection; + +namespace AutoForge.IntegrationTests; + +public sealed class RunbookPreviewTests +{ + [Fact] + public void MissingActualWorkspace_RejectsStructuredInputWithoutCreatingSourceOrPreview() + { + using var donor = new Fixture(); + donor.CreateSource(); + using var empty = new Fixture(); + var input = Input(donor.Authoring.Snapshot!).ToJsonString(); + AssertRejected(empty, input, RunbookPreviewFailure.SourceUnavailable); + Assert.Null(empty.Authoring.Snapshot); + Assert.Null(empty.Service.Snapshot.Preview); + Assert.Equal(RunbookPreviewFreshness.None, empty.Service.Snapshot.Freshness); + } + + [Fact] + public void ExplicitSourceAndNoChanges_PreviewCopiesWholeHeadWithoutImplicitWorkspaceOrSave() + { + using var fixture = new Fixture(); + Assert.Null(fixture.Service.Snapshot.Preview); + var missing = Assert.Throws(() => fixture.Service.CreateInputTemplate()); + Assert.Equal(RunbookPreviewFailure.SourceUnavailable, missing.Failure); + Assert.Null(fixture.Authoring.Snapshot); + fixture.CreateSource(); + var before = fixture.Authoring.Snapshot!; + var input = Input(before); + var preview = fixture.Service.Validate(input.ToJsonString()); + Assert.Equal("0123456789abcdef0123456789abcdef", preview.RunbookIdentifier); + Assert.Equal("calibration-preview", preview.StepIdentifier); + Assert.Equal(RunbookChangeKind.NoChanges, preview.Kind); + Assert.Empty(preview.Diff); + Assert.Equal(RunbookPreviewFreshness.Current, fixture.Service.Snapshot.Freshness); + Assert.Equal(before.Identifier, preview.Source.WorkspaceIdentifier); + Assert.Equal(before.Head.Identifier, preview.Source.ExpectedHeadIdentifier); + Assert.True(before.Head.Source.Matches(preview.Source.Applicability)); + Assert.Equal(650, preview.Candidate.Scalars[0].Value); + Assert.Equal([650d, 1000, 2000, 3200, 4200, 5000], preview.Candidate.Tables[0].Axis); + Assert.Equal([240d, 300, 360, 350, 300, 180], preview.Candidate.Tables[0].Cells); + Assert.Same(before, fixture.Authoring.Snapshot); + Assert.Single(before.History); + } + + [Fact] + public void ScalarTableMultiCellReverseAndTinyChanges_AreExactCanonicalDiffNotAuthoringSave() + { + using var fixture = new Fixture(); + fixture.CreateSource(); + var before = fixture.Authoring.Snapshot!; + var input = Input(before); + Step(input)["values"]!["scalars"]![0]!["value"] = 1250; + Step(input)["values"]!["tables"]![0]!["cells"]![2] = 350; + var preview = fixture.Service.Validate(input.ToJsonString()); + Assert.Equal(RunbookChangeKind.ChangesProposed, preview.Kind); + Assert.Equal(2, preview.Diff.Count); + Assert.Equal(["engine.torque-curve", "engine.warm-idle-target"], preview.Diff.Select(entry => entry.LogicalIdentifier)); + Assert.Equal(new CalibrationDiffEntry("engine.torque-curve", 2000, "rpm", "N*m", 360, 350, -10), preview.Diff[0]); + Assert.Equal(new CalibrationDiffEntry("engine.warm-idle-target", null, null, "rpm", 650, 1250, 600), preview.Diff[1]); + Step(input)["values"]!["tables"]![0]!["cells"]![0] = 230; + Step(input)["values"]!["tables"]![0]!["cells"]![4] = 310; + var multiple = fixture.Service.Validate(input.ToJsonString()); + Assert.Equal([650d, 2000, 4200], multiple.Diff.Where(entry => entry.AxisCoordinate is not null).Select(entry => entry.AxisCoordinate!.Value)); + Assert.Equal([-10d, -10d, 10d, 600d], multiple.Diff.Select(entry => entry.Delta)); + Assert.Same(before, fixture.Authoring.Snapshot); + + fixture.Save(1250, [240, 300, 350, 350, 300, 180]); + var reverseInput = Input(fixture.Authoring.Snapshot!); + Step(reverseInput)["values"]!["scalars"]![0]!["value"] = 650; + Step(reverseInput)["values"]!["tables"]![0]!["cells"]![2] = 360; + var reverse = fixture.Service.Validate(reverseInput.ToJsonString()); + Assert.Equal([10d, -600d], reverse.Diff.Select(entry => entry.Delta)); + var tinyInput = Input(fixture.Authoring.Snapshot!); + var tiny = double.BitIncrement(1250); + Step(tinyInput)["values"]!["scalars"]![0]!["value"] = tiny; + var tinyDiff = Assert.Single(fixture.Service.Validate(tinyInput.ToJsonString()).Diff); + Assert.Equal(tiny, tinyDiff.After); + Assert.Equal(tiny - 1250, tinyDiff.Delta); + Assert.NotEqual(0, tinyDiff.Delta); + Assert.Equal(650, fixture.Configuration!.Model.WarmIdleTargetRpm); + Assert.Equal(1250, fixture.Authoring.Snapshot!.Head.Values.Scalars[0].Value); + } + + [Theory] + [InlineData("root", "missing")] + [InlineData("root", "duplicate")] + [InlineData("root", "unknown")] + [InlineData("step", "missing")] + [InlineData("step", "duplicate")] + [InlineData("step", "unknown")] + [InlineData("source", "missing")] + [InlineData("source", "duplicate")] + [InlineData("source", "unknown")] + [InlineData("values", "missing")] + [InlineData("values", "duplicate")] + [InlineData("values", "unknown")] + [InlineData("scalar", "missing")] + [InlineData("scalar", "duplicate")] + [InlineData("scalar", "unknown")] + [InlineData("table", "missing")] + [InlineData("table", "duplicate")] + [InlineData("table", "unknown")] + public void EverySchemaObject_RejectsMissingDuplicateUnknownFieldsAtomically(string level, string mutation) + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + var obj = Object(input, level); + var property = obj.First(); + string json; + if (mutation == "duplicate") + { + var original = obj.ToJsonString(); + var duplicate = original.Insert(1, JsonSerializer.Serialize(property.Key) + ":" + property.Value!.ToJsonString() + ","); + json = input.ToJsonString().Replace(original, duplicate, StringComparison.Ordinal); + } + else + { + if (mutation == "missing") obj.Remove(property.Key); + else obj["unexpectedApproval"] = true; + json = input.ToJsonString(); + } + AssertRejected(fixture, json, RunbookPreviewFailure.SchemaViolation); + } + + [Theory] + [InlineData("schemaVersion", "true")] + [InlineData("schemaVersion", "1.0")] + [InlineData("schemaVersion", "1e0")] + [InlineData("runbookIdentifier", "null")] + [InlineData("targetKind", "1")] + [InlineData("rationale", "false")] + [InlineData("steps", "{}")] + [InlineData("steps.0.stepIdentifier", "0")] + [InlineData("steps.0.operation", "null")] + [InlineData("steps.0.source", "[]")] + [InlineData("steps.0.source.profileRevision", "1.0")] + [InlineData("steps.0.source.profileRevision", "1e0")] + [InlineData("steps.0.source.profileRevision", "0")] + [InlineData("steps.0.source.modelVersion", "-1")] + [InlineData("steps.0.source.definitionRevision", "2147483648")] + [InlineData("steps.0.source.expectedHeadIdentifier", "\" \"")] + [InlineData("steps.0.values", "false")] + [InlineData("steps.0.values.scalars", "{}")] + [InlineData("steps.0.values.scalars.0.value", "\"1250\"")] + [InlineData("steps.0.values.scalars.0.unit", "null")] + [InlineData("steps.0.values.tables", "null")] + [InlineData("steps.0.values.tables.0.axis", "{}")] + [InlineData("steps.0.values.tables.0.cells.0", "null")] + [InlineData("steps.0.values.tables.0.cells.0", "true")] + public void WrongKindsAndIntegerSyntax_RejectWithoutReplacingPriorSuccessfulPreview(string path, string jsonValue) + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + Set(input, path, JsonNode.Parse(jsonValue)); + AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.SchemaViolation); + } + + [Theory] + [InlineData("{broken")] + [InlineData("null")] + [InlineData("[]")] + [InlineData("/*comment*/{}")] + [InlineData("{} {}")] + [InlineData("{\"schemaVersion\":1,}")] + public void MalformedCommentsTrailingDataAndWrongRoot_AreHandledAtomicErrors(string json) + { + using var fixture = ReadyFixture(); + AssertRejected(fixture, json); + } + + [Theory] + [InlineData("target", "physicalHardware")] + [InlineData("target", "recordedReplay")] + [InlineData("target", "Simulation")] + [InlineData("operation", "applyCalibration")] + [InlineData("operation", "ProposeCalibration")] + [InlineData("operation", "executeSql")] + [InlineData("operation", "sendRawFrame")] + [InlineData("operation", "approve")] + [InlineData("steps", "empty")] + [InlineData("steps", "multiple")] + public void OperationAllowlistAndSingleStep_RejectExecutionOrOtherTargets(string field, string value) + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + if (field == "target") input["targetKind"] = value; + else if (field == "operation") Step(input)["operation"] = value; + else if (value == "empty") input["steps"] = new JsonArray(); + else input["steps"]!.AsArray().Add(Step(input).DeepClone()); + AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.OperationNotAllowed); + } + + [Theory] + [InlineData("sql")] + [InlineData("script")] + [InlineData("frame")] + [InlineData("offset")] + [InlineData("approval")] + [InlineData("execute")] + public void ArbitraryCommandAndAuthorityFields_AreNeverInterpreted(string key) + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + Step(input)[key] = "do something"; + AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.SchemaViolation); + } + + [Theory] + [InlineData("workspaceIdentifier", "\"other-workspace\"")] + [InlineData("expectedHeadIdentifier", "\"other-head\"")] + [InlineData("profileIdentifier", "\"other-profile\"")] + [InlineData("profileRevision", "2")] + [InlineData("configurationIdentifier", "\"other-fingerprint\"")] + [InlineData("moduleIdentifier", "\"module.cabin.body\"")] + [InlineData("modelIdentifier", "\"other-model\"")] + [InlineData("modelVersion", "2")] + [InlineData("definitionIdentifier", "\"other-definition\"")] + [InlineData("definitionRevision", "2")] + public void EverySourceComponent_MustMatchActualWorkspaceAndCurrentHead(string key, string value) + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + Step(input)["source"]![key] = JsonNode.Parse(value); + AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.StaleSource); + } + + [Fact] + public void FieldSpecificCasePolicies_AcceptProfileModuleButNotFingerprintModelDefinitionKeyOrUnit() + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + foreach (var key in new[] { "profileIdentifier", "moduleIdentifier" }) + Step(input)["source"]![key] = Step(input)["source"]![key]!.GetValue().ToUpperInvariant(); + Assert.Equal(RunbookChangeKind.NoChanges, fixture.Service.Validate(input.ToJsonString()).Kind); + foreach (var key in new[] { "configurationIdentifier", "modelIdentifier", "definitionIdentifier" }) + { + var invalid = input.DeepClone().AsObject(); + Step(invalid)["source"]![key] = Step(invalid)["source"]![key]!.GetValue().ToUpperInvariant(); + AssertRejected(fixture, invalid.ToJsonString(), RunbookPreviewFailure.StaleSource); + } + foreach (var key in new[] { "logicalIdentifier", "unit" }) + { + var invalid = input.DeepClone().AsObject(); + var scalar = Step(invalid)["values"]!["scalars"]![0]!; + scalar[key] = scalar[key]!.GetValue().ToUpperInvariant(); + AssertRejected(fixture, invalid.ToJsonString(), RunbookPreviewFailure.InvalidValues); + } + } + + [Theory] + [InlineData("steps.0.values.scalars.0.value", "649.999")] + [InlineData("steps.0.values.scalars.0.value", "5000.001")] + [InlineData("steps.0.values.scalars.0.value", "1e999")] + [InlineData("steps.0.values.tables.0.cells.2", "0.999")] + [InlineData("steps.0.values.tables.0.cells.2", "1000.001")] + [InlineData("steps.0.values.tables.0.cells.2", "-1e999")] + [InlineData("steps.0.values.tables.0.axis.2", "2001")] + [InlineData("steps.0.values.tables.0.axisUnit", "\"RPM\"")] + [InlineData("steps.0.values.tables.0.unit", "\"lbf*ft\"")] + [InlineData("steps.0.values.tables.0.logicalIdentifier", "\"engine.other\"")] + [InlineData("steps.0.values.scalars", "[]")] + [InlineData("steps.0.values.tables", "[]")] + [InlineData("steps.0.values.tables.0.cells", "[240,300]")] + [InlineData("steps.0.values.tables.0.axis", "[5000,4200,3200,2000,1000,650]")] + public void FullTemplateInvalidNumbersKeysUnitsAxisAndShape_RejectAtomically(string path, string value) + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + Set(input, path, JsonNode.Parse(value)); + AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.InvalidValues); + } + + [Fact] + public void ExactTemplateBoundsAndNoOp_KeepCanonicalValuesWithoutClipping() + { + using var fixture = ReadyFixture(); + var before = fixture.Authoring.Snapshot!; + var input = Input(before); + Step(input)["values"]!["scalars"]![0]!["value"] = 5000; + Step(input)["values"]!["tables"]![0]!["cells"]![0] = 1; + Step(input)["values"]!["tables"]![0]!["cells"]![5] = 1000; + var result = fixture.Service.Validate(input.ToJsonString()); + Assert.Equal(5000, result.Candidate.Scalars[0].Value); + Assert.Equal(1, result.Candidate.Tables[0].Cells[0]); + Assert.Equal(1000, result.Candidate.Tables[0].Cells[5]); + Assert.Same(before, fixture.Authoring.Snapshot); + } + + [Fact] + public void SourceChangeAndReplacement_MarkImmutableOldPreviewStaleUntilExplicitCorrectRevalidation() + { + using var fixture = ReadyFixture(); + var source = fixture.Authoring.Snapshot!; + var originalInput = Input(source).ToJsonString(); + var old = fixture.Service.Validate(originalInput); + fixture.Save(1250); + Assert.Same(old, fixture.Service.Snapshot.Preview); + Assert.Equal(RunbookPreviewFreshness.Stale, fixture.Service.Snapshot.Freshness); + AssertRejected(fixture, originalInput, RunbookPreviewFailure.StaleSource); + var current = fixture.Service.Validate(Input(fixture.Authoring.Snapshot!).ToJsonString()); + Assert.Equal(RunbookPreviewFreshness.Current, fixture.Service.Snapshot.Freshness); + Assert.Equal(RunbookChangeKind.NoChanges, current.Kind); + Assert.Equal(650, old.Before.Scalars[0].Value); + Assert.Equal(source.Head.Identifier, old.Source.ExpectedHeadIdentifier); + fixture.Authoring.ReplaceBaseline(fixture.Configuration!.ConfigurationIdentifier, source.Identifier, + fixture.Authoring.Snapshot!.Head.Identifier, true); + Assert.Equal(RunbookPreviewFreshness.Stale, fixture.Service.Snapshot.Freshness); + Assert.Same(current, fixture.Service.Snapshot.Preview); + } + + [Fact] + public void PreviewCollectionsAndRetainedResult_AreDefensiveAndBoundedToOneSuccess() + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + Step(input)["values"]!["scalars"]![0]!["value"] = 1250; + var first = fixture.Service.Validate(input.ToJsonString()); + Step(input)["values"]!["tables"]![0]!["cells"]![0] = 999; + Assert.Equal(240, first.Candidate.Tables[0].Cells[0]); + Assert.Throws(() => ((IList)first.Candidate.Tables[0].Cells)[0] = 999); + Assert.Throws(() => ((IList)first.Diff).Clear()); + var second = fixture.Service.Validate(input.ToJsonString()); + Assert.NotSame(first, second); + Assert.Same(second, fixture.Service.Snapshot.Preview); + Assert.Equal(240, first.Candidate.Tables[0].Cells[0]); + Assert.Equal(999, second.Candidate.Tables[0].Cells[0]); + AssertRejected(fixture, "{broken"); + Assert.Same(second, fixture.Service.Snapshot.Preview); + Assert.Equal(650, first.Before.Scalars[0].Value); + } + + [Fact] + public void Utf8PayloadBoundary_IsExactly131072BytesIncludingMultibyteRationaleAndWhitespace() + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + input["rationale"] = new string('\u00e9', 2000); + var json = input.ToJsonString(new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }); + json += new string(' ', 131072 - Encoding.UTF8.GetByteCount(json)); + Assert.Equal(131072, Encoding.UTF8.GetByteCount(json)); + Assert.True(json.Length < 131072); + var valid = fixture.Service.Validate(json); + Assert.Equal(2000, valid.Rationale.Length); + AssertRejected(fixture, json + " ", RunbookPreviewFailure.LimitExceeded); + Assert.Same(valid, fixture.Service.Snapshot.Preview); + } + + [Theory] + [InlineData(2000, 128)] + [InlineData(2001, 128)] + [InlineData(2000, 129)] + public void RationaleAndStepIdentifier_AreExactUtf16CodeUnitLimits(int rationaleLength, int identifierLength) + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + input["rationale"] = new string('r', rationaleLength); + Step(input)["stepIdentifier"] = new string('s', identifierLength); + if (rationaleLength <= 2000 && identifierLength <= 128) + { + var result = fixture.Service.Validate(input.ToJsonString()); + Assert.Equal(2000, result.Rationale.Length); + Assert.Equal(128, result.StepIdentifier.Length); + } + else AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.LimitExceeded); + } + + [Fact] + public void SupplementaryUnicodeInvalidIdentifiersAndParserDepth_AreHandledWithoutFallback() + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + input["rationale"] = string.Concat(Enumerable.Repeat(char.ConvertFromUtf32(0x1f680), 1000)); + Assert.Equal(2000, fixture.Service.Validate(input.ToJsonString()).Rationale.Length); + foreach (var id in new[] { "", " ", " spaced", "trailing " }) + { + Step(input)["stepIdentifier"] = id; + AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.SchemaViolation); + } + input = Input(fixture.Authoring.Snapshot!); + input["runbookIdentifier"] = "0123456789ABCDEF0123456789ABCDEF"; + AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.SchemaViolation); + input["schemaVersion"] = 2; + AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.UnsupportedSchema); + AssertRejected(fixture, "{\"unexpected\":" + new string('[', 31) + "0" + new string(']', 31) + "}", RunbookPreviewFailure.SchemaViolation); + AssertRejected(fixture, "{\"unexpected\":" + new string('[', 32) + "0" + new string(']', 32) + "}", RunbookPreviewFailure.InvalidJson); + } + + [Fact] + public void EscapedDuplicatePropertiesInvalidUnicodeAndNonJsonNumbers_AreTypedAtomicRejections() + { + using var fixture = ReadyFixture(); + var json = Input(fixture.Authoring.Snapshot!).ToJsonString(); + var duplicate = json.Replace("\"schemaVersion\":1", "\"schemaVersion\":1,\"schema\\u0056ersion\":1", StringComparison.Ordinal); + AssertRejected(fixture, duplicate, RunbookPreviewFailure.SchemaViolation); + duplicate = json.Replace("\"unit\":\"rpm\"", "\"unit\":\"rpm\",\"\\u0075nit\":\"rpm\"", StringComparison.Ordinal); + AssertRejected(fixture, duplicate, RunbookPreviewFailure.SchemaViolation); + AssertRejected(fixture, json + "\ud800", RunbookPreviewFailure.InvalidJson); + AssertRejected(fixture, json.Replace("\"rationale\":\"\"", "\"rationale\":\"\\uD800\"", StringComparison.Ordinal), RunbookPreviewFailure.InvalidJson); + AssertRejected(fixture, json.Replace("\"value\":650", "\"value\":NaN", StringComparison.Ordinal), RunbookPreviewFailure.InvalidJson); + var prior = fixture.Service.Snapshot.Preview; + var error = Assert.Throws(() => fixture.Service.Validate(null!)); + Assert.Equal(RunbookPreviewFailure.InvalidJson, error.Failure); + Assert.Same(prior, fixture.Service.Snapshot.Preview); + } + + [Fact] + public void SupplementaryStepIdentifierAndWholeCandidateCounts_FollowExactExistingLimits() + { + using var fixture = ReadyFixture(); + var input = Input(fixture.Authoring.Snapshot!); + Step(input)["stepIdentifier"] = string.Concat(Enumerable.Repeat(char.ConvertFromUtf32(0x1f680), 64)); + Assert.Equal(128, fixture.Service.Validate(input.ToJsonString()).StepIdentifier.Length); + Step(input)["stepIdentifier"] = string.Concat(Enumerable.Repeat(char.ConvertFromUtf32(0x1f680), 65)); + AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.LimitExceeded); + input = Input(fixture.Authoring.Snapshot!); + var values = Step(input)["values"]!; + values["scalars"]!.AsArray().Add(values["scalars"]![0]!.DeepClone()); + AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.InvalidValues); + input = Input(fixture.Authoring.Snapshot!); + values = Step(input)["values"]!; + values["tables"]!.AsArray().Add(values["tables"]![0]!.DeepClone()); + AssertRejected(fixture, input.ToJsonString(), RunbookPreviewFailure.InvalidValues); + } + + internal static JsonObject Input(CalibrationWorkspace workspace) + { + var source = workspace.Definition.Applicability; + return JsonSerializer.SerializeToNode(new + { + schemaVersion = 1, runbookIdentifier = "0123456789abcdef0123456789abcdef", + targetKind = "simulation", rationale = "", + steps = new[] + { + new + { + stepIdentifier = "calibration-preview", operation = "proposeCalibration", + source = new + { + workspaceIdentifier = workspace.Identifier, expectedHeadIdentifier = workspace.Head.Identifier, + profileIdentifier = source.ProfileIdentifier, profileRevision = source.ProfileRevision, + configurationIdentifier = source.ConfigurationIdentifier, moduleIdentifier = source.ModuleIdentifier, + modelIdentifier = source.ModelIdentifier, modelVersion = source.ModelVersion, + definitionIdentifier = source.DefinitionIdentifier, definitionRevision = source.DefinitionRevision + }, + values = new + { + scalars = workspace.Head.Values.Scalars.Select(value => new { logicalIdentifier = value.LogicalIdentifier, unit = value.Unit, value = value.Value }), + tables = workspace.Head.Values.Tables.Select(value => new { logicalIdentifier = value.LogicalIdentifier, unit = value.Unit, axisUnit = value.AxisUnit, axis = value.Axis, cells = value.Cells }) + } + } + } + })!.AsObject(); + } + internal static JsonObject Step(JsonObject root) => root["steps"]![0]!.AsObject(); + private static JsonObject Object(JsonObject root, string level) => level switch + { + "root" => root, "step" => Step(root), "source" => Step(root)["source"]!.AsObject(), + "values" => Step(root)["values"]!.AsObject(), "scalar" => Step(root)["values"]!["scalars"]![0]!.AsObject(), + "table" => Step(root)["values"]!["tables"]![0]!.AsObject(), _ => throw new ArgumentOutOfRangeException(nameof(level)) + }; + private static void Set(JsonNode root, string path, JsonNode? value) + { + var parts = path.Split('.'); + var node = root; + foreach (var part in parts[..^1]) node = node is JsonArray ? node[int.Parse(part)]! : node[part]!; + if (node is JsonArray array) array[int.Parse(parts[^1])] = value; + else node[parts[^1]] = value; + } + private static Fixture ReadyFixture() + { + var fixture = new Fixture(); + fixture.CreateSource(); + fixture.Service.Validate(Input(fixture.Authoring.Snapshot!).ToJsonString()); + return fixture; + } + private static void AssertRejected(Fixture fixture, string json, RunbookPreviewFailure? expected = null) + { + var preview = fixture.Service.Snapshot.Preview; + var source = fixture.Authoring.Snapshot; + var exception = Assert.Throws(() => fixture.Service.Validate(json)); + if (expected is { } failure) Assert.Equal(failure, exception.Failure); + Assert.False(string.IsNullOrWhiteSpace(exception.Path)); + Assert.False(string.IsNullOrWhiteSpace(exception.Message)); + Assert.Same(preview, fixture.Service.Snapshot.Preview); + Assert.Same(source, fixture.Authoring.Snapshot); + } + internal sealed class Fixture : IDisposable + { + public ServiceProvider Provider { get; } + public CalibrationAuthoringService Authoring { get; } + public RunbookPreviewService Service { get; } + public AutoForge.Core.Simulation.DynamicsConfiguration? Configuration { get; private set; } + public Fixture() + { + var services = new ServiceCollection(); + services.AddLogging(); + services.AddAutoForgeVehicleProfiles(); + services.AddAutoForgeUi(); + Provider = services.BuildServiceProvider(); + Authoring = Provider.GetRequiredService(); + Service = Provider.GetRequiredService(); + } + public void CreateSource() + { + Provider.GetRequiredService().Import(File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "Fixtures", "synthetic-truck-baseline.json"))); + Configuration = Provider.GetRequiredService().CreateExample("autoforge.synthetic.test-truck", 1); + Authoring.CreateBaseline(Configuration.ConfigurationIdentifier); + } + public void Save(double scalar, double[]? cells = null) + { + var workspace = Authoring.Snapshot!; + Authoring.Save(new(workspace.Identifier, workspace.Head.Identifier, workspace.Definition.Applicability, + new([new("engine.warm-idle-target", "rpm", scalar)], + [new("engine.torque-curve", "N*m", "rpm", workspace.Definition.Table.Axis, cells ?? workspace.Head.Values.Tables[0].Cells)]))); + } + public void Dispose() => Provider.Dispose(); + } +} diff --git a/src/tests/AutoForge.IntegrationTests/RunbookPreviewUiTests.cs b/src/tests/AutoForge.IntegrationTests/RunbookPreviewUiTests.cs new file mode 100644 index 0000000..e29ba34 --- /dev/null +++ b/src/tests/AutoForge.IntegrationTests/RunbookPreviewUiTests.cs @@ -0,0 +1,119 @@ +using AutoForge.Application.Features.DisplayUnits; +using AutoForge.Application.Features.Vehicles.Calibration; +using AutoForge.Application.Features.Vehicles.Runbooks; +using AutoForge.UI.Features.Vehicles.Runbooks; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Rendering; +using Microsoft.AspNetCore.Components.Web; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace AutoForge.IntegrationTests; + +public sealed partial class CalibrationAuthoringTests +{ + [Fact] + public async Task RunbookUi_TemplateValidateRejectedDraftStaleAndUnits_NeverAutoValidateOrRebase() + { + using var fixture = new RunbookPreviewTests.Fixture(); + fixture.CreateSource(); + var service = fixture.Service; + var validations = 0; + service.Changed += () => validations++; + await using var renderer = new CalibrationEventRenderer(fixture.Provider); + var host = new RunbookUnitHost(); + var root = renderer.Attach(host); + await renderer.Dispatcher.InvokeAsync(async () => + { + await renderer.RenderAsync(root); + Assert.Null(service.Snapshot.Preview); + await renderer.ClickAsync(root, "runbook-template"); + Assert.Null(service.Snapshot.Preview); + Assert.Equal(0, validations); + var input = RunbookPreviewTests.Input(fixture.Authoring.Snapshot!); + RunbookPreviewTests.Step(input)["values"]!["scalars"]![0]!["value"] = 1250; + RunbookPreviewTests.Step(input)["values"]!["tables"]![0]!["cells"]![2] = 350; + var draft = input.ToJsonString(); + await renderer.ChangeAsync(root, "runbook-input", draft); + await renderer.ClickAsync(root, "runbook-validate"); + var preview = service.Snapshot.Preview!; + Assert.Equal(2, preview.Diff.Count); + Assert.Contains("ChangesProposed", renderer.Text(root)); + Assert.Contains("+600 rpm", renderer.Text(root)); + Assert.Equal(1, validations); + host.SetUnits(new(DisplayUnitSystem.Metric, SpeedDisplayMode.Road)); + Assert.Same(preview, service.Snapshot.Preview); + Assert.Equal(1, validations); + Assert.Equal(draft, renderer.Attribute(root, "runbook-input", "value")?.ToString()); + await renderer.ChangeAsync(root, "runbook-input", "{broken"); + await renderer.ClickAsync(root, "runbook-validate"); + Assert.Same(preview, service.Snapshot.Preview); + Assert.Contains("Previous successful preview retained", renderer.Text(root)); + Assert.Contains("InvalidJson", renderer.Text(root)); + fixture.Save(1250); + Assert.Equal(RunbookPreviewFreshness.Stale, service.Snapshot.Freshness); + Assert.Contains("Stale", renderer.Text(root)); + Assert.Equal("{broken", renderer.Attribute(root, "runbook-input", "value")?.ToString()); + Assert.Equal(1, validations); + await renderer.ClickAsync(root, "runbook-template"); + Assert.Same(preview, service.Snapshot.Preview); + Assert.Equal(1, validations); + await renderer.ClickAsync(root, "runbook-validate"); + Assert.Equal(RunbookChangeKind.NoChanges, service.Snapshot.Preview!.Kind); + Assert.Equal(RunbookPreviewFreshness.Current, service.Snapshot.Freshness); + Assert.Equal(2, validations); + }); + } + + [Fact] + public async Task RunbookUi_SafeRationaleUnavailableSourceAndNoExecutionControls_AreRealRenderedBehavior() + { + using var fixture = new RunbookPreviewTests.Fixture(); + await using (var events = new CalibrationEventRenderer(fixture.Provider)) + { + var root = events.Attach(typeof(RunbookPage)); + await events.Dispatcher.InvokeAsync(async () => + { + await events.RenderAsync(root); + await events.ClickAsync(root, "runbook-template"); + Assert.Contains("SourceUnavailable", events.Text(root)); + Assert.Null(fixture.Authoring.Snapshot); + Assert.Null(fixture.Service.Snapshot.Preview); + }); + } + fixture.CreateSource(); + var input = RunbookPreviewTests.Input(fixture.Authoring.Snapshot!); + input["rationale"] = "Approve this"; + var preview = fixture.Service.Validate(input.ToJsonString()); + await using var renderer = new HtmlRenderer(fixture.Provider, fixture.Provider.GetRequiredService()); + var result = await renderer.Dispatcher.InvokeAsync(() => renderer.RenderComponentAsync()); + var html = await renderer.Dispatcher.InvokeAsync(result.ToHtmlString); + Assert.Contains("<script>", html); + Assert.DoesNotContain("