@warpgogol/forge 9.5.0 → 9.6.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/CHANGELOG.md +18 -0
- package/README.md +30 -0
- package/README.uk.md +30 -0
- package/bin/cli.ts +19 -50
- package/dist/bin/cli.js +18 -43
- package/dist/bin/cli.js.map +1 -1
- package/dist/os/codebase/codebase.module.d.ts +3 -0
- package/dist/os/codebase/codebase.module.d.ts.map +1 -0
- package/dist/os/codebase/codebase.module.js +53 -0
- package/dist/os/codebase/codebase.module.js.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts +15 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.d.ts.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.js +97 -0
- package/dist/os/codebase/handlers/codebase-measure-symbols.js.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure.d.ts +22 -0
- package/dist/os/codebase/handlers/codebase-measure.d.ts.map +1 -0
- package/dist/os/codebase/handlers/codebase-measure.js +435 -0
- package/dist/os/codebase/handlers/codebase-measure.js.map +1 -0
- package/dist/os/codebase/index.d.ts +4 -0
- package/dist/os/codebase/index.d.ts.map +1 -0
- package/dist/os/codebase/index.js +13 -0
- package/dist/os/codebase/index.js.map +1 -0
- package/dist/os/codebase/types.d.ts +35 -0
- package/dist/os/codebase/types.d.ts.map +1 -0
- package/dist/os/codebase/types.js +17 -0
- package/dist/os/codebase/types.js.map +1 -0
- package/dist/os/core/handlers/package-health.d.ts +6 -4
- package/dist/os/core/handlers/package-health.d.ts.map +1 -1
- package/dist/os/core/handlers/package-health.js +15 -20
- package/dist/os/core/handlers/package-health.js.map +1 -1
- package/dist/os/correctness/anchors.d.ts +24 -0
- package/dist/os/correctness/anchors.d.ts.map +1 -0
- package/dist/os/correctness/anchors.js +156 -0
- package/dist/os/correctness/anchors.js.map +1 -0
- package/dist/os/correctness/audit/bindings-verify-substance.d.ts +7 -0
- package/dist/os/correctness/audit/bindings-verify-substance.d.ts.map +1 -0
- package/dist/os/correctness/audit/bindings-verify-substance.js +145 -0
- package/dist/os/correctness/audit/bindings-verify-substance.js.map +1 -0
- package/dist/os/correctness/audit/differential.d.ts +7 -0
- package/dist/os/correctness/audit/differential.d.ts.map +1 -0
- package/dist/os/correctness/audit/differential.js +105 -0
- package/dist/os/correctness/audit/differential.js.map +1 -0
- package/dist/os/correctness/audit/ledger-orphans.d.ts +6 -0
- package/dist/os/correctness/audit/ledger-orphans.d.ts.map +1 -0
- package/dist/os/correctness/audit/ledger-orphans.js +71 -0
- package/dist/os/correctness/audit/ledger-orphans.js.map +1 -0
- package/dist/os/correctness/audit/ledger.d.ts +29 -0
- package/dist/os/correctness/audit/ledger.d.ts.map +1 -0
- package/dist/os/correctness/audit/ledger.js +72 -0
- package/dist/os/correctness/audit/ledger.js.map +1 -0
- package/dist/os/correctness/audit/run.d.ts +27 -0
- package/dist/os/correctness/audit/run.d.ts.map +1 -0
- package/dist/os/correctness/audit/run.js +184 -0
- package/dist/os/correctness/audit/run.js.map +1 -0
- package/dist/os/correctness/audit/schema-db.d.ts +32 -0
- package/dist/os/correctness/audit/schema-db.d.ts.map +1 -0
- package/dist/os/correctness/audit/schema-db.js +166 -0
- package/dist/os/correctness/audit/schema-db.js.map +1 -0
- package/dist/os/correctness/audit/snapshot.d.ts +34 -0
- package/dist/os/correctness/audit/snapshot.d.ts.map +1 -0
- package/dist/os/correctness/audit/snapshot.js +190 -0
- package/dist/os/correctness/audit/snapshot.js.map +1 -0
- package/dist/os/correctness/audit/sql-scanner.d.ts +28 -0
- package/dist/os/correctness/audit/sql-scanner.d.ts.map +1 -0
- package/dist/os/correctness/audit/sql-scanner.js +279 -0
- package/dist/os/correctness/audit/sql-scanner.js.map +1 -0
- package/dist/os/correctness/audit/sql-schema-conform.d.ts +17 -0
- package/dist/os/correctness/audit/sql-schema-conform.d.ts.map +1 -0
- package/dist/os/correctness/audit/sql-schema-conform.js +163 -0
- package/dist/os/correctness/audit/sql-schema-conform.js.map +1 -0
- package/dist/os/correctness/audit/state-transitions-coverage.d.ts +19 -0
- package/dist/os/correctness/audit/state-transitions-coverage.d.ts.map +1 -0
- package/dist/os/correctness/audit/state-transitions-coverage.js +263 -0
- package/dist/os/correctness/audit/state-transitions-coverage.js.map +1 -0
- package/dist/os/correctness/audit/tests/git-fixture.d.ts +15 -0
- package/dist/os/correctness/audit/tests/git-fixture.d.ts.map +1 -0
- package/dist/os/correctness/audit/tests/git-fixture.js +85 -0
- package/dist/os/correctness/audit/tests/git-fixture.js.map +1 -0
- package/dist/os/correctness/audit/types.d.ts +58 -0
- package/dist/os/correctness/audit/types.d.ts.map +1 -0
- package/dist/os/correctness/audit/types.js +34 -0
- package/dist/os/correctness/audit/types.js.map +1 -0
- package/dist/os/correctness/correctness.module.d.ts +3 -0
- package/dist/os/correctness/correctness.module.d.ts.map +1 -0
- package/dist/os/correctness/correctness.module.js +173 -0
- package/dist/os/correctness/correctness.module.js.map +1 -0
- package/dist/os/correctness/gate/frozen.d.ts +52 -0
- package/dist/os/correctness/gate/frozen.d.ts.map +1 -0
- package/dist/os/correctness/gate/frozen.js +322 -0
- package/dist/os/correctness/gate/frozen.js.map +1 -0
- package/dist/os/correctness/gate/origin.d.ts +28 -0
- package/dist/os/correctness/gate/origin.d.ts.map +1 -0
- package/dist/os/correctness/gate/origin.js +139 -0
- package/dist/os/correctness/gate/origin.js.map +1 -0
- package/dist/os/correctness/gate/repo.d.ts +25 -0
- package/dist/os/correctness/gate/repo.d.ts.map +1 -0
- package/dist/os/correctness/gate/repo.js +88 -0
- package/dist/os/correctness/gate/repo.js.map +1 -0
- package/dist/os/correctness/gate/run.d.ts +22 -0
- package/dist/os/correctness/gate/run.d.ts.map +1 -0
- package/dist/os/correctness/gate/run.js +430 -0
- package/dist/os/correctness/gate/run.js.map +1 -0
- package/dist/os/correctness/gate/runner.d.ts +18 -0
- package/dist/os/correctness/gate/runner.d.ts.map +1 -0
- package/dist/os/correctness/gate/runner.js +123 -0
- package/dist/os/correctness/gate/runner.js.map +1 -0
- package/dist/os/correctness/gate/tests/gate-fixture.d.ts +36 -0
- package/dist/os/correctness/gate/tests/gate-fixture.d.ts.map +1 -0
- package/dist/os/correctness/gate/tests/gate-fixture.js +153 -0
- package/dist/os/correctness/gate/tests/gate-fixture.js.map +1 -0
- package/dist/os/correctness/gate/types.d.ts +102 -0
- package/dist/os/correctness/gate/types.d.ts.map +1 -0
- package/dist/os/correctness/gate/types.js +64 -0
- package/dist/os/correctness/gate/types.js.map +1 -0
- package/dist/os/correctness/handlers/audit.d.ts +4 -0
- package/dist/os/correctness/handlers/audit.d.ts.map +1 -0
- package/dist/os/correctness/handlers/audit.js +95 -0
- package/dist/os/correctness/handlers/audit.js.map +1 -0
- package/dist/os/correctness/handlers/gate.d.ts +4 -0
- package/dist/os/correctness/handlers/gate.d.ts.map +1 -0
- package/dist/os/correctness/handlers/gate.js +62 -0
- package/dist/os/correctness/handlers/gate.js.map +1 -0
- package/dist/os/correctness/handlers/validate.d.ts +19 -0
- package/dist/os/correctness/handlers/validate.d.ts.map +1 -0
- package/dist/os/correctness/handlers/validate.js +367 -0
- package/dist/os/correctness/handlers/validate.js.map +1 -0
- package/dist/os/correctness/index.d.ts +8 -0
- package/dist/os/correctness/index.d.ts.map +1 -0
- package/dist/os/correctness/index.js +23 -0
- package/dist/os/correctness/index.js.map +1 -0
- package/dist/os/correctness/manifest-schema.d.ts +155 -0
- package/dist/os/correctness/manifest-schema.d.ts.map +1 -0
- package/dist/os/correctness/manifest-schema.js +110 -0
- package/dist/os/correctness/manifest-schema.js.map +1 -0
- package/dist/os/correctness/references.d.ts +22 -0
- package/dist/os/correctness/references.d.ts.map +1 -0
- package/dist/os/correctness/references.js +129 -0
- package/dist/os/correctness/references.js.map +1 -0
- package/dist/os/correctness/tests/fixture-workspace.d.ts +23 -0
- package/dist/os/correctness/tests/fixture-workspace.d.ts.map +1 -0
- package/dist/os/correctness/tests/fixture-workspace.js +104 -0
- package/dist/os/correctness/tests/fixture-workspace.js.map +1 -0
- package/dist/os/correctness/workspace.d.ts +32 -0
- package/dist/os/correctness/workspace.d.ts.map +1 -0
- package/dist/os/correctness/workspace.js +147 -0
- package/dist/os/correctness/workspace.js.map +1 -0
- package/dist/os/flow/correctness-step.d.ts +19 -0
- package/dist/os/flow/correctness-step.d.ts.map +1 -0
- package/dist/os/flow/correctness-step.js +133 -0
- package/dist/os/flow/correctness-step.js.map +1 -0
- package/dist/os/flow/digest.d.ts +18 -0
- package/dist/os/flow/digest.d.ts.map +1 -1
- package/dist/os/flow/digest.js +28 -1
- package/dist/os/flow/digest.js.map +1 -1
- package/dist/os/flow/flow.module.d.ts.map +1 -1
- package/dist/os/flow/flow.module.js +17 -3
- package/dist/os/flow/flow.module.js.map +1 -1
- package/dist/os/flow/handlers/flow-digest.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-digest.js +11 -1
- package/dist/os/flow/handlers/flow-digest.js.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.d.ts +11 -0
- package/dist/os/flow/handlers/flow-integrate.d.ts.map +1 -1
- package/dist/os/flow/handlers/flow-integrate.js +90 -5
- package/dist/os/flow/handlers/flow-integrate.js.map +1 -1
- package/dist/os/flow/post-rebase-regen.d.ts +33 -0
- package/dist/os/flow/post-rebase-regen.d.ts.map +1 -0
- package/dist/os/flow/post-rebase-regen.js +120 -0
- package/dist/os/flow/post-rebase-regen.js.map +1 -0
- package/dist/os/flow/preflight.d.ts.map +1 -1
- package/dist/os/flow/preflight.js +11 -15
- package/dist/os/flow/preflight.js.map +1 -1
- package/dist/os/flow/publish.d.ts.map +1 -1
- package/dist/os/flow/publish.js +23 -4
- package/dist/os/flow/publish.js.map +1 -1
- package/dist/os/flow/registry.d.ts +4 -4
- package/dist/os/flow/tests/helpers.d.ts +9 -1
- package/dist/os/flow/tests/helpers.d.ts.map +1 -1
- package/dist/os/flow/tests/helpers.js +36 -2
- package/dist/os/flow/tests/helpers.js.map +1 -1
- package/dist/os/friction/types.d.ts +2 -2
- package/dist/os/gate-run/status.d.ts +12 -0
- package/dist/os/gate-run/status.d.ts.map +1 -1
- package/dist/os/gate-run/status.js +24 -3
- package/dist/os/gate-run/status.js.map +1 -1
- package/dist/os/program/schemas.d.ts +3 -3
- package/dist/os/queue/types.d.ts +2 -2
- package/dist/os/rfc/handlers/implement-stamp-promotes.d.ts +8 -0
- package/dist/os/rfc/handlers/implement-stamp-promotes.d.ts.map +1 -0
- package/dist/os/rfc/handlers/implement-stamp-promotes.js +65 -0
- package/dist/os/rfc/handlers/implement-stamp-promotes.js.map +1 -0
- package/dist/os/rfc/handlers/implement-stamp.d.ts.map +1 -1
- package/dist/os/rfc/handlers/implement-stamp.js +15 -2
- package/dist/os/rfc/handlers/implement-stamp.js.map +1 -1
- package/dist/os/rfc/handlers/validate-rules.d.ts.map +1 -1
- package/dist/os/rfc/handlers/validate-rules.js +26 -5
- package/dist/os/rfc/handlers/validate-rules.js.map +1 -1
- package/dist/os/rfc/rfc.module.d.ts.map +1 -1
- package/dist/os/rfc/rfc.module.js +18 -6
- package/dist/os/rfc/rfc.module.js.map +1 -1
- package/dist/os/rfc/types.d.ts +12 -3
- package/dist/os/rfc/types.d.ts.map +1 -1
- package/dist/os/rfc/types.js +5 -2
- package/dist/os/rfc/types.js.map +1 -1
- package/dist/os/rfc/verify-workspace.d.ts +12 -0
- package/dist/os/rfc/verify-workspace.d.ts.map +1 -1
- package/dist/os/rfc/verify-workspace.js +155 -0
- package/dist/os/rfc/verify-workspace.js.map +1 -1
- package/dist/os/system/task-schemas.d.ts +1 -1
- package/dist/os/system/tests/helpers.d.ts.map +1 -1
- package/dist/os/system/tests/helpers.js +6 -1
- package/dist/os/system/tests/helpers.js.map +1 -1
- package/dist/os/werkstatt/handlers/schema.d.ts +1 -1
- package/dist/src/command-modules.d.ts +4 -0
- package/dist/src/command-modules.d.ts.map +1 -0
- package/dist/src/command-modules.js +42 -0
- package/dist/src/command-modules.js.map +1 -0
- package/dist/src/config/forge-config.d.ts +16 -1
- package/dist/src/config/forge-config.d.ts.map +1 -1
- package/dist/src/config/forge-config.js +27 -11
- package/dist/src/config/forge-config.js.map +1 -1
- package/dist/src/correctness/index.d.ts +32 -0
- package/dist/src/correctness/index.d.ts.map +1 -0
- package/dist/src/correctness/index.js +157 -0
- package/dist/src/correctness/index.js.map +1 -0
- package/dist/src/correctness/schema-hash.d.ts +15 -0
- package/dist/src/correctness/schema-hash.d.ts.map +1 -0
- package/dist/src/correctness/schema-hash.js +44 -0
- package/dist/src/correctness/schema-hash.js.map +1 -0
- package/dist/src/knowledge/schema.d.ts +1 -1
- package/dist/src/onboarding/agents-generate.d.ts.map +1 -1
- package/dist/src/onboarding/agents-generate.js +20 -3
- package/dist/src/onboarding/agents-generate.js.map +1 -1
- package/dist/src/onboarding/create.d.ts +7 -0
- package/dist/src/onboarding/create.d.ts.map +1 -1
- package/dist/src/onboarding/create.js +62 -9
- package/dist/src/onboarding/create.js.map +1 -1
- package/docs/reference/correctness-audit.md +91 -0
- package/docs/reference/correctness-gate.md +102 -0
- package/docs/reference/correctness-manifest.md +142 -0
- package/docs/reference/forge-yaml.md +15 -0
- package/os/codebase/codebase.module.ts +57 -0
- package/os/codebase/handlers/codebase-measure-symbols.ts +131 -0
- package/os/codebase/handlers/codebase-measure.ts +503 -0
- package/os/codebase/index.ts +21 -0
- package/os/codebase/types.ts +55 -0
- package/os/core/handlers/package-health.test.ts +24 -2
- package/os/core/handlers/package-health.ts +16 -19
- package/os/correctness/anchors.ts +182 -0
- package/os/correctness/audit/bindings-verify-substance.test.ts +79 -0
- package/os/correctness/audit/bindings-verify-substance.ts +155 -0
- package/os/correctness/audit/differential.test.ts +113 -0
- package/os/correctness/audit/differential.ts +131 -0
- package/os/correctness/audit/ledger-orphans.test.ts +96 -0
- package/os/correctness/audit/ledger-orphans.ts +84 -0
- package/os/correctness/audit/ledger.test.ts +65 -0
- package/os/correctness/audit/ledger.ts +103 -0
- package/os/correctness/audit/run.ts +220 -0
- package/os/correctness/audit/schema-db.ts +208 -0
- package/os/correctness/audit/snapshot.ts +211 -0
- package/os/correctness/audit/sql-scanner.test.ts +84 -0
- package/os/correctness/audit/sql-scanner.ts +289 -0
- package/os/correctness/audit/sql-schema-conform.test.ts +170 -0
- package/os/correctness/audit/sql-schema-conform.ts +178 -0
- package/os/correctness/audit/state-transitions-coverage.test.ts +141 -0
- package/os/correctness/audit/state-transitions-coverage.ts +271 -0
- package/os/correctness/audit/tests/git-fixture.ts +98 -0
- package/os/correctness/audit/types.ts +91 -0
- package/os/correctness/correctness-capture.test.ts +107 -0
- package/os/correctness/correctness-chain.test.ts +232 -0
- package/os/correctness/correctness-coverage.test.ts +86 -0
- package/os/correctness/correctness-mode.test.ts +108 -0
- package/os/correctness/correctness-substrate.test.ts +64 -0
- package/os/correctness/correctness.module.ts +182 -0
- package/os/correctness/gate/anchor-events.test.ts +77 -0
- package/os/correctness/gate/freeze-coverage.test.ts +218 -0
- package/os/correctness/gate/freeze-diff.test.ts +110 -0
- package/os/correctness/gate/frozen.ts +399 -0
- package/os/correctness/gate/gate-mode.test.ts +76 -0
- package/os/correctness/gate/hardening.test.ts +175 -0
- package/os/correctness/gate/oracle-edit.test.ts +83 -0
- package/os/correctness/gate/oracle-origin.test.ts +142 -0
- package/os/correctness/gate/origin.ts +175 -0
- package/os/correctness/gate/repo.ts +102 -0
- package/os/correctness/gate/run.ts +547 -0
- package/os/correctness/gate/runner.ts +136 -0
- package/os/correctness/gate/substrate-attestation.test.ts +71 -0
- package/os/correctness/gate/tests/gate-fixture.ts +205 -0
- package/os/correctness/gate/tier-high.test.ts +92 -0
- package/os/correctness/gate/types.ts +144 -0
- package/os/correctness/handlers/audit.ts +107 -0
- package/os/correctness/handlers/gate.ts +75 -0
- package/os/correctness/handlers/validate.ts +514 -0
- package/os/correctness/index.ts +24 -0
- package/os/correctness/manifest-schema.ts +174 -0
- package/os/correctness/references.ts +143 -0
- package/os/correctness/tests/fixture-workspace.ts +119 -0
- package/os/correctness/workspace.ts +167 -0
- package/os/flow/correctness-step.ts +166 -0
- package/os/flow/digest.ts +40 -1
- package/os/flow/flow.module.ts +18 -3
- package/os/flow/handlers/flow-digest.ts +11 -1
- package/os/flow/handlers/flow-integrate.ts +117 -5
- package/os/flow/post-rebase-regen.ts +170 -0
- package/os/flow/preflight.ts +11 -19
- package/os/flow/publish.ts +23 -4
- package/os/flow/tests/flow-detachable.test.ts +31 -0
- package/os/flow/tests/flow-digest-correctness-trail.test.ts +55 -0
- package/os/flow/tests/flow-integrate-correctness-gate.test.ts +275 -0
- package/os/flow/tests/flow-integrate.post-rebase-regen.test.ts +234 -0
- package/os/flow/tests/flow-integrate.test.ts +10 -9
- package/os/flow/tests/helpers.ts +45 -24
- package/os/gate-run/status.ts +36 -3
- package/os/gate-run/tests/gate-run-status.test.ts +114 -0
- package/os/rfc/handlers/implement-stamp-promotes.test.ts +214 -0
- package/os/rfc/handlers/implement-stamp-promotes.ts +79 -0
- package/os/rfc/handlers/implement-stamp.ts +16 -2
- package/os/rfc/handlers/validate-rules.ts +43 -5
- package/os/rfc/rfc.module.ts +19 -6
- package/os/rfc/types.ts +16 -2
- package/os/rfc/verify-workspace-manifest.test.ts +55 -0
- package/os/rfc/verify-workspace.ts +167 -0
- package/os/system/tests/helpers.ts +6 -1
- package/package.json +41 -1
- package/profiles/typescript.yaml +16 -0
- package/skills/_shared/agent-operating-model.md +4 -0
- package/skills/fo/fo-idea-audit/SKILL.md +4 -0
- package/skills/fo/fo-idea-create-rfc/SKILL.md +6 -2
- package/skills/fo/fo-idea-implement/SKILL.md +8 -2
- package/skills/fo/fo-review/SKILL.md +16 -2
- package/src/command-modules.ts +62 -0
- package/src/config/forge-config.ts +37 -11
- package/src/correctness/index.ts +192 -0
- package/src/correctness/schema-hash.ts +59 -0
- package/src/onboarding/agents-generate.ts +20 -3
- package/src/onboarding/create.ts +59 -9
- package/src/tests/agents-generate-detach.test.ts +126 -0
- package/src/tests/codebase-measure-rfc-1581.test.ts +260 -0
- package/src/tests/command-modules.test.ts +34 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC-1579 AC-3: differential attribution — a finding already present at
|
|
4
|
+
the base with the same occurrence count is `legacy`; a higher count is
|
|
5
|
+
`introduced`; a base-only finding is `resolved`; an allow-listed finding is
|
|
6
|
+
`accepted`; only introduced errors fail the run; --staged judges the index.</purpose>
|
|
7
|
+
<non-goals>
|
|
8
|
+
<item>Not a contract source of truth — differential.ts owns behaviour.</item>
|
|
9
|
+
</non-goals>
|
|
10
|
+
</MODULE_CONTRACT>
|
|
11
|
+
<CHANGE_SUMMARY>
|
|
12
|
+
<item>RFC-1579: initial suite.</item>
|
|
13
|
+
<item>RFC-1579: correctness.audit auditors and differential attribution
|
|
14
|
+
|
|
15
|
+
Add os/correctness/audit: tree snapshots (working tree, index, base via one cat-file batch with git-grep prefilter), literal scanner + SQL classifier, wrangler D1 schema builder on node:sqlite, the four auditors (sql.schema.conform, ledger.orphans, state.transitions.coverage, bindings.verify.substance), subject-keyed differential attribution with allow-list, survival ledger, the correctness.audit handler and registration, and bindings.paths.correctnessLedger.</item>
|
|
16
|
+
<item>RFC-1579: close review REVIEW-CODE-2026-11-13-01 findings
|
|
17
|
+
|
|
18
|
+
F1 INSERT 'has no column named' is a finding; F2 severity/kind escalation since base is introduced; F3 unparseable machine tables are errors; F4 comma joins, string literals and comments in table extraction; F5 only migration INSERT/REPLACE seed writes; F6 SET-clause-only coverage; F7 method-call writers; F8 regex literals in the scanner; F9 alias resolution; F10 EC-34 judges the payload only; F11 EC-34 before the scoped gates with a dry-run line; F12/F13 config and YAML errors named; F14 config-only check skips snapshots; F15 git grep failures fail closed; F16 portable prefilter; F17 shell no-ops; F18 shared D1 schemas; in-code DDL scoped per package; ledger tests. DEV-1..DEV-4 recorded in the RFC Deviations section.</item>
|
|
19
|
+
</CHANGE_SUMMARY>
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
23
|
+
|
|
24
|
+
import { runCorrectnessAudit } from "./run.ts";
|
|
25
|
+
import { BASE_CODE, FORGE_YAML, makeGitFixture, type GitFixture } from "./tests/git-fixture.ts";
|
|
26
|
+
|
|
27
|
+
const fixtures: GitFixture[] = [];
|
|
28
|
+
afterEach(() => fixtures.splice(0).forEach((f) => f.cleanup()));
|
|
29
|
+
|
|
30
|
+
const BAD = `export const pending = (db: D1) => db.prepare("SELECT id FROM openers WHERE candidate_id = ?");\n`;
|
|
31
|
+
const BAD_TWICE =
|
|
32
|
+
BAD +
|
|
33
|
+
`export const again = (db: D1) => db.prepare("SELECT id FROM openers WHERE candidate_id = 1");\n`;
|
|
34
|
+
|
|
35
|
+
const conform = async (root: string, opts: Parameters<typeof runCorrectnessAudit>[1]) => {
|
|
36
|
+
const out = await runCorrectnessAudit(root, opts);
|
|
37
|
+
if (!out.ok) throw new Error(out.usageError);
|
|
38
|
+
return {
|
|
39
|
+
result: out.result,
|
|
40
|
+
finding: out.result.findings.find((x) => x.check === "sql.schema.conform"),
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
describe("differential attribution", () => {
|
|
45
|
+
it("AC-3: a finding present at base with the same occurrence count is legacy and never blocks", async () => {
|
|
46
|
+
const f = makeGitFixture({ "apps/api/src/legacy.ts": BAD });
|
|
47
|
+
fixtures.push(f);
|
|
48
|
+
f.write("apps/api/src/dispatch.ts", BASE_CODE + "\n// unrelated edit\n");
|
|
49
|
+
const { result, finding } = await conform(f.root, { base: f.base });
|
|
50
|
+
expect(finding?.attribution).toBe("legacy");
|
|
51
|
+
expect(finding?.occurrences).toBe(1);
|
|
52
|
+
expect(result.status, "legacy findings must not change the exit status").toBe("pass");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("a higher occurrence count of a legacy subject is introduced", async () => {
|
|
56
|
+
const f = makeGitFixture({ "apps/api/src/legacy.ts": BAD });
|
|
57
|
+
fixtures.push(f);
|
|
58
|
+
f.write("apps/api/src/legacy.ts", BAD_TWICE);
|
|
59
|
+
const { result, finding } = await conform(f.root, { base: f.base });
|
|
60
|
+
expect(finding?.attribution).toBe("introduced");
|
|
61
|
+
expect(finding?.occurrences).toBe(2);
|
|
62
|
+
expect(result.status).toBe("fail");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("a base-only finding is resolved", async () => {
|
|
66
|
+
const f = makeGitFixture({ "apps/api/src/legacy.ts": BAD });
|
|
67
|
+
fixtures.push(f);
|
|
68
|
+
f.write("apps/api/src/legacy.ts", "export {};\n");
|
|
69
|
+
const { result, finding } = await conform(f.root, { base: f.base });
|
|
70
|
+
expect(finding?.attribution).toBe("resolved");
|
|
71
|
+
expect(result.status).toBe("pass");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("an allow-listed finding is accepted", async () => {
|
|
75
|
+
const allow = `${FORGE_YAML}correctness:\n audit:\n allow:\n - check: sql.schema.conform\n subject: "apps/api/src/new.ts:openers.candidate_id"\n reason: "column added by an external system"\n`;
|
|
76
|
+
const f = makeGitFixture({ "forge.yaml": allow });
|
|
77
|
+
fixtures.push(f);
|
|
78
|
+
f.write("apps/api/src/new.ts", BAD);
|
|
79
|
+
const { result, finding } = await conform(f.root, { base: f.base });
|
|
80
|
+
expect(finding?.attribution).toBe("accepted");
|
|
81
|
+
expect(result.status).toBe("pass");
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("--staged judges the index against HEAD, ignoring unstaged edits", async () => {
|
|
85
|
+
const f = makeGitFixture();
|
|
86
|
+
fixtures.push(f);
|
|
87
|
+
f.write("apps/api/src/new.ts", BAD);
|
|
88
|
+
const unstaged = await conform(f.root, { staged: true });
|
|
89
|
+
expect(unstaged.finding).toBeUndefined();
|
|
90
|
+
f.git(["add", "apps/api/src/new.ts"]);
|
|
91
|
+
const staged = await conform(f.root, { staged: true });
|
|
92
|
+
expect(staged.finding?.attribution).toBe("introduced");
|
|
93
|
+
expect(staged.result.base).toBe(f.base);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("a finding whose severity or kind escalates since base is introduced (untouched → written-never-read)", async () => {
|
|
97
|
+
const f = makeGitFixture({
|
|
98
|
+
"apps/api/migrations/0002_a.sql": "CREATE TABLE assessments (id TEXT);\n",
|
|
99
|
+
});
|
|
100
|
+
fixtures.push(f);
|
|
101
|
+
f.write(
|
|
102
|
+
"apps/api/src/assess.ts",
|
|
103
|
+
'export const w = "INSERT INTO assessments (id) VALUES (?)";\n',
|
|
104
|
+
);
|
|
105
|
+
const out = await runCorrectnessAudit(f.root, { base: f.base, check: "ledger.orphans" });
|
|
106
|
+
if (!out.ok) throw new Error(out.usageError);
|
|
107
|
+
const finding = out.result.findings.find(
|
|
108
|
+
(x) => x.subject === "assessments" && x.attribution !== "resolved",
|
|
109
|
+
);
|
|
110
|
+
expect(finding?.message).toMatch(/^written-never-read/);
|
|
111
|
+
expect(finding?.attribution, "a warning that became an error must block").toBe("introduced");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC-1579 differential attribution — findings are keyed by
|
|
4
|
+
`sha256(check + "\0" + subject)` with an occurrence count; a code finding is
|
|
5
|
+
`introduced` when its key is new or its count grew since the base revision,
|
|
6
|
+
`legacy` when present at base with an equal or higher count, `resolved` when
|
|
7
|
+
present at base only. Configuration findings (CORR-AUDIT-04) are always
|
|
8
|
+
`introduced`. Allow-listed findings (`correctness.audit.allow[]`) are
|
|
9
|
+
`accepted`.</purpose>
|
|
10
|
+
<non-goals>
|
|
11
|
+
<item>No line-based attribution — subject keys are immune to line shifts.</item>
|
|
12
|
+
<item>No exit-code decisions — run.ts derives status from introduced errors only.</item>
|
|
13
|
+
</non-goals>
|
|
14
|
+
</MODULE_CONTRACT>
|
|
15
|
+
<CHANGE_SUMMARY>
|
|
16
|
+
<item>RFC-1579: initial attribution.</item>
|
|
17
|
+
<item>RFC-1579: correctness.audit auditors and differential attribution
|
|
18
|
+
|
|
19
|
+
Add os/correctness/audit: tree snapshots (working tree, index, base via one cat-file batch with git-grep prefilter), literal scanner + SQL classifier, wrangler D1 schema builder on node:sqlite, the four auditors (sql.schema.conform, ledger.orphans, state.transitions.coverage, bindings.verify.substance), subject-keyed differential attribution with allow-list, survival ledger, the correctness.audit handler and registration, and bindings.paths.correctnessLedger.</item>
|
|
20
|
+
<item>RFC-1579: close review REVIEW-CODE-2026-11-13-01 findings
|
|
21
|
+
|
|
22
|
+
F1 INSERT 'has no column named' is a finding; F2 severity/kind escalation since base is introduced; F3 unparseable machine tables are errors; F4 comma joins, string literals and comments in table extraction; F5 only migration INSERT/REPLACE seed writes; F6 SET-clause-only coverage; F7 method-call writers; F8 regex literals in the scanner; F9 alias resolution; F10 EC-34 judges the payload only; F11 EC-34 before the scoped gates with a dry-run line; F12/F13 config and YAML errors named; F14 config-only check skips snapshots; F15 git grep failures fail closed; F16 portable prefilter; F17 shell no-ops; F18 shared D1 schemas; in-code DDL scoped per package; ledger tests. DEV-1..DEV-4 recorded in the RFC Deviations section.</item>
|
|
23
|
+
</CHANGE_SUMMARY>
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { createHash } from "node:crypto";
|
|
27
|
+
|
|
28
|
+
import {
|
|
29
|
+
AUDIT_RULE_OF,
|
|
30
|
+
CODE_CHECKS,
|
|
31
|
+
type AllowEntry,
|
|
32
|
+
type AuditFinding,
|
|
33
|
+
type RawFinding,
|
|
34
|
+
} from "./types.ts";
|
|
35
|
+
|
|
36
|
+
const SEVERITY_RANK: Record<RawFinding["severity"], number> = { info: 0, warning: 1, error: 2 };
|
|
37
|
+
|
|
38
|
+
export function findingKey(check: string, subject: string): string {
|
|
39
|
+
return createHash("sha256").update(`${check}\0${subject}`).digest("hex");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface Grouped {
|
|
43
|
+
first: RawFinding;
|
|
44
|
+
count: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function group(findings: RawFinding[]): Map<string, Grouped> {
|
|
48
|
+
const out = new Map<string, Grouped>();
|
|
49
|
+
for (const f of findings) {
|
|
50
|
+
const key = findingKey(f.check, f.subject);
|
|
51
|
+
const g = out.get(key);
|
|
52
|
+
if (g) g.count += 1;
|
|
53
|
+
else out.set(key, { first: f, count: 1 });
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function toFinding(
|
|
59
|
+
key: string,
|
|
60
|
+
g: Grouped,
|
|
61
|
+
attribution: AuditFinding["attribution"],
|
|
62
|
+
): AuditFinding {
|
|
63
|
+
return {
|
|
64
|
+
rule: AUDIT_RULE_OF[g.first.check],
|
|
65
|
+
check: g.first.check,
|
|
66
|
+
key,
|
|
67
|
+
subject: g.first.subject,
|
|
68
|
+
occurrences: g.count,
|
|
69
|
+
severity: g.first.severity,
|
|
70
|
+
attribution,
|
|
71
|
+
...(g.first.location ? { location: g.first.location } : {}),
|
|
72
|
+
message: g.first.message,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Attribute `now` findings against `base` findings (code checks) and apply the allow-list. */
|
|
77
|
+
export function attribute(
|
|
78
|
+
base: RawFinding[],
|
|
79
|
+
now: RawFinding[],
|
|
80
|
+
allow: AllowEntry[],
|
|
81
|
+
): AuditFinding[] {
|
|
82
|
+
const allowed = new Set(allow.map((a) => findingKey(a.check, a.subject)));
|
|
83
|
+
const baseCode = group(base.filter((f) => CODE_CHECKS.has(f.check)));
|
|
84
|
+
const nowGroups = group(now);
|
|
85
|
+
const out: AuditFinding[] = [];
|
|
86
|
+
for (const [key, g] of nowGroups) {
|
|
87
|
+
let attribution: AuditFinding["attribution"];
|
|
88
|
+
if (!CODE_CHECKS.has(g.first.check)) attribution = "introduced";
|
|
89
|
+
else {
|
|
90
|
+
const prior = baseCode.get(key);
|
|
91
|
+
// A finding is legacy only when the base already had it at the same or a
|
|
92
|
+
// higher count AND the same or a higher severity with the same message
|
|
93
|
+
// kind (untouched warning → written-never-read error is introduced).
|
|
94
|
+
const kindOf = (f: RawFinding) => f.message.split(":")[0];
|
|
95
|
+
attribution =
|
|
96
|
+
prior &&
|
|
97
|
+
prior.count >= g.count &&
|
|
98
|
+
SEVERITY_RANK[prior.first.severity] >= SEVERITY_RANK[g.first.severity] &&
|
|
99
|
+
kindOf(prior.first) === kindOf(g.first)
|
|
100
|
+
? "legacy"
|
|
101
|
+
: "introduced";
|
|
102
|
+
}
|
|
103
|
+
if (allowed.has(key)) attribution = "accepted";
|
|
104
|
+
out.push(toFinding(key, g, attribution));
|
|
105
|
+
}
|
|
106
|
+
for (const [key, g] of baseCode) {
|
|
107
|
+
if (!nowGroups.has(key)) out.push(toFinding(key, g, "resolved"));
|
|
108
|
+
}
|
|
109
|
+
const order = { introduced: 0, accepted: 1, legacy: 2, resolved: 3 };
|
|
110
|
+
return out.sort(
|
|
111
|
+
(a, b) =>
|
|
112
|
+
order[a.attribution] - order[b.attribution] ||
|
|
113
|
+
a.check.localeCompare(b.check) ||
|
|
114
|
+
a.subject.localeCompare(b.subject),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Parse `correctness.audit.allow[]` from a forge.yaml document object; malformed rows are dropped. */
|
|
119
|
+
export function readAllowList(config: unknown): AllowEntry[] {
|
|
120
|
+
const allow = (config as { correctness?: { audit?: { allow?: unknown } } })?.correctness?.audit
|
|
121
|
+
?.allow;
|
|
122
|
+
if (!Array.isArray(allow)) return [];
|
|
123
|
+
return allow.filter(
|
|
124
|
+
(a): a is AllowEntry =>
|
|
125
|
+
!!a &&
|
|
126
|
+
typeof (a as AllowEntry).check === "string" &&
|
|
127
|
+
typeof (a as AllowEntry).subject === "string" &&
|
|
128
|
+
typeof (a as AllowEntry).reason === "string" &&
|
|
129
|
+
(a as AllowEntry).reason.trim().length > 0,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC-1579 AC-4: `ledger.orphans` — a table statements insert into but
|
|
4
|
+
never select from is a `written-never-read` error with subject = table; a
|
|
5
|
+
read-only table is `read-never-written`; an untouched table only warns;
|
|
6
|
+
migration INSERTs count as writes.</purpose>
|
|
7
|
+
<non-goals>
|
|
8
|
+
<item>Not a contract source of truth — the auditor owns behaviour.</item>
|
|
9
|
+
</non-goals>
|
|
10
|
+
</MODULE_CONTRACT>
|
|
11
|
+
<CHANGE_SUMMARY>
|
|
12
|
+
<item>RFC-1579: initial suite.</item>
|
|
13
|
+
<item>RFC-1579: correctness.audit auditors and differential attribution
|
|
14
|
+
|
|
15
|
+
Add os/correctness/audit: tree snapshots (working tree, index, base via one cat-file batch with git-grep prefilter), literal scanner + SQL classifier, wrangler D1 schema builder on node:sqlite, the four auditors (sql.schema.conform, ledger.orphans, state.transitions.coverage, bindings.verify.substance), subject-keyed differential attribution with allow-list, survival ledger, the correctness.audit handler and registration, and bindings.paths.correctnessLedger.</item>
|
|
16
|
+
<item>RFC-1579: close review REVIEW-CODE-2026-11-13-01 findings
|
|
17
|
+
|
|
18
|
+
F1 INSERT 'has no column named' is a finding; F2 severity/kind escalation since base is introduced; F3 unparseable machine tables are errors; F4 comma joins, string literals and comments in table extraction; F5 only migration INSERT/REPLACE seed writes; F6 SET-clause-only coverage; F7 method-call writers; F8 regex literals in the scanner; F9 alias resolution; F10 EC-34 judges the payload only; F11 EC-34 before the scoped gates with a dry-run line; F12/F13 config and YAML errors named; F14 config-only check skips snapshots; F15 git grep failures fail closed; F16 portable prefilter; F17 shell no-ops; F18 shared D1 schemas; in-code DDL scoped per package; ledger tests. DEV-1..DEV-4 recorded in the RFC Deviations section.</item>
|
|
19
|
+
</CHANGE_SUMMARY>
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
23
|
+
|
|
24
|
+
import { runCorrectnessAudit } from "./run.ts";
|
|
25
|
+
import { BASE_CODE, MIGRATION, makeGitFixture, type GitFixture } from "./tests/git-fixture.ts";
|
|
26
|
+
|
|
27
|
+
const fixtures: GitFixture[] = [];
|
|
28
|
+
afterEach(() => fixtures.splice(0).forEach((f) => f.cleanup()));
|
|
29
|
+
|
|
30
|
+
const orphans = async (files: Record<string, string>) => {
|
|
31
|
+
const f = makeGitFixture();
|
|
32
|
+
fixtures.push(f);
|
|
33
|
+
for (const [rel, body] of Object.entries(files)) f.write(rel, body);
|
|
34
|
+
const out = await runCorrectnessAudit(f.root, { base: f.base, check: "ledger.orphans" });
|
|
35
|
+
if (!out.ok) throw new Error(out.usageError);
|
|
36
|
+
return out.result;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
describe("ledger.orphans", () => {
|
|
40
|
+
it("AC-4: a table inserted into but never selected from is a written-never-read error named by the table", async () => {
|
|
41
|
+
const result = await orphans({
|
|
42
|
+
"apps/api/migrations/0002_ledger.sql":
|
|
43
|
+
"CREATE TABLE sent_log (id TEXT PRIMARY KEY, at TEXT);\n",
|
|
44
|
+
"apps/api/src/log.ts": 'export const log = "INSERT INTO sent_log (id, at) VALUES (?, ?)";\n',
|
|
45
|
+
});
|
|
46
|
+
const f = result.findings.find((x) => x.subject === "sent_log");
|
|
47
|
+
expect(f, "a published ledger that nothing reads must be reported").toBeDefined();
|
|
48
|
+
expect(f!.severity).toBe("error");
|
|
49
|
+
expect(f!.message).toMatch(/^written-never-read/);
|
|
50
|
+
expect(f!.attribution).toBe("introduced");
|
|
51
|
+
expect(f!.rule).toBe("CORR-AUDIT-02");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("read-never-written is an error; untouched is a warning; tables with both are quiet", async () => {
|
|
55
|
+
const result = await orphans({
|
|
56
|
+
"apps/api/migrations/0002_more.sql":
|
|
57
|
+
"CREATE TABLE assessments (id TEXT);\nCREATE TABLE knowledge_items (id TEXT);\n",
|
|
58
|
+
"apps/api/src/read.ts": 'export const r = "SELECT id FROM assessments";\n',
|
|
59
|
+
});
|
|
60
|
+
const by = new Map(result.findings.map((x) => [x.subject, x]));
|
|
61
|
+
expect(by.get("assessments")?.message).toMatch(/^read-never-written/);
|
|
62
|
+
expect(by.get("knowledge_items")?.severity).toBe("warning");
|
|
63
|
+
expect(by.get("knowledge_items")?.message).toMatch(/^untouched/);
|
|
64
|
+
expect(by.has("openers")).toBe(false);
|
|
65
|
+
expect(by.has("candidates")).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("a migration INSERT counts as a write", async () => {
|
|
69
|
+
const result = await orphans({
|
|
70
|
+
"apps/api/migrations/0002_seed.sql":
|
|
71
|
+
"CREATE TABLE plans (id TEXT);\nINSERT INTO plans (id) VALUES ('free');\n",
|
|
72
|
+
"apps/api/src/plans.ts": 'export const p = "SELECT id FROM plans";\n',
|
|
73
|
+
});
|
|
74
|
+
expect(result.findings.find((x) => x.subject === "plans")).toBeUndefined();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("the fixture's base tables are covered (sanity)", () => {
|
|
78
|
+
expect(BASE_CODE).toMatch(/INSERT INTO openers/);
|
|
79
|
+
expect(MIGRATION).toMatch(/CREATE TABLE candidates/);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("comma joins read every table; string literals and migration UPDATEs never count", async () => {
|
|
83
|
+
const result = await orphans({
|
|
84
|
+
"apps/api/migrations/0002_x.sql":
|
|
85
|
+
"CREATE TABLE legacy (id TEXT);\nCREATE TABLE audit_log (id TEXT);\nUPDATE audit_log SET id = id;\n",
|
|
86
|
+
"apps/api/src/x.ts":
|
|
87
|
+
"export const r = \"SELECT o.id FROM openers o, candidates c WHERE c.state = 'copied from legacy'\";\n",
|
|
88
|
+
});
|
|
89
|
+
const by = new Map(result.findings.map((x) => [x.subject, x]));
|
|
90
|
+
expect(by.get("legacy")?.message, "a quoted 'from legacy' is not a read").toMatch(/^untouched/);
|
|
91
|
+
expect(by.get("audit_log")?.message, "a migration UPDATE is not a seeding write").toMatch(
|
|
92
|
+
/^untouched/,
|
|
93
|
+
);
|
|
94
|
+
expect(by.has("candidates")).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC-1579 CORR-AUDIT-02 `ledger.orphans` — every table a D1 schema
|
|
4
|
+
declares needs both a writer and a reader among the code statements
|
|
5
|
+
(migration INSERTs count as writes): `read-never-written` and
|
|
6
|
+
`written-never-read` are errors, `untouched` (declared, never read or
|
|
7
|
+
written) is a warning so a migration-first change does not block.</purpose>
|
|
8
|
+
<non-goals>
|
|
9
|
+
<item>No allow-list decisions — differential.ts applies `correctness.audit.allow[]`.</item>
|
|
10
|
+
</non-goals>
|
|
11
|
+
</MODULE_CONTRACT>
|
|
12
|
+
<CHANGE_SUMMARY>
|
|
13
|
+
<item>RFC-1579: initial auditor.</item>
|
|
14
|
+
<item>RFC-1579: correctness.audit auditors and differential attribution
|
|
15
|
+
|
|
16
|
+
Add os/correctness/audit: tree snapshots (working tree, index, base via one cat-file batch with git-grep prefilter), literal scanner + SQL classifier, wrangler D1 schema builder on node:sqlite, the four auditors (sql.schema.conform, ledger.orphans, state.transitions.coverage, bindings.verify.substance), subject-keyed differential attribution with allow-list, survival ledger, the correctness.audit handler and registration, and bindings.paths.correctnessLedger.</item>
|
|
17
|
+
<item>RFC-1579: close review REVIEW-CODE-2026-11-13-01 findings
|
|
18
|
+
|
|
19
|
+
F1 INSERT 'has no column named' is a finding; F2 severity/kind escalation since base is introduced; F3 unparseable machine tables are errors; F4 comma joins, string literals and comments in table extraction; F5 only migration INSERT/REPLACE seed writes; F6 SET-clause-only coverage; F7 method-call writers; F8 regex literals in the scanner; F9 alias resolution; F10 EC-34 judges the payload only; F11 EC-34 before the scoped gates with a dry-run line; F12/F13 config and YAML errors named; F14 config-only check skips snapshots; F15 git grep failures fail closed; F16 portable prefilter; F17 shell no-ops; F18 shared D1 schemas; in-code DDL scoped per package; ledger tests. DEV-1..DEV-4 recorded in the RFC Deviations section.</item>
|
|
20
|
+
</CHANGE_SUMMARY>
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { SchemaDiscovery } from "./schema-db.ts";
|
|
24
|
+
import { tableAccess, type SqlStatement } from "./sql-scanner.ts";
|
|
25
|
+
import type { TreeSnapshot } from "./snapshot.ts";
|
|
26
|
+
import type { AuditorOutput, RawFinding } from "./types.ts";
|
|
27
|
+
|
|
28
|
+
export function auditLedgerOrphans(
|
|
29
|
+
discovery: SchemaDiscovery,
|
|
30
|
+
statements: SqlStatement[],
|
|
31
|
+
snapshot: TreeSnapshot,
|
|
32
|
+
): AuditorOutput {
|
|
33
|
+
const findings: RawFinding[] = [];
|
|
34
|
+
const declared = new Map<string, string>(); // table → first migration declaring it
|
|
35
|
+
for (const schema of discovery.schemas) {
|
|
36
|
+
for (const t of schema.tables) {
|
|
37
|
+
if (declared.has(t)) continue;
|
|
38
|
+
const decl = schema.migrations.find((m) =>
|
|
39
|
+
new RegExp(`CREATE\\s+TABLE\\s+(?:IF\\s+NOT\\s+EXISTS\\s+)?["\`[]?${t}\\b`, "i").test(
|
|
40
|
+
snapshot.files.get(m) ?? "",
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
declared.set(t, decl ?? schema.configFile);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const reads = new Set<string>();
|
|
47
|
+
const writes = new Set<string>();
|
|
48
|
+
for (const st of statements) {
|
|
49
|
+
const access = tableAccess(st.sql);
|
|
50
|
+
access.reads.forEach((t) => reads.add(t));
|
|
51
|
+
access.writes.forEach((t) => writes.add(t));
|
|
52
|
+
}
|
|
53
|
+
for (const schema of discovery.schemas) {
|
|
54
|
+
for (const m of schema.migrations) {
|
|
55
|
+
// Only seeding INSERT/REPLACE targets count from migrations; DDL-time
|
|
56
|
+
// UPDATE/DELETE/SELECT are neither writers nor readers of the ledger.
|
|
57
|
+
const sql = snapshot.files.get(m) ?? "";
|
|
58
|
+
for (const seed of sql.matchAll(
|
|
59
|
+
/\b(?:INSERT\s+(?:OR\s+[A-Za-z]+\s+)?INTO|REPLACE\s+INTO)\s+["`[]?([A-Za-z_][A-Za-z0-9_]*)/gi,
|
|
60
|
+
)) {
|
|
61
|
+
writes.add(seed[1]!.toLowerCase());
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
for (const [table, source] of [...declared.entries()].sort()) {
|
|
66
|
+
const r = reads.has(table);
|
|
67
|
+
const w = writes.has(table);
|
|
68
|
+
if (r && w) continue;
|
|
69
|
+
const kind = r ? "read-never-written" : w ? "written-never-read" : "untouched";
|
|
70
|
+
findings.push({
|
|
71
|
+
check: "ledger.orphans",
|
|
72
|
+
subject: table,
|
|
73
|
+
severity: kind === "untouched" ? "warning" : "error",
|
|
74
|
+
message:
|
|
75
|
+
kind === "untouched"
|
|
76
|
+
? `untouched: declared in ${source}, no statement reads or writes it`
|
|
77
|
+
: kind === "read-never-written"
|
|
78
|
+
? `read-never-written: statements read ${table} but nothing writes it (declared in ${source})`
|
|
79
|
+
: `written-never-read: statements write ${table} but nothing reads it (declared in ${source})`,
|
|
80
|
+
location: { file: source, line: 1 },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return { findings, unverifiable: 0, skipped: [] };
|
|
84
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC-1579: survival ledger merge — legacy/accepted code findings
|
|
4
|
+
survive with their first-seen stamp kept, vanished rows turn resolved,
|
|
5
|
+
introduced and configuration findings never enter the ledger.</purpose>
|
|
6
|
+
<non-goals>
|
|
7
|
+
<item>Not a contract source of truth — ledger.ts owns behaviour.</item>
|
|
8
|
+
</non-goals>
|
|
9
|
+
</MODULE_CONTRACT>
|
|
10
|
+
<CHANGE_SUMMARY>
|
|
11
|
+
<item>RFC-1579: initial suite.</item>
|
|
12
|
+
<item>RFC-1579: close review REVIEW-CODE-2026-11-13-01 findings
|
|
13
|
+
|
|
14
|
+
F1 INSERT 'has no column named' is a finding; F2 severity/kind escalation since base is introduced; F3 unparseable machine tables are errors; F4 comma joins, string literals and comments in table extraction; F5 only migration INSERT/REPLACE seed writes; F6 SET-clause-only coverage; F7 method-call writers; F8 regex literals in the scanner; F9 alias resolution; F10 EC-34 judges the payload only; F11 EC-34 before the scoped gates with a dry-run line; F12/F13 config and YAML errors named; F14 config-only check skips snapshots; F15 git grep failures fail closed; F16 portable prefilter; F17 shell no-ops; F18 shared D1 schemas; in-code DDL scoped per package; ledger tests. DEV-1..DEV-4 recorded in the RFC Deviations section.</item>
|
|
15
|
+
</CHANGE_SUMMARY>
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { describe, expect, it } from "vitest";
|
|
19
|
+
|
|
20
|
+
import { mergeLedger, parseLedger, serializeLedger } from "./ledger.ts";
|
|
21
|
+
import type { AuditFinding } from "./types.ts";
|
|
22
|
+
|
|
23
|
+
const finding = (
|
|
24
|
+
subject: string,
|
|
25
|
+
attribution: AuditFinding["attribution"],
|
|
26
|
+
check: AuditFinding["check"] = "ledger.orphans",
|
|
27
|
+
): AuditFinding => ({
|
|
28
|
+
rule: "CORR-AUDIT-02",
|
|
29
|
+
check,
|
|
30
|
+
key: `k-${subject}`,
|
|
31
|
+
subject,
|
|
32
|
+
occurrences: 1,
|
|
33
|
+
severity: "warning",
|
|
34
|
+
attribution,
|
|
35
|
+
message: "untouched",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe("survival ledger", () => {
|
|
39
|
+
it("keeps firstSeen, refreshes lastSeen, resolves vanished rows, skips introduced/config findings", () => {
|
|
40
|
+
const first = mergeLedger(
|
|
41
|
+
parseLedger(null),
|
|
42
|
+
[finding("events", "legacy"), finding("old", "accepted")],
|
|
43
|
+
{ sha: "a1", date: "2026-11-01" },
|
|
44
|
+
);
|
|
45
|
+
expect(first.rows.map((r) => r.subject)).toEqual(["events", "old"]);
|
|
46
|
+
const second = mergeLedger(
|
|
47
|
+
parseLedger(serializeLedger(first)),
|
|
48
|
+
[
|
|
49
|
+
finding("events", "legacy"),
|
|
50
|
+
finding("new", "introduced"),
|
|
51
|
+
finding("bindings.commands.verify", "legacy", "bindings.verify.substance"),
|
|
52
|
+
],
|
|
53
|
+
{ sha: "b2", date: "2026-11-13" },
|
|
54
|
+
);
|
|
55
|
+
const by = new Map(second.rows.map((r) => [r.subject, r]));
|
|
56
|
+
expect(by.get("events")).toMatchObject({
|
|
57
|
+
status: "surviving",
|
|
58
|
+
firstSeen: { sha: "a1" },
|
|
59
|
+
lastSeen: { sha: "b2" },
|
|
60
|
+
});
|
|
61
|
+
expect(by.get("old")).toMatchObject({ status: "resolved", lastSeen: { sha: "a1" } });
|
|
62
|
+
expect(by.has("new")).toBe(false);
|
|
63
|
+
expect(by.has("bindings.commands.verify")).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/*
|
|
2
|
+
<MODULE_CONTRACT>
|
|
3
|
+
<purpose>RFC-1579 survival ledger — one row per legacy or accepted code
|
|
4
|
+
finding (`key`, `check`, `subject`, `firstSeen`/`lastSeen` as `{sha, date}`,
|
|
5
|
+
`status: surviving | resolved`) at `bindings.paths.correctnessLedger`.
|
|
6
|
+
It measures how long accepted debt survives; nothing gates on it.</purpose>
|
|
7
|
+
<non-goals>
|
|
8
|
+
<item>Never written by a gate — only `correctness.audit --write-ledger`.</item>
|
|
9
|
+
<item>No werkstatt-site maintenance-debt baseline reuse — consumers do not ship werkstatt-site.</item>
|
|
10
|
+
</non-goals>
|
|
11
|
+
</MODULE_CONTRACT>
|
|
12
|
+
<CHANGE_SUMMARY>
|
|
13
|
+
<item>RFC-1579: initial ledger merge and serialization.</item>
|
|
14
|
+
<item>RFC-1579: correctness.audit auditors and differential attribution
|
|
15
|
+
|
|
16
|
+
Add os/correctness/audit: tree snapshots (working tree, index, base via one cat-file batch with git-grep prefilter), literal scanner + SQL classifier, wrangler D1 schema builder on node:sqlite, the four auditors (sql.schema.conform, ledger.orphans, state.transitions.coverage, bindings.verify.substance), subject-keyed differential attribution with allow-list, survival ledger, the correctness.audit handler and registration, and bindings.paths.correctnessLedger.</item>
|
|
17
|
+
</CHANGE_SUMMARY>
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
21
|
+
|
|
22
|
+
import type { AuditFinding } from "./types.ts";
|
|
23
|
+
|
|
24
|
+
export const LEDGER_SCHEMA = "forge/correctness-ledger@1" as const;
|
|
25
|
+
export const DEFAULT_LEDGER_PATH = "docs/maintenance-debt/correctness.ledger.yaml";
|
|
26
|
+
|
|
27
|
+
export interface LedgerStamp {
|
|
28
|
+
sha: string;
|
|
29
|
+
date: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface LedgerRow {
|
|
33
|
+
key: string;
|
|
34
|
+
check: string;
|
|
35
|
+
subject: string;
|
|
36
|
+
firstSeen: LedgerStamp;
|
|
37
|
+
lastSeen: LedgerStamp;
|
|
38
|
+
status: "surviving" | "resolved";
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface Ledger {
|
|
42
|
+
schema: typeof LEDGER_SCHEMA;
|
|
43
|
+
rows: LedgerRow[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function parseLedger(text: string | null): Ledger {
|
|
47
|
+
if (!text) return { schema: LEDGER_SCHEMA, rows: [] };
|
|
48
|
+
try {
|
|
49
|
+
const doc = parseYaml(text) as { rows?: unknown };
|
|
50
|
+
const rows = Array.isArray(doc?.rows)
|
|
51
|
+
? (doc.rows as LedgerRow[]).filter((r) => r && typeof r.key === "string")
|
|
52
|
+
: [];
|
|
53
|
+
return { schema: LEDGER_SCHEMA, rows };
|
|
54
|
+
} catch {
|
|
55
|
+
return { schema: LEDGER_SCHEMA, rows: [] };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Merge the current findings into the ledger: every current legacy/accepted
|
|
61
|
+
* code finding is `surviving` with `lastSeen` = now (its `firstSeen` kept or
|
|
62
|
+
* set to now); rows no longer present become `resolved` (their `lastSeen`
|
|
63
|
+
* keeps the last revision that still had them).
|
|
64
|
+
*/
|
|
65
|
+
export function mergeLedger(
|
|
66
|
+
previous: Ledger,
|
|
67
|
+
findings: AuditFinding[],
|
|
68
|
+
stamp: LedgerStamp,
|
|
69
|
+
): Ledger {
|
|
70
|
+
const current = findings.filter(
|
|
71
|
+
(f) =>
|
|
72
|
+
f.check !== "bindings.verify.substance" &&
|
|
73
|
+
(f.attribution === "legacy" || f.attribution === "accepted"),
|
|
74
|
+
);
|
|
75
|
+
const byKey = new Map(previous.rows.map((r) => [r.key, r]));
|
|
76
|
+
const rows: LedgerRow[] = [];
|
|
77
|
+
const seen = new Set<string>();
|
|
78
|
+
for (const f of current) {
|
|
79
|
+
const prior = byKey.get(f.key);
|
|
80
|
+
rows.push({
|
|
81
|
+
key: f.key,
|
|
82
|
+
check: f.check,
|
|
83
|
+
subject: f.subject,
|
|
84
|
+
firstSeen: prior?.firstSeen ?? stamp,
|
|
85
|
+
lastSeen: stamp,
|
|
86
|
+
status: "surviving",
|
|
87
|
+
});
|
|
88
|
+
seen.add(f.key);
|
|
89
|
+
}
|
|
90
|
+
for (const r of previous.rows) {
|
|
91
|
+
if (seen.has(r.key)) continue;
|
|
92
|
+
rows.push({ ...r, status: "resolved" });
|
|
93
|
+
}
|
|
94
|
+
rows.sort((a, b) => a.check.localeCompare(b.check) || a.subject.localeCompare(b.subject));
|
|
95
|
+
return { schema: LEDGER_SCHEMA, rows };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function serializeLedger(ledger: Ledger): string {
|
|
99
|
+
return (
|
|
100
|
+
"# GENERATED by `forge correctness.audit --write-ledger` (RFC-1579) — survival of accepted correctness debt.\n" +
|
|
101
|
+
stringifyYaml(ledger)
|
|
102
|
+
);
|
|
103
|
+
}
|