paperlint 18.4.1 → 18.6.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 (113) hide show
  1. package/CLAUDE.md +6 -2
  2. package/dist/adapters/hotcrp/portal.io.d.ts.map +1 -1
  3. package/dist/adapters/hotcrp/portal.io.js +1 -0
  4. package/dist/adapters/hotcrp/portal.io.js.map +1 -1
  5. package/dist/adapters/hotcrp/response.d.ts.map +1 -1
  6. package/dist/adapters/hotcrp/response.js +15 -0
  7. package/dist/adapters/hotcrp/response.js.map +1 -1
  8. package/dist/adapters/latex/abstract.d.ts +11 -0
  9. package/dist/adapters/latex/abstract.d.ts.map +1 -1
  10. package/dist/adapters/latex/abstract.js +1 -1
  11. package/dist/adapters/latex/abstract.js.map +1 -1
  12. package/dist/adapters/latex/index.d.ts.map +1 -1
  13. package/dist/adapters/latex/index.js +3 -0
  14. package/dist/adapters/latex/index.js.map +1 -1
  15. package/dist/adapters/latex/macros.d.ts +6 -0
  16. package/dist/adapters/latex/macros.d.ts.map +1 -0
  17. package/dist/adapters/latex/macros.js +27 -0
  18. package/dist/adapters/latex/macros.js.map +1 -0
  19. package/dist/adapters/osf/host.io.d.ts +12 -0
  20. package/dist/adapters/osf/host.io.d.ts.map +1 -0
  21. package/dist/adapters/osf/host.io.js +119 -0
  22. package/dist/adapters/osf/host.io.js.map +1 -0
  23. package/dist/adapters/osf/index.d.ts +10 -0
  24. package/dist/adapters/osf/index.d.ts.map +1 -0
  25. package/dist/adapters/osf/index.js +10 -0
  26. package/dist/adapters/osf/index.js.map +1 -0
  27. package/dist/adapters/osf/response.d.ts +11 -0
  28. package/dist/adapters/osf/response.d.ts.map +1 -0
  29. package/dist/adapters/osf/response.js +87 -0
  30. package/dist/adapters/osf/response.js.map +1 -0
  31. package/dist/artifact-upload-rule.d.ts +66 -0
  32. package/dist/artifact-upload-rule.d.ts.map +1 -0
  33. package/dist/artifact-upload-rule.js +151 -0
  34. package/dist/artifact-upload-rule.js.map +1 -0
  35. package/dist/artifact.d.ts +35 -0
  36. package/dist/artifact.d.ts.map +1 -0
  37. package/dist/artifact.js +251 -0
  38. package/dist/artifact.js.map +1 -0
  39. package/dist/cli.d.ts +7 -0
  40. package/dist/cli.d.ts.map +1 -1
  41. package/dist/cli.js +99 -7
  42. package/dist/cli.js.map +1 -1
  43. package/dist/domain/artifact-upload.d.ts +44 -0
  44. package/dist/domain/artifact-upload.d.ts.map +1 -0
  45. package/dist/domain/artifact-upload.js +80 -0
  46. package/dist/domain/artifact-upload.js.map +1 -0
  47. package/dist/domain/submission.d.ts +4 -0
  48. package/dist/domain/submission.d.ts.map +1 -1
  49. package/dist/domain/submission.js.map +1 -1
  50. package/dist/eslint-rules/CLAUDE.md.spec.d.ts.map +1 -1
  51. package/dist/eslint-rules/CLAUDE.md.spec.js +1 -0
  52. package/dist/eslint-rules/CLAUDE.md.spec.js.map +1 -1
  53. package/dist/ports/artifact-host.d.ts +54 -0
  54. package/dist/ports/artifact-host.d.ts.map +1 -0
  55. package/dist/ports/artifact-host.js +2 -0
  56. package/dist/ports/artifact-host.js.map +1 -0
  57. package/dist/ports/latex.d.ts +9 -0
  58. package/dist/ports/latex.d.ts.map +1 -1
  59. package/dist/submission-confirm-hook.d.ts +11 -1
  60. package/dist/submission-confirm-hook.d.ts.map +1 -1
  61. package/dist/submission-confirm-hook.js +83 -21
  62. package/dist/submission-confirm-hook.js.map +1 -1
  63. package/dist/submission.d.ts +19 -2
  64. package/dist/submission.d.ts.map +1 -1
  65. package/dist/submission.js +121 -17
  66. package/dist/submission.js.map +1 -1
  67. package/dist/types.d.ts +6 -0
  68. package/dist/types.d.ts.map +1 -1
  69. package/docs/artifact-upload.md +124 -0
  70. package/docs/optional-rules.md +1 -0
  71. package/docs/osf-artifact.md +4 -1
  72. package/docs/rules/artifact/upload-current.md +85 -0
  73. package/docs/rules.md +1 -0
  74. package/docs/submission.md +19 -4
  75. package/eslint-rules/CLAUDE.md +5 -1
  76. package/eslint-rules/CLAUDE.md.spec.ts +3 -0
  77. package/package.json +1 -1
  78. package/src/adapters/hotcrp/portal.io.ts +1 -0
  79. package/src/adapters/hotcrp/portal.test.ts +43 -2
  80. package/src/adapters/hotcrp/response.ts +21 -0
  81. package/src/adapters/latex/abstract.ts +3 -1
  82. package/src/adapters/latex/index.ts +3 -0
  83. package/src/adapters/latex/macros.test.ts +31 -0
  84. package/src/adapters/latex/macros.ts +43 -0
  85. package/src/adapters/osf/cassette/README.md +20 -0
  86. package/src/adapters/osf/cassette/get-file.json +108 -0
  87. package/src/adapters/osf/cassette/get-listing.json +111 -0
  88. package/src/adapters/osf/cassette/get-missing.json +1 -0
  89. package/src/adapters/osf/cassette/put-new.json +31 -0
  90. package/src/adapters/osf/host.io.ts +156 -0
  91. package/src/adapters/osf/host.test.ts +274 -0
  92. package/src/adapters/osf/index.ts +14 -0
  93. package/src/adapters/osf/response.ts +105 -0
  94. package/src/artifact-upload-rule.test.ts +213 -0
  95. package/src/artifact-upload-rule.ts +213 -0
  96. package/src/artifact.test.ts +504 -0
  97. package/src/artifact.ts +402 -0
  98. package/src/cli.test.ts +149 -1
  99. package/src/cli.ts +121 -8
  100. package/src/domain/artifact-upload.test.ts +80 -0
  101. package/src/domain/artifact-upload.ts +111 -0
  102. package/src/domain/submission.ts +4 -0
  103. package/src/ports/artifact-host.ts +65 -0
  104. package/src/ports/latex.ts +10 -0
  105. package/src/rule-cases.test.ts +44 -0
  106. package/src/submission-confirm-hook.test.ts +113 -1
  107. package/src/submission-confirm-hook.ts +120 -27
  108. package/src/submission-fields-run.test.ts +1 -0
  109. package/src/submission-prior-reviews.test.ts +9 -1
  110. package/src/submission-show.test.ts +81 -0
  111. package/src/submission-update.test.ts +164 -6
  112. package/src/submission.ts +208 -24
  113. package/src/types.ts +6 -0
package/src/cli.ts CHANGED
@@ -193,6 +193,10 @@ import preregCoverage from "#eslint-rules/prereg-coverage";
193
193
  import { CYCLE_RULE_LEVELS, cycleRules } from "./cycle-rules.ts";
194
194
  import { EDITION_RULE_LEVELS, editionRules } from "./edition-rule.ts";
195
195
  import { ARTIFACT_RULE_LEVELS, artifactRules } from "./artifact-rules.ts";
196
+ import { artifactUploadRules } from "./artifact-upload-rule.ts";
197
+ import { runArtifact } from "./artifact.ts";
198
+ import { osfHost } from "./adapters/osf/index.ts";
199
+ import type { ArtifactHost } from "./ports/artifact-host.ts";
196
200
  import { changesRules } from "./changes-rule.ts";
197
201
  import { latexDiff, withTexBin } from "./adapters/latexdiff/index.ts";
198
202
  import { runVersions } from "./versions-command.ts";
@@ -238,6 +242,7 @@ import {
238
242
  import {
239
243
  submissionConfirm,
240
244
  UNREADABLE_INPUT,
245
+ type Upload,
241
246
  } from "./submission-confirm-hook.ts";
242
247
  import { leafCommandsNormalized } from "vigiles/hook";
243
248
  import {
@@ -303,16 +308,27 @@ const USAGE = `paperlint — machine-checkable gates for a paper kept in git
303
308
  npx paperlint submission show [paper]
304
309
  the paper's submission on the venue's portal: status, title,
305
310
  type, topics, abstract length, the PDF the portal holds, and
306
- whether it is the local paper.pdf (sha256)
311
+ whether it is the local paper.pdf (sha256); flags a title,
312
+ abstract or authors that are not the paper's
307
313
  npx paperlint submission update [paper] [--pdf <file>] [--abstract <file>] [--submit] [--save]
308
- send the PDF (default: the paper's own), an abstract, or
309
- "submitted". A DRY RUN unless --save: the portal checks the
314
+ send the PDF (default: the paper's own), the paper's title
315
+ and abstract each when the portal holds another (--abstract:
316
+ that file's text instead), or "submitted". A DRY RUN unless --save: the portal checks the
310
317
  change and keeps nothing. First prints what the venue rules find
311
318
  in that exact PDF, as lint does; --save refuses a PDF the last
312
319
  build did not measure (exit 2)
313
320
  npx paperlint submission topics [paper]
314
321
  the topics the venue's portal offers, against the ones its
315
322
  preset records; exit 1 when they differ
323
+ npx paperlint artifact record <zip> --url <url> [--host <name>] [--numbers <file>] [paper]
324
+ write the upload record (submission/artifact-upload.json): the
325
+ zip's sha256 and md5, and the numbers the paper prints now. Any
326
+ host, no network; artifact/upload-current reads it
327
+ npx paperlint artifact upload --to osf <zip> [--node <id>] [paper] [--save]
328
+ upload the zip and write the same record with the host's own
329
+ hashes. A DRY RUN unless --save. Token: OSF_TOKEN_OSF_IO
330
+ npx paperlint artifact show [paper] the record, and match yes/no against the hashes the host holds
331
+ now, where its adapter reads them (osf)
316
332
  npx paperlint versions [show|lock|migrate|approve|diff] [paper]
317
333
  the paper's frozen versions, one folder per attempt:
318
334
  versions/<cycle>/<stage>.{pdf,tex}. show (the default): each
@@ -566,6 +582,22 @@ const today = (now = new Date()): string =>
566
582
  String(now.getDate()).padStart(2, "0"),
567
583
  ].join("-");
568
584
 
585
+ /** What `artifact/upload-current` and `paperlint artifact record` read with. */
586
+ const UPLOAD_RULE_DEPS = {
587
+ files: nodeFiles,
588
+ codec: sourcesCodec,
589
+ latex: latexReader,
590
+ };
591
+
592
+ /**
593
+ * The `artifact` plugin: required-files and promised on for every paper, silent for one whose
594
+ * paperlint.json declares no `artifact`; upload-current on for no paper until its options turn it on.
595
+ */
596
+ const ARTIFACT_PLUGIN_RULES = {
597
+ ...artifactRules({ files: nodeFiles, listTree: nodeListTree }),
598
+ ...artifactUploadRules(UPLOAD_RULE_DEPS),
599
+ };
600
+
569
601
  /** What the talk rules read with: the disk, the shipped presets, and the three media readers. */
570
602
  const TALK_RULE_DEPS = {
571
603
  files: nodeFiles,
@@ -641,10 +673,7 @@ export function buildConfig(
641
673
  },
642
674
  },
643
675
  repro: { rules: REPRO_RULES },
644
- // On for every paper, silent for one whose paperlint.json declares no `artifact`.
645
- artifact: {
646
- rules: artifactRules({ files: nodeFiles, listTree: nodeListTree }),
647
- },
676
+ artifact: { rules: ARTIFACT_PLUGIN_RULES },
648
677
  // Registered, on for no paper: `"study/declare-sample": "error"` in paperlint.json turns it on.
649
678
  study: { rules: preregCoverage.rules },
650
679
  cycle: { rules: CYCLE_STATUS_RULES },
@@ -1164,6 +1193,11 @@ export function parseArgs(argv: readonly string[]): Args {
1164
1193
  abstract: null,
1165
1194
  submit: false,
1166
1195
  save: false,
1196
+ url: null,
1197
+ host: null,
1198
+ to: null,
1199
+ node: null,
1200
+ numbers: null,
1167
1201
  hooksMode: null,
1168
1202
  // -1 = warnings NEVER fail the run. In this set most findings are advisory by design, and a
1169
1203
  // gate that fails on advice gets muted entirely.
@@ -1256,13 +1290,27 @@ const SWITCHES: ReadonlyMap<
1256
1290
  /** The flags whose value is one string field of `Args`. */
1257
1291
  const STRING_FLAGS: ReadonlyMap<
1258
1292
  string,
1259
- "paper" | "venue" | "kind" | "pdf" | "abstract"
1293
+ | "paper"
1294
+ | "venue"
1295
+ | "kind"
1296
+ | "pdf"
1297
+ | "abstract"
1298
+ | "url"
1299
+ | "host"
1300
+ | "to"
1301
+ | "node"
1302
+ | "numbers"
1260
1303
  > = new Map([
1261
1304
  ["--paper", "paper"],
1262
1305
  ["--venue", "venue"],
1263
1306
  ["--kind", "kind"],
1264
1307
  ["--pdf", "pdf"],
1265
1308
  ["--abstract", "abstract"],
1309
+ ["--url", "url"],
1310
+ ["--host", "host"],
1311
+ ["--to", "to"],
1312
+ ["--node", "node"],
1313
+ ["--numbers", "numbers"],
1266
1314
  ]);
1267
1315
 
1268
1316
  /** The flags that take a value, in either spelling: `--flag value` or `--flag=value`. */
@@ -1403,6 +1451,7 @@ const IN_PROCESS_HOOKS: Readonly<
1403
1451
  portalHosts,
1404
1452
  shellLeaves: leafCommandsNormalized,
1405
1453
  readSend: submissionSend,
1454
+ readUpload: uploadSend,
1406
1455
  });
1407
1456
  } catch {
1408
1457
  return UNREADABLE_INPUT;
@@ -1430,6 +1479,24 @@ export function submissionSend(
1430
1479
  return clean ? { paper: a.paths[1] ?? null, pdf: a.pdf } : null;
1431
1480
  }
1432
1481
 
1482
+ /**
1483
+ * The words after `artifact`, read by this CLI's own parser, for an upload: the file it uploads, the
1484
+ * paper (null for the current folder), and the host and project it goes to — or null when they would
1485
+ * not run cleanly. `--save` uploads only to a project named on the command line (`artifact.ts`).
1486
+ */
1487
+ export function uploadSend(words: readonly string[]): Upload | null {
1488
+ const a = parseArgs(["artifact", ...words]);
1489
+ const [sub, file, paper, ...rest] = a.paths;
1490
+ const clean =
1491
+ a.missingValue === undefined &&
1492
+ a.unknownFlag === undefined &&
1493
+ sub === "upload" &&
1494
+ rest.length === 0;
1495
+ return clean && file !== undefined && a.to !== null && a.node !== null
1496
+ ? { paper: paper ?? null, artifact: file, host: a.to, project: a.node }
1497
+ : null;
1498
+ }
1499
+
1433
1500
  /**
1434
1501
  * `paperlint hook <name>` — run an editor hook. It exists for ONE thing: so that the wiring does not
1435
1502
  * address the runtime from the project root.
@@ -2177,6 +2244,20 @@ const SIMPLE: Readonly<
2177
2244
  log,
2178
2245
  err,
2179
2246
  }),
2247
+ artifact: (a, { log, err, cwd }) =>
2248
+ runArtifact(
2249
+ { ...a, sub: a.paths[0], operands: a.paths.slice(1) },
2250
+ {
2251
+ ...UPLOAD_RULE_DEPS,
2252
+ ruleEntry: uploadRuleEntry,
2253
+ hosts: ARTIFACT_HOSTS,
2254
+ env: (name) => process.env[name],
2255
+ now: isoNow,
2256
+ cwd,
2257
+ log,
2258
+ err,
2259
+ },
2260
+ ),
2180
2261
  submission: (a, { log, err, cwd }) =>
2181
2262
  runSubmission(
2182
2263
  {
@@ -2205,6 +2286,38 @@ const SIMPLE: Readonly<
2205
2286
  ),
2206
2287
  };
2207
2288
 
2289
+ /**
2290
+ * `artifact/upload-current`'s entry for the paper in `dir`, as ESLint computes it for the paper's
2291
+ * `PIPELINE-STATUS.md`, where the rule runs, under the config `paperlint lint` run there would use: one answer for the rule and the commands,
2292
+ * whichever shape the settings take (a `rules` object, a list of blocks, the project's or the
2293
+ * paper's). Undefined when the rule is not on there or the config does not read; lint says why.
2294
+ */
2295
+ async function uploadRuleEntry(dir: string): Promise<unknown> {
2296
+ // Quiet: a config that does not read is lint's to report, not this command's.
2297
+ const quiet = (): void => {};
2298
+ const cfg = readConfig(parseArgs(["lint"]), {
2299
+ log: quiet,
2300
+ err: quiet,
2301
+ cwd: dir,
2302
+ });
2303
+ if (cfg.code !== undefined) return undefined;
2304
+ const engine = await paperEslint(cfg, [dir], {
2305
+ loadTexLanguage: loadLatexLanguage,
2306
+ fix: false,
2307
+ stats: false,
2308
+ });
2309
+ if (!engine.ok) return undefined;
2310
+ const computed = ComputedConfig.parse(
2311
+ await engine.value.eslint.calculateConfigForFile(join(dir, STATUS_FILE)),
2312
+ );
2313
+ return computed?.rules?.["artifact/upload-current"];
2314
+ }
2315
+
2316
+ /** Every artifact host paperlint has an adapter for: a new host is its folder and one line here. */
2317
+ const ARTIFACT_HOSTS: Readonly<Record<string, ArtifactHost>> = {
2318
+ osf: osfHost(),
2319
+ };
2320
+
2208
2321
  /** The adapter of each portal kind — one per kind, chosen here at the root. */
2209
2322
  const PORTALS: Readonly<Record<PortalKind, (url: string) => PortalSite>> = {
2210
2323
  hotcrp: hotcrpSite,
@@ -0,0 +1,80 @@
1
+ import { omit } from "remeda";
2
+ import { expect, test } from "vitest";
3
+ import {
4
+ drift,
5
+ md5Hex,
6
+ parseUploadRecord,
7
+ uploadRecordText,
8
+ type UploadRecord,
9
+ } from "./artifact-upload.ts";
10
+
11
+ const RECORD: UploadRecord = {
12
+ version: 1,
13
+ host: "osf",
14
+ url: "https://osf.io/abcde/",
15
+ file: "artifact.zip",
16
+ id: "0123456789abcdef01234567",
17
+ sha256: "a".repeat(64),
18
+ md5: "b".repeat(32),
19
+ uploadedAt: "2026-11-01T10:00:00Z",
20
+ numbers: { nRepos: "63", pctPass: "41.2\\%" },
21
+ };
22
+
23
+ test("a record survives its own text: written, then read back whole", () => {
24
+ // Guards: the writer and the reader agree on every field.
25
+ expect(parseUploadRecord(uploadRecordText(RECORD))).toEqual({
26
+ ok: true,
27
+ value: RECORD,
28
+ });
29
+ });
30
+
31
+ test("a hand-written record without the optional fields is a record", () => {
32
+ const bare = omit(RECORD, ["id", "sha256", "md5"]);
33
+ // Guards: id and the hashes are optional; a host that gives none still has a record.
34
+ expect(parseUploadRecord(JSON.stringify(bare))).toEqual({
35
+ ok: true,
36
+ value: bare,
37
+ });
38
+ });
39
+
40
+ test("what is not a record is refused, saying which field and why", () => {
41
+ // Guards: text that is not JSON is named as such.
42
+ expect(parseUploadRecord("{")).toEqual({
43
+ ok: false,
44
+ error: "it is not JSON",
45
+ });
46
+ // Guards: an unknown version, an unknown key and a bad hash each name their path.
47
+ expect(
48
+ parseUploadRecord(
49
+ JSON.stringify({ ...RECORD, version: 2, sha256: "x", extra: 1 }),
50
+ ),
51
+ ).toEqual({
52
+ ok: false,
53
+ error:
54
+ 'version: Invalid input: expected 1; sha256: Invalid string: must match pattern /^[0-9a-f]{64}$/; the record: Unrecognized key: "extra"',
55
+ });
56
+ });
57
+
58
+ test("md5 as hosts print it", () => {
59
+ // Guards: the digest of the empty input, the one every md5 implementation agrees on.
60
+ expect(md5Hex(new Uint8Array())).toBe("d41d8cd98f00b204e9800998ecf8427e");
61
+ });
62
+
63
+ test("drift: keys the paper prints that the upload lacked or held with another value, used keys only", () => {
64
+ const current = new Map([
65
+ ["nRepos", "64"],
66
+ ["pctPass", "41.2\\%"],
67
+ ["nNew", "7"],
68
+ ["nUnused", "9"],
69
+ ]);
70
+ const used = new Set(["nRepos", "pctPass", "nNew"]);
71
+ // Guards: a changed value, a new key, and an unused new key that does not count.
72
+ expect(drift(RECORD.numbers, current, used)).toEqual({
73
+ added: ["nNew"],
74
+ changed: ["nRepos"],
75
+ });
76
+ // Guards: the paper as uploaded drifts nowhere.
77
+ expect(
78
+ drift(RECORD.numbers, new Map(Object.entries(RECORD.numbers)), used),
79
+ ).toEqual({ added: [], changed: [] });
80
+ });
@@ -0,0 +1,111 @@
1
+ /**
2
+ * THE UPLOAD RECORD — what an artifact host holds, written down once at upload time, so a lint rule
3
+ * can say later whether the paper still prints what that upload was built for. Pure.
4
+ *
5
+ * The record is a JSON file (default `<paper>/submission/artifact-upload.json`, docs/artifact-upload.md)
6
+ * that anyone may write: `paperlint artifact record`, `paperlint artifact upload --save`, the author's
7
+ * own script, or a hand. It is parsed here, once, into `UploadRecord`; nothing after reads the raw
8
+ * JSON. `numbers` is the paper's printed key → value map at upload time: every argument-less macro
9
+ * of the paper's numbers file, as written in its definition.
10
+ */
11
+ import { createHash } from "node:crypto";
12
+ import { z } from "zod";
13
+ import { err, ok, type Result } from "./result.ts";
14
+
15
+ /** The record's version: a reader refuses one it does not know rather than misread it. */
16
+ export const RECORD_VERSION = 1;
17
+
18
+ /** Where the record is, relative to the paper, unless the rule's `record` option names another. */
19
+ export const DEFAULT_RECORD = "submission/artifact-upload.json";
20
+
21
+ const Hex = (n: number) =>
22
+ z.string().regex(new RegExp(`^[0-9a-f]{${String(n)}}$`));
23
+
24
+ const Record = z.strictObject({
25
+ version: z.literal(RECORD_VERSION),
26
+ /** The host's name: `osf`, `zenodo`, `other`, … — a host paperlint has no adapter for is fine. */
27
+ host: z.string().min(1),
28
+ url: z.url(),
29
+ /** The uploaded file's name. */
30
+ file: z.string().min(1),
31
+ /** The host's own id of the file, when it has one (OSF: the file's id); lets `show` find it. */
32
+ id: z.string().min(1).optional(),
33
+ sha256: Hex(64).optional(),
34
+ md5: Hex(32).optional(),
35
+ uploadedAt: z.iso.datetime({ offset: true }),
36
+ numbers: z.record(z.string(), z.string()),
37
+ });
38
+
39
+ export type UploadRecord = Readonly<z.infer<typeof Record>>;
40
+
41
+ /** `json` as a record, or why it is not one, in words: which field and what is wrong with it. */
42
+ export function recordOf(json: unknown): Result<UploadRecord, string> {
43
+ const r = Record.safeParse(json);
44
+ return r.success
45
+ ? ok(r.data)
46
+ : err(
47
+ r.error.issues
48
+ .map((i) => `${i.path.join(".") || "the record"}: ${i.message}`)
49
+ .join("; "),
50
+ );
51
+ }
52
+
53
+ /** The record in `text`, or why it is not one, in words. */
54
+ export function parseUploadRecord(text: string): Result<UploadRecord, string> {
55
+ try {
56
+ return recordOf(JSON.parse(text));
57
+ } catch {
58
+ return err("it is not JSON");
59
+ }
60
+ }
61
+
62
+ /** The record as its file holds it: two-space JSON, keys in the order given, a final newline. */
63
+ export const uploadRecordText = (r: UploadRecord): string =>
64
+ `${JSON.stringify(r, null, 2)}\n`;
65
+
66
+ /** The md5 of `bytes`, as hosts print it: 32 lowercase hex digits. */
67
+ export const md5Hex = (bytes: Uint8Array): string =>
68
+ createHash("md5").update(bytes).digest("hex");
69
+
70
+ /**
71
+ * `used`, plus every macro of `values` that a used macro's definition names, at any depth
72
+ * (`repoCount` defined as `\nRepos` prints `nRepos` too). `usesIn` reads the names a definition
73
+ * uses. The set only grows and is bounded by `values`, so a cycle of definitions ends.
74
+ */
75
+ export const printedThrough = (
76
+ values: ReadonlyMap<string, string>,
77
+ used: ReadonlySet<string>,
78
+ usesIn: (definition: string) => readonly string[],
79
+ ): ReadonlySet<string> => {
80
+ const next = new Set([
81
+ ...used,
82
+ ...[...used].flatMap((k) =>
83
+ usesIn(values.get(k) ?? "").filter((u) => values.has(u)),
84
+ ),
85
+ ]);
86
+ return next.size === used.size ? used : printedThrough(values, next, usesIn);
87
+ };
88
+
89
+ /** What the paper prints now that the upload was not built for: keys it lacked, keys with another value. */
90
+ export interface Drift {
91
+ readonly added: readonly string[];
92
+ readonly changed: readonly string[];
93
+ }
94
+
95
+ /**
96
+ * The drift between the numbers recorded at upload and the paper's `current` ones, counting only the
97
+ * keys the paper uses: a macro defined and never printed never fires. Keys in source order.
98
+ */
99
+ export const drift = (
100
+ recorded: Readonly<Record<string, string>>,
101
+ current: ReadonlyMap<string, string>,
102
+ used: ReadonlySet<string>,
103
+ ): Drift => {
104
+ const printed = [...current].filter(([k]) => used.has(k));
105
+ return {
106
+ added: printed.filter(([k]) => !Object.hasOwn(recorded, k)).map(([k]) => k),
107
+ changed: printed
108
+ .filter(([k, v]) => Object.hasOwn(recorded, k) && recorded[k] !== v)
109
+ .map(([k]) => k),
110
+ };
111
+ };
@@ -86,6 +86,8 @@ export interface SubmissionView {
86
86
  readonly paperType: string | null;
87
87
  readonly topics: readonly string[];
88
88
  readonly abstract: string | null;
89
+ /** The authors the portal records, in its order; null when it does not say. */
90
+ readonly authors: readonly Author[] | null;
89
91
  /** The PDF the portal holds; null when none is uploaded. */
90
92
  readonly pdf: PortalDocument | null;
91
93
  /** Unix seconds; null when not submitted or not said. */
@@ -98,6 +100,8 @@ export interface SubmissionView {
98
100
  /** A change to send. Every absent part is left as the portal has it. */
99
101
  export interface SubmissionChange {
100
102
  readonly pdf: { readonly name: string; readonly bytes: Uint8Array } | null;
103
+ /** The paper's title, sent when it differs from the portal's; null leaves the portal's. */
104
+ readonly title: string | null;
101
105
  readonly abstract: string | null;
102
106
  /** Mark the submission submitted (ready for review). */
103
107
  readonly submit: boolean;
@@ -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 = {