@sublang/slc 0.16.6 → 0.16.8
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/runner.d.ts.map +1 -1
- package/dist/runner.js +2 -8
- package/dist/runner.js.map +1 -1
- package/dist/verify-coverage.d.ts +13 -4
- package/dist/verify-coverage.d.ts.map +1 -1
- package/dist/verify-coverage.js +119 -12
- package/dist/verify-coverage.js.map +1 -1
- package/dist/verify.d.ts +31 -8
- package/dist/verify.d.ts.map +1 -1
- package/dist/verify.js +704 -37
- package/dist/verify.js.map +1 -1
- package/package.json +1 -1
package/dist/verify-coverage.js
CHANGED
|
@@ -23,8 +23,9 @@ import { AsyncLocalStorage } from 'node:async_hooks';
|
|
|
23
23
|
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
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
26
27
|
import { createActor, fromPromise } from 'xstate';
|
|
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
|
+
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';
|
|
28
29
|
/** The `gears2fsm`-mandated captain actor name a machine declares. */
|
|
29
30
|
export const CAPTAIN_ACTOR = 'captain';
|
|
30
31
|
// Each check owns its resources, including concurrent checks and async actor
|
|
@@ -1026,7 +1027,7 @@ function entryDriveForRef(machine, refs, target, extraValues = [], initialContex
|
|
|
1026
1027
|
return first.done ? undefined : first.value;
|
|
1027
1028
|
}
|
|
1028
1029
|
/** Lazy one-field public events, never new context or an unguarded entry. */
|
|
1029
|
-
function* entryDrivesForRef(machine, refs, target, extraValues = [], initialContext = initializedCoverageContext(machine)) {
|
|
1030
|
+
function* entryDrivesForRef(machine, refs, target, extraValues = [], initialContext = initializedCoverageContext(machine), allEntrySurfaces = false) {
|
|
1030
1031
|
const initialPath = initialActiveRefs(machine.config, refs);
|
|
1031
1032
|
const surfaces = [
|
|
1032
1033
|
...initialPath
|
|
@@ -1114,7 +1115,9 @@ function* entryDrivesForRef(machine, refs, target, extraValues = [], initialCont
|
|
|
1114
1115
|
}
|
|
1115
1116
|
}
|
|
1116
1117
|
}
|
|
1117
|
-
|
|
1118
|
+
// Literal proof may need another authored entry on this same iterator.
|
|
1119
|
+
if (!allEntrySurfaces)
|
|
1120
|
+
return;
|
|
1118
1121
|
}
|
|
1119
1122
|
}
|
|
1120
1123
|
}
|
|
@@ -1177,7 +1180,7 @@ function minedLiterals(fn) {
|
|
|
1177
1180
|
// helper call sites, invisible in the guard closures themselves; the module's
|
|
1178
1181
|
// identifier-like string literals recover them without dragging prompt prose
|
|
1179
1182
|
// into the candidate pool.
|
|
1180
|
-
const IDENTIFIER_LITERAL = /^[A-Za-z][A-Za-z0-9_-]
|
|
1183
|
+
const IDENTIFIER_LITERAL = /^[A-Za-z][A-Za-z0-9_-]*$/;
|
|
1181
1184
|
// Bound comparisons (cycle limits, retry counters, exit statuses) route on
|
|
1182
1185
|
// integers that neither the string miner nor the generic value pool supplies:
|
|
1183
1186
|
// GENERIC_VALUES carries only 1, and minedLiterals matches quoted text alone. A
|
|
@@ -1333,6 +1336,9 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1333
1336
|
const readsUnder = (assignment, discoverShape = false) => {
|
|
1334
1337
|
coverageCheckpoint();
|
|
1335
1338
|
const reads = new Set();
|
|
1339
|
+
// Enumeration also queries descriptors. Prefer semantic property reads so
|
|
1340
|
+
// those incidental queries cannot starve the existing bounded search.
|
|
1341
|
+
let descriptorRead;
|
|
1336
1342
|
const enumerated = new Set();
|
|
1337
1343
|
let declaredField;
|
|
1338
1344
|
const contextRead = (field) => {
|
|
@@ -1404,11 +1410,27 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1404
1410
|
};
|
|
1405
1411
|
}
|
|
1406
1412
|
}
|
|
1413
|
+
if (tag !== 'c:' &&
|
|
1414
|
+
typeof prop === 'string' &&
|
|
1415
|
+
descriptor !== undefined &&
|
|
1416
|
+
'value' in descriptor &&
|
|
1417
|
+
!discoverShape &&
|
|
1418
|
+
shapeTag === undefined) {
|
|
1419
|
+
const payload = payloads.find((item) => item.tag === tag);
|
|
1420
|
+
if (varyExisting ||
|
|
1421
|
+
payload?.varyExisting === true ||
|
|
1422
|
+
payload?.shapeFields?.includes(prop))
|
|
1423
|
+
descriptorRead = Object.hasOwn(assigned, prop)
|
|
1424
|
+
? undefined
|
|
1425
|
+
: `${tag}${prop}`;
|
|
1426
|
+
}
|
|
1407
1427
|
return descriptor;
|
|
1408
1428
|
},
|
|
1409
1429
|
get(target, prop) {
|
|
1410
1430
|
if (typeof prop !== 'string')
|
|
1411
1431
|
return undefined;
|
|
1432
|
+
if (tag !== 'c:' && !discoverShape && shapeTag === undefined)
|
|
1433
|
+
descriptorRead = undefined;
|
|
1412
1434
|
if (tag === 'c:')
|
|
1413
1435
|
contextRead(prop);
|
|
1414
1436
|
else if (tag === 'o:' && options.declaredResultFields !== undefined) {
|
|
@@ -1487,7 +1509,18 @@ function probeGuardAssignment(guard, fixedEvent, payloads, extraValues, options
|
|
|
1487
1509
|
}
|
|
1488
1510
|
}
|
|
1489
1511
|
}
|
|
1490
|
-
|
|
1512
|
+
// An explicit assignable read is the next useful constraint. Descriptor
|
|
1513
|
+
// queries made by enumeration are fallback guidance only when none remains.
|
|
1514
|
+
return [
|
|
1515
|
+
...reads,
|
|
1516
|
+
...([...reads].some((key) => !key.startsWith('c:') ||
|
|
1517
|
+
(options.assignContext !== false &&
|
|
1518
|
+
!options.fixedContextFields?.includes(key.slice(2))))
|
|
1519
|
+
? []
|
|
1520
|
+
: descriptorRead === undefined
|
|
1521
|
+
? []
|
|
1522
|
+
: [descriptorRead]),
|
|
1523
|
+
];
|
|
1491
1524
|
};
|
|
1492
1525
|
const initial = {
|
|
1493
1526
|
context: baseContext,
|
|
@@ -1722,7 +1755,9 @@ function callCount(calls, captain) {
|
|
|
1722
1755
|
/** One public drive or the actual initialized state, never a private jump. */
|
|
1723
1756
|
function childCoverageDrive(machine, refs, ref, targetId, candidates) {
|
|
1724
1757
|
const interrupt = interruptDriveForRef(machine, refs, ref, targetId, candidates);
|
|
1725
|
-
const alternatives = entryDrivesForRef(machine, refs, ref, candidates)
|
|
1758
|
+
const alternatives = entryDrivesForRef(machine, refs, ref, candidates, coverageRuns.getStore()?.literalChecks?.pending()
|
|
1759
|
+
? initializedMachineContext(machine)
|
|
1760
|
+
: initializedCoverageContext(machine), coverageRuns.getStore()?.literalChecks?.pending() ?? false);
|
|
1726
1761
|
// A valid interrupt need not preserve every public entry's reached context.
|
|
1727
1762
|
if (interrupt.satisfiable)
|
|
1728
1763
|
return { drive: interrupt, alternatives };
|
|
@@ -1835,6 +1870,15 @@ function coverageArmResults(machine, node, outcome, armIndex, context, input, ca
|
|
|
1835
1870
|
return results;
|
|
1836
1871
|
}
|
|
1837
1872
|
}
|
|
1873
|
+
// The public successful child envelope may omit output entirely. Probe that
|
|
1874
|
+
// one concrete value without object synthesis or mutable reached context.
|
|
1875
|
+
if (node.kind === 'child' &&
|
|
1876
|
+
outcome === 'onDone' &&
|
|
1877
|
+
probeGuardAssignment(guard.run, { ...event, output: undefined }, [], [], {
|
|
1878
|
+
initialContext: context,
|
|
1879
|
+
assignContext: false,
|
|
1880
|
+
}) !== undefined)
|
|
1881
|
+
results.push(undefined);
|
|
1838
1882
|
return results;
|
|
1839
1883
|
}
|
|
1840
1884
|
/** Replay every prefix transition; no persisted private-state restoration. */
|
|
@@ -1858,6 +1902,16 @@ async function replayCoveragePath(machine, nodes, path) {
|
|
|
1858
1902
|
});
|
|
1859
1903
|
};
|
|
1860
1904
|
const actor = makeActor(machine, script, script, path.drive?.context);
|
|
1905
|
+
const trustedEntry = path.drive === undefined ||
|
|
1906
|
+
isDeepStrictEqual(path.drive.context, initializedMachineContext(machine));
|
|
1907
|
+
const observe = (current) => {
|
|
1908
|
+
if (trustedEntry &&
|
|
1909
|
+
current?.node.kind === 'child' &&
|
|
1910
|
+
atState(current.node.value.ref)(actor.getSnapshot()))
|
|
1911
|
+
coverageRuns
|
|
1912
|
+
.getStore()
|
|
1913
|
+
?.literalChecks?.observe(current.node.value.invocation, actor.getSnapshot().context, current.input);
|
|
1914
|
+
};
|
|
1861
1915
|
gate.armed = true;
|
|
1862
1916
|
if (path.drive !== undefined)
|
|
1863
1917
|
actor.send(path.drive.event);
|
|
@@ -1874,6 +1928,7 @@ async function replayCoveragePath(machine, nodes, path) {
|
|
|
1874
1928
|
completedPrefix = false;
|
|
1875
1929
|
break;
|
|
1876
1930
|
}
|
|
1931
|
+
observe(current);
|
|
1877
1932
|
pending = undefined;
|
|
1878
1933
|
expected = step.next;
|
|
1879
1934
|
current.complete(step.result);
|
|
@@ -1897,6 +1952,7 @@ async function replayCoveragePath(machine, nodes, path) {
|
|
|
1897
1952
|
}
|
|
1898
1953
|
await wait();
|
|
1899
1954
|
const snapshot = actor.getSnapshot();
|
|
1955
|
+
observe(pending);
|
|
1900
1956
|
const failure = actor.coverageErrors.find(({ eventType }) => eventType ===
|
|
1901
1957
|
`xstate.error.actor.${invocationActorId(machine, expected.value)}`);
|
|
1902
1958
|
return {
|
|
@@ -1947,6 +2003,10 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
1947
2003
|
}
|
|
1948
2004
|
let attempts = 0;
|
|
1949
2005
|
let entered = false;
|
|
2006
|
+
let transitionCovered = false;
|
|
2007
|
+
const needsLiteral = () => target.kind === 'child' &&
|
|
2008
|
+
(coverageRuns.getStore()?.literalChecks?.needs(target.value.invocation) ??
|
|
2009
|
+
false);
|
|
1950
2010
|
const limitations = new Set();
|
|
1951
2011
|
let inputFailure;
|
|
1952
2012
|
while (queue.length > 0 && attempts < MAX_COVERAGE_PATH_ATTEMPTS) {
|
|
@@ -1963,7 +2023,9 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
1963
2023
|
entered = true;
|
|
1964
2024
|
if (await check(replay.actor, replay.pending)) {
|
|
1965
2025
|
covered = true;
|
|
1966
|
-
|
|
2026
|
+
transitionCovered = true;
|
|
2027
|
+
if (!needsLiteral())
|
|
2028
|
+
return { covered: true, entered };
|
|
1967
2029
|
}
|
|
1968
2030
|
// A target check may have completed its actor. Re-enter the same
|
|
1969
2031
|
// authored prefix before considering successors, charging that replay
|
|
@@ -2010,7 +2072,9 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2010
2072
|
for (const result of coverageArmResults(machine, node, 'onDone', index, context, pending.input, candidates, undefined, NEEDS_BOSS_REPLY)) {
|
|
2011
2073
|
// A malformed question can legitimately reach a parked failure;
|
|
2012
2074
|
// ordinary arm coverage owns it, not a question/reply prefix.
|
|
2013
|
-
if (result
|
|
2075
|
+
if (result === undefined ||
|
|
2076
|
+
result instanceof Error ||
|
|
2077
|
+
typeof result.question !== 'string')
|
|
2014
2078
|
continue;
|
|
2015
2079
|
nextSteps.push({ node, result, next: node, questionWait: waitRef });
|
|
2016
2080
|
}
|
|
@@ -2044,7 +2108,7 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2044
2108
|
}
|
|
2045
2109
|
finally {
|
|
2046
2110
|
replay.actor.stop();
|
|
2047
|
-
if (!covered &&
|
|
2111
|
+
if ((!covered || needsLiteral()) &&
|
|
2048
2112
|
path.alternatives !== undefined &&
|
|
2049
2113
|
attempts < MAX_COVERAGE_PATH_ATTEMPTS) {
|
|
2050
2114
|
const next = path.alternatives.next();
|
|
@@ -2061,7 +2125,7 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2061
2125
|
if (queue.length > 0)
|
|
2062
2126
|
limitations.add(`exhausted ${MAX_COVERAGE_PATH_ATTEMPTS}-attempt path budget`);
|
|
2063
2127
|
return {
|
|
2064
|
-
covered:
|
|
2128
|
+
covered: transitionCovered,
|
|
2065
2129
|
entered,
|
|
2066
2130
|
...(limitations.size === 0
|
|
2067
2131
|
? {}
|
|
@@ -2551,6 +2615,7 @@ function reachedBossQuestionFinding(machine, captain, actor, output) {
|
|
|
2551
2615
|
typeof input.sourceItem === 'string' &&
|
|
2552
2616
|
record.sourceItem === input.sourceItem &&
|
|
2553
2617
|
askerMatches &&
|
|
2618
|
+
output !== undefined &&
|
|
2554
2619
|
!(output instanceof Error) &&
|
|
2555
2620
|
typeof output.question === 'string' &&
|
|
2556
2621
|
record.question === output.question
|
|
@@ -2902,7 +2967,7 @@ export function fsmCoverageTestTimeout(fsmModule) {
|
|
|
2902
2967
|
const done = transitionArms(node.value.invocation.onDone).length;
|
|
2903
2968
|
const error = transitionArms(node.value.invocation.onError).length;
|
|
2904
2969
|
if (node.kind === 'child')
|
|
2905
|
-
return
|
|
2970
|
+
return 4 * done + 4 * error;
|
|
2906
2971
|
const keys = Object.keys(node.value.binding.result);
|
|
2907
2972
|
const candidates = node.value.binding.actor === 'script'
|
|
2908
2973
|
? keys.length * MAX_SCRIPT_EXIT_STATUSES
|
|
@@ -2945,12 +3010,35 @@ export function fsmCoverageTestTimeout(fsmModule) {
|
|
|
2945
3010
|
* surface entirely, in which case interrupt coverage is skipped.
|
|
2946
3011
|
*/
|
|
2947
3012
|
export async function checkFsmCoverage(fsmModule, opts = {}) {
|
|
3013
|
+
return fsmCoverage(fsmModule, opts);
|
|
3014
|
+
}
|
|
3015
|
+
/** Conformance suites replay only pending literal bindings; coverage stays separate. */
|
|
3016
|
+
export async function checkGearsFsmConformanceAsync(gears, fsmModule, options = {}) {
|
|
3017
|
+
const { findings, literalChecks } = prepareGearsFsmConformance(gears, findMachine(fsmModule).config, { concurrentRoleSets: findConcurrentRoleSets(fsmModule), ...options });
|
|
3018
|
+
options.signal?.throwIfAborted();
|
|
3019
|
+
return findings.length > 0 || !literalChecks.pending()
|
|
3020
|
+
? findings
|
|
3021
|
+
: fsmCoverage(fsmModule, options, literalChecks, true);
|
|
3022
|
+
}
|
|
3023
|
+
/** One bounded replay owns transition coverage and reached literal-child proof. */
|
|
3024
|
+
export async function checkGearsFsmArtifact(gears, fsmModule, options = {}) {
|
|
3025
|
+
const { findings, literalChecks } = prepareGearsFsmConformance(gears, findMachine(fsmModule).config, {
|
|
3026
|
+
concurrentRoleSets: findConcurrentRoleSets(fsmModule),
|
|
3027
|
+
...options,
|
|
3028
|
+
});
|
|
3029
|
+
options.signal?.throwIfAborted();
|
|
3030
|
+
return findings.length > 0
|
|
3031
|
+
? findings
|
|
3032
|
+
: fsmCoverage(fsmModule, options, literalChecks);
|
|
3033
|
+
}
|
|
3034
|
+
async function fsmCoverage(fsmModule, opts = {}, literalChecks, literalOnly = false) {
|
|
2948
3035
|
opts.signal?.throwIfAborted();
|
|
2949
3036
|
if (opts.timeoutMs !== undefined &&
|
|
2950
3037
|
(!Number.isFinite(opts.timeoutMs) || opts.timeoutMs <= 0))
|
|
2951
3038
|
throw new RangeError('FSM coverage timeout must be a positive finite number');
|
|
2952
3039
|
const started = performance.now();
|
|
2953
3040
|
const run = {
|
|
3041
|
+
literalChecks,
|
|
2954
3042
|
signal: opts.signal,
|
|
2955
3043
|
deadline: started +
|
|
2956
3044
|
Math.min(opts.timeoutMs ?? Infinity, MAX_COVERAGE_TEST_TIMEOUT_MS),
|
|
@@ -2974,8 +3062,11 @@ export async function checkFsmCoverage(fsmModule, opts = {}) {
|
|
|
2974
3062
|
run.artifactSchema = schema.artifactSchema;
|
|
2975
3063
|
const findings = [
|
|
2976
3064
|
...schema.findings,
|
|
2977
|
-
...(
|
|
3065
|
+
...(literalOnly
|
|
3066
|
+
? await reachedLiteralContexts(fsmModule, opts.sourceText ?? '', literalChecks)
|
|
3067
|
+
: await runFsmCoverage(fsmModule, opts.sourceText ?? '')),
|
|
2978
3068
|
...run.questionFindings,
|
|
3069
|
+
...(literalChecks?.findings() ?? []),
|
|
2979
3070
|
];
|
|
2980
3071
|
await coverageYield(true);
|
|
2981
3072
|
completed = true;
|
|
@@ -2986,6 +3077,22 @@ export async function checkFsmCoverage(fsmModule, opts = {}) {
|
|
|
2986
3077
|
}
|
|
2987
3078
|
});
|
|
2988
3079
|
}
|
|
3080
|
+
/** A conformance-only suite uses one existing bounded search per pending call. */
|
|
3081
|
+
async function reachedLiteralContexts(fsmModule, sourceText, checks) {
|
|
3082
|
+
const machine = findMachine(fsmModule);
|
|
3083
|
+
const refs = stateRefs(machine.config), captains = captainRefs(machine.config), playbooks = playbookRefs(machine.config);
|
|
3084
|
+
const candidates = [
|
|
3085
|
+
...identifierLiterals(sourceText),
|
|
3086
|
+
...numericLiterals(sourceText),
|
|
3087
|
+
];
|
|
3088
|
+
for (const playbook of playbooks) {
|
|
3089
|
+
if (!checks.needs(playbook.invocation))
|
|
3090
|
+
continue;
|
|
3091
|
+
await coverageYield();
|
|
3092
|
+
await searchCoverageEntry(machine, { kind: 'child', value: playbook }, refs, captains, playbooks, candidates, async () => true);
|
|
3093
|
+
}
|
|
3094
|
+
return [];
|
|
3095
|
+
}
|
|
2989
3096
|
async function runFsmCoverage(fsmModule, sourceText) {
|
|
2990
3097
|
const findings = [];
|
|
2991
3098
|
const machine = findMachine(fsmModule);
|