Skip to content

Commit 8195100

Browse files
committed
test(qa): require full identity inspection proof
1 parent b0112f3 commit 8195100

1 file changed

Lines changed: 82 additions & 98 deletions

File tree

‎test/e2e/qa-lab/runtime/agent-run-identity-inspection.ts‎

Lines changed: 82 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const GATEWAY_SCOPES = [
6666

6767
type ProducerOptions = {
6868
artifactBase: string;
69-
i1Only: boolean;
7069
repoRoot: string;
7170
};
7271

@@ -311,7 +310,6 @@ function parseOptions(argv: readonly string[]): ProducerOptions {
311310
}
312311
return {
313312
artifactBase: path.resolve(artifactBase),
314-
i1Only: argv.includes("--i1-only"),
315313
repoRoot: path.resolve(readValue("--repo-root") ?? process.cwd()),
316314
};
317315
}
@@ -628,19 +626,17 @@ async function runProof(options: ProducerOptions): Promise<string> {
628626
PATH: `${fakeTailscale.binaryDir}${path.delimiter}${process.env.PATH ?? ""}`,
629627
},
630628
});
631-
if (!options.i1Only) {
632-
await gateway.restartAfterStateMutation(async () => {
633-
await runLocalTurn(gateway!, "Reply exactly: IDENTITY-DISABLED-FRESH");
634-
});
635-
if (inspectExecutionIdentityStorage(gateway).tablePresent) {
636-
throw new Error("fresh-install default unexpectedly created execution identity storage");
637-
}
638-
await gateway.restartAfterStateMutation(async () => {
639-
await runLocalTurn(gateway!, "Reply exactly: IDENTITY-DISABLED-UPGRADE");
640-
});
641-
if (inspectExecutionIdentityStorage(gateway).tablePresent) {
642-
throw new Error("existing-install restart unexpectedly created execution identity storage");
643-
}
629+
await gateway.restartAfterStateMutation(async () => {
630+
await runLocalTurn(gateway!, "Reply exactly: IDENTITY-DISABLED-FRESH");
631+
});
632+
if (inspectExecutionIdentityStorage(gateway).tablePresent) {
633+
throw new Error("fresh-install default unexpectedly created execution identity storage");
634+
}
635+
await gateway.restartAfterStateMutation(async () => {
636+
await runLocalTurn(gateway!, "Reply exactly: IDENTITY-DISABLED-UPGRADE");
637+
});
638+
if (inspectExecutionIdentityStorage(gateway).tablePresent) {
639+
throw new Error("existing-install restart unexpectedly created execution identity storage");
644640
}
645641
await gateway.restartAfterStateMutation(async ({ configPath }) => {
646642
await updateExecutionIdentityConfig(configPath, { executionIdentity: true });
@@ -797,58 +793,54 @@ async function runProof(options: ProducerOptions): Promise<string> {
797793
const repeatedRunId = `identity-repeated-${randomUUID()}`;
798794
let repeatedRows: ReturnType<typeof findRunExecutions> = [];
799795
const repeatedBeforeRestart = new Map<string, string>();
800-
if (!options.i1Only) {
801-
await runRepeatedIngressTurns(gateway, options.repoRoot, repeatedRunId);
802-
repeatedRows = findRunExecutions(gateway, repeatedRunId);
803-
if (
804-
repeatedRows.length !== 2 ||
805-
new Set(repeatedRows.map((row) => row.execution_id)).size !== 2 ||
806-
new Set(repeatedRows.map((row) => row.context_id)).size !== 2
807-
) {
808-
throw new Error(
809-
`repeated same-session run recorded ${String(repeatedRows.length)} non-distinct executions`,
810-
);
811-
}
812-
const discoveryText = await gateway.runCli(["audit", "--run", repeatedRunId, "--explain"]);
796+
await runRepeatedIngressTurns(gateway, options.repoRoot, repeatedRunId);
797+
repeatedRows = findRunExecutions(gateway, repeatedRunId);
798+
if (
799+
repeatedRows.length !== 2 ||
800+
new Set(repeatedRows.map((row) => row.execution_id)).size !== 2 ||
801+
new Set(repeatedRows.map((row) => row.context_id)).size !== 2
802+
) {
803+
throw new Error(
804+
`repeated same-session run recorded ${String(repeatedRows.length)} non-distinct executions`,
805+
);
806+
}
807+
const discoveryText = await gateway.runCli(["audit", "--run", repeatedRunId, "--explain"]);
808+
if (
809+
!discoveryText.includes("execution_selection_required") ||
810+
!discoveryText.includes("--execution <id> --explain")
811+
) {
812+
throw new Error("ambiguous run discovery omitted exact-execution selection guidance");
813+
}
814+
const discovery = parseJson(
815+
await gateway.runCli(["audit", "--run", repeatedRunId, "--explain", "--json"]),
816+
"repeated-run discovery",
817+
) as AuditRunInspectResult;
818+
if (discovery.identity.state !== "ambiguous" || discovery.identity.candidates.length !== 2) {
819+
throw new Error("repeated same-session run was not reported as two ambiguous executions");
820+
}
821+
for (const row of repeatedRows) {
822+
const text = await gateway.runCli(["audit", "--execution", row.execution_id, "--explain"]);
823+
assertTextProjection(text);
824+
const exact = parseJson(
825+
await gateway.runCli(["audit", "--execution", row.execution_id, "--explain", "--json"]),
826+
`execution ${row.execution_id}`,
827+
) as AuditRunInspectResult;
828+
const context = requireIdentityContext(exact);
813829
if (
814-
!discoveryText.includes("execution_selection_required") ||
815-
!discoveryText.includes("--execution <id> --explain")
830+
exact.run.executionId !== row.execution_id ||
831+
context.executionId !== row.execution_id ||
832+
context.contextId !== row.context_id ||
833+
context.runId !== repeatedRunId ||
834+
context.ingress.kind !== "api" ||
835+
context.ingress.state !== "unknown"
816836
) {
817-
throw new Error("ambiguous run discovery omitted exact-execution selection guidance");
818-
}
819-
const discovery = parseJson(
820-
await gateway.runCli(["audit", "--run", repeatedRunId, "--explain", "--json"]),
821-
"repeated-run discovery",
822-
) as AuditRunInspectResult;
823-
if (discovery.identity.state !== "ambiguous" || discovery.identity.candidates.length !== 2) {
824-
throw new Error("repeated same-session run was not reported as two ambiguous executions");
837+
throw new Error(`exact execution inspection selected the wrong turn: ${row.execution_id}`);
825838
}
826-
for (const row of repeatedRows) {
827-
const text = await gateway.runCli(["audit", "--execution", row.execution_id, "--explain"]);
828-
assertTextProjection(text);
829-
const exact = parseJson(
830-
await gateway.runCli(["audit", "--execution", row.execution_id, "--explain", "--json"]),
831-
`execution ${row.execution_id}`,
832-
) as AuditRunInspectResult;
833-
const context = requireIdentityContext(exact);
834-
if (
835-
exact.run.executionId !== row.execution_id ||
836-
context.executionId !== row.execution_id ||
837-
context.contextId !== row.context_id ||
838-
context.runId !== repeatedRunId ||
839-
context.ingress.kind !== "api" ||
840-
context.ingress.state !== "unknown"
841-
) {
842-
throw new Error(
843-
`exact execution inspection selected the wrong turn: ${row.execution_id}`,
844-
);
845-
}
846-
const exactContextJson = normalizedContextJson(exact);
847-
if (exactContextJson !== row.context_json) {
848-
throw new Error(`RPC context bytes differ from persisted bytes: ${row.execution_id}`);
849-
}
850-
repeatedBeforeRestart.set(row.execution_id, exactContextJson);
839+
const exactContextJson = normalizedContextJson(exact);
840+
if (exactContextJson !== row.context_json) {
841+
throw new Error(`RPC context bytes differ from persisted bytes: ${row.execution_id}`);
851842
}
843+
repeatedBeforeRestart.set(row.execution_id, exactContextJson);
852844
}
853845

854846
await gateway.restartAfterStateMutation(async () => {});
@@ -886,25 +878,23 @@ async function runProof(options: ProducerOptions): Promise<string> {
886878
throw new Error(`repeated execution changed across Gateway restart: ${executionId}`);
887879
}
888880
}
889-
if (!options.i1Only) {
890-
const retainedBeforeGlobalDisable = inspectExecutionIdentityStorage(gateway).rowCount;
891-
await gateway.restartAfterStateMutation(async ({ configPath }) => {
892-
await updateExecutionIdentityConfig(configPath, {
893-
enabled: false,
894-
executionIdentity: true,
895-
});
896-
await runLocalTurn(gateway!, "Reply exactly: IDENTITY-DISABLED-GLOBAL");
881+
const retainedBeforeGlobalDisable = inspectExecutionIdentityStorage(gateway).rowCount;
882+
await gateway.restartAfterStateMutation(async ({ configPath }) => {
883+
await updateExecutionIdentityConfig(configPath, {
884+
enabled: false,
885+
executionIdentity: true,
897886
});
898-
if (inspectExecutionIdentityStorage(gateway).rowCount !== retainedBeforeGlobalDisable) {
899-
throw new Error("global audit disable unexpectedly retained a new execution context");
900-
}
901-
const afterGlobalDisable = parseJson(
902-
await gateway.runCli(["audit", "--run", runId, "--explain", "--json"]),
903-
"global-disabled retained inspection",
904-
) as AuditRunInspectResult;
905-
if (normalizedContextJson(afterGlobalDisable) !== beforeContext) {
906-
throw new Error("global audit disable hid or changed retained identity evidence");
907-
}
887+
await runLocalTurn(gateway!, "Reply exactly: IDENTITY-DISABLED-GLOBAL");
888+
});
889+
if (inspectExecutionIdentityStorage(gateway).rowCount !== retainedBeforeGlobalDisable) {
890+
throw new Error("global audit disable unexpectedly retained a new execution context");
891+
}
892+
const afterGlobalDisable = parseJson(
893+
await gateway.runCli(["audit", "--run", runId, "--explain", "--json"]),
894+
"global-disabled retained inspection",
895+
) as AuditRunInspectResult;
896+
if (normalizedContextJson(afterGlobalDisable) !== beforeContext) {
897+
throw new Error("global audit disable hid or changed retained identity evidence");
908898
}
909899

910900
const snapshotPath = path.join(options.artifactBase, SNAPSHOT_FILE);
@@ -921,27 +911,23 @@ async function runProof(options: ProducerOptions): Promise<string> {
921911
contextSha256: sha256(profilelessContext),
922912
},
923913
},
924-
...(!options.i1Only
925-
? {
926-
repeatedRunId,
927-
repeatedExecutions: repeatedRows.map((row) => ({
928-
executionId: row.execution_id,
929-
contextId: row.context_id,
930-
})),
931-
}
932-
: {}),
914+
repeatedRunId,
915+
repeatedExecutions: repeatedRows.map((row) => ({
916+
executionId: row.execution_id,
917+
contextId: row.context_id,
918+
})),
933919
coverage: before.coverage,
934920
decision: before.decisions[0]?.decision,
935921
contextSha256: sha256(beforeContext),
936922
byteEquivalentAfterRestart: true,
937923
byteEquivalentPersistedReadback: true,
938924
optIn: {
939925
explicitEnablement: true,
940-
freshInstallDisabled: !options.i1Only,
941-
freshInstallTableAbsent: !options.i1Only,
942-
globalAuditDisabled: !options.i1Only,
943-
upgradeStyleExistingInstallDisabled: !options.i1Only,
944-
upgradeStyleTableAbsent: !options.i1Only,
926+
freshInstallDisabled: true,
927+
freshInstallTableAbsent: true,
928+
globalAuditDisabled: true,
929+
upgradeStyleExistingInstallDisabled: true,
930+
upgradeStyleTableAbsent: true,
945931
},
946932
textSections: TEXT_SECTIONS,
947933
identityFields: IDENTITY_FIELDS,
@@ -951,9 +937,7 @@ async function runProof(options: ProducerOptions): Promise<string> {
951937
)}\n`,
952938
"utf8",
953939
);
954-
const repeatedDetails = options.i1Only
955-
? "repeated-execution checks skipped by --i1-only"
956-
: `repeated run=${repeatedRunId} executions=${repeatedRows.map((row) => row.execution_id).join(",")}; exact selection passed`;
940+
const repeatedDetails = `repeated run=${repeatedRunId} executions=${repeatedRows.map((row) => row.execution_id).join(",")}; exact selection passed`;
957941
return `local run=${runId}; profiled Gateway run=${profiledRunId}; profileless Gateway run=${profilelessRunId}; ${repeatedDetails}; Gateway pid=${gateway.pid ?? "unknown"}; text+JSON and persisted bytes passed before/after replacement; normalized context sha256=${sha256(beforeContext)}`;
958942
} finally {
959943
await gateway?.stop().catch(() => undefined);

0 commit comments

Comments
 (0)