Repository navigation
Decode the runner API's responses whole, against TypeBox schemas - #105
Merged
Merged
Conversation
The Inspector's response decoders checked an outer object and array, then asserted the full type with `as unknown as`: an adopt preview with `files: [null]`, an explore candidate missing a field or a sweep cell of the wrong type reached UI code, which failed there instead of at the boundary. The local runner's API responses the Inspector decodes now have TypeBox schemas in `packages/schemas/src/runner` (exported as `@githubnext/projections-schemas/runner`; internal and unversioned), which give the Inspector's types and `decodeRunnerResponse`, whose `RunnerResponseError` names the request and the JSON pointer. The generated `internal/runner-api.json` holds the Rust service to them: the service tests check each response they receive against it, refusing undeclared fields. Saved documents and trial definitions stay opaque past their envelope. Code review, finding 11. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The schema omits the runner’s existing basis.file field, causing the strict Rust conformance checker to reject legitimate per-file explore candidates.
1 open issue
What changed in this PR
This PR moves selected runner API response contracts into the shared schemas package, replacing shallow Inspector checks with nested validation and adding Rust response conformance checks.
Changes:
- Adds TypeBox response schemas, derived types, and a CSP-compatible decoder with structured errors.
- Migrates Inspector response parsing to the shared decoder while retaining deliberately opaque document payloads.
- Adds generated-schema tracking, decoder tests, Rust conformance checks, and contract documentation.
| File | Description |
|---|---|
tools/cli/src/lib/generated.ts |
Tracks the generated runner API schema. |
packages/schemas/test/runner.test.mjs |
Tests valid responses and nested validation failures. |
packages/schemas/src/runner/index.ts |
Exports runner schemas and decoding APIs. |
packages/schemas/src/runner/decode.ts |
Implements validation and structured errors. |
packages/schemas/src/runner/api.ts |
Defines response schemas and derived types. |
packages/schemas/scripts/generate.mjs |
Generates and checks the internal API schema. |
packages/schemas/README.md |
Documents the internal runner schema entry point. |
packages/schemas/package.json |
Exposes the ./runner subpath. |
packages/schemas/internal/runner-api.json |
Supplies generated schemas for Rust conformance checks. |
packages/host/inspector/src/types.ts |
Re-exports schema-derived response types. |
packages/host/inspector/src/client/responses.ts |
Uses shared decoding for selected responses. |
packages/host/inspector/src/client/documents.ts |
Removes the replaced document-envelope guard. |
packages/cli/tests/service/main.rs |
Registers the conformance test module. |
packages/cli/tests/service/history.rs |
Checks pairs and sweep responses for conformance. |
packages/cli/tests/service/fixtures.rs |
Checks document and fixture-generation responses. |
packages/cli/tests/service/conformance.rs |
Adds strict response-schema validation for tests. |
packages/cli/tests/service/changes.rs |
Checks working-tree change responses. |
packages/cli/tests/service/authoring.rs |
Checks save, explore, and adopt responses. |
docs/runner/stdio-backend.md |
Links response documentation to schema ownership. |
docs/contracts.md |
Defines schema ownership, opacity, and conformance rules. |
Review effort: Balanced
Explore's per-file candidates (one per workflow) name their file in basis.file, which the schema omitted, so the strict conformance check refused them. Declare it, regenerate internal/runner-api.json, and check a workflow's candidate against the schema. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Code review, finding 11: the response decoders certified nested shapes they didn't check.
Evidence
In
packages/host/inspector/src/client/responses.ts(lines 13-18, 25-28, 36-42 and 50-59 before this change),parseWrite,parseExplore,parseSweepandparsePairschecked an outer object and array and then asserted the full type withas unknown as.parseWriteacceptedfiles: [null], andFilesPreviewinexplore.tsx(29-48) then dereferencedfile.pathon each entry. Explore candidates and sweep cells had the same gap between the envelope and its elements. A malformed or version-skewed response therefore failed in unrelated UI code rather than as an actionable error at the boundary. This is about robustness and the type contract. It doesn't treat the authenticated local runner as an adversary.Strategy
The user approved the proposal ("Sure that proposal sounds good"):
packages/schemasis the one schema system for the contracts we own. It already produces the published JSON Schemas and TS types. No Zod, no tRPC (the server is Rust).packages/schemas/src/runner/api.ts, exported as@githubnext/projections-schemas/runner. The Inspector'stypes.tsnow re-exports theirStatictypes in place of the hand-written interfaces:ExploreCandidate(s),OnboardingFile/OnboardingWrite,Sweep*,InspectorPair(s),InspectorDefinitionSaveandInspectorWorkspaceChanges. The names are unchanged, and a scratch check confirmed the new and old types are mutually assignable.responses.tscallsdecodeRunnerResponse(name, value). It returns the decoded value or throws aRunnerResponseErrorwithrequest,pointerandreason, for exampleThe local runner's response to GET /api/sweep is invalid at /sweep/cells/0/status: must be one of "changed", "unchanged", "failed".Value.Check/Value.Errors), notCompile. The JIT needsunsafe-eval, which the Inspector's CSP (served page and VS Code webview) forbids. Probing for it would log CSP violations.@githubnext/projections-schemasentry still loads no TypeBox at run time; only the./runnersubpath does.packages/cli/tests/service/conformance.rsvalidates every response the service tests receive for these endpoints against the generatedpackages/schemas/internal/runner-api.json. The covered endpoints are adopt, explore, both sweep forms, pairs, definition save, changes, fixtures changes and document. Generating Rust types is out of scope./api/pairssuggestions'backwardsand/api/changes'tree. Sweep cells'stderrand explorebasis.skippedwere added from reading the Rust.Where the schemas live, and why
The schemas are in
packages/schemas/src/runner, kept apart from the publishedsrc/typebox, and the generated file ispackages/schemas/internal/runner-api.json, outsideschemas/. It has no$idon the schemas host, isn't in the publication set and gets no reference pages.The runner API is internal: the CLI and its Inspector ship from the same commit, and the editor and hosted clients follow the CLI. Publishing it as a versioned document would promise outside readers a stability it doesn't have. It still sits in
packages/schemasso there is one schema system and one generator:npm run generatewrites it, and the package's--check(andtools generated) fail when it's stale.Validated vs deliberately opaque
/api/document's document (onlyformatandversion; the CLI'sartifact::read_documentvalidated it when loading) and an explore candidate's trialdefinition(an object; the runner loads and validates definitions).host/core/src/frame/admission.ts,renderers/sdk/src/protocol/frame.ts), which is asymmetric on purpose. Decoders already written by hand in other files (definitions, revisions, scenarios, jobs, fixtures catalog, renderers, comparator) stay as they are and could move to schemas later.Docs
docs/contracts.md#schema-owned-contractsstates which contracts TypeBox owns, the internal runner API, the opaque documents and the Rust conformance rule.packages/schemas/README.mdanddocs/runner/stdio-backend.mdpoint to that section.Tests
packages/schemas/test/runner.test.mjscovers decoding with malformed nested entries:files: [null]→/files/0, a candidate missingbasis→/candidates/1, a sweep cell withchanges: 'one'and with an unknownstatus, a document with the wrongformat, a non-object root, and opaque documents passing through. The whole schemas package passes (22 tests).cargo test -p projections-cli --test service, filtered to the conformance test and the pairs, sweeps, adopting, saving, working-tree changes and fixtures tests that now check conformance: 8 of 9 pass.sweeps_run_projections_across_recent_commitsfailed locally only because that build didn't embed the default comparator Wasm. Its responses conformed, including the failed cells; its laterunchangedassertion needs the comparator. CI builds it.tools check --fastpasses.docs:check.Follow-up (private)
After the pin is bumped, the private
src/github/projections-cli.tsshould adoptdecodeRunnerResponsefrom@githubnext/projections-schemas/runnerand replace its own guards for these endpoints. The VS Code extension's separateparseWrite/parsePairs(integrations/vscode/src/writes.ts,projections/pair-list.ts) could do the same.