paperlint 20.1.1 → 20.1.2
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.
- package/.claude-plugin/plugin.json +1 -1
- package/.github/workflows/ci.yml +7 -0
- package/CLAUDE.md +2 -2
- package/CONTRIBUTING.md +2 -2
- package/{action.harness.mjs → action.test.mjs} +147 -138
- package/dist/eslint-rules/papers.js +1 -1
- package/dist/latex-log.d.ts +1 -1
- package/dist/latex-log.js +1 -1
- package/dist/latex-loop.d.ts +1 -1
- package/dist/latex-loop.js +1 -1
- package/dist/lib/paper-config.d.ts +3 -3
- package/dist/lib/paper-config.js +3 -3
- package/docs/e2e.md +9 -9
- package/docs/testing.md +3 -4
- package/eslint-rules/{install-path-literals.harness.mjs → install-path-literals.test.mjs} +14 -13
- package/eslint-rules/{latex-language.harness.mjs → latex-language-rules.test.mjs} +61 -51
- package/eslint-rules/{paper-stages.harness.mjs → paper-stages-rule.test.mjs} +66 -69
- package/eslint-rules/{papers.harness.mjs → papers.test.mjs} +41 -30
- package/eslint-rules/papers.ts +1 -1
- package/eslint-rules/{pdf-last-page-balance.harness.mjs → pdf-last-page-balance.test.mjs} +27 -15
- package/eslint-rules/{temp-root-realpath.harness.mjs → temp-root-realpath.test.mjs} +24 -24
- package/eslint-rules/{tex-build.harness.mjs → tex-build.test.mjs} +292 -271
- package/eslint.config.mjs +15 -2
- package/fixtures/pdf-facts/README.md +1 -1
- package/fixtures/render-paper/build-clean.sh +1 -1
- package/fixtures/toolchain-mirror/install-tl +1 -1
- package/lib/{agent-cli-version.harness.mjs → agent-cli-version.test.mjs} +17 -18
- package/lib/{paper-config.harness.mjs → paper-config.test.mjs} +21 -20
- package/lib/paper-config.ts +3 -3
- package/lib/{skill-trigger-cases.harness.mjs → skill-trigger-cases-carrier.test.mjs} +78 -115
- package/package.json +3 -3
- package/presets/acm-acmsmall.jsonc +1 -1
- package/scripts/check-workflow.test.ts +368 -0
- package/scripts/check.ts +2 -2
- package/scripts/eslint-file-length.mjs +9 -9
- package/scripts/eslint-report-guard.mjs +1 -1
- package/scripts/eslint-report-guard.test.mjs +1 -1
- package/scripts/harness-api.test.ts +7 -46
- package/scripts/{rules-see-files.harness.mjs → rules-see-files-rule.test.mjs} +10 -6
- package/scripts/rules-see-files.mjs +1 -1
- package/skills/paper-pipeline/{paper-pipeline.harness.mjs → paper-pipeline.test.mjs} +45 -46
- package/skills/paper-pipeline/scripts/{consumer.harness.mjs → consumer-paths.test.mjs} +66 -59
- package/skills/paper-pipeline/scripts/consumer.mjs +3 -3
- package/skills/paper-pipeline/scripts/{extract-ref-facts.harness.mjs → extract-ref-facts-cli.test.mjs} +29 -31
- package/skills/paper-pipeline/scripts/fixtures/real-bib/refs.bib +1 -1
- package/skills/paper-pipeline/scripts/{generated-code.harness.mjs → generated-code-fixtures.test.mjs} +39 -46
- package/skills/render-paper/{extract-pdf-facts.harness.ts → extract-pdf-facts.test.ts} +20 -13
- package/skills/render-paper/{render-paper.harness.mjs → render-paper.test.mjs} +41 -40
- package/src/adapters/pdfjs/fill.test.ts +1 -1
- package/src/{build-engine.harness.mjs → build-engine-prepare.test.mjs} +98 -81
- package/src/{build.harness.mjs → build-fake-tex.test.mjs} +61 -28
- package/src/{cli.harness.mjs → cli-e2e.test.mjs} +108 -102
- package/src/cli.test.ts +1 -1
- package/src/{doctor.harness.mjs → doctor-install.test.mjs} +28 -29
- package/src/{engine.harness.mjs → engine.test.mjs} +120 -106
- package/src/facts-file.test.ts +1 -1
- package/src/{hooks-settings.harness.ts → hooks-settings.test.ts} +161 -146
- package/src/latex-log.test.ts +395 -0
- package/src/latex-log.ts +1 -1
- package/src/latex-loop.test.ts +553 -0
- package/src/latex-loop.ts +1 -1
- package/src/{link-skills.harness.ts → link-skills-fs.test.ts} +26 -26
- package/src/{new-paper.harness.mjs → new-paper-scaffold.test.mjs} +31 -19
- package/src/{pdf-facts.harness.ts → pdf-facts-tables.test.ts} +28 -22
- package/src/{pdf-geometry.harness.ts → pdf-geometry.test.ts} +93 -75
- package/src/{rules-config.harness.ts → rules-config.test.ts} +41 -31
- package/src/{structure.harness.ts → structure.test.ts} +12 -10
- package/src/{tex-requirements.harness.ts → tex-requirements-tables.test.ts} +106 -85
- package/src/{toolchain.harness.mjs → toolchain-mirror.test.mjs} +204 -186
- package/scripts/check.harness.ts +0 -343
- package/scripts/harness-api.frozen.json +0 -41
- package/src/latex-log.harness.ts +0 -382
- package/src/latex-loop.harness.ts +0 -515
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `latex-loop.ts` — three tables, in order:
|
|
3
|
+
* 1. `nextStep` over a `State`: one row per question, plus the cap;
|
|
4
|
+
* 2. `summarize` over histories: one row per field;
|
|
5
|
+
* 3. the two composed, over the histories the loop really sees — the behaviour the build has.
|
|
6
|
+
* A defect in `nextStep` fails in table 1, one in `summarize` in table 2, before table 3 runs.
|
|
7
|
+
*
|
|
8
|
+
* The decision is pure, so none of this needs TeX. The real-pdflatex half lives in
|
|
9
|
+
* `test/e2e/tex/build.e2e.ts`.
|
|
10
|
+
*/
|
|
11
|
+
import { expect, it, vi } from "vitest";
|
|
12
|
+
import type {
|
|
13
|
+
BibInput,
|
|
14
|
+
Hashes,
|
|
15
|
+
LogFailure,
|
|
16
|
+
Observation,
|
|
17
|
+
State,
|
|
18
|
+
Step,
|
|
19
|
+
} from "./latex-loop.ts";
|
|
20
|
+
|
|
21
|
+
// Several tests here run real ESLint, spawn processes or walk the repository.
|
|
22
|
+
vi.setConfig({ testTimeout: 120_000 });
|
|
23
|
+
|
|
24
|
+
const { nextStep, summarize, changedFiles, MAX_PASSES } =
|
|
25
|
+
await import("./latex-loop.ts");
|
|
26
|
+
|
|
27
|
+
/** One soft assertion: a failed check does not stop the checks after it in the same test. */
|
|
28
|
+
const check = (label: string, cond: unknown, detail?: unknown): void => {
|
|
29
|
+
const shown = typeof detail === "string" ? detail : JSON.stringify(detail);
|
|
30
|
+
expect
|
|
31
|
+
.soft(cond, detail === undefined ? label : `${label}\n${shown}`)
|
|
32
|
+
.toBe(true);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// ── builders ────────────────────────────────────────────────────────────────────────────
|
|
36
|
+
type LatexPass = Extract<Observation, { step: "latex" }>;
|
|
37
|
+
type BibtexPass = Extract<Observation, { step: "bibtex" }>;
|
|
38
|
+
const H = (
|
|
39
|
+
aux: string | null,
|
|
40
|
+
toc: string | null = null,
|
|
41
|
+
out: string | null = null,
|
|
42
|
+
bbl: string | null = null,
|
|
43
|
+
): Hashes => ({ aux, toc, out, bbl });
|
|
44
|
+
const NO_BIB: BibInput = { kind: "none" };
|
|
45
|
+
const bib = (
|
|
46
|
+
citations: readonly string[],
|
|
47
|
+
bibHash: string | null = "b1",
|
|
48
|
+
): BibInput => ({
|
|
49
|
+
kind: "needed",
|
|
50
|
+
citations,
|
|
51
|
+
databases: ["refs"],
|
|
52
|
+
style: "plain",
|
|
53
|
+
bibHash,
|
|
54
|
+
});
|
|
55
|
+
const latex = (o: Partial<LatexPass> = {}): LatexPass => ({
|
|
56
|
+
step: "latex",
|
|
57
|
+
final: false,
|
|
58
|
+
exitCode: 0,
|
|
59
|
+
before: H("a1"),
|
|
60
|
+
after: H("a1"),
|
|
61
|
+
markers: [],
|
|
62
|
+
bib: NO_BIB,
|
|
63
|
+
errorLines: [],
|
|
64
|
+
fls: null,
|
|
65
|
+
failing: [],
|
|
66
|
+
...o,
|
|
67
|
+
});
|
|
68
|
+
const bibtex = (o: Partial<BibtexPass> = {}): BibtexPass => ({
|
|
69
|
+
step: "bibtex",
|
|
70
|
+
exitCode: 0,
|
|
71
|
+
before: H("a1"),
|
|
72
|
+
after: H("a1", null, null, "bbl1"),
|
|
73
|
+
bib: bib(["k"]),
|
|
74
|
+
errorLines: [],
|
|
75
|
+
...o,
|
|
76
|
+
});
|
|
77
|
+
/** What latex-log reports for the end-of-run "There were undefined references." */
|
|
78
|
+
const undefRefs: LogFailure = {
|
|
79
|
+
id: "undefined-references",
|
|
80
|
+
reason: "a \\ref names a label no pass defined",
|
|
81
|
+
quotes: [
|
|
82
|
+
{ text: "LaTeX Warning: There were undefined references.", times: 1 },
|
|
83
|
+
],
|
|
84
|
+
};
|
|
85
|
+
const kind = (s: Step) =>
|
|
86
|
+
s.kind === "latex" ? `latex${s.final ? "-final" : ""}` : s.kind;
|
|
87
|
+
|
|
88
|
+
// ── 1. nextStep over a State ─────────────────────────────────────────────────────────────
|
|
89
|
+
it("1. nextStep over a State", () => {
|
|
90
|
+
const S = (o: Partial<State> = {}): State => ({
|
|
91
|
+
failed: null,
|
|
92
|
+
bibOutdated: false,
|
|
93
|
+
unsettled: [],
|
|
94
|
+
latexPasses: 1,
|
|
95
|
+
finalDone: false,
|
|
96
|
+
...o,
|
|
97
|
+
});
|
|
98
|
+
const exitFail: NonNullable<State["failed"]> = {
|
|
99
|
+
step: "bibtex",
|
|
100
|
+
cause: { kind: "exit", code: 2 },
|
|
101
|
+
lines: ["I couldn't open database file nope.bib"],
|
|
102
|
+
};
|
|
103
|
+
const STATES: [string, State, string][] = [
|
|
104
|
+
// Guards: the only moment paper-guards can speak — its error comes on the final pass, so testing
|
|
105
|
+
// 'final' before 'exit code' would ship the undefined reference green.
|
|
106
|
+
[
|
|
107
|
+
"Q1 the last program failed — fail, whatever else holds",
|
|
108
|
+
S({
|
|
109
|
+
failed: exitFail,
|
|
110
|
+
bibOutdated: true,
|
|
111
|
+
unsettled: ["paper.aux"],
|
|
112
|
+
finalDone: true,
|
|
113
|
+
}),
|
|
114
|
+
"fail",
|
|
115
|
+
],
|
|
116
|
+
["the final pass ran clean — done", S({ finalDone: true }), "done"],
|
|
117
|
+
// Guards: running bibtex at all — the first pass writes the \citation list; without this question
|
|
118
|
+
// the loop reruns pdflatex, never produces a .bbl, and every \cite stays undefined.
|
|
119
|
+
[
|
|
120
|
+
"Q2 the bibliography input moved since bibtex ran — bibtex, before any rerun",
|
|
121
|
+
S({ bibOutdated: true, unsettled: ["paper.aux"] }),
|
|
122
|
+
"bibtex",
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
"Q3 a tracked file moved or the log asked — another plain pass",
|
|
126
|
+
S({ unsettled: ["paper.aux"] }),
|
|
127
|
+
"latex",
|
|
128
|
+
],
|
|
129
|
+
// Guards: the stop on a document that never settles — without it the loop runs forever; with a
|
|
130
|
+
// silent cap it ships a PDF with stale cross-references.
|
|
131
|
+
[
|
|
132
|
+
`Q3 cap: ${String(MAX_PASSES)} passes and still unsettled — fail`,
|
|
133
|
+
S({ unsettled: ["paper.aux"], latexPasses: MAX_PASSES }),
|
|
134
|
+
"fail",
|
|
135
|
+
],
|
|
136
|
+
// Guards: the \finalpass run that arms paper-guards.tex — skipping it saves one pdflatex run and
|
|
137
|
+
// turns every undefined \ref and \cite back into a green build.
|
|
138
|
+
[
|
|
139
|
+
"Q4 nothing unsettled — the FINAL pass (even at the cap)",
|
|
140
|
+
S({ latexPasses: MAX_PASSES }),
|
|
141
|
+
"latex-final",
|
|
142
|
+
],
|
|
143
|
+
];
|
|
144
|
+
for (const [label, state, expected] of STATES) {
|
|
145
|
+
const got = kind(nextStep(state));
|
|
146
|
+
check(`${label} (expected ${expected}, got ${got})`, got === expected);
|
|
147
|
+
}
|
|
148
|
+
const q1 = nextStep(S({ failed: exitFail }));
|
|
149
|
+
check(
|
|
150
|
+
"Q1 passes the failure through: the step, the cause and the lines verbatim",
|
|
151
|
+
q1.kind === "fail" &&
|
|
152
|
+
q1.step === "bibtex" &&
|
|
153
|
+
q1.cause.kind === "exit" &&
|
|
154
|
+
q1.cause.code === 2 &&
|
|
155
|
+
q1.lines === exitFail.lines,
|
|
156
|
+
);
|
|
157
|
+
const q3cap = nextStep(
|
|
158
|
+
S({ unsettled: ["paper.aux", "labels-changed"], latexPasses: MAX_PASSES }),
|
|
159
|
+
);
|
|
160
|
+
check(
|
|
161
|
+
"the cap's failure is no-convergence and NAMES what stayed unsettled",
|
|
162
|
+
q3cap.kind === "fail" &&
|
|
163
|
+
q3cap.cause.kind === "no-convergence" &&
|
|
164
|
+
(q3cap.lines[0] ?? "").includes("paper.aux, labels-changed"),
|
|
165
|
+
);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// ── 2. summarize over histories ─────────────────────────────────────────────────────────
|
|
169
|
+
it("2. summarize over histories", () => {
|
|
170
|
+
const sum = summarize;
|
|
171
|
+
check(
|
|
172
|
+
"summarize: nothing ran — paper.aux is unsettled (no pass has written it), nothing else holds",
|
|
173
|
+
JSON.stringify(sum([])) ===
|
|
174
|
+
JSON.stringify({
|
|
175
|
+
failed: null,
|
|
176
|
+
bibOutdated: false,
|
|
177
|
+
unsettled: ["paper.aux"],
|
|
178
|
+
latexPasses: 0,
|
|
179
|
+
finalDone: false,
|
|
180
|
+
}),
|
|
181
|
+
);
|
|
182
|
+
// Guards: failing on a failed pass — -halt-on-error stops pdflatex at the first error, and a loop
|
|
183
|
+
// reading the half-written aux as progress would rerun it or call it converged.
|
|
184
|
+
check(
|
|
185
|
+
"summarize: a non-zero exit is `failed`, naming the step, the code and the log excerpt",
|
|
186
|
+
(() => {
|
|
187
|
+
const f = sum([latex({ exitCode: 1, errorLines: ["l.4 \\foo"] })]).failed;
|
|
188
|
+
return (
|
|
189
|
+
f?.step === "latex" &&
|
|
190
|
+
f.cause.kind === "exit" &&
|
|
191
|
+
f.cause.code === 1 &&
|
|
192
|
+
f.lines[0] === "l.4 \\foo"
|
|
193
|
+
);
|
|
194
|
+
})(),
|
|
195
|
+
);
|
|
196
|
+
check(
|
|
197
|
+
"summarize: a FINAL pass that exited non-zero is failed, not finalDone-and-clean",
|
|
198
|
+
sum([latex({ final: true, exitCode: 1 })]).failed !== null,
|
|
199
|
+
);
|
|
200
|
+
check(
|
|
201
|
+
"summarize: bibOutdated when the aux names a bibliography bibtex has not run on",
|
|
202
|
+
sum([latex({ bib: bib(["k"]) })]).bibOutdated,
|
|
203
|
+
);
|
|
204
|
+
check(
|
|
205
|
+
"summarize: bibOutdated is false once bibtex ran on exactly that input",
|
|
206
|
+
!sum([latex({ bib: bib(["k"]) }), bibtex()]).bibOutdated,
|
|
207
|
+
);
|
|
208
|
+
// Guards: the .bib hash as an input — a corrected author or year in refs.bib would keep the old
|
|
209
|
+
// .bbl, and the PDF would print the entry as it was before the fix.
|
|
210
|
+
check(
|
|
211
|
+
"summarize: the .bib content changed since bibtex ran — bibOutdated",
|
|
212
|
+
sum([
|
|
213
|
+
latex({ bib: bib(["k"]) }),
|
|
214
|
+
bibtex(),
|
|
215
|
+
latex({ bib: bib(["k"], "b2") }),
|
|
216
|
+
]).bibOutdated,
|
|
217
|
+
);
|
|
218
|
+
check(
|
|
219
|
+
"summarize: no bibliography at all — never bibOutdated",
|
|
220
|
+
!sum([latex()]).bibOutdated,
|
|
221
|
+
);
|
|
222
|
+
check(
|
|
223
|
+
"summarize: unsettled names every tracked file the last pass changed",
|
|
224
|
+
JSON.stringify(
|
|
225
|
+
sum([latex({ before: H("a1", "t1"), after: H("a2", "t2") })]).unsettled,
|
|
226
|
+
) === JSON.stringify(["paper.aux", "paper.toc"]),
|
|
227
|
+
);
|
|
228
|
+
// Guards: the log's own request for another pass — a package that keeps state outside the tracked
|
|
229
|
+
// files (longtable widths, hyperref outlines) speaks only through this line.
|
|
230
|
+
check(
|
|
231
|
+
"summarize: marker: Rerun to get — unsettled names the rerun marker even with identical files",
|
|
232
|
+
JSON.stringify(sum([latex({ markers: ["rerun-requested"] })]).unsettled) ===
|
|
233
|
+
JSON.stringify(["rerun-requested"]),
|
|
234
|
+
);
|
|
235
|
+
// Guards: 'not settled yet' vs 'this key does not exist' — on stable files an undefined reference
|
|
236
|
+
// never resolves, so rerunning for it burns the cap and reports no-convergence for a typo.
|
|
237
|
+
check(
|
|
238
|
+
"summarize: undefined references ALONE leave nothing unsettled — on stable files they are a real bad key",
|
|
239
|
+
sum([latex({ failing: [undefRefs] })]).unsettled.length === 0,
|
|
240
|
+
);
|
|
241
|
+
check(
|
|
242
|
+
"summarize: bibtex that rewrote the .bbl leaves paper.bbl unsettled",
|
|
243
|
+
JSON.stringify(sum([latex({ bib: bib(["k"]) }), bibtex()]).unsettled) ===
|
|
244
|
+
JSON.stringify(["paper.bbl"]),
|
|
245
|
+
);
|
|
246
|
+
// Guards: reading bibtex's effect from the .bbl — a byte-identical .bbl changes nothing the next
|
|
247
|
+
// pass would read.
|
|
248
|
+
check(
|
|
249
|
+
"summarize: bibtex left the .bbl byte-identical — the pass before it answers",
|
|
250
|
+
sum([latex({ bib: bib(["k"]) }), bibtex({ after: H("a1") })]).unsettled
|
|
251
|
+
.length === 0,
|
|
252
|
+
);
|
|
253
|
+
check(
|
|
254
|
+
"summarize: latexPasses counts the non-final pdflatex passes only",
|
|
255
|
+
sum([latex(), bibtex(), latex(), latex({ final: true })]).latexPasses === 2,
|
|
256
|
+
);
|
|
257
|
+
check(
|
|
258
|
+
"summarize: finalDone after a clean final pass",
|
|
259
|
+
sum([latex(), latex({ final: true })]).finalDone,
|
|
260
|
+
);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// ── 3. composed: nextStep(summarize(history)) ───────────────────────────────────────────
|
|
264
|
+
const step = (history: readonly Observation[]) => nextStep(summarize(history));
|
|
265
|
+
|
|
266
|
+
// ── the histories the loop sees ───────────────────────────────────────────────────────────────────────────
|
|
267
|
+
it("3. composed: nextStep(summarize(history)) over the histories the loop sees", () => {
|
|
268
|
+
const TABLE: [string, Observation[], string][] = [
|
|
269
|
+
["nothing ran yet — the first step is a plain pass", [], "latex"],
|
|
270
|
+
[
|
|
271
|
+
"a pass that created the aux — rerun",
|
|
272
|
+
[latex({ before: H(null), after: H("a1") })],
|
|
273
|
+
"latex",
|
|
274
|
+
],
|
|
275
|
+
[
|
|
276
|
+
"a pass whose tracked files did not change and whose log asks for nothing — converged, so the FINAL pass",
|
|
277
|
+
[latex({ before: H(null), after: H("a1") }), latex()],
|
|
278
|
+
"latex-final",
|
|
279
|
+
],
|
|
280
|
+
[
|
|
281
|
+
"the final pass exited 0 — done",
|
|
282
|
+
[latex(), latex({ final: true })],
|
|
283
|
+
"done",
|
|
284
|
+
],
|
|
285
|
+
[
|
|
286
|
+
"a .toc change alone is a rerun",
|
|
287
|
+
[latex({ before: H("a1", "t1"), after: H("a1", "t2") })],
|
|
288
|
+
"latex",
|
|
289
|
+
],
|
|
290
|
+
[
|
|
291
|
+
"a .out change alone is a rerun (hyperref bookmarks)",
|
|
292
|
+
[latex({ before: H("a1", null, "o1"), after: H("a1", null, "o2") })],
|
|
293
|
+
"latex",
|
|
294
|
+
],
|
|
295
|
+
[
|
|
296
|
+
"marker: Rerun to get … — rerun even with identical files",
|
|
297
|
+
[latex({ markers: ["rerun-requested"] })],
|
|
298
|
+
"latex",
|
|
299
|
+
],
|
|
300
|
+
[
|
|
301
|
+
"marker: Label(s) may have changed — rerun",
|
|
302
|
+
[latex({ markers: ["labels-changed"] })],
|
|
303
|
+
"latex",
|
|
304
|
+
],
|
|
305
|
+
[
|
|
306
|
+
"marker: rerunfilecheck — rerun",
|
|
307
|
+
[latex({ markers: ["rerunfilecheck"] })],
|
|
308
|
+
"latex",
|
|
309
|
+
],
|
|
310
|
+
[
|
|
311
|
+
"undefined references ALONE do not request a rerun — on stable files they are a real bad key",
|
|
312
|
+
[latex({ failing: [undefRefs] })],
|
|
313
|
+
"latex-final",
|
|
314
|
+
],
|
|
315
|
+
[
|
|
316
|
+
"the aux names a bibliography bibtex has not run on — bibtex",
|
|
317
|
+
[latex({ before: H(null), after: H("a1"), bib: bib(["k"]) })],
|
|
318
|
+
"bibtex",
|
|
319
|
+
],
|
|
320
|
+
[
|
|
321
|
+
"after bibtex changed the .bbl — rerun",
|
|
322
|
+
[latex({ bib: bib(["k"]) }), bibtex()],
|
|
323
|
+
"latex",
|
|
324
|
+
],
|
|
325
|
+
[
|
|
326
|
+
"bibtex ran on exactly this input — not again",
|
|
327
|
+
[
|
|
328
|
+
latex({ bib: bib(["k"]) }),
|
|
329
|
+
bibtex(),
|
|
330
|
+
latex({
|
|
331
|
+
before: H("a1", null, null, "bbl1"),
|
|
332
|
+
after: H("a1", null, null, "bbl1"),
|
|
333
|
+
bib: bib(["k"]),
|
|
334
|
+
}),
|
|
335
|
+
],
|
|
336
|
+
"latex-final",
|
|
337
|
+
],
|
|
338
|
+
[
|
|
339
|
+
"the \\citation set changed since bibtex ran — bibtex again",
|
|
340
|
+
[latex({ bib: bib(["k"]) }), bibtex(), latex({ bib: bib(["k", "k2"]) })],
|
|
341
|
+
"bibtex",
|
|
342
|
+
],
|
|
343
|
+
[
|
|
344
|
+
"the .bib content changed since bibtex ran — bibtex again",
|
|
345
|
+
[latex({ bib: bib(["k"]) }), bibtex(), latex({ bib: bib(["k"], "b2") })],
|
|
346
|
+
"bibtex",
|
|
347
|
+
],
|
|
348
|
+
[
|
|
349
|
+
"bibtex left the .bbl byte-identical — the verdict of the pass before it stands (converged)",
|
|
350
|
+
[
|
|
351
|
+
latex({ bib: bib(["k"]) }),
|
|
352
|
+
bibtex({
|
|
353
|
+
before: H("a1", null, null, "bbl1"),
|
|
354
|
+
after: H("a1", null, null, "bbl1"),
|
|
355
|
+
}),
|
|
356
|
+
],
|
|
357
|
+
"latex-final",
|
|
358
|
+
],
|
|
359
|
+
[
|
|
360
|
+
"a pdflatex pass exited non-zero — fail",
|
|
361
|
+
[
|
|
362
|
+
latex({
|
|
363
|
+
exitCode: 1,
|
|
364
|
+
errorLines: [
|
|
365
|
+
"./paper.tex:4: Undefined control sequence.",
|
|
366
|
+
"l.4 \\foo",
|
|
367
|
+
],
|
|
368
|
+
}),
|
|
369
|
+
],
|
|
370
|
+
"fail",
|
|
371
|
+
],
|
|
372
|
+
[
|
|
373
|
+
"bibtex exited non-zero — fail",
|
|
374
|
+
[
|
|
375
|
+
latex({ bib: bib(["k"]) }),
|
|
376
|
+
bibtex({
|
|
377
|
+
exitCode: 2,
|
|
378
|
+
errorLines: ["I couldn't open database file nope.bib"],
|
|
379
|
+
}),
|
|
380
|
+
],
|
|
381
|
+
"fail",
|
|
382
|
+
],
|
|
383
|
+
[
|
|
384
|
+
"the FINAL pass exited non-zero (a paper-guards error) — fail, not done",
|
|
385
|
+
[latex(), latex({ final: true, exitCode: 1 })],
|
|
386
|
+
"fail",
|
|
387
|
+
],
|
|
388
|
+
];
|
|
389
|
+
|
|
390
|
+
for (const [label, history, expected] of TABLE) {
|
|
391
|
+
const got = kind(step(history));
|
|
392
|
+
check(`${label} (expected ${expected}, got ${got})`, got === expected);
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
// ── what a fail carries ─────────────────────────────────────────────────────────────────
|
|
397
|
+
it("what a fail carries", () => {
|
|
398
|
+
const latexFail = step([
|
|
399
|
+
latex({
|
|
400
|
+
exitCode: 1,
|
|
401
|
+
errorLines: ["./paper.tex:4: Undefined control sequence.", "l.4 \\foo"],
|
|
402
|
+
}),
|
|
403
|
+
]);
|
|
404
|
+
check(
|
|
405
|
+
"a latex fail names the step, the exit code and the log excerpt verbatim",
|
|
406
|
+
latexFail.kind === "fail" &&
|
|
407
|
+
latexFail.step === "latex" &&
|
|
408
|
+
latexFail.cause.kind === "exit" &&
|
|
409
|
+
latexFail.cause.code === 1 &&
|
|
410
|
+
latexFail.lines[1] === "l.4 \\foo",
|
|
411
|
+
);
|
|
412
|
+
const bibFail = step([
|
|
413
|
+
latex({ bib: bib(["k"]) }),
|
|
414
|
+
bibtex({
|
|
415
|
+
exitCode: 2,
|
|
416
|
+
errorLines: ["I couldn't open database file nope.bib"],
|
|
417
|
+
}),
|
|
418
|
+
]);
|
|
419
|
+
check(
|
|
420
|
+
"a bibtex fail names BIBTEX, not latex",
|
|
421
|
+
bibFail.kind === "fail" &&
|
|
422
|
+
bibFail.step === "bibtex" &&
|
|
423
|
+
bibFail.cause.kind === "exit" &&
|
|
424
|
+
bibFail.cause.code === 2,
|
|
425
|
+
);
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
// ── the cap ─────────────────────────────────────────────────────────────────────────────
|
|
429
|
+
it("the cap", () => {
|
|
430
|
+
const moving = (i: number) =>
|
|
431
|
+
latex({ before: H(`a${String(i)}`), after: H(`a${String(i + 1)}`) });
|
|
432
|
+
const underCap = Array.from({ length: MAX_PASSES - 1 }, (_, i) => moving(i));
|
|
433
|
+
check(
|
|
434
|
+
`the cap is ${String(MAX_PASSES)} and it is not hit early: after ${String(MAX_PASSES - 1)} moving passes, one more`,
|
|
435
|
+
MAX_PASSES === 5 && kind(step(underCap)) === "latex",
|
|
436
|
+
);
|
|
437
|
+
const atCap = Array.from({ length: MAX_PASSES }, (_, i) => moving(i));
|
|
438
|
+
const capped = step(atCap);
|
|
439
|
+
check(
|
|
440
|
+
"🔴 after the cap, a still-moving aux is a FAIL — no convergence — not a PDF with stale references",
|
|
441
|
+
capped.kind === "fail" && capped.cause.kind === "no-convergence",
|
|
442
|
+
);
|
|
443
|
+
check(
|
|
444
|
+
"the non-convergence failure NAMES the file that kept changing",
|
|
445
|
+
capped.kind === "fail" && (capped.lines[0] ?? "").includes("paper.aux"),
|
|
446
|
+
);
|
|
447
|
+
const cappedMarker = step(
|
|
448
|
+
Array.from({ length: MAX_PASSES }, () =>
|
|
449
|
+
latex({ markers: ["labels-changed"] }),
|
|
450
|
+
),
|
|
451
|
+
);
|
|
452
|
+
check(
|
|
453
|
+
"a log that keeps asking for a rerun hits the same cap, and names the marker",
|
|
454
|
+
cappedMarker.kind === "fail" &&
|
|
455
|
+
(cappedMarker.lines[0] ?? "").includes("labels-changed"),
|
|
456
|
+
);
|
|
457
|
+
const convergedAtCap = [...atCap.slice(0, -1), latex()];
|
|
458
|
+
check(
|
|
459
|
+
"reaching the cap WITH a converged last pass is not a failure — the final pass still runs",
|
|
460
|
+
kind(step(convergedAtCap)) === "latex-final",
|
|
461
|
+
);
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// ── a warning on the list of failing ones (latex-log's FAILING_WARNINGS) fails the build ──
|
|
465
|
+
it("a warning on the list of failing ones (latex-log's FAILING_WARNINGS) fails the build", () => {
|
|
466
|
+
const lost: LogFailure = {
|
|
467
|
+
id: "lost-character",
|
|
468
|
+
reason: "pdflatex dropped a character its font has no glyph for",
|
|
469
|
+
quotes: [
|
|
470
|
+
{
|
|
471
|
+
text: "Missing character: There is no \u207b in font cmr10!",
|
|
472
|
+
times: 1,
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
text: "Missing character: There is no \ufffd in font cmtt10!",
|
|
476
|
+
times: 3,
|
|
477
|
+
},
|
|
478
|
+
],
|
|
479
|
+
};
|
|
480
|
+
const lostFinal = step([latex(), latex({ final: true, failing: [lost] })]);
|
|
481
|
+
check(
|
|
482
|
+
"🔴 a failing warning in the FINAL log is a fail: latex, the ids, the reason and every quoted line",
|
|
483
|
+
lostFinal.kind === "fail" &&
|
|
484
|
+
lostFinal.step === "latex" &&
|
|
485
|
+
JSON.stringify(lostFinal.cause) ===
|
|
486
|
+
JSON.stringify({ kind: "log-warnings", ids: ["lost-character"] }) &&
|
|
487
|
+
JSON.stringify(lostFinal.lines) ===
|
|
488
|
+
JSON.stringify([
|
|
489
|
+
"lost-character — pdflatex dropped a character its font has no glyph for:",
|
|
490
|
+
" Missing character: There is no \u207b in font cmr10!",
|
|
491
|
+
" Missing character: There is no \ufffd in font cmtt10! (3 times)",
|
|
492
|
+
]),
|
|
493
|
+
lostFinal,
|
|
494
|
+
);
|
|
495
|
+
check(
|
|
496
|
+
"a failing warning in a NON-final log decides nothing: the loop goes on to the final pass",
|
|
497
|
+
kind(step([latex({ failing: [lost] })])) === "latex-final",
|
|
498
|
+
);
|
|
499
|
+
const lostAndExit = step([
|
|
500
|
+
latex(),
|
|
501
|
+
latex({
|
|
502
|
+
final: true,
|
|
503
|
+
exitCode: 1,
|
|
504
|
+
errorLines: ["! Emergency stop."],
|
|
505
|
+
failing: [lost],
|
|
506
|
+
}),
|
|
507
|
+
]);
|
|
508
|
+
check(
|
|
509
|
+
"a final pass that also exited non-zero fails on its exit code, quoting the error",
|
|
510
|
+
lostAndExit.kind === "fail" &&
|
|
511
|
+
lostAndExit.cause.kind === "exit" &&
|
|
512
|
+
lostAndExit.lines[0] === "! Emergency stop.",
|
|
513
|
+
);
|
|
514
|
+
check(
|
|
515
|
+
"an undefined-references summary in the final log fails too — the same path, its own id",
|
|
516
|
+
(() => {
|
|
517
|
+
const s = step([latex(), latex({ final: true, failing: [undefRefs] })]);
|
|
518
|
+
return (
|
|
519
|
+
s.kind === "fail" &&
|
|
520
|
+
JSON.stringify(s.cause) ===
|
|
521
|
+
JSON.stringify({
|
|
522
|
+
kind: "log-warnings",
|
|
523
|
+
ids: ["undefined-references"],
|
|
524
|
+
})
|
|
525
|
+
);
|
|
526
|
+
})(),
|
|
527
|
+
);
|
|
528
|
+
check(
|
|
529
|
+
"a final log whose only marker is off the list (a rerun request) is done",
|
|
530
|
+
kind(
|
|
531
|
+
step([latex(), latex({ final: true, markers: ["rerun-requested"] })]),
|
|
532
|
+
) === "done",
|
|
533
|
+
);
|
|
534
|
+
});
|
|
535
|
+
|
|
536
|
+
// ── helpers ─────────────────────────────────────────────────────────────────────────────
|
|
537
|
+
it("helpers", () => {
|
|
538
|
+
check(
|
|
539
|
+
"changedFiles lists exactly the differing tracked files",
|
|
540
|
+
JSON.stringify(
|
|
541
|
+
changedFiles(H("a", "t", null, "b"), H("a", "t2", "o", "b")),
|
|
542
|
+
) === JSON.stringify(["toc", "out"]),
|
|
543
|
+
);
|
|
544
|
+
check(
|
|
545
|
+
"a file appearing (null → digest) is a change",
|
|
546
|
+
changedFiles(H(null), H("a1")).includes("aux"),
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
check(
|
|
550
|
+
"a history of only a bibtex run that left every file as it was: nothing unsettled",
|
|
551
|
+
JSON.stringify(summarize([bibtex({ after: H("a1") })]).unsettled) === "[]",
|
|
552
|
+
);
|
|
553
|
+
});
|
package/src/latex-loop.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* PURE. No disk, no process, no clock. The shell in `build.ts` runs a step, records what it saw
|
|
5
5
|
* as an `Observation`, appends it to the history and asks `nextStep(summarize(history))` again.
|
|
6
|
-
* Both halves are table tests (`latex-loop.
|
|
6
|
+
* Both halves are table tests (`latex-loop.test.ts`), not scenarios that need TeX.
|
|
7
7
|
*
|
|
8
8
|
* ── THE LOOP: `summarize` reduces the history to a `State`, and `nextStep` asks four questions ──
|
|
9
9
|
* 1. did the last program fail — a non-zero exit, or a
|