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.

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.

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.

75 changes: 75 additions & 0 deletions pstack/skills/poteto-mode/scripts/watch-pr/cli.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, it } from "bun:test";
import { type CliRuntime, main, parseArgs } from "./cli.ts";
import { fakeReader, passingCheck } from "./fakes.test-helper.ts";
import { WatcherQueryError } from "./github.ts";
import { renderJson, renderPretty } from "./render.ts";
import type { GitHubReader, WatcherVerdict } from "./types.ts";
import { parsePrNumber } from "./types.ts";
Expand Down Expand Up @@ -103,6 +104,80 @@ describe("parseArgs", () => {
});
});

describe("heads without checks", () => {
const noChecks = () =>
fakeReader({
fastPath: {
kind: "unusable",
exitCode: 1,
stderr: "no checks reported on the 'feature' branch",
},
rollupPages: [{ checks: [], endCursor: null }],
});

it("--status-only reports the head once instead of retrying", async () => {
const harness = testRuntime(noChecks());
expect(await main(["--pr", "1", "--status-only"], harness.runtime)).toBe(0);
expect(harness.stdout).toHaveLength(1);
const verdict = JSON.parse(harness.stdout[0] ?? "") as WatcherVerdict;
expect(verdict.kind).toBe("STATUS");
if (verdict.kind !== "STATUS") throw new Error("expected STATUS");
const row = verdict.rows[0];
expect(row.kind).toBe("open");
if (row.kind !== "open") throw new Error("expected open row");
expect(row.ci.kind).toBe("ci-none");
});

it("--status-only --pretty names the missing checks", async () => {
const harness = testRuntime(noChecks());
expect(
await main(["--pr", "1", "--status-only", "--pretty"], harness.runtime)
).toBe(0);
expect(harness.stdout.join("")).toContain("no checks reported");
});

it("--status-only ends on the first query error instead of sleeping", async () => {
const reader = noChecks();
const failing: GitHubReader = {
...reader,
async pullRequest() {
throw new WatcherQueryError({
kind: "json-parse",
retryable: true,
detail: "simulated outage",
});
},
};
const harness = testRuntime(failing);
const code = await main(["--pr", "1", "--status-only"], harness.runtime);
expect(code).not.toBe(0);
expect(harness.stdout).toHaveLength(1);
const verdict = JSON.parse(harness.stdout[0] ?? "") as WatcherVerdict;
expect(verdict.kind).not.toBe("RETRY");
});

it("polling still treats a head without checks as a retryable error", async () => {
const harness = testRuntime(noChecks());
const slept: number[] = [];
const runtime: CliRuntime = {
...harness.runtime,
clock: {
...harness.runtime.clock,
async sleep(seconds) {
slept.push(seconds);
if (slept.length >= 2) throw new Error("stop test");
},
},
};
await expect(
main(["--pr", "1", "--max-query-errors", "5"], runtime)
).rejects.toThrow("stop test");
expect(slept.length).toBe(2);
const first = JSON.parse(harness.stdout[0] ?? "") as WatcherVerdict;
expect(first.kind).toBe("RETRY");
});
});

describe("rendering", () => {
const context = {
owner: "owner",
Expand Down
6 changes: 5 additions & 1 deletion pstack/skills/poteto-mode/scripts/watch-pr/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ export function parseArgs(
positiveInteger,
5
)
.option("--status-only", "print one status table and exit 0", false)
.option(
"--status-only",
"read GitHub once, print one status table and exit 0; a head with no checks is reported, not retried",
false
)
.option("--allow-draft", "do not treat a draft as a merge gate", false)
.option("--pretty", "render human text instead of JSON", false);
program.parse(argv, { from: "user" });
Expand Down
Loading