Skip to content

Commit 775b047

Browse files
committed
test: validate required author activity fixture entries
1 parent 9c683f9 commit 775b047

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

‎test/scripts/github-activity-helper.test.ts‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import assert from "node:assert/strict";
12
import { spawnSync } from "node:child_process";
23
import { closeSync, mkdirSync, openSync, readFileSync, writeFileSync } from "node:fs";
34
import path from "node:path";
@@ -21,6 +22,12 @@ type Fixture = {
2122
};
2223
type Request = { route: string; args: string[]; output: string };
2324

25+
function requiredAt<T>(items: T[], index: number): T {
26+
const item = items[index];
27+
assert(item !== undefined, `Missing fixture item at index ${index}`);
28+
return item;
29+
}
30+
2431
function runHelper(args: string[], fixture: Fixture = {}) {
2532
const dir = createTempDir("github-activity-helper-");
2633
const binDir = path.join(dir, "bin");
@@ -127,8 +134,8 @@ fi
127134
describe("openclaw-pr-maintainer github activity helper", () => {
128135
it("prints canonical identity before the first activity request, even when a scan blocks", () => {
129136
const { requests } = runHelper(["alias"], { blockActivity: true });
130-
expect(requests[0].args[1]).toBe("users/alias");
131-
expect(requests[1].output).toContain(
137+
expect(requiredAt(requests, 0).args[1]).toBe("users/alias");
138+
expect(requiredAt(requests, 1).output).toContain(
132139
"Example Author (@Canonical, User, account created 2010-09-21",
133140
);
134141
});
@@ -144,7 +151,7 @@ describe("openclaw-pr-maintainer github activity helper", () => {
144151
expect(args).not.toContain("--paginate");
145152
expect(args).not.toContain("-f");
146153
expect(args).not.toContain("-F");
147-
const url = new URL(args[1], "https://api.github.test/");
154+
const url = new URL(requiredAt(args, 1), "https://api.github.test/");
148155
expect(url.searchParams.get("per_page")).toBe("1");
149156
expect(url.searchParams.get("q")).toContain("repo:openclaw/openclaw author:Canonical");
150157
return url;
@@ -154,9 +161,9 @@ describe("openclaw-pr-maintainer github activity helper", () => {
154161
"/search/issues",
155162
"/search/commits",
156163
]);
157-
expect(searches[0].searchParams.get("q")).toContain("is:pr");
158-
expect(searches[1].searchParams.get("q")).toContain("is:issue");
159-
expect(searches[2].searchParams.get("q")).toContain("committer-date:");
164+
expect(requiredAt(searches, 0).searchParams.get("q")).toContain("is:pr");
165+
expect(requiredAt(searches, 1).searchParams.get("q")).toContain("is:issue");
166+
expect(requiredAt(searches, 2).searchParams.get("q")).toContain("committer-date:");
160167
expect(stdout).toContain("index/cache may lag");
161168
});
162169

@@ -191,11 +198,12 @@ describe("openclaw-pr-maintainer github activity helper", () => {
191198
expect(requests.map(({ args }) => args[args.indexOf("--cache") + 1])).toEqual(
192199
Array(5).fill("1h"),
193200
);
201+
const repoArgs = requiredAt(requests, 1).args;
194202
const repoQuery =
195-
new URL(requests[1].args[1], "https://api.github.test").searchParams.get("q") ?? "";
203+
new URL(requiredAt(repoArgs, 1), "https://api.github.test").searchParams.get("q") ?? "";
196204
const repoRange = /created:([^ ]+)\.\.([^ ]+)/.exec(repoQuery);
197205
expect(repoRange).not.toBeNull();
198-
const graphql = requests[4].args;
206+
const graphql = requiredAt(requests, 4).args;
199207
const from = graphql.find((arg) => arg.startsWith("from="))?.slice(5) ?? "";
200208
const to = graphql.find((arg) => arg.startsWith("to="))?.slice(3) ?? "";
201209
expect(repoRange?.slice(1)).toEqual(["2024-08-26T00:00:00Z", "2026-08-25T23:59:59Z"]);
@@ -240,7 +248,7 @@ describe("openclaw-pr-maintainer github activity helper", () => {
240248
expect(stdout).toContain("@missing (profile unavailable; account age unknown)");
241249
expect(stdout).toContain("Example Author (@Canonical");
242250
expect(requests).toHaveLength(5);
243-
expect(requests[1].args[1]).toBe("users/alias");
251+
expect(requiredAt(requests, 1).args[1]).toBe("users/alias");
244252
});
245253
it("continues later logins after a failed global request without falling back to scans", () => {
246254
const { result, stdout, requests } = runHelper(["--global", "first", "second"], {
@@ -249,7 +257,7 @@ describe("openclaw-pr-maintainer github activity helper", () => {
249257
expect(result.status).toBe(1);
250258
expect(requests).toHaveLength(10);
251259
expect(stdout.match(/unavailable \(request failed\)/g)).toHaveLength(2);
252-
expect(requests[5].args[1]).toBe("users/second");
260+
expect(requiredAt(requests, 5).args[1]).toBe("users/second");
253261
});
254262

255263
it("keeps valid contribution zeroes without inferring inactivity or scanning other endpoints", () => {
@@ -295,10 +303,12 @@ describe("openclaw-pr-maintainer github activity helper", () => {
295303
])("bounds calendar subtraction at month ends: %s", (now, months, from) => {
296304
const { result, requests } = runHelper(["--months", months, "--global", "alias"], { now });
297305
expect(result.status).toBe(0);
298-
const query = new URL(requests[1].args[1], "https://api.github.test").searchParams.get("q");
306+
const repoArgs = requiredAt(requests, 1).args;
307+
const query = new URL(requiredAt(repoArgs, 1), "https://api.github.test").searchParams.get("q");
299308
expect(query).toContain(`created:${from}..`);
300-
expect(requests[4].args).toContain(`from=${from}`);
301-
const to = requests[4].args.find((arg) => arg.startsWith("to="))?.slice(3) ?? "";
309+
const graphql = requiredAt(requests, 4).args;
310+
expect(graphql).toContain(`from=${from}`);
311+
const to = graphql.find((arg) => arg.startsWith("to="))?.slice(3) ?? "";
302312
expect(Date.parse(to) - Date.parse(from)).toBeLessThanOrEqual(366 * 86400000);
303313
});
304314
});

0 commit comments

Comments
 (0)