paperlint 20.1.0 → 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.
Files changed (86) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/.github/workflows/ci.yml +7 -0
  3. package/CLAUDE.md +2 -2
  4. package/CONTRIBUTING.md +2 -2
  5. package/{action.harness.mjs → action.test.mjs} +147 -138
  6. package/dist/domain/paper-layout.d.ts +18 -6
  7. package/dist/domain/paper-layout.d.ts.map +1 -1
  8. package/dist/domain/paper-layout.js +44 -38
  9. package/dist/domain/paper-layout.js.map +1 -1
  10. package/dist/eslint-rules/papers.js +1 -1
  11. package/dist/folder-layout-hook.js +1 -1
  12. package/dist/latex-log.d.ts +1 -1
  13. package/dist/latex-log.js +1 -1
  14. package/dist/latex-loop.d.ts +1 -1
  15. package/dist/latex-loop.js +1 -1
  16. package/dist/lib/paper-config.d.ts +3 -3
  17. package/dist/lib/paper-config.js +3 -3
  18. package/docs/e2e.md +9 -9
  19. package/docs/install.md +11 -11
  20. package/docs/rules/paper/allowed-files-only.md +31 -28
  21. package/docs/testing.md +3 -4
  22. package/eslint-rules/{install-path-literals.harness.mjs → install-path-literals.test.mjs} +14 -13
  23. package/eslint-rules/{latex-language.harness.mjs → latex-language-rules.test.mjs} +61 -51
  24. package/eslint-rules/{paper-stages.harness.mjs → paper-stages-rule.test.mjs} +66 -69
  25. package/eslint-rules/{papers.harness.mjs → papers.test.mjs} +41 -30
  26. package/eslint-rules/papers.ts +1 -1
  27. package/eslint-rules/{pdf-last-page-balance.harness.mjs → pdf-last-page-balance.test.mjs} +27 -15
  28. package/eslint-rules/{temp-root-realpath.harness.mjs → temp-root-realpath.test.mjs} +24 -24
  29. package/eslint-rules/{tex-build.harness.mjs → tex-build.test.mjs} +292 -271
  30. package/eslint.config.mjs +15 -2
  31. package/fixtures/pdf-facts/README.md +1 -1
  32. package/fixtures/render-paper/build-clean.sh +1 -1
  33. package/fixtures/toolchain-mirror/install-tl +1 -1
  34. package/lib/{agent-cli-version.harness.mjs → agent-cli-version.test.mjs} +17 -18
  35. package/lib/{paper-config.harness.mjs → paper-config.test.mjs} +21 -20
  36. package/lib/paper-config.ts +3 -3
  37. package/lib/{skill-trigger-cases.harness.mjs → skill-trigger-cases-carrier.test.mjs} +78 -115
  38. package/package.json +3 -3
  39. package/presets/acm-acmsmall.jsonc +1 -1
  40. package/scripts/check-workflow.test.ts +368 -0
  41. package/scripts/check.ts +2 -2
  42. package/scripts/eslint-file-length.mjs +9 -9
  43. package/scripts/eslint-report-guard.mjs +1 -1
  44. package/scripts/eslint-report-guard.test.mjs +1 -1
  45. package/scripts/harness-api.test.ts +7 -46
  46. package/scripts/{rules-see-files.harness.mjs → rules-see-files-rule.test.mjs} +10 -6
  47. package/scripts/rules-see-files.mjs +1 -1
  48. package/skills/paper-pipeline/{paper-pipeline.harness.mjs → paper-pipeline.test.mjs} +45 -46
  49. package/skills/paper-pipeline/scripts/{consumer.harness.mjs → consumer-paths.test.mjs} +66 -59
  50. package/skills/paper-pipeline/scripts/consumer.mjs +3 -3
  51. package/skills/paper-pipeline/scripts/{extract-ref-facts.harness.mjs → extract-ref-facts-cli.test.mjs} +29 -31
  52. package/skills/paper-pipeline/scripts/fixtures/real-bib/refs.bib +1 -1
  53. package/skills/paper-pipeline/scripts/{generated-code.harness.mjs → generated-code-fixtures.test.mjs} +39 -46
  54. package/skills/render-paper/{extract-pdf-facts.harness.ts → extract-pdf-facts.test.ts} +20 -13
  55. package/skills/render-paper/{render-paper.harness.mjs → render-paper.test.mjs} +41 -40
  56. package/src/adapters/pdfjs/fill.test.ts +1 -1
  57. package/src/{build-engine.harness.mjs → build-engine-prepare.test.mjs} +98 -81
  58. package/src/{build.harness.mjs → build-fake-tex.test.mjs} +61 -28
  59. package/src/{cli.harness.mjs → cli-e2e.test.mjs} +109 -103
  60. package/src/cli.test.ts +2 -2
  61. package/src/{doctor.harness.mjs → doctor-install.test.mjs} +28 -29
  62. package/src/domain/paper-layout.test.ts +89 -49
  63. package/src/domain/paper-layout.ts +61 -42
  64. package/src/{engine.harness.mjs → engine.test.mjs} +120 -106
  65. package/src/facts-file.test.ts +1 -1
  66. package/src/folder-layout-hook.test.ts +1 -1
  67. package/src/folder-layout-hook.ts +1 -1
  68. package/src/folder-layout-rule.test.ts +1 -1
  69. package/src/{hooks-settings.harness.ts → hooks-settings.test.ts} +161 -146
  70. package/src/latex-log.test.ts +395 -0
  71. package/src/latex-log.ts +1 -1
  72. package/src/latex-loop.test.ts +553 -0
  73. package/src/latex-loop.ts +1 -1
  74. package/src/layout-docs.test.ts +47 -0
  75. package/src/{link-skills.harness.ts → link-skills-fs.test.ts} +26 -26
  76. package/src/{new-paper.harness.mjs → new-paper-scaffold.test.mjs} +31 -19
  77. package/src/{pdf-facts.harness.ts → pdf-facts-tables.test.ts} +28 -22
  78. package/src/{pdf-geometry.harness.ts → pdf-geometry.test.ts} +93 -75
  79. package/src/{rules-config.harness.ts → rules-config.test.ts} +41 -31
  80. package/src/{structure.harness.ts → structure.test.ts} +12 -10
  81. package/src/{tex-requirements.harness.ts → tex-requirements-tables.test.ts} +106 -85
  82. package/src/{toolchain.harness.mjs → toolchain-mirror.test.mjs} +204 -186
  83. package/scripts/check.harness.ts +0 -343
  84. package/scripts/harness-api.frozen.json +0 -41
  85. package/src/latex-log.harness.ts +0 -382
  86. package/src/latex-loop.harness.ts +0 -515
@@ -11,9 +11,9 @@
11
11
  *
12
12
  * The fixture package keeps its skills where the real one does, under `SHIPPED_SKILLS_DIR` from
13
13
  * consumer.mjs — the same constant the linker and the install e2e read.
14
- *
15
- * Run: node src/link-skills.harness.ts
16
14
  */
15
+ import { afterAll, describe, expect, it } from "vitest";
16
+ import { failureMessage } from "../lib/check.ts";
17
17
  import {
18
18
  existsSync,
19
19
  mkdirSync,
@@ -27,7 +27,6 @@ import {
27
27
  } from "node:fs";
28
28
  import { tmpdir } from "node:os";
29
29
  import { isAbsolute, join } from "node:path";
30
- import { createChecker } from "../lib/check.ts";
31
30
  import type { LinkReport } from "./link-skills.ts";
32
31
 
33
32
  const { linkSkills, locatePackage, shippedSkills } =
@@ -35,7 +34,10 @@ const { linkSkills, locatePackage, shippedSkills } =
35
34
  const { SHIPPED_SKILLS_DIR: SHIPS, PACKAGE_NAME: PKG } =
36
35
  await import("../skills/paper-pipeline/scripts/consumer.mjs");
37
36
 
38
- const check = createChecker();
37
+ // A failed check is recorded and the rest of the test keeps running.
38
+ const check = (label: string, cond: unknown, detail?: unknown): void => {
39
+ expect.soft(cond, failureMessage(label, detail)).toBeTruthy();
40
+ };
39
41
 
40
42
  const SKILLS = ["alpha", "beta", "gamma"];
41
43
  const work = realpathSync(
@@ -92,9 +94,13 @@ const linksOf = (report: LinkReport) => (report.ok ? report.links : []);
92
94
  const status = (report: LinkReport, name: string) =>
93
95
  linksOf(report).find((l) => l.name === name);
94
96
 
95
- try {
97
+ afterAll(() => {
98
+ rmSync(work, { recursive: true, force: true });
99
+ });
100
+
101
+ describe("link-skills: the skills are where Claude Code looks", () => {
96
102
  // ── I. A FRESH npm CONSUMER: EVERY DECLARED SKILL IS LINKED, AND ONLY SKILLS ───────────
97
- {
103
+ it("I. A FRESH npm CONSUMER: EVERY DECLARED SKILL IS LINKED, AND ONLY SKILLS", () => {
98
104
  const dir = consumer("npm");
99
105
  const r = linkSkills(dir);
100
106
  check(
@@ -120,10 +126,10 @@ try {
120
126
  !isAbsolute(target) &&
121
127
  target === join("..", "..", "node_modules", PKG, SHIPS, "alpha"),
122
128
  );
123
- }
129
+ });
124
130
 
125
131
  // ── II. A SECOND RUN CHANGES NOTHING ──────────────────────────────────────────────────
126
- {
132
+ it("II. A SECOND RUN CHANGES NOTHING", () => {
127
133
  const dir = join(work, "npm");
128
134
  const before = SKILLS.map((s) => readlinkSync(join(home(dir), s)));
129
135
  const r = linkSkills(dir);
@@ -135,10 +141,10 @@ try {
135
141
  "and leaves the links byte for byte as they were",
136
142
  SKILLS.every((s, i) => readlinkSync(join(home(dir), s)) === before[i]),
137
143
  );
138
- }
144
+ });
139
145
 
140
146
  // ── III. A NAME THAT IS ALREADY TAKEN IS SOMEONE ELSE'S ───────────────────────────────
141
- {
147
+ it("III. A NAME THAT IS ALREADY TAKEN IS SOMEONE ELSE'S", () => {
142
148
  const dir = consumer("foreign");
143
149
  mkdirSync(join(home(dir), "alpha"), { recursive: true });
144
150
  writeFileSync(join(home(dir), "alpha", "SKILL.md"), "mine\n");
@@ -165,10 +171,10 @@ try {
165
171
  /^a link to /.test(status(r, "beta")?.reason ?? "") &&
166
172
  /^a dangling link to /.test(status(r, "gamma")?.reason ?? ""),
167
173
  );
168
- }
174
+ });
169
175
 
170
176
  // ── IV. pnpm: THE LINK GOES THROUGH THE PROJECT'S OWN SPELLING ─────────────────────────
171
- {
177
+ it("IV. pnpm: THE LINK GOES THROUGH THE PROJECT'S OWN SPELLING", () => {
172
178
  const dir = consumer("pnpm", "pnpm");
173
179
  const located = locatePackage(dir);
174
180
  check(
@@ -187,10 +193,10 @@ try {
187
193
  "and SKILL.md is reachable through both hops",
188
194
  SKILLS.every((s) => existsSync(join(home(dir), s, "SKILL.md"))),
189
195
  );
190
- }
196
+ });
191
197
 
192
198
  // ── V. NOT INSTALLED IN THIS PROJECT — NOTHING IS LINKED, AND IT SAYS WHY ──────────────
193
- {
199
+ it("V. NOT INSTALLED IN THIS PROJECT — NOTHING IS LINKED, AND IT SAYS WHY", () => {
194
200
  const dir = consumer("bare", "none");
195
201
  const r = linkSkills(dir);
196
202
  check(
@@ -198,10 +204,10 @@ try {
198
204
  !r.ok && /does not resolve from/.test(r.error),
199
205
  );
200
206
  check("and nothing is created", !existsSync(join(dir, ".claude")));
201
- }
207
+ });
202
208
 
203
209
  // ── VI. doctor's READ WRITES NOTHING ───────────────────────────────────────────────────
204
- {
210
+ it("VI. doctor's READ WRITES NOTHING", () => {
205
211
  const dir = consumer("readonly");
206
212
  const r = linkSkills(dir, { write: false });
207
213
  check(
@@ -210,11 +216,11 @@ try {
210
216
  SKILLS.every((s) => status(r, s)?.status === "missing") &&
211
217
  !existsSync(home(dir)),
212
218
  );
213
- }
219
+ });
214
220
 
215
221
  // ── VI-bis. LINKS LEFT BY AN INSTALL UNDER THE OLD NAME ARE REPLACED, NOT SKIPPED ─────
216
222
  // ── VII. A PACKAGE WITHOUT ITS SKILLS DIRECTORY IS AN ERROR, NOT ZERO SKILLS ─────────
217
- {
223
+ it("VII. A PACKAGE WITHOUT ITS SKILLS DIRECTORY IS AN ERROR, NOT ZERO SKILLS", () => {
218
224
  const pkg = join(work, "no-skills");
219
225
  writePackage(pkg);
220
226
  rmSync(join(pkg, SHIPS), { recursive: true, force: true });
@@ -223,11 +229,5 @@ try {
223
229
  "no skills directory — an error that names it, not an empty list",
224
230
  "error" in s && s.error.includes(join(pkg, SHIPS)),
225
231
  );
226
- }
227
- } finally {
228
- rmSync(work, { recursive: true, force: true });
229
- }
230
-
231
- console.log(
232
- `✓ ${String(check.count)} assertions passed — link-skills: the skills are where Claude Code looks`,
233
- );
232
+ });
233
+ });
@@ -14,9 +14,9 @@
14
14
  * - it never overwrites, and on an existing folder adds only what is missing;
15
15
  * - the project's `<papers>/.template/` wins over the package, file by file.
16
16
  *
17
- * ⚠️ Assertions at the TOP LEVEL: `vigiles test` imports the file and counts "did not throw"
18
- * as a pass.
17
+ * The tests run in order: later ones build on the folders earlier ones made.
19
18
  */
19
+ import { afterAll, expect, it } from "vitest";
20
20
  import {
21
21
  existsSync,
22
22
  mkdirSync,
@@ -31,7 +31,6 @@ import { dirname, join } from "node:path";
31
31
  import { fileURLToPath } from "node:url";
32
32
  import { load } from "js-yaml";
33
33
  import { frontmatterBlock } from "../lib/markdown.ts";
34
- import { createChecker } from "../lib/check.ts";
35
34
 
36
35
  const HERE = dirname(fileURLToPath(import.meta.url));
37
36
  const ROOT = dirname(HERE);
@@ -45,9 +44,15 @@ const {
45
44
  } = await import(join(HERE, "new-paper.ts"));
46
45
  const { run } = await import(join(HERE, "cli.ts"));
47
46
 
48
- const check = createChecker();
47
+ // A failed check is recorded and the rest of the test keeps running.
48
+ const check = (label, cond, detail) => {
49
+ expect
50
+ .soft(cond, detail === undefined ? label : `${label}\n${String(detail)}`)
51
+ .toBeTruthy();
52
+ };
49
53
 
50
54
  const work = realpathSync(mkdtempSync(join(tmpdir(), "paperlint-new-")));
55
+ const papers = join(work, "papers");
51
56
  const read = (...p) => readFileSync(join(...p), "utf8");
52
57
  const front = (text) => load(frontmatterBlock(text) ?? "") ?? {};
53
58
 
@@ -62,8 +67,12 @@ async function lint(dir) {
62
67
  return { code, text: out.join("\n") };
63
68
  }
64
69
 
65
- try {
66
- // ── the templates are FILES in the package, one per required file ──────────────────────
70
+ afterAll(() => {
71
+ rmSync(work, { recursive: true, force: true });
72
+ });
73
+
74
+ // ── the templates are FILES in the package, one per required file ──────────────────────
75
+ it("the templates are FILES in the package, one per required file", () => {
67
76
  for (const f of [STATUS_FILE, SOURCE_FILE])
68
77
  check(
69
78
  `the package ships templates/paper/${f}`,
@@ -73,8 +82,10 @@ try {
73
82
  "🔴 the templates ship in the npm tarball — `templates` is in package.json `files`",
74
83
  JSON.parse(read(ROOT, "package.json")).files.includes("templates"),
75
84
  );
85
+ });
76
86
 
77
- // ── names ───────────────────────────────────────────────────────────────────────────
87
+ // ── names ───────────────────────────────────────────────────────────────────────────
88
+ it("names", () => {
78
89
  for (const ok of ["demo", "aisec-2026", "v1.2_final"])
79
90
  check(`\`${ok}\` is a valid name`, nameProblem(ok, []) === null);
80
91
  for (const bad of ["Demo", "my paper", "a/b", "../x", "", "ÿ"])
@@ -94,9 +105,10 @@ try {
94
105
  newPaper(work, "Bad", { venues: [] }).ok === false &&
95
106
  !existsSync(join(work, "Bad")),
96
107
  );
108
+ });
97
109
 
98
- // ── a fresh LaTeX paper ─────────────────────────────────────────────────────────────
99
- const papers = join(work, "papers");
110
+ // ── a fresh LaTeX paper ─────────────────────────────────────────────────────────────
111
+ it("a fresh LaTeX paper", async () => {
100
112
  const r = newPaper(papers, "demo", { venues: [] });
101
113
  check(
102
114
  "a fresh folder gets the scorecard, a .tex source and paperlint.json, all from the package",
@@ -147,8 +159,10 @@ try {
147
159
  readFileSync(join(papers, "demo", STATUS_FILE), "utf8"),
148
160
  ),
149
161
  );
162
+ });
150
163
 
151
- // ── never overwrite; on an existing folder only the missing files ─────────────────────
164
+ // ── never overwrite; on an existing folder only the missing files ─────────────────────
165
+ it("never overwrite; on an existing folder only the missing files", () => {
152
166
  writeFileSync(join(papers, "demo", STATUS_FILE), "mine\n");
153
167
  const again = newPaper(papers, "demo", { venues: [] });
154
168
  check(
@@ -164,8 +178,10 @@ try {
164
178
  "a name taken by a FILE is refused, not written through",
165
179
  newPaper(papers, "afile", { venues: [] }).ok === false,
166
180
  );
181
+ });
167
182
 
168
- // ── the project's template wins, file by file ─────────────────────────────────────────
183
+ // ── the project's template wins, file by file ─────────────────────────────────────────
184
+ it("the project's template wins, file by file", () => {
169
185
  mkdirSync(join(papers, OVERRIDE_DIR), { recursive: true });
170
186
  writeFileSync(
171
187
  join(papers, OVERRIDE_DIR, STATUS_FILE),
@@ -182,8 +198,10 @@ try {
182
198
  own.files.find((f) => f.file === STATUS_FILE)?.from === "project" &&
183
199
  own.files.find((f) => f.file === SOURCE_FILE)?.from === "package",
184
200
  );
201
+ });
185
202
 
186
- // ── a missing template is a broken install, not an empty file ─────────────────────────
203
+ // ── a missing template is a broken install, not an empty file ─────────────────────────
204
+ it("a missing template is a broken install, not an empty file", () => {
187
205
  const broken = newPaper(join(work, "b"), "x", {
188
206
  venues: [],
189
207
  packageTemplates: join(work, "no-such-dir"),
@@ -194,10 +212,4 @@ try {
194
212
  /no template for/.test(broken.reason) &&
195
213
  !existsSync(join(work, "b", "x")),
196
214
  );
197
- } finally {
198
- rmSync(work, { recursive: true, force: true });
199
- }
200
-
201
- console.log(
202
- `✓ ${String(check.count)} assertions passed — paperlint new scaffolds what paperlint lint accepts`,
203
- );
215
+ });
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * `pdf-facts.ts` — pdf.js reading REAL PDFs, committed under `fixtures/pdf-facts/`.
3
3
  *
4
- * The pure decisions are tested in `pdf-geometry.harness.ts` with hand-written words. This file is
4
+ * The pure decisions are tested in `pdf-geometry.test.ts` with hand-written words. This file is
5
5
  * the other half: that the shell asks pdf.js the right questions, with the right options, and maps
6
6
  * what comes back. The expected numbers are the ones poppler reported for the same files in the
7
7
  * 2026-09-24 measurement (issue #61), so a pass here is agreement with the tool this replaced.
@@ -11,15 +11,24 @@ import { writeFileSync, mkdtempSync, realpathSync, rmSync } from "node:fs";
11
11
  import { tmpdir } from "node:os";
12
12
  import { dirname, join, resolve } from "node:path";
13
13
  import { fileURLToPath } from "node:url";
14
- import { createChecker } from "../lib/check.ts";
14
+ import { afterAll, expect, it, vi } from "vitest";
15
15
  import type { PdfFacts } from "./pdf-facts.ts";
16
16
 
17
+ // Several tests here run real ESLint, spawn processes or walk the repository.
18
+ vi.setConfig({ testTimeout: 120_000 });
19
+
17
20
  const HERE = dirname(fileURLToPath(import.meta.url));
18
21
  const FIX = resolve(HERE, "..", "fixtures", "pdf-facts");
19
22
  const { readPdf } = await import("./pdf-facts.ts");
20
23
  const { classifyLastPage } = await import("./pdf-geometry.ts");
21
24
 
22
- const check = createChecker();
25
+ /** One soft assertion: a failed check does not stop the checks after it in the same test. */
26
+ const check = (label: string, cond: unknown, detail?: unknown): void => {
27
+ const shown = typeof detail === "string" ? detail : JSON.stringify(detail);
28
+ expect
29
+ .soft(cond, detail === undefined ? label : `${label}\n${shown}`)
30
+ .toBe(true);
31
+ };
23
32
 
24
33
  const read = async (name: string): Promise<PdfFacts> => {
25
34
  const r = await readPdf(join(FIX, name));
@@ -34,7 +43,7 @@ const named = (facts: PdfFacts, name: string) =>
34
43
  : undefined;
35
44
 
36
45
  // ── t3-all: every text font is Type 3 ──────────────────────────────────────────────────
37
- {
46
+ it("t3-all: every text font is Type 3", async () => {
38
47
  const f = await read("t3-all.pdf");
39
48
  check(
40
49
  "t3-all: four Type 3 fonts, as poppler lists — including one no text item names",
@@ -50,10 +59,10 @@ const named = (facts: PdfFacts, name: string) =>
50
59
  Math.abs(last.columns[1] - 553.2) <= 7.2,
51
60
  JSON.stringify(last),
52
61
  );
53
- }
62
+ });
54
63
 
55
64
  // ── ttf: a LuaLaTeX PDF, composite TrueType ────────────────────────────────────────────
56
- {
65
+ it("ttf: a LuaLaTeX PDF, composite TrueType", async () => {
57
66
  const f = await read("ttf.pdf");
58
67
  const arsenal = named(f, "Arsenal SC Regular");
59
68
  check(
@@ -65,10 +74,10 @@ const named = (facts: PdfFacts, name: string) =>
65
74
  "ttf: two pages, and the 8-word last page is a stub",
66
75
  f.pages === 2 && classifyLastPage(f.last).kind === "stub",
67
76
  );
68
- }
77
+ });
69
78
 
70
79
  // ── t3-mixed: the sub/uni bug of the poppler reader ────────────────────────────────────
71
- {
80
+ it("t3-mixed: the sub/uni bug of the poppler reader", async () => {
72
81
  const f = await read("t3-mixed.pdf");
73
82
  // pdffonts prints this font as `Times-Roman Type 1 Custom no no yes`. The old reader
74
83
  // tested `yes` anywhere in the row, found the `uni` column's, and called the font embedded.
@@ -92,10 +101,10 @@ const named = (facts: PdfFacts, name: string) =>
92
101
  JSON.stringify(["embedded", "embedded", "type3", "not-embedded"]),
93
102
  JSON.stringify(f.fonts),
94
103
  );
95
- }
104
+ });
96
105
 
97
106
  // ── corrupt-font: poppler says embedded, the program does not parse ────────────────────
98
- {
107
+ it("corrupt-font: poppler says embedded, the program does not parse", async () => {
99
108
  const f = await read("corrupt-font.pdf");
100
109
  check(
101
110
  "corrupt-font: a font program that does not parse counts as not embedded",
@@ -103,19 +112,19 @@ const named = (facts: PdfFacts, name: string) =>
103
112
  named(f, "CMBX12")?.kind === "embedded",
104
113
  JSON.stringify(f.fonts),
105
114
  );
106
- }
115
+ });
107
116
 
108
117
  // ── what cannot be read says so ─────────────────────────────────────────────────────────
109
- {
118
+ it("what cannot be read says so", async () => {
110
119
  const r = await readPdf(join(FIX, "encrypted.pdf"));
111
120
  check(
112
121
  "an encrypted PDF is `encrypted`, not a crash",
113
122
  !r.ok && r.reason === "encrypted",
114
123
  JSON.stringify(r),
115
124
  );
116
- }
125
+ });
117
126
  const tmp = realpathSync(mkdtempSync(join(tmpdir(), "paperlint-pdf-facts-")));
118
- try {
127
+ it("what cannot be read says so: a file that is not a PDF, and a missing one", async () => {
119
128
  const notPdf = join(tmp, "paper.pdf");
120
129
  writeFileSync(notPdf, "%PDF-stale\n");
121
130
  const bad = await readPdf(notPdf);
@@ -130,12 +139,13 @@ try {
130
139
  !missing.ok && missing.reason === "unreadable",
131
140
  JSON.stringify(missing),
132
141
  );
133
- } finally {
142
+ });
143
+ afterAll(() => {
134
144
  rmSync(tmp, { recursive: true, force: true });
135
- }
145
+ });
136
146
 
137
147
  // ── hidden-text: the boxes banal is fed ────────────────────────────────────────────────
138
- {
148
+ it("hidden-text: the boxes banal is fed", async () => {
139
149
  const f = await read("hidden-text.pdf");
140
150
  const boxes = f.layout.flatMap((p, i) =>
141
151
  p.boxes.map((b) => ({ ...b, page: i + 1 })),
@@ -179,8 +189,4 @@ try {
179
189
  Math.abs(b.size - 9.96) < 0.1,
180
190
  ) > 3000,
181
191
  );
182
- }
183
-
184
- console.log(
185
- `✓ ${String(check.count)} assertions passed — pdf-facts: pdf.js on real PDFs agrees with poppler, and says what it cannot read`,
186
- );
192
+ });
@@ -4,9 +4,10 @@
4
4
  * Every page here is written by hand as words, because the cases that matter are pages the fixture
5
5
  * corpus does not contain. Each column case reproduces an error the poppler-based measurement made
6
6
  * on 2026-08-29 (the midpoint cut, the review build, years mistaken for line numbers), ported from
7
- * the harness of the function this replaces.
7
+ * the test of the function this replaces.
8
8
  */
9
- import { createChecker } from "../lib/check.ts";
9
+ import { failureMessage } from "../lib/check.ts";
10
+ import { expect, it } from "vitest";
10
11
  import type { RawFont } from "./pdf-geometry.ts";
11
12
 
12
13
  const {
@@ -19,7 +20,10 @@ const {
19
20
  STUB_WORDS,
20
21
  } = await import("./pdf-geometry.ts");
21
22
 
22
- const check = createChecker();
23
+ // A failed check is recorded and the rest of the test keeps running.
24
+ const check = (label: string, cond: unknown, detail?: unknown): void => {
25
+ expect.soft(cond, failureMessage(label, detail)).toBeTruthy();
26
+ };
23
27
 
24
28
  /** A row of stacked words: `n` of them from `top` downwards, `step` apart. */
25
29
  interface Row {
@@ -50,7 +54,7 @@ const page = (rows: readonly Row[], widthPt = W) => ({
50
54
  });
51
55
 
52
56
  // ── the last page's columns ─────────────────────────────────────────────────────────────
53
- {
57
+ it("the last page's columns", () => {
54
58
  const p = classifyLastPage(
55
59
  page([
56
60
  { x: 54, top: 60, n: 40 },
@@ -61,8 +65,8 @@ const page = (rows: readonly Row[], widthPt = W) => ({
61
65
  "balanced: two identical columns measure identical heights",
62
66
  p.kind === "measured" && p.columns[0] === 400 && p.columns[1] === 400,
63
67
  );
64
- }
65
- {
68
+ });
69
+ it("unbalanced: the 300 pt difference shows up as heights 600 / 300", () => {
66
70
  const p = classifyLastPage(
67
71
  page([
68
72
  { x: 54, top: 60, n: 60 },
@@ -73,8 +77,8 @@ const page = (rows: readonly Row[], widthPt = W) => ({
73
77
  "unbalanced: the 300 pt difference shows up as heights 600 / 300",
74
78
  p.kind === "measured" && p.columns[0] === 600 && p.columns[1] === 300,
75
79
  );
76
- }
77
- {
80
+ });
81
+ it("midpoint: an empty right column measures 0 — the split is the page's middle, not the words'", () => {
78
82
  // 🔴 Split at the PAGE's middle. Only the left column is filled, lines span 54…300, and a page
79
83
  // number sits centred at the bottom: the words' own midpoint would fall inside the left column.
80
84
  const rows = [];
@@ -87,8 +91,8 @@ const page = (rows: readonly Row[], widthPt = W) => ({
87
91
  "midpoint: an empty right column measures 0 — the split is the page's middle, not the words'",
88
92
  p.kind === "measured" && p.columns[1] === 0 && p.columns[0] > 600,
89
93
  );
90
- }
91
- {
94
+ });
95
+ it("review (left margin): numbered lines make a review build, which is not measured", () => {
92
96
  const body = [
93
97
  { x: 54, top: 60, n: 60 },
94
98
  { x: 320, top: 60, n: 10 },
@@ -120,8 +124,8 @@ const page = (rows: readonly Row[], widthPt = W) => ({
120
124
  classifyLastPage(page([...body, { x: 20, top: 60, n: 5, text: "7" }]))
121
125
  .kind === "review",
122
126
  );
123
- }
124
- {
127
+ });
128
+ it("years in the body are not line numbers — a bibliography stays measured", () => {
125
129
  const p = classifyLastPage(
126
130
  page([
127
131
  { x: 54, top: 60, n: 40, text: "2024" },
@@ -132,8 +136,8 @@ const page = (rows: readonly Row[], widthPt = W) => ({
132
136
  "years in the body are not line numbers — a bibliography stays measured",
133
137
  p.kind === "measured",
134
138
  );
135
- }
136
- {
139
+ });
140
+ it("stub: a page with fewer than 60 words is a stub, with its word count", () => {
137
141
  const stub = classifyLastPage(page([{ x: 54, top: 60, n: STUB_WORDS - 1 }]));
138
142
  check(
139
143
  "stub: a page with fewer than 60 words is a stub, with its word count",
@@ -144,21 +148,23 @@ const page = (rows: readonly Row[], widthPt = W) => ({
144
148
  classifyLastPage(page([{ x: 54, top: 60, n: STUB_WORDS }])).kind ===
145
149
  "measured",
146
150
  );
147
- }
148
- check(
149
- "a page with no width is a caller's defect: it throws, it is not a measurement",
150
- (() => {
151
- try {
152
- classifyLastPage(page([{ x: 54, top: 60, n: 70 }], 0));
153
- return false;
154
- } catch (e) {
155
- return e instanceof RangeError;
156
- }
157
- })(),
158
- );
151
+ });
152
+ it("a page with no width is a caller's defect: it throws, it is not a measurement", () => {
153
+ check(
154
+ "a page with no width is a caller's defect: it throws, it is not a measurement",
155
+ (() => {
156
+ try {
157
+ classifyLastPage(page([{ x: 54, top: 60, n: 70 }], 0));
158
+ return false;
159
+ } catch (e) {
160
+ return e instanceof RangeError;
161
+ }
162
+ })(),
163
+ );
164
+ });
159
165
 
160
166
  // ── words from a text run ───────────────────────────────────────────────────────────────
161
- {
167
+ it("words from a text run", () => {
162
168
  const ws = wordsOf({
163
169
  text: "ab cd",
164
170
  x: 100,
@@ -180,7 +186,7 @@ check(
180
186
  "a word spans ascent above the baseline to descent below it",
181
187
  ws[0]?.y0 === 192 && ws[0].y1 === 202,
182
188
  );
183
- }
189
+ });
184
190
 
185
191
  // ── fonts ───────────────────────────────────────────────────────────────────────────────
186
192
  const font = (over: Partial<RawFont>): RawFont => ({
@@ -192,42 +198,56 @@ const font = (over: Partial<RawFont>): RawFont => ({
192
198
  missingFile: false,
193
199
  ...over,
194
200
  });
195
- check(
196
- "an embedded font: the subset tag is dropped, the program named",
197
- JSON.stringify(fontFact(font({}))) ===
198
- JSON.stringify({
199
- kind: "embedded",
200
- name: "LinLibertineT",
201
- program: "Type1C",
202
- }),
203
- );
204
- check(
205
- "🔴 a font with no usable program is NOT embedded — whatever else the PDF says about it",
206
- fontFact(font({ name: "Times-Roman", subtype: undefined, missingFile: true }))
207
- .kind === "not-embedded",
208
- );
209
- check(
210
- "a Type 3 font is its own kind, named Type3",
211
- JSON.stringify(fontFact(font({ isType3Font: true, name: "" }))) ===
212
- JSON.stringify({ kind: "type3", name: "Type3" }),
213
- );
214
- check(
215
- "programs: composite TrueType, CFF-in-CID, OpenType, and an unknown one kept verbatim",
216
- programOf("CIDFontType2", undefined) === "CIDTrueType" &&
217
- programOf("CIDFontType0", "CIDFontType0C") === "CIDType0C" &&
218
- programOf("CIDFontType0", undefined) === "CIDType0" &&
219
- programOf("TrueType", "OpenType") === "OpenType" &&
220
- programOf("MMType1", undefined) === "MMType1" &&
221
- programOf(undefined, undefined) === "unknown:undefined/undefined",
222
- );
223
- check(
224
- "the type column keeps poppler's spelling, which consumers match on",
225
- popplerType({ kind: "type3", name: "Type3" }) === "Type 3" &&
226
- popplerType(fontFact(font({}))) === "Type 1C" &&
227
- popplerType({ kind: "embedded", name: "x", program: "unknown:Foo/Bar" }) ===
228
- "unknown:Foo/Bar",
229
- );
230
- {
201
+ it("an embedded font: the subset tag is dropped, the program named", () => {
202
+ check(
203
+ "an embedded font: the subset tag is dropped, the program named",
204
+ JSON.stringify(fontFact(font({}))) ===
205
+ JSON.stringify({
206
+ kind: "embedded",
207
+ name: "LinLibertineT",
208
+ program: "Type1C",
209
+ }),
210
+ );
211
+ });
212
+ it("🔴 a font with no usable program is NOT embedded — whatever else the PDF says about it", () => {
213
+ check(
214
+ "🔴 a font with no usable program is NOT embedded — whatever else the PDF says about it",
215
+ fontFact(
216
+ font({ name: "Times-Roman", subtype: undefined, missingFile: true }),
217
+ ).kind === "not-embedded",
218
+ );
219
+ });
220
+ it("a Type 3 font is its own kind, named Type3", () => {
221
+ check(
222
+ "a Type 3 font is its own kind, named Type3",
223
+ JSON.stringify(fontFact(font({ isType3Font: true, name: "" }))) ===
224
+ JSON.stringify({ kind: "type3", name: "Type3" }),
225
+ );
226
+ });
227
+ it("programs: composite TrueType, CFF-in-CID, OpenType, and an unknown one kept verbatim", () => {
228
+ check(
229
+ "programs: composite TrueType, CFF-in-CID, OpenType, and an unknown one kept verbatim",
230
+ programOf("CIDFontType2", undefined) === "CIDTrueType" &&
231
+ programOf("CIDFontType0", "CIDFontType0C") === "CIDType0C" &&
232
+ programOf("CIDFontType0", undefined) === "CIDType0" &&
233
+ programOf("TrueType", "OpenType") === "OpenType" &&
234
+ programOf("MMType1", undefined) === "MMType1" &&
235
+ programOf(undefined, undefined) === "unknown:undefined/undefined",
236
+ );
237
+ });
238
+ it("the type column keeps poppler's spelling, which consumers match on", () => {
239
+ check(
240
+ "the type column keeps poppler's spelling, which consumers match on",
241
+ popplerType({ kind: "type3", name: "Type3" }) === "Type 3" &&
242
+ popplerType(fontFact(font({}))) === "Type 1C" &&
243
+ popplerType({
244
+ kind: "embedded",
245
+ name: "x",
246
+ program: "unknown:Foo/Bar",
247
+ }) === "unknown:Foo/Bar",
248
+ );
249
+ });
250
+ it("fonts: each font once, in the order pages first drew them", () => {
231
251
  const r = fontsOf([
232
252
  { hasText: true, fonts: [font({ id: "a" }), font({ id: "b", name: "B" })] },
233
253
  { hasText: true, fonts: [font({ id: "a" })] },
@@ -236,8 +256,8 @@ check(
236
256
  "fonts: each font once, in the order pages first drew them",
237
257
  r.kind === "drawn" && r.list.length === 2 && r.list[1]?.name === "B",
238
258
  );
239
- }
240
- {
259
+ });
260
+ it("🔴 text on a page with no font is a FAILED READ, naming the page — not an empty list", () => {
241
261
  const r = fontsOf([
242
262
  { hasText: true, fonts: [font({ id: "a" })] },
243
263
  { hasText: true, fonts: [] },
@@ -246,12 +266,10 @@ check(
246
266
  "🔴 text on a page with no font is a FAILED READ, naming the page — not an empty list",
247
267
  r.kind === "zero-fonts-on-text" && r.pages.join() === "2",
248
268
  );
249
- }
250
- check(
251
- "no page draws text and there are no fonts: that is `no-text`, not a failure",
252
- fontsOf([{ hasText: false, fonts: [] }]).kind === "no-text",
253
- );
254
-
255
- console.log(
256
- `✓ ${String(check.count)} assertions passed — pdf-geometry: columns, stub/review, words from runs, fonts`,
257
- );
269
+ });
270
+ it("no page draws text and there are no fonts: that is `no-text`, not a failure", () => {
271
+ check(
272
+ "no page draws text and there are no fonts: that is `no-text`, not a failure",
273
+ fontsOf([{ hasText: false, fonts: [] }]).kind === "no-text",
274
+ );
275
+ });