@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,235 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import {EventEmitter} from 'node:events';
|
|
4
|
+
import {PassThrough} from 'node:stream';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import {spawn} from 'node:child_process';
|
|
9
|
+
import {createInterface} from 'node:readline';
|
|
10
|
+
import {createClaudeReviewStream} from '../runtime/js/cm-ai/claude-review-stream.mjs';
|
|
11
|
+
import {claudeWorker,claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
12
|
+
import {createReviewVerificationSession} from '../runtime/js/cm-fix/review-verification.mjs';
|
|
13
|
+
|
|
14
|
+
const session_id='diagnostic-fixture';
|
|
15
|
+
const init={type:'system',subtype:'init',session_id};
|
|
16
|
+
const assistant={type:'assistant',session_id,parent_tool_use_id:null,
|
|
17
|
+
message:{role:'assistant',content:[{type:'text',text:'synthetic review'}]}};
|
|
18
|
+
const success={type:'result',subtype:'success',session_id,is_error:false,num_turns:1,structured_output:{verdict:'approved'}};
|
|
19
|
+
const api=(error='invalid_request',text='API Error',extra={})=>({...assistant,error,
|
|
20
|
+
message:{role:'assistant',content:[{type:'text',text}]},...extra});
|
|
21
|
+
function failure(message,prefix=[init],allowedTools=[]){
|
|
22
|
+
const events=[],stream=createClaudeReviewStream(event=>events.push(event),null,allowedTools);
|
|
23
|
+
prefix.forEach(value=>stream.accept(value));
|
|
24
|
+
let caught;try{stream.accept(message);}catch(error){caught=error;}
|
|
25
|
+
assert.ok(caught);assert.throws(()=>stream.finish(),{code:'incomplete_result'});
|
|
26
|
+
return {error:caught,events};
|
|
27
|
+
}
|
|
28
|
+
const privateText='PRIVATE-BODY-SENTINEL sk-private-credential https://private.invalid/secret /private/secret';
|
|
29
|
+
test('API diagnostics preserve failure classes and expose only fixed categories, status and bounded token limits',()=>{
|
|
30
|
+
for(const [kind,code] of [['authentication_failed','reviewer_auth_failed'],['billing_error','reviewer_billing_error'],
|
|
31
|
+
['rate_limit','reviewer_rate_limited'],['server_error','reviewer_server_error'],['model_not_found','reviewer_model_not_found'],
|
|
32
|
+
...['invalid_request','invalid_request_error','api_error','overloaded_error','context_window_exceeded','unknown'].map(kind=>[kind,'reviewer_api_error'])]){
|
|
33
|
+
const text='API Error: 400 '+JSON.stringify({type:'error',error:{type:'invalid_request_error',
|
|
34
|
+
message:'prompt is too long: 210123 tokens > 200000 maximum '+privateText},request_id:privateText});
|
|
35
|
+
const {error,events}=failure(api(kind,text));
|
|
36
|
+
assert.equal(error.code,code);
|
|
37
|
+
assert.deepEqual(error.failureDetail,{version:1,check:'api_error',stage:'assistant',eventType:'assistant',eventTypeLength:9,
|
|
38
|
+
eventSubtype:'absent',eventSubtypeLength:0,noticeCount:0,thinkingCount:0,progressCount:0,apiErrorClass:kind,apiErrorClassLength:kind.length,
|
|
39
|
+
providerErrorClass:'invalid_request_error',httpStatus:400,errorFlags:['prompt_too_long'],tokenBudget:{inputTokens:210123,maximumTokens:200000}});
|
|
40
|
+
assert.deepEqual(events.map(value=>value.event),['thread.started','turn.started']);
|
|
41
|
+
assert(!JSON.stringify(error.failureDetail).includes('PRIVATE'));
|
|
42
|
+
assert(Buffer.byteLength(JSON.stringify(error.failureDetail))<1024);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
test('unknown or malformed provider fields and oversized API bodies never enter diagnostics',()=>{
|
|
46
|
+
for(const text of [privateText,'API Error: 400 '+JSON.stringify({error:{type:privateText,message:privateText}}),
|
|
47
|
+
'API Error: 400 '+privateText.repeat(200),
|
|
48
|
+
'API Error: 400 '+JSON.stringify({error:{type:'api_error',message:'prompt is too long: 1234567890 tokens > 200000 maximum'}})]){
|
|
49
|
+
const {error}=failure(api(privateText,text,{subtype:privateText,status_code:'401',error_status:999,api_error_status:99}));
|
|
50
|
+
assert.equal(error.code,'reviewer_api_error');assert.equal(error.failureDetail.apiErrorClass,'other');
|
|
51
|
+
assert.equal(error.failureDetail.eventSubtype,'other');assert.equal(error.failureDetail.tokenBudget,null);
|
|
52
|
+
assert.equal(error.failureDetail.httpStatus,text.startsWith('API Error: 400 ')?400:null);
|
|
53
|
+
assert(!JSON.stringify(error.failureDetail).includes('PRIVATE'));
|
|
54
|
+
assert(!JSON.stringify(error.failureDetail).includes('https:'));
|
|
55
|
+
assert(!JSON.stringify(error.failureDetail).includes('/private/'));
|
|
56
|
+
}
|
|
57
|
+
const explicit=failure(api('unknown','context_length_exceeded '+privateText,{api_error_status:413})).error.failureDetail;
|
|
58
|
+
assert.equal(explicit.httpStatus,413);assert.deepEqual(explicit.errorFlags,['context_length_exceeded']);
|
|
59
|
+
const huge=failure({type:privateText.repeat(15000),subtype:privateText.repeat(15000),session_id}).error.failureDetail;
|
|
60
|
+
assert.equal(huge.eventType,'other');assert.equal(huge.eventSubtype,'other');
|
|
61
|
+
assert.equal(huge.eventTypeLength,1_000_001);assert.equal(huge.eventSubtypeLength,1_000_001);
|
|
62
|
+
assert(Buffer.byteLength(JSON.stringify(huge))<1024);
|
|
63
|
+
});
|
|
64
|
+
test('locally known but unsupported protocol enums are diagnosed without accepting them',()=>{
|
|
65
|
+
for(const subtype of ['compact_boundary','status','task_started','task_progress','task_notification',
|
|
66
|
+
'files_persisted','hook_progress','local_command_output']){
|
|
67
|
+
const {error}=failure({type:'system',subtype,session_id,body:privateText});
|
|
68
|
+
assert.equal(error.code,'unexpected_event');assert.equal(error.failureDetail.check,'unknown_system_subtype');
|
|
69
|
+
assert.equal(error.failureDetail.eventType,'system');assert.equal(error.failureDetail.eventSubtype,subtype);
|
|
70
|
+
}
|
|
71
|
+
for(const type of ['auth_status','keep_alive','stream_event','tool_use_summary']){
|
|
72
|
+
const {error}=failure({type,session_id,body:privateText});
|
|
73
|
+
assert.equal(error.code,'unexpected_event');assert.equal(error.failureDetail.check,'unknown_message_type');
|
|
74
|
+
assert.equal(error.failureDetail.eventType,type);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
test('unexpected_event distinguishes exact existing notice, thinking and terminal boundaries',()=>{
|
|
78
|
+
const notice={type:'system',subtype:'api_retry',session_id};
|
|
79
|
+
const heartbeat={type:'system',subtype:'thinking_tokens',session_id};
|
|
80
|
+
for(const [message,prefix,check,count] of [
|
|
81
|
+
[notice,[init,...Array(32).fill(notice)],'notice_limit',32],
|
|
82
|
+
[heartbeat,[init,...Array(4096).fill(heartbeat)],'thinking_limit',4096],
|
|
83
|
+
[notice,[init,assistant,success],'terminal_stage',0],
|
|
84
|
+
]){
|
|
85
|
+
const {error}=failure(message,prefix);assert.equal(error.code,'unexpected_event');assert.equal(error.failureDetail.check,check);
|
|
86
|
+
if(check==='notice_limit')assert.equal(error.failureDetail.noticeCount,count);
|
|
87
|
+
if(check==='thinking_limit')assert.equal(error.failureDetail.thinkingCount,count);
|
|
88
|
+
if(check==='terminal_stage')assert.equal(error.failureDetail.stage,'done');
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
async function run(wire,onDiagnostic){
|
|
93
|
+
const config={cwd:'/tmp',model:'diagnostic-fixture',cli:'never-execute-provider'};
|
|
94
|
+
const events=[],kills=[],terminals=[];
|
|
95
|
+
const worker=claudeWorker({...config,onDiagnostic,timeoutMs:5000,
|
|
96
|
+
preflight:{passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint(config)},
|
|
97
|
+
killProcess:(pid,signal)=>kills.push({pid,signal}),
|
|
98
|
+
spawnProcess:()=>{
|
|
99
|
+
const child=new EventEmitter();
|
|
100
|
+
// No PID: owned-process cleanup cannot reach a real process.
|
|
101
|
+
child.kill=()=>true;
|
|
102
|
+
child.stdin=new PassThrough();child.stdout=new PassThrough();child.stderr=new PassThrough();
|
|
103
|
+
child.stdin.resume();
|
|
104
|
+
child.stdin.once('finish',()=>queueMicrotask(()=>{
|
|
105
|
+
child.stderr.end(privateText);
|
|
106
|
+
child.stdout.end(wire.map(JSON.stringify).join('\n')+'\n');
|
|
107
|
+
child.emit('close',wire.at(-1)===success?0:null,wire.at(-1)===success?null:'SIGKILL');
|
|
108
|
+
}));return child;
|
|
109
|
+
}});
|
|
110
|
+
const result=await worker({prompt:'synthetic-only'},{signal:new AbortController().signal,onEvent:event=>events.push(event),onTerminal:value=>terminals.push(value)});
|
|
111
|
+
return {result,events,kills:kills.map(value=>value.signal),terminals};
|
|
112
|
+
}
|
|
113
|
+
test('worker diagnostic sidecar preserves strict receipts, cleanup signals and first failure',async()=>{
|
|
114
|
+
const wire=[init,api('invalid_request','API Error: 400 '+JSON.stringify({error:{type:'invalid_request_error',message:'prompt_too_long '+privateText}})),
|
|
115
|
+
{type:'system',subtype:'status',session_id}];
|
|
116
|
+
const rows=[];
|
|
117
|
+
const [baseline,withDiagnostic,throwing]=await Promise.all([run(wire),run(wire,row=>rows.push(row)),
|
|
118
|
+
run(wire,()=>{throw Error(privateText);})]);
|
|
119
|
+
assert.deepEqual(withDiagnostic,baseline);assert.deepEqual(throwing,baseline);
|
|
120
|
+
assert.deepEqual(baseline.result,{status:'failed',code:'reviewer_api_error'});
|
|
121
|
+
assert.deepEqual(baseline.events.map(value=>value.event),['thread.started','turn.started','process_closed']);
|
|
122
|
+
assert.equal(baseline.events.at(-1).signal,'SIGKILL');assert.equal(baseline.events.at(-1).timed_out,false);
|
|
123
|
+
assert.deepEqual(baseline.kills,['SIGTERM','SIGKILL']);assert.deepEqual(baseline.terminals,[]);
|
|
124
|
+
assert.equal(rows.length,1);assert.equal(rows[0].code,'reviewer_api_error');
|
|
125
|
+
assert.equal(rows[0].failureDetail.providerErrorClass,'invalid_request_error');
|
|
126
|
+
assert(!JSON.stringify(rows).includes('PRIVATE'));assert.deepEqual(Object.keys(baseline.result),['status','code']);
|
|
127
|
+
});
|
|
128
|
+
test('worker exposes unsupported subtype, reports no success diagnostic and cannot accept a diagnostic verdict',async()=>{
|
|
129
|
+
const rows=[];
|
|
130
|
+
const actual=await run([init,{type:'system',subtype:'status',session_id}],row=>{rows.push(row);return {status:'succeeded',value:{verdict:'approved'}};});
|
|
131
|
+
assert.deepEqual(actual.result,{status:'failed',code:'unexpected_event'});
|
|
132
|
+
assert.equal(rows.length,1);assert.equal(rows[0].failureDetail.eventSubtype,'status');assert.deepEqual(actual.terminals,[]);
|
|
133
|
+
const successRows=[],passed=await run([init,assistant,success],row=>successRows.push(row));
|
|
134
|
+
assert.deepEqual(passed.result,{status:'succeeded',value:{verdict:'approved'}});assert.deepEqual(successRows,[]);
|
|
135
|
+
assert.deepEqual(passed.kills,[]);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const reviewTools=['mcp__cm_review__read_file','mcp__cm_review__run_check','mcp__cm_review__mutate_check'];
|
|
139
|
+
const toolCall=(name=reviewTools[1],id='pending-tool')=>({...assistant,
|
|
140
|
+
message:{role:'assistant',content:[{type:'tool_use',id,name,input:{id:'long'}}]}});
|
|
141
|
+
const toolResult=(id='pending-tool')=>({type:'user',session_id,
|
|
142
|
+
message:{role:'user',content:[{type:'tool_result',tool_use_id:id,is_error:false,content:'synthetic result'}]}});
|
|
143
|
+
const progress=(extra={})=>({type:'tool_progress',session_id,tool_use_id:'pending-tool',
|
|
144
|
+
tool_name:reviewTools[1],parent_tool_use_id:null,elapsed_time_seconds:1,...extra});
|
|
145
|
+
test('progress is bound to an allowed pending tool and never emits review events or clears its result',()=>{
|
|
146
|
+
for(const name of [...reviewTools,'StructuredOutput']){
|
|
147
|
+
const events=[],notices=[],stream=createClaudeReviewStream(event=>events.push(event),value=>notices.push(value),reviewTools);
|
|
148
|
+
stream.accept(init);stream.accept(toolCall(name));
|
|
149
|
+
for(const elapsed of [0,1,10])stream.accept(progress({tool_name:name,elapsed_time_seconds:elapsed,payload:privateText}));
|
|
150
|
+
assert.deepEqual(events.map(value=>value.event),['thread.started','turn.started']);assert.deepEqual(notices,[]);
|
|
151
|
+
stream.accept(toolResult());stream.accept(success);assert.deepEqual(stream.finish(),{status:'succeeded',value:{verdict:'approved'}});
|
|
152
|
+
}
|
|
153
|
+
const {error}=failure(success,[init,toolCall(),progress()],reviewTools);
|
|
154
|
+
assert.equal(error.code,'unexpected_result');assert.equal(error.failureDetail.progressCount,1);
|
|
155
|
+
const stream=createClaudeReviewStream(()=>{},null,reviewTools);
|
|
156
|
+
[init,toolCall(),progress()].forEach(value=>stream.accept(value));assert.throws(()=>stream.finish(),{code:'incomplete_result'});
|
|
157
|
+
});
|
|
158
|
+
test('progress rejects wrong sessions, missing calls, mismatched names, unapproved tools and invalid elapsed time',()=>{
|
|
159
|
+
for(const [message,prefix,code,check] of [
|
|
160
|
+
[progress({session_id:'different'}),[init,toolCall()],'session_mismatch','session_mismatch'],
|
|
161
|
+
[progress({session_id:''}),[init,toolCall()],'invalid_session','invalid_session'],
|
|
162
|
+
[progress(),[],'missing_init','missing_init'],
|
|
163
|
+
[progress(),[init],'unexpected_event','tool_progress_stage'],
|
|
164
|
+
[progress({tool_use_id:'unregistered'}),[init,toolCall()],'unexpected_event','tool_progress_identity'],
|
|
165
|
+
[progress({tool_use_id:null}),[init,toolCall()],'unexpected_event','tool_progress_identity'],
|
|
166
|
+
[progress({tool_name:reviewTools[0]}),[init,toolCall()],'unexpected_event','tool_progress_tool'],
|
|
167
|
+
[progress({tool_name:'Bash'}),[init,toolCall('Bash')],'unexpected_event','tool_progress_tool'],
|
|
168
|
+
[progress({parent_tool_use_id:'child'}),[init,toolCall()],'unexpected_event','tool_progress_parent'],
|
|
169
|
+
[progress({parent_tool_use_id:undefined}),[init,toolCall()],'unexpected_event','tool_progress_parent'],
|
|
170
|
+
[progress(),[init,toolCall(),toolResult()],'unexpected_event','tool_progress_identity'],
|
|
171
|
+
[progress(),[init,toolCall(),toolResult(),success],'unexpected_event','terminal_stage'],
|
|
172
|
+
...[-1,0.5,Infinity,NaN,'1',null,Number.MAX_SAFE_INTEGER+1].map(elapsed_time_seconds=>[
|
|
173
|
+
progress({elapsed_time_seconds}),[init,toolCall()],'unexpected_event','tool_progress_elapsed']),
|
|
174
|
+
]){
|
|
175
|
+
const {error}=failure(message,prefix,reviewTools);assert.equal(error.code,code);assert.equal(error.failureDetail.check,check);
|
|
176
|
+
}
|
|
177
|
+
assert.equal(failure(progress(),[init,toolCall()]).error.failureDetail.check,'tool_progress_tool');
|
|
178
|
+
});
|
|
179
|
+
test('progress has a separate bounded budget while notices, thinking and pending tool rules stay intact',()=>{
|
|
180
|
+
const prefix=[init,toolCall(),...Array(32).fill({type:'system',subtype:'api_retry',session_id}),
|
|
181
|
+
...Array(4096).fill({type:'system',subtype:'thinking_tokens',session_id}),...Array(4096).fill(progress())];
|
|
182
|
+
const stream=createClaudeReviewStream(()=>{},null,reviewTools);prefix.forEach(value=>stream.accept(value));
|
|
183
|
+
stream.accept(toolResult());stream.accept(success);assert.equal(stream.finish().status,'succeeded');
|
|
184
|
+
const {error}=failure(progress(),prefix,reviewTools);assert.equal(error.code,'unexpected_event');
|
|
185
|
+
assert.equal(error.failureDetail.check,'tool_progress_limit');assert.equal(error.failureDetail.progressCount,4096);
|
|
186
|
+
assert.equal(error.failureDetail.noticeCount,32);assert.equal(error.failureDetail.thinkingCount,4096);
|
|
187
|
+
});
|
|
188
|
+
test('a real isolated MCP check remains pending across progress and finishes through its original tool result',
|
|
189
|
+
{skip:process.platform!=='darwin',timeout:15000},async()=>{
|
|
190
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'claude-progress-')));
|
|
191
|
+
const source="import {value} from './value.mjs'; await new Promise(resolve=>setTimeout(resolve,300)); if(value!==1)process.exit(1);\n";
|
|
192
|
+
fs.writeFileSync(path.join(root,'long.test.mjs'),source);
|
|
193
|
+
fs.writeFileSync(path.join(root,'value.mjs'),'export const value=1;\n');
|
|
194
|
+
const verification={files:['value.mjs','long.test.mjs'],checks:[{id:'long',command:[process.execPath,'long.test.mjs']}],mutationPaths:['value.mjs'],timeoutMs:5000};
|
|
195
|
+
let session,server,closed,pendingReply;
|
|
196
|
+
try{
|
|
197
|
+
session=createReviewVerificationSession({codeProject:root,configuration:verification,
|
|
198
|
+
request:{requestDigest:'a'.repeat(64),provider:'claude',payload:{reviewPackage:{packageDigest:'b'.repeat(64),files:[]}}}});
|
|
199
|
+
const transport=JSON.parse(session.transport.mcpConfig).mcpServers.cm_review;
|
|
200
|
+
server=spawn(transport.command,transport.args,{stdio:['pipe','pipe','pipe']});server.stderr.resume();
|
|
201
|
+
closed=new Promise(resolve=>server.once('close',resolve));
|
|
202
|
+
const reply=new Promise((resolve,reject)=>{pendingReply={resolve,reject};});
|
|
203
|
+
createInterface({input:server.stdout}).on('line',line=>{
|
|
204
|
+
try{const value=JSON.parse(line);if(value.id===1)pendingReply.resolve(value.result);}catch(error){pendingReply.reject(error);}
|
|
205
|
+
});
|
|
206
|
+
server.once('error',error=>pendingReply.reject(error));
|
|
207
|
+
const events=[],diagnostics=[],config={cwd:root,model:'diagnostic-fixture',cli:'never-execute-provider',verification};
|
|
208
|
+
let transportError=null;
|
|
209
|
+
const worker=claudeWorker({...config,verificationTransport:session.transport,timeoutMs:10000,
|
|
210
|
+
preflight:{passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint(config)},
|
|
211
|
+
onDiagnostic:value=>diagnostics.push(value),killProcess:()=>{throw Error('unexpected fixture stop');},
|
|
212
|
+
spawnProcess:()=>{
|
|
213
|
+
const child=new EventEmitter();child.kill=()=>true;
|
|
214
|
+
child.stdin=new PassThrough();child.stdout=new PassThrough();child.stderr=new PassThrough();child.stdin.resume();
|
|
215
|
+
child.stdin.once('finish',()=>{void(async()=>{
|
|
216
|
+
const emit=value=>child.stdout.write(JSON.stringify(value)+'\n');
|
|
217
|
+
try{
|
|
218
|
+
emit(init);emit(toolCall());
|
|
219
|
+
server.stdin.write(JSON.stringify({jsonrpc:'2.0',id:1,method:'tools/call',params:{name:'run_check',arguments:{id:'long'}}})+'\n');
|
|
220
|
+
let finished=false;void reply.then(()=>{finished=true;});
|
|
221
|
+
for(let i=0;i<3;i++){await new Promise(resolve=>setTimeout(resolve,25));assert.equal(finished,false);emit(progress({elapsed_time_seconds:0}));}
|
|
222
|
+
const value=await reply;assert.equal(value.isError,undefined);assert.equal(JSON.parse(value.content[0].text).exitCode,0);
|
|
223
|
+
emit(toolResult());emit(success);child.stdout.end();child.emit('close',0,null);
|
|
224
|
+
}catch(error){transportError=error;child.emit('close',1,null);}
|
|
225
|
+
})();});return child;
|
|
226
|
+
}});
|
|
227
|
+
const result=await worker({prompt:'synthetic-only'},{signal:new AbortController().signal,onEvent:value=>events.push(value)});
|
|
228
|
+
assert.equal(transportError,null);assert.deepEqual(result,{status:'succeeded',value:{verdict:'approved'}});
|
|
229
|
+
assert.deepEqual(diagnostics,[]);assert.deepEqual(events.map(value=>value.event),['thread.started','turn.started','item.completed','turn.completed','process_closed']);
|
|
230
|
+
assert.equal(fs.readFileSync(path.join(root,'long.test.mjs'),'utf8'),source);
|
|
231
|
+
}finally{
|
|
232
|
+
if(server){server.stdin.end();await closed;}
|
|
233
|
+
await session?.close();fs.rmSync(root,{recursive:true,force:true});
|
|
234
|
+
}
|
|
235
|
+
});
|
|
@@ -387,3 +387,16 @@ test('API error classes before any tool call name the reviewer failure',()=>{
|
|
|
387
387
|
assert.throws(()=>messages.forEach(message=>stream.accept(message)),{code:'unexpected_assistant'});
|
|
388
388
|
}
|
|
389
389
|
});
|
|
390
|
+
|
|
391
|
+
test('opt-in verification permits only the fixed MCP tools; default remains no-tools',()=>{
|
|
392
|
+
const names=['mcp__cm_review__read_file','mcp__cm_review__run_check','mcp__cm_review__mutate_check'];
|
|
393
|
+
for(const name of names){
|
|
394
|
+
const messages=[transcript()[0],assistant([tool('verify',name)]),toolResult('verify'),transcript()[2]];
|
|
395
|
+
assert.throws(()=>decode(messages),{code:'unexpected_tool_or_content'});
|
|
396
|
+
const stream=createClaudeReviewStream(()=>{},null,names);messages.forEach(m=>stream.accept(m));assert.equal(stream.finish().status,'succeeded');
|
|
397
|
+
}
|
|
398
|
+
for(const name of ['Bash','Read','mcp__other__run_check']){
|
|
399
|
+
const stream=createClaudeReviewStream(()=>{},null,names);stream.accept(transcript()[0]);stream.accept(assistant([tool('bad',name)]));
|
|
400
|
+
assert.throws(()=>stream.accept(toolResult('bad')),{code:'unexpected_tool_or_content'});
|
|
401
|
+
}
|
|
402
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import {EventEmitter} from 'node:events';
|
|
4
|
+
import {PassThrough} from 'node:stream';
|
|
5
|
+
import {codexDeveloperWorker} from '../runtime/js/cm-ai/worker-codex-developer.mjs';
|
|
6
|
+
|
|
7
|
+
const reconnect=n=>({type:'error',message:`Reconnecting... ${n}/5 (stream disconnected before completion: synthetic)`});
|
|
8
|
+
const start=[{type:'thread.started',thread_id:'synthetic-developer-reconnect'},{type:'turn.started'}];
|
|
9
|
+
const finish=[{type:'item.completed',item:{type:'agent_message',text:'{"outcome":"implemented"}'}},{type:'turn.completed'}];
|
|
10
|
+
const succeeded={status:'succeeded',value:{outcome:'implemented'},providerThread:'synthetic-developer-reconnect'};
|
|
11
|
+
|
|
12
|
+
async function stream(rows,{throwNotice=false}={}){
|
|
13
|
+
const notices=[];
|
|
14
|
+
const run=codexDeveloperWorker({cwd:'/fixture',model:'gpt-6.1-sol',effort:'high',learning:false,timeoutMs:1000,
|
|
15
|
+
onNotice:notice=>{notices.push(notice);if(throwNotice)throw Error('synthetic notice sink failure');},
|
|
16
|
+
spawnProcess(){
|
|
17
|
+
const child=new EventEmitter();
|
|
18
|
+
child.stdin=new PassThrough();child.stdout=new PassThrough();child.stderr=new PassThrough();
|
|
19
|
+
queueMicrotask(()=>{
|
|
20
|
+
for(const row of rows)child.stdout.write(JSON.stringify(row)+'\n');
|
|
21
|
+
child.stdout.end();child.stderr.end();child.emit('close',0,null);
|
|
22
|
+
});
|
|
23
|
+
return child;
|
|
24
|
+
}});
|
|
25
|
+
const result=await run({prompt:'synthetic developer reconnect test'},{signal:new AbortController().signal});
|
|
26
|
+
return {result,notices};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('developer reconnect 2/5 through 5/5 followed by HTTPS fallback succeeds',async()=>{
|
|
30
|
+
const reconnects=[2,3,4,5].map(reconnect);
|
|
31
|
+
const fallback={type:'item.completed',item:{type:'error',message:'Falling back to HTTPS transport. synthetic'}};
|
|
32
|
+
const actual=await stream([...start,...reconnects,fallback,...finish]);
|
|
33
|
+
assert.deepEqual(actual.result,succeeded);
|
|
34
|
+
assert.deepEqual(actual.notices,[...reconnects.map(row=>row.message),fallback.item.message]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('developer reconnect notices cannot hide a later turn.failed',async()=>{
|
|
38
|
+
const actual=await stream([...start,reconnect(2),reconnect(3),{type:'turn.failed',error:{message:'Reconnecting... 4/5'}}]);
|
|
39
|
+
assert.deepEqual(actual.result,{status:'unknown',code:'provider_failed'});
|
|
40
|
+
assert.deepEqual(actual.notices,[reconnect(2).message,reconnect(3).message]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('developer non-reconnect top-level errors remain fatal',async()=>{
|
|
44
|
+
for(const message of ['request failed','prefix Reconnecting... 2/5','Reconnecting.. 2/5','Reconnecting... two/5',null]){
|
|
45
|
+
const actual=await stream([...start,{type:'error',message},...finish]);
|
|
46
|
+
assert.deepEqual(actual.result,{status:'unknown',code:'provider_failed'});
|
|
47
|
+
assert.deepEqual(actual.notices,[]);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('developer reconnect limit allows 32 notices independently of eight item notices',async()=>{
|
|
52
|
+
const reconnects=Array.from({length:32},(_,n)=>reconnect(n+1));
|
|
53
|
+
const items=Array.from({length:8},()=>({type:'item.completed',item:{type:'error',message:'synthetic startup notice'}}));
|
|
54
|
+
const actual=await stream([...start,...reconnects,...items,...finish]);
|
|
55
|
+
assert.deepEqual(actual.result,succeeded);
|
|
56
|
+
assert.deepEqual(actual.notices,[...reconnects.map(row=>row.message),...items.map(row=>row.item.message)]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('developer reconnect notice 33 fails instead of allowing an endless stream',async()=>{
|
|
60
|
+
const actual=await stream([...start,...Array.from({length:33},(_,n)=>reconnect(n+1)),...finish]);
|
|
61
|
+
assert.deepEqual(actual.result,{status:'unknown',code:'provider_failed'});
|
|
62
|
+
assert.deepEqual(actual.notices,Array.from({length:32},(_,n)=>reconnect(n+1).message));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('developer reconnect notices are bounded and notice sink failure does not fail a turn',async()=>{
|
|
66
|
+
const notice={...reconnect(1),message:reconnect(1).message+'x'.repeat(400)};
|
|
67
|
+
const actual=await stream([...start,notice,...finish],{throwNotice:true});
|
|
68
|
+
assert.deepEqual(actual.result,succeeded);
|
|
69
|
+
assert.deepEqual(actual.notices,[notice.message.slice(0,200)]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('developer reconnect before thread may recover but cannot replace thread initialization',async()=>{
|
|
73
|
+
const recovered=await stream([reconnect(1),...start,...finish]);
|
|
74
|
+
assert.deepEqual(recovered.result,succeeded);
|
|
75
|
+
assert.deepEqual(recovered.notices,[reconnect(1).message]);
|
|
76
|
+
const missing=await stream([reconnect(1),{type:'turn.started'},...finish]);
|
|
77
|
+
assert.deepEqual(missing.result,{status:'unknown',code:'thread_missing'});
|
|
78
|
+
assert.deepEqual(missing.notices,[reconnect(1).message]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test('developer reconnect after completion remains fatal without emitting a notice',async()=>{
|
|
82
|
+
const actual=await stream([...start,...finish,reconnect(1)]);
|
|
83
|
+
assert.deepEqual(actual.result,{status:'unknown',code:'provider_failed'});
|
|
84
|
+
assert.deepEqual(actual.notices,[]);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('developer reconnect does not reset or bypass existing item and turn guards',async()=>{
|
|
88
|
+
const item={type:'item.completed',item:{type:'error',message:'synthetic startup notice'}};
|
|
89
|
+
for(const [rows,code] of [
|
|
90
|
+
[[...start,...Array(8).fill(item),reconnect(1),item,...finish],'invalid_event'],
|
|
91
|
+
[[start[0],reconnect(1),...finish],'turn_missing'],
|
|
92
|
+
[[...start,reconnect(1),start[0],...finish],'thread_mismatch'],
|
|
93
|
+
[[...start,reconnect(1),start[1],...finish],'duplicate_turn'],
|
|
94
|
+
]){
|
|
95
|
+
const actual=await stream(rows);
|
|
96
|
+
assert.deepEqual(actual.result,{status:'unknown',code});
|
|
97
|
+
}
|
|
98
|
+
});
|
|
@@ -4,6 +4,8 @@ import {spawn} from 'node:child_process';
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import os from 'node:os';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
+
import {EventEmitter} from 'node:events';
|
|
8
|
+
import {PassThrough} from 'node:stream';
|
|
7
9
|
import {codexDeveloperWorker,developerArgs} from '../runtime/js/cm-ai/worker-codex-developer.mjs';
|
|
8
10
|
import {commonArgs} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
9
11
|
import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
@@ -211,3 +213,121 @@ for(const mode of ['omitted','non-function','throwing'])test(`developer notice c
|
|
|
211
213
|
assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),
|
|
212
214
|
{status:'unavailable',code:'worker_dispatch_limit'});
|
|
213
215
|
}));
|
|
216
|
+
|
|
217
|
+
// 2026-10-26: a Codex developer that hits the API rate limit (429 / Too Many Requests /
|
|
218
|
+
// rate limit, the same rule as the Codex reviewer) ends as developer_rate_limited;
|
|
219
|
+
// other provider failures stay provider_failed. Only the class is kept.
|
|
220
|
+
const limitedScript=message=>`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
|
|
221
|
+
const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
|
|
222
|
+
emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
|
|
223
|
+
emit({type:'error',message:${JSON.stringify(message)}});emit({type:'turn.failed',error:{message:${JSON.stringify(message)}}});
|
|
224
|
+
setTimeout(()=>process.exit(1),5000);
|
|
225
|
+
});`;
|
|
226
|
+
for(const [message,code] of [['exceeded retry limit, last status: 429 Too Many Requests','developer_rate_limited'],
|
|
227
|
+
['unexpected status HTTP 429','developer_rate_limited'],['Rate limit reached','developer_rate_limited'],
|
|
228
|
+
['request failed','provider_failed'],['error 4290 unrelated id','provider_failed']])
|
|
229
|
+
test(`Codex developer failure "${message}" ends as ${code}`,()=>fixture(async cwd=>{
|
|
230
|
+
const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
|
|
231
|
+
spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',limitedScript(message)],options)});
|
|
232
|
+
const result=await worker({prompt:'synthetic'},{signal:new AbortController().signal});
|
|
233
|
+
assert.deepEqual(result,{status:'unknown',code});
|
|
234
|
+
}));
|
|
235
|
+
|
|
236
|
+
// Codex review round 1: the class is collected from every failure event of the turn
|
|
237
|
+
// (as the Codex reviewer does), whichever carries it; the terminal stays the first.
|
|
238
|
+
const failedPair=(first,second)=>`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
|
|
239
|
+
const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
|
|
240
|
+
emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
|
|
241
|
+
emit({type:'error',message:${JSON.stringify(first)}});emit({type:'turn.failed',error:{message:${JSON.stringify(second)}}});
|
|
242
|
+
setTimeout(()=>process.exit(1),5000);
|
|
243
|
+
});`;
|
|
244
|
+
for(const [first,second,code] of [['Request failed','HTTP 429 Too Many Requests','developer_rate_limited'],
|
|
245
|
+
['HTTP 429 Too Many Requests','Request failed','developer_rate_limited'],['Request failed','stream closed','provider_failed']])
|
|
246
|
+
test(`Codex developer error "${first}" then turn.failed "${second}" ends as ${code}`,()=>fixture(async cwd=>{
|
|
247
|
+
const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
|
|
248
|
+
spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',failedPair(first,second)],options)});
|
|
249
|
+
assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code});
|
|
250
|
+
}));
|
|
251
|
+
|
|
252
|
+
// Ticket 11: Codex can write the generic error line first and the turn.failed naming
|
|
253
|
+
// the 429 a moment later. Killing the group on the first line used to lose the class.
|
|
254
|
+
const delayedPair=delayMs=>`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
|
|
255
|
+
const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
|
|
256
|
+
emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
|
|
257
|
+
emit({type:'error',message:'Request failed'});
|
|
258
|
+
${delayMs===null?'':`setTimeout(()=>emit({type:'turn.failed',error:{message:'HTTP 429 Too Many Requests'}}),${delayMs});`}
|
|
259
|
+
setTimeout(()=>process.exit(1),5000);
|
|
260
|
+
});`;
|
|
261
|
+
test('Codex developer keeps the 429 of a turn.failed written 400 ms after a generic error',()=>fixture(async cwd=>{
|
|
262
|
+
const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
|
|
263
|
+
spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',delayedPair(400)],options)});
|
|
264
|
+
assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'developer_rate_limited'});
|
|
265
|
+
}));
|
|
266
|
+
test('Codex developer stops a lone generic error within the short grace, not the call timeout',()=>fixture(async cwd=>{
|
|
267
|
+
const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',timeoutMs:60000,
|
|
268
|
+
spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',delayedPair(null)],options)});
|
|
269
|
+
const started=Date.now();
|
|
270
|
+
assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'provider_failed'});
|
|
271
|
+
assert.ok(Date.now()-started<4500,`stopped after ${Date.now()-started} ms`);
|
|
272
|
+
}));
|
|
273
|
+
|
|
274
|
+
// Codex review r1 (ticket 11): a cancel or timeout during the grace keeps its own code,
|
|
275
|
+
// and a second error line stops at once instead of waiting out the grace.
|
|
276
|
+
test('Codex developer cancel and timeout during the error grace keep cancelled and timeout',()=>fixture(async cwd=>{
|
|
277
|
+
const cancelled=new AbortController();
|
|
278
|
+
const cancel=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
|
|
279
|
+
spawnProcess:(_,__,options)=>{setTimeout(()=>cancelled.abort(),300);return spawn(process.execPath,['-e',delayedPair(null)],options);}});
|
|
280
|
+
assert.deepEqual(await cancel({prompt:'synthetic'},{signal:cancelled.signal}),{status:'unknown',code:'cancelled'});
|
|
281
|
+
const timeout=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',timeoutMs:500,
|
|
282
|
+
spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',delayedPair(null)],options)});
|
|
283
|
+
assert.deepEqual(await timeout({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'timeout'});
|
|
284
|
+
}));
|
|
285
|
+
test('Codex developer stops at once on a second error line and keeps its 429 class',()=>fixture(async cwd=>{
|
|
286
|
+
const script=`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
|
|
287
|
+
const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
|
|
288
|
+
emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
|
|
289
|
+
emit({type:'error',message:'Request failed'});setTimeout(()=>emit({type:'error',message:'HTTP 429 Too Many Requests'}),100);
|
|
290
|
+
setTimeout(()=>process.exit(1),5000);
|
|
291
|
+
});`;
|
|
292
|
+
const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
|
|
293
|
+
spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',script],options)});
|
|
294
|
+
const started=Date.now();
|
|
295
|
+
assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'developer_rate_limited'});
|
|
296
|
+
// Without the immediate stop the 2 s grace plus the 1 s kill escalation would pass 3 s.
|
|
297
|
+
assert.ok(Date.now()-started<2700,`stopped after ${Date.now()-started} ms`);
|
|
298
|
+
}));
|
|
299
|
+
|
|
300
|
+
test('Codex developer starts no grace for an unterminated error read at close',async()=>{
|
|
301
|
+
const timers=()=>process.getActiveResourcesInfo().filter(name=>name==='Timeout').length;
|
|
302
|
+
const worker=codexDeveloperWorker({cwd:'/fixture',model:'fixture',schemaPath:'/unused',
|
|
303
|
+
spawnProcess(){
|
|
304
|
+
// In-memory child without a pid: group signals are skipped, only the stream matters.
|
|
305
|
+
const child=new EventEmitter();child.stdin=new PassThrough();child.stdout=new PassThrough();child.stderr=new PassThrough();
|
|
306
|
+
child.stdin.on('finish',()=>{
|
|
307
|
+
child.stdout.write([{type:'thread.started',thread_id:'fixture'},{type:'turn.started'}].map(x=>JSON.stringify(x)+'\n').join(''));
|
|
308
|
+
child.stdout.end(JSON.stringify({type:'error',message:'Request failed'}));
|
|
309
|
+
child.stdout.once('end',()=>{child.emit('exit',1,null);child.emit('close',1,null);});
|
|
310
|
+
});
|
|
311
|
+
return child;
|
|
312
|
+
}});
|
|
313
|
+
const before=timers();
|
|
314
|
+
assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'provider_failed'});
|
|
315
|
+
assert.equal(timers(),before,'no grace timer left after the call settled');
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
// 2026-10-27: a Codex developer that exits right after its failed turn (its group is
|
|
319
|
+
// then only our unreaped zombie child, EPERM on macOS) is proven stopped, so the call
|
|
320
|
+
// keeps its class instead of process_cleanup_failed.
|
|
321
|
+
test('Codex developer exiting at once after a 429 keeps developer_rate_limited (no cleanup failure)',()=>fixture(async cwd=>{
|
|
322
|
+
const script=`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
|
|
323
|
+
const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
|
|
324
|
+
emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
|
|
325
|
+
emit({type:'error',message:'HTTP 429 Too Many Requests'});emit({type:'turn.failed',error:{message:'HTTP 429 Too Many Requests'}});
|
|
326
|
+
process.exit(1);
|
|
327
|
+
});`;
|
|
328
|
+
for(let attempt=0;attempt<3;attempt++){
|
|
329
|
+
const worker=codexDeveloperWorker({cwd,model:'fixture',schemaPath:'/unused',
|
|
330
|
+
spawnProcess:(_,__,options)=>spawn(process.execPath,['-e',script],options)});
|
|
331
|
+
assert.deepEqual(await worker({prompt:'synthetic'},{signal:new AbortController().signal}),{status:'unknown',code:'developer_rate_limited'},`attempt ${attempt}`);
|
|
332
|
+
}
|
|
333
|
+
}));
|