@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
|
@@ -50,12 +50,6 @@ jest.mock('chalk', () => ({
|
|
|
50
50
|
bold: jest.fn((str: string) => str),
|
|
51
51
|
}));
|
|
52
52
|
|
|
53
|
-
// Mock validate module
|
|
54
|
-
jest.mock('../validate', () => ({
|
|
55
|
-
createExampleCheckpoint: jest.fn(),
|
|
56
|
-
createExampleResolutions: jest.fn(),
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
53
|
const mockFs = fs as jest.Mocked<typeof fs>;
|
|
60
54
|
|
|
61
55
|
// Use explicit projectPath to avoid CI path mismatch
|
|
@@ -193,6 +187,59 @@ describe('init command', () => {
|
|
|
193
187
|
expect(io2.outText()).toContain(line);
|
|
194
188
|
}
|
|
195
189
|
});
|
|
190
|
+
|
|
191
|
+
it('应该创建 pre-push hook(第 9 站点,#144)并带可执行位', async () => {
|
|
192
|
+
mockFs.mkdir.mockResolvedValue(undefined);
|
|
193
|
+
mockFs.writeFile.mockResolvedValue(undefined);
|
|
194
|
+
mockFs.chmod.mockResolvedValue(undefined);
|
|
195
|
+
existingFiles.add(`${PROJECT}/.git`);
|
|
196
|
+
existingFiles.add(`${PROJECT}/.git/hooks`);
|
|
197
|
+
|
|
198
|
+
await init({ preset: 'standard', projectPath: PROJECT }, io);
|
|
199
|
+
|
|
200
|
+
expect(io.outText()).toContain('已创建 .git/hooks/pre-push');
|
|
201
|
+
expect(mockFs.chmod).toHaveBeenCalledWith(
|
|
202
|
+
`${PROJECT}/.git/hooks/pre-push`,
|
|
203
|
+
0o755,
|
|
204
|
+
);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('pre-push 落盘正文 = 整仓全量兜底:check 不带 --staged + validate,scoped 包名(#144/#36)', async () => {
|
|
208
|
+
mockFs.mkdir.mockResolvedValue(undefined);
|
|
209
|
+
mockFs.writeFile.mockResolvedValue(undefined);
|
|
210
|
+
existingFiles.add(`${PROJECT}/.git`);
|
|
211
|
+
existingFiles.add(`${PROJECT}/.git/hooks`);
|
|
212
|
+
|
|
213
|
+
await init({ preset: 'standard', projectPath: PROJECT }, io);
|
|
214
|
+
const call = mockFs.writeFile.mock.calls.find((c: any[]) => String(c[0]).includes('pre-push'));
|
|
215
|
+
expect(call).toBeDefined();
|
|
216
|
+
const body = String(call![1]);
|
|
217
|
+
|
|
218
|
+
expect(body).toContain('npx @dommaker/harness check');
|
|
219
|
+
expect(body).not.toContain('check --staged');
|
|
220
|
+
expect(body).toContain('npx @dommaker/harness validate');
|
|
221
|
+
expect(body).not.toMatch(/npx harness /);
|
|
222
|
+
// 任一失败即非零退出挡住 push
|
|
223
|
+
expect(body.match(/\n {2}exit 1\n/g)?.length).toBe(2);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it('pre-push 已存在时告知并打印同源片段(#144 + #103)', async () => {
|
|
227
|
+
mockFs.mkdir.mockResolvedValue(undefined);
|
|
228
|
+
mockFs.writeFile.mockResolvedValue(undefined);
|
|
229
|
+
existingFiles.add(`${PROJECT}/.git`);
|
|
230
|
+
existingFiles.add(`${PROJECT}/.git/hooks`);
|
|
231
|
+
existingFiles.add(`${PROJECT}/.git/hooks/pre-push`);
|
|
232
|
+
|
|
233
|
+
await init({ preset: 'standard', projectPath: PROJECT }, io);
|
|
234
|
+
expect(io.outText()).toContain('pre-push 已存在');
|
|
235
|
+
|
|
236
|
+
const written = mockFs.writeFile.mock.calls.find((c: any[]) => String(c[0]).includes('pre-push'));
|
|
237
|
+
expect(written).toBeUndefined();
|
|
238
|
+
|
|
239
|
+
const io2 = captureIO();
|
|
240
|
+
await init({ preset: 'standard', printSnippets: true }, io2);
|
|
241
|
+
expect(io2.outText()).toContain('echo "🔍 Running harness pre-push checks (whole repo)..."');
|
|
242
|
+
});
|
|
196
243
|
});
|
|
197
244
|
|
|
198
245
|
describe('GitHub Actions', () => {
|
|
@@ -221,6 +268,35 @@ describe('init command', () => {
|
|
|
221
268
|
});
|
|
222
269
|
});
|
|
223
270
|
|
|
271
|
+
describe('跳过旗帜 → plan 里没有这些站点(scaffold 不持有覆盖/跳过策略)', () => {
|
|
272
|
+
it('--no-git-hooks 与 --no-github-actions 不落任何 hook / workflow', async () => {
|
|
273
|
+
mockFs.mkdir.mockResolvedValue(undefined);
|
|
274
|
+
mockFs.writeFile.mockResolvedValue(undefined);
|
|
275
|
+
existingFiles.add(`${PROJECT}/.git`);
|
|
276
|
+
existingFiles.add(`${PROJECT}/.git/hooks`);
|
|
277
|
+
|
|
278
|
+
await init({ preset: 'standard', gitHooks: false, githubActions: false, projectPath: PROJECT }, io);
|
|
279
|
+
const writes = mockFs.writeFile.mock.calls.map((c: unknown[]) => String(c[0]));
|
|
280
|
+
expect(writes.some((w: string) => w.includes('pre-commit'))).toBe(false);
|
|
281
|
+
expect(writes.some((w: string) => w.includes('pre-push'))).toBe(false);
|
|
282
|
+
expect(writes.some((w: string) => w.includes('.github/workflows'))).toBe(false);
|
|
283
|
+
expect(io.outText()).not.toContain('未检测到 Git 仓库');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('未带跳过旗帜时两站点照常进 plan', async () => {
|
|
287
|
+
mockFs.mkdir.mockResolvedValue(undefined);
|
|
288
|
+
mockFs.writeFile.mockResolvedValue(undefined);
|
|
289
|
+
existingFiles.add(`${PROJECT}/.git`);
|
|
290
|
+
existingFiles.add(`${PROJECT}/.git/hooks`);
|
|
291
|
+
|
|
292
|
+
await init({ preset: 'standard', projectPath: PROJECT }, io);
|
|
293
|
+
const writes = mockFs.writeFile.mock.calls.map((c: unknown[]) => String(c[0]));
|
|
294
|
+
expect(writes.some((w: string) => w.includes('pre-commit'))).toBe(true);
|
|
295
|
+
expect(writes.some((w: string) => w.includes('pre-push'))).toBe(true);
|
|
296
|
+
expect(writes.some((w: string) => w.includes('harness-check.yml'))).toBe(true);
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
224
300
|
describe('CAPABILITIES.md', () => {
|
|
225
301
|
it('init 不应创建 CAPABILITIES.md(由 sync-docs 管理)', async () => {
|
|
226
302
|
mockFs.mkdir.mockResolvedValue(undefined);
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* knowledge audit --threshold 的装配面测试(harness#152)
|
|
3
|
+
*
|
|
4
|
+
* 证的是「数值旗帜从 commander 到判定」这一程,不是投影:
|
|
5
|
+
* ① 声明与运行时一致——`--threshold <n>` 恒给字符串,`knowledge.ts` 不得再靠 `as any` 躲编译期;
|
|
6
|
+
* ② 脏输入 fail-loud——非零判定 + stderr 提示,不出报告、不写盘(原先 NaN 静默关掉短内容规则);
|
|
7
|
+
* ③ 缺省与显式 '50' 逐字同果、显式 '0' 不被当「未传」兜掉。
|
|
8
|
+
* 用真 KnowledgeAudit:要证的是阈值落进判定,而非参数传到(那是 mock 入参断言的假绿)。
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
import * as os from 'os';
|
|
13
|
+
import * as path from 'path';
|
|
14
|
+
|
|
15
|
+
// Mock chalk(断言看文本,不看 ANSI)
|
|
16
|
+
jest.mock('chalk', () => ({
|
|
17
|
+
blue: jest.fn((s: string) => s),
|
|
18
|
+
bold: jest.fn((s: string) => s),
|
|
19
|
+
green: jest.fn((s: string) => s),
|
|
20
|
+
yellow: jest.fn((s: string) => s),
|
|
21
|
+
red: jest.fn((s: string) => s),
|
|
22
|
+
gray: jest.fn((s: string) => s),
|
|
23
|
+
cyan: jest.fn((s: string) => s),
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
import { captureIO, lastJsonOutput, type CapturingIO } from '../../command-contract';
|
|
27
|
+
import { FileKnowledgeStore } from '../../../knowledge/store';
|
|
28
|
+
import type { KnowledgeEntry } from '../../../knowledge/types';
|
|
29
|
+
import { knowledgeAudit } from '../knowledge';
|
|
30
|
+
|
|
31
|
+
const SRC_FILE = path.join(__dirname, '..', 'knowledge.ts');
|
|
32
|
+
const DAY = 24 * 60 * 60 * 1000;
|
|
33
|
+
const daysAgo = (n: number): string => new Date(Date.now() - n * DAY).toISOString();
|
|
34
|
+
|
|
35
|
+
/** 三条探针条目:30 / 25 字符在缺省阈值 50 下都算短,80 字符怎么都不算 */
|
|
36
|
+
const EDGE_30 = 'GUI-101';
|
|
37
|
+
const SHORT_25 = 'GUI-102';
|
|
38
|
+
const LONG_80 = 'GUI-103';
|
|
39
|
+
|
|
40
|
+
function makeEntry(id: string, content: string): KnowledgeEntry {
|
|
41
|
+
return {
|
|
42
|
+
id,
|
|
43
|
+
type: 'guideline',
|
|
44
|
+
title: `阈值探针 ${id}`,
|
|
45
|
+
content,
|
|
46
|
+
maturity: 'draft',
|
|
47
|
+
layer: 'project',
|
|
48
|
+
created: daysAgo(3),
|
|
49
|
+
lastReferenced: daysAgo(1),
|
|
50
|
+
contributors: [],
|
|
51
|
+
projects: [],
|
|
52
|
+
tags: [],
|
|
53
|
+
applicablePhases: [],
|
|
54
|
+
sourceReferences: [],
|
|
55
|
+
referencedBy: [],
|
|
56
|
+
executionResults: [],
|
|
57
|
+
consumptionMode: 'reference',
|
|
58
|
+
origin: 'agent',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function fixture(): string {
|
|
63
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'harness-k152-'));
|
|
64
|
+
const store = new FileKnowledgeStore({ baseDir: dir });
|
|
65
|
+
store.save(makeEntry(EDGE_30, 'x'.repeat(30)));
|
|
66
|
+
store.save(makeEntry(SHORT_25, 'y'.repeat(25)));
|
|
67
|
+
store.save(makeEntry(LONG_80, 'z'.repeat(80)));
|
|
68
|
+
return dir;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
let io: CapturingIO;
|
|
72
|
+
let dir: string;
|
|
73
|
+
|
|
74
|
+
beforeEach(() => {
|
|
75
|
+
io = captureIO();
|
|
76
|
+
dir = fixture();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
/** 走 --json 面取短内容命中的条目 id(判定结果的正本面) */
|
|
80
|
+
async function shortContentIds(threshold?: string): Promise<string[]> {
|
|
81
|
+
const probe = captureIO();
|
|
82
|
+
const result = await knowledgeAudit({ dir, json: true, threshold }, probe);
|
|
83
|
+
expect(result.kind).toBe('ok');
|
|
84
|
+
const report = lastJsonOutput<{ issues: { rule: string; entryId: string }[] }>(probe);
|
|
85
|
+
return report.issues.filter(i => i.rule === 'short-content').map(i => i.entryId).sort();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
describe('knowledge audit --threshold:阈值真的进判定', () => {
|
|
89
|
+
it('未传 = 缺省 50,与显式 "50" 逐字同果', async () => {
|
|
90
|
+
expect(await shortContentIds(undefined)).toEqual([EDGE_30, SHORT_25].sort());
|
|
91
|
+
expect(await shortContentIds('50')).toEqual([EDGE_30, SHORT_25].sort());
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it('"30" 生效:恰好 30 字符的条目退出短内容判定,detail 打的是阈值 30', async () => {
|
|
95
|
+
const result = await knowledgeAudit({ dir, json: true, threshold: '30' }, io);
|
|
96
|
+
expect(result.kind).toBe('ok');
|
|
97
|
+
const report = lastJsonOutput<{ issues: { rule: string; entryId: string; detail: string }[] }>(io);
|
|
98
|
+
const hits = report.issues.filter(i => i.rule === 'short-content');
|
|
99
|
+
expect(hits.map(i => i.entryId)).toEqual([SHORT_25]);
|
|
100
|
+
expect(hits[0].detail).toContain('阈值 30');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('显式 "0" 不被当「未传」兜掉:按 0 判定,一条不报(兜掉则回 50、报两条)', async () => {
|
|
104
|
+
expect(await shortContentIds('0')).toEqual([]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('阈值随入参移动:40 两条都算短,29 只剩 25 字符那条', async () => {
|
|
108
|
+
expect(await shortContentIds('40')).toEqual([EDGE_30, SHORT_25].sort());
|
|
109
|
+
expect(await shortContentIds('29')).toEqual([SHORT_25]);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('knowledge audit --threshold:脏输入 fail-loud(不再 NaN 穿透)', () => {
|
|
114
|
+
const DIRTY = ['abc', '30abc', '1e2', '0.7', '-5', '', ' ', 'NaN', 'Infinity', '0x10'];
|
|
115
|
+
|
|
116
|
+
it.each(DIRTY.map(v => [v]))('--threshold %o → usage-error + stderr 提示,stdout 零字节', async (raw) => {
|
|
117
|
+
const result = await knowledgeAudit({ dir, json: true, threshold: raw }, io);
|
|
118
|
+
expect(result).toEqual({ kind: 'usage-error', reason: expect.stringContaining('--threshold') });
|
|
119
|
+
expect(io.outText()).toBe('');
|
|
120
|
+
expect(io.errText()).toContain('阈值');
|
|
121
|
+
if (raw.trim() !== '') expect(io.errText()).toContain(raw);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('人读面同样不产出报告,且不落「阈值 NaN」这种自证异常的行', async () => {
|
|
125
|
+
const result = await knowledgeAudit({ dir, threshold: 'abc' }, io);
|
|
126
|
+
expect(result.kind).toBe('usage-error');
|
|
127
|
+
expect(io.outText()).toBe('');
|
|
128
|
+
expect(io.outText()).not.toContain('阈值 NaN');
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('脏值不写盘:审计后的索引重建随之不发生(人读路径的既有副作用)', async () => {
|
|
132
|
+
const before = fs.readdirSync(dir).sort();
|
|
133
|
+
await knowledgeAudit({ dir, threshold: 'abc' }, io);
|
|
134
|
+
expect(fs.readdirSync(dir).sort()).toEqual(before);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('knowledge audit --threshold:声明与运行时一致', () => {
|
|
139
|
+
it('knowledge.ts 零 as any(断言不得替编译器记住旗帜的实际形状)', () => {
|
|
140
|
+
const offenders = fs.readFileSync(SRC_FILE, 'utf-8')
|
|
141
|
+
.split('\n')
|
|
142
|
+
.map((line, i) => ({ line: i + 1, text: line }))
|
|
143
|
+
.filter(({ text }) => text.includes('as any'));
|
|
144
|
+
expect(offenders).toEqual([]);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -77,7 +77,7 @@ describe('飞轮指标三处同源', () => {
|
|
|
77
77
|
const projectRoot = setupKnowledgeBase();
|
|
78
78
|
const baseDir = path.join(projectRoot, '.harness', 'knowledge');
|
|
79
79
|
|
|
80
|
-
const report = new KnowledgeAudit({ baseDir }).run();
|
|
80
|
+
const report = new KnowledgeAudit(new FileKnowledgeStore({ baseDir })).run();
|
|
81
81
|
const auditDetails = report.dimensions.flywheel.details;
|
|
82
82
|
await knowledgeStats({ projectPath: projectRoot, json: true }, io);
|
|
83
83
|
const statsFlywheel = lastJsonOutput<any>(io).flywheel;
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tone 映射冻结闸(harness#151)
|
|
3
|
+
*
|
|
4
|
+
* #133 的人读侧冻成「identity chalk 之下的逐行文本基线」(`knowledge-view.test.ts:20-21`,
|
|
5
|
+
* 注释写明「人读断言看的是文本,不看 ANSI」)。代价是渲染类映射里唯一没被钉住的维度就是
|
|
6
|
+
* **颜色本身**:`grep -rn "toneForMaturity\|TONE_STYLES" src/cli/commands/__tests__` 零命中,
|
|
7
|
+
* 于是把 `toneForMaturity('verified')` 改回 `'warn'`(#133 有意偏离③ 的回退)、或把
|
|
8
|
+
* `TONE_STYLES.accent` 换成 `chalk.yellow`,全仓零红。本文件把那两张表逐格钉住,且不经 identity mock:
|
|
9
|
+
*
|
|
10
|
+
* 1. **输入值 → tone**:`toneForMaturity` / `toneForSeverity` / `toneForScore` 每个键一格。
|
|
11
|
+
* 2. **tone → chalk 样式键**:`TONE_STYLES` 每个档位一格。chalk 替身按样式键给文本加标签,
|
|
12
|
+
* 断言走 `renderDisplayModel` / `announce` 的真实渲染链(`{cells:[{tone}]}` → 上色),
|
|
13
|
+
* 不是只读表——表读得到、链断了也算漏。
|
|
14
|
+
* 3. **表键集合穷尽**:本文件的登记表与源码里的 `DisplayTone` 联合、`TONE_STYLES` 字面量
|
|
15
|
+
* 逐字对撞。新增档位不登记即红(编译期 `Record<…, …>` 与运行期集合对撞双钉)。
|
|
16
|
+
*
|
|
17
|
+
* 生产侧零改动:`TONE_STYLES` 保持模块内私有——本闸要钉的是它的行为(经渲染链)与它的
|
|
18
|
+
* 声明形状(源码对撞),不是它的可访问性。导出它会动 `knowledge-view.ts` 的公开面。
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import * as fs from 'fs';
|
|
22
|
+
import * as path from 'path';
|
|
23
|
+
|
|
24
|
+
// chalk 替身:每个样式键把文本包成 "<key>文本</key>",「这一格走了哪个样式」由此成为可断言的文本。
|
|
25
|
+
// 与 knowledge-view.test.ts 的 identity mock 相反——那份为的是读文案,这份为的是读颜色。
|
|
26
|
+
jest.mock('chalk', () => {
|
|
27
|
+
const tag = (key: string) => (text: string): string => `<${key}>${String(text)}</${key}>`;
|
|
28
|
+
return {
|
|
29
|
+
blue: tag('blue'),
|
|
30
|
+
bold: tag('bold'),
|
|
31
|
+
green: tag('green'),
|
|
32
|
+
yellow: tag('yellow'),
|
|
33
|
+
red: tag('red'),
|
|
34
|
+
gray: tag('gray'),
|
|
35
|
+
cyan: tag('cyan'),
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
import { captureIO } from '../../command-contract';
|
|
40
|
+
import {
|
|
41
|
+
announce, renderDisplayModel,
|
|
42
|
+
toneForMaturity, toneForScore, toneForSeverity,
|
|
43
|
+
type DisplayCell, type DisplayModel, type DisplayTone, type SeverityName,
|
|
44
|
+
} from '../knowledge-view';
|
|
45
|
+
import type { MaturityLevel } from '../../../knowledge/types';
|
|
46
|
+
|
|
47
|
+
const VIEW_SOURCE = fs.readFileSync(path.join(__dirname, '..', 'knowledge-view.ts'), 'utf-8');
|
|
48
|
+
|
|
49
|
+
const wrap = (style: string, text: string): string => `<${style}>${text}</${style}>`;
|
|
50
|
+
|
|
51
|
+
/** 把若干格塞进单 section 单 row,走真实渲染链 */
|
|
52
|
+
function renderCells(...cells: DisplayCell[]): string[] {
|
|
53
|
+
const model: DisplayModel = { sections: [{ rows: [{ cells }] }] };
|
|
54
|
+
const io = captureIO();
|
|
55
|
+
renderDisplayModel(io, model);
|
|
56
|
+
return io.outLines();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function renderSectionTitle(title: string): string[] {
|
|
60
|
+
const io = captureIO();
|
|
61
|
+
renderDisplayModel(io, { sections: [{ title, rows: [] }] });
|
|
62
|
+
return io.outLines();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ========================================
|
|
66
|
+
// 登记表 1:tone → chalk 样式键(源码 TONE_STYLES 的测试侧镜像)
|
|
67
|
+
// ========================================
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 缺键即编译期红(`Record<DisplayTone, …>` 要求全键),另有与源码字面量的运行期对撞闸。
|
|
71
|
+
* 这张表是人读面颜色语义的唯一登记处:改色要在源码改一笔、这里改一笔,diff 即评审材料。
|
|
72
|
+
*/
|
|
73
|
+
const TONE_TO_STYLE: Record<DisplayTone, string> = {
|
|
74
|
+
heading: 'blue',
|
|
75
|
+
accent: 'cyan',
|
|
76
|
+
emph: 'bold',
|
|
77
|
+
muted: 'gray',
|
|
78
|
+
ok: 'green',
|
|
79
|
+
warn: 'yellow',
|
|
80
|
+
error: 'red',
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const TONE_KEYS = Object.keys(TONE_TO_STYLE) as DisplayTone[];
|
|
84
|
+
|
|
85
|
+
/** 源码里 `export type DisplayTone = 'a' | 'b' | …` 的成员清单 */
|
|
86
|
+
function declaredTones(): string[] {
|
|
87
|
+
const decl = /export type DisplayTone =([^;]+);/.exec(VIEW_SOURCE);
|
|
88
|
+
if (!decl) {
|
|
89
|
+
throw new Error('源码里找不到 DisplayTone 声明——本闸的穷尽判据随之失效,去看一眼 knowledge-view.ts');
|
|
90
|
+
}
|
|
91
|
+
return [...decl[1].matchAll(/'([^']+)'/g)].map(m => m[1]);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** 源码里 `TONE_STYLES` 字面量的 `{ tone: chalk.<style> }` 条目 */
|
|
95
|
+
function declaredToneStyles(): Array<{ tone: string; style: string }> {
|
|
96
|
+
const start = VIEW_SOURCE.indexOf('const TONE_STYLES');
|
|
97
|
+
if (start < 0) {
|
|
98
|
+
throw new Error('源码里找不到 TONE_STYLES——上色单表被搬走或改名,本闸需要跟着搬家');
|
|
99
|
+
}
|
|
100
|
+
const end = VIEW_SOURCE.indexOf('\n};', start);
|
|
101
|
+
const entries = [...VIEW_SOURCE.slice(start, end).matchAll(/^\s*(\w+):\s*chalk\.(\w+),$/gm)]
|
|
102
|
+
.map(m => ({ tone: m[1], style: m[2] }));
|
|
103
|
+
if (entries.length === 0) throw new Error('TONE_STYLES 里解析不出任何条目——正则与源码形状脱节');
|
|
104
|
+
return entries;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// ========================================
|
|
108
|
+
// 登记表 2:输入值 → tone(三张映射表的测试侧镜像)
|
|
109
|
+
// ========================================
|
|
110
|
+
|
|
111
|
+
/** 成熟度→角色:Record 全键,`MaturityLevel` 新增成员不登记即编译期红 */
|
|
112
|
+
const MATURITY_TO_TONE: Record<MaturityLevel, DisplayTone> = {
|
|
113
|
+
draft: 'warn',
|
|
114
|
+
verified: 'accent', // #133 有意偏离③:stats 人读面由此格决定是青不是黄
|
|
115
|
+
proven: 'ok',
|
|
116
|
+
archived: 'muted',
|
|
117
|
+
active: 'warn',
|
|
118
|
+
deprecated: 'warn',
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/** severity→角色:审计条目的 critical/high/medium/low 与 health 问题的 error/warn/info 共用一张表 */
|
|
122
|
+
const SEVERITY_TO_TONE: Record<SeverityName, DisplayTone> = {
|
|
123
|
+
critical: 'error',
|
|
124
|
+
high: 'warn',
|
|
125
|
+
medium: 'muted',
|
|
126
|
+
low: 'muted',
|
|
127
|
+
error: 'error',
|
|
128
|
+
warn: 'warn',
|
|
129
|
+
info: 'muted',
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** 0-100 分的档位边界:≥80 / ≥60 / 其余 */
|
|
133
|
+
const SCORE_TO_TONE: Array<{ score: number; tone: DisplayTone }> = [
|
|
134
|
+
{ score: 100, tone: 'ok' },
|
|
135
|
+
{ score: 80, tone: 'ok' },
|
|
136
|
+
{ score: 79, tone: 'warn' },
|
|
137
|
+
{ score: 60, tone: 'warn' },
|
|
138
|
+
{ score: 59, tone: 'error' },
|
|
139
|
+
{ score: 0, tone: 'error' },
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
describe('输入值 → tone:三张映射逐格冻结', () => {
|
|
143
|
+
for (const [level, tone] of Object.entries(MATURITY_TO_TONE)) {
|
|
144
|
+
it(`toneForMaturity('${level}') = '${tone}'`, () => {
|
|
145
|
+
expect(toneForMaturity(level as MaturityLevel)).toBe(tone);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
for (const [severity, tone] of Object.entries(SEVERITY_TO_TONE)) {
|
|
150
|
+
it(`toneForSeverity('${severity}') = '${tone}'`, () => {
|
|
151
|
+
expect(toneForSeverity(severity as SeverityName)).toBe(tone);
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
for (const { score, tone } of SCORE_TO_TONE) {
|
|
156
|
+
it(`toneForScore(${score}) = '${tone}'`, () => {
|
|
157
|
+
expect(toneForScore(score)).toBe(tone);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
it('三张映射的输出恒在样式表键集内(不会映射出一个没人上色的 tone)', () => {
|
|
162
|
+
const produced: DisplayTone[] = [
|
|
163
|
+
...Object.keys(MATURITY_TO_TONE).map(l => toneForMaturity(l as MaturityLevel)),
|
|
164
|
+
...Object.keys(SEVERITY_TO_TONE).map(s => toneForSeverity(s as SeverityName)),
|
|
165
|
+
...SCORE_TO_TONE.map(({ score }) => toneForScore(score)),
|
|
166
|
+
];
|
|
167
|
+
for (const tone of produced) {
|
|
168
|
+
expect(TONE_TO_STYLE[tone]).toEqual(expect.any(String));
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe('tone → chalk 样式键:TONE_STYLES 逐格冻结(经真实渲染链)', () => {
|
|
174
|
+
for (const tone of TONE_KEYS) {
|
|
175
|
+
it(`${tone} 渲染走 chalk.${TONE_TO_STYLE[tone]}`, () => {
|
|
176
|
+
expect(renderCells({ label: 'X', tone })).toEqual([wrap(TONE_TO_STYLE[tone], 'X')]);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
it('未声明 tone 的格不上色:渲染链不套任何样式', () => {
|
|
181
|
+
expect(renderCells({ label: 'plain' })).toEqual(['plain']);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('section 标题恒走 emph(tone 由渲染器决定,不经格)', () => {
|
|
185
|
+
expect(renderSectionTitle(' 按成熟度:')).toEqual([wrap('bold', ' 按成熟度:')]);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('announce 缺省走 heading、显式 tone 照表,--json 下静默', () => {
|
|
189
|
+
const headingIo = captureIO();
|
|
190
|
+
announce(headingIo, false, '📊 取数中');
|
|
191
|
+
expect(headingIo.outLines()).toEqual([wrap('blue', '📊 取数中')]);
|
|
192
|
+
|
|
193
|
+
const warnIo = captureIO();
|
|
194
|
+
announce(warnIo, false, '⚠ 降级', 'warn');
|
|
195
|
+
expect(warnIo.outLines()).toEqual([wrap('yellow', '⚠ 降级')]);
|
|
196
|
+
|
|
197
|
+
const jsonIo = captureIO();
|
|
198
|
+
announce(jsonIo, true, '📊 取数中');
|
|
199
|
+
expect(jsonIo.outText()).toBe('');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('表键集合穷尽:登记表 = 源码 DisplayTone 联合 = TONE_STYLES 字面量键', () => {
|
|
203
|
+
expect(TONE_KEYS.slice().sort()).toEqual(declaredTones().sort());
|
|
204
|
+
expect(declaredToneStyles().map(e => e.tone).sort()).toEqual(TONE_KEYS.slice().sort());
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('逐格对撞:源码 TONE_STYLES 的样式键 = 登记表(源码改一格即红)', () => {
|
|
208
|
+
for (const { tone, style } of declaredToneStyles()) {
|
|
209
|
+
expect(TONE_TO_STYLE[tone as DisplayTone]).toBe(style);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 整条链(#133 偏离③ 的回退就是沿这条链发生的):输入值 → toneForXxx → 格的 tone → 渲染上色。
|
|
216
|
+
* 只钉前两张表也能抓到回退,这条钉的是「命令侧真拿它去渲染」这个用法本身。
|
|
217
|
+
*/
|
|
218
|
+
describe('两表串成一条链:输入值经映射后渲染出的样式 = 样式键表的落点', () => {
|
|
219
|
+
for (const [level, tone] of Object.entries(MATURITY_TO_TONE)) {
|
|
220
|
+
it(`成熟度 ${level} 的人读格渲染成 chalk.${TONE_TO_STYLE[tone]}`, () => {
|
|
221
|
+
const text = ` [${level}]`;
|
|
222
|
+
expect(renderCells({ label: text, tone: toneForMaturity(level as MaturityLevel) }))
|
|
223
|
+
.toEqual([wrap(TONE_TO_STYLE[tone], text)]);
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
for (const { score, tone } of SCORE_TO_TONE) {
|
|
228
|
+
it(`健康分 ${score} 的人读格渲染成 chalk.${TONE_TO_STYLE[tone]}`, () => {
|
|
229
|
+
const text = ` 健康分: ${score}/100`;
|
|
230
|
+
expect(renderCells({ label: text, tone: toneForScore(score) }))
|
|
231
|
+
.toEqual([wrap(TONE_TO_STYLE[tone], text)]);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
it('一格多 tone:同排相邻格各自上色,互不吞并', () => {
|
|
236
|
+
expect(renderCells(
|
|
237
|
+
{ label: ' [verified]', tone: toneForMaturity('verified') },
|
|
238
|
+
{ label: ' | ', tone: 'muted' },
|
|
239
|
+
{ label: '条目 K-002', tone: 'emph' },
|
|
240
|
+
)).toEqual([
|
|
241
|
+
`${wrap('cyan', ' [verified]')}${wrap('gray', ' | ')}${wrap('bold', '条目 K-002')}`,
|
|
242
|
+
]);
|
|
243
|
+
});
|
|
244
|
+
});
|