Description
Add E2E tests for double-dispatch, exact lease, and shell bypass. Add structured log events for the full dispatch lifecycle. Fail framework self-test if regression conditions are detected.
Code References (§6 Phase E)
Files to Modify
.opencode/scripts/framework-self-test.ts
.opencode/lib/__tests__/dispatch-db.test.ts
.opencode/scripts/e2e/dispatch-exact-lease.e2e-test.ts
.opencode/scripts/e2e/shell-backup-bypass.e2e-test.ts
New E2E Tests (from §5.6)
- Single-call harness: One
dispatch_subagent tool call creates one DB queue row and one prompt ref
- Duplicate guard: Same task/hash is idempotent; different hash is rejected
- Exact lease harness: Returned prompt leases the row whose
dag_task_id and hash match the token
- Agent-only lease regression: Preload an older Super-Admin pending row; new Super-Admin Task must not lease the older row
- DB/file split regression:
rg ".pending.json|.auto-dispatch.json|ctx/" .opencode/plugins .opencode/tools .opencode/scripts/command-tools finds no runtime writer except migration/doctor code
- DISPATCH_TOKEN tests: Missing token blocks, tampered prompt blocks, exact prompt passes
- Temp-script bypass tests:
cat > /tmp/x.ts with workspace writes blocks; bun /tmp/x.ts blocks; python3 <<EOF open(...).write() blocks
- Backup tests:
safe_edit creates backup row; shell write paths have no write effect and log a block
- Concurrency tests: Parallel same/different agent dispatches use DB locks and do not overwrite context
Log Schema
Add structured log events required by §5.9:
| Event |
Producer |
Key Fields |
DISPATCH-CREATE-REQUEST |
dispatch_subagent.ts |
sessionID, callID, agent, target_agent, dag_task_id, description_sha256 |
DISPATCH-DB-CREATED |
dispatch-db.ts |
queue_id, dispatch_key, prompt_ref_id, prompt_sha256 |
DISPATCH-PROMPT-RETURNED |
dispatch_subagent.ts |
queue_id, dispatch_key, file_path, size_bytes |
DISPATCH-INTEGRITY-PASS |
task-before.ts |
dispatch_key, prompt_sha256, agent_type, dag_task_id |
DISPATCH-QUEUE-EXACT-LEASE |
task-before.ts |
queue_id, lease_owner, lease_expiry |
DISPATCH-QUEUE-EXACT-MISS |
task-before.ts |
attempted tuple and pending counts |
SHELL-WRITE-BLOCKED |
scope-before.ts / safe-bash-core.ts |
agent, command_kind, targets, reason |
BACKUP-CREATED |
backup-manager.ts |
backup_uuid, file, agent, sessionID, dag_task_id |
Self-Test Checks
- Fail if duplicate dispatch rows exist for same active tuple
- Fail if runtime writers still touch
.pending.json
- Fail if a log event misses the required identity tuple
Acceptance Criteria
- The harness reproduces today's double-dispatch bug before the fix
- The harness passes after Phases A-D are implemented
Description
Add E2E tests for double-dispatch, exact lease, and shell bypass. Add structured log events for the full dispatch lifecycle. Fail framework self-test if regression conditions are detected.
Code References (§6 Phase E)
Files to Modify
.opencode/scripts/framework-self-test.ts.opencode/lib/__tests__/dispatch-db.test.ts.opencode/scripts/e2e/dispatch-exact-lease.e2e-test.ts.opencode/scripts/e2e/shell-backup-bypass.e2e-test.tsNew E2E Tests (from §5.6)
dispatch_subagenttool call creates one DB queue row and one prompt refdag_task_idand hash match the tokenrg ".pending.json|.auto-dispatch.json|ctx/" .opencode/plugins .opencode/tools .opencode/scripts/command-toolsfinds no runtime writer except migration/doctor codecat > /tmp/x.tswith workspace writes blocks;bun /tmp/x.tsblocks;python3 <<EOF open(...).write()blockssafe_editcreates backup row; shell write paths have no write effect and log a blockLog Schema
Add structured log events required by §5.9:
DISPATCH-CREATE-REQUESTDISPATCH-DB-CREATEDDISPATCH-PROMPT-RETURNEDDISPATCH-INTEGRITY-PASSDISPATCH-QUEUE-EXACT-LEASEDISPATCH-QUEUE-EXACT-MISSSHELL-WRITE-BLOCKEDBACKUP-CREATEDSelf-Test Checks
.pending.jsonAcceptance Criteria