@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,404 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* constraint-evolver 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect } from '@jest/globals';
|
|
6
|
+
import { ConstraintEvolver } from '../monitoring/constraint-evolver';
|
|
7
|
+
import type { Diagnosis } from '../monitoring/constraint-doctor';
|
|
8
|
+
|
|
9
|
+
describe('ConstraintEvolver', () => {
|
|
10
|
+
describe('constructor', () => {
|
|
11
|
+
it('应该创建实例', () => {
|
|
12
|
+
const evolver = new ConstraintEvolver();
|
|
13
|
+
expect(evolver).toBeDefined();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('支持自定义 proposalsDir', () => {
|
|
17
|
+
const evolver = new ConstraintEvolver('/tmp/test-proposals');
|
|
18
|
+
expect(evolver).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('propose', () => {
|
|
23
|
+
it('应该根据诊断生成提案', async () => {
|
|
24
|
+
const evolver = new ConstraintEvolver();
|
|
25
|
+
|
|
26
|
+
const diagnosis: Diagnosis = {
|
|
27
|
+
anomalyId: 'anomaly-001',
|
|
28
|
+
constraintId: 'no_fix_without_root_cause',
|
|
29
|
+
diagnosedAt: Date.now(),
|
|
30
|
+
rootCause: {
|
|
31
|
+
primary: '例外使用过多',
|
|
32
|
+
evidence: [],
|
|
33
|
+
},
|
|
34
|
+
impact: {
|
|
35
|
+
severity: 'medium',
|
|
36
|
+
scope: 'single_project',
|
|
37
|
+
userImpact: '质量下降',
|
|
38
|
+
},
|
|
39
|
+
recommendations: [
|
|
40
|
+
{
|
|
41
|
+
type: 'add_exception',
|
|
42
|
+
content: '添加 simple_typo 例外',
|
|
43
|
+
expectedOutcome: '减少误报',
|
|
44
|
+
implementationCost: 'low',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
needsChange: true,
|
|
48
|
+
urgency: 'medium',
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const proposal = await evolver.propose(diagnosis);
|
|
52
|
+
|
|
53
|
+
expect(proposal).toBeDefined();
|
|
54
|
+
expect(proposal?.constraintId).toBe('no_fix_without_root_cause');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('needsChange=false 应该返回 null', async () => {
|
|
58
|
+
const evolver = new ConstraintEvolver();
|
|
59
|
+
|
|
60
|
+
const diagnosis: Diagnosis = {
|
|
61
|
+
anomalyId: 'anomaly-no-change',
|
|
62
|
+
constraintId: 'test_constraint',
|
|
63
|
+
diagnosedAt: Date.now(),
|
|
64
|
+
rootCause: { primary: '正常', evidence: [] },
|
|
65
|
+
impact: { severity: 'low', scope: 'single_project', userImpact: '无' },
|
|
66
|
+
recommendations: [],
|
|
67
|
+
needsChange: false,
|
|
68
|
+
urgency: 'low',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const proposal = await evolver.propose(diagnosis);
|
|
72
|
+
expect(proposal).toBeNull();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('recommendations 为空应该返回 null', async () => {
|
|
76
|
+
const evolver = new ConstraintEvolver();
|
|
77
|
+
|
|
78
|
+
const diagnosis: Diagnosis = {
|
|
79
|
+
anomalyId: 'anomaly-no-rec',
|
|
80
|
+
constraintId: 'test_constraint',
|
|
81
|
+
diagnosedAt: Date.now(),
|
|
82
|
+
rootCause: { primary: '测试', evidence: [] },
|
|
83
|
+
impact: { severity: 'medium', scope: 'single_project', userImpact: '测试' },
|
|
84
|
+
recommendations: [],
|
|
85
|
+
needsChange: true,
|
|
86
|
+
urgency: 'medium',
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const proposal = await evolver.propose(diagnosis);
|
|
90
|
+
expect(proposal).toBeNull();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('应该处理 adjust_threshold 类型', async () => {
|
|
94
|
+
const evolver = new ConstraintEvolver();
|
|
95
|
+
|
|
96
|
+
const diagnosis: Diagnosis = {
|
|
97
|
+
anomalyId: 'anomaly-002',
|
|
98
|
+
constraintId: 'no_fix_without_root_cause',
|
|
99
|
+
diagnosedAt: Date.now(),
|
|
100
|
+
rootCause: { primary: '触发条件过宽', evidence: [] },
|
|
101
|
+
impact: { severity: 'low', scope: 'single_project', userImpact: '少量误报' },
|
|
102
|
+
recommendations: [
|
|
103
|
+
{ type: 'adjust_threshold', content: '缩小触发范围', expectedOutcome: '减少误报', implementationCost: 'low' },
|
|
104
|
+
],
|
|
105
|
+
needsChange: true,
|
|
106
|
+
urgency: 'low',
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const proposal = await evolver.propose(diagnosis);
|
|
110
|
+
expect(proposal).toBeDefined();
|
|
111
|
+
expect(proposal?.type).toBe('adjust_trigger');
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('应该处理 modify_constraint 类型', async () => {
|
|
115
|
+
const evolver = new ConstraintEvolver();
|
|
116
|
+
|
|
117
|
+
const diagnosis: Diagnosis = {
|
|
118
|
+
anomalyId: 'anomaly-003',
|
|
119
|
+
constraintId: 'no_fix_without_root_cause',
|
|
120
|
+
diagnosedAt: Date.now(),
|
|
121
|
+
rootCause: { primary: '消息不清晰', evidence: [] },
|
|
122
|
+
impact: { severity: 'low', scope: 'single_project', userImpact: '用户体验差' },
|
|
123
|
+
recommendations: [
|
|
124
|
+
{ type: 'modify_constraint', content: '优化提示消息', expectedOutcome: '更清晰', implementationCost: 'low' },
|
|
125
|
+
],
|
|
126
|
+
needsChange: true,
|
|
127
|
+
urgency: 'low',
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const proposal = await evolver.propose(diagnosis);
|
|
131
|
+
expect(proposal).toBeDefined();
|
|
132
|
+
expect(proposal?.type).toBe('modify_message');
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('proposeBatch', () => {
|
|
137
|
+
it('应该批量生成提案', async () => {
|
|
138
|
+
const evolver = new ConstraintEvolver();
|
|
139
|
+
|
|
140
|
+
const diagnoses: Diagnosis[] = [
|
|
141
|
+
{
|
|
142
|
+
anomalyId: 'batch-001',
|
|
143
|
+
constraintId: 'no_fix_without_root_cause',
|
|
144
|
+
diagnosedAt: Date.now(),
|
|
145
|
+
rootCause: { primary: '测试1', evidence: [] },
|
|
146
|
+
impact: { severity: 'low', scope: 'single_project', userImpact: '无' },
|
|
147
|
+
recommendations: [{ type: 'add_exception', content: 'test', expectedOutcome: 'ok', implementationCost: 'low' }],
|
|
148
|
+
needsChange: true,
|
|
149
|
+
urgency: 'low',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
anomalyId: 'batch-002',
|
|
153
|
+
constraintId: 'no_code_without_test',
|
|
154
|
+
diagnosedAt: Date.now(),
|
|
155
|
+
rootCause: { primary: '测试2', evidence: [] },
|
|
156
|
+
impact: { severity: 'low', scope: 'single_project', userImpact: '无' },
|
|
157
|
+
recommendations: [{ type: 'add_exception', content: 'test', expectedOutcome: 'ok', implementationCost: 'low' }],
|
|
158
|
+
needsChange: true,
|
|
159
|
+
urgency: 'low',
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
anomalyId: 'batch-003',
|
|
163
|
+
constraintId: 'unknown_constraint',
|
|
164
|
+
diagnosedAt: Date.now(),
|
|
165
|
+
rootCause: { primary: '测试3', evidence: [] },
|
|
166
|
+
impact: { severity: 'low', scope: 'single_project', userImpact: '无' },
|
|
167
|
+
recommendations: [],
|
|
168
|
+
needsChange: false,
|
|
169
|
+
urgency: 'low',
|
|
170
|
+
},
|
|
171
|
+
];
|
|
172
|
+
|
|
173
|
+
const proposals = await evolver.proposeBatch(diagnoses);
|
|
174
|
+
expect(proposals.length).toBe(2);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('review', () => {
|
|
179
|
+
it('Iron Law 非添加例外应该被拒绝', async () => {
|
|
180
|
+
const evolver = new ConstraintEvolver();
|
|
181
|
+
|
|
182
|
+
const diagnosis: Diagnosis = {
|
|
183
|
+
anomalyId: 'review-001',
|
|
184
|
+
constraintId: 'no_bypass_checkpoint', // iron_law
|
|
185
|
+
diagnosedAt: Date.now(),
|
|
186
|
+
rootCause: { primary: '测试', evidence: [] },
|
|
187
|
+
impact: { severity: 'high', scope: 'single_project', userImpact: '严重' },
|
|
188
|
+
recommendations: [{ type: 'modify_constraint', content: '修改消息', expectedOutcome: '更清晰', implementationCost: 'low' }],
|
|
189
|
+
needsChange: true,
|
|
190
|
+
urgency: 'high',
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const proposal = await evolver.propose(diagnosis);
|
|
194
|
+
const review = evolver.review(proposal!);
|
|
195
|
+
|
|
196
|
+
expect(review.accepted).toBe(false);
|
|
197
|
+
expect(review.comment).toContain('Iron Law');
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('高风险提案应该被拒绝', async () => {
|
|
201
|
+
const evolver = new ConstraintEvolver();
|
|
202
|
+
|
|
203
|
+
const diagnosis: Diagnosis = {
|
|
204
|
+
anomalyId: 'review-002',
|
|
205
|
+
constraintId: 'no_fix_without_root_cause',
|
|
206
|
+
diagnosedAt: Date.now(),
|
|
207
|
+
rootCause: { primary: '高风险', evidence: [] },
|
|
208
|
+
impact: { severity: 'high', scope: 'multiple_projects', userImpact: '严重' },
|
|
209
|
+
recommendations: [{ type: 'add_exception', content: 'test', expectedOutcome: '高风险', implementationCost: 'high' }],
|
|
210
|
+
needsChange: true,
|
|
211
|
+
urgency: 'high',
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const proposal = await evolver.propose(diagnosis);
|
|
215
|
+
const review = evolver.review(proposal!);
|
|
216
|
+
|
|
217
|
+
expect(review.accepted).toBe(false);
|
|
218
|
+
expect(review.comment).toContain('高风险');
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('低风险 + 有测试应该通过', async () => {
|
|
222
|
+
const evolver = new ConstraintEvolver();
|
|
223
|
+
|
|
224
|
+
const diagnosis: Diagnosis = {
|
|
225
|
+
anomalyId: 'review-003',
|
|
226
|
+
constraintId: 'no_fix_without_root_cause',
|
|
227
|
+
diagnosedAt: Date.now(),
|
|
228
|
+
rootCause: { primary: '低风险变更', evidence: [] },
|
|
229
|
+
impact: { severity: 'low', scope: 'single_project', userImpact: '无' },
|
|
230
|
+
recommendations: [{ type: 'add_exception', content: 'test', expectedOutcome: '低风险', implementationCost: 'low' }],
|
|
231
|
+
needsChange: true,
|
|
232
|
+
urgency: 'low',
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const proposal = await evolver.propose(diagnosis);
|
|
236
|
+
const review = evolver.review(proposal!);
|
|
237
|
+
|
|
238
|
+
expect(review.accepted).toBe(true);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('中风险需要人工审核', async () => {
|
|
242
|
+
const evolver = new ConstraintEvolver();
|
|
243
|
+
|
|
244
|
+
const diagnosis: Diagnosis = {
|
|
245
|
+
anomalyId: 'review-004',
|
|
246
|
+
constraintId: 'no_fix_without_root_cause',
|
|
247
|
+
diagnosedAt: Date.now(),
|
|
248
|
+
rootCause: { primary: '中风险', evidence: [] },
|
|
249
|
+
impact: { severity: 'medium', scope: 'single_project', userImpact: '中等' },
|
|
250
|
+
recommendations: [{ type: 'adjust_threshold', content: 'test', expectedOutcome: '中风险', implementationCost: 'high' }],
|
|
251
|
+
needsChange: true,
|
|
252
|
+
urgency: 'medium',
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const proposal = await evolver.propose(diagnosis);
|
|
256
|
+
const review = evolver.review(proposal!);
|
|
257
|
+
|
|
258
|
+
expect(review.accepted).toBe(false);
|
|
259
|
+
expect(review.comment).toContain('人工审核');
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
describe('implement', () => {
|
|
264
|
+
it('add_exception 应该生成正确指令', async () => {
|
|
265
|
+
const evolver = new ConstraintEvolver();
|
|
266
|
+
|
|
267
|
+
const diagnosis: Diagnosis = {
|
|
268
|
+
anomalyId: 'impl-001',
|
|
269
|
+
constraintId: 'no_fix_without_root_cause',
|
|
270
|
+
diagnosedAt: Date.now(),
|
|
271
|
+
rootCause: { primary: '测试', evidence: [] },
|
|
272
|
+
impact: { severity: 'low', scope: 'single_project', userImpact: '无' },
|
|
273
|
+
recommendations: [{ type: 'add_exception', content: 'test_exception', expectedOutcome: 'ok', implementationCost: 'low' }],
|
|
274
|
+
needsChange: true,
|
|
275
|
+
urgency: 'low',
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const proposal = await evolver.propose(diagnosis);
|
|
279
|
+
const impl = evolver.implement(proposal!);
|
|
280
|
+
|
|
281
|
+
expect(impl.instructions.length).toBeGreaterThan(0);
|
|
282
|
+
expect(impl.filesToModify).toContain('src/core/constraints/definitions.ts');
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('remove_exception 应该生成正确指令', async () => {
|
|
286
|
+
const evolver = new ConstraintEvolver();
|
|
287
|
+
|
|
288
|
+
const proposal = {
|
|
289
|
+
id: 'test-remove',
|
|
290
|
+
proposedAt: Date.now(),
|
|
291
|
+
diagnosisId: 'diag-001',
|
|
292
|
+
constraintId: 'test',
|
|
293
|
+
type: 'remove_exception' as const,
|
|
294
|
+
content: { proposed: 'old_exception', description: 'test' },
|
|
295
|
+
reasoning: 'test',
|
|
296
|
+
expectedOutcome: 'ok',
|
|
297
|
+
risk: { level: 'low' as const, description: 'test' },
|
|
298
|
+
implementation: { files: ['test.ts'], linesChanged: 5, testsRequired: true },
|
|
299
|
+
status: 'proposed' as const,
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
const impl = evolver.implement(proposal);
|
|
303
|
+
expect(impl.instructions.some(i => i.includes('移除'))).toBe(true);
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it('adjust_trigger 应该生成正确指令', async () => {
|
|
307
|
+
const evolver = new ConstraintEvolver();
|
|
308
|
+
|
|
309
|
+
const proposal = {
|
|
310
|
+
id: 'test-adjust',
|
|
311
|
+
proposedAt: Date.now(),
|
|
312
|
+
diagnosisId: 'diag-002',
|
|
313
|
+
constraintId: 'test',
|
|
314
|
+
type: 'adjust_trigger' as const,
|
|
315
|
+
content: { current: 'old_trigger', proposed: 'new_trigger', description: 'test' },
|
|
316
|
+
reasoning: 'test',
|
|
317
|
+
expectedOutcome: 'ok',
|
|
318
|
+
risk: { level: 'low' as const, description: 'test' },
|
|
319
|
+
implementation: { files: ['test.ts'], linesChanged: 5, testsRequired: true },
|
|
320
|
+
status: 'proposed' as const,
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const impl = evolver.implement(proposal);
|
|
324
|
+
expect(impl.instructions.some(i => i.includes('调整'))).toBe(true);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it('change_level 应该生成正确指令', async () => {
|
|
328
|
+
const evolver = new ConstraintEvolver();
|
|
329
|
+
|
|
330
|
+
const proposal = {
|
|
331
|
+
id: 'test-level',
|
|
332
|
+
proposedAt: Date.now(),
|
|
333
|
+
diagnosisId: 'diag-003',
|
|
334
|
+
constraintId: 'test',
|
|
335
|
+
type: 'change_level' as const,
|
|
336
|
+
content: { current: 'iron_law', proposed: 'guideline', description: 'test' },
|
|
337
|
+
reasoning: 'test',
|
|
338
|
+
expectedOutcome: 'ok',
|
|
339
|
+
risk: { level: 'low' as const, description: 'test' },
|
|
340
|
+
implementation: { files: ['test.ts'], linesChanged: 5, testsRequired: true },
|
|
341
|
+
status: 'proposed' as const,
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
const impl = evolver.implement(proposal);
|
|
345
|
+
expect(impl.instructions.some(i => i.includes('层级'))).toBe(true);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('modify_message 应该生成正确指令', async () => {
|
|
349
|
+
const evolver = new ConstraintEvolver();
|
|
350
|
+
|
|
351
|
+
const proposal = {
|
|
352
|
+
id: 'test-msg',
|
|
353
|
+
proposedAt: Date.now(),
|
|
354
|
+
diagnosisId: 'diag-004',
|
|
355
|
+
constraintId: 'test',
|
|
356
|
+
type: 'modify_message' as const,
|
|
357
|
+
content: { current: 'old msg', proposed: 'new msg', description: 'test' },
|
|
358
|
+
reasoning: 'test',
|
|
359
|
+
expectedOutcome: 'ok',
|
|
360
|
+
risk: { level: 'low' as const, description: 'test' },
|
|
361
|
+
implementation: { files: ['test.ts'], linesChanged: 5, testsRequired: true },
|
|
362
|
+
status: 'proposed' as const,
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
const impl = evolver.implement(proposal);
|
|
366
|
+
expect(impl.instructions.some(i => i.includes('修改'))).toBe(true);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it('new_constraint 应该生成正确指令', async () => {
|
|
370
|
+
const evolver = new ConstraintEvolver();
|
|
371
|
+
|
|
372
|
+
const proposal = {
|
|
373
|
+
id: 'test-new',
|
|
374
|
+
proposedAt: Date.now(),
|
|
375
|
+
diagnosisId: 'diag-005',
|
|
376
|
+
constraintId: 'test',
|
|
377
|
+
type: 'new_constraint' as const,
|
|
378
|
+
content: { proposed: { id: 'new_constraint', level: 'guideline', rule: 'test' }, description: 'test' },
|
|
379
|
+
reasoning: 'test',
|
|
380
|
+
expectedOutcome: 'ok',
|
|
381
|
+
risk: { level: 'low' as const, description: 'test' },
|
|
382
|
+
implementation: { files: ['test.ts'], linesChanged: 20, testsRequired: true },
|
|
383
|
+
status: 'proposed' as const,
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
const impl = evolver.implement(proposal);
|
|
387
|
+
expect(impl.filesToModify.length).toBeGreaterThan(1);
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
describe('listProposals', () => {
|
|
392
|
+
it('应该返回所有提案', () => {
|
|
393
|
+
const evolver = new ConstraintEvolver();
|
|
394
|
+
const proposals = evolver.listProposals();
|
|
395
|
+
expect(Array.isArray(proposals)).toBe(true);
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
it('应该返回待审核提案', () => {
|
|
399
|
+
const evolver = new ConstraintEvolver();
|
|
400
|
+
const pending = evolver.listProposals('proposed');
|
|
401
|
+
expect(Array.isArray(pending)).toBe(true);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConstraintViolationHandler 测试(S4)
|
|
3
|
+
*/
|
|
4
|
+
import { describe, it, expect } from '@jest/globals';
|
|
5
|
+
import {
|
|
6
|
+
ConstraintViolationHandler,
|
|
7
|
+
executeWithBlock,
|
|
8
|
+
executeWithCollect,
|
|
9
|
+
executeWithSafeBoolean,
|
|
10
|
+
} from '../failure/constraint-handler';
|
|
11
|
+
import { ConstraintViolationError } from '../types/constraint';
|
|
12
|
+
import type { ConstraintCheckResult } from '../types/constraint';
|
|
13
|
+
|
|
14
|
+
function makePassingResult(): ConstraintCheckResult {
|
|
15
|
+
return {
|
|
16
|
+
ironLaws: [{ id: 'test_law', level: 'iron_law', satisfied: true, checkedAt: new Date() }],
|
|
17
|
+
guidelines: [],
|
|
18
|
+
tips: [],
|
|
19
|
+
passed: true,
|
|
20
|
+
warningCount: 0,
|
|
21
|
+
tipCount: 0,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function makeFailingResult(): ConstraintCheckResult {
|
|
26
|
+
return {
|
|
27
|
+
ironLaws: [{ id: 'test_law', level: 'iron_law', satisfied: false, message: '违规', checkedAt: new Date() }],
|
|
28
|
+
guidelines: [{ id: 'guide', level: 'guideline', satisfied: false, checkedAt: new Date() }],
|
|
29
|
+
tips: [],
|
|
30
|
+
passed: false,
|
|
31
|
+
warningCount: 1,
|
|
32
|
+
tipCount: 0,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function makeThrowingFn() {
|
|
37
|
+
return async () => {
|
|
38
|
+
throw new ConstraintViolationError({
|
|
39
|
+
id: 'test_law',
|
|
40
|
+
level: 'iron_law',
|
|
41
|
+
satisfied: false,
|
|
42
|
+
message: '铁律违规',
|
|
43
|
+
checkedAt: new Date(),
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('ConstraintViolationHandler', () => {
|
|
49
|
+
const handler = new ConstraintViolationHandler();
|
|
50
|
+
|
|
51
|
+
describe('BLOCK strategy', () => {
|
|
52
|
+
it('通过时返回结果', async () => {
|
|
53
|
+
const result = await handler.execute(() => Promise.resolve(makePassingResult()), 'BLOCK');
|
|
54
|
+
expect(result.strategy).toBe('BLOCK');
|
|
55
|
+
expect(result.hasViolation).toBe(false);
|
|
56
|
+
expect(result.checkResult?.passed).toBe(true);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('违规时抛出异常', async () => {
|
|
60
|
+
await expect(
|
|
61
|
+
handler.execute(makeThrowingFn(), 'BLOCK')
|
|
62
|
+
).rejects.toThrow(ConstraintViolationError);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('checkResult 包含 failed 时 hasViolation=true', async () => {
|
|
66
|
+
const result = await handler.execute(() => Promise.resolve(makeFailingResult()), 'BLOCK');
|
|
67
|
+
expect(result.hasViolation).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('COLLECT strategy', () => {
|
|
72
|
+
it('通过时返回完整结果', async () => {
|
|
73
|
+
const result = await handler.execute(() => Promise.resolve(makePassingResult()), 'COLLECT');
|
|
74
|
+
expect(result.strategy).toBe('COLLECT');
|
|
75
|
+
expect(result.hasViolation).toBe(false);
|
|
76
|
+
expect(result.checkResult).toBeDefined();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('checkResult 有违规时 hasViolation=true', async () => {
|
|
80
|
+
const result = await handler.execute(() => Promise.resolve(makeFailingResult()), 'COLLECT');
|
|
81
|
+
expect(result.hasViolation).toBe(true);
|
|
82
|
+
expect(result.violationCount).toBe(2); // 1 iron + 1 guideline
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('抛出异常时捕获并返回空结果', async () => {
|
|
86
|
+
const result = await handler.execute(makeThrowingFn(), 'COLLECT');
|
|
87
|
+
expect(result.strategy).toBe('COLLECT');
|
|
88
|
+
expect(result.hasViolation).toBe(true);
|
|
89
|
+
expect(result.checkResult).toBeDefined();
|
|
90
|
+
expect(result.checkResult!.passed).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe('SAFE_BOOLEAN strategy', () => {
|
|
95
|
+
it('通过时返回 false', async () => {
|
|
96
|
+
const result = await handler.execute(() => Promise.resolve(makePassingResult()), 'SAFE_BOOLEAN');
|
|
97
|
+
expect(result.strategy).toBe('SAFE_BOOLEAN');
|
|
98
|
+
expect(result.hasViolation).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('违规时返回 true', async () => {
|
|
102
|
+
const result = await handler.execute(() => Promise.resolve(makeFailingResult()), 'SAFE_BOOLEAN');
|
|
103
|
+
expect(result.hasViolation).toBe(true);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('抛出异常时返回 true', async () => {
|
|
107
|
+
const result = await handler.execute(makeThrowingFn(), 'SAFE_BOOLEAN');
|
|
108
|
+
expect(result.hasViolation).toBe(true);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe('快捷函数', () => {
|
|
114
|
+
it('executeWithBlock 通过', async () => {
|
|
115
|
+
const result = await executeWithBlock(() => Promise.resolve(makePassingResult()));
|
|
116
|
+
expect(result.strategy).toBe('BLOCK');
|
|
117
|
+
expect(result.hasViolation).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('executeWithBlock 违规抛出', async () => {
|
|
121
|
+
await expect(
|
|
122
|
+
executeWithBlock(makeThrowingFn())
|
|
123
|
+
).rejects.toThrow(ConstraintViolationError);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it('executeWithCollect 异常不抛出', async () => {
|
|
127
|
+
const result = await executeWithCollect(makeThrowingFn());
|
|
128
|
+
expect(result.hasViolation).toBe(true);
|
|
129
|
+
expect(result.checkResult).toBeDefined();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('executeWithSafeBoolean 异常返回 true', async () => {
|
|
133
|
+
const result = await executeWithSafeBoolean(makeThrowingFn());
|
|
134
|
+
expect(result.hasViolation).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @spec HZ-002
|
|
3
|
+
* @acceptance AC-001-1, AC-001-2, AC-001-3, AC-001-4
|
|
4
|
+
*
|
|
5
|
+
* Progressive Loader 测试
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { ProgressiveLoader } from '../../context/progressive-loader';
|
|
9
|
+
import { TokenEstimator, TokenBudget, AdaptiveTokenBudget } from '../../context/token-budget';
|
|
10
|
+
|
|
11
|
+
describe('TokenEstimator', () => {
|
|
12
|
+
it('should estimate English text', () => {
|
|
13
|
+
const tokens = TokenEstimator.estimateText('Hello World');
|
|
14
|
+
expect(tokens).toBeGreaterThan(0);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should estimate Chinese text', () => {
|
|
18
|
+
const tokens = TokenEstimator.estimateText('你好世界');
|
|
19
|
+
expect(tokens).toBeGreaterThan(0);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('should estimate object', () => {
|
|
23
|
+
const tokens = TokenEstimator.estimateObject({ foo: 'bar', num: 123 });
|
|
24
|
+
expect(tokens).toBeGreaterThan(0);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('TokenBudget', () => {
|
|
29
|
+
it('should manage budget correctly', () => {
|
|
30
|
+
const budget = new TokenBudget(1000);
|
|
31
|
+
expect(budget.total).toBe(1000);
|
|
32
|
+
expect(budget.remaining).toBe(1000);
|
|
33
|
+
|
|
34
|
+
budget.consume(300);
|
|
35
|
+
expect(budget.used).toBe(300);
|
|
36
|
+
expect(budget.remaining).toBe(700);
|
|
37
|
+
expect(budget.status).toBe('healthy');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should reserve and release budget', () => {
|
|
41
|
+
const budget = new TokenBudget(1000);
|
|
42
|
+
budget.reserve(200);
|
|
43
|
+
expect(budget.remaining).toBe(800);
|
|
44
|
+
|
|
45
|
+
budget.release(100);
|
|
46
|
+
expect(budget.remaining).toBe(900);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should detect budget exceeded', () => {
|
|
50
|
+
const budget = new TokenBudget(100);
|
|
51
|
+
budget.consume(80);
|
|
52
|
+
expect(budget.status).toBe('critical');
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('ProgressiveLoader', () => {
|
|
57
|
+
it('should load in chunks', async () => {
|
|
58
|
+
const loader = new ProgressiveLoader();
|
|
59
|
+
const items = Array.from({ length: 100 }, (_, i) => i);
|
|
60
|
+
const chunks: number[][] = [];
|
|
61
|
+
|
|
62
|
+
await loader.loadInChunks(items, {
|
|
63
|
+
chunkSize: 10,
|
|
64
|
+
onChunk: (chunk: number[]) => { chunks.push(chunk); }
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
expect(chunks.length).toBe(10);
|
|
68
|
+
expect(chunks[0].length).toBe(10);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('should respect token budget with truncate', async () => {
|
|
72
|
+
const loader = new ProgressiveLoader();
|
|
73
|
+
const items = [
|
|
74
|
+
{ content: 'a'.repeat(100) },
|
|
75
|
+
{ content: 'b'.repeat(100) },
|
|
76
|
+
{ content: 'c'.repeat(100) },
|
|
77
|
+
{ content: 'd'.repeat(100) },
|
|
78
|
+
];
|
|
79
|
+
|
|
80
|
+
const result = await loader.loadWithBudget(items, {
|
|
81
|
+
budget: 60,
|
|
82
|
+
estimator: (item: { content: string }) => TokenEstimator.estimateText(item.content),
|
|
83
|
+
onBudgetExceeded: 'truncate',
|
|
84
|
+
minItems: 1
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
expect(result.items.length).toBeLessThanOrEqual(3);
|
|
88
|
+
expect(result.truncated).toBe(true);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should respect token budget with skip', async () => {
|
|
92
|
+
const loader = new ProgressiveLoader();
|
|
93
|
+
const items = [
|
|
94
|
+
{ content: 'a'.repeat(100) },
|
|
95
|
+
{ content: 'b'.repeat(1000) },
|
|
96
|
+
{ content: 'c'.repeat(100) },
|
|
97
|
+
];
|
|
98
|
+
|
|
99
|
+
const result = await loader.loadWithBudget(items, {
|
|
100
|
+
budget: 60,
|
|
101
|
+
estimator: (item: { content: string }) => TokenEstimator.estimateText(item.content),
|
|
102
|
+
onBudgetExceeded: 'skip',
|
|
103
|
+
minItems: 1
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
expect(result.skipped).toBeGreaterThan(0);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('AdaptiveTokenBudget', () => {
|
|
111
|
+
it('should suggest budget adjustment', () => {
|
|
112
|
+
const budget = new AdaptiveTokenBudget(1000);
|
|
113
|
+
|
|
114
|
+
for (let i = 0; i < 5; i++) {
|
|
115
|
+
budget.recordActualUsage(950);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const suggestion = budget.suggestBudgetAdjustment();
|
|
119
|
+
expect(suggestion.action).toBe('increase');
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should predict future needs', () => {
|
|
123
|
+
const budget = new AdaptiveTokenBudget(1000);
|
|
124
|
+
budget.recordActualUsage(500);
|
|
125
|
+
budget.recordActualUsage(600);
|
|
126
|
+
budget.recordActualUsage(550);
|
|
127
|
+
|
|
128
|
+
const prediction = budget.predictNeed();
|
|
129
|
+
expect(prediction).toBeGreaterThan(0);
|
|
130
|
+
});
|
|
131
|
+
});
|