paperlint 18.2.2 → 18.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/readability.d.ts +12 -9
  2. package/dist/readability.d.ts.map +1 -1
  3. package/dist/readability.js +3 -3
  4. package/dist/readability.js.map +1 -1
  5. package/dist/skills/pc-panel-review/scripts/prior-reviews-core.d.ts +19 -0
  6. package/dist/skills/pc-panel-review/scripts/prior-reviews.d.ts +2 -0
  7. package/docs/optional-rules.md +2 -2
  8. package/docs/rules/tex/max-paragraph-numbers.md +13 -7
  9. package/docs/rules/tex/max-paragraph-words.md +17 -28
  10. package/docs/rules.md +2 -2
  11. package/package.json +1 -1
  12. package/scripts/grow-real-papers/archive.test.ts +294 -0
  13. package/scripts/grow-real-papers/archive.ts +287 -0
  14. package/scripts/grow-real-papers/collect.test.ts +329 -0
  15. package/scripts/grow-real-papers/collect.ts +316 -0
  16. package/scripts/grow-real-papers/http.test.ts +95 -0
  17. package/scripts/grow-real-papers/http.ts +76 -0
  18. package/scripts/grow-real-papers/main.test.ts +295 -0
  19. package/scripts/grow-real-papers/main.ts +221 -0
  20. package/scripts/grow-real-papers/paper.test.ts +305 -0
  21. package/scripts/grow-real-papers/paper.ts +241 -0
  22. package/scripts/grow-real-papers/rules.test.ts +222 -0
  23. package/scripts/grow-real-papers/rules.ts +250 -0
  24. package/scripts/grow-real-papers/sources.test.ts +275 -0
  25. package/scripts/grow-real-papers/sources.ts +239 -0
  26. package/scripts/grow-real-papers/testkit.ts +79 -0
  27. package/skills/pc-panel-review/SKILL.md +18 -11
  28. package/skills/pc-panel-review/SKILL.md.spec.ts +17 -10
  29. package/skills/pc-panel-review/scripts/prior-reviews-core.js +44 -0
  30. package/skills/pc-panel-review/scripts/prior-reviews-core.ts +66 -0
  31. package/skills/pc-panel-review/scripts/prior-reviews.js +14 -0
  32. package/skills/pc-panel-review/scripts/prior-reviews.test.ts +206 -0
  33. package/skills/pc-panel-review/scripts/prior-reviews.ts +19 -0
  34. package/src/readability.test.ts +44 -41
  35. package/src/readability.ts +12 -9
  36. package/src/rule-cases.test.ts +6 -6
@@ -0,0 +1,287 @@
1
+ /**
2
+ * An arXiv source archive, read in memory and never executed: `unpack` turns the e-print's bytes
3
+ * into files, `stagingPlan` decides which files a paper keeps and where, `recordOf` writes the
4
+ * `record-by-hand.json` of what was staged. arXiv compiles from the archive's ROOT (its
5
+ * `00README.json` names the top-level file, e.g. `ACL2026/main.tex`), so every kept file keeps its
6
+ * path from the root and only the main file moves, to `paper.tex`. No I/O.
7
+ */
8
+ import { createHash } from "node:crypto";
9
+ import { gunzipSync } from "node:zlib";
10
+ import { z } from "zod";
11
+ import { stripComments, TEXT_EXT, type Verdict } from "./rules.ts";
12
+
13
+ export type ArchiveFile = Readonly<{ path: string; bytes: Uint8Array }>;
14
+
15
+ const latin1 = (b: Uint8Array): string => Buffer.from(b).toString("latin1");
16
+ const cString = (b: Uint8Array, at: number, len: number): string =>
17
+ latin1(b.subarray(at, at + len)).replace(/\0.*$/s, "");
18
+
19
+ /** A path inside the archive, or null for one that would leave it (absolute, or `..`). */
20
+ const safePath = (p: string): string | null => {
21
+ const parts = p
22
+ .replace(/^(\.\/)+/, "")
23
+ .split("/")
24
+ .filter((s) => s !== "" && s !== ".");
25
+ return p.startsWith("/") || parts.includes("..") || parts.length === 0
26
+ ? null
27
+ : parts.join("/");
28
+ };
29
+
30
+ type TarEntry = Readonly<{
31
+ name: string;
32
+ type: string;
33
+ body: Uint8Array;
34
+ next: number;
35
+ }>;
36
+
37
+ /** The tar entry whose header starts at `at`, or null at the end of the archive. */
38
+ const entryAt = (tar: Uint8Array, at: number): TarEntry | null => {
39
+ if (at + 512 > tar.length || tar[at] === 0) return null;
40
+ const head = tar.subarray(at, at + 512);
41
+ const size = parseInt(cString(head, 124, 12).trim(), 8);
42
+ const prefix = cString(head, 345, 155);
43
+ return {
44
+ name: (prefix === "" ? "" : `${prefix}/`) + cString(head, 0, 100),
45
+ type: latin1(head.subarray(156, 157)),
46
+ body: tar.subarray(at + 512, at + 512 + size),
47
+ next: at + 512 + Math.ceil(size / 512) * 512,
48
+ };
49
+ };
50
+
51
+ /** The name a GNU long-name (`L`) or pax (`x`) entry gives the entry after it. */
52
+ const nameForNext = (e: TarEntry): string | null =>
53
+ e.type === "L"
54
+ ? cString(e.body, 0, e.body.length)
55
+ : e.type === "x"
56
+ ? (/(?:^|\n)\d+ path=([^\n]*)\n/.exec(latin1(e.body))?.[1] ?? null)
57
+ : null;
58
+
59
+ /** The regular files of a tar stream; links, directories and unsafe paths are left out. */
60
+ export function untar(
61
+ tar: Uint8Array,
62
+ at = 0,
63
+ longName: string | null = null,
64
+ ): readonly ArchiveFile[] {
65
+ const e = entryAt(tar, at);
66
+ if (e === null) return [];
67
+ const regular = e.type === "0" || e.type === "\0";
68
+ const path = regular ? safePath(longName ?? e.name) : null;
69
+ return [
70
+ ...(path === null ? [] : [{ path, bytes: e.body }]),
71
+ ...untar(tar, e.next, nameForNext(e)),
72
+ ];
73
+ }
74
+
75
+ /** The e-print's files: a gzipped tar, or one gzipped `.tex` (named `main.tex`). */
76
+ export function unpack(
77
+ bytes: Uint8Array,
78
+ ): Verdict<{ files: readonly ArchiveFile[] }> {
79
+ if (bytes[0] !== 0x1f || bytes[1] !== 0x8b)
80
+ return { ok: false, reason: "no source: not gzip (PDF-only submission)" };
81
+ try {
82
+ const raw = gunzipSync(bytes);
83
+ if (latin1(raw.subarray(257, 262)) === "ustar")
84
+ return { ok: true, files: untar(raw) };
85
+ // A NUL byte is no TeX: an older tar with no ustar mark, which this reader does not take.
86
+ return raw.includes(0)
87
+ ? { ok: false, reason: "unreadable source: binary data, not a ustar tar" }
88
+ : { ok: true, files: [{ path: "main.tex", bytes: raw }] };
89
+ } catch (e) {
90
+ return {
91
+ ok: false,
92
+ reason: `unreadable source: ${String(e).slice(0, 80)}`,
93
+ };
94
+ }
95
+ }
96
+
97
+ const ext = (p: string): string => {
98
+ const m = /\.([^./]+)$/.exec(p);
99
+ return m === null ? "" : String(m[1]).toLowerCase();
100
+ };
101
+
102
+ const ReadmeSchema = z.object({
103
+ sources: z.array(
104
+ z.object({ usage: z.string().optional(), filename: z.string() }),
105
+ ),
106
+ });
107
+
108
+ /** JSON text as a value, or undefined when it is not JSON. */
109
+ export const jsonOf = (text: string): unknown => {
110
+ try {
111
+ return JSON.parse(text);
112
+ } catch {
113
+ return undefined;
114
+ }
115
+ };
116
+
117
+ /** The top-level file the archive's `00README.json` (or legacy `00README.XXX`) names, if any. */
118
+ export function toplevelOf(files: readonly ArchiveFile[]): string | null {
119
+ const json = files.find((f) => f.path === "00README.json");
120
+ if (json !== undefined) {
121
+ const readme = ReadmeSchema.safeParse(jsonOf(latin1(json.bytes)));
122
+ return readme.success
123
+ ? (readme.data.sources.find((s) => s.usage === "toplevel")?.filename ??
124
+ null)
125
+ : null;
126
+ }
127
+ const legacy = files.find((f) => /^00README/i.test(f.path));
128
+ return legacy === undefined
129
+ ? null
130
+ : (/(\S+\.tex)\s+toplevelfile/i.exec(latin1(legacy.bytes))?.[1] ?? null);
131
+ }
132
+
133
+ /** What a paper keeps of its archive, and every change made on the way. */
134
+ export type StagingPlan = Readonly<{
135
+ /** The main file's path in the archive. */
136
+ main: string;
137
+ mainText: string;
138
+ /** How many files could be the main one (a `\documentclass` and a `\begin{document}`). */
139
+ mainCandidates: number;
140
+ /** Every kept file at its staged path: the main one at `paper.tex`, the rest where they were. */
141
+ staged: readonly ArchiveFile[];
142
+ /** «a to b», for each renamed file. */
143
+ renames: readonly string[];
144
+ /** «a to b», for each `\input` of the main file that was rewritten to `paper`. */
145
+ edits: readonly string[];
146
+ /** Bytes of the staged text sources. */
147
+ size: number;
148
+ }>;
149
+
150
+ const escape = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
151
+
152
+ const isMain = (f: ArchiveFile): boolean => {
153
+ const t = stripComments(latin1(f.bytes));
154
+ return (
155
+ ext(f.path) === "tex" &&
156
+ t.includes("\\documentclass") &&
157
+ t.includes("\\begin{document}")
158
+ );
159
+ };
160
+
161
+ /** The one `00README` names, else one called main, paper or ms, else the largest candidate. */
162
+ const pickMain = (
163
+ mains: readonly ArchiveFile[],
164
+ named: string | null,
165
+ ): ArchiveFile | undefined =>
166
+ mains.find((f) => f.path === named) ??
167
+ mains.find((f) => /(^|\/)(main|paper|ms)\.tex$/.test(f.path)) ??
168
+ mains.toSorted((a, b) => b.bytes.length - a.bytes.length)[0];
169
+
170
+ /** Rewrites an `\input`/`\include` of the main file to `paper`, noting each «from to to». */
171
+ const pointAtPaper = (
172
+ f: ArchiveFile,
173
+ stem: string,
174
+ ): Readonly<{ bytes: Uint8Array; edits: readonly string[] }> => {
175
+ if (ext(f.path) !== "tex" || stem === "paper")
176
+ return { bytes: f.bytes, edits: [] };
177
+ const re = new RegExp(
178
+ `\\\\(input|include)\\{${escape(stem)}(\\.tex|\\.bbl)?\\}`,
179
+ "g",
180
+ );
181
+ const text = latin1(f.bytes);
182
+ const edits = [...text.matchAll(re)].map(
183
+ (m) => `${m[0]} to \\${String(m[1])}{paper${m[2] ?? ""}}`,
184
+ );
185
+ return {
186
+ bytes: Buffer.from(text.replace(re, "\\$1{paper$2}"), "latin1"),
187
+ edits,
188
+ };
189
+ };
190
+
191
+ /** A rename target the archive already holds: staging both would drop one of the two files. */
192
+ const takenTwice = (staged: readonly { path: string }[]): string | undefined =>
193
+ ["paper.tex", "paper.bbl"].find(
194
+ (p) => staged.filter((f) => f.path === p).length > 1,
195
+ );
196
+
197
+ /**
198
+ * Every text source of the archive, kept at its path from the root; the main file becomes
199
+ * `paper.tex`, the `.bbl` beside it with its stem `paper.bbl`, and an `\input` of the main file
200
+ * (rare: a wrapper) is rewritten to `paper`.
201
+ */
202
+ export function stagingPlan(
203
+ files: readonly ArchiveFile[],
204
+ ): Verdict<StagingPlan> {
205
+ const mains = files.filter(isMain);
206
+ const pick = pickMain(mains, toplevelOf(files));
207
+ if (pick === undefined) return { ok: false, reason: "no main .tex found" };
208
+ const stem = pick.path.replace(/\.tex$/, "");
209
+ const target = (p: string): string =>
210
+ p === pick.path ? "paper.tex" : p === `${stem}.bbl` ? "paper.bbl" : p;
211
+ const kept = files.filter((f) => TEXT_EXT.has(ext(f.path)));
212
+ const staged = kept.map((f) => ({
213
+ path: target(f.path),
214
+ ...pointAtPaper(f, stem),
215
+ }));
216
+ const taken = takenTwice(staged);
217
+ if (taken !== undefined)
218
+ return { ok: false, reason: `two files would be staged as ${taken}` };
219
+ return {
220
+ ok: true,
221
+ main: pick.path,
222
+ mainText: latin1(pick.bytes),
223
+ mainCandidates: mains.length,
224
+ staged: staged.map((f) => ({ path: f.path, bytes: f.bytes })),
225
+ renames: kept
226
+ .filter((f) => target(f.path) !== f.path)
227
+ .map((f) => `${f.path} to ${target(f.path)}`),
228
+ edits: staged.flatMap((x) => x.edits),
229
+ size: staged.reduce((n, f) => n + f.bytes.length, 0),
230
+ };
231
+ }
232
+
233
+ export const sha256 = (b: Uint8Array): string =>
234
+ createHash("sha256").update(b).digest("hex");
235
+
236
+ const INPUT = /\\(?:input|include)\s*\{([^}]+)\}/g;
237
+
238
+ /** The `.tex` files reached from `file`, depth first in source order, after those in `seen`. */
239
+ const reached = (
240
+ byPath: ReadonlyMap<string, Uint8Array>,
241
+ file: string,
242
+ seen: readonly string[],
243
+ ): readonly string[] =>
244
+ [
245
+ ...stripComments(latin1(byPath.get(file) ?? new Uint8Array())).matchAll(
246
+ INPUT,
247
+ ),
248
+ ].reduce<readonly string[]>((acc, m) => {
249
+ const n = String(m[1]).trim().replace(/^\.\//, "");
250
+ const hit = [n, `${n}.tex`].find((x) => ext(x) === "tex" && byPath.has(x));
251
+ return hit === undefined || acc.includes(hit)
252
+ ? acc
253
+ : reached(byPath, hit, [...acc, hit]);
254
+ }, seen);
255
+
256
+ /**
257
+ * `record-by-hand.json`, NOT TeX's answer: `paper.tex`, the class and style files at the root in
258
+ * name order, then each `\input`/`\include` reached from `paper.tex`, depth first in source order,
259
+ * every one hashed over the staged bytes. A staging without `paper.tex` records it as empty.
260
+ */
261
+ export function recordOf(staged: readonly ArchiveFile[]) {
262
+ const byPath = new Map(staged.map((f) => [f.path, f.bytes]));
263
+ const preamble = staged
264
+ .map((f) => f.path)
265
+ .filter((p) => !p.includes("/") && ["cls", "sty"].includes(ext(p)))
266
+ .toSorted();
267
+ const inputs = [
268
+ { path: "paper.tex", role: "body" },
269
+ ...preamble.map((path) => ({ path, role: "preamble" })),
270
+ ...reached(byPath, "paper.tex", ["paper.tex"])
271
+ .slice(1)
272
+ .map((path) => ({ path, role: "body" })),
273
+ ];
274
+ return {
275
+ schema: 1,
276
+ inputs,
277
+ written: [],
278
+ bibdata: [],
279
+ bibtex: { ran: false },
280
+ sha256: Object.fromEntries(
281
+ inputs.map((i) => [
282
+ i.path,
283
+ sha256(byPath.get(i.path) ?? new Uint8Array()),
284
+ ]),
285
+ ),
286
+ };
287
+ }
@@ -0,0 +1,329 @@
1
+ /**
2
+ * The walk over a fake world: which candidates are judged, in what order, why each is rejected,
3
+ * when an edition is full, and that quotas and caps count the whole manifest, earlier batches too.
4
+ */
5
+ import { describe, expect, test } from "vitest";
6
+ import {
7
+ collect,
8
+ targets,
9
+ type Counted,
10
+ type ProbeLine,
11
+ type Queries,
12
+ type Walk,
13
+ } from "./collect.ts";
14
+ import type { KeptPaper } from "./paper.ts";
15
+ import type { Slot } from "./rules.ts";
16
+ import { fakeGet, mainTex, tarGz, type Route } from "./testkit.ts";
17
+
18
+ const BY = "http://creativecommons.org/licenses/by/4.0/";
19
+ const slot: Slot = {
20
+ field: "nlp",
21
+ series: "ACL",
22
+ year: 2025,
23
+ cap: 1,
24
+ queries: ['co:"ACL 2025"'],
25
+ max_results: 50,
26
+ venue: "acl",
27
+ classSpec: "acl",
28
+ };
29
+ const queries = (over: Partial<Queries> = {}): Queries => ({
30
+ hardCap: 5,
31
+ maxPages: 1,
32
+ quotas: { nlp: 9 },
33
+ slots: [slot],
34
+ ...over,
35
+ });
36
+
37
+ const entry = (id: string, comment: string) =>
38
+ `<entry><id>http://arxiv.org/abs/${id}</id><updated>2025-05-01</updated><title>T</title><arxiv:comment>${comment}</arxiv:comment></entry>`;
39
+ const feed = (es: readonly (readonly [string, string])[]) =>
40
+ `<feed>${es.map(([id, c]) => entry(id, c)).join("")}</feed>`;
41
+ const ACCEPTED = "Accepted at ACL 2025";
42
+ const camera = tarGz([
43
+ {
44
+ name: "main.tex",
45
+ body: mainTex("Hi.", "\\documentclass{article}\\usepackage{acl}"),
46
+ },
47
+ ]);
48
+
49
+ /** A world where each id has a licence and an e-print, and the search lists `listed` in order. */
50
+ function world(
51
+ listed: readonly (readonly [string, string])[],
52
+ papers: Readonly<Record<string, Readonly<{ licence?: Route; src?: Route }>>>,
53
+ ) {
54
+ const routes: (readonly [string, Route])[] = [
55
+ ["api/query", feed(listed)],
56
+ ...Object.entries(papers).flatMap(([id, p]) => [
57
+ [`arXiv.org:${id}&`, p.licence ?? `<license>${BY}</license>`] as const,
58
+ [`src/${id}`, p.src ?? camera] as const,
59
+ ]),
60
+ ];
61
+ return fakeGet(routes);
62
+ }
63
+
64
+ async function walk(over: Partial<Walk> & Pick<Walk, "get">) {
65
+ const lines: ProbeLine[] = [];
66
+ const kept: KeptPaper[] = [];
67
+ const ends = await collect({
68
+ queries: queries(),
69
+ only: null,
70
+ entries: [],
71
+ otherIds: new Set(),
72
+ logged: [],
73
+ shipped: new Set(),
74
+ outOfTime: () => false,
75
+ emit: (line, paper) => {
76
+ lines.push(line);
77
+ if (paper !== undefined) kept.push(paper);
78
+ },
79
+ ...over,
80
+ });
81
+ return {
82
+ ends,
83
+ kept: kept.map((k) => k.id),
84
+ log: lines.map((l) => [l.rank, l.id, l.outcome, l.reason]),
85
+ };
86
+ }
87
+
88
+ describe("rules 1 to 4 in the fixed order", () => {
89
+ test("each candidate's first failing rule is its reason; the first passing are kept", async () => {
90
+ const big = mainTex(
91
+ "x".repeat(300_001),
92
+ "\\documentclass{article}\\usepackage{acl}",
93
+ );
94
+ const { get } = world(
95
+ [
96
+ ["p0", "Submitted to ACL 2025"],
97
+ ["p1", ACCEPTED],
98
+ ["p2", ACCEPTED],
99
+ ["p3", ACCEPTED],
100
+ ["p4", ACCEPTED],
101
+ ["p5", ACCEPTED],
102
+ ["p6", ACCEPTED],
103
+ ["p7", ACCEPTED],
104
+ ["p8", ACCEPTED],
105
+ ["p9", ACCEPTED],
106
+ ],
107
+ {
108
+ p1: { licence: { status: "503 after 4 attempts" } },
109
+ p2: { licence: "<record/>" },
110
+ p3: { src: { status: "403" } },
111
+ p4: { src: "%PDF" },
112
+ p5: { src: tarGz([{ name: "a.bib", body: "" }]) },
113
+ p6: {
114
+ src: tarGz([
115
+ { name: "m.tex", body: mainTex("", "\\documentclass{revtex4}") },
116
+ ]),
117
+ },
118
+ p7: { src: tarGz([{ name: "m.tex", body: big }]) },
119
+ p8: {},
120
+ p9: {},
121
+ },
122
+ );
123
+ const r = await walk({ get, queries: queries({ quotas: { nlp: 1 } }) });
124
+ // Guards: one reason per rule, in the order the rules run, and the walk stops when full.
125
+ expect(r.log).toEqual([
126
+ [1, "p0", "rejected", 'not accepted wording: comment says "Submitted"'],
127
+ [2, "p1", "rejected", "download failed: OAI 503 after 4 attempts"],
128
+ [3, "p2", "rejected", "licence arXiv default (none)"],
129
+ [4, "p3", "rejected", "download failed: src 403"],
130
+ [5, "p4", "rejected", "no source: not gzip (PDF-only submission)"],
131
+ [6, "p5", "rejected", "no main .tex found"],
132
+ [7, "p6", "rejected", "template: class revtex4, not article"],
133
+ [
134
+ 8,
135
+ "p7",
136
+ "rejected",
137
+ `>300KB of text sources (${String(big.length)} bytes)`,
138
+ ],
139
+ [9, "p8", "kept", "passes rules 1-4"],
140
+ ]);
141
+ // Guards: how the edition's walk ended, and where.
142
+ expect(r.ends).toEqual([
143
+ { slot: "nlp/ACL 2025", ended: "full", walkedTo: 9 },
144
+ ]);
145
+ });
146
+ });
147
+
148
+ describe("quotas and caps are totals over the manifest", () => {
149
+ const earlier: readonly Counted[] = [
150
+ { arxiv_id: "old1", field: "nlp", series: "ACL", year: 2024 },
151
+ { arxiv_id: "old2", field: "nlp", series: "ACL", year: 2024 },
152
+ ];
153
+ const three = () =>
154
+ world(
155
+ [
156
+ ["n1", ACCEPTED],
157
+ ["n2", ACCEPTED],
158
+ ["n3", ACCEPTED],
159
+ ],
160
+ { n1: {}, n2: {}, n3: {} },
161
+ );
162
+
163
+ test("a quota already met adds nothing and asks nothing", async () => {
164
+ const { get, asked } = three();
165
+ const r = await walk({
166
+ get,
167
+ entries: earlier,
168
+ queries: queries({ quotas: { nlp: 2 } }),
169
+ });
170
+ // Guards: two earlier nlp papers fill a quota of 2; no request is made.
171
+ expect([r.kept, r.ends, asked]).toEqual([[], [], []]);
172
+ });
173
+
174
+ test("a raised quota adds only the difference", async () => {
175
+ const { get } = three();
176
+ const r = await walk({
177
+ get,
178
+ entries: earlier,
179
+ queries: queries({ quotas: { nlp: 3 } }),
180
+ });
181
+ // Guards: quota 3 with 2 earlier papers keeps exactly one.
182
+ expect(r.kept).toEqual(["n1"]);
183
+ });
184
+
185
+ test("an edition holds at most its round's target, round-robin up to 5", async () => {
186
+ const { get } = three();
187
+ const fullEdition: readonly Counted[] = Array.from(
188
+ { length: 5 },
189
+ (_, i) => ({
190
+ arxiv_id: `e${String(i)}`,
191
+ series: "ACL",
192
+ year: 2025,
193
+ }),
194
+ );
195
+ const r = await walk({ get, entries: fullEdition });
196
+ // Guards: five papers of ACL 2025 already, so the edition takes no more.
197
+ expect([r.kept, r.ends]).toEqual([[], []]);
198
+ // Guards: the rounds: cap 1 then 2…5 for one slot, a slot at 5 only in round 0.
199
+ expect(
200
+ targets([slot, { ...slot, series: "EMNLP", cap: 5 }], 5).map(
201
+ ([s, t]) => `${s.series} ${String(t)}`,
202
+ ),
203
+ ).toEqual(["ACL 1", "EMNLP 5", "ACL 2", "ACL 3", "ACL 4", "ACL 5"]);
204
+ });
205
+ });
206
+
207
+ const logged = (
208
+ id: string,
209
+ reason: string,
210
+ outcome: "kept" | "rejected" = "rejected",
211
+ ): ProbeLine => ({
212
+ id,
213
+ field: "nlp",
214
+ series: "ACL",
215
+ year: 2025,
216
+ rank: 1,
217
+ query: "q",
218
+ source: "arxiv-comment",
219
+ acceptance: "arxiv-comment",
220
+ outcome,
221
+ reason,
222
+ });
223
+
224
+ describe("a run resumes, skips and stops", () => {
225
+ test("a judged candidate is not judged again, a failed download is; a taken id is skipped", async () => {
226
+ const { get } = world(
227
+ [
228
+ ["a1", ACCEPTED],
229
+ ["a2v2", ACCEPTED],
230
+ ["a3", ACCEPTED],
231
+ ["a4", ACCEPTED],
232
+ ["a5", ACCEPTED],
233
+ ],
234
+ { a1: {}, a2: {}, a3: {}, a4: {}, a5: {} },
235
+ );
236
+ const r = await walk({
237
+ get,
238
+ queries: queries({ quotas: { nlp: 2 }, hardCap: 1 }),
239
+ otherIds: new Set(["a2"]),
240
+ logged: [
241
+ logged("a1", "licence arXiv default (none)"),
242
+ logged("a3", "download failed: src 503"),
243
+ logged("a4", "passes rules 1-4", "kept"),
244
+ ],
245
+ });
246
+ // Guards: a1 and a4 stand as judged; a2 is a preprint already; a3's failed download is retried.
247
+ expect([r.log, r.ends]).toEqual([
248
+ [
249
+ [2, "a2v2", "rejected", "already in the corpora"],
250
+ [3, "a3", "kept", "passes rules 1-4"],
251
+ ],
252
+ [{ slot: "nlp/ACL 2025", ended: "full", walkedTo: 3 }],
253
+ ]);
254
+ });
255
+
256
+ test("the time box stops the whole run; an exhausted edition moves on", async () => {
257
+ const { get } = world([["t1", "no"]], {});
258
+ const two = queries({
259
+ slots: [slot, { ...slot, series: "EMNLP", venue: "emnlp" }],
260
+ });
261
+ const ticks = { n: 0 };
262
+ const r = await walk({ get, queries: two, outOfTime: () => ++ticks.n > 1 });
263
+ // Guards: the first edition ran out of candidates, the second hit the deadline; nothing after it.
264
+ expect(r.ends).toEqual([
265
+ { slot: "nlp/ACL 2025", ended: "exhausted", walkedTo: 1 },
266
+ { slot: "nlp/EMNLP 2025", ended: "time", walkedTo: 0 },
267
+ ]);
268
+ });
269
+
270
+ test("a search error ends the edition; --only and a field without a quota", async () => {
271
+ const failing = fakeGet([["api/query", { status: "503" }]]);
272
+ const r = await walk({ get: failing.get });
273
+ // Guards: the error is the edition's end.
274
+ expect(r.ends).toEqual([
275
+ {
276
+ slot: "nlp/ACL 2025",
277
+ ended: "search error",
278
+ walkedTo: 0,
279
+ error: 'co:"ACL 2025" page 0: 503',
280
+ },
281
+ ]);
282
+ const other = queries({ slots: [slot, { ...slot, field: "ml" }] });
283
+ // Guards: --only leaves the other field out, and a field with no quota (ml) walks nothing.
284
+ expect(
285
+ (await walk({ get: failing.get, queries: other, only: ["ml"] })).ends,
286
+ ).toEqual([]);
287
+ });
288
+ });
289
+
290
+ describe("from a Semantic Scholar listing", () => {
291
+ test("the listing's venue is rule 1, and an id arXiv does not describe is rejected", async () => {
292
+ const s2Slot: Slot = {
293
+ ...slot,
294
+ source: "semantic-scholar",
295
+ s2Venue: "ACL",
296
+ };
297
+ const listing = JSON.stringify({
298
+ data: [
299
+ { venue: "ACL", externalIds: { ArXiv: "s1" } },
300
+ { venue: "ACL Workshop", externalIds: { ArXiv: "s2" } },
301
+ { venue: "ACL", externalIds: { ArXiv: "s3" } },
302
+ ],
303
+ });
304
+ const { get } = fakeGet([
305
+ ["semanticscholar", listing],
306
+ [
307
+ "id_list=",
308
+ feed([
309
+ ["s2v1", ""],
310
+ ["s3v1", ""],
311
+ ]),
312
+ ],
313
+ ["arXiv.org:s3&", `<license>${BY}</license>`],
314
+ ["src/s3v1", camera],
315
+ ]);
316
+ const r = await walk({ get, queries: queries({ slots: [s2Slot] }) });
317
+ // Guards: each listed id's reason, and the kept one.
318
+ expect(r.log).toEqual([
319
+ [1, "s1", "rejected", "arXiv metadata missing for the listed id"],
320
+ [
321
+ 2,
322
+ "s2v1",
323
+ "rejected",
324
+ 'S2 venue string is not the main proceedings: "ACL Workshop"',
325
+ ],
326
+ [3, "s3v1", "kept", "passes rules 1-4"],
327
+ ]);
328
+ });
329
+ });