@sublang/slc 0.16.7 → 0.16.9
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 +92 -11
- 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
|
|
@@ -1752,7 +1755,9 @@ function callCount(calls, captain) {
|
|
|
1752
1755
|
/** One public drive or the actual initialized state, never a private jump. */
|
|
1753
1756
|
function childCoverageDrive(machine, refs, ref, targetId, candidates) {
|
|
1754
1757
|
const interrupt = interruptDriveForRef(machine, refs, ref, targetId, candidates);
|
|
1755
|
-
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);
|
|
1756
1761
|
// A valid interrupt need not preserve every public entry's reached context.
|
|
1757
1762
|
if (interrupt.satisfiable)
|
|
1758
1763
|
return { drive: interrupt, alternatives };
|
|
@@ -1897,6 +1902,16 @@ async function replayCoveragePath(machine, nodes, path) {
|
|
|
1897
1902
|
});
|
|
1898
1903
|
};
|
|
1899
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
|
+
};
|
|
1900
1915
|
gate.armed = true;
|
|
1901
1916
|
if (path.drive !== undefined)
|
|
1902
1917
|
actor.send(path.drive.event);
|
|
@@ -1913,6 +1928,7 @@ async function replayCoveragePath(machine, nodes, path) {
|
|
|
1913
1928
|
completedPrefix = false;
|
|
1914
1929
|
break;
|
|
1915
1930
|
}
|
|
1931
|
+
observe(current);
|
|
1916
1932
|
pending = undefined;
|
|
1917
1933
|
expected = step.next;
|
|
1918
1934
|
current.complete(step.result);
|
|
@@ -1936,6 +1952,7 @@ async function replayCoveragePath(machine, nodes, path) {
|
|
|
1936
1952
|
}
|
|
1937
1953
|
await wait();
|
|
1938
1954
|
const snapshot = actor.getSnapshot();
|
|
1955
|
+
observe(pending);
|
|
1939
1956
|
const failure = actor.coverageErrors.find(({ eventType }) => eventType ===
|
|
1940
1957
|
`xstate.error.actor.${invocationActorId(machine, expected.value)}`);
|
|
1941
1958
|
return {
|
|
@@ -1984,13 +2001,33 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
1984
2001
|
if (entry !== undefined)
|
|
1985
2002
|
queue.push({ root: node, ...entry, steps: [] });
|
|
1986
2003
|
}
|
|
2004
|
+
// Family identity is only the declared root invocation. Keep every actual
|
|
2005
|
+
// context, prefix and lazy entry alternative distinct within that family.
|
|
2006
|
+
const rootFamilies = [
|
|
2007
|
+
...new Set(queue.map((path) => coverageNodeKey(path.root))),
|
|
2008
|
+
];
|
|
2009
|
+
let familyCursor = 0;
|
|
1987
2010
|
let attempts = 0;
|
|
1988
2011
|
let entered = false;
|
|
2012
|
+
let transitionCovered = false;
|
|
2013
|
+
const needsLiteral = () => target.kind === 'child' &&
|
|
2014
|
+
(coverageRuns.getStore()?.literalChecks?.needs(target.value.invocation) ??
|
|
2015
|
+
false);
|
|
1989
2016
|
const limitations = new Set();
|
|
1990
2017
|
let inputFailure;
|
|
1991
2018
|
while (queue.length > 0 && attempts < MAX_COVERAGE_PATH_ATTEMPTS) {
|
|
1992
2019
|
await coverageYield();
|
|
1993
|
-
|
|
2020
|
+
let pathIndex = 0;
|
|
2021
|
+
for (let scanned = 0; scanned < rootFamilies.length; scanned++) {
|
|
2022
|
+
const family = rootFamilies[familyCursor];
|
|
2023
|
+
familyCursor = (familyCursor + 1) % rootFamilies.length;
|
|
2024
|
+
const candidate = queue.findIndex((path) => coverageNodeKey(path.root) === family);
|
|
2025
|
+
if (candidate < 0)
|
|
2026
|
+
continue;
|
|
2027
|
+
pathIndex = candidate;
|
|
2028
|
+
break;
|
|
2029
|
+
}
|
|
2030
|
+
const [path] = queue.splice(pathIndex, 1);
|
|
1994
2031
|
attempts++;
|
|
1995
2032
|
let replay = await replayCoveragePath(machine, nodes, path);
|
|
1996
2033
|
let covered = false;
|
|
@@ -2002,7 +2039,9 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2002
2039
|
entered = true;
|
|
2003
2040
|
if (await check(replay.actor, replay.pending)) {
|
|
2004
2041
|
covered = true;
|
|
2005
|
-
|
|
2042
|
+
transitionCovered = true;
|
|
2043
|
+
if (!needsLiteral())
|
|
2044
|
+
return { covered: true, entered };
|
|
2006
2045
|
}
|
|
2007
2046
|
// A target check may have completed its actor. Re-enter the same
|
|
2008
2047
|
// authored prefix before considering successors, charging that replay
|
|
@@ -2080,12 +2119,12 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2080
2119
|
queue.push(successor);
|
|
2081
2120
|
}
|
|
2082
2121
|
// Replay a discovered target, including its canonical question continuation,
|
|
2083
|
-
// before unrelated prefixes; retain candidate order and
|
|
2122
|
+
// before unrelated prefixes in its family; retain candidate order and budgets.
|
|
2084
2123
|
queue.unshift(...continuations);
|
|
2085
2124
|
}
|
|
2086
2125
|
finally {
|
|
2087
2126
|
replay.actor.stop();
|
|
2088
|
-
if (!covered &&
|
|
2127
|
+
if ((!covered || needsLiteral()) &&
|
|
2089
2128
|
path.alternatives !== undefined &&
|
|
2090
2129
|
attempts < MAX_COVERAGE_PATH_ATTEMPTS) {
|
|
2091
2130
|
const next = path.alternatives.next();
|
|
@@ -2102,7 +2141,7 @@ async function searchCoverageEntry(machine, target, refs, captains, playbooks, c
|
|
|
2102
2141
|
if (queue.length > 0)
|
|
2103
2142
|
limitations.add(`exhausted ${MAX_COVERAGE_PATH_ATTEMPTS}-attempt path budget`);
|
|
2104
2143
|
return {
|
|
2105
|
-
covered:
|
|
2144
|
+
covered: transitionCovered,
|
|
2106
2145
|
entered,
|
|
2107
2146
|
...(limitations.size === 0
|
|
2108
2147
|
? {}
|
|
@@ -2987,12 +3026,35 @@ export function fsmCoverageTestTimeout(fsmModule) {
|
|
|
2987
3026
|
* surface entirely, in which case interrupt coverage is skipped.
|
|
2988
3027
|
*/
|
|
2989
3028
|
export async function checkFsmCoverage(fsmModule, opts = {}) {
|
|
3029
|
+
return fsmCoverage(fsmModule, opts);
|
|
3030
|
+
}
|
|
3031
|
+
/** Conformance suites replay only pending literal bindings; coverage stays separate. */
|
|
3032
|
+
export async function checkGearsFsmConformanceAsync(gears, fsmModule, options = {}) {
|
|
3033
|
+
const { findings, literalChecks } = prepareGearsFsmConformance(gears, findMachine(fsmModule).config, { concurrentRoleSets: findConcurrentRoleSets(fsmModule), ...options });
|
|
3034
|
+
options.signal?.throwIfAborted();
|
|
3035
|
+
return findings.length > 0 || !literalChecks.pending()
|
|
3036
|
+
? findings
|
|
3037
|
+
: fsmCoverage(fsmModule, options, literalChecks, true);
|
|
3038
|
+
}
|
|
3039
|
+
/** One bounded replay owns transition coverage and reached literal-child proof. */
|
|
3040
|
+
export async function checkGearsFsmArtifact(gears, fsmModule, options = {}) {
|
|
3041
|
+
const { findings, literalChecks } = prepareGearsFsmConformance(gears, findMachine(fsmModule).config, {
|
|
3042
|
+
concurrentRoleSets: findConcurrentRoleSets(fsmModule),
|
|
3043
|
+
...options,
|
|
3044
|
+
});
|
|
3045
|
+
options.signal?.throwIfAborted();
|
|
3046
|
+
return findings.length > 0
|
|
3047
|
+
? findings
|
|
3048
|
+
: fsmCoverage(fsmModule, options, literalChecks);
|
|
3049
|
+
}
|
|
3050
|
+
async function fsmCoverage(fsmModule, opts = {}, literalChecks, literalOnly = false) {
|
|
2990
3051
|
opts.signal?.throwIfAborted();
|
|
2991
3052
|
if (opts.timeoutMs !== undefined &&
|
|
2992
3053
|
(!Number.isFinite(opts.timeoutMs) || opts.timeoutMs <= 0))
|
|
2993
3054
|
throw new RangeError('FSM coverage timeout must be a positive finite number');
|
|
2994
3055
|
const started = performance.now();
|
|
2995
3056
|
const run = {
|
|
3057
|
+
literalChecks,
|
|
2996
3058
|
signal: opts.signal,
|
|
2997
3059
|
deadline: started +
|
|
2998
3060
|
Math.min(opts.timeoutMs ?? Infinity, MAX_COVERAGE_TEST_TIMEOUT_MS),
|
|
@@ -3016,8 +3078,11 @@ export async function checkFsmCoverage(fsmModule, opts = {}) {
|
|
|
3016
3078
|
run.artifactSchema = schema.artifactSchema;
|
|
3017
3079
|
const findings = [
|
|
3018
3080
|
...schema.findings,
|
|
3019
|
-
...(
|
|
3081
|
+
...(literalOnly
|
|
3082
|
+
? await reachedLiteralContexts(fsmModule, opts.sourceText ?? '', literalChecks)
|
|
3083
|
+
: await runFsmCoverage(fsmModule, opts.sourceText ?? '')),
|
|
3020
3084
|
...run.questionFindings,
|
|
3085
|
+
...(literalChecks?.findings() ?? []),
|
|
3021
3086
|
];
|
|
3022
3087
|
await coverageYield(true);
|
|
3023
3088
|
completed = true;
|
|
@@ -3028,6 +3093,22 @@ export async function checkFsmCoverage(fsmModule, opts = {}) {
|
|
|
3028
3093
|
}
|
|
3029
3094
|
});
|
|
3030
3095
|
}
|
|
3096
|
+
/** A conformance-only suite uses one existing bounded search per pending call. */
|
|
3097
|
+
async function reachedLiteralContexts(fsmModule, sourceText, checks) {
|
|
3098
|
+
const machine = findMachine(fsmModule);
|
|
3099
|
+
const refs = stateRefs(machine.config), captains = captainRefs(machine.config), playbooks = playbookRefs(machine.config);
|
|
3100
|
+
const candidates = [
|
|
3101
|
+
...identifierLiterals(sourceText),
|
|
3102
|
+
...numericLiterals(sourceText),
|
|
3103
|
+
];
|
|
3104
|
+
for (const playbook of playbooks) {
|
|
3105
|
+
if (!checks.needs(playbook.invocation))
|
|
3106
|
+
continue;
|
|
3107
|
+
await coverageYield();
|
|
3108
|
+
await searchCoverageEntry(machine, { kind: 'child', value: playbook }, refs, captains, playbooks, candidates, async () => true);
|
|
3109
|
+
}
|
|
3110
|
+
return [];
|
|
3111
|
+
}
|
|
3031
3112
|
async function runFsmCoverage(fsmModule, sourceText) {
|
|
3032
3113
|
const findings = [];
|
|
3033
3114
|
const machine = findMachine(fsmModule);
|