@gate-forge/pack-playwright 0.13.8 → 0.13.10
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/discovery/discover.d.ts.map +1 -1
- package/dist/discovery/discover.js +157 -39
- package/dist/discovery/discover.js.map +1 -1
- package/dist/discovery/inference.d.ts.map +1 -1
- package/dist/discovery/inference.js +35 -14
- package/dist/discovery/inference.js.map +1 -1
- package/dist/discovery/reconcile.d.ts +8 -0
- package/dist/discovery/reconcile.d.ts.map +1 -1
- package/dist/discovery/reconcile.js +11 -0
- package/dist/discovery/reconcile.js.map +1 -1
- package/dist/discovery/static-discovery.d.ts +40 -17
- package/dist/discovery/static-discovery.d.ts.map +1 -1
- package/dist/discovery/static-discovery.js +1250 -87
- package/dist/discovery/static-discovery.js.map +1 -1
- package/dist/fixture/api-request.d.ts +15 -102
- package/dist/fixture/api-request.d.ts.map +1 -1
- package/dist/fixture/api-request.js +27 -101
- package/dist/fixture/api-request.js.map +1 -1
- package/dist/fixture/fixture.d.ts +16 -25
- package/dist/fixture/fixture.d.ts.map +1 -1
- package/dist/fixture/fixture.js +184 -66
- package/dist/fixture/fixture.js.map +1 -1
- package/dist/reporter/project-graph-reporter.d.ts +11 -1
- package/dist/reporter/project-graph-reporter.d.ts.map +1 -1
- package/dist/reporter/project-graph-reporter.js +16 -0
- package/dist/reporter/project-graph-reporter.js.map +1 -1
- package/package.json +3 -3
|
@@ -35,8 +35,13 @@ import ts from 'typescript';
|
|
|
35
35
|
import { pathInScope } from '@gate-forge/core';
|
|
36
36
|
import { CLAIM_ANNOTATION_TYPE } from '../constants.js';
|
|
37
37
|
import { gitIgnoredPaths } from './git-ignore.js';
|
|
38
|
-
/**
|
|
39
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Default cap on files pulled in through import traversal. A guard against
|
|
40
|
+
* runaway import graphs, not a proof rule: exceeding it still fails closed.
|
|
41
|
+
* Sized for real suites whose every listed spec is read (one measured app:
|
|
42
|
+
* 147 spec files pulled 266 helper files) at the same scan time.
|
|
43
|
+
*/
|
|
44
|
+
export const DEFAULT_MAX_TRAVERSED_FILES = 2000;
|
|
40
45
|
/** Default bound on import-traversal depth (chain length). */
|
|
41
46
|
export const DEFAULT_MAX_IMPORT_DEPTH = 16;
|
|
42
47
|
/** Placeholder titlePath for unresolved calls with no readable title. */
|
|
@@ -45,6 +50,42 @@ export const UNRESOLVED_TITLE_PLACEHOLDER = '<unresolved-title>';
|
|
|
45
50
|
const PRUNED_DIRS = new Set(['.git', 'node_modules', 'dist', 'test-results', 'playwright-report']);
|
|
46
51
|
/** File extensions the scanner parses (everything else is skipped). */
|
|
47
52
|
const PARSEABLE_EXTENSIONS = ['.ts', '.tsx', '.mts', '.cts', '.js', '.jsx', '.mjs', '.cjs'];
|
|
53
|
+
/**
|
|
54
|
+
* TypeScript's ESM extension substitution (0.13.9): a RELATIVE specifier
|
|
55
|
+
* that literally ends in one of these JavaScript extensions names the
|
|
56
|
+
* TypeScript sibling of the same stem whenever the literal file does not
|
|
57
|
+
* exist — `.js` prefers `.ts` and falls back to `.tsx`; `.mjs`, `.cjs`,
|
|
58
|
+
* and `.jsx` map one-to-one. This is exactly the rule the runner's own
|
|
59
|
+
* loader applies, so `./helpers.mjs` on disk as `helpers.mts` resolves
|
|
60
|
+
* here the way it resolves at runtime; without it every such spec
|
|
61
|
+
* sprouted a blocking `<unresolved-title>` row the runner provably
|
|
62
|
+
* enumerated (0.13.9 consumer run). The suffixes are mutually exclusive
|
|
63
|
+
* (`.mjs`/`.cjs`/`.jsx` never end in a literal `.js`), so first match
|
|
64
|
+
* wins.
|
|
65
|
+
*/
|
|
66
|
+
const TS_EXTENSION_SUBSTITUTIONS = [
|
|
67
|
+
['.js', ['.ts', '.tsx']],
|
|
68
|
+
['.mjs', ['.mts']],
|
|
69
|
+
['.cjs', ['.cts']],
|
|
70
|
+
['.jsx', ['.tsx']],
|
|
71
|
+
];
|
|
72
|
+
/**
|
|
73
|
+
* The TypeScript-sibling candidates for a `.js`-style specifier.
|
|
74
|
+
*
|
|
75
|
+
* Args:
|
|
76
|
+
* joined: the repo-relative specifier path with the JS extension.
|
|
77
|
+
*
|
|
78
|
+
* Returns:
|
|
79
|
+
* string[]: same-stem TypeScript paths, best-first; empty when the
|
|
80
|
+
* specifier does not end in a substitutable extension.
|
|
81
|
+
*/
|
|
82
|
+
function typescriptSubstituteCandidates(joined) {
|
|
83
|
+
for (const [from, to] of TS_EXTENSION_SUBSTITUTIONS) {
|
|
84
|
+
if (joined.endsWith(from))
|
|
85
|
+
return to.map((extension) => `${joined.slice(0, -from.length)}${extension}`);
|
|
86
|
+
}
|
|
87
|
+
return [];
|
|
88
|
+
}
|
|
48
89
|
/** Playwright's exported test-function binding names. */
|
|
49
90
|
const TEST_BINDING_NAMES = new Set(['test', 'it']);
|
|
50
91
|
/**
|
|
@@ -57,19 +98,93 @@ const TEST_BINDING_NAMES = new Set(['test', 'it']);
|
|
|
57
98
|
*/
|
|
58
99
|
const TEST_STRUCTURE_NAMES = new Set(['test', 'it', 'describe']);
|
|
59
100
|
/**
|
|
60
|
-
* The
|
|
61
|
-
*
|
|
62
|
-
* `
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* instead of emitting unresolvable rows for it. Every OTHER
|
|
67
|
-
* module-external import stays unresolved — fail-closed is unchanged.
|
|
101
|
+
* The package root and exported `fixture` subpath both expose the pack's
|
|
102
|
+
* Playwright test function (`base.extend` over `playwright/test` — see
|
|
103
|
+
* `fixture/fixture.ts`). Binding either sanctioned runner source lets the
|
|
104
|
+
* static scan follow documented package imports instead of emitting
|
|
105
|
+
* unresolvable rows. Every OTHER module-external import stays unresolved —
|
|
106
|
+
* fail-closed is unchanged.
|
|
68
107
|
*/
|
|
69
108
|
export const GATEFORGE_PACK_SPECIFIER = '@gate-forge/pack-playwright';
|
|
70
|
-
/**
|
|
71
|
-
function
|
|
72
|
-
|
|
109
|
+
/** Reads package metadata without loading or executing consumer code. */
|
|
110
|
+
function readPackageMetadata(state, absolutePath) {
|
|
111
|
+
const cached = state.packageMetadata.get(absolutePath);
|
|
112
|
+
if (cached !== undefined)
|
|
113
|
+
return cached;
|
|
114
|
+
let metadata = null;
|
|
115
|
+
if (isFile(absolutePath)) {
|
|
116
|
+
try {
|
|
117
|
+
const parsed = JSON.parse(readFileSync(absolutePath, 'utf8'));
|
|
118
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
|
119
|
+
metadata = parsed;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
// Invalid package metadata is not proof of package identity.
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
state.packageMetadata.set(absolutePath, metadata);
|
|
127
|
+
return metadata;
|
|
128
|
+
}
|
|
129
|
+
function packageDeclaresAlias(metadata, alias) {
|
|
130
|
+
if (metadata === null)
|
|
131
|
+
return false;
|
|
132
|
+
for (const field of ['dependencies', 'devDependencies', 'optionalDependencies']) {
|
|
133
|
+
const group = metadata[field];
|
|
134
|
+
if (typeof group !== 'object' || group === null || Array.isArray(group))
|
|
135
|
+
continue;
|
|
136
|
+
const target = group[alias];
|
|
137
|
+
if (typeof target === 'string' &&
|
|
138
|
+
(target === `npm:${GATEFORGE_PACK_SPECIFIER}` ||
|
|
139
|
+
(target.startsWith(`npm:${GATEFORGE_PACK_SPECIFIER}@`) &&
|
|
140
|
+
target.length > `npm:${GATEFORGE_PACK_SPECIFIER}@`.length))) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
/** Whether a bare package name is proven to alias the Gateforge package. */
|
|
147
|
+
function isGateforgePackageAlias(state, file, alias) {
|
|
148
|
+
if (!/^(?:@[a-z0-9._-]+\/)?[a-z0-9._-]+$/i.test(alias))
|
|
149
|
+
return false;
|
|
150
|
+
const rootPackage = readPackageMetadata(state, join(state.cwd, 'package.json'));
|
|
151
|
+
if (packageDeclaresAlias(rootPackage, alias))
|
|
152
|
+
return true;
|
|
153
|
+
let directory = join(state.cwd, posix.dirname(file));
|
|
154
|
+
let nearestPackagePath = null;
|
|
155
|
+
while (directory === state.cwd || directory.startsWith(`${state.cwd}/`)) {
|
|
156
|
+
const candidate = join(directory, 'package.json');
|
|
157
|
+
if (isFile(candidate)) {
|
|
158
|
+
nearestPackagePath = candidate;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
if (directory === state.cwd)
|
|
162
|
+
break;
|
|
163
|
+
directory = posix.dirname(directory);
|
|
164
|
+
}
|
|
165
|
+
if (nearestPackagePath !== null &&
|
|
166
|
+
nearestPackagePath !== join(state.cwd, 'package.json') &&
|
|
167
|
+
packageDeclaresAlias(readPackageMetadata(state, nearestPackagePath), alias)) {
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
directory = join(state.cwd, posix.dirname(file));
|
|
171
|
+
while (directory === state.cwd || directory.startsWith(`${state.cwd}/`)) {
|
|
172
|
+
const installed = readPackageMetadata(state, join(directory, 'node_modules', alias, 'package.json'));
|
|
173
|
+
if (installed?.name === GATEFORGE_PACK_SPECIFIER)
|
|
174
|
+
return true;
|
|
175
|
+
if (directory === state.cwd)
|
|
176
|
+
break;
|
|
177
|
+
directory = posix.dirname(directory);
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
/** Whether the specifier is the Gateforge package's runner module. */
|
|
182
|
+
function isPackSpecifier(state, file, specifier) {
|
|
183
|
+
const suffix = '/fixture';
|
|
184
|
+
const packageName = specifier.endsWith(suffix) ? specifier.slice(0, -suffix.length) : specifier;
|
|
185
|
+
if (packageName === GATEFORGE_PACK_SPECIFIER)
|
|
186
|
+
return true;
|
|
187
|
+
return isGateforgePackageAlias(state, file, packageName);
|
|
73
188
|
}
|
|
74
189
|
/** Chain segments that modify a test/describe call without changing identity. */
|
|
75
190
|
const SUPPRESSION_SEGMENTS = new Set(['skip', 'only', 'fixme']);
|
|
@@ -425,6 +540,11 @@ function modelModuleScope(state, cwd, model, source) {
|
|
|
425
540
|
model.bindings.set(local, { kind: 'import', target, importedName: imported });
|
|
426
541
|
return;
|
|
427
542
|
}
|
|
543
|
+
const jsonData = jsonDataModuleTarget(cwd, model.file, specifier);
|
|
544
|
+
if (jsonData !== null) {
|
|
545
|
+
model.bindings.set(local, { kind: 'data' });
|
|
546
|
+
return;
|
|
547
|
+
}
|
|
428
548
|
model.bindings.set(local, { kind: 'import-broken', importedName: imported });
|
|
429
549
|
state.result.unresolved.push({
|
|
430
550
|
code: 'unresolved-import',
|
|
@@ -442,7 +562,7 @@ function modelModuleScope(state, cwd, model, source) {
|
|
|
442
562
|
for (const element of clause.namedBindings.elements) {
|
|
443
563
|
const imported = element.propertyName?.text ?? element.name.text;
|
|
444
564
|
const local = element.name.text;
|
|
445
|
-
if (TEST_BINDING_NAMES.has(imported) && isTestModuleSpecifier(specifier)) {
|
|
565
|
+
if (TEST_BINDING_NAMES.has(imported) && isTestModuleSpecifier(state, model.file, specifier)) {
|
|
446
566
|
model.bindings.set(local, { kind: 'test' });
|
|
447
567
|
}
|
|
448
568
|
else {
|
|
@@ -454,7 +574,7 @@ function modelModuleScope(state, cwd, model, source) {
|
|
|
454
574
|
// object (test-module when the specifier is the test module).
|
|
455
575
|
if (clause?.namedBindings !== undefined && ts.isNamespaceImport(clause.namedBindings)) {
|
|
456
576
|
const local = clause.namedBindings.name.text;
|
|
457
|
-
if (isTestModuleSpecifier(specifier)) {
|
|
577
|
+
if (isTestModuleSpecifier(state, model.file, specifier)) {
|
|
458
578
|
model.bindings.set(local, { kind: 'testmodule' });
|
|
459
579
|
}
|
|
460
580
|
else {
|
|
@@ -473,7 +593,7 @@ function modelModuleScope(state, cwd, model, source) {
|
|
|
473
593
|
if (specifier !== undefined && ts.isStringLiteral(specifier)) {
|
|
474
594
|
if (node.exportClause !== undefined &&
|
|
475
595
|
ts.isNamedExports(node.exportClause) &&
|
|
476
|
-
isPackSpecifier(specifier.text)) {
|
|
596
|
+
isPackSpecifier(state, model.file, specifier.text)) {
|
|
477
597
|
// Bare re-export of the pack's own surface (the sanctioned
|
|
478
598
|
// local runner-module pattern, e.g. the consumer's
|
|
479
599
|
// `helpers.js`: `export { test } from '@gate-forge/pack-playwright'`).
|
|
@@ -541,7 +661,7 @@ function modelModuleScope(state, cwd, model, source) {
|
|
|
541
661
|
initializer.arguments.length > 0 &&
|
|
542
662
|
initializer.arguments[0] !== undefined &&
|
|
543
663
|
ts.isStringLiteral(initializer.arguments[0]) &&
|
|
544
|
-
isTestModuleSpecifier(initializer.arguments[0].text)) {
|
|
664
|
+
isTestModuleSpecifier(state, model.file, initializer.arguments[0].text)) {
|
|
545
665
|
// `const base = require('@playwright/test')`: the module object
|
|
546
666
|
// whose `.test` is the test function. Bare requires of any other
|
|
547
667
|
// specifier bind nothing (ordinary library calls, not aliases).
|
|
@@ -591,7 +711,7 @@ function modelModuleScope(state, cwd, model, source) {
|
|
|
591
711
|
? element.propertyName.text
|
|
592
712
|
: element.name.text);
|
|
593
713
|
const local = element.name.text;
|
|
594
|
-
if (TEST_BINDING_NAMES.has(imported) && isTestModuleSpecifier(specifier)) {
|
|
714
|
+
if (TEST_BINDING_NAMES.has(imported) && isTestModuleSpecifier(state, model.file, specifier)) {
|
|
595
715
|
model.bindings.set(local, { kind: 'test' });
|
|
596
716
|
}
|
|
597
717
|
else if (specifier.startsWith('./') || specifier.startsWith('../')) {
|
|
@@ -599,6 +719,9 @@ function modelModuleScope(state, cwd, model, source) {
|
|
|
599
719
|
if (target !== null) {
|
|
600
720
|
model.bindings.set(local, { kind: 'import', target, importedName: imported });
|
|
601
721
|
}
|
|
722
|
+
else if (jsonDataModuleTarget(cwd, model.file, specifier) !== null) {
|
|
723
|
+
model.bindings.set(local, { kind: 'data' });
|
|
724
|
+
}
|
|
602
725
|
else {
|
|
603
726
|
// Same failed-binding marker as the ESM path above: the
|
|
604
727
|
// name was meant as an alias, so later test-shaped calls
|
|
@@ -628,11 +751,41 @@ function modelModuleScope(state, cwd, model, source) {
|
|
|
628
751
|
model.exports.set(name, { local: name });
|
|
629
752
|
}
|
|
630
753
|
}
|
|
631
|
-
// CJS exports: `module.exports
|
|
632
|
-
//
|
|
633
|
-
//
|
|
754
|
+
// CJS exports: property assignments on `exports`/`module.exports` and
|
|
755
|
+
// object assignment via `module.exports = { test, seed: runSeed }`.
|
|
756
|
+
// These map exports back to bindings so local require chains resolve.
|
|
634
757
|
if (ts.isExpressionStatement(node) && isModuleScope(node)) {
|
|
635
758
|
const expr = node.expression;
|
|
759
|
+
if (ts.isBinaryExpression(expr) &&
|
|
760
|
+
expr.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
761
|
+
ts.isPropertyAccessExpression(expr.left)) {
|
|
762
|
+
const owner = expr.left.expression;
|
|
763
|
+
const exportName = expr.left.name.text;
|
|
764
|
+
const isExportsProperty = (ts.isIdentifier(owner) && owner.text === 'exports') ||
|
|
765
|
+
(ts.isPropertyAccessExpression(owner) &&
|
|
766
|
+
owner.name.text === 'exports' &&
|
|
767
|
+
ts.isIdentifier(owner.expression) &&
|
|
768
|
+
owner.expression.text === 'module');
|
|
769
|
+
if (isExportsProperty) {
|
|
770
|
+
let target = ts.isIdentifier(expr.right) ? expr.right.text : null;
|
|
771
|
+
if (target === null &&
|
|
772
|
+
ts.isCallExpression(expr.right) &&
|
|
773
|
+
ts.isPropertyAccessExpression(expr.right.expression) &&
|
|
774
|
+
expr.right.expression.name.text === 'extend') {
|
|
775
|
+
const extended = expr.right.expression.expression;
|
|
776
|
+
if (ts.isIdentifier(extended)) {
|
|
777
|
+
target = extended.text;
|
|
778
|
+
}
|
|
779
|
+
else if (ts.isPropertyAccessExpression(extended) &&
|
|
780
|
+
(extended.name.text === 'test' || extended.name.text === 'it') &&
|
|
781
|
+
ts.isIdentifier(extended.expression)) {
|
|
782
|
+
target = extended.expression.text;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
model.bindings.set(exportName, target === null ? { kind: 'unresolvable' } : { kind: 'alias', target });
|
|
786
|
+
model.exports.set(exportName, { local: exportName });
|
|
787
|
+
}
|
|
788
|
+
}
|
|
636
789
|
if (ts.isBinaryExpression(expr) &&
|
|
637
790
|
expr.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
638
791
|
ts.isPropertyAccessExpression(expr.left) &&
|
|
@@ -656,6 +809,19 @@ function modelModuleScope(state, cwd, model, source) {
|
|
|
656
809
|
};
|
|
657
810
|
visit(source);
|
|
658
811
|
}
|
|
812
|
+
/**
|
|
813
|
+
* Resolves a relative specifier that names an EXISTING .json document:
|
|
814
|
+
* a data module the scan never parses (fresh-clone snag 5b: parsing one
|
|
815
|
+
* flooded the catalog with parse errors). Null when the specifier does
|
|
816
|
+
* not end in .json or names no existing regular file — that shape stays
|
|
817
|
+
* a visible unresolved-import row.
|
|
818
|
+
*/
|
|
819
|
+
function jsonDataModuleTarget(cwd, fromFile, specifier) {
|
|
820
|
+
if (!specifier.endsWith('.json'))
|
|
821
|
+
return null;
|
|
822
|
+
const joined = posix.normalize(posix.join(posix.dirname(fromFile), specifier));
|
|
823
|
+
return isFile(join(cwd, joined)) ? joined : null;
|
|
824
|
+
}
|
|
659
825
|
/** Whether the specifier is playwright's own test module. */
|
|
660
826
|
function isPlaywrightSpecifier(specifier) {
|
|
661
827
|
return specifier === '@playwright/test' || specifier === 'playwright/test' || specifier === 'playwright';
|
|
@@ -666,8 +832,8 @@ function isPlaywrightSpecifier(specifier) {
|
|
|
666
832
|
* exported `test` is a `base.extend` over playwright's — see
|
|
667
833
|
* {@link GATEFORGE_PACK_SPECIFIER}).
|
|
668
834
|
*/
|
|
669
|
-
function isTestModuleSpecifier(specifier) {
|
|
670
|
-
return isPlaywrightSpecifier(specifier) || isPackSpecifier(specifier);
|
|
835
|
+
function isTestModuleSpecifier(state, file, specifier) {
|
|
836
|
+
return isPlaywrightSpecifier(specifier) || isPackSpecifier(state, file, specifier);
|
|
671
837
|
}
|
|
672
838
|
/**
|
|
673
839
|
* Resolves a relative specifier the way node/TS resolve it: a FILE
|
|
@@ -711,6 +877,18 @@ function resolveSpecifier(state, cwd, fromFile, specifier) {
|
|
|
711
877
|
if (isFile(join(cwd, candidate)))
|
|
712
878
|
return candidate;
|
|
713
879
|
}
|
|
880
|
+
// TypeScript's extension substitution (0.13.9), only after EVERY
|
|
881
|
+
// literal candidate failed — the literal file always wins when it
|
|
882
|
+
// exists, exactly as TypeScript resolves it.
|
|
883
|
+
const substituted = typescriptSubstituteCandidates(joined);
|
|
884
|
+
for (const candidate of substituted) {
|
|
885
|
+
if (state.seeded.has(candidate) || state.traversed.has(candidate))
|
|
886
|
+
return candidate;
|
|
887
|
+
}
|
|
888
|
+
for (const candidate of substituted) {
|
|
889
|
+
if (isFile(join(cwd, candidate)))
|
|
890
|
+
return candidate;
|
|
891
|
+
}
|
|
714
892
|
return null;
|
|
715
893
|
}
|
|
716
894
|
/**
|
|
@@ -759,6 +937,8 @@ function resolveTestAlias(state, cwd, file, name, depth) {
|
|
|
759
937
|
return 'testmodule';
|
|
760
938
|
if (binding.kind === 'plain')
|
|
761
939
|
return 'not-a-test';
|
|
940
|
+
if (binding.kind === 'data')
|
|
941
|
+
return 'not-a-test';
|
|
762
942
|
if (binding.kind === 'import-broken')
|
|
763
943
|
return 'unknown';
|
|
764
944
|
if (binding.kind === 'external')
|
|
@@ -853,7 +1033,16 @@ function signatureParamsOf(callback) {
|
|
|
853
1033
|
* real browser journey.
|
|
854
1034
|
*/
|
|
855
1035
|
export const BROWSER_FIXTURE_PARAMS = new Set(['page', 'browser', 'context', 'browserName', 'evidence']);
|
|
856
|
-
const HTTP_CLIENT_CALLEES =
|
|
1036
|
+
const HTTP_CLIENT_CALLEES = { fetch: true, axios: true };
|
|
1037
|
+
const PLAYWRIGHT_REQUEST_METHODS = {
|
|
1038
|
+
delete: true,
|
|
1039
|
+
fetch: true,
|
|
1040
|
+
get: true,
|
|
1041
|
+
head: true,
|
|
1042
|
+
patch: true,
|
|
1043
|
+
post: true,
|
|
1044
|
+
put: true,
|
|
1045
|
+
};
|
|
857
1046
|
/** Whether the subtree contains `<x>.route(` — playwright interception. */
|
|
858
1047
|
function findPageRoute(node, source, file) {
|
|
859
1048
|
let found = null;
|
|
@@ -900,17 +1089,31 @@ function pageRouteTargets(node) {
|
|
|
900
1089
|
visit(node);
|
|
901
1090
|
return [...targets].sort();
|
|
902
1091
|
}
|
|
903
|
-
/**
|
|
904
|
-
|
|
1092
|
+
/**
|
|
1093
|
+
* Whether the subtree calls fetch/axios or a Playwright APIRequestContext method.
|
|
1094
|
+
* `includeFetchAxios` is false when following an imported test helper: product
|
|
1095
|
+
* modules commonly use fetch/axios, but those calls are not Playwright API evidence.
|
|
1096
|
+
*/
|
|
1097
|
+
function findHttpClientCall(node, source, file, includePlaywrightRequests = true, includeFetchAxios = true) {
|
|
905
1098
|
let found = null;
|
|
906
1099
|
const visit = (current) => {
|
|
907
1100
|
if (found !== null)
|
|
908
1101
|
return;
|
|
909
1102
|
if (ts.isCallExpression(current)) {
|
|
910
1103
|
const chain = calleeChain(current.expression);
|
|
911
|
-
if (chain !== null
|
|
912
|
-
|
|
913
|
-
|
|
1104
|
+
if (chain !== null) {
|
|
1105
|
+
const method = chain.names[chain.names.length - 1];
|
|
1106
|
+
const playwrightRequest = includePlaywrightRequests &&
|
|
1107
|
+
method !== undefined &&
|
|
1108
|
+
PLAYWRIGHT_REQUEST_METHODS[method] === true &&
|
|
1109
|
+
((chain.base === 'request' && chain.names.length === 1) ||
|
|
1110
|
+
((chain.base === 'page' || chain.base === 'context') &&
|
|
1111
|
+
chain.names.length === 2 &&
|
|
1112
|
+
chain.names[0] === 'request'));
|
|
1113
|
+
if ((includeFetchAxios && HTTP_CLIENT_CALLEES[chain.base] === true) || playwrightRequest) {
|
|
1114
|
+
found = locationOf(file, source, current);
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
914
1117
|
}
|
|
915
1118
|
}
|
|
916
1119
|
ts.forEachChild(current, visit);
|
|
@@ -918,15 +1121,37 @@ function findHttpClientCall(node, source, file) {
|
|
|
918
1121
|
visit(node);
|
|
919
1122
|
return found;
|
|
920
1123
|
}
|
|
1124
|
+
/** Whether a module path identifies test infrastructure rather than product code. */
|
|
1125
|
+
function isTestInfrastructureFile(file) {
|
|
1126
|
+
const segments = file.split('/').map((segment) => segment.toLowerCase());
|
|
1127
|
+
const sourceRoots = { app: true, src: true };
|
|
1128
|
+
const testMarkers = {
|
|
1129
|
+
e2e: true,
|
|
1130
|
+
fixture: true,
|
|
1131
|
+
fixtures: true,
|
|
1132
|
+
spec: true,
|
|
1133
|
+
specs: true,
|
|
1134
|
+
test: true,
|
|
1135
|
+
tests: true,
|
|
1136
|
+
'__tests__': true,
|
|
1137
|
+
'test-fixtures': true,
|
|
1138
|
+
'test-helpers': true,
|
|
1139
|
+
'test-support': true,
|
|
1140
|
+
'test-utils': true,
|
|
1141
|
+
};
|
|
1142
|
+
const sourceRoot = segments.findIndex((segment) => sourceRoots[segment] === true);
|
|
1143
|
+
const candidates = sourceRoot < 0 ? segments : segments.slice(sourceRoot + 1);
|
|
1144
|
+
return candidates.some((segment) => testMarkers[segment] === true);
|
|
1145
|
+
}
|
|
921
1146
|
/** Whether the file imports the gateforge evidence pack (fixture tests). */
|
|
922
|
-
function findGateforgeFixtureImport(source, file) {
|
|
1147
|
+
function findGateforgeFixtureImport(state, source, file) {
|
|
923
1148
|
let found = null;
|
|
924
1149
|
const visit = (node) => {
|
|
925
1150
|
if (found !== null)
|
|
926
1151
|
return;
|
|
927
1152
|
if (ts.isImportDeclaration(node) &&
|
|
928
1153
|
ts.isStringLiteral(node.moduleSpecifier) &&
|
|
929
|
-
isPackSpecifier(node.moduleSpecifier.text)) {
|
|
1154
|
+
isPackSpecifier(state, file, node.moduleSpecifier.text)) {
|
|
930
1155
|
found = locationOf(file, source, node);
|
|
931
1156
|
return;
|
|
932
1157
|
}
|
|
@@ -935,7 +1160,7 @@ function findGateforgeFixtureImport(source, file) {
|
|
|
935
1160
|
ts.isIdentifier(node.expression) &&
|
|
936
1161
|
node.expression.text === 'require') {
|
|
937
1162
|
const specifier = node.arguments[0];
|
|
938
|
-
if (specifier !== undefined && ts.isStringLiteral(specifier) && isPackSpecifier(specifier.text)) {
|
|
1163
|
+
if (specifier !== undefined && ts.isStringLiteral(specifier) && isPackSpecifier(state, file, specifier.text)) {
|
|
939
1164
|
found = locationOf(file, source, node);
|
|
940
1165
|
return;
|
|
941
1166
|
}
|
|
@@ -967,6 +1192,7 @@ function findModuleMock(source, file) {
|
|
|
967
1192
|
/** The storage mutations a storage-only init script may make. */
|
|
968
1193
|
const SAFE_STORAGE_METHODS = {
|
|
969
1194
|
clear: true,
|
|
1195
|
+
getItem: true,
|
|
970
1196
|
removeItem: true,
|
|
971
1197
|
setItem: true,
|
|
972
1198
|
};
|
|
@@ -979,8 +1205,168 @@ function storageReceiverName(node) {
|
|
|
979
1205
|
}
|
|
980
1206
|
return ts.isIdentifier(node) ? node.text : null;
|
|
981
1207
|
}
|
|
982
|
-
/**
|
|
983
|
-
|
|
1208
|
+
/**
|
|
1209
|
+
* Resolves a name to a variable initializer declared in a block (or
|
|
1210
|
+
* module scope) enclosing `from`, walking outward — the lexical lookup
|
|
1211
|
+
* a closure reference performs, innermost block winning. `let`/`var`
|
|
1212
|
+
* count too: the grammar below admits only values that are inert data,
|
|
1213
|
+
* so a reassigned binding can add no capability.
|
|
1214
|
+
*/
|
|
1215
|
+
function resolveLocalInitializer(name, from) {
|
|
1216
|
+
let current = from.parent;
|
|
1217
|
+
while (current !== undefined) {
|
|
1218
|
+
if (ts.isBlock(current) || ts.isSourceFile(current)) {
|
|
1219
|
+
for (const statement of current.statements) {
|
|
1220
|
+
if (!ts.isVariableStatement(statement))
|
|
1221
|
+
continue;
|
|
1222
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
1223
|
+
if (ts.isIdentifier(declaration.name) && declaration.name.text === name) {
|
|
1224
|
+
return declaration.initializer;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
current = current.parent;
|
|
1230
|
+
}
|
|
1231
|
+
return undefined;
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Resolves a name to a function declared in a block (or module scope)
|
|
1235
|
+
* enclosing `from`: a function declaration, a variable whose
|
|
1236
|
+
* initializer is the function itself, or — one bounded hop, cycle
|
|
1237
|
+
* guarded — an alias to another such name. Null when the name is not a
|
|
1238
|
+
* locally declared function: a reference form the scan cannot prove
|
|
1239
|
+
* stays a tamper.
|
|
1240
|
+
*/
|
|
1241
|
+
function resolveLocalFunctionReference(name, from, depth, seen) {
|
|
1242
|
+
if (depth > 4 || seen.has(name))
|
|
1243
|
+
return null;
|
|
1244
|
+
let current = from.parent;
|
|
1245
|
+
while (current !== undefined) {
|
|
1246
|
+
if (ts.isBlock(current) || ts.isSourceFile(current)) {
|
|
1247
|
+
for (const statement of current.statements) {
|
|
1248
|
+
if (ts.isFunctionDeclaration(statement) && statement.name !== undefined && statement.name.text === name && statement.body !== undefined) {
|
|
1249
|
+
return statement;
|
|
1250
|
+
}
|
|
1251
|
+
if (!ts.isVariableStatement(statement))
|
|
1252
|
+
continue;
|
|
1253
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
1254
|
+
if (!ts.isIdentifier(declaration.name) || declaration.name.text !== name)
|
|
1255
|
+
continue;
|
|
1256
|
+
const initializer = declaration.initializer;
|
|
1257
|
+
if (initializer === undefined)
|
|
1258
|
+
return null;
|
|
1259
|
+
if (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer))
|
|
1260
|
+
return initializer;
|
|
1261
|
+
if (ts.isIdentifier(initializer)) {
|
|
1262
|
+
const next = new Set(seen);
|
|
1263
|
+
next.add(name);
|
|
1264
|
+
return resolveLocalFunctionReference(initializer.text, declaration, depth + 1, next);
|
|
1265
|
+
}
|
|
1266
|
+
return null;
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
current = current.parent;
|
|
1271
|
+
}
|
|
1272
|
+
return null;
|
|
1273
|
+
}
|
|
1274
|
+
/** Whether `new` is a zero-argument `new Date()` — an inert timestamp read. */
|
|
1275
|
+
function isNewDateConstruction(expression) {
|
|
1276
|
+
return (ts.isIdentifier(expression.expression) &&
|
|
1277
|
+
expression.expression.text === 'Date' &&
|
|
1278
|
+
(expression.arguments === undefined || expression.arguments.length === 0));
|
|
1279
|
+
}
|
|
1280
|
+
/**
|
|
1281
|
+
* A value a storage-only init script may compute for a storage
|
|
1282
|
+
* key/value slot: literals (never template forms), the script's own
|
|
1283
|
+
* parameters, lexically declared constants whose initializer is such a
|
|
1284
|
+
* value, structured literals of them, and a whitelist of inert
|
|
1285
|
+
* builtins (`JSON.stringify`, `String`, `Date.now()`, `new Date()` and
|
|
1286
|
+
* its `toISOString()`). Every shape is data only — nothing here can
|
|
1287
|
+
* reach the page, the network, or any other browser API. Anything else
|
|
1288
|
+
* — a bare unresolved identifier, a template form, a computed member
|
|
1289
|
+
* read — fails closed.
|
|
1290
|
+
*/
|
|
1291
|
+
function isStorageOnlyValue(expression, params, stack) {
|
|
1292
|
+
if (ts.isStringLiteral(expression) ||
|
|
1293
|
+
ts.isNumericLiteral(expression) ||
|
|
1294
|
+
expression.kind === ts.SyntaxKind.TrueKeyword ||
|
|
1295
|
+
expression.kind === ts.SyntaxKind.FalseKeyword ||
|
|
1296
|
+
expression.kind === ts.SyntaxKind.NullKeyword) {
|
|
1297
|
+
return true;
|
|
1298
|
+
}
|
|
1299
|
+
if (ts.isIdentifier(expression)) {
|
|
1300
|
+
if (expression.text === 'undefined')
|
|
1301
|
+
return true;
|
|
1302
|
+
if (params.has(expression.text))
|
|
1303
|
+
return true;
|
|
1304
|
+
if (stack.has(expression.text))
|
|
1305
|
+
return false;
|
|
1306
|
+
const initializer = resolveLocalInitializer(expression.text, expression);
|
|
1307
|
+
if (initializer === undefined)
|
|
1308
|
+
return false;
|
|
1309
|
+
const next = new Set(stack);
|
|
1310
|
+
next.add(expression.text);
|
|
1311
|
+
return isStorageOnlyValue(initializer, params, next);
|
|
1312
|
+
}
|
|
1313
|
+
if (ts.isPropertyAccessExpression(expression)) {
|
|
1314
|
+
return (expression.name.text === 'toISOString' &&
|
|
1315
|
+
ts.isNewExpression(expression.expression) &&
|
|
1316
|
+
isNewDateConstruction(expression.expression));
|
|
1317
|
+
}
|
|
1318
|
+
if (ts.isCallExpression(expression)) {
|
|
1319
|
+
const callee = expression.expression;
|
|
1320
|
+
if (ts.isPropertyAccessExpression(callee)) {
|
|
1321
|
+
const owner = callee.expression;
|
|
1322
|
+
if (callee.name.text === 'now' &&
|
|
1323
|
+
ts.isIdentifier(owner) &&
|
|
1324
|
+
owner.text === 'Date' &&
|
|
1325
|
+
expression.arguments.length === 0) {
|
|
1326
|
+
return true;
|
|
1327
|
+
}
|
|
1328
|
+
if (callee.name.text === 'stringify' &&
|
|
1329
|
+
ts.isIdentifier(owner) &&
|
|
1330
|
+
owner.text === 'JSON' &&
|
|
1331
|
+
expression.arguments.length === 1) {
|
|
1332
|
+
const first = expression.arguments[0];
|
|
1333
|
+
return first !== undefined && isStorageOnlyValue(first, params, stack);
|
|
1334
|
+
}
|
|
1335
|
+
if (callee.name.text === 'toISOString' &&
|
|
1336
|
+
expression.arguments.length === 0 &&
|
|
1337
|
+
ts.isNewExpression(owner) &&
|
|
1338
|
+
isNewDateConstruction(owner)) {
|
|
1339
|
+
return true;
|
|
1340
|
+
}
|
|
1341
|
+
return false;
|
|
1342
|
+
}
|
|
1343
|
+
if (ts.isIdentifier(callee) && callee.text === 'String' && expression.arguments.length === 1) {
|
|
1344
|
+
const first = expression.arguments[0];
|
|
1345
|
+
return first !== undefined && isStorageOnlyValue(first, params, stack);
|
|
1346
|
+
}
|
|
1347
|
+
return false;
|
|
1348
|
+
}
|
|
1349
|
+
if (ts.isNewExpression(expression))
|
|
1350
|
+
return isNewDateConstruction(expression);
|
|
1351
|
+
if (ts.isObjectLiteralExpression(expression)) {
|
|
1352
|
+
return expression.properties.every((property) => {
|
|
1353
|
+
if (ts.isPropertyAssignment(property))
|
|
1354
|
+
return isStorageOnlyValue(property.initializer, params, stack);
|
|
1355
|
+
if (ts.isShorthandPropertyAssignment(property))
|
|
1356
|
+
return isStorageOnlyValue(property.name, params, stack);
|
|
1357
|
+
return false;
|
|
1358
|
+
});
|
|
1359
|
+
}
|
|
1360
|
+
if (ts.isArrayLiteralExpression(expression)) {
|
|
1361
|
+
return expression.elements.every((element) => ts.isExpression(element) && isStorageOnlyValue(element, params, stack));
|
|
1362
|
+
}
|
|
1363
|
+
return false;
|
|
1364
|
+
}
|
|
1365
|
+
/**
|
|
1366
|
+
* One `localStorage.setItem('k', 'v')`-shaped storage call, keyed and
|
|
1367
|
+
* valued by {@link isStorageOnlyValue} expressions.
|
|
1368
|
+
*/
|
|
1369
|
+
function isStorageOnlyCall(expression, params, stack) {
|
|
984
1370
|
if (!ts.isCallExpression(expression) || !ts.isPropertyAccessExpression(expression.expression))
|
|
985
1371
|
return false;
|
|
986
1372
|
const method = expression.expression.name.text;
|
|
@@ -994,40 +1380,176 @@ function isSafeStorageCall(expression) {
|
|
|
994
1380
|
if (method === 'setItem') {
|
|
995
1381
|
return (first !== undefined &&
|
|
996
1382
|
second !== undefined &&
|
|
997
|
-
|
|
998
|
-
|
|
1383
|
+
isStorageOnlyValue(first, params, stack) &&
|
|
1384
|
+
isStorageOnlyValue(second, params, stack));
|
|
999
1385
|
}
|
|
1000
|
-
if (method === 'removeItem') {
|
|
1001
|
-
return expression.arguments.length === 1 && first !== undefined &&
|
|
1386
|
+
if (method === 'removeItem' || method === 'getItem') {
|
|
1387
|
+
return expression.arguments.length === 1 && first !== undefined && isStorageOnlyValue(first, params, stack);
|
|
1002
1388
|
}
|
|
1003
1389
|
return expression.arguments.length === 0;
|
|
1004
1390
|
}
|
|
1005
|
-
/**
|
|
1006
|
-
function
|
|
1007
|
-
return
|
|
1391
|
+
/** A storage read or an inert value — one operand of a guarded condition. */
|
|
1392
|
+
function isStorageOnlyOperand(expression, params, stack) {
|
|
1393
|
+
return isStorageOnlyValue(expression, params, stack) || isStorageOnlyCall(expression, params, stack);
|
|
1394
|
+
}
|
|
1395
|
+
/**
|
|
1396
|
+
* The condition of a guarded storage-only statement: an equality
|
|
1397
|
+
* comparison (or negation) over storage reads and inert values — the
|
|
1398
|
+
* read-then-seed shape. Anything else fails closed.
|
|
1399
|
+
*/
|
|
1400
|
+
function isStorageOnlyCondition(expression, params, stack) {
|
|
1401
|
+
if (ts.isBinaryExpression(expression)) {
|
|
1402
|
+
const operator = expression.operatorToken.kind;
|
|
1403
|
+
const comparable = operator === ts.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
1404
|
+
operator === ts.SyntaxKind.ExclamationEqualsEqualsToken ||
|
|
1405
|
+
operator === ts.SyntaxKind.EqualsEqualsToken ||
|
|
1406
|
+
operator === ts.SyntaxKind.ExclamationEqualsToken;
|
|
1407
|
+
return (comparable &&
|
|
1408
|
+
isStorageOnlyOperand(expression.left, params, stack) &&
|
|
1409
|
+
isStorageOnlyOperand(expression.right, params, stack));
|
|
1410
|
+
}
|
|
1411
|
+
if (ts.isPrefixUnaryExpression(expression) && expression.operator === ts.SyntaxKind.ExclamationToken) {
|
|
1412
|
+
return isStorageOnlyOperand(expression.operand, params, stack);
|
|
1413
|
+
}
|
|
1414
|
+
return isStorageOnlyOperand(expression, params, stack);
|
|
1415
|
+
}
|
|
1416
|
+
/** One statement of a storage-only init script body. */
|
|
1417
|
+
function isStorageOnlyStatement(node, params) {
|
|
1418
|
+
if (ts.isExpressionStatement(node))
|
|
1419
|
+
return isStorageOnlyCall(node.expression, params, new Set());
|
|
1420
|
+
if (ts.isIfStatement(node)) {
|
|
1421
|
+
return (isStorageOnlyCondition(node.expression, params, new Set()) &&
|
|
1422
|
+
isStorageOnlyStatement(node.thenStatement, params) &&
|
|
1423
|
+
(node.elseStatement === undefined || isStorageOnlyStatement(node.elseStatement, params)));
|
|
1424
|
+
}
|
|
1425
|
+
if (ts.isTryStatement(node)) {
|
|
1426
|
+
const tryClean = node.tryBlock.statements.every((statement) => isStorageOnlyStatement(statement, params));
|
|
1427
|
+
const catchClean = node.catchClause === undefined ||
|
|
1428
|
+
node.catchClause.block.statements.every((statement) => isStorageOnlyStatement(statement, params));
|
|
1429
|
+
const finallyClean = node.finallyBlock === undefined ||
|
|
1430
|
+
node.finallyBlock.statements.every((statement) => isStorageOnlyStatement(statement, params));
|
|
1431
|
+
return tryClean && catchClean && finallyClean;
|
|
1432
|
+
}
|
|
1433
|
+
if (ts.isBlock(node))
|
|
1434
|
+
return node.statements.every((statement) => isStorageOnlyStatement(statement, params));
|
|
1435
|
+
return false;
|
|
1436
|
+
}
|
|
1437
|
+
/**
|
|
1438
|
+
* Collects the LOCAL names a script function's parameter pattern binds:
|
|
1439
|
+
* the identifier itself, or — for object/array destructuring — each
|
|
1440
|
+
* bound element's local name, recursively. Destructured properties are
|
|
1441
|
+
* serialized data exactly like a whole parameter, so they are usable as
|
|
1442
|
+
* storage keys/values too. False when the pattern binds nothing
|
|
1443
|
+
* trackable (computed properties) — the script then stays a tamper.
|
|
1444
|
+
*/
|
|
1445
|
+
function collectBoundParamNames(pattern, into) {
|
|
1446
|
+
if (ts.isIdentifier(pattern)) {
|
|
1447
|
+
into.add(pattern.text);
|
|
1448
|
+
return true;
|
|
1449
|
+
}
|
|
1450
|
+
for (const element of pattern.elements) {
|
|
1451
|
+
if (!ts.isBindingElement(element))
|
|
1452
|
+
return false;
|
|
1453
|
+
if (!collectBoundParamNames(element.name, into))
|
|
1454
|
+
return false;
|
|
1455
|
+
}
|
|
1456
|
+
return true;
|
|
1457
|
+
}
|
|
1458
|
+
/** Applies the storage-only body grammar to one resolved script function. */
|
|
1459
|
+
function isStorageOnlyScriptFunction(script, call) {
|
|
1460
|
+
// The script may take parameters ONLY when the addInitScript call
|
|
1461
|
+
// passes exactly one argument per parameter (0.13.10 F2); a
|
|
1462
|
+
// parameterless script with extra arguments stays a tamper (0.13.9).
|
|
1463
|
+
// Each parameter can then only ever be serialized data, so a body
|
|
1464
|
+
// made solely of storage calls mutates nothing but storage.
|
|
1465
|
+
if (call.arguments.length !== script.parameters.length + 1)
|
|
1466
|
+
return false;
|
|
1467
|
+
const params = new Set();
|
|
1468
|
+
for (const parameter of script.parameters) {
|
|
1469
|
+
if (!collectBoundParamNames(parameter.name, params))
|
|
1470
|
+
return false;
|
|
1471
|
+
}
|
|
1472
|
+
const body = script.body;
|
|
1473
|
+
if (body === undefined)
|
|
1474
|
+
return false;
|
|
1475
|
+
if (ts.isBlock(body)) {
|
|
1476
|
+
return (body.statements.length > 0 &&
|
|
1477
|
+
body.statements.every((statement) => isStorageOnlyStatement(statement, params)));
|
|
1478
|
+
}
|
|
1479
|
+
return isStorageOnlyCall(body, params, new Set());
|
|
1008
1480
|
}
|
|
1009
1481
|
/**
|
|
1010
1482
|
* True when one `addInitScript(...)` call is a STORAGE-ONLY init
|
|
1011
|
-
* script:
|
|
1012
|
-
* whose body is made solely
|
|
1013
|
-
* mutations (`setItem`/`
|
|
1014
|
-
*
|
|
1015
|
-
*
|
|
1016
|
-
*
|
|
1017
|
-
*
|
|
1483
|
+
* script: a single script argument — an arrow/function literal or a
|
|
1484
|
+
* reference to a locally declared function — whose body is made solely
|
|
1485
|
+
* of localStorage/sessionStorage mutations (`setItem`/`getItem`/
|
|
1486
|
+
* `removeItem`/`clear`, optional `window.` receiver), with exactly one
|
|
1487
|
+
* `addInitScript` argument per declared parameter. The body grammar
|
|
1488
|
+
* admits storage calls keyed/valued by literals, the script's own
|
|
1489
|
+
* parameters, lexically declared constants and inert builtins
|
|
1490
|
+
* (`JSON.stringify`, `String`, `Date.now()`, `new Date()`
|
|
1491
|
+
* `.toISOString()`), under the control flow that guards them (`if`
|
|
1492
|
+
* over a storage read, `try`/`catch`). Such a script mutates nothing
|
|
1493
|
+
* the witness cannot verify solely from its independent observer, so
|
|
1494
|
+
* it is not a tamper and the scan continues past it. Every other shape
|
|
1495
|
+
* — an arity mismatch, a template form, an unresolved identifier in a
|
|
1496
|
+
* key/value slot, any other statement (network, DOM,
|
|
1497
|
+
* `Object.defineProperty`), a string/path script, an empty body, a
|
|
1498
|
+
* reference the scan cannot resolve to a local declaration — stays a
|
|
1499
|
+
* tamper (fail closed). The same function handed to `page.evaluate`
|
|
1500
|
+
* is unaffected: evaluate keeps its own rule.
|
|
1018
1501
|
*/
|
|
1019
1502
|
function isStorageOnlyInitScript(call) {
|
|
1020
|
-
if (call.arguments.length !== 1)
|
|
1021
|
-
return false;
|
|
1022
1503
|
const script = call.arguments[0];
|
|
1023
|
-
if (script === undefined
|
|
1024
|
-
return false;
|
|
1025
|
-
if (script.parameters.length !== 0)
|
|
1504
|
+
if (script === undefined)
|
|
1026
1505
|
return false;
|
|
1027
|
-
if (ts.
|
|
1028
|
-
return script
|
|
1506
|
+
if (ts.isArrowFunction(script) || ts.isFunctionExpression(script)) {
|
|
1507
|
+
return isStorageOnlyScriptFunction(script, call);
|
|
1508
|
+
}
|
|
1509
|
+
if (ts.isIdentifier(script)) {
|
|
1510
|
+
const resolved = resolveLocalFunctionReference(script.text, script, 0, new Set());
|
|
1511
|
+
return resolved !== null && isStorageOnlyScriptFunction(resolved, call);
|
|
1029
1512
|
}
|
|
1030
|
-
return
|
|
1513
|
+
return false;
|
|
1514
|
+
}
|
|
1515
|
+
/** Page-observation tamper API calls: browser mutations the witness cannot verify solely from its independent CDP observer. */
|
|
1516
|
+
const TAMPER_API_CALLS = {
|
|
1517
|
+
addInitScript: true,
|
|
1518
|
+
connectOverCDP: true,
|
|
1519
|
+
evaluate: true,
|
|
1520
|
+
exposeFunction: true,
|
|
1521
|
+
fulfill: true,
|
|
1522
|
+
newBrowserCDPSession: true,
|
|
1523
|
+
newCDPSession: true,
|
|
1524
|
+
route: true,
|
|
1525
|
+
setContent: true,
|
|
1526
|
+
};
|
|
1527
|
+
/** The evaluate family: at runtime the Chromium initiator rule already refuses every request evaluated test code starts (0.13.10 F7). */
|
|
1528
|
+
const EVALUATE_FAMILY_CALLS = {
|
|
1529
|
+
$$eval: true,
|
|
1530
|
+
$eval: true,
|
|
1531
|
+
evaluate: true,
|
|
1532
|
+
evaluateHandle: true,
|
|
1533
|
+
};
|
|
1534
|
+
/**
|
|
1535
|
+
* The location of one page-observation tamper API call, or null. A
|
|
1536
|
+
* storage-only init script ({@link isStorageOnlyInitScript}) is not a
|
|
1537
|
+
* tamper — the scan continues past it so a real tamper later in the
|
|
1538
|
+
* file is still found. With `ignoreEvaluate` the evaluate family does
|
|
1539
|
+
* not match either: the chromium-only blocking pass, which reads what a
|
|
1540
|
+
* chromium project may still refuse statically.
|
|
1541
|
+
*/
|
|
1542
|
+
function tamperApiLocation(source, file, node, ignoreEvaluate) {
|
|
1543
|
+
if (!ts.isPropertyAccessExpression(node.expression))
|
|
1544
|
+
return null;
|
|
1545
|
+
const name = node.expression.name.text;
|
|
1546
|
+
if (TAMPER_API_CALLS[name] !== true)
|
|
1547
|
+
return null;
|
|
1548
|
+
if (ignoreEvaluate && EVALUATE_FAMILY_CALLS[name] === true)
|
|
1549
|
+
return null;
|
|
1550
|
+
if (name === 'addInitScript' && isStorageOnlyInitScript(node))
|
|
1551
|
+
return null;
|
|
1552
|
+
return locationOf(file, source, node);
|
|
1031
1553
|
}
|
|
1032
1554
|
/**
|
|
1033
1555
|
* Finds one page-observation tamper API call in a parsed helper/spec.
|
|
@@ -1037,31 +1559,17 @@ function isStorageOnlyInitScript(call) {
|
|
|
1037
1559
|
* localStorage/sessionStorage and is therefore not a tamper; the scan
|
|
1038
1560
|
* continues past it so a real tamper later in the file is still found.
|
|
1039
1561
|
*/
|
|
1040
|
-
function findRouteInterception(source, file) {
|
|
1041
|
-
const tamperCalls = {
|
|
1042
|
-
addInitScript: true,
|
|
1043
|
-
connectOverCDP: true,
|
|
1044
|
-
evaluate: true,
|
|
1045
|
-
exposeFunction: true,
|
|
1046
|
-
fulfill: true,
|
|
1047
|
-
newBrowserCDPSession: true,
|
|
1048
|
-
newCDPSession: true,
|
|
1049
|
-
route: true,
|
|
1050
|
-
setContent: true,
|
|
1051
|
-
};
|
|
1562
|
+
function findRouteInterception(source, file, ignoreEvaluate) {
|
|
1052
1563
|
let found = null;
|
|
1053
1564
|
const visit = (node) => {
|
|
1054
1565
|
if (found !== null)
|
|
1055
1566
|
return;
|
|
1056
|
-
if (ts.isCallExpression(node)
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
ts.forEachChild(node, visit);
|
|
1567
|
+
if (ts.isCallExpression(node)) {
|
|
1568
|
+
const tamper = tamperApiLocation(source, file, node, ignoreEvaluate);
|
|
1569
|
+
if (tamper !== null) {
|
|
1570
|
+
found = tamper;
|
|
1061
1571
|
return;
|
|
1062
1572
|
}
|
|
1063
|
-
found = locationOf(file, source, node);
|
|
1064
|
-
return;
|
|
1065
1573
|
}
|
|
1066
1574
|
ts.forEachChild(node, visit);
|
|
1067
1575
|
};
|
|
@@ -1069,7 +1577,7 @@ function findRouteInterception(source, file) {
|
|
|
1069
1577
|
return found;
|
|
1070
1578
|
}
|
|
1071
1579
|
/** First tamper call in a spec or any helper imported by its module graph. */
|
|
1072
|
-
function findImportedRouteInterception(state, cwd, root) {
|
|
1580
|
+
function findImportedRouteInterception(state, cwd, root, ignoreEvaluate) {
|
|
1073
1581
|
const visited = new Set();
|
|
1074
1582
|
const visit = (file, depth) => {
|
|
1075
1583
|
if (visited.has(file) || depth > state.maxImportDepth)
|
|
@@ -1078,7 +1586,7 @@ function findImportedRouteInterception(state, cwd, root) {
|
|
|
1078
1586
|
const model = state.models.get(file) ?? modelOf(state, cwd, file, true);
|
|
1079
1587
|
if (model === null)
|
|
1080
1588
|
return null;
|
|
1081
|
-
const local = findRouteInterception(model.source, file);
|
|
1589
|
+
const local = findRouteInterception(model.source, file, ignoreEvaluate);
|
|
1082
1590
|
if (local !== null)
|
|
1083
1591
|
return local;
|
|
1084
1592
|
for (const binding of model.bindings.values()) {
|
|
@@ -1092,6 +1600,595 @@ function findImportedRouteInterception(state, cwd, root) {
|
|
|
1092
1600
|
};
|
|
1093
1601
|
return visit(root, 0);
|
|
1094
1602
|
}
|
|
1603
|
+
/** Shared immutable verdicts; never mutated. */
|
|
1604
|
+
const CLEAN_REACH = { kind: 'clean' };
|
|
1605
|
+
const UNKNOWN_REACH = { kind: 'unknown' };
|
|
1606
|
+
/**
|
|
1607
|
+
* A reference to a risky or unprovable name whose invocation cannot be
|
|
1608
|
+
* proven at this site: a helper CALLED directly carries its reach; a
|
|
1609
|
+
* helper passed around as a value reads as unknown, and the caller
|
|
1610
|
+
* falls back to today's file-wide flag.
|
|
1611
|
+
*/
|
|
1612
|
+
function referenceVerdict(reach, called) {
|
|
1613
|
+
if (reach.kind === 'clean')
|
|
1614
|
+
return CLEAN_REACH;
|
|
1615
|
+
return called ? reach : UNKNOWN_REACH;
|
|
1616
|
+
}
|
|
1617
|
+
/** Module-scope declarations by name: variable initializers, function declarations. */
|
|
1618
|
+
const routeDeclsByModel = new WeakMap();
|
|
1619
|
+
function routeDeclsOf(model) {
|
|
1620
|
+
const cached = routeDeclsByModel.get(model);
|
|
1621
|
+
if (cached !== undefined)
|
|
1622
|
+
return cached;
|
|
1623
|
+
const decls = new Map();
|
|
1624
|
+
for (const statement of model.source.statements) {
|
|
1625
|
+
if (ts.isVariableStatement(statement)) {
|
|
1626
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
1627
|
+
if (ts.isIdentifier(declaration.name) && declaration.initializer !== undefined) {
|
|
1628
|
+
decls.set(declaration.name.text, declaration.initializer);
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
else if (ts.isFunctionDeclaration(statement) && statement.name !== undefined && statement.body !== undefined) {
|
|
1633
|
+
decls.set(statement.name.text, statement);
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
routeDeclsByModel.set(model, decls);
|
|
1637
|
+
return decls;
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Resolves a name to a declaration readable from `from`'s lexical
|
|
1641
|
+
* position: a variable initializer or a function declaration in a
|
|
1642
|
+
* block (or the module scope) enclosing it, innermost block winning —
|
|
1643
|
+
* the lookup a closure reference performs. Undefined when the name
|
|
1644
|
+
* declares nothing lexically visible.
|
|
1645
|
+
*/
|
|
1646
|
+
function resolveLocalReferenceNode(name, from) {
|
|
1647
|
+
let current = from.parent;
|
|
1648
|
+
while (current !== undefined) {
|
|
1649
|
+
if (ts.isBlock(current) || ts.isSourceFile(current)) {
|
|
1650
|
+
for (const statement of current.statements) {
|
|
1651
|
+
if (ts.isFunctionDeclaration(statement) && statement.name !== undefined && statement.name.text === name && statement.body !== undefined) {
|
|
1652
|
+
return statement;
|
|
1653
|
+
}
|
|
1654
|
+
if (!ts.isVariableStatement(statement))
|
|
1655
|
+
continue;
|
|
1656
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
1657
|
+
if (ts.isIdentifier(declaration.name) && declaration.name.text === name && declaration.initializer !== undefined) {
|
|
1658
|
+
return declaration.initializer;
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
current = current.parent;
|
|
1664
|
+
}
|
|
1665
|
+
return undefined;
|
|
1666
|
+
}
|
|
1667
|
+
/**
|
|
1668
|
+
* The first tamper call OUTSIDE any function body in the file: code an
|
|
1669
|
+
* import executes, so every file importing this one reaches it. Memoized
|
|
1670
|
+
* per scan; a file that cannot be modeled adds none.
|
|
1671
|
+
*/
|
|
1672
|
+
function topLevelTamperOf(state, cwd, file, ignoreEvaluate) {
|
|
1673
|
+
const memoKey = `${file}::${ignoreEvaluate ? 'blocking' : 'any'}`;
|
|
1674
|
+
const cached = state.routeTopLevelByFile.get(memoKey);
|
|
1675
|
+
if (cached !== undefined)
|
|
1676
|
+
return cached;
|
|
1677
|
+
const model = state.models.get(file) ?? modelOf(state, cwd, file, true);
|
|
1678
|
+
let found = null;
|
|
1679
|
+
if (model !== null) {
|
|
1680
|
+
const runsAtImport = (node) => ts.isFunctionDeclaration(node) ||
|
|
1681
|
+
ts.isArrowFunction(node) ||
|
|
1682
|
+
ts.isFunctionExpression(node) ||
|
|
1683
|
+
ts.isMethodDeclaration(node) ||
|
|
1684
|
+
ts.isConstructorDeclaration(node) ||
|
|
1685
|
+
ts.isGetAccessorDeclaration(node) ||
|
|
1686
|
+
ts.isSetAccessorDeclaration(node);
|
|
1687
|
+
const visit = (node) => {
|
|
1688
|
+
if (found !== null)
|
|
1689
|
+
return;
|
|
1690
|
+
if (ts.isCallExpression(node)) {
|
|
1691
|
+
const tamper = tamperApiLocation(model.source, file, node, ignoreEvaluate);
|
|
1692
|
+
if (tamper !== null) {
|
|
1693
|
+
found = tamper;
|
|
1694
|
+
return;
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
if (runsAtImport(node))
|
|
1698
|
+
return;
|
|
1699
|
+
ts.forEachChild(node, visit);
|
|
1700
|
+
};
|
|
1701
|
+
visit(model.source);
|
|
1702
|
+
}
|
|
1703
|
+
state.routeTopLevelByFile.set(memoKey, found);
|
|
1704
|
+
return found;
|
|
1705
|
+
}
|
|
1706
|
+
/** First import-time (top-level) tamper across the file's import graph, or null. */
|
|
1707
|
+
function firstGraphTopLevelTamper(state, cwd, root, ignoreEvaluate) {
|
|
1708
|
+
const visited = new Set();
|
|
1709
|
+
const visit = (file, depth) => {
|
|
1710
|
+
if (visited.has(file) || depth > state.maxImportDepth)
|
|
1711
|
+
return null;
|
|
1712
|
+
visited.add(file);
|
|
1713
|
+
const model = state.models.get(file) ?? modelOf(state, cwd, file, true);
|
|
1714
|
+
if (model === null)
|
|
1715
|
+
return null;
|
|
1716
|
+
const topLevel = topLevelTamperOf(state, cwd, file, ignoreEvaluate);
|
|
1717
|
+
if (topLevel !== null)
|
|
1718
|
+
return topLevel;
|
|
1719
|
+
for (const binding of model.bindings.values()) {
|
|
1720
|
+
if (binding.kind !== 'import' || binding.target === undefined)
|
|
1721
|
+
continue;
|
|
1722
|
+
const nested = visit(binding.target, depth + 1);
|
|
1723
|
+
if (nested !== null)
|
|
1724
|
+
return nested;
|
|
1725
|
+
}
|
|
1726
|
+
return null;
|
|
1727
|
+
};
|
|
1728
|
+
return visit(root, 0);
|
|
1729
|
+
}
|
|
1730
|
+
/** The reach of one module-scope name: its declaration's subtree, or the export it points at. */
|
|
1731
|
+
function localNameTamperReach(state, cwd, model, name, depth, active, ignoreEvaluate, httpClientRoot = null) {
|
|
1732
|
+
const declaration = routeDeclsOf(model).get(name);
|
|
1733
|
+
if (declaration !== undefined) {
|
|
1734
|
+
return nodeTamperReach(state, cwd, model, declaration, depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1735
|
+
}
|
|
1736
|
+
const binding = model.bindings.get(name);
|
|
1737
|
+
if (binding === undefined)
|
|
1738
|
+
return UNKNOWN_REACH;
|
|
1739
|
+
switch (binding.kind) {
|
|
1740
|
+
case 'import': {
|
|
1741
|
+
if (binding.target === undefined)
|
|
1742
|
+
return CLEAN_REACH;
|
|
1743
|
+
if (httpClientRoot !== null && !isTestInfrastructureFile(binding.target))
|
|
1744
|
+
return CLEAN_REACH;
|
|
1745
|
+
return binding.importedName === '*'
|
|
1746
|
+
? namespaceModuleReach(state, cwd, binding.target, depth + 1, active, ignoreEvaluate, httpClientRoot)
|
|
1747
|
+
: exportedNameTamperReach(state, cwd, binding.target, binding.importedName ?? '', depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1748
|
+
}
|
|
1749
|
+
case 'alias': {
|
|
1750
|
+
const aliased = binding.target === undefined ? undefined : routeDeclsOf(model).get(binding.target);
|
|
1751
|
+
return aliased === undefined
|
|
1752
|
+
? CLEAN_REACH
|
|
1753
|
+
: nodeTamperReach(state, cwd, model, aliased, depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1754
|
+
}
|
|
1755
|
+
case 'test':
|
|
1756
|
+
case 'testmodule':
|
|
1757
|
+
case 'external':
|
|
1758
|
+
case 'plain':
|
|
1759
|
+
case 'import-broken':
|
|
1760
|
+
case 'data':
|
|
1761
|
+
return CLEAN_REACH;
|
|
1762
|
+
case 'unresolvable':
|
|
1763
|
+
return UNKNOWN_REACH;
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Memoized tamper reach of one exported name, following re-exports.
|
|
1768
|
+
* An in-progress name reads as clean: a recursion through a cycle adds
|
|
1769
|
+
* no reach beyond the cycle's own direct tampers, which are found on
|
|
1770
|
+
* their own. Over the import budget reads as unknown (fail closed); a
|
|
1771
|
+
* file that cannot be modeled adds no reach — the same visibility the
|
|
1772
|
+
* graph traversal itself has.
|
|
1773
|
+
*/
|
|
1774
|
+
function exportedNameTamperReach(state, cwd, file, name, depth, active, ignoreEvaluate, httpClientRoot = null) {
|
|
1775
|
+
if (httpClientRoot !== null && file !== httpClientRoot && !isTestInfrastructureFile(file))
|
|
1776
|
+
return CLEAN_REACH;
|
|
1777
|
+
const key = `${httpClientRoot === null ? '' : `http-client::${httpClientRoot}::`}${ignoreEvaluate ? 'blocking' : 'any'}::${file}::${name}`;
|
|
1778
|
+
const cached = state.routeReachByExport.get(key);
|
|
1779
|
+
if (cached !== undefined)
|
|
1780
|
+
return cached;
|
|
1781
|
+
if (depth > state.maxImportDepth)
|
|
1782
|
+
return UNKNOWN_REACH;
|
|
1783
|
+
if (active.has(key))
|
|
1784
|
+
return CLEAN_REACH;
|
|
1785
|
+
active.add(key);
|
|
1786
|
+
const model = state.models.get(file) ?? modelOf(state, cwd, file, true);
|
|
1787
|
+
let verdict;
|
|
1788
|
+
if (model === null) {
|
|
1789
|
+
verdict = CLEAN_REACH;
|
|
1790
|
+
}
|
|
1791
|
+
else {
|
|
1792
|
+
const exported = model.exports.get(name);
|
|
1793
|
+
if (exported === undefined) {
|
|
1794
|
+
verdict = localNameTamperReach(state, cwd, model, name, depth, active, ignoreEvaluate, httpClientRoot);
|
|
1795
|
+
}
|
|
1796
|
+
else if ('packTest' in exported) {
|
|
1797
|
+
verdict = CLEAN_REACH;
|
|
1798
|
+
}
|
|
1799
|
+
else if ('targetFile' in exported) {
|
|
1800
|
+
verdict = exportedNameTamperReach(state, cwd, exported.targetFile, exported.importedName, depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1801
|
+
}
|
|
1802
|
+
else {
|
|
1803
|
+
verdict = localNameTamperReach(state, cwd, model, exported.local, depth, active, ignoreEvaluate, httpClientRoot);
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
active.delete(key);
|
|
1807
|
+
state.routeReachByExport.set(key, verdict);
|
|
1808
|
+
return verdict;
|
|
1809
|
+
}
|
|
1810
|
+
/**
|
|
1811
|
+
* Whether a whole module can carry a tamper at all: its import-time
|
|
1812
|
+
* calls, every export it declares, and everything its own imports
|
|
1813
|
+
* point at. This is the summary an UNPROVABLE use of a namespace
|
|
1814
|
+
* import is judged against — `clean` only when nothing anywhere in the
|
|
1815
|
+
* module's reach can tamper; anything else falls back to the file-wide
|
|
1816
|
+
* flag.
|
|
1817
|
+
*/
|
|
1818
|
+
function namespaceModuleReach(state, cwd, file, depth, active, ignoreEvaluate, httpClientRoot = null) {
|
|
1819
|
+
if (httpClientRoot !== null && file !== httpClientRoot && !isTestInfrastructureFile(file))
|
|
1820
|
+
return CLEAN_REACH;
|
|
1821
|
+
const key = `${httpClientRoot === null ? '' : `http-client::${httpClientRoot}::`}${ignoreEvaluate ? 'blocking' : 'any'}::${file}::<namespace>`;
|
|
1822
|
+
const cached = state.routeReachByExport.get(key);
|
|
1823
|
+
if (cached !== undefined)
|
|
1824
|
+
return cached;
|
|
1825
|
+
if (depth > state.maxImportDepth)
|
|
1826
|
+
return UNKNOWN_REACH;
|
|
1827
|
+
if (active.has(key))
|
|
1828
|
+
return CLEAN_REACH;
|
|
1829
|
+
active.add(key);
|
|
1830
|
+
const verdict = (() => {
|
|
1831
|
+
if (httpClientRoot === null) {
|
|
1832
|
+
const topLevel = topLevelTamperOf(state, cwd, file, ignoreEvaluate);
|
|
1833
|
+
if (topLevel !== null)
|
|
1834
|
+
return { kind: 'tamper', location: topLevel };
|
|
1835
|
+
}
|
|
1836
|
+
const model = state.models.get(file) ?? modelOf(state, cwd, file, true);
|
|
1837
|
+
if (model === null)
|
|
1838
|
+
return CLEAN_REACH;
|
|
1839
|
+
for (const exportedName of model.exports.keys()) {
|
|
1840
|
+
const reach = exportedNameTamperReach(state, cwd, file, exportedName, depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1841
|
+
if (reach.kind !== 'clean')
|
|
1842
|
+
return reach;
|
|
1843
|
+
}
|
|
1844
|
+
for (const binding of model.bindings.values()) {
|
|
1845
|
+
if (binding.kind !== 'import' || binding.target === undefined)
|
|
1846
|
+
continue;
|
|
1847
|
+
if (httpClientRoot !== null && !isTestInfrastructureFile(binding.target))
|
|
1848
|
+
continue;
|
|
1849
|
+
const reach = binding.importedName === '*'
|
|
1850
|
+
? namespaceModuleReach(state, cwd, binding.target, depth + 1, active, ignoreEvaluate, httpClientRoot)
|
|
1851
|
+
: exportedNameTamperReach(state, cwd, binding.target, binding.importedName ?? '', depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1852
|
+
if (reach.kind !== 'clean')
|
|
1853
|
+
return reach;
|
|
1854
|
+
}
|
|
1855
|
+
return CLEAN_REACH;
|
|
1856
|
+
})();
|
|
1857
|
+
active.delete(key);
|
|
1858
|
+
state.routeReachByExport.set(key, verdict);
|
|
1859
|
+
return verdict;
|
|
1860
|
+
}
|
|
1861
|
+
/** Reach of one identifier reference: a local declaration, an import, or nothing. */
|
|
1862
|
+
function identifierReach(state, cwd, model, identifier, depth, active, called, ignoreEvaluate, httpClientRoot = null) {
|
|
1863
|
+
const text = identifier.text;
|
|
1864
|
+
const key = `${model.file}::${text}`;
|
|
1865
|
+
if (active.has(key))
|
|
1866
|
+
return CLEAN_REACH;
|
|
1867
|
+
const local = resolveLocalReferenceNode(text, identifier);
|
|
1868
|
+
if (local !== undefined) {
|
|
1869
|
+
active.add(key);
|
|
1870
|
+
const reach = referenceVerdict(nodeTamperReach(state, cwd, model, local, depth + 1, active, ignoreEvaluate, httpClientRoot), called);
|
|
1871
|
+
active.delete(key);
|
|
1872
|
+
return reach;
|
|
1873
|
+
}
|
|
1874
|
+
const binding = model.bindings.get(text);
|
|
1875
|
+
if (binding === undefined)
|
|
1876
|
+
return CLEAN_REACH;
|
|
1877
|
+
if (binding.kind === 'import' && binding.target !== undefined) {
|
|
1878
|
+
const reach = binding.importedName === '*'
|
|
1879
|
+
? namespaceModuleReach(state, cwd, binding.target, depth + 1, active, ignoreEvaluate, httpClientRoot)
|
|
1880
|
+
: exportedNameTamperReach(state, cwd, binding.target, binding.importedName ?? '', depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1881
|
+
return referenceVerdict(reach, called);
|
|
1882
|
+
}
|
|
1883
|
+
return CLEAN_REACH;
|
|
1884
|
+
}
|
|
1885
|
+
/**
|
|
1886
|
+
* Tamper reach of one node subtree (a test body, a helper declaration):
|
|
1887
|
+
* the first tamper API call in the subtree, or the reach of any name it
|
|
1888
|
+
* references. A name referenced only as a VALUE (passed around,
|
|
1889
|
+
* stored) cannot be proven to run and reads as unknown; property
|
|
1890
|
+
* names, binding names, and parameters are never references.
|
|
1891
|
+
*/
|
|
1892
|
+
function nodeTamperReach(state, cwd, model, node, depth, active, ignoreEvaluate, httpClientRoot = null) {
|
|
1893
|
+
if (depth > state.maxImportDepth)
|
|
1894
|
+
return UNKNOWN_REACH;
|
|
1895
|
+
let verdict = CLEAN_REACH;
|
|
1896
|
+
// Whether this syntactic position IS the callee of its parent call —
|
|
1897
|
+
// the one position where a reference is proof the referenced code runs.
|
|
1898
|
+
const calledHere = (reference) => ts.isCallExpression(reference.parent) && reference.parent.expression === reference;
|
|
1899
|
+
const visit = (current) => {
|
|
1900
|
+
if (verdict.kind !== 'clean')
|
|
1901
|
+
return;
|
|
1902
|
+
if (ts.isIdentifier(current)) {
|
|
1903
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, current, depth, active, false, ignoreEvaluate, httpClientRoot), false);
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
if (ts.isCallExpression(current)) {
|
|
1907
|
+
const tamper = httpClientRoot !== null
|
|
1908
|
+
? findHttpClientCall(current, model.source, model.file, true, model.file === httpClientRoot)
|
|
1909
|
+
: tamperApiLocation(model.source, model.file, current, ignoreEvaluate);
|
|
1910
|
+
if (tamper !== null) {
|
|
1911
|
+
verdict = { kind: 'tamper', location: tamper };
|
|
1912
|
+
return;
|
|
1913
|
+
}
|
|
1914
|
+
if (ts.isIdentifier(current.expression)) {
|
|
1915
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, current.expression, depth, active, true, ignoreEvaluate, httpClientRoot), true);
|
|
1916
|
+
}
|
|
1917
|
+
else {
|
|
1918
|
+
visit(current.expression);
|
|
1919
|
+
}
|
|
1920
|
+
if (verdict.kind !== 'clean')
|
|
1921
|
+
return;
|
|
1922
|
+
for (const argument of current.arguments) {
|
|
1923
|
+
visit(argument);
|
|
1924
|
+
if (verdict.kind !== 'clean')
|
|
1925
|
+
return;
|
|
1926
|
+
}
|
|
1927
|
+
return;
|
|
1928
|
+
}
|
|
1929
|
+
if (ts.isPropertyAccessExpression(current)) {
|
|
1930
|
+
const base = current.expression;
|
|
1931
|
+
const called = calledHere(current);
|
|
1932
|
+
if (ts.isIdentifier(base)) {
|
|
1933
|
+
const binding = model.bindings.get(base.text);
|
|
1934
|
+
if (binding !== undefined && binding.kind === 'import' && binding.target !== undefined && binding.importedName === '*') {
|
|
1935
|
+
verdict = referenceVerdict(exportedNameTamperReach(state, cwd, binding.target, current.name.text, depth + 1, active, ignoreEvaluate, httpClientRoot), called);
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, base, depth, active, called, ignoreEvaluate, httpClientRoot), called);
|
|
1939
|
+
return;
|
|
1940
|
+
}
|
|
1941
|
+
visit(base);
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
if (ts.isElementAccessExpression(current)) {
|
|
1945
|
+
const base = current.expression;
|
|
1946
|
+
const called = calledHere(current);
|
|
1947
|
+
if (ts.isIdentifier(base)) {
|
|
1948
|
+
const binding = model.bindings.get(base.text);
|
|
1949
|
+
if (binding !== undefined && binding.kind === 'import' && binding.target !== undefined && binding.importedName === '*') {
|
|
1950
|
+
if (ts.isStringLiteral(current.argumentExpression)) {
|
|
1951
|
+
verdict = referenceVerdict(exportedNameTamperReach(state, cwd, binding.target, current.argumentExpression.text, depth + 1, active, ignoreEvaluate, httpClientRoot), called);
|
|
1952
|
+
return;
|
|
1953
|
+
}
|
|
1954
|
+
verdict = UNKNOWN_REACH; // dynamic namespace access: cannot prove which export runs
|
|
1955
|
+
return;
|
|
1956
|
+
}
|
|
1957
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, base, depth, active, false, ignoreEvaluate, httpClientRoot), false);
|
|
1958
|
+
if (verdict.kind !== 'clean')
|
|
1959
|
+
return;
|
|
1960
|
+
visit(current.argumentExpression);
|
|
1961
|
+
return;
|
|
1962
|
+
}
|
|
1963
|
+
visit(base);
|
|
1964
|
+
if (verdict.kind !== 'clean')
|
|
1965
|
+
return;
|
|
1966
|
+
visit(current.argumentExpression);
|
|
1967
|
+
return;
|
|
1968
|
+
}
|
|
1969
|
+
if (ts.isSpreadElement(current)) {
|
|
1970
|
+
if (ts.isIdentifier(current.expression)) {
|
|
1971
|
+
const binding = model.bindings.get(current.expression.text);
|
|
1972
|
+
if (binding !== undefined && binding.kind === 'import' && binding.importedName === '*') {
|
|
1973
|
+
verdict = UNKNOWN_REACH; // spreading a namespace: cannot prove what runs
|
|
1974
|
+
return;
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1977
|
+
visit(current.expression);
|
|
1978
|
+
return;
|
|
1979
|
+
}
|
|
1980
|
+
if (ts.isVariableStatement(current)) {
|
|
1981
|
+
for (const declaration of current.declarationList.declarations) {
|
|
1982
|
+
if (declaration.initializer !== undefined) {
|
|
1983
|
+
visit(declaration.initializer);
|
|
1984
|
+
if (verdict.kind !== 'clean')
|
|
1985
|
+
return;
|
|
1986
|
+
}
|
|
1987
|
+
}
|
|
1988
|
+
return;
|
|
1989
|
+
}
|
|
1990
|
+
if (ts.isFunctionDeclaration(current) ||
|
|
1991
|
+
ts.isFunctionExpression(current) ||
|
|
1992
|
+
ts.isArrowFunction(current) ||
|
|
1993
|
+
ts.isMethodDeclaration(current)) {
|
|
1994
|
+
for (const parameter of current.parameters) {
|
|
1995
|
+
if (parameter.initializer !== undefined) {
|
|
1996
|
+
visit(parameter.initializer);
|
|
1997
|
+
if (verdict.kind !== 'clean')
|
|
1998
|
+
return;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
if (current.body !== undefined)
|
|
2002
|
+
visit(current.body);
|
|
2003
|
+
return;
|
|
2004
|
+
}
|
|
2005
|
+
if (ts.isImportDeclaration(current) || ts.isExportDeclaration(current))
|
|
2006
|
+
return;
|
|
2007
|
+
ts.forEachChild(current, visit);
|
|
2008
|
+
};
|
|
2009
|
+
visit(node);
|
|
2010
|
+
return verdict;
|
|
2011
|
+
}
|
|
2012
|
+
/**
|
|
2013
|
+
* The tamper location attributed to ONE test (0.13.10 F3): a tamper
|
|
2014
|
+
* written in the spec, or one that executes at import time anywhere in
|
|
2015
|
+
* its import graph, flags every test of the file exactly as before;
|
|
2016
|
+
* otherwise the test's own body — and the fixture chain its
|
|
2017
|
+
* registration name resolves through — is followed, flagging the test
|
|
2018
|
+
* at the reached helper's tamper line. When reachability cannot be
|
|
2019
|
+
* proven, today's file-wide graph tamper is the flag; when the scan
|
|
2020
|
+
* proves the test never reaches any tamper, there is none.
|
|
2021
|
+
*/
|
|
2022
|
+
function attributedRouteInterception(state, cwd, model, base, callback, fileWideTamper, fallback, ignoreEvaluate) {
|
|
2023
|
+
if (fileWideTamper !== null)
|
|
2024
|
+
return fileWideTamper;
|
|
2025
|
+
const active = new Set();
|
|
2026
|
+
const registration = localNameTamperReach(state, cwd, model, base, 0, active, ignoreEvaluate);
|
|
2027
|
+
if (registration.kind === 'tamper')
|
|
2028
|
+
return registration.location;
|
|
2029
|
+
if (registration.kind === 'unknown')
|
|
2030
|
+
return fallback;
|
|
2031
|
+
if (callback === undefined)
|
|
2032
|
+
return fallback;
|
|
2033
|
+
const body = nodeTamperReach(state, cwd, model, callback, 0, active, ignoreEvaluate);
|
|
2034
|
+
if (body.kind === 'tamper')
|
|
2035
|
+
return body.location;
|
|
2036
|
+
if (body.kind === 'unknown')
|
|
2037
|
+
return fallback;
|
|
2038
|
+
return null;
|
|
2039
|
+
}
|
|
2040
|
+
function attributedHttpClientCall(state, cwd, model, base, callback, fallback) {
|
|
2041
|
+
const active = new Set();
|
|
2042
|
+
const registration = localNameTamperReach(state, cwd, model, base, 0, active, false, model.file);
|
|
2043
|
+
if (registration.kind === 'tamper')
|
|
2044
|
+
return registration.location;
|
|
2045
|
+
if (registration.kind === 'unknown')
|
|
2046
|
+
return fallback;
|
|
2047
|
+
if (callback === undefined)
|
|
2048
|
+
return fallback;
|
|
2049
|
+
const body = nodeTamperReach(state, cwd, model, callback, 0, active, false, model.file);
|
|
2050
|
+
if (body.kind === 'tamper')
|
|
2051
|
+
return body.location;
|
|
2052
|
+
return body.kind === 'unknown' ? fallback : null;
|
|
2053
|
+
}
|
|
2054
|
+
function fixtureClasses(state, file) {
|
|
2055
|
+
const cached = state.fixtureClassesByFile.get(file);
|
|
2056
|
+
if (cached !== undefined)
|
|
2057
|
+
return cached;
|
|
2058
|
+
const reachable = new Set();
|
|
2059
|
+
const pending = [file];
|
|
2060
|
+
while (pending.length > 0) {
|
|
2061
|
+
const next = pending.pop();
|
|
2062
|
+
if (reachable.has(next))
|
|
2063
|
+
continue;
|
|
2064
|
+
reachable.add(next);
|
|
2065
|
+
const model = state.models.get(next);
|
|
2066
|
+
for (const binding of model?.bindings.values() ?? []) {
|
|
2067
|
+
if (binding.kind === 'import' && binding.target !== undefined)
|
|
2068
|
+
pending.push(binding.target);
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
const models = [...reachable].flatMap((target) => {
|
|
2072
|
+
const model = state.models.get(target);
|
|
2073
|
+
return model === undefined ? [] : [model];
|
|
2074
|
+
});
|
|
2075
|
+
const definitions = new Map();
|
|
2076
|
+
for (const model of models) {
|
|
2077
|
+
const visit = (node) => {
|
|
2078
|
+
if (ts.isCallExpression(node) &&
|
|
2079
|
+
ts.isPropertyAccessExpression(node.expression) &&
|
|
2080
|
+
node.expression.name.text === 'extend' &&
|
|
2081
|
+
node.arguments[0] !== undefined &&
|
|
2082
|
+
ts.isObjectLiteralExpression(node.arguments[0])) {
|
|
2083
|
+
for (const property of node.arguments[0].properties) {
|
|
2084
|
+
if (!ts.isPropertyAssignment(property))
|
|
2085
|
+
continue;
|
|
2086
|
+
const name = ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) ? property.name.text : null;
|
|
2087
|
+
if (name === null)
|
|
2088
|
+
continue;
|
|
2089
|
+
const initializer = property.initializer;
|
|
2090
|
+
const dependencies = [];
|
|
2091
|
+
if ((ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer)) &&
|
|
2092
|
+
initializer.parameters[0] !== undefined &&
|
|
2093
|
+
ts.isObjectBindingPattern(initializer.parameters[0].name)) {
|
|
2094
|
+
for (const element of initializer.parameters[0].name.elements) {
|
|
2095
|
+
const dependency = element.propertyName ?? element.name;
|
|
2096
|
+
if (ts.isIdentifier(dependency))
|
|
2097
|
+
dependencies.push(dependency.text);
|
|
2098
|
+
}
|
|
2099
|
+
}
|
|
2100
|
+
definitions.set(name, { file: model.file, node: initializer, dependencies });
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
ts.forEachChild(node, visit);
|
|
2104
|
+
};
|
|
2105
|
+
visit(model.source);
|
|
2106
|
+
}
|
|
2107
|
+
const output = {};
|
|
2108
|
+
const active = new Set();
|
|
2109
|
+
const classify = (name) => {
|
|
2110
|
+
const existing = output[name];
|
|
2111
|
+
if (existing !== undefined)
|
|
2112
|
+
return existing;
|
|
2113
|
+
const definition = definitions.get(name);
|
|
2114
|
+
if (definition === undefined || active.has(name))
|
|
2115
|
+
return { kind: 'unknown', chain: name };
|
|
2116
|
+
active.add(name);
|
|
2117
|
+
let browser = false;
|
|
2118
|
+
let api = false;
|
|
2119
|
+
let unknown = false;
|
|
2120
|
+
let helperCall = null;
|
|
2121
|
+
const visit = (node) => {
|
|
2122
|
+
if (ts.isCallExpression(node)) {
|
|
2123
|
+
const callee = node.expression.getText();
|
|
2124
|
+
if (callee.includes('newPage') || callee.includes('newContext')) {
|
|
2125
|
+
if (callee.includes('browser'))
|
|
2126
|
+
browser = true;
|
|
2127
|
+
else if (callee.includes('request') || callee.includes('playwright'))
|
|
2128
|
+
api = true;
|
|
2129
|
+
else
|
|
2130
|
+
helperCall = callee;
|
|
2131
|
+
}
|
|
2132
|
+
else if (ts.isPropertyAccessExpression(node.expression)) {
|
|
2133
|
+
helperCall = callee;
|
|
2134
|
+
}
|
|
2135
|
+
if (node.expression.kind === ts.SyntaxKind.ImportKeyword)
|
|
2136
|
+
unknown = true;
|
|
2137
|
+
}
|
|
2138
|
+
ts.forEachChild(node, visit);
|
|
2139
|
+
};
|
|
2140
|
+
visit(definition.node);
|
|
2141
|
+
if (helperCall !== null &&
|
|
2142
|
+
models.some((model) => {
|
|
2143
|
+
let found = false;
|
|
2144
|
+
const findFactory = (current) => {
|
|
2145
|
+
if (ts.isCallExpression(current) &&
|
|
2146
|
+
ts.isPropertyAccessExpression(current.expression) &&
|
|
2147
|
+
current.expression.name.text === 'newContext' &&
|
|
2148
|
+
current.expression.expression.getText().includes('request')) {
|
|
2149
|
+
found = true;
|
|
2150
|
+
}
|
|
2151
|
+
if (!found)
|
|
2152
|
+
ts.forEachChild(current, findFactory);
|
|
2153
|
+
};
|
|
2154
|
+
findFactory(model.source);
|
|
2155
|
+
return found;
|
|
2156
|
+
})) {
|
|
2157
|
+
api = true;
|
|
2158
|
+
}
|
|
2159
|
+
const dependencyKinds = definition.dependencies.map((dependency) => {
|
|
2160
|
+
if (dependency === name && BROWSER_FIXTURE_PARAMS.has(dependency)) {
|
|
2161
|
+
return { kind: 'browser', chain: dependency };
|
|
2162
|
+
}
|
|
2163
|
+
if (!definitions.has(dependency) && BROWSER_FIXTURE_PARAMS.has(dependency)) {
|
|
2164
|
+
return { kind: 'browser', chain: dependency };
|
|
2165
|
+
}
|
|
2166
|
+
if (!definitions.has(dependency) && dependency === 'request') {
|
|
2167
|
+
return { kind: 'api', chain: dependency };
|
|
2168
|
+
}
|
|
2169
|
+
return classify(dependency);
|
|
2170
|
+
});
|
|
2171
|
+
if (dependencyKinds.some((item) => item.kind === 'browser'))
|
|
2172
|
+
browser = true;
|
|
2173
|
+
if (dependencyKinds.some((item) => item.kind === 'api'))
|
|
2174
|
+
api = true;
|
|
2175
|
+
const kind = browser ? 'browser' : api ? 'api' : unknown ? 'unknown' : definition.dependencies.length > 0 ? 'data' : 'unknown';
|
|
2176
|
+
const dependency = dependencyKinds.find((item) => item.kind === 'api' || item.kind === 'browser');
|
|
2177
|
+
const chain = kind === 'api' && helperCall !== null
|
|
2178
|
+
? `${name} → ${helperCall} → request.newContext()`
|
|
2179
|
+
: dependency !== undefined
|
|
2180
|
+
? `${name} → ${dependency.chain}`
|
|
2181
|
+
: name;
|
|
2182
|
+
active.delete(name);
|
|
2183
|
+
const result = { kind, chain };
|
|
2184
|
+
output[name] = result;
|
|
2185
|
+
return result;
|
|
2186
|
+
};
|
|
2187
|
+
for (const name of definitions.keys())
|
|
2188
|
+
classify(name);
|
|
2189
|
+
state.fixtureClassesByFile.set(file, output);
|
|
2190
|
+
return output;
|
|
2191
|
+
}
|
|
1095
2192
|
/**
|
|
1096
2193
|
* Runs the bounded static scan over the configured globs. Every value is
|
|
1097
2194
|
* derived from ASTs; the only I/O is reading candidate + import-target
|
|
@@ -1124,6 +2221,10 @@ export function scanTestFiles(options) {
|
|
|
1124
2221
|
maxTraversedFiles: options.budget?.maxTraversedFiles ?? DEFAULT_MAX_TRAVERSED_FILES,
|
|
1125
2222
|
maxImportDepth: options.budget?.maxImportDepth ?? DEFAULT_MAX_IMPORT_DEPTH,
|
|
1126
2223
|
testGlobals: options.testGlobals ?? (() => false),
|
|
2224
|
+
packageMetadata: new Map(),
|
|
2225
|
+
routeReachByExport: new Map(),
|
|
2226
|
+
routeTopLevelByFile: new Map(),
|
|
2227
|
+
fixtureClassesByFile: new Map(),
|
|
1127
2228
|
};
|
|
1128
2229
|
const seededFiles = collectCandidateFiles(options.cwd, options.include, options.exclude, options.excludeFile);
|
|
1129
2230
|
for (const file of seededFiles)
|
|
@@ -1132,11 +2233,15 @@ export function scanTestFiles(options) {
|
|
|
1132
2233
|
const model = modelOf(state, options.cwd, file, false);
|
|
1133
2234
|
if (model === null)
|
|
1134
2235
|
continue;
|
|
1135
|
-
const fileHttpClient = findHttpClientCall(model.source, model.source, file);
|
|
2236
|
+
const fileHttpClient = findHttpClientCall(model.source, model.source, file, false);
|
|
1136
2237
|
const fileMock = findModuleMock(model.source, file);
|
|
1137
|
-
const fileRoute = findImportedRouteInterception(state, options.cwd, file);
|
|
1138
|
-
const
|
|
1139
|
-
|
|
2238
|
+
const fileRoute = findImportedRouteInterception(state, options.cwd, file, false);
|
|
2239
|
+
const fileRouteBlocking = findImportedRouteInterception(state, options.cwd, file, true);
|
|
2240
|
+
const gateforgeImport = findGateforgeFixtureImport(state, model.source, file);
|
|
2241
|
+
scanFileForTests(state, options.cwd, model, fileHttpClient, fileMock, fileRoute, fileRouteBlocking, gateforgeImport);
|
|
2242
|
+
}
|
|
2243
|
+
for (const entry of state.result.entries) {
|
|
2244
|
+
entry.facts.fixtureClasses = fixtureClasses(state, entry.file);
|
|
1140
2245
|
}
|
|
1141
2246
|
// The import graph of everything the scan modeled. Every module-scope
|
|
1142
2247
|
// relative import was resolved to a repo-relative path while modeling
|
|
@@ -1217,6 +2322,10 @@ export function namedPathGraph(cwd, roots, budget) {
|
|
|
1217
2322
|
maxTraversedFiles: budget?.maxTraversedFiles ?? DEFAULT_MAX_TRAVERSED_FILES,
|
|
1218
2323
|
maxImportDepth: budget?.maxImportDepth ?? DEFAULT_MAX_IMPORT_DEPTH,
|
|
1219
2324
|
testGlobals: () => false,
|
|
2325
|
+
packageMetadata: new Map(),
|
|
2326
|
+
routeReachByExport: new Map(),
|
|
2327
|
+
routeTopLevelByFile: new Map(),
|
|
2328
|
+
fixtureClassesByFile: new Map(),
|
|
1220
2329
|
};
|
|
1221
2330
|
const rootFiles = new Set(roots);
|
|
1222
2331
|
const reached = new Set();
|
|
@@ -1283,11 +2392,31 @@ function compareEntry(a, b) {
|
|
|
1283
2392
|
a.location.line - b.location.line);
|
|
1284
2393
|
}
|
|
1285
2394
|
/** Visits one modeled file, harvesting describe stacks and test calls. */
|
|
1286
|
-
function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute, gateforgeImport) {
|
|
2395
|
+
function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute, fileRouteBlocking, gateforgeImport) {
|
|
1287
2396
|
const { file, source } = model;
|
|
1288
2397
|
// Once per file, not once per call site: the runner-globals predicate
|
|
1289
2398
|
// matches globs, and a file has hundreds of call expressions.
|
|
1290
2399
|
const runnerGlobals = state.testGlobals(file);
|
|
2400
|
+
const importedHttpClient = namespaceModuleReach(state, cwd, file, 0, new Set(), false, file);
|
|
2401
|
+
const httpClientFallback = importedHttpClient.kind === 'tamper' ? importedHttpClient.location : fileHttpClient;
|
|
2402
|
+
// 0.13.10 F3: a tamper written in this spec — or one that executes at
|
|
2403
|
+
// import time anywhere in its import graph — flags every test of the
|
|
2404
|
+
// file exactly as before. A tamper inside an imported HELPER is
|
|
2405
|
+
// attributed per test; when reachability cannot be proven, today's
|
|
2406
|
+
// file-wide graph tamper (`fileRoute`) stays the flag. 0.13.10 F7:
|
|
2407
|
+
// the blocking pass ignores the evaluate family — what a CHROMIUM
|
|
2408
|
+
// project may still refuse statically.
|
|
2409
|
+
const specDirectTamper = findRouteInterception(source, file, false);
|
|
2410
|
+
const specDirectBlocking = findRouteInterception(source, file, true);
|
|
2411
|
+
const importTimeTamper = specDirectTamper === null ? firstGraphTopLevelTamper(state, cwd, file, false) : null;
|
|
2412
|
+
const importTimeBlocking = specDirectBlocking === null ? firstGraphTopLevelTamper(state, cwd, file, true) : null;
|
|
2413
|
+
const fileWideTamper = specDirectTamper ?? importTimeTamper;
|
|
2414
|
+
const fileWideBlocking = specDirectBlocking ?? importTimeBlocking;
|
|
2415
|
+
const routeFor = (base, callback) => ({
|
|
2416
|
+
any: attributedRouteInterception(state, cwd, model, base, callback, fileWideTamper, fileRoute, false),
|
|
2417
|
+
blocking: attributedRouteInterception(state, cwd, model, base, callback, fileWideBlocking, fileRouteBlocking, true),
|
|
2418
|
+
httpClientCall: attributedHttpClientCall(state, cwd, model, base, callback, httpClientFallback),
|
|
2419
|
+
});
|
|
1291
2420
|
const visit = (node, describeStack, enclosing) => {
|
|
1292
2421
|
if (!ts.isCallExpression(node)) {
|
|
1293
2422
|
ts.forEachChild(node, (child) => visit(child, describeStack, enclosing));
|
|
@@ -1418,12 +2547,29 @@ function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute
|
|
|
1418
2547
|
if (effectiveResolution === 'test' && !isExtend && !lifecycle && !isDescribe && titleArgument !== undefined && !eachCall) {
|
|
1419
2548
|
const title = titleOf(titleArgument);
|
|
1420
2549
|
if (title === null) {
|
|
2550
|
+
const callSite = buildEntry({
|
|
2551
|
+
file,
|
|
2552
|
+
source,
|
|
2553
|
+
node,
|
|
2554
|
+
callback,
|
|
2555
|
+
titlePath: [UNRESOLVED_TITLE_PLACEHOLDER],
|
|
2556
|
+
parameterized: false,
|
|
2557
|
+
inheritedSignals: describeStack.flatMap((scope) => scope.signals),
|
|
2558
|
+
suppression,
|
|
2559
|
+
location,
|
|
2560
|
+
fileHttpClient,
|
|
2561
|
+
fileMock,
|
|
2562
|
+
route: routeFor(chain.base, callback),
|
|
2563
|
+
gateforgeImport,
|
|
2564
|
+
});
|
|
1421
2565
|
state.result.unresolved.push({
|
|
1422
2566
|
code: 'dynamic-title',
|
|
1423
2567
|
detail: 'test title is computed and cannot be resolved statically',
|
|
1424
2568
|
file,
|
|
1425
2569
|
titlePath: [UNRESOLVED_TITLE_PLACEHOLDER],
|
|
1426
2570
|
location,
|
|
2571
|
+
facts: callSite.facts,
|
|
2572
|
+
signals: callSite.signals,
|
|
1427
2573
|
});
|
|
1428
2574
|
return;
|
|
1429
2575
|
}
|
|
@@ -1439,7 +2585,7 @@ function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute
|
|
|
1439
2585
|
location,
|
|
1440
2586
|
fileHttpClient,
|
|
1441
2587
|
fileMock,
|
|
1442
|
-
|
|
2588
|
+
route: routeFor(chain.base, callback),
|
|
1443
2589
|
gateforgeImport,
|
|
1444
2590
|
});
|
|
1445
2591
|
state.result.entries.push(entry);
|
|
@@ -1460,12 +2606,29 @@ function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute
|
|
|
1460
2606
|
const outerCallback = outer.arguments.find((argument) => ts.isArrowFunction(argument) || ts.isFunctionExpression(argument));
|
|
1461
2607
|
const outerLocation = locationOf(file, source, outer);
|
|
1462
2608
|
if (title === null) {
|
|
2609
|
+
const callSite = buildEntry({
|
|
2610
|
+
file,
|
|
2611
|
+
source,
|
|
2612
|
+
node: outer,
|
|
2613
|
+
callback: outerCallback,
|
|
2614
|
+
titlePath: [UNRESOLVED_TITLE_PLACEHOLDER],
|
|
2615
|
+
parameterized: 'each',
|
|
2616
|
+
inheritedSignals: describeStack.flatMap((scope) => scope.signals),
|
|
2617
|
+
suppression,
|
|
2618
|
+
location: outerLocation,
|
|
2619
|
+
fileHttpClient,
|
|
2620
|
+
fileMock,
|
|
2621
|
+
route: routeFor(chain.base, outerCallback),
|
|
2622
|
+
gateforgeImport,
|
|
2623
|
+
});
|
|
1463
2624
|
state.result.unresolved.push({
|
|
1464
2625
|
code: 'dynamic-title',
|
|
1465
2626
|
detail: 'parameterized test title is computed and cannot be resolved statically',
|
|
1466
2627
|
file,
|
|
1467
2628
|
titlePath: [UNRESOLVED_TITLE_PLACEHOLDER],
|
|
1468
2629
|
location: outerLocation,
|
|
2630
|
+
facts: callSite.facts,
|
|
2631
|
+
signals: callSite.signals,
|
|
1469
2632
|
});
|
|
1470
2633
|
return;
|
|
1471
2634
|
}
|
|
@@ -1481,7 +2644,7 @@ function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute
|
|
|
1481
2644
|
location: outerLocation,
|
|
1482
2645
|
fileHttpClient,
|
|
1483
2646
|
fileMock,
|
|
1484
|
-
|
|
2647
|
+
route: routeFor(chain.base, outerCallback),
|
|
1485
2648
|
gateforgeImport,
|
|
1486
2649
|
});
|
|
1487
2650
|
state.result.entries.push(entry);
|
|
@@ -1763,11 +2926,10 @@ function buildEntry(input) {
|
|
|
1763
2926
|
signals.push({ kind: kind, detail: `test.${kind} modifier`, location });
|
|
1764
2927
|
}
|
|
1765
2928
|
let pageRoute = null;
|
|
1766
|
-
|
|
2929
|
+
const httpClientCall = input.route.httpClientCall;
|
|
1767
2930
|
const interceptedTargets = callback === undefined ? [] : pageRouteTargets(callback);
|
|
1768
2931
|
if (callback !== undefined) {
|
|
1769
2932
|
pageRoute = findPageRoute(callback, source, file);
|
|
1770
|
-
httpClientCall = findHttpClientCall(callback, source, file);
|
|
1771
2933
|
}
|
|
1772
2934
|
return {
|
|
1773
2935
|
file,
|
|
@@ -1783,7 +2945,8 @@ function buildEntry(input) {
|
|
|
1783
2945
|
httpClientCall,
|
|
1784
2946
|
fileHttpClientCall: input.fileHttpClient,
|
|
1785
2947
|
fileMockImport: input.fileMock,
|
|
1786
|
-
fileRouteInterception: input.
|
|
2948
|
+
fileRouteInterception: input.route.any,
|
|
2949
|
+
fileRouteInterceptionNonEvaluate: input.route.blocking,
|
|
1787
2950
|
gateforgeFixtureImport: input.gateforgeImport,
|
|
1788
2951
|
},
|
|
1789
2952
|
...(annotations.claims.length > 0 ? { annotationClaims: annotations.claims } : {}),
|