Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

Make CI watchers resilient to transient GitHub failures (#1327)

Regan Bell29e26dce8873
diff --git a/skills-seed/github-gitlab/SKILL.md b/skills-seed/github-gitlab/SKILL.md
index 260c9ea8c..2815ddf8d 100644
--- a/skills-seed/github-gitlab/SKILL.md
+++ b/skills-seed/github-gitlab/SKILL.md
@@ -37,7 +37,11 @@ Never copy tokens into remotes or expose them while checking authentication.
## Logging in
-If `gh auth status` (or `glab auth status`) fails, log in with the native command:
+Use the native login only after an explicit authentication rejection. A TLS timeout,
+connection reset, rate limit, or GitHub server error is not evidence of logout or
+permission expiry. Do not consume another credential grant to repair transport.
+
+For a confirmed missing or expired GitHub login:
```bash
gh auth login
@@ -109,3 +113,41 @@ glab mr create --repo GROUP/PROJECT --title "..." --description-file mr.md
```
Report the final URL and leave enough context for review.
+
+## Wait for GitHub CI
+
+Use the bundled helper instead of a bare `gh pr checks --watch` or a handwritten
+shell loop. It is one blocking watcher process, not repeated agent turns:
+
+```bash
+node skills/github-gitlab/scripts/watch-ci.mjs --repo OWNER/REPO --pr NUMBER --head REVIEWED_HEAD_SHA
+```
+
+Capture the full head SHA from `gh pr view NUMBER --repo OWNER/REPO --json headRefOid`
+before review. Use that same SHA for the watcher and the final merge gate. Start the
+watcher with the background-process tool and subscribe to its completion. Keep one
+watcher per PR. Set the process lifetime longer than the helper's 30-minute deadline;
+use `--timeout-ms` for a different bounded deadline. Use only credentials authorized
+for that background process; a live foreground grant does not authorize background work.
+
+The helper polls GitHub internally and emits JSON status records. It retries only
+recognized transient transport/server errors with bounded backoff. Pending checks
+remain pending. Real CI failures, authentication/authorization failures, changed heads,
+unknown errors, exhausted retries, and deadline expiry all stop with nonzero status.
+Explicit API rate limits stop as `rate_limited`, not authentication errors.
+Empty check sets, skipped checks, and cancelled checks are not successful evidence.
+Do not interpret an exit code alone as "checks concluded": read the status record.
+Do not suppress a nonzero exit or print a success marker after it. Keep `set -e`.
+
+Success means the checks observed for the expected head passed, not permission to
+merge. Re-read checks and review threads immediately before merging. Wait for async
+reviewers on that exact head; resolve findings and obtain a fresh-context adversarial
+review. After any push or head change, discard old success/review evidence and repeat.
+Only merge when all gates pass, with GitHub's atomic head guard:
+
+```bash
+gh pr merge NUMBER --repo OWNER/REPO --squash --match-head-commit REVIEWED_HEAD_SHA
+```
+
+Never use auto-merge or bypass repository gates. This helper does not retry GitLab
+commands or change their authentication behavior.
diff --git a/skills-seed/github-gitlab/scripts/watch-ci.mjs b/skills-seed/github-gitlab/scripts/watch-ci.mjs
new file mode 100755
index 000000000..5fd519c4a
--- /dev/null
+++ b/skills-seed/github-gitlab/scripts/watch-ci.mjs
@@ -0,0 +1,170 @@
+#!/usr/bin/env node
+import { spawnSync } from "node:child_process";
+import { parseArgs } from "node:util";
+import { setTimeout as sleep } from "node:timers/promises";
+
+function report(status, details = {}) {
+ console.log(JSON.stringify({ status, ...details }));
+}
+
+function stop(status, exitCode = 1, details = {}) {
+ report(status, { ...details, exitCode });
+ process.exit(exitCode);
+}
+
+let options;
+try {
+ options = parseArgs({
+ options: Object.fromEntries(
+ [
+ "repo",
+ "pr",
+ "head",
+ "timeout-ms",
+ "poll-ms",
+ "request-timeout-ms",
+ "max-retries",
+ "backoff-ms",
+ "max-backoff-ms",
+ ].map((name) => [name, { type: "string" }]),
+ ),
+ }).values;
+ if (
+ !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(options.repo ?? "") ||
+ !/^[1-9]\d*$/.test(options.pr ?? "") ||
+ !/^[a-fA-F0-9]{40}$/.test(options.head ?? "")
+ ) {
+ throw new Error("invalid target");
+ }
+} catch {
+ stop("invalid_arguments", 2);
+}
+
+function integer(name, fallback, minimum = 1) {
+ const value = options[name] === undefined ? fallback : Number(options[name]);
+ if (!Number.isSafeInteger(value) || value < minimum || value > 2147483647) {
+ stop("invalid_arguments", 2, { option: name });
+ }
+ return value;
+}
+
+const timeoutMs = integer("timeout-ms", 1800000);
+const pollMs = integer("poll-ms", 15000);
+const requestTimeoutMs = integer("request-timeout-ms", 30000);
+const maxRetries = integer("max-retries", 5, 0);
+const backoffMs = integer("backoff-ms", 1000);
+const maxBackoffMs = integer("max-backoff-ms", 15000);
+const deadline = performance.now() + timeoutMs;
+const expectedHead = options.head.toLowerCase();
+let retries = 0;
+
+function remaining() {
+ const left = Math.floor(deadline - performance.now());
+ if (left <= 0) stop("deadline_exceeded", 124);
+ return left;
+}
+
+async function pause(ms) {
+ await sleep(Math.min(ms, remaining()));
+ remaining();
+}
+
+function classify(result) {
+ const text = result.stderr ?? "";
+ if (/\bHTTP\s*429\b|API rate limit exceeded|secondary rate limit|abuse detection/i.test(text)) return "rate_limited";
+ if (
+ result.status === 4 ||
+ /\bHTTP\s*(?:401|403)\b|\b(?:unauthorized|forbidden|authentication failed|bad credentials|requires authentication|not logged in)\b|gh auth login|resource not accessible|could not resolve to a repository/i.test(
+ text,
+ )
+ )
+ return "auth_error";
+ if (
+ result.error?.code === "ETIMEDOUT" ||
+ /TLS handshake timeout|\b(?:ETIMEDOUT|ECONNRESET|ECONNREFUSED|EAI_AGAIN|ENETUNREACH|EHOSTUNREACH)\b|connection reset|connection refused|network is unreachable|network error|error connecting to|could not resolve host|no such host|socket hang up|Client\.Timeout exceeded|i\/o timeout|context deadline exceeded|request timed out|connection timed out|temporary failure in name resolution|unexpected EOF|\bHTTP\s*5\d\d\b|\b(?:502 Bad Gateway|503 Service Unavailable|504 Gateway Timeout)\b/i.test(
+ text,
+ )
+ )
+ return "transport_error";
+ return "unknown_error";
+}
+
+async function snapshot(operation) {
+ const fields = operation === "view" ? "headRefOid" : "bucket,name";
+ for (;;) {
+ const result = spawnSync("gh", ["pr", operation, options.pr, "--repo", options.repo, "--json", fields], {
+ encoding: "utf8",
+ timeout: Math.min(requestTimeoutMs, remaining()),
+ killSignal: "SIGKILL",
+ maxBuffer: 1024 * 1024,
+ env: { ...process.env, GH_PROMPT_DISABLED: "1", GH_DEBUG: "", DEBUG: "" },
+ });
+ remaining();
+ const documentedCheckExit = operation === "checks" && (result.status === 1 || result.status === 8);
+ if (!result.error && !result.signal && (result.status === 0 || documentedCheckExit)) {
+ try {
+ const value = JSON.parse(result.stdout);
+ if (
+ result.status === 0 ||
+ (Array.isArray(value) &&
+ value.length > 0 &&
+ value.every((check) => check && typeof check.name === "string" && typeof check.bucket === "string") &&
+ (result.status === 1
+ ? value.some((check) => check.bucket === "fail")
+ : value.some((check) => check.bucket === "pending")))
+ ) {
+ return { value, exitCode: result.status };
+ }
+ } catch {
+ if (result.status === 0) stop("unknown_error", 1, { operation, reason: "invalid_json" });
+ }
+ }
+ const category = classify(result);
+ const ghExitCode = result.status ?? 1;
+ if (category !== "transport_error") stop(category, ghExitCode || 1, { operation, ghExitCode });
+ if (retries >= maxRetries) stop("retries_exhausted", ghExitCode || 1, { operation, category, retries });
+ retries += 1;
+ const delayMs = Math.min(maxBackoffMs, backoffMs * 2 ** Math.min(retries - 1, 30));
+ report("retrying", { operation, category, retry: retries, delayMs, ghExitCode });
+ await pause(delayMs);
+ }
+}
+
+async function verifyHead() {
+ const { value } = await snapshot("view");
+ if (!value || typeof value.headRefOid !== "string" || !/^[a-fA-F0-9]{40}$/.test(value.headRefOid))
+ stop("unknown_error", 1, { operation: "view", reason: "invalid_head" });
+ if (value.headRefOid.toLowerCase() !== expectedHead) stop("head_changed", 1);
+}
+
+for (;;) {
+ await verifyHead();
+ const { value: checks, exitCode } = await snapshot("checks");
+ if (
+ !Array.isArray(checks) ||
+ !checks.every(
+ (check) =>
+ check &&
+ typeof check.name === "string" &&
+ ["pass", "fail", "pending", "skipping", "cancel"].includes(check.bucket),
+ )
+ )
+ stop("unknown_error", exitCode || 1, { operation: "checks", reason: "invalid_checks" });
+ if (checks.length === 0) stop("blocked", 1, { reason: "empty_checks" });
+ const counts = Object.fromEntries(
+ ["pass", "fail", "pending", "skipping", "cancel"].map((bucket) => [
+ bucket,
+ checks.filter((check) => check.bucket === bucket).length,
+ ]),
+ );
+ if (counts.fail) stop("failed", exitCode || 1, { counts });
+ if (counts.pending) {
+ report("pending", { counts });
+ await pause(pollMs);
+ continue;
+ }
+ if (counts.skipping || counts.cancel) stop("blocked", 1, { reason: "non_passing_checks", counts });
+ await verifyHead();
+ remaining();
+ stop("success", 0, { head: expectedHead, counts });
+}
diff --git a/skills-seed/send/SKILL.md b/skills-seed/send/SKILL.md
new file mode 100644
index 000000000..724be8764
--- /dev/null
+++ b/skills-seed/send/SKILL.md
@@ -0,0 +1,114 @@
+---
+name: send
+description: Make a PR, wait for CI with bounded transport retries, independently review, and merge only when all gates pass.
+requiredCapabilities:
+ - egress:github.com
+ - egress:api.github.com
+ - egress:gitlab.com
+---
+
+# Babysit
+
+Make a pull request for the change we just discussed, file it, babysit CI, fix
+any issues that come up, and merge once CI is **fully** green.
+
+## Steps
+
+1. **Make the PR.** Commit the discussed change on a feature branch (create one
+ off the default branch if currently on it). Push it.
+
+2. **File it.** Open a pull request with a clear title and description covering why and what changed. Use `gh` for GitHub or `glab` for
+ GitLab. Detect from the remote.
+
+3. **Wait for CI in one blocking process, with bounded transport retries.**
+ Read the `github-gitlab` skill. For GitHub, capture the PR's full head SHA and
+ use its bundled helper, not bare `gh pr checks --watch`:
+
+ ```bash
+ node skills/github-gitlab/scripts/watch-ci.mjs --repo OWNER/REPO --pr NUMBER --head REVIEWED_HEAD_SHA
+ ```
+
+ Run this in the background with authorized credentials and subscribe to completion.
+ Keep one watcher per PR; hand off if another agent already owns it. The helper
+ polls internally, retries recognized transport/server errors with bounded backoff,
+ and has a 30-minute overall deadline. Set the background lifetime longer than that.
+ Do not wake the model repeatedly to report pending checks.
+
+ Read the helper's JSON status, not just the exit code. Pending is not failure;
+ TLS timeouts and connection resets are not logout or permission expiry. Failed
+ checks, auth failures, rate limits, unknown errors, exhausted retries, and deadlines all
+ remain nonzero. Keep `set -e`; never mask failure with a success marker or merge.
+ A changed head invalidates successful checks and reviews: restart both on the
+ new SHA. Empty, skipped, or cancelled checks do not count as success.
+
+ For GitLab, use `glab ci status --live`; the GitHub helper does not cover it.
+ Preserve its nonzero status and investigate failures before proceeding.
+
+ Also wait for asynchronous reviewers (including Bugbot) to finish on the latest
+ commit. Watcher success alone is never approval to merge.
+
+4. **Adversarially review the PR — always in a fresh context, before merging.**
+ Dispatch an independent subagent (or `/code-review`) that has not seen you
+ write the change. **Never review your own diff in the context that produced
+ it** — that context already believes the change is correct, and that belief is
+ exactly the bias review exists to defeat. A fresh reviewer is non-negotiable on
+ every send, however small the diff and however green CI is.
+
+ What scales with risk is the reviewer's **depth and breadth**, not its
+ independence:
+
+ - **Small, well-tested, single-file change:** one reviewer, modest effort,
+ scoped to the diff and its immediate call sites. Cheap, but still a
+ stranger's eyes.
+ - **Risky change** — core control flow, auth/credentials/security, data loss or
+ migrations, concurrency and retry logic, spend, a public API contract, or a
+ diff too large to hold in your head: high effort, wider blast-radius reading,
+ and consider several reviewers with distinct lenses (correctness, security,
+ does-it-actually-reproduce).
+
+ Prompt the reviewer to _break_ the change: correctness bugs, edge cases,
+ regressions, security holes, violations of the repo's CLAUDE.md/spec,
+ **overengineering** (needless abstraction, flags, layers, or generality for one
+ caller — prefer the simplest thing that works), and **reward hacking** (tests
+ weakened, skipped, or tailored to pass rather than to verify; assertions
+ gutted; intent met in letter but not spirit; CI gamed). Treat the diff as
+ guilty until proven correct. Green CI is not review.
+
+5. **Fix every real issue found.** Address each genuine finding from the
+ adversarial review, from CI, and from reviewers/bots: fix it, push, and go
+ back to step 3. Re-review the **delta**, not the whole diff again — a fresh
+ full review per round is how a small PR turns into an afternoon. For anything
+ that needs human judgment, ask the user. Cap at ~3 fix rounds, then stop and
+ report what's unresolved.
+
+6. **Merge once green AND reviewed.** Merge only when all checks pass, the
+ adversarial review is clean (no unaddressed findings), and there are no
+ unresolved comments/findings — re-read checks and review threads, then merge directly
+ (`gh pr merge NUMBER --repo OWNER/REPO --squash --match-head-commit REVIEWED_HEAD_SHA` /
+ `glab mr merge --squash`). Do **not** use platform auto-merge — it fires the
+ moment required checks pass, before async bots like Bugbot finish and before
+ your review is done.
+
+## Notes
+
+- "Pull request" = PR/MR; same thing on either platform.
+- The review is non-optional on every send, and always runs in a fresh context —
+ what scales with risk is how deep the reviewer goes, never whether it's someone
+ other than the author.
+- Don't merge with open Bugbot/reviewer findings on the current commit.
+- Weight human feedback over bot feedback; don't blindly accept everything.
+- Prefer rebase over merge for conflicts. Never amend commits.
+- **Verify locally with the affected tests, not the whole suite.** Run the tests
+ covering what you changed, plus typecheck and lint, then push and let CI be the
+ full gate. CI shards the suite across parallel runners; reproducing that
+ serially on one machine can cost 4x the wall clock for the same signal. Run the
+ full suite locally only when the change is broad enough that you can't tell
+ which tests are affected.
+
+## Installed skill overrides
+
+This workflow uses the `github-gitlab` seed skill's bundled watcher. Existing
+user-authored skills with the same name are not overwritten by seed installation.
+If an installed `send` or `github-gitlab` skill still says to use bare `gh --watch`,
+update that managed skill explicitly with its owner's approval. Do not claim an
+upstream merge updates already-published custom skills or running watcher scripts.
diff --git a/test/ci-watch.test.ts b/test/ci-watch.test.ts
new file mode 100644
index 000000000..c10bb4830
--- /dev/null
+++ b/test/ci-watch.test.ts
@@ -0,0 +1,270 @@
+import assert from "node:assert/strict";
+import { spawnSync } from "node:child_process";
+import { mkdtempSync, writeFileSync, readFileSync, rmSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { delimiter, join } from "node:path";
+import { fileURLToPath } from "node:url";
+import { test } from "node:test";
+
+const head = "a".repeat(40);
+const watcher = fileURLToPath(new URL("../skills-seed/github-gitlab/scripts/watch-ci.mjs", import.meta.url));
+const view = { operation: "view", json: { headRefOid: head } };
+const pass = { operation: "checks", json: [{ name: "CI", bucket: "pass" }] };
+const pending = { operation: "checks", json: [{ name: "CI", bucket: "pending" }], code: 8 };
+type Step = { operation: string; json?: unknown; stdout?: string; stderr?: string; code?: number; hang?: boolean };
+
+function run(steps: Step[], args: string[] = []) {
+ const dir = mkdtempSync(join(tmpdir(), "ci-watch-"));
+ writeFileSync(join(dir, "steps.json"), JSON.stringify(steps));
+ writeFileSync(
+ join(dir, "gh"),
+ `#!${process.execPath}
+import { readFileSync, writeFileSync, appendFileSync, existsSync } from 'node:fs';
+const dir = process.env.FAKE_GH_DIR;
+const indexFile = dir + '/index';
+const index = existsSync(indexFile) ? Number(readFileSync(indexFile, 'utf8')) : 0;
+const steps = JSON.parse(readFileSync(dir + '/steps.json', 'utf8'));
+const step = steps[index];
+appendFileSync(dir + '/calls', JSON.stringify(process.argv.slice(2)) + '\\n');
+writeFileSync(indexFile, String(index + 1));
+if (!step || step.operation !== process.argv[3]) process.exit(99);
+if (step.hang) {
+ setInterval(() => {}, 1000);
+} else {
+ process.stdout.write(step.stdout ?? JSON.stringify(step.json ?? null));
+ process.stderr.write(step.stderr ?? '');
+ process.exitCode = step.code ?? 0;
+}
+`,
+ { mode: 0o755 },
+ );
+ try {
+ const result = spawnSync(
+ process.execPath,
+ [
+ watcher,
+ "--repo",
+ "owner/repo",
+ "--pr",
+ "42",
+ "--head",
+ head,
+ "--timeout-ms",
+ "4000",
+ "--poll-ms",
+ "1",
+ "--request-timeout-ms",
+ "1000",
+ "--backoff-ms",
+ "1",
+ "--max-backoff-ms",
+ "2",
+ "--max-retries",
+ "2",
+ ...args,
+ ],
+ {
+ encoding: "utf8",
+ timeout: 10000,
+ env: {
+ ...process.env,
+ PATH: `${dir}${delimiter}${process.env.PATH}`,
+ FAKE_GH_DIR: dir,
+ GH_TOKEN: "secret-must-not-appear",
+ },
+ },
+ );
+ assert.equal(result.error, undefined);
+ assert.equal(result.signal, null);
+ assert.equal(result.stderr, "");
+ assert.ok(!result.stdout.includes("secret-must-not-appear"));
+ const lines = result.stdout
+ .trim()
+ .split("\n")
+ .map((line) => JSON.parse(line));
+ const calls = readFileSync(join(dir, "calls"), "utf8")
+ .trim()
+ .split("\n")
+ .map((line) => JSON.parse(line));
+ for (const call of calls)
+ assert.deepEqual(call, [
+ "pr",
+ call[1],
+ "42",
+ "--repo",
+ "owner/repo",
+ "--json",
+ call[1] === "view" ? "headRefOid" : "bucket,name",
+ ]);
+ assert.equal(lines.at(-1).exitCode, result.status);
+ return { code: result.status, lines, calls };
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+}
+
+for (const stderr of [
+ "net/http: TLS handshake timeout",
+ "read: connection reset by peer",
+ "HTTP 502: Bad Gateway",
+ "error connecting to api.github.com",
+]) {
+ test(`recovers from ${stderr} inside one watcher process`, () => {
+ const result = run([view, { operation: "checks", stderr, code: 1 }, pass, view]);
+ assert.equal(result.code, 0);
+ assert.deepEqual(
+ result.lines.map((line) => line.status),
+ ["retrying", "success"],
+ );
+ });
+}
+
+test("pending exit 8 and exit 0 poll until a complete passing snapshot", () => {
+ const result = run([view, pending, view, { ...pending, code: 0 }, view, pass, view]);
+ assert.equal(result.code, 0);
+ assert.deepEqual(
+ result.lines.map((line) => line.status),
+ ["pending", "pending", "success"],
+ );
+ assert.equal(result.calls.length, 7);
+});
+
+test("pending snapshots can replace skipped or cancelled checks before passing", () => {
+ for (const bucket of ["skipping", "cancel"]) {
+ const result = run([
+ view,
+ { ...pending, json: [...pending.json, { name: "previous check", bucket }] },
+ view,
+ pass,
+ view,
+ ]);
+ assert.equal(result.code, 0);
+ assert.deepEqual(
+ result.lines.map((line) => line.status),
+ ["pending", "success"],
+ );
+ assert.equal(result.calls.length, 5);
+ }
+});
+
+test("transport errors exhaust the bounded retry budget", () => {
+ const error = { operation: "checks", stderr: "TLS handshake timeout", code: 1 };
+ const result = run([view, error, error, error]);
+ assert.equal(result.code, 1);
+ assert.deepEqual(
+ result.lines.map((line) => line.status),
+ ["retrying", "retrying", "retries_exhausted"],
+ );
+});
+
+test("real failed checks stop immediately, including mixed pending checks", () => {
+ const result = run([view, { operation: "checks", json: [{ name: "CI", bucket: "fail" }, ...pending.json], code: 1 }]);
+ assert.equal(result.code, 1);
+ assert.equal(result.lines.at(-1).status, "failed");
+ assert.equal(result.calls.length, 2);
+});
+
+for (const stderr of [
+ "HTTP 401: Bad credentials",
+ "HTTP 403: Resource not accessible by integration",
+ "To get started with GitHub CLI, please run: gh auth login",
+]) {
+ test(`auth failure does not retry: ${stderr}`, () => {
+ const code = stderr.includes("gh auth login") ? 4 : 1;
+ const result = run([{ operation: "view", stderr: `${stderr} secret-must-not-appear`, code }]);
+ assert.equal(result.code, code);
+ assert.equal(result.lines.at(-1).status, "auth_error");
+ assert.equal(result.calls.length, 1);
+ });
+}
+
+for (const stderr of [
+ "HTTP 403: API rate limit exceeded",
+ "HTTP 403: You have exceeded a secondary rate limit",
+ "HTTP 403: You have triggered an abuse detection mechanism",
+ "HTTP 429: Too Many Requests",
+]) {
+ test(`rate limits stop without auth errors or retries: ${stderr}`, () => {
+ const result = run([view, { operation: "checks", stderr, code: 1 }]);
+ assert.equal(result.code, 1);
+ assert.deepEqual(
+ result.lines.map((line) => line.status),
+ ["rate_limited"],
+ );
+ assert.equal(result.lines.at(-1).ghExitCode, 1);
+ assert.equal(result.calls.length, 2);
+ });
+}
+
+test("unknown exit code propagates and valid-looking partial output cannot pass", () => {
+ const result = run([view, { ...pass, code: 42, stderr: "unknown error secret-must-not-appear" }]);
+ assert.equal(result.code, 42);
+ assert.equal(result.lines.at(-1).status, "unknown_error");
+});
+
+for (const step of [
+ { ...pass, code: 1 },
+ { ...pass, code: 8 },
+ { operation: "checks", stdout: '[{"name":"CI","bucket":"pass"}', code: 0 },
+ { operation: "checks", json: [{ name: "CI", bucket: "unexpected" }] },
+]) {
+ test(`fails closed on invalid checks or inconsistent exit: ${JSON.stringify(step)}`, () => {
+ const result = run([view, step]);
+ assert.notEqual(result.code, 0);
+ assert.equal(result.lines.at(-1).status, "unknown_error");
+ });
+}
+
+for (const checks of [[], [{ name: "CI", bucket: "skipping" }], [{ name: "CI", bucket: "cancel" }]]) {
+ test(`blocks empty or nonpassing checks: ${JSON.stringify(checks)}`, () => {
+ const result = run([view, { operation: "checks", json: checks }]);
+ assert.equal(result.code, 1);
+ assert.equal(result.lines.at(-1).status, "blocked");
+ });
+}
+
+for (const steps of [
+ [{ operation: "view", json: { headRefOid: "b".repeat(40) } }],
+ [view, pass, { operation: "view", json: { headRefOid: "b".repeat(40) } }],
+ [view, pending, { operation: "view", json: { headRefOid: "b".repeat(40) } }],
+]) {
+ test(`head changes stop before success at invocation ${steps.length}`, () => {
+ const result = run(steps);
+ assert.equal(result.code, 1);
+ assert.equal(result.lines.at(-1).status, "head_changed");
+ });
+}
+
+test("overall deadline kills a hung gh request", () => {
+ const started = performance.now();
+ const result = run([{ operation: "view", hang: true }], ["--timeout-ms", "200"]);
+ assert.equal(result.code, 124);
+ assert.equal(result.lines.at(-1).status, "deadline_exceeded");
+ assert.ok(performance.now() - started < 2000);
+});
+
+test("a request timeout retries within the overall deadline", () => {
+ const result = run([{ operation: "view", hang: true }, view, pass, view], ["--request-timeout-ms", "200"]);
+ assert.equal(result.code, 0);
+ assert.deepEqual(
+ result.lines.map((line) => line.status),
+ ["retrying", "success"],
+ );
+});
+
+test("pending sleep and retry backoff cannot exceed the overall deadline", () => {
+ for (const steps of [[view, pending], [{ operation: "view", code: 1, stderr: "TLS handshake timeout" }]]) {
+ const result = run(steps, [
+ "--timeout-ms",
+ "300",
+ "--poll-ms",
+ "10000",
+ "--backoff-ms",
+ "10000",
+ "--max-backoff-ms",
+ "10000",
+ ]);
+ assert.equal(result.code, 124);
+ assert.equal(result.lines.at(-1).status, "deadline_exceeded");
+ }
+});
diff --git a/test/skills-seed.test.ts b/test/skills-seed.test.ts
index 207e03755..eba6e787f 100644
--- a/test/skills-seed.test.ts
+++ b/test/skills-seed.test.ts
@@ -43,6 +43,12 @@ test("installSeedSkills publishes the repository starter catalog into org scope"
assert.ok(result.installed.includes("google-workspace"));
assert.ok(result.installed.includes("google-drive-sheets"));
assert.ok(result.installed.includes("github-gitlab"));
+ assert.ok(result.installed.includes("send"));
+ const github = (await skills.list()).find((s) => s.manifest.name === "github-gitlab")!;
+ assert.equal(
+ github.manifest.files?.find((file) => file.path === "scripts/watch-ci.mjs")?.content,
+ readFileSync("skills-seed/github-gitlab/scripts/watch-ci.mjs", "utf8"),
+ );
assert.ok(result.installed.includes("taste-skill"));
assert.ok(result.installed.includes("use-shared-credential"));