reading-stone 0.0.0-stage → 0.2.1
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/LICENSE +201 -0
- package/NOTICE +11 -0
- package/README.md +301 -2
- package/dist/analysis.d.ts +341 -0
- package/dist/analysis.js +392 -0
- package/dist/cognitive.d.ts +163 -0
- package/dist/cognitive.js +380 -0
- package/dist/complexity.d.ts +102 -0
- package/dist/complexity.js +163 -0
- package/dist/coverage.d.ts +78 -0
- package/dist/coverage.js +635 -0
- package/dist/detector.d.ts +41 -0
- package/dist/detector.js +2134 -0
- package/dist/discovery.d.ts +330 -0
- package/dist/discovery.js +930 -0
- package/dist/doc-coverage.d.ts +155 -0
- package/dist/doc-coverage.js +543 -0
- package/dist/extract.d.ts +209 -0
- package/dist/extract.js +498 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +63 -0
- package/dist/internal.d.ts +75 -0
- package/dist/internal.js +63 -0
- package/dist/main.d.ts +8 -0
- package/dist/main.js +39 -0
- package/dist/models.d.ts +185 -0
- package/dist/models.js +170 -0
- package/dist/program.d.ts +207 -0
- package/dist/program.js +662 -0
- package/dist/protocol.d.ts +88 -0
- package/dist/protocol.js +74 -0
- package/dist/quality/assertions.d.ts +81 -0
- package/dist/quality/assertions.js +425 -0
- package/dist/quality/collect.d.ts +66 -0
- package/dist/quality/collect.js +412 -0
- package/dist/quality/inference.d.ts +86 -0
- package/dist/quality/inference.js +603 -0
- package/dist/quality/matchers.d.ts +129 -0
- package/dist/quality/matchers.js +220 -0
- package/dist/quality/pairing.d.ts +133 -0
- package/dist/quality/pairing.js +770 -0
- package/dist/quality/pipeline.d.ts +59 -0
- package/dist/quality/pipeline.js +202 -0
- package/dist/quality/types.d.ts +127 -0
- package/dist/quality/types.js +92 -0
- package/dist/safeio.d.ts +107 -0
- package/dist/safeio.js +314 -0
- package/dist/server.d.ts +19 -0
- package/dist/server.js +451 -0
- package/dist/signals/adapter.d.ts +103 -0
- package/dist/signals/adapter.js +323 -0
- package/dist/signals/caller-index.d.ts +117 -0
- package/dist/signals/caller-index.js +147 -0
- package/dist/signals/caller.d.ts +76 -0
- package/dist/signals/caller.js +108 -0
- package/dist/signals/evidence.d.ts +233 -0
- package/dist/signals/evidence.js +578 -0
- package/dist/signals/interface.d.ts +68 -0
- package/dist/signals/interface.js +87 -0
- package/dist/signals/jsdoc.d.ts +27 -0
- package/dist/signals/jsdoc.js +233 -0
- package/dist/signals/naming.d.ts +26 -0
- package/dist/signals/naming.js +160 -0
- package/dist/signals/routing.d.ts +163 -0
- package/dist/signals/routing.js +416 -0
- package/dist/signals/types.d.ts +146 -0
- package/dist/signals/types.js +99 -0
- package/dist/signals/visibility.d.ts +23 -0
- package/dist/signals/visibility.js +82 -0
- package/dist/taxonomy.d.ts +89 -0
- package/dist/taxonomy.js +217 -0
- package/package.json +61 -4
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { Writable } from "node:stream";
|
|
2
|
+
import { type Node } from "typescript/unstable/ast";
|
|
3
|
+
import type { ProgramContext } from "../program.js";
|
|
4
|
+
/** One collected vitest/jest test function (data-model.md Section 5.1). */
|
|
5
|
+
export interface TestFunction {
|
|
6
|
+
/**
|
|
7
|
+
* The invocation's first argument when a string literal or
|
|
8
|
+
* no-substitution template literal; `""` otherwise — never dropped
|
|
9
|
+
* (FR-002).
|
|
10
|
+
*/
|
|
11
|
+
readonly title: string;
|
|
12
|
+
/**
|
|
13
|
+
* Enclosing describe titles joined `" > "` outermost-to-innermost, then
|
|
14
|
+
* the title; bare title at top level; empty segments join verbatim
|
|
15
|
+
* (FR-003).
|
|
16
|
+
*/
|
|
17
|
+
readonly qualifiedTitle: string;
|
|
18
|
+
/** Root-relative POSIX path of the test file. */
|
|
19
|
+
readonly relPath: string;
|
|
20
|
+
/** The enclosing describe titles, outermost first (nearest for pairing). */
|
|
21
|
+
readonly describeTitles: readonly string[];
|
|
22
|
+
/**
|
|
23
|
+
* The callback function-expression node — `null` when the callback
|
|
24
|
+
* argument is a reference, not a function expression (research R3).
|
|
25
|
+
*/
|
|
26
|
+
readonly callback: Node | null;
|
|
27
|
+
/** 1-based line of the `it`/`test` invocation (the outer call). */
|
|
28
|
+
readonly line: number;
|
|
29
|
+
/** 0-based source-order index within the file. */
|
|
30
|
+
readonly index: number;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Collects every test function from the discovery-screened test arm
|
|
34
|
+
* (FR-002/FR-003; research R3).
|
|
35
|
+
*
|
|
36
|
+
* Both `ProgramContext` modes collect identically — the walk is purely
|
|
37
|
+
* lexical over the parsed sources, exactly as extraction is (research R5's
|
|
38
|
+
* both-modes parity). The statement-level walk domain is the data model's:
|
|
39
|
+
* `it`/`test`/`describe` invocations are statements, describe callbacks
|
|
40
|
+
* are the only containers, and the enumerated control-flow interiors
|
|
41
|
+
* (T041) are walked wherever they appear — top level or container body —
|
|
42
|
+
* while hooks, benches, non-invocation statements, and the
|
|
43
|
+
* non-enumerated statement kinds contribute nothing by construction.
|
|
44
|
+
*
|
|
45
|
+
* The walk is depth-bounded (F2; plan.md Scale/Scope): a file whose
|
|
46
|
+
* describe nesting passes the shared `MAPPING_WALK_DEPTH_BUDGET` skips
|
|
47
|
+
* whole — its tests are discarded and exactly one diagnostic is written
|
|
48
|
+
* to `stderr` — while every other file collects normally (the
|
|
49
|
+
* `extractFromFile` per-file-skip discipline; a `RangeError` from lazy
|
|
50
|
+
* node materialization is treated identically: pathological input
|
|
51
|
+
* degrades to a skip, never a crash — Constitution V).
|
|
52
|
+
*
|
|
53
|
+
* @param testPaths The discovered, exclusion-screened test arm —
|
|
54
|
+
* root-relative POSIX paths in classifyFiles' sorted order (pattern
|
|
55
|
+
* scoping never narrows this arm; FR-006).
|
|
56
|
+
* @param context The bootstrapped `ProgramContext` in either mode; read
|
|
57
|
+
* only during the call.
|
|
58
|
+
* @param rootPath Realpath-resolved absolute analysis root — the
|
|
59
|
+
* program-mode source-name base (the buildCallerIndex threading
|
|
60
|
+
* precedent: the root is passed explicitly, never re-derived).
|
|
61
|
+
* @param stderr The diagnostic sink for depth-budget skips (the server's
|
|
62
|
+
* stderr; never stdout — protocol fidelity).
|
|
63
|
+
* @returns The collected test functions, sorted by `(relPath, collection
|
|
64
|
+
* index)` — a stable, deterministic input to pairing.
|
|
65
|
+
*/
|
|
66
|
+
export declare function collectTestFunctions(testPaths: readonly string[], context: ProgramContext, rootPath: string, stderr?: Writable): TestFunction[];
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
// Test-function collection (T015; FR-002/FR-003; research R3; data-model.md
|
|
2
|
+
// Section 5.1; Constitution Principles I, III, and V).
|
|
3
|
+
//
|
|
4
|
+
// `collectTestFunctions` walks the discovery-screened test arm and returns
|
|
5
|
+
// every vitest/jest test function as a `TestFunction` — the pairing
|
|
6
|
+
// pipeline's test-side input. The walk is purely lexical (statement-level
|
|
7
|
+
// AST inspection through the compiler API): test files are untrusted input
|
|
8
|
+
// parsed inside the bounded hermetic host, never executed or imported
|
|
9
|
+
// (Constitution V, FR-012 — the canary fixture in tests/quality/
|
|
10
|
+
// pipeline.test.ts pins it).
|
|
11
|
+
//
|
|
12
|
+
// Collection rules (FR-002, research R3):
|
|
13
|
+
//
|
|
14
|
+
// - The callee root — after unwrapping intermediate call-expression
|
|
15
|
+
// wrappers (`it.each(table)(title, fn)` — the callback and title live on
|
|
16
|
+
// the OUTER call) — is an identifier `it`/`test` or a property chain
|
|
17
|
+
// rooted at one. The modifier set is deliberately open: `it.only`,
|
|
18
|
+
// `it.skip`, `it.concurrent`, `it.fails`, `it.skipIf`, `test.each`, and
|
|
19
|
+
// future modifiers all collect (the availability-first reading of
|
|
20
|
+
// FR-002's "and siblings" — an unrecognized modifier is never a reason
|
|
21
|
+
// to drop a test).
|
|
22
|
+
// - The callback is the LAST argument that is a function expression or
|
|
23
|
+
// arrow function — robust to trailing timeout arguments. A bare
|
|
24
|
+
// identifier callback still collects with `callback: null` (research
|
|
25
|
+
// R3): title-based and import-graph pairing still apply, and the
|
|
26
|
+
// assertion collector answers `[]` for it — never dropped, never a scan
|
|
27
|
+
// of the referenced function's body.
|
|
28
|
+
// - The title is the first argument when a string literal or a
|
|
29
|
+
// no-substitution template literal — the static-text rule — else `""`.
|
|
30
|
+
// The same rule applies per describe level; `qualifiedTitle` joins the
|
|
31
|
+
// enclosing describe titles with " > " outermost-to-innermost, then the
|
|
32
|
+
// title, empty segments joining verbatim (FR-003).
|
|
33
|
+
// - `describe` invocations (with their own `.each` unwrapping) are
|
|
34
|
+
// containers: the walk maintains the title stack through their
|
|
35
|
+
// callbacks, including expression-bodied describe callbacks
|
|
36
|
+
// (`describe("a", () => it("b", fn))`). `bench` and the four hooks are
|
|
37
|
+
// excluded by callee root.
|
|
38
|
+
// - The walk descends into control-flow interiors (T040/T041;
|
|
39
|
+
// iteration-3 F3): `if`/`else` branches, `for`/`for-of`/`for-in`/
|
|
40
|
+
// `while`/`do-while` loop bodies, and plain blocks — within the file
|
|
41
|
+
// top level and describe callback bodies alike — collecting the
|
|
42
|
+
// invocations found at expression-statement position within them
|
|
43
|
+
// (loop-registered tests: `for (const c of cases) it(c.label, fn)`).
|
|
44
|
+
// `switch`, `try`/`catch`/`finally`, and labeled statements stay
|
|
45
|
+
// OUTSIDE the domain (iteration-3 F2 — the deliberately conservative
|
|
46
|
+
// enumeration), and nested function bodies — helpers — are never
|
|
47
|
+
// entered: a helper is a different scope, not a container.
|
|
48
|
+
// - Output is sorted by `(relPath, collection index)` — a stable,
|
|
49
|
+
// deterministic input to pairing (Constitution I).
|
|
50
|
+
//
|
|
51
|
+
// Bounded walk (iteration-2 review fix F2; plan.md Scale/Scope): the
|
|
52
|
+
// collection recursion is depth-bounded by the shared
|
|
53
|
+
// `MAPPING_WALK_DEPTH_BUDGET` — the extract.ts `AST_DEPTH_BUDGET` shape —
|
|
54
|
+
// so a pathological describe or control-flow nest degrades to a per-file
|
|
55
|
+
// skip with exactly one diagnostic (the `extractFromFile` discipline),
|
|
56
|
+
// never a request crash (Constitution V). The walk does NOT inherit
|
|
57
|
+
// prepareAnalysis's depth budget: that one guards the extraction walk
|
|
58
|
+
// only, and this walk runs outside it.
|
|
59
|
+
import { join } from "node:path";
|
|
60
|
+
import { isArrowFunction, isBlock, isCallExpression, isDoStatement, isExpressionStatement, isForInStatement, isForOfStatement, isForStatement, isFunctionExpression, isIdentifier, isIfStatement, isNoSubstitutionTemplateLiteral, isPropertyAccessExpression, isStringLiteral, isWhileStatement, } from "typescript/unstable/ast";
|
|
61
|
+
import { MAPPING_WALK_DEPTH_BUDGET } from "../internal.js";
|
|
62
|
+
/** The callee-root roots that collect as tests (the modifier set is open). */
|
|
63
|
+
const TEST_ROOTS = new Set(["it", "test"]);
|
|
64
|
+
/** The callee-root root that makes an invocation a describe container. */
|
|
65
|
+
const DESCRIBE_ROOT = "describe";
|
|
66
|
+
/**
|
|
67
|
+
* The collection walk's depth sentinel (F2): raised when the describe
|
|
68
|
+
* nesting depth passes the shared `MAPPING_WALK_DEPTH_BUDGET`, caught by
|
|
69
|
+
* the per-file loop — never escapes this module (the extract.ts
|
|
70
|
+
* `AstDepthExceeded` discipline). `RangeError` from lazy node
|
|
71
|
+
* materialization is caught at the same site and treated identically:
|
|
72
|
+
* both mean "pathological file, skip it whole."
|
|
73
|
+
*/
|
|
74
|
+
class MappingWalkDepthExceeded extends Error {
|
|
75
|
+
constructor() {
|
|
76
|
+
super("ast depth exceeds budget");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Resolves each test path's parsed source in either bootstrap mode.
|
|
81
|
+
*
|
|
82
|
+
* Parse-only sources are keyed by root-relative path already; program-mode
|
|
83
|
+
* source names are the compiler's absolute file names, spelled exactly as
|
|
84
|
+
* the extender config's `files` root set spelled them —
|
|
85
|
+
* `join(realRoot, relPath)` (src/program.ts) — so the same join resolves
|
|
86
|
+
* them back. A path absent from the bootstrap (a pre-read skip whose
|
|
87
|
+
* diagnostic readBounded already wrote) resolves to nothing and is skipped
|
|
88
|
+
* silently — never a second diagnostic, never a crash.
|
|
89
|
+
*
|
|
90
|
+
* @param testPaths Root-relative POSIX paths of the test arm.
|
|
91
|
+
* @param context The bootstrapped `ProgramContext` in either mode.
|
|
92
|
+
* @param rootPath Realpath-resolved absolute analysis root — the
|
|
93
|
+
* program-mode relativization base.
|
|
94
|
+
* @returns `(relPath, SourceFile)` pairs in testPaths order, missing paths
|
|
95
|
+
* excluded.
|
|
96
|
+
*/
|
|
97
|
+
function resolveTestSources(testPaths, context, rootPath) {
|
|
98
|
+
if (context.mode === "parse-only") {
|
|
99
|
+
const pairs = [];
|
|
100
|
+
for (const relPath of testPaths) {
|
|
101
|
+
const sourceFile = context.sources.get(relPath);
|
|
102
|
+
if (sourceFile !== undefined) {
|
|
103
|
+
pairs.push([relPath, sourceFile]);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return pairs;
|
|
107
|
+
}
|
|
108
|
+
const pairs = [];
|
|
109
|
+
for (const relPath of testPaths) {
|
|
110
|
+
// The extender config's own spelling: both sides go through node:path's
|
|
111
|
+
// join against the same resolved root, so the compiler's absolute name
|
|
112
|
+
// matches exactly (case and separators alike — no re-derivation).
|
|
113
|
+
const sourceFile = context.program.getSourceFile(join(rootPath, relPath));
|
|
114
|
+
if (sourceFile !== undefined) {
|
|
115
|
+
pairs.push([relPath, sourceFile]);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return pairs;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Unwraps intermediate call-expression wrappers and reads the callee root:
|
|
122
|
+
* the leftmost identifier the callee chain roots at, or `null` when the
|
|
123
|
+
* chain roots at anything else (a call, a literal, an element access).
|
|
124
|
+
* `it.each(table)` and `it.skip.each(table)` both root at `it`;
|
|
125
|
+
* `something().it(...)` roots at a call and does not qualify.
|
|
126
|
+
*
|
|
127
|
+
* @param callee The outer invocation's callee expression.
|
|
128
|
+
* @returns The root identifier's text, or `null` when the chain does not
|
|
129
|
+
* root at an identifier.
|
|
130
|
+
*/
|
|
131
|
+
function calleeRoot(callee) {
|
|
132
|
+
let node = callee;
|
|
133
|
+
// The `.each(table)` wrapper: the callback and title live on the OUTER
|
|
134
|
+
// call, so classification unwraps through the inner call expressions to
|
|
135
|
+
// the property chain (or identifier) beneath.
|
|
136
|
+
while (isCallExpression(node)) {
|
|
137
|
+
node = node.expression;
|
|
138
|
+
}
|
|
139
|
+
if (isIdentifier(node)) {
|
|
140
|
+
return node.text;
|
|
141
|
+
}
|
|
142
|
+
if (isPropertyAccessExpression(node)) {
|
|
143
|
+
let base = node;
|
|
144
|
+
while (isPropertyAccessExpression(base)) {
|
|
145
|
+
base = base.expression;
|
|
146
|
+
}
|
|
147
|
+
return isIdentifier(base) ? base.text : null;
|
|
148
|
+
}
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The static title of an invocation's first argument (the static-text
|
|
153
|
+
* rule): a string literal or a NO-substitution template literal reads its
|
|
154
|
+
* text verbatim — `$a` placeholders included; anything else (a substituted
|
|
155
|
+
* template, a call, a number, an absent argument) is `""`.
|
|
156
|
+
*
|
|
157
|
+
* @param argument The invocation's first argument, when present.
|
|
158
|
+
* @returns The static title text, or `""`.
|
|
159
|
+
*/
|
|
160
|
+
function staticTitle(argument) {
|
|
161
|
+
if (argument === undefined) {
|
|
162
|
+
return "";
|
|
163
|
+
}
|
|
164
|
+
if (isStringLiteral(argument) || isNoSubstitutionTemplateLiteral(argument)) {
|
|
165
|
+
return argument.text;
|
|
166
|
+
}
|
|
167
|
+
return "";
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The callback of an invocation: the LAST argument that is a function
|
|
171
|
+
* expression or arrow function — robust to trailing timeout arguments
|
|
172
|
+
* (`it("slow", fn, 5000)`). A callback passed as a bare identifier
|
|
173
|
+
* reference yields `null` (research R3) — the test still collects.
|
|
174
|
+
*
|
|
175
|
+
* @param arguments_ The invocation's argument nodes.
|
|
176
|
+
* @returns The callback function-expression node, or `null`.
|
|
177
|
+
*/
|
|
178
|
+
function callbackOf(arguments_) {
|
|
179
|
+
for (let i = arguments_.length - 1; i >= 0; i--) {
|
|
180
|
+
// noUncheckedIndexedAccess: an in-bounds index still reads as
|
|
181
|
+
// possibly undefined; the loop walks real positions only, so an
|
|
182
|
+
// undefined element (impossible for a materialized argument list)
|
|
183
|
+
// simply fails the callback-form test below.
|
|
184
|
+
const argument = arguments_[i];
|
|
185
|
+
if (argument !== undefined && isCallbackForm(argument)) {
|
|
186
|
+
return argument;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Is the node a function expression or arrow function (the callback
|
|
193
|
+
* forms)?
|
|
194
|
+
*/
|
|
195
|
+
function isCallbackForm(node) {
|
|
196
|
+
return isFunctionExpression(node) || isArrowFunction(node);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Walks one statement list of the broadened collection domain (T041): the
|
|
200
|
+
* file top level, a describe callback's block body, or a control-flow
|
|
201
|
+
* interior. Each statement flows through `walkStatement`.
|
|
202
|
+
*
|
|
203
|
+
* @param statements The statement list to walk.
|
|
204
|
+
* @param describeTitles The enclosing describe titles, outermost first.
|
|
205
|
+
* @param depth The nesting depth of this statement list.
|
|
206
|
+
* @param walk The per-invocation continuation (`processInvocation`).
|
|
207
|
+
*/
|
|
208
|
+
function walkStatementList(statements, describeTitles, depth, walk) {
|
|
209
|
+
for (const statement of statements) {
|
|
210
|
+
walkStatement(statement, describeTitles, depth, walk);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Walks one statement of the broadened domain (T041): expression
|
|
215
|
+
* statements yield their expression to the walk continuation;
|
|
216
|
+
* `if`/`else` branches, `for`/`for-of`/`for-in`/`while`/`do-while` loop
|
|
217
|
+
* bodies, and plain blocks recurse one level deeper — each control-flow
|
|
218
|
+
* nesting level counts toward the shared `MAPPING_WALK_DEPTH_BUDGET`, so
|
|
219
|
+
* the broadened walk stays inside the depth guard. `switch`, `try`/
|
|
220
|
+
* `catch`/`finally`, labeled statements, and every other statement kind
|
|
221
|
+
* (declarations, returns, throws) stay OUTSIDE the walk domain
|
|
222
|
+
* (iteration-3 review gate F2: the enumeration is deliberately
|
|
223
|
+
* conservative — anything not enumerated is not walked), and nested
|
|
224
|
+
* function bodies — helpers — are never entered: a helper is a different
|
|
225
|
+
* scope, not a container.
|
|
226
|
+
*
|
|
227
|
+
* @param statement The statement to walk.
|
|
228
|
+
* @param describeTitles The enclosing describe titles, outermost first.
|
|
229
|
+
* @param depth The nesting depth of this statement.
|
|
230
|
+
* @param walk The per-invocation continuation (`processInvocation`).
|
|
231
|
+
*/
|
|
232
|
+
function walkStatement(statement, describeTitles, depth, walk) {
|
|
233
|
+
if (depth > MAPPING_WALK_DEPTH_BUDGET) {
|
|
234
|
+
// The statement walk owns the same bound `processInvocation` checks:
|
|
235
|
+
// deep control-flow nesting must trip the per-file skip even when no
|
|
236
|
+
// invocation sits at the bottom to raise it there.
|
|
237
|
+
throw new MappingWalkDepthExceeded();
|
|
238
|
+
}
|
|
239
|
+
if (isExpressionStatement(statement)) {
|
|
240
|
+
walk(statement.expression, describeTitles, depth);
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (isBlock(statement)) {
|
|
244
|
+
walkStatementList(statement.statements, describeTitles, depth + 1, walk);
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
if (isIfStatement(statement)) {
|
|
248
|
+
const { thenStatement, elseStatement } = statement;
|
|
249
|
+
walkStatement(thenStatement, describeTitles, depth + 1, walk);
|
|
250
|
+
if (elseStatement !== undefined) {
|
|
251
|
+
walkStatement(elseStatement, describeTitles, depth + 1, walk);
|
|
252
|
+
}
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (isForStatement(statement) ||
|
|
256
|
+
isForOfStatement(statement) ||
|
|
257
|
+
isForInStatement(statement) ||
|
|
258
|
+
isWhileStatement(statement) ||
|
|
259
|
+
isDoStatement(statement)) {
|
|
260
|
+
// The five iteration kinds share one body property; the `for-in`
|
|
261
|
+
// shape extends StatementBase directly rather than
|
|
262
|
+
// IterationStatementBase, so the union's common access stays `statement`.
|
|
263
|
+
walkStatement(statement.statement, describeTitles, depth + 1, walk);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Walks one container callback's body: a block body through the shared
|
|
269
|
+
* statement walk (control-flow interiors included, T041), an
|
|
270
|
+
* expression-bodied arrow as the single contained invocation
|
|
271
|
+
* (`describe("a", () => it("b", fn))` — the tight-suite form). Tests are
|
|
272
|
+
* never containers; only describe callbacks flow through here. The walk
|
|
273
|
+
* callback receives the container's describe titles and the CONTINUATION
|
|
274
|
+
* depth (one deeper than the describe's own level) so the budget guard
|
|
275
|
+
* counts every recursion level.
|
|
276
|
+
*
|
|
277
|
+
* @param callback The describe callback whose body walks.
|
|
278
|
+
* @param describeTitles The titles including this describe's own.
|
|
279
|
+
* @param depth The continuation depth for the body's invocations.
|
|
280
|
+
* @param walk The per-invocation continuation (`processInvocation`).
|
|
281
|
+
*/
|
|
282
|
+
function walkContainerBody(callback, describeTitles, depth, walk) {
|
|
283
|
+
const body = callback.body;
|
|
284
|
+
if (isBlock(body)) {
|
|
285
|
+
walkStatementList(body.statements, describeTitles, depth, walk);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
walk(body, describeTitles, depth);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Collects every test function from the discovery-screened test arm
|
|
292
|
+
* (FR-002/FR-003; research R3).
|
|
293
|
+
*
|
|
294
|
+
* Both `ProgramContext` modes collect identically — the walk is purely
|
|
295
|
+
* lexical over the parsed sources, exactly as extraction is (research R5's
|
|
296
|
+
* both-modes parity). The statement-level walk domain is the data model's:
|
|
297
|
+
* `it`/`test`/`describe` invocations are statements, describe callbacks
|
|
298
|
+
* are the only containers, and the enumerated control-flow interiors
|
|
299
|
+
* (T041) are walked wherever they appear — top level or container body —
|
|
300
|
+
* while hooks, benches, non-invocation statements, and the
|
|
301
|
+
* non-enumerated statement kinds contribute nothing by construction.
|
|
302
|
+
*
|
|
303
|
+
* The walk is depth-bounded (F2; plan.md Scale/Scope): a file whose
|
|
304
|
+
* describe nesting passes the shared `MAPPING_WALK_DEPTH_BUDGET` skips
|
|
305
|
+
* whole — its tests are discarded and exactly one diagnostic is written
|
|
306
|
+
* to `stderr` — while every other file collects normally (the
|
|
307
|
+
* `extractFromFile` per-file-skip discipline; a `RangeError` from lazy
|
|
308
|
+
* node materialization is treated identically: pathological input
|
|
309
|
+
* degrades to a skip, never a crash — Constitution V).
|
|
310
|
+
*
|
|
311
|
+
* @param testPaths The discovered, exclusion-screened test arm —
|
|
312
|
+
* root-relative POSIX paths in classifyFiles' sorted order (pattern
|
|
313
|
+
* scoping never narrows this arm; FR-006).
|
|
314
|
+
* @param context The bootstrapped `ProgramContext` in either mode; read
|
|
315
|
+
* only during the call.
|
|
316
|
+
* @param rootPath Realpath-resolved absolute analysis root — the
|
|
317
|
+
* program-mode source-name base (the buildCallerIndex threading
|
|
318
|
+
* precedent: the root is passed explicitly, never re-derived).
|
|
319
|
+
* @param stderr The diagnostic sink for depth-budget skips (the server's
|
|
320
|
+
* stderr; never stdout — protocol fidelity).
|
|
321
|
+
* @returns The collected test functions, sorted by `(relPath, collection
|
|
322
|
+
* index)` — a stable, deterministic input to pairing.
|
|
323
|
+
*/
|
|
324
|
+
export function collectTestFunctions(testPaths, context, rootPath, stderr = process.stderr) {
|
|
325
|
+
const collected = [];
|
|
326
|
+
// The per-file collection walk: `processInvocation` classifies one
|
|
327
|
+
// statement-level call by its callee root and either collects a test,
|
|
328
|
+
// recurses through a describe container, or stops (hooks, benches, and
|
|
329
|
+
// unrecognized roots are excluded by root). Defined inside the entry so
|
|
330
|
+
// the per-file counter and the injected output list close over nothing
|
|
331
|
+
// else. `depth` is the nesting level (0 at the file top level) —
|
|
332
|
+
// describe callbacks and control-flow interiors each add one (T041) —
|
|
333
|
+
// the budget guard's measure.
|
|
334
|
+
function processInvocation(expression, relPath, sourceFile, describeTitles, index, output, depth) {
|
|
335
|
+
if (depth > MAPPING_WALK_DEPTH_BUDGET) {
|
|
336
|
+
// F2: the mapping walks run outside extract.ts's AST_DEPTH_BUDGET,
|
|
337
|
+
// so this walk owns its own bound — a pathological describe or
|
|
338
|
+
// control-flow nest degrades to the per-file skip, never a request
|
|
339
|
+
// crash.
|
|
340
|
+
throw new MappingWalkDepthExceeded();
|
|
341
|
+
}
|
|
342
|
+
if (!isCallExpression(expression)) {
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
const root = calleeRoot(expression.expression);
|
|
346
|
+
if (root === null) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (TEST_ROOTS.has(root)) {
|
|
350
|
+
const title = staticTitle(expression.arguments[0]);
|
|
351
|
+
output.push({
|
|
352
|
+
title,
|
|
353
|
+
qualifiedTitle: [...describeTitles, title].join(" > "),
|
|
354
|
+
relPath,
|
|
355
|
+
describeTitles,
|
|
356
|
+
callback: callbackOf(expression.arguments),
|
|
357
|
+
line: sourceFile.getLineAndCharacterOfPosition(expression.getStart(sourceFile))
|
|
358
|
+
.line + 1,
|
|
359
|
+
index: index.count,
|
|
360
|
+
});
|
|
361
|
+
index.count += 1;
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (root === DESCRIBE_ROOT) {
|
|
365
|
+
const callback = callbackOf(expression.arguments);
|
|
366
|
+
if (callback !== null && isCallbackForm(callback)) {
|
|
367
|
+
const title = staticTitle(expression.arguments[0]);
|
|
368
|
+
walkContainerBody(callback, [...describeTitles, title], depth + 1, (inner, innerTitles, innerDepth) => processInvocation(inner, relPath, sourceFile, innerTitles, index, output, innerDepth));
|
|
369
|
+
}
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
// Every other root — bench, the four hooks, and unrelated calls
|
|
373
|
+
// rooted at other identifiers — contributes nothing: the walk
|
|
374
|
+
// simply does not descend (exclusion by callee root, FR-002).
|
|
375
|
+
}
|
|
376
|
+
for (const [relPath, sourceFile] of resolveTestSources(testPaths, context, rootPath)) {
|
|
377
|
+
const index = { count: 0 };
|
|
378
|
+
// Per-file buffer (F2): one pathological file discards only its own
|
|
379
|
+
// tests — the extractFromFile discipline — instead of aborting the
|
|
380
|
+
// whole collection, so sibling files keep their tests.
|
|
381
|
+
const fileTests = [];
|
|
382
|
+
try {
|
|
383
|
+
// The file top level is the root statement list of the broadened
|
|
384
|
+
// walk (T041): expression statements AND the enumerated
|
|
385
|
+
// control-flow interiors flow through the same dispatch.
|
|
386
|
+
walkStatementList(sourceFile.statements, [], 0, (expression, describeTitles, depth) => processInvocation(expression, relPath, sourceFile, describeTitles, index, fileTests, depth));
|
|
387
|
+
}
|
|
388
|
+
catch (error) {
|
|
389
|
+
// Only the depth sentinel and a materialization RangeError are
|
|
390
|
+
// diagnosed skips; anything else escapes (a crash is never a
|
|
391
|
+
// silent skip — the buildProgramContext rethrow discipline).
|
|
392
|
+
if (!(error instanceof MappingWalkDepthExceeded || error instanceof RangeError)) {
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
stderr.write(`reading-stone: skipping ${relPath}: ast depth exceeds budget\n`);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
collected.push(...fileTests);
|
|
399
|
+
}
|
|
400
|
+
// The structural output sort: (relPath, collection index), UTF-16
|
|
401
|
+
// code-unit comparison for the path — the deterministic order the
|
|
402
|
+
// pairing strategies consume, independent of the input path order
|
|
403
|
+
// (Constitution I).
|
|
404
|
+
collected.sort((a, b) => {
|
|
405
|
+
if (a.relPath !== b.relPath) {
|
|
406
|
+
return a.relPath < b.relPath ? -1 : 1;
|
|
407
|
+
}
|
|
408
|
+
return a.index - b.index;
|
|
409
|
+
});
|
|
410
|
+
return collected;
|
|
411
|
+
}
|
|
412
|
+
//# sourceMappingURL=collect.js.map
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type ArrowFunction, type FunctionDeclaration, type FunctionExpression, type Node, type SourceFile } from "typescript/unstable/ast";
|
|
2
|
+
import type { Effect } from "../models.js";
|
|
3
|
+
import { type ProgramContext } from "../program.js";
|
|
4
|
+
import { type SideEffectType } from "../taxonomy.js";
|
|
5
|
+
import type { AssertionSite } from "./assertions.js";
|
|
6
|
+
import type { Pairing } from "./pairing.js";
|
|
7
|
+
/**
|
|
8
|
+
* One file-scope helper of a test file — pass 3's bridge domain
|
|
9
|
+
* (research R7; data-model Section 5.5): a declared function at the
|
|
10
|
+
* file's statement top level, or a const-bound arrow/function
|
|
11
|
+
* expression declarator. `declaration` is the node checker-mode symbol
|
|
12
|
+
* resolution lands on (the `FunctionDeclaration` itself, or the
|
|
13
|
+
* `VariableDeclaration` for expression forms); parse-only matches on
|
|
14
|
+
* `name`. `fn` is the body-owning function-like whose returns are the
|
|
15
|
+
* bridge evidence.
|
|
16
|
+
*/
|
|
17
|
+
export interface FileLocalHelper {
|
|
18
|
+
/** The helper's declared name (the callee spelling both modes read). */
|
|
19
|
+
readonly name: string;
|
|
20
|
+
/** The declaring node — checker-mode symbol identity; `name` for parse-only. */
|
|
21
|
+
readonly declaration: Node;
|
|
22
|
+
/** The body-owning function-like (pass 3 scans its returns). */
|
|
23
|
+
readonly fn: FunctionDeclaration | FunctionExpression | ArrowFunction;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The pass evaluation's inputs (data-model Section 5.5): the live
|
|
27
|
+
* `ProgramContext` — call resolution per mode, exactly the pairing
|
|
28
|
+
* `calls` strategy's route — and the test file's file-local helper table
|
|
29
|
+
* (pass 3's bridge domain). Built by the pipeline once per paired test
|
|
30
|
+
* with assertions, the helper table memoized per test file, so passes
|
|
31
|
+
* never recompute shared evidence (research R8's single-walk
|
|
32
|
+
* discipline).
|
|
33
|
+
*/
|
|
34
|
+
export interface ProvenanceInputs {
|
|
35
|
+
/** The live analysis context; read-only lending, never owned. */
|
|
36
|
+
readonly context: ProgramContext;
|
|
37
|
+
/** The test file's file-scope helpers (pass 3's bridge domain). */
|
|
38
|
+
readonly helpers: readonly FileLocalHelper[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Collects a test file's file-local helper table (pass 3's bridge
|
|
42
|
+
* domain): file-scope declared functions and const-bound function
|
|
43
|
+
* expressions — the two declaration forms research R7 pins.
|
|
44
|
+
*
|
|
45
|
+
* Statement top level only, and never entered: the scan reads the
|
|
46
|
+
* source's own statement list (no recursion, so no depth budget), and
|
|
47
|
+
* the const requirement is the conservative-boundary spirit (US4-8) —
|
|
48
|
+
* a `let`/`var` binding is reassignable, so its initializer proves
|
|
49
|
+
* nothing about any later call site. Overload signatures (a declared
|
|
50
|
+
* function with no body) are skipped: the checker's symbol for the
|
|
51
|
+
* callee carries the implementation's declaration, so the body-bearing
|
|
52
|
+
* twin is the bridge evidence. This is not a function-extraction walk —
|
|
53
|
+
* a helper here is evidence for pass 3, never a mapping target itself
|
|
54
|
+
* (test files are outside the target arm by construction, FR-006).
|
|
55
|
+
*
|
|
56
|
+
* @param sourceFile The test file's parsed source.
|
|
57
|
+
* @returns The helpers in statement order; `[]` for a file declaring none.
|
|
58
|
+
*/
|
|
59
|
+
export declare function collectFileLocalHelpers(sourceFile: SourceFile): readonly FileLocalHelper[];
|
|
60
|
+
/**
|
|
61
|
+
* Infers one mapping row's `side_effect_type` (FR-009/FR-010/FR-011;
|
|
62
|
+
* research R7; data-model Section 7): which canonical taxonomy name the
|
|
63
|
+
* assertion observes about its paired target.
|
|
64
|
+
*
|
|
65
|
+
* Error rows select by assertion type alone; value rows run US4's
|
|
66
|
+
* provenance passes ahead of the standard chain — a succeeding pass
|
|
67
|
+
* prefers the return family (`ReturnValue` → `GeneratorYield` →
|
|
68
|
+
* `AsyncGeneratorYield`), and with no return-family effect present, or
|
|
69
|
+
* no succeeding pass, the standard chain governs unchanged.
|
|
70
|
+
*
|
|
71
|
+
* Pure and total (Constitution Principles I and II): a deterministic
|
|
72
|
+
* function of the assertion's kind, the pair's AST evidence, and the
|
|
73
|
+
* target's effect set, defined for every shape including the empty set.
|
|
74
|
+
*
|
|
75
|
+
* @param assertion The classified assertion site.
|
|
76
|
+
* @param pair The test-to-target pair the row is being built for — the
|
|
77
|
+
* provenance-pass subject (unread by the fallback chains).
|
|
78
|
+
* @param effects The paired target's detected effects (`detectEffects`'
|
|
79
|
+
* output for its record), in effect-array order.
|
|
80
|
+
* @param provenance The pass inputs — live context and the test file's
|
|
81
|
+
* helper table. Optional so fallback-chain fixtures exercise FR-010 in
|
|
82
|
+
* isolation; the pipeline always supplies it.
|
|
83
|
+
* @returns The canonical side-effect type — one of the 48 taxonomy
|
|
84
|
+
* names, never an alias, never an omission.
|
|
85
|
+
*/
|
|
86
|
+
export declare function inferSideEffectType(assertion: AssertionSite, pair: Pairing, effects: readonly Effect[], provenance?: ProvenanceInputs): SideEffectType;
|