@codyswann/lisa 6.0.0 → 6.0.1

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 (73) hide show
  1. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  2. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  3. package/dist/core/upstream-evidence-manifest.js +16 -2
  4. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  5. package/package.json +5 -5
  6. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  7. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  8. package/plugins/lisa-agy/plugin.json +1 -1
  9. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  10. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  11. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  12. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  13. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  14. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  15. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  16. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  17. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  18. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  19. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  20. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  21. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  22. package/plugins/lisa-expo-agy/plugin.json +1 -1
  23. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  24. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  25. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  26. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  27. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  28. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  29. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  30. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  31. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  32. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  33. package/plugins/lisa-harper-fabric-devin/.devin-plugin/plugin.json +1 -1
  34. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  35. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  36. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  37. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  38. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  39. package/plugins/lisa-nestjs-devin/.claude-plugin/plugin.json +1 -1
  40. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  41. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  42. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  43. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  44. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  45. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  46. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  48. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  49. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  50. package/plugins/lisa-rails-agy/plugin.json +1 -1
  51. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  52. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  53. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  54. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  55. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  56. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  57. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  58. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  59. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  60. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  62. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  63. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  64. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  65. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  66. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  67. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  69. package/scripts/check-self-dependency-pin.mjs +172 -5
  70. package/scripts/push-self-pin-raise.sh +79 -0
  71. package/scripts/raise-self-dependency-pin.mjs +166 -0
  72. package/scripts/two-channel-couplings.json +125 -9
  73. package/scripts/verify-self-pin-raise.mjs +487 -0
@@ -0,0 +1,487 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Prove a self-pin raise changes the one line it claims to, and nothing else
4
+ * (CodySwannGT/lisa#4951).
5
+ *
6
+ * The deploy workflow raises Lisa's own `@codyswann/lisa` pin in a job with
7
+ * no secrets: that job runs `bun install`, the build and the checks, all of
8
+ * which execute dependency code, the just-published Lisa included. A SEPARATE
9
+ * job then pushes the result with the ruleset-bypassing deploy key. That job
10
+ * runs no dependency code and trusts nothing the unprivileged job produced:
11
+ *
12
+ * 1. **package.json** (`manifest` mode, the default): the candidate is accepted
13
+ * only when it is main's text with exactly the self-pin value replaced by
14
+ * `^<published version>`.
15
+ * 2. **bun.lock** (`lockfile` mode): the push job does NOT take the candidate
16
+ * lockfile on trust, and it cannot be checked entry by entry either — a
17
+ * major raise legitimately changes other entries (the self-dependency's own
18
+ * transitive tree moves). Instead the push job regenerates the lockfile
19
+ * itself with `bun install --lockfile-only --ignore-scripts`, from main's
20
+ * lockfile plus the verified package.json. That reads registry manifests
21
+ * only: no tarball is downloaded and no package code runs. This mode then
22
+ * requires the candidate the prepare job TESTED to be byte-identical to the
23
+ * lockfile the push job GENERATED, so what was tested is what is pushed, and
24
+ * a lockfile rewritten by dependency code in the prepare job is refused. On
25
+ * top of that, the `@codyswann/lisa` entry must name exactly the published
26
+ * version with the integrity the npm registry reports for it, fetched here
27
+ * with a deadline and failing closed.
28
+ *
29
+ * 3. **Exact resolution** (`spec` mode): a caret range can resolve a NEWER
30
+ * release than the one being raised to — a retried 7.0.0 raise after 7.0.1
31
+ * shipped would lock 7.0.1 and fail the lockfile check. So both jobs resolve
32
+ * with the pin set to the exact published version (`spec --form exact`),
33
+ * then write the committed caret range back into package.json and the
34
+ * lockfile's workspace specifier (`spec --form caret`). Bun keeps a locked
35
+ * version that satisfies the declared range, so the resulting pair passes
36
+ * `--frozen-lockfile` and locks exactly the published release.
37
+ *
38
+ * Deliberately dependency-free (no `semver`, no repository imports), because
39
+ * the privileged job has no `node_modules` and must not need any.
40
+ * @module scripts/verify-self-pin-raise
41
+ */
42
+ import { readFileSync, writeFileSync } from "node:fs";
43
+ import process from "node:process";
44
+
45
+ import { invokedAsScript } from "./lib/invoked-as-script.mjs";
46
+
47
+ /** The package whose pin is raised. */
48
+ const SELF_PACKAGE = "@codyswann/lisa";
49
+
50
+ /** A plain release version: no range operators, no prerelease, no build. */
51
+ const RELEASE_VERSION = /^\d+\.\d+\.\d+$/;
52
+
53
+ /** The line a caller greps for. */
54
+ const VERDICT_PREFIX = "verify-self-pin-raise:";
55
+
56
+ /** Public npm registry, the source of truth for the published tarball. */
57
+ const DEFAULT_REGISTRY = "https://registry.npmjs.org";
58
+
59
+ /** How long the registry may take before the push is refused. */
60
+ const REGISTRY_TIMEOUT_MS = 30_000;
61
+
62
+ /** How many times a transient registry failure is tried before refusing. */
63
+ const REGISTRY_ATTEMPTS = 3;
64
+
65
+ /** Base delay between registry attempts; attempt n waits n times this. */
66
+ const REGISTRY_RETRY_DELAY_MS = 2_000;
67
+
68
+ /** How much of a differing lockfile line a refusal prints. */
69
+ const EXCERPT_LENGTH = 160;
70
+
71
+ /**
72
+ * The self-dependency's package entry in a bun.lock: the resolved version and
73
+ * its integrity. Anchored to the four-space `packages` indentation, so the
74
+ * `@codyswann/lisa/<nested>` entries and the workspace's declared range never
75
+ * match.
76
+ */
77
+ const SELF_LOCK_ENTRY =
78
+ /^ {4}"@codyswann\/lisa": \["@codyswann\/lisa@([^"]+)", "", \{.*\}, "(sha512-[A-Za-z0-9+/=]+)"\],$/gm;
79
+
80
+ /**
81
+ * The root workspace's declared self-pin in a bun.lock, eight spaces deep
82
+ * under `workspaces[""].devDependencies`. Package entries sit at four spaces
83
+ * and start with `[`, so they never match.
84
+ * @param {string} spec - The exact specifier text expected on the line.
85
+ * @returns {RegExp} A global, multiline matcher for that line.
86
+ */
87
+ function workspaceSpecLine(spec) {
88
+ const escaped = spec.replace(/[.^]/g, character => `\\${character}`);
89
+ return new RegExp(`^( {8}"@codyswann/lisa": )"${escaped}"(,?)$`, "gm");
90
+ }
91
+
92
+ /**
93
+ * Serialize a manifest the way the raise script writes it.
94
+ * @param {object} manifest - Parsed package.json.
95
+ * @returns {string} Two-space JSON with a trailing newline.
96
+ */
97
+ function serialize(manifest) {
98
+ return `${JSON.stringify(manifest, null, 2)}\n`;
99
+ }
100
+
101
+ /**
102
+ * Switch the self-pin between the exact published version (to resolve) and
103
+ * the committed caret range (to commit).
104
+ *
105
+ * `exact` requires the manifest to declare `^version` and sets it to
106
+ * `version`; the lockfile is left for the install to rewrite. `caret` requires
107
+ * the manifest AND the lockfile's workspace specifier to declare exactly
108
+ * `version` — proof the exact resolution ran — and sets both to `^version`.
109
+ * @param {object} input - The current texts and the requested form.
110
+ * @param {string} input.manifestText - package.json text.
111
+ * @param {string} input.lockText - bun.lock text.
112
+ * @param {string} input.version - The published release version.
113
+ * @param {"exact" | "caret"} input.form - Which specifier to write.
114
+ * @returns {{ok: boolean, detail: string, manifestText?: string, lockText?: string}} The verdict and, when ok, the new texts.
115
+ */
116
+ export function setSelfSpec({ manifestText, lockText, version, form }) {
117
+ if (!RELEASE_VERSION.test(version)) {
118
+ return { ok: false, detail: `"${version}" is not a release version` };
119
+ }
120
+ if (form !== "exact" && form !== "caret") {
121
+ return { ok: false, detail: `"${form}" is not exact or caret` };
122
+ }
123
+ const manifest = JSON.parse(manifestText);
124
+ const from = form === "exact" ? `^${version}` : version;
125
+ const to = form === "exact" ? version : `^${version}`;
126
+ const declared = manifest?.devDependencies?.[SELF_PACKAGE];
127
+ if (declared !== from) {
128
+ return {
129
+ ok: false,
130
+ detail: `package.json declares ${SELF_PACKAGE} ${JSON.stringify(declared)}, not "${from}"`,
131
+ };
132
+ }
133
+ const nextManifest = serialize({
134
+ ...manifest,
135
+ devDependencies: { ...manifest.devDependencies, [SELF_PACKAGE]: to },
136
+ });
137
+ if (form === "exact") {
138
+ return {
139
+ ok: true,
140
+ detail: `resolving ${SELF_PACKAGE} at exactly ${version}`,
141
+ manifestText: nextManifest,
142
+ lockText,
143
+ };
144
+ }
145
+ const lines = [...lockText.matchAll(workspaceSpecLine(from))];
146
+ if (lines.length !== 1) {
147
+ return {
148
+ ok: false,
149
+ detail: `bun.lock has ${lines.length} workspace specifiers "${from}" for ${SELF_PACKAGE}, not exactly one`,
150
+ };
151
+ }
152
+ return {
153
+ ok: true,
154
+ detail: `committing ${SELF_PACKAGE} as ^${version}, locked at ${version}`,
155
+ manifestText: nextManifest,
156
+ lockText: lockText.replace(workspaceSpecLine(from), `$1"${to}"$2`),
157
+ };
158
+ }
159
+
160
+ /**
161
+ * Decide whether the candidate manifest is the base with only the pin raised.
162
+ * @param {string} baseText - main's package.json, as text.
163
+ * @param {string} candidateText - The raised package.json, as text.
164
+ * @param {string} version - The version the release published.
165
+ * @returns {{ok: boolean, detail: string}} The verdict.
166
+ */
167
+ export function verifySelfPinRaise(baseText, candidateText, version) {
168
+ if (!RELEASE_VERSION.test(version)) {
169
+ return { ok: false, detail: `"${version}" is not a release version` };
170
+ }
171
+ const base = JSON.parse(baseText);
172
+ const spec = base?.devDependencies?.[SELF_PACKAGE];
173
+ if (typeof spec !== "string") {
174
+ return {
175
+ ok: false,
176
+ detail: `main's package.json declares no devDependencies["${SELF_PACKAGE}"]`,
177
+ };
178
+ }
179
+ const expected = JSON.stringify(
180
+ {
181
+ ...base,
182
+ devDependencies: {
183
+ ...base.devDependencies,
184
+ [SELF_PACKAGE]: `^${version}`,
185
+ },
186
+ },
187
+ null,
188
+ 2
189
+ );
190
+ if (`${expected}\n` !== candidateText) {
191
+ return {
192
+ ok: false,
193
+ detail: `the candidate is not main's package.json with only "${SELF_PACKAGE}" set to ^${version}`,
194
+ };
195
+ }
196
+ if (spec === `^${version}`) {
197
+ return { ok: false, detail: `main already pins ^${version}` };
198
+ }
199
+ return {
200
+ ok: true,
201
+ detail: `only ${SELF_PACKAGE} changes: ${spec} → ^${version}`,
202
+ };
203
+ }
204
+
205
+ /**
206
+ * Require the lockfile the prepare job tested to be the one this job generated.
207
+ * @param {string} regeneratedText - bun.lock as regenerated in the push job.
208
+ * @param {string} candidateText - bun.lock the prepare job tested.
209
+ * @returns {{ok: boolean, detail: string}} The verdict.
210
+ */
211
+ export function verifyLockfileMatch(regeneratedText, candidateText) {
212
+ if (regeneratedText === candidateText) {
213
+ return { ok: true, detail: "the tested bun.lock is the regenerated one" };
214
+ }
215
+ const regenerated = regeneratedText.split("\n");
216
+ const candidate = candidateText.split("\n");
217
+ const length = Math.max(regenerated.length, candidate.length);
218
+ const line = Array.from({ length }, (_unused, index) => index).find(
219
+ index => regenerated[index] !== candidate[index]
220
+ );
221
+ const excerpt = value =>
222
+ value === undefined
223
+ ? "<end of file>"
224
+ : JSON.stringify(value.slice(0, EXCERPT_LENGTH));
225
+ return {
226
+ ok: false,
227
+ detail:
228
+ `the tested bun.lock differs from the one regenerated from main at line ${(line ?? 0) + 1}: ` +
229
+ `regenerated ${excerpt(regenerated[line ?? 0])}, tested ${excerpt(candidate[line ?? 0])}`,
230
+ };
231
+ }
232
+
233
+ /**
234
+ * Require the self-dependency's lock entry to be the published tarball.
235
+ * @param {string} lockText - bun.lock text.
236
+ * @param {string} version - The version the release published.
237
+ * @param {string} registryIntegrity - `dist.integrity` the registry reports.
238
+ * @returns {{ok: boolean, detail: string}} The verdict.
239
+ */
240
+ export function verifySelfLockEntry(lockText, version, registryIntegrity) {
241
+ const entries = [...lockText.matchAll(SELF_LOCK_ENTRY)];
242
+ if (entries.length !== 1) {
243
+ return {
244
+ ok: false,
245
+ detail: `bun.lock has ${entries.length} "${SELF_PACKAGE}" package entries, not exactly one`,
246
+ };
247
+ }
248
+ const [, locked, integrity] = entries[0];
249
+ if (locked !== version) {
250
+ return {
251
+ ok: false,
252
+ detail: `bun.lock resolves ${SELF_PACKAGE}@${locked}, not the published ${version}`,
253
+ };
254
+ }
255
+ if (integrity !== registryIntegrity) {
256
+ return {
257
+ ok: false,
258
+ detail: `bun.lock's integrity for ${SELF_PACKAGE}@${version} is not the registry's`,
259
+ };
260
+ }
261
+ return {
262
+ ok: true,
263
+ detail: `${SELF_PACKAGE}@${version} is locked at the registry's integrity`,
264
+ };
265
+ }
266
+
267
+ /**
268
+ * One registry request. `retry` is true only for a failure that says nothing
269
+ * about the document — a network error, a deadline, or a 5xx. A 404, any other
270
+ * 4xx, and a document that does not describe the version are answers, and an
271
+ * answer is never asked again.
272
+ * @param {string} url - The exact-version registry URL.
273
+ * @param {string} version - The version the document must describe.
274
+ * @param {typeof fetch} fetchImpl - The fetch seam.
275
+ * @param {number} timeoutMs - The per-request deadline.
276
+ * @returns {Promise<{integrity: string | null, detail: string, retry: boolean}>} The answer.
277
+ */
278
+ async function requestIntegrity(url, version, fetchImpl, timeoutMs) {
279
+ try {
280
+ const response = await fetchImpl(url, {
281
+ headers: { accept: "application/json" },
282
+ signal: AbortSignal.timeout(timeoutMs),
283
+ });
284
+ if (!response.ok) {
285
+ return {
286
+ integrity: null,
287
+ detail: `HTTP ${response.status} from ${url}`,
288
+ retry: response.status >= 500,
289
+ };
290
+ }
291
+ const body = await response.json();
292
+ const integrity = body?.dist?.integrity;
293
+ if (body?.version !== version || typeof integrity !== "string") {
294
+ return {
295
+ integrity: null,
296
+ detail: `${url} did not describe ${version} with a dist.integrity`,
297
+ retry: false,
298
+ };
299
+ }
300
+ return { integrity, detail: "ok", retry: false };
301
+ } catch (error) {
302
+ return { integrity: null, detail: `${url}: ${error.message}`, retry: true };
303
+ }
304
+ }
305
+
306
+ /**
307
+ * Ask the registry for the published tarball's integrity, failing closed.
308
+ *
309
+ * A transient failure (network error, deadline, 5xx) is retried a bounded
310
+ * number of times; when every attempt fails the answer is still `null`, so the
311
+ * push is refused. A 404 or a wrong document is returned at once.
312
+ * @param {object} options - Version, registry, fetch seam, deadline, attempts and sleep seam.
313
+ * @returns {Promise<{integrity: string | null, detail: string}>} The answer.
314
+ */
315
+ export async function fetchRegistryIntegrity({
316
+ version,
317
+ registry = DEFAULT_REGISTRY,
318
+ fetchImpl = fetch,
319
+ timeoutMs = REGISTRY_TIMEOUT_MS,
320
+ attempts = REGISTRY_ATTEMPTS,
321
+ sleep = milliseconds =>
322
+ new Promise(resolve => {
323
+ setTimeout(resolve, milliseconds);
324
+ }),
325
+ }) {
326
+ const url = `${registry}/${SELF_PACKAGE}/${version}`;
327
+ const attempt = async number => {
328
+ const answer = await requestIntegrity(url, version, fetchImpl, timeoutMs);
329
+ if (!answer.retry || number >= attempts) {
330
+ const suffix =
331
+ answer.retry && attempts > 1 ? ` (after ${attempts} attempts)` : "";
332
+ return {
333
+ integrity: answer.integrity,
334
+ detail: `${answer.detail}${suffix}`,
335
+ };
336
+ }
337
+ await sleep(number * REGISTRY_RETRY_DELAY_MS);
338
+ return attempt(number + 1);
339
+ };
340
+ return attempt(1);
341
+ }
342
+
343
+ /**
344
+ * Print a verdict line and turn it into an exit code.
345
+ * @param {{ok: boolean, detail: string}} verdict - The verdict.
346
+ * @returns {number} 0 only for ok.
347
+ */
348
+ function report(verdict) {
349
+ process.stdout.write(
350
+ `${VERDICT_PREFIX} ${verdict.ok ? "ok" : "refused"} — ${verdict.detail}\n`
351
+ );
352
+ return verdict.ok ? 0 : 1;
353
+ }
354
+
355
+ /**
356
+ * Return a required CLI option.
357
+ * @param {string[]} argv - Arguments after the script path.
358
+ * @param {string} name - Option name, `--` included.
359
+ * @returns {string | undefined} The option's value.
360
+ */
361
+ function option(argv, name) {
362
+ const index = argv.indexOf(name);
363
+ const value = index === -1 ? undefined : argv[index + 1];
364
+ return value === undefined || value.startsWith("--") ? undefined : value;
365
+ }
366
+
367
+ /**
368
+ * Run the verification for a workflow step.
369
+ * @param {string[]} argv - `--base <file> --candidate <file> --version <v>`.
370
+ * @returns {number} Process exit code: 0 only for a proven one-line raise.
371
+ */
372
+ export function main(argv) {
373
+ const base = option(argv, "--base");
374
+ const candidate = option(argv, "--candidate");
375
+ const version = option(argv, "--version");
376
+ if (base === undefined || candidate === undefined || version === undefined) {
377
+ process.stderr.write(
378
+ "❌ usage: verify-self-pin-raise.mjs --base <file> --candidate <file> --version <version>\n"
379
+ );
380
+ return 1;
381
+ }
382
+ return report(
383
+ verifySelfPinRaise(
384
+ readFileSync(base, "utf8"),
385
+ readFileSync(candidate, "utf8"),
386
+ version
387
+ )
388
+ );
389
+ }
390
+
391
+ /**
392
+ * Run the lockfile verification for a workflow step.
393
+ * @param {string[]} argv - `--regenerated <file> --candidate <file> --version <v>`.
394
+ * @param {object} [injected] - Test seams forwarded to {@link fetchRegistryIntegrity}.
395
+ * @returns {Promise<number>} Process exit code: 0 only when both checks pass.
396
+ */
397
+ export async function mainLockfile(argv, injected = {}) {
398
+ const regenerated = option(argv, "--regenerated");
399
+ const candidate = option(argv, "--candidate");
400
+ const version = option(argv, "--version");
401
+ if (
402
+ regenerated === undefined ||
403
+ candidate === undefined ||
404
+ version === undefined ||
405
+ !RELEASE_VERSION.test(version)
406
+ ) {
407
+ process.stderr.write(
408
+ "❌ usage: verify-self-pin-raise.mjs lockfile --regenerated <file> --candidate <file> --version <release version>\n"
409
+ );
410
+ return 1;
411
+ }
412
+ const regeneratedText = readFileSync(regenerated, "utf8");
413
+ const match = verifyLockfileMatch(
414
+ regeneratedText,
415
+ readFileSync(candidate, "utf8")
416
+ );
417
+ if (!match.ok) return report(match);
418
+ const registry = option(argv, "--registry") ?? DEFAULT_REGISTRY;
419
+ const answer = await fetchRegistryIntegrity({
420
+ version,
421
+ registry,
422
+ ...injected,
423
+ });
424
+ if (answer.integrity === null) {
425
+ return report({
426
+ ok: false,
427
+ detail: `could not read the registry's integrity, so nothing is pushed: ${answer.detail}`,
428
+ });
429
+ }
430
+ return report(
431
+ verifySelfLockEntry(regeneratedText, version, answer.integrity)
432
+ );
433
+ }
434
+
435
+ /**
436
+ * Switch the pin between exact and caret for a workflow step, in place.
437
+ * @param {string[]} argv - `--form exact|caret --version <v> [--manifest <file>] [--lockfile <file>]`.
438
+ * @returns {number} Process exit code: 0 only when the switch was written.
439
+ */
440
+ export function mainSpec(argv) {
441
+ const form = option(argv, "--form");
442
+ const version = option(argv, "--version");
443
+ if (form === undefined || version === undefined) {
444
+ process.stderr.write(
445
+ "❌ usage: verify-self-pin-raise.mjs spec --form exact|caret --version <version> [--manifest <file>] [--lockfile <file>]\n"
446
+ );
447
+ return 1;
448
+ }
449
+ const manifest = option(argv, "--manifest") ?? "package.json";
450
+ const lockfile = option(argv, "--lockfile") ?? "bun.lock";
451
+ const result = setSelfSpec({
452
+ manifestText: readFileSync(manifest, "utf8"),
453
+ lockText: readFileSync(lockfile, "utf8"),
454
+ version,
455
+ form,
456
+ });
457
+ if (result.ok) {
458
+ writeFileSync(manifest, result.manifestText);
459
+ writeFileSync(lockfile, result.lockText);
460
+ }
461
+ return report(result);
462
+ }
463
+
464
+ /* c8 ignore start -- CLI wiring, exercised through main() in tests */
465
+ if (invokedAsScript(import.meta.url)) {
466
+ try {
467
+ const argv = process.argv.slice(2);
468
+ if (argv[0] === "spec") {
469
+ process.exitCode = mainSpec(argv.slice(1));
470
+ } else if (argv[0] === "lockfile") {
471
+ mainLockfile(argv.slice(1))
472
+ .then(code => {
473
+ process.exitCode = code;
474
+ })
475
+ .catch(error => {
476
+ process.stderr.write(`❌ ${error.message}\n`);
477
+ process.exitCode = 1;
478
+ });
479
+ } else {
480
+ process.exitCode = main(argv);
481
+ }
482
+ } catch (error) {
483
+ process.stderr.write(`❌ ${error.message}\n`);
484
+ process.exitCode = 1;
485
+ }
486
+ }
487
+ /* c8 ignore stop */