@dommaker/harness 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/bin/harness.js +17 -1
- package/dist/agents/index.d.ts +6 -2
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +6 -16
- package/dist/agents/index.js.map +1 -1
- package/dist/cli/commands/__tests__/gate-decision.d.ts +18 -0
- package/dist/cli/commands/__tests__/gate-decision.d.ts.map +1 -0
- package/dist/cli/commands/__tests__/gate-decision.js +26 -0
- package/dist/cli/commands/__tests__/gate-decision.js.map +1 -0
- package/dist/cli/commands/acceptance.d.ts.map +1 -1
- package/dist/cli/commands/acceptance.js +17 -28
- package/dist/cli/commands/acceptance.js.map +1 -1
- package/dist/cli/commands/check.d.ts +11 -3
- package/dist/cli/commands/check.d.ts.map +1 -1
- package/dist/cli/commands/check.js +26 -11
- package/dist/cli/commands/check.js.map +1 -1
- package/dist/cli/commands/command.d.ts +0 -1
- package/dist/cli/commands/command.d.ts.map +1 -1
- package/dist/cli/commands/command.js +8 -6
- package/dist/cli/commands/command.js.map +1 -1
- package/dist/cli/commands/constraints-retire.d.ts.map +1 -1
- package/dist/cli/commands/constraints-retire.js +36 -57
- package/dist/cli/commands/constraints-retire.js.map +1 -1
- package/dist/cli/commands/contract.d.ts.map +1 -1
- package/dist/cli/commands/contract.js +36 -42
- package/dist/cli/commands/contract.js.map +1 -1
- package/dist/cli/commands/definitions.d.ts +2 -0
- package/dist/cli/commands/definitions.d.ts.map +1 -1
- package/dist/cli/commands/definitions.js +11 -6
- package/dist/cli/commands/definitions.js.map +1 -1
- package/dist/cli/commands/failure.d.ts.map +1 -1
- package/dist/cli/commands/failure.js +16 -2
- package/dist/cli/commands/failure.js.map +1 -1
- package/dist/cli/commands/init.d.ts +14 -8
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +172 -364
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/knowledge-view.d.ts +90 -0
- package/dist/cli/commands/knowledge-view.d.ts.map +1 -0
- package/dist/cli/commands/knowledge-view.js +198 -0
- package/dist/cli/commands/knowledge-view.js.map +1 -0
- package/dist/cli/commands/knowledge.d.ts +137 -52
- package/dist/cli/commands/knowledge.d.ts.map +1 -1
- package/dist/cli/commands/knowledge.js +534 -400
- package/dist/cli/commands/knowledge.js.map +1 -1
- package/dist/cli/commands/passes-gate.d.ts +4 -1
- package/dist/cli/commands/passes-gate.d.ts.map +1 -1
- package/dist/cli/commands/passes-gate.js +11 -2
- package/dist/cli/commands/passes-gate.js.map +1 -1
- package/dist/cli/commands/performance.d.ts.map +1 -1
- package/dist/cli/commands/performance.js +19 -31
- package/dist/cli/commands/performance.js.map +1 -1
- package/dist/cli/commands/report.d.ts.map +1 -1
- package/dist/cli/commands/report.js +2 -1
- package/dist/cli/commands/report.js.map +1 -1
- package/dist/cli/commands/review.d.ts.map +1 -1
- package/dist/cli/commands/review.js +13 -25
- package/dist/cli/commands/review.js.map +1 -1
- package/dist/cli/commands/scaffold-templates.d.ts +73 -0
- package/dist/cli/commands/scaffold-templates.d.ts.map +1 -0
- package/dist/cli/commands/scaffold-templates.js +424 -0
- package/dist/cli/commands/scaffold-templates.js.map +1 -0
- package/dist/cli/commands/scaffold.d.ts +105 -0
- package/dist/cli/commands/scaffold.d.ts.map +1 -0
- package/dist/cli/commands/scaffold.js +263 -0
- package/dist/cli/commands/scaffold.js.map +1 -0
- package/dist/cli/commands/security.d.ts.map +1 -1
- package/dist/cli/commands/security.js +22 -24
- package/dist/cli/commands/security.js.map +1 -1
- package/dist/cli/commands/spec-baseline-check.d.ts +43 -0
- package/dist/cli/commands/spec-baseline-check.d.ts.map +1 -1
- package/dist/cli/commands/spec-baseline-check.js +109 -34
- package/dist/cli/commands/spec-baseline-check.js.map +1 -1
- package/dist/cli/commands/sync-docs/context-syncer.d.ts +21 -2
- package/dist/cli/commands/sync-docs/context-syncer.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/context-syncer.js +112 -28
- package/dist/cli/commands/sync-docs/context-syncer.js.map +1 -1
- package/dist/cli/commands/sync-docs/index.d.ts +1 -1
- package/dist/cli/commands/sync-docs/index.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/index.js +86 -27
- package/dist/cli/commands/sync-docs/index.js.map +1 -1
- package/dist/cli/commands/sync-docs/project-reader.d.ts +24 -1
- package/dist/cli/commands/sync-docs/project-reader.d.ts.map +1 -1
- package/dist/cli/commands/sync-docs/project-reader.js +33 -7
- package/dist/cli/commands/sync-docs/project-reader.js.map +1 -1
- package/dist/cli/commands/validate.d.ts +0 -16
- package/dist/cli/commands/validate.d.ts.map +1 -1
- package/dist/cli/commands/validate.js +2 -97
- package/dist/cli/commands/validate.js.map +1 -1
- package/dist/cli/gate-command.d.ts +37 -0
- package/dist/cli/gate-command.d.ts.map +1 -0
- package/dist/cli/gate-command.js +64 -0
- package/dist/cli/gate-command.js.map +1 -0
- package/dist/completion-checkers/index.d.ts +1 -1
- package/dist/completion-checkers/index.d.ts.map +1 -1
- package/dist/completion-checkers/index.js +0 -15
- package/dist/completion-checkers/index.js.map +1 -1
- package/dist/context/knowledge-injector.d.ts +4 -2
- package/dist/context/knowledge-injector.d.ts.map +1 -1
- package/dist/context/knowledge-injector.js +13 -6
- package/dist/context/knowledge-injector.js.map +1 -1
- package/dist/core/constraints/agent-prompt-renderer.js +2 -2
- package/dist/core/constraints/agent-prompt-renderer.js.map +1 -1
- package/dist/core/constraints/capabilities-reconcile.d.ts +20 -0
- package/dist/core/constraints/capabilities-reconcile.d.ts.map +1 -1
- package/dist/core/constraints/capabilities-reconcile.js +26 -4
- package/dist/core/constraints/capabilities-reconcile.js.map +1 -1
- package/dist/core/constraints/check-cache.d.ts +1 -1
- package/dist/core/constraints/check-cache.js +1 -1
- package/dist/core/constraints/checker.d.ts +8 -3
- package/dist/core/constraints/checker.d.ts.map +1 -1
- package/dist/core/constraints/checker.js +30 -19
- package/dist/core/constraints/checker.js.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts +3 -1
- package/dist/core/constraints/checkers/capability-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/capability-sync.js +17 -24
- package/dist/core/constraints/checkers/capability-sync.js.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.d.ts +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.d.ts.map +1 -1
- package/dist/core/constraints/checkers/context-doc-sync.js +9 -6
- package/dist/core/constraints/checkers/context-doc-sync.js.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.d.ts.map +1 -1
- package/dist/core/constraints/checkers/docs-freshness.js +24 -30
- package/dist/core/constraints/checkers/docs-freshness.js.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.d.ts.map +1 -1
- package/dist/core/constraints/checkers/governance-presence.js +10 -4
- package/dist/core/constraints/checkers/governance-presence.js.map +1 -1
- package/dist/core/constraints/checkers/types.d.ts +10 -6
- package/dist/core/constraints/checkers/types.d.ts.map +1 -1
- package/dist/core/constraints/checkers/types.js +7 -3
- package/dist/core/constraints/checkers/types.js.map +1 -1
- package/dist/core/constraints/context-builder.d.ts +11 -10
- package/dist/core/constraints/context-builder.d.ts.map +1 -1
- package/dist/core/constraints/context-builder.js +31 -27
- package/dist/core/constraints/context-builder.js.map +1 -1
- package/dist/core/constraints/context-reconcile.d.ts +75 -0
- package/dist/core/constraints/context-reconcile.d.ts.map +1 -0
- package/dist/core/constraints/context-reconcile.js +161 -0
- package/dist/core/constraints/context-reconcile.js.map +1 -0
- package/dist/core/constraints/doc-freshness/runner.d.ts +7 -0
- package/dist/core/constraints/doc-freshness/runner.d.ts.map +1 -1
- package/dist/core/constraints/doc-freshness/runner.js +8 -3
- package/dist/core/constraints/doc-freshness/runner.js.map +1 -1
- package/dist/core/constraints/git-evidence.js +1 -1
- package/dist/core/constraints/git-evidence.js.map +1 -1
- package/dist/core/constraints/injection-drift.d.ts +7 -2
- package/dist/core/constraints/injection-drift.d.ts.map +1 -1
- package/dist/core/constraints/injection-drift.js +13 -7
- package/dist/core/constraints/injection-drift.js.map +1 -1
- package/dist/core/constraints/run-env.d.ts +92 -0
- package/dist/core/constraints/run-env.d.ts.map +1 -0
- package/dist/core/constraints/run-env.js +175 -0
- package/dist/core/constraints/run-env.js.map +1 -0
- package/dist/core/constraints/triggers.d.ts +22 -0
- package/dist/core/constraints/triggers.d.ts.map +1 -0
- package/dist/core/constraints/triggers.js +31 -0
- package/dist/core/constraints/triggers.js.map +1 -0
- package/dist/core/effective-constraints.d.ts +13 -4
- package/dist/core/effective-constraints.d.ts.map +1 -1
- package/dist/core/effective-constraints.js +16 -6
- package/dist/core/effective-constraints.js.map +1 -1
- package/dist/core/effective-set.d.ts +8 -15
- package/dist/core/effective-set.d.ts.map +1 -1
- package/dist/core/effective-set.js +7 -12
- package/dist/core/effective-set.js.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/project-config-loader.d.ts +39 -17
- package/dist/core/project-config-loader.d.ts.map +1 -1
- package/dist/core/project-config-loader.js +51 -122
- package/dist/core/project-config-loader.js.map +1 -1
- package/dist/core/validators/check-handlers/http.d.ts +2 -2
- package/dist/core/validators/check-handlers/http.d.ts.map +1 -1
- package/dist/core/validators/check-handlers/http.js +12 -7
- package/dist/core/validators/check-handlers/http.js.map +1 -1
- package/dist/failure/classifier.d.ts +1 -1
- package/dist/failure/classifier.d.ts.map +1 -1
- package/dist/failure/classifier.js +8 -8
- package/dist/failure/classifier.js.map +1 -1
- package/dist/failure/index.d.ts +2 -1
- package/dist/failure/index.d.ts.map +1 -1
- package/dist/failure/index.js +9 -17
- package/dist/failure/index.js.map +1 -1
- package/dist/failure/recorder.d.ts +1 -1
- package/dist/failure/recorder.d.ts.map +1 -1
- package/dist/gates/checker-gate.d.ts +2 -1
- package/dist/gates/checker-gate.d.ts.map +1 -1
- package/dist/gates/checker-gate.js +3 -2
- package/dist/gates/checker-gate.js.map +1 -1
- package/dist/gates/command.d.ts +10 -4
- package/dist/gates/command.d.ts.map +1 -1
- package/dist/gates/command.js +36 -62
- package/dist/gates/command.js.map +1 -1
- package/dist/gates/contract.d.ts.map +1 -1
- package/dist/gates/contract.js +0 -4
- package/dist/gates/contract.js.map +1 -1
- package/dist/gates/definitions.d.ts +2 -1
- package/dist/gates/definitions.d.ts.map +1 -1
- package/dist/gates/definitions.js +6 -5
- package/dist/gates/definitions.js.map +1 -1
- package/dist/gates/index.d.ts +0 -4
- package/dist/gates/index.d.ts.map +1 -1
- package/dist/gates/index.js +1 -6
- package/dist/gates/index.js.map +1 -1
- package/dist/gates/performance.d.ts.map +1 -1
- package/dist/gates/performance.js +0 -4
- package/dist/gates/performance.js.map +1 -1
- package/dist/gates/runner.d.ts +1 -1
- package/dist/gates/runner.js +1 -1
- package/dist/gates/security.d.ts +1 -1
- package/dist/gates/security.d.ts.map +1 -1
- package/dist/gates/security.js +5 -6
- package/dist/gates/security.js.map +1 -1
- package/dist/gates/types.d.ts +14 -17
- package/dist/gates/types.d.ts.map +1 -1
- package/dist/gates/types.js.map +1 -1
- package/dist/hooks/bootstrap.d.ts +6 -4
- package/dist/hooks/bootstrap.d.ts.map +1 -1
- package/dist/hooks/bootstrap.js +25 -13
- package/dist/hooks/bootstrap.js.map +1 -1
- package/dist/hooks/config.d.ts +6 -2
- package/dist/hooks/config.d.ts.map +1 -1
- package/dist/hooks/config.js +5 -1
- package/dist/hooks/config.js.map +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +0 -15
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/pipeline.d.ts.map +1 -1
- package/dist/hooks/pipeline.js +2 -4
- package/dist/hooks/pipeline.js.map +1 -1
- package/dist/hooks/registry.d.ts +11 -8
- package/dist/hooks/registry.d.ts.map +1 -1
- package/dist/hooks/registry.js +22 -7
- package/dist/hooks/registry.js.map +1 -1
- package/dist/hooks/types.d.ts +23 -7
- package/dist/hooks/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/knowledge/audit-scoring.d.ts +87 -0
- package/dist/knowledge/audit-scoring.d.ts.map +1 -0
- package/dist/knowledge/audit-scoring.js +470 -0
- package/dist/knowledge/audit-scoring.js.map +1 -0
- package/dist/knowledge/audit.d.ts +11 -59
- package/dist/knowledge/audit.d.ts.map +1 -1
- package/dist/knowledge/audit.js +47 -522
- package/dist/knowledge/audit.js.map +1 -1
- package/dist/knowledge/import.d.ts.map +1 -1
- package/dist/knowledge/import.js +2 -0
- package/dist/knowledge/import.js.map +1 -1
- package/dist/knowledge/index-generator.d.ts.map +1 -1
- package/dist/knowledge/index-generator.js +4 -5
- package/dist/knowledge/index-generator.js.map +1 -1
- package/dist/knowledge/index.d.ts +3 -2
- package/dist/knowledge/index.d.ts.map +1 -1
- package/dist/knowledge/index.js +3 -16
- package/dist/knowledge/index.js.map +1 -1
- package/dist/knowledge/ingest.js +1 -1
- package/dist/knowledge/ingest.js.map +1 -1
- package/dist/knowledge/lifecycle.d.ts.map +1 -1
- package/dist/knowledge/lifecycle.js +4 -2
- package/dist/knowledge/lifecycle.js.map +1 -1
- package/dist/knowledge/migration.d.ts +3 -0
- package/dist/knowledge/migration.d.ts.map +1 -1
- package/dist/knowledge/migration.js +8 -2
- package/dist/knowledge/migration.js.map +1 -1
- package/dist/knowledge/query.d.ts +6 -0
- package/dist/knowledge/query.d.ts.map +1 -1
- package/dist/knowledge/query.js +8 -2
- package/dist/knowledge/query.js.map +1 -1
- package/dist/knowledge/reference-tracker.d.ts.map +1 -1
- package/dist/knowledge/reference-tracker.js +4 -6
- package/dist/knowledge/reference-tracker.js.map +1 -1
- package/dist/knowledge/store.d.ts +22 -16
- package/dist/knowledge/store.d.ts.map +1 -1
- package/dist/knowledge/store.js +53 -12
- package/dist/knowledge/store.js.map +1 -1
- package/dist/knowledge/tree-walker.d.ts +19 -0
- package/dist/knowledge/tree-walker.d.ts.map +1 -0
- package/dist/knowledge/tree-walker.js +30 -0
- package/dist/knowledge/tree-walker.js.map +1 -0
- package/dist/knowledge/types.d.ts +16 -0
- package/dist/knowledge/types.d.ts.map +1 -1
- package/dist/monitoring/traces.d.ts +5 -3
- package/dist/monitoring/traces.d.ts.map +1 -1
- package/dist/monitoring/traces.js +19 -5
- package/dist/monitoring/traces.js.map +1 -1
- package/dist/test-setup/jsonl-fake-fs.d.ts +30 -0
- package/dist/test-setup/jsonl-fake-fs.d.ts.map +1 -0
- package/dist/test-setup/jsonl-fake-fs.js +49 -0
- package/dist/test-setup/jsonl-fake-fs.js.map +1 -0
- package/dist/tools/index.d.ts +4 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +7 -15
- package/dist/tools/index.js.map +1 -1
- package/dist/types/checkpoint.d.ts +5 -0
- package/dist/types/checkpoint.d.ts.map +1 -1
- package/dist/types/project-config.d.ts +18 -0
- package/dist/types/project-config.d.ts.map +1 -1
- package/dist/types/trace.d.ts +13 -4
- package/dist/types/trace.d.ts.map +1 -1
- package/dist/types/trace.js +4 -3
- package/dist/types/trace.js.map +1 -1
- package/dist/utils/exec.d.ts +4 -27
- package/dist/utils/exec.d.ts.map +1 -1
- package/dist/utils/exec.js +4 -94
- package/dist/utils/exec.js.map +1 -1
- package/dist/utils/jsonl.d.ts +17 -7
- package/dist/utils/jsonl.d.ts.map +1 -1
- package/dist/utils/jsonl.js +144 -17
- package/dist/utils/jsonl.js.map +1 -1
- package/dist/utils/numeric-flag.d.ts +44 -0
- package/dist/utils/numeric-flag.d.ts.map +1 -0
- package/dist/utils/numeric-flag.js +62 -0
- package/dist/utils/numeric-flag.js.map +1 -0
- package/package.json +1 -1
- package/src/CONTEXT.md +5 -2
- package/src/__tests__/acceptance-gate.test.ts +7 -4
- package/src/__tests__/checker-extra.test.ts +3 -2
- package/src/__tests__/checker.test.ts +4 -3
- package/src/__tests__/checkpoint.test.ts +26 -9
- package/src/__tests__/context-files-resolution.test.ts +29 -15
- package/src/__tests__/contract-gate.test.ts +19 -40
- package/src/__tests__/error-classifier.test.ts +1 -1
- package/src/__tests__/exec.test.ts +45 -107
- package/src/__tests__/failure-recorder.test.ts +7 -5
- package/src/__tests__/hooks-pipeline.test.ts +34 -47
- package/src/__tests__/layering.test.ts +217 -25
- package/src/__tests__/passes-gate.test.ts +9 -4
- package/src/__tests__/performance-gate.test.ts +3 -15
- package/src/__tests__/project-config-loader-extra.test.ts +31 -57
- package/src/__tests__/project-config-loader.test.ts +6 -3
- package/src/__tests__/public-exports.test.ts +0 -1
- package/src/__tests__/public-type-surface.test.ts +5 -4
- package/src/__tests__/public-value-surface.test.ts +182 -0
- package/src/__tests__/review-gate.test.ts +4 -6
- package/src/__tests__/security-gate.test.ts +5 -20
- package/src/__tests__/skip-semantics.test.ts +5 -3
- package/src/__tests__/spec-validator.test.ts +3 -2
- package/src/__tests__/sub-barrels-explicit.test.ts +87 -0
- package/src/__tests__/test-fixture-hygiene.test.ts +53 -0
- package/src/__tests__/trace-analyzer-extra.test.ts +5 -3
- package/src/__tests__/trace-analyzer.test.ts +5 -3
- package/src/__tests__/trace-collector.test.ts +5 -3
- package/src/agents/index.ts +13 -2
- package/src/cli/__tests__/gate-command.test.ts +162 -0
- package/src/cli/commands/CONTEXT.md +29 -5
- package/src/cli/commands/__tests__/acceptance.test.ts +24 -25
- package/src/cli/commands/__tests__/bin-exit-mapping.test.ts +15 -0
- package/src/cli/commands/__tests__/check-drift.test.ts +42 -1
- package/src/cli/commands/__tests__/check-read-count.test.ts +167 -0
- package/src/cli/commands/__tests__/check-skip-output.test.ts +4 -1
- package/src/cli/commands/__tests__/check.test.ts +43 -36
- package/src/cli/commands/__tests__/command-gate-dead-options.test.ts +60 -0
- package/src/cli/commands/__tests__/command.test.ts +33 -17
- package/src/cli/commands/__tests__/constraints-retire.test.ts +52 -0
- package/src/cli/commands/__tests__/context-syncer.test.ts +141 -0
- package/src/cli/commands/__tests__/contract.test.ts +20 -20
- package/src/cli/commands/__tests__/failure.test.ts +5 -4
- package/src/cli/commands/__tests__/gate-decision.ts +30 -0
- package/src/cli/commands/__tests__/init-dead-options.test.ts +50 -0
- package/src/cli/commands/__tests__/init-governance-io.test.ts +139 -0
- package/src/cli/commands/__tests__/init-injection.test.ts +3 -3
- package/src/cli/commands/__tests__/init-ondisk.test.ts +867 -0
- package/src/cli/commands/__tests__/init.test.ts +82 -6
- package/src/cli/commands/__tests__/knowledge-audit-threshold.test.ts +146 -0
- package/src/cli/commands/__tests__/knowledge-flywheel-consistency.test.ts +1 -1
- package/src/cli/commands/__tests__/knowledge-tone-mapping.test.ts +244 -0
- package/src/cli/commands/__tests__/knowledge-view.test.ts +839 -0
- package/src/cli/commands/__tests__/knowledge.test.ts +33 -15
- package/src/cli/commands/__tests__/numeric-flag-assembly.test.ts +368 -0
- package/src/cli/commands/__tests__/performance.test.ts +19 -21
- package/src/cli/commands/__tests__/posteval-plan.test.ts +5 -3
- package/src/cli/commands/__tests__/pre-push-hook.test.ts +181 -0
- package/src/cli/commands/__tests__/project-path-anchoring.test.ts +95 -2
- package/src/cli/commands/__tests__/project-path-convention.test.ts +103 -25
- package/src/cli/commands/__tests__/registry.test.ts +2 -0
- package/src/cli/commands/__tests__/report.test.ts +23 -1
- package/src/cli/commands/__tests__/review.test.ts +10 -17
- package/src/cli/commands/__tests__/scaffold.test.ts +505 -0
- package/src/cli/commands/__tests__/security-default-scan.test.ts +75 -0
- package/src/cli/commands/__tests__/security.test.ts +21 -24
- package/src/cli/commands/__tests__/spec-baseline-check.test.ts +3 -2
- package/src/cli/commands/__tests__/spec-baseline-index-cap.test.ts +131 -0
- package/src/cli/commands/__tests__/spec-baseline-read-count.test.ts +325 -0
- package/src/cli/commands/__tests__/sync-docs-agents.test.ts +19 -4
- package/src/cli/commands/__tests__/sync-docs-context-drift.test.ts +232 -0
- package/src/cli/commands/__tests__/sync-docs-module-order.test.ts +111 -0
- package/src/cli/commands/__tests__/sync-docs-read-count.test.ts +192 -0
- package/src/cli/commands/__tests__/sync-docs.test.ts +3 -2
- package/src/cli/commands/__tests__/validate.test.ts +1 -48
- package/src/cli/commands/acceptance.ts +24 -29
- package/src/cli/commands/check.ts +40 -17
- package/src/cli/commands/command.ts +9 -8
- package/src/cli/commands/constraints-retire.ts +57 -70
- package/src/cli/commands/contract.ts +44 -47
- package/src/cli/commands/definitions.ts +12 -6
- package/src/cli/commands/failure.ts +16 -3
- package/src/cli/commands/init.ts +242 -389
- package/src/cli/commands/knowledge-view.ts +224 -0
- package/src/cli/commands/knowledge.ts +643 -448
- package/src/cli/commands/passes-gate.ts +12 -3
- package/src/cli/commands/performance.ts +31 -38
- package/src/cli/commands/report.ts +3 -2
- package/src/cli/commands/review.ts +22 -28
- package/src/cli/commands/scaffold-templates.ts +406 -0
- package/src/cli/commands/scaffold.ts +302 -0
- package/src/cli/commands/security.ts +27 -23
- package/src/cli/commands/spec-baseline-check.ts +158 -33
- package/src/cli/commands/sync-docs/__tests__/context-export-surface.test.ts +102 -0
- package/src/cli/commands/sync-docs/__tests__/module-descriptions.test.ts +196 -0
- package/src/cli/commands/sync-docs/context-syncer.ts +137 -31
- package/src/cli/commands/sync-docs/index.ts +103 -28
- package/src/cli/commands/sync-docs/project-reader.ts +51 -7
- package/src/cli/commands/validate.ts +1 -104
- package/src/cli/gate-command.ts +87 -0
- package/src/completion-checkers/index.ts +10 -1
- package/src/context/CONTEXT.md +2 -1
- package/src/context/__tests__/knowledge-injector.test.ts +27 -0
- package/src/context/__tests__/session-manager.test.ts +19 -12
- package/src/context/knowledge-injector.ts +14 -7
- package/src/core/CONTEXT.md +10 -7
- package/src/core/__tests__/effective-set.test.ts +36 -60
- package/src/core/constraints/__tests__/context-reconcile.test.ts +246 -0
- package/src/core/constraints/__tests__/run-env.test.ts +377 -0
- package/src/core/constraints/__tests__/triggers.test.ts +70 -0
- package/src/core/constraints/agent-prompt-renderer.ts +1 -1
- package/src/core/constraints/capabilities-reconcile.ts +28 -4
- package/src/core/constraints/check-cache.ts +1 -1
- package/src/core/constraints/checker.ts +30 -14
- package/src/core/constraints/checkers/__tests__/context-doc-sync.test.ts +8 -3
- package/src/core/constraints/checkers/__tests__/governance-presence.test.ts +16 -7
- package/src/core/constraints/checkers/__tests__/no-hardcoded-credentials.test.ts +2 -1
- package/src/core/constraints/checkers/capability-sync.ts +27 -28
- package/src/core/constraints/checkers/context-doc-sync.ts +9 -7
- package/src/core/constraints/checkers/docs-freshness.ts +28 -33
- package/src/core/constraints/checkers/governance-presence.ts +10 -6
- package/src/core/constraints/checkers/types.ts +14 -8
- package/src/core/constraints/context-builder.ts +35 -26
- package/src/core/constraints/context-reconcile.ts +200 -0
- package/src/core/constraints/doc-freshness/__tests__/runner.test.ts +25 -0
- package/src/core/constraints/doc-freshness/runner.ts +18 -4
- package/src/core/constraints/git-evidence.ts +1 -1
- package/src/core/constraints/injection-drift.ts +19 -8
- package/src/core/constraints/run-env.ts +207 -0
- package/src/core/constraints/triggers.ts +33 -0
- package/src/core/effective-constraints.ts +17 -6
- package/src/core/effective-set.ts +8 -24
- package/src/core/index.ts +2 -0
- package/src/core/project-config-loader.ts +54 -102
- package/src/core/validators/__tests__/http-retry-sleep.test.ts +231 -0
- package/src/core/validators/check-handlers/http.ts +18 -7
- package/src/failure/CONTEXT.md +2 -1
- package/src/failure/classifier.ts +2 -2
- package/src/failure/index.ts +14 -2
- package/src/failure/recorder.ts +1 -1
- package/src/gates/CONTEXT.md +13 -7
- package/src/gates/__tests__/checker-gate.test.ts +1 -1
- package/src/gates/__tests__/command-single-predicate.test.ts +135 -0
- package/src/gates/__tests__/command.test.ts +8 -15
- package/src/gates/__tests__/contract.test.ts +5 -5
- package/src/gates/__tests__/gate-interface.test.ts +0 -17
- package/src/gates/__tests__/performance.test.ts +0 -13
- package/src/gates/__tests__/review.test.ts +0 -1
- package/src/gates/__tests__/runner.test.ts +1 -1
- package/src/gates/__tests__/security-default-scan.test.ts +97 -0
- package/src/gates/__tests__/security.test.ts +0 -13
- package/src/gates/checker-gate.ts +3 -2
- package/src/gates/command.ts +51 -74
- package/src/gates/contract.ts +0 -5
- package/src/gates/definitions.ts +6 -5
- package/src/gates/index.ts +0 -5
- package/src/gates/performance.ts +1 -6
- package/src/gates/runner.ts +1 -1
- package/src/gates/security.ts +9 -11
- package/src/gates/types.ts +20 -23
- package/src/hooks/CONTEXT.md +10 -9
- package/src/hooks/__tests__/bootstrap.test.ts +29 -6
- package/src/hooks/__tests__/pipeline.test.ts +28 -17
- package/src/hooks/__tests__/registry.test.ts +51 -3
- package/src/hooks/bootstrap.ts +35 -15
- package/src/hooks/config.ts +6 -2
- package/src/hooks/index.ts +10 -1
- package/src/hooks/pipeline.ts +4 -6
- package/src/hooks/registry.ts +31 -12
- package/src/hooks/types.ts +24 -7
- package/src/index.ts +1 -2
- package/src/knowledge/CONTEXT.md +14 -7
- package/src/knowledge/__tests__/audit-labels.test.ts +8 -5
- package/src/knowledge/__tests__/audit-scoring.test.ts +230 -0
- package/src/knowledge/__tests__/audit-write-count.test.ts +131 -0
- package/src/knowledge/__tests__/audit.test.ts +291 -208
- package/src/knowledge/__tests__/doctor.test.ts +3 -2
- package/src/knowledge/__tests__/ingest.test.ts +3 -2
- package/src/knowledge/__tests__/lifecycle.test.ts +57 -2
- package/src/knowledge/__tests__/migration.test.ts +35 -6
- package/src/knowledge/__tests__/query.test.ts +3 -2
- package/src/knowledge/__tests__/reference-tracker.test.ts +23 -2
- package/src/knowledge/__tests__/store.test.ts +149 -4
- package/src/knowledge/__tests__/tree-walker.test.ts +132 -0
- package/src/knowledge/audit-scoring.ts +589 -0
- package/src/knowledge/audit.ts +55 -599
- package/src/knowledge/import.ts +2 -0
- package/src/knowledge/index-generator.ts +4 -6
- package/src/knowledge/index.ts +27 -2
- package/src/knowledge/ingest.ts +1 -1
- package/src/knowledge/lifecycle.ts +5 -2
- package/src/knowledge/migration.ts +8 -2
- package/src/knowledge/query.ts +8 -1
- package/src/knowledge/reference-tracker.ts +5 -7
- package/src/knowledge/store.ts +75 -16
- package/src/knowledge/tree-walker.ts +29 -0
- package/src/knowledge/types.ts +19 -0
- package/src/monitoring/CONTEXT.md +5 -2
- package/src/monitoring/__tests__/context-tracker.test.ts +16 -8
- package/src/monitoring/__tests__/trace-file-anchoring.test.ts +80 -0
- package/src/monitoring/traces.ts +19 -5
- package/src/release/CONTEXT.md +1 -1
- package/src/release/__tests__/integrity.test.ts +21 -12
- package/src/test-setup/__tests__/jsonl-fake-fs.test.ts +98 -0
- package/src/test-setup/jsonl-fake-fs.ts +59 -0
- package/src/tools/index.ts +5 -1
- package/src/types/checkpoint.ts +6 -0
- package/src/types/project-config.ts +21 -0
- package/src/types/trace.ts +14 -4
- package/src/utils/__tests__/file-walk.test.ts +3 -2
- package/src/utils/__tests__/jsonl-bounded-read.test.ts +106 -0
- package/src/utils/__tests__/jsonl-skip-disposition.test.ts +10 -6
- package/src/utils/__tests__/jsonl.test.ts +61 -14
- package/src/utils/__tests__/numeric-flag.test.ts +80 -0
- package/src/utils/__tests__/package-version.test.ts +2 -2
- package/src/utils/exec.ts +4 -64
- package/src/utils/jsonl.ts +159 -20
- package/src/utils/numeric-flag.ts +64 -0
- package/dist/failure/types.d.ts +0 -9
- package/dist/failure/types.d.ts.map +0 -1
- package/dist/failure/types.js +0 -25
- package/dist/failure/types.js.map +0 -1
- package/dist/gates/effective-gates.d.ts +0 -30
- package/dist/gates/effective-gates.d.ts.map +0 -1
- package/dist/gates/effective-gates.js +0 -81
- package/dist/gates/effective-gates.js.map +0 -1
- package/src/failure/types.ts +0 -9
- package/src/gates/__tests__/effective-gates.test.ts +0 -77
- package/src/gates/effective-gates.ts +0 -99
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* scaffold 模块测试(harness#132,架构评审候选3)
|
|
3
|
+
*
|
|
4
|
+
* 覆盖三件事:
|
|
5
|
+
* 1. 三态判定(created / exists / manual)的形状——判定、建目录、上色、片段打印
|
|
6
|
+
* 全在实现内,测试注入内存 fs 替身,零真实文件系统。
|
|
7
|
+
* 2. 9 站点(init 7 + validate 2)的对外文案逐字冻结:新增站点的每一行按同一形状
|
|
8
|
+
* 冻结(pre-push 是 harness#144 加的第 9 处),其余站点改前后用户看到的都一样。
|
|
9
|
+
* 3. 「打印给用户的片段 == 真正落盘的内容」同源不变量(#103 判据)的单点断言。
|
|
10
|
+
* 4. CI 站点的平台维度(harness#143):同一站点在 github / gitlab 两形下各自的
|
|
11
|
+
* 目标路径、三态文案与冲突片段。
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import * as path from 'path';
|
|
15
|
+
import * as yaml from 'js-yaml';
|
|
16
|
+
import chalk from 'chalk';
|
|
17
|
+
import { captureIO, type CapturingIO } from '../../command-contract';
|
|
18
|
+
import {
|
|
19
|
+
GITHUB_ACTIONS_SNIPPET,
|
|
20
|
+
GITLAB_CI_SNIPPET,
|
|
21
|
+
HARNESS_CHECK_WORKFLOW,
|
|
22
|
+
} from '../scaffold-templates';
|
|
23
|
+
import {
|
|
24
|
+
writeManagedFile,
|
|
25
|
+
runPlan,
|
|
26
|
+
preCommitHookFile,
|
|
27
|
+
prePushHookFile,
|
|
28
|
+
harnessCheckCiFile,
|
|
29
|
+
customConstraintsFile,
|
|
30
|
+
changelogFile,
|
|
31
|
+
contextDocFile,
|
|
32
|
+
governanceWorkflowFile,
|
|
33
|
+
checkpointsFile,
|
|
34
|
+
resolutionsFile,
|
|
35
|
+
type ManagedFile,
|
|
36
|
+
type ScaffoldFileSystem,
|
|
37
|
+
} from '../scaffold';
|
|
38
|
+
|
|
39
|
+
jest.mock('chalk', () => ({
|
|
40
|
+
blue: jest.fn((s: string) => s),
|
|
41
|
+
yellow: jest.fn((s: string) => s),
|
|
42
|
+
green: jest.fn((s: string) => s),
|
|
43
|
+
gray: jest.fn((s: string) => s),
|
|
44
|
+
red: jest.fn((s: string) => s),
|
|
45
|
+
cyan: jest.fn((s: string) => s),
|
|
46
|
+
bold: jest.fn((s: string) => s),
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
/** 内存 fs 替身:写盘内容、建过的目录、权限位全部可断言 */
|
|
50
|
+
class MemoryFs implements ScaffoldFileSystem {
|
|
51
|
+
readonly files = new Map<string, string>();
|
|
52
|
+
readonly dirs: string[] = [];
|
|
53
|
+
readonly modes = new Map<string, number>();
|
|
54
|
+
|
|
55
|
+
seed(target: string, content: string): void {
|
|
56
|
+
this.files.set(target, content);
|
|
57
|
+
}
|
|
58
|
+
async exists(target: string): Promise<boolean> {
|
|
59
|
+
return this.files.has(target);
|
|
60
|
+
}
|
|
61
|
+
async mkdir(dir: string): Promise<void> {
|
|
62
|
+
this.dirs.push(dir);
|
|
63
|
+
}
|
|
64
|
+
async writeFile(target: string, content: string): Promise<void> {
|
|
65
|
+
this.files.set(target, content);
|
|
66
|
+
}
|
|
67
|
+
async chmod(target: string, mode: number): Promise<void> {
|
|
68
|
+
this.modes.set(target, mode);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const PROJECT = '/srv/project';
|
|
73
|
+
const USER_CONTENT = '用户自己的内容,不许覆盖\n';
|
|
74
|
+
|
|
75
|
+
/** 全部 9 站点,顺序 = init 的落盘顺序 */
|
|
76
|
+
function allSites(): ManagedFile[] {
|
|
77
|
+
return [
|
|
78
|
+
checkpointsFile(PROJECT),
|
|
79
|
+
resolutionsFile(PROJECT),
|
|
80
|
+
customConstraintsFile(PROJECT),
|
|
81
|
+
preCommitHookFile(PROJECT),
|
|
82
|
+
prePushHookFile(PROJECT),
|
|
83
|
+
harnessCheckCiFile(PROJECT, 'github', ['ci.yml']),
|
|
84
|
+
changelogFile(PROJECT, 'keep-a-changelog'),
|
|
85
|
+
contextDocFile(PROJECT, 'src'),
|
|
86
|
+
governanceWorkflowFile(PROJECT, 'standard'),
|
|
87
|
+
];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** stdout 每次写入的文本(去掉 log 补的换行,空行即为 '') */
|
|
91
|
+
function printed(io: CapturingIO): string[] {
|
|
92
|
+
return io.outRecords().map(chunk => chunk.replace(/\n$/, ''));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function mergeOf(file: ManagedFile): Extract<ManagedFile['onPresent'], { outcome: 'merge' }> {
|
|
96
|
+
if (file.onPresent.outcome !== 'merge') throw new Error(`${file.target} 不是 merge 站点`);
|
|
97
|
+
return file.onPresent;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function noticeOf(file: ManagedFile): string {
|
|
101
|
+
if (file.onPresent.outcome !== 'skip') throw new Error(`${file.target} 不是 skip 站点`);
|
|
102
|
+
return file.onPresent.notice;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
let fs: MemoryFs;
|
|
106
|
+
let io: CapturingIO;
|
|
107
|
+
|
|
108
|
+
beforeEach(() => {
|
|
109
|
+
jest.clearAllMocks();
|
|
110
|
+
fs = new MemoryFs();
|
|
111
|
+
io = captureIO();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('writeManagedFile:三态判定', () => {
|
|
115
|
+
it('不在场 → created:建父目录、落盘模板正文、绿字告知', async () => {
|
|
116
|
+
const file = customConstraintsFile(PROJECT);
|
|
117
|
+
|
|
118
|
+
expect(await writeManagedFile(file, io, fs)).toBe('created');
|
|
119
|
+
|
|
120
|
+
expect(fs.dirs).toContain(path.dirname(file.target));
|
|
121
|
+
expect(fs.files.get(file.target)).toBe(file.content);
|
|
122
|
+
expect(printed(io)).toEqual([file.created]);
|
|
123
|
+
expect(chalk.green).toHaveBeenCalledWith(file.created);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('声明 mode 才 chmod,缺省不动权限位', async () => {
|
|
127
|
+
expect(await writeManagedFile(preCommitHookFile(PROJECT), io, fs)).toBe('created');
|
|
128
|
+
expect(fs.modes.get(path.join(PROJECT, '.git/hooks/pre-commit'))).toBe(0o755);
|
|
129
|
+
|
|
130
|
+
fs = new MemoryFs();
|
|
131
|
+
io = captureIO();
|
|
132
|
+
expect(await writeManagedFile(prePushHookFile(PROJECT), io, fs)).toBe('created');
|
|
133
|
+
expect(fs.modes.get(path.join(PROJECT, '.git/hooks/pre-push'))).toBe(0o755);
|
|
134
|
+
|
|
135
|
+
fs = new MemoryFs();
|
|
136
|
+
io = captureIO();
|
|
137
|
+
expect(await writeManagedFile(changelogFile(PROJECT, 'keep-a-changelog'), io, fs)).toBe('created');
|
|
138
|
+
expect(fs.modes.size).toBe(0);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('在场 + skip → exists:灰字告知,用户内容一字节不动', async () => {
|
|
142
|
+
const file = changelogFile(PROJECT, 'keep-a-changelog');
|
|
143
|
+
fs.seed(file.target, USER_CONTENT);
|
|
144
|
+
|
|
145
|
+
expect(await writeManagedFile(file, io, fs)).toBe('exists');
|
|
146
|
+
|
|
147
|
+
expect(fs.files.get(file.target)).toBe(USER_CONTENT);
|
|
148
|
+
expect(fs.dirs).toEqual([]);
|
|
149
|
+
expect(printed(io)).toEqual([noticeOf(file)]);
|
|
150
|
+
expect(chalk.gray).toHaveBeenCalledWith(noticeOf(file));
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('在场 + merge → manual:提示 + 指引 + 空行 + cyan 片段,用户内容一字节不动', async () => {
|
|
154
|
+
const file = preCommitHookFile(PROJECT);
|
|
155
|
+
const userHook = '#!/bin/sh\n# 用户自己的钩子\n';
|
|
156
|
+
fs.seed(file.target, userHook);
|
|
157
|
+
|
|
158
|
+
expect(await writeManagedFile(file, io, fs)).toBe('manual');
|
|
159
|
+
|
|
160
|
+
const merge = mergeOf(file);
|
|
161
|
+
expect(printed(io)).toEqual([merge.notice, merge.instruction, '', merge.snippet]);
|
|
162
|
+
expect(chalk.yellow).toHaveBeenCalledWith(merge.notice);
|
|
163
|
+
expect(chalk.cyan).toHaveBeenCalledWith(merge.snippet);
|
|
164
|
+
expect(fs.files.get(file.target)).toBe(userHook);
|
|
165
|
+
expect(fs.modes.has(file.target)).toBe(false);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('present 覆写:冲突判定可以不落在 target 自身(GH Actions 站点按同目录既有 CI 判)', async () => {
|
|
169
|
+
const withCi = harnessCheckCiFile(PROJECT, 'github', ['ci.yml']);
|
|
170
|
+
fs.seed(path.join(PROJECT, '.github/workflows/ci.yml'), 'name: CI\n');
|
|
171
|
+
|
|
172
|
+
expect(await writeManagedFile(withCi, io, fs)).toBe('manual');
|
|
173
|
+
expect(fs.files.has(withCi.target)).toBe(false);
|
|
174
|
+
expect(printed(io)[1]).toBe(' - .github/workflows/ci.yml');
|
|
175
|
+
|
|
176
|
+
io = captureIO();
|
|
177
|
+
expect(await writeManagedFile(harnessCheckCiFile(PROJECT, 'github', []), io, fs)).toBe('created');
|
|
178
|
+
expect(fs.files.get(withCi.target)).toBe(withCi.content);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('runPlan 按顺序逐站点落盘并逐站点回报状态', async () => {
|
|
182
|
+
const plan = [customConstraintsFile(PROJECT), changelogFile(PROJECT, 'keep-a-changelog')];
|
|
183
|
+
fs.seed(plan[1].target, USER_CONTENT);
|
|
184
|
+
|
|
185
|
+
expect(await runPlan(plan, io, fs)).toEqual(['created', 'exists']);
|
|
186
|
+
expect(printed(io)).toEqual([plan[0].created, noticeOf(plan[1])]);
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('init 的脚手架 plan 站点面', () => {
|
|
191
|
+
it('9 站点齐备且目标路径逐字冻结(init 7 + validate 2 同源收口)', () => {
|
|
192
|
+
expect(allSites().map(f => f.target)).toEqual([
|
|
193
|
+
`${PROJECT}/.harness/checkpoints.yml`,
|
|
194
|
+
`${PROJECT}/.harness/resolutions.json`,
|
|
195
|
+
`${PROJECT}/.harness/custom-constraints.yml`,
|
|
196
|
+
`${PROJECT}/.git/hooks/pre-commit`,
|
|
197
|
+
`${PROJECT}/.git/hooks/pre-push`,
|
|
198
|
+
`${PROJECT}/.github/workflows/harness-check.yml`,
|
|
199
|
+
`${PROJECT}/CHANGELOG.md`,
|
|
200
|
+
`${PROJECT}/src/CONTEXT.md`,
|
|
201
|
+
`${PROJECT}/.github/workflows/harness-governance.yml`,
|
|
202
|
+
]);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('治理 workflow 正文随治理级别增减 docs check(模板作数据,级别是入参)', () => {
|
|
206
|
+
const strict = governanceWorkflowFile(PROJECT, 'strict').content;
|
|
207
|
+
const minimal = governanceWorkflowFile(PROJECT, 'minimal').content;
|
|
208
|
+
|
|
209
|
+
expect(strict).toContain('npx @dommaker/harness sync-docs --check');
|
|
210
|
+
expect(minimal).not.toContain('sync-docs');
|
|
211
|
+
expect(minimal).toContain('npx @dommaker/harness passes-gate');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('changelog 模板两档正文各自可辨', () => {
|
|
215
|
+
expect(changelogFile(PROJECT, 'keep-a-changelog').content).toContain('Keep a Changelog');
|
|
216
|
+
expect(changelogFile(PROJECT, 'simple').content).not.toContain('Keep a Changelog');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('CONTEXT.md 模板按目录渲染', () => {
|
|
220
|
+
const content = contextDocFile(PROJECT, 'src').content;
|
|
221
|
+
expect(content).toContain('# src');
|
|
222
|
+
expect(content).toContain('## 职责');
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
describe('CI 站点的平台维度(harness#143)', () => {
|
|
227
|
+
/** governanceLevel 入参 = init 的 `-g` 档;gitlab 形下治理任务并入同一文件 */
|
|
228
|
+
const gitlabCi = (governanceLevel?: string) =>
|
|
229
|
+
harnessCheckCiFile(PROJECT, 'gitlab', [], governanceLevel);
|
|
230
|
+
|
|
231
|
+
it('目标路径按平台给:gitlab → .gitlab-ci.yml,github → workflow 文件', () => {
|
|
232
|
+
expect(gitlabCi().target).toBe(`${PROJECT}/.gitlab-ci.yml`);
|
|
233
|
+
expect(harnessCheckCiFile(PROJECT, 'github', []).target).toBe(
|
|
234
|
+
`${PROJECT}/.github/workflows/harness-check.yml`,
|
|
235
|
+
);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('三态文案逐字冻结:落盘态绿字 / 在场态提示 + 指引 + 空行 + 片段', async () => {
|
|
239
|
+
const memoryFs = new MemoryFs();
|
|
240
|
+
expect(await writeManagedFile(gitlabCi(), io, memoryFs)).toBe('created');
|
|
241
|
+
expect(printed(io)).toEqual(['✅ 已创建 .gitlab-ci.yml']);
|
|
242
|
+
|
|
243
|
+
io = captureIO();
|
|
244
|
+
const file = gitlabCi('standard');
|
|
245
|
+
memoryFs.seed(file.target, USER_CONTENT);
|
|
246
|
+
expect(await writeManagedFile(file, io, memoryFs)).toBe('manual');
|
|
247
|
+
expect(printed(io).slice(0, 2)).toEqual([
|
|
248
|
+
'⚠️ .gitlab-ci.yml 已存在',
|
|
249
|
+
'💡 请手动添加以下内容到文件中:',
|
|
250
|
+
]);
|
|
251
|
+
expect(printed(io)[2]).toBe('');
|
|
252
|
+
expect(memoryFs.files.get(file.target)).toBe(USER_CONTENT);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('冲突面 = target 自身(gitlab 没有「同目录任何 CI 配置即冲突」那一条,GH 侧判定不变)', async () => {
|
|
256
|
+
const memoryFs = new MemoryFs();
|
|
257
|
+
memoryFs.seed(`${PROJECT}/.gitlab/ci/other.yml`, 'x\n');
|
|
258
|
+
expect(await writeManagedFile(gitlabCi(), io, memoryFs)).toBe('created');
|
|
259
|
+
|
|
260
|
+
io = captureIO();
|
|
261
|
+
expect(await writeManagedFile(harnessCheckCiFile(PROJECT, 'github', ['ci.yml']), io, memoryFs)).toBe(
|
|
262
|
+
'manual',
|
|
263
|
+
);
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('落盘正文与 GH 版对仗:同三条命令、image: node:20、stage: test、rules 触发、无缓存', () => {
|
|
267
|
+
const content = gitlabCi().content;
|
|
268
|
+
for (const cmd of ['check', 'validate', 'passes-gate']) {
|
|
269
|
+
expect(content).toContain(`npx @dommaker/harness ${cmd}`);
|
|
270
|
+
}
|
|
271
|
+
expect(content).toContain('image: node:20');
|
|
272
|
+
expect(content).toContain('stage: test');
|
|
273
|
+
expect(content).toContain('- if: $CI_PIPELINE_SOURCE == "merge_request_event"');
|
|
274
|
+
expect(content).toContain('- if: $CI_COMMIT_BRANCH == "main"');
|
|
275
|
+
expect(content).toContain('- if: $CI_COMMIT_BRANCH == "master"');
|
|
276
|
+
expect(content).not.toMatch(/(^|\n)only:/);
|
|
277
|
+
expect(content).not.toMatch(/(^|\n)cache:/);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('治理档并入同一文件,docs 新鲜度检查非阻断 = allow_failure: true', () => {
|
|
281
|
+
const standard = gitlabCi('standard').content;
|
|
282
|
+
expect(standard).toContain('harness-governance:');
|
|
283
|
+
expect(standard).toContain('harness-docs-freshness:');
|
|
284
|
+
expect(standard).toContain('npx @dommaker/harness sync-docs --check');
|
|
285
|
+
expect(standard).toContain('allow_failure: true');
|
|
286
|
+
expect(gitlabCi('minimal').content).toContain('harness-governance:');
|
|
287
|
+
expect(gitlabCi('minimal').content).not.toContain('sync-docs');
|
|
288
|
+
expect(gitlabCi().content).not.toContain('harness-governance:');
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('落盘正文是合法 YAML(自建的 GitLab 实例不吃坏文件)', () => {
|
|
292
|
+
for (const level of [undefined, 'minimal', 'strict']) {
|
|
293
|
+
const doc = yaml.load(gitlabCi(level).content) as Record<string, unknown>;
|
|
294
|
+
expect(doc).toHaveProperty('image', 'node:20');
|
|
295
|
+
expect(doc).toHaveProperty('stages', ['test']);
|
|
296
|
+
expect(Object.keys(doc).filter(k => k.startsWith('harness-'))).toEqual(
|
|
297
|
+
level === undefined ? ['harness-check'] : level === 'minimal'
|
|
298
|
+
? ['harness-check', 'harness-governance']
|
|
299
|
+
: ['harness-check', 'harness-governance', 'harness-docs-freshness'],
|
|
300
|
+
);
|
|
301
|
+
const docs = doc['harness-docs-freshness'] as { allow_failure?: boolean } | undefined;
|
|
302
|
+
if (docs) expect(docs.allow_failure).toBe(true);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('github 形不受平台参数影响:治理站仍是独立 workflow 文件', () => {
|
|
307
|
+
expect(governanceWorkflowFile(PROJECT, 'standard').target).toBe(
|
|
308
|
+
`${PROJECT}/.github/workflows/harness-governance.yml`,
|
|
309
|
+
);
|
|
310
|
+
expect(governanceWorkflowFile(PROJECT, 'standard').content).toContain('name: Harness Governance');
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
describe('对外文案逐字冻结(9 站点 × 落盘态 / 在场态)', () => {
|
|
315
|
+
/** build 入参 = 该站点运行期发现的既有 CI 配置清单(只有 GH Actions 站点用它判冲突) */
|
|
316
|
+
type SiteBuilder = (existingCiWorkflows: string[]) => ManagedFile;
|
|
317
|
+
|
|
318
|
+
/** presentRecords = 在场态除片段外的逐字行(merge 站点片段另由同源闸钉住) */
|
|
319
|
+
const cases: Array<[string, SiteBuilder, string, string[], string?]> = [
|
|
320
|
+
[
|
|
321
|
+
'pre-commit',
|
|
322
|
+
() => preCommitHookFile(PROJECT),
|
|
323
|
+
'✅ 已创建 .git/hooks/pre-commit',
|
|
324
|
+
['⚠️ .git/hooks/pre-commit 已存在', '💡 请手动添加以下内容到文件末尾:'],
|
|
325
|
+
'echo "🔍 Running harness checks..."',
|
|
326
|
+
],
|
|
327
|
+
[
|
|
328
|
+
'pre-push',
|
|
329
|
+
() => prePushHookFile(PROJECT),
|
|
330
|
+
'✅ 已创建 .git/hooks/pre-push',
|
|
331
|
+
['⚠️ .git/hooks/pre-push 已存在', '💡 请手动添加以下内容到文件末尾:'],
|
|
332
|
+
'echo "🔍 Running harness pre-push checks (whole repo)..."',
|
|
333
|
+
],
|
|
334
|
+
[
|
|
335
|
+
'harness-check.yml',
|
|
336
|
+
ci => harnessCheckCiFile(PROJECT, 'github', ci),
|
|
337
|
+
'✅ 已创建 .github/workflows/harness-check.yml',
|
|
338
|
+
[
|
|
339
|
+
'⚠️ 检测到已存在的 CI 配置:',
|
|
340
|
+
' - .github/workflows/ci.yml',
|
|
341
|
+
'💡 请手动添加以下内容到 jobs 中:',
|
|
342
|
+
],
|
|
343
|
+
'name: Harness Check',
|
|
344
|
+
],
|
|
345
|
+
[
|
|
346
|
+
'custom-constraints.yml',
|
|
347
|
+
() => customConstraintsFile(PROJECT),
|
|
348
|
+
'✅ 已创建自定义约束示例: custom-constraints.yml',
|
|
349
|
+
['custom-constraints.yml 已存在'],
|
|
350
|
+
'',
|
|
351
|
+
],
|
|
352
|
+
[
|
|
353
|
+
'checkpoints.yml',
|
|
354
|
+
() => checkpointsFile(PROJECT),
|
|
355
|
+
'✅ 已创建示例检查点文件: /srv/project/.harness/checkpoints.yml',
|
|
356
|
+
['checkpoints.yml 已存在,跳过'],
|
|
357
|
+
'',
|
|
358
|
+
],
|
|
359
|
+
[
|
|
360
|
+
'resolutions.json',
|
|
361
|
+
() => resolutionsFile(PROJECT),
|
|
362
|
+
'✅ 已创建 Resolutions 文件: /srv/project/.harness/resolutions.json',
|
|
363
|
+
['resolutions.json 已存在,跳过'],
|
|
364
|
+
'',
|
|
365
|
+
],
|
|
366
|
+
[
|
|
367
|
+
'CHANGELOG.md',
|
|
368
|
+
() => changelogFile(PROJECT, 'keep-a-changelog'),
|
|
369
|
+
'✅ 已创建 CHANGELOG.md',
|
|
370
|
+
['CHANGELOG.md 已存在'],
|
|
371
|
+
'',
|
|
372
|
+
],
|
|
373
|
+
[
|
|
374
|
+
'CONTEXT.md',
|
|
375
|
+
() => contextDocFile(PROJECT, 'src'),
|
|
376
|
+
'✅ 已创建 src/CONTEXT.md',
|
|
377
|
+
['src/CONTEXT.md 已存在'],
|
|
378
|
+
'',
|
|
379
|
+
],
|
|
380
|
+
[
|
|
381
|
+
'harness-governance.yml',
|
|
382
|
+
() => governanceWorkflowFile(PROJECT, 'standard'),
|
|
383
|
+
'✅ 已创建 .github/workflows/harness-governance.yml',
|
|
384
|
+
['harness-governance.yml 已存在'],
|
|
385
|
+
'',
|
|
386
|
+
],
|
|
387
|
+
];
|
|
388
|
+
|
|
389
|
+
it.each(cases)('%s 落盘态', async (_label, build, created) => {
|
|
390
|
+
const memoryFs = new MemoryFs();
|
|
391
|
+
const file = build([]);
|
|
392
|
+
expect(await writeManagedFile(file, io, memoryFs)).toBe('created');
|
|
393
|
+
expect(printed(io)).toEqual([created]);
|
|
394
|
+
expect(memoryFs.files.size).toBe(1);
|
|
395
|
+
expect(memoryFs.files.get(file.target)).toBe(file.content);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it.each(cases)('%s 在场态(第三态)', async (_label, build, _created, presentRecords, snippetHead) => {
|
|
399
|
+
const memoryFs = new MemoryFs();
|
|
400
|
+
const file = build(['ci.yml']);
|
|
401
|
+
memoryFs.seed(file.target, USER_CONTENT);
|
|
402
|
+
|
|
403
|
+
await writeManagedFile(file, io, memoryFs);
|
|
404
|
+
|
|
405
|
+
const lines = printed(io);
|
|
406
|
+
expect(lines.slice(0, presentRecords.length)).toEqual(presentRecords);
|
|
407
|
+
if (snippetHead) {
|
|
408
|
+
// merge 站点:指引之后是空行 + 片段本体
|
|
409
|
+
expect(lines[presentRecords.length]).toBe('');
|
|
410
|
+
expect(lines.slice(presentRecords.length + 1).join('\n')).toContain(snippetHead);
|
|
411
|
+
} else {
|
|
412
|
+
expect(lines).toEqual(presentRecords);
|
|
413
|
+
}
|
|
414
|
+
expect(memoryFs.files.get(file.target)).toBe(USER_CONTENT);
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
describe('打印片段与落盘内容同源(#103 判据)', () => {
|
|
419
|
+
/** 片段必须是落盘正文的一部分(或逐字等于正文),否则用户手工合并的是另一份文本 */
|
|
420
|
+
function snippetDrift(file: ManagedFile): string | undefined {
|
|
421
|
+
if (file.onPresent.outcome !== 'merge') return undefined;
|
|
422
|
+
return file.content.includes(file.onPresent.snippet) ? undefined : `${file.target}: 打印片段不在落盘正文里`;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
it('merge 站点全部同源', () => {
|
|
426
|
+
expect(allSites().map(snippetDrift).filter(Boolean)).toEqual([]);
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
it('CI 站点的两种平台形全部同源(gitlab 三档治理形一并入闸)', () => {
|
|
430
|
+
const ciSites = [
|
|
431
|
+
harnessCheckCiFile(PROJECT, 'github', ['ci.yml']),
|
|
432
|
+
harnessCheckCiFile(PROJECT, 'gitlab', []),
|
|
433
|
+
harnessCheckCiFile(PROJECT, 'gitlab', [], 'minimal'),
|
|
434
|
+
harnessCheckCiFile(PROJECT, 'gitlab', [], 'standard'),
|
|
435
|
+
];
|
|
436
|
+
expect(ciSites.map(snippetDrift).filter(Boolean)).toEqual([]);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it('GitLab 站点冲突分支打印 job 片段,且片段是落盘全文正本的一部分', () => {
|
|
440
|
+
const plain = mergeOf(harnessCheckCiFile(PROJECT, 'gitlab', [])).snippet;
|
|
441
|
+
const governed = mergeOf(harnessCheckCiFile(PROJECT, 'gitlab', [], 'standard')).snippet;
|
|
442
|
+
|
|
443
|
+
expect(plain).toBe(GITLAB_CI_SNIPPET);
|
|
444
|
+
expect(plain).toContain('harness-check:');
|
|
445
|
+
expect(plain).not.toContain('image:');
|
|
446
|
+
expect(governed.startsWith(plain)).toBe(true);
|
|
447
|
+
expect(governed).toContain('harness-docs-freshness:');
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it('GH Actions 站点冲突分支打印完整 workflow 正文(不再是 job 片段)', () => {
|
|
451
|
+
const file = harnessCheckCiFile(PROJECT, 'github', ['ci.yml']);
|
|
452
|
+
const snippet = mergeOf(file).snippet;
|
|
453
|
+
|
|
454
|
+
expect(snippet).toBe(file.content);
|
|
455
|
+
expect(snippet).toContain('name: Harness Check');
|
|
456
|
+
expect(snippet).toContain('npx @dommaker/harness passes-gate');
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
it('GH 片段视图是落盘正本裁出来的一段,不是第二份手抄文本(#153)', () => {
|
|
460
|
+
expect(HARNESS_CHECK_WORKFLOW.includes(GITHUB_ACTIONS_SNIPPET)).toBe(true);
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
it('pre-commit 站点落盘正文 = 打印片段 + shebang 头', () => {
|
|
464
|
+
const file = preCommitHookFile(PROJECT);
|
|
465
|
+
expect(file.content.startsWith('#!/bin/sh\n')).toBe(true);
|
|
466
|
+
expect(file.content.endsWith(mergeOf(file).snippet)).toBe(true);
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
it('pre-push 站点落盘正文 = 打印片段 + shebang 头(#103 判据)', () => {
|
|
470
|
+
const file = prePushHookFile(PROJECT);
|
|
471
|
+
expect(file.content.startsWith('#!/bin/sh\n# Harness pre-push hook\n')).toBe(true);
|
|
472
|
+
expect(file.content.endsWith(mergeOf(file).snippet)).toBe(true);
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
it('pre-push 跑整仓全量兜底:check 不带 --staged + validate,恰好这两道', () => {
|
|
476
|
+
const body = prePushHookFile(PROJECT).content;
|
|
477
|
+
|
|
478
|
+
expect(body).toContain('npx @dommaker/harness check');
|
|
479
|
+
expect(body).not.toContain('check --staged');
|
|
480
|
+
expect(body).toContain('npx @dommaker/harness validate');
|
|
481
|
+
expect(body.match(/npx @dommaker\/harness/g)).toHaveLength(2);
|
|
482
|
+
});
|
|
483
|
+
|
|
484
|
+
it('pre-push 不做增量、不内建逃生机制(决议:唯一逃生口是 git 原生 --no-verify)', () => {
|
|
485
|
+
const body = prePushHookFile(PROJECT).content;
|
|
486
|
+
|
|
487
|
+
// 不解析 pre-push 从 stdin 收到的 <local_ref> <local_oid> <remote_ref> <remote_oid> 清单
|
|
488
|
+
expect(body).not.toMatch(/\bwhile read\b|local_ref|remote_ref/);
|
|
489
|
+
// 无环境变量开关、无超时、无「慢则降级」
|
|
490
|
+
expect(body).not.toMatch(/\$\{?[A-Z][A-Z0-9_]*\}?/);
|
|
491
|
+
expect(body).not.toMatch(/\btimeout\b/);
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
it.each(['pre-commit', 'pre-push'] as const)(
|
|
495
|
+
'闸非空洞:%s 落盘正文被改动而片段未跟进 → 报出该站点',
|
|
496
|
+
which => {
|
|
497
|
+
const build = which === 'pre-commit' ? preCommitHookFile : prePushHookFile;
|
|
498
|
+
const drifted: ManagedFile = {
|
|
499
|
+
...build(PROJECT),
|
|
500
|
+
content: '#!/bin/sh\n# 悄悄改了这里\n',
|
|
501
|
+
};
|
|
502
|
+
expect(snippetDrift(drifted)).toContain(which);
|
|
503
|
+
},
|
|
504
|
+
);
|
|
505
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #138 缺省扫描命令断链回归测试(CLI 命令级)
|
|
3
|
+
*
|
|
4
|
+
* 门禁级的三级兜底可达性见 `src/gates/__tests__/security-default-scan.test.ts`。
|
|
5
|
+
* 本文件从命令入口证明:不给 --scan-command 时,`harness security` / `harness security audit`
|
|
6
|
+
* 走的正是恢复后的缺省链——把 detectScanCommand() 的返回值交给执行,不再以空串报错退出。
|
|
7
|
+
*
|
|
8
|
+
* 替身只落在 `src/utils/exec` 的 execAsync 缝上(记录命令 + 对空串复现真实抛错),
|
|
9
|
+
* 门禁与命令实现全部走真码;chalk 桩掉只为读输出,成败按 CommandResult.kind 判定。
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { execAsync } from '../../../utils/exec';
|
|
13
|
+
import { security, auditDetails } from '../security';
|
|
14
|
+
import { captureIO, type CapturingIO } from '../../command-contract';
|
|
15
|
+
|
|
16
|
+
jest.mock('../../../utils/exec', () => {
|
|
17
|
+
const actual = jest.requireActual('../../../utils/exec');
|
|
18
|
+
return { ...actual, execAsync: jest.fn() };
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
jest.mock('chalk', () => ({
|
|
22
|
+
blue: jest.fn((s: string) => s),
|
|
23
|
+
green: jest.fn((s: string) => s),
|
|
24
|
+
red: Object.assign(jest.fn((s: string) => s), { bold: jest.fn((s: string) => s) }),
|
|
25
|
+
yellow: jest.fn((s: string) => s),
|
|
26
|
+
gray: jest.fn((s: string) => s),
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
const mockExecAsync = execAsync as unknown as jest.Mock;
|
|
30
|
+
const DETECTED = 'npm audit --json';
|
|
31
|
+
|
|
32
|
+
describe('harness security 缺省扫描命令(#138 断链 · CLI 级)', () => {
|
|
33
|
+
const issued = (): string[] => mockExecAsync.mock.calls.map((c) => String(c[0]));
|
|
34
|
+
let io: CapturingIO;
|
|
35
|
+
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
jest.clearAllMocks();
|
|
38
|
+
io = captureIO();
|
|
39
|
+
mockExecAsync.mockImplementation((cmd: string) => {
|
|
40
|
+
if (!cmd || !cmd.trim()) {
|
|
41
|
+
return Promise.reject(new TypeError("The argument 'file' cannot be empty. Received ''"));
|
|
42
|
+
}
|
|
43
|
+
return Promise.resolve({ stdout: JSON.stringify({ vulnerabilities: {} }), stderr: '' });
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('security 不给 --scan-command → 执行探测命令并按结果放行', async () => {
|
|
48
|
+
const result = await security({}, io);
|
|
49
|
+
|
|
50
|
+
expect(issued()).toEqual([DETECTED]);
|
|
51
|
+
expect(result.kind).toBe('ok');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('security audit 不给 --scan-command → 同一条链真的把扫描命令交给执行', async () => {
|
|
55
|
+
const result = await auditDetails({}, io);
|
|
56
|
+
|
|
57
|
+
expect(issued()).toEqual([DETECTED]);
|
|
58
|
+
expect(result.kind).toBe('ok');
|
|
59
|
+
expect(io.outText()).toContain('未发现安全漏洞');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('security --scan-command "" → 视为未提供,落到探测', async () => {
|
|
63
|
+
const result = await security({ scanCommand: '' }, io);
|
|
64
|
+
|
|
65
|
+
expect(issued()).toEqual([DETECTED]);
|
|
66
|
+
expect(result.kind).toBe('ok');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('security --scan-command <cmd> 显式路径行为不变', async () => {
|
|
70
|
+
const result = await security({ scanCommand: 'snyk test --json' }, io);
|
|
71
|
+
|
|
72
|
+
expect(issued()).toEqual(['snyk test --json']);
|
|
73
|
+
expect(result.kind).toBe('ok');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import { security, auditDetails } from '../security';
|
|
6
6
|
import { captureIO, type CapturingIO } from '../../command-contract';
|
|
7
|
+
import { decide, fakeGate } from './gate-decision';
|
|
7
8
|
import { SecurityGate } from '../../../gates/security';
|
|
8
9
|
|
|
9
10
|
jest.mock('../../../gates/security', () => ({
|
|
10
11
|
SecurityGate: jest.fn().mockImplementation(() => ({
|
|
12
|
+
evaluate: jest.fn(),
|
|
11
13
|
scan: jest.fn(),
|
|
12
14
|
})),
|
|
13
15
|
}));
|
|
@@ -33,12 +35,9 @@ describe('security command', () => {
|
|
|
33
35
|
|
|
34
36
|
describe('security', () => {
|
|
35
37
|
it('should print success when scan passes', async () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
details: { critical: 0, high: 0, moderate: 0, low: 0 },
|
|
40
|
-
});
|
|
41
|
-
MockGate.mockImplementation(() => ({ scan: mockScan }) as any);
|
|
38
|
+
MockGate.mockImplementation(() =>
|
|
39
|
+
fakeGate(decide('security', true, 'no vulnerabilities', { critical: 0, high: 0, moderate: 0, low: 0 })) as any
|
|
40
|
+
);
|
|
42
41
|
|
|
43
42
|
const result = await security({}, io);
|
|
44
43
|
|
|
@@ -47,34 +46,33 @@ describe('security command', () => {
|
|
|
47
46
|
});
|
|
48
47
|
|
|
49
48
|
it('should print failure and exit 1 when scan fails', async () => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
MockGate.mockImplementation(() => ({ scan: mockScan }) as any);
|
|
49
|
+
MockGate.mockImplementation(() =>
|
|
50
|
+
fakeGate(
|
|
51
|
+
decide('security', false, 'vulnerabilities found', {
|
|
52
|
+
critical: 1,
|
|
53
|
+
high: 2,
|
|
54
|
+
vulnerabilities: [
|
|
55
|
+
{ name: 'pkg-a', severity: 'critical', via: 'CVE-2026-0001' },
|
|
56
|
+
{ name: 'pkg-b', severity: 'high', via: 'CVE-2026-0002' },
|
|
57
|
+
],
|
|
58
|
+
})
|
|
59
|
+
) as any
|
|
60
|
+
);
|
|
63
61
|
|
|
64
62
|
const result = await security({}, io);
|
|
65
63
|
|
|
66
64
|
expect(io.outText()).toContain('安全门控检查失败');
|
|
65
|
+
expect(io.outText()).toContain(' 阈值: high');
|
|
67
66
|
expect(io.outText()).toContain('pkg-a');
|
|
68
67
|
expect(io.outText()).toContain('pkg-b');
|
|
69
68
|
expect(result).toEqual({
|
|
70
69
|
kind: 'fail',
|
|
71
|
-
reason: 'security gate denied
|
|
70
|
+
reason: 'security gate denied: vulnerabilities found',
|
|
72
71
|
});
|
|
73
72
|
});
|
|
74
73
|
|
|
75
74
|
it('should default severity to high', async () => {
|
|
76
|
-
|
|
77
|
-
MockGate.mockImplementation(() => ({ scan: mockScan }) as any);
|
|
75
|
+
MockGate.mockImplementation(() => fakeGate(decide('security', true, 'ok')) as any);
|
|
78
76
|
|
|
79
77
|
await security({}, io);
|
|
80
78
|
|
|
@@ -84,8 +82,7 @@ describe('security command', () => {
|
|
|
84
82
|
});
|
|
85
83
|
|
|
86
84
|
it('should use custom severity', async () => {
|
|
87
|
-
|
|
88
|
-
MockGate.mockImplementation(() => ({ scan: mockScan }) as any);
|
|
85
|
+
MockGate.mockImplementation(() => fakeGate(decide('security', true, 'ok')) as any);
|
|
89
86
|
|
|
90
87
|
await security({ severity: 'critical' }, io);
|
|
91
88
|
|