@gate-forge/pack-playwright 0.13.7 → 0.13.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/discovery/discover.d.ts.map +1 -1
- package/dist/discovery/discover.js +141 -39
- package/dist/discovery/discover.js.map +1 -1
- package/dist/discovery/index.d.ts +1 -0
- package/dist/discovery/index.d.ts.map +1 -1
- package/dist/discovery/index.js +1 -0
- package/dist/discovery/index.js.map +1 -1
- package/dist/discovery/inference.d.ts.map +1 -1
- package/dist/discovery/inference.js +2 -9
- 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/serial-scopes.d.ts +76 -0
- package/dist/discovery/serial-scopes.d.ts.map +1 -0
- package/dist/discovery/serial-scopes.js +244 -0
- package/dist/discovery/serial-scopes.js.map +1 -0
- package/dist/discovery/static-discovery.d.ts +34 -16
- package/dist/discovery/static-discovery.d.ts.map +1 -1
- package/dist/discovery/static-discovery.js +1025 -78
- package/dist/discovery/static-discovery.js.map +1 -1
- package/dist/discovery/supervised-run.d.ts +6 -0
- package/dist/discovery/supervised-run.d.ts.map +1 -1
- package/dist/discovery/supervised-run.js +1 -0
- package/dist/discovery/supervised-run.js.map +1 -1
- package/dist/discovery/trusted-config.d.ts +6 -0
- package/dist/discovery/trusted-config.d.ts.map +1 -1
- package/dist/discovery/trusted-config.js +5 -1
- package/dist/discovery/trusted-config.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/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.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')
|
|
@@ -919,14 +1099,14 @@ function findHttpClientCall(node, source, file) {
|
|
|
919
1099
|
return found;
|
|
920
1100
|
}
|
|
921
1101
|
/** Whether the file imports the gateforge evidence pack (fixture tests). */
|
|
922
|
-
function findGateforgeFixtureImport(source, file) {
|
|
1102
|
+
function findGateforgeFixtureImport(state, source, file) {
|
|
923
1103
|
let found = null;
|
|
924
1104
|
const visit = (node) => {
|
|
925
1105
|
if (found !== null)
|
|
926
1106
|
return;
|
|
927
1107
|
if (ts.isImportDeclaration(node) &&
|
|
928
1108
|
ts.isStringLiteral(node.moduleSpecifier) &&
|
|
929
|
-
isPackSpecifier(node.moduleSpecifier.text)) {
|
|
1109
|
+
isPackSpecifier(state, file, node.moduleSpecifier.text)) {
|
|
930
1110
|
found = locationOf(file, source, node);
|
|
931
1111
|
return;
|
|
932
1112
|
}
|
|
@@ -935,7 +1115,7 @@ function findGateforgeFixtureImport(source, file) {
|
|
|
935
1115
|
ts.isIdentifier(node.expression) &&
|
|
936
1116
|
node.expression.text === 'require') {
|
|
937
1117
|
const specifier = node.arguments[0];
|
|
938
|
-
if (specifier !== undefined && ts.isStringLiteral(specifier) && isPackSpecifier(specifier.text)) {
|
|
1118
|
+
if (specifier !== undefined && ts.isStringLiteral(specifier) && isPackSpecifier(state, file, specifier.text)) {
|
|
939
1119
|
found = locationOf(file, source, node);
|
|
940
1120
|
return;
|
|
941
1121
|
}
|
|
@@ -967,6 +1147,7 @@ function findModuleMock(source, file) {
|
|
|
967
1147
|
/** The storage mutations a storage-only init script may make. */
|
|
968
1148
|
const SAFE_STORAGE_METHODS = {
|
|
969
1149
|
clear: true,
|
|
1150
|
+
getItem: true,
|
|
970
1151
|
removeItem: true,
|
|
971
1152
|
setItem: true,
|
|
972
1153
|
};
|
|
@@ -979,8 +1160,168 @@ function storageReceiverName(node) {
|
|
|
979
1160
|
}
|
|
980
1161
|
return ts.isIdentifier(node) ? node.text : null;
|
|
981
1162
|
}
|
|
982
|
-
/**
|
|
983
|
-
|
|
1163
|
+
/**
|
|
1164
|
+
* Resolves a name to a variable initializer declared in a block (or
|
|
1165
|
+
* module scope) enclosing `from`, walking outward — the lexical lookup
|
|
1166
|
+
* a closure reference performs, innermost block winning. `let`/`var`
|
|
1167
|
+
* count too: the grammar below admits only values that are inert data,
|
|
1168
|
+
* so a reassigned binding can add no capability.
|
|
1169
|
+
*/
|
|
1170
|
+
function resolveLocalInitializer(name, from) {
|
|
1171
|
+
let current = from.parent;
|
|
1172
|
+
while (current !== undefined) {
|
|
1173
|
+
if (ts.isBlock(current) || ts.isSourceFile(current)) {
|
|
1174
|
+
for (const statement of current.statements) {
|
|
1175
|
+
if (!ts.isVariableStatement(statement))
|
|
1176
|
+
continue;
|
|
1177
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
1178
|
+
if (ts.isIdentifier(declaration.name) && declaration.name.text === name) {
|
|
1179
|
+
return declaration.initializer;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
current = current.parent;
|
|
1185
|
+
}
|
|
1186
|
+
return undefined;
|
|
1187
|
+
}
|
|
1188
|
+
/**
|
|
1189
|
+
* Resolves a name to a function declared in a block (or module scope)
|
|
1190
|
+
* enclosing `from`: a function declaration, a variable whose
|
|
1191
|
+
* initializer is the function itself, or — one bounded hop, cycle
|
|
1192
|
+
* guarded — an alias to another such name. Null when the name is not a
|
|
1193
|
+
* locally declared function: a reference form the scan cannot prove
|
|
1194
|
+
* stays a tamper.
|
|
1195
|
+
*/
|
|
1196
|
+
function resolveLocalFunctionReference(name, from, depth, seen) {
|
|
1197
|
+
if (depth > 4 || seen.has(name))
|
|
1198
|
+
return null;
|
|
1199
|
+
let current = from.parent;
|
|
1200
|
+
while (current !== undefined) {
|
|
1201
|
+
if (ts.isBlock(current) || ts.isSourceFile(current)) {
|
|
1202
|
+
for (const statement of current.statements) {
|
|
1203
|
+
if (ts.isFunctionDeclaration(statement) && statement.name !== undefined && statement.name.text === name && statement.body !== undefined) {
|
|
1204
|
+
return statement;
|
|
1205
|
+
}
|
|
1206
|
+
if (!ts.isVariableStatement(statement))
|
|
1207
|
+
continue;
|
|
1208
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
1209
|
+
if (!ts.isIdentifier(declaration.name) || declaration.name.text !== name)
|
|
1210
|
+
continue;
|
|
1211
|
+
const initializer = declaration.initializer;
|
|
1212
|
+
if (initializer === undefined)
|
|
1213
|
+
return null;
|
|
1214
|
+
if (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer))
|
|
1215
|
+
return initializer;
|
|
1216
|
+
if (ts.isIdentifier(initializer)) {
|
|
1217
|
+
const next = new Set(seen);
|
|
1218
|
+
next.add(name);
|
|
1219
|
+
return resolveLocalFunctionReference(initializer.text, declaration, depth + 1, next);
|
|
1220
|
+
}
|
|
1221
|
+
return null;
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
current = current.parent;
|
|
1226
|
+
}
|
|
1227
|
+
return null;
|
|
1228
|
+
}
|
|
1229
|
+
/** Whether `new` is a zero-argument `new Date()` — an inert timestamp read. */
|
|
1230
|
+
function isNewDateConstruction(expression) {
|
|
1231
|
+
return (ts.isIdentifier(expression.expression) &&
|
|
1232
|
+
expression.expression.text === 'Date' &&
|
|
1233
|
+
(expression.arguments === undefined || expression.arguments.length === 0));
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* A value a storage-only init script may compute for a storage
|
|
1237
|
+
* key/value slot: literals (never template forms), the script's own
|
|
1238
|
+
* parameters, lexically declared constants whose initializer is such a
|
|
1239
|
+
* value, structured literals of them, and a whitelist of inert
|
|
1240
|
+
* builtins (`JSON.stringify`, `String`, `Date.now()`, `new Date()` and
|
|
1241
|
+
* its `toISOString()`). Every shape is data only — nothing here can
|
|
1242
|
+
* reach the page, the network, or any other browser API. Anything else
|
|
1243
|
+
* — a bare unresolved identifier, a template form, a computed member
|
|
1244
|
+
* read — fails closed.
|
|
1245
|
+
*/
|
|
1246
|
+
function isStorageOnlyValue(expression, params, stack) {
|
|
1247
|
+
if (ts.isStringLiteral(expression) ||
|
|
1248
|
+
ts.isNumericLiteral(expression) ||
|
|
1249
|
+
expression.kind === ts.SyntaxKind.TrueKeyword ||
|
|
1250
|
+
expression.kind === ts.SyntaxKind.FalseKeyword ||
|
|
1251
|
+
expression.kind === ts.SyntaxKind.NullKeyword) {
|
|
1252
|
+
return true;
|
|
1253
|
+
}
|
|
1254
|
+
if (ts.isIdentifier(expression)) {
|
|
1255
|
+
if (expression.text === 'undefined')
|
|
1256
|
+
return true;
|
|
1257
|
+
if (params.has(expression.text))
|
|
1258
|
+
return true;
|
|
1259
|
+
if (stack.has(expression.text))
|
|
1260
|
+
return false;
|
|
1261
|
+
const initializer = resolveLocalInitializer(expression.text, expression);
|
|
1262
|
+
if (initializer === undefined)
|
|
1263
|
+
return false;
|
|
1264
|
+
const next = new Set(stack);
|
|
1265
|
+
next.add(expression.text);
|
|
1266
|
+
return isStorageOnlyValue(initializer, params, next);
|
|
1267
|
+
}
|
|
1268
|
+
if (ts.isPropertyAccessExpression(expression)) {
|
|
1269
|
+
return (expression.name.text === 'toISOString' &&
|
|
1270
|
+
ts.isNewExpression(expression.expression) &&
|
|
1271
|
+
isNewDateConstruction(expression.expression));
|
|
1272
|
+
}
|
|
1273
|
+
if (ts.isCallExpression(expression)) {
|
|
1274
|
+
const callee = expression.expression;
|
|
1275
|
+
if (ts.isPropertyAccessExpression(callee)) {
|
|
1276
|
+
const owner = callee.expression;
|
|
1277
|
+
if (callee.name.text === 'now' &&
|
|
1278
|
+
ts.isIdentifier(owner) &&
|
|
1279
|
+
owner.text === 'Date' &&
|
|
1280
|
+
expression.arguments.length === 0) {
|
|
1281
|
+
return true;
|
|
1282
|
+
}
|
|
1283
|
+
if (callee.name.text === 'stringify' &&
|
|
1284
|
+
ts.isIdentifier(owner) &&
|
|
1285
|
+
owner.text === 'JSON' &&
|
|
1286
|
+
expression.arguments.length === 1) {
|
|
1287
|
+
const first = expression.arguments[0];
|
|
1288
|
+
return first !== undefined && isStorageOnlyValue(first, params, stack);
|
|
1289
|
+
}
|
|
1290
|
+
if (callee.name.text === 'toISOString' &&
|
|
1291
|
+
expression.arguments.length === 0 &&
|
|
1292
|
+
ts.isNewExpression(owner) &&
|
|
1293
|
+
isNewDateConstruction(owner)) {
|
|
1294
|
+
return true;
|
|
1295
|
+
}
|
|
1296
|
+
return false;
|
|
1297
|
+
}
|
|
1298
|
+
if (ts.isIdentifier(callee) && callee.text === 'String' && expression.arguments.length === 1) {
|
|
1299
|
+
const first = expression.arguments[0];
|
|
1300
|
+
return first !== undefined && isStorageOnlyValue(first, params, stack);
|
|
1301
|
+
}
|
|
1302
|
+
return false;
|
|
1303
|
+
}
|
|
1304
|
+
if (ts.isNewExpression(expression))
|
|
1305
|
+
return isNewDateConstruction(expression);
|
|
1306
|
+
if (ts.isObjectLiteralExpression(expression)) {
|
|
1307
|
+
return expression.properties.every((property) => {
|
|
1308
|
+
if (ts.isPropertyAssignment(property))
|
|
1309
|
+
return isStorageOnlyValue(property.initializer, params, stack);
|
|
1310
|
+
if (ts.isShorthandPropertyAssignment(property))
|
|
1311
|
+
return isStorageOnlyValue(property.name, params, stack);
|
|
1312
|
+
return false;
|
|
1313
|
+
});
|
|
1314
|
+
}
|
|
1315
|
+
if (ts.isArrayLiteralExpression(expression)) {
|
|
1316
|
+
return expression.elements.every((element) => ts.isExpression(element) && isStorageOnlyValue(element, params, stack));
|
|
1317
|
+
}
|
|
1318
|
+
return false;
|
|
1319
|
+
}
|
|
1320
|
+
/**
|
|
1321
|
+
* One `localStorage.setItem('k', 'v')`-shaped storage call, keyed and
|
|
1322
|
+
* valued by {@link isStorageOnlyValue} expressions.
|
|
1323
|
+
*/
|
|
1324
|
+
function isStorageOnlyCall(expression, params, stack) {
|
|
984
1325
|
if (!ts.isCallExpression(expression) || !ts.isPropertyAccessExpression(expression.expression))
|
|
985
1326
|
return false;
|
|
986
1327
|
const method = expression.expression.name.text;
|
|
@@ -994,40 +1335,176 @@ function isSafeStorageCall(expression) {
|
|
|
994
1335
|
if (method === 'setItem') {
|
|
995
1336
|
return (first !== undefined &&
|
|
996
1337
|
second !== undefined &&
|
|
997
|
-
|
|
998
|
-
|
|
1338
|
+
isStorageOnlyValue(first, params, stack) &&
|
|
1339
|
+
isStorageOnlyValue(second, params, stack));
|
|
999
1340
|
}
|
|
1000
|
-
if (method === 'removeItem') {
|
|
1001
|
-
return expression.arguments.length === 1 && first !== undefined &&
|
|
1341
|
+
if (method === 'removeItem' || method === 'getItem') {
|
|
1342
|
+
return expression.arguments.length === 1 && first !== undefined && isStorageOnlyValue(first, params, stack);
|
|
1002
1343
|
}
|
|
1003
1344
|
return expression.arguments.length === 0;
|
|
1004
1345
|
}
|
|
1005
|
-
/**
|
|
1006
|
-
function
|
|
1007
|
-
return
|
|
1346
|
+
/** A storage read or an inert value — one operand of a guarded condition. */
|
|
1347
|
+
function isStorageOnlyOperand(expression, params, stack) {
|
|
1348
|
+
return isStorageOnlyValue(expression, params, stack) || isStorageOnlyCall(expression, params, stack);
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* The condition of a guarded storage-only statement: an equality
|
|
1352
|
+
* comparison (or negation) over storage reads and inert values — the
|
|
1353
|
+
* read-then-seed shape. Anything else fails closed.
|
|
1354
|
+
*/
|
|
1355
|
+
function isStorageOnlyCondition(expression, params, stack) {
|
|
1356
|
+
if (ts.isBinaryExpression(expression)) {
|
|
1357
|
+
const operator = expression.operatorToken.kind;
|
|
1358
|
+
const comparable = operator === ts.SyntaxKind.EqualsEqualsEqualsToken ||
|
|
1359
|
+
operator === ts.SyntaxKind.ExclamationEqualsEqualsToken ||
|
|
1360
|
+
operator === ts.SyntaxKind.EqualsEqualsToken ||
|
|
1361
|
+
operator === ts.SyntaxKind.ExclamationEqualsToken;
|
|
1362
|
+
return (comparable &&
|
|
1363
|
+
isStorageOnlyOperand(expression.left, params, stack) &&
|
|
1364
|
+
isStorageOnlyOperand(expression.right, params, stack));
|
|
1365
|
+
}
|
|
1366
|
+
if (ts.isPrefixUnaryExpression(expression) && expression.operator === ts.SyntaxKind.ExclamationToken) {
|
|
1367
|
+
return isStorageOnlyOperand(expression.operand, params, stack);
|
|
1368
|
+
}
|
|
1369
|
+
return isStorageOnlyOperand(expression, params, stack);
|
|
1370
|
+
}
|
|
1371
|
+
/** One statement of a storage-only init script body. */
|
|
1372
|
+
function isStorageOnlyStatement(node, params) {
|
|
1373
|
+
if (ts.isExpressionStatement(node))
|
|
1374
|
+
return isStorageOnlyCall(node.expression, params, new Set());
|
|
1375
|
+
if (ts.isIfStatement(node)) {
|
|
1376
|
+
return (isStorageOnlyCondition(node.expression, params, new Set()) &&
|
|
1377
|
+
isStorageOnlyStatement(node.thenStatement, params) &&
|
|
1378
|
+
(node.elseStatement === undefined || isStorageOnlyStatement(node.elseStatement, params)));
|
|
1379
|
+
}
|
|
1380
|
+
if (ts.isTryStatement(node)) {
|
|
1381
|
+
const tryClean = node.tryBlock.statements.every((statement) => isStorageOnlyStatement(statement, params));
|
|
1382
|
+
const catchClean = node.catchClause === undefined ||
|
|
1383
|
+
node.catchClause.block.statements.every((statement) => isStorageOnlyStatement(statement, params));
|
|
1384
|
+
const finallyClean = node.finallyBlock === undefined ||
|
|
1385
|
+
node.finallyBlock.statements.every((statement) => isStorageOnlyStatement(statement, params));
|
|
1386
|
+
return tryClean && catchClean && finallyClean;
|
|
1387
|
+
}
|
|
1388
|
+
if (ts.isBlock(node))
|
|
1389
|
+
return node.statements.every((statement) => isStorageOnlyStatement(statement, params));
|
|
1390
|
+
return false;
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Collects the LOCAL names a script function's parameter pattern binds:
|
|
1394
|
+
* the identifier itself, or — for object/array destructuring — each
|
|
1395
|
+
* bound element's local name, recursively. Destructured properties are
|
|
1396
|
+
* serialized data exactly like a whole parameter, so they are usable as
|
|
1397
|
+
* storage keys/values too. False when the pattern binds nothing
|
|
1398
|
+
* trackable (computed properties) — the script then stays a tamper.
|
|
1399
|
+
*/
|
|
1400
|
+
function collectBoundParamNames(pattern, into) {
|
|
1401
|
+
if (ts.isIdentifier(pattern)) {
|
|
1402
|
+
into.add(pattern.text);
|
|
1403
|
+
return true;
|
|
1404
|
+
}
|
|
1405
|
+
for (const element of pattern.elements) {
|
|
1406
|
+
if (!ts.isBindingElement(element))
|
|
1407
|
+
return false;
|
|
1408
|
+
if (!collectBoundParamNames(element.name, into))
|
|
1409
|
+
return false;
|
|
1410
|
+
}
|
|
1411
|
+
return true;
|
|
1412
|
+
}
|
|
1413
|
+
/** Applies the storage-only body grammar to one resolved script function. */
|
|
1414
|
+
function isStorageOnlyScriptFunction(script, call) {
|
|
1415
|
+
// The script may take parameters ONLY when the addInitScript call
|
|
1416
|
+
// passes exactly one argument per parameter (0.13.10 F2); a
|
|
1417
|
+
// parameterless script with extra arguments stays a tamper (0.13.9).
|
|
1418
|
+
// Each parameter can then only ever be serialized data, so a body
|
|
1419
|
+
// made solely of storage calls mutates nothing but storage.
|
|
1420
|
+
if (call.arguments.length !== script.parameters.length + 1)
|
|
1421
|
+
return false;
|
|
1422
|
+
const params = new Set();
|
|
1423
|
+
for (const parameter of script.parameters) {
|
|
1424
|
+
if (!collectBoundParamNames(parameter.name, params))
|
|
1425
|
+
return false;
|
|
1426
|
+
}
|
|
1427
|
+
const body = script.body;
|
|
1428
|
+
if (body === undefined)
|
|
1429
|
+
return false;
|
|
1430
|
+
if (ts.isBlock(body)) {
|
|
1431
|
+
return (body.statements.length > 0 &&
|
|
1432
|
+
body.statements.every((statement) => isStorageOnlyStatement(statement, params)));
|
|
1433
|
+
}
|
|
1434
|
+
return isStorageOnlyCall(body, params, new Set());
|
|
1008
1435
|
}
|
|
1009
1436
|
/**
|
|
1010
1437
|
* 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
|
-
*
|
|
1438
|
+
* script: a single script argument — an arrow/function literal or a
|
|
1439
|
+
* reference to a locally declared function — whose body is made solely
|
|
1440
|
+
* of localStorage/sessionStorage mutations (`setItem`/`getItem`/
|
|
1441
|
+
* `removeItem`/`clear`, optional `window.` receiver), with exactly one
|
|
1442
|
+
* `addInitScript` argument per declared parameter. The body grammar
|
|
1443
|
+
* admits storage calls keyed/valued by literals, the script's own
|
|
1444
|
+
* parameters, lexically declared constants and inert builtins
|
|
1445
|
+
* (`JSON.stringify`, `String`, `Date.now()`, `new Date()`
|
|
1446
|
+
* `.toISOString()`), under the control flow that guards them (`if`
|
|
1447
|
+
* over a storage read, `try`/`catch`). Such a script mutates nothing
|
|
1448
|
+
* the witness cannot verify solely from its independent observer, so
|
|
1449
|
+
* it is not a tamper and the scan continues past it. Every other shape
|
|
1450
|
+
* — an arity mismatch, a template form, an unresolved identifier in a
|
|
1451
|
+
* key/value slot, any other statement (network, DOM,
|
|
1452
|
+
* `Object.defineProperty`), a string/path script, an empty body, a
|
|
1453
|
+
* reference the scan cannot resolve to a local declaration — stays a
|
|
1454
|
+
* tamper (fail closed). The same function handed to `page.evaluate`
|
|
1455
|
+
* is unaffected: evaluate keeps its own rule.
|
|
1018
1456
|
*/
|
|
1019
1457
|
function isStorageOnlyInitScript(call) {
|
|
1020
|
-
if (call.arguments.length !== 1)
|
|
1021
|
-
return false;
|
|
1022
1458
|
const script = call.arguments[0];
|
|
1023
|
-
if (script === undefined
|
|
1024
|
-
return false;
|
|
1025
|
-
if (script.parameters.length !== 0)
|
|
1459
|
+
if (script === undefined)
|
|
1026
1460
|
return false;
|
|
1027
|
-
if (ts.
|
|
1028
|
-
return script
|
|
1461
|
+
if (ts.isArrowFunction(script) || ts.isFunctionExpression(script)) {
|
|
1462
|
+
return isStorageOnlyScriptFunction(script, call);
|
|
1029
1463
|
}
|
|
1030
|
-
|
|
1464
|
+
if (ts.isIdentifier(script)) {
|
|
1465
|
+
const resolved = resolveLocalFunctionReference(script.text, script, 0, new Set());
|
|
1466
|
+
return resolved !== null && isStorageOnlyScriptFunction(resolved, call);
|
|
1467
|
+
}
|
|
1468
|
+
return false;
|
|
1469
|
+
}
|
|
1470
|
+
/** Page-observation tamper API calls: browser mutations the witness cannot verify solely from its independent CDP observer. */
|
|
1471
|
+
const TAMPER_API_CALLS = {
|
|
1472
|
+
addInitScript: true,
|
|
1473
|
+
connectOverCDP: true,
|
|
1474
|
+
evaluate: true,
|
|
1475
|
+
exposeFunction: true,
|
|
1476
|
+
fulfill: true,
|
|
1477
|
+
newBrowserCDPSession: true,
|
|
1478
|
+
newCDPSession: true,
|
|
1479
|
+
route: true,
|
|
1480
|
+
setContent: true,
|
|
1481
|
+
};
|
|
1482
|
+
/** The evaluate family: at runtime the Chromium initiator rule already refuses every request evaluated test code starts (0.13.10 F7). */
|
|
1483
|
+
const EVALUATE_FAMILY_CALLS = {
|
|
1484
|
+
$$eval: true,
|
|
1485
|
+
$eval: true,
|
|
1486
|
+
evaluate: true,
|
|
1487
|
+
evaluateHandle: true,
|
|
1488
|
+
};
|
|
1489
|
+
/**
|
|
1490
|
+
* The location of one page-observation tamper API call, or null. A
|
|
1491
|
+
* storage-only init script ({@link isStorageOnlyInitScript}) is not a
|
|
1492
|
+
* tamper — the scan continues past it so a real tamper later in the
|
|
1493
|
+
* file is still found. With `ignoreEvaluate` the evaluate family does
|
|
1494
|
+
* not match either: the chromium-only blocking pass, which reads what a
|
|
1495
|
+
* chromium project may still refuse statically.
|
|
1496
|
+
*/
|
|
1497
|
+
function tamperApiLocation(source, file, node, ignoreEvaluate) {
|
|
1498
|
+
if (!ts.isPropertyAccessExpression(node.expression))
|
|
1499
|
+
return null;
|
|
1500
|
+
const name = node.expression.name.text;
|
|
1501
|
+
if (TAMPER_API_CALLS[name] !== true)
|
|
1502
|
+
return null;
|
|
1503
|
+
if (ignoreEvaluate && EVALUATE_FAMILY_CALLS[name] === true)
|
|
1504
|
+
return null;
|
|
1505
|
+
if (name === 'addInitScript' && isStorageOnlyInitScript(node))
|
|
1506
|
+
return null;
|
|
1507
|
+
return locationOf(file, source, node);
|
|
1031
1508
|
}
|
|
1032
1509
|
/**
|
|
1033
1510
|
* Finds one page-observation tamper API call in a parsed helper/spec.
|
|
@@ -1037,31 +1514,17 @@ function isStorageOnlyInitScript(call) {
|
|
|
1037
1514
|
* localStorage/sessionStorage and is therefore not a tamper; the scan
|
|
1038
1515
|
* continues past it so a real tamper later in the file is still found.
|
|
1039
1516
|
*/
|
|
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
|
-
};
|
|
1517
|
+
function findRouteInterception(source, file, ignoreEvaluate) {
|
|
1052
1518
|
let found = null;
|
|
1053
1519
|
const visit = (node) => {
|
|
1054
1520
|
if (found !== null)
|
|
1055
1521
|
return;
|
|
1056
|
-
if (ts.isCallExpression(node)
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
ts.forEachChild(node, visit);
|
|
1522
|
+
if (ts.isCallExpression(node)) {
|
|
1523
|
+
const tamper = tamperApiLocation(source, file, node, ignoreEvaluate);
|
|
1524
|
+
if (tamper !== null) {
|
|
1525
|
+
found = tamper;
|
|
1061
1526
|
return;
|
|
1062
1527
|
}
|
|
1063
|
-
found = locationOf(file, source, node);
|
|
1064
|
-
return;
|
|
1065
1528
|
}
|
|
1066
1529
|
ts.forEachChild(node, visit);
|
|
1067
1530
|
};
|
|
@@ -1069,7 +1532,7 @@ function findRouteInterception(source, file) {
|
|
|
1069
1532
|
return found;
|
|
1070
1533
|
}
|
|
1071
1534
|
/** First tamper call in a spec or any helper imported by its module graph. */
|
|
1072
|
-
function findImportedRouteInterception(state, cwd, root) {
|
|
1535
|
+
function findImportedRouteInterception(state, cwd, root, ignoreEvaluate) {
|
|
1073
1536
|
const visited = new Set();
|
|
1074
1537
|
const visit = (file, depth) => {
|
|
1075
1538
|
if (visited.has(file) || depth > state.maxImportDepth)
|
|
@@ -1078,7 +1541,7 @@ function findImportedRouteInterception(state, cwd, root) {
|
|
|
1078
1541
|
const model = state.models.get(file) ?? modelOf(state, cwd, file, true);
|
|
1079
1542
|
if (model === null)
|
|
1080
1543
|
return null;
|
|
1081
|
-
const local = findRouteInterception(model.source, file);
|
|
1544
|
+
const local = findRouteInterception(model.source, file, ignoreEvaluate);
|
|
1082
1545
|
if (local !== null)
|
|
1083
1546
|
return local;
|
|
1084
1547
|
for (const binding of model.bindings.values()) {
|
|
@@ -1092,6 +1555,431 @@ function findImportedRouteInterception(state, cwd, root) {
|
|
|
1092
1555
|
};
|
|
1093
1556
|
return visit(root, 0);
|
|
1094
1557
|
}
|
|
1558
|
+
/** Shared immutable verdicts; never mutated. */
|
|
1559
|
+
const CLEAN_REACH = { kind: 'clean' };
|
|
1560
|
+
const UNKNOWN_REACH = { kind: 'unknown' };
|
|
1561
|
+
/**
|
|
1562
|
+
* A reference to a risky or unprovable name whose invocation cannot be
|
|
1563
|
+
* proven at this site: a helper CALLED directly carries its reach; a
|
|
1564
|
+
* helper passed around as a value reads as unknown, and the caller
|
|
1565
|
+
* falls back to today's file-wide flag.
|
|
1566
|
+
*/
|
|
1567
|
+
function referenceVerdict(reach, called) {
|
|
1568
|
+
if (reach.kind === 'clean')
|
|
1569
|
+
return CLEAN_REACH;
|
|
1570
|
+
return called ? reach : UNKNOWN_REACH;
|
|
1571
|
+
}
|
|
1572
|
+
/** Module-scope declarations by name: variable initializers, function declarations. */
|
|
1573
|
+
const routeDeclsByModel = new WeakMap();
|
|
1574
|
+
function routeDeclsOf(model) {
|
|
1575
|
+
const cached = routeDeclsByModel.get(model);
|
|
1576
|
+
if (cached !== undefined)
|
|
1577
|
+
return cached;
|
|
1578
|
+
const decls = new Map();
|
|
1579
|
+
for (const statement of model.source.statements) {
|
|
1580
|
+
if (ts.isVariableStatement(statement)) {
|
|
1581
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
1582
|
+
if (ts.isIdentifier(declaration.name) && declaration.initializer !== undefined) {
|
|
1583
|
+
decls.set(declaration.name.text, declaration.initializer);
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
}
|
|
1587
|
+
else if (ts.isFunctionDeclaration(statement) && statement.name !== undefined && statement.body !== undefined) {
|
|
1588
|
+
decls.set(statement.name.text, statement);
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1591
|
+
routeDeclsByModel.set(model, decls);
|
|
1592
|
+
return decls;
|
|
1593
|
+
}
|
|
1594
|
+
/**
|
|
1595
|
+
* Resolves a name to a declaration readable from `from`'s lexical
|
|
1596
|
+
* position: a variable initializer or a function declaration in a
|
|
1597
|
+
* block (or the module scope) enclosing it, innermost block winning —
|
|
1598
|
+
* the lookup a closure reference performs. Undefined when the name
|
|
1599
|
+
* declares nothing lexically visible.
|
|
1600
|
+
*/
|
|
1601
|
+
function resolveLocalReferenceNode(name, from) {
|
|
1602
|
+
let current = from.parent;
|
|
1603
|
+
while (current !== undefined) {
|
|
1604
|
+
if (ts.isBlock(current) || ts.isSourceFile(current)) {
|
|
1605
|
+
for (const statement of current.statements) {
|
|
1606
|
+
if (ts.isFunctionDeclaration(statement) && statement.name !== undefined && statement.name.text === name && statement.body !== undefined) {
|
|
1607
|
+
return statement;
|
|
1608
|
+
}
|
|
1609
|
+
if (!ts.isVariableStatement(statement))
|
|
1610
|
+
continue;
|
|
1611
|
+
for (const declaration of statement.declarationList.declarations) {
|
|
1612
|
+
if (ts.isIdentifier(declaration.name) && declaration.name.text === name && declaration.initializer !== undefined) {
|
|
1613
|
+
return declaration.initializer;
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
current = current.parent;
|
|
1619
|
+
}
|
|
1620
|
+
return undefined;
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* The first tamper call OUTSIDE any function body in the file: code an
|
|
1624
|
+
* import executes, so every file importing this one reaches it. Memoized
|
|
1625
|
+
* per scan; a file that cannot be modeled adds none.
|
|
1626
|
+
*/
|
|
1627
|
+
function topLevelTamperOf(state, cwd, file, ignoreEvaluate) {
|
|
1628
|
+
const memoKey = `${file}::${ignoreEvaluate ? 'blocking' : 'any'}`;
|
|
1629
|
+
const cached = state.routeTopLevelByFile.get(memoKey);
|
|
1630
|
+
if (cached !== undefined)
|
|
1631
|
+
return cached;
|
|
1632
|
+
const model = state.models.get(file) ?? modelOf(state, cwd, file, true);
|
|
1633
|
+
let found = null;
|
|
1634
|
+
if (model !== null) {
|
|
1635
|
+
const runsAtImport = (node) => ts.isFunctionDeclaration(node) ||
|
|
1636
|
+
ts.isArrowFunction(node) ||
|
|
1637
|
+
ts.isFunctionExpression(node) ||
|
|
1638
|
+
ts.isMethodDeclaration(node) ||
|
|
1639
|
+
ts.isConstructorDeclaration(node) ||
|
|
1640
|
+
ts.isGetAccessorDeclaration(node) ||
|
|
1641
|
+
ts.isSetAccessorDeclaration(node);
|
|
1642
|
+
const visit = (node) => {
|
|
1643
|
+
if (found !== null)
|
|
1644
|
+
return;
|
|
1645
|
+
if (ts.isCallExpression(node)) {
|
|
1646
|
+
const tamper = tamperApiLocation(model.source, file, node, ignoreEvaluate);
|
|
1647
|
+
if (tamper !== null) {
|
|
1648
|
+
found = tamper;
|
|
1649
|
+
return;
|
|
1650
|
+
}
|
|
1651
|
+
}
|
|
1652
|
+
if (runsAtImport(node))
|
|
1653
|
+
return;
|
|
1654
|
+
ts.forEachChild(node, visit);
|
|
1655
|
+
};
|
|
1656
|
+
visit(model.source);
|
|
1657
|
+
}
|
|
1658
|
+
state.routeTopLevelByFile.set(memoKey, found);
|
|
1659
|
+
return found;
|
|
1660
|
+
}
|
|
1661
|
+
/** First import-time (top-level) tamper across the file's import graph, or null. */
|
|
1662
|
+
function firstGraphTopLevelTamper(state, cwd, root, ignoreEvaluate) {
|
|
1663
|
+
const visited = new Set();
|
|
1664
|
+
const visit = (file, depth) => {
|
|
1665
|
+
if (visited.has(file) || depth > state.maxImportDepth)
|
|
1666
|
+
return null;
|
|
1667
|
+
visited.add(file);
|
|
1668
|
+
const model = state.models.get(file) ?? modelOf(state, cwd, file, true);
|
|
1669
|
+
if (model === null)
|
|
1670
|
+
return null;
|
|
1671
|
+
const topLevel = topLevelTamperOf(state, cwd, file, ignoreEvaluate);
|
|
1672
|
+
if (topLevel !== null)
|
|
1673
|
+
return topLevel;
|
|
1674
|
+
for (const binding of model.bindings.values()) {
|
|
1675
|
+
if (binding.kind !== 'import' || binding.target === undefined)
|
|
1676
|
+
continue;
|
|
1677
|
+
const nested = visit(binding.target, depth + 1);
|
|
1678
|
+
if (nested !== null)
|
|
1679
|
+
return nested;
|
|
1680
|
+
}
|
|
1681
|
+
return null;
|
|
1682
|
+
};
|
|
1683
|
+
return visit(root, 0);
|
|
1684
|
+
}
|
|
1685
|
+
/** The reach of one module-scope name: its declaration's subtree, or the export it points at. */
|
|
1686
|
+
function localNameTamperReach(state, cwd, model, name, depth, active, ignoreEvaluate) {
|
|
1687
|
+
const declaration = routeDeclsOf(model).get(name);
|
|
1688
|
+
if (declaration !== undefined) {
|
|
1689
|
+
return nodeTamperReach(state, cwd, model, declaration, depth + 1, active, ignoreEvaluate);
|
|
1690
|
+
}
|
|
1691
|
+
const binding = model.bindings.get(name);
|
|
1692
|
+
if (binding === undefined)
|
|
1693
|
+
return UNKNOWN_REACH;
|
|
1694
|
+
switch (binding.kind) {
|
|
1695
|
+
case 'import': {
|
|
1696
|
+
if (binding.target === undefined)
|
|
1697
|
+
return CLEAN_REACH;
|
|
1698
|
+
return binding.importedName === '*'
|
|
1699
|
+
? namespaceModuleReach(state, cwd, binding.target, depth + 1, active, ignoreEvaluate)
|
|
1700
|
+
: exportedNameTamperReach(state, cwd, binding.target, binding.importedName ?? '', depth + 1, active, ignoreEvaluate);
|
|
1701
|
+
}
|
|
1702
|
+
case 'alias': {
|
|
1703
|
+
const aliased = binding.target === undefined ? undefined : routeDeclsOf(model).get(binding.target);
|
|
1704
|
+
return aliased === undefined
|
|
1705
|
+
? CLEAN_REACH
|
|
1706
|
+
: nodeTamperReach(state, cwd, model, aliased, depth + 1, active, ignoreEvaluate);
|
|
1707
|
+
}
|
|
1708
|
+
case 'test':
|
|
1709
|
+
case 'testmodule':
|
|
1710
|
+
case 'external':
|
|
1711
|
+
case 'plain':
|
|
1712
|
+
case 'import-broken':
|
|
1713
|
+
case 'data':
|
|
1714
|
+
return CLEAN_REACH;
|
|
1715
|
+
case 'unresolvable':
|
|
1716
|
+
return UNKNOWN_REACH;
|
|
1717
|
+
}
|
|
1718
|
+
}
|
|
1719
|
+
/**
|
|
1720
|
+
* Memoized tamper reach of one exported name, following re-exports.
|
|
1721
|
+
* An in-progress name reads as clean: a recursion through a cycle adds
|
|
1722
|
+
* no reach beyond the cycle's own direct tampers, which are found on
|
|
1723
|
+
* their own. Over the import budget reads as unknown (fail closed); a
|
|
1724
|
+
* file that cannot be modeled adds no reach — the same visibility the
|
|
1725
|
+
* graph traversal itself has.
|
|
1726
|
+
*/
|
|
1727
|
+
function exportedNameTamperReach(state, cwd, file, name, depth, active, ignoreEvaluate) {
|
|
1728
|
+
const key = `${ignoreEvaluate ? 'blocking' : 'any'}::${file}::${name}`;
|
|
1729
|
+
const cached = state.routeReachByExport.get(key);
|
|
1730
|
+
if (cached !== undefined)
|
|
1731
|
+
return cached;
|
|
1732
|
+
if (depth > state.maxImportDepth)
|
|
1733
|
+
return UNKNOWN_REACH;
|
|
1734
|
+
if (active.has(key))
|
|
1735
|
+
return CLEAN_REACH;
|
|
1736
|
+
active.add(key);
|
|
1737
|
+
const model = state.models.get(file) ?? modelOf(state, cwd, file, true);
|
|
1738
|
+
let verdict;
|
|
1739
|
+
if (model === null) {
|
|
1740
|
+
verdict = CLEAN_REACH;
|
|
1741
|
+
}
|
|
1742
|
+
else {
|
|
1743
|
+
const exported = model.exports.get(name);
|
|
1744
|
+
if (exported === undefined) {
|
|
1745
|
+
verdict = localNameTamperReach(state, cwd, model, name, depth, active, ignoreEvaluate);
|
|
1746
|
+
}
|
|
1747
|
+
else if ('packTest' in exported) {
|
|
1748
|
+
verdict = CLEAN_REACH;
|
|
1749
|
+
}
|
|
1750
|
+
else if ('targetFile' in exported) {
|
|
1751
|
+
verdict = exportedNameTamperReach(state, cwd, exported.targetFile, exported.importedName, depth + 1, active, ignoreEvaluate);
|
|
1752
|
+
}
|
|
1753
|
+
else {
|
|
1754
|
+
verdict = localNameTamperReach(state, cwd, model, exported.local, depth, active, ignoreEvaluate);
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
active.delete(key);
|
|
1758
|
+
state.routeReachByExport.set(key, verdict);
|
|
1759
|
+
return verdict;
|
|
1760
|
+
}
|
|
1761
|
+
/**
|
|
1762
|
+
* Whether a whole module can carry a tamper at all: its import-time
|
|
1763
|
+
* calls, every export it declares, and everything its own imports
|
|
1764
|
+
* point at. This is the summary an UNPROVABLE use of a namespace
|
|
1765
|
+
* import is judged against — `clean` only when nothing anywhere in the
|
|
1766
|
+
* module's reach can tamper; anything else falls back to the file-wide
|
|
1767
|
+
* flag.
|
|
1768
|
+
*/
|
|
1769
|
+
function namespaceModuleReach(state, cwd, file, depth, active, ignoreEvaluate) {
|
|
1770
|
+
const key = `${ignoreEvaluate ? 'blocking' : 'any'}::${file}::<namespace>`;
|
|
1771
|
+
const cached = state.routeReachByExport.get(key);
|
|
1772
|
+
if (cached !== undefined)
|
|
1773
|
+
return cached;
|
|
1774
|
+
if (depth > state.maxImportDepth)
|
|
1775
|
+
return UNKNOWN_REACH;
|
|
1776
|
+
if (active.has(key))
|
|
1777
|
+
return CLEAN_REACH;
|
|
1778
|
+
active.add(key);
|
|
1779
|
+
const verdict = (() => {
|
|
1780
|
+
const topLevel = topLevelTamperOf(state, cwd, file, ignoreEvaluate);
|
|
1781
|
+
if (topLevel !== null)
|
|
1782
|
+
return { kind: 'tamper', location: topLevel };
|
|
1783
|
+
const model = state.models.get(file) ?? modelOf(state, cwd, file, true);
|
|
1784
|
+
if (model === null)
|
|
1785
|
+
return CLEAN_REACH;
|
|
1786
|
+
for (const exportedName of model.exports.keys()) {
|
|
1787
|
+
const reach = exportedNameTamperReach(state, cwd, file, exportedName, depth + 1, active, ignoreEvaluate);
|
|
1788
|
+
if (reach.kind !== 'clean')
|
|
1789
|
+
return reach;
|
|
1790
|
+
}
|
|
1791
|
+
for (const binding of model.bindings.values()) {
|
|
1792
|
+
if (binding.kind !== 'import' || binding.target === undefined)
|
|
1793
|
+
continue;
|
|
1794
|
+
const reach = binding.importedName === '*'
|
|
1795
|
+
? namespaceModuleReach(state, cwd, binding.target, depth + 1, active, ignoreEvaluate)
|
|
1796
|
+
: exportedNameTamperReach(state, cwd, binding.target, binding.importedName ?? '', depth + 1, active, ignoreEvaluate);
|
|
1797
|
+
if (reach.kind !== 'clean')
|
|
1798
|
+
return reach;
|
|
1799
|
+
}
|
|
1800
|
+
return CLEAN_REACH;
|
|
1801
|
+
})();
|
|
1802
|
+
active.delete(key);
|
|
1803
|
+
state.routeReachByExport.set(key, verdict);
|
|
1804
|
+
return verdict;
|
|
1805
|
+
}
|
|
1806
|
+
/** Reach of one identifier reference: a local declaration, an import, or nothing. */
|
|
1807
|
+
function identifierReach(state, cwd, model, identifier, depth, active, called, ignoreEvaluate) {
|
|
1808
|
+
const text = identifier.text;
|
|
1809
|
+
const key = `${model.file}::${text}`;
|
|
1810
|
+
if (active.has(key))
|
|
1811
|
+
return CLEAN_REACH;
|
|
1812
|
+
const local = resolveLocalReferenceNode(text, identifier);
|
|
1813
|
+
if (local !== undefined) {
|
|
1814
|
+
active.add(key);
|
|
1815
|
+
const reach = referenceVerdict(nodeTamperReach(state, cwd, model, local, depth + 1, active, ignoreEvaluate), called);
|
|
1816
|
+
active.delete(key);
|
|
1817
|
+
return reach;
|
|
1818
|
+
}
|
|
1819
|
+
const binding = model.bindings.get(text);
|
|
1820
|
+
if (binding === undefined)
|
|
1821
|
+
return CLEAN_REACH;
|
|
1822
|
+
if (binding.kind === 'import' && binding.target !== undefined) {
|
|
1823
|
+
const reach = binding.importedName === '*'
|
|
1824
|
+
? namespaceModuleReach(state, cwd, binding.target, depth + 1, active, ignoreEvaluate)
|
|
1825
|
+
: exportedNameTamperReach(state, cwd, binding.target, binding.importedName ?? '', depth + 1, active, ignoreEvaluate);
|
|
1826
|
+
return referenceVerdict(reach, called);
|
|
1827
|
+
}
|
|
1828
|
+
return CLEAN_REACH;
|
|
1829
|
+
}
|
|
1830
|
+
/**
|
|
1831
|
+
* Tamper reach of one node subtree (a test body, a helper declaration):
|
|
1832
|
+
* the first tamper API call in the subtree, or the reach of any name it
|
|
1833
|
+
* references. A name referenced only as a VALUE (passed around,
|
|
1834
|
+
* stored) cannot be proven to run and reads as unknown; property
|
|
1835
|
+
* names, binding names, and parameters are never references.
|
|
1836
|
+
*/
|
|
1837
|
+
function nodeTamperReach(state, cwd, model, node, depth, active, ignoreEvaluate) {
|
|
1838
|
+
if (depth > state.maxImportDepth)
|
|
1839
|
+
return UNKNOWN_REACH;
|
|
1840
|
+
let verdict = CLEAN_REACH;
|
|
1841
|
+
// Whether this syntactic position IS the callee of its parent call —
|
|
1842
|
+
// the one position where a reference is proof the referenced code runs.
|
|
1843
|
+
const calledHere = (reference) => ts.isCallExpression(reference.parent) && reference.parent.expression === reference;
|
|
1844
|
+
const visit = (current) => {
|
|
1845
|
+
if (verdict.kind !== 'clean')
|
|
1846
|
+
return;
|
|
1847
|
+
if (ts.isIdentifier(current)) {
|
|
1848
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, current, depth, active, false, ignoreEvaluate), false);
|
|
1849
|
+
return;
|
|
1850
|
+
}
|
|
1851
|
+
if (ts.isCallExpression(current)) {
|
|
1852
|
+
const tamper = tamperApiLocation(model.source, model.file, current, ignoreEvaluate);
|
|
1853
|
+
if (tamper !== null) {
|
|
1854
|
+
verdict = { kind: 'tamper', location: tamper };
|
|
1855
|
+
return;
|
|
1856
|
+
}
|
|
1857
|
+
if (ts.isIdentifier(current.expression)) {
|
|
1858
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, current.expression, depth, active, true, ignoreEvaluate), true);
|
|
1859
|
+
}
|
|
1860
|
+
else {
|
|
1861
|
+
visit(current.expression);
|
|
1862
|
+
}
|
|
1863
|
+
if (verdict.kind !== 'clean')
|
|
1864
|
+
return;
|
|
1865
|
+
for (const argument of current.arguments) {
|
|
1866
|
+
visit(argument);
|
|
1867
|
+
if (verdict.kind !== 'clean')
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
return;
|
|
1871
|
+
}
|
|
1872
|
+
if (ts.isPropertyAccessExpression(current)) {
|
|
1873
|
+
const base = current.expression;
|
|
1874
|
+
const called = calledHere(current);
|
|
1875
|
+
if (ts.isIdentifier(base)) {
|
|
1876
|
+
const binding = model.bindings.get(base.text);
|
|
1877
|
+
if (binding !== undefined && binding.kind === 'import' && binding.target !== undefined && binding.importedName === '*') {
|
|
1878
|
+
verdict = referenceVerdict(exportedNameTamperReach(state, cwd, binding.target, current.name.text, depth + 1, active, ignoreEvaluate), called);
|
|
1879
|
+
return;
|
|
1880
|
+
}
|
|
1881
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, base, depth, active, called, ignoreEvaluate), called);
|
|
1882
|
+
return;
|
|
1883
|
+
}
|
|
1884
|
+
visit(base);
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
if (ts.isElementAccessExpression(current)) {
|
|
1888
|
+
const base = current.expression;
|
|
1889
|
+
const called = calledHere(current);
|
|
1890
|
+
if (ts.isIdentifier(base)) {
|
|
1891
|
+
const binding = model.bindings.get(base.text);
|
|
1892
|
+
if (binding !== undefined && binding.kind === 'import' && binding.target !== undefined && binding.importedName === '*') {
|
|
1893
|
+
if (ts.isStringLiteral(current.argumentExpression)) {
|
|
1894
|
+
verdict = referenceVerdict(exportedNameTamperReach(state, cwd, binding.target, current.argumentExpression.text, depth + 1, active, ignoreEvaluate), called);
|
|
1895
|
+
return;
|
|
1896
|
+
}
|
|
1897
|
+
verdict = UNKNOWN_REACH; // dynamic namespace access: cannot prove which export runs
|
|
1898
|
+
return;
|
|
1899
|
+
}
|
|
1900
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, base, depth, active, false, ignoreEvaluate), false);
|
|
1901
|
+
if (verdict.kind !== 'clean')
|
|
1902
|
+
return;
|
|
1903
|
+
visit(current.argumentExpression);
|
|
1904
|
+
return;
|
|
1905
|
+
}
|
|
1906
|
+
visit(base);
|
|
1907
|
+
if (verdict.kind !== 'clean')
|
|
1908
|
+
return;
|
|
1909
|
+
visit(current.argumentExpression);
|
|
1910
|
+
return;
|
|
1911
|
+
}
|
|
1912
|
+
if (ts.isSpreadElement(current)) {
|
|
1913
|
+
if (ts.isIdentifier(current.expression)) {
|
|
1914
|
+
const binding = model.bindings.get(current.expression.text);
|
|
1915
|
+
if (binding !== undefined && binding.kind === 'import' && binding.importedName === '*') {
|
|
1916
|
+
verdict = UNKNOWN_REACH; // spreading a namespace: cannot prove what runs
|
|
1917
|
+
return;
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
visit(current.expression);
|
|
1921
|
+
return;
|
|
1922
|
+
}
|
|
1923
|
+
if (ts.isVariableStatement(current)) {
|
|
1924
|
+
for (const declaration of current.declarationList.declarations) {
|
|
1925
|
+
if (declaration.initializer !== undefined) {
|
|
1926
|
+
visit(declaration.initializer);
|
|
1927
|
+
if (verdict.kind !== 'clean')
|
|
1928
|
+
return;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
return;
|
|
1932
|
+
}
|
|
1933
|
+
if (ts.isFunctionDeclaration(current) ||
|
|
1934
|
+
ts.isFunctionExpression(current) ||
|
|
1935
|
+
ts.isArrowFunction(current) ||
|
|
1936
|
+
ts.isMethodDeclaration(current)) {
|
|
1937
|
+
for (const parameter of current.parameters) {
|
|
1938
|
+
if (parameter.initializer !== undefined) {
|
|
1939
|
+
visit(parameter.initializer);
|
|
1940
|
+
if (verdict.kind !== 'clean')
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
if (current.body !== undefined)
|
|
1945
|
+
visit(current.body);
|
|
1946
|
+
return;
|
|
1947
|
+
}
|
|
1948
|
+
if (ts.isImportDeclaration(current) || ts.isExportDeclaration(current))
|
|
1949
|
+
return;
|
|
1950
|
+
ts.forEachChild(current, visit);
|
|
1951
|
+
};
|
|
1952
|
+
visit(node);
|
|
1953
|
+
return verdict;
|
|
1954
|
+
}
|
|
1955
|
+
/**
|
|
1956
|
+
* The tamper location attributed to ONE test (0.13.10 F3): a tamper
|
|
1957
|
+
* written in the spec, or one that executes at import time anywhere in
|
|
1958
|
+
* its import graph, flags every test of the file exactly as before;
|
|
1959
|
+
* otherwise the test's own body — and the fixture chain its
|
|
1960
|
+
* registration name resolves through — is followed, flagging the test
|
|
1961
|
+
* at the reached helper's tamper line. When reachability cannot be
|
|
1962
|
+
* proven, today's file-wide graph tamper is the flag; when the scan
|
|
1963
|
+
* proves the test never reaches any tamper, there is none.
|
|
1964
|
+
*/
|
|
1965
|
+
function attributedRouteInterception(state, cwd, model, base, callback, fileWideTamper, fallback, ignoreEvaluate) {
|
|
1966
|
+
if (fileWideTamper !== null)
|
|
1967
|
+
return fileWideTamper;
|
|
1968
|
+
const active = new Set();
|
|
1969
|
+
const registration = localNameTamperReach(state, cwd, model, base, 0, active, ignoreEvaluate);
|
|
1970
|
+
if (registration.kind === 'tamper')
|
|
1971
|
+
return registration.location;
|
|
1972
|
+
if (registration.kind === 'unknown')
|
|
1973
|
+
return fallback;
|
|
1974
|
+
if (callback === undefined)
|
|
1975
|
+
return fallback;
|
|
1976
|
+
const body = nodeTamperReach(state, cwd, model, callback, 0, active, ignoreEvaluate);
|
|
1977
|
+
if (body.kind === 'tamper')
|
|
1978
|
+
return body.location;
|
|
1979
|
+
if (body.kind === 'unknown')
|
|
1980
|
+
return fallback;
|
|
1981
|
+
return null;
|
|
1982
|
+
}
|
|
1095
1983
|
/**
|
|
1096
1984
|
* Runs the bounded static scan over the configured globs. Every value is
|
|
1097
1985
|
* derived from ASTs; the only I/O is reading candidate + import-target
|
|
@@ -1124,6 +2012,9 @@ export function scanTestFiles(options) {
|
|
|
1124
2012
|
maxTraversedFiles: options.budget?.maxTraversedFiles ?? DEFAULT_MAX_TRAVERSED_FILES,
|
|
1125
2013
|
maxImportDepth: options.budget?.maxImportDepth ?? DEFAULT_MAX_IMPORT_DEPTH,
|
|
1126
2014
|
testGlobals: options.testGlobals ?? (() => false),
|
|
2015
|
+
packageMetadata: new Map(),
|
|
2016
|
+
routeReachByExport: new Map(),
|
|
2017
|
+
routeTopLevelByFile: new Map(),
|
|
1127
2018
|
};
|
|
1128
2019
|
const seededFiles = collectCandidateFiles(options.cwd, options.include, options.exclude, options.excludeFile);
|
|
1129
2020
|
for (const file of seededFiles)
|
|
@@ -1134,9 +2025,10 @@ export function scanTestFiles(options) {
|
|
|
1134
2025
|
continue;
|
|
1135
2026
|
const fileHttpClient = findHttpClientCall(model.source, model.source, file);
|
|
1136
2027
|
const fileMock = findModuleMock(model.source, file);
|
|
1137
|
-
const fileRoute = findImportedRouteInterception(state, options.cwd, file);
|
|
1138
|
-
const
|
|
1139
|
-
|
|
2028
|
+
const fileRoute = findImportedRouteInterception(state, options.cwd, file, false);
|
|
2029
|
+
const fileRouteBlocking = findImportedRouteInterception(state, options.cwd, file, true);
|
|
2030
|
+
const gateforgeImport = findGateforgeFixtureImport(state, model.source, file);
|
|
2031
|
+
scanFileForTests(state, options.cwd, model, fileHttpClient, fileMock, fileRoute, fileRouteBlocking, gateforgeImport);
|
|
1140
2032
|
}
|
|
1141
2033
|
// The import graph of everything the scan modeled. Every module-scope
|
|
1142
2034
|
// relative import was resolved to a repo-relative path while modeling
|
|
@@ -1217,6 +2109,9 @@ export function namedPathGraph(cwd, roots, budget) {
|
|
|
1217
2109
|
maxTraversedFiles: budget?.maxTraversedFiles ?? DEFAULT_MAX_TRAVERSED_FILES,
|
|
1218
2110
|
maxImportDepth: budget?.maxImportDepth ?? DEFAULT_MAX_IMPORT_DEPTH,
|
|
1219
2111
|
testGlobals: () => false,
|
|
2112
|
+
packageMetadata: new Map(),
|
|
2113
|
+
routeReachByExport: new Map(),
|
|
2114
|
+
routeTopLevelByFile: new Map(),
|
|
1220
2115
|
};
|
|
1221
2116
|
const rootFiles = new Set(roots);
|
|
1222
2117
|
const reached = new Set();
|
|
@@ -1283,11 +2178,28 @@ function compareEntry(a, b) {
|
|
|
1283
2178
|
a.location.line - b.location.line);
|
|
1284
2179
|
}
|
|
1285
2180
|
/** Visits one modeled file, harvesting describe stacks and test calls. */
|
|
1286
|
-
function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute, gateforgeImport) {
|
|
2181
|
+
function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute, fileRouteBlocking, gateforgeImport) {
|
|
1287
2182
|
const { file, source } = model;
|
|
1288
2183
|
// Once per file, not once per call site: the runner-globals predicate
|
|
1289
2184
|
// matches globs, and a file has hundreds of call expressions.
|
|
1290
2185
|
const runnerGlobals = state.testGlobals(file);
|
|
2186
|
+
// 0.13.10 F3: a tamper written in this spec — or one that executes at
|
|
2187
|
+
// import time anywhere in its import graph — flags every test of the
|
|
2188
|
+
// file exactly as before. A tamper inside an imported HELPER is
|
|
2189
|
+
// attributed per test; when reachability cannot be proven, today's
|
|
2190
|
+
// file-wide graph tamper (`fileRoute`) stays the flag. 0.13.10 F7:
|
|
2191
|
+
// the blocking pass ignores the evaluate family — what a CHROMIUM
|
|
2192
|
+
// project may still refuse statically.
|
|
2193
|
+
const specDirectTamper = findRouteInterception(source, file, false);
|
|
2194
|
+
const specDirectBlocking = findRouteInterception(source, file, true);
|
|
2195
|
+
const importTimeTamper = specDirectTamper === null ? firstGraphTopLevelTamper(state, cwd, file, false) : null;
|
|
2196
|
+
const importTimeBlocking = specDirectBlocking === null ? firstGraphTopLevelTamper(state, cwd, file, true) : null;
|
|
2197
|
+
const fileWideTamper = specDirectTamper ?? importTimeTamper;
|
|
2198
|
+
const fileWideBlocking = specDirectBlocking ?? importTimeBlocking;
|
|
2199
|
+
const routeFor = (base, callback) => ({
|
|
2200
|
+
any: attributedRouteInterception(state, cwd, model, base, callback, fileWideTamper, fileRoute, false),
|
|
2201
|
+
blocking: attributedRouteInterception(state, cwd, model, base, callback, fileWideBlocking, fileRouteBlocking, true),
|
|
2202
|
+
});
|
|
1291
2203
|
const visit = (node, describeStack, enclosing) => {
|
|
1292
2204
|
if (!ts.isCallExpression(node)) {
|
|
1293
2205
|
ts.forEachChild(node, (child) => visit(child, describeStack, enclosing));
|
|
@@ -1418,12 +2330,29 @@ function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute
|
|
|
1418
2330
|
if (effectiveResolution === 'test' && !isExtend && !lifecycle && !isDescribe && titleArgument !== undefined && !eachCall) {
|
|
1419
2331
|
const title = titleOf(titleArgument);
|
|
1420
2332
|
if (title === null) {
|
|
2333
|
+
const callSite = buildEntry({
|
|
2334
|
+
file,
|
|
2335
|
+
source,
|
|
2336
|
+
node,
|
|
2337
|
+
callback,
|
|
2338
|
+
titlePath: [UNRESOLVED_TITLE_PLACEHOLDER],
|
|
2339
|
+
parameterized: false,
|
|
2340
|
+
inheritedSignals: describeStack.flatMap((scope) => scope.signals),
|
|
2341
|
+
suppression,
|
|
2342
|
+
location,
|
|
2343
|
+
fileHttpClient,
|
|
2344
|
+
fileMock,
|
|
2345
|
+
route: routeFor(chain.base, callback),
|
|
2346
|
+
gateforgeImport,
|
|
2347
|
+
});
|
|
1421
2348
|
state.result.unresolved.push({
|
|
1422
2349
|
code: 'dynamic-title',
|
|
1423
2350
|
detail: 'test title is computed and cannot be resolved statically',
|
|
1424
2351
|
file,
|
|
1425
2352
|
titlePath: [UNRESOLVED_TITLE_PLACEHOLDER],
|
|
1426
2353
|
location,
|
|
2354
|
+
facts: callSite.facts,
|
|
2355
|
+
signals: callSite.signals,
|
|
1427
2356
|
});
|
|
1428
2357
|
return;
|
|
1429
2358
|
}
|
|
@@ -1439,7 +2368,7 @@ function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute
|
|
|
1439
2368
|
location,
|
|
1440
2369
|
fileHttpClient,
|
|
1441
2370
|
fileMock,
|
|
1442
|
-
|
|
2371
|
+
route: routeFor(chain.base, callback),
|
|
1443
2372
|
gateforgeImport,
|
|
1444
2373
|
});
|
|
1445
2374
|
state.result.entries.push(entry);
|
|
@@ -1460,12 +2389,29 @@ function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute
|
|
|
1460
2389
|
const outerCallback = outer.arguments.find((argument) => ts.isArrowFunction(argument) || ts.isFunctionExpression(argument));
|
|
1461
2390
|
const outerLocation = locationOf(file, source, outer);
|
|
1462
2391
|
if (title === null) {
|
|
2392
|
+
const callSite = buildEntry({
|
|
2393
|
+
file,
|
|
2394
|
+
source,
|
|
2395
|
+
node: outer,
|
|
2396
|
+
callback: outerCallback,
|
|
2397
|
+
titlePath: [UNRESOLVED_TITLE_PLACEHOLDER],
|
|
2398
|
+
parameterized: 'each',
|
|
2399
|
+
inheritedSignals: describeStack.flatMap((scope) => scope.signals),
|
|
2400
|
+
suppression,
|
|
2401
|
+
location: outerLocation,
|
|
2402
|
+
fileHttpClient,
|
|
2403
|
+
fileMock,
|
|
2404
|
+
route: routeFor(chain.base, outerCallback),
|
|
2405
|
+
gateforgeImport,
|
|
2406
|
+
});
|
|
1463
2407
|
state.result.unresolved.push({
|
|
1464
2408
|
code: 'dynamic-title',
|
|
1465
2409
|
detail: 'parameterized test title is computed and cannot be resolved statically',
|
|
1466
2410
|
file,
|
|
1467
2411
|
titlePath: [UNRESOLVED_TITLE_PLACEHOLDER],
|
|
1468
2412
|
location: outerLocation,
|
|
2413
|
+
facts: callSite.facts,
|
|
2414
|
+
signals: callSite.signals,
|
|
1469
2415
|
});
|
|
1470
2416
|
return;
|
|
1471
2417
|
}
|
|
@@ -1481,7 +2427,7 @@ function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute
|
|
|
1481
2427
|
location: outerLocation,
|
|
1482
2428
|
fileHttpClient,
|
|
1483
2429
|
fileMock,
|
|
1484
|
-
|
|
2430
|
+
route: routeFor(chain.base, outerCallback),
|
|
1485
2431
|
gateforgeImport,
|
|
1486
2432
|
});
|
|
1487
2433
|
state.result.entries.push(entry);
|
|
@@ -1783,7 +2729,8 @@ function buildEntry(input) {
|
|
|
1783
2729
|
httpClientCall,
|
|
1784
2730
|
fileHttpClientCall: input.fileHttpClient,
|
|
1785
2731
|
fileMockImport: input.fileMock,
|
|
1786
|
-
fileRouteInterception: input.
|
|
2732
|
+
fileRouteInterception: input.route.any,
|
|
2733
|
+
fileRouteInterceptionNonEvaluate: input.route.blocking,
|
|
1787
2734
|
gateforgeFixtureImport: input.gateforgeImport,
|
|
1788
2735
|
},
|
|
1789
2736
|
...(annotations.claims.length > 0 ? { annotationClaims: annotations.claims } : {}),
|