@gate-forge/pack-playwright 0.13.8 → 0.13.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/discovery/discover.d.ts.map +1 -1
- package/dist/discovery/discover.js +157 -39
- package/dist/discovery/discover.js.map +1 -1
- package/dist/discovery/inference.d.ts.map +1 -1
- package/dist/discovery/inference.js +35 -14
- package/dist/discovery/inference.js.map +1 -1
- package/dist/discovery/reconcile.d.ts +8 -0
- package/dist/discovery/reconcile.d.ts.map +1 -1
- package/dist/discovery/reconcile.js +11 -0
- package/dist/discovery/reconcile.js.map +1 -1
- package/dist/discovery/static-discovery.d.ts +40 -17
- package/dist/discovery/static-discovery.d.ts.map +1 -1
- package/dist/discovery/static-discovery.js +1250 -87
- package/dist/discovery/static-discovery.js.map +1 -1
- package/dist/fixture/api-request.d.ts +15 -102
- package/dist/fixture/api-request.d.ts.map +1 -1
- package/dist/fixture/api-request.js +27 -101
- package/dist/fixture/api-request.js.map +1 -1
- package/dist/fixture/fixture.d.ts +16 -25
- package/dist/fixture/fixture.d.ts.map +1 -1
- package/dist/fixture/fixture.js +184 -66
- package/dist/fixture/fixture.js.map +1 -1
- package/dist/reporter/project-graph-reporter.d.ts +11 -1
- package/dist/reporter/project-graph-reporter.d.ts.map +1 -1
- package/dist/reporter/project-graph-reporter.js +16 -0
- package/dist/reporter/project-graph-reporter.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,114 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
* Validates the origin pair exactly like the page channel's own rule:
|
|
3
|
-
* both must be plain http and share the same (loopback) host — the swap
|
|
4
|
-
* is a port swap, never a host change.
|
|
5
|
-
*
|
|
6
|
-
* Args:
|
|
7
|
-
* appBaseURL: the configured app origin (GATEFORGE_APP_BASE_URL).
|
|
8
|
-
* sessionProxyURL: the supervisor-issued session proxy origin.
|
|
9
|
-
*
|
|
10
|
-
* Returns:
|
|
11
|
-
* SessionApiRouting: the parsed, validated pair.
|
|
12
|
-
*/
|
|
13
|
-
export function sessionApiRouting(appBaseURL, sessionProxyURL) {
|
|
14
|
-
const appOrigin = new URL(appBaseURL);
|
|
15
|
-
const sessionOrigin = new URL(sessionProxyURL);
|
|
16
|
-
if (appOrigin.protocol !== 'http:' ||
|
|
17
|
-
sessionOrigin.protocol !== appOrigin.protocol ||
|
|
18
|
-
sessionOrigin.hostname !== appOrigin.hostname) {
|
|
19
|
-
throw new Error('Gateforge session proxy and app base must share the same loopback HTTP host');
|
|
20
|
-
}
|
|
21
|
-
return { appOrigin: appOrigin.origin, sessionOrigin: sessionOrigin.origin };
|
|
22
|
-
}
|
|
23
|
-
/** Loopback in the three forms a browser URL can carry it. */
|
|
24
|
-
export function isLoopbackHostname(hostname) {
|
|
1
|
+
function isLoopbackHostname(hostname) {
|
|
25
2
|
return hostname === 'localhost' || hostname === '::1' || hostname === '[::1]' || /^127\./.test(hostname);
|
|
26
3
|
}
|
|
27
4
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* Non-app URLs come back RAW so the underlying context's own base URL
|
|
31
|
-
* semantics keep applying to relative foreign paths.
|
|
32
|
-
*
|
|
33
|
-
* Args:
|
|
34
|
-
* rawUrl: the URL exactly as the test passed it.
|
|
35
|
-
* baseURL: the context's base URL (project `use.baseURL`), if known.
|
|
36
|
-
* routing: the validated session routing.
|
|
37
|
-
*
|
|
38
|
-
* Returns:
|
|
39
|
-
* ApiRewrite: the URL to send, the routing verdict, and any mismatch.
|
|
40
|
-
*/
|
|
41
|
-
export function rewriteApiUrl(rawUrl, baseURL, routing) {
|
|
42
|
-
if (routing.appOrigin === routing.sessionOrigin) {
|
|
43
|
-
return { url: rawUrl, routed: false, mismatchedOrigin: null };
|
|
44
|
-
}
|
|
45
|
-
const resolved = new URL(rawUrl, baseURL ?? routing.appOrigin);
|
|
46
|
-
if (resolved.origin === routing.appOrigin) {
|
|
47
|
-
const rehosted = new URL(resolved.href);
|
|
48
|
-
rehosted.host = new URL(routing.sessionOrigin).host;
|
|
49
|
-
return { url: rehosted.href, routed: true, mismatchedOrigin: null };
|
|
50
|
-
}
|
|
51
|
-
const mismatched = resolved.hostname === new URL(routing.appOrigin).hostname || isLoopbackHostname(resolved.hostname)
|
|
52
|
-
? resolved.origin
|
|
53
|
-
: null;
|
|
54
|
-
return { url: rawUrl, routed: false, mismatchedOrigin: mismatched };
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Wraps an APIRequestContext so app-origin calls ride the session proxy.
|
|
58
|
-
* All arguments are passed through untouched; only the URL can change.
|
|
59
|
-
*
|
|
60
|
-
* Args:
|
|
61
|
-
* underlying: the real context (the built-in `request` fixture, the
|
|
62
|
-
* page context's request, or a fresh `request.newContext()`).
|
|
63
|
-
* options: base URL for relative resolution, the routing source, and
|
|
64
|
-
* the optional unrouted-origin reporter.
|
|
65
|
-
*
|
|
66
|
-
* Returns:
|
|
67
|
-
* APIRequestContext: the explicitly wrapped context.
|
|
5
|
+
* Reports direct app-origin API calls made by test contexts. Reporting is
|
|
6
|
+
* best-effort and cannot change the underlying response.
|
|
68
7
|
*/
|
|
69
|
-
export function
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
options.
|
|
8
|
+
export function wrapDirectRequestContext(underlying, options) {
|
|
9
|
+
const invoke = async (method, target, call) => {
|
|
10
|
+
const response = await call();
|
|
11
|
+
try {
|
|
12
|
+
const resolved = options.baseURL === undefined ? new URL(target) : new URL(target, options.baseURL);
|
|
13
|
+
const appOrigin = options.baseURL === undefined ? null : new URL(options.baseURL).origin;
|
|
14
|
+
if ((resolved.protocol === 'http:' || resolved.protocol === 'https:') &&
|
|
15
|
+
(appOrigin === null ? isLoopbackHostname(resolved.hostname) : resolved.origin === appOrigin)) {
|
|
16
|
+
options.onExchange({ method, url: resolved.href, status: response.status() });
|
|
78
17
|
}
|
|
79
|
-
return call(target, verbOptions);
|
|
80
18
|
}
|
|
81
|
-
|
|
19
|
+
catch {
|
|
20
|
+
// A URL that cannot be resolved is not useful for diagnosis.
|
|
21
|
+
}
|
|
22
|
+
return response;
|
|
82
23
|
};
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
24
|
+
const wrapped = {
|
|
25
|
+
fetch: (url, verbOptions) => typeof url === 'string'
|
|
26
|
+
? invoke('GET', url, () => underlying.fetch(url, verbOptions))
|
|
27
|
+
: underlying.fetch(url, verbOptions),
|
|
28
|
+
get: (url, verbOptions) => invoke('GET', url, () => underlying.get(url, verbOptions)),
|
|
29
|
+
post: (url, verbOptions) => invoke('POST', url, () => underlying.post(url, verbOptions)),
|
|
30
|
+
put: (url, verbOptions) => invoke('PUT', url, () => underlying.put(url, verbOptions)),
|
|
31
|
+
patch: (url, verbOptions) => invoke('PATCH', url, () => underlying.patch(url, verbOptions)),
|
|
32
|
+
delete: (url, verbOptions) => invoke('DELETE', url, () => underlying.delete(url, verbOptions)),
|
|
33
|
+
head: (url, verbOptions) => invoke('HEAD', url, () => underlying.head(url, verbOptions)),
|
|
92
34
|
dispose: (verbOptions) => underlying.dispose(verbOptions),
|
|
93
35
|
storageState: (verbOptions) => underlying.storageState(verbOptions),
|
|
94
36
|
[Symbol.asyncDispose]: () => underlying.dispose(),
|
|
95
37
|
};
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Rehosts the owned APIRequestContext of a witnessed page's context
|
|
99
|
-
* (`page.request` and `context.request` are the SAME lazily-created
|
|
100
|
-
* object; shadowing it on the context instance covers both access
|
|
101
|
-
* paths). The underlying context is materialized first and delegated to.
|
|
102
|
-
*
|
|
103
|
-
* Args:
|
|
104
|
-
* context: the browser context of the witnessed page.
|
|
105
|
-
* options: the same arguments {@link wrapApiRequestContext} takes.
|
|
106
|
-
*
|
|
107
|
-
* Returns:
|
|
108
|
-
* void.
|
|
109
|
-
*/
|
|
110
|
-
export function rehostContextRequest(context, options) {
|
|
111
|
-
const wrapped = wrapApiRequestContext(context.request, options);
|
|
112
|
-
Object.defineProperty(context, 'request', { value: wrapped, configurable: true });
|
|
38
|
+
return wrapped;
|
|
113
39
|
}
|
|
114
40
|
//# sourceMappingURL=api-request.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-request.js","sourceRoot":"","sources":["../../src/fixture/api-request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api-request.js","sourceRoot":"","sources":["../../src/fixture/api-request.ts"],"names":[],"mappings":"AAWA,SAAS,kBAAkB,CAAC,QAAgB;IAC1C,OAAO,QAAQ,KAAK,WAAW,IAAI,QAAQ,KAAK,KAAK,IAAI,QAAQ,KAAK,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAC3G,CAAC;AAcD;;;GAGG;AACH,MAAM,UAAU,wBAAwB,CACtC,UAA6B,EAC7B,OAAwC;IAExC,MAAM,MAAM,GAAG,KAAK,EAClB,MAAc,EACd,MAAc,EACd,IAAgC,EACV,EAAE;QACxB,MAAM,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;YACpG,MAAM,SAAS,GAAG,OAAO,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;YACzF,IACE,CAAC,QAAQ,CAAC,QAAQ,KAAK,OAAO,IAAI,QAAQ,CAAC,QAAQ,KAAK,QAAQ,CAAC;gBACjE,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E,CAAC,GAAW,EAAE,WAA2B,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QACnH,MAAM,EAAE,CAAC,GAAW,EAAE,WAA2B,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QACtH,IAAI,EAAE,CAAC,GAAW,EAAE,WAA2B,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC;QAChH,OAAO,EAAE,CAAC,WAAwD,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC;QACtG,YAAY,EAAE,CAAC,WAA6D,EAAE,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,WAAW,CAAC;QACrH,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE;KAClD,CAAC;IACF,OAAO,OAA4B,CAAC;AACtC,CAAC"}
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
* raw `playwright/test` bypasses the fixture and produces claims with no
|
|
15
15
|
* records (the engine grades the obligation `missing`; GF-24).
|
|
16
16
|
*
|
|
17
|
-
* API
|
|
18
|
-
* `page.request`/`context.request`, and
|
|
19
|
-
*
|
|
20
|
-
*
|
|
17
|
+
* API requests made directly from test code are never E2E evidence. The
|
|
18
|
+
* `request` fixture, owned `page.request`/`context.request`, and exported
|
|
19
|
+
* `request` factory all go directly to the app; only browser page traffic
|
|
20
|
+
* rides the session proxy.
|
|
21
21
|
*/
|
|
22
22
|
import { request as playwrightRequest } from 'playwright';
|
|
23
23
|
import type { Page } from 'playwright/test';
|
|
@@ -50,7 +50,7 @@ export declare function flushPageObserverEvidence(witness: Pick<WitnessClient, '
|
|
|
50
50
|
* sessionProxyURL: dedicated observation-proxy origin for this test.
|
|
51
51
|
* onUnroutedOrigin: optional sink for unrouted same-host origins.
|
|
52
52
|
*/
|
|
53
|
-
export declare function routePageThroughSessionProxy(page: Page, appBaseURL: string, sessionProxyURL: string, onUnroutedOrigin?: (origin: string) => void): Promise<void>;
|
|
53
|
+
export declare function routePageThroughSessionProxy(page: Page, appBaseURL: string, sessionProxyURL: string, onUnroutedOrigin?: (origin: string) => void, initiatorForRequest?: (method: string, url: string) => Promise<'page' | 'test-code' | 'unknown'>): Promise<void>;
|
|
54
54
|
/**
|
|
55
55
|
* The diagnostic sink the page fixture hands to
|
|
56
56
|
* {@link routePageThroughSessionProxy}: it hands each distinct unrouted
|
|
@@ -91,10 +91,8 @@ export declare function createUnroutedOriginReporter(options: {
|
|
|
91
91
|
}): UnroutedOriginReporter;
|
|
92
92
|
/** Fixture map this pack adds to every test. */
|
|
93
93
|
export type EvidenceFixtures = {
|
|
94
|
-
/**
|
|
95
|
-
|
|
96
|
-
* `evidence.ui.*` need to declare it.
|
|
97
|
-
*/
|
|
94
|
+
/** Pending diagnostic-only direct API reports, settled before test teardown. */
|
|
95
|
+
directApiReports: void;
|
|
98
96
|
surface: SurfaceDescriptor | undefined;
|
|
99
97
|
/** The trusted evidence primitive surface for the running test. */
|
|
100
98
|
evidence: EvidenceApi;
|
|
@@ -108,23 +106,16 @@ declare const extended: import("playwright/test").TestType<import("playwright/te
|
|
|
108
106
|
export declare const test: typeof extended;
|
|
109
107
|
export { expect };
|
|
110
108
|
/**
|
|
111
|
-
* The module-scope `request` of `@gate-forge/pack-playwright/fixture
|
|
112
|
-
* `newContext(options)`
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* the first test's session window, so the session being open proves
|
|
118
|
-
* nothing), the returned context talks to the app DIRECTLY — setup
|
|
119
|
-
* traffic stays uncredited: it never reaches any session proxy, and
|
|
120
|
-
* the witness refuses session-attributed evidence outside a bound
|
|
121
|
-
* session. INSIDE a test body a session that never answers is a
|
|
122
|
-
* failure, not a fallback: the context waits the fixtures' own
|
|
123
|
-
* bound and then throws, so in-test traffic can never silently
|
|
124
|
-
* bypass the witness.
|
|
109
|
+
* The module-scope `request` of `@gate-forge/pack-playwright/fixture`.
|
|
110
|
+
* `newContext(options)` creates a normal Playwright API context with the
|
|
111
|
+
* supplied options and never rehosts its calls onto the session proxy.
|
|
112
|
+
* App-origin calls made in a test body are reported as direct-API
|
|
113
|
+
* diagnostics only; they can never satisfy an E2E claim. Calls made at
|
|
114
|
+
* module scope have no owning test and are not reported.
|
|
125
115
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
116
|
+
* In worker hooks, calls go straight to the app and remain uncredited;
|
|
117
|
+
* the first test's session may already be open, but that does not make
|
|
118
|
+
* hook traffic test-body evidence.
|
|
128
119
|
*/
|
|
129
120
|
export declare const request: {
|
|
130
121
|
newContext(options?: Parameters<typeof playwrightRequest.newContext>[0]): Promise<APIRequestContext>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../src/fixture/fixture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAA6B,OAAO,IAAI,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,KAAK,EAAE,IAAI,EAAY,MAAM,iBAAiB,CAAC;AAGtD,OAAO,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"fixture.d.ts","sourceRoot":"","sources":["../../src/fixture/fixture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,OAAO,EAA6B,OAAO,IAAI,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACrF,OAAO,KAAK,EAAE,IAAI,EAAY,MAAM,iBAAiB,CAAC;AAGtD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AE,MAAM,CAAC;CACpB,GAAG,sBAAsB,CA2BzB;AA6CD,gDAAgD;AAChD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gFAAgF;IAChF,gBAAgB,EAAE,IAAI,CAAC;IACvB,OAAO,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACvC,mEAAmE;IACnE,QAAQ,EAAE,WAAW,CAAC;CACvB,CAAC;AAmCF;;;;GAIG;AACH,QAAA,MAAM,QAAQ,2PA6IZ,CAAC;AAyEH,eAAO,MAAM,IAAI,EAAE,OAAO,QAAqC,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO;yBACQ,UAAU,CAAC,OAAO,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,GAAQ,OAAO,CAAC,iBAAiB,CAAC;CAoD/G,CAAC"}
|
package/dist/fixture/fixture.js
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
* raw `playwright/test` bypasses the fixture and produces claims with no
|
|
15
15
|
* records (the engine grades the obligation `missing`; GF-24).
|
|
16
16
|
*
|
|
17
|
-
* API
|
|
18
|
-
* `page.request`/`context.request`, and
|
|
19
|
-
*
|
|
20
|
-
*
|
|
17
|
+
* API requests made directly from test code are never E2E evidence. The
|
|
18
|
+
* `request` fixture, owned `page.request`/`context.request`, and exported
|
|
19
|
+
* `request` factory all go directly to the app; only browser page traffic
|
|
20
|
+
* rides the session proxy.
|
|
21
21
|
*/
|
|
22
22
|
import { chromium, firefox, webkit, request as playwrightRequest } from 'playwright';
|
|
23
23
|
import { createServer as createTcpServer } from 'node:net';
|
|
@@ -26,9 +26,10 @@ import { expect, test as base } from './consumer-runner.js';
|
|
|
26
26
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
27
27
|
import { ENV_WITNESS_URL } from '../constants.js';
|
|
28
28
|
import { createEvidence, } from './evidence.js';
|
|
29
|
-
import {
|
|
29
|
+
import { wrapDirectRequestContext } from './api-request.js';
|
|
30
30
|
import { WitnessClient } from './witness-client.js';
|
|
31
31
|
const browserDebuggingPorts = new WeakMap();
|
|
32
|
+
const unavailableInitiatorBrowsers = new Set();
|
|
32
33
|
/**
|
|
33
34
|
* Flushes this test's page observations to the witness. A flush failure
|
|
34
35
|
* must never fail the app's own passing test: the failure is surfaced as
|
|
@@ -83,6 +84,64 @@ function projectBaseURL(testInfo) {
|
|
|
83
84
|
const baseURL = testInfo.project.use['baseURL'];
|
|
84
85
|
return typeof baseURL === 'string' && baseURL !== '' ? baseURL : undefined;
|
|
85
86
|
}
|
|
87
|
+
async function attachInitiatorTracking(page, appBaseURL) {
|
|
88
|
+
const session = await page.context().newCDPSession(page);
|
|
89
|
+
const pending = new Map();
|
|
90
|
+
// Route callbacks that arrived before their CDP event, oldest first.
|
|
91
|
+
const waiting = new Map();
|
|
92
|
+
const appOriginPrefix = `${new URL(appBaseURL).origin}/`;
|
|
93
|
+
session.on('Network.requestWillBeSent', (event) => {
|
|
94
|
+
if (!event.request.url.startsWith(appOriginPrefix))
|
|
95
|
+
return;
|
|
96
|
+
let deepest = event.initiator?.stack;
|
|
97
|
+
while (deepest?.parent !== undefined)
|
|
98
|
+
deepest = deepest.parent;
|
|
99
|
+
const outermost = deepest?.callFrames?.at(-1);
|
|
100
|
+
const verdict = outermost === undefined ? 'unknown' : outermost.url ? 'page' : 'test-code';
|
|
101
|
+
const key = `${event.request.method} ${event.request.url}`;
|
|
102
|
+
const waiter = waiting.get(key)?.shift();
|
|
103
|
+
if (waiter !== undefined) {
|
|
104
|
+
waiter(verdict);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
const queue = pending.get(key) ?? [];
|
|
108
|
+
queue.push(verdict);
|
|
109
|
+
pending.set(key, queue);
|
|
110
|
+
});
|
|
111
|
+
await session.send('Network.enable');
|
|
112
|
+
await session.send('Debugger.enable');
|
|
113
|
+
await session.send('Debugger.setAsyncCallStackDepth', { maxDepth: 32 });
|
|
114
|
+
return {
|
|
115
|
+
session,
|
|
116
|
+
classify(method, url) {
|
|
117
|
+
const key = `${method} ${url}`;
|
|
118
|
+
const queue = pending.get(key);
|
|
119
|
+
const queued = queue?.shift();
|
|
120
|
+
if (queue?.length === 0)
|
|
121
|
+
pending.delete(key);
|
|
122
|
+
if (queued !== undefined)
|
|
123
|
+
return Promise.resolve(queued);
|
|
124
|
+
// A burst of requests can deliver a CDP event just after its route
|
|
125
|
+
// callback. Wait for that event only, never a fixed pause: a fixed
|
|
126
|
+
// pause shifts the app's request timing. No event in 50 ms: unknown.
|
|
127
|
+
return new Promise((resolve) => {
|
|
128
|
+
const waiters = waiting.get(key) ?? [];
|
|
129
|
+
const timer = setTimeout(() => {
|
|
130
|
+
const index = waiters.indexOf(settle);
|
|
131
|
+
if (index >= 0)
|
|
132
|
+
waiters.splice(index, 1);
|
|
133
|
+
resolve('unknown');
|
|
134
|
+
}, 50);
|
|
135
|
+
const settle = (verdict) => {
|
|
136
|
+
clearTimeout(timer);
|
|
137
|
+
resolve(verdict);
|
|
138
|
+
};
|
|
139
|
+
waiters.push(settle);
|
|
140
|
+
waiting.set(key, waiters);
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
86
145
|
/**
|
|
87
146
|
* Routes browser requests for the configured app origin through the
|
|
88
147
|
* supervisor-issued session proxy, preserving the app URL and path.
|
|
@@ -101,7 +160,7 @@ function projectBaseURL(testInfo) {
|
|
|
101
160
|
* sessionProxyURL: dedicated observation-proxy origin for this test.
|
|
102
161
|
* onUnroutedOrigin: optional sink for unrouted same-host origins.
|
|
103
162
|
*/
|
|
104
|
-
export async function routePageThroughSessionProxy(page, appBaseURL, sessionProxyURL, onUnroutedOrigin) {
|
|
163
|
+
export async function routePageThroughSessionProxy(page, appBaseURL, sessionProxyURL, onUnroutedOrigin, initiatorForRequest) {
|
|
105
164
|
const appOrigin = new URL(appBaseURL);
|
|
106
165
|
const sessionOrigin = new URL(sessionProxyURL);
|
|
107
166
|
if (appOrigin.protocol !== 'http:' ||
|
|
@@ -120,8 +179,13 @@ export async function routePageThroughSessionProxy(page, appBaseURL, sessionProx
|
|
|
120
179
|
await route.continue();
|
|
121
180
|
return;
|
|
122
181
|
}
|
|
182
|
+
const originalURL = requestURL.href;
|
|
123
183
|
requestURL.host = sessionOrigin.host;
|
|
124
|
-
await route.
|
|
184
|
+
const initiator = await initiatorForRequest?.(route.request().method(), originalURL);
|
|
185
|
+
const headers = initiator === 'test-code'
|
|
186
|
+
? { ...route.request().headers(), 'x-gateforge-initiator': 'test-code' }
|
|
187
|
+
: undefined;
|
|
188
|
+
await route.continue({ url: requestURL.href, ...(headers === undefined ? {} : { headers }) });
|
|
125
189
|
});
|
|
126
190
|
}
|
|
127
191
|
/**
|
|
@@ -181,6 +245,47 @@ export function createUnroutedOriginReporter(options) {
|
|
|
181
245
|
},
|
|
182
246
|
};
|
|
183
247
|
}
|
|
248
|
+
const directExchangeReporters = new Map();
|
|
249
|
+
function directExchangeReporterFor(testInfo) {
|
|
250
|
+
const existing = directExchangeReporters.get(testInfo.testId);
|
|
251
|
+
if (existing !== undefined)
|
|
252
|
+
return existing;
|
|
253
|
+
const inFlight = new Set();
|
|
254
|
+
const witness = new WitnessClient();
|
|
255
|
+
const reporter = {
|
|
256
|
+
report(exchange) {
|
|
257
|
+
const sent = (async () => {
|
|
258
|
+
const session = await resolveSessionBounded(witness, testInfo.testId, testInfo.workerIndex, 5_000);
|
|
259
|
+
if (session === null)
|
|
260
|
+
return;
|
|
261
|
+
await witness.reportSessionDirectExchanges({
|
|
262
|
+
sessionId: session.sessionId,
|
|
263
|
+
sessionToken: session.sessionToken,
|
|
264
|
+
exchanges: [exchange],
|
|
265
|
+
});
|
|
266
|
+
})().catch(() => undefined);
|
|
267
|
+
inFlight.add(sent);
|
|
268
|
+
void sent.then(() => inFlight.delete(sent));
|
|
269
|
+
},
|
|
270
|
+
async settled() {
|
|
271
|
+
while (inFlight.size > 0)
|
|
272
|
+
await Promise.all([...inFlight]);
|
|
273
|
+
},
|
|
274
|
+
};
|
|
275
|
+
directExchangeReporters.set(testInfo.testId, reporter);
|
|
276
|
+
return reporter;
|
|
277
|
+
}
|
|
278
|
+
async function settleDirectExchangeReports(testInfo) {
|
|
279
|
+
const reporter = directExchangeReporters.get(testInfo.testId);
|
|
280
|
+
if (reporter === undefined)
|
|
281
|
+
return;
|
|
282
|
+
try {
|
|
283
|
+
await reporter.settled();
|
|
284
|
+
}
|
|
285
|
+
finally {
|
|
286
|
+
directExchangeReporters.delete(testInfo.testId);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
184
289
|
/**
|
|
185
290
|
* The runner the evidence fixtures extend. Page observation needs a
|
|
186
291
|
* Chromium debugging port, so only then does it replace Playwright's
|
|
@@ -220,7 +325,20 @@ const browserRunner = process.env['GATEFORGE_PAGE_OBSERVATION_ENABLED'] === '1'
|
|
|
220
325
|
* was wired.
|
|
221
326
|
*/
|
|
222
327
|
const extended = browserRunner.extend({
|
|
223
|
-
|
|
328
|
+
directApiReports: [async ({}, use, testInfo) => {
|
|
329
|
+
if (!process.env[ENV_WITNESS_URL]) {
|
|
330
|
+
await use(undefined);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
directExchangeReporterFor(testInfo);
|
|
334
|
+
try {
|
|
335
|
+
await use(undefined);
|
|
336
|
+
}
|
|
337
|
+
finally {
|
|
338
|
+
await settleDirectExchangeReports(testInfo);
|
|
339
|
+
}
|
|
340
|
+
}, { auto: true }],
|
|
341
|
+
page: async ({ page, browser, browserName }, use, testInfo) => {
|
|
224
342
|
if (!process.env[ENV_WITNESS_URL]) {
|
|
225
343
|
await use(page);
|
|
226
344
|
return;
|
|
@@ -274,21 +392,20 @@ const extended = browserRunner.extend({
|
|
|
274
392
|
testId: session.testId,
|
|
275
393
|
});
|
|
276
394
|
};
|
|
395
|
+
let initiatorTracking;
|
|
396
|
+
if (browserName === 'chromium') {
|
|
397
|
+
initiatorTracking = await attachInitiatorTracking(page, appBaseURL);
|
|
398
|
+
}
|
|
399
|
+
else if (!unavailableInitiatorBrowsers.has(browserName)) {
|
|
400
|
+
unavailableInitiatorBrowsers.add(browserName);
|
|
401
|
+
console.warn(`initiator check unavailable for ${browserName}; requests started by test code cannot be told apart`);
|
|
402
|
+
}
|
|
277
403
|
if (session.proxyUrl !== null) {
|
|
278
404
|
const sessionProxyUrl = session.proxyUrl;
|
|
279
|
-
// The reporter rides along so a page that loads ANOTHER origin
|
|
280
|
-
// (a suite base URL Gateforge was never told about) reaches the
|
|
281
|
-
// witness as a name, not as silence.
|
|
282
405
|
const reporter = createUnroutedOriginReporter({ witness, session, appBaseURL });
|
|
283
|
-
await routePageThroughSessionProxy(page, appBaseURL, sessionProxyUrl, reporter.report);
|
|
284
|
-
//
|
|
285
|
-
//
|
|
286
|
-
// other origins pass through, plausible mismatches are reported.
|
|
287
|
-
rehostContextRequest(page.context(), {
|
|
288
|
-
baseURL: projectBaseURL(testInfo),
|
|
289
|
-
routing: async () => sessionApiRouting(appBaseURL, sessionProxyUrl),
|
|
290
|
-
onUnroutedOrigin: reporter.report,
|
|
291
|
-
});
|
|
406
|
+
await routePageThroughSessionProxy(page, appBaseURL, sessionProxyUrl, reporter.report, initiatorTracking?.classify);
|
|
407
|
+
// Do not wrap page/context.request: Playwright's Route.fetch uses
|
|
408
|
+
// the context request internally to forward browser traffic here.
|
|
292
409
|
try {
|
|
293
410
|
await use(page);
|
|
294
411
|
}
|
|
@@ -297,7 +414,12 @@ const extended = browserRunner.extend({
|
|
|
297
414
|
await reporter.settled();
|
|
298
415
|
}
|
|
299
416
|
finally {
|
|
300
|
-
|
|
417
|
+
try {
|
|
418
|
+
await flushPageObserver();
|
|
419
|
+
}
|
|
420
|
+
finally {
|
|
421
|
+
await initiatorTracking?.session.detach();
|
|
422
|
+
}
|
|
301
423
|
}
|
|
302
424
|
}
|
|
303
425
|
return;
|
|
@@ -306,7 +428,12 @@ const extended = browserRunner.extend({
|
|
|
306
428
|
await use(page);
|
|
307
429
|
}
|
|
308
430
|
finally {
|
|
309
|
-
|
|
431
|
+
try {
|
|
432
|
+
await flushPageObserver();
|
|
433
|
+
}
|
|
434
|
+
finally {
|
|
435
|
+
await initiatorTracking?.session.detach();
|
|
436
|
+
}
|
|
310
437
|
}
|
|
311
438
|
},
|
|
312
439
|
request: async ({ request }, use, testInfo) => {
|
|
@@ -323,23 +450,15 @@ const extended = browserRunner.extend({
|
|
|
323
450
|
if (session === null) {
|
|
324
451
|
throw new Error(`No supervisor-issued witness session for ${testInfo.testId}.`);
|
|
325
452
|
}
|
|
326
|
-
|
|
327
|
-
// No proxy channel exists for this session: nothing can be
|
|
328
|
-
// witnessed, and unwrapped behavior is today's behavior.
|
|
329
|
-
await use(request);
|
|
330
|
-
return;
|
|
331
|
-
}
|
|
332
|
-
const sessionProxyUrl = session.proxyUrl;
|
|
333
|
-
const reporter = createUnroutedOriginReporter({ witness, session, appBaseURL });
|
|
453
|
+
const directReporter = directExchangeReporterFor(testInfo);
|
|
334
454
|
try {
|
|
335
|
-
await use(
|
|
336
|
-
baseURL: projectBaseURL(testInfo),
|
|
337
|
-
|
|
338
|
-
onUnroutedOrigin: reporter.report,
|
|
455
|
+
await use(wrapDirectRequestContext(request, {
|
|
456
|
+
...(projectBaseURL(testInfo) === undefined ? {} : { baseURL: projectBaseURL(testInfo) }),
|
|
457
|
+
onExchange: (exchange) => directReporter.report(exchange),
|
|
339
458
|
}));
|
|
340
459
|
}
|
|
341
460
|
finally {
|
|
342
|
-
await
|
|
461
|
+
await directReporter.settled();
|
|
343
462
|
}
|
|
344
463
|
},
|
|
345
464
|
surface: async ({}, use) => {
|
|
@@ -416,23 +535,16 @@ function trackedHook(callback) {
|
|
|
416
535
|
export const test = withHookTracking(extended);
|
|
417
536
|
export { expect }; // re-exported so tests never need `playwright/test`
|
|
418
537
|
/**
|
|
419
|
-
* The module-scope `request` of `@gate-forge/pack-playwright/fixture
|
|
420
|
-
* `newContext(options)`
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
* the first test's session window, so the session being open proves
|
|
426
|
-
* nothing), the returned context talks to the app DIRECTLY — setup
|
|
427
|
-
* traffic stays uncredited: it never reaches any session proxy, and
|
|
428
|
-
* the witness refuses session-attributed evidence outside a bound
|
|
429
|
-
* session. INSIDE a test body a session that never answers is a
|
|
430
|
-
* failure, not a fallback: the context waits the fixtures' own
|
|
431
|
-
* bound and then throws, so in-test traffic can never silently
|
|
432
|
-
* bypass the witness.
|
|
538
|
+
* The module-scope `request` of `@gate-forge/pack-playwright/fixture`.
|
|
539
|
+
* `newContext(options)` creates a normal Playwright API context with the
|
|
540
|
+
* supplied options and never rehosts its calls onto the session proxy.
|
|
541
|
+
* App-origin calls made in a test body are reported as direct-API
|
|
542
|
+
* diagnostics only; they can never satisfy an E2E claim. Calls made at
|
|
543
|
+
* module scope have no owning test and are not reported.
|
|
433
544
|
*
|
|
434
|
-
*
|
|
435
|
-
*
|
|
545
|
+
* In worker hooks, calls go straight to the app and remain uncredited;
|
|
546
|
+
* the first test's session may already be open, but that does not make
|
|
547
|
+
* hook traffic test-body evidence.
|
|
436
548
|
*/
|
|
437
549
|
export const request = {
|
|
438
550
|
async newContext(options = {}) {
|
|
@@ -441,12 +553,27 @@ export const request = {
|
|
|
441
553
|
const appBaseURL = process.env['GATEFORGE_APP_BASE_URL']?.trim();
|
|
442
554
|
if (appBaseURL === undefined || appBaseURL === '')
|
|
443
555
|
return await playwrightRequest.newContext(options);
|
|
444
|
-
const directContext = (testInfo) => {
|
|
445
|
-
//
|
|
446
|
-
// when the caller gave none, so
|
|
447
|
-
//
|
|
556
|
+
const directContext = async (testInfo) => {
|
|
557
|
+
// Calls go to the app directly. The project's own base URL rides
|
|
558
|
+
// along when the caller gave none, so relative setup calls retain
|
|
559
|
+
// the suite's configured resolution.
|
|
448
560
|
const fallbackBaseURL = options.baseURL ?? (testInfo === undefined ? undefined : projectBaseURL(testInfo));
|
|
449
|
-
|
|
561
|
+
const context = await playwrightRequest.newContext(fallbackBaseURL === undefined ? options : { ...options, baseURL: fallbackBaseURL });
|
|
562
|
+
return wrapDirectRequestContext(context, {
|
|
563
|
+
...(fallbackBaseURL === undefined ? {} : { baseURL: fallbackBaseURL }),
|
|
564
|
+
onExchange: (exchange) => {
|
|
565
|
+
let owner = testInfo;
|
|
566
|
+
if (owner === undefined) {
|
|
567
|
+
try {
|
|
568
|
+
owner = base.info();
|
|
569
|
+
}
|
|
570
|
+
catch {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
directExchangeReporterFor(owner).report(exchange);
|
|
575
|
+
},
|
|
576
|
+
});
|
|
450
577
|
};
|
|
451
578
|
let testInfo;
|
|
452
579
|
try {
|
|
@@ -472,16 +599,7 @@ export const request = {
|
|
|
472
599
|
if (session === null) {
|
|
473
600
|
throw new Error(`No supervisor-issued witness session for ${testInfo.testId}.`);
|
|
474
601
|
}
|
|
475
|
-
|
|
476
|
-
// No proxy channel exists for this session: nothing can be
|
|
477
|
-
// witnessed, and unwrapped behavior is today's behavior.
|
|
478
|
-
return await directContext(testInfo);
|
|
479
|
-
}
|
|
480
|
-
const routing = sessionApiRouting(appBaseURL, session.proxyUrl);
|
|
481
|
-
return wrapApiRequestContext(await playwrightRequest.newContext(options), {
|
|
482
|
-
...(options.baseURL === undefined ? {} : { baseURL: options.baseURL }),
|
|
483
|
-
routing: async () => routing,
|
|
484
|
-
});
|
|
602
|
+
return await directContext(testInfo);
|
|
485
603
|
},
|
|
486
604
|
};
|
|
487
605
|
//# sourceMappingURL=fixture.js.map
|