@sublang/slc 0.16.9 → 0.18.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/README.md +15 -0
- package/dist/app.d.ts +2 -0
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +27 -3
- package/dist/app.js.map +1 -1
- package/dist/config-file.d.ts +3 -0
- package/dist/config-file.d.ts.map +1 -1
- package/dist/config-file.js +20 -0
- package/dist/config-file.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/runner.d.ts +2 -0
- package/dist/runner.d.ts.map +1 -1
- package/dist/runner.js +37 -24
- package/dist/runner.js.map +1 -1
- package/dist/slc.config.template.yaml +5 -0
- package/dist/verify-coverage.d.ts +18 -1
- package/dist/verify-coverage.d.ts.map +1 -1
- package/dist/verify-coverage.js +138 -35
- package/dist/verify-coverage.js.map +1 -1
- package/dist/verify.d.ts +3 -0
- package/dist/verify.d.ts.map +1 -1
- package/dist/verify.js +7 -1
- package/dist/verify.js.map +1 -1
- package/package.json +1 -1
package/dist/verify-coverage.js
CHANGED
|
@@ -28,6 +28,26 @@ import { createActor, fromPromise } from 'xstate';
|
|
|
28
28
|
import { AWAIT_BOSS_REPLY_STATE, BOSS_REPLY_EVENT, INTERRUPT_EVENT, NEEDS_BOSS_REPLY, VERIFY_MODULE, controllerDecisionNearMiss, enumerateCaptainStates, enumeratePlaybookStates, enumerateScriptStates, initialStateTarget, isControllerDecisionResult, isControllerMachine, loadFsmModule, normalizeArms, prepareGearsFsmConformance, findConcurrentRoleSets, ReachedLiteralChildChecks, resolveArtifactSchemaForVerification, usesKeyedBossQuestionContext, } from './verify.js';
|
|
29
29
|
/** The `gears2fsm`-mandated captain actor name a machine declares. */
|
|
30
30
|
export const CAPTAIN_ACTOR = 'captain';
|
|
31
|
+
/** Validate before artifact access and return an independent immutable policy. */
|
|
32
|
+
export function resolveCoverageBudget(value = {}) {
|
|
33
|
+
if (value === null || typeof value !== 'object' || Array.isArray(value))
|
|
34
|
+
throw new TypeError('coverage must be an object');
|
|
35
|
+
for (const key of Reflect.ownKeys(value))
|
|
36
|
+
if (key !== 'maxInvocations' &&
|
|
37
|
+
key !== 'maxAttempts' &&
|
|
38
|
+
key !== 'maxDurationMs')
|
|
39
|
+
throw new TypeError(`Unknown coverage budget key: ${String(key)}`);
|
|
40
|
+
const { maxInvocations = 8, maxAttempts = 64, maxDurationMs = 300_000, } = value;
|
|
41
|
+
for (const [key, limit, cap] of [
|
|
42
|
+
['maxInvocations', maxInvocations, 64],
|
|
43
|
+
['maxAttempts', maxAttempts, 1024],
|
|
44
|
+
['maxDurationMs', maxDurationMs, 1_800_000],
|
|
45
|
+
]) {
|
|
46
|
+
if (!Number.isSafeInteger(limit) || limit < 1 || limit > cap)
|
|
47
|
+
throw new RangeError(`coverage.${key} must be an integer from 1 to ${cap}`);
|
|
48
|
+
}
|
|
49
|
+
return Object.freeze({ maxInvocations, maxAttempts, maxDurationMs });
|
|
50
|
+
}
|
|
31
51
|
// Each check owns its resources, including concurrent checks and async actor
|
|
32
52
|
// callbacks. No current-run variable is shared between invocations.
|
|
33
53
|
const coverageRuns = new AsyncLocalStorage();
|
|
@@ -211,8 +231,6 @@ const SETTLE_MS = 1_000;
|
|
|
211
231
|
const PARALLEL_SETTLE_MS = 250;
|
|
212
232
|
const PARALLEL_QUESTION_SETTLE_MS = 500;
|
|
213
233
|
const MAX_PARALLEL_COMBINATIONS = 64;
|
|
214
|
-
const MAX_COVERAGE_PATH_STEPS = 8;
|
|
215
|
-
const MAX_COVERAGE_PATH_ATTEMPTS = 64;
|
|
216
234
|
/** Stable values shared by machine input, result output, and guard probing. */
|
|
217
235
|
const COVERAGE_PLAYBOOK_ID = 'coverage-child-playbook';
|
|
218
236
|
const COVERAGE_PLAYBOOK_INPUT = 'coverage: complete the child request';
|
|
@@ -1163,7 +1181,6 @@ const MAX_SCRIPT_EXIT_STATUSES = 8;
|
|
|
1163
1181
|
const PROBES_PER_TIMEOUT_MILLISECOND = 50;
|
|
1164
1182
|
const COVERAGE_TIMEOUT_MARGIN_MS = 5_000;
|
|
1165
1183
|
const MIN_COVERAGE_TEST_TIMEOUT_MS = 10_000;
|
|
1166
|
-
const MAX_COVERAGE_TEST_TIMEOUT_MS = 300_000;
|
|
1167
1184
|
function minedLiterals(fn) {
|
|
1168
1185
|
let source;
|
|
1169
1186
|
try {
|
|
@@ -1229,9 +1246,26 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1229
1246
|
prototype: Object.getPrototypeOf(base),
|
|
1230
1247
|
descriptors: Object.getOwnPropertyDescriptors(base),
|
|
1231
1248
|
};
|
|
1249
|
+
const descriptors = shape.descriptors;
|
|
1250
|
+
if ((shape.prototype === Object.prototype || shape.prototype === null) &&
|
|
1251
|
+
Reflect.ownKeys(descriptors).every((key) => {
|
|
1252
|
+
const descriptor = Reflect.get(descriptors, key);
|
|
1253
|
+
return ('value' in descriptor &&
|
|
1254
|
+
descriptor.enumerable === true &&
|
|
1255
|
+
descriptor.configurable === true &&
|
|
1256
|
+
descriptor.writable === true);
|
|
1257
|
+
})) {
|
|
1258
|
+
// Define once from descriptors: never read seed getters or assign an
|
|
1259
|
+
// own __proto__ through a setter. Spread only this private data seed.
|
|
1260
|
+
shape.data = Object.create(Object.prototype, descriptors);
|
|
1261
|
+
}
|
|
1232
1262
|
bases.set(base, shape);
|
|
1233
1263
|
}
|
|
1234
|
-
const copy =
|
|
1264
|
+
const copy = shape.data === undefined
|
|
1265
|
+
? Object.create(shape.prototype, shape.descriptors)
|
|
1266
|
+
: { ...shape.data };
|
|
1267
|
+
if (shape.data !== undefined && shape.prototype === null)
|
|
1268
|
+
Object.setPrototypeOf(copy, null);
|
|
1235
1269
|
return Object.assign(copy, assigned);
|
|
1236
1270
|
};
|
|
1237
1271
|
// Guard-source literals first: the likeliest matches are tried earliest.
|
|
@@ -1284,8 +1318,8 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1284
1318
|
reachedValues++;
|
|
1285
1319
|
values.push(value);
|
|
1286
1320
|
};
|
|
1287
|
-
function* candidateValues(key, hasBaseline, baseline) {
|
|
1288
|
-
if (hasBaseline)
|
|
1321
|
+
function* candidateValues(key, hasBaseline, baseline, deferBaseline = false) {
|
|
1322
|
+
if (hasBaseline && !deferBaseline)
|
|
1289
1323
|
yield baseline;
|
|
1290
1324
|
const guided = key.startsWith('o:')
|
|
1291
1325
|
? declaredValues.get(key.slice(2))
|
|
@@ -1295,6 +1329,8 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1295
1329
|
if (guided[index] !== baseline)
|
|
1296
1330
|
yield guided[index];
|
|
1297
1331
|
}
|
|
1332
|
+
if (hasBaseline && deferBaseline)
|
|
1333
|
+
yield baseline;
|
|
1298
1334
|
return;
|
|
1299
1335
|
}
|
|
1300
1336
|
// A failed candidate can reveal a fixed-context value needed by this same
|
|
@@ -1303,6 +1339,8 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1303
1339
|
if (!hasBaseline || values[index] !== baseline)
|
|
1304
1340
|
yield values[index];
|
|
1305
1341
|
}
|
|
1342
|
+
if (hasBaseline && deferBaseline)
|
|
1343
|
+
yield baseline;
|
|
1306
1344
|
}
|
|
1307
1345
|
const probeBudget = options.probeBudget ?? { probes: 0 };
|
|
1308
1346
|
const discovered = new Map();
|
|
@@ -1417,12 +1455,13 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1417
1455
|
!discoverShape &&
|
|
1418
1456
|
shapeTag === undefined) {
|
|
1419
1457
|
const payload = payloads.find((item) => item.tag === tag);
|
|
1420
|
-
|
|
1458
|
+
// An assigned field cannot guide another choice, but reading it
|
|
1459
|
+
// must not erase an earlier unresolved descriptor-value hint.
|
|
1460
|
+
if ((varyExisting ||
|
|
1421
1461
|
payload?.varyExisting === true ||
|
|
1422
|
-
payload?.shapeFields?.includes(prop))
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
: `${tag}${prop}`;
|
|
1462
|
+
payload?.shapeFields?.includes(prop)) &&
|
|
1463
|
+
!Object.hasOwn(assigned, prop))
|
|
1464
|
+
descriptorRead = `${tag}${prop}`;
|
|
1426
1465
|
}
|
|
1427
1466
|
return descriptor;
|
|
1428
1467
|
},
|
|
@@ -1502,9 +1541,31 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1502
1541
|
if (!enumerated.has(payload.tag))
|
|
1503
1542
|
continue;
|
|
1504
1543
|
shapeTag = payload.tag;
|
|
1544
|
+
// Overriding existing default data keys preserves their enumerable set.
|
|
1545
|
+
// New keys can encounter inherited setters; keep the original trials
|
|
1546
|
+
// for those, event-level merges and descriptor-backed seeds.
|
|
1547
|
+
const data = bases.get(payload.base)?.data;
|
|
1548
|
+
const assigned = assignment.payloads[payload.tag] ?? {};
|
|
1549
|
+
const unpaddedWidth = payload.eventField !== undefined &&
|
|
1550
|
+
data !== undefined &&
|
|
1551
|
+
!Object.hasOwn(assigned, '__proto__') &&
|
|
1552
|
+
Object.keys(assigned).every((key) => Object.hasOwn(data, key))
|
|
1553
|
+
? Object.keys(data).length
|
|
1554
|
+
: undefined;
|
|
1555
|
+
let previousWidth;
|
|
1505
1556
|
for (shapeWidth = 1; shapeWidth <= 4; shapeWidth++) {
|
|
1557
|
+
coverageCheckpoint();
|
|
1506
1558
|
if (++probeBudget.probes > MAX_PROBES)
|
|
1507
1559
|
return [...reads];
|
|
1560
|
+
// Keep every logical trial's charge, but evaluate an identical
|
|
1561
|
+
// guidance-only padding shape once within this payload/read pass.
|
|
1562
|
+
// The first selected-shape trace remains separate from trace() above.
|
|
1563
|
+
const width = unpaddedWidth === undefined
|
|
1564
|
+
? undefined
|
|
1565
|
+
: Math.max(unpaddedWidth, shapeWidth);
|
|
1566
|
+
if (width !== undefined && width === previousWidth)
|
|
1567
|
+
continue;
|
|
1568
|
+
previousWidth = width;
|
|
1508
1569
|
trace();
|
|
1509
1570
|
}
|
|
1510
1571
|
}
|
|
@@ -1556,7 +1617,9 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1556
1617
|
};
|
|
1557
1618
|
});
|
|
1558
1619
|
}
|
|
1559
|
-
|
|
1620
|
+
function* search(assignment, depth, deferred) {
|
|
1621
|
+
// Resume before evaluation so the other traversal shares every probe charge.
|
|
1622
|
+
yield;
|
|
1560
1623
|
coverageCheckpoint();
|
|
1561
1624
|
if (probeBudget.probes > MAX_PROBES)
|
|
1562
1625
|
return undefined;
|
|
@@ -1588,7 +1651,9 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1588
1651
|
const baseline = hasBaseline
|
|
1589
1652
|
? base[field]
|
|
1590
1653
|
: undefined;
|
|
1591
|
-
for (const value of candidateValues(key, hasBaseline, baseline
|
|
1654
|
+
for (const value of candidateValues(key, hasBaseline, baseline, deferred &&
|
|
1655
|
+
payload?.shapeFields?.includes(field) === true &&
|
|
1656
|
+
baseline === null)) {
|
|
1592
1657
|
coverageCheckpoint();
|
|
1593
1658
|
if (probeBudget.probes > MAX_PROBES)
|
|
1594
1659
|
return undefined;
|
|
@@ -1609,13 +1674,13 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1609
1674
|
},
|
|
1610
1675
|
},
|
|
1611
1676
|
};
|
|
1612
|
-
const found = search(next, nextDepth);
|
|
1677
|
+
const found = yield* search(next, nextDepth, deferred);
|
|
1613
1678
|
if (found !== undefined)
|
|
1614
1679
|
return found;
|
|
1615
1680
|
}
|
|
1616
1681
|
}
|
|
1617
1682
|
return undefined;
|
|
1618
|
-
}
|
|
1683
|
+
}
|
|
1619
1684
|
const shapes = payloads;
|
|
1620
1685
|
const slots = shapes.flatMap((payload, index) => (payload.shapeFields ?? []).map((field) => ({ index, field })));
|
|
1621
1686
|
if (slots.length > 4)
|
|
@@ -1636,7 +1701,34 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1636
1701
|
}
|
|
1637
1702
|
return { ...payload, base, shapeFields: fields };
|
|
1638
1703
|
});
|
|
1639
|
-
const
|
|
1704
|
+
const paired = payloads.some((payload) => (payload.shapeFields?.length ?? 0) > 0);
|
|
1705
|
+
const continuations = [
|
|
1706
|
+
search(initial, 0, false),
|
|
1707
|
+
...(paired ? [search(initial, 0, true)] : []),
|
|
1708
|
+
];
|
|
1709
|
+
const active = continuations.map(() => true);
|
|
1710
|
+
let found;
|
|
1711
|
+
try {
|
|
1712
|
+
while (active.some(Boolean) && found === undefined) {
|
|
1713
|
+
for (let index = 0; index < continuations.length; index++) {
|
|
1714
|
+
if (!active[index])
|
|
1715
|
+
continue;
|
|
1716
|
+
const step = continuations[index].next();
|
|
1717
|
+
if (step.done) {
|
|
1718
|
+
active[index] = false;
|
|
1719
|
+
if (step.value !== undefined) {
|
|
1720
|
+
found = step.value;
|
|
1721
|
+
break;
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
finally {
|
|
1728
|
+
// Neither continuation may retain a suspended read across presence masks.
|
|
1729
|
+
for (const continuation of continuations)
|
|
1730
|
+
continuation.return(undefined);
|
|
1731
|
+
}
|
|
1640
1732
|
if (found === undefined)
|
|
1641
1733
|
continue;
|
|
1642
1734
|
for (const payload of payloads) {
|
|
@@ -1971,6 +2063,7 @@ async function replayCoveragePath(machine, nodes, path) {
|
|
|
1971
2063
|
}
|
|
1972
2064
|
/** Finite path replay, including bounded canonical question/reply revisits. */
|
|
1973
2065
|
async function searchCoverageEntry(machine, target, refs, captains, playbooks, candidates, check) {
|
|
2066
|
+
const budget = coverageRuns.getStore().coverage;
|
|
1974
2067
|
const nodes = coverageNodes(captains, playbooks);
|
|
1975
2068
|
const nodesForTarget = (raw, source) => {
|
|
1976
2069
|
const targetName = rawArmTarget(raw);
|
|
@@ -2015,7 +2108,7 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2015
2108
|
false);
|
|
2016
2109
|
const limitations = new Set();
|
|
2017
2110
|
let inputFailure;
|
|
2018
|
-
while (queue.length > 0 && attempts <
|
|
2111
|
+
while (queue.length > 0 && attempts < budget.maxAttempts) {
|
|
2019
2112
|
await coverageYield();
|
|
2020
2113
|
let pathIndex = 0;
|
|
2021
2114
|
for (let scanned = 0; scanned < rootFamilies.length; scanned++) {
|
|
@@ -2047,8 +2140,8 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2047
2140
|
// authored prefix before considering successors, charging that replay
|
|
2048
2141
|
// against the same attempt limit.
|
|
2049
2142
|
replay.actor.stop();
|
|
2050
|
-
if (attempts >=
|
|
2051
|
-
limitations.add(`exhausted ${
|
|
2143
|
+
if (attempts >= budget.maxAttempts) {
|
|
2144
|
+
limitations.add(`exhausted ${budget.maxAttempts}-attempt path budget`);
|
|
2052
2145
|
break;
|
|
2053
2146
|
}
|
|
2054
2147
|
attempts++;
|
|
@@ -2098,8 +2191,8 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2098
2191
|
}
|
|
2099
2192
|
const continuations = [];
|
|
2100
2193
|
for (const step of nextSteps) {
|
|
2101
|
-
if (path.steps.length + 1 >=
|
|
2102
|
-
limitations.add(`exhausted ${
|
|
2194
|
+
if (path.steps.length + 1 >= budget.maxInvocations) {
|
|
2195
|
+
limitations.add(`exhausted ${budget.maxInvocations}-invocation path depth`);
|
|
2103
2196
|
continue;
|
|
2104
2197
|
}
|
|
2105
2198
|
const visited = [path.root, ...path.steps.map((step) => step.next)].map(coverageNodeKey);
|
|
@@ -2126,7 +2219,7 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2126
2219
|
replay.actor.stop();
|
|
2127
2220
|
if ((!covered || needsLiteral()) &&
|
|
2128
2221
|
path.alternatives !== undefined &&
|
|
2129
|
-
attempts <
|
|
2222
|
+
attempts < budget.maxAttempts) {
|
|
2130
2223
|
const next = path.alternatives.next();
|
|
2131
2224
|
if (!next.done)
|
|
2132
2225
|
queue.push({
|
|
@@ -2139,7 +2232,7 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2139
2232
|
}
|
|
2140
2233
|
}
|
|
2141
2234
|
if (queue.length > 0)
|
|
2142
|
-
limitations.add(`exhausted ${
|
|
2235
|
+
limitations.add(`exhausted ${budget.maxAttempts}-attempt path budget`);
|
|
2143
2236
|
return {
|
|
2144
2237
|
covered: transitionCovered,
|
|
2145
2238
|
entered,
|
|
@@ -2884,7 +2977,8 @@ async function probeParallelJoins(machine, parallel, refs, captains, interruptVa
|
|
|
2884
2977
|
* guard search, and a final scheduling margin. Generated tests use this instead
|
|
2885
2978
|
* of Vitest's five-second default.
|
|
2886
2979
|
*/
|
|
2887
|
-
export function fsmCoverageTestTimeout(fsmModule) {
|
|
2980
|
+
export function fsmCoverageTestTimeout(fsmModule, coverage) {
|
|
2981
|
+
const budget = resolveCoverageBudget(coverage);
|
|
2888
2982
|
const machine = findMachine(fsmModule);
|
|
2889
2983
|
const config = machine.config;
|
|
2890
2984
|
const refs = stateRefs(config);
|
|
@@ -2995,22 +3089,22 @@ export function fsmCoverageTestTimeout(fsmModule) {
|
|
|
2995
3089
|
guardProbeCalls +=
|
|
2996
3090
|
pathSearches *
|
|
2997
3091
|
(nodes.length * (1 + entryArmCount) +
|
|
2998
|
-
|
|
3092
|
+
budget.maxAttempts * 2 * maxNodeCandidates);
|
|
2999
3093
|
// Parallel question/join helpers retain their independent entry probes.
|
|
3000
3094
|
guardProbeCalls += 2 * parallels.length;
|
|
3001
|
-
// Each charged replay contains at most
|
|
3002
|
-
//
|
|
3095
|
+
// Each charged replay contains at most the selected invocation count and
|
|
3096
|
+
// one fewer parked question waits, plus two target/reply settles and
|
|
3003
3097
|
// no-transition checks.
|
|
3004
3098
|
const pathSettles = pathSearches *
|
|
3005
|
-
|
|
3006
|
-
((2 *
|
|
3099
|
+
budget.maxAttempts *
|
|
3100
|
+
((2 * budget.maxInvocations + 1) * PARALLEL_SETTLE_MS + 2 * 10);
|
|
3007
3101
|
const parallelSettles = parallels.reduce((total, parallel) => total +
|
|
3008
3102
|
2 * PARALLEL_QUESTION_SETTLE_MS +
|
|
3009
3103
|
transitionArms(parallel.state.onDone).length *
|
|
3010
3104
|
MAX_PARALLEL_COMBINATIONS *
|
|
3011
3105
|
PARALLEL_SETTLE_MS, 0);
|
|
3012
3106
|
const guardAllowance = guardProbeCalls * Math.ceil(MAX_PROBES / PROBES_PER_TIMEOUT_MILLISECOND);
|
|
3013
|
-
return Math.min(
|
|
3107
|
+
return Math.min(budget.maxDurationMs, Math.max(MIN_COVERAGE_TEST_TIMEOUT_MS, rootSettles +
|
|
3014
3108
|
entrySettles +
|
|
3015
3109
|
captainSettles +
|
|
3016
3110
|
pathSettles +
|
|
@@ -3030,6 +3124,7 @@ export async function checkFsmCoverage(fsmModule, opts = {}) {
|
|
|
3030
3124
|
}
|
|
3031
3125
|
/** Conformance suites replay only pending literal bindings; coverage stays separate. */
|
|
3032
3126
|
export async function checkGearsFsmConformanceAsync(gears, fsmModule, options = {}) {
|
|
3127
|
+
options = { ...options, coverage: resolveCoverageBudget(options.coverage) };
|
|
3033
3128
|
const { findings, literalChecks } = prepareGearsFsmConformance(gears, findMachine(fsmModule).config, { concurrentRoleSets: findConcurrentRoleSets(fsmModule), ...options });
|
|
3034
3129
|
options.signal?.throwIfAborted();
|
|
3035
3130
|
return findings.length > 0 || !literalChecks.pending()
|
|
@@ -3038,6 +3133,7 @@ export async function checkGearsFsmConformanceAsync(gears, fsmModule, options =
|
|
|
3038
3133
|
}
|
|
3039
3134
|
/** One bounded replay owns transition coverage and reached literal-child proof. */
|
|
3040
3135
|
export async function checkGearsFsmArtifact(gears, fsmModule, options = {}) {
|
|
3136
|
+
options = { ...options, coverage: resolveCoverageBudget(options.coverage) };
|
|
3041
3137
|
const { findings, literalChecks } = prepareGearsFsmConformance(gears, findMachine(fsmModule).config, {
|
|
3042
3138
|
concurrentRoleSets: findConcurrentRoleSets(fsmModule),
|
|
3043
3139
|
...options,
|
|
@@ -3048,16 +3144,17 @@ export async function checkGearsFsmArtifact(gears, fsmModule, options = {}) {
|
|
|
3048
3144
|
: fsmCoverage(fsmModule, options, literalChecks);
|
|
3049
3145
|
}
|
|
3050
3146
|
async function fsmCoverage(fsmModule, opts = {}, literalChecks, literalOnly = false) {
|
|
3147
|
+
const coverage = resolveCoverageBudget(opts.coverage);
|
|
3051
3148
|
opts.signal?.throwIfAborted();
|
|
3052
3149
|
if (opts.timeoutMs !== undefined &&
|
|
3053
3150
|
(!Number.isFinite(opts.timeoutMs) || opts.timeoutMs <= 0))
|
|
3054
3151
|
throw new RangeError('FSM coverage timeout must be a positive finite number');
|
|
3055
3152
|
const started = performance.now();
|
|
3056
3153
|
const run = {
|
|
3154
|
+
coverage,
|
|
3057
3155
|
literalChecks,
|
|
3058
3156
|
signal: opts.signal,
|
|
3059
|
-
deadline: started +
|
|
3060
|
-
Math.min(opts.timeoutMs ?? Infinity, MAX_COVERAGE_TEST_TIMEOUT_MS),
|
|
3157
|
+
deadline: started + Math.min(opts.timeoutMs ?? Infinity, coverage.maxDurationMs),
|
|
3061
3158
|
lastYield: started,
|
|
3062
3159
|
actors: new Set(),
|
|
3063
3160
|
questionFindings: new Set(),
|
|
@@ -3066,7 +3163,7 @@ async function fsmCoverage(fsmModule, opts = {}, literalChecks, literalOnly = fa
|
|
|
3066
3163
|
return coverageRuns.run(run, async () => {
|
|
3067
3164
|
let completed = false;
|
|
3068
3165
|
try {
|
|
3069
|
-
run.deadline = Math.min(run.deadline, started + fsmCoverageTestTimeout(fsmModule));
|
|
3166
|
+
run.deadline = Math.min(run.deadline, started + fsmCoverageTestTimeout(fsmModule, coverage));
|
|
3070
3167
|
await coverageYield(true);
|
|
3071
3168
|
const schema = resolveArtifactSchemaForVerification({
|
|
3072
3169
|
config: findMachine(fsmModule).config,
|
|
@@ -3754,6 +3851,7 @@ async function runFsmCoverage(fsmModule, sourceText) {
|
|
|
3754
3851
|
* beside the artifacts (verification-6).
|
|
3755
3852
|
*/
|
|
3756
3853
|
export function generateFsmCoverageTest(opts) {
|
|
3854
|
+
const coverage = resolveCoverageBudget(opts.coverage);
|
|
3757
3855
|
const commentBasename = JSON.stringify(opts.basename)
|
|
3758
3856
|
.replaceAll('\u2028', '\\u2028')
|
|
3759
3857
|
.replaceAll('\u2029', '\\u2029');
|
|
@@ -3773,14 +3871,16 @@ import { describe, expect, it } from 'vitest';
|
|
|
3773
3871
|
import { checkFsmCoverage, fsmCoverageTestTimeout } from ${verifyModule};
|
|
3774
3872
|
import * as fsm from ${fsmModule};
|
|
3775
3873
|
|
|
3874
|
+
const coverage = ${JSON.stringify(coverage)};
|
|
3875
|
+
|
|
3776
3876
|
describe(${suiteName}, () => {
|
|
3777
3877
|
it('reaches every declared transition', async () => {
|
|
3778
3878
|
const sourceText = readFileSync(
|
|
3779
3879
|
fileURLToPath(new URL(${fsmSourceFile}, import.meta.url)),
|
|
3780
3880
|
'utf8',
|
|
3781
3881
|
);
|
|
3782
|
-
expect(await checkFsmCoverage(fsm, { sourceText${opts.artifactSchema === undefined ? '' : `, artifactSchema: ${opts.artifactSchema}`} })).toEqual([]);
|
|
3783
|
-
}, fsmCoverageTestTimeout(fsm));
|
|
3882
|
+
expect(await checkFsmCoverage(fsm, { coverage, sourceText${opts.artifactSchema === undefined ? '' : `, artifactSchema: ${opts.artifactSchema}`} })).toEqual([]);
|
|
3883
|
+
}, fsmCoverageTestTimeout(fsm, coverage));
|
|
3784
3884
|
});
|
|
3785
3885
|
`;
|
|
3786
3886
|
}
|
|
@@ -3793,6 +3893,7 @@ describe(${suiteName}, () => {
|
|
|
3793
3893
|
* @throws when the `fsm` artifact cannot be imported or exports no machine.
|
|
3794
3894
|
*/
|
|
3795
3895
|
export async function emitFsmCoverageTest(opts) {
|
|
3896
|
+
const coverage = resolveCoverageBudget(opts.coverage);
|
|
3796
3897
|
const fsmPath = join(opts.artifactDir, `${opts.basename}.fsm.ts`);
|
|
3797
3898
|
const module = await loadFsmModule(fsmPath);
|
|
3798
3899
|
const schema = resolveArtifactSchemaForVerification({
|
|
@@ -3804,12 +3905,14 @@ export async function emitFsmCoverageTest(opts) {
|
|
|
3804
3905
|
});
|
|
3805
3906
|
const artifactSchema = schema.artifactSchema;
|
|
3806
3907
|
const findings = await checkFsmCoverage(module, {
|
|
3908
|
+
coverage,
|
|
3807
3909
|
sourceText: await readFile(fsmPath, 'utf8'),
|
|
3808
3910
|
...(opts.artifactSchema === undefined
|
|
3809
3911
|
? {}
|
|
3810
3912
|
: { artifactSchema: opts.artifactSchema }),
|
|
3811
3913
|
});
|
|
3812
3914
|
const content = generateFsmCoverageTest({
|
|
3915
|
+
coverage,
|
|
3813
3916
|
basename: opts.basename,
|
|
3814
3917
|
fsmModule: `./${opts.basename}.fsm.js`,
|
|
3815
3918
|
fsmSourceFile: `./${opts.basename}.fsm.ts`,
|