@intentius/chant 0.101.0 → 0.102.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/checks.d.ts.map +1 -1
- package/dist/attrref.d.ts.map +1 -1
- package/dist/audit/discover.d.ts.map +1 -1
- package/dist/audit/nginx.d.ts.map +1 -1
- package/dist/audit/prior-art.d.ts +48 -0
- package/dist/audit/prior-art.d.ts.map +1 -1
- package/dist/behaviour-kinds.d.ts.map +1 -1
- package/dist/builder.d.ts.map +1 -1
- package/dist/cli/commands/carve-emit.d.ts.map +1 -1
- package/dist/cli/commands/check-lexicon.d.ts +16 -0
- package/dist/cli/commands/check-lexicon.d.ts.map +1 -1
- package/dist/cli/commands/import.d.ts +8 -0
- package/dist/cli/commands/import.d.ts.map +1 -1
- package/dist/cli/commands/init-lexicon.d.ts.map +1 -1
- package/dist/cli/commands/init.d.ts +19 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/onboard.d.ts +9 -0
- package/dist/cli/commands/onboard.d.ts.map +1 -1
- package/dist/cli/commands/pinned-upgrade.d.ts +19 -5
- package/dist/cli/commands/pinned-upgrade.d.ts.map +1 -1
- package/dist/cli/handlers/dev.d.ts.map +1 -1
- package/dist/cli/handlers/lifecycle.d.ts.map +1 -1
- package/dist/cli/handlers/misc.d.ts.map +1 -1
- package/dist/cli/handlers/operator.d.ts +9 -0
- package/dist/cli/handlers/operator.d.ts.map +1 -1
- package/dist/cli/handlers/run.d.ts.map +1 -1
- package/dist/cli/lsp/server.d.ts.map +1 -1
- package/dist/cli/main.d.ts.map +1 -1
- package/dist/cli/mcp/server.d.ts.map +1 -1
- package/dist/cli/mcp/tools/build.d.ts.map +1 -1
- package/dist/cli/mcp/tools/composites.d.ts.map +1 -1
- package/dist/cli/mcp/tools/explain.d.ts.map +1 -1
- package/dist/cli/mcp/tools/import.d.ts.map +1 -1
- package/dist/cli/mcp/tools/lint.d.ts.map +1 -1
- package/dist/cli/mcp/tools/scaffold.d.ts.map +1 -1
- package/dist/cli/mcp/tools/search.d.ts.map +1 -1
- package/dist/cli/mcp/workspace-tools.d.ts +1 -1
- package/dist/cli/mcp/workspace-tools.d.ts.map +1 -1
- package/dist/cli/registry.d.ts +11 -2
- package/dist/cli/registry.d.ts.map +1 -1
- package/dist/codegen/fetch.d.ts.map +1 -1
- package/dist/codegen/naming.d.ts.map +1 -1
- package/dist/codegen/pinned-upgrade.d.ts +67 -3
- package/dist/codegen/pinned-upgrade.d.ts.map +1 -1
- package/dist/codegen/registry.d.ts.map +1 -1
- package/dist/components/capability-plugin-loader.d.ts.map +1 -1
- package/dist/components/capability.d.ts.map +1 -1
- package/dist/components/driver.d.ts.map +1 -1
- package/dist/components/fan-out.d.ts.map +1 -1
- package/dist/components/starter-plugin.d.ts.map +1 -1
- package/dist/components/verbs/process-runner.d.ts.map +1 -1
- package/dist/components/verbs/r2-sync.d.ts.map +1 -1
- package/dist/components/verbs/run-agent.d.ts.map +1 -1
- package/dist/components/verbs/sbom-generator.d.ts.map +1 -1
- package/dist/components/verbs/sign.d.ts.map +1 -1
- package/dist/components/verbs/verify.d.ts.map +1 -1
- package/dist/components/verbs/vuln-gate.d.ts.map +1 -1
- package/dist/components/verbs/vuln-scan.d.ts.map +1 -1
- package/dist/components/verbs/wrangler.d.ts.map +1 -1
- package/dist/composite.d.ts.map +1 -1
- package/dist/config.d.ts +19 -7
- package/dist/config.d.ts.map +1 -1
- package/dist/declarable.d.ts +16 -0
- package/dist/declarable.d.ts.map +1 -1
- package/dist/discovery/cache.d.ts.map +1 -1
- package/dist/discovery/fold-import.d.ts +15 -5
- package/dist/discovery/fold-import.d.ts.map +1 -1
- package/dist/discovery/param-deps.d.ts +16 -0
- package/dist/discovery/param-deps.d.ts.map +1 -1
- package/dist/discovery/sandbox/policy-wire.d.ts.map +1 -1
- package/dist/discovery/specifier-resolve.d.ts +37 -0
- package/dist/discovery/specifier-resolve.d.ts.map +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/fold/fold.d.ts +3 -1
- package/dist/fold/fold.d.ts.map +1 -1
- package/dist/graph-detail.d.ts.map +1 -1
- package/dist/graph-ir.d.ts.map +1 -1
- package/dist/graph-layout.d.ts.map +1 -1
- package/dist/import/base-parser.d.ts.map +1 -1
- package/dist/import/embedded.d.ts +7 -0
- package/dist/import/embedded.d.ts.map +1 -1
- package/dist/import/parser-options.d.ts +14 -0
- package/dist/import/parser-options.d.ts.map +1 -0
- package/dist/import/parser.d.ts +17 -0
- package/dist/import/parser.d.ts.map +1 -1
- package/dist/kubectl-context.d.ts.map +1 -1
- package/dist/lexicon-output.d.ts.map +1 -1
- package/dist/lexicon-schema.d.ts +3 -3
- package/dist/lexicon.d.ts +55 -3
- package/dist/lexicon.d.ts.map +1 -1
- package/dist/lifecycle/assert-live.d.ts.map +1 -1
- package/dist/lifecycle/gate-ledger.d.ts +15 -0
- package/dist/lifecycle/gate-ledger.d.ts.map +1 -1
- package/dist/lifecycle/git.d.ts.map +1 -1
- package/dist/lifecycle/member-ledger.d.ts.map +1 -1
- package/dist/lifecycle/observe.d.ts.map +1 -1
- package/dist/lifecycle/plan-ledger.d.ts.map +1 -1
- package/dist/lifecycle/release-ledger.d.ts.map +1 -1
- package/dist/lifecycle/scenario.d.ts.map +1 -1
- package/dist/lifecycle/status.d.ts.map +1 -1
- package/dist/lifecycle/work-lease.d.ts +61 -2
- package/dist/lifecycle/work-lease.d.ts.map +1 -1
- package/dist/lint/config.d.ts +8 -8
- package/dist/lint/engine.d.ts +6 -0
- package/dist/lint/engine.d.ts.map +1 -1
- package/dist/lsp/lexicon-providers.d.ts.map +1 -1
- package/dist/op/activities/activity-contracts.d.ts +11 -11
- package/dist/op/activities/apply.d.ts +79 -9
- package/dist/op/activities/apply.d.ts.map +1 -1
- package/dist/op/activities/decide.d.ts.map +1 -1
- package/dist/op/activities/index.d.ts +1 -1
- package/dist/op/activities/index.d.ts.map +1 -1
- package/dist/op/activities/lexicon-upgrade.d.ts +44 -12
- package/dist/op/activities/lexicon-upgrade.d.ts.map +1 -1
- package/dist/op/activity-contract.d.ts +1 -1
- package/dist/op/activity-failure.d.ts.map +1 -1
- package/dist/op/activity-profiles.d.ts.map +1 -1
- package/dist/op/builders.d.ts.map +1 -1
- package/dist/op/composites/apply-op.d.ts +12 -5
- package/dist/op/composites/apply-op.d.ts.map +1 -1
- package/dist/op/composites/lexicon-upgrade-op.d.ts +22 -6
- package/dist/op/composites/lexicon-upgrade-op.d.ts.map +1 -1
- package/dist/op/decide-backend.d.ts.map +1 -1
- package/dist/op/decide-read-inputs.d.ts.map +1 -1
- package/dist/op/emulator-lifecycle.d.ts +21 -2
- package/dist/op/emulator-lifecycle.d.ts.map +1 -1
- package/dist/op/gate-approval.d.ts +5 -1
- package/dist/op/gate-approval.d.ts.map +1 -1
- package/dist/op/gate-wait.d.ts.map +1 -1
- package/dist/op/gate.d.ts +19 -3
- package/dist/op/gate.d.ts.map +1 -1
- package/dist/op/index.d.ts +2 -0
- package/dist/op/index.d.ts.map +1 -1
- package/dist/op/local-executor.d.ts +6 -0
- package/dist/op/local-executor.d.ts.map +1 -1
- package/dist/op/operator.d.ts.map +1 -1
- package/dist/op/run-context.d.ts +39 -0
- package/dist/op/run-context.d.ts.map +1 -0
- package/dist/op/run-live.d.ts.map +1 -1
- package/dist/op/runtimes/local.d.ts.map +1 -1
- package/dist/op/source-archive.d.ts.map +1 -1
- package/dist/op/steward-beside.d.ts.map +1 -1
- package/dist/op/steward-points.d.ts.map +1 -1
- package/dist/op/steward.d.ts.map +1 -1
- package/dist/op/types.d.ts +8 -3
- package/dist/op/types.d.ts.map +1 -1
- package/dist/op/work-lease-run.d.ts +24 -4
- package/dist/op/work-lease-run.d.ts.map +1 -1
- package/dist/project-root.d.ts.map +1 -1
- package/dist/provenance.d.ts +21 -0
- package/dist/provenance.d.ts.map +1 -1
- package/dist/pseudo-parameter.d.ts.map +1 -1
- package/dist/reconcile.d.ts.map +1 -1
- package/dist/secret-materialization.d.ts.map +1 -1
- package/dist/terraform/emit-source.d.ts.map +1 -1
- package/dist/terraform/parse.d.ts.map +1 -1
- package/dist/testing.d.ts.map +1 -1
- package/dist/workspace/__fixtures__/contract-repo.d.ts.map +1 -1
- package/dist/workspace/__fixtures__/decide-workspace.d.ts +1 -1
- package/dist/workspace/__fixtures__/decide-workspace.d.ts.map +1 -1
- package/dist/workspace/agent-cli.d.ts +5 -0
- package/dist/workspace/agent-cli.d.ts.map +1 -1
- package/dist/workspace/box-factory.d.ts +73 -0
- package/dist/workspace/box-factory.d.ts.map +1 -0
- package/dist/workspace/changes.d.ts.map +1 -1
- package/dist/workspace/chant-migrations/chud-lexicon-exit.d.ts.map +1 -1
- package/dist/workspace/checks/boxes.d.ts.map +1 -1
- package/dist/workspace/checks.d.ts +5 -0
- package/dist/workspace/checks.d.ts.map +1 -1
- package/dist/workspace/compose-graph.d.ts +10 -0
- package/dist/workspace/compose-graph.d.ts.map +1 -1
- package/dist/workspace/conformance/index.d.ts +67 -6
- package/dist/workspace/conformance/index.d.ts.map +1 -1
- package/dist/workspace/conformance/vitest.d.ts +12 -3
- package/dist/workspace/conformance/vitest.d.ts.map +1 -1
- package/dist/workspace/conformance/writer.d.ts +368 -0
- package/dist/workspace/conformance/writer.d.ts.map +1 -0
- package/dist/workspace/decide.d.ts +1 -1
- package/dist/workspace/decide.d.ts.map +1 -1
- package/dist/workspace/declaration.d.ts +91 -4
- package/dist/workspace/declaration.d.ts.map +1 -1
- package/dist/workspace/declaration.schema.json +234 -5
- package/dist/workspace/generated-files.d.ts.map +1 -1
- package/dist/workspace/graph-cache.d.ts.map +1 -1
- package/dist/workspace/graph-cli.d.ts +2 -0
- package/dist/workspace/graph-cli.d.ts.map +1 -1
- package/dist/workspace/identity.d.ts +111 -0
- package/dist/workspace/identity.d.ts.map +1 -0
- package/dist/workspace/intent-cli.d.ts +7 -4
- package/dist/workspace/intent-cli.d.ts.map +1 -1
- package/dist/workspace/intent-record.d.ts +8 -1
- package/dist/workspace/intent-record.d.ts.map +1 -1
- package/dist/workspace/intent.d.ts +149 -5
- package/dist/workspace/intent.d.ts.map +1 -1
- package/dist/workspace/kinds.d.ts +18 -4
- package/dist/workspace/kinds.d.ts.map +1 -1
- package/dist/workspace/lineage-hash-index.d.ts.map +1 -1
- package/dist/workspace/lineage-lock.d.ts +2 -2
- package/dist/workspace/lineage-lock.d.ts.map +1 -1
- package/dist/workspace/links.d.ts.map +1 -1
- package/dist/workspace/points.d.ts.map +1 -1
- package/dist/workspace/principal-classes.d.ts +114 -0
- package/dist/workspace/principal-classes.d.ts.map +1 -0
- package/dist/workspace/reason-codes.d.ts +21 -1
- package/dist/workspace/reason-codes.d.ts.map +1 -1
- package/dist/workspace/record-assets.d.ts.map +1 -1
- package/dist/workspace/records-checkout.d.ts +54 -0
- package/dist/workspace/records-checkout.d.ts.map +1 -0
- package/dist/workspace/records-cli.d.ts +27 -1
- package/dist/workspace/records-cli.d.ts.map +1 -1
- package/dist/workspace/records-close.d.ts +1 -1
- package/dist/workspace/records-close.d.ts.map +1 -1
- package/dist/workspace/records-since.d.ts.map +1 -1
- package/dist/workspace/records-write.d.ts +5 -4
- package/dist/workspace/records-write.d.ts.map +1 -1
- package/dist/workspace/records.d.ts +15 -0
- package/dist/workspace/records.d.ts.map +1 -1
- package/dist/workspace/runs-cli.d.ts +164 -0
- package/dist/workspace/runs-cli.d.ts.map +1 -0
- package/dist/workspace/runs.d.ts +423 -0
- package/dist/workspace/runs.d.ts.map +1 -0
- package/dist/workspace/source-block.d.ts +1 -1
- package/dist/workspace/source-block.d.ts.map +1 -1
- package/dist/workspace/status-gates.d.ts +15 -3
- package/dist/workspace/status-gates.d.ts.map +1 -1
- package/dist/workspace/status.d.ts +10 -0
- package/dist/workspace/status.d.ts.map +1 -1
- package/dist/workspace/symbols.d.ts +52 -0
- package/dist/workspace/symbols.d.ts.map +1 -0
- package/dist/workspace/trailer-joins.d.ts +46 -0
- package/dist/workspace/trailer-joins.d.ts.map +1 -0
- package/dist/workspace/trailers.d.ts +89 -0
- package/dist/workspace/trailers.d.ts.map +1 -0
- package/dist/workspace/trust/attestor.d.ts.map +1 -1
- package/dist/workspace/trust/rotation.d.ts.map +1 -1
- package/dist/workspace/trust/seal.d.ts +33 -0
- package/dist/workspace/trust/seal.d.ts.map +1 -1
- package/dist/workspace/trust/test-repo.d.ts.map +1 -1
- package/dist/workspace/work-cli.d.ts +39 -3
- package/dist/workspace/work-cli.d.ts.map +1 -1
- package/dist/workspace/work-evidence.d.ts +1 -1
- package/dist/workspace/work-evidence.d.ts.map +1 -1
- package/dist/workspace/work.d.ts +26 -1
- package/dist/workspace/work.d.ts.map +1 -1
- package/dist/workspace/workspace-principals.schema.json +60 -0
- package/dist/workspace/write-scope.d.ts +79 -19
- package/dist/workspace/write-scope.d.ts.map +1 -1
- package/dist/yaml.d.ts +21 -39
- package/dist/yaml.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/audit/prior-art.ts +15 -0
- package/src/cli/commands/__fixtures__/init-lexicon-output/package.json +1 -1
- package/src/cli/commands/carve-emit-state.test.ts +4 -0
- package/src/cli/commands/carve-emit.ts +5 -19
- package/src/cli/commands/check-lexicon.test.ts +62 -1
- package/src/cli/commands/check-lexicon.ts +36 -6
- package/src/cli/commands/import-live.test.ts +18 -0
- package/src/cli/commands/import-parser-options.test.ts +133 -0
- package/src/cli/commands/import.ts +21 -3
- package/src/cli/commands/init-lexicon/templates/project.ts +1 -1
- package/src/cli/commands/init.test.ts +8 -1
- package/src/cli/commands/init.ts +23 -8
- package/src/cli/commands/lint.test.ts +37 -0
- package/src/cli/commands/onboard.test.ts +53 -3
- package/src/cli/commands/onboard.ts +52 -4
- package/src/cli/commands/pinned-upgrade.ts +73 -33
- package/src/cli/handlers/__snapshots__/build-member.test.ts.snap +2 -2
- package/src/cli/handlers/components.ts +2 -2
- package/src/cli/handlers/dev.ts +8 -6
- package/src/cli/handlers/lifecycle.test.ts +67 -0
- package/src/cli/handlers/lifecycle.ts +6 -5
- package/src/cli/handlers/misc.ts +2 -0
- package/src/cli/handlers/operator.ts +87 -3
- package/src/cli/handlers/run.test.ts +111 -0
- package/src/cli/handlers/run.ts +85 -24
- package/src/cli/handlers/scenario.ts +2 -2
- package/src/cli/main.test.ts +1 -0
- package/src/cli/main.ts +65 -11
- package/src/cli/mcp/workspace-tools.test.ts +5 -2
- package/src/cli/mcp/workspace-tools.ts +29 -2
- package/src/cli/registry.ts +11 -2
- package/src/codegen/pinned-upgrade-multi.test.ts +157 -0
- package/src/codegen/pinned-upgrade-tags.test.ts +112 -0
- package/src/codegen/pinned-upgrade.test.ts +104 -0
- package/src/codegen/pinned-upgrade.ts +250 -56
- package/src/codegen/testdata/postgres-tags.json +242 -0
- package/src/config.test.ts +21 -0
- package/src/config.ts +15 -0
- package/src/declarable.test.ts +21 -0
- package/src/declarable.ts +19 -0
- package/src/discovery/fold-composite.test.ts +41 -5
- package/src/discovery/fold-import.test.ts +129 -0
- package/src/discovery/fold-import.ts +643 -131
- package/src/discovery/fold-package-composite.test.ts +264 -0
- package/src/discovery/fold-specifiers.test.ts +191 -0
- package/src/discovery/param-deps.test.ts +66 -1
- package/src/discovery/param-deps.ts +45 -0
- package/src/discovery/specifier-resolve.ts +344 -0
- package/src/fold/fold.test.ts +39 -1
- package/src/fold/fold.ts +83 -9
- package/src/fold-provenance.test.ts +140 -0
- package/src/graph-ir.test.ts +83 -0
- package/src/graph-ir.ts +29 -0
- package/src/import/embedded.test.ts +20 -0
- package/src/import/embedded.ts +13 -0
- package/src/import/parser-options.ts +46 -0
- package/src/import/parser.ts +20 -0
- package/src/lexicon.ts +55 -3
- package/src/lifecycle/gate-ledger.ts +16 -0
- package/src/lifecycle/observe.test.ts +18 -0
- package/src/lifecycle/observe.ts +6 -4
- package/src/lifecycle/snapshot.ts +2 -2
- package/src/lifecycle/work-lease.test.ts +1 -1
- package/src/lifecycle/work-lease.ts +93 -2
- package/src/lint/engine.test.ts +55 -0
- package/src/lint/engine.ts +30 -4
- package/src/lint/output-docs.test.ts +59 -56
- package/src/op/activities/apply.test.ts +189 -5
- package/src/op/activities/apply.ts +230 -8
- package/src/op/activities/index.ts +3 -0
- package/src/op/activities/lexicon-upgrade.test.ts +160 -6
- package/src/op/activities/lexicon-upgrade.ts +154 -51
- package/src/op/composites/apply-op.ts +12 -5
- package/src/op/composites/composites.test.ts +30 -3
- package/src/op/composites/lexicon-upgrade-op.test.ts +7 -2
- package/src/op/composites/lexicon-upgrade-op.ts +29 -8
- package/src/op/emulator-lifecycle.test.ts +23 -0
- package/src/op/emulator-lifecycle.ts +52 -14
- package/src/op/gate-approval.test.ts +74 -0
- package/src/op/gate-approval.ts +5 -1
- package/src/op/gate.ts +31 -5
- package/src/op/index.ts +2 -0
- package/src/op/local-executor.test.ts +15 -0
- package/src/op/local-executor.ts +40 -12
- package/src/op/local-output.ts +1 -1
- package/src/op/operator.ts +4 -0
- package/src/op/run-context.test.ts +141 -0
- package/src/op/run-context.ts +51 -0
- package/src/op/runtimes/local.test.ts +14 -0
- package/src/op/runtimes/local.ts +2 -0
- package/src/op/steward-beside.ts +2 -0
- package/src/op/types.ts +8 -3
- package/src/op/work-lease-run.test.ts +47 -0
- package/src/op/work-lease-run.ts +73 -11
- package/src/provenance.ts +35 -0
- package/src/workspace/__fixtures__/studio-template-84c8b21.json +1 -1
- package/src/workspace/agent-cli.ts +7 -3
- package/src/workspace/agent.schema.json +22 -0
- package/src/workspace/box-factory.test.ts +320 -0
- package/src/workspace/box-factory.ts +103 -0
- package/src/workspace/changes.schema.json +12 -20
- package/src/workspace/changes.ts +4 -1
- package/src/workspace/checks/boxes.test.ts +2 -0
- package/src/workspace/checks.ts +29 -5
- package/src/workspace/compose-graph.ts +7 -0
- package/src/workspace/conformance/__writer_fixture__/answers/answer.kind.mjs +27 -0
- package/src/workspace/conformance/__writer_fixture__/answers/answer.schema.json +95 -0
- package/src/workspace/conformance/__writer_fixture__/decisions/points.json +132 -0
- package/src/workspace/conformance/__writer_fixture__/sessions/session.kind.mjs +48 -0
- package/src/workspace/conformance/__writer_fixture__/sessions/session.schema.json +108 -0
- package/src/workspace/conformance/__writer_fixture__/work/W-001-the-writer-suite-works-this-item.md +25 -0
- package/src/workspace/conformance/__writer_fixture__/work/work.kind.mjs +60 -0
- package/src/workspace/conformance/__writer_fixture__/work/work.schema.json +578 -0
- package/src/workspace/conformance/conformance.e2e.test.ts +35 -3
- package/src/workspace/conformance/index.mjs +30 -3
- package/src/workspace/conformance/index.ts +103 -15
- package/src/workspace/conformance/vitest.ts +44 -2
- package/src/workspace/conformance/writer-conformance.e2e.test.ts +131 -0
- package/src/workspace/conformance/writer.test.ts +156 -0
- package/src/workspace/conformance/writer.ts +880 -0
- package/src/workspace/decide.ts +7 -1
- package/src/workspace/declaration.schema.json +234 -5
- package/src/workspace/declaration.ts +174 -10
- package/src/workspace/graph-cli.ts +5 -2
- package/src/workspace/graph.schema.json +247 -0
- package/src/workspace/identity.test.ts +196 -0
- package/src/workspace/identity.ts +186 -0
- package/src/workspace/intent-cli.ts +64 -10
- package/src/workspace/intent-record.schema.json +208 -0
- package/src/workspace/intent-record.ts +35 -1
- package/src/workspace/intent-why.test.ts +274 -0
- package/src/workspace/intent.schema.json +718 -7
- package/src/workspace/intent.test.ts +11 -2
- package/src/workspace/intent.ts +495 -32
- package/src/workspace/kinds.ts +44 -37
- package/src/workspace/points-write.schema.json +1 -0
- package/src/workspace/principal-classes.test.ts +175 -0
- package/src/workspace/principal-classes.ts +307 -0
- package/src/workspace/reason-codes.test.ts +11 -3
- package/src/workspace/reason-codes.ts +24 -1
- package/src/workspace/records-amend.schema.json +2 -0
- package/src/workspace/records-checkout.ts +106 -0
- package/src/workspace/records-cli.ts +103 -11
- package/src/workspace/records-close.schema.json +1 -0
- package/src/workspace/records-new.schema.json +2 -0
- package/src/workspace/records-review.schema.json +2 -0
- package/src/workspace/records-uncommitted.test.ts +171 -0
- package/src/workspace/records-write.ts +28 -6
- package/src/workspace/records.schema.json +72 -1
- package/src/workspace/records.ts +27 -0
- package/src/workspace/runs-cli.ts +381 -0
- package/src/workspace/runs-write.schema.json +583 -0
- package/src/workspace/runs.schema.json +810 -0
- package/src/workspace/runs.test.ts +242 -0
- package/src/workspace/runs.ts +709 -0
- package/src/workspace/status-contract.test.ts +5 -0
- package/src/workspace/status-gates.ts +22 -8
- package/src/workspace/status.schema.json +127 -2
- package/src/workspace/status.ts +21 -1
- package/src/workspace/symbols.ts +180 -0
- package/src/workspace/trailer-joins.test.ts +171 -0
- package/src/workspace/trailer-joins.ts +82 -0
- package/src/workspace/trailers.ts +148 -0
- package/src/workspace/trust/seal.ts +52 -1
- package/src/workspace/work-cli.e2e.test.ts +28 -1
- package/src/workspace/work-cli.ts +133 -8
- package/src/workspace/work-evidence.schema.json +2 -0
- package/src/workspace/work-history.schema.json +73 -1
- package/src/workspace/work-history.test.ts +48 -5
- package/src/workspace/work-kind-fields.test.ts +154 -0
- package/src/workspace/work-lease.schema.json +14 -1
- package/src/workspace/work.ts +82 -0
- package/src/workspace/workspace-principals.schema.json +60 -0
- package/src/workspace/write-scope.test.ts +128 -2
- package/src/workspace/write-scope.ts +170 -45
- package/src/yaml.test.ts +111 -1
- package/src/yaml.ts +141 -549
|
@@ -0,0 +1,880 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace writer conformance (#3159, ws-074).
|
|
3
|
+
*
|
|
4
|
+
* The repo is the database (ws-074): every durable fact about a workspace is
|
|
5
|
+
* a file in the repository or a line on its ledger branch, written only
|
|
6
|
+
* through chant's write contract, and a tool keeps nothing but secrets,
|
|
7
|
+
* telemetry, caches and its substrate's runtime state outside it. The reader
|
|
8
|
+
* suite beside this module holds a reader to the read contract. This one
|
|
9
|
+
* holds a writer, such as hud or studio's factory, to the write contract:
|
|
10
|
+
*
|
|
11
|
+
* 1. Writes go through chant. The suite drives a script of writes
|
|
12
|
+
* ({@link WRITER_SCRIPT}) through the writer's `write(step)`. Each step
|
|
13
|
+
* must make exactly one chant call, the step's write-contract command
|
|
14
|
+
* with its arguments (and its JSON flag, where the command has one),
|
|
15
|
+
* giving chant the step's fields on stdin. The document the writer
|
|
16
|
+
* returns is the one chant printed, it validates against the command's
|
|
17
|
+
* output schema, and it is not a refusal.
|
|
18
|
+
* 2. Every change is chant's. The workspace's files (outside `.git`) and its
|
|
19
|
+
* git refs are read before and after each step. A file may change only
|
|
20
|
+
* when it is the path the command reports writing, and a ref only when
|
|
21
|
+
* it is the lease ref or the `chant/lifecycle` commit the command
|
|
22
|
+
* reports.
|
|
23
|
+
* 3. Amnesia. The writer is given a state directory of its own, outside
|
|
24
|
+
* the workspace, and declares what it keeps there (`privateState`). After
|
|
25
|
+
* the script the suite asks the writer for the facts it shows
|
|
26
|
+
* (`facts()`), closes it, deletes everything in the state directory,
|
|
27
|
+
* builds the writer again and asks again: the two answers must be equal.
|
|
28
|
+
* The suite also reads every fact the script produced back through the
|
|
29
|
+
* read contract, the uncommitted records included.
|
|
30
|
+
* 4. No facts outside the repo. A file left in the state directory that
|
|
31
|
+
* `privateState` does not declare is a problem, and so is an entry of
|
|
32
|
+
* the writer's optional `holds()` that names a record, run or lease the
|
|
33
|
+
* repository does not have, unless it names itself one of the four
|
|
34
|
+
* exceptions.
|
|
35
|
+
*
|
|
36
|
+
* `facts()` may only read: every chant call it makes must be a read-contract
|
|
37
|
+
* command, and it must leave the workspace as it was.
|
|
38
|
+
*
|
|
39
|
+
* The workspace is generated for each run, from the reader suite's fixture
|
|
40
|
+
* and the `__writer_fixture__/` overlay this package ships beside this module:
|
|
41
|
+
* the reference workspace's work, answer and session kinds, its decision
|
|
42
|
+
* points, and one open work item, W-001. Nothing is written anywhere else.
|
|
43
|
+
*
|
|
44
|
+
* Actions a writer does not list in `actions` are not applicable to it. The
|
|
45
|
+
* suite still performs those steps itself, directly through chant, so a later
|
|
46
|
+
* step that depends on one (an amend on the decision a `records new` made,
|
|
47
|
+
* an evidence entry under a claimed lease) has what it needs.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
import { execFileSync } from "node:child_process";
|
|
51
|
+
import { createHash } from "node:crypto";
|
|
52
|
+
import { cpSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
53
|
+
import { createRequire } from "node:module";
|
|
54
|
+
import { tmpdir } from "node:os";
|
|
55
|
+
import { dirname, join, resolve } from "node:path";
|
|
56
|
+
import { fileURLToPath } from "node:url";
|
|
57
|
+
import { isDeepStrictEqual } from "node:util";
|
|
58
|
+
import { createConformanceWorkspace, defaultChantCommand, runChant, treeChanges, type ChantRun, type ChantTransport } from "./index";
|
|
59
|
+
|
|
60
|
+
// Nothing at the top level of this module may use a binding imported from
|
|
61
|
+
// ./index: index re-exports this module, so this module is evaluated first.
|
|
62
|
+
|
|
63
|
+
/** The write-contract commands a writer performs, as the suite names them. */
|
|
64
|
+
export const WRITE_CONTRACT_ACTIONS = [
|
|
65
|
+
"records new",
|
|
66
|
+
"records amend",
|
|
67
|
+
"records review",
|
|
68
|
+
"records close",
|
|
69
|
+
"points ask",
|
|
70
|
+
"points answer",
|
|
71
|
+
"work claim",
|
|
72
|
+
"work renew",
|
|
73
|
+
"work evidence",
|
|
74
|
+
"work release",
|
|
75
|
+
"runs start",
|
|
76
|
+
"runs end",
|
|
77
|
+
"runs record",
|
|
78
|
+
] as const;
|
|
79
|
+
export type WriteContractAction = (typeof WRITE_CONTRACT_ACTIONS)[number];
|
|
80
|
+
|
|
81
|
+
/** Each action's output schema, in `src/workspace/` beside this module's directory. */
|
|
82
|
+
export const WRITE_CONTRACT_SCHEMAS: Record<WriteContractAction, string> = {
|
|
83
|
+
"records new": "records-new.schema.json",
|
|
84
|
+
"records amend": "records-amend.schema.json",
|
|
85
|
+
"records review": "records-review.schema.json",
|
|
86
|
+
"records close": "records-close.schema.json",
|
|
87
|
+
"points ask": "points-write.schema.json",
|
|
88
|
+
"points answer": "points-write.schema.json",
|
|
89
|
+
"work claim": "work-lease.schema.json",
|
|
90
|
+
"work renew": "work-lease.schema.json",
|
|
91
|
+
"work evidence": "work-evidence.schema.json",
|
|
92
|
+
"work release": "work-lease.schema.json",
|
|
93
|
+
"runs start": "runs-write.schema.json",
|
|
94
|
+
"runs end": "runs-write.schema.json",
|
|
95
|
+
"runs record": "runs-write.schema.json",
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The flags a writer may add to each command. The record, points, evidence
|
|
100
|
+
* and run writes always print their document, so a writer adds nothing or
|
|
101
|
+
* `--json`; a lease prints its document only with `--json`.
|
|
102
|
+
*/
|
|
103
|
+
export const WRITE_CONTRACT_JSON_FLAGS: Record<WriteContractAction, readonly (readonly string[])[]> = {
|
|
104
|
+
"records new": [[], ["--json"]],
|
|
105
|
+
"records amend": [[], ["--json"]],
|
|
106
|
+
"records review": [[], ["--json"]],
|
|
107
|
+
"records close": [[], ["--json"]],
|
|
108
|
+
"points ask": [[], ["--json"]],
|
|
109
|
+
"points answer": [[], ["--json"]],
|
|
110
|
+
"work claim": [["--json"]],
|
|
111
|
+
"work renew": [["--json"]],
|
|
112
|
+
"work evidence": [[], ["--json"]],
|
|
113
|
+
"work release": [["--json"]],
|
|
114
|
+
"runs start": [[], ["--json"]],
|
|
115
|
+
"runs end": [[], ["--json"]],
|
|
116
|
+
"runs record": [[], ["--json"]],
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/** What each action is given. Field documents are JSON values; the command reads them from stdin. */
|
|
120
|
+
export interface WriteParams {
|
|
121
|
+
"records new": { kind: string; fields: Record<string, unknown> };
|
|
122
|
+
"records amend": { id: string; kind: string; fields: Record<string, unknown> };
|
|
123
|
+
"records review": { id: string; kind: string; verdict: "agree" | "dissent" | "abstain"; by: string; note?: string };
|
|
124
|
+
"records close": { id: string; kind: string };
|
|
125
|
+
"points ask": { point: string; kind: string; inputs: Record<string, unknown>; subject?: string };
|
|
126
|
+
"points answer": { id: string; kind: string; answer: string; by: string };
|
|
127
|
+
"work claim": { id: string; kind: string; holder: string };
|
|
128
|
+
"work renew": { id: string; kind: string; holder: string; token: string };
|
|
129
|
+
"work evidence": { id: string; kind: string; holder: string; token: string; entry: Record<string, unknown> };
|
|
130
|
+
"work release": { id: string; kind: string; holder: string; token: string; outcome: string };
|
|
131
|
+
"runs start": { run: Record<string, unknown> };
|
|
132
|
+
"runs end": { id: string; fields: Record<string, unknown> };
|
|
133
|
+
"runs record": { run: Record<string, unknown> };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** One write the suite asks of the writer: the action, what it is given, and the command that performs it. */
|
|
137
|
+
export type WriteStep = {
|
|
138
|
+
[A in WriteContractAction]: {
|
|
139
|
+
/** The step's name in the script, such as `review`. */
|
|
140
|
+
id: string;
|
|
141
|
+
action: A;
|
|
142
|
+
params: WriteParams[A];
|
|
143
|
+
/** The arguments after `chant workspace <action>`, as {@link writeArgv} builds them from `params`. */
|
|
144
|
+
args: string[];
|
|
145
|
+
/** What the command reads on stdin (`--from -`, `--set -`, `--inputs -`), when it reads anything. */
|
|
146
|
+
input?: string;
|
|
147
|
+
};
|
|
148
|
+
}[WriteContractAction];
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* The arguments that perform `action` with `params`, after `chant workspace
|
|
152
|
+
* <action>`, and the JSON the command reads on stdin. A writer can build its
|
|
153
|
+
* calls with this, or with its own code that makes the same call.
|
|
154
|
+
*/
|
|
155
|
+
export function writeArgv<A extends WriteContractAction>(action: A, params: WriteParams[A]): { args: string[]; input?: string } {
|
|
156
|
+
const p = params as WriteParams[WriteContractAction] & Record<string, unknown>;
|
|
157
|
+
const json = (v: unknown) => JSON.stringify(v);
|
|
158
|
+
switch (action) {
|
|
159
|
+
case "records new": {
|
|
160
|
+
const q = p as WriteParams["records new"];
|
|
161
|
+
return { args: [q.kind, "--from", "-"], input: json(q.fields) };
|
|
162
|
+
}
|
|
163
|
+
case "records amend": {
|
|
164
|
+
const q = p as WriteParams["records amend"];
|
|
165
|
+
return { args: [q.id, "--kind", q.kind, "--set", "-"], input: json(q.fields) };
|
|
166
|
+
}
|
|
167
|
+
case "records review": {
|
|
168
|
+
const q = p as WriteParams["records review"];
|
|
169
|
+
return { args: [q.id, "--kind", q.kind, "--verdict", q.verdict, "--by", q.by, ...(q.note !== undefined ? ["--note", q.note] : [])] };
|
|
170
|
+
}
|
|
171
|
+
case "records close": {
|
|
172
|
+
const q = p as WriteParams["records close"];
|
|
173
|
+
return { args: [q.id, "--kind", q.kind] };
|
|
174
|
+
}
|
|
175
|
+
case "points ask": {
|
|
176
|
+
const q = p as WriteParams["points ask"];
|
|
177
|
+
return { args: [q.point, "--inputs", "-", ...(q.subject !== undefined ? ["--subject", q.subject] : []), "--kind", q.kind], input: json(q.inputs) };
|
|
178
|
+
}
|
|
179
|
+
case "points answer": {
|
|
180
|
+
const q = p as WriteParams["points answer"];
|
|
181
|
+
return { args: [q.id, "--answer", q.answer, "--by", q.by, "--kind", q.kind] };
|
|
182
|
+
}
|
|
183
|
+
case "work claim": {
|
|
184
|
+
const q = p as WriteParams["work claim"];
|
|
185
|
+
return { args: [q.id, "--holder", q.holder, "--kind", q.kind] };
|
|
186
|
+
}
|
|
187
|
+
case "work renew": {
|
|
188
|
+
const q = p as WriteParams["work renew"];
|
|
189
|
+
return { args: [q.id, "--holder", q.holder, "--token", q.token, "--kind", q.kind] };
|
|
190
|
+
}
|
|
191
|
+
case "work evidence": {
|
|
192
|
+
const q = p as WriteParams["work evidence"];
|
|
193
|
+
return { args: [q.id, "--holder", q.holder, "--token", q.token, "--from", "-", "--kind", q.kind], input: json(q.entry) };
|
|
194
|
+
}
|
|
195
|
+
case "work release": {
|
|
196
|
+
const q = p as WriteParams["work release"];
|
|
197
|
+
return { args: [q.id, "--holder", q.holder, "--token", q.token, "--outcome", q.outcome, "--kind", q.kind] };
|
|
198
|
+
}
|
|
199
|
+
case "runs start":
|
|
200
|
+
case "runs record": {
|
|
201
|
+
const q = p as WriteParams["runs start"];
|
|
202
|
+
return { args: ["--from", "-"], input: json(q.run) };
|
|
203
|
+
}
|
|
204
|
+
case "runs end": {
|
|
205
|
+
const q = p as WriteParams["runs end"];
|
|
206
|
+
return { args: [q.id, "--from", "-"], input: json(q.fields) };
|
|
207
|
+
}
|
|
208
|
+
default:
|
|
209
|
+
throw new Error(`not a write-contract action: ${String(action)}`);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** The kind files of the writer workspace, from its root. */
|
|
214
|
+
export const WRITER_KINDS = {
|
|
215
|
+
decision: "decisions/decision.kind.mjs",
|
|
216
|
+
session: "sessions/session.kind.mjs",
|
|
217
|
+
answer: "answers/answer.kind.mjs",
|
|
218
|
+
work: "work/work.kind.mjs",
|
|
219
|
+
} as const;
|
|
220
|
+
|
|
221
|
+
/** The principals the script writes as. */
|
|
222
|
+
export const WRITER_PRINCIPALS = { holder: "conformance-writer", reviewer: "conformance-reviewer", by: "conformance" } as const;
|
|
223
|
+
|
|
224
|
+
/** One step of the script: its name, its action, and its params from the documents of the steps before it. */
|
|
225
|
+
export interface WriterScriptStep<A extends WriteContractAction = WriteContractAction> {
|
|
226
|
+
id: string;
|
|
227
|
+
action: A;
|
|
228
|
+
params(done: Record<string, Record<string, unknown>>): WriteParams[A];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const step = <A extends WriteContractAction>(id: string, action: A, params: (done: Record<string, Record<string, unknown>>) => WriteParams[A]): WriterScriptStep => ({ id, action, params }) as WriterScriptStep;
|
|
232
|
+
|
|
233
|
+
const leaseToken = (done: Record<string, Record<string, unknown>>): string => String((done.claim?.lease as { token?: unknown } | undefined)?.token ?? "");
|
|
234
|
+
const RUN_STARTED = { harness: { name: "conformance", version: "1" }, model: "none", provider: "none", by: WRITER_PRINCIPALS.by, unit: "W-001" };
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* The writes the suite drives, in order, each action at least once: a
|
|
238
|
+
* decision made, amended and reviewed; a review session opened and closed; a
|
|
239
|
+
* decision point asked and answered; the work item's lease claimed, renewed,
|
|
240
|
+
* evidence attached under it and released; one run started and ended, and one
|
|
241
|
+
* recorded whole.
|
|
242
|
+
*/
|
|
243
|
+
export const WRITER_SCRIPT: readonly WriterScriptStep[] = [
|
|
244
|
+
step("decision", "records new", () => ({
|
|
245
|
+
kind: WRITER_KINDS.decision,
|
|
246
|
+
fields: {
|
|
247
|
+
schema: 1,
|
|
248
|
+
title: "How a writer writes the workspace",
|
|
249
|
+
state: "proposed",
|
|
250
|
+
area: "delivery",
|
|
251
|
+
source: { kind: "workspace", member: "delivery" },
|
|
252
|
+
question: "How does a tool write a fact about this workspace?",
|
|
253
|
+
options: [{ id: "a", label: "through chant's write contract", how: "Each fact is one chant write command.", tradeoff: "One chant call per fact." }],
|
|
254
|
+
choice: null,
|
|
255
|
+
rejected: [],
|
|
256
|
+
supersedes: [],
|
|
257
|
+
evidence: [{ title: "INTENTIUS/chant#3159, the writer conformance suite", url: "https://github.com/INTENTIUS/chant/issues/3159" }],
|
|
258
|
+
decided_by: null,
|
|
259
|
+
decided_on: null,
|
|
260
|
+
reviews: [],
|
|
261
|
+
constrains: ["member:delivery"],
|
|
262
|
+
},
|
|
263
|
+
})),
|
|
264
|
+
step("amend", "records amend", (d) => ({ id: String(d.decision.id), kind: WRITER_KINDS.decision, fields: { title: "How a writer writes the workspace, through chant" } })),
|
|
265
|
+
step("review", "records review", (d) => ({ id: String(d.decision.id), kind: WRITER_KINDS.decision, verdict: "agree", by: WRITER_PRINCIPALS.reviewer, note: "Written through chant, read back after amnesia." })),
|
|
266
|
+
step("session", "records new", (d) => ({
|
|
267
|
+
kind: WRITER_KINDS.session,
|
|
268
|
+
fields: {
|
|
269
|
+
schema: 1,
|
|
270
|
+
id: "S-0001",
|
|
271
|
+
title: "The writer suite walks its decision",
|
|
272
|
+
state: "open",
|
|
273
|
+
agenda: [{ record: String(d.decision.id) }],
|
|
274
|
+
attendance: [{ principal: WRITER_PRINCIPALS.reviewer, class: "person" }],
|
|
275
|
+
opened: "2026-01-01T00:00:00Z",
|
|
276
|
+
closed: null,
|
|
277
|
+
verdicts: [],
|
|
278
|
+
},
|
|
279
|
+
})),
|
|
280
|
+
step("close", "records close", (d) => ({ id: String(d.session.id), kind: WRITER_KINDS.session })),
|
|
281
|
+
step("ask", "points ask", () => ({
|
|
282
|
+
point: "slice-tier",
|
|
283
|
+
kind: WRITER_KINDS.answer,
|
|
284
|
+
subject: "W-001",
|
|
285
|
+
inputs: { "work-item.criteria": 1, "work-item.files": 1, "work-item.words": 40, "work-item.fits_small": false, "work-item.fits_medium": false },
|
|
286
|
+
})),
|
|
287
|
+
step("answer", "points answer", (d) => ({ id: String(d.ask.id), kind: WRITER_KINDS.answer, answer: "medium", by: WRITER_PRINCIPALS.reviewer })),
|
|
288
|
+
step("claim", "work claim", () => ({ id: "W-001", kind: WRITER_KINDS.work, holder: WRITER_PRINCIPALS.holder })),
|
|
289
|
+
step("renew", "work renew", (d) => ({ id: "W-001", kind: WRITER_KINDS.work, holder: WRITER_PRINCIPALS.holder, token: leaseToken(d) })),
|
|
290
|
+
step("evidence", "work evidence", (d) => ({
|
|
291
|
+
id: "W-001",
|
|
292
|
+
kind: WRITER_KINDS.work,
|
|
293
|
+
holder: WRITER_PRINCIPALS.holder,
|
|
294
|
+
token: leaseToken(d),
|
|
295
|
+
entry: { criterion: "AC-1", result: "pass", title: "The writer conformance suite's evidence step", url: "https://github.com/INTENTIUS/chant/issues/3159" },
|
|
296
|
+
})),
|
|
297
|
+
step("release", "work release", (d) => ({ id: "W-001", kind: WRITER_KINDS.work, holder: WRITER_PRINCIPALS.holder, token: leaseToken(d), outcome: "done" })),
|
|
298
|
+
step("run-start", "runs start", () => ({ run: { id: "writer-run-1", startedAt: "2026-01-01T00:00:00Z", ...RUN_STARTED } })),
|
|
299
|
+
step("run-end", "runs end", (d) => ({
|
|
300
|
+
id: String((d["run-start"].run as { id?: unknown }).id),
|
|
301
|
+
fields: { endedAt: "2026-01-01T00:05:00Z", outcome: "done", usage: { turns: 2, inputTokens: 100, outputTokens: 50 }, cost: { amount: 0.02, currency: "USD", source: "conformance" }, commits: [] },
|
|
302
|
+
})),
|
|
303
|
+
step("run-record", "runs record", () => ({
|
|
304
|
+
run: {
|
|
305
|
+
id: "writer-run-2",
|
|
306
|
+
startedAt: "2026-01-01T01:00:00Z",
|
|
307
|
+
endedAt: "2026-01-01T01:01:00Z",
|
|
308
|
+
outcome: "done",
|
|
309
|
+
usage: { turns: 1, inputTokens: 10, outputTokens: 5 },
|
|
310
|
+
cost: { amount: 0.01, currency: "USD", source: "conformance" },
|
|
311
|
+
commits: [],
|
|
312
|
+
...RUN_STARTED,
|
|
313
|
+
},
|
|
314
|
+
})),
|
|
315
|
+
];
|
|
316
|
+
|
|
317
|
+
/** The four things ws-074 lets a tool keep outside the repo. */
|
|
318
|
+
export const PRIVATE_STATE_CATEGORIES = ["cache", "telemetry", "secret", "runtime"] as const;
|
|
319
|
+
export type PrivateStateCategory = (typeof PRIVATE_STATE_CATEGORIES)[number];
|
|
320
|
+
|
|
321
|
+
/** A file or directory the writer keeps in its state directory, and which of the four it is. */
|
|
322
|
+
export interface PrivateStatePath {
|
|
323
|
+
/** From the state directory, with / separators. A directory covers everything under it. */
|
|
324
|
+
path: string;
|
|
325
|
+
is: PrivateStateCategory | readonly PrivateStateCategory[];
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** One thing the writer holds, as its `holds()` reports it. */
|
|
329
|
+
export type HeldItem =
|
|
330
|
+
| { record: string; kind: string }
|
|
331
|
+
| { run: string }
|
|
332
|
+
| { lease: string; kind: string }
|
|
333
|
+
| { exempt: PrivateStateCategory; what: string };
|
|
334
|
+
|
|
335
|
+
export interface WorkspaceWriter {
|
|
336
|
+
/** Perform one step: run its write-contract command through the transport, and return the parsed document chant printed. */
|
|
337
|
+
write(step: WriteStep): Promise<unknown> | unknown;
|
|
338
|
+
/**
|
|
339
|
+
* The facts the tool shows, read the way the tool reads them, as a JSON
|
|
340
|
+
* value. The suite compares the answer before and after amnesia. It may make
|
|
341
|
+
* read-contract calls only.
|
|
342
|
+
*/
|
|
343
|
+
facts(): Promise<unknown> | unknown;
|
|
344
|
+
/** Optional: what the tool holds, each entry a record, run or lease in the repo, or one of the four exceptions. */
|
|
345
|
+
holds?(): Promise<readonly HeldItem[]> | readonly HeldItem[];
|
|
346
|
+
/** Optional: let go of the state directory (close a database) before the suite deletes it. */
|
|
347
|
+
close?(): Promise<void> | void;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export interface WriterContext {
|
|
351
|
+
/**
|
|
352
|
+
* A directory the writer keeps its private state in, such as a database
|
|
353
|
+
* file. The suite makes it, outside the workspace, and the same one is given
|
|
354
|
+
* to the writer built again after amnesia.
|
|
355
|
+
*/
|
|
356
|
+
stateDir: string;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** Build the writer over the transport the suite gives it. Called twice: before the script, and again after amnesia. */
|
|
360
|
+
export type WorkspaceWriterFactory = (chant: ChantTransport, context: WriterContext) => WorkspaceWriter;
|
|
361
|
+
|
|
362
|
+
export interface WorkspaceWriterConformanceOptions {
|
|
363
|
+
/** The actions the writer performs. The suite performs the other steps itself. Defaults to every action. */
|
|
364
|
+
actions?: readonly WriteContractAction[];
|
|
365
|
+
/** What the writer keeps in its state directory. Anything else left there is a problem. Defaults to nothing. */
|
|
366
|
+
privateState?: readonly PrivateStatePath[];
|
|
367
|
+
/** The chant to run, as a command and its leading arguments. The reader suite's default. */
|
|
368
|
+
chantCommand?: string[];
|
|
369
|
+
/** How long one chant run may take, in milliseconds. Default 120000. */
|
|
370
|
+
timeoutMs?: number;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export interface WorkspaceWriterConformanceConfig extends WorkspaceWriterConformanceOptions {
|
|
374
|
+
/** Short label, used in the suite name. */
|
|
375
|
+
name: string;
|
|
376
|
+
writer: WorkspaceWriterFactory;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/** What one step found. */
|
|
380
|
+
export interface WriterStepResult {
|
|
381
|
+
id: string;
|
|
382
|
+
action: WriteContractAction;
|
|
383
|
+
/** Whether the writer performed it, or the suite did because the action is not the writer's. */
|
|
384
|
+
by: "writer" | "suite";
|
|
385
|
+
args: string[];
|
|
386
|
+
problems: string[];
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/** What {@link runWorkspaceWriterConformance} found. The writer conforms when `problems` is empty. */
|
|
390
|
+
export interface WorkspaceWriterConformanceReport {
|
|
391
|
+
/** Every problem, each starting with the step it concerns, or `amnesia:`, `facts:`, `state:`, `holds:` or `read back:`. */
|
|
392
|
+
problems: string[];
|
|
393
|
+
/** The actions the writer performed, in contract order. */
|
|
394
|
+
checked: WriteContractAction[];
|
|
395
|
+
/** The actions not in `actions`, so not applicable to this writer. */
|
|
396
|
+
skipped: WriteContractAction[];
|
|
397
|
+
results: WriterStepResult[];
|
|
398
|
+
/** The problems of the checks after the script, by check. */
|
|
399
|
+
after: { facts: string[]; state: string[]; amnesia: string[]; holds: string[]; readBack: string[] };
|
|
400
|
+
/** What `facts()` returned before amnesia and after. */
|
|
401
|
+
facts: { before: unknown; after: unknown };
|
|
402
|
+
/** The workspace written. Removed before the report is returned. */
|
|
403
|
+
workspaceDir: string;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
407
|
+
const workspaceSrc = resolve(here, "..");
|
|
408
|
+
/** The overlay the writer workspace adds to the reader suite's fixture, shipped under `src/`. */
|
|
409
|
+
export const WRITER_FIXTURE_DIR = join(here, "__writer_fixture__");
|
|
410
|
+
|
|
411
|
+
type Validate = ((d: unknown) => boolean) & { errors?: unknown };
|
|
412
|
+
const writeValidators = new Map<string, { validate: Validate; schema: { $id: string } }>();
|
|
413
|
+
|
|
414
|
+
/** An action's output schema and a draft 2020-12 validator for it, from this package's own ajv 8. */
|
|
415
|
+
export function writeContractSchema(action: WriteContractAction): { schema: { $id: string }; validate: Validate } {
|
|
416
|
+
const file = WRITE_CONTRACT_SCHEMAS[action];
|
|
417
|
+
let v = writeValidators.get(file);
|
|
418
|
+
if (!v) {
|
|
419
|
+
const schema = JSON.parse(readFileSync(join(workspaceSrc, file), "utf-8")) as { $id: string };
|
|
420
|
+
const mod = createRequire(import.meta.url)("ajv/dist/2020") as { default?: unknown };
|
|
421
|
+
const Ajv = (mod.default ?? mod) as new (opts: object) => { compile(s: object): Validate };
|
|
422
|
+
v = { validate: new Ajv({ strict: true, allErrors: true }).compile(schema), schema };
|
|
423
|
+
writeValidators.set(file, v);
|
|
424
|
+
}
|
|
425
|
+
return v;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/** A digest of every file under `dir`, skipping `.git` and node_modules: the working tree. */
|
|
429
|
+
export function worktreeDigest(dir: string): Record<string, string> {
|
|
430
|
+
const out: Record<string, string> = {};
|
|
431
|
+
const walk = (at: string, prefix: string) => {
|
|
432
|
+
for (const e of readdirSync(at, { withFileTypes: true })) {
|
|
433
|
+
if (e.name === "node_modules" || (prefix === "" && e.name === ".git")) continue;
|
|
434
|
+
const rel = prefix ? `${prefix}/${e.name}` : e.name;
|
|
435
|
+
if (e.isDirectory()) walk(join(at, e.name), rel);
|
|
436
|
+
else if (e.isFile()) out[rel] = createHash("sha256").update(readFileSync(join(at, e.name))).digest("hex");
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
walk(dir, "");
|
|
440
|
+
return out;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
/** Every git ref in `dir` and what it points at, with `HEAD` as the branch it names and its commit. */
|
|
444
|
+
export function gitRefs(dir: string): Record<string, string> {
|
|
445
|
+
const out: Record<string, string> = {};
|
|
446
|
+
const text = execFileSync("git", ["for-each-ref", "--format=%(refname) %(objectname)"], { cwd: dir, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] });
|
|
447
|
+
for (const line of text.split("\n")) {
|
|
448
|
+
const at = line.indexOf(" ");
|
|
449
|
+
if (at > 0) out[line.slice(0, at)] = line.slice(at + 1);
|
|
450
|
+
}
|
|
451
|
+
const head = (args: string[]) => {
|
|
452
|
+
try {
|
|
453
|
+
return execFileSync("git", args, { cwd: dir, encoding: "utf-8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
454
|
+
} catch {
|
|
455
|
+
return "";
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
out.HEAD = `${head(["symbolic-ref", "-q", "HEAD"])} ${head(["rev-parse", "-q", "--verify", "HEAD"])}`;
|
|
459
|
+
return out;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/** The refs that differ between two {@link gitRefs}, with what each now points at (empty when removed). */
|
|
463
|
+
export function refChanges(before: Record<string, string>, after: Record<string, string>): Record<string, string> {
|
|
464
|
+
const out: Record<string, string> = {};
|
|
465
|
+
for (const [r, v] of Object.entries(after)) if (before[r] !== v) out[r] = v;
|
|
466
|
+
for (const r of Object.keys(before)) if (after[r] === undefined) out[r] = "";
|
|
467
|
+
return out;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** Whether `argv` is a read-contract call: one a reader may make, which writes nothing. */
|
|
471
|
+
export function isReadCall(argv: readonly string[]): boolean {
|
|
472
|
+
if (argv[0] !== "workspace") return false;
|
|
473
|
+
const [, verb, sub] = argv;
|
|
474
|
+
switch (verb) {
|
|
475
|
+
case "ls":
|
|
476
|
+
case "graph":
|
|
477
|
+
case "check":
|
|
478
|
+
case "status":
|
|
479
|
+
return true;
|
|
480
|
+
case "records":
|
|
481
|
+
return !["new", "amend", "review", "close", "pin"].includes(sub ?? "");
|
|
482
|
+
case "runs":
|
|
483
|
+
return !["start", "end", "record"].includes(sub ?? "");
|
|
484
|
+
case "points":
|
|
485
|
+
return !["ask", "answer"].includes(sub ?? "");
|
|
486
|
+
case "work":
|
|
487
|
+
return sub === "history";
|
|
488
|
+
default:
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* What is wrong with the chant calls one step made: anything but exactly
|
|
495
|
+
* one call, of `workspace <action>` with the step's arguments in order and
|
|
496
|
+
* the action's JSON flag, given the step's fields on stdin. Empty when the
|
|
497
|
+
* calls conform.
|
|
498
|
+
*/
|
|
499
|
+
export function writerCallProblems(step: WriteStep, calls: readonly ChantRun[]): string[] {
|
|
500
|
+
const name = `${step.id} (${step.action})`;
|
|
501
|
+
if (calls.length !== 1) return [`${name}: made ${calls.length} chant calls (${calls.map((c) => c.argv.join(" ")).join("; ")}), expected exactly one`];
|
|
502
|
+
const { argv, input } = calls[0];
|
|
503
|
+
const prefix = ["workspace", ...step.action.split(" ")];
|
|
504
|
+
if (prefix.some((t, i) => argv[i] !== t)) return [`${name}: ran chant ${argv.join(" ")}, which is not workspace ${step.action}`];
|
|
505
|
+
const rest = argv.slice(prefix.length);
|
|
506
|
+
const at = rest.findIndex((_, i) => step.args.every((a, j) => rest[i + j] === a));
|
|
507
|
+
if (step.args.length > 0 && at === -1) return [`${name}: ran chant ${argv.join(" ")}, which does not pass ${step.args.join(" ")} in order`];
|
|
508
|
+
const extra = step.args.length > 0 ? [...rest.slice(0, at), ...rest.slice(at + step.args.length)] : rest;
|
|
509
|
+
const allowed = WRITE_CONTRACT_JSON_FLAGS[step.action];
|
|
510
|
+
if (!allowed.some((flags) => flags.length === extra.length && flags.every((f, i) => extra[i] === f))) {
|
|
511
|
+
return [`${name}: ran chant ${argv.join(" ")}; beyond the command and its arguments it may add only ${allowed.map((f) => (f.length ? f.join(" ") : "nothing")).join(" or ")}, and it added ${extra.join(" ") || "nothing"}`];
|
|
512
|
+
}
|
|
513
|
+
if (step.input === undefined) return input === undefined || input === "" ? [] : [`${name}: gave chant ${argv.join(" ")} something on stdin, and the command reads nothing there`];
|
|
514
|
+
let given: unknown;
|
|
515
|
+
try {
|
|
516
|
+
given = input === undefined ? undefined : JSON.parse(input);
|
|
517
|
+
} catch {
|
|
518
|
+
given = undefined;
|
|
519
|
+
}
|
|
520
|
+
return isDeepStrictEqual(given, JSON.parse(step.input)) ? [] : [`${name}: gave chant ${argv.join(" ")} other fields on stdin than the step's`];
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/** Everything wrong with the document one step returned (`doc`), given what chant printed (`printed`). Empty when it conforms. */
|
|
524
|
+
export function writerDocumentProblems(step: WriteStep, printed: ChantRun, doc: unknown): string[] {
|
|
525
|
+
const name = `${step.id} (${step.action})`;
|
|
526
|
+
if (printed.stdout.trim() === "") return [`${name}: chant ${printed.argv.join(" ")} printed nothing${printed.stderr ? `; stderr: ${printed.stderr.trim()}` : ""}`];
|
|
527
|
+
let parsed: unknown;
|
|
528
|
+
try {
|
|
529
|
+
parsed = JSON.parse(printed.stdout);
|
|
530
|
+
} catch (e) {
|
|
531
|
+
return [`${name}: chant ${printed.argv.join(" ")} printed something that is not JSON (${(e as Error).message}); stderr: ${printed.stderr.trim()}`];
|
|
532
|
+
}
|
|
533
|
+
const problems: string[] = [];
|
|
534
|
+
if (!isDeepStrictEqual(doc, parsed)) problems.push(`${name}: the writer must return the document chant printed, unchanged, and it returned something else`);
|
|
535
|
+
const { schema, validate } = writeContractSchema(step.action);
|
|
536
|
+
if (!validate(parsed)) problems.push(`${name}: the document does not validate against ${WRITE_CONTRACT_SCHEMAS[step.action]}: ${JSON.stringify(validate.errors)}`);
|
|
537
|
+
const head = (parsed ?? {}) as { $schema?: unknown; error?: { code?: string; message?: string }; refused?: { code?: string; message?: string } };
|
|
538
|
+
if (head.$schema !== schema.$id) problems.push(`${name}: $schema is ${JSON.stringify(head.$schema)}, expected ${schema.$id}`);
|
|
539
|
+
const no = head.error ?? head.refused;
|
|
540
|
+
if (no) problems.push(`${name}: chant did not write: ${no.code}: ${no.message}`);
|
|
541
|
+
return problems;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/** The files and refs a step's document says chant wrote. */
|
|
545
|
+
export function reportedWrites(action: WriteContractAction, doc: unknown): { paths: string[]; refs: Record<string, string> } {
|
|
546
|
+
const d = (doc ?? {}) as Record<string, unknown>;
|
|
547
|
+
const str = (v: unknown) => (typeof v === "string" ? v : undefined);
|
|
548
|
+
if (action.startsWith("work ") && action !== "work evidence") {
|
|
549
|
+
// The lease ref holds a lease blob whose value the document does not
|
|
550
|
+
// print, so any value of the ref it names is chant's ("*").
|
|
551
|
+
const history = (d.history ?? {}) as Record<string, unknown>;
|
|
552
|
+
const refs: Record<string, string> = {};
|
|
553
|
+
if (str(history.commit)) refs["refs/heads/chant/lifecycle"] = String(history.commit);
|
|
554
|
+
if (str(d.ref)) refs[String(d.ref)] = "*";
|
|
555
|
+
return { paths: [], refs };
|
|
556
|
+
}
|
|
557
|
+
if (action.startsWith("runs ")) {
|
|
558
|
+
const ledger = (d.ledger ?? {}) as Record<string, unknown>;
|
|
559
|
+
return { paths: [], refs: str(ledger.commit) ? { "refs/heads/chant/lifecycle": String(ledger.commit) } : {} };
|
|
560
|
+
}
|
|
561
|
+
return { paths: str(d.path) ? [String(d.path)] : [], refs: {} };
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* What changed in the workspace during one step that the step's document
|
|
566
|
+
* does not report: a file other than the path chant wrote, or a ref other
|
|
567
|
+
* than the lease ref and the ledger commit chant wrote.
|
|
568
|
+
*/
|
|
569
|
+
export function unreportedChanges(
|
|
570
|
+
step: WriteStep,
|
|
571
|
+
doc: unknown,
|
|
572
|
+
files: { before: Record<string, string>; after: Record<string, string> },
|
|
573
|
+
refs: { before: Record<string, string>; after: Record<string, string> },
|
|
574
|
+
): string[] {
|
|
575
|
+
const name = `${step.id} (${step.action})`;
|
|
576
|
+
const reported = reportedWrites(step.action, doc);
|
|
577
|
+
const problems: string[] = [];
|
|
578
|
+
const changed = treeChanges(files.before, files.after).filter((c) => !reported.paths.includes(c.replace(/ \((added|changed|removed)\)$/, "")));
|
|
579
|
+
if (changed.length > 0) problems.push(`${name}: files changed that chant did not report writing: ${changed.join(", ")}`);
|
|
580
|
+
const refsChanged = Object.entries(refChanges(refs.before, refs.after)).filter(([r, v]) => !(r in reported.refs && (reported.refs[r] === "*" || reported.refs[r] === v)));
|
|
581
|
+
if (refsChanged.length > 0) problems.push(`${name}: git refs changed that chant did not report writing: ${refsChanged.map(([r]) => r).join(", ")}`);
|
|
582
|
+
return problems;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
/** Build the step a script step is at, from the documents of the steps before it. */
|
|
586
|
+
export function buildStep(s: WriterScriptStep, done: Record<string, Record<string, unknown>>): WriteStep {
|
|
587
|
+
const params = s.params(done);
|
|
588
|
+
return { id: s.id, action: s.action, params, ...writeArgv(s.action, params) } as WriteStep;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/** The smallest writer that conforms: each step is its one command, and its facts are read through the read contract. */
|
|
592
|
+
export const referenceWriter: WorkspaceWriterFactory = (chant) => ({
|
|
593
|
+
async write(step) {
|
|
594
|
+
const run = await chant.run(["workspace", ...step.action.split(" "), ...step.args, ...WRITE_CONTRACT_JSON_FLAGS[step.action][0]], step.input === undefined ? undefined : { input: step.input });
|
|
595
|
+
return JSON.parse(run.stdout);
|
|
596
|
+
},
|
|
597
|
+
async facts() {
|
|
598
|
+
const out: Record<string, unknown> = {};
|
|
599
|
+
for (const [name, kind] of Object.entries(WRITER_KINDS)) {
|
|
600
|
+
const run = await chant.run(["workspace", "records", "--kind", kind, "--json"]);
|
|
601
|
+
const doc = JSON.parse(run.stdout) as { records: { id: string; state: string | null }[] };
|
|
602
|
+
out[name] = doc.records.map((r) => [r.id, r.state]).sort();
|
|
603
|
+
}
|
|
604
|
+
const runs = JSON.parse((await chant.run(["workspace", "runs", "--json"])).stdout) as { runs: { id: string; state: string }[] };
|
|
605
|
+
out.runs = runs.runs.map((r) => [r.id, r.state]).sort();
|
|
606
|
+
return out;
|
|
607
|
+
},
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
/** A workspace generated for a writer run, and how to remove it. */
|
|
611
|
+
export interface WriterConformanceWorkspace {
|
|
612
|
+
dir: string;
|
|
613
|
+
dispose(): void;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Generate the writer conformance workspace: the reader suite's workspace
|
|
618
|
+
* ({@link createConformanceWorkspace}), with `__writer_fixture__/` copied over
|
|
619
|
+
* it, the four kinds declared in its `records`, and that committed.
|
|
620
|
+
*/
|
|
621
|
+
export function createWriterConformanceWorkspace(options: { chantCommand?: string[]; timeoutMs?: number } = {}): WriterConformanceWorkspace {
|
|
622
|
+
const ws = createConformanceWorkspace({ chantCommand: options.chantCommand, timeoutMs: options.timeoutMs });
|
|
623
|
+
try {
|
|
624
|
+
cpSync(WRITER_FIXTURE_DIR, ws.dir, { recursive: true });
|
|
625
|
+
const declFile = join(ws.dir, "chant.workspace.json");
|
|
626
|
+
const decl = JSON.parse(readFileSync(declFile, "utf-8")) as Record<string, unknown>;
|
|
627
|
+
decl.records = Object.values(WRITER_KINDS).map((kind) => ({ kind }));
|
|
628
|
+
writeFileSync(declFile, `${JSON.stringify(decl, null, 2)}\n`);
|
|
629
|
+
const git = (...args: string[]) =>
|
|
630
|
+
execFileSync("git", ["-c", "user.name=chant", "-c", "user.email=chant@localhost", "-c", "commit.gpgsign=false", ...args], {
|
|
631
|
+
cwd: ws.dir,
|
|
632
|
+
env: { ...process.env, GIT_CONFIG_GLOBAL: process.platform === "win32" ? "NUL" : "/dev/null", GIT_CONFIG_NOSYSTEM: "1" },
|
|
633
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
634
|
+
});
|
|
635
|
+
git("add", "-A");
|
|
636
|
+
git("commit", "--quiet", "-m", "the writer conformance workspace");
|
|
637
|
+
return ws;
|
|
638
|
+
} catch (e) {
|
|
639
|
+
ws.dispose();
|
|
640
|
+
const err = e as Error & { stderr?: Buffer | string };
|
|
641
|
+
throw new Error(`could not generate the writer conformance workspace: ${err.message}${err.stderr ? `\n${String(err.stderr)}` : ""}`);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
/** The actions to exercise and the ones skipped, from `actions`. Throws on a name that is not a write-contract action. */
|
|
646
|
+
export function selectActions(actions?: readonly WriteContractAction[]): { checked: WriteContractAction[]; skipped: WriteContractAction[] } {
|
|
647
|
+
if (actions === undefined) return { checked: [...WRITE_CONTRACT_ACTIONS], skipped: [] };
|
|
648
|
+
const unknown = actions.filter((a) => !(WRITE_CONTRACT_ACTIONS as readonly string[]).includes(a));
|
|
649
|
+
if (unknown.length > 0) throw new Error(`not write-contract actions: ${unknown.join(", ")}; the actions are ${WRITE_CONTRACT_ACTIONS.join(", ")}`);
|
|
650
|
+
if (actions.length === 0) throw new Error("actions is empty; list at least one write-contract action");
|
|
651
|
+
return { checked: WRITE_CONTRACT_ACTIONS.filter((a) => actions.includes(a)), skipped: WRITE_CONTRACT_ACTIONS.filter((a) => !actions.includes(a)) };
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/** Every file under `dir`, from it, with / separators. */
|
|
655
|
+
function filesUnder(dir: string): string[] {
|
|
656
|
+
const out: string[] = [];
|
|
657
|
+
const walk = (at: string, prefix: string) => {
|
|
658
|
+
for (const e of readdirSync(at, { withFileTypes: true })) {
|
|
659
|
+
const rel = prefix ? `${prefix}/${e.name}` : e.name;
|
|
660
|
+
if (e.isDirectory()) walk(join(at, e.name), rel);
|
|
661
|
+
else out.push(rel);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
if (existsSync(dir)) walk(dir, "");
|
|
665
|
+
return out.sort();
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/** The files in the state directory that `privateState` does not declare, and problems with the declaration itself. */
|
|
669
|
+
export function undeclaredState(files: readonly string[], privateState: readonly PrivateStatePath[]): string[] {
|
|
670
|
+
const problems: string[] = [];
|
|
671
|
+
for (const p of privateState) {
|
|
672
|
+
const is = typeof p.is === "string" ? [p.is] : [...p.is];
|
|
673
|
+
const wrong = is.filter((c) => !(PRIVATE_STATE_CATEGORIES as readonly string[]).includes(c));
|
|
674
|
+
if (is.length === 0 || wrong.length > 0) problems.push(`state: ${p.path} is declared as ${JSON.stringify(p.is)}; private state is ${PRIVATE_STATE_CATEGORIES.join(", ")} (ws-074)`);
|
|
675
|
+
}
|
|
676
|
+
const declared = (f: string) => privateState.some((p) => f === p.path || f.startsWith(`${p.path.replace(/\/+$/, "")}/`));
|
|
677
|
+
const loose = files.filter((f) => !declared(f));
|
|
678
|
+
if (loose.length > 0) problems.push(`state: the writer keeps ${loose.join(", ")} in its state directory, and privateState does not declare it`);
|
|
679
|
+
return problems;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/** A short JSON rendering of a value for a problem message. */
|
|
683
|
+
function brief(v: unknown): string {
|
|
684
|
+
const s = JSON.stringify(v) ?? String(v);
|
|
685
|
+
return s.length > 400 ? `${s.slice(0, 400)}...` : s;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
/**
|
|
689
|
+
* Hold a writer to the write contract, with no test runner: drive
|
|
690
|
+
* {@link WRITER_SCRIPT} through it on a generated workspace, check each step,
|
|
691
|
+
* then the amnesia test and what the writer holds, and return what is wrong.
|
|
692
|
+
* The writer conforms when `problems` is empty.
|
|
693
|
+
*
|
|
694
|
+
* ```js
|
|
695
|
+
* import { test } from "node:test";
|
|
696
|
+
* import assert from "node:assert/strict";
|
|
697
|
+
* import { runWorkspaceWriterConformance } from "@intentius/chant/workspace/conformance";
|
|
698
|
+
*
|
|
699
|
+
* test("my writer writes only through chant", { timeout: 600_000 }, async () => {
|
|
700
|
+
* const report = await runWorkspaceWriterConformance(myWriter, {
|
|
701
|
+
* actions: ["records review", "points answer"],
|
|
702
|
+
* privateState: [{ path: "events.db", is: "cache" }],
|
|
703
|
+
* });
|
|
704
|
+
* assert.deepEqual(report.problems, []);
|
|
705
|
+
* });
|
|
706
|
+
* ```
|
|
707
|
+
*/
|
|
708
|
+
export async function runWorkspaceWriterConformance(writer: WorkspaceWriterFactory, options: WorkspaceWriterConformanceOptions = {}): Promise<WorkspaceWriterConformanceReport> {
|
|
709
|
+
const { checked, skipped } = selectActions(options.actions);
|
|
710
|
+
const chantCommand = options.chantCommand ?? defaultChantCommand();
|
|
711
|
+
const timeoutMs = options.timeoutMs ?? 120_000;
|
|
712
|
+
const privateState = options.privateState ?? [];
|
|
713
|
+
const ws = createWriterConformanceWorkspace({ chantCommand, timeoutMs });
|
|
714
|
+
const stateDir = realpathSync(mkdtempSync(join(tmpdir(), "chant-writer-state-")));
|
|
715
|
+
const calls: ChantRun[] = [];
|
|
716
|
+
const transport: ChantTransport = {
|
|
717
|
+
async run(argv, opts) {
|
|
718
|
+
const run = await runChant(chantCommand, [...argv], ws.dir, timeoutMs, opts?.input);
|
|
719
|
+
calls.push(run);
|
|
720
|
+
return run;
|
|
721
|
+
},
|
|
722
|
+
};
|
|
723
|
+
const direct = async (argv: string[], input?: string): Promise<Record<string, unknown>> => {
|
|
724
|
+
const run = await runChant(chantCommand, argv, ws.dir, timeoutMs, input);
|
|
725
|
+
try {
|
|
726
|
+
return JSON.parse(run.stdout) as Record<string, unknown>;
|
|
727
|
+
} catch {
|
|
728
|
+
throw new Error(`chant ${argv.join(" ")} printed no JSON (exit ${run.status}): ${run.stderr.trim()}`);
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
const after = { facts: [] as string[], state: [] as string[], amnesia: [] as string[], holds: [] as string[], readBack: [] as string[] };
|
|
732
|
+
const facts: { before: unknown; after: unknown } = { before: undefined, after: undefined };
|
|
733
|
+
const results: WriterStepResult[] = [];
|
|
734
|
+
try {
|
|
735
|
+
let built = writer(transport, { stateDir });
|
|
736
|
+
const done: Record<string, Record<string, unknown>> = {};
|
|
737
|
+
for (const s of WRITER_SCRIPT) {
|
|
738
|
+
const st = buildStep(s, done);
|
|
739
|
+
if (!checked.includes(st.action)) {
|
|
740
|
+
const doc = await direct(["workspace", ...st.action.split(" "), ...st.args, ...WRITE_CONTRACT_JSON_FLAGS[st.action][0]], st.input);
|
|
741
|
+
done[st.id] = doc;
|
|
742
|
+
const no = (doc.error ?? doc.refused) as { code?: string; message?: string } | undefined;
|
|
743
|
+
results.push({ id: st.id, action: st.action, by: "suite", args: st.args, problems: no ? [`${st.id} (${st.action}): the suite's own write failed: ${no.code}: ${no.message}`] : [] });
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
const files = { before: worktreeDigest(ws.dir), after: {} as Record<string, string> };
|
|
747
|
+
const refs = { before: gitRefs(ws.dir), after: {} as Record<string, string> };
|
|
748
|
+
calls.length = 0;
|
|
749
|
+
let doc: unknown;
|
|
750
|
+
let problems: string[];
|
|
751
|
+
try {
|
|
752
|
+
doc = await built.write(st);
|
|
753
|
+
problems = writerCallProblems(st, calls);
|
|
754
|
+
if (problems.length === 0) problems = writerDocumentProblems(st, calls[0], doc);
|
|
755
|
+
} catch (e) {
|
|
756
|
+
const stderr = calls[0]?.stderr.trim();
|
|
757
|
+
problems = [`${st.id} (${st.action}): the writer threw: ${(e as Error).message}${stderr ? `; chant's stderr: ${stderr}` : ""}`];
|
|
758
|
+
}
|
|
759
|
+
files.after = worktreeDigest(ws.dir);
|
|
760
|
+
refs.after = gitRefs(ws.dir);
|
|
761
|
+
// What chant printed is what the later steps build on, whatever the writer returned.
|
|
762
|
+
const printed = calls.length === 1 ? (() => { try { return JSON.parse(calls[0].stdout) as Record<string, unknown>; } catch { return undefined; } })() : undefined;
|
|
763
|
+
done[st.id] = printed ?? ((doc ?? {}) as Record<string, unknown>);
|
|
764
|
+
problems.push(...unreportedChanges(st, done[st.id], files, refs));
|
|
765
|
+
results.push({ id: st.id, action: st.action, by: "writer", args: st.args, problems });
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// What the writer shows, read only through the read contract.
|
|
769
|
+
const readFacts = async (w: WorkspaceWriter, when: string): Promise<unknown> => {
|
|
770
|
+
const files = worktreeDigest(ws.dir);
|
|
771
|
+
const refs = gitRefs(ws.dir);
|
|
772
|
+
calls.length = 0;
|
|
773
|
+
let value: unknown;
|
|
774
|
+
try {
|
|
775
|
+
value = await w.facts();
|
|
776
|
+
} catch (e) {
|
|
777
|
+
after.facts.push(`facts: ${when}, facts() threw: ${(e as Error).message}`);
|
|
778
|
+
}
|
|
779
|
+
const writes = calls.filter((c) => !isReadCall(c.argv));
|
|
780
|
+
if (writes.length > 0) after.facts.push(`facts: ${when}, facts() made calls outside the read contract: ${writes.map((c) => c.argv.join(" ")).join("; ")}`);
|
|
781
|
+
const changed = treeChanges(files, worktreeDigest(ws.dir));
|
|
782
|
+
if (changed.length > 0) after.facts.push(`facts: ${when}, facts() changed files: ${changed.join(", ")}`);
|
|
783
|
+
const refsChanged = Object.keys(refChanges(refs, gitRefs(ws.dir)));
|
|
784
|
+
if (refsChanged.length > 0) after.facts.push(`facts: ${when}, facts() changed git refs: ${refsChanged.join(", ")}`);
|
|
785
|
+
return value;
|
|
786
|
+
};
|
|
787
|
+
facts.before = await readFacts(built, "before amnesia");
|
|
788
|
+
if (facts.before === undefined || facts.before === null) after.facts.push("facts: facts() returned nothing; it returns the facts the tool shows, read the way the tool reads them");
|
|
789
|
+
|
|
790
|
+
// What the writer holds: each fact in the repo, or one of the four exceptions.
|
|
791
|
+
if (built.holds) {
|
|
792
|
+
let held: readonly HeldItem[] = [];
|
|
793
|
+
try {
|
|
794
|
+
held = await built.holds();
|
|
795
|
+
} catch (e) {
|
|
796
|
+
after.holds.push(`holds: holds() threw: ${(e as Error).message}`);
|
|
797
|
+
}
|
|
798
|
+
const records = new Map<string, Set<string>>();
|
|
799
|
+
const recordIds = async (kind: string) => {
|
|
800
|
+
if (!records.has(kind)) {
|
|
801
|
+
const doc = await direct(["workspace", "records", "--kind", kind, "--json"]);
|
|
802
|
+
records.set(kind, new Set(((doc.records ?? []) as { id: string }[]).map((r) => r.id)));
|
|
803
|
+
}
|
|
804
|
+
return records.get(kind)!;
|
|
805
|
+
};
|
|
806
|
+
let runIds: Set<string> | undefined;
|
|
807
|
+
for (const h of held) {
|
|
808
|
+
if ("record" in h) {
|
|
809
|
+
if (!(await recordIds(h.kind)).has(h.record)) after.holds.push(`holds: the writer holds record ${h.record} of ${h.kind}, which the repository does not have`);
|
|
810
|
+
} else if ("run" in h) {
|
|
811
|
+
runIds ??= new Set(((await direct(["workspace", "runs", "--json"])).runs as { id: string }[] | undefined ?? []).map((r) => r.id));
|
|
812
|
+
if (!runIds.has(h.run)) after.holds.push(`holds: the writer holds run ${h.run}, which the run ledger does not have`);
|
|
813
|
+
} else if ("lease" in h) {
|
|
814
|
+
const doc = await direct(["workspace", "work", "history", h.lease, "--kind", h.kind, "--json"]);
|
|
815
|
+
if (!Array.isArray(doc.claims) || doc.claims.length === 0) after.holds.push(`holds: the writer holds a lease on ${h.lease}, which has no lease history`);
|
|
816
|
+
} else if ("exempt" in h) {
|
|
817
|
+
if (!(PRIVATE_STATE_CATEGORIES as readonly string[]).includes(h.exempt)) after.holds.push(`holds: ${h.what} is held as ${JSON.stringify(h.exempt)}; outside the repo a tool keeps only ${PRIVATE_STATE_CATEGORIES.join(", ")} (ws-074)`);
|
|
818
|
+
} else {
|
|
819
|
+
after.holds.push(`holds: ${brief(h)} is not a record, run, lease or exemption`);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// Amnesia: close the writer, delete its state, build it again, and ask again.
|
|
825
|
+
try {
|
|
826
|
+
await built.close?.();
|
|
827
|
+
} catch (e) {
|
|
828
|
+
after.amnesia.push(`amnesia: close() threw: ${(e as Error).message}`);
|
|
829
|
+
}
|
|
830
|
+
after.state.push(...undeclaredState(filesUnder(stateDir), privateState));
|
|
831
|
+
rmSync(stateDir, { recursive: true, force: true });
|
|
832
|
+
mkdirSync(stateDir, { recursive: true });
|
|
833
|
+
built = writer(transport, { stateDir });
|
|
834
|
+
facts.after = await readFacts(built, "after amnesia");
|
|
835
|
+
if (!isDeepStrictEqual(facts.before, facts.after)) {
|
|
836
|
+
after.amnesia.push(`amnesia: after its private state was deleted, the writer shows other facts; before: ${brief(facts.before)}; after: ${brief(facts.after)}`);
|
|
837
|
+
}
|
|
838
|
+
try {
|
|
839
|
+
await built.close?.();
|
|
840
|
+
} catch {
|
|
841
|
+
// Closed again after the comparison; a failure here is not the writer's contract.
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// Every fact the script produced, read back through the read contract.
|
|
845
|
+
const uncommitted = new Map<string, Map<string, string>>();
|
|
846
|
+
for (const kind of Object.values(WRITER_KINDS)) {
|
|
847
|
+
const doc = await direct(["workspace", "records", "--uncommitted", "--kind", kind, "--json"]);
|
|
848
|
+
uncommitted.set(kind, new Map(((doc.records ?? []) as { id: string; worktree: string }[]).map((r) => [r.id, r.worktree])));
|
|
849
|
+
}
|
|
850
|
+
const runs = new Map(((await direct(["workspace", "runs", "--json"])).runs as { id: string; state: string }[] | undefined ?? []).map((r) => [r.id, r.state]));
|
|
851
|
+
const history = await direct(["workspace", "work", "history", "W-001", "--kind", WRITER_KINDS.work, "--json"]);
|
|
852
|
+
const claims = (history.claims ?? []) as { token: string; ended: string | null; release?: { outcome?: string } | null }[];
|
|
853
|
+
for (const s of WRITER_SCRIPT) {
|
|
854
|
+
const doc = done[s.id] ?? {};
|
|
855
|
+
if (s.action.startsWith("records ") || s.action.startsWith("points ")) {
|
|
856
|
+
const kind = String((doc.kind as { file?: unknown } | undefined)?.file ?? "");
|
|
857
|
+
const id = String(doc.id ?? "");
|
|
858
|
+
if (!uncommitted.get(kind)?.has(id)) after.readBack.push(`read back: ${s.id} (${s.action}) wrote ${id}, and records --uncommitted --kind ${kind} does not list it`);
|
|
859
|
+
} else if (s.action === "work evidence") {
|
|
860
|
+
if (!uncommitted.get(WRITER_KINDS.work)?.has(String(doc.item ?? ""))) after.readBack.push(`read back: ${s.id} (${s.action}) amended ${String(doc.item)}, and records --uncommitted does not list it`);
|
|
861
|
+
} else if (s.action.startsWith("work ")) {
|
|
862
|
+
const token = String((doc.lease as { token?: unknown } | undefined)?.token ?? "");
|
|
863
|
+
const claim = claims.find((c) => c.token === token);
|
|
864
|
+
if (!claim) after.readBack.push(`read back: ${s.id} (${s.action}) wrote a lease with token ${token}, and work history does not list it`);
|
|
865
|
+
else if (s.action === "work release" && claim.release?.outcome !== "done") after.readBack.push(`read back: ${s.id} (${s.action}) released the lease as done, and work history says ${brief(claim.release)}`);
|
|
866
|
+
} else if (s.action.startsWith("runs ")) {
|
|
867
|
+
const id = String((doc.run as { id?: unknown } | undefined)?.id ?? "");
|
|
868
|
+
const want = s.action === "runs start" ? undefined : "ended";
|
|
869
|
+
if (!runs.has(id)) after.readBack.push(`read back: ${s.id} (${s.action}) wrote run ${id}, and runs does not list it`);
|
|
870
|
+
else if (want && runs.get(id) !== want) after.readBack.push(`read back: ${s.id} (${s.action}) ended run ${id}, and runs says it is ${runs.get(id)}`);
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
const problems = [...results.flatMap((r) => r.problems), ...after.facts, ...after.state, ...after.amnesia, ...after.holds, ...after.readBack];
|
|
875
|
+
return { problems, checked, skipped, results, after, facts, workspaceDir: ws.dir };
|
|
876
|
+
} finally {
|
|
877
|
+
rmSync(stateDir, { recursive: true, force: true });
|
|
878
|
+
ws.dispose();
|
|
879
|
+
}
|
|
880
|
+
}
|