test: dedupe exec policy mock reads

This commit is contained in:
Peter Steinberger
2026-05-13 03:26:58 +01:00
parent d1ddb68d37
commit 4ce9ff7845

View File

@@ -40,7 +40,8 @@ function expectFields(value: unknown, expected: Record<string, unknown>): void {
}
function readLastJsonWrite(): Record<string, unknown> {
const [payload, space] = mocks.defaultRuntime.writeJson.mock.calls.at(-1) ?? [];
const calls = mocks.defaultRuntime.writeJson.mock.calls;
const [payload, space] = calls[calls.length - 1] ?? [];
expect(space).toBe(0);
if (!payload || typeof payload !== "object") {
throw new Error("expected JSON write payload object");
@@ -59,11 +60,11 @@ function readFirstPolicyScope(payload: Record<string, unknown>): Record<string,
}
function readFirstReplaceConfigArg(): Record<string, unknown> {
const call = mocks.replaceConfigFile.mock.calls.at(0);
const call = mocks.replaceConfigFile.mock.calls[0];
if (!call) {
throw new Error("expected replaceConfigFile call");
}
const arg = call.at(0);
const arg = call[0];
if (!arg || typeof arg !== "object") {
throw new Error("expected replaceConfigFile argument");
}