Skip to content

feat: add the canonical domain contract, glossary, and decision records - #101

Merged
keyurgolani merged 7 commits into
nextfrom
docs/01.1-contracts
Oct 20, 2026
Merged

keyurgolani merged 7 commits into
nextfrom
docs/01.1-contracts

Conversation

@keyurgolani

@keyurgolani keyurgolani commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Implements CHECKMATE-01.1 · contracts
Refs #29

What changed

  • src/lib/domain/, contract 1.0.0:
  • docs/architecture/glossary.md, rendered from those files by scripts/transformation/render.ts. Its counts and lists come from the data, and every leaf ID links to its issue.
  • Eleven decision records in docs/architecture/decisions/.
  • .github/ci-scope.json, so the unit job runs for the docs and schema that unit tests read.

The adapter, records.ts, the type test and the ratchet come in the next PR for #29. No service, schema or UI change.

Why

Revision storage (#38), run creation (#47), expected revisions (#59) and domain events (#62) start from these names, and #30, #41 and #89 build on them.

CI scope

This touches .github/ci-scope.json from #92. Unit tests compare the Markdown in docs/architecture/ and docs/transformation/ against the data, and the retention test reads docker/pocketbase/pb_schema.json. A change to only those files skipped the unit job, so a hand-edited glossary or a schema relation with no retention row could merge green. The new contract-docs class runs unit for that Markdown, and the fixture class runs unit too. dependency-graph.json still runs every code job. scope.test.ts and CONTRIBUTING cover both.

Verification

Check origin/next (cfcd9ae) This branch
npx eslint on the 14 changed TS files exit 0, no eslint-disable
npm run lint 41 errors, 48 warnings 41 errors, 48 warnings
npx tsc --noEmit 0 errors 0 errors
npm test (unit, plus backend on the fixture) 34 files, 621 tests pass
npx vitest run src/lib/domain scripts/transformation 6 files, 301 tests pass
npm run build with both PocketBase URLs on http://127.0.0.1:9 passes

Test plan items 2 to 5:

  1. Glossary: the 23 entities in PRODUCT.md's order and every supporting term, each with the owner [CHECKMATE-01.1] Publish canonical domain vocabulary and lifecycle state machines #29 names. glossary.md has a row for each and matches the renderer. Every cited owner is checked against docs/transformation/dependency-graph.json.
  2. Transitions: nothing leaves a terminal state, every cause is a listed command or time or derived, every state is reachable, immutable records have no lifecycle, and Run Step has every state and inclusion value that [CHECKMATE-07.3] Replace sync stubs with dry-run and apply upgrade plans #49, [CHECKMATE-08.3] Add deterministic conditions and structured exceptions #52, [CHECKMATE-09.1] Redesign run execution around one focused next step #53, [CHECKMATE-10.2] Add approval policy, decisions, rework, and invalidation #57 and [CHECKMATE-10.3] Issue immutable portable completion records #58 name.
  3. Progress: each case is checked against a test-only restatement of [CHECKMATE-01.1] Publish canonical domain vocabulary and lifecycle state machines #29's rules. 199 of 200 is 99% and not complete. A last completed step completes the run, a last excepted one only offers CompleteRun, and a resent completed changes nothing. A reference whose children are all excluded or retired counts as a checkable step.
  4. Step Key golden values come from Python's hashlib, checked with shasum, and didn't change with the move to Web Crypto. Retention reads pb_schema.json in its current shape and in PocketBase's export shape: a class per collection, a row per relation, restrict rows required unless the row says nullable, and the purge cases.

I broke each new rule on purpose (a record id passing isStepKey, no excluded to retired move, a rescind on an excepted step, UpdateStep without its check, a restrict row losing nullable, an unreferenced proof row staying proof, a resent completion, a hand edit to the glossary, a missing scope class) and watched the tests fail.

Decisions

  1. Step Keys stay opaque strings, as [CHECKMATE-01.1] Publish canonical domain vocabulary and lifecycle state machines #29 says. isStepKey takes any non-empty string up to 128 characters that isn't a PocketBase record id, so keys written in blueprint files ([CHECKMATE-16.3] Add UI and YAML or JSON blueprints over one schema #76) or kept by imports ([CHECKMATE-16.1] Publish canonical versioned package, workflow, and proof schemas #74, [CHECKMATE-16.2] Add deterministic export, dry-run import, and migration reports #75) pass. Minted keys stay version-4 UUIDs and derived keys version-8.
  2. deriveLegacyStepKey is async now. step-key.ts uses Web Crypto with no node: import, because [CHECKMATE-16.1] Publish canonical versioned package, workflow, and proof schemas #74 runs it in the browser. Nothing on next calls it yet, and the golden values are the same.
  3. Records drop the 01.1- prefix to match [CHECKMATE-01.2] Specify command and projection authority for every actor type #30's enforcement-point.md, so the folder has one naming convention.
  4. [CHECKMATE-03.3] Add expiring progress and completion-record capabilities #37 names no share link commands, so the table uses CreateShareCapability, RevokeShareCapability and RevokeAllShareCapabilities. The last one covers both revoke-all surfaces in [CHECKMATE-03.3] Add expiring progress and completion-record capabilities #37, and [CHECKMATE-01.2] Specify command and projection authority for every actor type #30 gives it a matrix row per surface.
  5. Labels follow the owners' copy: "Share link", "Input" for Parameter, "Role" for Role Slot, "Account settings" for Account Preferences. Grant and Secret Reference get no label. [CHECKMATE-03.1] Create workspace memberships and policy-backed roles #35 shows grants as "Shared with N people", and Settings lists each secret under its own name.
  6. A storage name is the collection or field in the baseline schema, or the name the owning leaf plans, marked planned.
  7. The stub removal test from fix: remove the run sync stub and its success-shaped UI #96 bans the sync flag's name anywhere in src/, so lifecycles.ts lists only blueprints.version as stateless and the Run record covers the sync flag.

Where this differs from #29

  1. Transfer isn't a soft delete. [CHECKMATE-01.1] Publish canonical domain vocabulary and lifecycle state machines #29 lists transfer from [CHECKMATE-03.1] Create workspace memberships and policy-backed roles #35 with the soft deletes, but [CHECKMATE-03.1] Create workspace memberships and policy-backed roles #35 makes it an atomic owner swap that deletes nothing, so it has no purge. I dropped the unused TransferOwnership command.
  2. PRODUCT.md wins where [CHECKMATE-01.1] Publish canonical domain vocabulary and lifecycle state machines #29 shortens a meaning. Workspace also owns policies and installations, a revision can be published, addressed and rolled back to, a Module Include binds a revision or a compatible revision range, a share link is optionally authenticated and can target a progress view or completion record, a package has reviewable upgrade behavior, and a completion record keeps its event chain. The visibility record lists all seven sharing states, upgraded included. [CHECKMATE-01.1] Publish canonical domain vocabulary and lifecycle state machines #29 keeps all 23 entities and the seven destinations, so nothing else needed restoring.
  3. PRODUCT.md calls a Run Step the execution projection of a Step Definition. The glossary doesn't, since [CHECKMATE-01.1] Publish canonical domain vocabulary and lifecycle state machines #29 defines a projection as a read model.
  4. basedOn and publishedBy on revisions get no retention row. [CHECKMATE-04.1] Split template identity, editable draft, and immutable revision storage #38 doesn't make them relations, and the retention test fails as soon as pb_schema.json gains a relation without a row.

Owner steps: none.

@sourcery-ai

sourcery-ai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Sorry @keyurgolani, your pull request is larger than the review limit of 150,000 diff characters

Contract 1.0.0 for CHECKMATE-01.1 · contracts (#29), under src/lib/domain/:
the 23 PRODUCT.md entities and #29's supporting terms with one label,
domain name, storage name and owner each; the five lifecycle tables and
the command names they use; minimum states for the other entities;
progress and run completion cases for 05.2's computeRunProgress; the
retention classes, purge rules and relation matrix; and Step Keys with
deriveLegacyStepKey.

Tests cover test plan items 3 to 5. The retention test reads
pb_schema.json, so a collection or relation without a row fails.
docs/architecture/glossary.md is rendered from src/lib/domain/ by
scripts/transformation/render.ts, which now writes it beside the
dependency graph. vocabulary.test.ts fails when the glossary is stale,
when a PRODUCT.md entity or #29 supporting term is missing, or when a
decision record lacks its status and superseded clauses (test plan item
2). The eleven records cover Run, Blueprint, Step and Task, Section and
reference, Step Key, aggregates, the revision store, retention, the
navigation map, the visibility split and personal presentation.
Unit tests check docs/architecture/ and docs/transformation/ Markdown against the data in src/lib/domain/ and the dependency graph, and the retention test reads docker/pocketbase/pb_schema.json. A docs-only or schema-only pull request skipped those tests, so a stale glossary or an unmatched relation could merge with a green aggregate. The new contract-docs class runs unit for those Markdown files, and the fixture class now runs unit too. dependency-graph.json still runs the full set.
step-key.ts imported node:crypto, but 16.1 runs it in the browser and 05.1 keeps Node imports out of domain code. It now uses globalThis.crypto, so deriveLegacyStepKey and sha256UuidV8 are async. The golden keys are unchanged.

isStepKey now follows #29's opaque-string rule: a non-empty string of up to 128 characters that isn't a PocketBase record id. Minted keys stay version-4 UUIDs and derived keys version-8, and keys authored in 16.3 files or kept by 16.1 and 16.2 imports pass.
…ess cases

A legacy reference counts as checkable when it has no included child steps, since excluded and retired children aren't in the run. A step sent the state it already has is unchanged, writes nothing and never completes the run. Both rules now have cases that 05.2's computeRunProgress must pass.
Lifecycles. A scheduled run with no executable steps can go straight to
completed through CompleteRun. RestoreRevisionToDraft makes a clean draft
dirty, and a rollback restore leaves it clean. A rejected approval reopens
its subject steps, and an upgrade's reconfirm reopens a changed done step
to pending until 10.2 makes that an invalidation. Only an approval step is
invalidated by a subject reopen or a rescind, and an approval step can't be
excepted, so excepted to invalidated is left to the upgrade. An upgrade
that drops an excluded step retires it. TRANSITION_TABLES now comes from
LIFECYCLES.

Commands and checks. PRECONDITIONS replaces the two check lists. It adds
StartRunFromDraft, RestoreRevisionToDraft and multi-op draft calls to the
aggregateRevision checks, UpdateStep and RemoveStep to the stepRevision
checks, the last-seen value for SetHeaderField and SetQuestion, and the
commands that take only an idempotency key. TransferOwnership is gone:
03.1 makes transfer an atomic owner swap that deletes nothing, so it has
no purge. Minimum states name their fields, including
catalogListings.state.

Retention. A proof row nothing references purges as history, except
revisions and completion records, which never leave proof, and
purgeEffect applies that rule. runSources.run is a planned relation that
DeleteRun's tombstone clears. Restrict rows must be required in the
schema unless the row says nullable.

Vocabulary. Module Include, Catalog Package, Share Capability, Template
Revision and Completion Record use PRODUCT.md's wording again. Grant and
Secret Reference have no invented label, and Account Preferences is
labeled Account settings.

Records and glossary. The records drop the 01.1- prefix to match the
other leaves' records, and say what changed above. The glossary links
every leaf ID to its issue, and its counts, soft-delete list and
precondition table come from the data.
@keyurgolani
keyurgolani merged commit 1ff2762 into next Oct 20, 2026
10 checks passed
@keyurgolani
keyurgolani deleted the docs/01.1-contracts branch October 20, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant