@ultimat3/cli 31.26.0 → 31.28.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.
- package/CLAUDE.md +47 -37
- package/README.md +19 -8
- package/package.json +29 -29
- package/src/app-manifest.ts +6 -1
- package/src/app-mcp.ts +17 -3
- package/src/cmd-cache-spec.ts +5 -2
- package/src/cmd-db-spec.ts +2 -3
- package/src/cmd-db.ts +0 -2
- package/src/cmd-deploy-verify-sample.ts +93 -0
- package/src/cmd-deploy-verify.ts +2 -41
- package/src/cmd-dev-spec.ts +15 -1
- package/src/cmd-dev.ts +31 -4
- package/src/cmd-doctor.ts +15 -4
- package/src/cmd-exercise-spec.ts +7 -1
- package/src/cmd-exercise.ts +22 -10
- package/src/cmd-generate.ts +2 -0
- package/src/cmd-jobs-spec.ts +3 -6
- package/src/cmd-jobs.ts +1 -7
- package/src/cmd-logs-spec.ts +2 -1
- package/src/cmd-logs.ts +9 -28
- package/src/cmd-planned.ts +11 -45
- package/src/cmd-profile-frames.ts +99 -0
- package/src/cmd-profile-spec.ts +24 -0
- package/src/cmd-profile.ts +164 -0
- package/src/cmd-repro-spec.ts +13 -1
- package/src/cmd-repro.ts +37 -5
- package/src/cmd-status-sample.ts +57 -0
- package/src/cmd-status-spec.ts +30 -0
- package/src/cmd-status.ts +108 -0
- package/src/cmd-token-spec.ts +5 -2
- package/src/cmd-token.ts +7 -3
- package/src/cmd-upgrade-codemods.ts +71 -0
- package/src/cmd-upgrade-spec.ts +19 -5
- package/src/cmd-upgrade.ts +91 -34
- package/src/codemods/agents-dev-mcp.ts +50 -0
- package/src/codemods/authenticator-session-refusal.ts +214 -0
- package/src/codemods/biome-no-default-export.ts +58 -0
- package/src/codemods/bunfig-island-coverage.ts +33 -0
- package/src/codemods/chart-dashboard.ts +73 -0
- package/src/codemods/ci-e2e-browser-stock.ts +75 -0
- package/src/codemods/ci-e2e-browser.ts +63 -0
- package/src/codemods/codemod.ts +58 -0
- package/src/codemods/define-error-leaf.ts +73 -0
- package/src/codemods/docs-ci-parts.ts +65 -0
- package/src/codemods/docs-gate-prose.ts +53 -0
- package/src/codemods/docs-island-rows.ts +31 -0
- package/src/codemods/docs-shipped-guards.ts +100 -0
- package/src/codemods/docs-test-services.ts +62 -0
- package/src/codemods/engine-diff.ts +104 -0
- package/src/codemods/engine-edits.ts +111 -0
- package/src/codemods/engine-fs.ts +95 -0
- package/src/codemods/engine.ts +191 -0
- package/src/codemods/format-edited-hook-3122.ts +28 -0
- package/src/codemods/format-edited-hook.ts +152 -0
- package/src/codemods/helm-alerts-objective.ts +105 -0
- package/src/codemods/helm-alerts-stock.ts +108 -0
- package/src/codemods/index.ts +56 -0
- package/src/codemods/metrics-probe-healthz.ts +47 -0
- package/src/codemods/pending.ts +36 -0
- package/src/codemods/repro-gitignore.ts +40 -0
- package/src/codemods/runtime-pin-lines.ts +109 -0
- package/src/codemods/runtime-pin.ts +116 -0
- package/src/codemods/solid-floor.ts +63 -0
- package/src/codemods/test-ports.ts +86 -0
- package/src/codemods/test-suites.ts +37 -0
- package/src/codemods/theme-toggle-mount-over.ts +70 -0
- package/src/codemods/vendored-guards.ts +186 -0
- package/src/codemods/verify-floor-skips.ts +88 -0
- package/src/codemods/verify-floor-steps.ts +90 -0
- package/src/coverage-island.ts +121 -0
- package/src/coverage-lcov.ts +49 -5
- package/src/coverage-remap.ts +146 -0
- package/src/db-replay-engine-prepared.ts +66 -0
- package/src/db-replay-engine-template.ts +156 -0
- package/src/db-replay-engine.ts +4 -0
- package/src/db-replay-scratch-reap.ts +54 -0
- package/src/deploy-verify-flags.ts +9 -2
- package/src/deploy-verify-grade.ts +10 -3
- package/src/dev-boot.ts +14 -1
- package/src/dev-dashboard-guard.ts +57 -10
- package/src/dev-host.ts +46 -0
- package/src/dev-tls-cache.ts +103 -0
- package/src/dev-tls-der.ts +69 -0
- package/src/dev-tls.ts +120 -0
- package/src/doctor-advisory-floors.ts +113 -0
- package/src/doctor-browser.ts +60 -0
- package/src/doctor-guards.ts +39 -86
- package/src/doctor-superseded.ts +67 -0
- package/src/error-codes-doctor.ts +12 -4
- package/src/error-codes-verify.ts +47 -0
- package/src/error-codes.ts +20 -23
- package/src/exercise-database.ts +47 -9
- package/src/exercise-push-device.ts +51 -0
- package/src/exercise-route-api.ts +74 -0
- package/src/exercise-routes.ts +14 -5
- package/src/exercise-services.ts +3 -1
- package/src/exercise-shard-flag.ts +47 -0
- package/src/fix-command.ts +2 -2
- package/src/generate-factories.ts +5 -11
- package/src/generate-feature-required.ts +9 -4
- package/src/generate-files.ts +26 -7
- package/src/generate-kinds.ts +5 -1
- package/src/guards-built-in-codes.ts +36 -0
- package/src/guards-built-in-refusal.ts +25 -0
- package/src/guards-built-in.ts +134 -0
- package/src/guards-materialize.ts +42 -0
- package/src/guards-paths.ts +37 -0
- package/src/guards-shipped-names.ts +38 -0
- package/src/guards-vendored.ts +73 -0
- package/src/guards.ts +105 -34
- package/src/index.ts +10 -0
- package/src/island-bundle-options.ts +48 -0
- package/src/island-bundle.ts +18 -46
- package/src/island-link.ts +5 -0
- package/src/island-outputs.ts +5 -0
- package/src/lint-findings.ts +3 -3
- package/src/mcp-errors-verify.ts +35 -0
- package/src/mcp-errors.ts +21 -20
- package/src/mcp-host-logs.ts +121 -0
- package/src/mcp-host.ts +12 -73
- package/src/measure-scope.ts +23 -3
- package/src/messages-floor.ts +19 -0
- package/src/messages-repro.ts +16 -2
- package/src/messages-status.ts +10 -0
- package/src/messages-upgrade.ts +15 -0
- package/src/messages.ts +22 -1
- package/src/registry.ts +4 -0
- package/src/repro-archive-collect.ts +161 -0
- package/src/repro-archive-write.ts +96 -0
- package/src/repro-archive.ts +161 -0
- package/src/repro-bundle.ts +8 -16
- package/src/repro-errors.ts +14 -2
- package/src/repro-framework.ts +53 -0
- package/src/repro-parse.ts +87 -0
- package/src/repro-redact.ts +218 -0
- package/src/repro-scrub.ts +257 -0
- package/src/role-start-types.ts +7 -0
- package/src/role-start.ts +4 -0
- package/src/serve-boot.ts +7 -1
- package/src/serve-env-tls.ts +57 -0
- package/src/solid-loader.ts +27 -10
- package/src/superseded-match.ts +87 -0
- package/src/superseded.ts +84 -0
- package/src/templates/bun-image.ts +48 -0
- package/src/templates/generate-export-rows.ts +136 -0
- package/src/templates/generate-import-rows.ts +186 -0
- package/src/templates/generate-rows-slice.ts +95 -0
- package/src/templates/github/ci.yml.ts +5 -1
- package/src/templates/guard-released-forms.ts +112 -0
- package/src/templates/guard-runtime-pin-test.ts +54 -0
- package/src/templates/guard-runtime-pin.ts +189 -0
- package/src/templates/scaffold-claude-agents.ts +6 -6
- package/src/templates/scaffold-claude-commands.ts +1 -1
- package/src/templates/scaffold-claude-hook.ts +18 -8
- package/src/templates/scaffold-claude.ts +2 -2
- package/src/templates/scaffold-db-package.ts +3 -0
- package/src/templates/scaffold-docs.ts +34 -30
- package/src/templates/scaffold-guards.ts +73 -39
- package/src/templates/scaffold-repo.ts +4 -8
- package/src/templates/scaffold-site.ts +4 -1
- package/src/templates/scaffold-suites.ts +72 -0
- package/src/templates/scaffold-test-services.ts +35 -10
- package/src/templates/scaffold-verify-floor.ts +53 -31
- package/src/templates/shapes/api.ts +4 -0
- package/src/templates/slice-foundation.ts +3 -3
- package/src/unthrown-codes.ts +3 -1
- package/src/upgrade-bun-floor.ts +4 -0
- package/src/upgrade-clean-tree.ts +54 -0
- package/src/upgrade-gate-codemods-install.ts +40 -0
- package/src/upgrade-gate-codemods.ts +151 -0
- package/src/upgrade-gate.ts +44 -7
- package/src/upgrade-guards-baseline.ts +43 -0
- package/src/upgrade-guards.ts +37 -2
- package/src/upgrade-lock.ts +118 -0
- package/src/upgrade-plan.ts +2 -1
- package/src/upgrade-report-codemods.ts +54 -0
- package/src/upgrade-report.ts +55 -27
- package/src/upgrade-signals.ts +91 -0
- package/src/upgrade-unfinished.ts +61 -0
- package/src/verify-coverage-run.ts +42 -11
- package/src/verify-e2e.ts +115 -4
- package/src/verify-floor.ts +27 -0
- package/src/verify-guard-baseline.ts +109 -0
- package/src/verify-live.ts +72 -0
- package/src/verify-merge-skips.ts +51 -0
- package/src/verify-merge.ts +36 -2
- package/src/verify-run.ts +48 -7
- package/src/verify-services.ts +287 -0
- package/src/verify-skip-reason.ts +53 -0
- package/src/verify-strict.ts +108 -0
- package/src/verify-test-command.ts +129 -0
- package/src/verify-tests.ts +39 -126
- package/types/babel-modules.d.ts +2 -0
- package/wiki/CLI-Reference.md +200 -27
- package/wiki/Caching-And-Invalidation.md +1 -1
- package/wiki/Entities-And-Migrations.md +1 -1
- package/wiki/Interface-Rules.md +17 -8
- package/wiki/Jobs-And-Workflows.md +3 -3
- package/wiki/Known-Gaps.md +5 -1
- package/wiki/MCP-And-AI.md +1 -1
- package/wiki/Observability.md +1 -0
- package/wiki/PWA-And-Offline.md +1 -1
- package/wiki/Project-Layout.md +4 -4
- package/wiki/Troubleshooting.md +3 -3
- package/wiki/Tutorial-05-Deploy-Free.md +2 -2
- package/wiki/Upgrading.md +8 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// `x upgrade codemods`: this CLI's codemods whose version lies after `--from`, up to `--to` (its own
|
|
2
|
+
// version by default), over the app. A hop runs it as the CLI it just installed, so the codemods
|
|
3
|
+
// are the target release's; by hand it carries an app whose hop ran under a CLI with none.
|
|
4
|
+
|
|
5
|
+
import { requireAppRoot } from './app-root';
|
|
6
|
+
import { CODEMODS } from './codemods';
|
|
7
|
+
import { runCodemods } from './codemods/engine';
|
|
8
|
+
import { fsCodemodApp } from './codemods/engine-fs';
|
|
9
|
+
import type { CommandContext } from './command';
|
|
10
|
+
import { ok } from './command';
|
|
11
|
+
import { BadFlagError } from './errors';
|
|
12
|
+
import { msg } from './messages';
|
|
13
|
+
import type { CommandResult, JsonValue } from './output';
|
|
14
|
+
import { flagBool, flagString } from './parse';
|
|
15
|
+
import { cliVersion } from './registry';
|
|
16
|
+
import { manifestSnapshot, reinstallIfMoved } from './upgrade-gate-codemods-install';
|
|
17
|
+
import { releaseOf } from './upgrade-plan';
|
|
18
|
+
import { codemodCounts, codemodLines } from './upgrade-report-codemods';
|
|
19
|
+
|
|
20
|
+
const FIX =
|
|
21
|
+
'x upgrade codemods --from 31.20.0 --dry-run --json # --from: the version the app came from, its old @ultimat3/cli pin';
|
|
22
|
+
|
|
23
|
+
const release = (ctx: CommandContext, flag: 'from' | 'to'): string | undefined => {
|
|
24
|
+
const value = flagString(ctx.args, flag);
|
|
25
|
+
if (value === undefined || releaseOf(value) !== undefined) return value;
|
|
26
|
+
throw new BadFlagError({
|
|
27
|
+
flag,
|
|
28
|
+
command: 'upgrade codemods',
|
|
29
|
+
reason: `"${value}" is not an exact release, major.minor.patch`,
|
|
30
|
+
fix: FIX,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export async function runUpgradeCodemods(ctx: CommandContext): Promise<CommandResult> {
|
|
35
|
+
const root = requireAppRoot('upgrade codemods', ctx.cwd).dir;
|
|
36
|
+
const from = release(ctx, 'from');
|
|
37
|
+
if (from === undefined) {
|
|
38
|
+
throw new BadFlagError({
|
|
39
|
+
flag: 'from',
|
|
40
|
+
command: 'upgrade codemods',
|
|
41
|
+
reason:
|
|
42
|
+
'names no release, and the codemods to run are the ones after the version the app came from',
|
|
43
|
+
fix: FIX,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const to = release(ctx, 'to') ?? cliVersion();
|
|
47
|
+
const dryRun = flagBool(ctx.args, 'dry-run');
|
|
48
|
+
const before = await manifestSnapshot(root);
|
|
49
|
+
const ran = await runCodemods({
|
|
50
|
+
app: fsCodemodApp(root),
|
|
51
|
+
codemods: CODEMODS,
|
|
52
|
+
from,
|
|
53
|
+
to,
|
|
54
|
+
dryRun,
|
|
55
|
+
});
|
|
56
|
+
// A codemod that moved a package.json owes the install, by hand as on a hop.
|
|
57
|
+
const report =
|
|
58
|
+
!dryRun && (await reinstallIfMoved({ runner: ctx.runner, root, to, before }))
|
|
59
|
+
? { ...ran, reinstalled: true as const }
|
|
60
|
+
: ran;
|
|
61
|
+
const counts = codemodCounts(report);
|
|
62
|
+
return ok(
|
|
63
|
+
'upgrade',
|
|
64
|
+
msg(dryRun ? 'cli.upgrade.codemods.dryRun' : 'cli.upgrade.codemods.done', {
|
|
65
|
+
from,
|
|
66
|
+
to,
|
|
67
|
+
...counts,
|
|
68
|
+
}),
|
|
69
|
+
{ data: { codemods: report as unknown as JsonValue }, lines: codemodLines(report) },
|
|
70
|
+
);
|
|
71
|
+
}
|
package/src/cmd-upgrade-spec.ts
CHANGED
|
@@ -3,24 +3,38 @@
|
|
|
3
3
|
|
|
4
4
|
import type { CommandSpec } from './parse';
|
|
5
5
|
|
|
6
|
+
/** `run` is the hop (a bare `x upgrade`); `codemods` applies the installed release's codemods. */
|
|
7
|
+
export const UPGRADE_SUBCOMMANDS = ['run', 'codemods'] as const;
|
|
8
|
+
|
|
6
9
|
export const upgradeSpec: CommandSpec = {
|
|
7
10
|
name: 'upgrade',
|
|
8
11
|
summary:
|
|
9
|
-
'move every @ultimat3/* one major in lockstep, raise the Bun floor, install, gate — and name the section to read',
|
|
10
|
-
usage:
|
|
12
|
+
'move every @ultimat3/* one major in lockstep, raise the Bun floor, install, apply codemods, gate — and name the section to read',
|
|
13
|
+
usage:
|
|
14
|
+
'x upgrade [--to <version>] [--dry-run] [--json] · x upgrade codemods --from <version> [--to <version>] [--dry-run] [--json]',
|
|
11
15
|
// The one command a repository with pins and no `app.config.ts` can still use: `upgrade-root.ts`
|
|
12
|
-
// finds its root, and its report says which check it could run.
|
|
16
|
+
// finds its root, and its report says which check it could run. `codemods` needs the app.
|
|
17
|
+
subcommands: UPGRADE_SUBCOMMANDS,
|
|
18
|
+
defaultSubcommand: 'run',
|
|
13
19
|
flags: [
|
|
14
20
|
{
|
|
15
21
|
name: 'to',
|
|
16
22
|
type: 'string',
|
|
17
23
|
summary:
|
|
18
|
-
'an exact release inside the next major; over a mixed set, inside the lowest pins’ next major, and only those pins move (default: the next major’s newest)',
|
|
24
|
+
'an exact release inside the next major; over a mixed set, inside the lowest pins’ next major, and only those pins move (default: the next major’s newest). With codemods: the last release whose codemods run (default: this CLI’s own)',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'from',
|
|
28
|
+
type: 'string',
|
|
29
|
+
subcommands: ['codemods'],
|
|
30
|
+
summary:
|
|
31
|
+
'the release the app came from: the codemods whose version lies after it, up to --to, run',
|
|
19
32
|
},
|
|
20
33
|
{
|
|
21
34
|
name: 'dry-run',
|
|
22
35
|
type: 'boolean',
|
|
23
|
-
summary:
|
|
36
|
+
summary:
|
|
37
|
+
'report the pins, the Bun floor edits, the codemods and the section; write nothing, run no gate',
|
|
24
38
|
},
|
|
25
39
|
],
|
|
26
40
|
};
|
package/src/cmd-upgrade.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
import { UltimateError } from '@ultimat3/core';
|
|
9
9
|
import { versionAtLeast } from './app-root';
|
|
10
|
+
import { runUpgradeCodemods } from './cmd-upgrade-codemods';
|
|
10
11
|
import { upgradeSpec } from './cmd-upgrade-spec';
|
|
11
12
|
import type { CliCommand, CommandContext } from './command';
|
|
12
13
|
import { failed, ok } from './command';
|
|
@@ -21,13 +22,21 @@ import { typescriptLags } from './typescript-floor';
|
|
|
21
22
|
import { applyAgentsLink, planAgentsLink } from './upgrade-agents-link';
|
|
22
23
|
import type { BunEdit, BunManual } from './upgrade-bun-floor';
|
|
23
24
|
import { editBunSites, floorOf, isBunSite } from './upgrade-bun-floor';
|
|
25
|
+
import { requireCleanTree } from './upgrade-clean-tree';
|
|
24
26
|
import { repoScripts, runHopGate, runRepoScripts } from './upgrade-gate';
|
|
27
|
+
import { atTargetCodemods, EVERY_RELEASE, previewCodemods } from './upgrade-gate-codemods';
|
|
28
|
+
import { acquireUpgradeLock } from './upgrade-lock';
|
|
25
29
|
import { readManifests, readPins, rewritePins } from './upgrade-pins';
|
|
30
|
+
import type { UpgradeHop } from './upgrade-plan';
|
|
26
31
|
import { planHop, releaseOf } from './upgrade-plan';
|
|
27
32
|
import { publishedVersions, releaseBunRange } from './upgrade-registry';
|
|
28
33
|
import type { PlannedWrites } from './upgrade-report';
|
|
29
34
|
import { humanLines, NO_WRITES, report, thenLine } from './upgrade-report';
|
|
35
|
+
import { codemodLines } from './upgrade-report-codemods';
|
|
30
36
|
import { findUpgradeRoot } from './upgrade-root';
|
|
37
|
+
import { stopChildrenOnSignal, tagRunner, upgradeTag } from './upgrade-signals';
|
|
38
|
+
import type { UnfinishedHop } from './upgrade-unfinished';
|
|
39
|
+
import { clearUnfinished, readUnfinished, writeUnfinished } from './upgrade-unfinished';
|
|
31
40
|
import { elapsedLabel, HEARTBEAT_MS } from './verify-progress';
|
|
32
41
|
import { writeErrorLine } from './write-line';
|
|
33
42
|
|
|
@@ -42,28 +51,6 @@ const readTarget = (ctx: CommandContext): string | undefined => {
|
|
|
42
51
|
});
|
|
43
52
|
};
|
|
44
53
|
|
|
45
|
-
/** The repository's root, or the refusal: git is the only record of where the walk stands. */
|
|
46
|
-
async function requireCleanTree(runner: Runner, root: string): Promise<string> {
|
|
47
|
-
const top = await runner(['git', 'rev-parse', '--show-toplevel'], { cwd: root });
|
|
48
|
-
if (!top.ok) {
|
|
49
|
-
throw new UltimateError({
|
|
50
|
-
code: 'X_UPGRADE_DIRTY_TREE',
|
|
51
|
-
cause: `${root} is not a git repository, and a hop has to be one commit you can review or undo`,
|
|
52
|
-
fix: 'git init && git add -A && git commit -m "before x upgrade" # then: x upgrade --json',
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
const status = await runner(['git', 'status', '--porcelain'], { cwd: root });
|
|
56
|
-
const changes = status.stdout.split('\n').filter((line) => line.trim().length > 0);
|
|
57
|
-
if (!status.ok || changes.length > 0) {
|
|
58
|
-
throw new UltimateError({
|
|
59
|
-
code: 'X_UPGRADE_DIRTY_TREE',
|
|
60
|
-
cause: `${String(changes.length)} uncommitted change(s), and a hop has to be one reviewable commit: ${changes.slice(0, 5).join('; ')}`,
|
|
61
|
-
fix: 'git status --short # then commit or stash, and re-run: x upgrade --json',
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
return top.stdout.trim();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
54
|
/** Everything the hop would write, decided before any of it is. `--dry-run` stops here. */
|
|
68
55
|
async function planWrites(input: {
|
|
69
56
|
readonly runner: Runner;
|
|
@@ -146,6 +133,16 @@ async function withHeartbeat<T>(
|
|
|
146
133
|
}
|
|
147
134
|
}
|
|
148
135
|
|
|
136
|
+
/** The recorded hop this run finishes: its pins are at target and it is the hop that wrote them. */
|
|
137
|
+
const resumable = (
|
|
138
|
+
unfinished: UnfinishedHop | undefined,
|
|
139
|
+
planned: UpgradeHop,
|
|
140
|
+
dryRun: boolean,
|
|
141
|
+
): UnfinishedHop | undefined =>
|
|
142
|
+
unfinished !== undefined && planned.atTarget && !dryRun && unfinished.to === planned.to
|
|
143
|
+
? unfinished
|
|
144
|
+
: undefined;
|
|
145
|
+
|
|
149
146
|
/** `YYYY-MM-DD` in UTC: the day a rebaselined floor's `why` names. */
|
|
150
147
|
const utcDay = (at: Date): string => at.toISOString().slice(0, 10);
|
|
151
148
|
|
|
@@ -153,22 +150,36 @@ export const createUpgradeCommand = (
|
|
|
153
150
|
write: (line: string) => void,
|
|
154
151
|
/** The clock a rebaselined coverage floor is dated by; a test pins it. */
|
|
155
152
|
now: () => Date = () => new Date(),
|
|
156
|
-
): CliCommand =>
|
|
157
|
-
|
|
158
|
-
async
|
|
159
|
-
|
|
160
|
-
|
|
153
|
+
): CliCommand => {
|
|
154
|
+
/** One hop, under the lock and the signal handlers `run` holds around it. */
|
|
155
|
+
async function runHop(
|
|
156
|
+
ctx: CommandContext,
|
|
157
|
+
root: string,
|
|
158
|
+
app: boolean,
|
|
159
|
+
to: string | undefined,
|
|
160
|
+
): Promise<CommandResult> {
|
|
161
161
|
const dryRun = flagBool(ctx.args, 'dry-run');
|
|
162
|
-
const
|
|
162
|
+
const unfinished = await readUnfinished(root);
|
|
163
|
+
const top = await requireCleanTree(ctx.runner, root, unfinished);
|
|
163
164
|
const manifests = await readManifests(root);
|
|
164
165
|
const pins = readPins(manifests);
|
|
165
166
|
// Reported, never written: a compiler is the app's to move, and the line names the command.
|
|
166
167
|
const typescript = typescriptLags(manifests);
|
|
167
168
|
const versions = await publishedVersions(ctx.runner, root);
|
|
168
|
-
const
|
|
169
|
+
const planned = planHop({ pins, versions, ...(to === undefined ? {} : { to }) });
|
|
170
|
+
// Pins at target with a hop recorded as unfinished: that hop wrote them and never reached its
|
|
171
|
+
// gate. It is finished now — install, then the whole gate, every codemod (each skips a file it
|
|
172
|
+
// already carried) — rather than answered done.
|
|
173
|
+
const resume = resumable(unfinished, planned, dryRun);
|
|
174
|
+
const hop = resume === undefined ? planned : { ...planned, from: resume.from, atTarget: false };
|
|
169
175
|
|
|
170
176
|
if (hop.atTarget) {
|
|
177
|
+
// A record for some other target is a hop since undone (`git stash`): nothing left to finish.
|
|
178
|
+
if (unfinished !== undefined && !dryRun) await clearUnfinished(root);
|
|
171
179
|
const then = thenLine({ hop, dryRun, app, gate: undefined, scripts: [] });
|
|
180
|
+
const carried = app
|
|
181
|
+
? await atTargetCodemods({ runner: ctx.runner, root, to: hop.to, dryRun })
|
|
182
|
+
: undefined;
|
|
172
183
|
const summary =
|
|
173
184
|
hop.next === null
|
|
174
185
|
? msg('cli.upgrade.atLatest', { version: hop.to })
|
|
@@ -187,15 +198,20 @@ export const createUpgradeCommand = (
|
|
|
187
198
|
scripts: [],
|
|
188
199
|
then,
|
|
189
200
|
typescript,
|
|
201
|
+
...carried,
|
|
190
202
|
}),
|
|
191
203
|
lines: [
|
|
192
204
|
...typescript.map((lag) => msg('cli.upgrade.typescript', { ...lag })),
|
|
205
|
+
...codemodLines(carried?.codemods ?? null),
|
|
193
206
|
msg('cli.upgrade.then', { then }),
|
|
194
207
|
],
|
|
195
208
|
});
|
|
196
209
|
}
|
|
197
210
|
|
|
198
|
-
const bunRange =
|
|
211
|
+
const bunRange =
|
|
212
|
+
resume === undefined
|
|
213
|
+
? await releaseBunRange(ctx.runner, root, hop.to)
|
|
214
|
+
: (resume.bunTo ?? undefined);
|
|
199
215
|
const floor = floorOf(bunRange);
|
|
200
216
|
// Before any write: the CLI this hop installs refuses this Bun on its first line, so the pins
|
|
201
217
|
// would land and every later step would report the same `X_BUN_VERSION` as a hop gone red.
|
|
@@ -211,7 +227,10 @@ export const createUpgradeCommand = (
|
|
|
211
227
|
manifests,
|
|
212
228
|
});
|
|
213
229
|
const held = manifests.find((manifest) => manifest.file === 'package.json')?.text ?? '';
|
|
214
|
-
const bunFrom =
|
|
230
|
+
const bunFrom =
|
|
231
|
+
resume === undefined
|
|
232
|
+
? (/"engines"\s*:\s*\{[^}]*?"bun"\s*:\s*"([^"]*)"/.exec(held)?.[1] ?? null)
|
|
233
|
+
: resume.bunFrom;
|
|
215
234
|
const agentsMd = await planAgentsLink(root);
|
|
216
235
|
const shared = {
|
|
217
236
|
hop,
|
|
@@ -228,6 +247,8 @@ export const createUpgradeCommand = (
|
|
|
228
247
|
if (dryRun) {
|
|
229
248
|
const named = scriptNames.map((name) => ({ name, ok: null }));
|
|
230
249
|
const then = thenLine({ hop, dryRun: true, app, gate: undefined, scripts: named });
|
|
250
|
+
// This CLI's list, written nowhere: the hop itself applies the installed release's.
|
|
251
|
+
const preview = app ? await previewCodemods(root, hop.from, hop.to) : undefined;
|
|
231
252
|
return ok('upgrade', msg('cli.upgrade.dryRun', { from: hop.from, to: hop.to }), {
|
|
232
253
|
data: report({
|
|
233
254
|
...shared,
|
|
@@ -236,6 +257,7 @@ export const createUpgradeCommand = (
|
|
|
236
257
|
gate: undefined,
|
|
237
258
|
scripts: named,
|
|
238
259
|
then,
|
|
260
|
+
...preview,
|
|
239
261
|
}),
|
|
240
262
|
lines: humanLines({
|
|
241
263
|
hop,
|
|
@@ -245,10 +267,19 @@ export const createUpgradeCommand = (
|
|
|
245
267
|
then,
|
|
246
268
|
agentsMd,
|
|
247
269
|
typescript,
|
|
270
|
+
...preview,
|
|
248
271
|
}),
|
|
249
272
|
});
|
|
250
273
|
}
|
|
251
274
|
|
|
275
|
+
// From the first pin written until the gate returns: a stopped hop is told apart from a done one.
|
|
276
|
+
await writeUnfinished(root, {
|
|
277
|
+
from: hop.from,
|
|
278
|
+
to: hop.to,
|
|
279
|
+
bunFrom,
|
|
280
|
+
bunTo: bunRange ?? null,
|
|
281
|
+
startedAt: resume?.startedAt ?? now().toISOString(),
|
|
282
|
+
});
|
|
252
283
|
await Promise.all(
|
|
253
284
|
[...writes.files].map(async ([path, text]) => {
|
|
254
285
|
await Bun.write(path, text);
|
|
@@ -277,15 +308,19 @@ export const createUpgradeCommand = (
|
|
|
277
308
|
runner: ctx.runner,
|
|
278
309
|
root,
|
|
279
310
|
onStage: stageReached,
|
|
311
|
+
codemods: { from: resume === undefined ? hop.from : EVERY_RELEASE, to: hop.to },
|
|
280
312
|
...(bunMoved === undefined ? {} : { bunMoved }),
|
|
281
313
|
});
|
|
282
314
|
return { gate: hopGate, scripts: [] };
|
|
283
315
|
});
|
|
316
|
+
await clearUnfinished(root);
|
|
284
317
|
|
|
285
318
|
const redScripts = scripts.filter((script) => script.ok !== true).map((script) => script.name);
|
|
286
319
|
// With no script, nothing was checked, and that is never a green.
|
|
287
320
|
const done =
|
|
288
|
-
gate !== undefined
|
|
321
|
+
gate !== undefined
|
|
322
|
+
? gate.verify.ok && gate.codemods?.failure === undefined
|
|
323
|
+
: scripts.length > 0 && redScripts.length === 0;
|
|
289
324
|
const then = thenLine({ hop, dryRun: false, app, gate, scripts });
|
|
290
325
|
const extra = {
|
|
291
326
|
data: report({ ...shared, done, dryRun: false, gate, scripts, then }),
|
|
@@ -309,7 +344,29 @@ export const createUpgradeCommand = (
|
|
|
309
344
|
msg('cli.upgrade.noApp.red', { ...span, names: redScripts.join(', ') }),
|
|
310
345
|
extra,
|
|
311
346
|
);
|
|
312
|
-
}
|
|
313
|
-
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return {
|
|
350
|
+
spec: upgradeSpec,
|
|
351
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
352
|
+
if (ctx.args.subcommand === 'codemods') return runUpgradeCodemods(ctx);
|
|
353
|
+
const { dir: root, app } = await findUpgradeRoot(ctx.cwd);
|
|
354
|
+
const to = readTarget(ctx);
|
|
355
|
+
// One hop per app at a time, and a stopped hop stops its children: every spawn below is
|
|
356
|
+
// tagged, and SIGINT/SIGTERM kill that tree and release the lock before the signal lands.
|
|
357
|
+
const release = acquireUpgradeLock(root);
|
|
358
|
+
const tag = upgradeTag();
|
|
359
|
+
const pids = new Set<number>();
|
|
360
|
+
const undoSignals = stopChildrenOnSignal({ tag, pids, cleanup: release });
|
|
361
|
+
try {
|
|
362
|
+
const runner = tagRunner(ctx.runner, tag, ctx.env, pids);
|
|
363
|
+
return await runHop({ ...ctx, runner }, root, app, to);
|
|
364
|
+
} finally {
|
|
365
|
+
undoSignals();
|
|
366
|
+
release();
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
};
|
|
370
|
+
};
|
|
314
371
|
|
|
315
372
|
export const upgradeCommand: CliCommand = createUpgradeCommand(writeErrorLine);
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// 31.22.0: the four `.claude/agents/*.md` the scaffold writes may call the app's dev MCP server
|
|
2
|
+
// (`mcp__<app>__*`, the server `.mcp.json` names). Each `tools:` line still as `x new` wrote it
|
|
3
|
+
// gains it; one the app changed is the app's choice, and is left as it is.
|
|
4
|
+
|
|
5
|
+
import { stringField } from '@ultimat3/core';
|
|
6
|
+
import type { Codemod } from './codemod';
|
|
7
|
+
import type { SnippetEdit } from './engine-edits';
|
|
8
|
+
import { editSnippets, mergeResults, readText } from './engine-edits';
|
|
9
|
+
|
|
10
|
+
/** Each agent and the `tools:` line `x new` gave it. */
|
|
11
|
+
export const AGENT_TOOLS: Readonly<Record<string, string>> = {
|
|
12
|
+
'.claude/agents/shape.md': 'tools: Read, Glob, Grep, Bash',
|
|
13
|
+
'.claude/agents/data.md': 'tools: Read, Write, Edit, Glob, Grep, Bash',
|
|
14
|
+
'.claude/agents/server.md': 'tools: Read, Write, Edit, Glob, Grep, Bash',
|
|
15
|
+
'.claude/agents/web.md': 'tools: Read, Write, Edit, Glob, Grep, Bash',
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/** The app's name as its root package.json declares it; undefined when it declares none usable. */
|
|
19
|
+
export const appName = (manifest: string): string | undefined => {
|
|
20
|
+
let parsed: unknown;
|
|
21
|
+
try {
|
|
22
|
+
parsed = JSON.parse(manifest);
|
|
23
|
+
} catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const name = stringField(parsed, 'name');
|
|
27
|
+
return name !== undefined && /^[a-z0-9][a-z0-9-]*$/.test(name) ? name : undefined;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const codemod: Codemod = {
|
|
31
|
+
id: 'agents-dev-mcp',
|
|
32
|
+
since: '31.22.0',
|
|
33
|
+
summary:
|
|
34
|
+
".claude/agents/*.md may call the app's dev MCP server: mcp__<app>__* on each tools: line",
|
|
35
|
+
async run(app) {
|
|
36
|
+
const name = appName((await readText(app, 'package.json'))?.text ?? '');
|
|
37
|
+
if (name === undefined) return { changed: [], skipped: [] };
|
|
38
|
+
const results = [];
|
|
39
|
+
for (const [path, tools] of Object.entries(AGENT_TOOLS)) {
|
|
40
|
+
// The front matter's own line, newline-bounded, so a longer `tools:` line never matches.
|
|
41
|
+
const edit: SnippetEdit = {
|
|
42
|
+
from: `\n${tools}\n`,
|
|
43
|
+
to: `\n${tools}, mcp__${name}__*\n`,
|
|
44
|
+
optional: true,
|
|
45
|
+
};
|
|
46
|
+
results.push(await editSnippets(app, path, [edit]));
|
|
47
|
+
}
|
|
48
|
+
return mergeResults(results);
|
|
49
|
+
},
|
|
50
|
+
};
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// 31.20.0: the app's session authenticator answers a stale, revoked or forged cookie `null` instead
|
|
2
|
+
// of throwing, so a signed-out socket is closed and sign-in opens for a stale cookie. Both shapes
|
|
3
|
+
// of `apps/web/app/auth/authenticator.ts` (`x new`'s, `x g sign-in`'s) and their tests.
|
|
4
|
+
|
|
5
|
+
import type { Codemod, CodemodApp } from './codemod';
|
|
6
|
+
import type { SnippetEdit } from './engine-edits';
|
|
7
|
+
import { editSnippets, mergeResults, readText } from './engine-edits';
|
|
8
|
+
|
|
9
|
+
const SOURCE = 'apps/web/app/auth/authenticator.ts';
|
|
10
|
+
const TEST = 'apps/web/app/auth/authenticator.test.ts';
|
|
11
|
+
|
|
12
|
+
const lines = (...text: readonly string[]): string => text.join('\n');
|
|
13
|
+
|
|
14
|
+
const CATCH = lines(
|
|
15
|
+
' try {',
|
|
16
|
+
' return await authenticate(TARGET, token);',
|
|
17
|
+
' } catch (error) {',
|
|
18
|
+
' if (isSessionRefusal(error)) return null;',
|
|
19
|
+
' throw error;',
|
|
20
|
+
' }',
|
|
21
|
+
' };',
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const SIGNED_OUT_TEST = (name: string, check: string): string =>
|
|
25
|
+
lines(
|
|
26
|
+
"unitTest('a signed-out cookie is nobody, so its socket is closed on re-check', async () => {",
|
|
27
|
+
' const auth = memoryAuth();',
|
|
28
|
+
' await register(auth(), {',
|
|
29
|
+
" email: 'ada@example.com',",
|
|
30
|
+
' password: PASSWORD,',
|
|
31
|
+
' orgId: DEMO_ORG_ID,',
|
|
32
|
+
" roles: ['member'],",
|
|
33
|
+
' });',
|
|
34
|
+
" const { token } = await login(auth(), { email: 'ada@example.com', password: PASSWORD });",
|
|
35
|
+
' await logout(auth(), token);',
|
|
36
|
+
` const ${name} = requestWith({ [auth().sessions.policy.cookieName]: token });`,
|
|
37
|
+
check,
|
|
38
|
+
'});',
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const AUTH_IMPORT: SnippetEdit = {
|
|
42
|
+
from: "import { defineAuth, login, memoryAuthAdapter, register } from '@ultimat3/auth';",
|
|
43
|
+
to: "import { defineAuth, login, logout, memoryAuthAdapter, register } from '@ultimat3/auth';",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const NULL_NOT_THROW =
|
|
47
|
+
' // `null`, not a throw: thrown, a stale cookie was a 401 on the sign-in page itself.';
|
|
48
|
+
|
|
49
|
+
/** `x new`'s authenticator: development falls back to the dev viewer, a cookie never does. */
|
|
50
|
+
const SCAFFOLD: readonly SnippetEdit[] = [
|
|
51
|
+
{
|
|
52
|
+
from: "import { type Actor, logger, tryResolveEnvironment } from '@ultimat3/core';",
|
|
53
|
+
to: "import { type Actor, isSessionRefusal, logger, tryResolveEnvironment } from '@ultimat3/core';",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
from: lines(
|
|
57
|
+
" * A session cookie is that session's user, or a refusal — never a fallback to anyone else:",
|
|
58
|
+
' * `X_SESSION_EXPIRED` for a session past its absolute or idle expiry, `X_UNAUTHENTICATED` for',
|
|
59
|
+
' * one that is unknown, revoked or forged, or whose user is disabled. No cookie is the development',
|
|
60
|
+
' * viewer or nobody.',
|
|
61
|
+
),
|
|
62
|
+
to: lines(
|
|
63
|
+
" * A session cookie is that session's user, or nobody — never a fallback to anyone else. A session",
|
|
64
|
+
' * past its expiry, or one unknown, revoked or forged, or whose user is disabled, is a refusal',
|
|
65
|
+
' * `authenticate()` THROWS (`isSessionRefusal`: `X_SESSION_EXPIRED`, `X_UNAUTHENTICATED`), and it',
|
|
66
|
+
' * is answered `null`: a stale cookie is an anonymous visitor, so sign-in still opens and a live',
|
|
67
|
+
' * socket it opened is closed. Anything else it throws — a session store that is down — is not an',
|
|
68
|
+
' * answer about this visitor and propagates. No cookie is the development viewer or nobody.',
|
|
69
|
+
),
|
|
70
|
+
optional: true,
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
from: lines(
|
|
74
|
+
' if (token !== null && token.length > 0) return await authenticate(auth, token);',
|
|
75
|
+
' return options.development ? devAuthenticate(request) : null;',
|
|
76
|
+
' };',
|
|
77
|
+
),
|
|
78
|
+
to: lines(
|
|
79
|
+
' if (token === null || token.length === 0) {',
|
|
80
|
+
' return options.development ? devAuthenticate(request) : null;',
|
|
81
|
+
' }',
|
|
82
|
+
CATCH.replace('TARGET', 'auth'),
|
|
83
|
+
),
|
|
84
|
+
},
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
const SCAFFOLD_TEST: readonly SnippetEdit[] = [
|
|
88
|
+
AUTH_IMPORT,
|
|
89
|
+
{
|
|
90
|
+
from: lines(
|
|
91
|
+
"unitTest('a cookie naming no live session is refused, never answered as the viewer', async () => {",
|
|
92
|
+
' const auth = memoryAuth();',
|
|
93
|
+
" const request = requestWith({ [auth().sessions.policy.cookieName]: 'forged.token' });",
|
|
94
|
+
' await expect(sessionAuthenticator({ auth, development: true })(request)).rejects.toMatchObject({',
|
|
95
|
+
" code: 'X_UNAUTHENTICATED',",
|
|
96
|
+
' });',
|
|
97
|
+
'});',
|
|
98
|
+
),
|
|
99
|
+
to: lines(
|
|
100
|
+
"unitTest('a cookie naming no live session is nobody, never answered as the viewer', async () => {",
|
|
101
|
+
' const auth = memoryAuth();',
|
|
102
|
+
" const request = requestWith({ [auth().sessions.policy.cookieName]: 'forged.token' });",
|
|
103
|
+
NULL_NOT_THROW,
|
|
104
|
+
' expect(await sessionAuthenticator({ auth, development: true })(request)).toBeNull();',
|
|
105
|
+
'});',
|
|
106
|
+
'',
|
|
107
|
+
SIGNED_OUT_TEST(
|
|
108
|
+
'request',
|
|
109
|
+
lines(
|
|
110
|
+
' for (const development of [true, false]) {',
|
|
111
|
+
' expect(await sessionAuthenticator({ auth, development })(request)).toBeNull();',
|
|
112
|
+
' }',
|
|
113
|
+
),
|
|
114
|
+
),
|
|
115
|
+
),
|
|
116
|
+
},
|
|
117
|
+
];
|
|
118
|
+
|
|
119
|
+
/** `x g sign-in`'s authenticator: no development fallback at all. */
|
|
120
|
+
const SIGN_IN: readonly SnippetEdit[] = [
|
|
121
|
+
{
|
|
122
|
+
from: "import type { Actor } from '@ultimat3/core';",
|
|
123
|
+
to: "import { type Actor, isSessionRefusal } from '@ultimat3/core';",
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
from: lines(
|
|
127
|
+
" * A session cookie is that session's user, or a refusal — never a fallback to anyone else:",
|
|
128
|
+
' * `X_SESSION_EXPIRED` past its expiry, `X_UNAUTHENTICATED` for one unknown, revoked or forged.',
|
|
129
|
+
),
|
|
130
|
+
to: lines(
|
|
131
|
+
" * A session cookie is that session's user, or nobody — never a fallback to anyone else. A session",
|
|
132
|
+
' * past its expiry, or one unknown, revoked or forged, is a refusal `authenticate()` THROWS',
|
|
133
|
+
' * (`isSessionRefusal`: `X_SESSION_EXPIRED`, `X_UNAUTHENTICATED`), answered `null`: a stale',
|
|
134
|
+
' * cookie is an anonymous visitor, so sign-in still opens and a live socket it opened is closed.',
|
|
135
|
+
' * Anything else it throws — a session store that is down — propagates.',
|
|
136
|
+
),
|
|
137
|
+
optional: true,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
from: lines(
|
|
141
|
+
' return token !== null && token.length > 0 ? await authenticate(resolved, token) : null;',
|
|
142
|
+
' };',
|
|
143
|
+
),
|
|
144
|
+
to: lines(
|
|
145
|
+
' if (token === null || token.length === 0) return null;',
|
|
146
|
+
CATCH.replace('TARGET', 'resolved'),
|
|
147
|
+
),
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
|
|
151
|
+
const SIGN_IN_TEST: readonly SnippetEdit[] = [
|
|
152
|
+
{
|
|
153
|
+
from: '// A session cookie is the user it was issued to; a bad one is refused; none is nobody.',
|
|
154
|
+
to: lines(
|
|
155
|
+
'// A session cookie is the user it was issued to; a bad, expired or signed-out one is nobody, and',
|
|
156
|
+
'// so is none.',
|
|
157
|
+
),
|
|
158
|
+
optional: true,
|
|
159
|
+
},
|
|
160
|
+
AUTH_IMPORT,
|
|
161
|
+
{
|
|
162
|
+
from: lines(
|
|
163
|
+
"unitTest('a forged cookie is refused, and no cookie is anonymous', async () => {",
|
|
164
|
+
' const auth = memoryAuth();',
|
|
165
|
+
" const forged = requestWith({ [auth().sessions.policy.cookieName]: 'forged.token' });",
|
|
166
|
+
' await expect(sessionAuthenticator(auth)(forged)).rejects.toMatchObject({',
|
|
167
|
+
" code: 'X_UNAUTHENTICATED',",
|
|
168
|
+
' });',
|
|
169
|
+
' expect(await sessionAuthenticator(auth)(requestWith({}))).toBeNull();',
|
|
170
|
+
'});',
|
|
171
|
+
),
|
|
172
|
+
to: lines(
|
|
173
|
+
"unitTest('a forged cookie is nobody, and no cookie is anonymous', async () => {",
|
|
174
|
+
' const auth = memoryAuth();',
|
|
175
|
+
" const forged = requestWith({ [auth().sessions.policy.cookieName]: 'forged.token' });",
|
|
176
|
+
NULL_NOT_THROW,
|
|
177
|
+
' expect(await sessionAuthenticator(auth)(forged)).toBeNull();',
|
|
178
|
+
' expect(await sessionAuthenticator(auth)(requestWith({}))).toBeNull();',
|
|
179
|
+
'});',
|
|
180
|
+
'',
|
|
181
|
+
SIGNED_OUT_TEST('cookie', ' expect(await sessionAuthenticator(auth)(cookie)).toBeNull();'),
|
|
182
|
+
),
|
|
183
|
+
},
|
|
184
|
+
];
|
|
185
|
+
|
|
186
|
+
/** Each shape's edits by file: what the codemod runs, and what its test runs backwards. */
|
|
187
|
+
export const AUTHENTICATOR_EDITS = {
|
|
188
|
+
scaffold: { [SOURCE]: SCAFFOLD, [TEST]: SCAFFOLD_TEST },
|
|
189
|
+
signIn: { [SOURCE]: SIGN_IN, [TEST]: SIGN_IN_TEST },
|
|
190
|
+
} as const;
|
|
191
|
+
|
|
192
|
+
/** `x g sign-in` rewrote the authenticator with no development fallback: its own signature. */
|
|
193
|
+
const isSignIn = async (app: CodemodApp): Promise<boolean> =>
|
|
194
|
+
((await app.read(SOURCE)) ?? '').includes('(auth: () => Auth) =>');
|
|
195
|
+
|
|
196
|
+
export const codemod: Codemod = {
|
|
197
|
+
id: 'authenticator-session-refusal',
|
|
198
|
+
since: '31.20.0',
|
|
199
|
+
summary:
|
|
200
|
+
'apps/web/app/auth/authenticator.ts answers a stale, revoked or forged session cookie null instead of throwing (and its test says so)',
|
|
201
|
+
async run(app) {
|
|
202
|
+
// The scaffold's file names `sessionAuthenticator`; one that does not is the app's own, and
|
|
203
|
+
// one that already answers `isSessionRefusal` has been carried across, by hand or otherwise.
|
|
204
|
+
const source = (await readText(app, SOURCE))?.text ?? '';
|
|
205
|
+
if (!source.includes('sessionAuthenticator') || source.includes('isSessionRefusal')) {
|
|
206
|
+
return { changed: [], skipped: [] };
|
|
207
|
+
}
|
|
208
|
+
const signIn = await isSignIn(app);
|
|
209
|
+
return mergeResults([
|
|
210
|
+
await editSnippets(app, SOURCE, signIn ? SIGN_IN : SCAFFOLD),
|
|
211
|
+
await editSnippets(app, TEST, signIn ? SIGN_IN_TEST : SCAFFOLD_TEST),
|
|
212
|
+
]);
|
|
213
|
+
},
|
|
214
|
+
};
|