Files
orca/src/shared/agent-session-record.test-fixture.ts
Brennan Benson c69b12b3dd Enforce the agent-session lease at every PTY write choke point
Route every byte that can reach a PTY through the single-writer lease
adjudicator, so a session owned by one runtime cannot be typed into by
another. Nothing binds a PTY to a durable session record yet, so the gate
short-circuits and today's shells, legacy agent terminals, and unbound
sessions are untouched.

Gated paths: terminal.send RPC, the renderer IPC write paths
(pty:write / pty:writeAccepted), plugin sendTerminalText, the agent-prompt
paste, and ptyController.write as a backstop for runtime writes that never
passed a typed gate. Every yield inside a write - inter-chunk, the
text/suffix pause, the agent-prompt submit delay, deferred size
measurement - re-checks the fence, so a handoff mid-paste stops the
remaining chunks instead of interleaving two owners.

Refusals are typed and additive on the wire: an optional
agentSessionRefusal on RuntimeTerminalSend and on the existing
pty:writeUnavailable payload, refusal codes drawn only from the existing
agent-session error codes, and stream-input refusals mapped onto the
WriteUnavailable frame old clients already decode.
2026-08-09 13:00:56 -07:00

64 lines
1.7 KiB
TypeScript

/** Durable-record fixtures shared by the write-admission tests across shared, runtime, and IPC. */
import type { AgentSessionLease, AgentSessionRecord } from './agent-session-record'
const OWNER_PROCESS = {
hostId: 'local',
pid: 4242,
processStartTimeMs: 1_700_000_000_000,
spawnToken: 'spawn-tui'
}
/** A proven-live TUI owner: the only lease state that admits a PTY write. */
export function agentSessionLeaseFixture(
overrides: Partial<AgentSessionLease> = {}
): AgentSessionLease {
return {
sessionId: 'session-alpha-1',
runtimeKind: 'tui',
runtimeFence: 7,
handoffStage: null,
provenHandleLinkId: 'link-1',
ownerProcess: OWNER_PROCESS,
reservedSpawnToken: 'spawn-tui',
leaseDeadlineAt: 60_000,
lastRenewedAt: 30_000,
handoffOperationId: null,
journalCheckpoint: null,
claimKeyId: 'key-1',
claimStatus: 'live',
unreconciled: false,
deathEvidence: null,
...overrides
}
}
export function agentSessionRecordFixture(
lease: AgentSessionLease = agentSessionLeaseFixture()
): AgentSessionRecord {
return {
schemaVersion: 1,
sessionId: lease.sessionId,
location: {
executionHostId: 'local',
wslDistro: null,
workspaceId: 'workspace-1',
workspaceKind: 'git-worktree'
},
provider: 'claude',
providerHandleChain: [
{
linkId: 'link-1',
origin: 'created',
mintedAtFence: lease.runtimeFence,
observedAt: 1_000,
handle: { provider: 'claude', sessionId: lease.sessionId, leafUuid: null }
}
],
accountHome: { variable: 'CLAUDE_CONFIG_DIR', path: '/home/user/.claude' },
lease,
createdAt: 1_000,
updatedAt: 2_000
}
}