@aibyzero/cm-workflow 0.17.1 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +23 -0
- package/CHANGELOG.md +242 -0
- package/README.md +20 -3
- package/THIRD_PARTY_NOTICES.md +13 -0
- package/VERSION +1 -1
- package/compat/claude-commands/cm-challenge.md +3 -0
- package/docs/architecture.md +11 -0
- package/docs/cm-control-policy-v2.md +127 -9
- package/docs/installation.md +310 -4
- package/docs/js-workflow-control.md +150 -15
- package/docs/live-evidence-drivers.md +28 -4
- package/docs/out-of-scope/README.md +25 -0
- package/docs/out-of-scope/background-supervisor.md +32 -0
- package/docs/reviewed-integration.md +48 -0
- package/docs/user-guide.md +50 -21
- package/install-codex.sh +331 -18
- package/install.ps1 +28 -2
- package/install.sh +321 -17
- package/package.json +2 -1
- package/runtime/js/autonomy.mjs +152 -0
- package/runtime/js/cm-ai/batch-location.mjs +55 -0
- package/runtime/js/cm-ai/batch-plan.mjs +242 -0
- package/runtime/js/cm-ai/checkpoint-package-material.mjs +162 -0
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +55 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +83 -14
- package/runtime/js/cm-ai/claude-tool-preview.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-admission.mjs +56 -17
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +91 -6
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +5 -1
- package/runtime/js/cm-ai/codex-config.mjs +6 -2
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +3 -2
- package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
- package/runtime/js/cm-ai/codex-reconnect-notice.mjs +6 -0
- package/runtime/js/cm-ai/codex-review-adapter.mjs +27 -7
- package/runtime/js/cm-ai/control-policy.mjs +21 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +19 -5
- package/runtime/js/cm-ai/drive-core.mjs +115 -11
- package/runtime/js/cm-ai/drive-rate-limit.mjs +105 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +234 -33
- package/runtime/js/cm-ai/effect-contract.mjs +11 -2
- package/runtime/js/cm-ai/execution-policy.mjs +3 -1
- package/runtime/js/cm-ai/execution-snapshot.mjs +4 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +14 -7
- package/runtime/js/cm-ai/execution-store.mjs +60 -17
- package/runtime/js/cm-ai/fix-code-association.mjs +73 -2
- package/runtime/js/cm-ai/host-check.mjs +11 -5
- package/runtime/js/cm-ai/host-conversation-execution.mjs +70 -28
- package/runtime/js/cm-ai/host-qa-executor.mjs +38 -5
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +19 -2
- package/runtime/js/cm-ai/host-replay.mjs +148 -0
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +19 -2
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/implicit-qa-decision.mjs +5 -0
- package/runtime/js/cm-ai/integration-snapshots.mjs +50 -0
- package/runtime/js/cm-ai/live-evidence.mjs +28 -6
- package/runtime/js/cm-ai/operator-guidance.mjs +9 -2
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +27 -9
- package/runtime/js/cm-ai/process-group-exit.mjs +46 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +3 -2
- package/runtime/js/cm-ai/qa-attachment.mjs +22 -0
- package/runtime/js/cm-ai/qa-config-revision.mjs +7 -2
- package/runtime/js/cm-ai/requirement-evidence.mjs +102 -0
- package/runtime/js/cm-ai/review-package.mjs +79 -7
- package/runtime/js/cm-ai/review-presentation-delta.mjs +166 -0
- package/runtime/js/cm-ai/review-presentation.mjs +177 -8
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +70 -2
- package/runtime/js/cm-ai/reviewed-integration.mjs +260 -0
- package/runtime/js/cm-ai/scope-revision.mjs +38 -0
- package/runtime/js/cm-ai/specification-material.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +242 -39
- package/runtime/js/cm-ai/verification-auto.mjs +38 -0
- package/runtime/js/cm-ai/worker-claude-developer.mjs +39 -15
- package/runtime/js/cm-ai/worker-claude.mjs +35 -13
- package/runtime/js/cm-ai/worker-codex-developer.mjs +43 -17
- package/runtime/js/cm-ai/worker-codex.mjs +41 -7
- package/runtime/js/cm-fix/cause-invocation.mjs +16 -2
- package/runtime/js/cm-fix/cause-package.mjs +46 -1
- package/runtime/js/cm-fix/command-correction.mjs +37 -0
- package/runtime/js/cm-fix/cooperative.mjs +12 -0
- package/runtime/js/cm-fix/dossier.mjs +8 -2
- package/runtime/js/cm-fix/execution.mjs +578 -100
- package/runtime/js/cm-fix/final-review.mjs +39 -8
- package/runtime/js/cm-fix/finish.mjs +15 -11
- package/runtime/js/cm-fix/host-review.mjs +65 -10
- package/runtime/js/cm-fix/host.mjs +35 -12
- package/runtime/js/cm-fix/jest-command-correction.mjs +69 -0
- package/runtime/js/cm-fix/metrics.mjs +18 -5
- package/runtime/js/cm-fix/regression-evidence.mjs +3 -2
- package/runtime/js/cm-fix/regression.mjs +16 -7
- package/runtime/js/cm-fix/repair.mjs +29 -8
- package/runtime/js/cm-fix/review-verification-command.mjs +135 -0
- package/runtime/js/cm-fix/review-verification-contract.mjs +54 -0
- package/runtime/js/cm-fix/review-verification-diagnostic.mjs +75 -0
- package/runtime/js/cm-fix/review-verification-recovery.mjs +44 -0
- package/runtime/js/cm-fix/review-verification-server.mjs +38 -0
- package/runtime/js/cm-fix/review-verification.mjs +214 -0
- package/runtime/js/cm-fix/source-correction-recovery.mjs +65 -0
- package/runtime/js/cm-fix/start.mjs +6 -3
- package/runtime/js/cm-fix/test-type-correction.mjs +86 -0
- package/runtime/js/cm-fix/test-type-recovery.mjs +51 -0
- package/runtime/js/cm-fix/type-import-correction.mjs +89 -0
- package/runtime/js/cm-prd/accepted-design.mjs +8 -0
- package/runtime/js/cm-prd/analysis.mjs +13 -9
- package/runtime/js/cm-prd/change.mjs +37 -16
- package/runtime/js/cm-prd/draft-save.mjs +13 -6
- package/runtime/js/cm-prd/draft.mjs +31 -3
- package/runtime/js/cm-prd/failed-correction.mjs +19 -3
- package/runtime/js/cm-prd/inputs-replaced.mjs +3 -0
- package/runtime/js/cm-prd/review-correction.mjs +6 -4
- package/runtime/js/cm-prd/review-disposition.mjs +7 -1
- package/runtime/js/cm-prd/self-check-revision.mjs +2 -2
- package/runtime/js/cm-prd/self-check.mjs +125 -6
- package/runtime/js/cm-prd/session.mjs +30 -1
- package/runtime/js/cm-prd/summary.mjs +11 -5
- package/runtime/js/cm-prd/task-scope-record.mjs +97 -0
- package/runtime/js/cm-prd/tree-digest.mjs +34 -0
- package/runtime/js/cm-prd/validation-reason.mjs +8 -4
- package/runtime/js/cm-security/scan.mjs +1 -1
- package/runtime/js/commander/decision.mjs +44 -0
- package/runtime/js/commander/dispatch-registry.mjs +110 -0
- package/runtime/js/commander/ledger.mjs +265 -0
- package/runtime/js/commander/preflight.mjs +107 -0
- package/runtime/js/notify-later.mjs +13 -0
- package/runtime/js/notify-send.mjs +6 -2
- package/runtime/js/notify.mjs +581 -65
- package/runtime/js/review-findings.mjs +38 -0
- package/runtime/js/session-boundary.mjs +56 -0
- package/runtime/js/session-handoff.mjs +68 -0
- package/runtime/js/spec-task-line.mjs +27 -13
- package/runtime/js/specs-status.mjs +5 -4
- package/runtime/js/task-scope.mjs +197 -0
- package/runtime/logging.md +6 -1
- package/runtime/model-efficiency.md +69 -10
- package/runtime/orchestration.md +3 -1
- package/runtime/project-learning.md +2 -0
- package/runtime/review.md +3 -2
- package/runtime/test-contract.md +1 -0
- package/scripts/ci-test-weights.json +3 -0
- package/scripts/cm-ai-admission.mjs +21 -7
- package/scripts/cm-ai-admission.test.mjs +171 -3
- package/scripts/cm-ai-batch-drive.mjs +79 -18
- package/scripts/cm-ai-batch-drive.test.mjs +169 -3
- package/scripts/cm-ai-batch-host.mjs +38 -9
- package/scripts/cm-ai-batch-host.test.mjs +6 -5
- package/scripts/cm-ai-batch-learning-merge.test.mjs +36 -0
- package/scripts/cm-ai-batch-location.test.mjs +57 -0
- package/scripts/cm-ai-batch-plan.mjs +52 -0
- package/scripts/cm-ai-batch-plan.test.mjs +397 -0
- package/scripts/cm-ai-batch-run-fixture.mjs +446 -35
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +16 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +28 -1
- package/scripts/cm-ai-batch-run.mjs +471 -57
- package/scripts/cm-ai-batch-run.test.mjs +23 -4
- package/scripts/cm-ai-batch-session-e2e.test.mjs +235 -0
- package/scripts/cm-ai-batch-session-member.test.mjs +293 -0
- package/scripts/cm-ai-batch-session-recovery.test.mjs +423 -0
- package/scripts/cm-ai-check-recheck-cancellation.test.mjs +247 -0
- package/scripts/cm-ai-checklist-coverage.test.mjs +4 -2
- package/scripts/cm-ai-checkpoint-package-material.test.mjs +221 -0
- package/scripts/cm-ai-checkpoint-package-owner.test.mjs +193 -0
- package/scripts/cm-ai-control-launch.test.mjs +21 -0
- package/scripts/cm-ai-control-policy.test.mjs +14 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +398 -3
- package/scripts/cm-ai-control-v2-supersede-race.mjs +25 -0
- package/scripts/cm-ai-control-v2-supersede.test.mjs +318 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +163 -0
- package/scripts/cm-ai-development-rework.test.mjs +423 -0
- package/scripts/cm-ai-drive.mjs +73 -17
- package/scripts/cm-ai-drive.test.mjs +34 -2
- package/scripts/cm-ai-execution-store-legacy-probe.test.mjs +84 -0
- package/scripts/cm-ai-host.mjs +60 -19
- package/scripts/cm-ai-integration-adoption.test.mjs +223 -0
- package/scripts/cm-ai-integration-independence.test.mjs +23 -0
- package/scripts/cm-ai-integration-launch.test.mjs +240 -0
- package/scripts/cm-ai-integration-preview.mjs +41 -0
- package/scripts/cm-ai-integration-snapshots.test.mjs +197 -0
- package/scripts/cm-ai-nested-execution.test.mjs +29 -1
- package/scripts/cm-ai-operator-guidance.test.mjs +16 -1
- package/scripts/cm-ai-prefinal-delivery.test.mjs +278 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +56 -0
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +28 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +36 -2
- package/scripts/cm-ai-requirement-evidence.test.mjs +65 -0
- package/scripts/cm-ai-review-failure.test.mjs +150 -5
- package/scripts/cm-ai-run.mjs +88 -21
- package/scripts/cm-ai-scope-revision.test.mjs +341 -0
- package/scripts/cm-ai-spec-rebind.test.mjs +13 -0
- package/scripts/cm-ai-supersede.test.mjs +28 -0
- package/scripts/cm-ai-verification-auto.test.mjs +99 -0
- package/scripts/cm-announce-hook.mjs +35 -8
- package/scripts/cm-announce-hook.test.mjs +25 -0
- package/scripts/cm-autonomy.mjs +94 -0
- package/scripts/cm-autonomy.test.mjs +162 -0
- package/scripts/cm-challenge.test.mjs +61 -0
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-runtime.sh +60 -1
- package/scripts/cm-claude-developer-worker.test.mjs +56 -7
- package/scripts/cm-claude-install-layout.test.mjs +1 -1
- package/scripts/cm-claude-review-diagnostics.test.mjs +235 -0
- package/scripts/cm-claude-review-stream.test.mjs +13 -0
- package/scripts/cm-codex-developer-reconnect-notice.test.mjs +98 -0
- package/scripts/cm-codex-developer-worker.test.mjs +120 -0
- package/scripts/cm-codex-install-local-edit-guard.test.mjs +436 -0
- package/scripts/cm-codex-prompt-input.test.mjs +153 -0
- package/scripts/cm-codex-reconnect-notice.test.mjs +167 -0
- package/scripts/cm-commander-ledger.test.mjs +260 -0
- package/scripts/cm-commander-p2.test.mjs +295 -0
- package/scripts/cm-commander-preflight.mjs +84 -0
- package/scripts/cm-commander.mjs +116 -0
- package/scripts/cm-config-lock.mjs +35 -0
- package/scripts/cm-controlled-correction.test.mjs +10 -1
- package/scripts/cm-developer-failure-code.test.mjs +62 -0
- package/scripts/cm-display-task-id.test.mjs +41 -0
- package/scripts/cm-efficiency-presentation-delta.test.mjs +218 -0
- package/scripts/cm-execution-snapshot-reuse.test.mjs +115 -0
- package/scripts/cm-external-batch-host.test.mjs +4 -3
- package/scripts/cm-external-process-cleanup.test.mjs +128 -0
- package/scripts/cm-external-qa-fix.test.mjs +89 -7
- package/scripts/cm-external-review-reconciliation.test.mjs +11 -0
- package/scripts/cm-failover.mjs +48 -10
- package/scripts/cm-failover.test.mjs +46 -0
- package/scripts/cm-fix-cause-invocation.test.mjs +19 -4
- package/scripts/cm-fix-command-correction.mjs +17 -0
- package/scripts/cm-fix-command-correction.test.mjs +211 -0
- package/scripts/cm-fix-cooperative-closeout.test.mjs +87 -0
- package/scripts/cm-fix-diagnosis-module-correction.test.mjs +217 -0
- package/scripts/cm-fix-drive.mjs +33 -5
- package/scripts/cm-fix-drive.test.mjs +49 -0
- package/scripts/cm-fix-host-review-assembly.test.mjs +197 -1
- package/scripts/cm-fix-host-review.test.mjs +21 -9
- package/scripts/cm-fix-host.mjs +26 -8
- package/scripts/cm-fix-monorepo-map.test.mjs +92 -0
- package/scripts/cm-fix-observation-task-id.test.mjs +122 -0
- package/scripts/cm-fix-regression-input-budget.test.mjs +111 -0
- package/scripts/cm-fix-repair-input-budget.test.mjs +119 -0
- package/scripts/cm-fix-review-file-paging.test.mjs +91 -0
- package/scripts/cm-fix-review-preflight.mjs +24 -0
- package/scripts/cm-fix-review-storage.test.mjs +233 -0
- package/scripts/cm-fix-review-verification-command.test.mjs +242 -0
- package/scripts/cm-fix-review-verification-evidence.test.mjs +218 -0
- package/scripts/cm-fix-review-verification-integration.test.mjs +81 -0
- package/scripts/cm-fix-review-verification-recovery.test.mjs +198 -0
- package/scripts/cm-fix-review-verification.test.mjs +146 -0
- package/scripts/cm-fix-revision-transport.test.mjs +81 -0
- package/scripts/cm-fix-source-correction.test.mjs +296 -0
- package/scripts/cm-fix-test-type-correction.mjs +18 -0
- package/scripts/cm-fix-test-type-correction.test.mjs +123 -0
- package/scripts/cm-fix-test-type-owner.test.mjs +208 -0
- package/scripts/cm-fix-test-type-verification-cost.test.mjs +66 -0
- package/scripts/cm-fix-type-import-correction.test.mjs +95 -0
- package/scripts/cm-fix-verification-diagnostic.test.mjs +200 -0
- package/scripts/cm-fix-verification-recovery.mjs +33 -0
- package/scripts/cm-host-qa-executor.test.mjs +77 -0
- package/scripts/cm-host-replay.test.mjs +176 -0
- package/scripts/cm-install-local-edit-guard.test.mjs +621 -0
- package/scripts/cm-install-manifest.sh +351 -0
- package/scripts/cm-live-evidence.test.mjs +59 -1
- package/scripts/cm-log-event.mjs +61 -10
- package/scripts/cm-log-event.test.mjs +121 -1
- package/scripts/cm-matt-skills.mjs +576 -0
- package/scripts/cm-matt-skills.test.mjs +550 -0
- package/scripts/cm-notify-command.test.mjs +42 -10
- package/scripts/cm-notify.mjs +14 -10
- package/scripts/cm-notify.test.mjs +581 -59
- package/scripts/cm-patrol.mjs +4 -1
- package/scripts/cm-patrol.test.mjs +23 -5
- package/scripts/cm-prd-answer-gaps.test.mjs +2 -2
- package/scripts/cm-prd-completion.test.mjs +56 -13
- package/scripts/cm-prd-design-phase.test.mjs +78 -8
- package/scripts/cm-prd-draft-save.test.mjs +12 -0
- package/scripts/cm-prd-draft.test.mjs +1 -1
- package/scripts/cm-prd-drive.mjs +13 -6
- package/scripts/cm-prd-drive.test.mjs +45 -1
- package/scripts/cm-prd-gate-diagnostic.test.mjs +2 -2
- package/scripts/cm-prd-host.mjs +10 -5
- package/scripts/cm-prd-host.test.mjs +4 -2
- package/scripts/cm-prd-inputs-replaced.test.mjs +1 -1
- package/scripts/cm-prd-review-disposition.test.mjs +124 -8
- package/scripts/cm-prd-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +1 -1
- package/scripts/cm-prd-self-check-rules.test.mjs +239 -0
- package/scripts/cm-prd-self-check.test.mjs +105 -5
- package/scripts/cm-prd-summary.test.mjs +24 -3
- package/scripts/cm-prd-task-grouping.test.mjs +6 -6
- package/scripts/cm-prd-tree-digest.test.mjs +74 -0
- package/scripts/cm-refactor-drive.mjs +2 -1
- package/scripts/cm-refactor-drive.test.mjs +9 -0
- package/scripts/cm-release-smoke.sh +1 -1
- package/scripts/cm-skill-hints-autowire.test.mjs +394 -0
- package/scripts/cm-skill-hints-exam.mjs +149 -0
- package/scripts/cm-skill-hints-install.test.mjs +168 -0
- package/scripts/cm-skill-hints.exam.json +706 -0
- package/scripts/cm-skill-hints.json +119 -0
- package/scripts/cm-skill-hints.mjs +669 -0
- package/scripts/cm-skill-hints.test.mjs +831 -0
- package/scripts/cm-skill-judge.mjs +181 -0
- package/scripts/cm-skill-judge.test.mjs +255 -0
- package/scripts/cm-specs-status.test.mjs +4 -2
- package/scripts/cm-start-check.mjs +323 -0
- package/scripts/cm-start-check.test.mjs +406 -0
- package/scripts/cm-task-gate.mjs +150 -29
- package/scripts/cm-task-gate.test.mjs +73 -1
- package/scripts/cm-task-id-grammar.test.mjs +66 -0
- package/scripts/cm-task-scope.test.mjs +308 -0
- package/scripts/cm-upgrade-compat-batch.test.mjs +172 -0
- package/scripts/cm-upgrade-compat.test.mjs +239 -0
- package/scripts/cm-workflow-config.mjs +12 -2
- package/scripts/fixtures/fix-verification-claude.mjs +44 -0
- package/scripts/fixtures/reviewed-integration.mjs +202 -0
- package/scripts/scan-public-safety.py +1 -0
- package/scripts/session-boundary.test.mjs +170 -0
- package/scripts/test-npm-install.py +14 -3
- package/scripts/test-shell-compat.sh +2 -0
- package/scripts/validate-public-repo.py +4 -0
- package/scripts/validate-test-cases.mjs +3 -2
- package/skills/cm-ai/SKILL.md +5 -2
- package/skills/cm-ai/references/N3-execute-task.md +1 -1
- package/skills/cm-ai/references/N4-review.md +2 -1
- package/skills/cm-ai/references/N6-qa-eval.md +3 -1
- package/skills/cm-ai/references/N8-finish.md +22 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +1 -1
- package/skills/cm-ai/references/js-host-recovery.md +79 -3
- package/skills/cm-ai/references/js-host.md +82 -16
- package/skills/cm-challenge/SKILL.md +65 -0
- package/skills/cm-challenge/evals/README.md +18 -0
- package/skills/cm-challenge/evals/trigger-cases.json +20 -0
- package/skills/cm-challenge/evals/trigger-config.json +28 -0
- package/skills/cm-challenge/references/examples.md +15 -0
- package/skills/cm-check/SKILL.md +5 -0
- package/skills/cm-check/references/js-host.md +2 -0
- package/skills/cm-fix/SKILL.md +12 -3
- package/skills/cm-fix/references/command-correction.md +67 -0
- package/skills/cm-fix/references/isolated-review.md +54 -0
- package/skills/cm-fix/references/js-host.md +62 -2
- package/skills/cm-fix/references/test-type-correction.md +72 -0
- package/skills/cm-fix/references/verification-recovery.md +114 -0
- package/skills/cm-idea/SKILL.md +2 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-notify/SKILL.md +2 -0
- package/skills/cm-prd/SKILL.md +14 -9
- package/skills/cm-prd/references/brownfield.md +8 -1
- package/skills/cm-prd/references/change-mode.md +8 -1
- package/skills/cm-prd/references/greenfield.md +4 -0
- package/skills/cm-prd/references/js-change-recovery.md +14 -0
- package/skills/cm-prd/references/js-host.md +4 -2
- package/skills/cm-prd/references/spec-self-check.md +5 -1
- package/skills/cm-refactor/SKILL.md +8 -0
- package/skills/cm-refactor/references/js-host.md +2 -0
- package/skills/cm-test/SKILL.md +4 -0
- package/templates/dashboard/dashboard.html +2 -2
- package/templates/pixel/cm-pixel.html +1 -1
- package/templates/pixel/cm-pixel.sh +1 -1
- package/templates/pixel/dev/template.html +1 -1
- package/templates/statusline/cm-statusline.sh +1 -1
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
7
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
8
|
+
import {startFixRun} from '../runtime/js/cm-fix/start.mjs';
|
|
9
|
+
import {publishFixObservationDossier,publishFixEscalationDossier,publishFixDossier} from '../runtime/js/cm-fix/dossier.mjs';
|
|
10
|
+
|
|
11
|
+
const learning={files:[],contextDigest:digest([]),application:{contextDigest:digest([]),status:'no_relevant_lesson',summary:'Synthetic fixture'}};
|
|
12
|
+
const diagnosis={status:'needs_evidence',rootCause:'Unknown',affectedPaths:['value.mjs'],plan:'Await evidence; no repair',crossLayer:false,affectedModules:['one']};
|
|
13
|
+
|
|
14
|
+
for(const mode of ['needs_evidence','not_reproduced'])
|
|
15
|
+
test(`existing observation identity closes without reproduction replay or completion: ${mode}`,async()=>{
|
|
16
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-obs-task-')));
|
|
17
|
+
const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
|
|
18
|
+
const identity={repositoryId:'fixture',runId:'same-run',taskId:'T-OBS-original-identity',attempt:1};
|
|
19
|
+
let diagnosisCalls=0;
|
|
20
|
+
const configuration={hostContextId:'fixture-host',defect:'Busy; root unknown',reproduction:{cwd,command:[process.execPath,'-e',"require('node:fs').appendFileSync('visits','1');console.error('BUSY');process.exit("+(mode==='needs_evidence'?'1':'0')+")"],expectedFailure:{exitCode:1,outputIncludes:'BUSY'},timeoutMs:2000}};
|
|
21
|
+
const options={specsRoot,identity,configuration,create:true};
|
|
22
|
+
let owner=openFixExecution(options,{prepare:async()=>learning,bridge:{async call(kind){diagnosisCalls++;assert.equal(mode,'needs_evidence');assert.equal(kind,'fix_diagnose');return diagnosis;}}});
|
|
23
|
+
try{
|
|
24
|
+
startFixRun({specsRoot,identity,configuration});
|
|
25
|
+
assert.equal((await owner.advance({authorized:true})).stage,'observation');
|
|
26
|
+
const stateFile=path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json');
|
|
27
|
+
const originalState=JSON.parse(fs.readFileSync(stateFile));
|
|
28
|
+
const prefix=originalState.records;
|
|
29
|
+
const frozen=({records,revision,...value})=>value;
|
|
30
|
+
owner.close();owner=openFixExecution({...options,create:false});
|
|
31
|
+
const result=owner.finish({authorized:true});
|
|
32
|
+
assert.equal(result.observationRunEnded,true);assert.equal(result.completionEligible,false);
|
|
33
|
+
assert.deepEqual(result.identity,identity);assert.equal(fs.readFileSync(path.join(cwd,'visits'),'utf8'),'1');
|
|
34
|
+
assert.match(path.basename(result.dossier.path),/^\d{8}-obs\.original-identity\.md$/);
|
|
35
|
+
const bytes=fs.readFileSync(result.dossier.path);assert(bytes.includes(Buffer.from(identity.taskId)));
|
|
36
|
+
const finalState=JSON.parse(fs.readFileSync(stateFile));
|
|
37
|
+
assert.deepEqual(finalState.records.slice(0,prefix.length),prefix);
|
|
38
|
+
assert.deepEqual(frozen(finalState),frozen(originalState));
|
|
39
|
+
assert.equal(diagnosisCalls,mode==='needs_evidence'?1:0);
|
|
40
|
+
const log=fs.readFileSync(path.join(specsRoot,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
41
|
+
assert.equal(log.filter(x=>x.event==='run_done'&&x.result==='observing').length,1);
|
|
42
|
+
assert.equal(log.filter(x=>x.event==='task_done').length,0);assert(!fs.existsSync(path.join(specsRoot,'METRICS.md')));
|
|
43
|
+
owner=openFixExecution({...options,create:false});
|
|
44
|
+
assert.equal(owner.status().stage,'observation');assert.deepEqual(owner.status().identity,identity);
|
|
45
|
+
assert.equal(owner.finish({authorized:true}).dossier.sha256,result.dossier.sha256);
|
|
46
|
+
assert.deepEqual(fs.readFileSync(result.dossier.path),bytes);
|
|
47
|
+
const reopenedLog=fs.readFileSync(path.join(specsRoot,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
48
|
+
assert.equal(reopenedLog.filter(x=>x.event==='run_done').length,1);
|
|
49
|
+
assert.equal(fs.readFileSync(path.join(cwd,'visits'),'utf8'),'1');
|
|
50
|
+
fs.appendFileSync(result.dossier.path,'user content');
|
|
51
|
+
owner.close();owner=openFixExecution({...options,create:false});
|
|
52
|
+
assert.throws(()=>owner.finish({authorized:true}),{code:'review_file_conflict'});
|
|
53
|
+
}finally{owner.close();fs.rmSync(root,{recursive:true,force:true});}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
for(const taskId of ['T-OBS-../escape','T-OBS-UPPER','T-OTHER-safe','T-OBS-safe/escape','T-OBS-a--b','T-OBS-','T-OBS-foo.md','T-OBS-café','T-OBS-foo\\escape'])
|
|
57
|
+
test(`observation archive rejects malformed or unsupported id ${taskId}`,()=>{
|
|
58
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-obs-invalid-')));
|
|
59
|
+
try{assert.throws(()=>publishFixObservationDossier({specsRoot:root,configuration:{reproduction:{cwd:root,command:[process.execPath,'-e',''],expectedFailure:{exitCode:1,outputIncludes:'BUSY'},timeoutMs:2000}},status:{stage:'observation',completionEligible:false,identity:{taskId},reproduction:{status:'not_reproduced',next:'observation',observation:{id:'reproduce',command:[process.execPath,'-e',''],outcome:'passed',exitCode:0,evidence:'Synthetic',signatureMatched:false}},diagnosis:null},registeredAt:0}),{code:'invalid_fix_dossier'});}
|
|
60
|
+
finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('observation task id does not become a design escalation slug',()=>{
|
|
64
|
+
assert.throws(()=>publishFixEscalationDossier({specsRoot:'/unused',configuration:{},status:{stage:'escalation_required',completionEligible:false,identity:{taskId:'T-OBS-original-identity'},diagnosis:{status:'design_change'},causeReview:{review:{verdict:'approved'}}},registeredAt:0}),{code:'invalid_fix_dossier'});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function archiveFixture(t,{bare=false}={}){
|
|
68
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-obs-publisher-')));
|
|
69
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
70
|
+
const command=[process.execPath,'-e',''];
|
|
71
|
+
const configuration={...(bare?{archiveMode:'bare'}:{}),defect:'Synthetic observation',
|
|
72
|
+
reproduction:{cwd:root,command,expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000}};
|
|
73
|
+
const status={stage:'observation',completionEligible:false,
|
|
74
|
+
identity:{repositoryId:'fixture',runId:'same-run',taskId:'T-OBS-safe',attempt:1},learning,
|
|
75
|
+
reproduction:{status:'not_reproduced',next:'observation',observation:{id:'reproduce',command,
|
|
76
|
+
outcome:'passed',exitCode:0,evidence:'Synthetic',signatureMatched:false}},diagnosis:null};
|
|
77
|
+
return {root,options:{specsRoot:root,configuration,status,registeredAt:0}};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
for(const bare of [false,true])
|
|
81
|
+
test(`archive publisher preserves identities and disjoint task filenames: bare=${bare}`,t=>{
|
|
82
|
+
const {root,options}=archiveFixture(t,{bare});
|
|
83
|
+
const expected=new Map([['T-FIX-safe','19700101-safe.md'],['T-FIX-obs-safe','19700101-obs-safe.md'],['T-FIX-t-obs-safe','19700101-t-obs-safe.md'],
|
|
84
|
+
['T-OBS-safe','19700101-obs.safe.md'],['T-OBS-obs-safe','19700101-obs.obs-safe.md']]);
|
|
85
|
+
const paths=[];
|
|
86
|
+
for(const [taskId,name]of expected){
|
|
87
|
+
const status={...options.status,identity:{...options.status.identity,taskId}};
|
|
88
|
+
const result=publishFixObservationDossier({...options,status});
|
|
89
|
+
assert.equal(path.basename(result.path),name);
|
|
90
|
+
assert.equal(path.dirname(result.path),bare?root:path.join(root,'fixes'));
|
|
91
|
+
assert.equal(result.completionEligible,false);assert.equal(status.identity.taskId,taskId);
|
|
92
|
+
assert(fs.readFileSync(result.path,'utf8').includes(`"taskId": "${taskId}"`));
|
|
93
|
+
assert.equal(fs.statSync(result.path).mode&0o777,0o600);paths.push(result.path);
|
|
94
|
+
}
|
|
95
|
+
assert.equal(new Set(paths).size,expected.size);
|
|
96
|
+
assert.equal(new Set(paths.map(file=>file.toLowerCase())).size,expected.size);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('archive publisher preserves exact replay bytes and refuses foreign content',t=>{
|
|
100
|
+
const {options}=archiveFixture(t);const first=publishFixObservationDossier(options);
|
|
101
|
+
const bytes=fs.readFileSync(first.path);assert.deepEqual(publishFixObservationDossier(options),first);
|
|
102
|
+
assert.deepEqual(fs.readFileSync(first.path),bytes);
|
|
103
|
+
fs.appendFileSync(first.path,'user content');const foreign=fs.readFileSync(first.path);
|
|
104
|
+
assert.throws(()=>publishFixObservationDossier(options),{code:'review_file_conflict'});
|
|
105
|
+
assert.deepEqual(fs.readFileSync(first.path),foreign);
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
test('archive publisher refuses an escaped dossier directory without writing outside',t=>{
|
|
109
|
+
const {root,options}=archiveFixture(t);const outside=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-obs-outside-')));
|
|
110
|
+
t.after(()=>fs.rmSync(outside,{recursive:true,force:true}));
|
|
111
|
+
fs.symlinkSync(outside,path.join(root,'fixes'));
|
|
112
|
+
assert.throws(()=>publishFixObservationDossier(options),{code:'unsupported_path'});
|
|
113
|
+
assert.deepEqual(fs.readdirSync(outside),[]);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test('archive publisher cannot turn observation identity into completed repair evidence',t=>{
|
|
117
|
+
const {options}=archiveFixture(t);
|
|
118
|
+
assert.throws(()=>publishFixObservationDossier({...options,status:{...options.status,completionEligible:true}}),
|
|
119
|
+
{code:'fix_observation_unavailable'});
|
|
120
|
+
assert.throws(()=>publishFixDossier({...options,status:{...options.status,stage:'closeout_required'}}),
|
|
121
|
+
{code:'invalid_fix_dossier'});
|
|
122
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {createHash} from 'node:crypto';
|
|
7
|
+
import {createFixRegression} from '../runtime/js/cm-fix/regression.mjs';
|
|
8
|
+
import {createFixRedTest} from '../runtime/js/cm-fix/red-test.mjs';
|
|
9
|
+
import {createFixBaseline} from '../runtime/js/cm-fix/baseline.mjs';
|
|
10
|
+
import {captureReviewBaseline,createReviewPackage} from '../runtime/js/cm-ai/review-package.mjs';
|
|
11
|
+
import {createHostHandoff} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
12
|
+
import {createFixFinalReview,fixFinalReviewConfiguration,inspectFixRepairReview} from '../runtime/js/cm-fix/final-review.mjs';
|
|
13
|
+
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
14
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
15
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
16
|
+
|
|
17
|
+
const MiB=1024*1024,MARK='CM_REGRESSION_INPUT_BUDGET',size=x=>Buffer.byteLength(JSON.stringify(x)),sha=b=>createHash('sha256').update(b).digest('hex');
|
|
18
|
+
const tree=root=>{const rows=[];function walk(dir){for(const e of fs.readdirSync(dir,{withFileTypes:true}).sort((a,b)=>a.name.localeCompare(b.name))){const p=path.join(dir,e.name);if(e.isDirectory())walk(p);else rows.push({path:path.relative(root,p),mode:fs.statSync(p).mode&511,sha256:sha(fs.readFileSync(p))});}}walk(root);return rows;};
|
|
19
|
+
async function fixture(t,{paddingBytes=430*1024}={}){
|
|
20
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-regression-input-budget-'))),codeProject=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(codeProject);fs.mkdirSync(specsRoot);fs.mkdirSync(path.join(specsRoot,'.reviews'));
|
|
21
|
+
const saved={},home=path.join(root,'home');fs.mkdirSync(home);
|
|
22
|
+
for(const key of ['HOME','CLAUDE_HOME','CODEX_HOME','CM_WORKFLOW_HOME','CM_WORKFLOW_LOG_HOME']){saved[key]=process.env[key];process.env[key]=path.join(home,key);fs.mkdirSync(process.env[key]);}
|
|
23
|
+
t.after(()=>{for(const [k,v]of Object.entries(saved))if(v===undefined)delete process.env[k];else process.env[k]=v;fs.rmSync(root,{recursive:true,force:true});});
|
|
24
|
+
fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=1;');
|
|
25
|
+
fs.writeFileSync(path.join(codeProject,'red.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('OWNED BUDGET BUG');process.exit(1)}");
|
|
26
|
+
fs.writeFileSync(path.join(codeProject,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
|
|
27
|
+
for(const p of ['context-a.txt','context-b.txt'])fs.writeFileSync(path.join(codeProject,p),'x'.repeat(paddingBytes));
|
|
28
|
+
const firstIdentity={repositoryId:'owned-fixture',runId:'regression-budget',taskId:'T-FIX-budget',attempt:1},identity={...firstIdentity,attempt:2},signal=new AbortController().signal;
|
|
29
|
+
const redTest={cwd:codeProject,testFiles:['red.mjs'],command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'OWNED BUDGET BUG'},timeoutMs:3000};
|
|
30
|
+
const baseline={cwd:codeProject,testFiles:['existing.mjs'],commands:[{id:'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:3000};
|
|
31
|
+
const redEvidence=await createFixRedTest(redTest,{identity:firstIdentity,specsRoot})({identity:firstIdentity},{authorized:true,signal});
|
|
32
|
+
const beforeBaseline=await createFixBaseline(baseline)({identity:firstIdentity},{authorized:true,signal});
|
|
33
|
+
assert.equal(redEvidence.status,'red_confirmed');assert.equal(beforeBaseline.status,'recorded');
|
|
34
|
+
const priorBaseline=captureReviewBaseline({root:codeProject,specsRoot,identity:firstIdentity,scope:['value.mjs'],requirements:['context-a.txt','context-b.txt']});
|
|
35
|
+
fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=2;');
|
|
36
|
+
const checks=[{id:'unit',command:[process.execPath,'red.mjs'],outcome:'passed',exitCode:0,evidence:'Owned synthetic first repair checked in fixture'}];
|
|
37
|
+
const handoffPath=path.join(specsRoot,'.reviews','budget-a1-handoff.json');createHostHandoff({root:codeProject,baseline:priorBaseline,checks,handoffPath,evidence:['Owned first-round package fixture']});
|
|
38
|
+
const pkg=createReviewPackage({root:codeProject,baseline:priorBaseline,checks,handoffPath});
|
|
39
|
+
const configuration=fixFinalReviewConfiguration({hostContextId:'owned-host',causeReview:{reviewerId:'fixture-cause',adapterId:'codex-cause-review-adapter',provider:'codex',requestedModel:'fixture',contextId:'fixture-cause-context',excludedThreadIds:[]}});
|
|
40
|
+
const authority=createHostReviewAuthority({hostContextId:configuration.hostContextId,reviewerId:configuration.reviewer.reviewerId,adapterId:configuration.reviewer.adapterId,decide:async()=>({status:'approved'})});
|
|
41
|
+
await authority.hostDecisionProvider.decide({identity:firstIdentity,packageDigest:pkg.packageDigest},signal);
|
|
42
|
+
let registration,started;
|
|
43
|
+
const review=createFixFinalReview({reviewPackage:pkg,configuration,timeoutMs:3000},{authorize:authority.authorize,run:async(request,{onEvent})=>{
|
|
44
|
+
for(const event of [{event:'thread.started',provider_thread:'owned-budget-reviewer'},{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])assert.equal(onEvent(event),true);
|
|
45
|
+
return {status:'succeeded',value:{verdict:'changes_requested',packageDigest:pkg.packageDigest,examinedPaths:reviewPaths(pkg),findings:[{id:'F1',severity:'P2',path:'value.mjs',message:'Owned second repair needed',evidence:'Owned fixture finding'}],summary:'Synthetic independent finding; no provider'}};
|
|
46
|
+
}});
|
|
47
|
+
const observed=await review({signal,register(value){registration=value;},onStarted(value){started=value;}});assert.equal(observed.outcome,'observed');
|
|
48
|
+
const reviewFeedback={configuration,registration,started,result:observed.value},priorReview=inspectFixRepairReview(reviewFeedback,identity);
|
|
49
|
+
assert.equal(priorReview.review.verdict,'changes_requested');assert.deepEqual(priorReview.identity,firstIdentity);
|
|
50
|
+
const options={identity,specsRoot,redTest,baseline,redEvidence,beforeBaseline,reviewFeedback};
|
|
51
|
+
return {root,codeProject,specsRoot,options,reviewFeedback,priorReview,firstIdentity,identity,signal};
|
|
52
|
+
}
|
|
53
|
+
function expectedRegression(options){try{return createFixRegression(options);}catch(error){if(error.code==='limit_exceeded')throw new Error(MARK+': fully validated reviewFeedback above 1MiB must construct regression under its existing 12MiB budget',{cause:error});throw error;}}
|
|
54
|
+
|
|
55
|
+
test('regression input budget: valid large prior review constructs without executing or changing source',async t=>{
|
|
56
|
+
const f=await fixture(t),before=tree(f.codeProject),feedbackBefore=digest(f.reviewFeedback),{reviewFeedback,...rest}=f.options;
|
|
57
|
+
assert(size(reviewFeedback)>MiB&&size(reviewFeedback)<12*MiB);assert(size(rest)<MiB);
|
|
58
|
+
const run=expectedRegression(f.options);assert.equal(typeof run,'function');assert.deepEqual(tree(f.codeProject),before);assert.equal(digest(f.reviewFeedback),feedbackBefore);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('regression input budget: actual a2 run preserves a1 red and enforces identity, authorization and single use',async t=>{
|
|
62
|
+
const f=await fixture(t),before=tree(f.codeProject),redPath=path.join(f.specsRoot,f.options.redEvidence.output.path),originalRed=fs.readFileSync(redPath),request={identity:f.identity},control={authorized:true,signal:f.signal},run=expectedRegression(f.options);
|
|
63
|
+
assert.deepEqual(f.priorReview.identity,f.firstIdentity);assert.equal(f.options.identity.attempt,2);
|
|
64
|
+
await assert.rejects(run(request,{...control,authorized:false}),{code:'regression_authorization_required'});
|
|
65
|
+
await assert.rejects(run({identity:f.firstIdentity},control),{code:'identity_mismatch'});
|
|
66
|
+
const result=await run(request,control);assert.equal(result.status,'passed');assert.equal(result.red.outcome,'passed');assert.equal(result.comparison.status,'passed');assert.equal(result.comparison.comparisons[0].status,'still_passed');assert.equal(result.completionEligible,false);
|
|
67
|
+
assert.deepEqual(fs.readFileSync(redPath),originalRed);assert.deepEqual(tree(f.codeProject),before);
|
|
68
|
+
await assert.rejects(run(request,control),{code:'regression_already_attempted'});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test('regression input budget: malformed large package, grant, identity and verdict retain original feedback validation',async t=>{
|
|
72
|
+
const f=await fixture(t),before=tree(f.codeProject);
|
|
73
|
+
for(const kind of ['package','grant','identity','verdict']){
|
|
74
|
+
const feedback=structuredClone(f.reviewFeedback),identity=kind==='identity'?{...f.identity,runId:'foreign'}:f.identity;
|
|
75
|
+
if(kind==='package')feedback.registration.request.payload.reviewPackage.packageDigest='0'.repeat(64);
|
|
76
|
+
if(kind==='grant')feedback.registration.grant.packageDigest='0'.repeat(64);
|
|
77
|
+
if(kind==='verdict')feedback.result.observation.result.value.verdict='approved';
|
|
78
|
+
let expected;try{inspectFixRepairReview(feedback,identity);}catch(error){expected=error.code;}assert(expected,kind+' must be invalid under the unchanged feedback validator');
|
|
79
|
+
assert.throws(()=>createFixRegression({...f.options,identity,reviewFeedback:feedback}),error=>error.code===expected,kind);assert.deepEqual(tree(f.codeProject),before);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test('regression input budget: feedback 12MiB and other arguments 1MiB keep separate hard bounds including exact framing',async t=>{
|
|
84
|
+
const f=await fixture(t),before=tree(f.codeProject),overFeedback={...f.reviewFeedback,oversize:'x'.repeat(12*MiB-size(f.reviewFeedback)+8)};
|
|
85
|
+
assert(size(overFeedback)>12*MiB&&size({...f.options,reviewFeedback:overFeedback})<13*MiB);
|
|
86
|
+
assert.throws(()=>createFixRegression({...f.options,reviewFeedback:overFeedback}),{code:'limit_exceeded'});
|
|
87
|
+
assert.throws(()=>createFixRegression({...f.options,specsRoot:'x'.repeat(MiB+1)}),{code:'limit_exceeded'});
|
|
88
|
+
const edgeFeedback={...f.reviewFeedback,oversize:''};edgeFeedback.oversize='x'.repeat(12*MiB-size(edgeFeedback));
|
|
89
|
+
const {reviewFeedback,...parameters}=f.options,edgeParameters={...parameters,specsRoot:''};edgeParameters.specsRoot='x'.repeat(MiB-size(edgeParameters));
|
|
90
|
+
assert.equal(size(edgeFeedback),12*MiB);assert.equal(size(edgeParameters),MiB);
|
|
91
|
+
const edgeOptions={...edgeParameters,reviewFeedback:edgeFeedback};assert.equal(size(edgeOptions),13*MiB+Buffer.byteLength(',"reviewFeedback":'));
|
|
92
|
+
// Deliberately invalid feedback still must reach its original validator within the exact framing bound.
|
|
93
|
+
assert.throws(()=>inspectFixRepairReview(edgeFeedback,f.identity),{code:'invalid_input'});
|
|
94
|
+
assert.throws(()=>createFixRegression(edgeOptions),{code:'invalid_input'});assert.deepEqual(tree(f.codeProject),before);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('regression input budget: plain shape and accessor rejection never invoke user getters',async t=>{
|
|
98
|
+
const f=await fixture(t),before=tree(f.codeProject);let getters=0;
|
|
99
|
+
const options={...f.options};Object.defineProperty(options,'reviewFeedback',{enumerable:true,get(){getters++;throw Error('top getter must not run');}});
|
|
100
|
+
assert.throws(()=>createFixRegression(options),{code:'invalid_input'});
|
|
101
|
+
const feedback={...f.reviewFeedback};Object.defineProperty(feedback,'registration',{enumerable:true,get(){getters++;throw Error('nested getter must not run');}});
|
|
102
|
+
assert.throws(()=>createFixRegression({...f.options,reviewFeedback:feedback}),{code:'invalid_input'});
|
|
103
|
+
assert.throws(()=>createFixRegression(Object.assign(Object.create({foreign:true}),f.options)),{code:'invalid_input'});
|
|
104
|
+
assert.throws(()=>createFixRegression({...f.options,arbitrary:true}),{code:'invalid_input'});assert.equal(getters,0);assert.deepEqual(tree(f.codeProject),before);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
test('regression input budget: no-feedback legacy retains original construction, real run and ordinary 1MiB limit',async t=>{
|
|
108
|
+
const f=await fixture(t,{paddingBytes:8}),{reviewFeedback,...rest}=f.options,options={...rest,identity:f.firstIdentity},before=tree(f.codeProject),run=createFixRegression(options);
|
|
109
|
+
assert.deepEqual(tree(f.codeProject),before);const result=await run({identity:f.firstIdentity},{authorized:true,signal:f.signal});assert.equal(result.status,'passed');assert.equal(result.completionEligible,false);assert.deepEqual(tree(f.codeProject),before);
|
|
110
|
+
assert.throws(()=>createFixRegression({...options,specsRoot:'x'.repeat(MiB+1)}),{code:'limit_exceeded'});
|
|
111
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {createHash} from 'node:crypto';
|
|
7
|
+
import {prepareFixRepair,verifyFixRepair} from '../runtime/js/cm-fix/repair.mjs';
|
|
8
|
+
import {createFixRedTest} from '../runtime/js/cm-fix/red-test.mjs';
|
|
9
|
+
import {createFixBaseline} from '../runtime/js/cm-fix/baseline.mjs';
|
|
10
|
+
import {captureReviewBaseline,createReviewPackage} from '../runtime/js/cm-ai/review-package.mjs';
|
|
11
|
+
import {createHostHandoff} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
12
|
+
import {createFixFinalReview,fixFinalReviewConfiguration,inspectFixRepairReview} from '../runtime/js/cm-fix/final-review.mjs';
|
|
13
|
+
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
14
|
+
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
15
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
16
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
17
|
+
|
|
18
|
+
const MiB=1024*1024,MARK='CM_REPAIR_INPUT_BUDGET',size=x=>Buffer.byteLength(JSON.stringify(x)),sha=b=>createHash('sha256').update(b).digest('hex');
|
|
19
|
+
const tree=root=>{const rows=[];function walk(dir){for(const e of fs.readdirSync(dir,{withFileTypes:true}).sort((a,b)=>a.name.localeCompare(b.name))){const p=path.join(dir,e.name);if(e.isDirectory())walk(p);else rows.push({path:path.relative(root,p),mode:fs.statSync(p).mode&511,sha256:sha(fs.readFileSync(p))});}}walk(root);return rows;};
|
|
20
|
+
async function fixture(t,{paddingBytes=430*1024}={}){
|
|
21
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-repair-input-budget-'))),codeProject=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(codeProject);fs.mkdirSync(specsRoot);fs.mkdirSync(path.join(specsRoot,'.reviews'));
|
|
22
|
+
const saved={},home=path.join(root,'home');fs.mkdirSync(home);
|
|
23
|
+
for(const key of ['HOME','CLAUDE_HOME','CODEX_HOME','CM_WORKFLOW_HOME','CM_WORKFLOW_LOG_HOME']){saved[key]=process.env[key];process.env[key]=path.join(home,key);fs.mkdirSync(process.env[key]);}
|
|
24
|
+
t.after(()=>{for(const [k,v]of Object.entries(saved))if(v===undefined)delete process.env[k];else process.env[k]=v;fs.rmSync(root,{recursive:true,force:true});});
|
|
25
|
+
fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=1;');
|
|
26
|
+
fs.writeFileSync(path.join(codeProject,'red.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('OWNED BUDGET BUG');process.exit(1)}");
|
|
27
|
+
fs.writeFileSync(path.join(codeProject,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
|
|
28
|
+
for(const p of ['context-a.txt','context-b.txt'])fs.writeFileSync(path.join(codeProject,p),'x'.repeat(paddingBytes));
|
|
29
|
+
const firstIdentity={repositoryId:'owned-fixture',runId:'repair-budget',taskId:'T-FIX-budget',attempt:1},identity={...firstIdentity,attempt:2},signal=new AbortController().signal;
|
|
30
|
+
const redTest={cwd:codeProject,testFiles:['red.mjs'],command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'OWNED BUDGET BUG'},timeoutMs:3000};
|
|
31
|
+
const baseline={cwd:codeProject,testFiles:['existing.mjs'],commands:[{id:'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:3000};
|
|
32
|
+
const redEvidence=await createFixRedTest(redTest,{identity:firstIdentity,specsRoot})({identity:firstIdentity},{authorized:true,signal});
|
|
33
|
+
const beforeBaseline=await createFixBaseline(baseline)({identity:firstIdentity},{authorized:true,signal});
|
|
34
|
+
assert.equal(redEvidence.status,'red_confirmed');assert.equal(beforeBaseline.status,'recorded');
|
|
35
|
+
const priorBaseline=captureReviewBaseline({root:codeProject,specsRoot,identity:firstIdentity,scope:['value.mjs'],requirements:['context-a.txt','context-b.txt']});
|
|
36
|
+
fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=2;');
|
|
37
|
+
const checks=[{id:'unit',command:[process.execPath,'red.mjs'],outcome:'passed',exitCode:0,evidence:'Owned synthetic first repair checked in fixture'}];
|
|
38
|
+
const handoffPath=path.join(specsRoot,'.reviews','budget-a1-handoff.json');createHostHandoff({root:codeProject,baseline:priorBaseline,checks,handoffPath,evidence:['Owned first-round package fixture']});
|
|
39
|
+
const pkg=createReviewPackage({root:codeProject,baseline:priorBaseline,checks,handoffPath});
|
|
40
|
+
const configuration=fixFinalReviewConfiguration({hostContextId:'owned-host',causeReview:{reviewerId:'fixture-cause',adapterId:'codex-cause-review-adapter',provider:'codex',requestedModel:'fixture',contextId:'fixture-cause-context',excludedThreadIds:[]}});
|
|
41
|
+
const authority=createHostReviewAuthority({hostContextId:configuration.hostContextId,reviewerId:configuration.reviewer.reviewerId,adapterId:configuration.reviewer.adapterId,decide:async()=>({status:'approved'})});
|
|
42
|
+
await authority.hostDecisionProvider.decide({identity:firstIdentity,packageDigest:pkg.packageDigest},signal);
|
|
43
|
+
let registration,started;
|
|
44
|
+
const review=createFixFinalReview({reviewPackage:pkg,configuration,timeoutMs:3000},{authorize:authority.authorize,run:async(request,{onEvent})=>{
|
|
45
|
+
for(const event of [{event:'thread.started',provider_thread:'owned-budget-reviewer'},{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])assert.equal(onEvent(event),true);
|
|
46
|
+
return {status:'succeeded',value:{verdict:'changes_requested',packageDigest:pkg.packageDigest,examinedPaths:reviewPaths(pkg),findings:[{id:'F1',severity:'P2',path:'value.mjs',message:'Owned second repair needed',evidence:'Owned fixture finding'}],summary:'Synthetic independent finding; no provider'}};
|
|
47
|
+
}});
|
|
48
|
+
const observed=await review({signal,register(value){registration=value;},onStarted(value){started=value;}});assert.equal(observed.outcome,'observed');
|
|
49
|
+
const reviewFeedback={configuration,registration,started,result:observed.value},priorReview=inspectFixRepairReview(reviewFeedback,identity);
|
|
50
|
+
assert.equal(priorReview.review.verdict,'changes_requested');assert.deepEqual(priorReview.identity,firstIdentity);
|
|
51
|
+
const options={identity,specsRoot,codeProject,scope:['value.mjs'],requirements:['value.mjs'],defect:'Owned second-round repair',diagnosis:{status:'diagnosed',affectedPaths:['value.mjs'],rootCause:'Owned constant repair'},redTest,baseline,redEvidence,beforeBaseline,reviewFeedback};
|
|
52
|
+
return {root,codeProject,specsRoot,options,reviewFeedback,priorReview,firstIdentity,identity,signal};
|
|
53
|
+
}
|
|
54
|
+
const quiet=()=>({bridge:{async call(){throw Error('prepare must not execute bridge');}},assertReviewReady(){}});
|
|
55
|
+
function expectedPreparation(options,capabilities){try{return prepareFixRepair(options,capabilities);}catch(error){if(error.code==='limit_exceeded')throw new Error(MARK+': a fully validated reviewFeedback above 1MiB must prepare under its existing 12MiB budget',{cause:error});throw error;}}
|
|
56
|
+
|
|
57
|
+
test('repair input budget: valid large prior review prepares without executing or changing source scope',async t=>{
|
|
58
|
+
const f=await fixture(t),before=tree(f.codeProject),feedbackBefore=digest(f.reviewFeedback),{reviewFeedback,...rest}=f.options;
|
|
59
|
+
assert(size(reviewFeedback)>MiB&&size(reviewFeedback)<12*MiB);assert(size(rest)<MiB);
|
|
60
|
+
const repair=expectedPreparation(f.options,quiet());assert.deepEqual(tree(f.codeProject),before);assert.equal(digest(f.reviewFeedback),feedbackBefore);
|
|
61
|
+
assert.deepEqual(repair.baseline.identity,f.identity);assert.deepEqual(repair.baseline.scope,['value.mjs']);assert.equal(typeof repair.execute,'function');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('repair input budget: actual second repair execution preserves first red and enforces original scope and authority',async t=>{
|
|
65
|
+
const f=await fixture(t),redPath=path.join(f.specsRoot,f.options.redEvidence.output.path),oldRed=fs.readFileSync(redPath),oldTests=['red.mjs','existing.mjs'].map(p=>[p,fs.readFileSync(path.join(f.codeProject,p))]);
|
|
66
|
+
assert.throws(()=>prepareFixRepair({...f.options,scope:['value.mjs','context-a.txt']},quiet()),{code:'repair_scope_mismatch'});
|
|
67
|
+
const bridge=createHostToolBridge();t.after(()=>bridge.close());let ready=0,registered=0,writes=0;
|
|
68
|
+
bridge.attach(row=>{if(row.type!=='host_request')return;assert.equal(row.kind,'fix_repair');assert.equal(ready,1);assert.equal(registered,1);assert.deepEqual(row.payload.identity,f.identity);assert.deepEqual(row.payload.priorReview,f.priorReview);assert.deepEqual(row.payload.priorReview.identity,f.firstIdentity);assert.deepEqual(row.payload.scope,['value.mjs']);writes++;
|
|
69
|
+
fs.writeFileSync(path.join(f.codeProject,'value.mjs'),'export const value=2;\n// second repair addresses the owned finding');bridge.accept({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result:{outcome:'repaired'}});
|
|
70
|
+
});
|
|
71
|
+
const repair=expectedPreparation(f.options,{bridge,assertReviewReady(){ready++;}}),control={authorized:true,signal:f.signal,register(b){registered++;assert.equal(b.baselineDigest,repair.baseline.baselineDigest);}};
|
|
72
|
+
await assert.rejects(repair.execute({...control,authorized:false}),{code:'repair_authorization_required'});assert.equal(writes,0);
|
|
73
|
+
const result=await repair.execute(control);assert.deepEqual(result.changedFiles,['value.mjs']);assert.equal(result.completionEligible,false);assert.equal(writes,1);verifyFixRepair({codeProject:f.codeProject,specsRoot:f.specsRoot,baseline:repair.baseline,result});
|
|
74
|
+
assert.deepEqual(fs.readFileSync(redPath),oldRed);for(const [p,b]of oldTests)assert.deepEqual(fs.readFileSync(path.join(f.codeProject,p)),b);await assert.rejects(repair.execute(control),{code:'repair_already_attempted'});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('repair input budget: large malformed package, grant, identity and verdict retain strict review validation',async t=>{
|
|
78
|
+
const f=await fixture(t),before=tree(f.codeProject);
|
|
79
|
+
for(const kind of ['package','grant','identity','verdict']){
|
|
80
|
+
const feedback=structuredClone(f.reviewFeedback),identity=kind==='identity'?{...f.identity,runId:'foreign'}:f.identity;
|
|
81
|
+
if(kind==='package')feedback.registration.request.payload.reviewPackage.packageDigest='0'.repeat(64);
|
|
82
|
+
if(kind==='grant')feedback.registration.grant.packageDigest='0'.repeat(64);
|
|
83
|
+
if(kind==='verdict')feedback.result.observation.result.value.verdict='approved';
|
|
84
|
+
let expected;try{inspectFixRepairReview(feedback,identity);}catch(error){expected=error.code;}assert(expected,kind+' fixture must be genuinely invalid under the unchanged validator');
|
|
85
|
+
assert.throws(()=>prepareFixRepair({...f.options,identity,reviewFeedback:feedback},quiet()),error=>error.code===expected,kind);assert.deepEqual(tree(f.codeProject),before);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('repair input budget: feedback 12MiB and all other arguments 1MiB remain separate hard bounds',async t=>{
|
|
90
|
+
const f=await fixture(t),before=tree(f.codeProject),overFeedback={...f.reviewFeedback,oversize:'x'.repeat(12*MiB-size(f.reviewFeedback)+8)};
|
|
91
|
+
assert(size(overFeedback)>12*MiB&&size({...f.options,reviewFeedback:overFeedback})<13*MiB);
|
|
92
|
+
assert.throws(()=>prepareFixRepair({...f.options,reviewFeedback:overFeedback},quiet()),{code:'limit_exceeded'});
|
|
93
|
+
assert.throws(()=>prepareFixRepair({...f.options,defect:'x'.repeat(MiB+1)},quiet()),{code:'limit_exceeded'});
|
|
94
|
+
const edgeFeedback={...f.reviewFeedback,oversize:''};edgeFeedback.oversize='x'.repeat(12*MiB-size(edgeFeedback));
|
|
95
|
+
const {reviewFeedback,...parameters}=f.options,edgeParameters={...parameters,defect:''};edgeParameters.defect='x'.repeat(MiB-size(edgeParameters));
|
|
96
|
+
assert.equal(size(edgeFeedback),12*MiB);assert.equal(size(edgeParameters),MiB);
|
|
97
|
+
const edgeOptions={...edgeParameters,reviewFeedback:edgeFeedback};assert.equal(size(edgeOptions),13*MiB+Buffer.byteLength(',"reviewFeedback":'));
|
|
98
|
+
// This extra-key feedback remains invalid. The wrapper must reach the existing validator,
|
|
99
|
+
// rather than reject valid-sized subcontracts because of its own JSON framing bytes.
|
|
100
|
+
assert.throws(()=>inspectFixRepairReview(edgeFeedback,f.identity),{code:'invalid_input'});
|
|
101
|
+
assert.throws(()=>prepareFixRepair(edgeOptions,quiet()),{code:'invalid_input'});
|
|
102
|
+
assert.deepEqual(tree(f.codeProject),before);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test('repair input budget: plain shape and accessor rejection never execute user getters',async t=>{
|
|
106
|
+
const f=await fixture(t),before=tree(f.codeProject);let getterCalls=0;
|
|
107
|
+
const getter={...f.options};Object.defineProperty(getter,'reviewFeedback',{enumerable:true,get(){getterCalls++;throw Error('must not execute getter');}});
|
|
108
|
+
assert.throws(()=>prepareFixRepair(getter,quiet()),{code:'invalid_input'});
|
|
109
|
+
const nested={...f.reviewFeedback};Object.defineProperty(nested,'registration',{enumerable:true,get(){getterCalls++;throw Error('nested getter must not execute');}});
|
|
110
|
+
assert.throws(()=>prepareFixRepair({...f.options,reviewFeedback:nested},quiet()),{code:'invalid_input'});
|
|
111
|
+
assert.throws(()=>prepareFixRepair(Object.assign(Object.create({foreign:true}),f.options),quiet()),{code:'invalid_input'});
|
|
112
|
+
assert.throws(()=>prepareFixRepair({...f.options,arbitrary:true},quiet()),{code:'invalid_input'});assert.equal(getterCalls,0);assert.deepEqual(tree(f.codeProject),before);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('repair input budget: no-feedback legacy keeps its 1MiB limit and unchanged prepare behavior',async t=>{
|
|
116
|
+
const f=await fixture(t,{paddingBytes:8}),{reviewFeedback,...rest}=f.options,options={...rest,identity:f.firstIdentity},before=tree(f.codeProject);
|
|
117
|
+
const repair=prepareFixRepair(options,quiet());assert.deepEqual(repair.baseline.identity,f.firstIdentity);assert.deepEqual(tree(f.codeProject),before);
|
|
118
|
+
assert.throws(()=>prepareFixRepair({...options,defect:'x'.repeat(MiB+1)},quiet()),{code:'limit_exceeded'});
|
|
119
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {createHash} from 'node:crypto';
|
|
7
|
+
import {spawnSync} from 'node:child_process';
|
|
8
|
+
import {createVerificationTools} from '../runtime/js/cm-fix/review-verification.mjs';
|
|
9
|
+
|
|
10
|
+
const sha=data=>createHash('sha256').update(data).digest('hex');
|
|
11
|
+
function fixture(t,text){
|
|
12
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-review-pages-'))),cwd=path.join(root,'project');
|
|
13
|
+
fs.mkdirSync(cwd);fs.writeFileSync(path.join(cwd,'value.mjs'),text);
|
|
14
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
15
|
+
const configuration={files:['value.mjs'],checks:[{id:'value',command:[process.execPath,'value.mjs']}],mutationPaths:['value.mjs'],timeoutMs:1000};
|
|
16
|
+
const options={configuration,cwd,files:[{path:'value.mjs',sha256:sha(text),mode:fs.statSync(path.join(cwd,'value.mjs')).mode&511}],
|
|
17
|
+
requestDigest:'a'.repeat(64),packageDigest:'b'.repeat(64),evidencePath:path.join(root,'evidence.json'),activePath:path.join(root,'active.json')};
|
|
18
|
+
return {root,cwd,options,tools:createVerificationTools(options)};
|
|
19
|
+
}
|
|
20
|
+
test('read_file keeps complete small text and full-file SHA, with a terminal cursor',async t=>{
|
|
21
|
+
const text='export const value="你好🌿";\n',f=fixture(t,text);
|
|
22
|
+
const page=await f.tools.call('read_file',{path:'value.mjs'});
|
|
23
|
+
assert.equal(page.content,text);assert.equal(page.sha256,sha(text));
|
|
24
|
+
assert.equal(page.offset,0);assert.equal(page.nextOffset,null);assert.equal(page.totalBytes,Buffer.byteLength(text));
|
|
25
|
+
});
|
|
26
|
+
test('read_file reads a registered 31 KiB file in bounded pages without truncation',async t=>{
|
|
27
|
+
const text='x'.repeat(31*1024),f=fixture(t,text);let offset=0,content='';
|
|
28
|
+
do{const page=await f.tools.call('read_file',{path:'value.mjs',offset});
|
|
29
|
+
assert.equal(page.offset,offset);assert.equal(page.sha256,sha(text));assert.equal(page.totalBytes,Buffer.byteLength(text));
|
|
30
|
+
assert(Buffer.byteLength(page.content)<=16384);assert(page.content.length>0);content+=page.content;offset=page.nextOffset;
|
|
31
|
+
}while(offset!==null);
|
|
32
|
+
assert.equal(content,text);
|
|
33
|
+
});
|
|
34
|
+
test('read_file byte cursors preserve Chinese and supplementary Unicode at page edges',async t=>{
|
|
35
|
+
const text='x'.repeat(16382)+'中🌿'.repeat(3000),f=fixture(t,text);let offset=0,content='';
|
|
36
|
+
do{const page=await f.tools.call('read_file',{path:'value.mjs',offset});
|
|
37
|
+
assert(Buffer.byteLength(page.content)<=16384);assert(!page.content.includes('\ufffd'));
|
|
38
|
+
if(page.nextOffset!==null)assert.equal(page.nextOffset,offset+Buffer.byteLength(page.content));
|
|
39
|
+
content+=page.content;offset=page.nextOffset;
|
|
40
|
+
}while(offset!==null);
|
|
41
|
+
assert.equal(content,text);
|
|
42
|
+
await assert.rejects(f.tools.call('read_file',{path:'value.mjs',offset:16383}),{code:'review_verification_offset'});
|
|
43
|
+
await assert.rejects(f.tools.call('read_file',{path:'value.mjs',offset:16386}),{code:'review_verification_offset'});
|
|
44
|
+
});
|
|
45
|
+
test('read_file supports the last page of an admitted 2 MiB file without enlarging a page',async t=>{
|
|
46
|
+
const text='x'.repeat(2*1024*1024),f=fixture(t,text),offset=Buffer.byteLength(text)-100;
|
|
47
|
+
const page=await f.tools.call('read_file',{path:'value.mjs',offset});
|
|
48
|
+
assert.equal(page.content,'x'.repeat(100));assert.equal(page.nextOffset,null);assert.equal(page.sha256,sha(text));
|
|
49
|
+
const eof=await f.tools.call('read_file',{path:'value.mjs',offset:Buffer.byteLength(text)});
|
|
50
|
+
assert.equal(eof.content,'');assert.equal(eof.nextOffset,null);
|
|
51
|
+
});
|
|
52
|
+
test('empty files terminate, invalid UTF-8 cannot be silently replaced, and call budget stays bounded',async t=>{
|
|
53
|
+
const empty=fixture(t,'');assert.equal((await empty.tools.call('read_file',{path:'value.mjs'})).nextOffset,null);
|
|
54
|
+
const invalid=fixture(t,Buffer.from([0x61,0xf0,0x9f]));
|
|
55
|
+
await assert.rejects(invalid.tools.call('read_file',{path:'value.mjs'}),{code:'review_verification_encoding'});
|
|
56
|
+
const f=fixture(t,'hello');
|
|
57
|
+
for(let i=0;i<32;i++)assert.equal((await f.tools.call('read_file',{path:'value.mjs'})).content,'hello');
|
|
58
|
+
await assert.rejects(f.tools.call('read_file',{path:'value.mjs'}),{code:'review_verification_limit'});
|
|
59
|
+
});
|
|
60
|
+
test('read_file rejects invalid cursors, extra fields, unregistered paths and oversized input files',async t=>{
|
|
61
|
+
const f=fixture(t,'value');
|
|
62
|
+
for(const offset of [-1,0.5,'1',null,6,Number.MAX_SAFE_INTEGER])
|
|
63
|
+
await assert.rejects(f.tools.call('read_file',{path:'value.mjs',offset}),{code:'review_verification_offset'});
|
|
64
|
+
await assert.rejects(f.tools.call('read_file',{path:'value.mjs',offset:0,length:999999}));
|
|
65
|
+
for(const target of ['../value.mjs','other.mjs','/value.mjs'])
|
|
66
|
+
await assert.rejects(f.tools.call('read_file',{path:target,offset:0}),{code:'review_verification_path'});
|
|
67
|
+
fs.writeFileSync(path.join(f.cwd,'value.mjs'),'x'.repeat(2*1024*1024+1));
|
|
68
|
+
await assert.rejects(f.tools.call('read_file',{path:'value.mjs'}),{code:'review_verification_path'});
|
|
69
|
+
});
|
|
70
|
+
test('every continuation still rejects drift, links and active-command cleanup',async t=>{
|
|
71
|
+
for(const change of ['content','mode','symlink','active']){
|
|
72
|
+
const f=fixture(t,'x'.repeat(20000));await f.tools.call('read_file',{path:'value.mjs'});
|
|
73
|
+
if(change==='content')fs.appendFileSync(path.join(f.cwd,'value.mjs'),'changed');
|
|
74
|
+
if(change==='mode')fs.chmodSync(path.join(f.cwd,'value.mjs'),0o700);
|
|
75
|
+
if(change==='symlink'){fs.renameSync(path.join(f.cwd,'value.mjs'),path.join(f.cwd,'other.mjs'));fs.symlinkSync('other.mjs',path.join(f.cwd,'value.mjs'));}
|
|
76
|
+
if(change==='active')fs.writeFileSync(f.options.activePath,JSON.stringify({pid:123}));
|
|
77
|
+
await assert.rejects(f.tools.call('read_file',{path:'value.mjs',offset:16384}),
|
|
78
|
+
{code:change==='symlink'?'review_verification_path':change==='active'?'review_verification_cleanup':'review_verification_copy_drift'});
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
test('MCP advertises optional bounded byte offset and default path-only requests still work',t=>{
|
|
82
|
+
const f=fixture(t,'hello'),config=path.join(f.root,'tools.json');fs.writeFileSync(config,JSON.stringify(f.options));
|
|
83
|
+
const messages=[{jsonrpc:'2.0',id:1,method:'tools/list'},{jsonrpc:'2.0',id:2,method:'tools/call',params:{name:'read_file',arguments:{path:'value.mjs'}}}];
|
|
84
|
+
const result=spawnSync(process.execPath,[new URL('../runtime/js/cm-fix/review-verification-server.mjs',import.meta.url).pathname,config],
|
|
85
|
+
{input:messages.map(x=>JSON.stringify(x)).join('\n')+'\n',encoding:'utf8',timeout:5000});
|
|
86
|
+
assert.equal(result.status,0,result.stderr);const replies=result.stdout.trim().split('\n').map(x=>JSON.parse(x));
|
|
87
|
+
const tool=replies[0].result.tools.find(x=>x.name==='read_file');
|
|
88
|
+
assert.deepEqual(tool.inputSchema.required,['path']);assert.equal(tool.inputSchema.properties.offset.type,'integer');
|
|
89
|
+
assert.equal(tool.inputSchema.properties.offset.minimum,0);assert.match(tool.description,/byte/i);
|
|
90
|
+
assert.equal(JSON.parse(replies[1].result.content[0].text).content,'hello');
|
|
91
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Synthetic local capability probe; no review or permission is issued here.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import {fileURLToPath} from 'node:url';
|
|
5
|
+
import {previewClaudeTools} from '../runtime/js/cm-ai/claude-tool-preview.mjs';
|
|
6
|
+
import {createReviewVerificationSession} from '../runtime/js/cm-fix/review-verification.mjs';
|
|
7
|
+
import {readReviewVerification} from '../runtime/js/cm-fix/review-verification-contract.mjs';
|
|
8
|
+
import {need} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
9
|
+
export async function previewFixReviewVerification({codeProject,configuration,model,effort}){
|
|
10
|
+
const verification=readReviewVerification(configuration);
|
|
11
|
+
const session=createReviewVerificationSession({codeProject,configuration:verification,
|
|
12
|
+
request:{provider:'claude',requestDigest:'0'.repeat(64),payload:{reviewPackage:{packageDigest:'0'.repeat(64),files:[]}}}});
|
|
13
|
+
try{return {...await previewClaudeTools({cwd:codeProject,model,effort,verification,verificationTransport:session.transport}),timeoutMs:900000};}
|
|
14
|
+
finally{await session.close();}
|
|
15
|
+
}
|
|
16
|
+
if(process.argv[1]&&fs.realpathSync(process.argv[1])===fileURLToPath(import.meta.url)){
|
|
17
|
+
try{
|
|
18
|
+
const a=process.argv.slice(2);need((a.length===4||a.length===6)&&a[0]==='--config'&&a[2]==='--model'&&(a.length===4||a[4]==='--effort'),'invalid_arguments');
|
|
19
|
+
const st=fs.lstatSync(a[1]);need(st.isFile()&&!st.isSymbolicLink()&&st.size<=65536,'invalid_fix_config');
|
|
20
|
+
const run=JSON.parse(fs.readFileSync(a[1],'utf8'));
|
|
21
|
+
const result=await previewFixReviewVerification({codeProject:run.reproduction.cwd,configuration:run.reviewVerification,model:a[3],...(a[5]?{effort:a[5]}:{})});
|
|
22
|
+
process.stdout.write(JSON.stringify(result)+'\n');process.exitCode=result.preflight.passed?0:1;
|
|
23
|
+
}catch(e){process.stderr.write(JSON.stringify({code:/^[a-z_]+$/.test(e.code??'')?e.code:'review_verification_preflight_failed'})+'\n');process.exitCode=1;}
|
|
24
|
+
}
|