@sublang/slc 0.16.3 → 0.16.4
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/dist/entry-module.js +2 -2
- package/dist/entry-module.js.map +1 -1
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +7 -3
- package/dist/runner.js.map +1 -1
- package/dist/verify-coverage.d.ts.map +1 -1
- package/dist/verify-coverage.js +580 -108
- package/dist/verify-coverage.js.map +1 -1
- package/dist/verify.d.ts +1 -0
- package/dist/verify.d.ts.map +1 -1
- package/dist/verify.js +5 -2
- package/dist/verify.js.map +1 -1
- package/package.json +1 -1
package/dist/verify-coverage.js
CHANGED
|
@@ -24,7 +24,7 @@ import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
|
24
24
|
import { join } from 'node:path';
|
|
25
25
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
26
26
|
import { createActor, fromPromise } from 'xstate';
|
|
27
|
-
import { AWAIT_BOSS_REPLY_STATE, BOSS_REPLY_EVENT, INTERRUPT_EVENT, NEEDS_BOSS_REPLY, VERIFY_MODULE, controllerDecisionNearMiss, enumerateCaptainStates, enumerateScriptStates, initialStateTarget, isControllerDecisionResult, isControllerMachine, loadFsmModule, normalizeArms, resolveArtifactSchemaForVerification, usesKeyedBossQuestionContext, } from './verify.js';
|
|
27
|
+
import { AWAIT_BOSS_REPLY_STATE, BOSS_REPLY_EVENT, INTERRUPT_EVENT, NEEDS_BOSS_REPLY, VERIFY_MODULE, controllerDecisionNearMiss, enumerateCaptainStates, enumeratePlaybookStates, enumerateScriptStates, initialStateTarget, isControllerDecisionResult, isControllerMachine, loadFsmModule, normalizeArms, resolveArtifactSchemaForVerification, usesKeyedBossQuestionContext, } from './verify.js';
|
|
28
28
|
/** The `gears2fsm`-mandated captain actor name a machine declares. */
|
|
29
29
|
export const CAPTAIN_ACTOR = 'captain';
|
|
30
30
|
// Each check owns its resources, including concurrent checks and async actor
|
|
@@ -233,13 +233,41 @@ const COVERAGE_MACHINE_INPUT = {
|
|
|
233
233
|
bossIntent: 'Exercise the compiled playbook transitions.',
|
|
234
234
|
enabledPlaybooks: COVERAGE_ENABLED_PLAYBOOKS,
|
|
235
235
|
};
|
|
236
|
+
/** Literal bindings, not arbitrary guard literals, declare extra child ids. */
|
|
237
|
+
function coverageMachineInput(machine) {
|
|
238
|
+
const cached = coverageRuns.getStore()?.machineInputs.get(machine.config);
|
|
239
|
+
if (cached !== undefined)
|
|
240
|
+
return cached;
|
|
241
|
+
const enabledPlaybooks = [
|
|
242
|
+
...COVERAGE_ENABLED_PLAYBOOKS,
|
|
243
|
+
];
|
|
244
|
+
const ids = new Set(enabledPlaybooks.map((entry) => entry.id));
|
|
245
|
+
for (const binding of enumeratePlaybookStates(machine.config)) {
|
|
246
|
+
if (binding.playbookIdContext !== undefined ||
|
|
247
|
+
binding.textContext !== undefined ||
|
|
248
|
+
(binding.bindingFindings?.length ?? 0) > 0 ||
|
|
249
|
+
binding.playbookId === '' ||
|
|
250
|
+
ids.has(binding.playbookId)) {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
ids.add(binding.playbookId);
|
|
254
|
+
enabledPlaybooks.push({
|
|
255
|
+
id: binding.playbookId,
|
|
256
|
+
command: `/${binding.playbookId}`,
|
|
257
|
+
intent: 'Exercise a declared literal child transition.',
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
const input = { ...COVERAGE_MACHINE_INPUT, enabledPlaybooks };
|
|
261
|
+
coverageRuns.getStore()?.machineInputs.set(machine.config, input);
|
|
262
|
+
return input;
|
|
263
|
+
}
|
|
236
264
|
/**
|
|
237
265
|
* A valid Captain context for direct guard evaluation. Dynamic call fields use
|
|
238
266
|
* the same id as the catalog entry, preserving exact catalog-membership guards.
|
|
239
267
|
*/
|
|
240
|
-
function coverageGuardContext(dynamic) {
|
|
268
|
+
function coverageGuardContext(dynamic, input = COVERAGE_MACHINE_INPUT) {
|
|
241
269
|
return {
|
|
242
|
-
...
|
|
270
|
+
...input,
|
|
243
271
|
remainingPlan: [],
|
|
244
272
|
completedCallResults: [
|
|
245
273
|
{
|
|
@@ -265,7 +293,7 @@ function initializedMachineContext(machine) {
|
|
|
265
293
|
let actor;
|
|
266
294
|
let failed = false;
|
|
267
295
|
try {
|
|
268
|
-
actor = trackCoverageActor(createActor(machine, { input:
|
|
296
|
+
actor = trackCoverageActor(createActor(machine, { input: coverageMachineInput(machine) }));
|
|
269
297
|
return actor.getSnapshot().context;
|
|
270
298
|
}
|
|
271
299
|
catch {
|
|
@@ -281,7 +309,7 @@ function initializedMachineContext(machine) {
|
|
|
281
309
|
function initializedCoverageContext(machine, dynamic) {
|
|
282
310
|
return {
|
|
283
311
|
...initializedMachineContext(machine),
|
|
284
|
-
...coverageGuardContext(dynamic),
|
|
312
|
+
...coverageGuardContext(dynamic, coverageMachineInput(machine)),
|
|
285
313
|
};
|
|
286
314
|
}
|
|
287
315
|
/** The `Output shall include` clause a result description declares. */
|
|
@@ -607,7 +635,7 @@ function resolvedStateNode(machine, ref) {
|
|
|
607
635
|
return node;
|
|
608
636
|
}
|
|
609
637
|
function persistedSnapshotWithContext(provided, context) {
|
|
610
|
-
const seed = trackCoverageActor(createActor(provided, { input:
|
|
638
|
+
const seed = trackCoverageActor(createActor(provided, { input: coverageMachineInput(provided) }));
|
|
611
639
|
let completed = false;
|
|
612
640
|
try {
|
|
613
641
|
const snapshot = {
|
|
@@ -661,7 +689,7 @@ function makeActor(machine, script, playbookScript = () => null, restoredContext
|
|
|
661
689
|
? undefined
|
|
662
690
|
: persistedSnapshotWithContext(provided, restoredContext);
|
|
663
691
|
const actor = trackCoverageActor(createActor(provided, {
|
|
664
|
-
input:
|
|
692
|
+
input: coverageMachineInput(machine),
|
|
665
693
|
...(restoredSnapshot === undefined
|
|
666
694
|
? {}
|
|
667
695
|
: { snapshot: restoredSnapshot }),
|
|
@@ -992,8 +1020,13 @@ function interruptDriveForRef(machine, refs, target, targetId, extraValues = [],
|
|
|
992
1020
|
satisfiable: true,
|
|
993
1021
|
};
|
|
994
1022
|
}
|
|
995
|
-
/**
|
|
1023
|
+
/** The existing first satisfying event remains unchanged for direct callers. */
|
|
996
1024
|
function entryDriveForRef(machine, refs, target, extraValues = [], initialContext = initializedCoverageContext(machine)) {
|
|
1025
|
+
const first = entryDrivesForRef(machine, refs, target, extraValues, initialContext).next();
|
|
1026
|
+
return first.done ? undefined : first.value;
|
|
1027
|
+
}
|
|
1028
|
+
/** Lazy one-field public events, never new context or an unguarded entry. */
|
|
1029
|
+
function* entryDrivesForRef(machine, refs, target, extraValues = [], initialContext = initializedCoverageContext(machine)) {
|
|
997
1030
|
const initialPath = initialActiveRefs(machine.config, refs);
|
|
998
1031
|
const surfaces = [
|
|
999
1032
|
...initialPath
|
|
@@ -1017,7 +1050,7 @@ function entryDriveForRef(machine, refs, target, extraValues = [], initialContex
|
|
|
1017
1050
|
if (guard === undefined)
|
|
1018
1051
|
continue;
|
|
1019
1052
|
const base = { type: eventType };
|
|
1020
|
-
const
|
|
1053
|
+
const values = [
|
|
1021
1054
|
...guard.probeValues,
|
|
1022
1055
|
...refs.flatMap((ref) => [
|
|
1023
1056
|
ref.key,
|
|
@@ -1025,21 +1058,68 @@ function entryDriveForRef(machine, refs, target, extraValues = [], initialContex
|
|
|
1025
1058
|
...(ref.configId === undefined ? [] : [ref.configId]),
|
|
1026
1059
|
]),
|
|
1027
1060
|
...extraValues,
|
|
1028
|
-
]
|
|
1061
|
+
];
|
|
1062
|
+
const probeBudget = { probes: 0 };
|
|
1063
|
+
const assignment = probeGuardAssignment(guard.run, {}, [{ tag: 'e:', base }], values, {
|
|
1029
1064
|
initialContext,
|
|
1030
1065
|
varyExistingContext: true,
|
|
1066
|
+
probeBudget,
|
|
1031
1067
|
});
|
|
1032
1068
|
if (assignment !== undefined) {
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1069
|
+
const event = assignedPayload(base, assignment, 'e:');
|
|
1070
|
+
yield { event, context: assignment.context, satisfiable: true };
|
|
1071
|
+
const fields = Object.keys(assignment.payloads['e:'] ?? {})
|
|
1072
|
+
.filter((field) => field !== 'type')
|
|
1073
|
+
.map((field) => ({ field, cursor: 0 }));
|
|
1074
|
+
const candidates = [
|
|
1075
|
+
...new Set([
|
|
1076
|
+
...minedLiterals(guard.run),
|
|
1077
|
+
...values,
|
|
1078
|
+
...GENERIC_VALUES,
|
|
1079
|
+
]),
|
|
1080
|
+
];
|
|
1081
|
+
// Scan each field to its next admitted value before returning to a
|
|
1082
|
+
// permissive sibling field. Only accepted variants consume replays.
|
|
1083
|
+
while (fields.some((field) => field.cursor < candidates.length)) {
|
|
1084
|
+
for (const field of fields) {
|
|
1085
|
+
while (field.cursor < candidates.length) {
|
|
1086
|
+
coverageCheckpoint();
|
|
1087
|
+
const value = candidates[field.cursor++];
|
|
1088
|
+
if (Object.is(value, event[field.field]))
|
|
1089
|
+
continue;
|
|
1090
|
+
if (++probeBudget.probes > MAX_PROBES)
|
|
1091
|
+
return;
|
|
1092
|
+
const nextEvent = { ...event, [field.field]: value };
|
|
1093
|
+
let accepted = false;
|
|
1094
|
+
try {
|
|
1095
|
+
accepted = Boolean(guard.run({
|
|
1096
|
+
context: assignment.context,
|
|
1097
|
+
event: nextEvent,
|
|
1098
|
+
}));
|
|
1099
|
+
}
|
|
1100
|
+
catch {
|
|
1101
|
+
coverageCheckpoint();
|
|
1102
|
+
}
|
|
1103
|
+
finally {
|
|
1104
|
+
coverageCheckpoint();
|
|
1105
|
+
}
|
|
1106
|
+
if (!accepted)
|
|
1107
|
+
continue;
|
|
1108
|
+
yield {
|
|
1109
|
+
event: nextEvent,
|
|
1110
|
+
context: assignment.context,
|
|
1111
|
+
satisfiable: true,
|
|
1112
|
+
};
|
|
1113
|
+
break;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
return;
|
|
1038
1118
|
}
|
|
1039
1119
|
}
|
|
1040
1120
|
}
|
|
1041
1121
|
}
|
|
1042
|
-
return
|
|
1122
|
+
return;
|
|
1043
1123
|
}
|
|
1044
1124
|
/** The arm XState selects for one concrete invocation output and context. */
|
|
1045
1125
|
function directlySelectedArm(machine, captain, output, context = coverageGuardContext()) {
|
|
@@ -1070,6 +1150,7 @@ function directTargetRef(machine, refs, captain, output, context = coverageGuard
|
|
|
1070
1150
|
const GENERIC_VALUES = [
|
|
1071
1151
|
'coverage',
|
|
1072
1152
|
true,
|
|
1153
|
+
false,
|
|
1073
1154
|
1,
|
|
1074
1155
|
['coverage'],
|
|
1075
1156
|
COVERAGE_ENABLED_PLAYBOOKS,
|
|
@@ -1154,7 +1235,74 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1154
1235
|
const values = [
|
|
1155
1236
|
...new Set([...minedLiterals(guard), ...extraValues, ...GENERIC_VALUES]),
|
|
1156
1237
|
];
|
|
1157
|
-
|
|
1238
|
+
const reachedContext = (options.discoverPayloadShape === true ||
|
|
1239
|
+
options.declaredResultFields !== undefined) &&
|
|
1240
|
+
options.assignContext === false
|
|
1241
|
+
? Object.getOwnPropertyDescriptors(options.initialContext ?? {})
|
|
1242
|
+
: undefined;
|
|
1243
|
+
let reachedValues = 0;
|
|
1244
|
+
const declaredValues = new Map();
|
|
1245
|
+
const declaredDistinct = new Set();
|
|
1246
|
+
const noteContextRead = (field, declaredField) => {
|
|
1247
|
+
if (reachedContext === undefined || !Object.hasOwn(reachedContext, field))
|
|
1248
|
+
return;
|
|
1249
|
+
const descriptor = reachedContext[field];
|
|
1250
|
+
if (!('value' in descriptor))
|
|
1251
|
+
return;
|
|
1252
|
+
const value = descriptor.value;
|
|
1253
|
+
if (options.declaredResultFields !== undefined) {
|
|
1254
|
+
// A declared placeholder already has a string shape. Associate only a
|
|
1255
|
+
// following context read with that output field, rather than varying
|
|
1256
|
+
// unrelated fields or spending the budget on initial preconditions.
|
|
1257
|
+
if (declaredField === undefined ||
|
|
1258
|
+
typeof value !== 'string' ||
|
|
1259
|
+
value === '')
|
|
1260
|
+
return;
|
|
1261
|
+
if (!declaredDistinct.has(value)) {
|
|
1262
|
+
if (reachedValues >= 4)
|
|
1263
|
+
return;
|
|
1264
|
+
reachedValues++;
|
|
1265
|
+
declaredDistinct.add(value);
|
|
1266
|
+
}
|
|
1267
|
+
const candidates = declaredValues.get(declaredField) ?? [];
|
|
1268
|
+
if (!candidates.includes(value)) {
|
|
1269
|
+
candidates.push(value);
|
|
1270
|
+
declaredValues.set(declaredField, candidates);
|
|
1271
|
+
}
|
|
1272
|
+
return;
|
|
1273
|
+
}
|
|
1274
|
+
if (reachedValues >= 4 ||
|
|
1275
|
+
!(value === null ||
|
|
1276
|
+
typeof value === 'string' ||
|
|
1277
|
+
typeof value === 'boolean' ||
|
|
1278
|
+
(typeof value === 'number' && Number.isFinite(value))) ||
|
|
1279
|
+
values.some((candidate) => Object.is(candidate, value)))
|
|
1280
|
+
return;
|
|
1281
|
+
reachedValues++;
|
|
1282
|
+
values.push(value);
|
|
1283
|
+
};
|
|
1284
|
+
function* candidateValues(key, hasBaseline, baseline) {
|
|
1285
|
+
if (hasBaseline)
|
|
1286
|
+
yield baseline;
|
|
1287
|
+
const guided = key.startsWith('o:')
|
|
1288
|
+
? declaredValues.get(key.slice(2))
|
|
1289
|
+
: undefined;
|
|
1290
|
+
if (guided !== undefined) {
|
|
1291
|
+
for (let index = 0; index < guided.length; index++) {
|
|
1292
|
+
if (guided[index] !== baseline)
|
|
1293
|
+
yield guided[index];
|
|
1294
|
+
}
|
|
1295
|
+
return;
|
|
1296
|
+
}
|
|
1297
|
+
// A failed candidate can reveal a fixed-context value needed by this same
|
|
1298
|
+
// field. Include new bounded observations before completing its iteration.
|
|
1299
|
+
for (let index = 0; index < values.length; index++) {
|
|
1300
|
+
if (!hasBaseline || values[index] !== baseline)
|
|
1301
|
+
yield values[index];
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
const probeBudget = options.probeBudget ?? { probes: 0 };
|
|
1305
|
+
const discovered = new Map();
|
|
1158
1306
|
const eventFor = (assignment) => {
|
|
1159
1307
|
let event = { ...fixedEvent };
|
|
1160
1308
|
for (const payload of payloads) {
|
|
@@ -1167,11 +1315,11 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1167
1315
|
}
|
|
1168
1316
|
return event;
|
|
1169
1317
|
};
|
|
1170
|
-
const passes = (assignment) => {
|
|
1318
|
+
const passes = (assignment, predicate = guard) => {
|
|
1171
1319
|
coverageCheckpoint();
|
|
1172
|
-
probes++;
|
|
1320
|
+
probeBudget.probes++;
|
|
1173
1321
|
try {
|
|
1174
|
-
return Boolean(
|
|
1322
|
+
return Boolean(predicate({ context: assignment.context, event: eventFor(assignment) }));
|
|
1175
1323
|
}
|
|
1176
1324
|
catch {
|
|
1177
1325
|
coverageCheckpoint();
|
|
@@ -1182,58 +1330,202 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1182
1330
|
}
|
|
1183
1331
|
};
|
|
1184
1332
|
// Records the unassigned fields the guard reads under the given assignment.
|
|
1185
|
-
const readsUnder = (assignment) => {
|
|
1333
|
+
const readsUnder = (assignment, discoverShape = false) => {
|
|
1186
1334
|
coverageCheckpoint();
|
|
1187
1335
|
const reads = new Set();
|
|
1188
|
-
const
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1336
|
+
const enumerated = new Set();
|
|
1337
|
+
let declaredField;
|
|
1338
|
+
const contextRead = (field) => {
|
|
1339
|
+
noteContextRead(field, declaredField);
|
|
1340
|
+
if (declaredField !== undefined && declaredValues.has(declaredField))
|
|
1341
|
+
reads.add(`o:${declaredField}`);
|
|
1342
|
+
};
|
|
1343
|
+
// An earlier arm's fields cannot satisfy a false selected guard. Once that
|
|
1344
|
+
// guard accepts, ordered reads can discover how to exclude the earlier arm.
|
|
1345
|
+
// This concrete guidance check shares the existing acceptance-probe budget.
|
|
1346
|
+
const selectedPending = !discoverShape &&
|
|
1347
|
+
options.discoverPayloadShape === true &&
|
|
1348
|
+
options.payloadShapeGuard !== undefined &&
|
|
1349
|
+
!passes(assignment, options.payloadShapeGuard);
|
|
1350
|
+
if (probeBudget.probes > MAX_PROBES)
|
|
1351
|
+
return [];
|
|
1352
|
+
let shapeTag;
|
|
1353
|
+
let shapeWidth = 0;
|
|
1354
|
+
const noteShapeField = (tag, field) => {
|
|
1355
|
+
if (!discoverShape || tag !== shapeTag)
|
|
1356
|
+
return;
|
|
1357
|
+
const fields = discovered.get(tag) ?? new Set();
|
|
1358
|
+
fields.add(field);
|
|
1359
|
+
discovered.set(tag, fields);
|
|
1360
|
+
};
|
|
1361
|
+
const recording = (base, assigned, tag, varyExisting = false) => {
|
|
1362
|
+
const target = overlay(base, assigned);
|
|
1363
|
+
if (tag === shapeTag) {
|
|
1364
|
+
// These placeholders only expose reads behind a key-count predicate.
|
|
1365
|
+
// They never enter an assignment or the real guard/replay evaluation.
|
|
1366
|
+
let index = 0;
|
|
1367
|
+
while (Object.keys(target).length < shapeWidth) {
|
|
1368
|
+
const key = `__slc_probe_${index++}`;
|
|
1369
|
+
if (!Object.hasOwn(target, key)) {
|
|
1370
|
+
Object.defineProperty(target, key, {
|
|
1371
|
+
value: null,
|
|
1372
|
+
enumerable: true,
|
|
1373
|
+
configurable: true,
|
|
1374
|
+
writable: true,
|
|
1375
|
+
});
|
|
1197
1376
|
}
|
|
1198
|
-
return target[prop];
|
|
1199
1377
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1378
|
+
}
|
|
1379
|
+
return new Proxy(target, {
|
|
1380
|
+
ownKeys(target) {
|
|
1381
|
+
enumerated.add(tag);
|
|
1382
|
+
return Reflect.ownKeys(target);
|
|
1383
|
+
},
|
|
1384
|
+
getOwnPropertyDescriptor(target, prop) {
|
|
1385
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, prop);
|
|
1386
|
+
if (tag === 'c:' && typeof prop === 'string')
|
|
1387
|
+
contextRead(prop);
|
|
1388
|
+
if (options.discoverPayloadShape === true &&
|
|
1389
|
+
tag !== 'c:' &&
|
|
1390
|
+
typeof prop === 'string' &&
|
|
1391
|
+
descriptor === undefined) {
|
|
1392
|
+
reads.add(`${tag}${prop}`);
|
|
1393
|
+
enumerated.add(tag);
|
|
1394
|
+
noteShapeField(tag, prop);
|
|
1395
|
+
// Discovery can follow a chain of Object.hasOwn checks without
|
|
1396
|
+
// choosing semantic values. Only concrete evaluation may accept
|
|
1397
|
+
// the resulting named shape; this descriptor never reaches replay.
|
|
1398
|
+
if (discoverShape && tag === shapeTag) {
|
|
1399
|
+
return {
|
|
1400
|
+
value: null,
|
|
1401
|
+
enumerable: true,
|
|
1402
|
+
configurable: true,
|
|
1403
|
+
writable: true,
|
|
1404
|
+
};
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
return descriptor;
|
|
1408
|
+
},
|
|
1409
|
+
get(target, prop) {
|
|
1410
|
+
if (typeof prop !== 'string')
|
|
1411
|
+
return undefined;
|
|
1412
|
+
if (tag === 'c:')
|
|
1413
|
+
contextRead(prop);
|
|
1414
|
+
else if (tag === 'o:' && options.declaredResultFields !== undefined) {
|
|
1415
|
+
declaredField =
|
|
1416
|
+
options.declaredResultFields.includes(prop) &&
|
|
1417
|
+
!Object.hasOwn(assigned, prop)
|
|
1418
|
+
? prop
|
|
1419
|
+
: undefined;
|
|
1420
|
+
}
|
|
1421
|
+
if (prop in target) {
|
|
1422
|
+
const payload = payloads.find((item) => item.tag === tag);
|
|
1423
|
+
if ((varyExisting ||
|
|
1424
|
+
payload?.varyExisting === true ||
|
|
1425
|
+
payload?.shapeFields?.includes(prop)) &&
|
|
1426
|
+
!(prop in assigned)) {
|
|
1427
|
+
reads.add(`${tag}${prop}`);
|
|
1428
|
+
}
|
|
1429
|
+
return target[prop];
|
|
1430
|
+
}
|
|
1205
1431
|
reads.add(`${tag}${prop}`);
|
|
1432
|
+
noteShapeField(tag, prop);
|
|
1433
|
+
return undefined;
|
|
1434
|
+
},
|
|
1435
|
+
has(target, prop) {
|
|
1436
|
+
if (typeof prop === 'string' && !(prop in target)) {
|
|
1437
|
+
reads.add(`${tag}${prop}`);
|
|
1438
|
+
}
|
|
1439
|
+
return prop in target;
|
|
1440
|
+
},
|
|
1441
|
+
});
|
|
1442
|
+
};
|
|
1443
|
+
const trace = () => {
|
|
1444
|
+
try {
|
|
1445
|
+
let event = { ...fixedEvent };
|
|
1446
|
+
for (const payload of payloads) {
|
|
1447
|
+
if (payload.eventField === undefined) {
|
|
1448
|
+
event = recording(overlay(payload.base, event), assignment.payloads[payload.tag] ?? {}, payload.tag);
|
|
1449
|
+
}
|
|
1450
|
+
else {
|
|
1451
|
+
event[payload.eventField] = recording(payload.base, assignment.payloads[payload.tag] ?? {}, payload.tag);
|
|
1452
|
+
}
|
|
1206
1453
|
}
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1454
|
+
(discoverShape || shapeTag !== undefined || selectedPending
|
|
1455
|
+
? (options.payloadShapeGuard ?? guard)
|
|
1456
|
+
: guard)({
|
|
1457
|
+
context: recording(baseContext, assignment.contextOverrides, 'c:', options.varyExistingContext === true),
|
|
1458
|
+
event,
|
|
1459
|
+
});
|
|
1460
|
+
}
|
|
1461
|
+
catch {
|
|
1462
|
+
coverageCheckpoint();
|
|
1463
|
+
// Reads observed before the throw still guide the search.
|
|
1464
|
+
}
|
|
1465
|
+
finally {
|
|
1466
|
+
coverageCheckpoint();
|
|
1467
|
+
}
|
|
1468
|
+
};
|
|
1469
|
+
trace();
|
|
1470
|
+
// Exact cardinality may short-circuit before any named property is read.
|
|
1471
|
+
// Fixed-context reads cannot guide values, so they do not suppress padding.
|
|
1472
|
+
// Explore only an observed payload enumeration, within the same four-field
|
|
1473
|
+
// assignment bound. Context and fixed event fields remain unchanged.
|
|
1474
|
+
if (options.discoverPayloadShape === true &&
|
|
1475
|
+
(discoverShape ||
|
|
1476
|
+
![...reads].some((key) => !key.startsWith('c:') ||
|
|
1477
|
+
(options.assignContext !== false &&
|
|
1478
|
+
!options.fixedContextFields?.includes(key.slice(2)))))) {
|
|
1212
1479
|
for (const payload of payloads) {
|
|
1213
|
-
if (payload.
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1480
|
+
if (!enumerated.has(payload.tag))
|
|
1481
|
+
continue;
|
|
1482
|
+
shapeTag = payload.tag;
|
|
1483
|
+
for (shapeWidth = 1; shapeWidth <= 4; shapeWidth++) {
|
|
1484
|
+
if (++probeBudget.probes > MAX_PROBES)
|
|
1485
|
+
return [...reads];
|
|
1486
|
+
trace();
|
|
1218
1487
|
}
|
|
1219
1488
|
}
|
|
1220
|
-
guard({
|
|
1221
|
-
context: recording(baseContext, assignment.contextOverrides, 'c:', options.varyExistingContext === true),
|
|
1222
|
-
event,
|
|
1223
|
-
});
|
|
1224
|
-
}
|
|
1225
|
-
catch {
|
|
1226
|
-
coverageCheckpoint();
|
|
1227
|
-
// Reads observed before the throw still guide the search.
|
|
1228
|
-
}
|
|
1229
|
-
finally {
|
|
1230
|
-
coverageCheckpoint();
|
|
1231
1489
|
}
|
|
1232
1490
|
return [...reads];
|
|
1233
1491
|
};
|
|
1492
|
+
const initial = {
|
|
1493
|
+
context: baseContext,
|
|
1494
|
+
contextOverrides: {},
|
|
1495
|
+
payloads: {},
|
|
1496
|
+
};
|
|
1497
|
+
if (options.discoverPayloadShape === true) {
|
|
1498
|
+
// Enrichment must not add an optional field to an already valid seed.
|
|
1499
|
+
if (passes(initial))
|
|
1500
|
+
return initial;
|
|
1501
|
+
// Exact own-field tests may hide every semantic read. Learn their names
|
|
1502
|
+
// once, then let ordinary value reads guide the same bounded search over
|
|
1503
|
+
// a fresh JSON-safe shape rather than exhausting unrelated combinations.
|
|
1504
|
+
readsUnder(initial, true);
|
|
1505
|
+
payloads = payloads.map((payload) => {
|
|
1506
|
+
const fields = discovered.get(payload.tag);
|
|
1507
|
+
if (fields === undefined || fields.size > 4)
|
|
1508
|
+
return payload;
|
|
1509
|
+
const shapeFields = [...fields].filter((field) => !Object.hasOwn(payload.base, field));
|
|
1510
|
+
const base = overlay(payload.base, {});
|
|
1511
|
+
for (const field of shapeFields) {
|
|
1512
|
+
Object.defineProperty(base, field, {
|
|
1513
|
+
value: null,
|
|
1514
|
+
enumerable: true,
|
|
1515
|
+
configurable: true,
|
|
1516
|
+
writable: true,
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
return {
|
|
1520
|
+
...payload,
|
|
1521
|
+
base,
|
|
1522
|
+
shapeFields,
|
|
1523
|
+
};
|
|
1524
|
+
});
|
|
1525
|
+
}
|
|
1234
1526
|
const search = (assignment, depth) => {
|
|
1235
1527
|
coverageCheckpoint();
|
|
1236
|
-
if (probes > MAX_PROBES)
|
|
1528
|
+
if (probeBudget.probes > MAX_PROBES)
|
|
1237
1529
|
return undefined;
|
|
1238
1530
|
if (passes(assignment))
|
|
1239
1531
|
return assignment;
|
|
@@ -1242,24 +1534,30 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1242
1534
|
for (const key of readsUnder(assignment)) {
|
|
1243
1535
|
const tag = key.slice(0, 2);
|
|
1244
1536
|
const field = key.slice(2);
|
|
1245
|
-
if (tag === 'c:' &&
|
|
1537
|
+
if (tag === 'c:' &&
|
|
1538
|
+
(options.assignContext === false ||
|
|
1539
|
+
options.fixedContextFields?.includes(field)))
|
|
1246
1540
|
continue;
|
|
1247
1541
|
const assigned = tag === 'c:'
|
|
1248
1542
|
? assignment.contextOverrides
|
|
1249
1543
|
: (assignment.payloads[tag] ?? {});
|
|
1250
1544
|
const payload = payloads.find((item) => item.tag === tag);
|
|
1545
|
+
if (payload?.shapeFields !== undefined &&
|
|
1546
|
+
discovered.get(tag)?.has(field) &&
|
|
1547
|
+
!payload.shapeFields.includes(field))
|
|
1548
|
+
continue;
|
|
1549
|
+
if (payload?.shapeFields !== undefined &&
|
|
1550
|
+
new Set([...payload.shapeFields, ...Object.keys(assigned), field])
|
|
1551
|
+
.size > 4)
|
|
1552
|
+
continue;
|
|
1251
1553
|
const base = tag === 'c:' ? baseContext : payload?.base;
|
|
1252
1554
|
const hasBaseline = base !== undefined && Object.prototype.hasOwnProperty.call(base, field);
|
|
1253
1555
|
const baseline = hasBaseline
|
|
1254
1556
|
? base[field]
|
|
1255
1557
|
: undefined;
|
|
1256
|
-
const
|
|
1257
|
-
...(hasBaseline ? [baseline] : []),
|
|
1258
|
-
...values.filter((value) => !hasBaseline || value !== baseline),
|
|
1259
|
-
];
|
|
1260
|
-
for (const value of candidates) {
|
|
1558
|
+
for (const value of candidateValues(key, hasBaseline, baseline)) {
|
|
1261
1559
|
coverageCheckpoint();
|
|
1262
|
-
if (probes > MAX_PROBES)
|
|
1560
|
+
if (probeBudget.probes > MAX_PROBES)
|
|
1263
1561
|
return undefined;
|
|
1264
1562
|
const nextDepth = depth + (hasBaseline && value === baseline ? 0 : 1);
|
|
1265
1563
|
const next = tag === 'c:'
|
|
@@ -1285,14 +1583,47 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1285
1583
|
}
|
|
1286
1584
|
return undefined;
|
|
1287
1585
|
};
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1586
|
+
const shapes = payloads;
|
|
1587
|
+
const slots = shapes.flatMap((payload, index) => (payload.shapeFields ?? []).map((field) => ({ index, field })));
|
|
1588
|
+
if (slots.length > 4)
|
|
1589
|
+
return undefined;
|
|
1590
|
+
// An observed own-field read may be an optional branch discriminator.
|
|
1591
|
+
// Try at most sixteen concrete shapes, sharing the same probe budget.
|
|
1592
|
+
for (let mask = 0; mask < 1 << slots.length && probeBudget.probes <= MAX_PROBES; mask++) {
|
|
1593
|
+
payloads = shapes.map((payload, index) => {
|
|
1594
|
+
if (payload.shapeFields === undefined)
|
|
1595
|
+
return payload;
|
|
1596
|
+
const fields = slots
|
|
1597
|
+
.filter((slot, bit) => slot.index === index && (mask & (1 << bit)) !== 0)
|
|
1598
|
+
.map((slot) => slot.field);
|
|
1599
|
+
const base = overlay(payload.base, {});
|
|
1600
|
+
for (const field of payload.shapeFields) {
|
|
1601
|
+
if (!fields.includes(field))
|
|
1602
|
+
delete base[field];
|
|
1603
|
+
}
|
|
1604
|
+
return { ...payload, base, shapeFields: fields };
|
|
1605
|
+
});
|
|
1606
|
+
const found = search(initial, 0);
|
|
1607
|
+
if (found === undefined)
|
|
1608
|
+
continue;
|
|
1609
|
+
for (const payload of payloads) {
|
|
1610
|
+
if (payload.shapeFields === undefined)
|
|
1611
|
+
continue;
|
|
1612
|
+
found.payloads[payload.tag] = {
|
|
1613
|
+
...Object.fromEntries(payload.shapeFields.map((field) => [field, null])),
|
|
1614
|
+
...found.payloads[payload.tag],
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
return found;
|
|
1618
|
+
}
|
|
1619
|
+
return undefined;
|
|
1293
1620
|
}
|
|
1294
|
-
function probeGuardSatisfiable(guard, fixedEvent, payloads, extraValues) {
|
|
1295
|
-
return (probeGuardAssignment(guard, fixedEvent, payloads, extraValues
|
|
1621
|
+
function probeGuardSatisfiable(guard, fixedEvent, payloads, extraValues, initialContext) {
|
|
1622
|
+
return (probeGuardAssignment(guard, fixedEvent, payloads, extraValues, {
|
|
1623
|
+
initialContext,
|
|
1624
|
+
varyExistingContext: true,
|
|
1625
|
+
fixedContextFields: ['enabledPlaybooks'],
|
|
1626
|
+
}) !== undefined);
|
|
1296
1627
|
}
|
|
1297
1628
|
function overlaidObject(base, assigned) {
|
|
1298
1629
|
const copy = Object.create(Object.getPrototypeOf(base));
|
|
@@ -1305,15 +1636,15 @@ function overlaidObject(base, assigned) {
|
|
|
1305
1636
|
* named nested payloads are assignable; event-level fields such as `type` and
|
|
1306
1637
|
* `actorId` remain the values XState actually supplies.
|
|
1307
1638
|
*/
|
|
1308
|
-
function doneGuardSatisfiable(guard, event, output, extraValues, fixedOutput = false) {
|
|
1309
|
-
return probeGuardSatisfiable(guard.run, fixedOutput ? { ...event, output } : event, fixedOutput ? [] : [{ eventField: 'output', tag: 'o:', base: output }], [...guard.probeValues, ...extraValues]);
|
|
1639
|
+
function doneGuardSatisfiable(guard, event, output, extraValues, fixedOutput = false, initialContext) {
|
|
1640
|
+
return probeGuardSatisfiable(guard.run, fixedOutput ? { ...event, output } : event, fixedOutput ? [] : [{ eventField: 'output', tag: 'o:', base: output }], [...guard.probeValues, ...extraValues], initialContext);
|
|
1310
1641
|
}
|
|
1311
1642
|
/** A concrete initialized-context/output assignment selecting one done arm. */
|
|
1312
1643
|
function controllerDoneGuardAssignment(guard, event, output, extraValues, initialContext) {
|
|
1313
1644
|
return probeGuardAssignment(guard.run, event, [{ eventField: 'output', tag: 'o:', base: output }], [...guard.probeValues, ...extraValues], { initialContext, varyExistingContext: true });
|
|
1314
1645
|
}
|
|
1315
|
-
function errorGuardSatisfiable(guard, event, error, extraValues) {
|
|
1316
|
-
return probeGuardSatisfiable(guard.run, event, [{ eventField: 'error', tag: 'r:', base: error, varyExisting: true }], [...guard.probeValues, ...extraValues]);
|
|
1646
|
+
function errorGuardSatisfiable(guard, event, error, extraValues, initialContext) {
|
|
1647
|
+
return probeGuardSatisfiable(guard.run, event, [{ eventField: 'error', tag: 'r:', base: error, varyExisting: true }], [...guard.probeValues, ...extraValues], initialContext);
|
|
1317
1648
|
}
|
|
1318
1649
|
function isDescendantOf(ref, ancestor) {
|
|
1319
1650
|
return (ref.path.length > ancestor.path.length &&
|
|
@@ -1391,11 +1722,13 @@ function callCount(calls, captain) {
|
|
|
1391
1722
|
/** One public drive or the actual initialized state, never a private jump. */
|
|
1392
1723
|
function childCoverageDrive(machine, refs, ref, targetId, candidates) {
|
|
1393
1724
|
const interrupt = interruptDriveForRef(machine, refs, ref, targetId, candidates);
|
|
1725
|
+
const alternatives = entryDrivesForRef(machine, refs, ref, candidates);
|
|
1726
|
+
// A valid interrupt need not preserve every public entry's reached context.
|
|
1394
1727
|
if (interrupt.satisfiable)
|
|
1395
|
-
return { drive: interrupt };
|
|
1396
|
-
const entry =
|
|
1397
|
-
if (entry
|
|
1398
|
-
return { drive: entry };
|
|
1728
|
+
return { drive: interrupt, alternatives };
|
|
1729
|
+
const entry = alternatives.next();
|
|
1730
|
+
if (!entry.done)
|
|
1731
|
+
return { drive: entry.value, alternatives };
|
|
1399
1732
|
return initialActiveRefs(machine.config, refs).some((active) => sameStateRef(active, ref))
|
|
1400
1733
|
? {}
|
|
1401
1734
|
: undefined;
|
|
@@ -1415,6 +1748,12 @@ function coverageArmResults(machine, node, outcome, armIndex, context, input, ca
|
|
|
1415
1748
|
const guard = orderedArmPredicate(machine, arms, armIndex);
|
|
1416
1749
|
if (guard === undefined)
|
|
1417
1750
|
return [];
|
|
1751
|
+
const shapeGuard = node.kind === 'child' && outcome === 'onDone'
|
|
1752
|
+
? resolveGuard(machine, armGuard(arms[armIndex]))?.run
|
|
1753
|
+
: undefined;
|
|
1754
|
+
const childValues = node.kind === 'child' && outcome === 'onDone'
|
|
1755
|
+
? [{ name: 'Error', message: 'coverage: child failure' }]
|
|
1756
|
+
: [];
|
|
1418
1757
|
const actorId = invocationActorId(machine, node.value);
|
|
1419
1758
|
const event = {
|
|
1420
1759
|
type: `xstate.${outcome === 'onDone' ? 'done' : 'error'}.actor.${actorId}`,
|
|
@@ -1426,6 +1765,9 @@ function coverageArmResults(machine, node, outcome, armIndex, context, input, ca
|
|
|
1426
1765
|
nestedFailure(typeof input.playbookId === 'string'
|
|
1427
1766
|
? input.playbookId
|
|
1428
1767
|
: COVERAGE_PLAYBOOK_ID),
|
|
1768
|
+
nestedAborted(typeof input.playbookId === 'string'
|
|
1769
|
+
? input.playbookId
|
|
1770
|
+
: COVERAGE_PLAYBOOK_ID),
|
|
1429
1771
|
nestedFailureTerminal(typeof input.playbookId === 'string'
|
|
1430
1772
|
? input.playbookId
|
|
1431
1773
|
: COVERAGE_PLAYBOOK_ID),
|
|
@@ -1474,7 +1816,19 @@ function coverageArmResults(machine, node, outcome, armIndex, context, input, ca
|
|
|
1474
1816
|
base,
|
|
1475
1817
|
...(outcome === 'onError' ? { varyExisting: true } : {}),
|
|
1476
1818
|
},
|
|
1477
|
-
], [...guard.probeValues, ...GENERIC_VALUES, ...candidates], {
|
|
1819
|
+
], [...guard.probeValues, ...GENERIC_VALUES, ...candidates, ...childValues], {
|
|
1820
|
+
initialContext: context,
|
|
1821
|
+
assignContext: false,
|
|
1822
|
+
discoverPayloadShape: node.kind === 'child' && outcome === 'onDone',
|
|
1823
|
+
...(node.kind === 'acting' && outcome === 'onDone'
|
|
1824
|
+
? {
|
|
1825
|
+
declaredResultFields: requiredFields(node.value.binding.result[String(base.guard)] ?? '').filter((field) => field !== 'guard' &&
|
|
1826
|
+
base[field] ===
|
|
1827
|
+
`coverage:${field}`),
|
|
1828
|
+
}
|
|
1829
|
+
: {}),
|
|
1830
|
+
...(shapeGuard === undefined ? {} : { payloadShapeGuard: shapeGuard }),
|
|
1831
|
+
});
|
|
1478
1832
|
if (assignment !== undefined) {
|
|
1479
1833
|
results.push(assignedPayload(base, assignment, outcome === 'onDone' ? 'o:' : 'r:'));
|
|
1480
1834
|
if (firstOnly)
|
|
@@ -1559,7 +1913,7 @@ async function replayCoveragePath(machine, nodes, path) {
|
|
|
1559
1913
|
: {}),
|
|
1560
1914
|
};
|
|
1561
1915
|
}
|
|
1562
|
-
/** Finite path replay,
|
|
1916
|
+
/** Finite path replay, including bounded canonical question/reply revisits. */
|
|
1563
1917
|
async function searchCoverageEntry(machine, target, refs, captains, playbooks, candidates, check) {
|
|
1564
1918
|
const nodes = coverageNodes(captains, playbooks);
|
|
1565
1919
|
const nodesForTarget = (raw, source) => {
|
|
@@ -1593,27 +1947,30 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
1593
1947
|
}
|
|
1594
1948
|
let attempts = 0;
|
|
1595
1949
|
let entered = false;
|
|
1596
|
-
|
|
1950
|
+
const limitations = new Set();
|
|
1597
1951
|
let inputFailure;
|
|
1598
1952
|
while (queue.length > 0 && attempts < MAX_COVERAGE_PATH_ATTEMPTS) {
|
|
1599
1953
|
await coverageYield();
|
|
1600
1954
|
const path = queue.shift();
|
|
1601
1955
|
attempts++;
|
|
1602
1956
|
let replay = await replayCoveragePath(machine, nodes, path);
|
|
1957
|
+
let covered = false;
|
|
1603
1958
|
try {
|
|
1604
1959
|
if (replay.inputFailure !== undefined)
|
|
1605
1960
|
inputFailure = replay.inputFailure;
|
|
1606
1961
|
if (replay.pending !== undefined &&
|
|
1607
1962
|
coverageNodeKey(replay.pending.node) === coverageNodeKey(target)) {
|
|
1608
1963
|
entered = true;
|
|
1609
|
-
if (await check(replay.actor, replay.pending))
|
|
1964
|
+
if (await check(replay.actor, replay.pending)) {
|
|
1965
|
+
covered = true;
|
|
1610
1966
|
return { covered: true, entered };
|
|
1967
|
+
}
|
|
1611
1968
|
// A target check may have completed its actor. Re-enter the same
|
|
1612
1969
|
// authored prefix before considering successors, charging that replay
|
|
1613
1970
|
// against the same attempt limit.
|
|
1614
1971
|
replay.actor.stop();
|
|
1615
1972
|
if (attempts >= MAX_COVERAGE_PATH_ATTEMPTS) {
|
|
1616
|
-
|
|
1973
|
+
limitations.add(`exhausted ${MAX_COVERAGE_PATH_ATTEMPTS}-attempt path budget`);
|
|
1617
1974
|
break;
|
|
1618
1975
|
}
|
|
1619
1976
|
attempts++;
|
|
@@ -1640,8 +1997,7 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
1640
1997
|
}
|
|
1641
1998
|
}
|
|
1642
1999
|
if (node.kind === 'acting' &&
|
|
1643
|
-
Object.hasOwn(node.value.binding.result, NEEDS_BOSS_REPLY)
|
|
1644
|
-
!path.steps.some((step) => step.questionWait !== undefined)) {
|
|
2000
|
+
Object.hasOwn(node.value.binding.result, NEEDS_BOSS_REPLY)) {
|
|
1645
2001
|
for (const [index, arm] of transitionArms(node.value.invocation.onDone).entries()) {
|
|
1646
2002
|
const rawTarget = rawArmTarget(arm);
|
|
1647
2003
|
const waitRef = rawTarget === undefined
|
|
@@ -1660,30 +2016,57 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
1660
2016
|
}
|
|
1661
2017
|
}
|
|
1662
2018
|
}
|
|
2019
|
+
const continuations = [];
|
|
1663
2020
|
for (const step of nextSteps) {
|
|
1664
2021
|
if (path.steps.length + 1 >= MAX_COVERAGE_PATH_STEPS) {
|
|
1665
|
-
|
|
2022
|
+
limitations.add(`exhausted ${MAX_COVERAGE_PATH_STEPS}-invocation path depth`);
|
|
1666
2023
|
continue;
|
|
1667
2024
|
}
|
|
1668
2025
|
const visited = [path.root, ...path.steps.map((step) => step.next)].map(coverageNodeKey);
|
|
1669
2026
|
if (step.questionWait === undefined &&
|
|
1670
2027
|
visited.includes(coverageNodeKey(step.next))) {
|
|
1671
|
-
|
|
2028
|
+
limitations.add('unsupported repeated-invocation path');
|
|
1672
2029
|
continue;
|
|
1673
2030
|
}
|
|
1674
|
-
|
|
2031
|
+
const successor = {
|
|
2032
|
+
root: path.root,
|
|
2033
|
+
drive: path.drive,
|
|
2034
|
+
steps: [...path.steps, step],
|
|
2035
|
+
};
|
|
2036
|
+
if (coverageNodeKey(node) === coverageNodeKey(target) &&
|
|
2037
|
+
step.questionWait !== undefined)
|
|
2038
|
+
continuations.push(successor);
|
|
2039
|
+
else
|
|
2040
|
+
queue.push(successor);
|
|
1675
2041
|
}
|
|
2042
|
+
// Continue a reached target before unrelated alternative prefixes, but
|
|
2043
|
+
// retain candidate order and charge every replay to the same budgets.
|
|
2044
|
+
queue.unshift(...continuations);
|
|
1676
2045
|
}
|
|
1677
2046
|
finally {
|
|
1678
2047
|
replay.actor.stop();
|
|
2048
|
+
if (!covered &&
|
|
2049
|
+
path.alternatives !== undefined &&
|
|
2050
|
+
attempts < MAX_COVERAGE_PATH_ATTEMPTS) {
|
|
2051
|
+
const next = path.alternatives.next();
|
|
2052
|
+
if (!next.done)
|
|
2053
|
+
queue.push({
|
|
2054
|
+
root: path.root,
|
|
2055
|
+
drive: next.value,
|
|
2056
|
+
steps: [],
|
|
2057
|
+
alternatives: path.alternatives,
|
|
2058
|
+
});
|
|
2059
|
+
}
|
|
1679
2060
|
}
|
|
1680
2061
|
}
|
|
1681
2062
|
if (queue.length > 0)
|
|
1682
|
-
|
|
2063
|
+
limitations.add(`exhausted ${MAX_COVERAGE_PATH_ATTEMPTS}-attempt path budget`);
|
|
1683
2064
|
return {
|
|
1684
2065
|
covered: false,
|
|
1685
2066
|
entered,
|
|
1686
|
-
...(
|
|
2067
|
+
...(limitations.size === 0
|
|
2068
|
+
? {}
|
|
2069
|
+
: { limitation: [...limitations].join('; ') }),
|
|
1687
2070
|
...(inputFailure === undefined ? {} : { inputFailure }),
|
|
1688
2071
|
};
|
|
1689
2072
|
}
|
|
@@ -1717,6 +2100,18 @@ function nestedFailure(playbookId) {
|
|
|
1717
2100
|
});
|
|
1718
2101
|
return error;
|
|
1719
2102
|
}
|
|
2103
|
+
/** A public aborted result may omit both child-session and error data. */
|
|
2104
|
+
function nestedAborted(playbookId) {
|
|
2105
|
+
const error = new Error(`Child playbook ${playbookId} aborted`);
|
|
2106
|
+
error.name = 'NestedPlaybookCallError';
|
|
2107
|
+
Object.defineProperty(error, 'result', {
|
|
2108
|
+
configurable: true,
|
|
2109
|
+
enumerable: true,
|
|
2110
|
+
writable: true,
|
|
2111
|
+
value: { status: 'aborted', playbookId },
|
|
2112
|
+
});
|
|
2113
|
+
return error;
|
|
2114
|
+
}
|
|
1720
2115
|
/**
|
|
1721
2116
|
* A child that completed at its own authored failure terminal. The bridge
|
|
1722
2117
|
* rejects the call with that exact `ok` result, so a recovering first
|
|
@@ -2101,16 +2496,16 @@ async function probePlaybookOutcome(machine, playbook, refs, captains, outcome,
|
|
|
2101
2496
|
if (result.covered)
|
|
2102
2497
|
continue;
|
|
2103
2498
|
const label = `state ${playbook.ref.stableId}: nested playbook ${outcome} arm ${armIndex}`;
|
|
2104
|
-
if (result.
|
|
2105
|
-
findings.push(`${label}: ${result.limitation}`);
|
|
2106
|
-
else if (result.inputFailure !== undefined && !result.entered)
|
|
2499
|
+
if (result.inputFailure !== undefined && !result.entered)
|
|
2107
2500
|
findings.push(`state ${playbook.ref.stableId}: nested playbook actor failed to start during ${outcome} coverage: ${result.inputFailure}`);
|
|
2108
2501
|
else if (!result.entered)
|
|
2109
2502
|
findings.push(`${label} has no reachable entry under probing (dead or unsupported entry path)`);
|
|
2110
|
-
else if (!satisfiable)
|
|
2503
|
+
else if (result.limitation === undefined && !satisfiable)
|
|
2111
2504
|
findings.push(`${label} is unsatisfiable under probing`);
|
|
2112
|
-
else
|
|
2505
|
+
else if (satisfiable)
|
|
2113
2506
|
findings.push(`${label} did not reach ${target.stableId}`);
|
|
2507
|
+
if (result.limitation !== undefined)
|
|
2508
|
+
findings.push(`${label}: ${result.limitation}`);
|
|
2114
2509
|
}
|
|
2115
2510
|
return findings;
|
|
2116
2511
|
}
|
|
@@ -2157,7 +2552,7 @@ function reachedBossQuestionFinding(machine, captain, actor, output) {
|
|
|
2157
2552
|
coverageRuns.getStore()?.questionFindings.add(finding);
|
|
2158
2553
|
return finding;
|
|
2159
2554
|
}
|
|
2160
|
-
/** No preemption is needed to audit ordinary acting outcomes and
|
|
2555
|
+
/** No preemption is needed to audit ordinary acting outcomes and replies. */
|
|
2161
2556
|
async function probeNonPreemptiveActor(machine, captain, refs, captains, playbooks, candidates) {
|
|
2162
2557
|
const node = { kind: 'acting', value: captain };
|
|
2163
2558
|
const findings = [];
|
|
@@ -2451,6 +2846,13 @@ export function fsmCoverageTestTimeout(fsmModule) {
|
|
|
2451
2846
|
errorArms;
|
|
2452
2847
|
continue;
|
|
2453
2848
|
}
|
|
2849
|
+
if (!controller &&
|
|
2850
|
+
captain.binding.actor !== 'script' &&
|
|
2851
|
+
resultKeys.includes(NEEDS_BOSS_REPLY)) {
|
|
2852
|
+
// An otherwise unproved arm uses the same bounded reached-context
|
|
2853
|
+
// search, including each actual canonical question/reply revisit.
|
|
2854
|
+
pathSearches += guardedDoneArms;
|
|
2855
|
+
}
|
|
2454
2856
|
captainSettles +=
|
|
2455
2857
|
resultKeys.reduce((total, key) => total + (key === NEEDS_BOSS_REPLY ? 4 : controller ? 2 : 1), 0) * SETTLE_MS;
|
|
2456
2858
|
// One directly selectable onError arm is driven.
|
|
@@ -2483,7 +2885,7 @@ export function fsmCoverageTestTimeout(fsmModule) {
|
|
|
2483
2885
|
const done = transitionArms(node.value.invocation.onDone).length;
|
|
2484
2886
|
const error = transitionArms(node.value.invocation.onError).length;
|
|
2485
2887
|
if (node.kind === 'child')
|
|
2486
|
-
return 3 *
|
|
2888
|
+
return 3 * done + 4 * error;
|
|
2487
2889
|
const keys = Object.keys(node.value.binding.result);
|
|
2488
2890
|
const candidates = node.value.binding.actor === 'script'
|
|
2489
2891
|
? keys.length * MAX_SCRIPT_EXIT_STATUSES
|
|
@@ -2498,11 +2900,12 @@ export function fsmCoverageTestTimeout(fsmModule) {
|
|
|
2498
2900
|
MAX_COVERAGE_PATH_ATTEMPTS * 2 * maxNodeCandidates);
|
|
2499
2901
|
// Parallel question/join helpers retain their independent entry probes.
|
|
2500
2902
|
guardProbeCalls += 2 * parallels.length;
|
|
2501
|
-
// Each charged replay contains at most eight invocation waits,
|
|
2502
|
-
// question
|
|
2903
|
+
// Each charged replay contains at most eight invocation waits, up to
|
|
2904
|
+
// seven parked question waits and two target/reply settles, plus
|
|
2905
|
+
// no-transition checks.
|
|
2503
2906
|
const pathSettles = pathSearches *
|
|
2504
2907
|
MAX_COVERAGE_PATH_ATTEMPTS *
|
|
2505
|
-
((MAX_COVERAGE_PATH_STEPS +
|
|
2908
|
+
((2 * MAX_COVERAGE_PATH_STEPS + 1) * PARALLEL_SETTLE_MS + 2 * 10);
|
|
2506
2909
|
const parallelSettles = parallels.reduce((total, parallel) => total +
|
|
2507
2910
|
2 * PARALLEL_QUESTION_SETTLE_MS +
|
|
2508
2911
|
transitionArms(parallel.state.onDone).length *
|
|
@@ -2537,6 +2940,7 @@ export async function checkFsmCoverage(fsmModule, opts = {}) {
|
|
|
2537
2940
|
lastYield: started,
|
|
2538
2941
|
actors: new Set(),
|
|
2539
2942
|
questionFindings: new Set(),
|
|
2943
|
+
machineInputs: new WeakMap(),
|
|
2540
2944
|
};
|
|
2541
2945
|
return coverageRuns.run(run, async () => {
|
|
2542
2946
|
let completed = false;
|
|
@@ -2785,6 +3189,7 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
2785
3189
|
const rawDoneArms = transitionArms(captain.invocation.onDone);
|
|
2786
3190
|
const onDoneArms = normalizeArms(captain.invocation.onDone);
|
|
2787
3191
|
const controllerResultByArm = new Map();
|
|
3192
|
+
let validatedQuestion;
|
|
2788
3193
|
// Every declared result needs an ordered arm accepting its valid output.
|
|
2789
3194
|
// A fallback is reachable exactly when all preceding guards reject it.
|
|
2790
3195
|
// Result names alone cannot distinguish authored failure from an orphan.
|
|
@@ -2840,7 +3245,7 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
2840
3245
|
]);
|
|
2841
3246
|
for (const candidate of outputs) {
|
|
2842
3247
|
await coverageYield();
|
|
2843
|
-
if (doneGuardSatisfiable(guard, doneEvent, candidate, candidates, state.actor === 'script')) {
|
|
3248
|
+
if (doneGuardSatisfiable(guard, doneEvent, candidate, candidates, state.actor === 'script', initialCoverageContext)) {
|
|
2844
3249
|
accepting.set(index, undefined);
|
|
2845
3250
|
acceptedOutputs.set(JSON.stringify(candidate), candidate);
|
|
2846
3251
|
}
|
|
@@ -2921,6 +3326,13 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
2921
3326
|
continue;
|
|
2922
3327
|
}
|
|
2923
3328
|
const actor = probe.actor;
|
|
3329
|
+
const transitionStart = actor.coverageTransitions.length;
|
|
3330
|
+
const sourceId = resolvedStateNode(machine, captain.ref)?.id;
|
|
3331
|
+
const questionCompletion = () => actor.coverageTransitions
|
|
3332
|
+
.slice(transitionStart)
|
|
3333
|
+
.find((transition) => sourceId !== undefined &&
|
|
3334
|
+
transition.sourceId === sourceId &&
|
|
3335
|
+
transition.event?.type === doneEvent.type);
|
|
2924
3336
|
gate.armed = true;
|
|
2925
3337
|
actor.send(probe.event);
|
|
2926
3338
|
if (controllerDirectTarget !== undefined &&
|
|
@@ -2937,18 +3349,31 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
2937
3349
|
: await settle(actor, isController
|
|
2938
3350
|
? (snapshot) => snapshot.status === 'done' ||
|
|
2939
3351
|
(initialRef !== undefined && atState(initialRef)(snapshot))
|
|
2940
|
-
:
|
|
3352
|
+
: key === NEEDS_BOSS_REPLY
|
|
3353
|
+
? (snapshot) => questionCompletion() !== undefined &&
|
|
3354
|
+
leftState(captain.ref)(snapshot)
|
|
3355
|
+
: leftState(captain.ref));
|
|
2941
3356
|
if (!transitioned) {
|
|
2942
3357
|
findings.push(isController
|
|
2943
3358
|
? `state ${stateKey}: controller result "${key}" reached neither the session hub nor a shutdown final`
|
|
2944
3359
|
: `state ${stateKey}: result "${key}" fired no transition`);
|
|
2945
3360
|
}
|
|
2946
3361
|
else if (key === NEEDS_BOSS_REPLY) {
|
|
2947
|
-
const
|
|
3362
|
+
const completion = questionCompletion();
|
|
3363
|
+
const completedArm = completion?.armIndex;
|
|
3364
|
+
const waitTarget = completedArm === undefined
|
|
3365
|
+
? undefined
|
|
3366
|
+
: (rawArmTarget(rawDoneArms[completedArm]) ??
|
|
3367
|
+
onDoneArms[completedArm]?.target);
|
|
2948
3368
|
const waitRef = waitTarget === null || waitTarget === undefined
|
|
2949
3369
|
? undefined
|
|
2950
3370
|
: stateRefForTarget(refs, waitTarget, captain.ref);
|
|
3371
|
+
const waitNodeId = waitRef === undefined
|
|
3372
|
+
? undefined
|
|
3373
|
+
: resolvedStateNode(machine, waitRef)?.id;
|
|
2951
3374
|
if (waitRef === undefined ||
|
|
3375
|
+
waitNodeId === undefined ||
|
|
3376
|
+
completion?.targetIds.includes(waitNodeId) !== true ||
|
|
2952
3377
|
(waitRef.stableId !== AWAIT_BOSS_REPLY_STATE &&
|
|
2953
3378
|
!tagsOf(waitRef.state).includes('playbook.parked')) ||
|
|
2954
3379
|
!(await settle(actor, atState(waitRef)))) {
|
|
@@ -2985,6 +3410,9 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
2985
3410
|
if (!(await settle(actor, atState(captain.ref)))) {
|
|
2986
3411
|
findings.push(`state ${stateKey}: ${BOSS_REPLY_EVENT} did not resume the suspended state`);
|
|
2987
3412
|
}
|
|
3413
|
+
else if (!isController && state.actor !== 'script') {
|
|
3414
|
+
validatedQuestion = { output: drivenOutput, wait: waitRef };
|
|
3415
|
+
}
|
|
2988
3416
|
actor.stop();
|
|
2989
3417
|
const blankGate = { armed: false };
|
|
2990
3418
|
const blankProbe = captainProbeActor(machine, captain, synthOutput(state, NEEDS_BOSS_REPLY), blankGate, refs, captains, playbooks, sourceCandidates, controllerContext);
|
|
@@ -3037,11 +3465,55 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
3037
3465
|
...declaredGuard.probeValues,
|
|
3038
3466
|
...candidates,
|
|
3039
3467
|
]);
|
|
3040
|
-
return (outputs.some((candidate) => doneGuardSatisfiable(guard, doneEvent, candidate, candidates, state.actor === 'script')) ||
|
|
3468
|
+
return (outputs.some((candidate) => doneGuardSatisfiable(guard, doneEvent, candidate, candidates, state.actor === 'script', initialCoverageContext)) ||
|
|
3041
3469
|
(state.actor !== 'script' &&
|
|
3042
|
-
doneGuardSatisfiable(guard, doneEvent, { guard: key }, candidates)));
|
|
3470
|
+
doneGuardSatisfiable(guard, doneEvent, { guard: key }, candidates, false, initialCoverageContext)));
|
|
3043
3471
|
});
|
|
3044
3472
|
if (!anyOutput) {
|
|
3473
|
+
const targetName = rawArmTarget(arm);
|
|
3474
|
+
const target = targetName === undefined
|
|
3475
|
+
? undefined
|
|
3476
|
+
: stateRefForTarget(refs, targetName, captain.ref);
|
|
3477
|
+
const sourceId = resolvedStateNode(machine, captain.ref)?.id;
|
|
3478
|
+
const targetId = target === undefined
|
|
3479
|
+
? undefined
|
|
3480
|
+
: resolvedStateNode(machine, target)?.id;
|
|
3481
|
+
if (validatedQuestion !== undefined &&
|
|
3482
|
+
target !== undefined &&
|
|
3483
|
+
sourceId !== undefined &&
|
|
3484
|
+
targetId !== undefined) {
|
|
3485
|
+
const node = { kind: 'acting', value: captain };
|
|
3486
|
+
let missedTarget = false;
|
|
3487
|
+
const reached = await searchCoverageEntry(machine, node, refs, captains, playbooks, candidates, async (actor, pending) => {
|
|
3488
|
+
const outputs = coverageArmResults(machine, node, 'onDone', index, actor.getSnapshot().context, pending.input, candidates, undefined, undefined, true, true);
|
|
3489
|
+
if (outputs.length === 0)
|
|
3490
|
+
return false;
|
|
3491
|
+
const before = actor.coverageTransitions.length;
|
|
3492
|
+
pending.complete(outputs[0]);
|
|
3493
|
+
const landed = await settle(actor, (snapshot) => atState(target)(snapshot) &&
|
|
3494
|
+
actor.coverageTransitions
|
|
3495
|
+
.slice(before)
|
|
3496
|
+
.some((transition) => transition.sourceId === sourceId &&
|
|
3497
|
+
transition.armIndex === index &&
|
|
3498
|
+
transition.event?.type === doneEvent.type &&
|
|
3499
|
+
transition.targetIds.includes(targetId)), PARALLEL_SETTLE_MS);
|
|
3500
|
+
if (!landed)
|
|
3501
|
+
missedTarget = true;
|
|
3502
|
+
return landed;
|
|
3503
|
+
});
|
|
3504
|
+
if (reached.covered)
|
|
3505
|
+
continue;
|
|
3506
|
+
if (missedTarget)
|
|
3507
|
+
findings.push(`state ${stateKey}: onDone arm ${index} did not reach ${target.stableId} after canonical Boss reply`);
|
|
3508
|
+
if (reached.inputFailure !== undefined && !reached.entered)
|
|
3509
|
+
findings.push(`state ${stateKey}: onDone arm ${index} actor failed to start: ${reached.inputFailure}`);
|
|
3510
|
+
if (reached.limitation !== undefined)
|
|
3511
|
+
findings.push(`state ${stateKey}: onDone arm ${index} remains unproved: ${reached.limitation}`);
|
|
3512
|
+
if (missedTarget ||
|
|
3513
|
+
(reached.inputFailure !== undefined && !reached.entered) ||
|
|
3514
|
+
reached.limitation !== undefined)
|
|
3515
|
+
continue;
|
|
3516
|
+
}
|
|
3045
3517
|
findings.push(`state ${stateKey}: onDone arm ${index} (target ${onDoneArms[index]?.target ?? 'none'}) is unsatisfiable under probing`);
|
|
3046
3518
|
}
|
|
3047
3519
|
}
|
|
@@ -3070,7 +3542,7 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
3070
3542
|
const guard = orderedArmPredicate(machine, rawErrorArms, index);
|
|
3071
3543
|
if (guard === undefined)
|
|
3072
3544
|
continue;
|
|
3073
|
-
if (!errorGuardSatisfiable(guard, errorEvent, forcedError, candidates)) {
|
|
3545
|
+
if (!errorGuardSatisfiable(guard, errorEvent, forcedError, candidates, initialCoverageContext)) {
|
|
3074
3546
|
findings.push(`state ${stateKey}: onError arm ${index} (target ${onErrorArms[index]?.target ?? 'none'}) is unsatisfiable under probing`);
|
|
3075
3547
|
}
|
|
3076
3548
|
}
|