mirror of
https://github.com/morluto/rea.git
synced 2026-11-18 20:53:00 +00:00
fix(ci): synchronize build-computer cancellation tests (#12042)
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
1 parent
25784cd4e7
commit
2f6773cbc7
3 files changed
+51
-18
No files matched your search
@@ -25,6 +25,7 @@ import {
|
||||
} from "../../fixtures/buildComputerMcp.js";
|
||||
import { COMPUTER_START_TIMING } from "../../../src/desktop/AgentEnvComputer.js";
|
||||
import {
|
||||
awaitFakeDeployWait,
|
||||
FAKE_FRAME_PNG,
|
||||
startFakeComputer,
|
||||
type FakeApp,
|
||||
@@ -603,16 +604,15 @@ it("stops the helper when the caller cancels a start", async () => {
|
||||
},
|
||||
{ signal: controller.signal },
|
||||
);
|
||||
const deploying = waitFor(async () => {
|
||||
const notes = await runner.notes("deploying.jsonl");
|
||||
expect(notes).toHaveLength(1);
|
||||
return notes;
|
||||
}).finally(() => controller.abort());
|
||||
const [, helper] = await Promise.all([
|
||||
expect(call).rejects.toThrow(),
|
||||
deploying,
|
||||
]);
|
||||
await expect.poll(() => runner.notes("interrupted.jsonl")).toEqual(helper);
|
||||
try {
|
||||
const helper = await awaitFakeDeployWait(runner, call);
|
||||
controller.abort();
|
||||
await expect(call).rejects.toThrow();
|
||||
await expect.poll(() => runner.notes("interrupted.jsonl")).toEqual(helper);
|
||||
} finally {
|
||||
controller.abort();
|
||||
await Promise.allSettled([call]);
|
||||
}
|
||||
});
|
||||
|
||||
/** An app whose reset keeps the computer unready for `polls` readiness polls, 500 ms apart. */
|
||||
|
||||
@@ -4,9 +4,11 @@ import { setTimeout as delay } from "node:timers/promises";
|
||||
|
||||
import { expect, it, onTestFinished } from "vitest";
|
||||
|
||||
import { fakeBuildComputers as setUp } from "../../fixtures/fakeAgentEnvComputer.js";
|
||||
import {
|
||||
awaitFakeDeployWait,
|
||||
fakeBuildComputers as setUp,
|
||||
} from "../../fixtures/fakeAgentEnvComputer.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { waitFor } from "../../support/testWait.js";
|
||||
|
||||
it("joins a start still in progress when the owner closes, and refuses later starts", async () => {
|
||||
const { computers, runner, start } = await setUp(
|
||||
@@ -18,12 +20,16 @@ it("joins a start still in progress when the owner closes, and refuses later sta
|
||||
order.push("start settled");
|
||||
return result;
|
||||
});
|
||||
const helper = await waitFor(async () => {
|
||||
const notes = await runner.notes("deploying.jsonl");
|
||||
expect(notes).toHaveLength(1);
|
||||
return notes;
|
||||
}).finally(() => computers.closeAll());
|
||||
order.push("closeAll returned");
|
||||
const helper = await awaitFakeDeployWait(runner, pending).finally(
|
||||
async () => {
|
||||
try {
|
||||
await computers.closeAll();
|
||||
order.push("closeAll returned");
|
||||
} finally {
|
||||
await Promise.allSettled([pending]);
|
||||
}
|
||||
},
|
||||
);
|
||||
expect(order).toEqual(["start settled", "closeAll returned"]);
|
||||
const started = await pending;
|
||||
expect(started.ok).toBe(false);
|
||||
|
||||
+27
@@ -34,7 +34,9 @@ import { onTestFinished } from "vitest";
|
||||
|
||||
import { DesktopBuildComputers } from "../../src/application/desktop/DesktopBuildComputers.js";
|
||||
import type { BuildComputerDefaults } from "../../src/desktop/BuildComputerEnvironment.js";
|
||||
import { awaitAcknowledgement } from "./lifecycleAcknowledgement.js";
|
||||
import { createTestTempDirectory } from "./temporaryDirectory.js";
|
||||
import { waitFor } from "../support/testWait.js";
|
||||
|
||||
/** A 2x1 PNG of a black and a white pixel, the fake driver's drawn desktop. */
|
||||
export const FAKE_FRAME_PNG =
|
||||
@@ -733,6 +735,31 @@ export interface FakeAgentEnvRunner {
|
||||
notes(name: string): Promise<unknown[]>;
|
||||
}
|
||||
|
||||
/** Observe the exact helper waiting at the cancellable deployment phase. */
|
||||
export const awaitFakeDeployWait = async (
|
||||
runner: FakeAgentEnvRunner,
|
||||
operation: Promise<unknown>,
|
||||
): Promise<{ pid: number }[]> => {
|
||||
let observing = true;
|
||||
const acknowledgement = waitFor(async () => {
|
||||
if (!observing) return [];
|
||||
return z
|
||||
.tuple([z.object({ pid: z.int().positive() })])
|
||||
.parse(await runner.notes("deploying.jsonl"));
|
||||
});
|
||||
try {
|
||||
await awaitAcknowledgement(
|
||||
acknowledgement,
|
||||
operation,
|
||||
"fake deployment wait",
|
||||
);
|
||||
return await acknowledgement;
|
||||
} finally {
|
||||
observing = false;
|
||||
await Promise.allSettled([acknowledgement]);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* JSONL notes from the fake build computer. A trailing fragment without a
|
||||
* newline is still being appended. Every newline-terminated line is a record
|
||||
|
||||
Reference in new issue
Block a user