@dommaker/harness 1.7.0 → 1.8.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 +37 -0
- package/bin/harness.js +17 -1
- package/dist/agents/index.d.ts +6 -2
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +6 -16
- package/dist/agents/index.js.map +1 -1
- package/dist/cli/commands/__tests__/gate-decision.d.ts +18 -0
- package/dist/cli/commands/__tests__/gate-decision.d.ts.map +1 -0
- package/dist/cli/commands/__tests__/gate-decision.js +26 -0
- package/dist/cli/commands/__tests__/gate-decision.js.map +1 -0
- package/dist/cli/commands/acceptance.d.ts.map +1 -1
- package/dist/cli/commands/acceptance.js +17 -28
- package/dist/cli/commands/acceptance.js.map +1 -1
- package/dist/cli/commands/check.d.ts +11 -3
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +26 -11
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/command.d.ts +0 -1
- package/dist/cli/commands/command.d.ts.map +1 -1
- package/dist/cli/commands/command.js +8 -6
- package/dist/cli/commands/command.js.map +1 -1
- package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
- package/dist/cli/commands/constraints-retire.js +36 -57
- package/dist/cli/commands/constraints-retire.js.map +1 -1
- package/dist/cli/commands/contract.d.ts.map +1 -1
- package/dist/cli/commands/contract.js +36 -42
- package/dist/cli/commands/contract.js.map +1 -1
- package/dist/cli/commands/definitions.d.ts +2 -0
- package/dist/cli/commands/definitions.d.ts.map +1 -1
- package/dist/cli/commands/definitions.js +11 -6
- package/dist/cli/commands/definitions.js.map +1 -1
- package/dist/cli/commands/failure.d.ts.map +1 -1
- package/dist/cli/commands/failure.js +16 -2
- package/dist/cli/commands/failure.js.map +1 -1
- package/dist/cli/commands/init.d.ts +14 -8
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +172 -364
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/knowledge-view.d.ts +90 -0
- package/dist/cli/commands/knowledge-view.d.ts.map +1 -0
- package/dist/cli/commands/knowledge-view.js +198 -0
- package/dist/cli/commands/knowledge-view.js.map +1 -0
- package/dist/cli/commands/knowledge.d.ts +137 -52
- package/dist/cli/commands/knowledge.d.ts.map +1 -1
- package/dist/cli/commands/knowledge.js +534 -400
- package/dist/cli/commands/knowledge.js.map +1 -1
- package/dist/cli/commands/passes-gate.d.ts +4 -1
- package/dist/cli/commands/passes-gate.d.ts.map +1 -1
- package/dist/cli/commands/passes-gate.js +11 -2
- package/dist/cli/commands/passes-gate.js.map +1 -1
- package/dist/cli/commands/performance.d.ts.map +1 -1
- package/dist/cli/commands/performance.js +19 -31
- package/dist/cli/commands/performance.js.map +1 -1
- package/dist/cli/commands/report.d.ts.map +1 -1
- package/dist/cli/commands/report.js +2 -1
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/review.d.ts.map +1 -1
- package/dist/cli/commands/review.js +13 -25
- package/dist/cli/commands/review.js.map +1 -1
- package/dist/cli/commands/scaffold-templates.d.ts +73 -0
- package/dist/cli/commands/scaffold-templates.d.ts.map +1 -0
- package/dist/cli/commands/scaffold-templates.js +424 -0
- package/dist/cli/commands/scaffold-templates.js.map +1 -0
- package/dist/cli/commands/scaffold.d.ts +105 -0
- package/dist/cli/commands/scaffold.d.ts.map +1 -0
- package/dist/cli/commands/scaffold.js +263 -0
- package/dist/cli/commands/scaffold.js.map +1 -0
- package/dist/cli/commands/security.d.ts.map +1 -1
- package/dist/cli/commands/security.js +22 -24
- package/dist/cli/commands/security.js.map +1 -1
- package/dist/cli/commands/spec-baseline-check.d.ts +43 -0
- package/dist/cli/commands/spec-baseline-check.d.ts.map +1 -1
- package/dist/cli/commands/spec-baseline-check.js +109 -34
- package/dist/cli/commands/spec-baseline-check.js.map +1 -1
- package/dist/cli/commands/sync-docs/context-syncer.d.ts +21 -2
- package/dist/cli/commands/sync-docs/context-syncer.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/context-syncer.js +112 -28
- package/dist/cli/commands/sync-docs/context-syncer.js.map +1 -1
- package/dist/cli/commands/sync-docs/index.d.ts +1 -1
- package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/index.js +86 -27
- package/dist/cli/commands/sync-docs/index.js.map +1 -1
- package/dist/cli/commands/sync-docs/project-reader.d.ts +24 -1
- package/dist/cli/commands/sync-docs/project-reader.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/project-reader.js +33 -7
- package/dist/cli/commands/sync-docs/project-reader.js.map +1 -1
- package/dist/cli/commands/validate.d.ts +0 -16
- package/dist/cli/commands/validate.d.ts.map +1 -1
- package/dist/cli/commands/validate.js +2 -97
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/gate-command.d.ts +37 -0
- package/dist/cli/gate-command.d.ts.map +1 -0
- package/dist/cli/gate-command.js +64 -0
- package/dist/cli/gate-command.js.map +1 -0
- package/dist/completion-checkers/index.d.ts +1 -1
- package/dist/completion-checkers/index.d.ts.map +1 -1
- package/dist/completion-checkers/index.js +0 -15
- package/dist/completion-checkers/index.js.map +1 -1
- package/dist/context/knowledge-injector.d.ts +4 -2
- package/dist/context/knowledge-injector.d.ts.map +1 -1
- package/dist/context/knowledge-injector.js +13 -6
- package/dist/context/knowledge-injector.js.map +1 -1
- package/dist/core/constraints/agent-prompt-renderer.js +2 -2
- package/dist/core/constraints/agent-prompt-renderer.js.map +1 -1
- package/dist/core/constraints/capabilities-reconcile.d.ts +20 -0
- package/dist/core/constraints/capabilities-reconcile.d.ts.map +1 -1
- package/dist/core/constraints/capabilities-reconcile.js +26 -4
- package/dist/core/constraints/capabilities-reconcile.js.map +1 -1
- package/dist/core/constraints/check-cache.d.ts +1 -1
- package/dist/core/constraints/check-cache.js +1 -1
- package/dist/core/constraints/checker.d.ts +8 -3
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +30 -19
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts +3 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.js +17 -24
- package/dist/core/constraints/checkers/capability-sync.js.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.d.ts +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.js +9 -6
- 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 +24 -30
- package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.d.ts.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.js +10 -4
- package/dist/core/constraints/checkers/governance-presence.js.map +1 -1
- package/dist/core/constraints/checkers/types.d.ts +10 -6
- package/dist/core/constraints/checkers/types.d.ts.map +1 -1
- package/dist/core/constraints/checkers/types.js +7 -3
- package/dist/core/constraints/checkers/types.js.map +1 -1
- package/dist/core/constraints/context-builder.d.ts +11 -10
- package/dist/core/constraints/context-builder.d.ts.map +1 -1
- package/dist/core/constraints/context-builder.js +31 -27
- package/dist/core/constraints/context-builder.js.map +1 -1
- package/dist/core/constraints/context-reconcile.d.ts +75 -0
- package/dist/core/constraints/context-reconcile.d.ts.map +1 -0
- package/dist/core/constraints/context-reconcile.js +161 -0
- package/dist/core/constraints/context-reconcile.js.map +1 -0
- package/dist/core/constraints/doc-freshness/runner.d.ts +7 -0
- package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
- package/dist/core/constraints/doc-freshness/runner.js +8 -3
- package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
- package/dist/core/constraints/git-evidence.js +1 -1
- package/dist/core/constraints/git-evidence.js.map +1 -1
- package/dist/core/constraints/injection-drift.d.ts +7 -2
- package/dist/core/constraints/injection-drift.d.ts.map +1 -1
- package/dist/core/constraints/injection-drift.js +13 -7
- package/dist/core/constraints/injection-drift.js.map +1 -1
- package/dist/core/constraints/run-env.d.ts +92 -0
- package/dist/core/constraints/run-env.d.ts.map +1 -0
- package/dist/core/constraints/run-env.js +175 -0
- package/dist/core/constraints/run-env.js.map +1 -0
- package/dist/core/constraints/triggers.d.ts +22 -0
- package/dist/core/constraints/triggers.d.ts.map +1 -0
- package/dist/core/constraints/triggers.js +31 -0
- package/dist/core/constraints/triggers.js.map +1 -0
- package/dist/core/effective-constraints.d.ts +13 -4
- package/dist/core/effective-constraints.d.ts.map +1 -1
- package/dist/core/effective-constraints.js +16 -6
- package/dist/core/effective-constraints.js.map +1 -1
- package/dist/core/effective-set.d.ts +8 -15
- package/dist/core/effective-set.d.ts.map +1 -1
- package/dist/core/effective-set.js +7 -12
- package/dist/core/effective-set.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +39 -17
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +51 -122
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/core/validators/check-handlers/http.d.ts +2 -2
- package/dist/core/validators/check-handlers/http.d.ts.map +1 -1
- package/dist/core/validators/check-handlers/http.js +12 -7
- package/dist/core/validators/check-handlers/http.js.map +1 -1
- package/dist/failure/classifier.d.ts +1 -1
- package/dist/failure/classifier.d.ts.map +1 -1
- package/dist/failure/classifier.js +8 -8
- package/dist/failure/classifier.js.map +1 -1
- package/dist/failure/index.d.ts +2 -1
- package/dist/failure/index.d.ts.map +1 -1
- package/dist/failure/index.js +9 -17
- package/dist/failure/index.js.map +1 -1
- package/dist/failure/recorder.d.ts +1 -1
- package/dist/failure/recorder.d.ts.map +1 -1
- package/dist/gates/checker-gate.d.ts +2 -1
- package/dist/gates/checker-gate.d.ts.map +1 -1
- package/dist/gates/checker-gate.js +3 -2
- package/dist/gates/checker-gate.js.map +1 -1
- package/dist/gates/command.d.ts +10 -4
- package/dist/gates/command.d.ts.map +1 -1
- package/dist/gates/command.js +36 -62
- package/dist/gates/command.js.map +1 -1
- package/dist/gates/contract.d.ts.map +1 -1
- package/dist/gates/contract.js +0 -4
- package/dist/gates/contract.js.map +1 -1
- package/dist/gates/definitions.d.ts +2 -1
- package/dist/gates/definitions.d.ts.map +1 -1
- package/dist/gates/definitions.js +6 -5
- package/dist/gates/definitions.js.map +1 -1
- package/dist/gates/index.d.ts +0 -4
- package/dist/gates/index.d.ts.map +1 -1
- package/dist/gates/index.js +1 -6
- package/dist/gates/index.js.map +1 -1
- package/dist/gates/performance.d.ts.map +1 -1
- package/dist/gates/performance.js +0 -4
- package/dist/gates/performance.js.map +1 -1
- package/dist/gates/runner.d.ts +1 -1
- package/dist/gates/runner.js +1 -1
- package/dist/gates/security.d.ts +1 -1
- package/dist/gates/security.d.ts.map +1 -1
- package/dist/gates/security.js +5 -6
- package/dist/gates/security.js.map +1 -1
- package/dist/gates/types.d.ts +14 -17
- package/dist/gates/types.d.ts.map +1 -1
- package/dist/gates/types.js.map +1 -1
- package/dist/hooks/bootstrap.d.ts +6 -4
- package/dist/hooks/bootstrap.d.ts.map +1 -1
- package/dist/hooks/bootstrap.js +25 -13
- package/dist/hooks/bootstrap.js.map +1 -1
- package/dist/hooks/config.d.ts +6 -2
- package/dist/hooks/config.d.ts.map +1 -1
- package/dist/hooks/config.js +5 -1
- package/dist/hooks/config.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +0 -15
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/pipeline.d.ts.map +1 -1
- package/dist/hooks/pipeline.js +2 -4
- package/dist/hooks/pipeline.js.map +1 -1
- package/dist/hooks/registry.d.ts +11 -8
- package/dist/hooks/registry.d.ts.map +1 -1
- package/dist/hooks/registry.js +22 -7
- package/dist/hooks/registry.js.map +1 -1
- package/dist/hooks/types.d.ts +23 -7
- package/dist/hooks/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/knowledge/audit-scoring.d.ts +87 -0
- package/dist/knowledge/audit-scoring.d.ts.map +1 -0
- package/dist/knowledge/audit-scoring.js +470 -0
- package/dist/knowledge/audit-scoring.js.map +1 -0
- package/dist/knowledge/audit.d.ts +11 -59
- package/dist/knowledge/audit.d.ts.map +1 -1
- package/dist/knowledge/audit.js +47 -522
- package/dist/knowledge/audit.js.map +1 -1
- package/dist/knowledge/import.d.ts.map +1 -1
- package/dist/knowledge/import.js +2 -0
- package/dist/knowledge/import.js.map +1 -1
- package/dist/knowledge/index-generator.d.ts.map +1 -1
- package/dist/knowledge/index-generator.js +4 -5
- package/dist/knowledge/index-generator.js.map +1 -1
- package/dist/knowledge/index.d.ts +3 -2
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +3 -16
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/ingest.js +1 -1
- package/dist/knowledge/ingest.js.map +1 -1
- package/dist/knowledge/lifecycle.d.ts.map +1 -1
- package/dist/knowledge/lifecycle.js +4 -2
- package/dist/knowledge/lifecycle.js.map +1 -1
- package/dist/knowledge/migration.d.ts +3 -0
- package/dist/knowledge/migration.d.ts.map +1 -1
- package/dist/knowledge/migration.js +8 -2
- package/dist/knowledge/migration.js.map +1 -1
- package/dist/knowledge/query.d.ts +6 -0
- package/dist/knowledge/query.d.ts.map +1 -1
- package/dist/knowledge/query.js +8 -2
- package/dist/knowledge/query.js.map +1 -1
- package/dist/knowledge/reference-tracker.d.ts.map +1 -1
- package/dist/knowledge/reference-tracker.js +4 -6
- package/dist/knowledge/reference-tracker.js.map +1 -1
- package/dist/knowledge/store.d.ts +22 -16
- package/dist/knowledge/store.d.ts.map +1 -1
- package/dist/knowledge/store.js +53 -12
- package/dist/knowledge/store.js.map +1 -1
- package/dist/knowledge/tree-walker.d.ts +19 -0
- package/dist/knowledge/tree-walker.d.ts.map +1 -0
- package/dist/knowledge/tree-walker.js +30 -0
- package/dist/knowledge/tree-walker.js.map +1 -0
- package/dist/knowledge/types.d.ts +16 -0
- package/dist/knowledge/types.d.ts.map +1 -1
- package/dist/monitoring/traces.d.ts +5 -3
- package/dist/monitoring/traces.d.ts.map +1 -1
- package/dist/monitoring/traces.js +19 -5
- package/dist/monitoring/traces.js.map +1 -1
- package/dist/test-setup/jsonl-fake-fs.d.ts +30 -0
- package/dist/test-setup/jsonl-fake-fs.d.ts.map +1 -0
- package/dist/test-setup/jsonl-fake-fs.js +49 -0
- package/dist/test-setup/jsonl-fake-fs.js.map +1 -0
- package/dist/tools/index.d.ts +4 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +7 -15
- package/dist/tools/index.js.map +1 -1
- package/dist/types/checkpoint.d.ts +5 -0
- package/dist/types/checkpoint.d.ts.map +1 -1
- package/dist/types/project-config.d.ts +18 -0
- package/dist/types/project-config.d.ts.map +1 -1
- package/dist/types/trace.d.ts +13 -4
- package/dist/types/trace.d.ts.map +1 -1
- package/dist/types/trace.js +4 -3
- package/dist/types/trace.js.map +1 -1
- package/dist/utils/exec.d.ts +4 -27
- package/dist/utils/exec.d.ts.map +1 -1
- package/dist/utils/exec.js +4 -94
- package/dist/utils/exec.js.map +1 -1
- package/dist/utils/jsonl.d.ts +17 -7
- package/dist/utils/jsonl.d.ts.map +1 -1
- package/dist/utils/jsonl.js +144 -17
- package/dist/utils/jsonl.js.map +1 -1
- package/dist/utils/numeric-flag.d.ts +44 -0
- package/dist/utils/numeric-flag.d.ts.map +1 -0
- package/dist/utils/numeric-flag.js +62 -0
- package/dist/utils/numeric-flag.js.map +1 -0
- package/package.json +1 -1
- package/src/CONTEXT.md +5 -2
- package/src/__tests__/acceptance-gate.test.ts +7 -4
- package/src/__tests__/checker-extra.test.ts +3 -2
- package/src/__tests__/checker.test.ts +4 -3
- package/src/__tests__/checkpoint.test.ts +26 -9
- package/src/__tests__/context-files-resolution.test.ts +29 -15
- package/src/__tests__/contract-gate.test.ts +19 -40
- package/src/__tests__/error-classifier.test.ts +1 -1
- package/src/__tests__/exec.test.ts +45 -107
- package/src/__tests__/failure-recorder.test.ts +7 -5
- package/src/__tests__/hooks-pipeline.test.ts +34 -47
- package/src/__tests__/layering.test.ts +217 -25
- package/src/__tests__/passes-gate.test.ts +9 -4
- package/src/__tests__/performance-gate.test.ts +3 -15
- package/src/__tests__/project-config-loader-extra.test.ts +31 -57
- package/src/__tests__/project-config-loader.test.ts +6 -3
- package/src/__tests__/public-exports.test.ts +0 -1
- package/src/__tests__/public-type-surface.test.ts +5 -4
- package/src/__tests__/public-value-surface.test.ts +182 -0
- package/src/__tests__/review-gate.test.ts +4 -6
- package/src/__tests__/security-gate.test.ts +5 -20
- package/src/__tests__/skip-semantics.test.ts +5 -3
- package/src/__tests__/spec-validator.test.ts +3 -2
- package/src/__tests__/sub-barrels-explicit.test.ts +87 -0
- package/src/__tests__/test-fixture-hygiene.test.ts +53 -0
- package/src/__tests__/trace-analyzer-extra.test.ts +5 -3
- package/src/__tests__/trace-analyzer.test.ts +5 -3
- package/src/__tests__/trace-collector.test.ts +5 -3
- package/src/agents/index.ts +13 -2
- package/src/cli/__tests__/gate-command.test.ts +162 -0
- package/src/cli/commands/CONTEXT.md +29 -5
- package/src/cli/commands/__tests__/acceptance.test.ts +24 -25
- package/src/cli/commands/__tests__/bin-exit-mapping.test.ts +15 -0
- package/src/cli/commands/__tests__/check-drift.test.ts +42 -1
- package/src/cli/commands/__tests__/check-read-count.test.ts +167 -0
- package/src/cli/commands/__tests__/check-skip-output.test.ts +4 -1
- package/src/cli/commands/__tests__/check.test.ts +43 -36
- package/src/cli/commands/__tests__/command-gate-dead-options.test.ts +60 -0
- package/src/cli/commands/__tests__/command.test.ts +33 -17
- package/src/cli/commands/__tests__/constraints-retire.test.ts +52 -0
- package/src/cli/commands/__tests__/context-syncer.test.ts +141 -0
- package/src/cli/commands/__tests__/contract.test.ts +20 -20
- package/src/cli/commands/__tests__/failure.test.ts +5 -4
- package/src/cli/commands/__tests__/gate-decision.ts +30 -0
- package/src/cli/commands/__tests__/init-dead-options.test.ts +50 -0
- package/src/cli/commands/__tests__/init-governance-io.test.ts +139 -0
- package/src/cli/commands/__tests__/init-injection.test.ts +3 -3
- package/src/cli/commands/__tests__/init-ondisk.test.ts +867 -0
- package/src/cli/commands/__tests__/init.test.ts +82 -6
- package/src/cli/commands/__tests__/knowledge-audit-threshold.test.ts +146 -0
- package/src/cli/commands/__tests__/knowledge-flywheel-consistency.test.ts +1 -1
- package/src/cli/commands/__tests__/knowledge-tone-mapping.test.ts +244 -0
- package/src/cli/commands/__tests__/knowledge-view.test.ts +839 -0
- package/src/cli/commands/__tests__/knowledge.test.ts +33 -15
- package/src/cli/commands/__tests__/numeric-flag-assembly.test.ts +368 -0
- package/src/cli/commands/__tests__/performance.test.ts +19 -21
- package/src/cli/commands/__tests__/posteval-plan.test.ts +5 -3
- package/src/cli/commands/__tests__/pre-push-hook.test.ts +181 -0
- package/src/cli/commands/__tests__/project-path-anchoring.test.ts +95 -2
- package/src/cli/commands/__tests__/project-path-convention.test.ts +103 -25
- package/src/cli/commands/__tests__/registry.test.ts +2 -0
- package/src/cli/commands/__tests__/report.test.ts +23 -1
- package/src/cli/commands/__tests__/review.test.ts +10 -17
- package/src/cli/commands/__tests__/scaffold.test.ts +505 -0
- package/src/cli/commands/__tests__/security-default-scan.test.ts +75 -0
- package/src/cli/commands/__tests__/security.test.ts +21 -24
- package/src/cli/commands/__tests__/spec-baseline-check.test.ts +3 -2
- package/src/cli/commands/__tests__/spec-baseline-index-cap.test.ts +131 -0
- package/src/cli/commands/__tests__/spec-baseline-read-count.test.ts +325 -0
- package/src/cli/commands/__tests__/sync-docs-agents.test.ts +19 -4
- package/src/cli/commands/__tests__/sync-docs-context-drift.test.ts +232 -0
- package/src/cli/commands/__tests__/sync-docs-module-order.test.ts +111 -0
- package/src/cli/commands/__tests__/sync-docs-read-count.test.ts +192 -0
- package/src/cli/commands/__tests__/sync-docs.test.ts +3 -2
- package/src/cli/commands/__tests__/validate.test.ts +1 -48
- package/src/cli/commands/acceptance.ts +24 -29
- package/src/cli/commands/check.ts +40 -17
- package/src/cli/commands/command.ts +9 -8
- package/src/cli/commands/constraints-retire.ts +57 -70
- package/src/cli/commands/contract.ts +44 -47
- package/src/cli/commands/definitions.ts +12 -6
- package/src/cli/commands/failure.ts +16 -3
- package/src/cli/commands/init.ts +242 -389
- package/src/cli/commands/knowledge-view.ts +224 -0
- package/src/cli/commands/knowledge.ts +643 -448
- package/src/cli/commands/passes-gate.ts +12 -3
- package/src/cli/commands/performance.ts +31 -38
- package/src/cli/commands/report.ts +3 -2
- package/src/cli/commands/review.ts +22 -28
- package/src/cli/commands/scaffold-templates.ts +406 -0
- package/src/cli/commands/scaffold.ts +302 -0
- package/src/cli/commands/security.ts +27 -23
- package/src/cli/commands/spec-baseline-check.ts +158 -33
- package/src/cli/commands/sync-docs/__tests__/context-export-surface.test.ts +102 -0
- package/src/cli/commands/sync-docs/__tests__/module-descriptions.test.ts +196 -0
- package/src/cli/commands/sync-docs/context-syncer.ts +137 -31
- package/src/cli/commands/sync-docs/index.ts +103 -28
- package/src/cli/commands/sync-docs/project-reader.ts +51 -7
- package/src/cli/commands/validate.ts +1 -104
- package/src/cli/gate-command.ts +87 -0
- package/src/completion-checkers/index.ts +10 -1
- package/src/context/CONTEXT.md +2 -1
- package/src/context/__tests__/knowledge-injector.test.ts +27 -0
- package/src/context/__tests__/session-manager.test.ts +19 -12
- package/src/context/knowledge-injector.ts +14 -7
- package/src/core/CONTEXT.md +10 -7
- package/src/core/__tests__/effective-set.test.ts +36 -60
- package/src/core/constraints/__tests__/context-reconcile.test.ts +246 -0
- package/src/core/constraints/__tests__/run-env.test.ts +377 -0
- package/src/core/constraints/__tests__/triggers.test.ts +70 -0
- package/src/core/constraints/agent-prompt-renderer.ts +1 -1
- package/src/core/constraints/capabilities-reconcile.ts +28 -4
- package/src/core/constraints/check-cache.ts +1 -1
- package/src/core/constraints/checker.ts +30 -14
- package/src/core/constraints/checkers/__tests__/context-doc-sync.test.ts +8 -3
- package/src/core/constraints/checkers/__tests__/governance-presence.test.ts +16 -7
- package/src/core/constraints/checkers/__tests__/no-hardcoded-credentials.test.ts +2 -1
- package/src/core/constraints/checkers/capability-sync.ts +27 -28
- package/src/core/constraints/checkers/context-doc-sync.ts +9 -7
- package/src/core/constraints/checkers/docs-freshness.ts +28 -33
- package/src/core/constraints/checkers/governance-presence.ts +10 -6
- package/src/core/constraints/checkers/types.ts +14 -8
- package/src/core/constraints/context-builder.ts +35 -26
- package/src/core/constraints/context-reconcile.ts +200 -0
- package/src/core/constraints/doc-freshness/__tests__/runner.test.ts +25 -0
- package/src/core/constraints/doc-freshness/runner.ts +18 -4
- package/src/core/constraints/git-evidence.ts +1 -1
- package/src/core/constraints/injection-drift.ts +19 -8
- package/src/core/constraints/run-env.ts +207 -0
- package/src/core/constraints/triggers.ts +33 -0
- package/src/core/effective-constraints.ts +17 -6
- package/src/core/effective-set.ts +8 -24
- package/src/core/index.ts +2 -0
- package/src/core/project-config-loader.ts +54 -102
- package/src/core/validators/__tests__/http-retry-sleep.test.ts +231 -0
- package/src/core/validators/check-handlers/http.ts +18 -7
- package/src/failure/CONTEXT.md +2 -1
- package/src/failure/classifier.ts +2 -2
- package/src/failure/index.ts +14 -2
- package/src/failure/recorder.ts +1 -1
- package/src/gates/CONTEXT.md +13 -7
- package/src/gates/__tests__/checker-gate.test.ts +1 -1
- package/src/gates/__tests__/command-single-predicate.test.ts +135 -0
- package/src/gates/__tests__/command.test.ts +8 -15
- package/src/gates/__tests__/contract.test.ts +5 -5
- package/src/gates/__tests__/gate-interface.test.ts +0 -17
- package/src/gates/__tests__/performance.test.ts +0 -13
- package/src/gates/__tests__/review.test.ts +0 -1
- package/src/gates/__tests__/runner.test.ts +1 -1
- package/src/gates/__tests__/security-default-scan.test.ts +97 -0
- package/src/gates/__tests__/security.test.ts +0 -13
- package/src/gates/checker-gate.ts +3 -2
- package/src/gates/command.ts +51 -74
- package/src/gates/contract.ts +0 -5
- package/src/gates/definitions.ts +6 -5
- package/src/gates/index.ts +0 -5
- package/src/gates/performance.ts +1 -6
- package/src/gates/runner.ts +1 -1
- package/src/gates/security.ts +9 -11
- package/src/gates/types.ts +20 -23
- package/src/hooks/CONTEXT.md +10 -9
- package/src/hooks/__tests__/bootstrap.test.ts +29 -6
- package/src/hooks/__tests__/pipeline.test.ts +28 -17
- package/src/hooks/__tests__/registry.test.ts +51 -3
- package/src/hooks/bootstrap.ts +35 -15
- package/src/hooks/config.ts +6 -2
- package/src/hooks/index.ts +10 -1
- package/src/hooks/pipeline.ts +4 -6
- package/src/hooks/registry.ts +31 -12
- package/src/hooks/types.ts +24 -7
- package/src/index.ts +1 -2
- package/src/knowledge/CONTEXT.md +14 -7
- package/src/knowledge/__tests__/audit-labels.test.ts +8 -5
- package/src/knowledge/__tests__/audit-scoring.test.ts +230 -0
- package/src/knowledge/__tests__/audit-write-count.test.ts +131 -0
- package/src/knowledge/__tests__/audit.test.ts +291 -208
- package/src/knowledge/__tests__/doctor.test.ts +3 -2
- package/src/knowledge/__tests__/ingest.test.ts +3 -2
- package/src/knowledge/__tests__/lifecycle.test.ts +57 -2
- package/src/knowledge/__tests__/migration.test.ts +35 -6
- package/src/knowledge/__tests__/query.test.ts +3 -2
- package/src/knowledge/__tests__/reference-tracker.test.ts +23 -2
- package/src/knowledge/__tests__/store.test.ts +149 -4
- package/src/knowledge/__tests__/tree-walker.test.ts +132 -0
- package/src/knowledge/audit-scoring.ts +589 -0
- package/src/knowledge/audit.ts +55 -599
- package/src/knowledge/import.ts +2 -0
- package/src/knowledge/index-generator.ts +4 -6
- package/src/knowledge/index.ts +27 -2
- package/src/knowledge/ingest.ts +1 -1
- package/src/knowledge/lifecycle.ts +5 -2
- package/src/knowledge/migration.ts +8 -2
- package/src/knowledge/query.ts +8 -1
- package/src/knowledge/reference-tracker.ts +5 -7
- package/src/knowledge/store.ts +75 -16
- package/src/knowledge/tree-walker.ts +29 -0
- package/src/knowledge/types.ts +19 -0
- package/src/monitoring/CONTEXT.md +5 -2
- package/src/monitoring/__tests__/context-tracker.test.ts +16 -8
- package/src/monitoring/__tests__/trace-file-anchoring.test.ts +80 -0
- package/src/monitoring/traces.ts +19 -5
- package/src/release/CONTEXT.md +1 -1
- package/src/release/__tests__/integrity.test.ts +21 -12
- package/src/test-setup/__tests__/jsonl-fake-fs.test.ts +98 -0
- package/src/test-setup/jsonl-fake-fs.ts +59 -0
- package/src/tools/index.ts +5 -1
- package/src/types/checkpoint.ts +6 -0
- package/src/types/project-config.ts +21 -0
- package/src/types/trace.ts +14 -4
- package/src/utils/__tests__/file-walk.test.ts +3 -2
- package/src/utils/__tests__/jsonl-bounded-read.test.ts +106 -0
- package/src/utils/__tests__/jsonl-skip-disposition.test.ts +10 -6
- package/src/utils/__tests__/jsonl.test.ts +61 -14
- package/src/utils/__tests__/numeric-flag.test.ts +80 -0
- package/src/utils/__tests__/package-version.test.ts +2 -2
- package/src/utils/exec.ts +4 -64
- package/src/utils/jsonl.ts +159 -20
- package/src/utils/numeric-flag.ts +64 -0
- package/dist/failure/types.d.ts +0 -9
- package/dist/failure/types.d.ts.map +0 -1
- package/dist/failure/types.js +0 -25
- package/dist/failure/types.js.map +0 -1
- package/dist/gates/effective-gates.d.ts +0 -30
- package/dist/gates/effective-gates.d.ts.map +0 -1
- package/dist/gates/effective-gates.js +0 -81
- package/dist/gates/effective-gates.js.map +0 -1
- package/src/failure/types.ts +0 -9
- package/src/gates/__tests__/effective-gates.test.ts +0 -77
- package/src/gates/effective-gates.ts +0 -99
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* audit-scoring 纯模块测试(harness#134)
|
|
3
|
+
*
|
|
4
|
+
* 本模块的立身之本是**零 IO**:判定只吃条目数组与已取好的环境数据。
|
|
5
|
+
* 因此这里既有行为断言,也有一道源形状闸——有人往打分核心塞回 fs,就跑红。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import * as fs from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import {
|
|
11
|
+
AUDIT_RULE_LABELS,
|
|
12
|
+
DEFAULT_PROMOTION_BLOCK_DAYS,
|
|
13
|
+
DEFAULT_SHORT_CONTENT_THRESHOLD,
|
|
14
|
+
DEFAULT_STALE_DAYS,
|
|
15
|
+
MAX_SOURCE_REFS,
|
|
16
|
+
calculateHealthScore,
|
|
17
|
+
computeDimensions,
|
|
18
|
+
resolveThresholds,
|
|
19
|
+
scanEntries,
|
|
20
|
+
summarizeIssues,
|
|
21
|
+
} from '../audit-scoring';
|
|
22
|
+
import type { AuditIssue } from '../audit-scoring';
|
|
23
|
+
import type { KnowledgeEntry } from '../types';
|
|
24
|
+
|
|
25
|
+
const SOURCE = fs.readFileSync(path.join(__dirname, '../audit-scoring.ts'), 'utf-8');
|
|
26
|
+
|
|
27
|
+
function makeEntry(overrides: Partial<KnowledgeEntry> = {}): KnowledgeEntry {
|
|
28
|
+
return {
|
|
29
|
+
id: 'SCORE-001',
|
|
30
|
+
type: 'guideline',
|
|
31
|
+
title: 'Scoring Entry',
|
|
32
|
+
content: 'Some meaningful content that is long enough to pass thresholds',
|
|
33
|
+
maturity: 'draft',
|
|
34
|
+
layer: 'project',
|
|
35
|
+
created: new Date().toISOString(),
|
|
36
|
+
lastReferenced: new Date().toISOString(),
|
|
37
|
+
contributors: ['tester'],
|
|
38
|
+
projects: ['probe'],
|
|
39
|
+
tags: [],
|
|
40
|
+
applicablePhases: [],
|
|
41
|
+
sourceReferences: [],
|
|
42
|
+
referencedBy: [],
|
|
43
|
+
executionResults: [],
|
|
44
|
+
consumptionMode: 'reference',
|
|
45
|
+
origin: 'agent',
|
|
46
|
+
...overrides,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('源形状闸:打分核心零 IO', () => {
|
|
51
|
+
it('不 import fs/path,也不直读 store 之外的任何东西', () => {
|
|
52
|
+
expect(SOURCE).not.toMatch(/from '(node:)?fs'/);
|
|
53
|
+
expect(SOURCE).not.toMatch(/from 'path'/);
|
|
54
|
+
expect(SOURCE).not.toMatch(/\bfs\.(readFileSync|existsSync|writeFileSync|readdirSync)\b/);
|
|
55
|
+
expect(SOURCE).not.toMatch(/new FileKnowledgeStore/);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('条目集合外唯一的入参是 env(消费统计与存活率由调用方取好喂入)', () => {
|
|
59
|
+
expect(SOURCE).toContain('env: AuditEnv');
|
|
60
|
+
expect(SOURCE).toContain('dailyConsumptionEvents?: number');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('resolveThresholds', () => {
|
|
65
|
+
it('未给阈值时落三张缺省值', () => {
|
|
66
|
+
expect(resolveThresholds()).toEqual({
|
|
67
|
+
shortContentThreshold: DEFAULT_SHORT_CONTENT_THRESHOLD,
|
|
68
|
+
staleDays: DEFAULT_STALE_DAYS,
|
|
69
|
+
promotionBlockDays: DEFAULT_PROMOTION_BLOCK_DAYS,
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('显式值原样生效(含 0 不被缺省兜掉)', () => {
|
|
74
|
+
expect(resolveThresholds({ shortContentThreshold: 0, staleDays: 7 }).shortContentThreshold).toBe(0);
|
|
75
|
+
expect(resolveThresholds({ staleDays: 7 }).staleDays).toBe(7);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe('scanEntries 的人口语义', () => {
|
|
80
|
+
it('单条目模式(不传人口)下跨条目规则不判定', () => {
|
|
81
|
+
const dupes = [
|
|
82
|
+
makeEntry({ id: 'P-1', title: 'Same', type: 'guideline' }),
|
|
83
|
+
makeEntry({ id: 'P-2', title: 'Same', type: 'guideline' }),
|
|
84
|
+
];
|
|
85
|
+
for (const entry of dupes) {
|
|
86
|
+
expect(scanEntries([entry], {}).some(i => i.rule === 'title-duplicate')).toBe(false);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('传入人口时同一对条目互相判重(两条都报)', () => {
|
|
91
|
+
const dupes = [
|
|
92
|
+
makeEntry({ id: 'P-1', title: 'Same', type: 'guideline' }),
|
|
93
|
+
makeEntry({ id: 'P-2', title: 'Same', type: 'guideline' }),
|
|
94
|
+
];
|
|
95
|
+
const issues = scanEntries(dupes, {}, dupes);
|
|
96
|
+
expect(issues.filter(i => i.rule === 'title-duplicate')).toHaveLength(2);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('人口与扫描集合可不同:autoFix 重扫沿用修复前人口的现状口径', () => {
|
|
100
|
+
const before = [
|
|
101
|
+
makeEntry({ id: 'Q-1', title: 'Dup', type: 'guideline' }),
|
|
102
|
+
makeEntry({ id: 'Q-2', title: 'Dup', type: 'guideline' }),
|
|
103
|
+
];
|
|
104
|
+
const after = before.map(e => ({ ...e, maturity: 'archived' as const }));
|
|
105
|
+
// 扫描已归档的集合、对照未归档的人口:active 规则不判定 archived,故零问题
|
|
106
|
+
expect(scanEntries(after, {}, before)).toHaveLength(0);
|
|
107
|
+
// 对照集合同为已归档:同样零问题(人口过滤唯一落点在 ruleDetail)
|
|
108
|
+
expect(scanEntries(after, {}, after)).toHaveLength(0);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('summarizeIssues', () => {
|
|
113
|
+
it('未命中的规则也出零值键,键集与 label 正本表一致', () => {
|
|
114
|
+
const summary = summarizeIssues([]);
|
|
115
|
+
expect(Object.keys(summary).sort()).toEqual(Object.keys(AUDIT_RULE_LABELS).sort());
|
|
116
|
+
expect(Object.values(summary).every(n => n === 0)).toBe(true);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('命中计数逐条累加', () => {
|
|
120
|
+
const issues: AuditIssue[] = [
|
|
121
|
+
{ rule: 'short-content', entryId: 'a', title: 'A', severity: 'medium', action: 'flag', detail: '' },
|
|
122
|
+
{ rule: 'short-content', entryId: 'b', title: 'B', severity: 'medium', action: 'flag', detail: '' },
|
|
123
|
+
{ rule: 'event-noise', entryId: 'c', title: 'C', severity: 'critical', action: 'archive', detail: '' },
|
|
124
|
+
];
|
|
125
|
+
const summary = summarizeIssues(issues);
|
|
126
|
+
expect(summary['short-content']).toBe(2);
|
|
127
|
+
expect(summary['event-noise']).toBe(1);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe('computeDimensions 的环境数据入参', () => {
|
|
132
|
+
const active = [
|
|
133
|
+
makeEntry({ id: 'D-1', maturity: 'verified', referencedBy: ['x:2026-09-01'] }),
|
|
134
|
+
makeEntry({ id: 'D-2', maturity: 'verified' }),
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
it('D6 消费事件数来自 env,透传到报告明细', () => {
|
|
138
|
+
const withOut = computeDimensions(active, [], {});
|
|
139
|
+
const withEnv = computeDimensions(active, [], { dailyConsumptionEvents: 8 });
|
|
140
|
+
expect(withOut.flywheel.details.dailyConsumptionEvents).toBe(0);
|
|
141
|
+
expect(withEnv.flywheel.details.dailyConsumptionEvents).toBe(8);
|
|
142
|
+
expect(withEnv.flywheel.score).toBeGreaterThan(withOut.flywheel.score);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('D7 由 env.survival 供给:无快照 = 满分带说明,有快照 = 分数即存活率', () => {
|
|
146
|
+
expect(computeDimensions(active, [], {}).incremental).toEqual({
|
|
147
|
+
score: 100,
|
|
148
|
+
issues: 0,
|
|
149
|
+
details: { note: 'no 30d snapshot available' },
|
|
150
|
+
});
|
|
151
|
+
expect(computeDimensions(active, [], {
|
|
152
|
+
survival: { rate: 60, survived: 6, total: 10, snapshotDate: '2026-08-10' },
|
|
153
|
+
}).incremental).toEqual({
|
|
154
|
+
score: 60,
|
|
155
|
+
issues: 4,
|
|
156
|
+
details: { survivalRate: 60, survived: 6, total: 10, snapshotDate: '2026-08-10' },
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('空人口:结构与成熟度满分、飞轮零分(无活动可测)', () => {
|
|
161
|
+
const dims = computeDimensions([], [], {});
|
|
162
|
+
expect(dims.structure.score).toBe(100);
|
|
163
|
+
expect(dims.maturity.score).toBe(100);
|
|
164
|
+
expect(dims.flywheel.score).toBe(0);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
describe('calculateHealthScore', () => {
|
|
169
|
+
const base = [makeEntry({ id: 'H-1', maturity: 'verified' }), makeEntry({ id: 'H-2', maturity: 'verified' })];
|
|
170
|
+
const issue = (severity: AuditIssue['severity']): AuditIssue => ({
|
|
171
|
+
rule: 'short-content', entryId: 'H-1', title: 'H', severity, action: 'flag', detail: '',
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('无问题 = 100', () => {
|
|
175
|
+
expect(calculateHealthScore(base, [])).toBe(100);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('惩罚按严重度分级:critical > high > medium > low', () => {
|
|
179
|
+
const critical = calculateHealthScore(base, [issue('critical')]);
|
|
180
|
+
const low = calculateHealthScore(base, [issue('low')]);
|
|
181
|
+
expect(critical).toBeLessThan(low);
|
|
182
|
+
expect(low).toBeLessThan(100);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('四档严重度各自的罚分权重(满分 100,人口 2 → 每条满罚 10 分权重)', () => {
|
|
186
|
+
// penalty / (entries × 10) → critical 10、high 5、medium 2、low 1
|
|
187
|
+
expect(calculateHealthScore(base, [issue('critical')])).toBe(50);
|
|
188
|
+
expect(calculateHealthScore(base, [issue('high')])).toBe(75);
|
|
189
|
+
expect(calculateHealthScore(base, [issue('medium')])).toBe(90);
|
|
190
|
+
expect(calculateHealthScore(base, [issue('low')])).toBe(95);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('条目为空时恒 100(无人口不判健康度)', () => {
|
|
194
|
+
expect(calculateHealthScore([], [issue('critical')])).toBe(100);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe('fragment-cluster(跨条目规则)', () => {
|
|
199
|
+
it('同 type + 共享 ≥2 标签 + 正文均 <100 字符且 peers≥2 才成簇', () => {
|
|
200
|
+
const short = (id: string, tags: string[]): KnowledgeEntry =>
|
|
201
|
+
makeEntry({ id, type: 'guideline', maturity: 'verified', content: '短'.repeat(20), tags });
|
|
202
|
+
const population = [short('FC-1', ['auth', 'db']), short('FC-2', ['auth', 'db']), short('FC-3', ['auth', 'db'])];
|
|
203
|
+
const issues = scanEntries(population, {}, population);
|
|
204
|
+
expect(issues.filter(i => i.rule === 'fragment-cluster').map(i => i.entryId).sort())
|
|
205
|
+
.toEqual(['FC-1', 'FC-2', 'FC-3']);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('peers 只有 1 个时不成簇', () => {
|
|
209
|
+
const short = (id: string): KnowledgeEntry =>
|
|
210
|
+
makeEntry({ id, type: 'guideline', maturity: 'verified', content: '短'.repeat(20), tags: ['auth', 'db'] });
|
|
211
|
+
const population = [short('FC-1'), short('FC-2'), makeEntry({ id: 'FC-LONG', type: 'guideline', maturity: 'verified', content: '长'.repeat(120), tags: ['auth', 'db'] })];
|
|
212
|
+
const issues = scanEntries(population, {}, population);
|
|
213
|
+
expect(issues.filter(i => i.rule === 'fragment-cluster')).toHaveLength(0);
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
describe('MAX_SOURCE_REFS', () => {
|
|
218
|
+
it('正好上限不报,超一条才报', () => {
|
|
219
|
+
const atLimit = makeEntry({
|
|
220
|
+
id: 'R-1',
|
|
221
|
+
sourceReferences: Array.from({ length: MAX_SOURCE_REFS }, (_, i) => ({ workflow: `w${i}`, timestamp: '' })),
|
|
222
|
+
});
|
|
223
|
+
const overLimit = makeEntry({
|
|
224
|
+
id: 'R-2',
|
|
225
|
+
sourceReferences: Array.from({ length: MAX_SOURCE_REFS + 1 }, (_, i) => ({ workflow: `w${i}`, timestamp: '' })),
|
|
226
|
+
});
|
|
227
|
+
expect(scanEntries([atLimit], {}).some(i => i.rule === 'source-refs-bloat')).toBe(false);
|
|
228
|
+
expect(scanEntries([overLimit], {}).some(i => i.rule === 'source-refs-bloat')).toBe(true);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 一次 `audit --fix` 的索引重写计数闸(harness#134 验收 2)
|
|
3
|
+
*
|
|
4
|
+
* 手法照 `src/cli/commands/__tests__/check-read-count.test.ts`:真执行、只在中间记一笔,
|
|
5
|
+
* 不改任何行为。数的是**底层 index.json 被重写了几次**——`store.writeIndex()` 的唯一出口
|
|
6
|
+
* 就是 `fs.writeFileSync(index.json)`,而 fs 属性不可 spyOn,故按该文件的做法整体 mock。
|
|
7
|
+
*
|
|
8
|
+
* 收口前:一次修复 = 一次 `store.update()` = 一次全量索引重写 → 计数 = 问题条数。
|
|
9
|
+
* 收口后:整批经 `store.applyAll()` → 计数 = 1。夹具必须让四种修复动作都真发生,
|
|
10
|
+
* 否则闸门是空跑的。
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import * as fs from 'fs';
|
|
14
|
+
import * as os from 'os';
|
|
15
|
+
import * as path from 'path';
|
|
16
|
+
import { KnowledgeAudit } from '../audit';
|
|
17
|
+
import { FileKnowledgeStore } from '../store';
|
|
18
|
+
import type { KnowledgeEntry } from '../types';
|
|
19
|
+
|
|
20
|
+
type WriteCall = { file: string };
|
|
21
|
+
|
|
22
|
+
// 计数器挂在 globalThis:jest.mock 工厂会被提前调用,闭包外提会撞 TDZ
|
|
23
|
+
jest.mock('fs', () => {
|
|
24
|
+
const actual = jest.requireActual<typeof import('fs')>('fs');
|
|
25
|
+
const g = globalThis as unknown as { __H134_INDEX_WRITES__?: WriteCall[] };
|
|
26
|
+
if (!g.__H134_INDEX_WRITES__) g.__H134_INDEX_WRITES__ = [];
|
|
27
|
+
const bucket = g.__H134_INDEX_WRITES__;
|
|
28
|
+
const name = (p: unknown): string => (Buffer.isBuffer(p) ? p.toString('utf8') : String(p));
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
...actual,
|
|
32
|
+
writeFileSync: jest.fn((p: unknown, ...rest: unknown[]) => {
|
|
33
|
+
bucket.push({ file: name(p) });
|
|
34
|
+
return (actual.writeFileSync as (...args: unknown[]) => unknown)(p, ...rest);
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const writes = () =>
|
|
40
|
+
((globalThis as unknown as { __H134_INDEX_WRITES__?: WriteCall[] }).__H134_INDEX_WRITES__ ||= []);
|
|
41
|
+
|
|
42
|
+
function makeEntry(overrides: Partial<KnowledgeEntry> = {}): KnowledgeEntry {
|
|
43
|
+
return {
|
|
44
|
+
id: 'WC-001',
|
|
45
|
+
type: 'guideline',
|
|
46
|
+
title: 'Write Count Entry',
|
|
47
|
+
content: 'Some meaningful content that is long enough to pass thresholds',
|
|
48
|
+
maturity: 'verified',
|
|
49
|
+
layer: 'project',
|
|
50
|
+
created: new Date().toISOString(),
|
|
51
|
+
lastReferenced: new Date().toISOString(),
|
|
52
|
+
contributors: ['tester'],
|
|
53
|
+
projects: ['probe'],
|
|
54
|
+
tags: [],
|
|
55
|
+
applicablePhases: [],
|
|
56
|
+
sourceReferences: [],
|
|
57
|
+
referencedBy: [],
|
|
58
|
+
executionResults: [],
|
|
59
|
+
consumptionMode: 'reference',
|
|
60
|
+
origin: 'agent',
|
|
61
|
+
...overrides,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 四种修复动作各一条:archive(测试标签)/ demote(零内容 proven)/ flag(短内容)/ trim(refs 膨胀) */
|
|
66
|
+
function fixtureEntries(): KnowledgeEntry[] {
|
|
67
|
+
return [
|
|
68
|
+
makeEntry({ id: 'WC-ARCH', title: 'Archive Me', maturity: 'verified', tags: ['test-scope-wc'] }),
|
|
69
|
+
makeEntry({ id: 'WC-DEMOTE', title: 'Demote Me', maturity: 'proven', content: 'tiny' }),
|
|
70
|
+
makeEntry({ id: 'WC-FLAG', title: 'Flag Me', maturity: 'verified', content: 'a'.repeat(30) }),
|
|
71
|
+
makeEntry({
|
|
72
|
+
id: 'WC-TRIM',
|
|
73
|
+
title: 'Trim Me',
|
|
74
|
+
maturity: 'verified',
|
|
75
|
+
sourceReferences: Array.from({ length: 25 }, (_, i) => ({ workflow: `wf-${i}`, timestamp: '' })),
|
|
76
|
+
}),
|
|
77
|
+
];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
describe('一次 audit --fix 的 index.json 重写计数(harness#134)', () => {
|
|
81
|
+
let dir: string;
|
|
82
|
+
|
|
83
|
+
beforeEach(() => {
|
|
84
|
+
writes().length = 0;
|
|
85
|
+
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'audit-write-count-'));
|
|
86
|
+
const seed = new FileKnowledgeStore({ baseDir: dir });
|
|
87
|
+
for (const entry of fixtureEntries()) seed.save(entry);
|
|
88
|
+
writes().length = 0; // 只数审计这一段
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
afterEach(() => {
|
|
92
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('4 条修复只重写一次 index.json,条目文件各重写一次', () => {
|
|
96
|
+
const audit = new KnowledgeAudit(new FileKnowledgeStore({ baseDir: dir }));
|
|
97
|
+
const report = audit.run({ autoFix: true });
|
|
98
|
+
|
|
99
|
+
// 正对照:四种动作全部真发生
|
|
100
|
+
expect(report.autoFixed).toBe(4);
|
|
101
|
+
|
|
102
|
+
const indexWrites = writes().filter(w => path.basename(w.file) === 'index.json');
|
|
103
|
+
const entryWrites = writes().filter(w => w.file.endsWith('.md'));
|
|
104
|
+
expect(indexWrites).toHaveLength(1);
|
|
105
|
+
expect(entryWrites.map(w => path.basename(w.file)).sort()).toEqual([
|
|
106
|
+
'guideline-WC-ARCH.md',
|
|
107
|
+
'guideline-WC-DEMOTE.md',
|
|
108
|
+
'guideline-WC-FLAG.md',
|
|
109
|
+
'guideline-WC-TRIM.md',
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('无修复项时零索引重写(applyAll 空批不落盘)', () => {
|
|
114
|
+
const cleanDir = fs.mkdtempSync(path.join(os.tmpdir(), 'audit-write-count-clean-'));
|
|
115
|
+
const seed = new FileKnowledgeStore({ baseDir: cleanDir });
|
|
116
|
+
seed.save(makeEntry({
|
|
117
|
+
id: 'WC-CLEAN',
|
|
118
|
+
title: 'Perfectly Ordinary Title',
|
|
119
|
+
maturity: 'verified',
|
|
120
|
+
content: 'x'.repeat(200),
|
|
121
|
+
referencedBy: ['someone:2026-09-14'],
|
|
122
|
+
}));
|
|
123
|
+
writes().length = 0;
|
|
124
|
+
|
|
125
|
+
const report = new KnowledgeAudit(new FileKnowledgeStore({ baseDir: cleanDir })).run({ autoFix: true });
|
|
126
|
+
|
|
127
|
+
expect(report.autoFixed).toBe(0); // 正对照:确实无可修项
|
|
128
|
+
expect(writes().filter(w => path.basename(w.file) === 'index.json')).toHaveLength(0);
|
|
129
|
+
fs.rmSync(cleanDir, { recursive: true, force: true });
|
|
130
|
+
});
|
|
131
|
+
});
|