@dommaker/harness 1.7.0 → 1.8.1
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 +44 -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 +19 -3
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +36 -22
- 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/status.d.ts +8 -0
- package/dist/cli/commands/status.d.ts.map +1 -1
- package/dist/cli/commands/status.js +5 -7
- package/dist/cli/commands/status.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/cli/state-io.d.ts +34 -0
- package/dist/cli/state-io.d.ts.map +1 -0
- package/dist/cli/state-io.js +71 -0
- package/dist/cli/state-io.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 +19 -1
- package/dist/hooks/pipeline.d.ts.map +1 -1
- package/dist/hooks/pipeline.js +42 -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 +25 -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/__tests__/state-io.test.ts +50 -0
- package/src/cli/commands/CONTEXT.md +30 -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 +170 -0
- package/src/cli/commands/__tests__/check-skip-output.test.ts +4 -1
- package/src/cli/commands/__tests__/check.test.ts +63 -44
- 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__/status-extra.test.ts +25 -8
- package/src/cli/commands/__tests__/status.test.ts +46 -18
- 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 +60 -35
- 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/status.ts +12 -7
- 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/cli/state-io.ts +53 -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 +133 -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 +51 -6
- package/src/hooks/registry.ts +31 -12
- package/src/hooks/types.ts +26 -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
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* ADR-0020 起不再 mock TraceAnalyzer/TraceCollector:统计与异常由 trace-analyzer
|
|
5
5
|
* 的模块级纯函数真算,用例喂合法 trace 行、断言真实输出。
|
|
6
|
+
* ADR-0026 起状态文件读写经注入的 StateIO 假件,不碰(被 mock 的)fs。
|
|
6
7
|
*/
|
|
7
8
|
|
|
8
|
-
import { status } from '../status';
|
|
9
|
-
import { captureIO, type CapturingIO } from '../../command-contract';
|
|
9
|
+
import { status, type StatusOptions } from '../status';
|
|
10
|
+
import { captureIO, type CapturingIO, type CommandResult } from '../../command-contract';
|
|
11
|
+
import type { HarnessState, StateIO } from '../../state-io';
|
|
10
12
|
import * as fs from 'fs';
|
|
11
13
|
import type { ExecutionTrace } from '../../../types/trace';
|
|
12
14
|
|
|
@@ -42,10 +44,27 @@ function repeats(constraintId: string, n: number, result: ExecutionTrace['result
|
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
let io: CapturingIO;
|
|
47
|
+
let stateIO: ReturnType<typeof memoryStateIO>;
|
|
45
48
|
beforeEach(() => {
|
|
46
49
|
io = captureIO();
|
|
50
|
+
stateIO = memoryStateIO();
|
|
47
51
|
});
|
|
48
52
|
|
|
53
|
+
/** 内存 StateIO 假件(ADR-0026):状态读写走注入面,缺省 fileStateIO 在全 mock 的 fs 下会吃到 trace 假数据 */
|
|
54
|
+
function memoryStateIO(initial: HarnessState = {}): StateIO & { snapshot(): HarnessState } {
|
|
55
|
+
let state = initial;
|
|
56
|
+
return {
|
|
57
|
+
read: () => state,
|
|
58
|
+
write: (next: HarnessState) => { state = next; },
|
|
59
|
+
snapshot: () => state,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 全部用例经注入假件调用 status(stateIO 可被单例覆盖以预置状态) */
|
|
64
|
+
function runStatus(options: StatusOptions = {}): Promise<CommandResult> {
|
|
65
|
+
return status({ stateIO, ...options }, io);
|
|
66
|
+
}
|
|
67
|
+
|
|
49
68
|
describe('status command', () => {
|
|
50
69
|
|
|
51
70
|
beforeEach(() => {
|
|
@@ -59,7 +78,7 @@ describe('status command', () => {
|
|
|
59
78
|
describe('未初始化情况', () => {
|
|
60
79
|
it('应该显示未初始化提示', async () => {
|
|
61
80
|
mockFs.existsSync.mockReturnValue(false);
|
|
62
|
-
await
|
|
81
|
+
await runStatus();
|
|
63
82
|
expect(io.outText()).toContain('未初始化');
|
|
64
83
|
});
|
|
65
84
|
});
|
|
@@ -71,7 +90,7 @@ describe('status command', () => {
|
|
|
71
90
|
.mockReturnValueOnce(true) // .harness dir
|
|
72
91
|
.mockReturnValueOnce(false); // traces file
|
|
73
92
|
|
|
74
|
-
await
|
|
93
|
+
await runStatus();
|
|
75
94
|
expect(io.outText()).toContain('暂无 Trace');
|
|
76
95
|
});
|
|
77
96
|
});
|
|
@@ -83,7 +102,7 @@ describe('status command', () => {
|
|
|
83
102
|
{ constraintId: 'test2', level: 'guideline' },
|
|
84
103
|
]));
|
|
85
104
|
|
|
86
|
-
await
|
|
105
|
+
await runStatus();
|
|
87
106
|
expect(io.outText()).toContain('记录数: 2 条');
|
|
88
107
|
expect(io.outText()).toContain('📈 约束统计:');
|
|
89
108
|
});
|
|
@@ -93,7 +112,7 @@ describe('status command', () => {
|
|
|
93
112
|
{ constraintId: 'no_bypass_checkpoint' },
|
|
94
113
|
]));
|
|
95
114
|
|
|
96
|
-
await
|
|
115
|
+
await runStatus({ detail: true });
|
|
97
116
|
expect(io.outText()).toContain('🔴 Iron Laws:');
|
|
98
117
|
expect(io.outText()).toContain('✅ no_bypass_checkpoint');
|
|
99
118
|
expect(io.outText()).toContain('检查: 1 | 通过: 100% | 失败: 0%');
|
|
@@ -106,7 +125,7 @@ describe('status command', () => {
|
|
|
106
125
|
{ constraintId: 'test1', result: 'fail' },
|
|
107
126
|
]));
|
|
108
127
|
|
|
109
|
-
await
|
|
128
|
+
await runStatus({ anomalies: true });
|
|
110
129
|
expect(io.outText()).toContain('发现 1 个异常');
|
|
111
130
|
expect(io.outText()).toContain(' test1');
|
|
112
131
|
expect(io.outText()).toContain('类型: low_pass_rate');
|
|
@@ -120,17 +139,26 @@ describe('status command', () => {
|
|
|
120
139
|
{ constraintId: 'test1', result: 'fail' },
|
|
121
140
|
]));
|
|
122
141
|
|
|
123
|
-
await
|
|
142
|
+
await runStatus({ detail: true });
|
|
124
143
|
expect(io.outText()).toContain('检查: 5 | 通过: 80% | 失败: 20%');
|
|
125
144
|
});
|
|
126
145
|
});
|
|
127
146
|
|
|
128
147
|
describe('状态文件更新', () => {
|
|
129
|
-
it('
|
|
148
|
+
it('应该经 StateIO 写入 lastStatusRun', async () => {
|
|
149
|
+
mockFs.readFileSync.mockReturnValue(traceFile([{ constraintId: 'test' }]));
|
|
150
|
+
|
|
151
|
+
await runStatus();
|
|
152
|
+
expect(stateIO.snapshot().lastStatusRun).toBeTruthy();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('读-改-写:已有的 shownHints 不被 status 抹掉(ADR-0026 决策 2 的行为修复)', async () => {
|
|
130
156
|
mockFs.readFileSync.mockReturnValue(traceFile([{ constraintId: 'test' }]));
|
|
157
|
+
stateIO = memoryStateIO({ shownHints: ['trace_50'] });
|
|
131
158
|
|
|
132
|
-
await
|
|
133
|
-
expect(
|
|
159
|
+
await runStatus();
|
|
160
|
+
expect(stateIO.snapshot().shownHints).toEqual(['trace_50']);
|
|
161
|
+
expect(stateIO.snapshot().lastStatusRun).toBeTruthy();
|
|
134
162
|
});
|
|
135
163
|
});
|
|
136
164
|
|
|
@@ -140,7 +168,7 @@ describe('status command', () => {
|
|
|
140
168
|
{ constraintId: 'test_guide', level: 'guideline' },
|
|
141
169
|
]));
|
|
142
170
|
|
|
143
|
-
await
|
|
171
|
+
await runStatus();
|
|
144
172
|
expect(io.outText()).toContain('🟡 Guidelines:');
|
|
145
173
|
expect(io.outText()).toContain('✅ test_guide');
|
|
146
174
|
});
|
|
@@ -150,7 +178,7 @@ describe('status command', () => {
|
|
|
150
178
|
it('应该显示未发现异常当无异常', async () => {
|
|
151
179
|
mockFs.readFileSync.mockReturnValue(traceFile([{ constraintId: 'test' }]));
|
|
152
180
|
|
|
153
|
-
await
|
|
181
|
+
await runStatus({ anomalies: true });
|
|
154
182
|
expect(io.outText()).toContain('✅ 未发现异常');
|
|
155
183
|
});
|
|
156
184
|
|
|
@@ -159,7 +187,7 @@ describe('status command', () => {
|
|
|
159
187
|
{ constraintId: 'test', result: 'fail' },
|
|
160
188
|
]));
|
|
161
189
|
|
|
162
|
-
await
|
|
190
|
+
await runStatus({ anomalies: true });
|
|
163
191
|
expect(io.outText()).toContain('当前值: 0');
|
|
164
192
|
expect(io.outText()).toContain('阈值: 0.3');
|
|
165
193
|
expect(io.outText()).toContain('下一步建议');
|
|
@@ -170,7 +198,7 @@ describe('status command', () => {
|
|
|
170
198
|
it('应该显示良好建议当 trace >= 100', async () => {
|
|
171
199
|
mockFs.readFileSync.mockReturnValue(traceFile(repeats('test', 100, 'pass')));
|
|
172
200
|
|
|
173
|
-
await
|
|
201
|
+
await runStatus();
|
|
174
202
|
expect(io.outText()).toContain('记录数: 100 条');
|
|
175
203
|
expect(io.outText()).toContain('状态良好');
|
|
176
204
|
});
|
|
@@ -178,7 +206,7 @@ describe('status command', () => {
|
|
|
178
206
|
it('应该显示积累数据建议当 trace < 100', async () => {
|
|
179
207
|
mockFs.readFileSync.mockReturnValue(traceFile([{ constraintId: 'test' }]));
|
|
180
208
|
|
|
181
|
-
await
|
|
209
|
+
await runStatus();
|
|
182
210
|
expect(io.outText()).toContain('继续积累数据');
|
|
183
211
|
});
|
|
184
212
|
|
|
@@ -187,7 +215,7 @@ describe('status command', () => {
|
|
|
187
215
|
{ constraintId: 'test', result: 'fail' },
|
|
188
216
|
]));
|
|
189
217
|
|
|
190
|
-
await
|
|
218
|
+
await runStatus({ anomalies: true });
|
|
191
219
|
expect(io.outText()).toContain('harness status --detail');
|
|
192
220
|
});
|
|
193
221
|
});
|
|
@@ -199,7 +227,7 @@ describe('status command', () => {
|
|
|
199
227
|
...repeats('test_guide', 2, 'fail'),
|
|
200
228
|
].map(t => ({ ...t, level: 'guideline' as const }))));
|
|
201
229
|
|
|
202
|
-
await
|
|
230
|
+
await runStatus({ detail: true });
|
|
203
231
|
expect(io.outText()).toContain('⚠️ test_guide');
|
|
204
232
|
expect(io.outText()).toContain('检查: 5 | 通过: 60% | 失败: 40%');
|
|
205
233
|
});
|
|
@@ -5,18 +5,33 @@
|
|
|
5
5
|
import * as fs from 'fs';
|
|
6
6
|
import { captureIO, type CapturingIO } from '../../command-contract';
|
|
7
7
|
import * as path from 'path';
|
|
8
|
+
import * as os from 'os';
|
|
8
9
|
import { syncDocs } from '../sync-docs';
|
|
9
10
|
|
|
11
|
+
/**
|
|
12
|
+
* 环境固定:CONTEXT.md 的 mtime 过时判定在 CI 下被有意关掉(#142——全新 checkout 的 mtime
|
|
13
|
+
* 由 clone 顺序决定,比出来的「过时」是假灯)。本文件的夹具都是现场写的、断言的是本地行为,
|
|
14
|
+
* 所以环境必须由用例自己声明,不能跟着跑测试的机器走(否则同一份代码在开发机绿、在 CI 红)。
|
|
15
|
+
* 「CI 下关掉 mtime 判定」这条规则本身由 sync-docs-context-drift.test.ts 负责验证。
|
|
16
|
+
*/
|
|
17
|
+
const SAVED_CI = process.env.CI;
|
|
18
|
+
|
|
10
19
|
let io: CapturingIO;
|
|
11
20
|
beforeEach(() => {
|
|
12
21
|
io = captureIO();
|
|
22
|
+
delete process.env.CI;
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
if (SAVED_CI === undefined) delete process.env.CI;
|
|
27
|
+
else process.env.CI = SAVED_CI;
|
|
13
28
|
});
|
|
14
29
|
|
|
15
30
|
describe('sync-docs --agents', () => {
|
|
16
|
-
|
|
31
|
+
let tempDir: string;
|
|
17
32
|
|
|
18
33
|
beforeAll(() => {
|
|
19
|
-
fs.
|
|
34
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-test-sync-docs-agents-'));
|
|
20
35
|
});
|
|
21
36
|
|
|
22
37
|
afterAll(() => {
|
|
@@ -489,11 +504,11 @@ describe('sync-docs --agents', () => {
|
|
|
489
504
|
expect(parsed.resolution.some((r: { action: string }) => r.action === 'update-context-md')).toBe(true);
|
|
490
505
|
expect(parsed.agentsMd).toEqual({ file: 'AGENTS.md', exists: false, stale: true });
|
|
491
506
|
|
|
492
|
-
//
|
|
507
|
+
// 人读模式:mtime 差异只给提示(harness#142 降级),判失败的是缺失
|
|
493
508
|
io = captureIO();
|
|
494
509
|
const humanResult = await syncDocs({ projectPath: testDir, agents: true, check: true }, io);
|
|
495
510
|
expect(humanResult).toEqual({ kind: 'fail', reason: expect.stringContaining('文档不是最新') });
|
|
496
|
-
expect(io.outText()).toContain('
|
|
511
|
+
expect(io.outText()).toContain('源码比文档新');
|
|
497
512
|
expect(io.outText()).toContain('缺少 CONTEXT.md');
|
|
498
513
|
|
|
499
514
|
fs.rmSync(testDir, { recursive: true, force: true });
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sync-docs 的 CONTEXT.md 内容漂移判定接线测试(harness#142)
|
|
3
|
+
*
|
|
4
|
+
* 钉四件事:
|
|
5
|
+
* 1. 内容漂移(幽灵 / barrel 未登记)在 `--check` 下判 fail,reason 点名文件与符号;
|
|
6
|
+
* 2. mtime 漂移降级为本地提示——不再影响退出码,且 CI 环境下连提示都抑制;
|
|
7
|
+
* 3. `--json` 有 contentDrift 结构(供 LLM/CI 消费);
|
|
8
|
+
* 4. 写入模式不改写 CONTEXT.md(散文不可机械生成),退出码面不变。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
import * as path from 'path';
|
|
13
|
+
import * as os from 'os';
|
|
14
|
+
import { captureIO, type CapturingIO, type CommandResult } from '../../command-contract';
|
|
15
|
+
import { syncDocs } from '../sync-docs';
|
|
16
|
+
|
|
17
|
+
jest.mock('chalk', () => ({
|
|
18
|
+
blue: jest.fn((s: string) => s),
|
|
19
|
+
yellow: jest.fn((s: string) => s),
|
|
20
|
+
green: jest.fn((s: string) => s),
|
|
21
|
+
gray: jest.fn((s: string) => s),
|
|
22
|
+
red: jest.fn((s: string) => s),
|
|
23
|
+
cyan: jest.fn((s: string) => s),
|
|
24
|
+
bold: jest.fn((s: string) => s),
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
/** 取 fail 的 reason(判别联合窄化只在测试里做一次) */
|
|
28
|
+
function failReason(result: CommandResult): string {
|
|
29
|
+
if (result.kind !== 'fail' && result.kind !== 'usage-error') {
|
|
30
|
+
throw new Error(`期望 fail,实得 ${result.kind}`);
|
|
31
|
+
}
|
|
32
|
+
return result.reason;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let tempDir: string;
|
|
36
|
+
const CI = process.env.CI;
|
|
37
|
+
|
|
38
|
+
let io: CapturingIO;
|
|
39
|
+
|
|
40
|
+
/** 建一个「CAPABILITIES 已覆盖 src/」的最小项目,把漂移轴隔离到 CONTEXT.md */
|
|
41
|
+
function makeProject(name: string, contextMd: string, indexTs: string): string {
|
|
42
|
+
const projectPath = path.join(tempDir, name);
|
|
43
|
+
const modDir = path.join(projectPath, 'src', 'mod');
|
|
44
|
+
fs.mkdirSync(modDir, { recursive: true });
|
|
45
|
+
fs.writeFileSync(
|
|
46
|
+
path.join(projectPath, 'CAPABILITIES.md'),
|
|
47
|
+
'# Capabilities\n\n| 模块 | 文件 | 说明 |\n|------|------|------|\n| all | src/ | 全量记录 |\n'
|
|
48
|
+
);
|
|
49
|
+
fs.writeFileSync(path.join(modDir, 'CONTEXT.md'), contextMd);
|
|
50
|
+
fs.writeFileSync(path.join(modDir, 'index.ts'), indexTs);
|
|
51
|
+
fs.writeFileSync(
|
|
52
|
+
path.join(modDir, 'impl.ts'),
|
|
53
|
+
'export class Widget {}\nexport function createWidget() {}\nexport const WIDGET_KIND = "a";\n'
|
|
54
|
+
);
|
|
55
|
+
return projectPath;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const CLEAN_DOC = [
|
|
59
|
+
'# mod/',
|
|
60
|
+
'',
|
|
61
|
+
'## 核心导出',
|
|
62
|
+
'- `Widget` — 主体',
|
|
63
|
+
'- `createWidget` — 工厂',
|
|
64
|
+
'- `WIDGET_KIND` — 常量',
|
|
65
|
+
'',
|
|
66
|
+
'## 约定',
|
|
67
|
+
'- 无',
|
|
68
|
+
'',
|
|
69
|
+
].join('\n');
|
|
70
|
+
|
|
71
|
+
const BARREL = [
|
|
72
|
+
"export { Widget, createWidget, WIDGET_KIND } from './impl';",
|
|
73
|
+
"export type { WidgetConfig } from './impl';",
|
|
74
|
+
].join('\n');
|
|
75
|
+
|
|
76
|
+
beforeEach(() => {
|
|
77
|
+
io = captureIO();
|
|
78
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'temp-test-sync-docs-drift-'));
|
|
79
|
+
delete process.env.CI;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
afterEach(() => {
|
|
83
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
84
|
+
if (CI === undefined) delete process.env.CI;
|
|
85
|
+
else process.env.CI = CI;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('sync-docs — CONTEXT.md 内容漂移判 fail(--check)', () => {
|
|
89
|
+
it('文档与导出面一致 → ok(新闸不制造存量噪音)', async () => {
|
|
90
|
+
const projectPath = makeProject('clean', CLEAN_DOC, BARREL);
|
|
91
|
+
await expect(syncDocs({ projectPath, check: true }, io)).resolves.toEqual({ kind: 'ok' });
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('幽灵符号(代码改名不回灌文档)→ fail 并指名文件与符号', async () => {
|
|
95
|
+
const projectPath = makeProject(
|
|
96
|
+
'ghost',
|
|
97
|
+
CLEAN_DOC.replace('`Widget`', '`WidgetRenamed`'),
|
|
98
|
+
BARREL
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
const result = await syncDocs({ projectPath, check: true }, io);
|
|
102
|
+
|
|
103
|
+
expect(failReason(result)).toContain('src/mod/CONTEXT.md');
|
|
104
|
+
expect(failReason(result)).toContain('WidgetRenamed');
|
|
105
|
+
expect(io.outText()).toContain('WidgetRenamed');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('barrel 未跟着改名的虚再导出不洗白幽灵(正本改名即撞)', async () => {
|
|
109
|
+
const projectPath = makeProject('ghost-barrel', CLEAN_DOC, BARREL);
|
|
110
|
+
// 只改声明侧(Widget → WidgetSink),index.ts 的再导出与文档都不动
|
|
111
|
+
fs.writeFileSync(
|
|
112
|
+
path.join(projectPath, 'src', 'mod', 'impl.ts'),
|
|
113
|
+
'export class WidgetSink {}\nexport function createWidget() {}\nexport const WIDGET_KIND = "a";\n'
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const result = await syncDocs({ projectPath, check: true }, io);
|
|
117
|
+
|
|
118
|
+
expect(failReason(result)).toContain('src/mod/CONTEXT.md');
|
|
119
|
+
expect(failReason(result)).toContain('Widget');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('barrel 新增值符号未登记 → fail 并指名该符号', async () => {
|
|
123
|
+
const projectPath = makeProject(
|
|
124
|
+
'unlisted',
|
|
125
|
+
CLEAN_DOC.replace('- `WIDGET_KIND` — 常量\n', ''),
|
|
126
|
+
BARREL
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const result = await syncDocs({ projectPath, check: true }, io);
|
|
130
|
+
|
|
131
|
+
expect(failReason(result)).toContain('src/mod/CONTEXT.md');
|
|
132
|
+
expect(failReason(result)).toContain('WIDGET_KIND');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('barrel 新增类型符号 → 不要求登记(类型面豁免)', async () => {
|
|
136
|
+
const projectPath = makeProject(
|
|
137
|
+
'type-only',
|
|
138
|
+
CLEAN_DOC,
|
|
139
|
+
[BARREL, "export { type ExtraShape } from './impl';"].join('\n')
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
await expect(syncDocs({ projectPath, check: true }, io)).resolves.toEqual({ kind: 'ok' });
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('无 index.ts 的目录跳过覆盖方向(内部导出不要求登记)', async () => {
|
|
146
|
+
const projectPath = makeProject('no-barrel', CLEAN_DOC, BARREL);
|
|
147
|
+
fs.rmSync(path.join(projectPath, 'src', 'mod', 'index.ts'));
|
|
148
|
+
|
|
149
|
+
await expect(syncDocs({ projectPath, check: true }, io)).resolves.toEqual({ kind: 'ok' });
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('sync-docs — mtime 判定降级为提示', () => {
|
|
154
|
+
/** 只把源码时间戳推到 CONTEXT.md 之后,内容一字不改 */
|
|
155
|
+
function touchSourceLater(projectPath: string): void {
|
|
156
|
+
const contextPath = path.join(projectPath, 'src', 'mod', 'CONTEXT.md');
|
|
157
|
+
const contextMtime = new Date(Date.now() - 60_000);
|
|
158
|
+
fs.utimesSync(contextPath, contextMtime, contextMtime);
|
|
159
|
+
const impl = path.join(projectPath, 'src', 'mod', 'impl.ts');
|
|
160
|
+
const later = new Date();
|
|
161
|
+
fs.utimesSync(impl, later, later);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
it('mtime 漂移不再判 fail,只在本地给提示', async () => {
|
|
165
|
+
const projectPath = makeProject('mtime', CLEAN_DOC, BARREL);
|
|
166
|
+
touchSourceLater(projectPath);
|
|
167
|
+
|
|
168
|
+
await expect(syncDocs({ projectPath, check: true }, io)).resolves.toEqual({ kind: 'ok' });
|
|
169
|
+
expect(io.outText()).toContain('源码比文档新');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('CI 环境下 mtime 提示抑制(全新 checkout 的 mtime 无意义)', async () => {
|
|
173
|
+
const projectPath = makeProject('mtime-ci', CLEAN_DOC, BARREL);
|
|
174
|
+
touchSourceLater(projectPath);
|
|
175
|
+
process.env.CI = 'true';
|
|
176
|
+
|
|
177
|
+
await expect(syncDocs({ projectPath, check: true }, io)).resolves.toEqual({ kind: 'ok' });
|
|
178
|
+
expect(io.outText()).not.toContain('源码比文档新');
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('内容漂移在 CI 环境下照样 fail', async () => {
|
|
182
|
+
const projectPath = makeProject('content-ci', CLEAN_DOC.replace('`Widget`', '`Gone`'), BARREL);
|
|
183
|
+
process.env.CI = 'true';
|
|
184
|
+
|
|
185
|
+
const result = await syncDocs({ projectPath, check: true }, io);
|
|
186
|
+
expect(failReason(result)).toContain('Gone');
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('sync-docs — --json 与写入模式', () => {
|
|
191
|
+
it('--json 输出 contentDrift(dir/file/ghosts/unlisted)', async () => {
|
|
192
|
+
const projectPath = makeProject(
|
|
193
|
+
'json',
|
|
194
|
+
CLEAN_DOC.replace('- `WIDGET_KIND` — 常量\n', '').replace('`Widget`', '`Ghost`'),
|
|
195
|
+
BARREL
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
await syncDocs({ projectPath, check: true, json: true }, io);
|
|
199
|
+
|
|
200
|
+
const payload = JSON.parse(io.outText());
|
|
201
|
+
expect(payload.stale).toBe(true);
|
|
202
|
+
expect(payload.summary.contextContentDrift).toBe(1);
|
|
203
|
+
expect(payload.contentDrift).toEqual([
|
|
204
|
+
{
|
|
205
|
+
dir: 'src/mod',
|
|
206
|
+
file: 'src/mod/CONTEXT.md',
|
|
207
|
+
ghosts: ['Ghost'],
|
|
208
|
+
unlisted: ['Widget', 'WIDGET_KIND'],
|
|
209
|
+
},
|
|
210
|
+
]);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it('--json 干净时 contentDrift 为空数组', async () => {
|
|
214
|
+
const projectPath = makeProject('json-clean', CLEAN_DOC, BARREL);
|
|
215
|
+
|
|
216
|
+
await syncDocs({ projectPath, check: true, json: true }, io);
|
|
217
|
+
|
|
218
|
+
expect(JSON.parse(io.outText()).contentDrift).toEqual([]);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('写入模式给提示但不改 CONTEXT.md、退出码面不变', async () => {
|
|
222
|
+
const projectPath = makeProject('write', CLEAN_DOC.replace('`Widget`', '`Ghost`'), BARREL);
|
|
223
|
+
const contextPath = path.join(projectPath, 'src', 'mod', 'CONTEXT.md');
|
|
224
|
+
const before = fs.readFileSync(contextPath, 'utf-8');
|
|
225
|
+
|
|
226
|
+
const result = await syncDocs({ projectPath }, io);
|
|
227
|
+
|
|
228
|
+
expect(result.kind).toBe('ok');
|
|
229
|
+
expect(io.outText()).toContain('Ghost');
|
|
230
|
+
expect(fs.readFileSync(contextPath, 'utf-8')).toBe(before);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sync-docs 生成的模块清单顺序冻结(#147 B 票)
|
|
3
|
+
*
|
|
4
|
+
* `sync-docs` 写出的 CAPABILITIES.md 模块表格行序 = 源码目录遍历序,这个顺序此前
|
|
5
|
+
* **无任何测试覆盖**,而它对外可见(`--check` 逐行比对、人工看 diff)。#147 把描述
|
|
6
|
+
* 提取从串行改并发,票面裁决「输出顺序逐字保持现状」,本文件就是那条裁决的闸。
|
|
7
|
+
*
|
|
8
|
+
* 不写死字面顺序:`readdir` 的返回顺序由文件系统决定(本仓 tmpfs 上是字典序、ext4 上
|
|
9
|
+
* 是哈希序),写死等于把断言建立在机器上。这里的口径是**目录遍历序**本身——用测试内
|
|
10
|
+
* 独立推导的遍历序(`readdirSync` + 同一份跳过口径)作对照,另加两次运行的自复现,
|
|
11
|
+
* 任何「按并发完成顺序 append」「改成字典序」「子目录结果挪到末尾」都会撞红。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import * as fs from 'fs';
|
|
15
|
+
import * as os from 'os';
|
|
16
|
+
import * as path from 'path';
|
|
17
|
+
import { syncDocs } from '../sync-docs';
|
|
18
|
+
import { scanSourceModules } from '../sync-docs/project-reader';
|
|
19
|
+
import { captureIO } from '../../command-contract';
|
|
20
|
+
import { DEFAULT_SKIP_DIRS, isTsSourceFile } from '../../../utils/file-walk';
|
|
21
|
+
|
|
22
|
+
let tempDir: string;
|
|
23
|
+
const io = captureIO();
|
|
24
|
+
|
|
25
|
+
function write(rel: string, content: string): void {
|
|
26
|
+
const target = path.join(tempDir, rel);
|
|
27
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
28
|
+
fs.writeFileSync(target, content, 'utf-8');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** 口径对照:目录遍历序 = readdir 序,子目录结果就地展开在父条目所在位置 */
|
|
32
|
+
function traversalOrder(dir: string, root: string): string[] {
|
|
33
|
+
const out: string[] = [];
|
|
34
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
35
|
+
if (DEFAULT_SKIP_DIRS.includes(entry)) continue;
|
|
36
|
+
const entryPath = path.join(dir, entry);
|
|
37
|
+
if (fs.statSync(entryPath).isDirectory()) {
|
|
38
|
+
out.push(...traversalOrder(entryPath, root));
|
|
39
|
+
} else if (isTsSourceFile(entry, { skipIndex: true, includeTsx: true })) {
|
|
40
|
+
out.push(path.relative(root, entryPath));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 生成后的 CAPABILITIES.md 表格行序(文件列) */
|
|
47
|
+
function tableRows(capabilitiesPath: string): string[] {
|
|
48
|
+
return fs
|
|
49
|
+
.readFileSync(capabilitiesPath, 'utf-8')
|
|
50
|
+
.split('\n')
|
|
51
|
+
.filter((line) => /^\|[^|]+\|[^|]+\.tsx?\s*\|[^|]+\|\s*$/.test(line))
|
|
52
|
+
.map((line) => line.split('|')[2].trim());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
beforeAll(() => {
|
|
56
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sd147-module-order-'));
|
|
57
|
+
// 一个子目录恰好排在两份顶层文件之间(顺序若被重排,这里最容易露馅)
|
|
58
|
+
write('src/alpha.ts', '// 描述-甲\nexport const a = 1;\n');
|
|
59
|
+
write('src/mid/beta.ts', '/**\n * 描述-乙\n */\nexport const b = 1;\n');
|
|
60
|
+
write('src/mid/gamma.ts', '// 描述-丙\nexport const c = 1;\n');
|
|
61
|
+
write('src/zeta.ts', '// 描述-丁\nexport const d = 1;\n');
|
|
62
|
+
// 同一条规则下的旁支:barrel 与 .d.ts 不进清单
|
|
63
|
+
write('src/index.ts', 'export * from "./alpha";\n');
|
|
64
|
+
write('src/ambient.d.ts', 'export const t = 1;\n');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
afterAll(() => {
|
|
68
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('sync-docs 模块清单顺序冻结(#147)', () => {
|
|
72
|
+
it('扫描产出的清单顺序 = 目录遍历序,且描述与文件配对不串位', async () => {
|
|
73
|
+
const modules = await scanSourceModules(path.join(tempDir, 'src'), tempDir);
|
|
74
|
+
const expected = traversalOrder(path.join(tempDir, 'src'), tempDir);
|
|
75
|
+
|
|
76
|
+
expect(modules.map((m) => m.file)).toEqual(expected);
|
|
77
|
+
// 并发取数后每条描述仍是自己那份文件的(回填按原索引,不按完成先后)
|
|
78
|
+
expect(modules.map((m) => `${m.file}=${m.description}`).sort()).toEqual(
|
|
79
|
+
[
|
|
80
|
+
'src/alpha.ts=描述-甲',
|
|
81
|
+
'src/mid/beta.ts=描述-乙',
|
|
82
|
+
'src/mid/gamma.ts=描述-丙',
|
|
83
|
+
'src/zeta.ts=描述-丁',
|
|
84
|
+
].sort()
|
|
85
|
+
);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('写出的 CAPABILITIES.md 行序 = 同一次扫描的清单顺序(对外可见面被锁住)', async () => {
|
|
89
|
+
const capPath = path.join(tempDir, 'CAPABILITIES.md');
|
|
90
|
+
expect(fs.existsSync(capPath)).toBe(false);
|
|
91
|
+
|
|
92
|
+
await syncDocs({ projectPath: tempDir }, io);
|
|
93
|
+
|
|
94
|
+
expect(tableRows(capPath)).toEqual(traversalOrder(path.join(tempDir, 'src'), tempDir));
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('同一次生成的清单顺序两次运行逐字复现(并发不引入运行间抖动)', async () => {
|
|
98
|
+
const capPath = path.join(tempDir, 'CAPABILITIES.md');
|
|
99
|
+
|
|
100
|
+
fs.rmSync(capPath, { force: true });
|
|
101
|
+
await syncDocs({ projectPath: tempDir }, io);
|
|
102
|
+
const first = tableRows(capPath);
|
|
103
|
+
expect(first.length).toBe(4);
|
|
104
|
+
|
|
105
|
+
fs.rmSync(capPath, { force: true });
|
|
106
|
+
await syncDocs({ projectPath: tempDir }, io);
|
|
107
|
+
|
|
108
|
+
expect(tableRows(capPath)).toEqual(first);
|
|
109
|
+
fs.rmSync(capPath, { force: true });
|
|
110
|
+
});
|
|
111
|
+
});
|