paperlint 18.4.1 → 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 (90) 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 +7 -0
  34. package/dist/cli.d.ts.map +1 -1
  35. package/dist/cli.js +94 -4
  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/eslint-rules/CLAUDE.md.spec.d.ts.map +1 -1
  42. package/dist/eslint-rules/CLAUDE.md.spec.js +1 -0
  43. package/dist/eslint-rules/CLAUDE.md.spec.js.map +1 -1
  44. package/dist/ports/artifact-host.d.ts +54 -0
  45. package/dist/ports/artifact-host.d.ts.map +1 -0
  46. package/dist/ports/artifact-host.js +2 -0
  47. package/dist/ports/artifact-host.js.map +1 -0
  48. package/dist/ports/latex.d.ts +9 -0
  49. package/dist/ports/latex.d.ts.map +1 -1
  50. package/dist/submission-confirm-hook.d.ts +11 -1
  51. package/dist/submission-confirm-hook.d.ts.map +1 -1
  52. package/dist/submission-confirm-hook.js +83 -21
  53. package/dist/submission-confirm-hook.js.map +1 -1
  54. package/dist/types.d.ts +6 -0
  55. package/dist/types.d.ts.map +1 -1
  56. package/docs/artifact-upload.md +124 -0
  57. package/docs/optional-rules.md +1 -0
  58. package/docs/osf-artifact.md +4 -1
  59. package/docs/rules/artifact/upload-current.md +85 -0
  60. package/docs/rules.md +1 -0
  61. package/eslint-rules/CLAUDE.md +5 -1
  62. package/eslint-rules/CLAUDE.md.spec.ts +3 -0
  63. package/package.json +1 -1
  64. package/src/adapters/latex/abstract.ts +3 -1
  65. package/src/adapters/latex/index.ts +3 -0
  66. package/src/adapters/latex/macros.test.ts +31 -0
  67. package/src/adapters/latex/macros.ts +43 -0
  68. package/src/adapters/osf/cassette/README.md +20 -0
  69. package/src/adapters/osf/cassette/get-file.json +108 -0
  70. package/src/adapters/osf/cassette/get-listing.json +111 -0
  71. package/src/adapters/osf/cassette/get-missing.json +1 -0
  72. package/src/adapters/osf/cassette/put-new.json +31 -0
  73. package/src/adapters/osf/host.io.ts +156 -0
  74. package/src/adapters/osf/host.test.ts +274 -0
  75. package/src/adapters/osf/index.ts +14 -0
  76. package/src/adapters/osf/response.ts +105 -0
  77. package/src/artifact-upload-rule.test.ts +213 -0
  78. package/src/artifact-upload-rule.ts +213 -0
  79. package/src/artifact.test.ts +504 -0
  80. package/src/artifact.ts +402 -0
  81. package/src/cli.test.ts +149 -1
  82. package/src/cli.ts +116 -5
  83. package/src/domain/artifact-upload.test.ts +80 -0
  84. package/src/domain/artifact-upload.ts +111 -0
  85. package/src/ports/artifact-host.ts +65 -0
  86. package/src/ports/latex.ts +10 -0
  87. package/src/rule-cases.test.ts +44 -0
  88. package/src/submission-confirm-hook.test.ts +113 -1
  89. package/src/submission-confirm-hook.ts +120 -27
  90. 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 {
@@ -313,6 +318,15 @@ const USAGE = `paperlint — machine-checkable gates for a paper kept in git
313
318
  npx paperlint submission topics [paper]
314
319
  the topics the venue's portal offers, against the ones its
315
320
  preset records; exit 1 when they differ
321
+ npx paperlint artifact record <zip> --url <url> [--host <name>] [--numbers <file>] [paper]
322
+ write the upload record (submission/artifact-upload.json): the
323
+ zip's sha256 and md5, and the numbers the paper prints now. Any
324
+ host, no network; artifact/upload-current reads it
325
+ npx paperlint artifact upload --to osf <zip> [--node <id>] [paper] [--save]
326
+ upload the zip and write the same record with the host's own
327
+ hashes. A DRY RUN unless --save. Token: OSF_TOKEN_OSF_IO
328
+ npx paperlint artifact show [paper] the record, and match yes/no against the hashes the host holds
329
+ now, where its adapter reads them (osf)
316
330
  npx paperlint versions [show|lock|migrate|approve|diff] [paper]
317
331
  the paper's frozen versions, one folder per attempt:
318
332
  versions/<cycle>/<stage>.{pdf,tex}. show (the default): each
@@ -566,6 +580,22 @@ const today = (now = new Date()): string =>
566
580
  String(now.getDate()).padStart(2, "0"),
567
581
  ].join("-");
568
582
 
583
+ /** What `artifact/upload-current` and `paperlint artifact record` read with. */
584
+ const UPLOAD_RULE_DEPS = {
585
+ files: nodeFiles,
586
+ codec: sourcesCodec,
587
+ latex: latexReader,
588
+ };
589
+
590
+ /**
591
+ * The `artifact` plugin: required-files and promised on for every paper, silent for one whose
592
+ * paperlint.json declares no `artifact`; upload-current on for no paper until its options turn it on.
593
+ */
594
+ const ARTIFACT_PLUGIN_RULES = {
595
+ ...artifactRules({ files: nodeFiles, listTree: nodeListTree }),
596
+ ...artifactUploadRules(UPLOAD_RULE_DEPS),
597
+ };
598
+
569
599
  /** What the talk rules read with: the disk, the shipped presets, and the three media readers. */
570
600
  const TALK_RULE_DEPS = {
571
601
  files: nodeFiles,
@@ -641,10 +671,7 @@ export function buildConfig(
641
671
  },
642
672
  },
643
673
  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
- },
674
+ artifact: { rules: ARTIFACT_PLUGIN_RULES },
648
675
  // Registered, on for no paper: `"study/declare-sample": "error"` in paperlint.json turns it on.
649
676
  study: { rules: preregCoverage.rules },
650
677
  cycle: { rules: CYCLE_STATUS_RULES },
@@ -1164,6 +1191,11 @@ export function parseArgs(argv: readonly string[]): Args {
1164
1191
  abstract: null,
1165
1192
  submit: false,
1166
1193
  save: false,
1194
+ url: null,
1195
+ host: null,
1196
+ to: null,
1197
+ node: null,
1198
+ numbers: null,
1167
1199
  hooksMode: null,
1168
1200
  // -1 = warnings NEVER fail the run. In this set most findings are advisory by design, and a
1169
1201
  // gate that fails on advice gets muted entirely.
@@ -1256,13 +1288,27 @@ const SWITCHES: ReadonlyMap<
1256
1288
  /** The flags whose value is one string field of `Args`. */
1257
1289
  const STRING_FLAGS: ReadonlyMap<
1258
1290
  string,
1259
- "paper" | "venue" | "kind" | "pdf" | "abstract"
1291
+ | "paper"
1292
+ | "venue"
1293
+ | "kind"
1294
+ | "pdf"
1295
+ | "abstract"
1296
+ | "url"
1297
+ | "host"
1298
+ | "to"
1299
+ | "node"
1300
+ | "numbers"
1260
1301
  > = new Map([
1261
1302
  ["--paper", "paper"],
1262
1303
  ["--venue", "venue"],
1263
1304
  ["--kind", "kind"],
1264
1305
  ["--pdf", "pdf"],
1265
1306
  ["--abstract", "abstract"],
1307
+ ["--url", "url"],
1308
+ ["--host", "host"],
1309
+ ["--to", "to"],
1310
+ ["--node", "node"],
1311
+ ["--numbers", "numbers"],
1266
1312
  ]);
1267
1313
 
1268
1314
  /** The flags that take a value, in either spelling: `--flag value` or `--flag=value`. */
@@ -1403,6 +1449,7 @@ const IN_PROCESS_HOOKS: Readonly<
1403
1449
  portalHosts,
1404
1450
  shellLeaves: leafCommandsNormalized,
1405
1451
  readSend: submissionSend,
1452
+ readUpload: uploadSend,
1406
1453
  });
1407
1454
  } catch {
1408
1455
  return UNREADABLE_INPUT;
@@ -1430,6 +1477,24 @@ export function submissionSend(
1430
1477
  return clean ? { paper: a.paths[1] ?? null, pdf: a.pdf } : null;
1431
1478
  }
1432
1479
 
1480
+ /**
1481
+ * The words after `artifact`, read by this CLI's own parser, for an upload: the file it uploads, the
1482
+ * paper (null for the current folder), and the host and project it goes to — or null when they would
1483
+ * not run cleanly. `--save` uploads only to a project named on the command line (`artifact.ts`).
1484
+ */
1485
+ export function uploadSend(words: readonly string[]): Upload | null {
1486
+ const a = parseArgs(["artifact", ...words]);
1487
+ const [sub, file, paper, ...rest] = a.paths;
1488
+ const clean =
1489
+ a.missingValue === undefined &&
1490
+ a.unknownFlag === undefined &&
1491
+ sub === "upload" &&
1492
+ rest.length === 0;
1493
+ return clean && file !== undefined && a.to !== null && a.node !== null
1494
+ ? { paper: paper ?? null, artifact: file, host: a.to, project: a.node }
1495
+ : null;
1496
+ }
1497
+
1433
1498
  /**
1434
1499
  * `paperlint hook <name>` — run an editor hook. It exists for ONE thing: so that the wiring does not
1435
1500
  * address the runtime from the project root.
@@ -2177,6 +2242,20 @@ const SIMPLE: Readonly<
2177
2242
  log,
2178
2243
  err,
2179
2244
  }),
2245
+ artifact: (a, { log, err, cwd }) =>
2246
+ runArtifact(
2247
+ { ...a, sub: a.paths[0], operands: a.paths.slice(1) },
2248
+ {
2249
+ ...UPLOAD_RULE_DEPS,
2250
+ ruleEntry: uploadRuleEntry,
2251
+ hosts: ARTIFACT_HOSTS,
2252
+ env: (name) => process.env[name],
2253
+ now: isoNow,
2254
+ cwd,
2255
+ log,
2256
+ err,
2257
+ },
2258
+ ),
2180
2259
  submission: (a, { log, err, cwd }) =>
2181
2260
  runSubmission(
2182
2261
  {
@@ -2205,6 +2284,38 @@ const SIMPLE: Readonly<
2205
2284
  ),
2206
2285
  };
2207
2286
 
2287
+ /**
2288
+ * `artifact/upload-current`'s entry for the paper in `dir`, as ESLint computes it for the paper's
2289
+ * `PIPELINE-STATUS.md`, where the rule runs, under the config `paperlint lint` run there would use: one answer for the rule and the commands,
2290
+ * whichever shape the settings take (a `rules` object, a list of blocks, the project's or the
2291
+ * paper's). Undefined when the rule is not on there or the config does not read; lint says why.
2292
+ */
2293
+ async function uploadRuleEntry(dir: string): Promise<unknown> {
2294
+ // Quiet: a config that does not read is lint's to report, not this command's.
2295
+ const quiet = (): void => {};
2296
+ const cfg = readConfig(parseArgs(["lint"]), {
2297
+ log: quiet,
2298
+ err: quiet,
2299
+ cwd: dir,
2300
+ });
2301
+ if (cfg.code !== undefined) return undefined;
2302
+ const engine = await paperEslint(cfg, [dir], {
2303
+ loadTexLanguage: loadLatexLanguage,
2304
+ fix: false,
2305
+ stats: false,
2306
+ });
2307
+ if (!engine.ok) return undefined;
2308
+ const computed = ComputedConfig.parse(
2309
+ await engine.value.eslint.calculateConfigForFile(join(dir, STATUS_FILE)),
2310
+ );
2311
+ return computed?.rules?.["artifact/upload-current"];
2312
+ }
2313
+
2314
+ /** Every artifact host paperlint has an adapter for: a new host is its folder and one line here. */
2315
+ const ARTIFACT_HOSTS: Readonly<Record<string, ArtifactHost>> = {
2316
+ osf: osfHost(),
2317
+ };
2318
+
2208
2319
  /** The adapter of each portal kind — one per kind, chosen here at the root. */
2209
2320
  const PORTALS: Readonly<Record<PortalKind, (url: string) => PortalSite>> = {
2210
2321
  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
+ };
@@ -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
+ });