paperlint 18.4.0 → 18.5.0

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 (104) hide show
  1. package/CLAUDE.md +5 -1
  2. package/dist/adapters/latex/abstract.d.ts +11 -0
  3. package/dist/adapters/latex/abstract.d.ts.map +1 -1
  4. package/dist/adapters/latex/abstract.js +1 -1
  5. package/dist/adapters/latex/abstract.js.map +1 -1
  6. package/dist/adapters/latex/index.d.ts.map +1 -1
  7. package/dist/adapters/latex/index.js +3 -0
  8. package/dist/adapters/latex/index.js.map +1 -1
  9. package/dist/adapters/latex/macros.d.ts +6 -0
  10. package/dist/adapters/latex/macros.d.ts.map +1 -0
  11. package/dist/adapters/latex/macros.js +27 -0
  12. package/dist/adapters/latex/macros.js.map +1 -0
  13. package/dist/adapters/osf/host.io.d.ts +12 -0
  14. package/dist/adapters/osf/host.io.d.ts.map +1 -0
  15. package/dist/adapters/osf/host.io.js +119 -0
  16. package/dist/adapters/osf/host.io.js.map +1 -0
  17. package/dist/adapters/osf/index.d.ts +10 -0
  18. package/dist/adapters/osf/index.d.ts.map +1 -0
  19. package/dist/adapters/osf/index.js +10 -0
  20. package/dist/adapters/osf/index.js.map +1 -0
  21. package/dist/adapters/osf/response.d.ts +11 -0
  22. package/dist/adapters/osf/response.d.ts.map +1 -0
  23. package/dist/adapters/osf/response.js +87 -0
  24. package/dist/adapters/osf/response.js.map +1 -0
  25. package/dist/artifact-upload-rule.d.ts +66 -0
  26. package/dist/artifact-upload-rule.d.ts.map +1 -0
  27. package/dist/artifact-upload-rule.js +151 -0
  28. package/dist/artifact-upload-rule.js.map +1 -0
  29. package/dist/artifact.d.ts +35 -0
  30. package/dist/artifact.d.ts.map +1 -0
  31. package/dist/artifact.js +251 -0
  32. package/dist/artifact.js.map +1 -0
  33. package/dist/cli.d.ts +9 -1
  34. package/dist/cli.d.ts.map +1 -1
  35. package/dist/cli.js +136 -23
  36. package/dist/cli.js.map +1 -1
  37. package/dist/domain/artifact-upload.d.ts +44 -0
  38. package/dist/domain/artifact-upload.d.ts.map +1 -0
  39. package/dist/domain/artifact-upload.js +80 -0
  40. package/dist/domain/artifact-upload.js.map +1 -0
  41. package/dist/domain/paper-dirs.d.ts +16 -0
  42. package/dist/domain/paper-dirs.d.ts.map +1 -0
  43. package/dist/domain/paper-dirs.js +42 -0
  44. package/dist/domain/paper-dirs.js.map +1 -0
  45. package/dist/eslint-rules/CLAUDE.md.spec.d.ts.map +1 -1
  46. package/dist/eslint-rules/CLAUDE.md.spec.js +1 -0
  47. package/dist/eslint-rules/CLAUDE.md.spec.js.map +1 -1
  48. package/dist/paper-files.d.ts +25 -42
  49. package/dist/paper-files.d.ts.map +1 -1
  50. package/dist/paper-files.js +101 -9
  51. package/dist/paper-files.js.map +1 -1
  52. package/dist/ports/artifact-host.d.ts +54 -0
  53. package/dist/ports/artifact-host.d.ts.map +1 -0
  54. package/dist/ports/artifact-host.js +2 -0
  55. package/dist/ports/artifact-host.js.map +1 -0
  56. package/dist/ports/latex.d.ts +9 -0
  57. package/dist/ports/latex.d.ts.map +1 -1
  58. package/dist/submission-confirm-hook.d.ts +11 -1
  59. package/dist/submission-confirm-hook.d.ts.map +1 -1
  60. package/dist/submission-confirm-hook.js +83 -21
  61. package/dist/submission-confirm-hook.js.map +1 -1
  62. package/dist/types.d.ts +6 -0
  63. package/dist/types.d.ts.map +1 -1
  64. package/docs/artifact-upload.md +124 -0
  65. package/docs/optional-rules.md +1 -0
  66. package/docs/osf-artifact.md +4 -1
  67. package/docs/rules/artifact/upload-current.md +85 -0
  68. package/docs/rules.md +1 -0
  69. package/eslint-rules/CLAUDE.md +5 -1
  70. package/eslint-rules/CLAUDE.md.spec.ts +3 -0
  71. package/package.json +1 -1
  72. package/src/adapters/latex/abstract.ts +3 -1
  73. package/src/adapters/latex/index.ts +3 -0
  74. package/src/adapters/latex/macros.test.ts +31 -0
  75. package/src/adapters/latex/macros.ts +43 -0
  76. package/src/adapters/osf/cassette/README.md +20 -0
  77. package/src/adapters/osf/cassette/get-file.json +108 -0
  78. package/src/adapters/osf/cassette/get-listing.json +111 -0
  79. package/src/adapters/osf/cassette/get-missing.json +1 -0
  80. package/src/adapters/osf/cassette/put-new.json +31 -0
  81. package/src/adapters/osf/host.io.ts +156 -0
  82. package/src/adapters/osf/host.test.ts +274 -0
  83. package/src/adapters/osf/index.ts +14 -0
  84. package/src/adapters/osf/response.ts +105 -0
  85. package/src/artifact-upload-rule.test.ts +213 -0
  86. package/src/artifact-upload-rule.ts +213 -0
  87. package/src/artifact.test.ts +504 -0
  88. package/src/artifact.ts +402 -0
  89. package/src/cli.test.ts +271 -1
  90. package/src/cli.ts +168 -23
  91. package/src/domain/artifact-upload.test.ts +80 -0
  92. package/src/domain/artifact-upload.ts +111 -0
  93. package/src/domain/paper-dirs.test.ts +91 -0
  94. package/src/domain/paper-dirs.ts +62 -0
  95. package/src/new-paper.test.ts +8 -2
  96. package/src/paper-files.test.ts +88 -0
  97. package/src/paper-files.ts +98 -9
  98. package/src/paper-settings-commands.test.ts +18 -0
  99. package/src/ports/artifact-host.ts +65 -0
  100. package/src/ports/latex.ts +10 -0
  101. package/src/rule-cases.test.ts +44 -0
  102. package/src/submission-confirm-hook.test.ts +113 -1
  103. package/src/submission-confirm-hook.ts +120 -27
  104. package/src/types.ts +6 -0
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Which papers a path given to `paperlint lint` reaches (#582). One owner for the question, so the
3
+ * claimed scope, the papers' own settings and the record checks cannot disagree about it.
4
+ *
5
+ * The rule, every case of which is a row in `paper-dirs.test.ts`:
6
+ * - a paper is a folder with `paper.tex` or `PIPELINE-STATUS.md` at its top. `paperlint.json` alone
7
+ * is the project's settings, not a paper;
8
+ * - a path inside a paper (the paper itself, a review card, its `reviews/`) reaches the nearest
9
+ * paper at or above it, looking only up, so a snapshot kept beside the card never stands in for
10
+ * the paper the card belongs to;
11
+ * - any other folder (the project root, a papers directory, an archive) reaches the papers below
12
+ * it, at any depth; the walk stops at each paper, so a copy kept inside one is never a paper;
13
+ * - nothing under a folder named `extra/` is a paper, the same reach as lint's own ignore.
14
+ */
15
+ import { unique } from "remeda";
16
+ import { dirname, join, sep } from "node:path";
17
+ import { STATUS_FILE } from "./paper-folder.ts";
18
+ import { ESCAPE_HATCH } from "./paper-layout.ts";
19
+ import { MAIN_FILE } from "./paper-sources.ts";
20
+ import { absolutePath } from "./paths.ts";
21
+ import type { IsFile } from "./paper-folder.ts";
22
+
23
+ /** The two questions the rule asks of the disk. */
24
+ export interface PaperTree extends IsFile {
25
+ /** The folders a walk enters below `dir`: not hidden, not installed packages, not `extra/`. */
26
+ subfolders(dir: string): readonly string[];
27
+ }
28
+
29
+ /** The files that make a folder a paper. */
30
+ export const PAPER_MARKERS: readonly string[] = [MAIN_FILE, STATUS_FILE];
31
+
32
+ const underExtra = (dir: string): boolean =>
33
+ dir.split(sep).includes(ESCAPE_HATCH);
34
+
35
+ export const isPaper = (dir: string, tree: IsFile): boolean =>
36
+ !underExtra(dir) &&
37
+ PAPER_MARKERS.some((m) => tree.isFile(absolutePath(join(dir, m))));
38
+
39
+ /** The nearest paper at or above `dir`; null when there is none. */
40
+ export const paperOwning = (dir: string, tree: IsFile): string | null => {
41
+ if (isPaper(dir, tree)) return dir;
42
+ const parent = dirname(dir);
43
+ return parent === dir ? null : paperOwning(parent, tree);
44
+ };
45
+
46
+ /** The papers below `dir`, at any depth, not looking inside any paper it finds. */
47
+ export const papersBelow = (dir: string, tree: PaperTree): readonly string[] =>
48
+ tree
49
+ .subfolders(dir)
50
+ .flatMap((d) => (isPaper(d, tree) ? [d] : papersBelow(d, tree)));
51
+
52
+ /** The papers the absolute folders `dirs` reach, each once, in the order they were reached. */
53
+ export const papersReached = (
54
+ dirs: readonly string[],
55
+ tree: PaperTree,
56
+ ): readonly string[] =>
57
+ unique(
58
+ dirs.flatMap((d) => {
59
+ const owner = paperOwning(d, tree);
60
+ return owner === null ? papersBelow(d, tree) : [owner];
61
+ }),
62
+ );
@@ -842,7 +842,8 @@ describe("paperlint lint — a scaffolded paper has no layout finding", () => {
842
842
 
843
843
  describe("paperlint lint — extra/ is never read", () => {
844
844
  // An archived snapshot of an older paper carries every marker a paper does. Under extra/ it is
845
- // spillover the layout promises never to judge; anywhere else its folder reads as a paper root.
845
+ // spillover the layout promises never to judge; anywhere else inside the paper it is a copy, and
846
+ // lint claims only the paper's own files (#582).
846
847
  const SNAPSHOT = (dir: string) => ({
847
848
  [`${dir}/PIPELINE-STATUS.md`]: "# Pipeline status\n",
848
849
  [`${dir}/notes.txt`]: "x\n",
@@ -853,8 +854,13 @@ describe("paperlint lint — extra/ is never read", () => {
853
854
  expect(ids).toEqual(["pdf/measured", "paper/sources-fresh"]);
854
855
  });
855
856
 
856
- it("the same snapshot outside extra/ is reported, so the test above can fail", async () => {
857
+ it("the same snapshot elsewhere in the paper is a copy, not a paper: no rule reads it either (#582)", async () => {
857
858
  const { ids } = await lintScaffold(SNAPSHOT("research/old-2025"));
859
+ expect(ids).toEqual(["pdf/measured", "paper/sources-fresh"]);
860
+ });
861
+
862
+ it("a stray file at the paper's own top level is reported, so the two tests above can fail", async () => {
863
+ const { ids } = await lintScaffold({ "notes.txt": "x\n" });
858
864
  expect(ids).toContain("paper/allowed-files-only");
859
865
  });
860
866
  });
@@ -25,15 +25,103 @@ import {
25
25
  narrowToOwners,
26
26
  ownedPatterns,
27
27
  ownedScopes,
28
+ paperFiles,
29
+ papersScope,
30
+ rebaseGlob,
28
31
  ruleOwners,
29
32
  scopeToOwned,
30
33
  } from "./paper-files.ts";
34
+ import { FRAGMENT_FILES } from "./paper-includes.ts";
35
+
31
36
  import { lintReport } from "../test/lint-report.ts";
32
37
  import { z } from "zod";
33
38
 
34
39
  /** What `calculateConfigForFile` answers for a file inside the config's scope, read for its rules. */
35
40
  const Computed = z.object({ rules: z.record(z.string(), z.unknown()) });
36
41
 
42
+ describe("the papers the config claims (#582)", () => {
43
+ it("🔴 GUARD: with papers named, every file a block of paperlint's own claims is one of theirs", () => {
44
+ // A block written the old way, `**/paper.tex`, would claim a copy of a paper kept inside it (a
45
+ // review snapshot, a build copy) as a paper of its own. The fragment block is scoped per paper
46
+ // by name instead (includeBlocks), so its glob is not a paper's.
47
+ const claimed = ownedPatterns(
48
+ buildConfig(
49
+ {},
50
+ texLanguage,
51
+ papersScope(["/w/papers/p", "/w/papers/q"], "/w"),
52
+ ),
53
+ ).filter((g) => !FRAGMENT_FILES.includes(g));
54
+ expect(
55
+ claimed.filter(
56
+ (g) => !g.startsWith("papers/p/") && !g.startsWith("papers/q/"),
57
+ ),
58
+ ).toEqual([]);
59
+ expect(claimed).toContain("papers/q/paper.tex");
60
+ });
61
+
62
+ it("names each paper relative to ESLint's cwd, glob characters escaped, and puts its files under it", () => {
63
+ const scope = papersScope(
64
+ ["/w/papers/p", "/w/papers/[draft] x*", "/w"],
65
+ "/w",
66
+ );
67
+ expect(paperFiles(scope, "reviews/*.md")).toEqual([
68
+ "papers/p/reviews/*.md",
69
+ "papers/\\[draft\\] x\\*/reviews/*.md",
70
+ "reviews/*.md",
71
+ ]);
72
+ expect(paperFiles({ kind: "any" }, "paper.tex")).toEqual(["**/paper.tex"]);
73
+ });
74
+ });
75
+
76
+ describe("a paper's own settings read from its folder (#582)", () => {
77
+ it.each([
78
+ ["the same folder", "papers/a/paper.tex", "/w", ["papers/a/paper.tex"]],
79
+ [
80
+ "a paper's own folder",
81
+ "papers/a/paper.tex",
82
+ "/w/papers/a",
83
+ ["paper.tex"],
84
+ ],
85
+ ["another paper's folder", "papers/a/paper.tex", "/w/papers/b", []],
86
+ ["a folder above cwd", "papers/a/paper.tex", "/", ["w/papers/a/paper.tex"]],
87
+ [
88
+ "any folder",
89
+ "**/siblings/README.md",
90
+ "/w/papers/a",
91
+ ["**/siblings/README.md"],
92
+ ],
93
+ ])(
94
+ "rebases a cwd-relative glob onto a block's basePath: %s",
95
+ (_, glob, base, want) => {
96
+ expect(rebaseGlob(glob, "/w", base)).toEqual(want);
97
+ },
98
+ );
99
+
100
+ it("a paper's own block gets its paper's files, relative to its folder, and none of another paper's", () => {
101
+ const own = buildConfig(
102
+ {},
103
+ texLanguage,
104
+ papersScope(["/w/papers/a"], "/w"),
105
+ );
106
+ const scope = papersScope(["/w/papers/a"], "/w");
107
+ const block = (basePath: string) =>
108
+ narrowToOwners(
109
+ { basePath, rules: { "paper/stages": "warn" } },
110
+ ruleOwners(own),
111
+ scope,
112
+ );
113
+ expect(block("/w/papers/a")).toEqual([
114
+ {
115
+ basePath: "/w/papers/a",
116
+ files: ["PIPELINE-STATUS.md"],
117
+ rules: { "paper/stages": "warn" },
118
+ },
119
+ ]);
120
+ // ESLint refuses an empty `files`, so a block that can reach no claimed file is not emitted.
121
+ expect(block("/w/papers/b")).toEqual([]);
122
+ });
123
+ });
124
+
37
125
  const dirs: string[] = [];
38
126
  afterEach(() => {
39
127
  for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true });
@@ -40,8 +40,71 @@
40
40
  * - later global-ignore patterns win, across blocks, in config order;
41
41
  * - `files: [["a", "b"]]` matches a file only when BOTH patterns match.
42
42
  */
43
+ import { relative, sep } from "node:path";
43
44
  import type { ConfigBlock, RuleBlock, RuleEntry } from "./rules-config.ts";
44
45
 
46
+ /**
47
+ * Which papers' own files paperlint's blocks claim. `any` is the config's SHAPE, for the rule list and
48
+ * the docs: a file in any folder. `papers` is what `paperlint lint` runs on: the real papers, as glob
49
+ * prefixes relative to ESLint's `cwd` ("" for `cwd` itself), so a copy of a paper kept inside one (a
50
+ * review snapshot, a build copy) is claimed by no block (#582).
51
+ */
52
+ export type PaperScope =
53
+ | { readonly kind: "any" }
54
+ | {
55
+ readonly kind: "papers";
56
+ readonly cwd: string;
57
+ readonly prefixes: readonly string[];
58
+ };
59
+
60
+ export const ANY_PAPER: PaperScope = { kind: "any" };
61
+
62
+ /** The characters a glob reads as syntax, escaped so a folder's name matches only itself. Pure. */
63
+ const literalGlob = (path: string): string =>
64
+ path.replace(/[\\*?[\]{}()!+@]/gu, "\\$&");
65
+
66
+ /** `to` relative to `from`, `/`-separated. Pure. */
67
+ const posixRelative = (from: string, to: string): string =>
68
+ relative(from, to).split(sep).join("/");
69
+
70
+ /** The papers `dirs` under ESLint's `cwd`: the scope `paperlint lint` lints. Pure. */
71
+ export const papersScope = (
72
+ dirs: readonly string[],
73
+ cwd: string,
74
+ ): PaperScope => ({
75
+ kind: "papers",
76
+ cwd,
77
+ prefixes: dirs.map((d) => literalGlob(posixRelative(cwd, d))),
78
+ });
79
+
80
+ /** A glob of a paper's own file (`paper.tex`, `reviews/*.md`) in each paper of `scope`. Pure. */
81
+ export const paperFiles = (
82
+ scope: PaperScope,
83
+ glob: string,
84
+ ): readonly string[] =>
85
+ scope.kind === "any"
86
+ ? [`**/${glob}`]
87
+ : scope.prefixes.map((p) => (p === "" ? glob : `${p}/${glob}`));
88
+
89
+ /**
90
+ * A glob relative to `cwd`, as the block whose `basePath` is `base` must write it — ESLint reads a
91
+ * block's patterns from its `basePath`, and a paper's own settings carry the paper's folder. None
92
+ * when the glob names files outside `base`: that block can never reach them. A glob that starts with
93
+ * `**` matches at any depth and is kept as it is. Pure.
94
+ */
95
+ export const rebaseGlob = (
96
+ glob: string,
97
+ cwd: string,
98
+ base: string,
99
+ ): readonly string[] => {
100
+ if (glob.startsWith("**")) return [glob];
101
+ const up = posixRelative(base, cwd);
102
+ if (!up.startsWith(".."))
103
+ return [up === "" ? glob : `${literalGlob(up)}/${glob}`];
104
+ const down = `${literalGlob(posixRelative(cwd, base))}/`;
105
+ return glob.startsWith(down) ? [glob.slice(down.length)] : [];
106
+ };
107
+
45
108
  /**
46
109
  * A set of files paperlint lints: an own block's globs and the exceptions that block makes. A file is
47
110
  * in it when it matches one of `files` and none of `ignores`.
@@ -158,6 +221,7 @@ export function ruleOwners(
158
221
  export function narrowToOwners(
159
222
  block: RuleBlock,
160
223
  owners: ReadonlyMap<string, readonly OwnedScope[]>,
224
+ papers: PaperScope = ANY_PAPER,
161
225
  ): ScopedBlock[] {
162
226
  // Keyed by the owner's JSON, so rules with equal owners share one group of blocks.
163
227
  const groups = new Map<string, Record<string, RuleEntry>>();
@@ -170,24 +234,49 @@ export function narrowToOwners(
170
234
  ownerOf.set(key, owner);
171
235
  }
172
236
  return [...ownerOf].flatMap(([key, owner]) =>
173
- owner.map((scope) => within(block, scope, { ...groups.get(key) })),
237
+ owner.flatMap((scope) =>
238
+ within(block, rebased(scope, papers, block.basePath), {
239
+ ...groups.get(key),
240
+ }),
241
+ ),
174
242
  );
175
243
  }
176
244
 
177
- /** `block`'s rules over the files both it and `scope` claim, minus both sets of exceptions. */
245
+ /**
246
+ * `scope` as the block with `basePath` `base` must write it. The scope's globs are relative to ESLint's
247
+ * `cwd`; a paper's own settings are read from the paper's folder (#582).
248
+ */
249
+ function rebased(
250
+ scope: OwnedScope,
251
+ papers: PaperScope,
252
+ base: string,
253
+ ): OwnedScope {
254
+ if (papers.kind === "any") return scope;
255
+ const onto = (globs: readonly string[]): readonly string[] =>
256
+ globs.flatMap((g) => rebaseGlob(g, papers.cwd, base));
257
+ return { files: onto(scope.files), ignores: onto(scope.ignores) };
258
+ }
259
+
260
+ /**
261
+ * `block`'s rules over the files both it and `scope` claim, minus both sets of exceptions; none when
262
+ * the scope claims no file the block can reach (ESLint refuses an empty `files`).
263
+ */
178
264
  function within(
179
265
  block: RuleBlock,
180
266
  scope: OwnedScope,
181
267
  rules: Readonly<Record<string, RuleEntry>>,
182
- ): ScopedBlock {
268
+ ): readonly ScopedBlock[] {
269
+ if (scope.files.length === 0) return [];
183
270
  const files: readonly FilesEntry[] = block.files
184
271
  ? block.files.flatMap((f) => scope.files.map((o) => [f, o]))
185
272
  : scope.files;
186
273
  const ignores = [...(block.ignores ?? []), ...scope.ignores];
187
- return {
188
- basePath: block.basePath,
189
- files,
190
- ...(ignores.length ? { ignores } : {}),
191
- rules,
192
- };
274
+ return [
275
+ {
276
+ basePath: block.basePath,
277
+ files,
278
+ ...(ignores.length ? { ignores } : {}),
279
+ rules,
280
+ },
281
+ ];
193
282
  }
@@ -98,6 +98,24 @@ describe("🔴 an optional rule that reaches no paper — judged against the PRO
98
98
  });
99
99
  });
100
100
 
101
+ describe("paperlint lint — `rules` in a paper's paperlint.json as a list of blocks (#582)", () => {
102
+ it("turns a rule on for that paper alone, globs relative to the paper", async () => {
103
+ const root = project({
104
+ "papers/a/paperlint.json": JSON.stringify({
105
+ rules: [
106
+ {
107
+ files: ["paper.tex"],
108
+ rules: { "pdf/last-page-balance": "error" },
109
+ },
110
+ ],
111
+ }),
112
+ });
113
+ const r = await lint(root);
114
+ expect(rulesIn(r.out, "a")).toContain("pdf/last-page-balance");
115
+ expect(rulesIn(r.out, "b")).not.toContain("pdf/last-page-balance");
116
+ });
117
+ });
118
+
101
119
  describe("paperlint lint — `rules` in a paper's paperlint.json", () => {
102
120
  it("turns an optional rule on for that paper alone", async () => {
103
121
  const root = project({
@@ -0,0 +1,65 @@
1
+ /**
2
+ * A host that keeps a paper's reproduction artifact — the port `paperlint artifact upload|show` talk
3
+ * through. Shaped by what the two commands need (put one file there, read one file's hashes back),
4
+ * not by any host's API; one adapter per host (`src/adapters/osf/`), listed in one place, the root's
5
+ * `ARTIFACT_HOSTS`. The rule `artifact/upload-current` never uses it: it reads the upload record.
6
+ */
7
+ import type { Result } from "../domain/result.ts";
8
+
9
+ /** A hash a host can give back for a file it holds. */
10
+ export type HashKind = "sha256" | "md5";
11
+
12
+ /** A file as the host holds it: its id there, its page, and the hashes the host gave. */
13
+ export interface HostedFile {
14
+ readonly id: string;
15
+ readonly url: string;
16
+ readonly sha256: string | null;
17
+ readonly md5: string | null;
18
+ }
19
+
20
+ /** Why the host gave no answer to use. The token never appears in `detail`. */
21
+ export interface HostFailure {
22
+ readonly kind: "unreachable" | "refused" | "not-found" | "malformed";
23
+ readonly detail: string;
24
+ }
25
+
26
+ /** Where a file was put, or is to be found: the record's url, the file's name, the host's id of it. */
27
+ export interface Where {
28
+ readonly url: string;
29
+ readonly file: string;
30
+ readonly id: string | null;
31
+ }
32
+
33
+ /** An upload: the file, and the host's container for it (an OSF project's guid). */
34
+ export interface Upload {
35
+ readonly target: string;
36
+ readonly name: string;
37
+ readonly bytes: Uint8Array;
38
+ }
39
+
40
+ export interface ArtifactHost {
41
+ /** What this host's adapter can do: upload, and which hashes it reads back (none: cannot check). */
42
+ readonly can: {
43
+ readonly upload: boolean;
44
+ readonly hashes: readonly HashKind[];
45
+ };
46
+ /** The environment variable the token is read from; the site-less one refused by name. */
47
+ readonly token: {
48
+ readonly variable: string;
49
+ readonly siteLess: string;
50
+ /** Where the author makes one, and with which permission, in the words the command prints. */
51
+ readonly help: string;
52
+ };
53
+ /** The container `upload` puts a file in, read off a record's url (an OSF project's guid); null when none. */
54
+ readonly targetOf: (url: string) => string | null;
55
+ /** The file's hashes as the host holds them now; a token only where the file is not public. */
56
+ readonly read: (
57
+ where: Where,
58
+ token: string | null,
59
+ ) => Promise<Result<HostedFile, HostFailure>>;
60
+ /** Put the file there: a new version of a file of the same name, else a new file. */
61
+ readonly upload: (
62
+ u: Upload,
63
+ token: string,
64
+ ) => Promise<Result<HostedFile, HostFailure>>;
65
+ }
@@ -48,6 +48,12 @@ export type AbstractProblem =
48
48
  readonly at: readonly number[];
49
49
  };
50
50
 
51
+ /** An argument-less macro the source defines, and its body as written. */
52
+ export interface MacroValue {
53
+ readonly name: string;
54
+ readonly value: string;
55
+ }
56
+
51
57
  export interface LatexReader {
52
58
  /** The source's `\documentclass`, as one of its states. */
53
59
  readonly documentClass: (src: string) => ClassLine;
@@ -143,4 +149,8 @@ export interface LatexReader {
143
149
  src: string,
144
150
  names: readonly string[],
145
151
  ) => readonly string[];
152
+ /** Each argument-less macro `src` defines, with its body as written, in source order. */
153
+ readonly macroValues: (src: string) => readonly MacroValue[];
154
+ /** The names of the macros `src` uses anywhere but in their own definition. */
155
+ readonly macrosUsed: (src: string) => readonly string[];
146
156
  }
@@ -13,9 +13,11 @@
13
13
  import { mkdirSync, readFileSync } from "node:fs";
14
14
  import { dirname, join } from "node:path";
15
15
  import { fileURLToPath } from "node:url";
16
+ import { omit } from "remeda";
16
17
  import { describe, expect, it } from "vitest";
17
18
  import { z } from "zod";
18
19
  import { run, rulePlugins } from "./cli.ts";
20
+ import { uploadRecordText } from "./domain/artifact-upload.ts";
19
21
  import { sha256Hex } from "./domain/sha256.ts";
20
22
  import { lockText, type LockEntry } from "./domain/versions.ts";
21
23
  import type { StudyMode } from "./domain/study-mode.ts";
@@ -833,7 +835,37 @@ const ARTIFACT_FILES: Readonly<Record<string, string>> = {
833
835
  const REQUIRED = ["README", "LICENSE"];
834
836
  const PROMISES = { prompts: "**/prompts/*.md" };
835
837
 
838
+ /** A paper that prints \\nRepos from numbersdef.tex, the rule on, and an upload record of `nRepos`. */
839
+ const withUpload = (nRepos: string): Record<string, string> =>
840
+ paper(tex("We read \\nRepos{} repositories."), {
841
+ [`${P}/paperlint.json`]: JSON.stringify({
842
+ rules: {
843
+ "artifact/upload-current": ["warn", { numbers: "numbersdef.tex" }],
844
+ },
845
+ }),
846
+ [`${P}/numbersdef.tex`]: "\\newcommand{\\nRepos}{64}\n",
847
+ [`${P}/submission/artifact-upload.json`]: uploadRecordText({
848
+ version: 1,
849
+ host: "other",
850
+ url: "https://example.org/artifact",
851
+ file: "artifact.zip",
852
+ uploadedAt: "2026-11-01T10:00:00Z",
853
+ numbers: { nRepos },
854
+ }),
855
+ });
856
+
836
857
  const CASES: Readonly<Record<string, RuleCases>> = {
858
+ // The upload was built when the paper printed 63 repositories; it prints 64 now.
859
+ "artifact/upload-current": {
860
+ reports: {
861
+ tree: withUpload("63"),
862
+ file: `${P}/PIPELINE-STATUS.md`,
863
+ severity: 1,
864
+ line: 1,
865
+ },
866
+ // The upload of the numbers the paper prints.
867
+ silent: withUpload("64"),
868
+ },
837
869
  // A paper that requires README and LICENSE of an artifact holding only a README.
838
870
  "artifact/required-files": {
839
871
  reports: {
@@ -1947,6 +1979,18 @@ describe("the term rules are off by default", () => {
1947
1979
  });
1948
1980
  });
1949
1981
 
1982
+ describe("artifact/upload-current is off by default", () => {
1983
+ it("🔴 a stale upload record says nothing until the paper turns the rule on", async () => {
1984
+ const off = omit(withUpload("63"), [`${P}/paperlint.json`]);
1985
+ const ids = async (tree: Record<string, string>) =>
1986
+ (await lintTree(tree)).map((m) => m.ruleId);
1987
+ // Guards: off means silent — the same stale record, the rule not named.
1988
+ expect(await ids(off)).not.toContain("artifact/upload-current");
1989
+ // Guards: and the record is not what silences it: turned on, it reports.
1990
+ expect(await ids(withUpload("63"))).toContain("artifact/upload-current");
1991
+ });
1992
+ });
1993
+
1950
1994
  describe("study/declare-sample is off by default", () => {
1951
1995
  it("is silent on an empty prereg.json until the paper turns it on", async () => {
1952
1996
  const study = {
@@ -9,7 +9,7 @@ import type { AbsolutePath } from "./domain/paths.ts";
9
9
  import { sha256Hex } from "./domain/sha256.ts";
10
10
  import type { Files } from "./ports/files.ts";
11
11
  import { leafCommandsNormalized as shellLeaves } from "vigiles/hook";
12
- import { submissionSend } from "./cli.ts";
12
+ import { submissionSend, uploadSend } from "./cli.ts";
13
13
  import { presetsDir } from "./package-dirs.ts";
14
14
  import {
15
15
  submissionConfirm as confirmWith,
@@ -43,6 +43,7 @@ const submissionConfirm = (
43
43
  portalHosts: () => HOSTS,
44
44
  shellLeaves,
45
45
  readSend: submissionSend,
46
+ readUpload: uploadSend,
46
47
  ...more,
47
48
  });
48
49
 
@@ -830,3 +831,114 @@ test("the approved command start is compared as written; the host in any case",
830
831
  decide(`Run ${command.replace("paper.pdf", "PAPER.PDF")} on hotcrp.com?`),
831
832
  ).toBe("deny");
832
833
  });
834
+
835
+ // ── an artifact upload that saves is a send ──────────────────────────────────────────────
836
+
837
+ const ZIP = new TextEncoder().encode("zip bytes");
838
+ const ZIP_SHA = sha256Hex(ZIP).slice(0, 12);
839
+ const UPLOAD =
840
+ "npx paperlint artifact upload --to osf a.zip --node abcde papers/p --save";
841
+ const withZip = (lines: readonly string[], command = UPLOAD) =>
842
+ submissionConfirm(
843
+ payload(command),
844
+ memoryFiles({ [T]: `${lines.join("\n")}\n`, "/w/a.zip": ZIP }),
845
+ )?.hookSpecificOutput.permissionDecisionReason ?? null;
846
+
847
+ test("🔴 artifact upload --save, no yes: refused, naming the folder and the file's sha256 to ask about", () => {
848
+ // Guards: the whole refusal an agent reads.
849
+ expect(withZip([])).toBe(
850
+ [
851
+ "Not run: this uploads the paper's artifact to its host, and the person has not said yes to it since the last send.",
852
+ "paper folder: /w/papers/p",
853
+ `artifact: a.zip, sha256 ${ZIP_SHA}`,
854
+ "to: osf project abcde",
855
+ "Ask the person with AskUserQuestion first, then run this command again. In the question, give the paper folder (the full path), the artifact's file and sha256, and the project, as written above.",
856
+ 'Options: "Yes, upload it" and "No". One yes lets one upload through.',
857
+ ].join("\n"),
858
+ );
859
+ });
860
+
861
+ test("artifact upload --save runs after a yes naming its folder, sha256 and project, once; the dry run is never gated", () => {
862
+ const yes = question(
863
+ "q1",
864
+ `Upload a.zip (paper folder /w/papers/p, sha256 ${ZIP_SHA}) to osf project abcde?`,
865
+ "Yes, upload it",
866
+ );
867
+ // Guards: a yes lets it through.
868
+ expect(withZip(yes)).toBe(null);
869
+ // Guards: an earlier upload uses that yes up.
870
+ expect(withZip([...yes, ...bash("b1", UPLOAD)])).toMatch(
871
+ /^Not run: this uploads/u,
872
+ );
873
+ // Guards: without --save, and record/show, nothing is asked.
874
+ expect(
875
+ withZip([], "npx paperlint artifact upload --to osf a.zip papers/p"),
876
+ ).toBe(null);
877
+ expect(
878
+ withZip(
879
+ [],
880
+ "npx paperlint artifact record a.zip --url https://x.org --save",
881
+ ),
882
+ ).toBe(null);
883
+ });
884
+
885
+ test("🔴 a yes to one project does not approve an upload to another", () => {
886
+ const yes = question(
887
+ "q1",
888
+ `Upload a.zip (paper folder /w/papers/p, sha256 ${ZIP_SHA}) to osf project abcde?`,
889
+ "Yes, upload it",
890
+ );
891
+ const elsewhere = UPLOAD.replace("abcde", "zzzzz");
892
+ // Guards: the same folder and file, another --node: the yes does not cover it.
893
+ expect(withZip(yes, elsewhere)).toMatch(/^Not run: this uploads/u);
894
+ // Guards: a longer id that starts with the approved one is another project too.
895
+ expect(withZip(yes, UPLOAD.replace("abcde", "abcdef"))).toMatch(
896
+ /^Not run: this uploads/u,
897
+ );
898
+ });
899
+
900
+ test("artifact upload --save with a flag before the subcommand is a send too: refused without a yes, and it uses a yes up", () => {
901
+ const before =
902
+ "npx paperlint artifact --to osf upload a.zip --node abcde papers/p --save";
903
+ // Guards: the CLI reads the subcommand wherever the flags put it, so the hook must too.
904
+ expect(withZip([], before)).toMatch(/^Not run: this uploads/u);
905
+ const yes = question(
906
+ "q1",
907
+ `Upload a.zip (paper folder /w/papers/p, sha256 ${ZIP_SHA}) to project abcde?`,
908
+ "Yes, upload it",
909
+ );
910
+ // Guards: it runs on a yes, and an earlier one of its kind used that yes.
911
+ expect(withZip(yes, before)).toBe(null);
912
+ expect(withZip([...yes, ...bash("b1", before)])).toMatch(
913
+ /^Not run: this uploads/u,
914
+ );
915
+ });
916
+
917
+ test("artifact upload --save of a file that is not there, or words that do not parse: refused, nothing to ask about", () => {
918
+ // Guards: a missing file has no sha256 to ask about.
919
+ expect(
920
+ withZip(
921
+ [],
922
+ "npx paperlint artifact upload --to osf gone.zip --node abcde --save",
923
+ ),
924
+ ).toBe(
925
+ [
926
+ "Not run: this uploads the paper's artifact to its host, and paperlint cannot find the file it uploads, so there is no sha256 to ask the person about.",
927
+ "paper folder: /w",
928
+ "artifact: gone.zip — NOT FOUND",
929
+ "to: osf project abcde",
930
+ "Name the paper folder and the file plainly (no cd, no $…), run the dry run, and ask then.",
931
+ ].join("\n"),
932
+ );
933
+ // Guards: an upload naming no file or no project, a stray operand, or an unknown flag is unresolved.
934
+ [
935
+ "artifact upload --node abcde --save",
936
+ "artifact upload --to osf a.zip papers/p --save",
937
+ "artifact upload a.zip --node abcde p extra --save",
938
+ "artifact upload a.zip --node abcde --nope --save",
939
+ ].forEach((c) => {
940
+ expect(withZip([], `npx paperlint ${c}`)).toMatch(
941
+ /could not resolve which PDF this send uploads/u,
942
+ );
943
+ });
944
+ });