@gate-forge/pack-playwright 0.13.9 → 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 +16 -0
- package/dist/discovery/discover.js.map +1 -1
- package/dist/discovery/inference.d.ts.map +1 -1
- package/dist/discovery/inference.js +35 -7
- package/dist/discovery/inference.js.map +1 -1
- package/dist/discovery/static-discovery.d.ts +6 -1
- package/dist/discovery/static-discovery.d.ts.map +1 -1
- package/dist/discovery/static-discovery.js +255 -39
- package/dist/discovery/static-discovery.js.map +1 -1
- package/package.json +3 -3
|
@@ -1033,7 +1033,16 @@ function signatureParamsOf(callback) {
|
|
|
1033
1033
|
* real browser journey.
|
|
1034
1034
|
*/
|
|
1035
1035
|
export const BROWSER_FIXTURE_PARAMS = new Set(['page', 'browser', 'context', 'browserName', 'evidence']);
|
|
1036
|
-
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
|
+
};
|
|
1037
1046
|
/** Whether the subtree contains `<x>.route(` — playwright interception. */
|
|
1038
1047
|
function findPageRoute(node, source, file) {
|
|
1039
1048
|
let found = null;
|
|
@@ -1080,17 +1089,31 @@ function pageRouteTargets(node) {
|
|
|
1080
1089
|
visit(node);
|
|
1081
1090
|
return [...targets].sort();
|
|
1082
1091
|
}
|
|
1083
|
-
/**
|
|
1084
|
-
|
|
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) {
|
|
1085
1098
|
let found = null;
|
|
1086
1099
|
const visit = (current) => {
|
|
1087
1100
|
if (found !== null)
|
|
1088
1101
|
return;
|
|
1089
1102
|
if (ts.isCallExpression(current)) {
|
|
1090
1103
|
const chain = calleeChain(current.expression);
|
|
1091
|
-
if (chain !== null
|
|
1092
|
-
|
|
1093
|
-
|
|
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
|
+
}
|
|
1094
1117
|
}
|
|
1095
1118
|
}
|
|
1096
1119
|
ts.forEachChild(current, visit);
|
|
@@ -1098,6 +1121,28 @@ function findHttpClientCall(node, source, file) {
|
|
|
1098
1121
|
visit(node);
|
|
1099
1122
|
return found;
|
|
1100
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
|
+
}
|
|
1101
1146
|
/** Whether the file imports the gateforge evidence pack (fixture tests). */
|
|
1102
1147
|
function findGateforgeFixtureImport(state, source, file) {
|
|
1103
1148
|
let found = null;
|
|
@@ -1683,10 +1728,10 @@ function firstGraphTopLevelTamper(state, cwd, root, ignoreEvaluate) {
|
|
|
1683
1728
|
return visit(root, 0);
|
|
1684
1729
|
}
|
|
1685
1730
|
/** 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) {
|
|
1731
|
+
function localNameTamperReach(state, cwd, model, name, depth, active, ignoreEvaluate, httpClientRoot = null) {
|
|
1687
1732
|
const declaration = routeDeclsOf(model).get(name);
|
|
1688
1733
|
if (declaration !== undefined) {
|
|
1689
|
-
return nodeTamperReach(state, cwd, model, declaration, depth + 1, active, ignoreEvaluate);
|
|
1734
|
+
return nodeTamperReach(state, cwd, model, declaration, depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1690
1735
|
}
|
|
1691
1736
|
const binding = model.bindings.get(name);
|
|
1692
1737
|
if (binding === undefined)
|
|
@@ -1695,15 +1740,17 @@ function localNameTamperReach(state, cwd, model, name, depth, active, ignoreEval
|
|
|
1695
1740
|
case 'import': {
|
|
1696
1741
|
if (binding.target === undefined)
|
|
1697
1742
|
return CLEAN_REACH;
|
|
1743
|
+
if (httpClientRoot !== null && !isTestInfrastructureFile(binding.target))
|
|
1744
|
+
return CLEAN_REACH;
|
|
1698
1745
|
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);
|
|
1746
|
+
? namespaceModuleReach(state, cwd, binding.target, depth + 1, active, ignoreEvaluate, httpClientRoot)
|
|
1747
|
+
: exportedNameTamperReach(state, cwd, binding.target, binding.importedName ?? '', depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1701
1748
|
}
|
|
1702
1749
|
case 'alias': {
|
|
1703
1750
|
const aliased = binding.target === undefined ? undefined : routeDeclsOf(model).get(binding.target);
|
|
1704
1751
|
return aliased === undefined
|
|
1705
1752
|
? CLEAN_REACH
|
|
1706
|
-
: nodeTamperReach(state, cwd, model, aliased, depth + 1, active, ignoreEvaluate);
|
|
1753
|
+
: nodeTamperReach(state, cwd, model, aliased, depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1707
1754
|
}
|
|
1708
1755
|
case 'test':
|
|
1709
1756
|
case 'testmodule':
|
|
@@ -1724,8 +1771,10 @@ function localNameTamperReach(state, cwd, model, name, depth, active, ignoreEval
|
|
|
1724
1771
|
* file that cannot be modeled adds no reach — the same visibility the
|
|
1725
1772
|
* graph traversal itself has.
|
|
1726
1773
|
*/
|
|
1727
|
-
function exportedNameTamperReach(state, cwd, file, name, depth, active, ignoreEvaluate) {
|
|
1728
|
-
|
|
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}`;
|
|
1729
1778
|
const cached = state.routeReachByExport.get(key);
|
|
1730
1779
|
if (cached !== undefined)
|
|
1731
1780
|
return cached;
|
|
@@ -1742,16 +1791,16 @@ function exportedNameTamperReach(state, cwd, file, name, depth, active, ignoreEv
|
|
|
1742
1791
|
else {
|
|
1743
1792
|
const exported = model.exports.get(name);
|
|
1744
1793
|
if (exported === undefined) {
|
|
1745
|
-
verdict = localNameTamperReach(state, cwd, model, name, depth, active, ignoreEvaluate);
|
|
1794
|
+
verdict = localNameTamperReach(state, cwd, model, name, depth, active, ignoreEvaluate, httpClientRoot);
|
|
1746
1795
|
}
|
|
1747
1796
|
else if ('packTest' in exported) {
|
|
1748
1797
|
verdict = CLEAN_REACH;
|
|
1749
1798
|
}
|
|
1750
1799
|
else if ('targetFile' in exported) {
|
|
1751
|
-
verdict = exportedNameTamperReach(state, cwd, exported.targetFile, exported.importedName, depth + 1, active, ignoreEvaluate);
|
|
1800
|
+
verdict = exportedNameTamperReach(state, cwd, exported.targetFile, exported.importedName, depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1752
1801
|
}
|
|
1753
1802
|
else {
|
|
1754
|
-
verdict = localNameTamperReach(state, cwd, model, exported.local, depth, active, ignoreEvaluate);
|
|
1803
|
+
verdict = localNameTamperReach(state, cwd, model, exported.local, depth, active, ignoreEvaluate, httpClientRoot);
|
|
1755
1804
|
}
|
|
1756
1805
|
}
|
|
1757
1806
|
active.delete(key);
|
|
@@ -1766,8 +1815,10 @@ function exportedNameTamperReach(state, cwd, file, name, depth, active, ignoreEv
|
|
|
1766
1815
|
* module's reach can tamper; anything else falls back to the file-wide
|
|
1767
1816
|
* flag.
|
|
1768
1817
|
*/
|
|
1769
|
-
function namespaceModuleReach(state, cwd, file, depth, active, ignoreEvaluate) {
|
|
1770
|
-
|
|
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>`;
|
|
1771
1822
|
const cached = state.routeReachByExport.get(key);
|
|
1772
1823
|
if (cached !== undefined)
|
|
1773
1824
|
return cached;
|
|
@@ -1777,23 +1828,27 @@ function namespaceModuleReach(state, cwd, file, depth, active, ignoreEvaluate) {
|
|
|
1777
1828
|
return CLEAN_REACH;
|
|
1778
1829
|
active.add(key);
|
|
1779
1830
|
const verdict = (() => {
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1831
|
+
if (httpClientRoot === null) {
|
|
1832
|
+
const topLevel = topLevelTamperOf(state, cwd, file, ignoreEvaluate);
|
|
1833
|
+
if (topLevel !== null)
|
|
1834
|
+
return { kind: 'tamper', location: topLevel };
|
|
1835
|
+
}
|
|
1783
1836
|
const model = state.models.get(file) ?? modelOf(state, cwd, file, true);
|
|
1784
1837
|
if (model === null)
|
|
1785
1838
|
return CLEAN_REACH;
|
|
1786
1839
|
for (const exportedName of model.exports.keys()) {
|
|
1787
|
-
const reach = exportedNameTamperReach(state, cwd, file, exportedName, depth + 1, active, ignoreEvaluate);
|
|
1840
|
+
const reach = exportedNameTamperReach(state, cwd, file, exportedName, depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1788
1841
|
if (reach.kind !== 'clean')
|
|
1789
1842
|
return reach;
|
|
1790
1843
|
}
|
|
1791
1844
|
for (const binding of model.bindings.values()) {
|
|
1792
1845
|
if (binding.kind !== 'import' || binding.target === undefined)
|
|
1793
1846
|
continue;
|
|
1847
|
+
if (httpClientRoot !== null && !isTestInfrastructureFile(binding.target))
|
|
1848
|
+
continue;
|
|
1794
1849
|
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);
|
|
1850
|
+
? namespaceModuleReach(state, cwd, binding.target, depth + 1, active, ignoreEvaluate, httpClientRoot)
|
|
1851
|
+
: exportedNameTamperReach(state, cwd, binding.target, binding.importedName ?? '', depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1797
1852
|
if (reach.kind !== 'clean')
|
|
1798
1853
|
return reach;
|
|
1799
1854
|
}
|
|
@@ -1804,7 +1859,7 @@ function namespaceModuleReach(state, cwd, file, depth, active, ignoreEvaluate) {
|
|
|
1804
1859
|
return verdict;
|
|
1805
1860
|
}
|
|
1806
1861
|
/** Reach of one identifier reference: a local declaration, an import, or nothing. */
|
|
1807
|
-
function identifierReach(state, cwd, model, identifier, depth, active, called, ignoreEvaluate) {
|
|
1862
|
+
function identifierReach(state, cwd, model, identifier, depth, active, called, ignoreEvaluate, httpClientRoot = null) {
|
|
1808
1863
|
const text = identifier.text;
|
|
1809
1864
|
const key = `${model.file}::${text}`;
|
|
1810
1865
|
if (active.has(key))
|
|
@@ -1812,7 +1867,7 @@ function identifierReach(state, cwd, model, identifier, depth, active, called, i
|
|
|
1812
1867
|
const local = resolveLocalReferenceNode(text, identifier);
|
|
1813
1868
|
if (local !== undefined) {
|
|
1814
1869
|
active.add(key);
|
|
1815
|
-
const reach = referenceVerdict(nodeTamperReach(state, cwd, model, local, depth + 1, active, ignoreEvaluate), called);
|
|
1870
|
+
const reach = referenceVerdict(nodeTamperReach(state, cwd, model, local, depth + 1, active, ignoreEvaluate, httpClientRoot), called);
|
|
1816
1871
|
active.delete(key);
|
|
1817
1872
|
return reach;
|
|
1818
1873
|
}
|
|
@@ -1821,8 +1876,8 @@ function identifierReach(state, cwd, model, identifier, depth, active, called, i
|
|
|
1821
1876
|
return CLEAN_REACH;
|
|
1822
1877
|
if (binding.kind === 'import' && binding.target !== undefined) {
|
|
1823
1878
|
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);
|
|
1879
|
+
? namespaceModuleReach(state, cwd, binding.target, depth + 1, active, ignoreEvaluate, httpClientRoot)
|
|
1880
|
+
: exportedNameTamperReach(state, cwd, binding.target, binding.importedName ?? '', depth + 1, active, ignoreEvaluate, httpClientRoot);
|
|
1826
1881
|
return referenceVerdict(reach, called);
|
|
1827
1882
|
}
|
|
1828
1883
|
return CLEAN_REACH;
|
|
@@ -1834,7 +1889,7 @@ function identifierReach(state, cwd, model, identifier, depth, active, called, i
|
|
|
1834
1889
|
* stored) cannot be proven to run and reads as unknown; property
|
|
1835
1890
|
* names, binding names, and parameters are never references.
|
|
1836
1891
|
*/
|
|
1837
|
-
function nodeTamperReach(state, cwd, model, node, depth, active, ignoreEvaluate) {
|
|
1892
|
+
function nodeTamperReach(state, cwd, model, node, depth, active, ignoreEvaluate, httpClientRoot = null) {
|
|
1838
1893
|
if (depth > state.maxImportDepth)
|
|
1839
1894
|
return UNKNOWN_REACH;
|
|
1840
1895
|
let verdict = CLEAN_REACH;
|
|
@@ -1845,17 +1900,19 @@ function nodeTamperReach(state, cwd, model, node, depth, active, ignoreEvaluate)
|
|
|
1845
1900
|
if (verdict.kind !== 'clean')
|
|
1846
1901
|
return;
|
|
1847
1902
|
if (ts.isIdentifier(current)) {
|
|
1848
|
-
verdict = referenceVerdict(identifierReach(state, cwd, model, current, depth, active, false, ignoreEvaluate), false);
|
|
1903
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, current, depth, active, false, ignoreEvaluate, httpClientRoot), false);
|
|
1849
1904
|
return;
|
|
1850
1905
|
}
|
|
1851
1906
|
if (ts.isCallExpression(current)) {
|
|
1852
|
-
const tamper =
|
|
1907
|
+
const tamper = httpClientRoot !== null
|
|
1908
|
+
? findHttpClientCall(current, model.source, model.file, true, model.file === httpClientRoot)
|
|
1909
|
+
: tamperApiLocation(model.source, model.file, current, ignoreEvaluate);
|
|
1853
1910
|
if (tamper !== null) {
|
|
1854
1911
|
verdict = { kind: 'tamper', location: tamper };
|
|
1855
1912
|
return;
|
|
1856
1913
|
}
|
|
1857
1914
|
if (ts.isIdentifier(current.expression)) {
|
|
1858
|
-
verdict = referenceVerdict(identifierReach(state, cwd, model, current.expression, depth, active, true, ignoreEvaluate), true);
|
|
1915
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, current.expression, depth, active, true, ignoreEvaluate, httpClientRoot), true);
|
|
1859
1916
|
}
|
|
1860
1917
|
else {
|
|
1861
1918
|
visit(current.expression);
|
|
@@ -1875,10 +1932,10 @@ function nodeTamperReach(state, cwd, model, node, depth, active, ignoreEvaluate)
|
|
|
1875
1932
|
if (ts.isIdentifier(base)) {
|
|
1876
1933
|
const binding = model.bindings.get(base.text);
|
|
1877
1934
|
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);
|
|
1935
|
+
verdict = referenceVerdict(exportedNameTamperReach(state, cwd, binding.target, current.name.text, depth + 1, active, ignoreEvaluate, httpClientRoot), called);
|
|
1879
1936
|
return;
|
|
1880
1937
|
}
|
|
1881
|
-
verdict = referenceVerdict(identifierReach(state, cwd, model, base, depth, active, called, ignoreEvaluate), called);
|
|
1938
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, base, depth, active, called, ignoreEvaluate, httpClientRoot), called);
|
|
1882
1939
|
return;
|
|
1883
1940
|
}
|
|
1884
1941
|
visit(base);
|
|
@@ -1891,13 +1948,13 @@ function nodeTamperReach(state, cwd, model, node, depth, active, ignoreEvaluate)
|
|
|
1891
1948
|
const binding = model.bindings.get(base.text);
|
|
1892
1949
|
if (binding !== undefined && binding.kind === 'import' && binding.target !== undefined && binding.importedName === '*') {
|
|
1893
1950
|
if (ts.isStringLiteral(current.argumentExpression)) {
|
|
1894
|
-
verdict = referenceVerdict(exportedNameTamperReach(state, cwd, binding.target, current.argumentExpression.text, depth + 1, active, ignoreEvaluate), called);
|
|
1951
|
+
verdict = referenceVerdict(exportedNameTamperReach(state, cwd, binding.target, current.argumentExpression.text, depth + 1, active, ignoreEvaluate, httpClientRoot), called);
|
|
1895
1952
|
return;
|
|
1896
1953
|
}
|
|
1897
1954
|
verdict = UNKNOWN_REACH; // dynamic namespace access: cannot prove which export runs
|
|
1898
1955
|
return;
|
|
1899
1956
|
}
|
|
1900
|
-
verdict = referenceVerdict(identifierReach(state, cwd, model, base, depth, active, false, ignoreEvaluate), false);
|
|
1957
|
+
verdict = referenceVerdict(identifierReach(state, cwd, model, base, depth, active, false, ignoreEvaluate, httpClientRoot), false);
|
|
1901
1958
|
if (verdict.kind !== 'clean')
|
|
1902
1959
|
return;
|
|
1903
1960
|
visit(current.argumentExpression);
|
|
@@ -1980,6 +2037,158 @@ function attributedRouteInterception(state, cwd, model, base, callback, fileWide
|
|
|
1980
2037
|
return fallback;
|
|
1981
2038
|
return null;
|
|
1982
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
|
+
}
|
|
1983
2192
|
/**
|
|
1984
2193
|
* Runs the bounded static scan over the configured globs. Every value is
|
|
1985
2194
|
* derived from ASTs; the only I/O is reading candidate + import-target
|
|
@@ -2015,6 +2224,7 @@ export function scanTestFiles(options) {
|
|
|
2015
2224
|
packageMetadata: new Map(),
|
|
2016
2225
|
routeReachByExport: new Map(),
|
|
2017
2226
|
routeTopLevelByFile: new Map(),
|
|
2227
|
+
fixtureClassesByFile: new Map(),
|
|
2018
2228
|
};
|
|
2019
2229
|
const seededFiles = collectCandidateFiles(options.cwd, options.include, options.exclude, options.excludeFile);
|
|
2020
2230
|
for (const file of seededFiles)
|
|
@@ -2023,13 +2233,16 @@ export function scanTestFiles(options) {
|
|
|
2023
2233
|
const model = modelOf(state, options.cwd, file, false);
|
|
2024
2234
|
if (model === null)
|
|
2025
2235
|
continue;
|
|
2026
|
-
const fileHttpClient = findHttpClientCall(model.source, model.source, file);
|
|
2236
|
+
const fileHttpClient = findHttpClientCall(model.source, model.source, file, false);
|
|
2027
2237
|
const fileMock = findModuleMock(model.source, file);
|
|
2028
2238
|
const fileRoute = findImportedRouteInterception(state, options.cwd, file, false);
|
|
2029
2239
|
const fileRouteBlocking = findImportedRouteInterception(state, options.cwd, file, true);
|
|
2030
2240
|
const gateforgeImport = findGateforgeFixtureImport(state, model.source, file);
|
|
2031
2241
|
scanFileForTests(state, options.cwd, model, fileHttpClient, fileMock, fileRoute, fileRouteBlocking, gateforgeImport);
|
|
2032
2242
|
}
|
|
2243
|
+
for (const entry of state.result.entries) {
|
|
2244
|
+
entry.facts.fixtureClasses = fixtureClasses(state, entry.file);
|
|
2245
|
+
}
|
|
2033
2246
|
// The import graph of everything the scan modeled. Every module-scope
|
|
2034
2247
|
// relative import was resolved to a repo-relative path while modeling
|
|
2035
2248
|
// (a broken one became its own `unresolved-import` row, never a
|
|
@@ -2112,6 +2325,7 @@ export function namedPathGraph(cwd, roots, budget) {
|
|
|
2112
2325
|
packageMetadata: new Map(),
|
|
2113
2326
|
routeReachByExport: new Map(),
|
|
2114
2327
|
routeTopLevelByFile: new Map(),
|
|
2328
|
+
fixtureClassesByFile: new Map(),
|
|
2115
2329
|
};
|
|
2116
2330
|
const rootFiles = new Set(roots);
|
|
2117
2331
|
const reached = new Set();
|
|
@@ -2183,6 +2397,8 @@ function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute
|
|
|
2183
2397
|
// Once per file, not once per call site: the runner-globals predicate
|
|
2184
2398
|
// matches globs, and a file has hundreds of call expressions.
|
|
2185
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;
|
|
2186
2402
|
// 0.13.10 F3: a tamper written in this spec — or one that executes at
|
|
2187
2403
|
// import time anywhere in its import graph — flags every test of the
|
|
2188
2404
|
// file exactly as before. A tamper inside an imported HELPER is
|
|
@@ -2199,6 +2415,7 @@ function scanFileForTests(state, cwd, model, fileHttpClient, fileMock, fileRoute
|
|
|
2199
2415
|
const routeFor = (base, callback) => ({
|
|
2200
2416
|
any: attributedRouteInterception(state, cwd, model, base, callback, fileWideTamper, fileRoute, false),
|
|
2201
2417
|
blocking: attributedRouteInterception(state, cwd, model, base, callback, fileWideBlocking, fileRouteBlocking, true),
|
|
2418
|
+
httpClientCall: attributedHttpClientCall(state, cwd, model, base, callback, httpClientFallback),
|
|
2202
2419
|
});
|
|
2203
2420
|
const visit = (node, describeStack, enclosing) => {
|
|
2204
2421
|
if (!ts.isCallExpression(node)) {
|
|
@@ -2709,11 +2926,10 @@ function buildEntry(input) {
|
|
|
2709
2926
|
signals.push({ kind: kind, detail: `test.${kind} modifier`, location });
|
|
2710
2927
|
}
|
|
2711
2928
|
let pageRoute = null;
|
|
2712
|
-
|
|
2929
|
+
const httpClientCall = input.route.httpClientCall;
|
|
2713
2930
|
const interceptedTargets = callback === undefined ? [] : pageRouteTargets(callback);
|
|
2714
2931
|
if (callback !== undefined) {
|
|
2715
2932
|
pageRoute = findPageRoute(callback, source, file);
|
|
2716
|
-
httpClientCall = findHttpClientCall(callback, source, file);
|
|
2717
2933
|
}
|
|
2718
2934
|
return {
|
|
2719
2935
|
file,
|