Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pstack/skills/poteto-mode/scripts/watch-pr/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,25 @@ printf '%s\\n' '[{"number":42,"headRefName":"feature","baseRefName":"main","isCr
}
});

it("reports a gh that cannot start as a query failure", () => {
const directory = mkdtempSync(join(tmpdir(), "watch-pr-no-gh-"));
try {
const program = `import { GhGitHubReader, WatcherQueryError } from ${JSON.stringify(import.meta.dir + "/github.ts")};
try {
await new GhGitHubReader().pullRequest({ owner: "owner", repo: "repo", number: 42 });
} catch (error) {
console.log(JSON.stringify(error instanceof WatcherQueryError ? error.failure.kind : String(error)));
}`;
const child = spawnSync(process.execPath, ["-e", program], {
encoding: "utf8", timeout: 2000,
env: { ...process.env, PATH: directory },
});
expect(child.error).toBeUndefined();
expect(child.status).toBe(0);
expect(JSON.parse(child.stdout)).toBe("command-exit");
} finally {
rmSync(directory, { recursive: true, force: true });
}
});

});
20 changes: 15 additions & 5 deletions pstack/skills/poteto-mode/scripts/watch-pr/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,20 @@ export class ChecksUnavailable extends WatcherQueryError {
const firstLine = (value: string): string =>
value.trim().split(/\r?\n/, 1)[0]?.slice(0, 240) ?? "";
function run(argv: readonly [string, ...string[]]): Promise<CommandResult> {
return new Promise((resolve, reject) => {
const child = spawn(argv[0], argv.slice(1), {
stdio: ["ignore", "pipe", "pipe"],
});
return new Promise((resolve) => {
// A command that cannot start fails like one that exits nonzero; Bun
// throws here while Node emits "error".
const failed = (error: unknown) =>
resolve({ code: -1, stdout: "", stderr: String(error) });
let child;
try {
child = spawn(argv[0], argv.slice(1), {
stdio: ["ignore", "pipe", "pipe"],
});
} catch (error) {
failed(error);
return;
}
let stdout = "";
let stderr = "";
child.stdout.setEncoding("utf8");
Expand All @@ -44,7 +54,7 @@ function run(argv: readonly [string, ...string[]]): Promise<CommandResult> {
child.stderr.on("data", (chunk: string) => {
stderr += chunk;
});
child.on("error", reject);
child.on("error", failed);
child.on("close", (code) => resolve({ code: code ?? -1, stdout, stderr }));
});
}
Expand Down
Loading