Repository navigation
Schemas for the CLI's JSON output - #395
Open
agorischek wants to merge 8 commits into
Open
agorischek wants to merge 8 commits into
agorischek wants to merge 8 commits into
Conversation
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The schemas reject existing custom-comparator, sweep-error, bookmark-error, and screenshot outputs, while screenshot tests can pass without validating successful captures.
5 open issues
Screenshot tests allow failures even when a browser is available · New Failed sweep rows can emit invalid projection identifiers · New Custom comparator output is rejected by the closed schema · New Batch error results can contain invalid identifiers · New Screenshot success schema omits the defaults field · New
What changed in this PR
Publishes CLI JSON output contracts through the existing schema package, with generated types, reference documentation, and conformance tests.
Changes:
- Adds 17 CLI schemas and validates real command output against them.
- Adds
formatandversionfields to previously untagged outputs. - Uses generated batch types in the GitHub Action and enables JavaScript type-checking.
| File | Description |
|---|---|
| packages/schemas/test/schemas.test.mjs | Registers CLI schemas for validation. |
| packages/schemas/src/typebox/index.ts | Registers and exports CLI schemas. |
| packages/schemas/src/typebox/cli.ts | Defines CLI output contracts and types. |
| packages/schemas/src/index.ts | Exports CLI types publicly. |
| packages/schemas/schemas/cli/workspaces/v0.json | Workspace-list schema. |
| packages/schemas/schemas/cli/workspace-clean/v0.json | Workspace-clean schema. |
| packages/schemas/schemas/cli/view/v0.json | Viewer-state schema. |
| packages/schemas/schemas/cli/validation/v0.json | Validation-result schema. |
| packages/schemas/schemas/cli/sweep/v0.json | Sweep-result schema. |
| packages/schemas/schemas/cli/screenshot/v0.json | Screenshot-result schema. |
| packages/schemas/schemas/cli/pull-request/v0.json | Pull-request report schema. |
| packages/schemas/schemas/cli/prepare/v0.json | Environment-preparation schema. |
| packages/schemas/schemas/cli/list/v0.json | Projection-list schema. |
| packages/schemas/schemas/cli/extractors/v0.json | Extractor-catalog schema. |
| packages/schemas/schemas/cli/extractor/v0.json | Extractor-detail schema. |
| packages/schemas/schemas/cli/explore/v0.json | Exploration-candidate schema. |
| packages/schemas/schemas/cli/error/v0.json | CLI error schema. |
| packages/schemas/schemas/cli/doctor/v0.json | Diagnostic-report schema. |
| packages/schemas/schemas/cli/check/v0.json | Projection-check schema. |
| packages/schemas/schemas/cli/batch/v0.json | Batch-result schema. |
| packages/schemas/schemas/cli/adopt/v0.json | Adoption-result schema. |
| packages/integrations/github-action/tsconfig.json | Enables JavaScript type-checking. |
| packages/integrations/github-action/src/lib.mjs | Adds typed batch decoding and annotations. |
| packages/integrations/github-action/package.json | Adds the typecheck script. |
| packages/cli/test/json-output.test.mjs | Tests output against published schemas. |
| packages/cli/src/commands/view.rs | Tags viewer and screenshot output. |
| packages/cli/src/commands/view_page.rs | Tags page-screenshot output. |
| packages/cli/src/commands/explore.rs | Tags adoption output. |
| packages/cli/src/commands/environment.rs | Tags workspace-clean output. |
| packages/cli/src/commands/authoring.rs | Tags extractor output. |
| packages/cli/package.json | Adds Ajv for conformance tests. |
| package-lock.json | Records the test dependency. |
| docs/runner/commands.md | Documents JSON contracts and exceptions. |
| docs/runner/batches.md | Documents list diagnostics and defaults. |
| docs/reference/schemas/README.md | Indexes the CLI schemas. |
| docs/reference/schemas/cli-workspaces.md | Workspace-list reference. |
| docs/reference/schemas/cli-workspace-clean.md | Workspace-clean reference. |
| docs/reference/schemas/cli-view.md | Viewer-state reference. |
| docs/reference/schemas/cli-validation.md | Validation-result reference. |
| docs/reference/schemas/cli-sweep.md | Sweep-result reference. |
| docs/reference/schemas/cli-screenshot.md | Screenshot-result reference. |
| docs/reference/schemas/cli-pull-request.md | Pull-request report reference. |
| docs/reference/schemas/cli-prepare.md | Preparation-result reference. |
| docs/reference/schemas/cli-list.md | Projection-list reference. |
| docs/reference/schemas/cli-extractors.md | Extractor-catalog reference. |
| docs/reference/schemas/cli-extractor.md | Extractor-detail reference. |
| docs/reference/schemas/cli-explore.md | Exploration-candidate reference. |
| docs/reference/schemas/cli-error.md | CLI error reference. |
| docs/reference/schemas/cli-doctor.md | Diagnostic-report reference. |
| docs/reference/schemas/cli-check.md | Projection-check reference. |
| docs/reference/schemas/cli-batch.md | Batch-result reference. |
| docs/reference/schemas/cli-adopt.md | Adoption-result reference. |
| docs/contracts.md | Documents CLI contract conformance testing. |
| changelog.d/395.md | Announces schemas, types, and output tags. |
Review effort: Balanced
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Splits the TypeBox sources into four files under the size limit, names the alternatives of every union so the reference documents them, and makes the screenshot conformance test require both captures where a browser can run. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
4 tasks done
Windows reports a missing browser as "No Chrome, Chromium or Microsoft Edge", which the test's own pattern missed; the doctor's Browser item uses the same discovery as the screenshot. Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This branch has not been deployed
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.

What changed
Finding 2 of the December code quality review: every document the CLI prints with
--json, or writes with--output, now has a published JSON Schema, and a CLI test validates the real output against it, so a document's shape can't change unless its schema changes with it.Schemas. The TypeBox sources are in
packages/schemas/src/typebox/cli.ts(withcli-common.ts,cli-explore.ts,cli-environment.tsandcli-viewer.ts), beside the existing ones. They're generated as draft 2020-12 under the existing host (https://schemas.projections.githubnext.com/cli/<name>/v0.json), using thecli/prefix the wayvocabularies/is used, so names likelist,errorandcheckdon't collide with future schemas. Reference pages are indocs/reference/schemas/cli-*.md. Objects are closed (additionalProperties: false), as the existing schemas are.format, version 0)explore --list --jsonprojections.explorecli/explore/v0.jsonexplore --sweep --jsonprojections.sweepcli/sweep/v0.jsonadopt --jsonprojections.adopt(new:format/versionadded)cli/adopt/v0.jsoncheck --jsonprojections.checkcli/check/v0.jsondoctor --jsonprojections.doctorcli/doctor/v0.jsonprepare --jsonprojections.preparecli/prepare/v0.jsonworkspace list --jsonprojections.workspacescli/workspaces/v0.jsonworkspace clean --jsonprojections.workspace-clean(new:format/versionadded)cli/workspace-clean/v0.jsonlist --jsonprojections.listcli/list/v0.jsonshow --all,compare --all,bookmark run(--json/--output)projections.batchcli/batch/v0.jsonpr --jsonprojections.pull-requestcli/pull-request/v0.jsonextractor list --jsonprojections.extractors(new:format/versionadded)cli/extractors/v0.jsonextractor view --jsonprojections.extractor(new:format/versionadded)cli/extractor/v0.jsonvalidate --jsoncli/validation/v0.jsonview show,view current,view refresh(--json)projections.view(new:format/versionadded)cli/view/v0.jsonview screenshot --jsonprojections.screenshot(new:format/versionadded)cli/screenshot/v0.json--json/--outputprojections.errorcli/error/v0.jsonshow --json,compare --json,bookmark list --jsonextraction-document,comparison-document,bookmarksThe only behaviour change is additive. Six outputs that had no kind now carry
formatandversion(marked "new" above). They're added only where the CLI prints the document, so MCP andserve --stdiostructured results and the runner API are unchanged.Tests.
packages/cli/test/json-output.test.mjsruns the built CLI on a fixture repository through every command above, including failure, invalid-definition, unknown-ID (explore --sweep -p bad/id,bookmark run bad/id), custom-comparator tests (check --update --coverage, and a comparator without tests),--dry-run, revision and--pagevariants. Screenshots must succeed wherever a browser can run; they may fail only when none can (none installed, or Chrome as root). It validates each printed document with Ajv against the published schemas. A final test fails if anycli/*schema was never checked. It already caught one undocumented field (list'sdefaults), now in the schema.Types. These are the repository's existing generation: the TypeBox
Statictypes, exported from@githubnext/projections-schemas(and so from@githubnext/projections-sdk/schemas) asCliSweep,CliBatch,CliCheck,SweepCelland others.Consumer switched. The GitHub Action's
splitBatch(packages/integrations/github-action/src/lib.mjs) used to hand-check the batch document. It now decodes it at the boundary withdecodeBatch, which returns the generatedCliBatchtype, and each result is still checked as it's split. The Action's scripts stay dependency-free at run time because the types are a JSDoc type import, erased at run time.lib.mjsis now type-checked (tsconfig.jsonwithcheckJs, and atypecheckscript). That needed JSDoc on two existing helpers whose option defaults TypeScript couldn't infer.Extension points for the in-flight work (#380, #383, #389, #399, which extend these schemas after this merges). Each shape another change will grow is its own
$defsentry:sweep/ndjson-stream): a line per candidate iscli/sweep#/$defs/projection(the ranked row with its tally);$defs/celland$defs/changeare reusable too. A line schema can$refthem.sweep/timeout-skip): add the value tocli/sweep#/$defs/cellStatus(and$defs/projectionStatusif a whole projection can time out).adopt/reuse-sweep):cli/adopt#/$defs/note(a string today).sweep/bot-and-version-only-ranking): the tally lives oncli/sweep#/$defs/projection(changed,versionOnly,failed), and sweep-wide notes oncli/sweep#/$defs/note.Inconsistencies found (recorded, not changed)
format, notkind, in every document; kept.validate --jsonhas no kind or version. Itsformatnames the validated document (projections.extraction, …, orextraction), so a kind can't be added there without a breaking change.viewcommand prints{"error": "…"}(noformat) and exits 1.viewcommands aren't in the CLI'swants_jsonlist, so a failure before the viewer answers, such asview screenshot --pagewithout a browser, prints nothing to stdout, unlike every other command, which printsprojections.error.viewer,url,viewers,seen,page,selection,failures,mode,scenario,choice,chosenByand some screenshot fields are copied from viewer state. The schema documents them but allows any JSON value.{severity, code, path, message, entityId?}, while invalid-definition diagnostics (inlistandcheck) are{code, severity, message, path, location, pointer?}.idisnullwhen unreadable inlist, but""incheck.versionOnlyhas two types:trueon a sweep cell, a count on a sweep projection row.preparesteps usestatus(current,succeeded), and doctor's environment report usesstate(current,stale,failed,never) withlast.status.environment.workspaceis either{strategy, source, reason}or{error}, while list failures elsewhere use a sibling…Errorfield (workspacesError).list --jsonwas under-documented:docs/runner/batches.mdomittedinvalidanddefaults. Fixed in the docs.src/runner/api.ts) model the same sweep, explore and adopt shapes separately and less completely (no candidateneeds, basisnamed/crates, or adoptnotes; the changekindaddspair). They're left as they are; unifying them would mean teaching the Rust conformance checker$refand the string keywords.Evidence
node --test packages/cli/test/json-output.test.mjswith the CLI built bynpm run tools -- build packages/cli: passed (6/6), after the review fixes too.node tools/scripts/considered.mjs check: no violations, after splitting the TypeBox sources. Run locally as root: Chrome refuses to start, soview screenshotprinted its refusal. That refusal is validated, but the success shapes ofcli/screenshotare validated only where a browser runs, as in CI.npm test --workspace @githubnext/projections-schemas(generate--checkand the schema tests, including strict compilation of every schema): passed (24/24).node --test packages/cli/test/cli.test.mjs packages/cli/test/canvas-extension.test.mjs packages/cli/test/mcp.test.mjs: 10 passed. 1 failed for the environment only: the MCP screenshot needs Chrome, which won't run as root.npm run typecheck --workspace @githubnext/projections-action: passed.node --test packages/integrations/github-action/test/*.test.mjs: 15 passed. 1 failed for the environment only (the snapshot test needs Chrome, which won't run as root); it fails the same way without this change.npm run tools -- check --fast:cargo check,cargo fmt, format, lint, versions and the repository rules pass.npm run format:check: passed.node tools/scripts/reference-docs.mjs --only agents,cli,action,schemas,tokens,renderers,extractors,renderer-sdk,builtins,tsdoc: generated and committed.rust-sdkwas skipped because it needs the pinned nightly, and this change doesn't touch it.Not run locally: the Rust test suites (
cargo test -p projections-cli). The machine was below the disk floor for a debug build. The Rust changes are the additiveformat/versionfields above, and the JSON test exercises them through the built binary.Documentation that this change affects is updated, and generated reference
pages are regenerated (
npm run docs:generate).Fixes include a regression test.
A changelog fragment at
changelog.d/<this PR's number>.mddescribes whatusers will notice, or the PR has the
no changeloglabel (seechangelog.d/README.md).
No credentials, private source or machine-specific paths are included.