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,504 @@
1
+ /**
2
+ * `paperlint artifact record|upload|show` (`src/artifact.ts`) over files in memory and a fake host:
3
+ * what each prints, what lands on disk, what the host is asked. The OSF adapter itself is tested
4
+ * against its cassette (`src/adapters/osf/host.test.ts`).
5
+ */
6
+ import { omit } from "remeda";
7
+ import { expect, test } from "vitest";
8
+ import { latexReader } from "./adapters/latex/index.ts";
9
+ import { callerPath } from "./caller-path.ts";
10
+ import { memoryFiles } from "./adapters/memory/index.ts";
11
+ import { sourcesCodec } from "./adapters/sources-record/index.ts";
12
+ import { neverSiteOnly, runArtifact, type ArtifactInput } from "./artifact.ts";
13
+ import {
14
+ md5Hex,
15
+ uploadRecordText,
16
+ type UploadRecord,
17
+ } from "./domain/artifact-upload.ts";
18
+ import { isRecord } from "./domain/record.ts";
19
+ import { err, ok } from "./domain/result.ts";
20
+ import { sha256Hex } from "./domain/sha256.ts";
21
+ import type { ArtifactHost, HostedFile } from "./ports/artifact-host.ts";
22
+
23
+ const CWD = "/work/papers/p";
24
+ const ZIP = new TextEncoder().encode("artifact bytes\n");
25
+ const SHA = sha256Hex(ZIP);
26
+ const MD5 = md5Hex(ZIP);
27
+ const NOW = "2026-11-21T10:00:00.000Z";
28
+ const ON = JSON.stringify({
29
+ rules: { "artifact/upload-current": ["warn", { numbers: "numbersdef.tex" }] },
30
+ });
31
+ const PAPER: Readonly<Record<string, string | Uint8Array>> = {
32
+ [`${CWD}/artifact.zip`]: ZIP,
33
+ [`${CWD}/numbersdef.tex`]: "\\newcommand{\\nRepos}{64}\n",
34
+ [`${CWD}/paperlint.json`]: ON,
35
+ };
36
+ const RECORD_AT = `${CWD}/submission/artifact-upload.json`;
37
+ const HOSTED: HostedFile = {
38
+ id: "f1",
39
+ url: "https://h.example/f1",
40
+ sha256: SHA,
41
+ md5: MD5,
42
+ };
43
+
44
+ /** A host that holds `held`, recording what it was asked. */
45
+ function fakeHost(
46
+ held: Result,
47
+ asked: string[],
48
+ can: ArtifactHost["can"] = { upload: true, hashes: ["sha256", "md5"] },
49
+ ): ArtifactHost {
50
+ return {
51
+ can,
52
+ token: {
53
+ variable: "H_TOKEN_H",
54
+ siteLess: "H_TOKEN",
55
+ help: "h.example/tokens",
56
+ },
57
+ targetOf: (url) => (url.startsWith("https://h.example/") ? "proj" : null),
58
+ read: (where, token) => {
59
+ asked.push(`read ${where.file} ${String(where.id)} ${String(token)}`);
60
+ return Promise.resolve(held);
61
+ },
62
+ upload: (u, token) => {
63
+ asked.push(
64
+ `upload ${u.target} ${u.name} ${String(u.bytes.length)} ${token}`,
65
+ );
66
+ return Promise.resolve(held);
67
+ },
68
+ };
69
+ }
70
+ type Result = Awaited<ReturnType<ArtifactHost["read"]>>;
71
+
72
+ const input = (i: Partial<ArtifactInput>): ArtifactInput => ({
73
+ sub: undefined,
74
+ operands: [],
75
+ url: null,
76
+ host: null,
77
+ to: null,
78
+ node: null,
79
+ numbers: null,
80
+ save: false,
81
+ ...i,
82
+ });
83
+
84
+ /** `artifact/upload-current` in a paperlint.json's `rules` object; undefined for anything else. */
85
+ const entryIn = (text: string | Uint8Array | undefined): unknown => {
86
+ const json = typeof text === "string" ? jsonOrText(text) : undefined;
87
+ const rules = isRecord(json) ? json["rules"] : undefined;
88
+ return isRecord(rules) ? rules["artifact/upload-current"] : undefined;
89
+ };
90
+
91
+ /** The record file as JSON, or its text when it is not JSON (a broken record planted by a test). */
92
+ const jsonOrText = (text: string): unknown => {
93
+ try {
94
+ return JSON.parse(text);
95
+ } catch {
96
+ return text;
97
+ }
98
+ };
99
+
100
+ async function run(
101
+ i: Partial<ArtifactInput>,
102
+ tree: Readonly<Record<string, string | Uint8Array>> = PAPER,
103
+ o: {
104
+ readonly held?: Result;
105
+ readonly env?: Readonly<Record<string, string>>;
106
+ readonly can?: Parameters<typeof fakeHost>[2];
107
+ } = {},
108
+ ) {
109
+ const files = memoryFiles(tree);
110
+ const out: string[] = [];
111
+ const asked: string[] = [];
112
+ const code = await runArtifact(input(i), {
113
+ files,
114
+ codec: sourcesCodec,
115
+ latex: latexReader,
116
+ hosts: { h: fakeHost(o.held ?? ok(HOSTED), asked, o.can) },
117
+ // The rule's entry as lint's config would give it: here, from the paper's own `rules` object.
118
+ ruleEntry: (dir) => Promise.resolve(entryIn(tree[`${dir}/paperlint.json`])),
119
+ env: (n) => o.env?.[n],
120
+ now: () => NOW,
121
+ cwd: CWD,
122
+ log: (l) => out.push(l),
123
+ err: (l) => out.push(`ERR ${l}`),
124
+ });
125
+ const written = files.readBytes(callerPath(RECORD_AT));
126
+ return {
127
+ code,
128
+ out,
129
+ asked,
130
+ record:
131
+ written === null ? null : jsonOrText(new TextDecoder().decode(written)),
132
+ };
133
+ }
134
+
135
+ const RECORD: UploadRecord = {
136
+ version: 1,
137
+ host: "other",
138
+ url: "https://example.org/a.zip",
139
+ file: "artifact.zip",
140
+ sha256: SHA,
141
+ md5: MD5,
142
+ uploadedAt: NOW,
143
+ numbers: { nRepos: "64" },
144
+ };
145
+
146
+ test("record: hashes the zip, snapshots the numbers, writes the record; the rule's options name the file", async () => {
147
+ const r = await run({
148
+ sub: "record",
149
+ operands: ["artifact.zip"],
150
+ url: RECORD.url,
151
+ });
152
+ // Guards: the whole record on disk, and what is printed about it.
153
+ expect(r).toEqual({
154
+ code: 0,
155
+ asked: [],
156
+ record: RECORD,
157
+ out: [
158
+ `wrote ${RECORD_AT}`,
159
+ " other https://example.org/a.zip",
160
+ ` artifact.zip sha256 ${SHA} md5 ${MD5}`,
161
+ " 1 numbers from the numbers file, as they are now",
162
+ ],
163
+ });
164
+ // Guards: a url the host's adapter knows names that host; --host and --numbers win.
165
+ const h = await run({
166
+ sub: "record",
167
+ operands: ["artifact.zip", "."],
168
+ url: "https://h.example/x",
169
+ });
170
+ expect(h.record).toEqual({
171
+ ...RECORD,
172
+ host: "h",
173
+ url: "https://h.example/x",
174
+ });
175
+ const own = await run(
176
+ {
177
+ sub: "record",
178
+ operands: ["artifact.zip"],
179
+ url: RECORD.url,
180
+ host: "zenodo",
181
+ numbers: "n2.tex",
182
+ },
183
+ {
184
+ ...PAPER,
185
+ [`${CWD}/n2.tex`]: "\\def\\k{1}",
186
+ [`${CWD}/paperlint.json`]: "{}",
187
+ },
188
+ );
189
+ expect(own.record).toEqual({
190
+ ...RECORD,
191
+ host: "zenodo",
192
+ numbers: { k: "1" },
193
+ });
194
+ });
195
+
196
+ test("record: refuses, saying why, and writes nothing", async () => {
197
+ const why = async (i: Partial<ArtifactInput>, tree = PAPER) => {
198
+ const r = await run({ sub: "record", url: RECORD.url, ...i }, tree);
199
+ return [r.code, r.record, r.out];
200
+ };
201
+ // Guards: each missing input is named, exit 2, no record.
202
+ expect(await why({})).toEqual([
203
+ 2,
204
+ null,
205
+ [
206
+ "ERR paperlint artifact: name the uploaded file: paperlint artifact record <zip> …",
207
+ ],
208
+ ]);
209
+ expect(await why({ operands: ["gone.zip"] })).toEqual([
210
+ 2,
211
+ null,
212
+ ["ERR paperlint artifact: no file gone.zip"],
213
+ ]);
214
+ expect(await why({ operands: ["artifact.zip"], url: null })).toEqual([
215
+ 2,
216
+ null,
217
+ ["ERR paperlint artifact: where is it? pass --url <url>"],
218
+ ]);
219
+ expect(await why({ operands: ["artifact.zip"], url: "not a url" })).toEqual([
220
+ 2,
221
+ null,
222
+ ["ERR paperlint artifact: not written — url: Invalid URL"],
223
+ ]);
224
+ const noRule = {
225
+ ...PAPER,
226
+ [`${CWD}/paperlint.json`]: JSON.stringify({ rules: [] }),
227
+ };
228
+ expect(await why({ operands: ["artifact.zip"] }, noRule)).toEqual([
229
+ 2,
230
+ null,
231
+ [
232
+ `ERR paperlint artifact: which file holds the paper's numbers? pass --numbers <file> (relative to the paper), or turn artifact/upload-current on with its "numbers" option`,
233
+ ],
234
+ ]);
235
+ expect(
236
+ await why({ operands: ["artifact.zip"], numbers: "gone.tex" }),
237
+ ).toEqual([
238
+ 2,
239
+ null,
240
+ [`ERR paperlint artifact: no numbers file gone.tex in ${CWD}`],
241
+ ]);
242
+ expect(
243
+ await why(
244
+ { operands: ["artifact.zip"] },
245
+ { ...PAPER, [`${CWD}/numbersdef.tex`]: "" },
246
+ ),
247
+ ).toEqual([
248
+ 2,
249
+ null,
250
+ [
251
+ "ERR paperlint artifact: the numbers file numbersdef.tex defines no macro without arguments (\\newcommand{\\key}{value})",
252
+ ],
253
+ ]);
254
+ });
255
+
256
+ const UPLOAD = {
257
+ sub: "upload",
258
+ operands: ["artifact.zip"],
259
+ to: "h",
260
+ node: "proj",
261
+ } as const;
262
+ const PLAN = [
263
+ `upload artifact.zip (15 bytes, sha256 ${SHA}) to h project proj`,
264
+ `then write ${RECORD_AT} with the host's hashes and 1 numbers`,
265
+ ];
266
+
267
+ test("upload: a dry run by default — it says what it would do and touches nothing", async () => {
268
+ // Guards: no request, no record; the token's presence is said, never its value.
269
+ expect(await run(UPLOAD, PAPER, { env: { H_TOKEN_H: "secret" } })).toEqual({
270
+ code: 0,
271
+ asked: [],
272
+ record: null,
273
+ out: [
274
+ ...PLAN,
275
+ "token: H_TOKEN_H is set",
276
+ "DRY RUN: nothing uploaded, nothing written. Run again with --save --node proj to upload.",
277
+ ],
278
+ });
279
+ const none = await run(UPLOAD, PAPER, { env: { H_TOKEN: "old" } });
280
+ // Guards: without its variable, the dry run says how to make one, and names the site-less one as unread.
281
+ expect(none.out.slice(2)).toEqual([
282
+ "H_TOKEN is set but not read: set H_TOKEN_H instead\n 1. make one: h.example/tokens\n 2. set it in your environment — never paste it into a chat: export H_TOKEN_H=<the token>",
283
+ "DRY RUN: nothing uploaded, nothing written. Run again with --save --node proj to upload.",
284
+ ]);
285
+ });
286
+
287
+ test("upload --save: uploads, then writes the record with the host's id, url and hashes", async () => {
288
+ const r = await run({ ...UPLOAD, save: true }, PAPER, {
289
+ env: { H_TOKEN_H: "secret" },
290
+ });
291
+ // Guards: one upload with the token, the record holding what the host said; the token printed nowhere.
292
+ expect(r.asked).toEqual(["upload proj artifact.zip 15 secret"]);
293
+ expect(r.record).toEqual({ ...RECORD, host: "h", url: HOSTED.url, id: "f1" });
294
+ expect(r.out.join("\n")).not.toContain("secret");
295
+ const noHash = await run({ ...UPLOAD, save: true }, PAPER, {
296
+ env: { H_TOKEN_H: "t" },
297
+ held: ok({ ...HOSTED, sha256: null, md5: null }),
298
+ });
299
+ // Guards: a host that gives no hash back leaves them out rather than inventing them.
300
+ expect(noHash.record).toEqual({
301
+ ...RECORD,
302
+ host: "h",
303
+ url: HOSTED.url,
304
+ id: "f1",
305
+ sha256: undefined,
306
+ md5: undefined,
307
+ });
308
+ });
309
+
310
+ /** An upload's exit code, how many requests, whether no record was written, and its last line. */
311
+ const code = async (
312
+ i: Partial<ArtifactInput>,
313
+ o: Parameters<typeof run>[2] = {},
314
+ tree = PAPER,
315
+ ) => {
316
+ const r = await run({ ...UPLOAD, ...i }, tree, o);
317
+ return [r.code, r.asked.length, r.record === null, r.out.at(-1)];
318
+ };
319
+
320
+ test("upload: what stops it before the host", async () => {
321
+ // Guards: an unknown host, one that cannot upload, no project — refused before anything.
322
+ expect(await code({ to: "zenodo" })).toEqual([
323
+ 2,
324
+ 0,
325
+ true,
326
+ "ERR paperlint artifact: name a host paperlint uploads to: --to h (for any other host, upload it yourself and run `paperlint artifact record <zip> --url <url>`)",
327
+ ]);
328
+ expect(await code({}, { can: { upload: false, hashes: [] } })).toEqual([
329
+ 2,
330
+ 0,
331
+ true,
332
+ expect.stringContaining("name a host"),
333
+ ]);
334
+ expect(await code({ node: null })).toEqual([
335
+ 2,
336
+ 0,
337
+ true,
338
+ "ERR paperlint artifact: which project? pass --node <id> (the project's id in its url)",
339
+ ]);
340
+ expect(await code({ operands: [] })).toEqual([
341
+ 2,
342
+ 0,
343
+ true,
344
+ "ERR paperlint artifact: name the uploaded file: paperlint artifact upload <zip> …",
345
+ ]);
346
+ // Guards: the project comes from an earlier record's url when --node is not given.
347
+ const before = {
348
+ ...PAPER,
349
+ [RECORD_AT]: uploadRecordText({ ...RECORD, url: "https://h.example/f0" }),
350
+ };
351
+ expect((await code({ node: null }, {}, before))[0]).toBe(0);
352
+ // Guards: --save uploads only to a project on the command line, the one the person's yes names.
353
+ expect(
354
+ await code({ node: null, save: true }, { env: { H_TOKEN_H: "t" } }, before),
355
+ ).toEqual([
356
+ 2,
357
+ 0,
358
+ false,
359
+ "ERR paperlint artifact: --save uploads only to a project named with --node: run again with --save --node proj",
360
+ ]);
361
+ });
362
+
363
+ test("upload: what stops it at the host", async () => {
364
+ // Guards: --save without a token, a failed upload, other bytes on the host.
365
+ expect(await code({ save: true })).toEqual([
366
+ 2,
367
+ 0,
368
+ true,
369
+ expect.stringContaining("no token: H_TOKEN_H is not set"),
370
+ ]);
371
+ const env = { H_TOKEN_H: "t" };
372
+ expect(
373
+ await code(
374
+ { save: true },
375
+ { env, held: err({ kind: "refused", detail: "HTTP 403" }) },
376
+ ),
377
+ ).toEqual([
378
+ 2,
379
+ 1,
380
+ true,
381
+ "ERR paperlint artifact: upload failed (refused): HTTP 403",
382
+ ]);
383
+ expect(
384
+ await code(
385
+ { save: true },
386
+ { env, held: ok({ ...HOSTED, sha256: "0".repeat(64) }) },
387
+ ),
388
+ ).toEqual([
389
+ 1,
390
+ 1,
391
+ true,
392
+ `ERR paperlint artifact: h holds sha256 ${"0".repeat(64)}, not the ${SHA} sent; no record written`,
393
+ ]);
394
+ });
395
+
396
+ const WITH_RECORD = (r: Partial<UploadRecord>) => ({
397
+ ...PAPER,
398
+ [RECORD_AT]: uploadRecordText({ ...RECORD, ...r }),
399
+ });
400
+
401
+ test("show: the record, and match yes or no against the host's hashes", async () => {
402
+ const tree = WITH_RECORD({ host: "h", url: HOSTED.url, id: "f1" });
403
+ const yes = await run({ sub: "show" }, tree, { env: { H_TOKEN_H: "t" } });
404
+ // Guards: the record, the host's hashes, `match yes`, exit 0; the token handed to the read.
405
+ expect(yes).toEqual({
406
+ code: 0,
407
+ asked: ["read artifact.zip f1 t"],
408
+ record: { ...RECORD, host: "h", url: HOSTED.url, id: "f1" },
409
+ out: [
410
+ `h ${HOSTED.url}`,
411
+ ` artifact.zip, uploaded ${NOW}, 1 numbers`,
412
+ ` record: sha256 ${SHA} md5 ${MD5}`,
413
+ ` host: sha256 ${SHA}`,
414
+ ` host: md5 ${MD5}`,
415
+ "match yes",
416
+ ],
417
+ });
418
+ const no = await run({ sub: "show", operands: ["."] }, tree, {
419
+ held: ok({ ...HOSTED, md5: "1".repeat(32) }),
420
+ });
421
+ // Guards: one differing hash is `match no`, exit 1; without a token the read gets none.
422
+ expect([no.code, no.asked, no.out.at(-1)]).toEqual([
423
+ 1,
424
+ ["read artifact.zip f1 null"],
425
+ "match no",
426
+ ]);
427
+ const unknown = await run({ sub: "show" }, tree, {
428
+ held: ok({ ...HOSTED, sha256: null, md5: null }),
429
+ });
430
+ // Guards: nothing to compare is said, not called a match.
431
+ expect(unknown.out.at(-1)).toBe(
432
+ "match unknown: the record holds no hash the host gives",
433
+ );
434
+ });
435
+
436
+ test("show: a host paperlint cannot check, and what stops it", async () => {
437
+ const other = await run({ sub: "show" }, WITH_RECORD({}));
438
+ // Guards: a host with no adapter says so, prints the record's own hashes, and asks nothing.
439
+ expect([other.code, other.asked, other.out.at(-1)]).toEqual([
440
+ 0,
441
+ [],
442
+ "paperlint cannot read hashes from other: the record's own are above; compare them on the host's page",
443
+ ]);
444
+ const blind = await run({ sub: "show" }, WITH_RECORD({ host: "h" }), {
445
+ can: { upload: true, hashes: [] },
446
+ });
447
+ // Guards: an adapter that reads no hash is the same.
448
+ expect(blind.asked).toEqual([]);
449
+ // Guards: no record, a broken one, a failed read.
450
+ expect((await run({ sub: "show" })).out).toEqual([
451
+ `ERR paperlint artifact: no upload record ${RECORD_AT}: write one with \`paperlint artifact record <zip> --url <url>\``,
452
+ ]);
453
+ expect(
454
+ (await run({ sub: "show" }, { ...PAPER, [RECORD_AT]: "{" })).out,
455
+ ).toEqual([
456
+ `ERR paperlint artifact: the upload record ${RECORD_AT} cannot be read: it is not JSON`,
457
+ ]);
458
+ const down = await run({ sub: "show" }, WITH_RECORD({ host: "h" }), {
459
+ held: err({ kind: "unreachable", detail: "ECONNREFUSED" }),
460
+ });
461
+ expect([down.code, down.out.at(-1)]).toEqual([
462
+ 2,
463
+ "ERR paperlint artifact: could not read the file on h (unreachable): ECONNREFUSED",
464
+ ]);
465
+ });
466
+
467
+ test("no subcommand, or an unknown one, names the three", async () => {
468
+ // Guards: exit 2 and the list.
469
+ expect((await run({})).out).toEqual([
470
+ "ERR paperlint artifact: no subcommand: record | upload | show",
471
+ ]);
472
+ expect((await run({ sub: "pack" })).code).toBe(2);
473
+ });
474
+
475
+ test("a host's token is never one site's only: the shared-variable policy of portal-token.ts does not apply", () => {
476
+ // Guards: the one answer lookUpToken could ask of it.
477
+ expect(neverSiteOnly()).toBe(false);
478
+ });
479
+
480
+ test("the paper's settings: none, or broken — the numbers come from --numbers alone; no --to names the hosts", async () => {
481
+ const bare = omit(PAPER, [`${CWD}/paperlint.json`]);
482
+ const opts = {
483
+ sub: "record",
484
+ operands: ["artifact.zip"],
485
+ url: RECORD.url,
486
+ numbers: "numbersdef.tex",
487
+ };
488
+ // Guards: no paperlint.json, and one that does not parse, still record with --numbers.
489
+ expect((await run(opts, bare)).record).toEqual(RECORD);
490
+ expect(
491
+ (await run(opts, { ...PAPER, [`${CWD}/paperlint.json`]: "{" })).record,
492
+ ).toEqual(RECORD);
493
+ // Guards: an upload without --to is refused naming the hosts.
494
+ expect((await code({ to: null }))[3]).toEqual(
495
+ expect.stringContaining("--to h"),
496
+ );
497
+ const bareRecord = omit(RECORD, ["sha256", "md5"]);
498
+ const shown = await run(
499
+ { sub: "show" },
500
+ { ...PAPER, [RECORD_AT]: uploadRecordText(bareRecord) },
501
+ );
502
+ // Guards: a record without hashes shows dashes for them.
503
+ expect(shown.out[2]).toBe(" record: sha256 — md5 —");
504
+ });