Skip to content

Commit 4060abb

Browse files
committed
fix review-gated packaging and smoke test hangs
1 parent 690caeb commit 4060abb

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

packaging.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ const packagingRunPermissions = await Promise.all([
1212
name: "run",
1313
command: Deno.build.os === "windows" ? "where" : "which",
1414
}),
15+
Deno.permissions.query({ name: "run", command: "bun" }),
1516
]);
1617
const packagingRunPermissionGranted = packagingRunPermissions.every(
17-
(permission) => permission.state === "granted",
18+
(permission, index) => index === 3 || permission.state === "granted",
1819
);
20+
const bunRunPermissionGranted = packagingRunPermissions[3]?.state === "granted";
1921

2022
const decodeText = (value: Uint8Array): string =>
2123
new TextDecoder().decode(value);
@@ -116,7 +118,7 @@ Deno.test({
116118
assertEquals(esmLoad.code, 0, esmLoad.stderr || esmLoad.stdout);
117119
assertEquals(esmLoad.stdout.trim(), '["graphiti"]');
118120

119-
if (await commandExists("bun")) {
121+
if (bunRunPermissionGranted && await commandExists("bun")) {
120122
const bunLoad = await run("bun", [bunRunnerPath], tempDir);
121123
assertEquals(bunLoad.code, 0, bunLoad.stderr || bunLoad.stdout);
122124
assertEquals(bunLoad.stdout.trim(), '["graphiti"]');

src/services/runtime-teardown.smoke.test.ts

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const waitForExit = async (
4444
const waitForText = async (
4545
stream: ReadableStream<Uint8Array> | null,
4646
expected: string,
47+
timeoutMs: number,
4748
): Promise<{
4849
seen: string;
4950
remainder: Promise<string>;
@@ -54,14 +55,27 @@ const waitForText = async (
5455
const reader = stream.getReader();
5556
const decoder = new TextDecoder();
5657
let seen = "";
58+
let timeoutId: ReturnType<typeof setTimeout> | undefined;
5759

5860
try {
59-
while (!seen.includes(expected)) {
60-
const { value, done } = await reader.read();
61-
if (done) break;
62-
if (!value) continue;
63-
seen += decoder.decode(value, { stream: true });
64-
}
61+
await Promise.race([
62+
(async () => {
63+
while (!seen.includes(expected)) {
64+
const { value, done } = await reader.read();
65+
if (done) break;
66+
if (!value) continue;
67+
seen += decoder.decode(value, { stream: true });
68+
}
69+
})(),
70+
new Promise<never>((_, reject) => {
71+
timeoutId = setTimeout(() => {
72+
void reader.cancel();
73+
reject(
74+
new Error(`timed out waiting for ${JSON.stringify(expected)}`),
75+
);
76+
}, timeoutMs);
77+
}),
78+
]);
6579
seen += decoder.decode();
6680

6781
const remainder = (async () => {
@@ -84,6 +98,8 @@ const waitForText = async (
8498
} catch (error) {
8599
reader.releaseLock();
86100
throw error;
101+
} finally {
102+
if (timeoutId !== undefined) clearTimeout(timeoutId);
87103
}
88104
};
89105

@@ -99,7 +115,7 @@ Deno.test({
99115
stderr: "piped",
100116
}).spawn();
101117

102-
const stdoutState = await waitForText(child.stdout, "ready\n");
118+
const stdoutState = await waitForText(child.stdout, "ready\n", 2_000);
103119
const stderrPromise = new Response(child.stderr).text();
104120

105121
child.kill("SIGINT");

0 commit comments

Comments
 (0)