@ultimat3/testing 30.6.0 → 30.8.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 -3
- package/README.md +1 -1
- package/package.json +17 -17
- package/src/define-exercise.ts +53 -17
- package/src/drill-writes.ts +3 -1
- package/src/errors.ts +9 -90
- package/src/exercise-actor-user.ts +63 -0
- package/src/exercise-actor.ts +64 -11
- package/src/exercise-crash.ts +7 -3
- package/src/exercise-drift-hint.ts +28 -0
- package/src/exercise-input.ts +3 -0
- package/src/exercise-job-tenant.ts +10 -5
- package/src/exercise-judge.ts +78 -0
- package/src/exercise-observed.ts +93 -0
- package/src/exercise-override-input.ts +56 -6
- package/src/exercise-report.ts +43 -2
- package/src/exercise-request.ts +7 -24
- package/src/exercise-setup.ts +34 -17
- package/src/exercise-subjects.ts +20 -5
- package/src/exercise-sweeps.ts +57 -12
- package/src/exercise.ts +141 -109
- package/src/fixture-island.ts +1 -1
- package/src/index.ts +4 -0
- package/src/island-errors.ts +82 -0
- package/src/job-crash-points.ts +36 -0
- package/src/job-crash-proof.ts +23 -6
- package/src/job-sim-errors.ts +24 -0
- package/src/plan-conditions.ts +106 -0
- package/src/plan-oracle.ts +93 -57
- package/src/plan-probes.ts +94 -0
- package/src/plan-sort-key.ts +65 -0
- package/src/plan-sweep-fix.ts +99 -22
- package/src/plan-sweep-report.ts +48 -4
- package/src/scale-sweep-graph.ts +3 -0
- package/src/scale-sweep-run.ts +14 -7
- package/src/seed-graph-plan.ts +11 -0
- package/src/seed-graph-values.ts +20 -11
- package/src/seed-graph.ts +39 -3
- package/src/subject-proof.ts +12 -2
- package/src/tenant-proof-report.ts +84 -25
- package/src/tenant-proof.ts +39 -6
- package/src/seed-pattern-sample.ts +0 -216
package/src/exercise-sweeps.ts
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
// What runs after every primitive's own call: the scale sweep (each reached one again, at 2 and at 8
|
|
2
2
|
// rows a table) and the plan sweep (every statement the pass sent, planned on the migrated
|
|
3
|
-
// database). Both verdicts land on the record of the primitive that sent the statements
|
|
3
|
+
// database). Both verdicts land on the record of the primitive that sent the statements, and each
|
|
4
|
+
// sweep's time on the pass.
|
|
4
5
|
|
|
5
6
|
import type { Actor } from '@ultimat3/core';
|
|
6
7
|
import type { ExerciseOverrides } from './define-exercise';
|
|
8
|
+
import { overrideFor } from './define-exercise';
|
|
7
9
|
import type { ActorRows, RoleGrants } from './exercise-actor';
|
|
8
10
|
import { asSeededRow, chooseActor } from './exercise-actor';
|
|
9
11
|
import type { Sampler } from './exercise-input';
|
|
10
12
|
import { bindIds, drawInput, seededIds } from './exercise-input';
|
|
11
13
|
import { overrideInput } from './exercise-override-input';
|
|
12
|
-
import type { ExerciseRecord } from './exercise-report';
|
|
14
|
+
import type { ExercisePhaseMs, ExerciseRecord } from './exercise-report';
|
|
13
15
|
import type { Subject } from './exercise-subjects';
|
|
14
16
|
import { seatIn } from './exercise-subjects';
|
|
15
17
|
import { sweepPlans } from './plan-sweep';
|
|
16
|
-
import type { ScaleSweepOptions } from './scale-sweep-run';
|
|
18
|
+
import type { ScaleSubject, ScaleSweepOptions } from './scale-sweep-run';
|
|
17
19
|
import { scaleSweep } from './scale-sweep-run';
|
|
18
20
|
import type { SeedGraph } from './seed-graph-plan';
|
|
19
21
|
import type { SeedEntity } from './seed-graph-shape';
|
|
@@ -30,7 +32,12 @@ export const actorRowsOf = (options: CallOptions, graph: SeedGraph): ActorRows |
|
|
|
30
32
|
const name = options.overrides?.actorEntity;
|
|
31
33
|
const entity = options.entities.find((one) => one.$name === name);
|
|
32
34
|
if (entity === undefined) return undefined;
|
|
33
|
-
|
|
35
|
+
const column = options.overrides?.actorColumn;
|
|
36
|
+
return {
|
|
37
|
+
entity,
|
|
38
|
+
rows: graph.inserts.filter((row) => row.entity === entity.$name),
|
|
39
|
+
...(column === undefined ? {} : { column }),
|
|
40
|
+
};
|
|
34
41
|
};
|
|
35
42
|
|
|
36
43
|
/** The actor of `chosen`, seated as a row of the app's actor entity in `tenant` when it names one. */
|
|
@@ -38,7 +45,7 @@ export const seated = (actor: Actor | null, tenant: string, rows: ActorRows | un
|
|
|
38
45
|
rows === undefined ? actor : asSeededRow(actor, tenant, rows);
|
|
39
46
|
|
|
40
47
|
/** A primitive as a sized call needs it: its schema, its policy, and a job's seat. */
|
|
41
|
-
type Callable = Pick<Subject, 'name' | 'input' | 'policy' | 'permissions' | 'seat'>;
|
|
48
|
+
type Callable = Pick<Subject, 'kind' | 'name' | 'input' | 'policy' | 'permissions' | 'seat'>;
|
|
42
49
|
|
|
43
50
|
/** One call of `subject` in `tenant` of a sized graph: the control's actor and first input. */
|
|
44
51
|
export async function sizedCall(
|
|
@@ -48,7 +55,7 @@ export async function sizedCall(
|
|
|
48
55
|
at: { readonly graph: SeedGraph; readonly tenant: string; readonly self: boolean },
|
|
49
56
|
): Promise<{ readonly actor: Actor | null; readonly input: unknown } | undefined> {
|
|
50
57
|
const { graph, tenant, self } = at;
|
|
51
|
-
const override = options.overrides
|
|
58
|
+
const override = overrideFor(options.overrides, subject.kind, subject.name);
|
|
52
59
|
const chosen = chooseActor(subject.policy, subject.permissions, options.roles, tenant, override);
|
|
53
60
|
if (chosen.kind === 'refused') return undefined;
|
|
54
61
|
const rows = actorRowsOf(options, graph);
|
|
@@ -66,31 +73,69 @@ export async function sizedCall(
|
|
|
66
73
|
return { actor, input: seatIn(subject, given, tenant) };
|
|
67
74
|
}
|
|
68
75
|
|
|
76
|
+
/** The records with both sweeps' verdicts and scale time on them, and each sweep's whole time. */
|
|
77
|
+
export interface Swept {
|
|
78
|
+
readonly records: readonly ExerciseRecord[];
|
|
79
|
+
readonly ms: Pick<ExercisePhaseMs, 'scale' | 'plans'>;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** `subject`'s calls, each timed into `spent` under its name: the sweep calls it once per size. */
|
|
83
|
+
const timed = (subject: ScaleSubject, spent: Map<string, number>): ScaleSubject => ({
|
|
84
|
+
...subject,
|
|
85
|
+
call: async (...args) => {
|
|
86
|
+
const started = performance.now();
|
|
87
|
+
try {
|
|
88
|
+
return await subject.call(...args);
|
|
89
|
+
} finally {
|
|
90
|
+
spent.set(subject.name, (spent.get(subject.name) ?? 0) + performance.now() - started);
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
69
95
|
/**
|
|
70
96
|
* The scale sweep inside the room, the room closed, then the plan sweep — on the installed client
|
|
71
|
-
* only: with none, the pass ran on a driver that sends no SQL and there is no plan to read.
|
|
97
|
+
* only: with none, the pass ran on a driver that sends no SQL and there is no plan to read. Each
|
|
98
|
+
* proof is found under `label(record)`, the name its primitive ran under in the room.
|
|
72
99
|
*/
|
|
73
100
|
export async function attachSweeps(
|
|
74
101
|
records: readonly ExerciseRecord[],
|
|
102
|
+
label: (record: ExerciseRecord) => string,
|
|
75
103
|
options: ScaleSweepOptions,
|
|
76
|
-
): Promise<
|
|
104
|
+
): Promise<Swept> {
|
|
105
|
+
const spent = new Map<string, number>();
|
|
77
106
|
let scale: Awaited<ReturnType<typeof scaleSweep>>;
|
|
107
|
+
const scaleStarted = performance.now();
|
|
78
108
|
try {
|
|
79
|
-
scale = await scaleSweep(
|
|
109
|
+
scale = await scaleSweep({
|
|
110
|
+
...options,
|
|
111
|
+
subjects: options.subjects.map((subject) => timed(subject, spent)),
|
|
112
|
+
});
|
|
80
113
|
} finally {
|
|
81
114
|
await options.room[Symbol.asyncDispose]();
|
|
82
115
|
}
|
|
116
|
+
const plansStarted = performance.now();
|
|
83
117
|
const db = await import('@ultimat3/db');
|
|
84
118
|
const plans = db.dbClientInstalled()
|
|
85
119
|
? await sweepPlans(db.db(), options.room.sent(), options.entities)
|
|
86
120
|
: new Map();
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
121
|
+
const ms = {
|
|
122
|
+
scale: Math.round(plansStarted - scaleStarted),
|
|
123
|
+
plans: Math.round(performance.now() - plansStarted),
|
|
124
|
+
};
|
|
125
|
+
const swept = records.map((record) => {
|
|
126
|
+
const proof = plans.get(label(record));
|
|
127
|
+
const sized = scale.get(label(record));
|
|
128
|
+
const scaleMs = spent.get(label(record));
|
|
129
|
+
const proofMs = {
|
|
130
|
+
...record.proofMs,
|
|
131
|
+
...(scaleMs === undefined ? {} : { scale: Math.round(scaleMs) }),
|
|
132
|
+
};
|
|
90
133
|
return {
|
|
91
134
|
...record,
|
|
92
135
|
...(proof === undefined ? {} : { plans: proof }),
|
|
93
136
|
...(sized === undefined ? {} : { scale: sized }),
|
|
137
|
+
...(Object.keys(proofMs).length === 0 ? {} : { proofMs }),
|
|
94
138
|
};
|
|
95
139
|
});
|
|
140
|
+
return { records: swept, ms };
|
|
96
141
|
}
|
package/src/exercise.ts
CHANGED
|
@@ -5,36 +5,36 @@
|
|
|
5
5
|
// Committed, never rolled back. Around that call the tenant proof runs: the pair's other tenant
|
|
6
6
|
// calls with the first one's ids before and after it (`tenant-proof.ts`, plan 101, 40). A reached
|
|
7
7
|
// job is then killed at every step boundary (`exercise-crash.ts`).
|
|
8
|
+
//
|
|
9
|
+
// Each record is its primitive's alone: an entry's input that throws is that primitive unreached,
|
|
10
|
+
// what the input sent is never the call's, and a name two kinds share has an entry per kind.
|
|
8
11
|
|
|
9
12
|
import type { Actor, ExerciseAttempt, ExerciseVerdict } from '@ultimat3/core';
|
|
10
|
-
import {
|
|
13
|
+
import { runExercise } from '@ultimat3/core';
|
|
11
14
|
import { registeredJobs } from '@ultimat3/jobs';
|
|
12
15
|
import type { ExerciseOverride, ExerciseOverrides } from './define-exercise';
|
|
13
|
-
import { assertOverridesKnown, unknownDeclaration } from './define-exercise';
|
|
16
|
+
import { assertOverridesKnown, overrideFor, unknownDeclaration } from './define-exercise';
|
|
14
17
|
import type { RoleGrants } from './exercise-actor';
|
|
15
18
|
import { chooseActor } from './exercise-actor';
|
|
19
|
+
import { seatActorUsers } from './exercise-actor-user';
|
|
16
20
|
import { proveCrash } from './exercise-crash';
|
|
17
21
|
import { defectDetail } from './exercise-defect';
|
|
18
22
|
import type { IdLookup, Sampler } from './exercise-input';
|
|
19
|
-
import {
|
|
20
|
-
bindIds,
|
|
21
|
-
drawInput,
|
|
22
|
-
idStem,
|
|
23
|
-
loadSampler,
|
|
24
|
-
namesActorEntity,
|
|
25
|
-
seededIds,
|
|
26
|
-
} from './exercise-input';
|
|
23
|
+
import { bindIds, drawInput, loadSampler, namesActorEntity, seededIds } from './exercise-input';
|
|
27
24
|
import { ambientJobRows } from './exercise-job-run';
|
|
25
|
+
import { judged, labelFor } from './exercise-judge';
|
|
26
|
+
import { mergeObserved } from './exercise-observed';
|
|
28
27
|
import type { OverrideInput } from './exercise-override-input';
|
|
29
|
-
import { overrideInput } from './exercise-override-input';
|
|
28
|
+
import { inputThrew, overrideInput } from './exercise-override-input';
|
|
30
29
|
import type {
|
|
31
30
|
EffectPayload,
|
|
32
31
|
ExerciseEffect,
|
|
32
|
+
ExercisePhaseMs,
|
|
33
33
|
ExerciseRecord,
|
|
34
34
|
ExerciseRoom,
|
|
35
35
|
Observed,
|
|
36
36
|
} from './exercise-report';
|
|
37
|
-
import { openExerciseRoom
|
|
37
|
+
import { openExerciseRoom } from './exercise-report';
|
|
38
38
|
import { withExerciseSetup } from './exercise-setup';
|
|
39
39
|
import type { Subject } from './exercise-subjects';
|
|
40
40
|
import { fixedTenant, seatIn, subjectsOf } from './exercise-subjects';
|
|
@@ -61,21 +61,15 @@ export interface ExercisePassOptions {
|
|
|
61
61
|
/** One primitive by name; unknown is `X_DECLARATION_UNKNOWN`. */
|
|
62
62
|
readonly only?: string;
|
|
63
63
|
readonly roles: RoleGrants;
|
|
64
|
+
/** Told once, as the pass returns: how long each phase took, so a slow pass names its slow part. */
|
|
65
|
+
readonly onPhases?: (ms: ExercisePhaseMs) => void;
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
const isOff = (overrides: ExerciseOverrides | undefined,
|
|
67
|
-
const override = overrides
|
|
68
|
+
const isOff = (overrides: ExerciseOverrides | undefined, subject: Subject): boolean => {
|
|
69
|
+
const override = overrideFor(overrides, subject.kind, subject.name);
|
|
68
70
|
return override !== undefined && 'off' in override;
|
|
69
71
|
};
|
|
70
72
|
|
|
71
|
-
const codeOf = (error: unknown): string | undefined => {
|
|
72
|
-
if (isUltimateError(error)) return error.code;
|
|
73
|
-
return typeof error === 'string' ? /^(X_[A-Z0-9_]+)/.exec(error)?.[1] : undefined;
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const reasonOf = (error: unknown): string =>
|
|
77
|
-
isUltimateError(error) ? error.cause : typeof error === 'string' ? error : renderThrowable(error);
|
|
78
|
-
|
|
79
73
|
/**
|
|
80
74
|
* Jobs the primitive queued, its own job excepted. Never run: a job's children are left queued as
|
|
81
75
|
* an action's are (`exercise-job-run.ts`), so their statements are theirs, never this record's.
|
|
@@ -103,42 +97,11 @@ async function queuedPayloads(subject: Subject): Promise<readonly EffectPayload[
|
|
|
103
97
|
}));
|
|
104
98
|
}
|
|
105
99
|
|
|
106
|
-
interface Run {
|
|
107
|
-
readonly verdict: ExerciseVerdict;
|
|
108
|
-
readonly answered: boolean;
|
|
109
|
-
readonly lastError: unknown;
|
|
110
|
-
readonly lastInput: unknown;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function judged(subject: Subject, run: Run, observed: Observed) {
|
|
114
|
-
const idFields = (input: unknown): readonly string[] =>
|
|
115
|
-
typeof input === 'object' && input !== null
|
|
116
|
-
? Object.keys(input).filter((key) => idStem(key) !== undefined)
|
|
117
|
-
: [];
|
|
118
|
-
const unreached = (code: string | undefined, reason: string) => ({
|
|
119
|
-
outcome: 'unreached' as const,
|
|
120
|
-
...(code === undefined ? {} : { code }),
|
|
121
|
-
reason,
|
|
122
|
-
override: overrideLine(subject.name, idFields(run.lastInput)),
|
|
123
|
-
});
|
|
124
|
-
if (observed.refusedHosts.length > 0) {
|
|
125
|
-
// A call out is a refusal whatever the handler made of it: sealed, so never sent.
|
|
126
|
-
const hosts = [...new Set(observed.refusedHosts)].join(', ');
|
|
127
|
-
return unreached('X_TEST_NETWORK_SEALED', `called out to ${hosts}: sealed, never sent`);
|
|
128
|
-
}
|
|
129
|
-
if (run.verdict.kind === 'pass' && run.answered) return { outcome: 'reached' as const };
|
|
130
|
-
if (run.verdict.kind === 'drift') {
|
|
131
|
-
return unreached('X_CONTRACT_DRIFT', 'its input schema refused every generated value');
|
|
132
|
-
}
|
|
133
|
-
if (run.verdict.kind === 'defect') {
|
|
134
|
-
return unreached(codeOf(run.verdict.error) ?? 'X_CONTRACT_DEFECT', run.verdict.defect);
|
|
135
|
-
}
|
|
136
|
-
return unreached(codeOf(run.lastError), reasonOf(run.lastError));
|
|
137
|
-
}
|
|
138
|
-
|
|
139
100
|
/** Everything one primitive's calls share: who acts in each tenant, and how ids are bound. */
|
|
140
101
|
interface Prepared {
|
|
141
102
|
readonly subject: Subject;
|
|
103
|
+
/** The entry key and room label: `labelFor`'s. */
|
|
104
|
+
readonly key: string;
|
|
142
105
|
readonly options: ExercisePassOptions;
|
|
143
106
|
readonly tenant: string;
|
|
144
107
|
readonly actor: Actor | null;
|
|
@@ -148,13 +111,21 @@ interface Prepared {
|
|
|
148
111
|
readonly bindInput: OverrideInput | undefined;
|
|
149
112
|
}
|
|
150
113
|
|
|
151
|
-
/**
|
|
114
|
+
/** Thrown out of 39's loop by a bind that failed: the record is the entry's, never the loop's. */
|
|
115
|
+
class BindThrew {
|
|
116
|
+
constructor(readonly error: unknown) {}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A's positive control: 39's loop, as the pass has always run it. The room records each CALL
|
|
121
|
+
* alone: an override's input runs between calls, and what it sends is never this primitive's.
|
|
122
|
+
*/
|
|
152
123
|
async function control(
|
|
153
124
|
run: Prepared,
|
|
154
125
|
room: ExerciseRoom,
|
|
155
126
|
sampler: Sampler,
|
|
156
127
|
): Promise<{ readonly record: ExerciseRecord; readonly output: unknown; readonly input: unknown }> {
|
|
157
|
-
const { subject, actor, tenant, declaredRuns, lookups, bindInput } = run;
|
|
128
|
+
const { subject, key, actor, tenant, declaredRuns, lookups, bindInput } = run;
|
|
158
129
|
const { kind, name } = subject;
|
|
159
130
|
let binds = 0;
|
|
160
131
|
await using jobs = await testJobs();
|
|
@@ -162,43 +133,66 @@ async function control(
|
|
|
162
133
|
let lastError: unknown;
|
|
163
134
|
let lastInput: unknown;
|
|
164
135
|
let output: unknown;
|
|
165
|
-
|
|
136
|
+
const segments: Observed[] = [];
|
|
166
137
|
const started = performance.now();
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
try {
|
|
183
|
-
const answer = await subject.call(input, actor, tenant, jobs);
|
|
184
|
-
if ('failure' in answer) {
|
|
185
|
-
lastError = answer.failure;
|
|
186
|
-
return { ok: false, reached: true, error: answer.failure };
|
|
138
|
+
let verdict: ExerciseVerdict;
|
|
139
|
+
try {
|
|
140
|
+
verdict = await runExercise({
|
|
141
|
+
name,
|
|
142
|
+
runs: run.runs,
|
|
143
|
+
stoppedLabel: 'stopped before the call answered',
|
|
144
|
+
// The minimal draw on every run the pass adds; 39's seeded draw only on runs an override asks.
|
|
145
|
+
draw: (at, n) => drawInput(sampler, subject.input, at, declaredRuns === undefined ? 0 : n),
|
|
146
|
+
bind: async (drawn) => {
|
|
147
|
+
const bound = bindIds(drawn, lookups[binds++ === 0 ? 0 : 1]);
|
|
148
|
+
try {
|
|
149
|
+
const given = bindInput === undefined ? bound : await bindInput(bound, actor);
|
|
150
|
+
lastInput = seatIn(subject, given, tenant);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
throw new BindThrew(error);
|
|
187
153
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
154
|
+
return lastInput;
|
|
155
|
+
},
|
|
156
|
+
accepts: async (input) =>
|
|
157
|
+
(await subject.input['~standard'].validate(input)).issues === undefined,
|
|
158
|
+
attempt: async (input): Promise<ExerciseAttempt> => {
|
|
159
|
+
room.begin(key);
|
|
160
|
+
try {
|
|
161
|
+
const answer = await subject.call(input, actor, tenant, jobs);
|
|
162
|
+
if ('failure' in answer) {
|
|
163
|
+
lastError = answer.failure;
|
|
164
|
+
return { ok: false, reached: true, error: answer.failure };
|
|
165
|
+
}
|
|
166
|
+
answered = true;
|
|
167
|
+
output = answer.output;
|
|
168
|
+
return { ok: true, reached: true };
|
|
169
|
+
} catch (error) {
|
|
170
|
+
lastError = error;
|
|
171
|
+
return { ok: false, reached: false, error };
|
|
172
|
+
} finally {
|
|
173
|
+
segments.push(room.end());
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
statusOf: (await import('@ultimat3/http')).statusFor,
|
|
177
|
+
});
|
|
178
|
+
} catch (error) {
|
|
179
|
+
if (!(error instanceof BindThrew)) throw error;
|
|
180
|
+
const observed = mergeObserved(segments);
|
|
181
|
+
const record = {
|
|
182
|
+
kind,
|
|
183
|
+
name,
|
|
184
|
+
statements: observed.statements,
|
|
185
|
+
effects: observed.effects,
|
|
186
|
+
ms: Math.round(performance.now() - started),
|
|
187
|
+
...inputThrew(name, key, error.error),
|
|
188
|
+
};
|
|
189
|
+
return { record, output, input: lastInput };
|
|
190
|
+
}
|
|
198
191
|
const ms = Math.round(performance.now() - started);
|
|
199
|
-
const observed =
|
|
192
|
+
const observed = mergeObserved(segments);
|
|
200
193
|
const effects = [...observed.effects, ...(await enqueued(subject, jobs))];
|
|
201
|
-
const
|
|
194
|
+
const outcome = { verdict, answered, lastError, lastInput };
|
|
195
|
+
const verdictOf = judged(subject, key, outcome, observed, sampler);
|
|
202
196
|
// A 5xx's cause, statement and fields: the code alone sent the author to reproduce it by hand.
|
|
203
197
|
const defect =
|
|
204
198
|
verdict.kind === 'defect' && verdictOf.outcome === 'unreached'
|
|
@@ -219,13 +213,14 @@ async function control(
|
|
|
219
213
|
/** One B leg: B's actor, A's ids, a queue of its own. What it answered and every effect it had. */
|
|
220
214
|
async function attack(
|
|
221
215
|
subject: Subject,
|
|
216
|
+
key: string,
|
|
222
217
|
input: unknown,
|
|
223
218
|
actor: Actor | null,
|
|
224
219
|
tenant: string,
|
|
225
220
|
room: ExerciseRoom,
|
|
226
221
|
): Promise<LegAnswer> {
|
|
227
222
|
await using jobs = await testJobs();
|
|
228
|
-
room.begin(
|
|
223
|
+
room.begin(key);
|
|
229
224
|
let output: unknown;
|
|
230
225
|
// A job's org is re-seated in B's: B cannot enqueue a payload naming A (refused at the enqueue,
|
|
231
226
|
// which proves nothing), so the attack that matters is a job of B's carrying A's ids.
|
|
@@ -251,6 +246,7 @@ async function attack(
|
|
|
251
246
|
|
|
252
247
|
async function exerciseOne(
|
|
253
248
|
subject: Subject,
|
|
249
|
+
key: string,
|
|
254
250
|
options: ExercisePassOptions,
|
|
255
251
|
[tenant, other]: readonly [string, string],
|
|
256
252
|
graph: SeedGraph,
|
|
@@ -258,7 +254,7 @@ async function exerciseOne(
|
|
|
258
254
|
sampler: Sampler,
|
|
259
255
|
): Promise<ExerciseRecord> {
|
|
260
256
|
const { kind, name } = subject;
|
|
261
|
-
const override: ExerciseOverride | undefined = options.overrides
|
|
257
|
+
const override: ExerciseOverride | undefined = overrideFor(options.overrides, kind, name);
|
|
262
258
|
const none = { kind, name, statements: 0, effects: [], ms: 0 };
|
|
263
259
|
if (override !== undefined && 'off' in override) {
|
|
264
260
|
return { ...none, outcome: 'off', reason: override.off.trim() };
|
|
@@ -272,10 +268,13 @@ async function exerciseOne(
|
|
|
272
268
|
const intruder = withoutCrossTenant(
|
|
273
269
|
theirs.kind === 'actor' ? seated(theirs.actor, other, rows) : null,
|
|
274
270
|
);
|
|
271
|
+
// Both are users, as a request's actor always is: their `x_users` rows, before any call.
|
|
272
|
+
await seatActorUsers([actor, intruder]);
|
|
275
273
|
|
|
276
274
|
const scope = { tenant, actorId: actor?.id, subject: name, actorEntity: rows?.entity.$name };
|
|
277
275
|
const bindInput = overrideInput(name, override);
|
|
278
|
-
|
|
276
|
+
// `off` returned above: any other entry's `runs` is declared, with or without an `actor`.
|
|
277
|
+
const declaredRuns = override === undefined || 'off' in override ? undefined : override.runs;
|
|
279
278
|
// A field naming the actor entity is tried as the actor's own row, then as somebody else's:
|
|
280
279
|
// both readings are legitimate and only the handler knows which it meant. Same minimal draw.
|
|
281
280
|
const twoWay =
|
|
@@ -288,6 +287,7 @@ async function exerciseOne(
|
|
|
288
287
|
] as const;
|
|
289
288
|
const run: Prepared = {
|
|
290
289
|
subject,
|
|
290
|
+
key,
|
|
291
291
|
options,
|
|
292
292
|
tenant,
|
|
293
293
|
actor,
|
|
@@ -298,7 +298,13 @@ async function exerciseOne(
|
|
|
298
298
|
};
|
|
299
299
|
// A's own first input, A's ids in it: B sends exactly what A legitimately would.
|
|
300
300
|
const drawn = bindIds(drawInput(sampler, subject.input, 0, 0), lookups[0]);
|
|
301
|
-
|
|
301
|
+
let given: unknown;
|
|
302
|
+
try {
|
|
303
|
+
given = bindInput === undefined ? drawn : await bindInput(drawn, actor);
|
|
304
|
+
} catch (error) {
|
|
305
|
+
const threw = inputThrew(name, key, error);
|
|
306
|
+
return { ...none, ...threw, tenant: { verdict: 'unproven', reason: threw.reason } };
|
|
307
|
+
}
|
|
302
308
|
const seat = subject.seat?.(given, tenant);
|
|
303
309
|
if (seat?.kind === 'fixed') {
|
|
304
310
|
const fixed = fixedTenant(name, seat.declared);
|
|
@@ -311,13 +317,15 @@ async function exerciseOne(
|
|
|
311
317
|
}
|
|
312
318
|
const input = seat === undefined ? given : seat.input;
|
|
313
319
|
let reachedWith: unknown;
|
|
320
|
+
const tenantStarted = performance.now();
|
|
314
321
|
const record = await proveTenant({
|
|
315
322
|
taint: tenantTaint(graph, tenant),
|
|
316
323
|
input,
|
|
317
324
|
public: publicReason(subject.policy),
|
|
318
325
|
read: kind === 'query',
|
|
319
326
|
sweep: kind === 'job',
|
|
320
|
-
|
|
327
|
+
tenantless: seat?.kind === 'none',
|
|
328
|
+
attack: () => attack(subject, key, input, intruder, other, room),
|
|
321
329
|
control: async () => {
|
|
322
330
|
const done = await control(run, room, sampler);
|
|
323
331
|
reachedWith = done.input;
|
|
@@ -325,18 +333,29 @@ async function exerciseOne(
|
|
|
325
333
|
},
|
|
326
334
|
snapshot: (seeded) => options.writer.snapshot(seeded),
|
|
327
335
|
});
|
|
336
|
+
// The control's own call is `ms`: the tenant proof's time is everything around it.
|
|
337
|
+
const tenantMs = Math.max(0, Math.round(performance.now() - tenantStarted) - record.ms);
|
|
328
338
|
// After the tenant proof, outside the room's begin/end: the crash runs' effects are their own.
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
339
|
+
if (subject.handle === undefined || record.outcome !== 'reached') {
|
|
340
|
+
return { ...record, proofMs: { tenant: tenantMs } };
|
|
341
|
+
}
|
|
342
|
+
const crashStarted = performance.now();
|
|
343
|
+
const crash = await proveCrash(subject.handle, reachedWith, actor);
|
|
344
|
+
const proofMs = { tenant: tenantMs, crash: Math.round(performance.now() - crashStarted) };
|
|
345
|
+
return { ...record, crash, proofMs };
|
|
332
346
|
}
|
|
333
347
|
|
|
334
348
|
export async function runExercisePass(
|
|
335
349
|
options: ExercisePassOptions,
|
|
336
350
|
): Promise<readonly ExerciseRecord[]> {
|
|
337
|
-
|
|
351
|
+
// Each call's request is its entry's, read by kind: an action's cookies are never its job twin's.
|
|
352
|
+
const subjects = await subjectsOf((kind, name) => {
|
|
353
|
+
const entry = overrideFor(options.overrides, kind, name);
|
|
354
|
+
return entry === undefined || 'off' in entry ? undefined : entry.request;
|
|
355
|
+
});
|
|
338
356
|
const known = new Set(subjects.map((subject) => subject.name));
|
|
339
|
-
assertOverridesKnown(options.overrides,
|
|
357
|
+
assertOverridesKnown(options.overrides, subjects);
|
|
358
|
+
const label = labelFor(subjects);
|
|
340
359
|
if (options.only !== undefined && !known.has(options.only)) {
|
|
341
360
|
throw unknownDeclaration([options.only], known, 'x exercise');
|
|
342
361
|
}
|
|
@@ -346,9 +365,11 @@ export async function runExercisePass(
|
|
|
346
365
|
const passSeed = options.seed ?? (crypto.getRandomValues(new Uint32Array(1))[0] as number);
|
|
347
366
|
// The app's setup runs inside the seal, before the first row: its routes answer every call.
|
|
348
367
|
const room = await withExerciseSetup(await openExerciseRoom(), options.overrides?.setup);
|
|
349
|
-
const live = chosen.filter((subject) => !isOff(options.overrides, subject
|
|
368
|
+
const live = chosen.filter((subject) => !isOff(options.overrides, subject));
|
|
350
369
|
const records: ExerciseRecord[] = [];
|
|
351
370
|
let graph: SeedGraph;
|
|
371
|
+
const seedStarted = performance.now();
|
|
372
|
+
let primitivesStarted = seedStarted;
|
|
352
373
|
try {
|
|
353
374
|
// Seeded before the first primitive runs: a failure here is the pass's, never one primitive's.
|
|
354
375
|
graph = await seedPass(options.entities, options.writer, {
|
|
@@ -358,21 +379,28 @@ export async function runExercisePass(
|
|
|
358
379
|
? {}
|
|
359
380
|
: { factories: options.overrides.factories }),
|
|
360
381
|
});
|
|
382
|
+
primitivesStarted = performance.now();
|
|
361
383
|
// In order, one at a time: the seams the room installs are the process's, not the primitive's.
|
|
362
384
|
for (const subject of chosen) {
|
|
363
385
|
const index = live.indexOf(subject);
|
|
364
386
|
const at = Math.max(0, index);
|
|
365
387
|
const view = pairGraph(graph, at);
|
|
366
|
-
|
|
388
|
+
const pair = tenantPair(graph, at);
|
|
389
|
+
records.push(await exerciseOne(subject, label(subject), options, pair, view, room, sampler));
|
|
367
390
|
}
|
|
368
391
|
} catch (error) {
|
|
369
392
|
await room[Symbol.asyncDispose]();
|
|
370
393
|
throw error;
|
|
371
394
|
}
|
|
395
|
+
const seed = Math.round(primitivesStarted - seedStarted);
|
|
396
|
+
const primitives = Math.round(performance.now() - primitivesStarted);
|
|
372
397
|
// The sweeps: every reached primitive again at two sizes, then every statement planned.
|
|
373
|
-
const reached = new Set(records.filter((r) => r.outcome === 'reached').map(
|
|
374
|
-
|
|
375
|
-
|
|
398
|
+
const reached = new Set(records.filter((r) => r.outcome === 'reached').map(label));
|
|
399
|
+
const swept = await attachSweeps(records, label, {
|
|
400
|
+
// Named by label: the sweeps key their proofs by name, and a shared name is two primitives.
|
|
401
|
+
subjects: chosen
|
|
402
|
+
.filter((subject) => reached.has(label(subject)))
|
|
403
|
+
.map((subject) => ({ ...subject, name: label(subject) })),
|
|
376
404
|
entities: options.entities,
|
|
377
405
|
// The sized graphs close their cycles as the pass's did: a refused deferred key stays null.
|
|
378
406
|
writer: deferredMayStayNull(options.writer),
|
|
@@ -381,10 +409,14 @@ export async function runExercisePass(
|
|
|
381
409
|
room,
|
|
382
410
|
factories: options.overrides?.factories,
|
|
383
411
|
setup: async (subject, sized, tenant, self) => {
|
|
384
|
-
const full = chosen.find((one) => one
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
412
|
+
const full = chosen.find((one) => label(one) === subject.name);
|
|
413
|
+
if (full === undefined) return undefined;
|
|
414
|
+
const call = await sizedCall(full, options, sampler, { graph: sized, tenant, self });
|
|
415
|
+
// Before the sweep's room opens: the sized tenant's actor is a user too.
|
|
416
|
+
if (call !== undefined) await seatActorUsers([call.actor]);
|
|
417
|
+
return call;
|
|
388
418
|
},
|
|
389
419
|
});
|
|
420
|
+
options.onPhases?.({ seed, primitives, ...swept.ms });
|
|
421
|
+
return swept.records;
|
|
390
422
|
}
|
package/src/fixture-island.ts
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
// edge. A structural seam keeps the direction honest and survives the bundler changing underneath.
|
|
5
5
|
|
|
6
6
|
import { basename, join } from 'node:path';
|
|
7
|
-
import { islandMountMissing, islandNotBuilt } from './errors';
|
|
8
7
|
import { onFileBoundary } from './file-boundary';
|
|
9
8
|
import { createIslandDocument, FakeElement, handlerFor, parseHtml } from './island-dom';
|
|
9
|
+
import { islandMountMissing, islandNotBuilt } from './island-errors';
|
|
10
10
|
import { installGlobals } from './island-globals';
|
|
11
11
|
import type { ResizeInput } from './island-observers';
|
|
12
12
|
import { deliverResize } from './island-observers';
|
package/src/index.ts
CHANGED
|
@@ -207,7 +207,9 @@ export type {
|
|
|
207
207
|
EffectPayload,
|
|
208
208
|
ExerciseEffect,
|
|
209
209
|
ExerciseOutcome,
|
|
210
|
+
ExercisePhaseMs,
|
|
210
211
|
ExerciseRecord,
|
|
212
|
+
ProofMs,
|
|
211
213
|
TenantFinding,
|
|
212
214
|
TenantLeg,
|
|
213
215
|
TenantProof,
|
|
@@ -366,6 +368,7 @@ export {
|
|
|
366
368
|
normalizeIslandName,
|
|
367
369
|
} from './island-states-resolve';
|
|
368
370
|
export { ISOLATED_ENV, releasePluginsAfterIsolatedFile } from './isolated-plugins';
|
|
371
|
+
export { CRASH_POINT_BOUND } from './job-crash-points';
|
|
369
372
|
export type {
|
|
370
373
|
CrashBoundary,
|
|
371
374
|
CrashDivergence,
|
|
@@ -379,6 +382,7 @@ export type { SimEffect } from './job-sim-effects';
|
|
|
379
382
|
export {
|
|
380
383
|
crashEffectPlace,
|
|
381
384
|
JobCrashDivergedError,
|
|
385
|
+
JobCrashUnboundedError,
|
|
382
386
|
JobSimInvariantError,
|
|
383
387
|
JobSimNondeterministicError,
|
|
384
388
|
} from './job-sim-errors';
|