@dommaker/harness 1.3.0 → 1.4.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 +8 -0
- package/README.md +0 -2
- package/bin/harness.js +86 -32
- package/dist/cli/command-contract.d.ts +83 -0
- package/dist/cli/command-contract.d.ts.map +1 -0
- package/dist/cli/command-contract.js +66 -0
- package/dist/cli/command-contract.js.map +1 -0
- package/dist/cli/commands/acceptance.d.ts +3 -2
- package/dist/cli/commands/acceptance.d.ts.map +1 -1
- package/dist/cli/commands/acceptance.js +28 -24
- package/dist/cli/commands/acceptance.js.map +1 -1
- package/dist/cli/commands/analyze-sessions.d.ts +2 -1
- package/dist/cli/commands/analyze-sessions.d.ts.map +1 -1
- package/dist/cli/commands/analyze-sessions.js +25 -24
- package/dist/cli/commands/analyze-sessions.js.map +1 -1
- package/dist/cli/commands/check.d.ts +14 -2
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +76 -61
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/command.d.ts +5 -1
- package/dist/cli/commands/command.d.ts.map +1 -1
- package/dist/cli/commands/command.js +26 -17
- package/dist/cli/commands/command.js.map +1 -1
- package/dist/cli/commands/constraints-report.d.ts +2 -1
- package/dist/cli/commands/constraints-report.d.ts.map +1 -1
- package/dist/cli/commands/constraints-report.js +37 -33
- package/dist/cli/commands/constraints-report.js.map +1 -1
- package/dist/cli/commands/constraints-retire.d.ts +6 -5
- package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
- package/dist/cli/commands/constraints-retire.js +50 -52
- package/dist/cli/commands/constraints-retire.js.map +1 -1
- package/dist/cli/commands/constraints.d.ts +2 -1
- package/dist/cli/commands/constraints.d.ts.map +1 -1
- package/dist/cli/commands/constraints.js +10 -27
- package/dist/cli/commands/constraints.js.map +1 -1
- package/dist/cli/commands/contract.d.ts +3 -2
- package/dist/cli/commands/contract.d.ts.map +1 -1
- package/dist/cli/commands/contract.js +45 -42
- package/dist/cli/commands/contract.js.map +1 -1
- package/dist/cli/commands/definitions.d.ts +11 -11
- package/dist/cli/commands/definitions.d.ts.map +1 -1
- package/dist/cli/commands/definitions.js +29 -214
- package/dist/cli/commands/definitions.js.map +1 -1
- package/dist/cli/commands/failure.d.ts +5 -4
- package/dist/cli/commands/failure.d.ts.map +1 -1
- package/dist/cli/commands/failure.js +31 -25
- package/dist/cli/commands/failure.js.map +1 -1
- package/dist/cli/commands/init.d.ts +7 -5
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +147 -211
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/knowledge.d.ts +21 -15
- package/dist/cli/commands/knowledge.d.ts.map +1 -1
- package/dist/cli/commands/knowledge.js +214 -199
- package/dist/cli/commands/knowledge.js.map +1 -1
- package/dist/cli/commands/passes-gate.d.ts +8 -2
- package/dist/cli/commands/passes-gate.d.ts.map +1 -1
- package/dist/cli/commands/passes-gate.js +44 -66
- package/dist/cli/commands/passes-gate.js.map +1 -1
- package/dist/cli/commands/performance.d.ts +2 -1
- package/dist/cli/commands/performance.d.ts.map +1 -1
- package/dist/cli/commands/performance.js +20 -18
- package/dist/cli/commands/performance.js.map +1 -1
- package/dist/cli/commands/posteval-plan.d.ts +5 -1
- package/dist/cli/commands/posteval-plan.d.ts.map +1 -1
- package/dist/cli/commands/posteval-plan.js +26 -15
- package/dist/cli/commands/posteval-plan.js.map +1 -1
- package/dist/cli/commands/release.d.ts +6 -1
- package/dist/cli/commands/release.d.ts.map +1 -1
- package/dist/cli/commands/release.js +69 -59
- package/dist/cli/commands/release.js.map +1 -1
- package/dist/cli/commands/report.d.ts +2 -1
- package/dist/cli/commands/report.d.ts.map +1 -1
- package/dist/cli/commands/report.js +9 -5
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/review.d.ts +3 -2
- package/dist/cli/commands/review.d.ts.map +1 -1
- package/dist/cli/commands/review.js +33 -29
- package/dist/cli/commands/review.js.map +1 -1
- package/dist/cli/commands/sdd.d.ts +2 -1
- package/dist/cli/commands/sdd.d.ts.map +1 -1
- package/dist/cli/commands/sdd.js +7 -5
- package/dist/cli/commands/sdd.js.map +1 -1
- package/dist/cli/commands/security.d.ts +3 -2
- package/dist/cli/commands/security.d.ts.map +1 -1
- package/dist/cli/commands/security.js +29 -26
- package/dist/cli/commands/security.js.map +1 -1
- package/dist/cli/commands/spec-baseline-check.d.ts +2 -1
- package/dist/cli/commands/spec-baseline-check.d.ts.map +1 -1
- package/dist/cli/commands/spec-baseline-check.js +15 -11
- package/dist/cli/commands/spec-baseline-check.js.map +1 -1
- package/dist/cli/commands/spec.d.ts +7 -2
- package/dist/cli/commands/spec.d.ts.map +1 -1
- package/dist/cli/commands/spec.js +61 -51
- package/dist/cli/commands/spec.js.map +1 -1
- package/dist/cli/commands/status.d.ts +2 -1
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +57 -53
- package/dist/cli/commands/status.js.map +1 -1
- package/dist/cli/commands/sync-docs/agents-syncer.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/agents-syncer.js +5 -2
- package/dist/cli/commands/sync-docs/agents-syncer.js.map +1 -1
- package/dist/cli/commands/sync-docs/context-syncer.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/context-syncer.js +3 -2
- package/dist/cli/commands/sync-docs/context-syncer.js.map +1 -1
- package/dist/cli/commands/sync-docs/index.d.ts +2 -1
- package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/index.js +68 -88
- package/dist/cli/commands/sync-docs/index.js.map +1 -1
- package/dist/cli/commands/sync-docs/project-reader.d.ts +6 -1
- package/dist/cli/commands/sync-docs/project-reader.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/project-reader.js +14 -16
- package/dist/cli/commands/sync-docs/project-reader.js.map +1 -1
- package/dist/cli/commands/update-user-model.d.ts +2 -1
- package/dist/cli/commands/update-user-model.d.ts.map +1 -1
- package/dist/cli/commands/update-user-model.js +31 -45
- package/dist/cli/commands/update-user-model.js.map +1 -1
- package/dist/cli/commands/validate.d.ts +4 -3
- package/dist/cli/commands/validate.d.ts.map +1 -1
- package/dist/cli/commands/validate.js +28 -26
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/session-mining/transcript.d.ts +7 -1
- package/dist/cli/session-mining/transcript.d.ts.map +1 -1
- package/dist/cli/session-mining/transcript.js +21 -14
- package/dist/cli/session-mining/transcript.js.map +1 -1
- package/dist/context/session-manager.d.ts.map +1 -1
- package/dist/context/session-manager.js +19 -32
- package/dist/context/session-manager.js.map +1 -1
- package/dist/core/constraints/agent-prompt-renderer.d.ts.map +1 -1
- package/dist/core/constraints/agent-prompt-renderer.js +1 -4
- package/dist/core/constraints/agent-prompt-renderer.js.map +1 -1
- package/dist/core/constraints/capabilities-parser.d.ts +24 -7
- package/dist/core/constraints/capabilities-parser.d.ts.map +1 -1
- package/dist/core/constraints/capabilities-parser.js +32 -28
- package/dist/core/constraints/capabilities-parser.js.map +1 -1
- package/dist/core/constraints/capabilities-reconcile.d.ts +67 -0
- package/dist/core/constraints/capabilities-reconcile.d.ts.map +1 -0
- package/dist/core/constraints/capabilities-reconcile.js +105 -0
- package/dist/core/constraints/capabilities-reconcile.js.map +1 -0
- package/dist/core/constraints/checker.d.ts +21 -43
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +64 -115
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts +4 -3
- package/dist/core/constraints/checkers/capability-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.js +29 -69
- package/dist/core/constraints/checkers/capability-sync.js.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.d.ts +4 -2
- package/dist/core/constraints/checkers/context-doc-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.js +13 -22
- package/dist/core/constraints/checkers/context-doc-sync.js.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.d.ts.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.js +37 -63
- package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.d.ts +2 -2
- package/dist/core/constraints/checkers/governance-presence.d.ts.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.js +7 -28
- package/dist/core/constraints/checkers/governance-presence.js.map +1 -1
- package/dist/core/constraints/checkers/no-test-simplification.d.ts.map +1 -1
- package/dist/core/constraints/checkers/no-test-simplification.js +4 -3
- package/dist/core/constraints/checkers/no-test-simplification.js.map +1 -1
- package/dist/core/constraints/checkers/types.d.ts +2 -2
- package/dist/core/constraints/context-builder.d.ts +15 -14
- package/dist/core/constraints/context-builder.d.ts.map +1 -1
- package/dist/core/constraints/context-builder.js +32 -96
- package/dist/core/constraints/context-builder.js.map +1 -1
- package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
- package/dist/core/constraints/doc-freshness/runner.js +2 -1
- package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
- package/dist/core/constraints/git-evidence.d.ts +60 -0
- package/dist/core/constraints/git-evidence.d.ts.map +1 -0
- package/dist/core/constraints/git-evidence.js +88 -0
- package/dist/core/constraints/git-evidence.js.map +1 -0
- package/dist/core/constraints/injection-drift.d.ts +3 -20
- package/dist/core/constraints/injection-drift.d.ts.map +1 -1
- package/dist/core/constraints/injection-drift.js +10 -57
- package/dist/core/constraints/injection-drift.js.map +1 -1
- package/dist/core/constraints/injection-writer.d.ts +113 -0
- package/dist/core/constraints/injection-writer.d.ts.map +1 -0
- package/dist/core/constraints/injection-writer.js +228 -0
- package/dist/core/constraints/injection-writer.js.map +1 -0
- package/dist/core/constraints/usage-report.d.ts +22 -1
- package/dist/core/constraints/usage-report.d.ts.map +1 -1
- package/dist/core/constraints/usage-report.js +27 -20
- package/dist/core/constraints/usage-report.js.map +1 -1
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +4 -2
- package/dist/core/index.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +32 -1
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +39 -9
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/core/validators/passes-gate.d.ts +15 -64
- package/dist/core/validators/passes-gate.d.ts.map +1 -1
- package/dist/core/validators/passes-gate.js +84 -222
- package/dist/core/validators/passes-gate.js.map +1 -1
- package/dist/core/validators/test-output.d.ts +58 -0
- package/dist/core/validators/test-output.d.ts.map +1 -0
- package/dist/core/validators/test-output.js +109 -0
- package/dist/core/validators/test-output.js.map +1 -0
- package/dist/failure/recorder.d.ts +6 -0
- package/dist/failure/recorder.d.ts.map +1 -1
- package/dist/failure/recorder.js +12 -8
- package/dist/failure/recorder.js.map +1 -1
- package/dist/gates/acceptance.d.ts +1 -48
- package/dist/gates/acceptance.d.ts.map +1 -1
- package/dist/gates/acceptance.js +6 -38
- package/dist/gates/acceptance.js.map +1 -1
- package/dist/gates/checker-gate.d.ts.map +1 -1
- package/dist/gates/checker-gate.js +6 -11
- package/dist/gates/checker-gate.js.map +1 -1
- package/dist/gates/command.d.ts.map +1 -1
- package/dist/gates/command.js +10 -22
- package/dist/gates/command.js.map +1 -1
- package/dist/gates/contract.d.ts.map +1 -1
- package/dist/gates/contract.js +22 -61
- package/dist/gates/contract.js.map +1 -1
- package/dist/gates/performance.d.ts.map +1 -1
- package/dist/gates/performance.js +13 -31
- package/dist/gates/performance.js.map +1 -1
- package/dist/gates/review.d.ts.map +1 -1
- package/dist/gates/review.js +21 -53
- package/dist/gates/review.js.map +1 -1
- package/dist/gates/security.d.ts.map +1 -1
- package/dist/gates/security.js +14 -32
- package/dist/gates/security.js.map +1 -1
- package/dist/gates/types.d.ts +28 -5
- package/dist/gates/types.d.ts.map +1 -1
- package/dist/gates/types.js +38 -1
- package/dist/gates/types.js.map +1 -1
- package/dist/hooks/bootstrap.d.ts +2 -0
- package/dist/hooks/bootstrap.d.ts.map +1 -1
- package/dist/hooks/bootstrap.js +5 -2
- package/dist/hooks/bootstrap.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/knowledge/audit.d.ts +7 -2
- package/dist/knowledge/audit.d.ts.map +1 -1
- package/dist/knowledge/audit.js +59 -79
- package/dist/knowledge/audit.js.map +1 -1
- package/dist/knowledge/flywheel-metrics.d.ts +39 -0
- package/dist/knowledge/flywheel-metrics.d.ts.map +1 -0
- package/dist/knowledge/flywheel-metrics.js +47 -0
- package/dist/knowledge/flywheel-metrics.js.map +1 -0
- package/dist/knowledge/import.d.ts.map +1 -1
- package/dist/knowledge/import.js +4 -14
- package/dist/knowledge/import.js.map +1 -1
- package/dist/knowledge/index-generator.d.ts.map +1 -1
- package/dist/knowledge/index-generator.js +17 -14
- package/dist/knowledge/index-generator.js.map +1 -1
- package/dist/knowledge/ingest.d.ts.map +1 -1
- package/dist/knowledge/ingest.js +9 -4
- package/dist/knowledge/ingest.js.map +1 -1
- package/dist/knowledge/migration.d.ts.map +1 -1
- package/dist/knowledge/migration.js +11 -8
- package/dist/knowledge/migration.js.map +1 -1
- package/dist/knowledge/reference-tracker.d.ts.map +1 -1
- package/dist/knowledge/reference-tracker.js +12 -9
- package/dist/knowledge/reference-tracker.js.map +1 -1
- package/dist/knowledge/store.d.ts +15 -0
- package/dist/knowledge/store.d.ts.map +1 -1
- package/dist/knowledge/store.js +59 -10
- package/dist/knowledge/store.js.map +1 -1
- package/dist/monitoring/context-tracker.d.ts.map +1 -1
- package/dist/monitoring/context-tracker.js +11 -20
- package/dist/monitoring/context-tracker.js.map +1 -1
- package/dist/monitoring/index.d.ts +1 -1
- package/dist/monitoring/index.d.ts.map +1 -1
- package/dist/monitoring/index.js +1 -2
- package/dist/monitoring/index.js.map +1 -1
- package/dist/monitoring/trace-analyzer.d.ts +15 -0
- package/dist/monitoring/trace-analyzer.d.ts.map +1 -1
- package/dist/monitoring/trace-analyzer.js +19 -2
- package/dist/monitoring/trace-analyzer.js.map +1 -1
- package/dist/monitoring/traces.d.ts +21 -2
- package/dist/monitoring/traces.d.ts.map +1 -1
- package/dist/monitoring/traces.js +38 -29
- package/dist/monitoring/traces.js.map +1 -1
- package/dist/release/index.d.ts +2 -2
- package/dist/release/index.d.ts.map +1 -1
- package/dist/release/index.js +1 -5
- package/dist/release/index.js.map +1 -1
- package/dist/sdd/index-generator.js +10 -11
- package/dist/sdd/index-generator.js.map +1 -1
- package/dist/test-setup/project-fixture.d.ts +48 -0
- package/dist/test-setup/project-fixture.d.ts.map +1 -0
- package/dist/test-setup/project-fixture.js +106 -0
- package/dist/test-setup/project-fixture.js.map +1 -0
- package/dist/types/constraint.d.ts +0 -18
- package/dist/types/constraint.d.ts.map +1 -1
- package/dist/types/constraint.js.map +1 -1
- package/dist/types/passes-gate.d.ts +10 -25
- package/dist/types/passes-gate.d.ts.map +1 -1
- package/dist/types/project-config.d.ts +1 -1
- package/dist/types/session.d.ts +6 -5
- package/dist/types/session.d.ts.map +1 -1
- package/dist/utils/exec.d.ts +10 -0
- package/dist/utils/exec.d.ts.map +1 -1
- package/dist/utils/exec.js +12 -0
- package/dist/utils/exec.js.map +1 -1
- package/dist/utils/file-walk.d.ts +9 -1
- package/dist/utils/file-walk.d.ts.map +1 -1
- package/dist/utils/file-walk.js +10 -1
- package/dist/utils/file-walk.js.map +1 -1
- package/dist/utils/frontmatter.d.ts +73 -0
- package/dist/utils/frontmatter.d.ts.map +1 -0
- package/dist/utils/frontmatter.js +141 -0
- package/dist/utils/frontmatter.js.map +1 -0
- package/dist/utils/jsonl.d.ts +92 -0
- package/dist/utils/jsonl.d.ts.map +1 -0
- package/dist/utils/jsonl.js +166 -0
- package/dist/utils/jsonl.js.map +1 -0
- package/dist/utils/package-version.d.ts +16 -0
- package/dist/utils/package-version.d.ts.map +1 -0
- package/dist/utils/package-version.js +63 -0
- package/dist/utils/package-version.js.map +1 -0
- package/package.json +1 -1
- package/src/CONTEXT.md +7 -2
- package/src/__tests__/acceptance-gate.test.ts +3 -1
- package/src/__tests__/checker-extra.test.ts +7 -1218
- package/src/__tests__/context-files-resolution.test.ts +116 -0
- package/src/__tests__/effective-constraints.test.ts +10 -13
- package/src/__tests__/exec.test.ts +35 -1
- package/src/__tests__/layering.test.ts +152 -0
- package/src/__tests__/passes-gate-extra.test.ts +0 -145
- package/src/__tests__/passes-gate.test.ts +142 -106
- package/src/__tests__/skip-semantics.test.ts +5 -9
- package/src/cli/__tests__/command-contract.test.ts +170 -0
- package/src/cli/command-contract.ts +108 -0
- package/src/cli/commands/CONTEXT.md +22 -7
- package/src/cli/commands/__tests__/acceptance.test.ts +40 -33
- package/src/cli/commands/__tests__/analyze-sessions.test.ts +35 -29
- package/src/cli/commands/__tests__/bin-exit-mapping.test.ts +101 -0
- package/src/cli/commands/__tests__/check-drift.test.ts +27 -34
- package/src/cli/commands/__tests__/check-skip-output.test.ts +21 -24
- package/src/cli/commands/__tests__/check.test.ts +378 -382
- package/src/cli/commands/__tests__/command.test.ts +85 -70
- package/src/cli/commands/__tests__/constraints-report.test.ts +100 -71
- package/src/cli/commands/__tests__/constraints-retire.test.ts +152 -95
- package/src/cli/commands/__tests__/contract.test.ts +27 -34
- package/src/cli/commands/__tests__/failure.test.ts +31 -34
- package/src/cli/commands/__tests__/init-injection.test.ts +58 -28
- package/src/cli/commands/__tests__/init.test.ts +77 -48
- package/src/cli/commands/__tests__/knowledge-flywheel-consistency.test.ts +108 -0
- package/src/cli/commands/__tests__/knowledge.test.ts +69 -43
- package/src/cli/commands/__tests__/passes-gate.test.ts +43 -45
- package/src/cli/commands/__tests__/performance.test.ts +22 -23
- package/src/cli/commands/__tests__/posteval-plan.test.ts +39 -38
- package/src/cli/commands/__tests__/project-path-anchoring.test.ts +157 -0
- package/src/cli/commands/__tests__/project-path-convention.test.ts +169 -0
- package/src/cli/commands/__tests__/registry.test.ts +69 -35
- package/src/cli/commands/__tests__/release.test.ts +209 -80
- package/src/cli/commands/__tests__/report-extra.test.ts +16 -16
- package/src/cli/commands/__tests__/report.test.ts +25 -25
- package/src/cli/commands/__tests__/review.test.ts +33 -31
- package/src/cli/commands/__tests__/security.test.ts +23 -27
- package/src/cli/commands/__tests__/spec-baseline-check.test.ts +20 -20
- package/src/cli/commands/__tests__/spec.test.ts +41 -29
- package/src/cli/commands/__tests__/status-extra.test.ts +18 -18
- package/src/cli/commands/__tests__/status-skipped-lines.test.ts +72 -0
- package/src/cli/commands/__tests__/status.test.ts +34 -34
- package/src/cli/commands/__tests__/sync-docs-agents.test.ts +77 -78
- package/src/cli/commands/__tests__/sync-docs.test.ts +72 -74
- package/src/cli/commands/__tests__/update-user-model.test.ts +62 -33
- package/src/cli/commands/__tests__/validate.test.ts +27 -29
- package/src/cli/commands/acceptance.ts +35 -24
- package/src/cli/commands/analyze-sessions.ts +25 -24
- package/src/cli/commands/check.ts +88 -65
- package/src/cli/commands/command.ts +30 -17
- package/src/cli/commands/constraints-report.ts +37 -34
- package/src/cli/commands/constraints-retire.ts +58 -55
- package/src/cli/commands/constraints.ts +10 -27
- package/src/cli/commands/contract.ts +51 -42
- package/src/cli/commands/definitions.ts +36 -222
- package/src/cli/commands/failure.ts +33 -26
- package/src/cli/commands/init.ts +166 -220
- package/src/cli/commands/knowledge.ts +225 -203
- package/src/cli/commands/passes-gate.ts +58 -68
- package/src/cli/commands/performance.ts +23 -18
- package/src/cli/commands/posteval-plan.ts +29 -15
- package/src/cli/commands/release.ts +70 -59
- package/src/cli/commands/report.ts +9 -5
- package/src/cli/commands/review.ts +39 -29
- package/src/cli/commands/sdd.ts +7 -5
- package/src/cli/commands/security.ts +35 -26
- package/src/cli/commands/spec-baseline-check.ts +16 -11
- package/src/cli/commands/spec.ts +66 -53
- package/src/cli/commands/status.ts +59 -53
- package/src/cli/commands/sync-docs/agents-syncer.ts +5 -2
- package/src/cli/commands/sync-docs/context-syncer.ts +3 -2
- package/src/cli/commands/sync-docs/index.ts +73 -100
- package/src/cli/commands/sync-docs/project-reader.ts +17 -18
- package/src/cli/commands/update-user-model.ts +33 -45
- package/src/cli/commands/validate.ts +31 -25
- package/src/cli/session-mining/__tests__/transcript.test.ts +118 -0
- package/src/cli/session-mining/transcript.ts +26 -8
- package/src/context/session-manager.ts +19 -33
- package/src/core/CONTEXT.md +9 -6
- package/src/core/constraints/__tests__/capabilities-reconcile.test.ts +200 -0
- package/src/core/constraints/__tests__/capability-counts.test.ts +94 -0
- package/src/core/constraints/__tests__/git-evidence.test.ts +208 -0
- package/src/core/constraints/__tests__/injection-drift.test.ts +3 -10
- package/src/core/constraints/__tests__/injection-writer.test.ts +231 -0
- package/src/core/constraints/__tests__/trace-injection.test.ts +71 -0
- package/src/core/constraints/__tests__/usage-report.test.ts +112 -0
- package/src/core/constraints/agent-prompt-renderer.ts +2 -6
- package/src/core/constraints/capabilities-parser.ts +53 -35
- package/src/core/constraints/capabilities-reconcile.ts +166 -0
- package/src/core/constraints/checker.ts +75 -130
- package/src/core/constraints/checkers/__tests__/capability-sync.test.ts +214 -0
- package/src/core/constraints/checkers/__tests__/context-doc-sync.test.ts +77 -0
- package/src/core/constraints/checkers/__tests__/docs-freshness.test.ts +117 -0
- package/src/{__tests__ → core/constraints/checkers/__tests__}/governance-presence.test.ts +83 -9
- package/src/core/constraints/checkers/__tests__/iron-flags.test.ts +50 -0
- package/src/core/constraints/checkers/__tests__/no-bypass-checkpoint.test.ts +76 -0
- package/src/{__tests__ → core/constraints/checkers/__tests__}/no-hardcoded-credentials.test.ts +4 -3
- package/src/core/constraints/checkers/__tests__/no-test-simplification.test.ts +58 -0
- package/src/core/constraints/checkers/__tests__/three-state-consistency.test.ts +145 -0
- package/src/core/constraints/checkers/capability-sync.ts +29 -88
- package/src/core/constraints/checkers/context-doc-sync.ts +15 -25
- package/src/core/constraints/checkers/docs-freshness.ts +40 -69
- package/src/core/constraints/checkers/governance-presence.ts +7 -25
- package/src/core/constraints/checkers/no-test-simplification.ts +4 -3
- package/src/core/constraints/checkers/types.ts +2 -2
- package/src/core/constraints/context-builder.ts +39 -91
- package/src/core/constraints/doc-freshness/runner.ts +2 -1
- package/src/core/constraints/git-evidence.ts +120 -0
- package/src/core/constraints/injection-drift.ts +13 -60
- package/src/core/constraints/injection-writer.ts +212 -0
- package/src/core/constraints/usage-report.ts +36 -17
- package/src/core/index.ts +4 -2
- package/src/core/project-config-loader.ts +49 -9
- package/src/core/validators/__tests__/passes-gate.test.ts +2 -56
- package/src/core/validators/__tests__/test-output.test.ts +372 -0
- package/src/core/validators/passes-gate.ts +86 -248
- package/src/core/validators/test-output.ts +128 -0
- package/src/failure/__tests__/recorder.test.ts +168 -0
- package/src/failure/recorder.ts +12 -10
- package/src/gates/CONTEXT.md +6 -3
- package/src/gates/__tests__/acceptance-types-single-source.test.ts +68 -0
- package/src/gates/__tests__/acceptance.test.ts +4 -86
- package/src/gates/__tests__/effective-gates.test.ts +3 -8
- package/src/gates/__tests__/test-verdict-consistency.test.ts +140 -0
- package/src/gates/acceptance.ts +19 -84
- package/src/gates/checker-gate.ts +8 -7
- package/src/gates/command.ts +10 -16
- package/src/gates/contract.ts +22 -61
- package/src/gates/performance.ts +10 -22
- package/src/gates/review.ts +21 -41
- package/src/gates/security.ts +10 -22
- package/src/gates/types.ts +70 -5
- package/src/hooks/CONTEXT.md +1 -1
- package/src/hooks/bootstrap.ts +5 -2
- package/src/index.ts +0 -4
- package/src/knowledge/CONTEXT.md +8 -3
- package/src/knowledge/__tests__/audit-labels.test.ts +44 -0
- package/src/knowledge/__tests__/flywheel-metrics.test.ts +135 -0
- package/src/knowledge/__tests__/import.test.ts +44 -0
- package/src/knowledge/__tests__/index-generator.test.ts +53 -0
- package/src/knowledge/__tests__/ingest.test.ts +85 -0
- package/src/knowledge/__tests__/migration.test.ts +47 -0
- package/src/knowledge/__tests__/reference-tracker.test.ts +16 -0
- package/src/knowledge/__tests__/store.test.ts +194 -0
- package/src/knowledge/audit.ts +67 -71
- package/src/knowledge/flywheel-metrics.ts +71 -0
- package/src/knowledge/import.ts +4 -18
- package/src/knowledge/index-generator.ts +19 -14
- package/src/knowledge/ingest.ts +9 -4
- package/src/knowledge/migration.ts +11 -8
- package/src/knowledge/reference-tracker.ts +12 -8
- package/src/knowledge/store.ts +64 -11
- package/src/monitoring/CONTEXT.md +8 -3
- package/src/monitoring/__tests__/skipped-lines-report.test.ts +178 -0
- package/src/monitoring/__tests__/traces.test.ts +57 -0
- package/src/monitoring/context-tracker.ts +11 -23
- package/src/monitoring/index.ts +1 -1
- package/src/monitoring/trace-analyzer.ts +21 -2
- package/src/monitoring/traces.ts +39 -36
- package/src/release/CONTEXT.md +1 -0
- package/src/release/__tests__/barrel.test.ts +60 -0
- package/src/release/index.ts +2 -13
- package/src/sdd/__tests__/index-generator.test.ts +71 -0
- package/src/sdd/index-generator.ts +9 -9
- package/src/test-setup/__tests__/project-fixture.test.ts +178 -0
- package/src/test-setup/project-fixture.ts +87 -0
- package/src/tools/CONTEXT.md +6 -0
- package/src/tools/__tests__/registry.test.ts +221 -0
- package/src/types/__tests__/types.test.ts +4 -5
- package/src/types/constraint.ts +0 -25
- package/src/types/passes-gate.ts +10 -30
- package/src/types/project-config.ts +1 -1
- package/src/types/session.ts +5 -5
- package/src/utils/__tests__/frontmatter.test.ts +206 -0
- package/src/utils/__tests__/jsonl-skip-disposition.test.ts +175 -0
- package/src/utils/__tests__/jsonl.test.ts +187 -0
- package/src/utils/__tests__/package-version.test.ts +97 -0
- package/src/utils/exec.ts +15 -0
- package/src/utils/file-walk.ts +11 -2
- package/src/utils/frontmatter.ts +121 -0
- package/src/utils/jsonl.ts +167 -0
- package/src/utils/package-version.ts +27 -0
- package/dist/cli/commands/doc-freshness-check.d.ts +0 -53
- package/dist/cli/commands/doc-freshness-check.d.ts.map +0 -1
- package/dist/cli/commands/doc-freshness-check.js +0 -352
- package/dist/cli/commands/doc-freshness-check.js.map +0 -1
- package/dist/types/index.d.ts +0 -14
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -39
- package/dist/types/index.js.map +0 -1
- package/src/__tests__/long-running.test.ts +0 -17
- package/src/__tests__/passes-gate-extension.test.ts +0 -151
- package/src/cli/commands/__tests__/doc-freshness-check.test.ts +0 -168
- package/src/cli/commands/doc-freshness-check.ts +0 -386
- package/src/spec/CONTEXT.md +0 -11
- package/src/types/index.ts +0 -47
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 知识飞轮指标纯判定测试(harness#81)
|
|
3
|
+
*
|
|
4
|
+
* interface 即测试面:喂 active 条目数组 + 可选消费事件数,断言 canonical 指标,零 fs。
|
|
5
|
+
* 口径正本 = genuine refs(过滤 synthetic 后):此前 audit/stats/health 三处各自实现分子计算,
|
|
6
|
+
* stats/health 用原始 referencedBy.length 把自动化触碰算成消费,同一库报出两套飞轮健康度。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { describe, it, expect } from '@jest/globals';
|
|
10
|
+
import { evaluateFlywheel, genuineRefs } from '../flywheel-metrics';
|
|
11
|
+
import type { KnowledgeEntry } from '../types';
|
|
12
|
+
|
|
13
|
+
function makeEntry(id: string, referencedBy: string[]): KnowledgeEntry {
|
|
14
|
+
return {
|
|
15
|
+
id,
|
|
16
|
+
type: 'guideline',
|
|
17
|
+
title: `entry ${id}`,
|
|
18
|
+
content: 'meaningful content long enough to survive every audit threshold',
|
|
19
|
+
maturity: 'verified',
|
|
20
|
+
layer: 'project',
|
|
21
|
+
created: '2026-09-01T00:00:00.000Z',
|
|
22
|
+
lastReferenced: '2026-09-01T00:00:00.000Z',
|
|
23
|
+
contributors: ['human'],
|
|
24
|
+
projects: ['harness'],
|
|
25
|
+
tags: [],
|
|
26
|
+
applicablePhases: [],
|
|
27
|
+
sourceReferences: [],
|
|
28
|
+
referencedBy,
|
|
29
|
+
executionResults: [],
|
|
30
|
+
consumptionMode: 'reference',
|
|
31
|
+
origin: 'agent',
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// ── genuineRefs:synthetic 过滤口径 ─────────────────────
|
|
36
|
+
|
|
37
|
+
describe('genuineRefs — synthetic 过滤口径', () => {
|
|
38
|
+
for (const prefix of [
|
|
39
|
+
'search', 'test-agent', 'prompt-inject', 'monitor',
|
|
40
|
+
'analyst', 'auditor', 'triage', 'executor', 'session', 'trend', 'incident',
|
|
41
|
+
]) {
|
|
42
|
+
it(`过滤自动化写入方 ${prefix}:<date>`, () => {
|
|
43
|
+
expect(genuineRefs([`${prefix}:2026-09-01`])).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
it('保留人/决策类引用(含同前缀但非日期键的历史写法)', () => {
|
|
48
|
+
const refs = [
|
|
49
|
+
'agent-a:2026-09-01',
|
|
50
|
+
'decision-123',
|
|
51
|
+
'unknown:2026-09-01',
|
|
52
|
+
'search:not-a-date',
|
|
53
|
+
'xsearch:2026-09-01',
|
|
54
|
+
];
|
|
55
|
+
expect(genuineRefs(refs)).toEqual([
|
|
56
|
+
'agent-a:2026-09-01',
|
|
57
|
+
'decision-123',
|
|
58
|
+
'unknown:2026-09-01',
|
|
59
|
+
'search:not-a-date',
|
|
60
|
+
'xsearch:2026-09-01',
|
|
61
|
+
]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('无结束锚点:日期后带后缀的自动化键同样过滤', () => {
|
|
65
|
+
expect(genuineRefs(['search:2026-09-01:extra'])).toEqual([]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('不改动入参数组(纯函数,不过滤掉调用方数据)', () => {
|
|
69
|
+
const refs = ['agent-a:2026-09-01', 'search:2026-09-01'];
|
|
70
|
+
genuineRefs(refs);
|
|
71
|
+
expect(refs).toHaveLength(2);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// ── evaluateFlywheel:canonical 指标 ────────────────────
|
|
76
|
+
|
|
77
|
+
describe('evaluateFlywheel — 引用侧指标', () => {
|
|
78
|
+
it('refCoverage / avgRefs 为未取整比例,分子只数 genuine refs', () => {
|
|
79
|
+
const metrics = evaluateFlywheel({
|
|
80
|
+
entries: [
|
|
81
|
+
makeEntry('K-001', ['agent-a:2026-09-01', 'search:2026-09-01']),
|
|
82
|
+
makeEntry('K-002', ['prompt-inject:2026-08-30', 'test-agent:2026-08-31']),
|
|
83
|
+
makeEntry('K-003', []),
|
|
84
|
+
makeEntry('K-004', ['decision-1:2026-07-01', 'studio-web:2026-07-02']),
|
|
85
|
+
],
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// 2/4 条目有真实引用;genuine refs 共 3 条 / 4 条目
|
|
89
|
+
expect(metrics.activeEntries).toBe(4);
|
|
90
|
+
expect(metrics.entriesWithRefs).toBe(2);
|
|
91
|
+
expect(metrics.refCoverage).toBe(0.5);
|
|
92
|
+
expect(metrics.avgRefs).toBe(0.75);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('纯 synthetic 引用不给条目续命(覆盖与均值都归零)', () => {
|
|
96
|
+
const metrics = evaluateFlywheel({
|
|
97
|
+
entries: [makeEntry('K-001', ['search:2026-09-01', 'analyst:2026-09-01'])],
|
|
98
|
+
});
|
|
99
|
+
expect(metrics.entriesWithRefs).toBe(0);
|
|
100
|
+
expect(metrics.refCoverage).toBe(0);
|
|
101
|
+
expect(metrics.avgRefs).toBe(0);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('空人口 → 全 0,不出 NaN / 不做除零', () => {
|
|
105
|
+
const metrics = evaluateFlywheel({ entries: [], dailyConsumptionEvents: 10 });
|
|
106
|
+
expect(metrics).toMatchObject({
|
|
107
|
+
activeEntries: 0,
|
|
108
|
+
entriesWithRefs: 0,
|
|
109
|
+
refCoverage: 0,
|
|
110
|
+
avgRefs: 0,
|
|
111
|
+
consumptionHitRate: 0,
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('不改动传入条目(人口筛选属调用方,本 module 零副作用)', () => {
|
|
116
|
+
const entries = [makeEntry('K-001', ['agent-a:2026-09-01', 'search:2026-09-01'])];
|
|
117
|
+
const before = JSON.stringify(entries);
|
|
118
|
+
evaluateFlywheel({ entries });
|
|
119
|
+
expect(JSON.stringify(entries)).toBe(before);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
describe('evaluateFlywheel — 消费命中率', () => {
|
|
124
|
+
it('未传消费事件 → 0,输入值原样透传便于报告层复用', () => {
|
|
125
|
+
const metrics = evaluateFlywheel({ entries: [makeEntry('K-001', ['agent-a:2026-09-01'])] });
|
|
126
|
+
expect(metrics.dailyConsumptionEvents).toBe(0);
|
|
127
|
+
expect(metrics.consumptionHitRate).toBe(0);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('dailyEvents / activeEntries,capped at 1', () => {
|
|
131
|
+
const entries = [makeEntry('K-001', []), makeEntry('K-002', [])];
|
|
132
|
+
expect(evaluateFlywheel({ entries, dailyConsumptionEvents: 1 }).consumptionHitRate).toBe(0.5);
|
|
133
|
+
expect(evaluateFlywheel({ entries, dailyConsumptionEvents: 99 }).consumptionHitRate).toBe(1);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -308,6 +308,23 @@ describe('ColdStartImporter', () => {
|
|
|
308
308
|
// 非 git 目录应该有错误但不崩溃
|
|
309
309
|
expect(results.length).toBe(1);
|
|
310
310
|
});
|
|
311
|
+
|
|
312
|
+
it('不应执行结果被丢弃的大型重构扫描命令(harness#111 死代码)', async () => {
|
|
313
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
314
|
+
const execSpy = jest.spyOn(require('child_process'), 'execSync').mockReturnValue('');
|
|
315
|
+
try {
|
|
316
|
+
const importer = new ColdStartImporter({
|
|
317
|
+
projectRoot: tmpDir,
|
|
318
|
+
store,
|
|
319
|
+
sources: ['git'],
|
|
320
|
+
});
|
|
321
|
+
await importer.importAll();
|
|
322
|
+
const commands = execSpy.mock.calls.map(call => String(call[0]));
|
|
323
|
+
expect(commands.some(cmd => cmd.includes('diff-filter=M'))).toBe(false);
|
|
324
|
+
} finally {
|
|
325
|
+
execSpy.mockRestore();
|
|
326
|
+
}
|
|
327
|
+
});
|
|
311
328
|
});
|
|
312
329
|
|
|
313
330
|
describe('importFromDocs - 目录', () => {
|
|
@@ -373,4 +390,31 @@ describe('ColdStartImporter', () => {
|
|
|
373
390
|
expect(importer.getState().totalImported).toBe(0);
|
|
374
391
|
});
|
|
375
392
|
});
|
|
393
|
+
|
|
394
|
+
describe('批量写入收口(harness#107)', () => {
|
|
395
|
+
it('多条目导入经 saveAll 一次落索引,不再逐条 save', async () => {
|
|
396
|
+
const importer = new ColdStartImporter({
|
|
397
|
+
projectRoot: tmpDir,
|
|
398
|
+
store,
|
|
399
|
+
sources: ['manual'],
|
|
400
|
+
manualEntries: [
|
|
401
|
+
{ title: 'Entry A', content: 'Content A', type: 'guideline' },
|
|
402
|
+
{ title: 'Entry B', content: 'Content B', type: 'guideline' },
|
|
403
|
+
],
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
const saveAllSpy = jest.spyOn(store, 'saveAll');
|
|
407
|
+
const saveSpy = jest.spyOn(store, 'save');
|
|
408
|
+
try {
|
|
409
|
+
const results = await importer.importAll();
|
|
410
|
+
expect(results[0].entries).toHaveLength(2);
|
|
411
|
+
expect(saveAllSpy).toHaveBeenCalledTimes(1);
|
|
412
|
+
expect(saveSpy).not.toHaveBeenCalled();
|
|
413
|
+
} finally {
|
|
414
|
+
saveAllSpy.mockRestore();
|
|
415
|
+
saveSpy.mockRestore();
|
|
416
|
+
}
|
|
417
|
+
expect(store.list()).toHaveLength(2);
|
|
418
|
+
});
|
|
419
|
+
});
|
|
376
420
|
});
|
|
@@ -332,4 +332,57 @@ Extra text
|
|
|
332
332
|
expect(lines[0]).toContain('real.md');
|
|
333
333
|
});
|
|
334
334
|
});
|
|
335
|
+
|
|
336
|
+
describe('frontmatter 收口(harness#89)', () => {
|
|
337
|
+
let errorSpy: jest.SpyInstance;
|
|
338
|
+
|
|
339
|
+
beforeEach(() => {
|
|
340
|
+
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
afterEach(() => {
|
|
344
|
+
errorSpy.mockRestore();
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('正文里的 --- 分隔线不误吞:headings 取自闭合之后的正文', () => {
|
|
348
|
+
fs.writeFileSync(
|
|
349
|
+
path.join(tmpDir, 'decision-SEP-001.md'),
|
|
350
|
+
'---\nid: SEP-001\ntype: decision\ntitle: "Sep"\nmaturity: verified\ntags: []\n---\n\n## 前段\n\n---\n\n## 附录\n',
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
const fields = new KnowledgeIndexGenerator(tmpDir).generateIndexLines()[0].split('|');
|
|
354
|
+
expect(fields).toHaveLength(7);
|
|
355
|
+
expect(fields[6]).toBe('前段;附录');
|
|
356
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('未闭合:按无 frontmatter best-effort 索引,并显式上报一行(不再静默)', () => {
|
|
360
|
+
fs.writeFileSync(path.join(tmpDir, 'decision-OPEN-001.md'), '---\nid: OPEN-001\n# 断掉的头\n\n## 附录\n');
|
|
361
|
+
|
|
362
|
+
const fields = new KnowledgeIndexGenerator(tmpDir).generateIndexLines()[0].split('|');
|
|
363
|
+
expect(fields[1]).toBe('decision-OPEN-001');
|
|
364
|
+
expect(fields[4]).toBe('unknown');
|
|
365
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
366
|
+
expect(errorSpy.mock.calls[0][0]).toMatch(/\[harness\].*unterminated.*decision-OPEN-001\.md/);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('YAML 非法:best-effort 索引 + 显式上报 invalid-yaml', () => {
|
|
370
|
+
fs.writeFileSync(path.join(tmpDir, 'decision-BAD-001.md'), '---\nid: [1,\n---\n\n正文\n');
|
|
371
|
+
|
|
372
|
+
const fields = new KnowledgeIndexGenerator(tmpDir).generateIndexLines()[0].split('|');
|
|
373
|
+
expect(fields[1]).toBe('decision-BAD-001');
|
|
374
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
375
|
+
expect(errorSpy.mock.calls[0][0]).toMatch(/\[harness\].*invalid-yaml/);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it('空 meta:与缺 frontmatter 同走 absent——静默 best-effort,标题取 H1', () => {
|
|
379
|
+
fs.writeFileSync(path.join(tmpDir, 'decision-EMPTY-001.md'), '---\n\n---\n\n# 空头条目\n\n## 小节\n');
|
|
380
|
+
|
|
381
|
+
const fields = new KnowledgeIndexGenerator(tmpDir).generateIndexLines()[0].split('|');
|
|
382
|
+
expect(fields[1]).toBe('decision-EMPTY-001');
|
|
383
|
+
expect(fields[3]).toBe('空头条目');
|
|
384
|
+
expect(fields[6]).toBe('小节');
|
|
385
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
386
|
+
});
|
|
387
|
+
});
|
|
335
388
|
});
|
|
@@ -127,6 +127,62 @@ describe('KnowledgeIngest', () => {
|
|
|
127
127
|
expect(entries).toHaveLength(2);
|
|
128
128
|
expect(store.list()).toHaveLength(2);
|
|
129
129
|
});
|
|
130
|
+
|
|
131
|
+
it('同类型条目 id 序号批内递增(harness#107)', () => {
|
|
132
|
+
const entries = ingest.ingestBatch(
|
|
133
|
+
[
|
|
134
|
+
{ title: 'First', type: 'decision' },
|
|
135
|
+
{ title: 'Second', type: 'decision' },
|
|
136
|
+
{ title: 'Third', type: 'decision' },
|
|
137
|
+
],
|
|
138
|
+
{ source: 'test', layer: 'project' },
|
|
139
|
+
);
|
|
140
|
+
expect(entries.map(e => e.id)).toEqual(['DEC-001', 'DEC-002', 'DEC-003']);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('generateId 走索引计数(harness#107)', () => {
|
|
145
|
+
it('不再经 store.list() 逐条读条目文件', () => {
|
|
146
|
+
const listSpy = jest.spyOn(store, 'list');
|
|
147
|
+
try {
|
|
148
|
+
ingest.ingestEntry(
|
|
149
|
+
{ title: 'Test', content: 'Content', type: 'decision' },
|
|
150
|
+
{ source: 'test', layer: 'project' },
|
|
151
|
+
);
|
|
152
|
+
expect(listSpy).not.toHaveBeenCalled();
|
|
153
|
+
} finally {
|
|
154
|
+
listSpy.mockRestore();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('archived/deprecated 条目不计入序号(与 list 默认过滤口径一致)', () => {
|
|
159
|
+
store.save({
|
|
160
|
+
id: 'DEC-001',
|
|
161
|
+
type: 'decision',
|
|
162
|
+
title: 'Archived One',
|
|
163
|
+
content: 'Original',
|
|
164
|
+
maturity: 'draft',
|
|
165
|
+
layer: 'project',
|
|
166
|
+
created: '2026-05-01T00:00:00.000Z',
|
|
167
|
+
lastReferenced: '',
|
|
168
|
+
contributors: [],
|
|
169
|
+
projects: [],
|
|
170
|
+
tags: [],
|
|
171
|
+
applicablePhases: [],
|
|
172
|
+
sourceReferences: [],
|
|
173
|
+
referencedBy: [],
|
|
174
|
+
executionResults: [],
|
|
175
|
+
consumptionMode: 'reference',
|
|
176
|
+
origin: 'agent',
|
|
177
|
+
});
|
|
178
|
+
store.update('DEC-001', { maturity: 'archived' });
|
|
179
|
+
|
|
180
|
+
const entry = ingest.ingestEntry(
|
|
181
|
+
{ title: 'Fresh', content: 'Content', type: 'decision' },
|
|
182
|
+
{ source: 'test', layer: 'project' },
|
|
183
|
+
);
|
|
184
|
+
expect(entry.id).toBe('DEC-001');
|
|
185
|
+
});
|
|
130
186
|
});
|
|
131
187
|
|
|
132
188
|
describe('findDuplicate reads from disk (A1)', () => {
|
|
@@ -273,6 +329,35 @@ describe('KnowledgeIngest', () => {
|
|
|
273
329
|
expect(store.list({ types: ['pitfall'] })).toHaveLength(2);
|
|
274
330
|
});
|
|
275
331
|
|
|
332
|
+
it('正文首行以 --- 开头但不是 frontmatter 时不误吞分隔线(harness#89 回归)', () => {
|
|
333
|
+
// 两条正文首行是 `--- 说明…`(不是整行 ---,故 absent),中间各有一条 --- 分隔线。
|
|
334
|
+
// 收口前的手写 strip 把正文里那条 --- 当成闭合,吞掉前面的说明行,
|
|
335
|
+
// 于是两条的 dedup 前缀都变成同一段尾巴 → 误判重复。
|
|
336
|
+
const tail = '端口 3001 与 13101 不一致导致 session:archive 事件无法送达,责任归属是启动配置未校验端口。';
|
|
337
|
+
store.save({
|
|
338
|
+
id: 'PIT-091', type: 'pitfall', title: '甲乙丙丁子网掩码配置漂移一',
|
|
339
|
+
content: `--- 说明:这一段以三个连字符开头,但它不是 frontmatter\n\n---\n\n${tail}\n`,
|
|
340
|
+
maturity: 'draft', layer: 'system',
|
|
341
|
+
created: '2026-05-28T00:00:00.000Z', lastReferenced: '',
|
|
342
|
+
contributors: [], projects: [], tags: [], applicablePhases: [],
|
|
343
|
+
sourceReferences: [], referencedBy: [],
|
|
344
|
+
executionResults: [],
|
|
345
|
+
consumptionMode: 'reference',
|
|
346
|
+
origin: 'agent',
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
ingest.ingestEntry(
|
|
350
|
+
{
|
|
351
|
+
title: '戊己庚辛存储配额阈值设定二',
|
|
352
|
+
content: `--- 另一段同样以三个连字符开头的说明文字,形态与上面完全对称\n\n---\n\n${tail}\n`,
|
|
353
|
+
type: 'pitfall',
|
|
354
|
+
},
|
|
355
|
+
{ source: 'test', layer: 'system' },
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
expect(store.list({ types: ['pitfall'] })).toHaveLength(2);
|
|
359
|
+
});
|
|
360
|
+
|
|
276
361
|
it('should detect duplicate by title keyword overlap >= 60%', () => {
|
|
277
362
|
store.save({
|
|
278
363
|
id: 'PIT-030', type: 'pitfall', title: 'Prisma 连接超时导致 API 请求失败',
|
|
@@ -106,4 +106,51 @@ describe('migrateKnowledgeEntries', () => {
|
|
|
106
106
|
expect(second.migrated).toBe(0);
|
|
107
107
|
expect(second.skipped).toBe(1);
|
|
108
108
|
});
|
|
109
|
+
|
|
110
|
+
describe('frontmatter 收口(harness#89)', () => {
|
|
111
|
+
it('缺 frontmatter:errors 记 no frontmatter(原文案不变),不算损坏', () => {
|
|
112
|
+
fs.writeFileSync(path.join(tempDir, 'PLAIN.md'), '# 只是普通 markdown\n\n正文\n', 'utf-8');
|
|
113
|
+
|
|
114
|
+
const result = migrateKnowledgeEntries(tempDir);
|
|
115
|
+
expect(result.errors).toEqual(['PLAIN.md: no frontmatter found']);
|
|
116
|
+
expect(result.migrated).toBe(0);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('空 meta:与缺 frontmatter 同走一支(absent),不静默丢', () => {
|
|
120
|
+
fs.writeFileSync(path.join(tempDir, 'EMPTY-META.md'), '---\n\n---\n\nBody\n', 'utf-8');
|
|
121
|
+
|
|
122
|
+
const result = migrateKnowledgeEntries(tempDir);
|
|
123
|
+
expect(result.errors).toEqual(['EMPTY-META.md: no frontmatter found']);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('未闭合:errors 显式记 unterminated(收口前是一条 YAML 内部报错)', () => {
|
|
127
|
+
fs.writeFileSync(path.join(tempDir, 'OPEN.md'), '---\nid: OPEN\ntype: decision\n', 'utf-8');
|
|
128
|
+
|
|
129
|
+
const result = migrateKnowledgeEntries(tempDir);
|
|
130
|
+
expect(result.errors).toHaveLength(1);
|
|
131
|
+
expect(result.errors[0]).toMatch(/^OPEN\.md: frontmatter unterminated \(.+\)$/);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('YAML 非法:errors 显式记 invalid-yaml 并带上可定位 detail', () => {
|
|
135
|
+
fs.writeFileSync(path.join(tempDir, 'BAD.md'), '---\nid: [1,\n---\n\nBody\n', 'utf-8');
|
|
136
|
+
|
|
137
|
+
const result = migrateKnowledgeEntries(tempDir);
|
|
138
|
+
expect(result.errors).toHaveLength(1);
|
|
139
|
+
expect(result.errors[0]).toMatch(/^BAD\.md: frontmatter invalid-yaml \(.+\)$/);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('写回走正本包裹格式:首尾分隔线与空行逐字一致,二次运行字节不变(无 diff 噪声)', () => {
|
|
143
|
+
writeEntry('DEC-005.md', { id: 'DEC-005', type: 'decision', title: 'T' });
|
|
144
|
+
|
|
145
|
+
expect(migrateKnowledgeEntries(tempDir).migrated).toBe(1);
|
|
146
|
+
const afterFirst = fs.readFileSync(path.join(tempDir, 'DEC-005.md'), 'utf-8');
|
|
147
|
+
|
|
148
|
+
expect(afterFirst.startsWith('---\nid: DEC-005\n')).toBe(true);
|
|
149
|
+
expect(afterFirst).toContain('---\n\nBody content');
|
|
150
|
+
expect(afterFirst).toMatch(/^---\n[\s\S]*\n---\n\n/);
|
|
151
|
+
|
|
152
|
+
expect(migrateKnowledgeEntries(tempDir).migrated).toBe(0);
|
|
153
|
+
expect(fs.readFileSync(path.join(tempDir, 'DEC-005.md'), 'utf-8')).toBe(afterFirst);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
109
156
|
});
|
|
@@ -125,6 +125,22 @@ describe('ReferenceTracker', () => {
|
|
|
125
125
|
expect(tracker.getReferencesForEntry('any')).toEqual([]);
|
|
126
126
|
});
|
|
127
127
|
|
|
128
|
+
it('单行损坏只丢该行,合法记录保留(harness#82:原「坏一行丢全部」改 skip)', () => {
|
|
129
|
+
const filePath = path.join(tempDir, 'references.jsonl');
|
|
130
|
+
fs.writeFileSync(
|
|
131
|
+
filePath,
|
|
132
|
+
[
|
|
133
|
+
JSON.stringify({ decisionId: 'decision-1', entryIds: ['entry-1'], timestamp: '2026-09-03' }),
|
|
134
|
+
'NOT VALID JSON',
|
|
135
|
+
JSON.stringify({ decisionId: 'decision-2', entryIds: ['entry-2'], timestamp: '2026-09-03' }),
|
|
136
|
+
].join('\n') + '\n',
|
|
137
|
+
'utf-8'
|
|
138
|
+
);
|
|
139
|
+
expect(tracker.getReferencesForEntry('entry-1')).toEqual(['decision-1']);
|
|
140
|
+
expect(tracker.getReferencesForEntry('entry-2')).toEqual(['decision-2']);
|
|
141
|
+
expect(tracker.getReferencesForDecision('decision-2')).toEqual(['entry-2']);
|
|
142
|
+
});
|
|
143
|
+
|
|
128
144
|
it('should return empty when file does not exist', () => {
|
|
129
145
|
expect(tracker.getReferencesForDecision('any')).toEqual([]);
|
|
130
146
|
});
|
|
@@ -455,4 +455,198 @@ describe('KnowledgeStore', () => {
|
|
|
455
455
|
expect(result!.total).toBe(2);
|
|
456
456
|
});
|
|
457
457
|
});
|
|
458
|
+
|
|
459
|
+
describe('readIndex memoize(harness#106)', () => {
|
|
460
|
+
// fs.readFileSync 不可 spy(Node 21+ 不可 redefine);list/readIndex 路径上
|
|
461
|
+
// JSON.parse 仅用于解析 index.json,用其调用次数度量 index 重读次数
|
|
462
|
+
it('list() 单次调用内 index.json 只解析一次(消除 N+1 重读)', () => {
|
|
463
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
464
|
+
store.save(makeEntry({ id: 'DEC-002', title: 'Second' }));
|
|
465
|
+
|
|
466
|
+
const parseSpy = jest.spyOn(JSON, 'parse');
|
|
467
|
+
try {
|
|
468
|
+
store.list();
|
|
469
|
+
expect(parseSpy).toHaveBeenCalledTimes(1);
|
|
470
|
+
} finally {
|
|
471
|
+
parseSpy.mockRestore();
|
|
472
|
+
}
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('readIndex() 重复调用命中缓存,不重复解析', () => {
|
|
476
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
477
|
+
|
|
478
|
+
const parseSpy = jest.spyOn(JSON, 'parse');
|
|
479
|
+
try {
|
|
480
|
+
store.readIndex();
|
|
481
|
+
store.readIndex();
|
|
482
|
+
expect(parseSpy).toHaveBeenCalledTimes(1);
|
|
483
|
+
} finally {
|
|
484
|
+
parseSpy.mockRestore();
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it('index.json 变更后缓存自动失效(mtime+size 指纹)', () => {
|
|
489
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
490
|
+
const first = store.readIndex();
|
|
491
|
+
expect(first).toHaveLength(1);
|
|
492
|
+
|
|
493
|
+
// 模拟外部进程直接改写 index.json
|
|
494
|
+
const indexPath = path.join(tempDir, 'index.json');
|
|
495
|
+
const external = [...first, { ...first[0], id: 'DEC-EXT' }];
|
|
496
|
+
fs.writeFileSync(indexPath, JSON.stringify(external, null, 2), 'utf-8');
|
|
497
|
+
|
|
498
|
+
const second = store.readIndex();
|
|
499
|
+
expect(second.map(e => e.id)).toContain('DEC-EXT');
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
it('index.json 被删除后缓存失效,readIndex 返回空', () => {
|
|
503
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
504
|
+
expect(store.readIndex()).toHaveLength(1);
|
|
505
|
+
|
|
506
|
+
fs.unlinkSync(path.join(tempDir, 'index.json'));
|
|
507
|
+
expect(store.readIndex()).toHaveLength(0);
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
describe('saveAll 批量写入(harness#107)', () => {
|
|
512
|
+
// writeIndex 是 store 内 JSON.stringify 的唯一调用方,用其调用次数度量 index.json 重写次数
|
|
513
|
+
it('K 条批量保存只重写一次 index.json', () => {
|
|
514
|
+
const stringifySpy = jest.spyOn(JSON, 'stringify');
|
|
515
|
+
try {
|
|
516
|
+
store.saveAll([
|
|
517
|
+
makeEntry({ id: 'DEC-001' }),
|
|
518
|
+
makeEntry({ id: 'DEC-002', title: 'Second' }),
|
|
519
|
+
makeEntry({ id: 'DEC-003', title: 'Third' }),
|
|
520
|
+
]);
|
|
521
|
+
expect(stringifySpy).toHaveBeenCalledTimes(1);
|
|
522
|
+
} finally {
|
|
523
|
+
stringifySpy.mockRestore();
|
|
524
|
+
}
|
|
525
|
+
expect(store.readIndex()).toHaveLength(3);
|
|
526
|
+
expect(store.get('DEC-002')!.title).toBe('Second');
|
|
527
|
+
});
|
|
528
|
+
|
|
529
|
+
it('批量保存只读一次 index.json', () => {
|
|
530
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
531
|
+
|
|
532
|
+
const parseSpy = jest.spyOn(JSON, 'parse');
|
|
533
|
+
try {
|
|
534
|
+
store.saveAll([
|
|
535
|
+
makeEntry({ id: 'DEC-002', title: 'Second' }),
|
|
536
|
+
makeEntry({ id: 'DEC-003', title: 'Third' }),
|
|
537
|
+
]);
|
|
538
|
+
expect(parseSpy).toHaveBeenCalledTimes(1);
|
|
539
|
+
} finally {
|
|
540
|
+
parseSpy.mockRestore();
|
|
541
|
+
}
|
|
542
|
+
expect(store.readIndex()).toHaveLength(3);
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
it('覆盖已存在同 id 条目,索引不产生重复', () => {
|
|
546
|
+
store.save(makeEntry({ id: 'DEC-001', title: 'Old' }));
|
|
547
|
+
|
|
548
|
+
store.saveAll([
|
|
549
|
+
makeEntry({ id: 'DEC-001', title: 'New' }),
|
|
550
|
+
makeEntry({ id: 'DEC-002' }),
|
|
551
|
+
]);
|
|
552
|
+
|
|
553
|
+
expect(store.readIndex()).toHaveLength(2);
|
|
554
|
+
expect(store.get('DEC-001')!.title).toBe('New');
|
|
555
|
+
});
|
|
556
|
+
|
|
557
|
+
it('批内同 id 后者覆盖前者', () => {
|
|
558
|
+
store.saveAll([
|
|
559
|
+
makeEntry({ id: 'DEC-001', title: 'First' }),
|
|
560
|
+
makeEntry({ id: 'DEC-001', title: 'Last' }),
|
|
561
|
+
]);
|
|
562
|
+
|
|
563
|
+
expect(store.readIndex()).toHaveLength(1);
|
|
564
|
+
expect(store.get('DEC-001')!.title).toBe('Last');
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
it('空批零读写,不创建 index.json', () => {
|
|
568
|
+
const stringifySpy = jest.spyOn(JSON, 'stringify');
|
|
569
|
+
try {
|
|
570
|
+
store.saveAll([]);
|
|
571
|
+
expect(stringifySpy).not.toHaveBeenCalled();
|
|
572
|
+
} finally {
|
|
573
|
+
stringifySpy.mockRestore();
|
|
574
|
+
}
|
|
575
|
+
expect(fs.existsSync(path.join(tempDir, 'index.json'))).toBe(false);
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
it('saveAll 后 list() 立即可见(缓存指纹失效)', () => {
|
|
579
|
+
store.save(makeEntry({ id: 'DEC-001' }));
|
|
580
|
+
expect(store.list()).toHaveLength(1); // 预热缓存
|
|
581
|
+
|
|
582
|
+
store.saveAll([makeEntry({ id: 'DEC-002' }), makeEntry({ id: 'DEC-003' })]);
|
|
583
|
+
|
|
584
|
+
expect(store.list().map(e => e.id)).toEqual(['DEC-001', 'DEC-002', 'DEC-003']);
|
|
585
|
+
});
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
describe('frontmatter 收口(harness#89)', () => {
|
|
589
|
+
const entryPath = (id: string): string => path.join(tempDir, `decision-${id}.md`);
|
|
590
|
+
let errorSpy: jest.SpyInstance;
|
|
591
|
+
|
|
592
|
+
beforeEach(() => {
|
|
593
|
+
errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
afterEach(() => {
|
|
597
|
+
errorSpy.mockRestore();
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
it('load→save 往返字节稳定:已落盘条目不产生无意义 diff', () => {
|
|
601
|
+
store.save(makeEntry({ id: 'FM-001' }));
|
|
602
|
+
const before = fs.readFileSync(entryPath('FM-001'), 'utf-8');
|
|
603
|
+
|
|
604
|
+
const loaded = store.get('FM-001')!;
|
|
605
|
+
store.save(loaded);
|
|
606
|
+
|
|
607
|
+
expect(fs.readFileSync(entryPath('FM-001'), 'utf-8')).toBe(before);
|
|
608
|
+
});
|
|
609
|
+
|
|
610
|
+
it('正文含 --- 分隔线的条目往返字节稳定,正文完整保留', () => {
|
|
611
|
+
const body = '第一段\n\n---\n\n## 附录\n末行\n';
|
|
612
|
+
store.save(makeEntry({ id: 'FM-002', content: body }));
|
|
613
|
+
const before = fs.readFileSync(entryPath('FM-002'), 'utf-8');
|
|
614
|
+
|
|
615
|
+
const loaded = store.get('FM-002')!;
|
|
616
|
+
expect(loaded.content).toBe(body);
|
|
617
|
+
store.save(loaded);
|
|
618
|
+
|
|
619
|
+
expect(fs.readFileSync(entryPath('FM-002'), 'utf-8')).toBe(before);
|
|
620
|
+
});
|
|
621
|
+
|
|
622
|
+
it('未闭合 frontmatter:跳过条目并显式上报(不再静默丢,口径与 migration 同派)', () => {
|
|
623
|
+
fs.writeFileSync(entryPath('FM-003'), '---\nid: FM-003\ntype: decision\n', 'utf-8');
|
|
624
|
+
|
|
625
|
+
expect(store.get('FM-003')).toBeUndefined();
|
|
626
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
627
|
+
expect(errorSpy.mock.calls[0][0]).toMatch(/\[harness\].*unterminated/);
|
|
628
|
+
});
|
|
629
|
+
|
|
630
|
+
it('YAML 非法 frontmatter:跳过条目并显式上报', () => {
|
|
631
|
+
fs.writeFileSync(entryPath('FM-004'), '---\nid: [1,\n---\n\nBody\n', 'utf-8');
|
|
632
|
+
|
|
633
|
+
expect(store.get('FM-004')).toBeUndefined();
|
|
634
|
+
expect(errorSpy).toHaveBeenCalledTimes(1);
|
|
635
|
+
expect(errorSpy.mock.calls[0][0]).toMatch(/\[harness\].*invalid-yaml/);
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
it('空 meta:按无 frontmatter 处理(absent)——跳过且不上报', () => {
|
|
639
|
+
fs.writeFileSync(entryPath('FM-005'), '---\n\n---\n\nBody\n', 'utf-8');
|
|
640
|
+
|
|
641
|
+
expect(store.get('FM-005')).toBeUndefined();
|
|
642
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
643
|
+
});
|
|
644
|
+
|
|
645
|
+
it('缺 frontmatter:合法的非条目文件——跳过且不上报', () => {
|
|
646
|
+
fs.writeFileSync(entryPath('FM-006'), '# 只是普通 markdown\n\n正文\n', 'utf-8');
|
|
647
|
+
|
|
648
|
+
expect(store.get('FM-006')).toBeUndefined();
|
|
649
|
+
expect(errorSpy).not.toHaveBeenCalled();
|
|
650
|
+
});
|
|
651
|
+
});
|
|
458
652
|
});
|