@ultimat3/cli 31.39.0 → 31.40.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.
- package/README.md +1 -1
- package/package.json +29 -29
- package/src/cmd-errors-guards.ts +69 -0
- package/src/cmd-errors.ts +11 -4
- package/src/cmd-exercise.ts +3 -2
- package/src/cmd-new-spec.ts +8 -1
- package/src/cmd-new-target.ts +115 -0
- package/src/cmd-new.ts +13 -19
- package/src/cmd-repro.ts +2 -1
- package/src/codemods/ci-e2e-browser.ts +7 -1
- package/src/codemods/ci-services-env.ts +25 -0
- package/src/codemods/docs-env-guard.ts +31 -0
- package/src/codemods/index.ts +4 -0
- package/src/dev-boot.ts +3 -0
- package/src/dev-rebuild-isr.ts +17 -0
- package/src/dev-rebuild.ts +14 -5
- package/src/error-contract.ts +11 -4
- package/src/exercise-findings-unreached.ts +94 -0
- package/src/exercise-findings.ts +9 -57
- package/src/exercise-route-api.ts +3 -4
- package/src/fix-sequence.ts +28 -3
- package/src/framework-schema-wait.ts +41 -2
- package/src/generate-feature-required.ts +40 -3
- package/src/generate-kinds.ts +23 -2
- package/src/guards-shipped-names.ts +1 -0
- package/src/messages.ts +8 -0
- package/src/serve-boot.ts +4 -0
- package/src/templates/action.ts +7 -2
- package/src/templates/github/ci.yml.ts +3 -2
- package/src/templates/guard-raw-colour.ts +88 -13
- package/src/templates/guard-released-forms.ts +9 -3
- package/src/templates/guard-undeclared-env.ts +192 -0
- package/src/templates/guard-untranslated-string.ts +29 -1
- package/src/templates/policy.ts +7 -1
- package/src/templates/query.ts +8 -6
- package/src/templates/scaffold-docs.ts +1 -0
- package/src/templates/scaffold-guards.ts +4 -1
- package/src/templates/scaffold-i18n.ts +1 -1
- package/src/templates/scaffold-repo.ts +26 -24
- package/src/templates/shapes/agent.ts +2 -2
- package/src/templates/shapes/offline.ts +1 -1
- package/src/templates/shapes/realtime.ts +2 -2
- package/src/templates/shapes/saas.ts +5 -4
- package/src/templates/slice-foundation.ts +29 -9
- package/wiki/Actions.md +1 -1
- package/wiki/CLI-Reference.md +2 -2
- package/wiki/Getting-Started.md +1 -1
- package/wiki/Installation.md +2 -2
- package/wiki/Queries-And-Live-Queries.md +4 -4
- package/wiki/Realtime.md +12 -2
- package/wiki/Tutorial-04-Jobs-And-Realtime.md +3 -2
- package/wiki/Upgrading.md +2 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// `X_CONTRACT_EXERCISE_UNREACHED`'s finding: a primitive no run got to as an allowed actor, and the
|
|
2
|
+
// ONE edit that can change that — a policy predicate that refused, the entry the file already holds,
|
|
3
|
+
// or the entry to paste. Only the paste carries the run's drawn ids; the other two are stable.
|
|
4
|
+
|
|
5
|
+
import { ERROR_DOCS_URL, renderCauseValue, renderFixShellArg } from '@ultimat3/core';
|
|
6
|
+
import type { ExerciseOverrides, ExerciseRecord } from '@ultimat3/testing';
|
|
7
|
+
import type { Finding } from './output';
|
|
8
|
+
|
|
9
|
+
/** The file an override is pasted into — `defineExercise()`'s one home. */
|
|
10
|
+
export const EXERCISE_FILE = 'apps/web/exercise.ts';
|
|
11
|
+
|
|
12
|
+
/** The overrides `apps/web/exercise.ts` declared, `undefined` when the app has no such file. */
|
|
13
|
+
export type ExerciseFileFacts = ExerciseOverrides | undefined;
|
|
14
|
+
|
|
15
|
+
const PASTE_NOTE =
|
|
16
|
+
"an inline .contract({ exercise: {...} }) in a test is not read here: move it, then pass .contract({ exercise }); or give the entry { off: '<why>' }";
|
|
17
|
+
|
|
18
|
+
/** `can()`'s denial when its predicate refused — `<label> predicate returned false` (policy.ts). */
|
|
19
|
+
const PREDICATE_REFUSED = /^(\S+) predicate returned (?:false|neither a boolean nor a decision)/;
|
|
20
|
+
|
|
21
|
+
const hasEntry = (facts: ExerciseFileFacts, record: ExerciseRecord): boolean =>
|
|
22
|
+
facts !== undefined &&
|
|
23
|
+
(facts.entries.has(`${record.kind}:${record.name}`) || facts.entries.has(record.name));
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The predicate's label is the permission `can()` was handed; its resource names the slice whose
|
|
27
|
+
* `policy.ts` `x g` wrote. No input passes a predicate that refuses every seeded actor, so the edit
|
|
28
|
+
* is the predicate; `x policy explain` prints the clause that decided, for an action or a query.
|
|
29
|
+
*/
|
|
30
|
+
const predicateFix = (record: ExerciseRecord, label: string, rerun: string): string => {
|
|
31
|
+
const name = renderFixShellArg(record.name, '<name>');
|
|
32
|
+
const show =
|
|
33
|
+
record.kind === 'action' || record.kind === 'query'
|
|
34
|
+
? `x policy explain ${name} --json`
|
|
35
|
+
: 'x policy list --json';
|
|
36
|
+
const permission = renderFixShellArg(label, '<permission>');
|
|
37
|
+
const resource = permission.includes(':') ? permission.split(':')[0] : undefined;
|
|
38
|
+
const where =
|
|
39
|
+
resource === undefined
|
|
40
|
+
? `the ${permission} predicate (${show} names its clause)`
|
|
41
|
+
: `the predicate of can('${permission}', …) in apps/web/app/${resource}/policy.ts, else the file declaring it (${show} names the clause)`;
|
|
42
|
+
return `edit ${where} so an actor the pass seeds passes it: it returned false for every one, and no ${EXERCISE_FILE} entry changes that — or give the ${name} entry { off: '<why>' }; ${rerun}`;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const pasteFix = (record: ExerciseRecord, facts: ExerciseFileFacts, rerun: string): string => {
|
|
46
|
+
const entry = (
|
|
47
|
+
record.override ?? `${record.name}: { input: { /* a value it accepts */ } }`
|
|
48
|
+
).replace(/[\s,]+$/, '');
|
|
49
|
+
return facts === undefined
|
|
50
|
+
? `import { defineExercise } from '@ultimat3/testing'; export const exercise = defineExercise({ ${entry} }); # create ${EXERCISE_FILE} with this (${PASTE_NOTE}); ${rerun}`
|
|
51
|
+
: `${entry}, # paste inside export const exercise = defineExercise({ … }) in ${EXERCISE_FILE} (${PASTE_NOTE}); ${rerun}`;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The fix, from its first character: a refusing predicate's edit; else the edit to the entry the
|
|
56
|
+
* file holds (a second key is TS1117); else the paste — into a file that exists, the bare entry
|
|
57
|
+
* (thirty findings are thirty entries inside the ONE export); with no file yet, the whole file.
|
|
58
|
+
*/
|
|
59
|
+
export const unreachedFinding =
|
|
60
|
+
(facts: ExerciseFileFacts) =>
|
|
61
|
+
(record: ExerciseRecord): Finding => {
|
|
62
|
+
const name = renderFixShellArg(record.name, '<name>');
|
|
63
|
+
const stopped = record.code === undefined ? '' : ` — stopped on ${record.code}`;
|
|
64
|
+
const why = record.reason === undefined ? '' : ` (${renderCauseValue(record.reason)})`;
|
|
65
|
+
const rerun = `then: x exercise ${name} --json`;
|
|
66
|
+
const label = PREDICATE_REFUSED.exec(record.reason ?? '')?.[1];
|
|
67
|
+
const fix =
|
|
68
|
+
label !== undefined
|
|
69
|
+
? predicateFix(record, label, rerun)
|
|
70
|
+
: hasEntry(facts, record)
|
|
71
|
+
? `edit the ${name} entry already in ${EXERCISE_FILE} (its input or actor; a second ${name}: key is TS1117), or give it { off: '<why>' }; then: x exercise ${name} --json`
|
|
72
|
+
: pasteFix(record, facts, rerun);
|
|
73
|
+
return {
|
|
74
|
+
code: 'X_CONTRACT_EXERCISE_UNREACHED',
|
|
75
|
+
cause: `${record.kind} ${renderCauseValue(record.name)} never reached its handler as an allowed actor in the exercise pass${stopped}${why}${defectOf(record)}`,
|
|
76
|
+
fix: record.fix ?? fix,
|
|
77
|
+
docs: ERROR_DOCS_URL,
|
|
78
|
+
at: EXERCISE_FILE,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A 5xx's own words — the cause testing recorded (credential values already masked there) and the
|
|
84
|
+
* fields a validation failure names. The statement is inside the cause, so it is not said twice.
|
|
85
|
+
*/
|
|
86
|
+
const defectOf = (record: ExerciseRecord): string => {
|
|
87
|
+
const defect = record.defect;
|
|
88
|
+
if (defect === undefined) return '';
|
|
89
|
+
const fields =
|
|
90
|
+
defect.fields === undefined
|
|
91
|
+
? ''
|
|
92
|
+
: ` at ${defect.fields.map((field) => renderCauseValue(field)).join(', ')}`;
|
|
93
|
+
return ` — cause: ${renderCauseValue(defect.cause)}${fields}`;
|
|
94
|
+
};
|
package/src/exercise-findings.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// What `x exercise` makes of a pass's records: one finding per `unreached` primitive
|
|
2
|
-
//
|
|
3
|
-
// table;
|
|
4
|
-
// command cannot disagree about what is red.
|
|
1
|
+
// What `x exercise` makes of a pass's records: one finding per `unreached` primitive (its fix is
|
|
2
|
+
// `exercise-findings-unreached.ts`'s), per crossed tenant and diverged crash proof; the counts; the
|
|
3
|
+
// table; the one report `--json` and `.x/exercise.json` hold. Pure — records in, plain values out —
|
|
4
|
+
// so the gate step and the command cannot disagree about what is red.
|
|
5
5
|
|
|
6
6
|
// why: Bun ships no path joiner.
|
|
7
7
|
import { join } from 'node:path';
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
} from '@ultimat3/core';
|
|
14
14
|
import type { ExercisePhaseMs, ExerciseRecord, ProofMs } from '@ultimat3/testing';
|
|
15
15
|
import { crashEffectPlace, planSweepFindings, tenantProofFindings } from '@ultimat3/testing';
|
|
16
|
+
import type { ExerciseFileFacts } from './exercise-findings-unreached';
|
|
17
|
+
import { unreachedFinding } from './exercise-findings-unreached';
|
|
16
18
|
import { msg } from './messages';
|
|
17
19
|
import type { Finding } from './output';
|
|
18
20
|
import { renderTable } from './table';
|
|
@@ -20,8 +22,8 @@ import { renderTable } from './table';
|
|
|
20
22
|
/** Where the pass's report is written, app-root-relative: state, gitignored with the rest of `.x/`. */
|
|
21
23
|
export const EXERCISE_REPORT_FILE = join('.x', 'exercise.json');
|
|
22
24
|
|
|
23
|
-
|
|
24
|
-
export
|
|
25
|
+
export type { ExerciseFileFacts } from './exercise-findings-unreached';
|
|
26
|
+
export { EXERCISE_FILE } from './exercise-findings-unreached';
|
|
25
27
|
|
|
26
28
|
type Outcome = ExerciseRecord['outcome'];
|
|
27
29
|
|
|
@@ -45,56 +47,6 @@ export const exerciseCounts = (records: readonly ExerciseRecord[]): ExerciseCoun
|
|
|
45
47
|
};
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
/**
|
|
49
|
-
* A 5xx's own words — the cause testing recorded (credential values already masked there) and the
|
|
50
|
-
* fields a validation failure names. The statement is inside the cause, so it is not said twice.
|
|
51
|
-
*/
|
|
52
|
-
const defectOf = (record: ExerciseRecord): string => {
|
|
53
|
-
const defect = record.defect;
|
|
54
|
-
if (defect === undefined) return '';
|
|
55
|
-
const fields =
|
|
56
|
-
defect.fields === undefined
|
|
57
|
-
? ''
|
|
58
|
-
: ` at ${defect.fields.map((field) => renderCauseValue(field)).join(', ')}`;
|
|
59
|
-
return ` — cause: ${renderCauseValue(defect.cause)}${fields}`;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/** Whether the app has an `apps/web/exercise.ts` yet: what an unreached finding's fix pastes into. */
|
|
63
|
-
export type ExerciseFileState = 'present' | 'absent';
|
|
64
|
-
|
|
65
|
-
const PASTE_NOTE =
|
|
66
|
-
"an inline .contract({ exercise: {...} }) in a test is not read here: move it, then pass .contract({ exercise }); or give the entry { off: '<why>' }";
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* `X_CONTRACT_EXERCISE_UNREACHED`, `@ultimat3/action`'s code for the same silence one level up: a
|
|
70
|
-
* primitive no run got to as an allowed actor. The fix is pasted from its first character: into a
|
|
71
|
-
* file that exists, the bare entry (thirty findings are thirty entries inside the ONE export, never
|
|
72
|
-
* thirty `defineExercise` calls to unwrap); with no file yet, the whole file to create. Then the
|
|
73
|
-
* one-primitive rerun that proves it.
|
|
74
|
-
*/
|
|
75
|
-
const unreachedFinding =
|
|
76
|
-
(file: ExerciseFileState) =>
|
|
77
|
-
(record: ExerciseRecord): Finding => {
|
|
78
|
-
const name = renderFixShellArg(record.name, '<name>');
|
|
79
|
-
const entry = (
|
|
80
|
-
record.override ?? `${record.name}: { input: { /* a value it accepts */ } }`
|
|
81
|
-
).replace(/[\s,]+$/, '');
|
|
82
|
-
const stopped = record.code === undefined ? '' : ` — stopped on ${record.code}`;
|
|
83
|
-
const why = record.reason === undefined ? '' : ` (${renderCauseValue(record.reason)})`;
|
|
84
|
-
const rerun = `then: x exercise ${name} --json`;
|
|
85
|
-
const paste =
|
|
86
|
-
file === 'present'
|
|
87
|
-
? `${entry}, # paste inside export const exercise = defineExercise({ … }) in ${EXERCISE_FILE} (${PASTE_NOTE}); ${rerun}`
|
|
88
|
-
: `import { defineExercise } from '@ultimat3/testing'; export const exercise = defineExercise({ ${entry} }); # create ${EXERCISE_FILE} with this (${PASTE_NOTE}); ${rerun}`;
|
|
89
|
-
return {
|
|
90
|
-
code: 'X_CONTRACT_EXERCISE_UNREACHED',
|
|
91
|
-
cause: `${record.kind} ${renderCauseValue(record.name)} never reached its handler as an allowed actor in the exercise pass${stopped}${why}${defectOf(record)}`,
|
|
92
|
-
fix: record.fix ?? paste,
|
|
93
|
-
docs: ERROR_DOCS_URL,
|
|
94
|
-
at: EXERCISE_FILE,
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
|
|
98
50
|
type CrashFinding = Extract<
|
|
99
51
|
NonNullable<ExerciseRecord['crash']>,
|
|
100
52
|
{ readonly verdict: 'diverged' }
|
|
@@ -150,7 +102,7 @@ export const crashFindingLines = (records: readonly ExerciseRecord[]): readonly
|
|
|
150
102
|
*/
|
|
151
103
|
export const exerciseFindings = (
|
|
152
104
|
records: readonly ExerciseRecord[],
|
|
153
|
-
file
|
|
105
|
+
file?: ExerciseFileFacts,
|
|
154
106
|
): readonly Finding[] => [
|
|
155
107
|
...records.filter((one) => one.outcome === 'unreached').map(unreachedFinding(file)),
|
|
156
108
|
...tenantProofFindings(records).map((one) => ({ ...one, docs: ERROR_DOCS_URL })),
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import type { Actor } from '@ultimat3/core';
|
|
7
7
|
import { asyncContext, isAnonymous, tryUseContext, withInProcessFetch } from '@ultimat3/core';
|
|
8
|
+
import { installedBuildId } from '@ultimat3/core/adapter';
|
|
8
9
|
import { defineHttpConfig, httpPipeline, httpRouter } from '@ultimat3/http';
|
|
9
10
|
import type { RouteLoadSubject } from '@ultimat3/testing';
|
|
10
11
|
import { apiRoutes } from './api-routes';
|
|
@@ -18,10 +19,8 @@ const caller = asyncContext<Actor | null>('the exercise in-process caller');
|
|
|
18
19
|
/** One dispatcher over the app's API table, built on first use: the registries are full by then. */
|
|
19
20
|
function dispatcher(): (url: string, init: RequestInit) => Promise<Response> {
|
|
20
21
|
// No rate limit: every request is the pass's own, as a build's are (`measure-scope.ts`).
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
rateLimit: { enabled: false },
|
|
24
|
-
});
|
|
22
|
+
// The id core holds (`'dev'` outside a boot, as `x exercise` runs), never `BUILD_ID` read again.
|
|
23
|
+
const config = defineHttpConfig({ buildId: installedBuildId(), rateLimit: { enabled: false } });
|
|
25
24
|
const pipeline = httpPipeline({
|
|
26
25
|
table: httpRouter(apiRoutes()),
|
|
27
26
|
config,
|
package/src/fix-sequence.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The order rule on a `fix:` line, for the `errors` step: the edit leads, the re-run follows —
|
|
2
2
|
// `x verify # after deleting .sensitive()` is pasted before it is read, and re-runs unchanged.
|
|
3
3
|
// Shipped lines are ratcheted per file in `FIX_SEQUENCE_BASELINE`; a new one is
|
|
4
|
-
// `X_ERROR_FIX_INVALID`. A generator offered with `--force` is never a fix (none shipped 2026-11).
|
|
4
|
+
// `X_ERROR_FIX_INVALID`. A generator or scaffolder offered with `--force` is never a fix (none shipped 2026-11).
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* A comment opening with the precondition, in its deferred-edit form only: `<command> # after
|
|
@@ -34,8 +34,13 @@ export function fixSequenceProblem(fix: string): string | undefined {
|
|
|
34
34
|
return undefined;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
|
|
37
|
+
/**
|
|
38
|
+
* `x g …` / `x generate …` / `x new …` / `create-ultimate …` carrying `--force`, before any `#`
|
|
39
|
+
* comment: the part that is pasted. The scaffolders are generators too — `x new … --force` over an
|
|
40
|
+
* existing app reset its `roles.ts` to the template (D1).
|
|
41
|
+
*/
|
|
42
|
+
const FORCED_GENERATOR =
|
|
43
|
+
/(?:^|[\s;|&(])(?:x\s+(?:g|generate|new)|create-ultimate)\b[^#]*?\s--force(?![\w-])/;
|
|
39
44
|
|
|
40
45
|
/**
|
|
41
46
|
* A printed fix is pasted with no diff in front of it, and a generator's file can be shared — a
|
|
@@ -48,6 +53,26 @@ export function generatorForceProblem(fix: string): string | undefined {
|
|
|
48
53
|
return `fix "${fix}" runs a generator with --force, which overwrites a file other slices or generators may share, and a pasted fix shows no diff first — name the edit to the existing file instead`;
|
|
49
54
|
}
|
|
50
55
|
|
|
56
|
+
/** A quoted `--force` token, whole: `'--force-with-lease'` is another flag. */
|
|
57
|
+
const QUOTED_FORCE = /(['"`])--force\1/;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The same rule on the RAW fix, inside its interpolations: `${[invocation, name, '--force'].join(' ')}`
|
|
61
|
+
* blanks to `<value>`, so the text rule above never saw the `--force` that `x new` printed (D1).
|
|
62
|
+
* Two `indexOf` scans, as `staticFix` does — no regex re-scanning from every unclosed `${`.
|
|
63
|
+
*/
|
|
64
|
+
export function interpolatedForceProblem(raw: string): string | undefined {
|
|
65
|
+
for (let open = raw.indexOf('${'); open >= 0; ) {
|
|
66
|
+
const close = raw.indexOf('}', open + 2);
|
|
67
|
+
if (close < 0) return undefined;
|
|
68
|
+
if (QUOTED_FORCE.test(raw.slice(open + 2, close))) {
|
|
69
|
+
return `fix "${raw}" assembles --force into the command it prints, which overwrites what the target already holds, and a pasted fix shows no diff first — name a free target or the edit instead`;
|
|
70
|
+
}
|
|
71
|
+
open = raw.indexOf('${', close + 1);
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
51
76
|
/**
|
|
52
77
|
* Root-relative file → how many fix lines in it the rule above refuses: 53 lines in 38 files across
|
|
53
78
|
* this repo and its three tracked apps, measured 2026-11-11 (the docs site's
|
|
@@ -89,13 +89,20 @@ export async function waitForSchema<T>(
|
|
|
89
89
|
// The `accept` phase, the first: the boot is under `holdWhileBooting`'s handlers, so a SIGTERM
|
|
90
90
|
// here is a drain, and this wait is the boot work it must end.
|
|
91
91
|
const unregister = onShutdown('cli:schema-wait', () => stop.abort(), { phase: 'accept' });
|
|
92
|
+
// The refusal a drain ends the wait with: the last verdict's, or — when the drain lands on the
|
|
93
|
+
// first read — the drain itself, since nothing was read to refuse with.
|
|
94
|
+
let refuse: ((waitedMs?: number) => UltimateError) | undefined;
|
|
95
|
+
const drained = (): UltimateError => (refuse ?? waitDrained)(clock.monotonic() - startedAt);
|
|
92
96
|
try {
|
|
93
97
|
for (let attempt = 1; ; attempt += 1) {
|
|
94
|
-
|
|
98
|
+
// Raced against the drain like the sleep below: a read on an unreachable database hangs
|
|
99
|
+
// until the pool gives up — ~125 s on a worker, past the pod's grace, so SIGKILL (137).
|
|
100
|
+
const verdict = await untilAborted(check(), stop.signal, drained);
|
|
95
101
|
if (verdict.ready) {
|
|
96
102
|
streak.passed();
|
|
97
103
|
return verdict.value;
|
|
98
104
|
}
|
|
105
|
+
refuse = verdict.refuse;
|
|
99
106
|
const waitedMs = clock.monotonic() - startedAt;
|
|
100
107
|
if (verdict.atOnce === true || deadlineMs === 0) throw verdict.refuse();
|
|
101
108
|
if (waitedMs >= deadlineMs || stop.signal.aborted || isDraining()) {
|
|
@@ -116,10 +123,42 @@ export async function waitForSchema<T>(
|
|
|
116
123
|
// The drain's abort ends the wait with the refusal `holdWhileBooting` turns into an exit
|
|
117
124
|
// of `drainExitCode()`; any other rejection is the clock's own, and is rethrown as it came.
|
|
118
125
|
if (!stop.signal.aborted) throw error;
|
|
119
|
-
throw
|
|
126
|
+
throw drained();
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
129
|
} finally {
|
|
123
130
|
unregister();
|
|
124
131
|
}
|
|
125
132
|
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* `X_DRAINING`, core's code for work cut short by shutdown: a drain landed on the first read, so
|
|
136
|
+
* no verdict exists to refuse with. `holdWhileBooting` turns it into an exit of `drainExitCode()`.
|
|
137
|
+
*/
|
|
138
|
+
function waitDrained(waitedMs = 0): UltimateError {
|
|
139
|
+
return new UltimateError({
|
|
140
|
+
code: 'X_DRAINING',
|
|
141
|
+
cause: `a drain began while this role's first schema read was in flight (${String(waitedMs)} ms in), so the boot ended there instead of waiting on a database that may never answer`,
|
|
142
|
+
fix: 'x deploy verify --url https://app.example.com --build "$BUILD_ID" # nothing to do on this pod: its replacement boots and reads the schema again',
|
|
143
|
+
retry: 'terminal',
|
|
144
|
+
meta: { waitedMs },
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* `work`, unless `signal` aborts first — then `refusal()`, thrown. The abandoned read is not
|
|
150
|
+
* cancelled (the pool's own bound retires it); `Promise.race` keeps its late rejection handled.
|
|
151
|
+
*/
|
|
152
|
+
function untilAborted<V>(
|
|
153
|
+
work: Promise<V>,
|
|
154
|
+
signal: AbortSignal,
|
|
155
|
+
refusal: () => UltimateError,
|
|
156
|
+
): Promise<V> {
|
|
157
|
+
let onAbort: () => void = () => undefined;
|
|
158
|
+
const aborted = new Promise<never>((_resolve, reject) => {
|
|
159
|
+
onAbort = () => reject(refusal());
|
|
160
|
+
if (signal.aborted) onAbort();
|
|
161
|
+
else signal.addEventListener('abort', onAbort, { once: true });
|
|
162
|
+
});
|
|
163
|
+
return Promise.race([work, aborted]).finally(() => signal.removeEventListener('abort', onAbort));
|
|
164
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
// `
|
|
2
|
-
// `
|
|
3
|
-
//
|
|
1
|
+
// `X_FEATURE_REQUIRED`: a generator refused when its slice lacks what its body needs — a table for
|
|
2
|
+
// `query`/`backfill`/`export-rows`/`import-rows` (`x g query order` once wrote 14 files over none),
|
|
3
|
+
// a permission subject for `action`/`mutator` (D13). Only `x g entity`/`resource` create a table,
|
|
4
|
+
// only `x g policy`/`resource` a subject; nothing else invents either.
|
|
4
5
|
|
|
5
6
|
import { existsSync } from 'node:fs'; // why: a synchronous file probe, as the slice's own guard.
|
|
7
|
+
// why: Bun ships no path helpers; the slice's own directory name is matched against its siblings.
|
|
8
|
+
import { basename } from 'node:path';
|
|
6
9
|
import { UltimateError } from '@ultimat3/core';
|
|
7
10
|
import { commentSafe } from './comment-safe';
|
|
8
11
|
import { closestSlice, slicesBeside } from './generate-feature';
|
|
@@ -18,6 +21,15 @@ export const READS_A_TABLE: ReadonlySet<Generator> = new Set<Generator>([
|
|
|
18
21
|
'import-rows',
|
|
19
22
|
]);
|
|
20
23
|
|
|
24
|
+
/**
|
|
25
|
+
* The generators whose body enforces `can('<slice>:<verb>')`: in a slice that does not exist the
|
|
26
|
+
* run wrote a `policy.ts` and granted the new subject in `roles.ts` — a permission nobody named.
|
|
27
|
+
*/
|
|
28
|
+
export const ENFORCES_A_PERMISSION: ReadonlySet<Generator> = new Set<Generator>([
|
|
29
|
+
'action',
|
|
30
|
+
'mutator',
|
|
31
|
+
]);
|
|
32
|
+
|
|
21
33
|
/** Declared beside its one thrower: `errors.ts` sits at its 500-line ceiling. */
|
|
22
34
|
export class FeatureRequiredError extends UltimateError {
|
|
23
35
|
constructor(input: { readonly cause: string; readonly fix: string }) {
|
|
@@ -43,6 +55,7 @@ export interface SliceToRead {
|
|
|
43
55
|
* Named flags stay out of the leading line's `--feature`, which this fix supplies itself.
|
|
44
56
|
*/
|
|
45
57
|
export function assertSliceToRead(root: string, target: SliceToRead): void {
|
|
58
|
+
assertSliceToWrite(root, target);
|
|
46
59
|
const { kind, name, feature, slice, flags } = target;
|
|
47
60
|
if (!READS_A_TABLE.has(kind)) return;
|
|
48
61
|
if (existsSync(containedPath(root, `${slice}/entity.ts`))) return;
|
|
@@ -68,3 +81,27 @@ export function assertSliceToRead(root: string, target: SliceToRead): void {
|
|
|
68
81
|
: `x g resource ${named} # a new table, or x g ${kind} ${named} --feature <slice> to read one of: ${listed}`,
|
|
69
82
|
});
|
|
70
83
|
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Refuses an action or mutator whose name names no slice and no `--feature` names one: the run
|
|
87
|
+
* would invent the permission subject it enforces. A `--feature` was already held to an existing
|
|
88
|
+
* directory by `assertFeatureExists`; a slice of the name's own spelling is today's path.
|
|
89
|
+
*/
|
|
90
|
+
function assertSliceToWrite(root: string, target: SliceToRead): void {
|
|
91
|
+
const { kind, name, feature, slice, flags } = target;
|
|
92
|
+
if (!ENFORCES_A_PERMISSION.has(kind) || feature !== undefined) return;
|
|
93
|
+
const slices = slicesBeside(root, slice);
|
|
94
|
+
if (slices.includes(basename(slice))) return;
|
|
95
|
+
const near = closestSlice(name, slices);
|
|
96
|
+
const named = quoteArg(name);
|
|
97
|
+
const listed = commentSafe(slices.join(', '));
|
|
98
|
+
throw new FeatureRequiredError({
|
|
99
|
+
cause: `x g ${kind} ${named} names no --feature and ${slice} is no slice (${slices.length === 0 ? 'no slice exists yet' : `slices: ${listed}`}), and an ${kind} never creates the permission subject it enforces — only x g policy and x g resource do`,
|
|
100
|
+
fix:
|
|
101
|
+
near !== undefined
|
|
102
|
+
? `${[`x g ${kind} ${named} --feature ${quoteArg(near)}`, ...flags].join(' ')} # or x g policy ${named} for a new permission subject`
|
|
103
|
+
: slices.length === 0
|
|
104
|
+
? `x g policy ${named} # a new permission subject: x g ${kind} writes into a slice, and none exists yet`
|
|
105
|
+
: `x g policy ${named} # a new permission subject, or x g ${kind} ${named} --feature <slice> to write into one of: ${listed}`,
|
|
106
|
+
});
|
|
107
|
+
}
|
package/src/generate-kinds.ts
CHANGED
|
@@ -157,6 +157,7 @@ export function readName(raw: string | undefined, kind: Generator): string {
|
|
|
157
157
|
if (kind === 'route') return readRoutePath(raw);
|
|
158
158
|
refusePath(raw, 'name', kind);
|
|
159
159
|
refuseNonAscii(raw, kind);
|
|
160
|
+
refuseUnsafeCharacter(raw, kind);
|
|
160
161
|
refuseBadIdentifier(raw, kind);
|
|
161
162
|
// A plural name is refused on the PLAN (`generate-plural.ts`): which kinds pluralise it into a
|
|
162
163
|
// table is a fact about the files they write, not a list kept here.
|
|
@@ -216,6 +217,26 @@ function refusePath(raw: string, flag: string, kind: Generator): void {
|
|
|
216
217
|
});
|
|
217
218
|
}
|
|
218
219
|
|
|
220
|
+
/**
|
|
221
|
+
* Letters, digits and the three separators every derived spelling folds away. The identifier check
|
|
222
|
+
* reads `camel(raw)`, which DROPS a quote, so `posts' + process.exit(7) + '` passed it while
|
|
223
|
+
* templates still spliced the raw name into a string literal: code in a module the app imports at
|
|
224
|
+
* boot. Refused here, before any template sees it; the fix is the kebab spelling.
|
|
225
|
+
*/
|
|
226
|
+
const NAME_CHARACTERS = /^[A-Za-z0-9 _-]+$/;
|
|
227
|
+
|
|
228
|
+
function refuseUnsafeCharacter(raw: string, kind: Generator): void {
|
|
229
|
+
if (NAME_CHARACTERS.test(raw)) return;
|
|
230
|
+
const safe = kebab(raw);
|
|
231
|
+
throw new BadFlagError({
|
|
232
|
+
flag: 'name',
|
|
233
|
+
command: `g ${kind}`,
|
|
234
|
+
// `JSON.stringify`, not `"${raw}"`: the rejected value is the one holding quotes and newlines.
|
|
235
|
+
reason: `${JSON.stringify(raw)} holds a character outside letters, digits, space, "_" and "-", and the name is written into generated source and file names`,
|
|
236
|
+
fix: safe === '' ? exampleFor(kind) : ['x g', kind, safe].join(' '),
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
219
240
|
/** Strict-mode reserved words: `export const delete = …` does not parse. */
|
|
220
241
|
const RESERVED = new Set(
|
|
221
242
|
(
|
|
@@ -287,8 +308,8 @@ export function readPermission(raw: string | undefined, kind: Generator): string
|
|
|
287
308
|
/** One runnable example per generator, so the `fix:` is a command and not a shape. */
|
|
288
309
|
const EXAMPLE_NAME: Readonly<Record<Generator, string>> = {
|
|
289
310
|
resource: 'invoice',
|
|
290
|
-
action: 'publish-post',
|
|
291
|
-
mutator: 'rename-post',
|
|
311
|
+
action: 'publish-post --feature post',
|
|
312
|
+
mutator: 'rename-post --feature post',
|
|
292
313
|
backfill: 'backfill-slugs',
|
|
293
314
|
'cron-job': 'nightly-report',
|
|
294
315
|
purge: 'purge-retained',
|
package/src/messages.ts
CHANGED
|
@@ -221,6 +221,14 @@ const CATALOG = {
|
|
|
221
221
|
// The two prose lines of `x new`'s report. The `run: cd … && git init …` line beneath the second
|
|
222
222
|
// one stays inline in `cmd-new.ts`: it is an instruction to paste verbatim, and a translated
|
|
223
223
|
// command is a broken one — the same split `Finding.fix` already makes.
|
|
224
|
+
// `x new`'s refusal of an existing target: what happened, never the usage line it printed
|
|
225
|
+
// before (D1). The finding beside it carries the free name to run instead.
|
|
226
|
+
'cli.new.exists': '{dir} already exists — nothing was written',
|
|
227
|
+
'cli.new.existsApp':
|
|
228
|
+
'{dir} already holds an app — x new never scaffolds over one, --force included',
|
|
229
|
+
// `--force` over a directory that already holds paths the scaffold writes: refused, not overwritten.
|
|
230
|
+
'cli.new.existsFiles':
|
|
231
|
+
'{dir} already holds {count} of the files x new writes — nothing was written, --force included',
|
|
224
232
|
'cli.new.wrote': ' {count} files in {dir}',
|
|
225
233
|
'cli.new.noRepository': ' no repository — {problem}',
|
|
226
234
|
// `git init` ran and the commit did not: `.git` exists, so "no repository" was false.
|
package/src/serve-boot.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import type { DrainConfig, LifecycleOptions, Role } from '@ultimat3/core';
|
|
11
11
|
import { configureLifecycle, logger, UltimateError } from '@ultimat3/core';
|
|
12
|
+
import { installBuildId } from '@ultimat3/core/adapter';
|
|
12
13
|
import { loadAppConfig } from './app-config-load';
|
|
13
14
|
import { armFailureCapture } from './failure-capture-boot';
|
|
14
15
|
import type { MetricsEndpoint } from './metrics-endpoint';
|
|
@@ -209,6 +210,9 @@ async function bootRoles(boot: {
|
|
|
209
210
|
acquired.push(armFailureCapture(appConfig, { store: runtime.failureStore }));
|
|
210
211
|
timeline.phase('app-checks');
|
|
211
212
|
const buildId = await buildIdFor(options, role);
|
|
213
|
+
// Core's one copy: `ctx.buildId` (a job's audit row), `/healthz` and `/readyz` read this, never
|
|
214
|
+
// `BUILD_ID` — an unstamped image's `''` would otherwise disagree with `x-ultimate-build`.
|
|
215
|
+
acquired.push(installBuildId(buildId));
|
|
212
216
|
timeline.phase('build-id');
|
|
213
217
|
// Before the first socket opens: everything above this line fails loudly into the container's
|
|
214
218
|
// own logs, everything below it is a served request, a claimed job or a routed frame.
|
package/src/templates/action.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
sliceFoundation,
|
|
20
20
|
sliceHasNoTenant,
|
|
21
21
|
sliceTakesScaffoldRow,
|
|
22
|
+
writesOrgRule,
|
|
22
23
|
} from './slice-foundation';
|
|
23
24
|
import { wrapImport } from './wrap';
|
|
24
25
|
|
|
@@ -195,8 +196,12 @@ export function actionFiles(rawName: string, target: ActionOptions): readonly Ge
|
|
|
195
196
|
: grantOf(target.slicePolicy, `can${feature.pascal}Write`);
|
|
196
197
|
const org =
|
|
197
198
|
!singleTenant || (target.slicePolicy !== undefined && policyReadsOrg(target.slicePolicy));
|
|
198
|
-
// The org rule the contract can rely on: the one this generator's own policy writes
|
|
199
|
-
|
|
199
|
+
// The org rule the contract can rely on: the one this generator's own policy writes — this run's,
|
|
200
|
+
// or an earlier `x g policy` / `x g resource` run's, read back unchanged.
|
|
201
|
+
const orgRule =
|
|
202
|
+
!singleTenant &&
|
|
203
|
+
(target.slicePolicy === undefined ||
|
|
204
|
+
writesOrgRule(target.slicePolicy, `can${feature.pascal}Write`));
|
|
200
205
|
// Before a file is planned: a generated action that does not compile is refused, never written.
|
|
201
206
|
assertPolicyExports(target, feature, isMutator);
|
|
202
207
|
const lookup =
|
|
@@ -116,7 +116,8 @@ ${SETUP_STEPS}
|
|
|
116
116
|
- run: bun run setup
|
|
117
117
|
# What the part's \`needs\` asks for and no more: \`--wait\` returns once every healthcheck
|
|
118
118
|
# passes, and only the URLs of what was started reach the suites — a URL to a server that is
|
|
119
|
-
# not running is a red suite, where an absent one is a suite that skips.
|
|
119
|
+
# not running is a red suite, where an absent one is a suite that skips. \`grep\`, never \`cat\`:
|
|
120
|
+
# GitHub refuses a $GITHUB_ENV holding the env file's \`#\` header ("Invalid format").
|
|
120
121
|
- if: matrix.needs == 'database'
|
|
121
122
|
run: |
|
|
122
123
|
docker compose -f ${TEST_COMPOSE_PATH} up -d --wait postgres
|
|
@@ -124,7 +125,7 @@ ${SETUP_STEPS}
|
|
|
124
125
|
- if: matrix.needs == 'services'
|
|
125
126
|
run: |
|
|
126
127
|
docker compose -f ${TEST_COMPOSE_PATH} up -d --wait
|
|
127
|
-
|
|
128
|
+
grep -E '^TEST_[A-Z0-9_]+=' ${TEST_ENV_PATH} >> "$GITHUB_ENV"
|
|
128
129
|
# ubuntu-latest ships Chrome, and the \`e2e\` step finds it. Required here, so a runner that
|
|
129
130
|
# has none (a \`CI_RUNNER\` label) is red with the command that locates one — never a skip.
|
|
130
131
|
- if: contains(matrix.only, 'e2e')
|