@ultimat3/cli 31.27.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 +3 -1
- package/README.md +14 -4
- package/package.json +29 -29
- package/src/app-manifest.ts +6 -1
- package/src/cmd-doctor.ts +11 -3
- package/src/cmd-repro-spec.ts +13 -1
- package/src/cmd-repro.ts +37 -5
- 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/doctor-advisory-floors.ts +113 -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.ts +6 -0
- package/src/exercise-database.ts +7 -2
- package/src/generate-files.ts +6 -5
- 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 +90 -34
- package/src/index.ts +10 -0
- package/src/lint-findings.ts +3 -3
- package/src/mcp-errors.ts +11 -1
- package/src/measure-scope.ts +23 -3
- package/src/messages-repro.ts +16 -2
- package/src/messages-upgrade.ts +15 -0
- package/src/messages.ts +1 -1
- 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/superseded-match.ts +87 -0
- package/src/superseded.ts +84 -0
- package/src/templates/bun-image.ts +48 -0
- package/src/templates/github/ci.yml.ts +1 -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-docs.ts +26 -24
- package/src/templates/scaffold-guards.ts +73 -39
- package/src/templates/scaffold-repo.ts +2 -1
- package/src/unthrown-codes.ts +2 -0
- 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 +38 -6
- 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 +52 -27
- package/src/upgrade-signals.ts +91 -0
- package/src/upgrade-unfinished.ts +61 -0
- package/wiki/CLI-Reference.md +58 -4
- package/wiki/Interface-Rules.md +17 -8
- package/wiki/Observability.md +1 -0
- package/wiki/Project-Layout.md +4 -4
- package/wiki/Upgrading.md +5 -0
package/src/messages-repro.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// The `x repro` rows of the CLI catalog (`messages.ts` composes them)
|
|
2
|
-
// one lookup.
|
|
1
|
+
// The `x repro` rows of the CLI catalog (`messages.ts` composes them), and `create-ultimate repro`'s.
|
|
2
|
+
// Data only — `msg()` is the one lookup.
|
|
3
3
|
|
|
4
4
|
export const REPRO_MESSAGES = {
|
|
5
5
|
'cli.repro.job': 'job {name} ({id}) died with {code} at step {step}',
|
|
@@ -8,4 +8,18 @@ export const REPRO_MESSAGES = {
|
|
|
8
8
|
'cli.repro.reproduced': ' reproduced: {file} fails with {code}',
|
|
9
9
|
'cli.repro.notReproduced': ' not reproduced: {file} ended in {got}',
|
|
10
10
|
'cli.repro.listed': '{count} captured bundle(s)',
|
|
11
|
+
'cli.repro.bundled': 'wrote the repro bundle {file}',
|
|
12
|
+
'cli.repro.bundleMasked':
|
|
13
|
+
' {count} field(s) masked or stood in — the bundle lists them under masked',
|
|
14
|
+
'cli.repro.bundleScrubbed': ' {env} env value(s) and {hosts} hostname(s) found and replaced',
|
|
15
|
+
'cli.repro.bundleReadFirst':
|
|
16
|
+
' read {file} before you attach it to an issue: it is all that leaves',
|
|
17
|
+
'cli.repro.opened': 'opened {code} from {bundle} into {dir}',
|
|
18
|
+
'cli.repro.openedFramework':
|
|
19
|
+
' @ultimat3/* linked from {framework} (the bundle was made on {versions})',
|
|
20
|
+
'cli.repro.openedRegistry':
|
|
21
|
+
' @ultimat3/* from the registry: pass --framework <checkout> to run on framework source',
|
|
22
|
+
'cli.repro.openedStandIn':
|
|
23
|
+
' stand in {name} in apps/web/api and the entities in repro/bundle.json schema, then:',
|
|
24
|
+
'cli.repro.openedNext': ' cd {dir} && bun install && bun test ./{file}',
|
|
11
25
|
} as const;
|
package/src/messages-upgrade.ts
CHANGED
|
@@ -58,4 +58,19 @@ export const UPGRADE_MESSAGES = {
|
|
|
58
58
|
'read the section, close each finding by its fix, re-check with x verify --json, commit this hop to {to}, then re-run x upgrade --json for the next one',
|
|
59
59
|
'cli.upgrade.then.walk':
|
|
60
60
|
'review the diff and commit this hop to {to}, then re-run x upgrade --json to take the next one, {next}',
|
|
61
|
+
// `upgrade-report.ts` / `cmd-upgrade-codemods.ts`: the codemods a hop applied, and what they left.
|
|
62
|
+
'cli.upgrade.codemods.done':
|
|
63
|
+
'{count} codemod(s) after {from} up to {to}: {changed} file(s) changed, {skipped} left for you',
|
|
64
|
+
'cli.upgrade.codemods.dryRun':
|
|
65
|
+
'{count} codemod(s) after {from} up to {to} would change {changed} file(s) and leave {skipped} for you; nothing written',
|
|
66
|
+
'cli.upgrade.codemod':
|
|
67
|
+
'codemod {id} ({since}): {changed} changed, {skipped} left for you — {summary}',
|
|
68
|
+
'cli.upgrade.codemod.changed': ' changed: {path}',
|
|
69
|
+
'cli.upgrade.codemod.skipped': ' left for you: {path} — {reason}',
|
|
70
|
+
'cli.upgrade.codemods.failed':
|
|
71
|
+
'codemods not applied: the installed CLI answered {code}: {cause} — fix: {fix}',
|
|
72
|
+
'cli.upgrade.codemods.fromDriver':
|
|
73
|
+
'the installed CLI applies no codemods of its own, so this CLI applied its list',
|
|
74
|
+
// `upgrade-report.ts`: a workaround the hop's framework made unnecessary (`doctor-superseded.ts`).
|
|
75
|
+
'cli.upgrade.superseded': 'superseded workaround{at}: {cause} — fix: {fix}',
|
|
61
76
|
} as const;
|
package/src/messages.ts
CHANGED
|
@@ -103,7 +103,7 @@ const CATALOG = {
|
|
|
103
103
|
'wake off, pickup within idlePollMaxMs ({ms} ms by default): a transaction pooler delivers no notification. For the wake, give this role a direct or session-pooled DATABASE_URL and unset DATABASE_POOLER',
|
|
104
104
|
'cli.doctor.findings': '{count} finding(s)',
|
|
105
105
|
'cli.doctor.guardsDiffer':
|
|
106
|
-
'{count} shipped guard(s)
|
|
106
|
+
'{count} shipped guard(s) still have a copy in guards/, which runs in place of the built-in guard and never receives a fix. Each line is the edit that resolves one:',
|
|
107
107
|
// `x doctor`'s other listing: what the coverage floor in x.verify.json does not see, and why.
|
|
108
108
|
'cli.doctor.coverageExclude':
|
|
109
109
|
'{count} path(s) x.verify.json excludes from the coverage floor — each with the reason it gives:',
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Single responsibility: the reads `x repro --bundle` makes beyond the subject — the installed
|
|
2
|
+
// `@ultimat3/*` versions, what the scrubber must hide (dotenv values, config hostnames, the home
|
|
3
|
+
// directory, the machine's name), the error's cause and stack, and the app's declarations by name.
|
|
4
|
+
|
|
5
|
+
// why: Bun exposes neither the home directory nor the machine's hostname.
|
|
6
|
+
import { homedir, hostname } from 'node:os';
|
|
7
|
+
// why: Bun exposes no path-join primitive.
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { getAction } from '@ultimat3/action';
|
|
10
|
+
import { postgresErrorGroupsStore } from '@ultimat3/admin/error-groups';
|
|
11
|
+
import { isJsonObject } from '@ultimat3/core';
|
|
12
|
+
import { getEntity, sealedFields } from '@ultimat3/entity';
|
|
13
|
+
import type { JobDriver } from '@ultimat3/jobs';
|
|
14
|
+
import { getJob, inspectJob } from '@ultimat3/jobs';
|
|
15
|
+
import { getQuery } from '@ultimat3/query';
|
|
16
|
+
import { appConfigExport } from './app-config-load';
|
|
17
|
+
import type { ReproErrorFacts } from './repro-archive';
|
|
18
|
+
import type { ReproSubject } from './repro-bundle';
|
|
19
|
+
import type { ReproLookups } from './repro-redact';
|
|
20
|
+
import type { ScrubSources } from './repro-scrub';
|
|
21
|
+
import { hostOf } from './repro-scrub';
|
|
22
|
+
import { parseDotenv } from './root-env';
|
|
23
|
+
|
|
24
|
+
/** Where an installed `@ultimat3/*` manifest sits: the root, a workspace, or Bun's isolated store. */
|
|
25
|
+
const MANIFEST_GLOBS = [
|
|
26
|
+
'node_modules/@ultimat3/*/package.json',
|
|
27
|
+
'{apps,packages}/*/node_modules/@ultimat3/*/package.json',
|
|
28
|
+
'node_modules/.bun/*/node_modules/@ultimat3/*/package.json',
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
/** Every installed `@ultimat3/*` package and the versions found of it, names and versions sorted. */
|
|
32
|
+
export async function installedFramework(root: string): Promise<Record<string, string[]>> {
|
|
33
|
+
const found = new Map<string, Set<string>>();
|
|
34
|
+
for (const pattern of MANIFEST_GLOBS) {
|
|
35
|
+
for await (const path of new Bun.Glob(pattern).scan({ cwd: root, dot: true })) {
|
|
36
|
+
const parsed: unknown = await Bun.file(join(root, path))
|
|
37
|
+
.json()
|
|
38
|
+
.catch(() => undefined);
|
|
39
|
+
if (!isJsonObject(parsed)) continue;
|
|
40
|
+
const { name, version } = parsed;
|
|
41
|
+
if (typeof name !== 'string' || typeof version !== 'string') continue;
|
|
42
|
+
if (!name.startsWith('@ultimat3/')) continue;
|
|
43
|
+
found.set(name, (found.get(name) ?? new Set()).add(version));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return Object.fromEntries(
|
|
47
|
+
[...found.keys()].sort().map((name) => [name, [...(found.get(name) ?? [])].sort()]),
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Every hostname a config value names: a URL anywhere, or a string under a host-like key. */
|
|
52
|
+
function configHosts(value: unknown, key: string, out: Set<string>, depth = 0): void {
|
|
53
|
+
if (depth > 16) return;
|
|
54
|
+
if (typeof value === 'string') {
|
|
55
|
+
const host = hostOf(value);
|
|
56
|
+
if (host !== undefined) out.add(host);
|
|
57
|
+
else if (/^(?:host|hostname|domain|origin)s?$/i.test(key) && value.trim() !== '') {
|
|
58
|
+
out.add(value.trim().toLowerCase());
|
|
59
|
+
}
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(value)) for (const entry of value) configHosts(entry, key, out, depth + 1);
|
|
63
|
+
else if (isJsonObject(value)) {
|
|
64
|
+
for (const [name, entry] of Object.entries(value)) configHosts(entry, name, out, depth + 1);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Every `.env*` file's values at the app root, by name; two files holding one name keep both. */
|
|
69
|
+
async function dotenvValues(root: string): Promise<[string, string][]> {
|
|
70
|
+
const files: string[] = [];
|
|
71
|
+
for await (const path of new Bun.Glob('.env*').scan({ cwd: root, dot: true })) files.push(path);
|
|
72
|
+
const out: [string, string][] = [];
|
|
73
|
+
for (const path of files.sort()) {
|
|
74
|
+
out.push(...parseDotenv(await Bun.file(join(root, path)).text()));
|
|
75
|
+
}
|
|
76
|
+
return out;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function scrubSourcesOf(
|
|
80
|
+
root: string,
|
|
81
|
+
env: Readonly<Record<string, string | undefined>>,
|
|
82
|
+
): Promise<ScrubSources> {
|
|
83
|
+
const hosts = new Set<string>();
|
|
84
|
+
configHosts(await appConfigExport(root, 'config'), '', hosts);
|
|
85
|
+
const machine = hostname().toLowerCase();
|
|
86
|
+
if (machine !== '') hosts.add(machine);
|
|
87
|
+
const homes = [env['HOME'], env['USERPROFILE'], homedir()].filter(
|
|
88
|
+
(home): home is string => typeof home === 'string' && home.length > 1,
|
|
89
|
+
);
|
|
90
|
+
return {
|
|
91
|
+
root,
|
|
92
|
+
homes,
|
|
93
|
+
env: [
|
|
94
|
+
...(await dotenvValues(root)).map(([name, value]) => ({
|
|
95
|
+
name,
|
|
96
|
+
value,
|
|
97
|
+
from: 'dotenv' as const,
|
|
98
|
+
})),
|
|
99
|
+
...Object.entries(env).map(([name, value]) => ({ name, value, from: 'process' as const })),
|
|
100
|
+
],
|
|
101
|
+
hosts: [...hosts],
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** `{ cause, stack }` beside the subject in a `--from` file (`data.error` or `error`), when there. */
|
|
106
|
+
export async function errorFromFile(path: string): Promise<ReproErrorFacts> {
|
|
107
|
+
const parsed: unknown = await Bun.file(path)
|
|
108
|
+
.json()
|
|
109
|
+
.catch(() => undefined);
|
|
110
|
+
const data = isJsonObject(parsed) && isJsonObject(parsed['data']) ? parsed['data'] : parsed;
|
|
111
|
+
const error = isJsonObject(data) ? data['error'] : undefined;
|
|
112
|
+
if (!isJsonObject(error)) return { cause: null, stack: null };
|
|
113
|
+
const text = (value: unknown): string | null => (typeof value === 'string' ? value : null);
|
|
114
|
+
return { cause: text(error['cause']), stack: text(error['stack']) };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The job row's last error and stack, or the error group's redacted sample for a request. */
|
|
118
|
+
export async function errorFromStore(
|
|
119
|
+
driver: JobDriver,
|
|
120
|
+
subject: ReproSubject,
|
|
121
|
+
): Promise<ReproErrorFacts> {
|
|
122
|
+
if (subject.kind === 'job') {
|
|
123
|
+
const trace = await inspectJob(driver, subject.failure.jobId);
|
|
124
|
+
return { cause: trace?.lastError ?? null, stack: trace?.stack ?? null };
|
|
125
|
+
}
|
|
126
|
+
// A group store that cannot answer leaves the bundle without a stack, as `--list` leaves a count.
|
|
127
|
+
const group = await postgresErrorGroupsStore()
|
|
128
|
+
.get(subject.bundle.fingerprint)
|
|
129
|
+
.catch(() => undefined);
|
|
130
|
+
return sampleFacts(group?.sample, subject.bundle.requestId);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The error group's sample is its LATEST failure, not necessarily this one: its cause and stack
|
|
135
|
+
* are this subject's only when the sample's request is the subject's own. Otherwise, nothing.
|
|
136
|
+
*/
|
|
137
|
+
export function sampleFacts(
|
|
138
|
+
sample:
|
|
139
|
+
| { readonly requestId: string | null; readonly cause: string; readonly stack: string | null }
|
|
140
|
+
| undefined,
|
|
141
|
+
requestId: string | null,
|
|
142
|
+
): ReproErrorFacts {
|
|
143
|
+
if (sample === undefined || requestId === null || sample.requestId !== requestId) {
|
|
144
|
+
return { cause: null, stack: null };
|
|
145
|
+
}
|
|
146
|
+
return { cause: sample.cause, stack: sample.stack };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** The registries `loadApp` filled: what the redaction asks by name. */
|
|
150
|
+
export const registryLookups: ReproLookups = {
|
|
151
|
+
inputSchema(kind, name) {
|
|
152
|
+
if (kind === 'job') return getJob(name)?.input;
|
|
153
|
+
return kind === 'action' ? getAction(name)?.input : getQuery(name)?.input;
|
|
154
|
+
},
|
|
155
|
+
entity(name) {
|
|
156
|
+
const entry = getEntity(name);
|
|
157
|
+
if (entry === undefined) return undefined;
|
|
158
|
+
const sealed = entry.core === undefined ? [] : sealedFields(entry.core);
|
|
159
|
+
return { description: entry.describe(), sealed: sealed.map((field) => field.property) };
|
|
160
|
+
},
|
|
161
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// Single responsibility: `x repro --bundle`'s answer — redact the subject, read what the scrubber
|
|
2
|
+
// must hide and what the framework is, assemble the one JSON document and write it under `repro/`.
|
|
3
|
+
// The parts are `repro-redact.ts`, `repro-archive-collect.ts`, `repro-scrub.ts`, `repro-archive.ts`.
|
|
4
|
+
|
|
5
|
+
// why: Bun has no rename or unlink; an atomic write needs both.
|
|
6
|
+
import { rename, rm } from 'node:fs/promises';
|
|
7
|
+
// why: Bun exposes no path-join primitive.
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import type { CommandContext } from './command';
|
|
10
|
+
import { msg } from './messages';
|
|
11
|
+
import type { CommandResult, JsonValue } from './output';
|
|
12
|
+
import type { ReproErrorFacts } from './repro-archive';
|
|
13
|
+
import { bundleFileOf, reproArchive } from './repro-archive';
|
|
14
|
+
import { installedFramework, registryLookups, scrubSourcesOf } from './repro-archive-collect';
|
|
15
|
+
import type { ReproSubject } from './repro-bundle';
|
|
16
|
+
import type { RedactOptions, ReproLookups } from './repro-redact';
|
|
17
|
+
import { redactSubject } from './repro-redact';
|
|
18
|
+
import { scrubberFor } from './repro-scrub';
|
|
19
|
+
import { loadVersion } from './version-loader';
|
|
20
|
+
|
|
21
|
+
/** The three file operations an atomic write needs; the system's by default, a recorder in tests. */
|
|
22
|
+
export interface AtomicIo {
|
|
23
|
+
write(path: string, text: string): Promise<void>;
|
|
24
|
+
rename(from: string, to: string): Promise<void>;
|
|
25
|
+
remove(path: string): Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const systemIo: AtomicIo = {
|
|
29
|
+
write: async (path, text) => {
|
|
30
|
+
await Bun.write(path, text);
|
|
31
|
+
},
|
|
32
|
+
rename: (from, to) => rename(from, to),
|
|
33
|
+
remove: (path) => rm(path, { force: true }),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* `text` at `path` or nothing new: a temp file beside it, renamed over it (`core`'s
|
|
38
|
+
* `writeOwnerOnlyFile` shape). A kill mid-write leaves the temp file, never a truncated bundle.
|
|
39
|
+
*/
|
|
40
|
+
export async function writeAtomically(
|
|
41
|
+
path: string,
|
|
42
|
+
text: string,
|
|
43
|
+
io: AtomicIo = systemIo,
|
|
44
|
+
): Promise<void> {
|
|
45
|
+
const temp = `${path}.${crypto.randomUUID()}.tmp`;
|
|
46
|
+
try {
|
|
47
|
+
await io.write(temp, text);
|
|
48
|
+
await io.rename(temp, path);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
await io.remove(temp);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function writeBundle(
|
|
56
|
+
root: string,
|
|
57
|
+
ctx: CommandContext,
|
|
58
|
+
subject: ReproSubject,
|
|
59
|
+
error: ReproErrorFacts,
|
|
60
|
+
options: RedactOptions,
|
|
61
|
+
lookups: ReproLookups = registryLookups,
|
|
62
|
+
): Promise<CommandResult> {
|
|
63
|
+
const redacted = redactSubject(subject, lookups, options);
|
|
64
|
+
const scrubber = scrubberFor(await scrubSourcesOf(root, ctx.env));
|
|
65
|
+
const { document, scrubbed } = reproArchive({
|
|
66
|
+
...redacted,
|
|
67
|
+
error,
|
|
68
|
+
framework: {
|
|
69
|
+
packages: await installedFramework(root),
|
|
70
|
+
cli: loadVersion(),
|
|
71
|
+
bun: ctx.bunVersion,
|
|
72
|
+
platform: `${process.platform}-${process.arch}`,
|
|
73
|
+
},
|
|
74
|
+
scrubber,
|
|
75
|
+
});
|
|
76
|
+
const file = bundleFileOf(subject);
|
|
77
|
+
await writeAtomically(join(root, file), `${JSON.stringify(document, null, 2)}\n`);
|
|
78
|
+
return {
|
|
79
|
+
ok: true,
|
|
80
|
+
command: 'repro',
|
|
81
|
+
summary: msg('cli.repro.bundled', { file }),
|
|
82
|
+
lines: [
|
|
83
|
+
msg('cli.repro.bundleMasked', { count: redacted.masked.length }),
|
|
84
|
+
msg('cli.repro.bundleScrubbed', { env: scrubbed.env.length, hosts: scrubbed.hosts }),
|
|
85
|
+
msg('cli.repro.bundleReadFirst', { file }),
|
|
86
|
+
],
|
|
87
|
+
data: {
|
|
88
|
+
kind: subject.kind,
|
|
89
|
+
file,
|
|
90
|
+
masked: [...redacted.masked],
|
|
91
|
+
dropped: [...redacted.dropped],
|
|
92
|
+
scrubbed: { env: [...scrubbed.env], hosts: scrubbed.hosts },
|
|
93
|
+
includeRows: options.includeRows,
|
|
94
|
+
} satisfies Record<string, JsonValue>,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Single responsibility: the repro bundle's one JSON document, assembled from parts already read —
|
|
2
|
+
// the redacted subject, the error, the framework versions, the touched declarations and the
|
|
3
|
+
// reproducer test — then passed whole through the scrubber. Pure and deterministic: no clock, no
|
|
4
|
+
// machine fact beyond the platform, keys in a fixed order, so two runs write the same bytes.
|
|
5
|
+
|
|
6
|
+
import type { EntityDescription } from '@ultimat3/entity';
|
|
7
|
+
import { API_INDEX } from './app-root';
|
|
8
|
+
import type { ReproSubject } from './repro-bundle';
|
|
9
|
+
import { jobTestSource } from './repro-job';
|
|
10
|
+
import { requestTestSource } from './repro-request';
|
|
11
|
+
import type { Scrubber, ScrubReport } from './repro-scrub';
|
|
12
|
+
import { reproFile } from './repro-write';
|
|
13
|
+
import { PLACEHOLDER_DB_MODULE } from './templates/scaffold-db-client';
|
|
14
|
+
|
|
15
|
+
/** The format tag `create-ultimate repro` checks before it opens anything. */
|
|
16
|
+
export const BUNDLE_FORMAT = 'x-repro-bundle/1';
|
|
17
|
+
|
|
18
|
+
/** What the bundle says about itself, first — the user reads this before sending it. */
|
|
19
|
+
export const READ_FIRST: readonly string[] = [
|
|
20
|
+
'Read this whole file before you attach it to an issue: it is everything that leaves your machine.',
|
|
21
|
+
'It holds: the installed @ultimat3/* versions, the declarations of the entities the failing call read,',
|
|
22
|
+
'the error code, cause and stack frames, the test that replays it (reproducer), and the failing call',
|
|
23
|
+
'(subject): its keys and ids as they were; every other input, row and step value a [redacted] stand-in',
|
|
24
|
+
'the replay fills, the actor org a placeholder. With --include-rows those values are real: read them.',
|
|
25
|
+
'Always masked: secret-named keys, .sensitive() fields, sealed columns. Replaced: the app root (.), home',
|
|
26
|
+
'(~), secret-named / URL / dotenv env values ([env:NAME]), config and env-URL hostnames ([host]), URL',
|
|
27
|
+
'credentials and query values, emails ([email]), IP addresses ([ip]), other absolute paths (<abs>/file).',
|
|
28
|
+
'NOT found: a value this machine never knew — a production-only secret, a customer name in a cause.',
|
|
29
|
+
'Edit any value you still do not want to send. Opening a bundle never runs code from it.',
|
|
30
|
+
'A maintainer opens it with: bunx create-ultimate repro <this file>',
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
export interface ReproErrorFacts {
|
|
34
|
+
readonly cause: string | null;
|
|
35
|
+
readonly stack: string | null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface FrameworkFacts {
|
|
39
|
+
/** Every installed `@ultimat3/*` package, each with the versions found (more than one is a finding). */
|
|
40
|
+
readonly packages: Readonly<Record<string, readonly string[]>>;
|
|
41
|
+
readonly cli: string;
|
|
42
|
+
readonly bun: string;
|
|
43
|
+
readonly platform: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface ReproArchiveInput {
|
|
47
|
+
readonly subject: ReproSubject;
|
|
48
|
+
readonly entities: readonly EntityDescription[];
|
|
49
|
+
readonly dropped: readonly string[];
|
|
50
|
+
readonly masked: readonly string[];
|
|
51
|
+
readonly error: ReproErrorFacts;
|
|
52
|
+
readonly framework: FrameworkFacts;
|
|
53
|
+
readonly scrubber: Scrubber;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The subject's own id: never the argument typed, which may be a path to a file. */
|
|
57
|
+
export const subjectIdOf = (subject: ReproSubject): string =>
|
|
58
|
+
subject.kind === 'job' ? subject.failure.jobId : (subject.bundle.requestId ?? subject.bundle.id);
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Where the bundle lands in the app: beside the written repro tests, named by the WHOLE subject id
|
|
62
|
+
* (an id past 48 characters keeps its first and last 24). Never its first 12 alone: those are a
|
|
63
|
+
* UUIDv7's millisecond, so two failures of one millisecond overwrote each other. The written test's
|
|
64
|
+
* name (`reproFile`) is left as it is: apps commit those, and a rename would duplicate them.
|
|
65
|
+
*/
|
|
66
|
+
export function bundleFileOf(subject: ReproSubject): string {
|
|
67
|
+
const id = subjectIdOf(subject)
|
|
68
|
+
.toLowerCase()
|
|
69
|
+
.replace(/[^a-z0-9]/g, '');
|
|
70
|
+
const short = id.length > 48 ? `${id.slice(0, 24)}${id.slice(-24)}` : id;
|
|
71
|
+
return `repro/bundle-${short || 'unnamed'}.json`;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The frames of a stack — its `at …` lines, trimmed — each through `location`. */
|
|
75
|
+
const framesOf = (stack: string | null, scrubber: Scrubber): string[] =>
|
|
76
|
+
(stack ?? '')
|
|
77
|
+
.split('\n')
|
|
78
|
+
.map((line) => line.trim())
|
|
79
|
+
.filter((line) => line.startsWith('at '))
|
|
80
|
+
.map((line) => scrubber.location(line));
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The reproducer, rendered from a subject alone — never from a bundle's own `reproducer` text,
|
|
84
|
+
* which a stranger could have written — against the scaffold's API index and `dbPackage` (the
|
|
85
|
+
* placeholder in a bundle; the scratch app's own when `create-ultimate repro` opens one).
|
|
86
|
+
*/
|
|
87
|
+
export function bundleReproducer(
|
|
88
|
+
subject: ReproSubject,
|
|
89
|
+
dbPackage: string = PLACEHOLDER_DB_MODULE,
|
|
90
|
+
): { file: string; source: string[] } {
|
|
91
|
+
const id = subjectIdOf(subject);
|
|
92
|
+
const imports = [`../${API_INDEX.replace(/\/index\.ts$/, '')}`];
|
|
93
|
+
const source =
|
|
94
|
+
subject.kind === 'job'
|
|
95
|
+
? jobTestSource(subject.failure, { id, imports })
|
|
96
|
+
: requestTestSource(subject.bundle, { id, imports, build: null, dbPackage });
|
|
97
|
+
return { file: reproFile(subject), source: source.split('\n') };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface ReproArchive {
|
|
101
|
+
readonly document: unknown;
|
|
102
|
+
readonly scrubbed: ScrubReport;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The fields the replay looks a primitive up by, kept OUT of the scrubber: a scrubbed `name` or
|
|
107
|
+
* `primitive` (a dotenv value that happens to be `createPost`) is a bundle that replays nothing,
|
|
108
|
+
* and none of them is data. Blanked before the scrub, put back after it.
|
|
109
|
+
*/
|
|
110
|
+
function scrubbedSubject(subject: ReproSubject, scrubber: Scrubber): ReproSubject {
|
|
111
|
+
if (subject.kind === 'job') {
|
|
112
|
+
const { name, code, step, jobId } = subject.failure;
|
|
113
|
+
const blank = { ...subject.failure, name: '', code: null, step: null, jobId: '' };
|
|
114
|
+
const clean = scrubber.value(blank) as typeof blank;
|
|
115
|
+
return { kind: 'job', failure: { ...clean, name, code, step, jobId } };
|
|
116
|
+
}
|
|
117
|
+
const { primitive, name, code, fingerprint, id } = subject.bundle;
|
|
118
|
+
const blank = { ...subject.bundle, name: '', code: '', fingerprint: '', id: '' };
|
|
119
|
+
const clean = scrubber.value(blank) as typeof blank;
|
|
120
|
+
return { kind: 'request', bundle: { ...clean, primitive, name, code, fingerprint, id } };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function reproArchive(input: ReproArchiveInput): ReproArchive {
|
|
124
|
+
const { subject, scrubber } = input;
|
|
125
|
+
// The subject is scrubbed BEFORE the reproducer is rendered from it, so the test's literal holds
|
|
126
|
+
// the same tokens the `subject` section does; the reproducer is then never scrubbed again — its
|
|
127
|
+
// import lines are the scratch app's, and nothing in it came from anywhere but the subject.
|
|
128
|
+
const clean = scrubbedSubject(subject, scrubber);
|
|
129
|
+
const code = clean.kind === 'job' ? clean.failure.code : clean.bundle.code;
|
|
130
|
+
const data = scrubber.value({
|
|
131
|
+
error: {
|
|
132
|
+
cause: input.error.cause === null ? null : scrubber.location(input.error.cause),
|
|
133
|
+
frames: framesOf(input.error.stack, scrubber),
|
|
134
|
+
},
|
|
135
|
+
schema: { entities: input.entities },
|
|
136
|
+
masked: input.masked,
|
|
137
|
+
dropped: input.dropped,
|
|
138
|
+
}) as {
|
|
139
|
+
error: { cause: string | null; frames: string[] };
|
|
140
|
+
schema: unknown;
|
|
141
|
+
masked: unknown;
|
|
142
|
+
dropped: unknown;
|
|
143
|
+
};
|
|
144
|
+
const document = {
|
|
145
|
+
format: BUNDLE_FORMAT,
|
|
146
|
+
readFirst: READ_FIRST,
|
|
147
|
+
kind: clean.kind,
|
|
148
|
+
id: subjectIdOf(clean),
|
|
149
|
+
code,
|
|
150
|
+
fingerprint: clean.kind === 'job' ? null : clean.bundle.fingerprint,
|
|
151
|
+
framework: input.framework,
|
|
152
|
+
error: { code, ...data.error },
|
|
153
|
+
schema: data.schema,
|
|
154
|
+
masked: data.masked,
|
|
155
|
+
dropped: data.dropped,
|
|
156
|
+
subject: clean.kind === 'job' ? clean.failure : clean.bundle,
|
|
157
|
+
reproducer: bundleReproducer(clean),
|
|
158
|
+
scrubbed: scrubber.report(),
|
|
159
|
+
};
|
|
160
|
+
return { document, scrubbed: scrubber.report() };
|
|
161
|
+
}
|
package/src/repro-bundle.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { inspectJob } from '@ultimat3/jobs';
|
|
|
10
10
|
import type { JobFailure } from '@ultimat3/testing';
|
|
11
11
|
import { ReproCaptureOffError, ReproUnknownError } from './repro-errors';
|
|
12
12
|
import { jobFailureOf } from './repro-job';
|
|
13
|
+
import { parseReproSubject } from './repro-parse';
|
|
13
14
|
|
|
14
15
|
export type ReproSubject =
|
|
15
16
|
| { readonly kind: 'job'; readonly failure: JobFailure }
|
|
@@ -18,27 +19,18 @@ export type ReproSubject =
|
|
|
18
19
|
/** A uuid in any spelling `x_jobs.id` accepts — `cmd-jobs.ts`' rule, so no statement is wasted. */
|
|
19
20
|
const JOB_ID = /^\{?[0-9a-f]{8}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{4}-?[0-9a-f]{12}\}?$/i;
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
isJsonObject(value) &&
|
|
23
|
-
typeof value['name'] === 'string' &&
|
|
24
|
-
(value['primitive'] === 'action' || value['primitive'] === 'query') &&
|
|
25
|
-
Array.isArray(value['reads']);
|
|
26
|
-
|
|
27
|
-
const isJobFailure = (value: unknown): value is JobFailure =>
|
|
28
|
-
isJsonObject(value) &&
|
|
29
|
-
typeof value['jobId'] === 'string' &&
|
|
30
|
-
typeof value['name'] === 'string' &&
|
|
31
|
-
Array.isArray(value['steps']);
|
|
32
|
-
|
|
33
|
-
/** `--from <file>`: a bundle `x repro <id> --json` printed (`data.bundle` or `data.failure`), or one bare. */
|
|
22
|
+
/** `--from <file>`: what `x repro <id> --json` printed (`data.bundle`/`data.failure`), a repro bundle, or bare. */
|
|
34
23
|
export async function subjectFromFile(path: string): Promise<ReproSubject> {
|
|
35
24
|
const file = Bun.file(path);
|
|
36
25
|
if (!(await file.exists())) throw new ReproUnknownError({ id: path });
|
|
37
26
|
const parsed: unknown = await file.json();
|
|
38
27
|
const data = isJsonObject(parsed) && isJsonObject(parsed['data']) ? parsed['data'] : parsed;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
// `subject` is a repro bundle's (`x repro --bundle`): the redacted failure, read back as-is.
|
|
29
|
+
const inner = isJsonObject(data)
|
|
30
|
+
? (data['bundle'] ?? data['failure'] ?? data['subject'] ?? data)
|
|
31
|
+
: data;
|
|
32
|
+
const subject = parseReproSubject(inner);
|
|
33
|
+
if (subject !== undefined) return subject;
|
|
42
34
|
throw new ReproUnknownError({ id: path });
|
|
43
35
|
}
|
|
44
36
|
|
package/src/repro-errors.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// The
|
|
2
|
-
//
|
|
1
|
+
// The ways `x repro` refuses: an id nothing holds, a capture that was never on, a written test that
|
|
2
|
+
// did not fail the way the original did, and a file `create-ultimate repro` cannot open as a bundle.
|
|
3
3
|
|
|
4
4
|
import { renderFixShellArg, UltimateError } from '@ultimat3/core';
|
|
5
5
|
|
|
@@ -45,3 +45,15 @@ export class ReproNotReproducedError extends UltimateError {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
/** `create-ultimate repro <file>` on a file this version cannot open: absent, another format, no test. */
|
|
50
|
+
export class ReproBundleInvalidError extends UltimateError {
|
|
51
|
+
constructor(input: { readonly path: string; readonly reason: string }) {
|
|
52
|
+
super({
|
|
53
|
+
code: 'X_REPRO_BUNDLE_INVALID',
|
|
54
|
+
cause: `${input.path} is not a repro bundle this version can open: ${input.reason}`,
|
|
55
|
+
fix: 'x repro <id> --bundle --json # on the failing app, then attach the file it writes',
|
|
56
|
+
meta: { path: input.path, reason: input.reason },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Single responsibility: a framework checkout as a scratch app's `@ultimat3/*` source — which
|
|
2
|
+
// directory is one (its `packages/core` is `@ultimat3/core`), the one a cwd sits inside, and the
|
|
3
|
+
// `file:` override per package that points every install of the graph at that checkout.
|
|
4
|
+
|
|
5
|
+
// why: a cwd walk-up asks synchronously, and Bun has no directory listing.
|
|
6
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
7
|
+
// why: Bun exposes no path-join primitive.
|
|
8
|
+
import { join, resolve } from 'node:path';
|
|
9
|
+
import { isJsonObject } from '@ultimat3/core';
|
|
10
|
+
|
|
11
|
+
/** A checkout is the directory whose `packages/core/package.json` names `@ultimat3/core`. */
|
|
12
|
+
export function isFrameworkCheckout(dir: string): boolean {
|
|
13
|
+
const manifest = join(dir, 'packages', 'core', 'package.json');
|
|
14
|
+
if (!existsSync(manifest)) return false;
|
|
15
|
+
try {
|
|
16
|
+
const parsed: unknown = JSON.parse(readFileSync(manifest, 'utf8'));
|
|
17
|
+
return isJsonObject(parsed) && parsed['name'] === '@ultimat3/core';
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The checkout `cwd` is inside, walking up; `undefined` outside every one. */
|
|
24
|
+
export function frameworkCheckoutFrom(cwd: string): string | undefined {
|
|
25
|
+
let dir = resolve(cwd);
|
|
26
|
+
for (;;) {
|
|
27
|
+
if (isFrameworkCheckout(dir)) return dir;
|
|
28
|
+
const parent = resolve(dir, '..');
|
|
29
|
+
if (parent === dir) return undefined;
|
|
30
|
+
dir = parent;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* One `file:` override per `@ultimat3/*` package under `<checkout>/packages`, names sorted.
|
|
36
|
+
* `overrides`, never `dependencies`: most of the graph is transitive, and only an override
|
|
37
|
+
* rewrites a range wherever it appears.
|
|
38
|
+
*/
|
|
39
|
+
export async function frameworkOverrides(checkout: string): Promise<Record<string, string>> {
|
|
40
|
+
const out: Record<string, string> = {};
|
|
41
|
+
const packages = join(checkout, 'packages');
|
|
42
|
+
if (!existsSync(packages)) return out;
|
|
43
|
+
for (const dir of readdirSync(packages).sort()) {
|
|
44
|
+
const manifest = Bun.file(join(packages, dir, 'package.json'));
|
|
45
|
+
if (!(await manifest.exists())) continue;
|
|
46
|
+
const parsed: unknown = await manifest.json().catch(() => undefined);
|
|
47
|
+
const name = isJsonObject(parsed) ? parsed['name'] : undefined;
|
|
48
|
+
if (typeof name === 'string' && name.startsWith('@ultimat3/')) {
|
|
49
|
+
out[name] = `file:${join(packages, dir)}`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return out;
|
|
53
|
+
}
|