sensorium-trace 0.18.2__py3-none-any.whl
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.
- sensorium/__init__.py +0 -0
- sensorium/__main__.py +4 -0
- sensorium/_c/rt/sensorium_c_rt.c +1446 -0
- sensorium/_typescript/package-lock.json +68 -0
- sensorium/_typescript/package.json +39 -0
- sensorium/_typescript/src/bindings.mjs +792 -0
- sensorium/_typescript/src/cap.mjs +227 -0
- sensorium/_typescript/src/capabilities.mjs +40 -0
- sensorium/_typescript/src/dbg.mjs +348 -0
- sensorium/_typescript/src/escape.mjs +351 -0
- sensorium/_typescript/src/focus.mjs +135 -0
- sensorium/_typescript/src/hook.mjs +127 -0
- sensorium/_typescript/src/index.mjs +1 -0
- sensorium/_typescript/src/naming.mjs +63 -0
- sensorium/_typescript/src/positions.mjs +37 -0
- sensorium/_typescript/src/probe.mjs +246 -0
- sensorium/_typescript/src/qualname.mjs +236 -0
- sensorium/_typescript/src/redact.mjs +711 -0
- sensorium/_typescript/src/register.mjs +15 -0
- sensorium/_typescript/src/resolve.mjs +260 -0
- sensorium/_typescript/src/rt.mjs +798 -0
- sensorium/_typescript/src/setup.mjs +11 -0
- sensorium/_typescript/src/tally.mjs +164 -0
- sensorium/_typescript/src/tasks.mjs +175 -0
- sensorium/_typescript/src/transform.mjs +800 -0
- sensorium/_typescript/src/vite.mjs +99 -0
- sensorium/c/__init__.py +8 -0
- sensorium/c/cc.py +612 -0
- sensorium/c/cli.py +60 -0
- sensorium/c/convert.py +669 -0
- sensorium/c/decode.py +300 -0
- sensorium/c/driver.py +365 -0
- sensorium/c/dwarf.py +706 -0
- sensorium/c/format.py +271 -0
- sensorium/c/pkg.py +187 -0
- sensorium/c/plan.py +277 -0
- sensorium/cli.py +140 -0
- sensorium/driver.py +47 -0
- sensorium/exit.py +33 -0
- sensorium/invocations.py +83 -0
- sensorium/limits.py +253 -0
- sensorium/mcp/__init__.py +0 -0
- sensorium/mcp/audit.py +162 -0
- sensorium/mcp/child.py +240 -0
- sensorium/mcp/cmd.py +101 -0
- sensorium/mcp/jsonrpc.py +172 -0
- sensorium/mcp/result.py +187 -0
- sensorium/mcp/schema.py +390 -0
- sensorium/mcp/server.py +493 -0
- sensorium/mcp/tools.py +299 -0
- sensorium/paths.py +80 -0
- sensorium/query/__init__.py +0 -0
- sensorium/query/caps.py +150 -0
- sensorium/query/dbg_dialects.py +64 -0
- sensorium/query/diff_cmd.py +748 -0
- sensorium/query/diff_notes.py +117 -0
- sensorium/query/exceptions_c.py +263 -0
- sensorium/query/exceptions_cmd.py +788 -0
- sensorium/query/exceptions_group.py +571 -0
- sensorium/query/exceptions_invocation.py +487 -0
- sensorium/query/exceptions_rust.py +683 -0
- sensorium/query/exceptions_typescript.py +688 -0
- sensorium/query/expr.py +606 -0
- sensorium/query/failures_cmd.py +306 -0
- sensorium/query/flow_cmd.py +778 -0
- sensorium/query/flow_report.py +128 -0
- sensorium/query/flow_values.py +195 -0
- sensorium/query/fmt.py +280 -0
- sensorium/query/frame_cmd.py +237 -0
- sensorium/query/grep_cmd.py +156 -0
- sensorium/query/help.py +18 -0
- sensorium/query/info_cmd.py +527 -0
- sensorium/query/info_rust.py +214 -0
- sensorium/query/info_typescript.py +261 -0
- sensorium/query/js_inspect.py +394 -0
- sensorium/query/moves.py +254 -0
- sensorium/query/redact_cmd.py +304 -0
- sensorium/query/refocus_cmd.py +661 -0
- sensorium/query/refocus_env.py +493 -0
- sensorium/query/refocus_facts.py +269 -0
- sensorium/query/refocus_licence.py +187 -0
- sensorium/query/refocus_report.py +327 -0
- sensorium/query/refocus_rust.py +537 -0
- sensorium/query/refocus_threads.py +197 -0
- sensorium/query/refocus_typescript.py +756 -0
- sensorium/query/refocus_world.py +666 -0
- sensorium/query/runs_cmd.py +213 -0
- sensorium/query/rust_debug.py +176 -0
- sensorium/query/sites.py +171 -0
- sensorium/query/tree_cmd.py +511 -0
- sensorium/query/tree_threads.py +168 -0
- sensorium/query/vocab.py +723 -0
- sensorium/query/watch_cmd.py +657 -0
- sensorium/record/__init__.py +0 -0
- sensorium/record/boot.py +797 -0
- sensorium/record/boot_io.py +141 -0
- sensorium/record/budget.py +135 -0
- sensorium/record/capture.py +433 -0
- sensorium/record/children.py +755 -0
- sensorium/record/children_merge.py +179 -0
- sensorium/record/elide.py +55 -0
- sensorium/record/fingerprint.py +26 -0
- sensorium/record/thread_starts.py +261 -0
- sensorium/record/tracer.py +798 -0
- sensorium/record/tracer_exc.py +199 -0
- sensorium/record/tracer_frames.py +618 -0
- sensorium/redact.py +304 -0
- sensorium/redact_content.py +156 -0
- sensorium/redact_key.py +317 -0
- sensorium/redact_store.py +502 -0
- sensorium/redact_values.py +433 -0
- sensorium/store/__init__.py +0 -0
- sensorium/store/db.py +284 -0
- sensorium/store/gc.py +360 -0
- sensorium/store/payloads.py +69 -0
- sensorium/store/reader.py +438 -0
- sensorium/store/writer.py +283 -0
- sensorium/ts/__init__.py +10 -0
- sensorium/ts/build.py +783 -0
- sensorium/ts/cli.py +130 -0
- sensorium/ts/driver.py +472 -0
- sensorium/ts/focus.py +146 -0
- sensorium/ts/harness.py +314 -0
- sensorium/ts/ingest.py +380 -0
- sensorium/ts/invocation.py +252 -0
- sensorium/ts/pkg.py +167 -0
- sensorium/ts/redaction.py +64 -0
- sensorium/ts/spool.py +168 -0
- sensorium/ts/truncation.py +81 -0
- sensorium/ts/wrapper.py +255 -0
- sensorium_trace-0.18.2.dist-info/METADATA +245 -0
- sensorium_trace-0.18.2.dist-info/RECORD +135 -0
- sensorium_trace-0.18.2.dist-info/WHEEL +4 -0
- sensorium_trace-0.18.2.dist-info/entry_points.txt +3 -0
- sensorium_trace-0.18.2.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The vitest setup file: the harness's own names, on the runtime's terms.
|
|
2
|
+
// Two copies of this text exist and exactly one line differs between them — the
|
|
3
|
+
// runtime's import specifier. `src/setup.mjs` is the template the driver writes
|
|
4
|
+
// out with the package placeholder resolved; `probes/setup.mjs` is the same text
|
|
5
|
+
// with the in-tree relative path, so the probes run with no driver at all.
|
|
6
|
+
// `test/setup.test.mjs` holds the two to that single difference.
|
|
7
|
+
import { beforeEach, expect } from 'vitest';
|
|
8
|
+
import * as rt from '__PKG__/src/rt.mjs';
|
|
9
|
+
rt.nameProvider(() => expect.getState().currentTestName ?? null);
|
|
10
|
+
rt.fileStart(expect.getState().testPath ?? null, expect.getState().environment ?? null);
|
|
11
|
+
beforeEach(() => { rt.seen(expect.getState().currentTestName ?? null); });
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
// The invocation's transform counts, and the per-file manifests beside them.
|
|
2
|
+
//
|
|
3
|
+
// One module because BOTH harnesses count. The Vite plugin transforms in
|
|
4
|
+
// vitest's main process; the loader hook transforms on each `node --test`
|
|
5
|
+
// child's hook thread. Held in the plugin, as it was, the counts existed for
|
|
6
|
+
// vitest runs and for nothing else, and every `node --test` trace carried no
|
|
7
|
+
// coverage number at all — while `HONESTY.md` §7 said a CommonJS file "is
|
|
8
|
+
// excluded and counted".
|
|
9
|
+
//
|
|
10
|
+
// TWO WRITERS, because the two threads end differently, and both facts below
|
|
11
|
+
// were measured on node v24.16.0 rather than assumed:
|
|
12
|
+
//
|
|
13
|
+
// * the plugin installs a `process.on('exit')` writer. vitest transforms in
|
|
14
|
+
// one process for the whole invocation, so the count is still moving until
|
|
15
|
+
// that process ends, and a count that is still moving is not a count. The
|
|
16
|
+
// file is `_tally.json`: one invocation, one number, every container's;
|
|
17
|
+
// * the hook writes after every file it decides. An `exit` listener
|
|
18
|
+
// registered from a module-customization hook NEVER FIRES — the hooks
|
|
19
|
+
// thread is torn down with the process and runs no exit handlers — so an
|
|
20
|
+
// exit-time write from there would write nothing at all. The file is named
|
|
21
|
+
// by the CHILD's pid, because `node --test` runs one child process per test
|
|
22
|
+
// file (measured: five files, five pids) and one shared name would be five
|
|
23
|
+
// writers racing over one number. The count on such a trace is therefore
|
|
24
|
+
// that container's own transform, which is the only one it had.
|
|
25
|
+
//
|
|
26
|
+
// A tally that cannot be written says so on stderr: the run is not the tally's
|
|
27
|
+
// to fail, but a silently missing count would let the converter under-report
|
|
28
|
+
// without anyone knowing (design §7).
|
|
29
|
+
import fs from 'node:fs';
|
|
30
|
+
import path from 'node:path';
|
|
31
|
+
|
|
32
|
+
// 0700 and 0600, at creation — spec §5.5, and `rt.mjs`'s spelling for the
|
|
33
|
+
// spool beside this directory. A manifest names every function in a file of
|
|
34
|
+
// somebody's project and the absolute path it lives at; `_tally.json` names
|
|
35
|
+
// how much of their suite this recorder instrumented. Both were written with
|
|
36
|
+
// no mode at all until E16 part A measured them at 0775/0664 (H2).
|
|
37
|
+
//
|
|
38
|
+
// `mode` on `mkdirSync` applies to the directories this call CREATES and to
|
|
39
|
+
// nothing else, and `writeFileSync`'s applies only when it creates the file:
|
|
40
|
+
// a directory or a record already on disk keeps the permissions its owner
|
|
41
|
+
// chose, which is the position `perms.rs` and `paths.traces_dir()` take on
|
|
42
|
+
// the same store.
|
|
43
|
+
const DIR_MODE = 0o700;
|
|
44
|
+
const FILE_MODE = 0o600;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @typedef {{files_transformed: number, functions_focused: number,
|
|
48
|
+
* excluded: Record<string, number>}} Tally
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* `functions_focused` is how many function-likes the invocation's focus
|
|
53
|
+
* actually selected -- zero on every unfocused run, which is what says a trace
|
|
54
|
+
* with no LINE rows had nothing to record rather than a recorder that missed.
|
|
55
|
+
* @type {Tally}
|
|
56
|
+
*/
|
|
57
|
+
const tally = { files_transformed: 0, functions_focused: 0, excluded: {} };
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The files already counted. Vite keeps one module graph per transform mode, so
|
|
61
|
+
* a module a `node` file and a `jsdom` file both import is transformed TWICE
|
|
62
|
+
* (measured: `setup.mjs` under a mixed suite). A count of files that counted
|
|
63
|
+
* calls would over-report itself, and the converter would publish the inflation.
|
|
64
|
+
* @type {Set<string>}
|
|
65
|
+
*/
|
|
66
|
+
const counted = new Set();
|
|
67
|
+
|
|
68
|
+
/** The invocation-wide name, read by the converter for every container. */
|
|
69
|
+
export const INVOCATION_TALLY = '_tally.json';
|
|
70
|
+
|
|
71
|
+
/** One container's own, named by its pid: `_tally-<pid>.json`. */
|
|
72
|
+
export const containerTally = () => `_tally-${process.pid}.json`;
|
|
73
|
+
|
|
74
|
+
/** @returns {string} the directory the driver named, or '' when it named none */
|
|
75
|
+
export function dir() {
|
|
76
|
+
return process.env.SENSORIUM_MANIFEST_DIR ?? '';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @param {string} file absolute path
|
|
81
|
+
* @returns {boolean} whether this file has not been counted before
|
|
82
|
+
*/
|
|
83
|
+
function first(file) {
|
|
84
|
+
if (counted.has(file)) return false;
|
|
85
|
+
counted.add(file);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Count one file the transform declined without ever parsing it — the CommonJS
|
|
91
|
+
* verdict, which no per-file manifest can carry because there is no manifest.
|
|
92
|
+
* @param {string} file absolute path
|
|
93
|
+
* @param {string} reason
|
|
94
|
+
* @returns {void}
|
|
95
|
+
*/
|
|
96
|
+
export function exclude(file, reason) {
|
|
97
|
+
if (!first(file)) return;
|
|
98
|
+
tally.excluded[reason] = (tally.excluded[reason] ?? 0) + 1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Fold one transform result into the invocation's counts and write the file's
|
|
103
|
+
* own manifest. The manifest is written on every call and the counts move only
|
|
104
|
+
* on the first: the manifest is the same bytes either way, the count is not.
|
|
105
|
+
* @param {string} file absolute path
|
|
106
|
+
* @param {{code: string|null, manifest: import('./transform.mjs').Manifest}} out
|
|
107
|
+
* @param {string} dirname the manifest directory, or '' for none
|
|
108
|
+
* @returns {void}
|
|
109
|
+
*/
|
|
110
|
+
export function record(file, out, dirname) {
|
|
111
|
+
if (dirname) writeManifest(dirname, out.manifest);
|
|
112
|
+
if (!first(file)) return;
|
|
113
|
+
for (const [reason, n] of Object.entries(out.manifest.excluded ?? {})) {
|
|
114
|
+
tally.excluded[reason] = (tally.excluded[reason] ?? 0) + n;
|
|
115
|
+
}
|
|
116
|
+
// `code: null` is 'ours, untouched, counted' (R10): the file did not parse,
|
|
117
|
+
// its manifest says so, and it was not edited.
|
|
118
|
+
if (out.code !== null) tally.files_transformed += 1;
|
|
119
|
+
tally.functions_focused += out.manifest.focused.length;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The per-file manifest, named by its root-relative path with the separators
|
|
124
|
+
* flattened so one directory holds them all.
|
|
125
|
+
* @param {string} dirname
|
|
126
|
+
* @param {import('./transform.mjs').Manifest} manifest
|
|
127
|
+
* @returns {void}
|
|
128
|
+
*/
|
|
129
|
+
function writeManifest(dirname, manifest) {
|
|
130
|
+
fs.mkdirSync(dirname, { recursive: true, mode: DIR_MODE });
|
|
131
|
+
fs.writeFileSync(
|
|
132
|
+
path.join(dirname, `${manifest.rel.split('/').join('__')}.json`),
|
|
133
|
+
JSON.stringify(manifest),
|
|
134
|
+
{ mode: FILE_MODE },
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Write the counts as they stand.
|
|
140
|
+
* @param {string} dirname
|
|
141
|
+
* @param {string} name
|
|
142
|
+
* @returns {void}
|
|
143
|
+
*/
|
|
144
|
+
export function write(dirname, name) {
|
|
145
|
+
try {
|
|
146
|
+
fs.mkdirSync(dirname, { recursive: true, mode: DIR_MODE });
|
|
147
|
+
fs.writeFileSync(path.join(dirname, name), JSON.stringify(tally), { mode: FILE_MODE });
|
|
148
|
+
} catch (err) {
|
|
149
|
+
process.emitWarning(`sensorium: could not write the transform tally to ${dirname}: ${err}`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
let installed = false;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Write `_tally.json` once, when the process that did the transforming ends.
|
|
157
|
+
* @param {string} dirname
|
|
158
|
+
* @returns {void}
|
|
159
|
+
*/
|
|
160
|
+
export function installExitWriter(dirname) {
|
|
161
|
+
if (installed) return;
|
|
162
|
+
installed = true;
|
|
163
|
+
process.on('exit', () => write(dirname, INVOCATION_TALLY));
|
|
164
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
// The test-file rule and the task boundary. Split out of `transform.mjs`
|
|
2
|
+
// 2026-09-11 (S5 rung 4) because that file reached 765 lines against the
|
|
3
|
+
// repo-wide 800-line ceiling; every line below the imports is the line that
|
|
4
|
+
// was there, moved and not rewritten.
|
|
5
|
+
//
|
|
6
|
+
// What lives here is one question and one splice: whether a file holds tests
|
|
7
|
+
// (R8, R8b) — the answer the whole test/suite wrap is gated on — and the splice
|
|
8
|
+
// that hands a `test`/`describe` call's title and callback to the runtime
|
|
9
|
+
// (R8a, R8c), with the two callee sets and the two helpers only those need.
|
|
10
|
+
//
|
|
11
|
+
// The JSDoc `import('./transform.mjs')` below is a TYPE reference and emits no
|
|
12
|
+
// runtime import, so `transform.mjs` importing this module is not a cycle;
|
|
13
|
+
// were it one it would still be safe, since both modules only define.
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
|
|
16
|
+
/** @typedef {typeof import('typescript')} TS */
|
|
17
|
+
/** @typedef {import('typescript').Node} Node */
|
|
18
|
+
/** @typedef {import('typescript').SourceFile} SourceFile */
|
|
19
|
+
/** @typedef {import('./transform.mjs').Splicer} Splicer */
|
|
20
|
+
|
|
21
|
+
/** A file whose name says it holds tests, whatever it imports. */
|
|
22
|
+
const TEST_FILE = /\.(test|spec)\.[cm]?[jt]sx?$/;
|
|
23
|
+
/** A file that imports one of these holds tests, whatever it is named. */
|
|
24
|
+
const HARNESS_MODULES = new Set(['vitest', 'node:test', '@jest/globals']);
|
|
25
|
+
|
|
26
|
+
const TASK_CALLEES = new Set(['test', 'it']);
|
|
27
|
+
const SUITE_CALLEES = new Set(['describe', 'suite']);
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A type-only import brings no `test` to call: `import type { Mock } from
|
|
31
|
+
* 'vitest'`, or a clause whose every specifier is `type`-qualified, does not
|
|
32
|
+
* make a test file (R8b). A bare `import 'vitest'` does — it runs the harness.
|
|
33
|
+
* @param {TS} ts
|
|
34
|
+
* @param {import('typescript').ImportDeclaration} node
|
|
35
|
+
* @returns {boolean}
|
|
36
|
+
*/
|
|
37
|
+
function isTypeOnlyImport(ts, node) {
|
|
38
|
+
const clause = node.importClause;
|
|
39
|
+
if (!clause) return false;
|
|
40
|
+
if (clause.isTypeOnly) return true;
|
|
41
|
+
const bindings = clause.namedBindings;
|
|
42
|
+
if (!clause.name && bindings && ts.isNamedImports(bindings) && bindings.elements.length > 0) {
|
|
43
|
+
return bindings.elements.every((element) => element.isTypeOnly);
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Whether this file holds tests. The test/suite wrap applies here and nowhere
|
|
50
|
+
* else: `test`, `it`, `describe` and `suite` are ordinary identifiers, and a
|
|
51
|
+
* consumer may own them — the lens does, a local `describe(label, formula,
|
|
52
|
+
* value)` in `src/lib/combat/attackRoll.ts`. Rewriting that call would change
|
|
53
|
+
* what the program does, which is the one thing this recorder may never do.
|
|
54
|
+
* Inside a test file the rule is the opposite: every second argument is wrapped,
|
|
55
|
+
* an identifier included, so no task boundary goes missing (controller R8).
|
|
56
|
+
* @param {TS} ts
|
|
57
|
+
* @param {SourceFile} sf
|
|
58
|
+
* @param {string} filePath
|
|
59
|
+
* @returns {boolean}
|
|
60
|
+
*/
|
|
61
|
+
export function isTestFile(ts, sf, filePath) {
|
|
62
|
+
if (TEST_FILE.test(path.basename(filePath))) return true;
|
|
63
|
+
let found = false;
|
|
64
|
+
/** @param {Node} node */
|
|
65
|
+
const visit = (node) => {
|
|
66
|
+
if (found) return;
|
|
67
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier) &&
|
|
68
|
+
HARNESS_MODULES.has(node.moduleSpecifier.text) && !isTypeOnlyImport(ts, node)) {
|
|
69
|
+
found = true;
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (ts.isCallExpression(node) && node.arguments.length > 0 &&
|
|
73
|
+
ts.isStringLiteral(node.arguments[0]) &&
|
|
74
|
+
HARNESS_MODULES.has(node.arguments[0].text) &&
|
|
75
|
+
(node.expression.kind === ts.SyntaxKind.ImportKeyword ||
|
|
76
|
+
(ts.isIdentifier(node.expression) && node.expression.text === 'require'))) {
|
|
77
|
+
found = true;
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
ts.forEachChild(node, visit);
|
|
81
|
+
};
|
|
82
|
+
visit(sf);
|
|
83
|
+
return found;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The identifier chain of a call's callee — `test.each(table)` is
|
|
88
|
+
* `['test', 'each']` — or null when it is not rooted at a plain identifier.
|
|
89
|
+
* @param {TS} ts
|
|
90
|
+
* @param {import('typescript').Expression} callee
|
|
91
|
+
* @returns {string[]|null}
|
|
92
|
+
*/
|
|
93
|
+
function calleeChain(ts, callee) {
|
|
94
|
+
/** @type {string[]} */
|
|
95
|
+
const chain = [];
|
|
96
|
+
let cur = callee;
|
|
97
|
+
for (;;) {
|
|
98
|
+
if (ts.isCallExpression(cur)) { cur = cur.expression; continue; }
|
|
99
|
+
if (ts.isTaggedTemplateExpression(cur)) { cur = cur.tag; continue; }
|
|
100
|
+
if (ts.isPropertyAccessExpression(cur)) {
|
|
101
|
+
chain.unshift(cur.name.text);
|
|
102
|
+
cur = cur.expression;
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (ts.isIdentifier(cur)) { chain.unshift(cur.text); return chain; }
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {TS} ts
|
|
112
|
+
* @param {Node} node
|
|
113
|
+
* @returns {boolean} whether a test title is a literal string in the source
|
|
114
|
+
*/
|
|
115
|
+
function isLiteralTitle(ts, node) {
|
|
116
|
+
return ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A test or a suite: the title and the callback are handed to the runtime as the
|
|
121
|
+
* call's own argument list, and every other argument stays exactly where the
|
|
122
|
+
* source put it — nothing is moved, so nothing carries a line, or a closing
|
|
123
|
+
* splice, to a place it does not belong (R8c).
|
|
124
|
+
*
|
|
125
|
+
* The rule is file-scoped (R8, `isTestFile`). Inside a test file the callback
|
|
126
|
+
* argument is wrapped whatever its shape — a bare identifier included, which the
|
|
127
|
+
* runtime passes through unchanged — so no task boundary goes missing; outside
|
|
128
|
+
* one, nothing is wrapped, so a consumer's own `describe` is never rewritten.
|
|
129
|
+
*
|
|
130
|
+
* vitest also documents an options signature, `test(name, options, fn)`, where
|
|
131
|
+
* the second argument is not the callback (R8a). The callback is then the third,
|
|
132
|
+
* and the options simply stay between them:
|
|
133
|
+
*
|
|
134
|
+
* test("x", {timeout: 100}, fn, 5000)
|
|
135
|
+
* -> test(...__srt.task(("x"), {timeout: 100}, fn,1), 5000)
|
|
136
|
+
* describe("y", {concurrent: true}, fn, 1000)
|
|
137
|
+
* -> describe(...__srt.suite(("y"), {concurrent: true}, fn), 1000)
|
|
138
|
+
* test("x", fn) -> test(...__srt.task(("x"),fn,1))
|
|
139
|
+
* describe("x", fn) -> describe(...__srt.suite(("x"),fn))
|
|
140
|
+
*
|
|
141
|
+
* The runtime contract that pairs with it (Task 3) reads the argument list from
|
|
142
|
+
* the end: `task(title, ...rest)` with `rest = [...between, fn, flags]` — flags
|
|
143
|
+
* is always the last element and the callback the one before it — and
|
|
144
|
+
* `suite(title, ...rest)` with `rest = [...between, fn]`. Both return
|
|
145
|
+
* `[title, ...between, wrapped]`.
|
|
146
|
+
*
|
|
147
|
+
* Both closing insertions are `prependRight`, and both are registered here,
|
|
148
|
+
* before the call's own children are visited. `prependRight` renders in reverse
|
|
149
|
+
* registration order, so ours end up outermost and a closer a descendant puts on
|
|
150
|
+
* the same offset — an arrow title's, a conditional callback's, an `await`'s —
|
|
151
|
+
* is spliced inside ours rather than around it.
|
|
152
|
+
* @param {Splicer} ctx
|
|
153
|
+
* @param {import('typescript').CallExpression} node
|
|
154
|
+
*/
|
|
155
|
+
export function spliceTaskBoundary(ctx, node) {
|
|
156
|
+
const { ts, sf, s } = ctx;
|
|
157
|
+
if (!ctx.isTestFile || node.arguments.length < 2) return;
|
|
158
|
+
const chain = calleeChain(ts, node.expression);
|
|
159
|
+
if (!chain) return;
|
|
160
|
+
const isTask = TASK_CALLEES.has(chain[0]);
|
|
161
|
+
if (!isTask && !SUITE_CALLEES.has(chain[0])) return;
|
|
162
|
+
|
|
163
|
+
const title = node.arguments[0];
|
|
164
|
+
const hasOptions = ts.isObjectLiteralExpression(node.arguments[1]);
|
|
165
|
+
// `test(name, options)` names no callback at all: it is not a task.
|
|
166
|
+
if (hasOptions && node.arguments.length < 3) return;
|
|
167
|
+
const fn = node.arguments[hasOptions ? 2 : 1];
|
|
168
|
+
|
|
169
|
+
const flags = isTask
|
|
170
|
+
? `,${(isLiteralTitle(ts, title) ? 1 : 0) | (chain.includes('each') ? 2 : 0)}`
|
|
171
|
+
: '';
|
|
172
|
+
s.appendLeft(title.getStart(sf), `...__srt.${isTask ? 'task' : 'suite'}((`);
|
|
173
|
+
s.prependRight(title.end, ')');
|
|
174
|
+
s.prependRight(fn.end, `${flags})`);
|
|
175
|
+
}
|