@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,321 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ContractGate 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeAll, afterAll, beforeEach } from '@jest/globals';
|
|
6
|
+
import { ContractGate } from '../gates/contract';
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
|
|
10
|
+
describe('ContractGate', () => {
|
|
11
|
+
const tempDir = path.join(process.cwd(), 'temp-test-contract');
|
|
12
|
+
const contractFile = path.join(tempDir, 'openapi.yaml');
|
|
13
|
+
const oldContractFile = path.join(tempDir, 'openapi-old.yaml');
|
|
14
|
+
const jsonContractFile = path.join(tempDir, 'openapi.json');
|
|
15
|
+
|
|
16
|
+
beforeAll(() => {
|
|
17
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterAll(() => {
|
|
21
|
+
try {
|
|
22
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
23
|
+
} catch {
|
|
24
|
+
// ignore
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
// 清理临时文件
|
|
30
|
+
try {
|
|
31
|
+
fs.rmSync(contractFile, { force: true });
|
|
32
|
+
fs.rmSync(oldContractFile, { force: true });
|
|
33
|
+
fs.rmSync(jsonContractFile, { force: true });
|
|
34
|
+
} catch {
|
|
35
|
+
// ignore
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
describe('check', () => {
|
|
40
|
+
it('禁用时应该返回通过', async () => {
|
|
41
|
+
const gate = new ContractGate({ enabled: false });
|
|
42
|
+
|
|
43
|
+
const result = await gate.check({
|
|
44
|
+
projectId: 'test',
|
|
45
|
+
projectPath: tempDir,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(result.passed).toBe(true);
|
|
49
|
+
expect(result.message).toContain('禁用');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('无契约文件时应该通过', async () => {
|
|
53
|
+
const gate = new ContractGate({ enabled: true });
|
|
54
|
+
|
|
55
|
+
const result = await gate.check({
|
|
56
|
+
projectId: 'test',
|
|
57
|
+
projectPath: tempDir,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
expect(result.passed).toBe(true);
|
|
61
|
+
expect(result.message).toContain('未找到');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('有效契约文件应该通过', async () => {
|
|
65
|
+
fs.writeFileSync(contractFile, `
|
|
66
|
+
openapi: 3.0.0
|
|
67
|
+
info:
|
|
68
|
+
title: Test API
|
|
69
|
+
version: 1.0.0
|
|
70
|
+
paths:
|
|
71
|
+
/test:
|
|
72
|
+
get:
|
|
73
|
+
summary: Test endpoint
|
|
74
|
+
/users:
|
|
75
|
+
post:
|
|
76
|
+
summary: Create user
|
|
77
|
+
`);
|
|
78
|
+
|
|
79
|
+
const gate = new ContractGate({ enabled: true });
|
|
80
|
+
|
|
81
|
+
const result = await gate.check({
|
|
82
|
+
projectId: 'test',
|
|
83
|
+
projectPath: tempDir,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
expect(result.passed).toBe(true);
|
|
87
|
+
expect(result.gate).toBe('contract');
|
|
88
|
+
expect(result.details?.endpoints).toBe(2);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('契约缺少版本应该失败', async () => {
|
|
92
|
+
fs.writeFileSync(contractFile, `
|
|
93
|
+
info:
|
|
94
|
+
title: Test API
|
|
95
|
+
paths:
|
|
96
|
+
/test:
|
|
97
|
+
get:
|
|
98
|
+
summary: Test
|
|
99
|
+
`);
|
|
100
|
+
|
|
101
|
+
const gate = new ContractGate({ enabled: true });
|
|
102
|
+
|
|
103
|
+
const result = await gate.check({
|
|
104
|
+
projectId: 'test',
|
|
105
|
+
projectPath: tempDir,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
expect(result.passed).toBe(false);
|
|
109
|
+
expect(result.message).toContain('缺少');
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('契约无端点应该失败', async () => {
|
|
113
|
+
fs.writeFileSync(contractFile, `
|
|
114
|
+
openapi: 3.0.0
|
|
115
|
+
info:
|
|
116
|
+
title: Empty API
|
|
117
|
+
version: 1.0.0
|
|
118
|
+
paths:
|
|
119
|
+
`);
|
|
120
|
+
|
|
121
|
+
const gate = new ContractGate({ enabled: true });
|
|
122
|
+
|
|
123
|
+
const result = await gate.check({
|
|
124
|
+
projectId: 'test',
|
|
125
|
+
projectPath: tempDir,
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
expect(result.passed).toBe(false);
|
|
129
|
+
expect(result.message).toContain('端点');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('JSON 契约应该正确解析', async () => {
|
|
133
|
+
fs.writeFileSync(jsonContractFile, JSON.stringify({
|
|
134
|
+
openapi: '3.0.0',
|
|
135
|
+
info: { title: 'Test', version: '1.0' },
|
|
136
|
+
paths: {
|
|
137
|
+
'/test': { get: { summary: 'Test' } },
|
|
138
|
+
'/users': { post: { summary: 'Create' } },
|
|
139
|
+
},
|
|
140
|
+
}));
|
|
141
|
+
|
|
142
|
+
const gate = new ContractGate({ enabled: true, contractPath: 'openapi.json' });
|
|
143
|
+
|
|
144
|
+
const result = await gate.check({
|
|
145
|
+
projectId: 'test',
|
|
146
|
+
projectPath: tempDir,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
expect(result.passed).toBe(true);
|
|
150
|
+
expect(result.details?.endpoints).toBe(2);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('破坏性变更检测 - 端点删除', async () => {
|
|
154
|
+
// 旧契约
|
|
155
|
+
fs.writeFileSync(oldContractFile, `
|
|
156
|
+
openapi: 3.0.0
|
|
157
|
+
paths:
|
|
158
|
+
/test:
|
|
159
|
+
get:
|
|
160
|
+
summary: Test
|
|
161
|
+
/users:
|
|
162
|
+
get:
|
|
163
|
+
summary: List users
|
|
164
|
+
`);
|
|
165
|
+
|
|
166
|
+
// 新契约(删除了 /users)
|
|
167
|
+
fs.writeFileSync(contractFile, `
|
|
168
|
+
openapi: 3.0.0
|
|
169
|
+
paths:
|
|
170
|
+
/test:
|
|
171
|
+
get:
|
|
172
|
+
summary: Test
|
|
173
|
+
`);
|
|
174
|
+
|
|
175
|
+
const gate = new ContractGate({ enabled: true, allowBreakingChanges: false });
|
|
176
|
+
|
|
177
|
+
const result = await gate.check({
|
|
178
|
+
projectId: 'test',
|
|
179
|
+
projectPath: tempDir,
|
|
180
|
+
oldContractPath: oldContractFile,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
expect(result.passed).toBe(false);
|
|
184
|
+
expect(result.message).toContain('破坏性变更');
|
|
185
|
+
expect(result.details?.breakingChanges?.length).toBe(1);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it('允许破坏性变更时应该通过', async () => {
|
|
189
|
+
fs.writeFileSync(oldContractFile, `
|
|
190
|
+
openapi: 3.0.0
|
|
191
|
+
paths:
|
|
192
|
+
/test:
|
|
193
|
+
get:
|
|
194
|
+
summary: Test
|
|
195
|
+
/users:
|
|
196
|
+
get:
|
|
197
|
+
summary: List
|
|
198
|
+
`);
|
|
199
|
+
|
|
200
|
+
fs.writeFileSync(contractFile, `
|
|
201
|
+
openapi: 3.0.0
|
|
202
|
+
paths:
|
|
203
|
+
/test:
|
|
204
|
+
get:
|
|
205
|
+
summary: Test
|
|
206
|
+
`);
|
|
207
|
+
|
|
208
|
+
const gate = new ContractGate({ enabled: true, allowBreakingChanges: true });
|
|
209
|
+
|
|
210
|
+
const result = await gate.check({
|
|
211
|
+
projectId: 'test',
|
|
212
|
+
projectPath: tempDir,
|
|
213
|
+
oldContractPath: oldContractFile,
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// 允许破坏性变更时,即使检测到变更也应该通过
|
|
217
|
+
expect(result.passed).toBe(true);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('新增端点不是破坏性变更', async () => {
|
|
221
|
+
fs.writeFileSync(oldContractFile, `
|
|
222
|
+
openapi: 3.0.0
|
|
223
|
+
paths:
|
|
224
|
+
/test:
|
|
225
|
+
get:
|
|
226
|
+
summary: Test
|
|
227
|
+
`);
|
|
228
|
+
|
|
229
|
+
fs.writeFileSync(contractFile, `
|
|
230
|
+
openapi: 3.0.0
|
|
231
|
+
paths:
|
|
232
|
+
/test:
|
|
233
|
+
get:
|
|
234
|
+
summary: Test
|
|
235
|
+
/new:
|
|
236
|
+
post:
|
|
237
|
+
summary: New endpoint
|
|
238
|
+
`);
|
|
239
|
+
|
|
240
|
+
const gate = new ContractGate({ enabled: true });
|
|
241
|
+
|
|
242
|
+
const result = await gate.check({
|
|
243
|
+
projectId: 'test',
|
|
244
|
+
projectPath: tempDir,
|
|
245
|
+
oldContractPath: oldContractFile,
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
expect(result.passed).toBe(true);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('使用 newContractPath 参数', async () => {
|
|
252
|
+
const customContract = path.join(tempDir, 'custom.yaml');
|
|
253
|
+
fs.writeFileSync(customContract, `
|
|
254
|
+
openapi: 3.0.0
|
|
255
|
+
paths:
|
|
256
|
+
/custom:
|
|
257
|
+
get:
|
|
258
|
+
summary: Custom
|
|
259
|
+
`);
|
|
260
|
+
|
|
261
|
+
const gate = new ContractGate({ enabled: true });
|
|
262
|
+
|
|
263
|
+
const result = await gate.check({
|
|
264
|
+
projectId: 'test',
|
|
265
|
+
projectPath: tempDir,
|
|
266
|
+
newContractPath: customContract,
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
expect(result.passed).toBe(true);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('无效 YAML 应该返回解析失败', async () => {
|
|
273
|
+
fs.writeFileSync(contractFile, 'invalid: yaml: content: [broken');
|
|
274
|
+
|
|
275
|
+
const gate = new ContractGate({ enabled: true });
|
|
276
|
+
|
|
277
|
+
const result = await gate.check({
|
|
278
|
+
projectId: 'test',
|
|
279
|
+
projectPath: tempDir,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// 基础验证会检查版本和端点,无效 YAML 可能没有这些
|
|
283
|
+
expect(result).toBeDefined();
|
|
284
|
+
});
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
describe('配置方法', () => {
|
|
288
|
+
it('setContractPath 应该更新路径', () => {
|
|
289
|
+
const gate = new ContractGate();
|
|
290
|
+
gate.setContractPath('new/path.yaml');
|
|
291
|
+
|
|
292
|
+
const config = gate.getConfig();
|
|
293
|
+
expect(config.contractPath).toBe('new/path.yaml');
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it('getConfig 应该返回当前配置', () => {
|
|
297
|
+
const gate = new ContractGate({
|
|
298
|
+
enabled: true,
|
|
299
|
+
strict: false,
|
|
300
|
+
allowBreakingChanges: true,
|
|
301
|
+
contractPath: 'api.yaml',
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
const config = gate.getConfig();
|
|
305
|
+
expect(config.enabled).toBe(true);
|
|
306
|
+
expect(config.strict).toBe(false);
|
|
307
|
+
expect(config.allowBreakingChanges).toBe(true);
|
|
308
|
+
expect(config.contractPath).toBe('api.yaml');
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('默认配置', () => {
|
|
312
|
+
const gate = new ContractGate();
|
|
313
|
+
const config = gate.getConfig();
|
|
314
|
+
|
|
315
|
+
expect(config.enabled).toBe(true);
|
|
316
|
+
expect(config.strict).toBe(true);
|
|
317
|
+
expect(config.allowBreakingChanges).toBe(false);
|
|
318
|
+
expect(config.contractPath).toBe('openapi.yaml');
|
|
319
|
+
});
|
|
320
|
+
});
|
|
321
|
+
});
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CrossProjectChecker 测试
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, expect, beforeAll, afterAll, beforeEach, jest } from '@jest/globals';
|
|
6
|
+
import { checkCrossProjectContracts, checkDocCodeConsistency, type CrossProjectConfig } from '../architecture/cross-project-checker';
|
|
7
|
+
import * as fs from 'fs';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
|
|
10
|
+
const TEST_CONFIG: CrossProjectConfig = {
|
|
11
|
+
dependencies: {
|
|
12
|
+
'agent-studio': ['agent-runtime', 'harness'],
|
|
13
|
+
'agent-runtime': ['harness', 'agent-workflows'],
|
|
14
|
+
'agent-workflows': ['harness'],
|
|
15
|
+
'harness': [],
|
|
16
|
+
},
|
|
17
|
+
contractLocations: {
|
|
18
|
+
'studio-runtime': [
|
|
19
|
+
'agent-runtime/src/api/types.ts',
|
|
20
|
+
'agent-studio/src/services/runtime-client.ts',
|
|
21
|
+
],
|
|
22
|
+
'runtime-harness': [
|
|
23
|
+
'harness/src/index.ts',
|
|
24
|
+
'agent-runtime/src/core/harness-adapter.ts',
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
// Mock utils/exec
|
|
30
|
+
jest.mock('../utils/exec', () => ({
|
|
31
|
+
runCommand: jest.fn((() => Promise.resolve('')) as any),
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
import { runCommand } from '../utils/exec';
|
|
35
|
+
const mockRunCommand = runCommand as jest.MockedFunction<typeof runCommand>;
|
|
36
|
+
|
|
37
|
+
describe('CrossProjectChecker', () => {
|
|
38
|
+
const tempDir = path.join(process.cwd(), 'temp-test-cross');
|
|
39
|
+
|
|
40
|
+
beforeAll(() => {
|
|
41
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
afterAll(() => {
|
|
45
|
+
try {
|
|
46
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
47
|
+
} catch {
|
|
48
|
+
// ignore
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
jest.clearAllMocks();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
describe('checkCrossProjectContracts', () => {
|
|
57
|
+
it('应该检查跨项目依赖', async () => {
|
|
58
|
+
mockRunCommand.mockResolvedValue('');
|
|
59
|
+
|
|
60
|
+
const result = await checkCrossProjectContracts({
|
|
61
|
+
baseBranch: 'main',
|
|
62
|
+
changedProjects: [],
|
|
63
|
+
changedFiles: [],
|
|
64
|
+
}, TEST_CONFIG);
|
|
65
|
+
|
|
66
|
+
expect(result).toBeDefined();
|
|
67
|
+
expect(Array.isArray(result)).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('空变更列表应该返回空数组', async () => {
|
|
71
|
+
mockRunCommand.mockResolvedValue('');
|
|
72
|
+
|
|
73
|
+
const result = await checkCrossProjectContracts({
|
|
74
|
+
baseBranch: 'main',
|
|
75
|
+
changedProjects: [],
|
|
76
|
+
changedFiles: [],
|
|
77
|
+
}, TEST_CONFIG);
|
|
78
|
+
|
|
79
|
+
expect(result).toEqual([]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('runtime API 变更未同步到 studio 应该报错', async () => {
|
|
83
|
+
mockRunCommand.mockResolvedValueOnce('projects/agent-runtime/src/api/types.ts\nprojects/agent-runtime/src/api/client.ts');
|
|
84
|
+
mockRunCommand.mockResolvedValue('');
|
|
85
|
+
|
|
86
|
+
const result = await checkCrossProjectContracts({
|
|
87
|
+
baseBranch: 'main',
|
|
88
|
+
changedProjects: ['agent-runtime'],
|
|
89
|
+
changedFiles: ['projects/agent-runtime/src/api/types.ts'],
|
|
90
|
+
}, TEST_CONFIG);
|
|
91
|
+
|
|
92
|
+
expect(result.length).toBeGreaterThan(0);
|
|
93
|
+
expect(result[0].type).toBe('api-mismatch');
|
|
94
|
+
expect(result[0].fromProject).toBe('agent-runtime');
|
|
95
|
+
expect(result[0].toProject).toBe('agent-studio');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('runtime 和 studio 同时变更不应该报错', async () => {
|
|
99
|
+
mockRunCommand.mockResolvedValueOnce('projects/agent-runtime/src/api/types.ts');
|
|
100
|
+
mockRunCommand.mockResolvedValue('');
|
|
101
|
+
|
|
102
|
+
const result = await checkCrossProjectContracts({
|
|
103
|
+
baseBranch: 'main',
|
|
104
|
+
changedProjects: ['agent-runtime', 'agent-studio'],
|
|
105
|
+
changedFiles: [
|
|
106
|
+
'projects/agent-runtime/src/api/types.ts',
|
|
107
|
+
'projects/agent-studio/src/services/runtime-client.ts',
|
|
108
|
+
],
|
|
109
|
+
}, TEST_CONFIG);
|
|
110
|
+
|
|
111
|
+
// API 变更已同步,不应该有 api-mismatch 错误
|
|
112
|
+
const apiMismatches = result.filter(v => v.type === 'api-mismatch');
|
|
113
|
+
expect(apiMismatches.length).toBe(0);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('破坏性变更未适配依赖项目应该报错', async () => {
|
|
117
|
+
// checkApiSync 和 checkBreakingChanges 都调用 getApiChanges,需要两轮 mock
|
|
118
|
+
// checkApiSync → getApiChanges → runCommand(name-only) + detectChangeType → runCommand(name-status)
|
|
119
|
+
// checkBreakingChanges → getApiChanges → runCommand(name-only) + detectChangeType → runCommand(name-status)
|
|
120
|
+
mockRunCommand
|
|
121
|
+
.mockResolvedValueOnce('projects/harness/src/core/checkpoint.ts') // checkApiSync: name-only
|
|
122
|
+
.mockResolvedValueOnce('D\tprojects/harness/src/core/checkpoint.ts') // checkApiSync: name-status
|
|
123
|
+
.mockResolvedValueOnce('projects/harness/src/core/checkpoint.ts') // checkBreakingChanges: name-only
|
|
124
|
+
.mockResolvedValueOnce('D\tprojects/harness/src/core/checkpoint.ts'); // checkBreakingChanges: name-status
|
|
125
|
+
|
|
126
|
+
const result = await checkCrossProjectContracts({
|
|
127
|
+
baseBranch: 'main',
|
|
128
|
+
changedProjects: ['harness'],
|
|
129
|
+
changedFiles: ['projects/harness/src/core/checkpoint.ts'],
|
|
130
|
+
}, TEST_CONFIG);
|
|
131
|
+
|
|
132
|
+
// 删除文件是破坏性变更,应产生 breaking-change 违规
|
|
133
|
+
const breakingChanges = result.filter(v => v.type === 'breaking-change');
|
|
134
|
+
expect(breakingChanges.length).toBeGreaterThan(0);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('签名变更应该被检测为破坏性变更', async () => {
|
|
138
|
+
// checkApiSync 和 checkBreakingChanges 都调用 getApiChanges
|
|
139
|
+
mockRunCommand
|
|
140
|
+
.mockResolvedValueOnce('projects/agent-runtime/src/api/types.ts') // checkApiSync: name-only
|
|
141
|
+
.mockResolvedValueOnce('M\tprojects/agent-runtime/src/api/types.ts') // checkApiSync: name-status
|
|
142
|
+
.mockResolvedValueOnce('-export function createAgent(config: Config): void\n+export function createAgent(config: Config, opts: Options): void') // checkApiSync: signature diff
|
|
143
|
+
.mockResolvedValueOnce('projects/agent-runtime/src/api/types.ts') // checkBreakingChanges: name-only
|
|
144
|
+
.mockResolvedValueOnce('M\tprojects/agent-runtime/src/api/types.ts') // checkBreakingChanges: name-status
|
|
145
|
+
.mockResolvedValueOnce('-export function createAgent(config: Config): void\n+export function createAgent(config: Config, opts: Options): void'); // checkBreakingChanges: signature diff
|
|
146
|
+
|
|
147
|
+
const result = await checkCrossProjectContracts({
|
|
148
|
+
baseBranch: 'main',
|
|
149
|
+
changedProjects: ['agent-runtime'],
|
|
150
|
+
changedFiles: ['projects/agent-runtime/src/api/types.ts'],
|
|
151
|
+
}, TEST_CONFIG);
|
|
152
|
+
|
|
153
|
+
const breakingChanges = result.filter(v => v.type === 'breaking-change');
|
|
154
|
+
expect(breakingChanges.length).toBeGreaterThan(0);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('git 命令失败时应该返回空数组', async () => {
|
|
158
|
+
mockRunCommand.mockRejectedValue(new Error('git error'));
|
|
159
|
+
|
|
160
|
+
const result = await checkCrossProjectContracts({
|
|
161
|
+
baseBranch: 'main',
|
|
162
|
+
changedProjects: ['agent-runtime'],
|
|
163
|
+
changedFiles: [],
|
|
164
|
+
}, TEST_CONFIG);
|
|
165
|
+
|
|
166
|
+
expect(result).toEqual([]);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('checkDocCodeConsistency', () => {
|
|
171
|
+
it('文档接口未实现应该报错', async () => {
|
|
172
|
+
const docPath = path.join(tempDir, 'api-doc.md');
|
|
173
|
+
fs.writeFileSync(docPath, '# API\n\n## agent-runtime\n- `createAgent(config)` - 创建 Agent');
|
|
174
|
+
|
|
175
|
+
const result = await checkDocCodeConsistency(docPath, ['agent-runtime']);
|
|
176
|
+
|
|
177
|
+
expect(result).toBeDefined();
|
|
178
|
+
expect(Array.isArray(result)).toBe(true);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('项目不在列表中应该跳过', async () => {
|
|
182
|
+
const docPath = path.join(tempDir, 'api-doc-2.md');
|
|
183
|
+
fs.writeFileSync(docPath, '# API\n\n## unknown-project\n- `test()`');
|
|
184
|
+
|
|
185
|
+
const result = await checkDocCodeConsistency(docPath, ['agent-runtime']);
|
|
186
|
+
|
|
187
|
+
// unknown-project 不在 projects 列表中,应该跳过
|
|
188
|
+
expect(result).toBeDefined();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it('extractExportedApis 应该返回数组', async () => {
|
|
192
|
+
// 测试内部函数的行为
|
|
193
|
+
const docPath = path.join(tempDir, 'api-doc-3.md');
|
|
194
|
+
fs.writeFileSync(docPath, '# API\n\n## agent-runtime\n- `createAgent(config)` - 创建 Agent');
|
|
195
|
+
|
|
196
|
+
const result = await checkDocCodeConsistency(docPath, ['agent-runtime']);
|
|
197
|
+
|
|
198
|
+
// 结果应该是数组
|
|
199
|
+
expect(Array.isArray(result)).toBe(true);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('isCompatible 检查签名一致性', async () => {
|
|
203
|
+
const docPath = path.join(tempDir, 'api-doc-4.md');
|
|
204
|
+
fs.writeFileSync(docPath, '# API\n\n## test-project\n- `testFunction(x: number)`');
|
|
205
|
+
|
|
206
|
+
const result = await checkDocCodeConsistency(docPath, ['test-project']);
|
|
207
|
+
|
|
208
|
+
expect(result).toBeDefined();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('解析文档接口测试', async () => {
|
|
212
|
+
const docPath = path.join(tempDir, 'complex-doc.md');
|
|
213
|
+
fs.writeFileSync(docPath, `# API
|
|
214
|
+
|
|
215
|
+
## project-a
|
|
216
|
+
- \`funcA(a: string, b: number): boolean\`
|
|
217
|
+
- \`funcB(config: Config): void\`
|
|
218
|
+
|
|
219
|
+
## project-b
|
|
220
|
+
- \`funcC()\`
|
|
221
|
+
`);
|
|
222
|
+
|
|
223
|
+
const result = await checkDocCodeConsistency(docPath, ['project-a', 'project-b']);
|
|
224
|
+
|
|
225
|
+
// parseDocInterfaces 现在应该解析出 3 个接口
|
|
226
|
+
// 由于 extractExportedApis 也已实现但项目目录不存在,应产生 missing-implementation 违规
|
|
227
|
+
expect(Array.isArray(result)).toBe(true);
|
|
228
|
+
expect(result.length).toBeGreaterThan(0);
|
|
229
|
+
expect(result[0].type).toBe('missing-implementation');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it('项目目录存在时应该提取导出 API', async () => {
|
|
233
|
+
// 创建项目目录结构
|
|
234
|
+
const projectDir = path.join(process.cwd(), 'projects', 'test-proj', 'src');
|
|
235
|
+
fs.mkdirSync(projectDir, { recursive: true });
|
|
236
|
+
fs.writeFileSync(path.join(projectDir, 'index.ts'), `
|
|
237
|
+
export function hello(name: string): string {
|
|
238
|
+
return name;
|
|
239
|
+
}
|
|
240
|
+
export class MyService {
|
|
241
|
+
run() {}
|
|
242
|
+
}
|
|
243
|
+
export const helper = (x: number) => x + 1;
|
|
244
|
+
export interface Config { key: string; }
|
|
245
|
+
export type Result = { ok: boolean; }
|
|
246
|
+
`);
|
|
247
|
+
|
|
248
|
+
const docPath = path.join(tempDir, 'api-with-impl.md');
|
|
249
|
+
fs.writeFileSync(docPath, `# API
|
|
250
|
+
|
|
251
|
+
## test-proj
|
|
252
|
+
- \`hello(name: string): string\`
|
|
253
|
+
`);
|
|
254
|
+
|
|
255
|
+
const result = await checkDocCodeConsistency(docPath, ['test-proj']);
|
|
256
|
+
|
|
257
|
+
// 应该能匹配到 hello 函数
|
|
258
|
+
expect(Array.isArray(result)).toBe(true);
|
|
259
|
+
|
|
260
|
+
// 清理
|
|
261
|
+
fs.rmSync(path.join(process.cwd(), 'projects'), { recursive: true, force: true });
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it('文档签名不匹配应该报 doc-code-mismatch', async () => {
|
|
265
|
+
const projectDir = path.join(process.cwd(), 'projects', 'mismatch-proj', 'src');
|
|
266
|
+
fs.mkdirSync(projectDir, { recursive: true });
|
|
267
|
+
fs.writeFileSync(path.join(projectDir, 'api.ts'), `
|
|
268
|
+
export function createAgent(config: object): void {}
|
|
269
|
+
`);
|
|
270
|
+
|
|
271
|
+
const docPath = path.join(tempDir, 'api-mismatch.md');
|
|
272
|
+
fs.writeFileSync(docPath, `# API
|
|
273
|
+
|
|
274
|
+
## mismatch-proj
|
|
275
|
+
- \`createAgent(config: string, opts: object): boolean\`
|
|
276
|
+
`);
|
|
277
|
+
|
|
278
|
+
const result = await checkDocCodeConsistency(docPath, ['mismatch-proj']);
|
|
279
|
+
|
|
280
|
+
// 签名不匹配,应产生 doc-code-mismatch
|
|
281
|
+
const mismatches = result.filter(v => v.type === 'doc-code-mismatch');
|
|
282
|
+
expect(mismatches.length).toBeGreaterThan(0);
|
|
283
|
+
|
|
284
|
+
fs.rmSync(path.join(process.cwd(), 'projects'), { recursive: true, force: true });
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('findTsFiles 应该排除 node_modules 和 dist', async () => {
|
|
288
|
+
const projectDir = path.join(process.cwd(), 'projects', 'filter-proj', 'src');
|
|
289
|
+
fs.mkdirSync(path.join(projectDir, 'node_modules'), { recursive: true });
|
|
290
|
+
fs.mkdirSync(path.join(projectDir, 'dist'), { recursive: true });
|
|
291
|
+
fs.mkdirSync(path.join(projectDir, '__tests__'), { recursive: true });
|
|
292
|
+
fs.writeFileSync(path.join(projectDir, 'valid.ts'), 'export const x = 1;');
|
|
293
|
+
fs.writeFileSync(path.join(projectDir, 'node_modules', 'dep.ts'), 'export const y = 2;');
|
|
294
|
+
fs.writeFileSync(path.join(projectDir, 'dist', 'built.js'), 'var x = 1;');
|
|
295
|
+
fs.writeFileSync(path.join(projectDir, '__tests__', 'test.ts'), 'export const z = 3;');
|
|
296
|
+
fs.writeFileSync(path.join(projectDir, 'types.d.ts'), 'export interface I {}');
|
|
297
|
+
|
|
298
|
+
const docPath = path.join(tempDir, 'api-filter.md');
|
|
299
|
+
fs.writeFileSync(docPath, `# API
|
|
300
|
+
|
|
301
|
+
## filter-proj
|
|
302
|
+
- \`nonexistent()\`
|
|
303
|
+
`);
|
|
304
|
+
|
|
305
|
+
const result = await checkDocCodeConsistency(docPath, ['filter-proj']);
|
|
306
|
+
|
|
307
|
+
// 应该只找到 valid.ts,不包含 node_modules/dist/__tests__/.d.ts
|
|
308
|
+
expect(Array.isArray(result)).toBe(true);
|
|
309
|
+
|
|
310
|
+
fs.rmSync(path.join(process.cwd(), 'projects'), { recursive: true, force: true });
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it('parseDocInterfaces 不存在的文件应该返回空', async () => {
|
|
314
|
+
const result = await checkDocCodeConsistency('/nonexistent/doc.md', ['any']);
|
|
315
|
+
expect(result).toEqual([]);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
});
|