paperlint 18.0.0 → 18.1.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 (39) hide show
  1. package/README.md +1 -1
  2. package/dist/adapters/hotcrp/index.d.ts +11 -1
  3. package/dist/adapters/hotcrp/index.d.ts.map +1 -1
  4. package/dist/adapters/hotcrp/index.js +11 -1
  5. package/dist/adapters/hotcrp/index.js.map +1 -1
  6. package/dist/adapters/hotcrp/site.d.ts.map +1 -1
  7. package/dist/adapters/hotcrp/site.js +3 -1
  8. package/dist/adapters/hotcrp/site.js.map +1 -1
  9. package/dist/adapters/hotcrp/token.d.ts +11 -0
  10. package/dist/adapters/hotcrp/token.d.ts.map +1 -1
  11. package/dist/adapters/hotcrp/token.js +34 -7
  12. package/dist/adapters/hotcrp/token.js.map +1 -1
  13. package/dist/cli.d.ts.map +1 -1
  14. package/dist/cli.js +4 -3
  15. package/dist/cli.js.map +1 -1
  16. package/dist/domain/portal-token.d.ts +26 -10
  17. package/dist/domain/portal-token.d.ts.map +1 -1
  18. package/dist/domain/portal-token.js +19 -12
  19. package/dist/domain/portal-token.js.map +1 -1
  20. package/dist/ports/submission-portal.d.ts +7 -0
  21. package/dist/ports/submission-portal.d.ts.map +1 -1
  22. package/dist/submission.d.ts +3 -2
  23. package/dist/submission.d.ts.map +1 -1
  24. package/dist/submission.js +24 -12
  25. package/dist/submission.js.map +1 -1
  26. package/docs/submission.md +26 -9
  27. package/package.json +1 -1
  28. package/src/adapters/hotcrp/cassette/README.md +1 -1
  29. package/src/adapters/hotcrp/index.ts +12 -0
  30. package/src/adapters/hotcrp/site.ts +4 -0
  31. package/src/adapters/hotcrp/token.test.ts +39 -1
  32. package/src/adapters/hotcrp/token.ts +40 -7
  33. package/src/cli.ts +4 -3
  34. package/src/domain/portal-token.test.ts +121 -2
  35. package/src/domain/portal-token.ts +39 -15
  36. package/src/ports/submission-portal.ts +7 -0
  37. package/src/submission-show.test.ts +1 -1
  38. package/src/submission.test.ts +98 -7
  39. package/src/submission.ts +28 -11
package/src/cli.ts CHANGED
@@ -365,9 +365,10 @@ submission:
365
365
  — and, for new, its "authors": [{ "name", "email", "affiliation"? }]. Its "fields" answer the
366
366
  form's own fields the preset records in "submission_fields" ({ "topics": [...], "pc_conflicts":
367
367
  { "<pc email>": "<type>" }, … }); new and update send them, checked first. The token comes only from
368
- the environment, one variable per site: HOTCRP_TOKEN_<subdomain> on *.hotcrp.com, else
369
- HOTCRP_TOKEN_<host and path> — e.g. HOTCRP_TOKEN_MSR2027 for msr2027.hotcrp.com,
370
- HOTCRP_TOKEN_AIDC_SUBMIT_ACSAC_ORG for aidc.submit.acsac.org (HotCRP: Account settings →
368
+ the environment: HOTCRP_TOKEN_HOTCRP_COM for every *.hotcrp.com site (an "All sites" token),
369
+ HOTCRP_TOKEN_<subdomain> to override it for one site, e.g. HOTCRP_TOKEN_MSR2027; a self-hosted
370
+ install only HOTCRP_TOKEN_<host and path>, e.g. HOTCRP_TOKEN_AIDC_SUBMIT_ACSAC_ORG for
371
+ aidc.submit.acsac.org, never the hotcrp.com one (HotCRP: Account settings →
371
372
  Developer). A plain HOTCRP_TOKEN is not read.
372
373
  [paper] the paper's folder; default the current directory
373
374
  --pdf <file> the PDF to compare (show) or send (update) instead of the paper's own
@@ -3,7 +3,13 @@ import assert from "node:assert/strict";
3
3
  import { test } from "vitest";
4
4
  import { hostOf, lookUpToken } from "./portal-token.ts";
5
5
 
6
- const NAMES = { variable: "HOTCRP_TOKEN_MSR2027", siteLess: "HOTCRP_TOKEN" };
6
+ const NAMES = {
7
+ variable: "HOTCRP_TOKEN_MSR2027",
8
+ shared: null,
9
+ siteOnly: (t: string) => t.startsWith("hct_"),
10
+ siteLess: "HOTCRP_TOKEN",
11
+ };
12
+ const HOSTED = { ...NAMES, shared: "HOTCRP_TOKEN_HOTCRP_COM" };
7
13
 
8
14
  test("hostOf: the URL's host; a text that is no URL stands for itself", () => {
9
15
  assert.equal(
@@ -36,6 +42,7 @@ test("🔴 lookUpToken: only the site-less variable set → refused by name, nev
36
42
  error: {
37
43
  kind: "site-less",
38
44
  variable: "HOTCRP_TOKEN_MSR2027",
45
+ shared: null,
39
46
  siteLess: "HOTCRP_TOKEN",
40
47
  },
41
48
  },
@@ -50,6 +57,118 @@ test("lookUpToken: neither set, or only blanks → missing, naming the site's va
50
57
  for (const read of [() => undefined, (n: string) => blank[n]])
51
58
  assert.deepEqual(lookUpToken(NAMES, read), {
52
59
  ok: false,
53
- error: { kind: "missing", variable: "HOTCRP_TOKEN_MSR2027" },
60
+ error: {
61
+ kind: "missing",
62
+ variable: "HOTCRP_TOKEN_MSR2027",
63
+ shared: null,
64
+ },
54
65
  });
55
66
  });
67
+
68
+ test("lookUpToken: a hosted site with only the shared variable set → the shared token, and its name", () => {
69
+ const env: Record<string, string> = {
70
+ HOTCRP_TOKEN_HOTCRP_COM: " hcT_all \n",
71
+ };
72
+ assert.deepEqual(
73
+ lookUpToken(HOSTED, (n) => env[n]),
74
+ {
75
+ ok: true,
76
+ value: { variable: "HOTCRP_TOKEN_HOTCRP_COM", token: "hcT_all" },
77
+ },
78
+ );
79
+ });
80
+
81
+ test("lookUpToken: a hosted site with both set → the site's own token wins", () => {
82
+ const env: Record<string, string> = {
83
+ HOTCRP_TOKEN_MSR2027: "hct_site",
84
+ HOTCRP_TOKEN_HOTCRP_COM: "hcT_all",
85
+ };
86
+ assert.deepEqual(
87
+ lookUpToken(HOSTED, (n) => env[n]),
88
+ {
89
+ ok: true,
90
+ value: { variable: "HOTCRP_TOKEN_MSR2027", token: "hct_site" },
91
+ },
92
+ );
93
+ });
94
+
95
+ test("lookUpToken: a hosted site with a blank own variable falls to the shared one", () => {
96
+ const env: Record<string, string> = {
97
+ HOTCRP_TOKEN_MSR2027: " ",
98
+ HOTCRP_TOKEN_HOTCRP_COM: "hcT_all",
99
+ };
100
+ assert.deepEqual(
101
+ lookUpToken(HOSTED, (n) => env[n]),
102
+ {
103
+ ok: true,
104
+ value: { variable: "HOTCRP_TOKEN_HOTCRP_COM", token: "hcT_all" },
105
+ },
106
+ );
107
+ });
108
+
109
+ test("🔴 lookUpToken: a site with no shared variable never reads it, set or not", () => {
110
+ const env: Record<string, string> = { HOTCRP_TOKEN_HOTCRP_COM: "hcT_all" };
111
+ const seen: string[] = [];
112
+ assert.deepEqual(
113
+ lookUpToken(NAMES, (n) => (seen.push(n), env[n])),
114
+ {
115
+ ok: false,
116
+ error: {
117
+ kind: "missing",
118
+ variable: "HOTCRP_TOKEN_MSR2027",
119
+ shared: null,
120
+ },
121
+ },
122
+ );
123
+ assert.deepEqual(seen, ["HOTCRP_TOKEN_MSR2027", "HOTCRP_TOKEN"]);
124
+ });
125
+
126
+ test("🔴 lookUpToken: a hosted site with only the site-less variable set → refused by name, shared named", () => {
127
+ const env: Record<string, string> = { HOTCRP_TOKEN: "hct_other" };
128
+ assert.deepEqual(
129
+ lookUpToken(HOSTED, (n) => env[n]),
130
+ {
131
+ ok: false,
132
+ error: {
133
+ kind: "site-less",
134
+ variable: "HOTCRP_TOKEN_MSR2027",
135
+ shared: "HOTCRP_TOKEN_HOTCRP_COM",
136
+ siteLess: "HOTCRP_TOKEN",
137
+ },
138
+ },
139
+ );
140
+ });
141
+
142
+ test("🔴 lookUpToken: a site-only token in the shared variable → refused, naming both variables, never used", () => {
143
+ const env: Record<string, string> = { HOTCRP_TOKEN_HOTCRP_COM: "hct_fake" };
144
+ assert.deepEqual(
145
+ lookUpToken(HOSTED, (n) => env[n]),
146
+ {
147
+ ok: false,
148
+ error: {
149
+ kind: "site-only",
150
+ variable: "HOTCRP_TOKEN_MSR2027",
151
+ shared: "HOTCRP_TOKEN_HOTCRP_COM",
152
+ },
153
+ },
154
+ );
155
+ });
156
+
157
+ test("lookUpToken: the same token in the site's own variable is used; an all-sites token in the shared one is used", () => {
158
+ const own: Record<string, string> = { HOTCRP_TOKEN_MSR2027: "hct_fake" };
159
+ assert.deepEqual(
160
+ lookUpToken(HOSTED, (n) => own[n]),
161
+ {
162
+ ok: true,
163
+ value: { variable: "HOTCRP_TOKEN_MSR2027", token: "hct_fake" },
164
+ },
165
+ );
166
+ const all: Record<string, string> = { HOTCRP_TOKEN_HOTCRP_COM: "hcT_fake" };
167
+ assert.deepEqual(
168
+ lookUpToken(HOSTED, (n) => all[n]),
169
+ {
170
+ ok: true,
171
+ value: { variable: "HOTCRP_TOKEN_HOTCRP_COM", token: "hcT_fake" },
172
+ },
173
+ );
174
+ });
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * WHICH TOKEN A PORTAL COMMAND USES — the policy, in one place. Pure.
3
3
  *
4
- * The site's own variable, and nothing else: there is NO fallback to a site-less variable. With one,
5
- * which token a command used is not visible, and a token from another site reads as "the portal
6
- * refused". A site-less variable that is set while the site's own is not is refused by name. The
7
- * names themselves are the portal's (`src/adapters/hotcrp/token.ts`).
4
+ * The site's own variable, then the one its portal's sites share (when it has one), and nothing else:
5
+ * there is NO fallback to a site-less variable. With one, which token a command used is not visible,
6
+ * and a token from another site reads as "the portal refused". A site-less variable that is set while
7
+ * neither of those is, is refused by name. The names themselves are the portal's
8
+ * (`src/adapters/hotcrp/token.ts`).
8
9
  */
9
10
  import { err, ok, type Result } from "./result.ts";
10
11
 
@@ -16,9 +17,15 @@ import { err, ok, type Result } from "./result.ts";
16
17
  export const hostOf = (url: string): string =>
17
18
  URL.canParse(url) ? new URL(url).host : url;
18
19
 
19
- /** The variables a lookup reads: the site's own, and the site-less one it refuses. */
20
+ /**
21
+ * The variables a lookup reads: the site's own, the one shared by the portal's sites (null: none),
22
+ * and the site-less one it refuses.
23
+ */
20
24
  export interface TokenNames {
21
25
  readonly variable: string;
26
+ readonly shared: string | null;
27
+ /** Whether a token is valid on one site only, so cannot stand in for the shared variable. */
28
+ readonly siteOnly: (token: string) => boolean;
22
29
  readonly siteLess: string;
23
30
  }
24
31
 
@@ -30,12 +37,23 @@ export interface FoundToken {
30
37
 
31
38
  /** Why there is no token to use. */
32
39
  export type TokenProblem =
33
- /** The site's variable is not set (or blank), and neither is the site-less one. */
34
- | { readonly kind: "missing"; readonly variable: string }
35
- /** The site's variable is not set, but the site-less one, no longer read, is. */
40
+ /** The site's variable is not set (or blank), nor the shared one, nor the site-less one. */
41
+ | {
42
+ readonly kind: "missing";
43
+ readonly variable: string;
44
+ readonly shared: string | null;
45
+ }
46
+ /** The shared variable holds a token that works on one site only. */
47
+ | {
48
+ readonly kind: "site-only";
49
+ readonly variable: string;
50
+ readonly shared: string;
51
+ }
52
+ /** Neither the site's variable nor the shared one is set, but the site-less one, no longer read, is. */
36
53
  | {
37
54
  readonly kind: "site-less";
38
55
  readonly variable: string;
56
+ readonly shared: string | null;
39
57
  readonly siteLess: string;
40
58
  };
41
59
 
@@ -48,16 +66,22 @@ const value = (
48
66
  };
49
67
 
50
68
  /**
51
- * The token for a portal, read through `read` (the root reads the environment): the site's variable
52
- * only. A set site-less variable never stands in for it — it is named as the problem instead.
69
+ * The token for a portal, read through `read` (the root reads the environment): the site's variable,
70
+ * else the shared one (unless that holds a token for one site only). A set site-less variable never stands in for either — it is named as the
71
+ * problem instead.
53
72
  */
54
73
  export function lookUpToken(
55
- { variable, siteLess }: TokenNames,
74
+ { variable, shared, siteOnly, siteLess }: TokenNames,
56
75
  read: (name: string) => string | undefined,
57
76
  ): Result<FoundToken, TokenProblem> {
58
- const token = value(read, variable);
59
- if (token !== null) return ok({ variable, token });
77
+ const own = value(read, variable);
78
+ if (own !== null) return ok({ variable, token: own });
79
+ const common = shared === null ? null : value(read, shared);
80
+ if (shared !== null && common !== null)
81
+ return siteOnly(common)
82
+ ? err({ kind: "site-only", variable, shared })
83
+ : ok({ variable: shared, token: common });
60
84
  return value(read, siteLess) === null
61
- ? err({ kind: "missing", variable })
62
- : err({ kind: "site-less", variable, siteLess });
85
+ ? err({ kind: "missing", variable, shared })
86
+ : err({ kind: "site-less", variable, shared, siteLess });
63
87
  }
@@ -57,6 +57,13 @@ export interface CredentialHelp {
57
57
  export interface PortalSite {
58
58
  /** The environment variable this site's token is read from. */
59
59
  readonly tokenVariable: string;
60
+ /**
61
+ * The variable read when `tokenVariable` is not set, for a portal whose sites share one account
62
+ * system and so one token; null: this site's token is its own.
63
+ */
64
+ readonly sharedVariable: string | null;
65
+ /** Whether a token works on one site only, so is refused in the shared variable. */
66
+ readonly isSiteOnlyToken: (token: string) => boolean;
60
67
  /** The site-less variable no longer read: named when still set, never used. */
61
68
  readonly siteLessVariable: string;
62
69
  /** The shape of a site's variable, for a message about another site's. */
@@ -125,7 +125,7 @@ test("the portal's refusal is printed with its own message, exit 1", async () =>
125
125
  expect(r.code).toBe(1);
126
126
  expect(r.errs).toStrictEqual([
127
127
  "the portal refused (HTTP 401): Missing credentials",
128
- "HOTCRP_TOKEN_127_0_0_1_9 was used; it may belong to another hotcrp site (tokens are per site), or be revoked or expired",
128
+ "HOTCRP_TOKEN_127_0_0_1_9 was used; it may belong to another hotcrp install (hotcrp.com sites share one token, a self-hosted install has its own), or be revoked or expired",
129
129
  ...STEPS,
130
130
  ]);
131
131
  });
@@ -72,6 +72,85 @@ test("only the site-less HOTCRP_TOKEN set: the rename instruction, and nothing i
72
72
  expect(r.errs.join("\n")).not.toMatch(/hct_old/);
73
73
  });
74
74
 
75
+ test("🔴 a self-hosted site never uses the hosted-service variable: only it set → the site's own variable is asked for", async () => {
76
+ const r = await run({}, { env: { HOTCRP_TOKEN_HOTCRP_COM: "hct_all" } });
77
+ expect(r.code).toBe(2);
78
+ expect(r.seen).toStrictEqual([]);
79
+ expect(r.errs).toStrictEqual([
80
+ `no hotcrp token for ${SITE}: HOTCRP_TOKEN_127_0_0_1_9 is not set`,
81
+ ...STEPS,
82
+ ]);
83
+ });
84
+
85
+ test("🔴 the bare HOTCRP_TOKEN stays refused beside the shared variable's absence", async () => {
86
+ const r = await run({}, { env: { HOTCRP_TOKEN: "hct_old" } });
87
+ expect(r.code).toBe(2);
88
+ expect(r.seen).toStrictEqual([]);
89
+ });
90
+
91
+ const HOSTED_SITE = "https://msr2027.hotcrp.com";
92
+ const HOSTED_PORTAL = { kind: "hotcrp", url: HOSTED_SITE } as const;
93
+ const HOSTED_STEPS = (variable: string) => [
94
+ ` 1. create a token on this site: ${HOSTED_SITE}/profile?t=developer (Account settings → Developer → API tokens), with the scopes submeta:read and document:read (show), submeta:write and document:write (update, new) — tick all four to use every subcommand`,
95
+ ` 2. set it in your environment — never paste it into a chat: export ${variable}=<the token>`,
96
+ " one token serves every hotcrp.com site: HOTCRP_TOKEN_HOTCRP_COM is read for all of them; HOTCRP_TOKEN_MSR2027, when set, overrides it for msr2027.hotcrp.com alone",
97
+ ];
98
+
99
+ test("no token on a hosted-service site: the shared variable is what to set, the per-site override is mentioned", () => {
100
+ expect(
101
+ tokenProblemLines(HOSTED_PORTAL, hotcrpSite(HOSTED_SITE), {
102
+ kind: "missing",
103
+ variable: "HOTCRP_TOKEN_MSR2027",
104
+ shared: "HOTCRP_TOKEN_HOTCRP_COM",
105
+ }),
106
+ ).toStrictEqual([
107
+ `no hotcrp token for ${HOSTED_SITE}: HOTCRP_TOKEN_HOTCRP_COM is not set (HOTCRP_TOKEN_MSR2027 would override it for this site)`,
108
+ ...HOSTED_STEPS("HOTCRP_TOKEN_HOTCRP_COM"),
109
+ ]);
110
+ });
111
+
112
+ test("only the site-less variable set on a hosted-service site: both variables it may be renamed to", () => {
113
+ expect(
114
+ tokenProblemLines(HOSTED_PORTAL, hotcrpSite(HOSTED_SITE), {
115
+ kind: "site-less",
116
+ variable: "HOTCRP_TOKEN_MSR2027",
117
+ shared: "HOTCRP_TOKEN_HOTCRP_COM",
118
+ siteLess: "HOTCRP_TOKEN",
119
+ }),
120
+ ).toStrictEqual([
121
+ "HOTCRP_TOKEN is no longer read. If it was made on a hotcrp.com site, rename it to HOTCRP_TOKEN_HOTCRP_COM (every hotcrp.com site) or HOTCRP_TOKEN_MSR2027 (this site alone); if it was made on a self-hosted install, rename it to that install's variable (HOTCRP_TOKEN_<LABEL>) and create a token here:",
122
+ ...HOSTED_STEPS("HOTCRP_TOKEN_HOTCRP_COM"),
123
+ ]);
124
+ });
125
+
126
+ test("a site-only token in the shared variable: what is wrong, and both ways out", () => {
127
+ expect(
128
+ tokenProblemLines(HOSTED_PORTAL, hotcrpSite(HOSTED_SITE), {
129
+ kind: "site-only",
130
+ variable: "HOTCRP_TOKEN_MSR2027",
131
+ shared: "HOTCRP_TOKEN_HOTCRP_COM",
132
+ }),
133
+ ).toStrictEqual([
134
+ 'HOTCRP_TOKEN_HOTCRP_COM holds a site-only token (it starts with hct_): that works on one hotcrp.com site only, not on all of them. Create a token with Site availability "All sites" (it starts with hcT_) and set that in HOTCRP_TOKEN_HOTCRP_COM, or move this one to HOTCRP_TOKEN_MSR2027 if it was made on this site:',
135
+ ...HOSTED_STEPS("HOTCRP_TOKEN_HOTCRP_COM"),
136
+ ]);
137
+ });
138
+
139
+ test("a 401 on a hosted-service site names the variable that was used", () => {
140
+ const f = { kind: "refused", httpStatus: 401, messages: [] } as const;
141
+ expect(
142
+ tokenRefusedLines(
143
+ HOSTED_PORTAL,
144
+ hotcrpSite(HOSTED_SITE),
145
+ f,
146
+ "HOTCRP_TOKEN_HOTCRP_COM",
147
+ ),
148
+ ).toStrictEqual([
149
+ "HOTCRP_TOKEN_HOTCRP_COM was used; it may belong to another hotcrp install (hotcrp.com sites share one token, a self-hosted install has its own), or be revoked or expired",
150
+ ...HOSTED_STEPS("HOTCRP_TOKEN_HOTCRP_COM"),
151
+ ]);
152
+ });
153
+
75
154
  test("the site's variable set beside a site-less one: the site's token is the one used", async () => {
76
155
  const r = await run(
77
156
  {},
@@ -105,7 +184,7 @@ test("a 401 from the portal: the portal's words, which variable was used, and ho
105
184
  );
106
185
  const said = [
107
186
  "the portal refused (HTTP 401): Unauthorized",
108
- "HOTCRP_TOKEN_127_0_0_1_9 was used; it may belong to another hotcrp site (tokens are per site), or be revoked or expired",
187
+ "HOTCRP_TOKEN_127_0_0_1_9 was used; it may belong to another hotcrp install (hotcrp.com sites share one token, a self-hosted install has its own), or be revoked or expired",
109
188
  ...STEPS,
110
189
  ];
111
190
  expect(map(runs, (r) => [r.code, r.errs])).toStrictEqual(
@@ -117,21 +196,33 @@ test("a 403 names a missing scope; any other failure says nothing about the toke
117
196
  const portal = { kind: "hotcrp", url: SITE } as const;
118
197
  const f = (httpStatus: number) =>
119
198
  ({ kind: "refused", httpStatus, messages: [] }) as const;
120
- expect(tokenRefusedLines(portal, hotcrpSite(SITE), f(403))).toStrictEqual([
199
+ expect(
200
+ tokenRefusedLines(
201
+ portal,
202
+ hotcrpSite(SITE),
203
+ f(403),
204
+ "HOTCRP_TOKEN_127_0_0_1_9",
205
+ ),
206
+ ).toStrictEqual([
121
207
  "HOTCRP_TOKEN_127_0_0_1_9 was used; the site turned the request away — the token may lack a scope this subcommand needs",
122
208
  ...STEPS,
123
209
  ]);
124
- expect(tokenRefusedLines(portal, hotcrpSite(SITE), f(500))).toStrictEqual([]);
125
210
  expect(
126
- tokenRefusedLines(portal, hotcrpSite(SITE), {
127
- kind: "unreachable",
128
- detail: "x",
129
- }),
211
+ tokenRefusedLines(portal, hotcrpSite(SITE), f(500), "X"),
212
+ ).toStrictEqual([]);
213
+ expect(
214
+ tokenRefusedLines(
215
+ portal,
216
+ hotcrpSite(SITE),
217
+ { kind: "unreachable", detail: "x" },
218
+ "X",
219
+ ),
130
220
  ).toStrictEqual([]);
131
221
  expect(
132
222
  tokenProblemLines(portal, hotcrpSite(SITE), {
133
223
  kind: "missing",
134
224
  variable: "HOTCRP_TOKEN_127_0_0_1_9",
225
+ shared: null,
135
226
  }),
136
227
  ).toStrictEqual([
137
228
  `no hotcrp token for ${SITE}: HOTCRP_TOKEN_127_0_0_1_9 is not set`,
package/src/submission.ts CHANGED
@@ -102,10 +102,13 @@ export function tokenSteps(
102
102
  variable: string,
103
103
  ): readonly string[] {
104
104
  const c = site.credentials;
105
+ const shared = site.sharedVariable;
105
106
  return [
106
107
  ` 1. create a token on this site: ${c.page} (${c.where}), with the scopes ${c.scopes}`,
107
108
  ` 2. set it in your environment — never paste it into a chat: export ${variable}=<the token>`,
108
- ` tokens are per ${portal.kind} site: ${variable} is read for ${hostOf(portal.url)} alone, so two venues take two variables`,
109
+ shared === null
110
+ ? ` a self-hosted install has a variable of its own: ${variable} is read for ${hostOf(portal.url)} alone, and never HOTCRP_TOKEN_HOTCRP_COM, which serves hotcrp.com sites only`
111
+ : ` one token serves every hotcrp.com site: ${shared} is read for all of them; ${site.tokenVariable}, when set, overrides it for ${hostOf(portal.url)} alone`,
109
112
  ];
110
113
  }
111
114
 
@@ -115,30 +118,36 @@ export function tokenProblemLines(
115
118
  site: PortalSite,
116
119
  p: TokenProblem,
117
120
  ): readonly string[] {
121
+ const asked = p.shared ?? p.variable;
118
122
  const head =
119
- p.kind === "missing"
120
- ? `no ${portal.kind} token for ${portal.url}: ${p.variable} is not set`
121
- : `${p.siteLess} is no longer read: tokens are per ${portal.kind} site. If it was made on ${hostOf(portal.url)}, rename it to ${p.variable}; if it was made on another site, rename it to that site's variable (${site.variablePattern}) and create a token here:`;
122
- return [head, ...tokenSteps(portal, site, p.variable)];
123
+ p.kind === "site-only"
124
+ ? `${p.shared} holds a site-only token (it starts with hct_): that works on one hotcrp.com site only, not on all of them. Create a token with Site availability "All sites" (it starts with hcT_) and set that in ${p.shared}, or move this one to ${p.variable} if it was made on this site:`
125
+ : p.kind === "missing"
126
+ ? `no ${portal.kind} token for ${portal.url}: ${asked} is not set${p.shared === null ? "" : ` (${p.variable} would override it for this site)`}`
127
+ : p.shared === null
128
+ ? `${p.siteLess} is no longer read: tokens are per ${portal.kind} site. If it was made on ${hostOf(portal.url)}, rename it to ${p.variable}; if it was made on another site, rename it to that site's variable (${site.variablePattern}) and create a token here:`
129
+ : `${p.siteLess} is no longer read. If it was made on a hotcrp.com site, rename it to ${p.shared} (every hotcrp.com site) or ${p.variable} (this site alone); if it was made on a self-hosted install, rename it to that install's variable (${site.variablePattern}) and create a token here:`;
130
+ return [head, ...tokenSteps(portal, site, asked)];
123
131
  }
124
132
 
125
133
  /**
126
134
  * What to do when the portal turned the token away: 401 is "this site does not know the token", 403
127
- * a token without the scope — both answered with the site's token page. Empty for anything else. Pure.
135
+ * a token without the scope — both answered with the site's token page, and the variable that was
136
+ * `used`. Empty for anything else. Pure.
128
137
  */
129
138
  export function tokenRefusedLines(
130
139
  portal: SupportedPortal,
131
140
  site: PortalSite,
132
141
  f: PortalFailure,
142
+ used: string,
133
143
  ): readonly string[] {
134
144
  if (f.kind !== "refused" || (f.httpStatus !== 401 && f.httpStatus !== 403))
135
145
  return [];
136
- const variable = site.tokenVariable;
137
146
  const why =
138
147
  f.httpStatus === 401
139
- ? `${variable} was used; it may belong to another ${portal.kind} site (tokens are per site), or be revoked or expired`
140
- : `${variable} was used; the site turned the request away — the token may lack a scope this subcommand needs`;
141
- return [why, ...tokenSteps(portal, site, variable)];
148
+ ? `${used} was used; it may belong to another ${portal.kind} install (hotcrp.com sites share one token, a self-hosted install has its own), or be revoked or expired`
149
+ : `${used} was used; the site turned the request away — the token may lack a scope this subcommand needs`;
150
+ return [why, ...tokenSteps(portal, site, used)];
142
151
  }
143
152
 
144
153
  export const SUBCOMMANDS = ["new", "show", "update", "topics"] as const;
@@ -1149,9 +1158,17 @@ export function usageProblem(a: SubmissionArgs): string | null {
1149
1158
  /** The variables a site's token lookup reads. */
1150
1159
  const tokenNames = (site: PortalSite) => ({
1151
1160
  variable: site.tokenVariable,
1161
+ shared: site.sharedVariable,
1162
+ siteOnly: site.isSiteOnlyToken,
1152
1163
  siteLess: site.siteLessVariable,
1153
1164
  });
1154
1165
 
1166
+ /** The lines for a refusal, naming the variable the token came from. */
1167
+ const refusedWith =
1168
+ (portal: SupportedPortal, site: PortalSite, used: string) =>
1169
+ (f: PortalFailure) =>
1170
+ tokenRefusedLines(portal, site, f, used);
1171
+
1155
1172
  /** No token to use: the complete instruction, exit 2 — nothing is sent. */
1156
1173
  function tokenMissing(
1157
1174
  portal: SupportedPortal,
@@ -1185,7 +1202,7 @@ export async function runSubmission(
1185
1202
  const withToken: RunDeps = {
1186
1203
  ...deps,
1187
1204
  portalSite: site,
1188
- refused: (f) => tokenRefusedLines(t.value.portal, site, f),
1205
+ refused: refusedWith(t.value.portal, site, found.value.variable),
1189
1206
  };
1190
1207
  const sending = { ...t.value, fields: ready.value.fields };
1191
1208
  if (a.sub === "topics") return runTopics(sending, portal, withToken);