@dommaker/harness 0.13.0 → 0.13.2
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 +169 -0
- package/bin/harness-knowledge-capture.js +99 -0
- package/bin/harness-knowledge-check.js +149 -0
- package/bin/harness-knowledge-track.js +92 -0
- package/bin/harness-knowledge-track.sh +47 -0
- package/bin/harness-sensitive-check.sh +67 -0
- package/dist/cli/commands/init.js +34 -2
- package/dist/cli/commands/init.js.map +1 -1
- package/package.json +6 -3
- package/src/CONTEXT.md +34 -0
- package/src/__tests__/acceptance-gate.test.ts +364 -0
- package/src/__tests__/annotation-checker.test.ts +183 -0
- package/src/__tests__/architecture-engine.test.ts +619 -0
- package/src/__tests__/checker-extra.test.ts +1627 -0
- package/src/__tests__/checker.test.ts +1268 -0
- package/src/__tests__/checkpoint.test.ts +697 -0
- package/src/__tests__/clean-state-extra.test.ts +301 -0
- package/src/__tests__/clean-state.test.ts +169 -0
- package/src/__tests__/constraint-doctor.test.ts +410 -0
- package/src/__tests__/constraint-evolver.test.ts +404 -0
- package/src/__tests__/constraint-handler.test.ts +136 -0
- package/src/__tests__/context/progressive-loader.test.ts +131 -0
- package/src/__tests__/contract-gate.test.ts +321 -0
- package/src/__tests__/cross-project-checker.test.ts +318 -0
- package/src/__tests__/cso-validator.test.ts +205 -0
- package/src/__tests__/detect-source-roots.test.ts +98 -0
- package/src/__tests__/doctor-evolver.test.ts +381 -0
- package/src/__tests__/error-classifier.test.ts +304 -0
- package/src/__tests__/exec.test.ts +83 -0
- package/src/__tests__/extend-exceptions.test.ts +149 -0
- package/src/__tests__/failure-recorder.test.ts +335 -0
- package/src/__tests__/hooks-pipeline.test.ts +214 -0
- package/src/__tests__/interceptor.test.ts +89 -0
- package/src/__tests__/iron-laws.test.ts +246 -0
- package/src/__tests__/long-running.test.ts +17 -0
- package/src/__tests__/passes-gate-check.test.ts +138 -0
- package/src/__tests__/passes-gate-extension.test.ts +151 -0
- package/src/__tests__/passes-gate-extra.test.ts +238 -0
- package/src/__tests__/passes-gate.test.ts +231 -0
- package/src/__tests__/performance-analyzer.test.ts +501 -0
- package/src/__tests__/performance-collector.test.ts +276 -0
- package/src/__tests__/performance-gate.test.ts +74 -0
- package/src/__tests__/presets.test.ts +104 -0
- package/src/__tests__/project-config-loader-extra.test.ts +269 -0
- package/src/__tests__/project-config-loader.test.ts +127 -0
- package/src/__tests__/review-gate.test.ts +92 -0
- package/src/__tests__/security-gate.test.ts +100 -0
- package/src/__tests__/session-startup.test.ts +334 -0
- package/src/__tests__/spec-validator.test.ts +57 -0
- package/src/__tests__/token-budget.test.ts +252 -0
- package/src/__tests__/trace-analyzer-extra.test.ts +307 -0
- package/src/__tests__/trace-analyzer.test.ts +131 -0
- package/src/__tests__/trace-collector.test.ts +258 -0
- package/src/__tests__/traces.test.ts +347 -0
- package/src/agents/CONTEXT.md +21 -0
- package/src/agents/__tests__/lifecycle.test.ts +248 -0
- package/src/agents/index.ts +2 -0
- package/src/agents/lifecycle.ts +201 -0
- package/src/agents/types.ts +46 -0
- package/src/architecture/CONTEXT.md +22 -0
- package/src/architecture/constraint-engine.ts +356 -0
- package/src/architecture/cross-project-checker.ts +563 -0
- package/src/cli/commands/CONTEXT.md +24 -0
- package/src/cli/commands/__tests__/acceptance.test.ts +180 -0
- package/src/cli/commands/__tests__/check.test.ts +598 -0
- package/src/cli/commands/__tests__/command.test.ts +149 -0
- package/src/cli/commands/__tests__/contract.test.ts +151 -0
- package/src/cli/commands/__tests__/failure.test.ts +199 -0
- package/src/cli/commands/__tests__/flow.test.ts +343 -0
- package/src/cli/commands/__tests__/init.test.ts +306 -0
- package/src/cli/commands/__tests__/passes-gate.test.ts +256 -0
- package/src/cli/commands/__tests__/performance.test.ts +116 -0
- package/src/cli/commands/__tests__/posteval-plan.test.ts +201 -0
- package/src/cli/commands/__tests__/report-extra.test.ts +98 -0
- package/src/cli/commands/__tests__/report.test.ts +109 -0
- package/src/cli/commands/__tests__/review.test.ts +153 -0
- package/src/cli/commands/__tests__/security.test.ts +147 -0
- package/src/cli/commands/__tests__/spec.test.ts +193 -0
- package/src/cli/commands/__tests__/status-extra.test.ts +223 -0
- package/src/cli/commands/__tests__/status.test.ts +306 -0
- package/src/cli/commands/__tests__/sync-docs.test.ts +335 -0
- package/src/cli/commands/__tests__/validate.test.ts +139 -0
- package/src/cli/commands/acceptance.ts +111 -0
- package/src/cli/commands/analyze-sessions.ts +488 -0
- package/src/cli/commands/check.ts +441 -0
- package/src/cli/commands/command.ts +90 -0
- package/src/cli/commands/constraints.ts +86 -0
- package/src/cli/commands/contract.ts +168 -0
- package/src/cli/commands/failure.ts +117 -0
- package/src/cli/commands/flow.ts +275 -0
- package/src/cli/commands/index.ts +26 -0
- package/src/cli/commands/init.ts +832 -0
- package/src/cli/commands/knowledge.ts +391 -0
- package/src/cli/commands/passes-gate.ts +158 -0
- package/src/cli/commands/performance.ts +108 -0
- package/src/cli/commands/posteval-plan.ts +85 -0
- package/src/cli/commands/release.ts +159 -0
- package/src/cli/commands/report.ts +198 -0
- package/src/cli/commands/review.ts +118 -0
- package/src/cli/commands/security.ts +122 -0
- package/src/cli/commands/spec.ts +158 -0
- package/src/cli/commands/status.ts +169 -0
- package/src/cli/commands/sync-docs.ts +743 -0
- package/src/cli/commands/update-user-model.ts +527 -0
- package/src/cli/commands/validate.ts +222 -0
- package/src/constraints/__tests__/lifecycle-runner.test.ts +246 -0
- package/src/constraints/__tests__/registry.test.ts +196 -0
- package/src/constraints/index.ts +3 -0
- package/src/constraints/lifecycle-runner.ts +184 -0
- package/src/constraints/registry.ts +134 -0
- package/src/constraints/types.ts +59 -0
- package/src/context/CONTEXT.md +28 -0
- package/src/context/__tests__/compaction.test.ts +169 -0
- package/src/context/__tests__/file-budget.test.ts +142 -0
- package/src/context/__tests__/knowledge-injector.test.ts +148 -0
- package/src/context/__tests__/progressive-loader.test.ts +264 -0
- package/src/context/__tests__/session-manager.test.ts +300 -0
- package/src/context/__tests__/token-budget.test.ts +338 -0
- package/src/context/__tests__/token-pipeline.test.ts +178 -0
- package/src/context/__tests__/tool-output-budget.test.ts +95 -0
- package/src/context/compaction.ts +202 -0
- package/src/context/file-budget.ts +142 -0
- package/src/context/index.ts +15 -0
- package/src/context/knowledge-injector.ts +168 -0
- package/src/context/progressive-loader.ts +260 -0
- package/src/context/session-manager.ts +343 -0
- package/src/context/token-budget.ts +295 -0
- package/src/context/token-pipeline.ts +265 -0
- package/src/context/tool-output-budget.ts +178 -0
- package/src/context/types.ts +160 -0
- package/src/core/CONTEXT.md +26 -0
- package/src/core/constraints/__tests__/default-executors.test.ts +57 -0
- package/src/core/constraints/__tests__/interceptor.test.ts +251 -0
- package/src/core/constraints/__tests__/prompt-injection.test.ts +89 -0
- package/src/core/constraints/check-cache.ts +96 -0
- package/src/core/constraints/checker.ts +1169 -0
- package/src/core/constraints/default-executors.ts +92 -0
- package/src/core/constraints/definitions.ts +1119 -0
- package/src/core/constraints/doc-freshness/__tests__/runner.test.ts +551 -0
- package/src/core/constraints/doc-freshness/auto-fix.ts +69 -0
- package/src/core/constraints/doc-freshness/runner.ts +486 -0
- package/src/core/constraints/index.ts +78 -0
- package/src/core/constraints/interceptor.ts +220 -0
- package/src/core/constraints/prompt-injection.ts +73 -0
- package/src/core/index.ts +23 -0
- package/src/core/project-config-loader.ts +252 -0
- package/src/core/session/__tests__/startup.test.ts +281 -0
- package/src/core/session/clean-state.ts +178 -0
- package/src/core/session/index.ts +15 -0
- package/src/core/session/startup.ts +253 -0
- package/src/core/spec/__tests__/validator.test.ts +379 -0
- package/src/core/spec/index.ts +7 -0
- package/src/core/spec/validator.ts +383 -0
- package/src/core/validators/__tests__/passes-gate.test.ts +131 -0
- package/src/core/validators/checkpoint.ts +547 -0
- package/src/core/validators/cso.ts +124 -0
- package/src/core/validators/index.ts +25 -0
- package/src/core/validators/passes-gate.ts +613 -0
- package/src/dashboard/CONTEXT.md +21 -0
- package/src/dashboard/__tests__/data.test.ts +115 -0
- package/src/dashboard/__tests__/stats.test.ts +156 -0
- package/src/dashboard/data.ts +113 -0
- package/src/dashboard/index.ts +3 -0
- package/src/dashboard/stats.ts +127 -0
- package/src/dashboard/types.ts +113 -0
- package/src/evolution/CONTEXT.md +22 -0
- package/src/evolution/__tests__/auto-evolve.test.ts +320 -0
- package/src/evolution/auto-evolve.ts +98 -0
- package/src/evolution/index.ts +1 -0
- package/src/failure/CONTEXT.md +24 -0
- package/src/failure/classifier.ts +156 -0
- package/src/failure/constraint-handler.ts +173 -0
- package/src/failure/index.ts +35 -0
- package/src/failure/recorder.ts +201 -0
- package/src/failure/types.ts +165 -0
- package/src/gates/CONTEXT.md +27 -0
- package/src/gates/__tests__/acceptance.test.ts +608 -0
- package/src/gates/__tests__/command.test.ts +206 -0
- package/src/gates/__tests__/performance.test.ts +381 -0
- package/src/gates/__tests__/review.test.ts +302 -0
- package/src/gates/__tests__/security.test.ts +332 -0
- package/src/gates/acceptance.ts +493 -0
- package/src/gates/command.ts +444 -0
- package/src/gates/contract.ts +260 -0
- package/src/gates/index.ts +67 -0
- package/src/gates/performance.ts +359 -0
- package/src/gates/review.ts +169 -0
- package/src/gates/security.ts +244 -0
- package/src/gates/types.ts +159 -0
- package/src/governance/CONTEXT.md +22 -0
- package/src/governance/__tests__/executor.test.ts +249 -0
- package/src/governance/executor.ts +229 -0
- package/src/governance/index.ts +13 -0
- package/src/governance/types.ts +53 -0
- package/src/hooks/CONTEXT.md +23 -0
- package/src/hooks/__tests__/bootstrap.test.ts +184 -0
- package/src/hooks/bootstrap.ts +144 -0
- package/src/hooks/index.ts +15 -0
- package/src/hooks/pipeline.ts +157 -0
- package/src/hooks/registry.ts +88 -0
- package/src/hooks/types.ts +80 -0
- package/src/index.ts +198 -0
- package/src/knowledge/CONTEXT.md +29 -0
- package/src/knowledge/__tests__/doctor.test.ts +272 -0
- package/src/knowledge/__tests__/import.test.ts +376 -0
- package/src/knowledge/__tests__/ingest.test.ts +125 -0
- package/src/knowledge/__tests__/lifecycle-hooks.test.ts +137 -0
- package/src/knowledge/__tests__/lifecycle.test.ts +248 -0
- package/src/knowledge/__tests__/lint.test.ts +401 -0
- package/src/knowledge/__tests__/query.test.ts +185 -0
- package/src/knowledge/__tests__/reference-tracker.test.ts +129 -0
- package/src/knowledge/__tests__/store.test.ts +238 -0
- package/src/knowledge/doctor.ts +104 -0
- package/src/knowledge/import.ts +505 -0
- package/src/knowledge/index.ts +16 -0
- package/src/knowledge/ingest.ts +126 -0
- package/src/knowledge/lifecycle-hooks.ts +199 -0
- package/src/knowledge/lifecycle.ts +175 -0
- package/src/knowledge/lint.ts +360 -0
- package/src/knowledge/query.ts +150 -0
- package/src/knowledge/reference-tracker.ts +99 -0
- package/src/knowledge/store.ts +264 -0
- package/src/knowledge/types.ts +139 -0
- package/src/llm/CONTEXT.md +21 -0
- package/src/llm/__tests__/adapter.test.ts +172 -0
- package/src/llm/adapter.ts +149 -0
- package/src/llm/index.ts +2 -0
- package/src/llm/types.ts +81 -0
- package/src/monitoring/CONTEXT.md +29 -0
- package/src/monitoring/__tests__/context-tracker.test.ts +172 -0
- package/src/monitoring/__tests__/knowledge-doctor.test.ts +276 -0
- package/src/monitoring/__tests__/knowledge-evolver.test.ts +365 -0
- package/src/monitoring/__tests__/performance-analyzer.test.ts +137 -0
- package/src/monitoring/__tests__/performance-collector.test.ts +332 -0
- package/src/monitoring/__tests__/traces.test.ts +190 -0
- package/src/monitoring/constraint-doctor.ts +499 -0
- package/src/monitoring/constraint-evolver.ts +573 -0
- package/src/monitoring/context-tracker.ts +148 -0
- package/src/monitoring/index.ts +23 -0
- package/src/monitoring/knowledge-doctor.ts +323 -0
- package/src/monitoring/knowledge-evolver.ts +289 -0
- package/src/monitoring/performance-analyzer.ts +450 -0
- package/src/monitoring/performance-collector.ts +348 -0
- package/src/monitoring/trace-analyzer.ts +470 -0
- package/src/monitoring/traces.ts +339 -0
- package/src/presets/__tests__/standard.test.ts +104 -0
- package/src/presets/index.ts +16 -0
- package/src/presets/standard.ts +163 -0
- package/src/safety/CONTEXT.md +23 -0
- package/src/safety/__tests__/input-guardrail.test.ts +105 -0
- package/src/safety/__tests__/output-guardrail.test.ts +108 -0
- package/src/safety/__tests__/sandbox.test.ts +158 -0
- package/src/safety/__tests__/tool-guardrail.test.ts +127 -0
- package/src/safety/index.ts +5 -0
- package/src/safety/input-guardrail.ts +133 -0
- package/src/safety/output-guardrail.ts +174 -0
- package/src/safety/sandbox.ts +148 -0
- package/src/safety/tool-guardrail.ts +176 -0
- package/src/safety/types.ts +124 -0
- package/src/spec/CONTEXT.md +19 -0
- package/src/spec/__tests__/annotation-checker.test.ts +289 -0
- package/src/spec/annotation-checker.ts +342 -0
- package/src/tools/CONTEXT.md +25 -0
- package/src/tools/__tests__/loader.test.ts +252 -0
- package/src/tools/__tests__/registry.test.ts +157 -0
- package/src/tools/core/__tests__/core.test.ts +122 -0
- package/src/tools/core/index.ts +201 -0
- package/src/tools/core/package.json +7 -0
- package/src/tools/core/pnpm-lock.yaml +232 -0
- package/src/tools/definitions/core/code/fingerprint.sh +273 -0
- package/src/tools/definitions/core/code/fingerprint.yml +72 -0
- package/src/tools/definitions/core/code/parse.yml +68 -0
- package/src/tools/definitions/core/code/register-language.sh +475 -0
- package/src/tools/definitions/core/code/register-language.yml +74 -0
- package/src/tools/definitions/core/docker/build.yml +73 -0
- package/src/tools/definitions/core/docker/run.yml +81 -0
- package/src/tools/definitions/core/file/copy.yml +88 -0
- package/src/tools/definitions/core/file/read.yml +69 -0
- package/src/tools/definitions/core/file/write.yml +75 -0
- package/src/tools/definitions/core/git/branch.yml +61 -0
- package/src/tools/definitions/core/git/cleanup-worktree.yml +50 -0
- package/src/tools/definitions/core/git/clone.yml +69 -0
- package/src/tools/definitions/core/git/commit.yml +65 -0
- package/src/tools/definitions/core/git/push.yml +79 -0
- package/src/tools/definitions/core/git/worktree.yml +96 -0
- package/src/tools/definitions/core/notification/notify.sh +152 -0
- package/src/tools/definitions/core/notification/notify.yml +60 -0
- package/src/tools/definitions/core/npm/build.yml +75 -0
- package/src/tools/definitions/core/npm/install.yml +58 -0
- package/src/tools/definitions/core/npm/test.yml +75 -0
- package/src/tools/definitions/core/validation/check-reuse.yml +170 -0
- package/src/tools/definitions/core/validation/validate-handlers.yml +118 -0
- package/src/tools/definitions/core/validation/validate-readme-stats.yml +155 -0
- package/src/tools/definitions/core/validation/validate-yaml-syntax.yml +134 -0
- package/src/tools/definitions/ext/browser/browser-automate.sh +255 -0
- package/src/tools/definitions/ext/browser/browser-automate.yml +166 -0
- package/src/tools/definitions/ext/browser/browser-close.sh +104 -0
- package/src/tools/definitions/ext/browser/browser-close.yml +55 -0
- package/src/tools/definitions/ext/browser/browser-mcp-debug.sh +682 -0
- package/src/tools/definitions/ext/browser/browser-mcp-debug.yml +167 -0
- package/src/tools/definitions/ext/browser/browser-start.sh +101 -0
- package/src/tools/definitions/ext/browser/browser-start.yml +62 -0
- package/src/tools/definitions/registry.json +795 -0
- package/src/tools/definitions/std/README.md +350 -0
- package/src/tools/definitions/std/analysis/analyze-codebase.yml +72 -0
- package/src/tools/definitions/std/analysis/analyze-diff.yml +182 -0
- package/src/tools/definitions/std/analysis/analyze-git-diff.yml +70 -0
- package/src/tools/definitions/std/analysis/analyze-impact.yml +78 -0
- package/src/tools/definitions/std/analysis/analyze-requirements.yml +105 -0
- package/src/tools/definitions/std/analysis/brainstorm-options.yml +106 -0
- package/src/tools/definitions/std/analysis/build-graph.yml +154 -0
- package/src/tools/definitions/std/analysis/clarify-requirements.yml +90 -0
- package/src/tools/definitions/std/analysis/detect-context.yml +109 -0
- package/src/tools/definitions/std/analysis/detect-layers.yml +125 -0
- package/src/tools/definitions/std/analysis/generate-tour.yml +102 -0
- package/src/tools/definitions/std/analysis/search-enhance.yml +105 -0
- package/src/tools/definitions/std/backlog/add.yml +51 -0
- package/src/tools/definitions/std/backlog/decide.yml +39 -0
- package/src/tools/definitions/std/backlog/github-sync.yml +161 -0
- package/src/tools/definitions/std/backlog/list.yml +53 -0
- package/src/tools/definitions/std/backlog/load.yml +46 -0
- package/src/tools/definitions/std/backlog/resolve.yml +37 -0
- package/src/tools/definitions/std/backlog/update.yml +42 -0
- package/src/tools/definitions/std/bugfix/diagnose.yml +68 -0
- package/src/tools/definitions/std/bugfix/fix.yml +66 -0
- package/src/tools/definitions/std/bugfix/verify.yml +69 -0
- package/src/tools/definitions/std/constraint/check-decomposition.yml +103 -0
- package/src/tools/definitions/std/constraint/check-feature-list.yml +77 -0
- package/src/tools/definitions/std/constraint/check-progress.yml +97 -0
- package/src/tools/definitions/std/constraint/generate-report.yml +147 -0
- package/src/tools/definitions/std/deploy/commit-push.yml +33 -0
- package/src/tools/definitions/std/deploy/deploy-backend.yml +37 -0
- package/src/tools/definitions/std/deploy/deploy-frontend.yml +37 -0
- package/src/tools/definitions/std/deploy/rollback.yml +148 -0
- package/src/tools/definitions/std/design/analyze-architecture-impact.yml +113 -0
- package/src/tools/definitions/std/design/design-api.yml +55 -0
- package/src/tools/definitions/std/design/design-architecture.yml +97 -0
- package/src/tools/definitions/std/design/design-db.yml +81 -0
- package/src/tools/definitions/std/design/generate-spec.yml +182 -0
- package/src/tools/definitions/std/development/develop-api.yml +85 -0
- package/src/tools/definitions/std/development/develop-backend.yml +88 -0
- package/src/tools/definitions/std/development/develop-frontend.yml +87 -0
- package/src/tools/definitions/std/development/develop-shared-types.yml +74 -0
- package/src/tools/definitions/std/development/develop-task.yml +122 -0
- package/src/tools/definitions/std/development/develop-tests.yml +76 -0
- package/src/tools/definitions/std/development/execute-batch.yml +152 -0
- package/src/tools/definitions/std/development/fix-issues.yml +100 -0
- package/src/tools/definitions/std/development/implement-task.yml +124 -0
- package/src/tools/definitions/std/development/review-fix-cycle.yml +232 -0
- package/src/tools/definitions/std/evolution/implement.yml +125 -0
- package/src/tools/definitions/std/evolution/prioritize.yml +112 -0
- package/src/tools/definitions/std/evolution/report-gap.yml +166 -0
- package/src/tools/definitions/std/file/read.yml +21 -0
- package/src/tools/definitions/std/governance/aggregate-opinions.sh +201 -0
- package/src/tools/definitions/std/governance/aggregate-opinions.yml +79 -0
- package/src/tools/definitions/std/governance/audit-task.yml +178 -0
- package/src/tools/definitions/std/governance/cast-vote.yml +129 -0
- package/src/tools/definitions/std/governance/collect-issues.yml +16 -0
- package/src/tools/definitions/std/governance/create-signed-document.yml +23 -0
- package/src/tools/definitions/std/governance/create-voting-session.yml +101 -0
- package/src/tools/definitions/std/governance/define-stance.sh +243 -0
- package/src/tools/definitions/std/governance/define-stance.yml +82 -0
- package/src/tools/definitions/std/governance/generate-review-report.yml +23 -0
- package/src/tools/definitions/std/governance/impeach.yml +179 -0
- package/src/tools/definitions/std/governance/multi-stance-review.yml +154 -0
- package/src/tools/definitions/std/governance/prepare-artifact.yml +20 -0
- package/src/tools/definitions/std/governance/review-spec-approval.yml +262 -0
- package/src/tools/definitions/std/governance/rollback.yml +186 -0
- package/src/tools/definitions/std/governance/stance-review.yml +149 -0
- package/src/tools/definitions/std/governance/track-effect.yml +199 -0
- package/src/tools/definitions/std/governance/vote-tally.yml +144 -0
- package/src/tools/definitions/std/patch/execute.yml +51 -0
- package/src/tools/definitions/std/planning/generate-tasks.yml +36 -0
- package/src/tools/definitions/std/planning/load-tasks.yml +44 -0
- package/src/tools/definitions/std/planning/split-batch.yml +481 -0
- package/src/tools/definitions/std/planning/split-tasks.yml +359 -0
- package/src/tools/definitions/std/planning/update-tasks.yml +51 -0
- package/src/tools/definitions/std/planning/validate-tasks.yml +46 -0
- package/src/tools/definitions/std/project/decide-next-workflow.yml +38 -0
- package/src/tools/definitions/std/project/load-state.yml +31 -0
- package/src/tools/definitions/std/project/save-state.yml +32 -0
- package/src/tools/definitions/std/quality/check-quality.yml +241 -0
- package/src/tools/definitions/std/quality/debug-systematic.yml +163 -0
- package/src/tools/definitions/std/quality/handle-feedback.yml +108 -0
- package/src/tools/definitions/std/quality/review-code.yml +128 -0
- package/src/tools/definitions/std/quality/review-spec.yml +140 -0
- package/src/tools/definitions/std/quality/review-task.yml +190 -0
- package/src/tools/definitions/std/quality/run-tests.yml +80 -0
- package/src/tools/definitions/std/quick/analyze.yml +56 -0
- package/src/tools/definitions/std/quick/implement.yml +67 -0
- package/src/tools/definitions/std/quick/verify.yml +71 -0
- package/src/tools/definitions/std/verification/verify_completion.yml +113 -0
- package/src/tools/definitions/std/verification/wait-condition.yml +107 -0
- package/src/tools/index.ts +5 -0
- package/src/tools/loader.ts +216 -0
- package/src/tools/paths.ts +15 -0
- package/src/tools/registry.ts +128 -0
- package/src/tools/types.ts +46 -0
- package/src/types/__tests__/types.test.ts +86 -0
- package/src/types/checkpoint.ts +174 -0
- package/src/types/constraint.ts +335 -0
- package/src/types/cso.ts +37 -0
- package/src/types/enforcement.ts +48 -0
- package/src/types/index.ts +59 -0
- package/src/types/iron-law.ts +50 -0
- package/src/types/passes-gate.ts +185 -0
- package/src/types/performance.ts +295 -0
- package/src/types/project-config.ts +251 -0
- package/src/types/session.ts +132 -0
- package/src/types/spec.ts +91 -0
- package/src/types/trace.ts +228 -0
- package/src/utils/detect-source-roots.ts +114 -0
- package/src/utils/exec.ts +61 -0
- package/src/verification/CONTEXT.md +23 -0
- package/src/verification/__tests__/loop.test.ts +303 -0
- package/src/verification/__tests__/rules-based.test.ts +240 -0
- package/src/verification/index.ts +3 -0
- package/src/verification/loop.ts +137 -0
- package/src/verification/rules-based.ts +153 -0
- package/src/verification/types.ts +81 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* harness validate 命令
|
|
3
|
+
*
|
|
4
|
+
* 验证检查点是否满足
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import * as fs from 'fs/promises';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import * as yaml from 'js-yaml';
|
|
11
|
+
import { CheckpointValidator } from '../../core/validators/checkpoint';
|
|
12
|
+
import type { Checkpoint, CheckpointContext } from '../../types/checkpoint';
|
|
13
|
+
import { detectSourceRoots } from '../../utils/detect-source-roots';
|
|
14
|
+
|
|
15
|
+
export interface ValidateOptions {
|
|
16
|
+
/** 检查点文件路径 */
|
|
17
|
+
file?: string;
|
|
18
|
+
/** 项目路径 */
|
|
19
|
+
projectPath?: string;
|
|
20
|
+
/** 是否严格模式 */
|
|
21
|
+
strict?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 默认检查点文件路径
|
|
26
|
+
*/
|
|
27
|
+
const DEFAULT_CHECKPOINT_FILE = '.harness/checkpoints.yml';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 加载检查点配置
|
|
31
|
+
*/
|
|
32
|
+
async function loadCheckpoints(filePath: string): Promise<Checkpoint[]> {
|
|
33
|
+
try {
|
|
34
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
35
|
+
const data = yaml.load(content) as { checkpoints?: Checkpoint[] };
|
|
36
|
+
return data.checkpoints || [];
|
|
37
|
+
} catch (error) {
|
|
38
|
+
console.log(chalk.yellow(`⚠️ 未找到检查点文件: ${filePath}`));
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 执行检查点验证
|
|
45
|
+
*/
|
|
46
|
+
export async function validate(options: ValidateOptions): Promise<void> {
|
|
47
|
+
console.log(chalk.blue('🔍 验证检查点...'));
|
|
48
|
+
|
|
49
|
+
const projectPath = options.projectPath || process.cwd();
|
|
50
|
+
const checkpointFile = options.file || path.join(projectPath, DEFAULT_CHECKPOINT_FILE);
|
|
51
|
+
|
|
52
|
+
// 加载检查点
|
|
53
|
+
const checkpoints = await loadCheckpoints(checkpointFile);
|
|
54
|
+
|
|
55
|
+
if (checkpoints.length === 0) {
|
|
56
|
+
console.log(chalk.gray('没有定义检查点,跳过验证'));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
console.log(chalk.gray(`检查点文件: ${checkpointFile}`));
|
|
61
|
+
console.log(chalk.gray(`检查点数量: ${checkpoints.length}`));
|
|
62
|
+
console.log();
|
|
63
|
+
|
|
64
|
+
// 构建上下文
|
|
65
|
+
const context: CheckpointContext = {
|
|
66
|
+
projectPath,
|
|
67
|
+
workdir: projectPath,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// 执行验证
|
|
71
|
+
const validator = CheckpointValidator.getInstance();
|
|
72
|
+
const results = [];
|
|
73
|
+
|
|
74
|
+
for (const checkpoint of checkpoints) {
|
|
75
|
+
const result = await validator.validate(checkpoint, context);
|
|
76
|
+
results.push(result);
|
|
77
|
+
|
|
78
|
+
if (result.passed) {
|
|
79
|
+
console.log(chalk.green(`✅ ${checkpoint.id}: 通过`));
|
|
80
|
+
} else {
|
|
81
|
+
console.log(chalk.red(`❌ ${checkpoint.id}: 失败`));
|
|
82
|
+
result.checks.forEach(check => {
|
|
83
|
+
if (!check.passed) {
|
|
84
|
+
console.log(chalk.red(` - ${check.checkId}: ${check.message || check.error}`));
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 统计结果
|
|
91
|
+
const passed = results.filter(r => r.passed).length;
|
|
92
|
+
const failed = results.filter(r => !r.passed).length;
|
|
93
|
+
|
|
94
|
+
console.log();
|
|
95
|
+
console.log(chalk.gray(`通过: ${passed}/${results.length}`));
|
|
96
|
+
|
|
97
|
+
if (failed > 0) {
|
|
98
|
+
console.log(chalk.red(`\n🛑 ${failed} 个检查点未通过`));
|
|
99
|
+
if (options.strict) {
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
console.log(chalk.green('\n✅ 所有检查点验证通过'));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 默认检查点列表(供 init 和 upgrade 共用)
|
|
109
|
+
*/
|
|
110
|
+
export const DEFAULT_CHECKPOINTS: Checkpoint[] = [
|
|
111
|
+
{
|
|
112
|
+
id: 'build-success',
|
|
113
|
+
name: '构建成功',
|
|
114
|
+
checks: [
|
|
115
|
+
{
|
|
116
|
+
id: 'build-command',
|
|
117
|
+
type: 'command_success',
|
|
118
|
+
config: { command: 'npm run build' },
|
|
119
|
+
message: '构建命令必须成功执行',
|
|
120
|
+
},
|
|
121
|
+
],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: 'test-pass',
|
|
125
|
+
name: '测试通过',
|
|
126
|
+
checks: [
|
|
127
|
+
{
|
|
128
|
+
id: 'test-command',
|
|
129
|
+
type: 'command_success',
|
|
130
|
+
config: { command: 'npm test' },
|
|
131
|
+
message: '测试命令必须成功执行',
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
id: 'no-console',
|
|
137
|
+
name: '无 console.log',
|
|
138
|
+
checks: [
|
|
139
|
+
{
|
|
140
|
+
id: 'check-console',
|
|
141
|
+
type: 'output_not_contains',
|
|
142
|
+
config: {
|
|
143
|
+
command: 'grep -r "console.log" src/ || true',
|
|
144
|
+
expected: '',
|
|
145
|
+
},
|
|
146
|
+
message: '源代码中不应包含 console.log',
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
];
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 创建示例检查点文件
|
|
154
|
+
*/
|
|
155
|
+
export async function createExampleCheckpoint(projectPath: string): Promise<void> {
|
|
156
|
+
const filePath = path.join(projectPath, DEFAULT_CHECKPOINT_FILE);
|
|
157
|
+
const dir = path.dirname(filePath);
|
|
158
|
+
|
|
159
|
+
await fs.mkdir(dir, { recursive: true });
|
|
160
|
+
|
|
161
|
+
// 动态替换 no-console 检查点的源目录
|
|
162
|
+
const roots = detectSourceRoots(projectPath);
|
|
163
|
+
let checkpoints = DEFAULT_CHECKPOINTS;
|
|
164
|
+
if (roots.length > 0) {
|
|
165
|
+
checkpoints = DEFAULT_CHECKPOINTS.map(cp => {
|
|
166
|
+
if (cp.id === 'no-console') {
|
|
167
|
+
return {
|
|
168
|
+
...cp,
|
|
169
|
+
checks: cp.checks.map(c => {
|
|
170
|
+
if (c.id === 'check-console') {
|
|
171
|
+
return { ...c, config: { command: `grep -r "console.log" ${roots.join(' ')} || true` } };
|
|
172
|
+
}
|
|
173
|
+
return c;
|
|
174
|
+
}),
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return cp;
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const content = yaml.dump({ checkpoints }, { indent: 2 });
|
|
182
|
+
await fs.writeFile(filePath, content, 'utf-8');
|
|
183
|
+
|
|
184
|
+
console.log(chalk.green(`✅ 已创建示例检查点文件: ${filePath}`));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 默认 Resolutions(RKB — 约束 → 已知解法映射)
|
|
189
|
+
*/
|
|
190
|
+
const DEFAULT_RESOLUTIONS = {
|
|
191
|
+
no_claim_without_evidence: {
|
|
192
|
+
title: 'commit message 缺少验证证据',
|
|
193
|
+
fix: '在 commit message body 中附上验证输出:\n`npx harness check --staged` | `npx harness validate` | `npm test -- --coverage`\n确认全部通过后重新 commit。',
|
|
194
|
+
},
|
|
195
|
+
capability_sync: {
|
|
196
|
+
title: '缺少 CAPABILITIES.md',
|
|
197
|
+
fix: '在项目根目录创建 CAPABILITIES.md,列出所有模块能力清单。运行 `npx harness sync-docs` 可自动生成模板。',
|
|
198
|
+
},
|
|
199
|
+
context_doc_sync: {
|
|
200
|
+
title: '关键目录缺少 CONTEXT.md',
|
|
201
|
+
fix: '在 required_dirs 目录下创建 CONTEXT.md。运行 `npx harness sync-docs` 可自动生成模板。',
|
|
202
|
+
},
|
|
203
|
+
no_coverage_decrease: {
|
|
204
|
+
title: '测试覆盖率下降',
|
|
205
|
+
fix: '运行 `npm test -- --coverage` 查看当前覆盖率。新增文件必须有对应的测试文件。',
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* 创建示例 Resolutions 文件(RKB dogfood)
|
|
211
|
+
*/
|
|
212
|
+
export async function createExampleResolutions(projectPath: string): Promise<void> {
|
|
213
|
+
const harnessDir = path.join(projectPath, '.harness');
|
|
214
|
+
const filePath = path.join(harnessDir, 'resolutions.json');
|
|
215
|
+
|
|
216
|
+
await fs.mkdir(harnessDir, { recursive: true });
|
|
217
|
+
|
|
218
|
+
const content = JSON.stringify(DEFAULT_RESOLUTIONS, null, 2);
|
|
219
|
+
await fs.writeFile(filePath, content, 'utf-8');
|
|
220
|
+
|
|
221
|
+
console.log(chalk.green(`✅ 已创建 Resolutions 文件: ${filePath}`));
|
|
222
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConstraintLifecycleRunner 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeEach } from '@jest/globals';
|
|
6
|
+
import { ConstraintLifecycleRunner, type ExecutionResult } from '../lifecycle-runner';
|
|
7
|
+
import { ConstraintRegistry } from '../registry';
|
|
8
|
+
import type { ConstraintProposal } from '../../monitoring/constraint-evolver';
|
|
9
|
+
|
|
10
|
+
function makeProposal(overrides: Partial<ConstraintProposal> = {}): ConstraintProposal {
|
|
11
|
+
return {
|
|
12
|
+
id: 'test-proposal-1',
|
|
13
|
+
proposedAt: Date.now(),
|
|
14
|
+
diagnosisId: 'diag-1',
|
|
15
|
+
constraintId: 'no_fix_without_root_cause',
|
|
16
|
+
type: 'change_level',
|
|
17
|
+
content: { proposed: 'tip', description: '降级为 tip' },
|
|
18
|
+
reasoning: 'low intercept rate',
|
|
19
|
+
expectedOutcome: 'fewer interruptions',
|
|
20
|
+
risk: { level: 'low', description: 'safe' },
|
|
21
|
+
implementation: { files: [], linesChanged: 0, testsRequired: false },
|
|
22
|
+
status: 'accepted',
|
|
23
|
+
...overrides,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe('ConstraintLifecycleRunner', () => {
|
|
28
|
+
let runner: ConstraintLifecycleRunner;
|
|
29
|
+
let registry: ConstraintRegistry;
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
registry = new ConstraintRegistry();
|
|
33
|
+
runner = new ConstraintLifecycleRunner(registry);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('execute - change_level', () => {
|
|
37
|
+
it('应该成功降级质量层约束', () => {
|
|
38
|
+
const proposal = makeProposal({
|
|
39
|
+
constraintId: 'no_fix_without_root_cause',
|
|
40
|
+
type: 'change_level',
|
|
41
|
+
content: { proposed: 'tip', description: '降级' },
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const result = runner.execute(proposal);
|
|
45
|
+
|
|
46
|
+
expect(result.success).toBe(true);
|
|
47
|
+
expect(result.action).toBe('degrade');
|
|
48
|
+
expect(result.details).toContain('Degraded');
|
|
49
|
+
|
|
50
|
+
// 验证 registry 状态已改变
|
|
51
|
+
const constraint = registry.get('no_fix_without_root_cause');
|
|
52
|
+
expect(constraint?.deprecationStatus).toBe('deprecated');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('应该拒绝安全层约束的 level 变更', () => {
|
|
56
|
+
const proposal = makeProposal({
|
|
57
|
+
constraintId: 'no_bypass_checkpoint',
|
|
58
|
+
type: 'change_level',
|
|
59
|
+
content: { proposed: 'guideline', description: '降级' },
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const result = runner.execute(proposal);
|
|
63
|
+
|
|
64
|
+
expect(result.success).toBe(false);
|
|
65
|
+
expect(result.details).toContain('safety-layer');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('应该返回失败当约束不存在', () => {
|
|
69
|
+
const proposal = makeProposal({
|
|
70
|
+
constraintId: 'nonexistent_constraint',
|
|
71
|
+
type: 'change_level',
|
|
72
|
+
content: { proposed: 'tip', description: '降级' },
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const result = runner.execute(proposal);
|
|
76
|
+
|
|
77
|
+
expect(result.success).toBe(false);
|
|
78
|
+
expect(result.details).toContain('not found');
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe('execute - add_exception', () => {
|
|
83
|
+
it('应该成功添加例外', () => {
|
|
84
|
+
const proposal = makeProposal({
|
|
85
|
+
constraintId: 'no_fix_without_root_cause',
|
|
86
|
+
type: 'add_exception',
|
|
87
|
+
content: { proposed: 'new_exception', description: '新增例外' },
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const result = runner.execute(proposal);
|
|
91
|
+
|
|
92
|
+
expect(result.success).toBe(true);
|
|
93
|
+
expect(result.action).toBe('add_exception');
|
|
94
|
+
expect(result.details).toContain('new_exception');
|
|
95
|
+
|
|
96
|
+
const constraint = registry.get('no_fix_without_root_cause');
|
|
97
|
+
expect(constraint?.exceptions).toContain('new_exception');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('应该拒绝重复的例外', () => {
|
|
101
|
+
const proposal = makeProposal({
|
|
102
|
+
constraintId: 'no_fix_without_root_cause',
|
|
103
|
+
type: 'add_exception',
|
|
104
|
+
content: { proposed: 'simple_typo', description: '重复例外' },
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const result = runner.execute(proposal);
|
|
108
|
+
|
|
109
|
+
expect(result.success).toBe(false);
|
|
110
|
+
expect(result.details).toContain('already exists');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('execute - adjust_trigger', () => {
|
|
115
|
+
it('应该成功修改触发条件', () => {
|
|
116
|
+
const proposal = makeProposal({
|
|
117
|
+
constraintId: 'no_fix_without_root_cause',
|
|
118
|
+
type: 'adjust_trigger',
|
|
119
|
+
content: { proposed: ['code_implementation', 'code_implementation'], description: '扩展触发' },
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
const result = runner.execute(proposal);
|
|
123
|
+
|
|
124
|
+
expect(result.success).toBe(true);
|
|
125
|
+
expect(result.action).toBe('adjust_trigger');
|
|
126
|
+
|
|
127
|
+
const constraint = registry.get('no_fix_without_root_cause');
|
|
128
|
+
expect(constraint?.trigger).toEqual(['code_implementation', 'code_implementation']);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('execute - modify_message', () => {
|
|
133
|
+
it('应该成功修改消息', () => {
|
|
134
|
+
const proposal = makeProposal({
|
|
135
|
+
constraintId: 'no_fix_without_root_cause',
|
|
136
|
+
type: 'modify_message',
|
|
137
|
+
content: { proposed: '新的消息', description: '更新消息' },
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const result = runner.execute(proposal);
|
|
141
|
+
|
|
142
|
+
expect(result.success).toBe(true);
|
|
143
|
+
expect(result.action).toBe('modify_message');
|
|
144
|
+
|
|
145
|
+
const constraint = registry.get('no_fix_without_root_cause');
|
|
146
|
+
expect(constraint?.message).toBe('新的消息');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('execute - unsupported type', () => {
|
|
151
|
+
it('应该拒绝不支持的提案类型', () => {
|
|
152
|
+
const proposal = makeProposal({
|
|
153
|
+
type: 'new_constraint' as any,
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const result = runner.execute(proposal);
|
|
157
|
+
|
|
158
|
+
expect(result.success).toBe(false);
|
|
159
|
+
expect(result.details).toContain('Unsupported');
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe('executeBatch', () => {
|
|
164
|
+
it('应该批量执行多个提案', () => {
|
|
165
|
+
const proposals = [
|
|
166
|
+
makeProposal({
|
|
167
|
+
id: 'p1',
|
|
168
|
+
constraintId: 'no_fix_without_root_cause',
|
|
169
|
+
type: 'modify_message',
|
|
170
|
+
content: { proposed: '消息1', description: '更新' },
|
|
171
|
+
}),
|
|
172
|
+
makeProposal({
|
|
173
|
+
id: 'p2',
|
|
174
|
+
constraintId: 'no_code_without_test',
|
|
175
|
+
type: 'modify_message',
|
|
176
|
+
content: { proposed: '消息2', description: '更新' },
|
|
177
|
+
}),
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
const results = runner.executeBatch(proposals);
|
|
181
|
+
|
|
182
|
+
expect(results).toHaveLength(2);
|
|
183
|
+
expect(results[0].success).toBe(true);
|
|
184
|
+
expect(results[1].success).toBe(true);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('rollbackConstraint', () => {
|
|
189
|
+
it('应该成功回滚已降级的约束', () => {
|
|
190
|
+
// 先降级
|
|
191
|
+
const proposal = makeProposal({
|
|
192
|
+
constraintId: 'no_fix_without_root_cause',
|
|
193
|
+
type: 'change_level',
|
|
194
|
+
content: { proposed: 'tip', description: '降级' },
|
|
195
|
+
});
|
|
196
|
+
runner.execute(proposal);
|
|
197
|
+
|
|
198
|
+
const constraint = registry.get('no_fix_without_root_cause');
|
|
199
|
+
expect(constraint?.deprecationStatus).toBe('deprecated');
|
|
200
|
+
|
|
201
|
+
// 回滚
|
|
202
|
+
const success = runner.rollbackConstraint('no_fix_without_root_cause', 'guideline');
|
|
203
|
+
expect(success).toBe(true);
|
|
204
|
+
|
|
205
|
+
const after = registry.get('no_fix_without_root_cause');
|
|
206
|
+
expect(after?.deprecationStatus).toBe('active');
|
|
207
|
+
expect(after?.level).toBe('guideline');
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
describe('scheduleDeprecation', () => {
|
|
212
|
+
it('应该成功设置弃用计划', () => {
|
|
213
|
+
const success = runner.scheduleDeprecation('no_fix_without_root_cause', {
|
|
214
|
+
targetLevel: 'tip',
|
|
215
|
+
reason: 'low usage',
|
|
216
|
+
rollbackable: true,
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
expect(success).toBe(true);
|
|
220
|
+
|
|
221
|
+
const constraint = registry.get('no_fix_without_root_cause');
|
|
222
|
+
expect(constraint?.deprecationStatus).toBe('scheduled');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
it('应该拒绝安全层约束的弃用计划', () => {
|
|
226
|
+
const success = runner.scheduleDeprecation('no_bypass_checkpoint', {
|
|
227
|
+
targetLevel: 'guideline',
|
|
228
|
+
reason: 'test',
|
|
229
|
+
rollbackable: false,
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
expect(success).toBe(false);
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
describe('getRegistry', () => {
|
|
237
|
+
it('应该返回内部 registry 实例', () => {
|
|
238
|
+
expect(runner.getRegistry()).toBe(registry);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('应该在无参数时创建默认 registry', () => {
|
|
242
|
+
const defaultRunner = new ConstraintLifecycleRunner();
|
|
243
|
+
expect(defaultRunner.getRegistry()).toBeDefined();
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
});
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConstraintRegistry 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { ConstraintRegistry } from '../registry';
|
|
6
|
+
import { IRON_LAWS, GUIDELINES, TIPS } from '../../core/constraints/definitions';
|
|
7
|
+
|
|
8
|
+
const SAFETY_COUNT = Object.keys(IRON_LAWS).length; // 7
|
|
9
|
+
const QUALITY_COUNT = Object.keys(GUIDELINES).length + Object.keys(TIPS).length; // 13
|
|
10
|
+
|
|
11
|
+
describe('ConstraintRegistry', () => {
|
|
12
|
+
let registry: ConstraintRegistry;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
registry = new ConstraintRegistry();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('get', () => {
|
|
19
|
+
it('应该获取安全层约束', () => {
|
|
20
|
+
const constraint = registry.get('no_bypass_checkpoint');
|
|
21
|
+
expect(constraint).toBeDefined();
|
|
22
|
+
expect(constraint?.layer).toBe('safety');
|
|
23
|
+
expect(constraint?.permanent).toBe(false); // 所有层级均可退化
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('应该获取质量层约束', () => {
|
|
27
|
+
const constraint = registry.get('no_any_type');
|
|
28
|
+
expect(constraint).toBeDefined();
|
|
29
|
+
expect(constraint?.layer).toBe('quality');
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('应该返回 undefined 对于不存在的约束', () => {
|
|
33
|
+
expect(registry.get('nonexistent')).toBeUndefined();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('getAll', () => {
|
|
38
|
+
it('应该返回所有约束', () => {
|
|
39
|
+
const all = registry.getAll();
|
|
40
|
+
expect(all.length).toBe(SAFETY_COUNT + QUALITY_COUNT);
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('getByLayer', () => {
|
|
45
|
+
it('应该按层过滤', () => {
|
|
46
|
+
const safety = registry.getByLayer('safety');
|
|
47
|
+
const quality = registry.getByLayer('quality');
|
|
48
|
+
|
|
49
|
+
expect(safety.every(c => c.layer === 'safety')).toBe(true);
|
|
50
|
+
expect(quality.every(c => c.layer === 'quality')).toBe(true);
|
|
51
|
+
expect(safety.length).toBe(SAFETY_COUNT);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('getByStatus', () => {
|
|
56
|
+
it('应该按退化状态过滤', () => {
|
|
57
|
+
const active = registry.getByStatus('active');
|
|
58
|
+
expect(active.length).toBe(registry.getAll().length);
|
|
59
|
+
|
|
60
|
+
const deprecated = registry.getByStatus('deprecated');
|
|
61
|
+
expect(deprecated.length).toBe(0);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('getByTrigger', () => {
|
|
66
|
+
it('应该按触发条件查找', () => {
|
|
67
|
+
const constraints = registry.getByTrigger('code_implementation');
|
|
68
|
+
expect(constraints.length).toBeGreaterThan(0);
|
|
69
|
+
expect(constraints.every(c => {
|
|
70
|
+
const triggers = Array.isArray(c.trigger) ? c.trigger : [c.trigger];
|
|
71
|
+
return triggers.includes('code_implementation');
|
|
72
|
+
})).toBe(true);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('degrade', () => {
|
|
77
|
+
it('应该降低约束级别', () => {
|
|
78
|
+
const result = registry.degrade('no_any_type');
|
|
79
|
+
expect(result).toBe(true);
|
|
80
|
+
|
|
81
|
+
const constraint = registry.get('no_any_type');
|
|
82
|
+
expect(constraint?.level).toBe('tip');
|
|
83
|
+
expect(constraint?.deprecationStatus).toBe('deprecated');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('安全层约束也可以退化(Iron Law <5% 高阈值)', () => {
|
|
87
|
+
const result = registry.degrade('no_bypass_checkpoint');
|
|
88
|
+
expect(result).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('不应该退化非 active 约束', () => {
|
|
92
|
+
registry.degrade('no_any_type');
|
|
93
|
+
const result = registry.degrade('no_any_type');
|
|
94
|
+
expect(result).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
describe('rollback', () => {
|
|
99
|
+
it('应该回滚退化', () => {
|
|
100
|
+
registry.degrade('no_any_type');
|
|
101
|
+
const result = registry.rollback('no_any_type', 'guideline');
|
|
102
|
+
expect(result).toBe(true);
|
|
103
|
+
|
|
104
|
+
const constraint = registry.get('no_any_type');
|
|
105
|
+
expect(constraint?.level).toBe('guideline');
|
|
106
|
+
expect(constraint?.deprecationStatus).toBe('active');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('不应该回滚不存在的约束', () => {
|
|
110
|
+
const result = registry.rollback('nonexistent', 'guideline');
|
|
111
|
+
expect(result).toBe(false);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe('scheduleDeprecation', () => {
|
|
116
|
+
it('应该为质量层约束安排退化', () => {
|
|
117
|
+
const result = registry.scheduleDeprecation('no_skill_without_test', {
|
|
118
|
+
targetLevel: 'tip',
|
|
119
|
+
reason: '测试能力提升',
|
|
120
|
+
rollbackable: true,
|
|
121
|
+
});
|
|
122
|
+
expect(result).toBe(true);
|
|
123
|
+
|
|
124
|
+
const constraint = registry.get('no_skill_without_test');
|
|
125
|
+
expect(constraint?.deprecationStatus).toBe('scheduled');
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('不应该为安全层约束安排退化', () => {
|
|
129
|
+
const result = registry.scheduleDeprecation('no_bypass_checkpoint', {
|
|
130
|
+
targetLevel: 'tip',
|
|
131
|
+
reason: 'test',
|
|
132
|
+
rollbackable: true,
|
|
133
|
+
});
|
|
134
|
+
expect(result).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('getLayerStats', () => {
|
|
139
|
+
it('应该返回层统计', () => {
|
|
140
|
+
const stats = registry.getLayerStats();
|
|
141
|
+
expect(stats.length).toBe(2);
|
|
142
|
+
|
|
143
|
+
const safetyStats = stats.find(s => s.layer === 'safety')!;
|
|
144
|
+
expect(safetyStats.totalConstraints).toBe(SAFETY_COUNT);
|
|
145
|
+
expect(safetyStats.active).toBe(safetyStats.totalConstraints);
|
|
146
|
+
|
|
147
|
+
const qualityStats = stats.find(s => s.layer === 'quality')!;
|
|
148
|
+
expect(qualityStats.totalConstraints).toBe(QUALITY_COUNT);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
describe('toLegacyConstraints', () => {
|
|
153
|
+
it('应该转换为旧格式', () => {
|
|
154
|
+
const legacy = registry.toLegacyConstraints();
|
|
155
|
+
expect(legacy.length).toBe(registry.getAll().length);
|
|
156
|
+
expect(legacy[0]).toHaveProperty('id');
|
|
157
|
+
expect(legacy[0]).toHaveProperty('rule');
|
|
158
|
+
expect(legacy[0]).toHaveProperty('level');
|
|
159
|
+
expect(legacy[0]).not.toHaveProperty('layer');
|
|
160
|
+
expect(legacy[0]).not.toHaveProperty('deprecationStatus');
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('register / remove', () => {
|
|
165
|
+
it('应该注册自定义约束', () => {
|
|
166
|
+
registry.register({
|
|
167
|
+
id: 'custom',
|
|
168
|
+
rule: 'CUSTOM',
|
|
169
|
+
message: '自定义约束',
|
|
170
|
+
level: 'guideline',
|
|
171
|
+
trigger: 'code_implementation',
|
|
172
|
+
enforcement: 'custom-check',
|
|
173
|
+
layer: 'quality',
|
|
174
|
+
deprecationStatus: 'active',
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
expect(registry.get('custom')).toBeDefined();
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
it('应该移除约束', () => {
|
|
181
|
+
registry.register({
|
|
182
|
+
id: 'temp',
|
|
183
|
+
rule: 'TEMP',
|
|
184
|
+
message: '临时',
|
|
185
|
+
level: 'tip',
|
|
186
|
+
trigger: 'commit',
|
|
187
|
+
enforcement: 'temp',
|
|
188
|
+
layer: 'quality',
|
|
189
|
+
deprecationStatus: 'active',
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
expect(registry.remove('temp')).toBe(true);
|
|
193
|
+
expect(registry.get('temp')).toBeUndefined();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
});
|