test(orchestration): make mailbox gates self-contained

This commit is contained in:
Jinwoo-H
2026-08-14 19:36:20 -04:00
parent 816c014004
commit b002e00d4b
3 changed files with 82 additions and 78 deletions
+2 -2
View File
@@ -8814,7 +8814,7 @@
"invariant": "Each message has one stable row ID and authoritative recipient; coordinator-addressed current-delivery inserts are atomically owned by run:<id>. Pointer staging may set delivered_at but never consumes mail. Each Run consumer generation has at most one outstanding Delivery with a fixed ID and fixed message IDs; ordinary checks replay it until an explicit matching acknowledgment marks exactly those rows read. Rebinding fences the old generation, notification types/counts correspond to unread rows retrievable under the same authority, and federation replay imports each stable message identity once without re-waking an already-read duplicate.",
"oracle": "Seed status, dispatch, and worker_done rows across direct-handle and canonical Run recipients in an isolated DB. Compare pointer count, RPC and built-CLI check output, direct SQLite rows, unread/peek/all/type filters, concurrent pollers, fixed Delivery IDs, explicit acknowledgment, restart, filtered check --wait, and coordinator remint. Route a 125-row old-handle backlog, inject a commit without notification, and require startup repair. Exercise duplicate Run/Dispatch owners, stale panes, 50-row pages, cancellation, lifecycle fencing, and absent PTYs. Drop a federation ACK, reconnect/restart v1/v2 peers, and require stable import plus no duplicate read-row wake. Hold a healthy SSH write past five seconds but below the 60-second settlement deadline, then separately exceed the bound and require retryable undelivered state.",
"commands": [
"pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orchestration-message-delivery-identity.test.ts --reporter=dot --testTimeout=5000",
"pnpm run build:cli && pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orchestration-message-delivery-identity.test.ts --reporter=dot --testTimeout=5000",
"pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orchestration-mailbox-routing-races.test.ts src/main/runtime/orchestration-mailbox-notification-consistency.test.ts src/main/runtime/orchestration-mailbox-detached-routing.test.ts src/main/runtime/orchestration-mailbox-transport-settlement.test.ts src/main/runtime/orchestration/run-coordinator-handle-migration.test.ts src/main/runtime/orchestration/orchestration-run-delivery-db.test.ts src/main/runtime/orchestration/orchestration-worker-dispatch-db.test.ts src/main/runtime/orchestration/formatter.test.ts src/main/providers/ssh-pty-provider.test.ts src/main/providers/ssh-pty-write.test.ts src/main/daemon/client.test.ts src/main/daemon/daemon-pty-router.test.ts src/main/daemon/degraded-daemon-pty-provider.test.ts",
"pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orca-runtime.test.ts src/main/runtime/terminal-send-stale-leaf-liveness.test.ts src/main/runtime/rpc/methods/orchestration.test.ts",
"pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orchestration/federation-sync.test.ts src/main/runtime/rpc/methods/orchestration-federation.test.ts src/main/runtime/rpc/methods/orchestration-federation-lifecycle-settlement.test.ts --reporter=dot"
@@ -8972,7 +8972,7 @@
"date": "2026-08-14",
"runner": "local",
"platform": "macos",
"command": "pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orchestration-message-delivery-identity.test.ts --reporter=dot --testTimeout=5000",
"command": "pnpm run build:cli && pnpm exec vitest run --config config/vitest.config.ts src/main/runtime/orchestration-message-delivery-identity.test.ts --reporter=dot --testTimeout=5000",
"result": "passed",
"durationSeconds": 8.42,
"summary": "The byte-identical five-case STA-4325 oracle (SHA-256 76a2d672d27e04e5b1db2f52df3b303468bdf006be7cfd003bf443618a856c35) failed 5/5 on reported v1.4.180, latest main, and production-reverted candidate, then passed 5/5 on the final candidate. It aligns pointer counts with one fixed Delivery across concurrent pollers and filters, replays that Delivery through restart, routes a 125-row old-handle backlog before rebind, repairs committed mail without relying on a notification callback, and matches built-CLI output to direct isolated SQLite state."
@@ -27,6 +27,7 @@ const WORKTREE_ID = 'repo-sta-4325::/tmp/sta-4325'
const LAUNCH_TOKEN = 'sta-4325-launch'
const temporaryDirectories: string[] = []
const CLI_PATH = join(process.cwd(), 'out', 'cli', 'index.js')
const itIfCliBuilt = existsSync(CLI_PATH) ? it : it.skip
type MessageResult = { id: string; type: string; read: number }
type CheckResult = {
@@ -428,82 +429,85 @@ describe('STA-4325 message and delivery identity', () => {
reopened.close()
})
it('keeps the built CLI count and Delivery output aligned with isolated SQLite state', async () => {
expect(existsSync(CLI_PATH)).toBe(true)
const userDataPath = mkdtempSync(join(tmpdir(), 'orca-sta-4325-cli-'))
temporaryDirectories.push(userDataPath)
const db = new OrchestrationDb(join(userDataPath, 'orchestration.db'))
const runtime = new OrcaRuntimeService()
runtime.setOrchestrationDb(db)
vi.spyOn(runtime, 'getTerminalPaneKey').mockImplementation((handle) =>
handle === TERMINAL_HANDLE ? PANE_KEY : null
)
const run = db.createRun({
objective: 'STA-4325 built CLI',
coordinatorHandle: TERMINAL_HANDLE,
coordinatorPaneKey: PANE_KEY
})
const status = db.insertMessage({
from: 'term_worker',
to: TERMINAL_HANDLE,
subject: 'direct status',
type: 'status',
runId: run.id,
deliveryContract: 'current_delivery'
})
const done = db.insertMessage({
from: 'term_worker',
to: `run:${run.id}`,
subject: 'canonical done',
type: 'worker_done',
runId: run.id,
deliveryContract: 'current_delivery'
})
const server = new OrcaRuntimeRpcServer({ runtime, userDataPath })
await server.start()
try {
const first = await runBuiltCli(userDataPath, ['orchestration', 'check', '--json'])
expect(first.exitCode, first.stderr).toBe(0)
const firstPayload = JSON.parse(first.stdout) as { result: CheckResult }
expect(firstPayload.result).toMatchObject({ runId: run.id, count: 2, replayed: false })
expect(firstPayload.result.messages.map((message) => message.id)).toEqual([
status.id,
done.id
])
const replay = await runBuiltCli(userDataPath, ['orchestration', 'check', '--json'])
expect(replay.exitCode, replay.stderr).toBe(0)
const replayPayload = JSON.parse(replay.stdout) as { result: CheckResult }
expect(replayPayload.result).toMatchObject({
count: 2,
deliveryId: firstPayload.result.deliveryId,
replayed: true
itIfCliBuilt(
'keeps the built CLI count and Delivery output aligned with isolated SQLite state',
async () => {
const userDataPath = mkdtempSync(join(tmpdir(), 'orca-sta-4325-cli-'))
temporaryDirectories.push(userDataPath)
const db = new OrchestrationDb(join(userDataPath, 'orchestration.db'))
const runtime = new OrcaRuntimeService()
runtime.setOrchestrationDb(db)
vi.spyOn(runtime, 'getTerminalPaneKey').mockImplementation((handle) =>
handle === TERMINAL_HANDLE ? PANE_KEY : null
)
const run = db.createRun({
objective: 'STA-4325 built CLI',
coordinatorHandle: TERMINAL_HANDLE,
coordinatorPaneKey: PANE_KEY
})
expect(sqliteFor(db).prepare('SELECT id, status FROM deliveries').all()).toEqual([
{ id: firstPayload.result.deliveryId, status: 'outstanding' }
])
expect(db.getMessageById(status.id)).toMatchObject({
to_handle: `run:${run.id}`,
read: 0
const status = db.insertMessage({
from: 'term_worker',
to: TERMINAL_HANDLE,
subject: 'direct status',
type: 'status',
runId: run.id,
deliveryContract: 'current_delivery'
})
const done = db.insertMessage({
from: 'term_worker',
to: `run:${run.id}`,
subject: 'canonical done',
type: 'worker_done',
runId: run.id,
deliveryContract: 'current_delivery'
})
const server = new OrcaRuntimeRpcServer({ runtime, userDataPath })
await server.start()
const acknowledged = await runBuiltCli(userDataPath, [
'orchestration',
'check',
'--ack',
firstPayload.result.deliveryId!,
'--json'
])
expect(acknowledged.exitCode, acknowledged.stderr).toBe(0)
expect(JSON.parse(acknowledged.stdout)).toMatchObject({
result: { count: 0, deliveryId: null, acknowledged: firstPayload.result.deliveryId }
})
expect(db.getMessageById(status.id)?.read).toBe(1)
expect(db.getMessageById(done.id)?.read).toBe(1)
} finally {
await server.stop()
db.close()
}
}, 30_000)
try {
const first = await runBuiltCli(userDataPath, ['orchestration', 'check', '--json'])
expect(first.exitCode, first.stderr).toBe(0)
const firstPayload = JSON.parse(first.stdout) as { result: CheckResult }
expect(firstPayload.result).toMatchObject({ runId: run.id, count: 2, replayed: false })
expect(firstPayload.result.messages.map((message) => message.id)).toEqual([
status.id,
done.id
])
const replay = await runBuiltCli(userDataPath, ['orchestration', 'check', '--json'])
expect(replay.exitCode, replay.stderr).toBe(0)
const replayPayload = JSON.parse(replay.stdout) as { result: CheckResult }
expect(replayPayload.result).toMatchObject({
count: 2,
deliveryId: firstPayload.result.deliveryId,
replayed: true
})
expect(sqliteFor(db).prepare('SELECT id, status FROM deliveries').all()).toEqual([
{ id: firstPayload.result.deliveryId, status: 'outstanding' }
])
expect(db.getMessageById(status.id)).toMatchObject({
to_handle: `run:${run.id}`,
read: 0
})
const acknowledged = await runBuiltCli(userDataPath, [
'orchestration',
'check',
'--ack',
firstPayload.result.deliveryId!,
'--json'
])
expect(acknowledged.exitCode, acknowledged.stderr).toBe(0)
expect(JSON.parse(acknowledged.stdout)).toMatchObject({
result: { count: 0, deliveryId: null, acknowledged: firstPayload.result.deliveryId }
})
expect(db.getMessageById(status.id)?.read).toBe(1)
expect(db.getMessageById(done.id)?.read).toBe(1)
} finally {
await server.stop()
db.close()
}
},
30_000
)
})
@@ -539,7 +539,7 @@ test.describe('orchestration push-on-idle mail delivery', () => {
expect(readMailRow(userDataDir, messageId)).toMatchObject({
run_id: runA.result.run.id,
delivery_contract: 'current_delivery',
to_handle: pane.handle,
to_handle: `run:${runA.result.run.id}`,
read: 0,
delivered_at: null
})