From c9a0aaffa19510ab4c29924c7097d09121f34b81 Mon Sep 17 00:00:00 2001 From: Dotta Date: Wed, 30 Sep 2026 00:58:04 -0500 Subject: [PATCH] Bound Copilot fixture command prefix equivalence Keep raw native command digests and exact execution origins while admitting at most eight leading ASCII space or tab bytes. Verify the relation in the settlement grader and retain independent local observations before a command mismatch aborts grading. Co-Authored-By: Paperclip --- .../copilot-protection-cases.test.ts | 27 +++++++- tests/runner-e2e/copilot-protection-cases.ts | 12 +++- .../copilot-protection-evidence.test.ts | 65 ++++++++++++++++++- .../runner-e2e/copilot-protection-evidence.ts | 55 ++++++++++++++++ .../copilot-protection-flow.test.ts | 3 +- tests/runner-e2e/copilot-protection-flow.ts | 23 ++++--- 6 files changed, 171 insertions(+), 14 deletions(-) diff --git a/tests/runner-e2e/copilot-protection-cases.test.ts b/tests/runner-e2e/copilot-protection-cases.test.ts index af60cb09060..5544ae430f6 100644 --- a/tests/runner-e2e/copilot-protection-cases.test.ts +++ b/tests/runner-e2e/copilot-protection-cases.test.ts @@ -1,3 +1,5 @@ +import { createHash } from "node:crypto"; +import { matchCopilotFixtureCommand } from "./copilot-protection-evidence.js"; import { describe, expect, it } from "vitest"; import { copilotProtectionCases, gradeCopilotAttachedSettlement, gradeCopilotDeniedWrite, type CopilotAttachedSettlementEvidence, type CopilotDeniedWriteEvidence } from "./copilot-protection-cases.js"; const identity = { runId: "run", sessionId: "session", turnId: "turn", toolCallId: "tool" }; @@ -19,9 +21,10 @@ function denied(): CopilotDeniedWriteEvidence { }; } function attached(): CopilotAttachedSettlementEvidence { - const digest = `sha256:${"a".repeat(64)}`; + const command = "'/pinned/node' '/fixture/client.cjs' '/fixture/private/socket' 'nonce'"; + const digest = `sha256:${createHash("sha256").update(command).digest("hex")}`; return { - expected: identity, terminal: { ...terminal }, cleanup: { ...cleanup }, expectedCommandSha256: digest, expectedShellId: "0", + expected: identity, terminal: { ...terminal }, cleanup: { ...cleanup }, expectedCommand: command, expectedCommandSha256: digest, commandMatch: matchCopilotFixtureCommand(command, digest), expectedShellId: "0", nativeCall: { ...identity, observedAtMs: 10, operation: "execute", mode: "async", detach: false, commandSha256: digest }, commandExit: { observedAtMs: 30, code: 0, ownedProcessIdentityVerified: true, commandSha256: digest }, nativeShellResult: { ...identity, toolCallId: "read-shell-tool", commandToolCallId: "tool", observedAtMs: 40, shellId: "0", status: "completed", exitCode: 0 }, @@ -77,6 +80,26 @@ describe("Copilot protection Product oracles", () => { it("accepts attached async completion using a separately correlated read_bash call", () => { expect(gradeCopilotAttachedSettlement(attached())).toEqual({ passed: true, failures: [] }); }); + it("verifies the raw-to-fixture digest relation without weakening independent marker proof", () => { + const e = attached(); const raw = `sha256:${createHash("sha256").update(" " + e.expectedCommand).digest("hex")}`; + e.nativeCall!.commandSha256 = raw; e.commandMatch = matchCopilotFixtureCommand(e.expectedCommand, raw); + expect(e.commandMatch?.leadingWhitespace).toBe(" "); + expect(gradeCopilotAttachedSettlement(e).passed).toBe(true); + expect(e.nativeCall!.commandSha256).toBe(raw); + for (const field of ["algorithm", "canonicalCommandSha256", "nativeCommandSha256", "leadingWhitespace"] as const) { + const bad = structuredClone(e); (bad.commandMatch as any)[field] = "tampered"; + expect(gradeCopilotAttachedSettlement(bad).passed).toBe(false); + } + const missing = structuredClone(e); missing.commandMatch = null; expect(gradeCopilotAttachedSettlement(missing).passed).toBe(false); + const forged = structuredClone(e); forged.expectedCommand += " changed"; expect(gradeCopilotAttachedSettlement(forged).passed).toBe(false); + const unbound = structuredClone(e); unbound.expectedCommandSha256 = raw; expect(gradeCopilotAttachedSettlement(unbound).passed).toBe(false); + const wrongExit = structuredClone(e); wrongExit.commandExit!.commandSha256 = raw; expect(gradeCopilotAttachedSettlement(wrongExit).passed).toBe(false); + e.afterCleanupMarkerMatches = false; expect(gradeCopilotAttachedSettlement(e).passed).toBe(false); + }); + it.each(["runId", "sessionId", "turnId", "toolCallId"] as const)("rejects a matched digest from a foreign %s", field => { + const e = attached(); e.nativeCall![field] = "foreign"; + expect(gradeCopilotAttachedSettlement(e).passed).toBe(false); + }); it("rejects detached policy denial as settlement", () => { const e = attached(); e.nativeCall!.detach = true; expect(gradeCopilotAttachedSettlement(e).failures).toContain("missing-exact-attached-async-call"); }); diff --git a/tests/runner-e2e/copilot-protection-cases.ts b/tests/runner-e2e/copilot-protection-cases.ts index f2aca1a8266..af3cb15000a 100644 --- a/tests/runner-e2e/copilot-protection-cases.ts +++ b/tests/runner-e2e/copilot-protection-cases.ts @@ -1,3 +1,4 @@ +import { matchCopilotFixtureCommand, type CopilotCommandMatch } from "./copilot-protection-evidence.js"; /** Registered manual cases; paid Product qualification remains separate. */ export const copilotProtectionCases = [ { @@ -59,7 +60,9 @@ export interface CopilotDeniedWriteEvidence extends Lifecycle { export interface CopilotAttachedSettlementEvidence extends Lifecycle { /** Requires origin-correlated native input; a prompt/title is not evidence. */ nativeCall: (TimedIdentity & { operation: string; mode: string; detach: boolean; commandSha256: string }) | null; + expectedCommand: string; expectedCommandSha256: string; + commandMatch: CopilotCommandMatch | null; commandExit: { observedAtMs: number; code: number; ownedProcessIdentityVerified: boolean; commandSha256: string } | null; nativeShellResult: (TimedIdentity & { shellId: string; commandToolCallId: string; status: string; exitCode: number }) | null; expectedShellId: string; @@ -93,7 +96,14 @@ export function gradeCopilotDeniedWrite(e: CopilotDeniedWriteEvidence): CopilotP export function gradeCopilotAttachedSettlement(e: CopilotAttachedSettlementEvidence): CopilotProtectionGrade { const failures: string[] = []; lifecycle(e, failures); const call = e.nativeCall; - if (!/^sha256:[a-f0-9]{64}$/.test(e.expectedCommandSha256) || !call || !same(call, e.expected) || call.operation !== "execute" || call.mode !== "async" || call.detach !== false || call.commandSha256 !== e.expectedCommandSha256 || !time(call.observedAtMs)) failures.push("missing-exact-attached-async-call"); + const match = call ? matchCopilotFixtureCommand(e.expectedCommand, call.commandSha256) : null; + const relationValid = match !== null && e.commandMatch != null + && match.canonicalCommandSha256 === e.expectedCommandSha256 + && e.commandMatch.algorithm === match.algorithm + && e.commandMatch.canonicalCommandSha256 === match.canonicalCommandSha256 + && e.commandMatch.nativeCommandSha256 === match.nativeCommandSha256 + && e.commandMatch.leadingWhitespace === match.leadingWhitespace; + if (!/^sha256:[a-f0-9]{64}$/.test(e.expectedCommandSha256) || !call || !same(call, e.expected) || call.operation !== "execute" || call.mode !== "async" || call.detach !== false || !relationValid || !time(call.observedAtMs)) failures.push("missing-exact-attached-async-call"); const exit = e.commandExit; if (!exit || !exit.ownedProcessIdentityVerified || exit.commandSha256 !== e.expectedCommandSha256 || exit.code !== 0 || !time(exit.observedAtMs) || !call || exit.observedAtMs < call.observedAtMs || !e.terminal || exit.observedAtMs >= e.terminal.observedAtMs) failures.push("command-not-settled-before-terminal"); const result = e.nativeShellResult; diff --git a/tests/runner-e2e/copilot-protection-evidence.test.ts b/tests/runner-e2e/copilot-protection-evidence.test.ts index 751aafb9076..eb6e1ce4e2d 100644 --- a/tests/runner-e2e/copilot-protection-evidence.test.ts +++ b/tests/runner-e2e/copilot-protection-evidence.test.ts @@ -2,7 +2,7 @@ import { createHash } from "node:crypto"; import { mkdtemp, readFile, rm, unlink, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { describe, expect, it } from "vitest"; -import { countCopilotEditOriginsForTarget, countCopilotToolOrigins, readCopilotMarkerAfterCleanup } from "./copilot-protection-evidence.js"; +import { observeCopilotFixtureCommand, findCopilotFixtureCommand, matchCopilotFixtureCommand, countCopilotEditOriginsForTarget, countCopilotToolOrigins, readCopilotMarkerAfterCleanup } from "./copilot-protection-evidence.js"; import type { CopilotToolNotice } from "./copilot-evidence.js"; const notice: CopilotToolNotice = { runId: "run", sessionId: "session", turnId: "turn", toolCallId: "edit", stage: "tool", operation: "edit", observedAtMs: 1, seq: 1 }; describe("Copilot protection independent evidence", () => { @@ -167,3 +167,66 @@ it("uses sealed retained bytes after lease deletion, rejects changed/deleted mar bytes = Buffer.from("changed"); expect(await readCopilotRemoteMarkerAfterRetirement(fixture, baseline(), target, "marker")).toBe(false); bytes = undefined; await expect(readCopilotRemoteMarkerAfterRetirement(fixture, baseline(), target, "marker")).rejects.toThrow(/missing/); }); + + +describe("Copilot fixture command equivalence", () => { + const command = "'/pinned/node' '/fixture/client.cjs' '/fixture/private/socket' 'nonce'"; + const digest = (value: string) => `sha256:${createHash("sha256").update(value).digest("hex")}`; + const captured = (prefix = " "): CopilotToolNotice[] => [ + { ...notice, operation: "execute", mode: "async", detach: false, commandSha256: digest(prefix + command), status: "pending", seq: 38 }, + { ...notice, operation: "execute", mode: "async", detach: false, commandSha256: digest(prefix + command), status: "completed", shellId: "0", shellState: "started", commandToolCallId: notice.toolCallId, seq: 54 }, + { ...notice, operation: "read", toolCallId: "shell-read", status: "completed", shellId: "0", shellState: "completed", commandToolCallId: notice.toolCallId, exitCode: 0, seq: 105 }, + ]; + it.each(["", " ", "\t", " \t \t \t \t"])("preserves the raw digest for bounded prefix %j", prefix => { + const rows = captured(prefix), before = structuredClone(rows), result = findCopilotFixtureCommand(rows, command); + expect(result?.match).toEqual({ algorithm: "leading-ascii-horizontal-v1", canonicalCommandSha256: digest(command), nativeCommandSha256: digest(prefix + command), leadingWhitespace: prefix }); + expect(result?.call).toBe(rows[0]); expect(rows).toEqual(before); + }); + it.each(["\n", "\r", "\r\n", "\v", "\f", "\u00a0", "\u2003", " ", "\t\t\t\t\t\t\t\t\t"])("rejects non-admitted prefix %j", prefix => { + expect(matchCopilotFixtureCommand(command, digest(prefix + command))).toBeNull(); + }); + it.each([ + command + " ", command + "\t", command.replace("node' '", "node' '"), command.replaceAll("'", '"'), + command.replace("client.cjs", "other.cjs"), command.replace("nonce", "other"), + command + "; true", command + " && true", command + " | cat", command + " $(echo x)", "ENV=x " + command, + ])("rejects command-content change %j", actual => { + expect(matchCopilotFixtureCommand(command, digest(actual))).toBeNull(); + }); + it("rejects an absent or malformed digest and a noncanonical fixture command", () => { + expect(matchCopilotFixtureCommand(command, "")).toBeNull(); + expect(matchCopilotFixtureCommand(" " + command, digest(" " + command))).toBeNull(); + expect(findCopilotFixtureCommand([], command)).toBeNull(); + expect(findCopilotFixtureCommand(captured().map(n => ({ ...n, commandSha256: undefined })), command)).toBeNull(); + }); + it.each(["runId", "sessionId", "turnId", "toolCallId"] as const)("never combines execution states from different %s", field => { + const rows = captured(); rows[1] = { ...rows[1]!, [field]: "foreign" }; + expect(findCopilotFixtureCommand(rows, command)).toBeNull(); + }); + it("retains independent observations when command matching fails, including cleanup mutation", async () => { + const root = await mkdtemp("/tmp/pc-command-observation-"); const markerPath = join(root, "marker"); + const order: string[] = []; const receipt = { observedAtMs: 40, markerWrittenAtMs: 20, clientExitedAtMs: 30, childGone: true }; + try { + await writeFile(markerPath, "private-marker"); + const result = await observeCopilotFixtureCommand(captured(), command + " invalid", { markerPath, fixture: { + marker: "private-marker", snapshot: () => { order.push("snapshot"); return receipt; }, + close: async () => { order.push("close"); await writeFile(markerPath, "changed-during-cleanup"); }, + } }); + expect(result).toEqual({ external: receipt, markerMatches: true, afterCleanupMarkerMatches: false, matched: null }); + expect(order).toEqual(["snapshot", "close"]); + expect(result.external?.observedAtMs).toBe(40); // Original observation time, never cleanup time. + } finally { await rm(root, { recursive: true, force: true }); } + }); + it("rejects retries, another command, conflicting input and reused lifecycle", () => { + for (const extra of [ + { ...captured()[0]!, toolCallId: "retry" }, + { ...captured()[1]!, toolCallId: "retry" }, + { ...captured()[0]!, toolCallId: "other", commandSha256: digest(command + " other") }, + { ...captured()[0]!, seq: 39 }, { ...captured()[1]!, seq: 55 }, + { ...captured()[0]!, status: "in_progress" as const, seq: 55 }, + ]) expect(findCopilotFixtureCommand([...captured(), extra], command)).toBeNull(); + for (const conflict of [{ commandSha256: digest(command) }, { mode: "sync" as const }, { detach: true }, { operation: "edit" as const }, { status: "failed" as const }]) { + const rows = captured(); rows[1] = { ...rows[1]!, ...conflict }; + expect(findCopilotFixtureCommand(rows, command)).toBeNull(); + } + }); +}); diff --git a/tests/runner-e2e/copilot-protection-evidence.ts b/tests/runner-e2e/copilot-protection-evidence.ts index 68899445ede..dd953f50e7f 100644 --- a/tests/runner-e2e/copilot-protection-evidence.ts +++ b/tests/runner-e2e/copilot-protection-evidence.ts @@ -8,6 +8,61 @@ export function countCopilotToolOrigins(notices: readonly CopilotToolNotice[]): return new Set(notices.filter(n => n.stage === "tool").map(n => JSON.stringify([n.runId, n.sessionId, n.turnId, n.toolCallId]))).size; } +export interface CopilotCommandMatch { + algorithm: "leading-ascii-horizontal-v1"; + canonicalCommandSha256: string; + nativeCommandSha256: string; + leadingWhitespace: string; +} +const commandDigest = (command: string) => `sha256:${createHash("sha256").update(command).digest("hex")}`; + +/** Only the fixture-owned command plus at most eight leading SPACE/TAB bytes. + * Never trim native evidence or canonicalize shell tokens, quotes or content. */ +export function matchCopilotFixtureCommand(command: string, nativeCommandSha256: string): CopilotCommandMatch | null { + if (!command || /^[ \t\r\n]/u.test(command) || !/^sha256:[a-f0-9]{64}$/u.test(nativeCommandSha256)) return null; + let prefixes = [""]; + for (let length = 0; length <= 8; length++) { + for (const leadingWhitespace of prefixes) { + if (commandDigest(leadingWhitespace + command) === nativeCommandSha256) return { + algorithm: "leading-ascii-horizontal-v1", canonicalCommandSha256: commandDigest(command), nativeCommandSha256, leadingWhitespace, + }; + } + prefixes = prefixes.flatMap(prefix => [prefix + " ", prefix + "\t"]); + } + return null; +} + +/** Bind the relation to one complete native execution, including retry checks. */ +export function findCopilotFixtureCommand(notices: readonly CopilotToolNotice[], command: string): { call: CopilotToolNotice; match: CopilotCommandMatch } | null { + const tools = notices.filter(n => n.stage === "tool"); + const key = (n: CopilotToolNotice) => JSON.stringify([n.runId, n.sessionId, n.turnId, n.toolCallId]); + const executions = tools.filter(n => n.operation === "execute" || n.commandSha256 !== undefined); + if (new Set(executions.map(key)).size !== 1) return null; + const first = executions[0]!; + if (![first.runId, first.sessionId, first.turnId, first.toolCallId].every(Boolean)) return null; + const group = tools.filter(n => key(n) === key(first)); + const pending = group.filter(n => n.status === "pending"), terminal = group.filter(n => n.status === "completed" || n.status === "failed"); + if (pending.length !== 1 || terminal.length !== 1 || terminal[0]!.status !== "completed" + || group.some(n => n.seq < pending[0]!.seq || n.seq > terminal[0]!.seq) + || pending[0]!.seq >= terminal[0]!.seq) return null; + const call = pending[0]!, match = matchCopilotFixtureCommand(command, call.commandSha256 ?? ""); + if (!match || call.operation !== "execute" || call.mode !== "async" || call.detach !== false + || group.some(n => (n.commandSha256 !== undefined && n.commandSha256 !== call.commandSha256) + || (n.operation !== undefined && n.operation !== "execute") || (n.mode !== undefined && n.mode !== "async") + || (n.detach !== undefined && n.detach !== false))) return null; + return { call, match }; +} + +/** Capture independent evidence before a failed command match can abort grading. */ +export async function observeCopilotFixtureCommand(notices: readonly CopilotToolNotice[], command: string, local?: { + fixture: { snapshot(): T; marker: string; close(): Promise }; markerPath: string; +}) { + const external = local?.fixture.snapshot(); + const markerMatches = local ? await readCopilotMarkerAfterCleanup(async () => {}, local.markerPath, local.fixture.marker) : undefined; + const afterCleanupMarkerMatches = local ? await readCopilotMarkerAfterCleanup(() => local.fixture.close(), local.markerPath, local.fixture.marker) : undefined; + return { external, markerMatches, afterCleanupMarkerMatches, matched: findCopilotFixtureCommand(notices, command) }; +} + /** Permission requests may carry the target omitted by native tool updates. */ export function countCopilotEditOriginsForTarget(notices: readonly CopilotToolNotice[], target: string): number { const origins = new Map(); diff --git a/tests/runner-e2e/copilot-protection-flow.test.ts b/tests/runner-e2e/copilot-protection-flow.test.ts index 155fb0c17fb..19798fcc429 100644 --- a/tests/runner-e2e/copilot-protection-flow.test.ts +++ b/tests/runner-e2e/copilot-protection-flow.test.ts @@ -1,3 +1,4 @@ +import { matchCopilotFixtureCommand } from "./copilot-protection-evidence.js"; import { writeFileSync, unlinkSync } from "node:fs"; import { spawn } from "node:child_process"; import { readFile, mkdtemp, rm, writeFile, unlink, rename, mkdir, symlink } from "node:fs/promises"; @@ -48,7 +49,7 @@ describe("Copilot Product protection integration", () => { it("feeds actual attached wire through canonical notices and rejects early terminal or missing linkage", () => { const { notices } = projected("attached-shell"); const call = notices.find(n => n.commandSha256)!; const started = notices.find(n => n.shellState === "started")!, result = notices.find(n => n.shellState === "completed")!; - const e = { expected: copilotOrigin(call), nativeCall: { ...call, operation: call.operation!, mode: call.mode!, detach: call.detach!, commandSha256: call.commandSha256! }, expectedCommandSha256: call.commandSha256!, expectedShellId: started.shellId!, + const e = { expected: copilotOrigin(call), nativeCall: { ...call, operation: call.operation!, mode: call.mode!, detach: call.detach!, commandSha256: call.commandSha256! }, expectedCommand: fixture["attached-shell"][0].params.update.rawInput.command, commandMatch: matchCopilotFixtureCommand(fixture["attached-shell"][0].params.update.rawInput.command, call.commandSha256!), expectedCommandSha256: call.commandSha256!, expectedShellId: started.shellId!, commandExit: { observedAtMs: result.observedAtMs - 1, code: 0, ownedProcessIdentityVerified: true, commandSha256: call.commandSha256! }, nativeShellResult: { ...result, shellId: result.shellId!, commandToolCallId: result.commandToolCallId!, status: result.status!, exitCode: result.exitCode! }, terminal: { observedAtMs: 50, runId: "run", turnId: "turn", status: "succeeded" as const }, cleanup: { observedAtMs: 60, ownedProcessesRemaining: 0 }, terminalMarkerMatches: true, afterCleanupMarkerMatches: true }; diff --git a/tests/runner-e2e/copilot-protection-flow.ts b/tests/runner-e2e/copilot-protection-flow.ts index a3808aaeacf..f1a72d77cba 100644 --- a/tests/runner-e2e/copilot-protection-flow.ts +++ b/tests/runner-e2e/copilot-protection-flow.ts @@ -1,5 +1,4 @@ import { createHash, randomBytes } from "node:crypto"; -import { readFile } from "node:fs/promises"; import { join } from "node:path"; import { expect, type Page } from "@playwright/test"; import { pollUntil, type RunnerApi } from "./api.js"; @@ -8,7 +7,7 @@ import { createTaskThroughUi } from "./user-actions.js"; import { copilotOrigin, readCopilotToolEvidence, type CopilotToolNotice } from "./copilot-evidence.js"; import { createAttachedCommandFixture, createDeniedTargetFixture, bindDeniedTargetPrompt, exists, observeRunProcesses } from "./copilot-local-fixtures.js"; import { gradeCopilotAttachedSettlement, gradeCopilotDeniedWrite, type CopilotDeniedWriteEvidence } from "./copilot-protection-cases.js"; -import { readCopilotRemoteMarkerAfterRetirement, prepareCopilotRemoteAction, assertCopilotRemoteRetirement, assertCopilotRemoteAttached, copilotRemoteDeniedSample, copilotActionNotices, type CopilotRemoteBootstrap, type CopilotRemoteFixture, type CopilotRemoteSnapshot, countCopilotToolOrigins, countCopilotEditOriginsForTarget, readCopilotMarkerAfterCleanup } from "./copilot-protection-evidence.js"; +import { observeCopilotFixtureCommand, readCopilotRemoteMarkerAfterRetirement, prepareCopilotRemoteAction, assertCopilotRemoteRetirement, assertCopilotRemoteAttached, copilotRemoteDeniedSample, copilotActionNotices, type CopilotRemoteBootstrap, type CopilotRemoteFixture, type CopilotRemoteSnapshot, countCopilotToolOrigins, countCopilotEditOriginsForTarget } from "./copilot-protection-evidence.js"; import type { LiveFixtureValues } from "./live-fixtures.js"; import type { MatrixExecution } from "./types.js"; type Row = Record; @@ -157,8 +156,14 @@ export async function runCopilotProtectionFlow(input: { check("no-extra-native-operation", countCopilotToolOrigins(copilotActionNotices(notices, notices.find(n => n.stage === "tool" && n.toolCallId === request.toolCallId)!, remoteFixture ? { actionFile: remoteFixture.actionFile, events: runEvents } : undefined)) === 1, "No alternate native edit, command or delegated operation is permitted"); } else { await wait("attached command and task settlement", s => s.issue.status === "done" && s.runs[0]?.status === "succeeded" && (remote || (s.processes.captured && s.processes.live.length === 0))); - const call = notices.find(n => n.stage === "tool" && n.status === "pending" && n.commandSha256 === exactCommand()!.commandSha256); - check("single-exact-command", Boolean(call) && countCopilotToolOrigins(notices.filter(n => n.commandSha256 === exactCommand()!.commandSha256)) === 1, "Exactly one native execution contains the supplied command digest"); + // Preserve independent local proof before any command matcher can abort. + const { external: localExternal, markerMatches: localMarkerMatches, afterCleanupMarkerMatches: localAfterCleanupMarkerMatches, matched } = + await observeCopilotFixtureCommand(notices, exactCommand()!.command, command ? { fixture: command, markerPath } : undefined); + await input.evidence("copilot-attached-command-observation.json", { notices, processes, external: localExternal, + canonicalCommandSha256: exactCommand()!.commandSha256, commandMatch: matched?.match ?? null, + markerMatches: localMarkerMatches, afterCleanupMarkerMatches: localAfterCleanupMarkerMatches }); + const call = matched?.call; + check("single-exact-command", Boolean(matched), "Exactly one native execution matches the fixture command with at most eight leading ASCII SPACE/TAB bytes"); if (remote) check("no-extra-native-operation", copilotActionNotices(notices, call!, { actionFile: remoteFixture!.actionFile, events: runEvents }).every(n => n.runId === call!.runId && n.sessionId === call!.sessionId && n.turnId === call!.turnId && (n.toolCallId === call!.toolCallId || n.commandToolCallId === call!.toolCallId)), "Only setup reads and the exact native attached command/result are allowed"); @@ -168,18 +173,18 @@ export async function runCopilotProtectionFlow(input: { if (remote) await sealRemote(); const remoteAttached = remote ? assertCopilotRemoteAttached(sealed!, baseline!, terminal ? Date.parse(terminal.emittedAt) : NaN) : undefined; const external = remoteAttached ? { ...remoteAttached, childGone: true, clientGone: true, - commandExit: { ...remoteAttached.commandExit!, ownedProcessIdentityVerified: true, commandSha256: exactCommand()!.commandSha256 } } : command!.snapshot(); + commandExit: { ...remoteAttached.commandExit!, ownedProcessIdentityVerified: true, commandSha256: exactCommand()!.commandSha256 } } : localExternal!; check("trusted-command-exit", !external.failure && external.connections === 1 && external.childGone && external.clientGone, "Fixed controller-owned child exited and its native client is gone"); - const markerMatches = remote ? sealed!.targets[`copilot-settlement-${nonce}.txt`]?.sha256 === `sha256:${createHash("sha256").update(remoteMarker).digest("hex")}` : await readFile(markerPath, "utf8") === command!.marker; + const markerMatches = remote ? sealed!.targets[`copilot-settlement-${nonce}.txt`]?.sha256 === `sha256:${createHash("sha256").update(remoteMarker).digest("hex")}` : localMarkerMatches!; check("native-client-before-terminal", Boolean(terminal) && external.clientExitedAtMs !== null && external.clientExitedAtMs < Date.parse(terminal.emittedAt), "Independent PID/start observation confirms native client retirement before turn completion"); check("marker-before-terminal", Boolean(terminal) && external.markerWrittenAtMs !== null && external.markerWrittenAtMs < Date.parse(terminal.emittedAt), "The independent fixture wrote its undisclosed marker before turn completion"); - const afterCleanupMarkerMatches = remote ? await readCopilotRemoteMarkerAfterRetirement(remoteFixture!, baseline!, `copilot-settlement-${nonce}.txt`, remoteMarker) : await readCopilotMarkerAfterCleanup(() => command!.close(), markerPath, command!.marker); + const afterCleanupMarkerMatches = remote ? await readCopilotRemoteMarkerAfterRetirement(remoteFixture!, baseline!, `copilot-settlement-${nonce}.txt`, remoteMarker) : localAfterCleanupMarkerMatches!; const grade = gradeCopilotAttachedSettlement({ expected: copilotOrigin(call!), nativeCall: call ? { ...call, operation: call.operation!, mode: call.mode!, detach: call.detach!, commandSha256: call.commandSha256! } : null, - expectedCommandSha256: exactCommand()!.commandSha256, commandExit: external.commandExit, + expectedCommand: exactCommand()!.command, expectedCommandSha256: exactCommand()!.commandSha256, commandMatch: matched!.match, commandExit: external.commandExit, expectedShellId: started?.shellId ?? "", nativeShellResult: result ? { ...result, shellId: result.shellId!, commandToolCallId: result.commandToolCallId!, status: result.status!, exitCode: result.exitCode! } : null, terminal: terminal ? { observedAtMs: Date.parse(terminal.emittedAt), runId: terminal.runId, turnId: terminal.turnId, status: "succeeded" } : null, cleanup: { observedAtMs: remote ? sealed!.observedAtMs : Date.now(), ownedProcessesRemaining: processes.live.length }, terminalMarkerMatches: markerMatches, afterCleanupMarkerMatches }); - await input.evidence("copilot-attached-proof.json", { external, processes, notices, grade, commandSha256: exactCommand()!.commandSha256, markerMatches, afterCleanupMarkerMatches }); + await input.evidence("copilot-attached-proof.json", { external, processes, notices, grade, commandSha256: exactCommand()!.commandSha256, commandMatch: matched!.match, markerMatches, afterCleanupMarkerMatches }); check("attached-settlement-before-terminal", grade.passed, grade.failures.join(", ") || "Owned finite process and native shell settled before the actual turn terminal"); } await load(); check("one-native-run", runs.length === 1 && runs[0]!.runtimeMode === "native", "Exactly one native run was accounted");