mirror of
https://github.com/morluto/rea.git
synced 2026-11-13 18:22:42 +00:00
test(native): cover deadlines throughout signature inspection (#10217)
This commit is contained in:
1 parent
070cfce443
commit
bfecbb1d48
1 file changed
+43
-20
@@ -32,7 +32,7 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
class RecordingRunner implements NativeCommandRunner {
|
||||
readonly timeouts: number[] = [];
|
||||
readonly calls: { tool: string; timeoutMs: number | undefined }[] = [];
|
||||
readonly #inner = new NativeFixtureRunner();
|
||||
|
||||
run(
|
||||
@@ -40,7 +40,7 @@ class RecordingRunner implements NativeCommandRunner {
|
||||
arguments_: readonly string[],
|
||||
options: NativeCommandOptions,
|
||||
) {
|
||||
if (options.timeoutMs !== undefined) this.timeouts.push(options.timeoutMs);
|
||||
this.calls.push({ tool, timeoutMs: options.timeoutMs });
|
||||
return this.#inner.run(tool, arguments_, options);
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@ class RecordingRunner implements NativeCommandRunner {
|
||||
const execute = async (
|
||||
runner: NativeCommandRunner,
|
||||
parameters: Readonly<Record<string, JsonValue>>,
|
||||
operation: "list_architectures" | "inspect_signature" = "list_architectures",
|
||||
) => {
|
||||
const root = await createTestTempDirectory("rea-native-deadline-");
|
||||
const path = join(root, "app");
|
||||
@@ -56,29 +57,51 @@ const execute = async (
|
||||
await nativeMachoTargetForFile(path),
|
||||
);
|
||||
try {
|
||||
return await client.execute("list_architectures", parameters);
|
||||
return await client.execute(operation, parameters);
|
||||
} finally {
|
||||
expect((await client.close()).ok).toBe(true);
|
||||
}
|
||||
};
|
||||
|
||||
describe("native_command_timeout_ms", () => {
|
||||
it("uses 60000 ms when the caller omits the setting", async () => {
|
||||
const runner = new RecordingRunner();
|
||||
const result = await execute(runner, {});
|
||||
expect(result.ok, JSON.stringify(result)).toBe(true);
|
||||
expect(runner.timeouts.every((timeout) => timeout === 60_000)).toBe(true);
|
||||
expect(DEFAULT_NATIVE_COMMAND_TIMEOUT_MS).toBe(60_000);
|
||||
expect(runner.timeouts.length).toBeGreaterThan(0);
|
||||
});
|
||||
// Signature inspection reads display, requirements and entitlements, then both
|
||||
// architecture states in the authored universal Mach-O fixture.
|
||||
const commandCases = [
|
||||
{ operation: "list_architectures", tools: ["lipo"] },
|
||||
{
|
||||
operation: "inspect_signature",
|
||||
tools: ["codesign", "codesign", "codesign", "codesign", "codesign"],
|
||||
},
|
||||
] as const;
|
||||
|
||||
it("passes a selected deadline through to each native command", async () => {
|
||||
const runner = new RecordingRunner();
|
||||
const result = await execute(runner, { native_command_timeout_ms: 1_500 });
|
||||
expect(result.ok, JSON.stringify(result)).toBe(true);
|
||||
expect(runner.timeouts.length).toBeGreaterThan(0);
|
||||
expect(runner.timeouts.every((timeout) => timeout === 1_500)).toBe(true);
|
||||
});
|
||||
describe("native_command_timeout_ms", () => {
|
||||
it.each(commandCases)(
|
||||
"uses 60000 ms for every $operation command when the caller omits the setting",
|
||||
async ({ operation, tools }) => {
|
||||
const runner = new RecordingRunner();
|
||||
const result = await execute(runner, {}, operation);
|
||||
expect(result.ok, JSON.stringify(result)).toBe(true);
|
||||
expect(runner.calls).toEqual(
|
||||
tools.map((tool) => ({ tool, timeoutMs: 60_000 })),
|
||||
);
|
||||
expect(DEFAULT_NATIVE_COMMAND_TIMEOUT_MS).toBe(60_000);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(commandCases)(
|
||||
"passes a selected deadline through every $operation command",
|
||||
async ({ operation, tools }) => {
|
||||
const runner = new RecordingRunner();
|
||||
const result = await execute(
|
||||
runner,
|
||||
{ native_command_timeout_ms: 1_500 },
|
||||
operation,
|
||||
);
|
||||
expect(result.ok, JSON.stringify(result)).toBe(true);
|
||||
expect(runner.calls).toEqual(
|
||||
tools.map((tool) => ({ tool, timeoutMs: 1_500 })),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("passes the selected deadline through production xcrun resolution", async () => {
|
||||
const calls: {
|
||||
@@ -125,7 +148,7 @@ describe("native_command_timeout_ms", () => {
|
||||
const runner = new RecordingRunner();
|
||||
const result = await execute(runner, { native_command_timeout_ms: 0 });
|
||||
if (result.ok) throw new Error("expected an invalid deadline");
|
||||
expect(runner.timeouts).toEqual([]);
|
||||
expect(runner.calls).toEqual([]);
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
|
||||
Reference in new issue
Block a user