agentpath 0.0.0-stage → 0.1.0-alpha.2
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/LICENSE.md +105 -0
- package/README.md +101 -2
- package/THIRD_PARTY_NOTICES +12 -0
- package/apps/demo-site/dist/site.js +92 -0
- package/apps/studio/dist/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/apps/studio/dist/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/apps/studio/dist/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/apps/studio/dist/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/apps/studio/dist/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/apps/studio/dist/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/apps/studio/dist/assets/index-DH4wJPHm.js +67 -0
- package/apps/studio/dist/assets/index-DrnNh2ip.css +1 -0
- package/apps/studio/dist/index.html +14 -0
- package/audit.md +173 -0
- package/autonomous-mode.md +104 -0
- package/ci.md +118 -0
- package/coding-agents.md +143 -0
- package/concepts.md +145 -0
- package/contracts.md +356 -0
- package/examples/tasks/ambiguous.json +98 -0
- package/examples/tasks/assertion-failure.json +98 -0
- package/examples/tasks/broken.json +98 -0
- package/examples/tasks/fixed.json +98 -0
- package/examples/tasks/recovery.json +19 -0
- package/images/compare-recovery-desktop.jpg +0 -0
- package/images/compare-variants-desktop.jpg +0 -0
- package/images/overview-desktop.jpg +0 -0
- package/images/run-autonomous-passed-desktop.jpg +0 -0
- package/images/run-failed-desktop.jpg +0 -0
- package/images/run-failed-mobile.jpg +0 -0
- package/images/run-missing-artifact-desktop.jpg +0 -0
- package/images/task-editor-laptop.jpg +0 -0
- package/installation.md +102 -0
- package/ledger.md +62 -0
- package/licenses/-fontsource-variable-geist-mono.txt +93 -0
- package/licenses/-fontsource-variable-geist.txt +93 -0
- package/licenses/lucide-react.txt +43 -0
- package/licenses/react-dom.txt +21 -0
- package/licenses/react.txt +21 -0
- package/licenses/scheduler.txt +21 -0
- package/licenses/tailwindcss.txt +21 -0
- package/licenses/zod.txt +21 -0
- package/package.json +165 -4
- package/packages/cli/bin/agentpath.js +39 -0
- package/packages/cli/dist/audit-rerun.js +384 -0
- package/packages/cli/dist/audit.js +387 -0
- package/packages/cli/dist/change-summaries.js +87 -0
- package/packages/cli/dist/ci-report.js +88 -0
- package/packages/cli/dist/demo.js +88 -0
- package/packages/cli/dist/doctor.js +265 -0
- package/packages/cli/dist/explain.js +89 -0
- package/packages/cli/dist/git.js +7 -0
- package/packages/cli/dist/inspect.js +118 -0
- package/packages/cli/dist/ledger.js +509 -0
- package/packages/cli/dist/local.js +102 -0
- package/packages/cli/dist/main.js +708 -0
- package/packages/cli/dist/mcp.js +231 -0
- package/packages/cli/dist/paths.js +6 -0
- package/packages/cli/dist/playwright-fixture.js +185 -0
- package/packages/cli/dist/playwright-reporter.js +49 -0
- package/packages/cli/dist/tasks.js +37 -0
- package/packages/cli/dist/test-source.js +283 -0
- package/packages/cli/dist/watch.js +96 -0
- package/packages/contracts/dist/agent-settings.js +18 -0
- package/packages/contracts/dist/agent.js +175 -0
- package/packages/contracts/dist/audit.js +115 -0
- package/packages/contracts/dist/guidance.js +339 -0
- package/packages/contracts/dist/index.js +14 -0
- package/packages/contracts/dist/inspect.js +63 -0
- package/packages/contracts/dist/ledger.js +80 -0
- package/packages/contracts/dist/local.js +171 -0
- package/packages/contracts/dist/outcomes.js +94 -0
- package/packages/contracts/dist/platform.js +105 -0
- package/packages/contracts/dist/playwright-live.js +76 -0
- package/packages/contracts/dist/policy.js +93 -0
- package/packages/contracts/dist/run.js +178 -0
- package/packages/contracts/dist/task-issues.js +39 -0
- package/packages/contracts/dist/task.js +185 -0
- package/packages/contracts/dist/watch.js +57 -0
- package/packages/core/dist/action-feedback.js +103 -0
- package/packages/core/dist/actions.js +160 -0
- package/packages/core/dist/agent-loop.js +122 -0
- package/packages/core/dist/artifacts.js +156 -0
- package/packages/core/dist/assertions.js +120 -0
- package/packages/core/dist/autonomous.js +1 -0
- package/packages/core/dist/browser.js +196 -0
- package/packages/core/dist/compare.js +141 -0
- package/packages/core/dist/control-state.js +62 -0
- package/packages/core/dist/diagnostics.js +134 -0
- package/packages/core/dist/evidence-diff.js +93 -0
- package/packages/core/dist/evidence.js +203 -0
- package/packages/core/dist/index.js +22 -0
- package/packages/core/dist/inspect.js +257 -0
- package/packages/core/dist/integrity.js +176 -0
- package/packages/core/dist/liveness.js +114 -0
- package/packages/core/dist/local-files.js +61 -0
- package/packages/core/dist/locators.js +214 -0
- package/packages/core/dist/model-provider.js +88 -0
- package/packages/core/dist/observation.js +257 -0
- package/packages/core/dist/playwright-live.js +519 -0
- package/packages/core/dist/playwright-results.js +543 -0
- package/packages/core/dist/policy.js +182 -0
- package/packages/core/dist/privacy.js +93 -0
- package/packages/core/dist/recovery.js +54 -0
- package/packages/core/dist/retention.js +204 -0
- package/packages/core/dist/run-index.js +177 -0
- package/packages/core/dist/run-plan.js +28 -0
- package/packages/core/dist/run-repository.js +518 -0
- package/packages/core/dist/runner.js +913 -0
- package/packages/core/dist/storage.js +63 -0
- package/packages/core/dist/task-fingerprint.js +36 -0
- package/packages/core/dist/test-change-rerun.js +84 -0
- package/packages/core/dist/test-changes.js +896 -0
- package/packages/core/dist/timing.js +41 -0
- package/packages/core/dist/watch.js +165 -0
- package/packages/server/dist/index.js +265 -0
- package/packages/server/dist/task-store.js +103 -0
- package/quickstart.md +85 -0
- package/security.md +136 -0
- package/try-on-your-repo.md +54 -0
- package/understanding-results.md +159 -0
- package/writing-tasks.md +196 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { once } from "node:events";
|
|
2
|
+
import { createServer } from "node:net";
|
|
3
|
+
import { allowedUrl, httpUrl } from "#agentpath/contracts";
|
|
4
|
+
import { chromium } from "playwright";
|
|
5
|
+
const TRACKED_BLOCKED_HOSTS = 200;
|
|
6
|
+
export class NavigationGuard {
|
|
7
|
+
hosts;
|
|
8
|
+
label;
|
|
9
|
+
#violation;
|
|
10
|
+
#blocked = new Map();
|
|
11
|
+
#untracked = false;
|
|
12
|
+
/** `label` turns a blocked host into its recorded form when the request is blocked, such as after privacy rules. */
|
|
13
|
+
constructor(hosts, label = (host) => host) {
|
|
14
|
+
this.hosts = hosts;
|
|
15
|
+
this.label = label;
|
|
16
|
+
}
|
|
17
|
+
/** Records a blocked request's host. Recording never changes whether a request is blocked. */
|
|
18
|
+
count(raw) {
|
|
19
|
+
try {
|
|
20
|
+
const url = httpUrl(raw);
|
|
21
|
+
const host = this.label(url?.host ?? "[non-HTTP destination]");
|
|
22
|
+
if (this.#blocked.has(host) || this.#blocked.size < TRACKED_BLOCKED_HOSTS)
|
|
23
|
+
this.#blocked.set(host, (this.#blocked.get(host) ?? 0) + 1);
|
|
24
|
+
else
|
|
25
|
+
this.#untracked = true;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
this.#untracked = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Hosts outside the allowlist whose requests the guard blocked, most requested first. */
|
|
32
|
+
blockedHosts(limit) {
|
|
33
|
+
const hosts = [...this.#blocked].map(([host, requests]) => ({ host, requests }))
|
|
34
|
+
.sort((a, b) => b.requests - a.requests || a.host.localeCompare(b.host));
|
|
35
|
+
return { hosts: hosts.slice(0, limit), truncated: this.#untracked || hosts.length > limit };
|
|
36
|
+
}
|
|
37
|
+
permits(raw) {
|
|
38
|
+
const url = httpUrl(raw);
|
|
39
|
+
return url !== undefined && allowedUrl(url, this.hosts);
|
|
40
|
+
}
|
|
41
|
+
block(raw) {
|
|
42
|
+
this.#violation ??= { disallowedHost: httpUrl(raw)?.host ?? "[non-HTTP destination]" };
|
|
43
|
+
}
|
|
44
|
+
/** `deliberate` identifies requests a trusted action policy aborted, which are not navigation failures. */
|
|
45
|
+
async install(context, deliberate = () => false) {
|
|
46
|
+
await context.route("**/*", async (route) => {
|
|
47
|
+
try {
|
|
48
|
+
if (this.permits(route.request().url()))
|
|
49
|
+
await route.continue();
|
|
50
|
+
else {
|
|
51
|
+
this.count(route.request().url());
|
|
52
|
+
await route.abort("blockedbyclient");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// The page or context can close while a request is being handled.
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
await context.routeWebSocket("**/*", (socket) => {
|
|
60
|
+
const url = new URL(socket.url());
|
|
61
|
+
url.protocol = url.protocol === "wss:" ? "https:" : "http:";
|
|
62
|
+
if (this.permits(url.href))
|
|
63
|
+
socket.connectToServer();
|
|
64
|
+
else {
|
|
65
|
+
this.count(url.href);
|
|
66
|
+
void socket.close({ code: 1008, reason: "Host is outside the run allowlist" }).catch(() => { });
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
// Also observe navigation events on targets outside the primary CDP session.
|
|
70
|
+
context.on("request", (request) => {
|
|
71
|
+
if (request.isNavigationRequest() && !this.permits(request.url()))
|
|
72
|
+
this.block(request.url());
|
|
73
|
+
});
|
|
74
|
+
context.on("response", (response) => {
|
|
75
|
+
if (response.status() >= 400 && isTopNavigation(response.request())) {
|
|
76
|
+
this.#violation ??= { httpStatus: response.status() };
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
context.on("requestfailed", (request) => {
|
|
80
|
+
if (isTopNavigation(request) && request.failure()?.errorText !== "net::ERR_ABORTED" && !deliberate(request)) {
|
|
81
|
+
this.#violation ??= { errorKind: "navigation" };
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async installRedirectGuard(page) {
|
|
86
|
+
const session = await page.context().newCDPSession(page);
|
|
87
|
+
session.on("Fetch.requestPaused", (event) => {
|
|
88
|
+
const status = event.responseStatusCode ?? 0;
|
|
89
|
+
const location = status >= 300 && status < 400
|
|
90
|
+
? event.responseHeaders?.find(({ name }) => name.toLowerCase() === "location")?.value
|
|
91
|
+
: undefined;
|
|
92
|
+
const target = location ? httpUrl(location, event.request.url) : undefined;
|
|
93
|
+
if (location && (!target || !allowedUrl(target, this.hosts))) {
|
|
94
|
+
if (event.resourceType === "Document")
|
|
95
|
+
this.block(target?.href ?? location);
|
|
96
|
+
void session.send("Fetch.failRequest", { requestId: event.requestId, errorReason: "BlockedByClient" }).catch(() => { });
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
void session.send("Fetch.continueRequest", { requestId: event.requestId }).catch(() => { });
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
// Playwright's request routes only handle the first hop of HTTP redirects.
|
|
103
|
+
await session.send("Fetch.enable", { patterns: [{ urlPattern: "http*", requestStage: "Response" }] });
|
|
104
|
+
}
|
|
105
|
+
check(page) {
|
|
106
|
+
if (page.url() !== "about:blank" && !this.permits(page.url()))
|
|
107
|
+
this.block(page.url());
|
|
108
|
+
return this.#violation;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
function isTopNavigation(request) {
|
|
112
|
+
if (!request.isNavigationRequest())
|
|
113
|
+
return false;
|
|
114
|
+
try {
|
|
115
|
+
return request.frame().parentFrame() === null;
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
// Only plain hostnames, IPv4 literals, and bracketed IPv6 literals become proxy bypass rules.
|
|
122
|
+
// Anything else (for example a literal "*" or a comma) stays behind the sinkhole and fails closed.
|
|
123
|
+
const bypassHost = /^(?:[a-z0-9-]+(?:\.[a-z0-9-]+)*|\[[0-9a-f:.]+\])$/;
|
|
124
|
+
function bypassEntries(hosts) {
|
|
125
|
+
return hosts.flatMap((entry) => {
|
|
126
|
+
const url = httpUrl(`http://${entry}`);
|
|
127
|
+
if (!url || url.host !== entry || !bypassHost.test(url.hostname))
|
|
128
|
+
return [];
|
|
129
|
+
// A portless allowlist entry means the scheme's default port, not every port.
|
|
130
|
+
return url.port ? [entry] : [`${entry}:80`, `${entry}:443`];
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
export function proxyBypassRules(hosts) {
|
|
134
|
+
// Chromium applies the later rule, so "<-loopback>" must precede the allowed loopback hosts.
|
|
135
|
+
return ["<-loopback>", ...bypassEntries(hosts)].join(",");
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Firefox preferences that put the sinkhole in front of everything outside `hosts`. Not used by runs yet: runs are
|
|
139
|
+
* Chromium-only. The egress tests launch Firefox with exactly these, so the tested configuration is the one a later
|
|
140
|
+
* engine option must use.
|
|
141
|
+
* - Firefox never proxies loopback unless `allow_hijacking_localhost` is set, so other local ports would be reachable.
|
|
142
|
+
* - A portless `no_proxies_on` entry opens every port of that host, so portless allowlist entries are pinned to 80 and 443.
|
|
143
|
+
* - `ice.proxy_only` keeps WebRTC from gathering candidates outside the proxy, which accepts none.
|
|
144
|
+
*/
|
|
145
|
+
export function firefoxEgressPrefs(hosts) {
|
|
146
|
+
return {
|
|
147
|
+
"network.proxy.allow_hijacking_localhost": true,
|
|
148
|
+
"network.proxy.no_proxies_on": bypassEntries(hosts).join(","),
|
|
149
|
+
"media.peerconnection.ice.proxy_only": true,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* A local proxy that accepts and immediately drops every connection. Chromium sends all traffic
|
|
154
|
+
* outside the allowlist to it, which backs up the route and redirect guards for requests they do
|
|
155
|
+
* not see, such as later redirect hops in popups and out-of-process frames.
|
|
156
|
+
*/
|
|
157
|
+
export class EgressSinkhole {
|
|
158
|
+
#server = createServer((socket) => socket.destroy());
|
|
159
|
+
async start() {
|
|
160
|
+
this.#server.listen(0, "127.0.0.1");
|
|
161
|
+
await once(this.#server, "listening");
|
|
162
|
+
const address = this.#server.address();
|
|
163
|
+
return `http://127.0.0.1:${address.port}`;
|
|
164
|
+
}
|
|
165
|
+
async close() {
|
|
166
|
+
if (!this.#server.listening)
|
|
167
|
+
return;
|
|
168
|
+
await new Promise((done) => this.#server.close(() => done()));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Launches sandboxed headless Chromium whose traffic outside `hosts` goes to the sinkhole. Every AgentPath browser
|
|
173
|
+
* starts here; callers then install a NavigationGuard on the context and its redirect guard on each page.
|
|
174
|
+
*/
|
|
175
|
+
export async function launchGuardedBrowser(hosts, sinkhole, timeoutMs) {
|
|
176
|
+
const proxy = { server: await sinkhole.start(), bypass: proxyBypassRules(hosts) };
|
|
177
|
+
return chromium.launchServer({
|
|
178
|
+
host: "127.0.0.1", port: 0, headless: true, chromiumSandbox: true,
|
|
179
|
+
timeout: timeoutMs(), proxy,
|
|
180
|
+
// Playwright's own handlers call process.exit after closing the browser, which would discard the final
|
|
181
|
+
// record. When the host already handles a signal (the CLI and Studio abort the run), defer to it.
|
|
182
|
+
handleSIGINT: process.listenerCount("SIGINT") === 0, handleSIGTERM: process.listenerCount("SIGTERM") === 0,
|
|
183
|
+
// Keep WebRTC UDP behind the proxy, which accepts none.
|
|
184
|
+
args: ["--force-webrtc-ip-handling-policy=disable_non_proxied_udp"],
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/** An Android Chrome user agent string (fixed; not updated with the bundled Chromium). Pages read it to choose a mobile layout; the engine is still desktop Chromium. */
|
|
188
|
+
export const MOBILE_USER_AGENT = "Mozilla/5.0 (Linux; Android 14; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36";
|
|
189
|
+
export function browserContextOptions(viewport, mobile = false) {
|
|
190
|
+
return {
|
|
191
|
+
viewport,
|
|
192
|
+
serviceWorkers: "block",
|
|
193
|
+
acceptDownloads: false,
|
|
194
|
+
...(mobile ? { isMobile: true, hasTouch: true, deviceScaleFactor: 3, userAgent: MOBILE_USER_AGENT } : {}),
|
|
195
|
+
};
|
|
196
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { comparePolicies, deriveOutcomes, detailedComparisonSchema, SCHEMA_VERSION } from "#agentpath/contracts";
|
|
2
|
+
import { diffOperation } from "./evidence-diff.js";
|
|
3
|
+
import { interpretComparison, taskContract } from "./recovery.js";
|
|
4
|
+
export class ComparisonUnavailable extends Error {
|
|
5
|
+
}
|
|
6
|
+
function operations(detail, phase) {
|
|
7
|
+
const result = detail.result;
|
|
8
|
+
const completed = phase === "step" ? result?.steps : result?.assertions;
|
|
9
|
+
const plan = phase === "step" ? detail.plan?.steps : detail.plan?.assertions;
|
|
10
|
+
if (plan) {
|
|
11
|
+
const byIndex = new Map(completed?.map((entry) => [entry.index, entry]));
|
|
12
|
+
return plan.map((entry, index) => ({ ...entry, identityVersion: detail.plan?.identityVersion, index, result: byIndex.get(index) }));
|
|
13
|
+
}
|
|
14
|
+
return (completed ?? []).map((entry) => {
|
|
15
|
+
const kind = "action" in entry ? entry.action : entry.assertion;
|
|
16
|
+
return { kind, intent: kind, index: entry.index, result: entry };
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
const untargeted = new Set(["navigate", "url"]);
|
|
20
|
+
function align(phase, left, right) {
|
|
21
|
+
const matches = (a, b) => a.key && b.key && a.identityVersion === b.identityVersion ? a.key === b.key : a.kind === b.kind;
|
|
22
|
+
if (left.length > 100 || right.length > 100)
|
|
23
|
+
throw new ComparisonUnavailable("Operation count exceeds the task limit.");
|
|
24
|
+
const scores = Array.from({ length: left.length + 1 }, () => new Int32Array(right.length + 1));
|
|
25
|
+
const score = (i, j) => scores[i]?.[j] ?? 0;
|
|
26
|
+
for (let i = left.length - 1; i >= 0; i--) {
|
|
27
|
+
for (let j = right.length - 1; j >= 0; j--) {
|
|
28
|
+
const a = left[i];
|
|
29
|
+
const b = right[j];
|
|
30
|
+
scores[i][j] = matches(a, b) ? 1 + score(i + 1, j + 1) : Math.max(score(i + 1, j), score(i, j + 1));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const rows = [];
|
|
34
|
+
let i = 0;
|
|
35
|
+
let j = 0;
|
|
36
|
+
while (i < left.length || j < right.length) {
|
|
37
|
+
const a = left[i];
|
|
38
|
+
const b = right[j];
|
|
39
|
+
if (a && b && matches(a, b)) {
|
|
40
|
+
rows.push(row(phase, a.key && b.key && a.identityVersion === b.identityVersion ? "identity" : "ordered", a, b));
|
|
41
|
+
i++;
|
|
42
|
+
j++;
|
|
43
|
+
}
|
|
44
|
+
else if (a && (!b || score(i + 1, j) >= score(i, j + 1))) {
|
|
45
|
+
rows.push(row(phase, "unmatched", a));
|
|
46
|
+
i++;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
rows.push(row(phase, "unmatched", undefined, b));
|
|
50
|
+
j++;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return rows;
|
|
54
|
+
}
|
|
55
|
+
function row(phase, alignment, a, b) {
|
|
56
|
+
const display = (operation) => operation && ({
|
|
57
|
+
index: operation.index, intent: operation.intent, result: operation.result,
|
|
58
|
+
});
|
|
59
|
+
const left = a?.result;
|
|
60
|
+
const right = b?.result;
|
|
61
|
+
const difference = alignment === "unmatched" ? "unmatched"
|
|
62
|
+
: left && right && left.status !== right.status ? "outcome"
|
|
63
|
+
: Boolean(left) !== Boolean(right) ? "coverage"
|
|
64
|
+
: a?.intent !== b?.intent && alignment === "identity" && a?.identityVersion !== 2 ? "intent" : undefined;
|
|
65
|
+
return {
|
|
66
|
+
phase, alignment, baseline: display(a), candidate: display(b), difference,
|
|
67
|
+
durationDeltaMs: left && right ? right.durationMs - left.durationMs : undefined,
|
|
68
|
+
targeted: !untargeted.has((a ?? b)?.kind ?? ""),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export function compareRuns(baseline, candidate, mode) {
|
|
72
|
+
const a = baseline.result;
|
|
73
|
+
const b = candidate.result;
|
|
74
|
+
if (!a || !b)
|
|
75
|
+
throw new ComparisonUnavailable("Comparison requires two finalized runs.");
|
|
76
|
+
if (a.runId === b.runId)
|
|
77
|
+
throw new ComparisonUnavailable("Choose two different runs.");
|
|
78
|
+
if (mode === "same-task" && a.taskId !== b.taskId) {
|
|
79
|
+
throw new ComparisonUnavailable("Different task IDs require scenario-variants mode.");
|
|
80
|
+
}
|
|
81
|
+
const rows = [
|
|
82
|
+
...align("step", operations(baseline, "step"), operations(candidate, "step")),
|
|
83
|
+
...align("assertion", operations(baseline, "assertion"), operations(candidate, "assertion")),
|
|
84
|
+
];
|
|
85
|
+
// Navigation and URL assertions align by kind alone, so nearly any two tasks share them.
|
|
86
|
+
// Variants must also share at least one operation on a semantic target.
|
|
87
|
+
if (mode === "scenario-variants" && !rows.some((entry) => entry.alignment !== "unmatched" && entry.targeted)) {
|
|
88
|
+
throw new ComparisonUnavailable("These variants share no semantic target, so they are not comparable as one scenario.");
|
|
89
|
+
}
|
|
90
|
+
for (const row of rows) {
|
|
91
|
+
row.evidenceDiff = diffOperation(row.phase, row.baseline, row.candidate, baseline, candidate);
|
|
92
|
+
if (!row.difference && row.evidenceDiff.some((diff) => diff.changed && !["timing", "evidence"].includes(diff.field))) {
|
|
93
|
+
row.difference = "evidence";
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const contract = taskContract(baseline, candidate);
|
|
97
|
+
const baselineFailure = a.status === "failed" ? a.failure : undefined;
|
|
98
|
+
const candidateFailure = b.status === "failed" ? b.failure : undefined;
|
|
99
|
+
const startup = [baselineFailure, candidateFailure].some((failure) => failure?.location.phase === "startup") &&
|
|
100
|
+
(baselineFailure?.location.phase !== candidateFailure?.location.phase || baselineFailure?.category !== candidateFailure?.category);
|
|
101
|
+
const firstRow = startup ? -1 : rows.findIndex((entry) => entry.difference ||
|
|
102
|
+
(baselineFailure?.category !== candidateFailure?.category &&
|
|
103
|
+
[baselineFailure?.location, candidateFailure?.location].some((location, side) => location && location.phase !== "startup" && location.phase === entry.phase &&
|
|
104
|
+
location.index === (side === 0 ? entry.baseline : entry.candidate)?.index)));
|
|
105
|
+
const first = rows[firstRow];
|
|
106
|
+
const operation = first?.baseline ?? first?.candidate;
|
|
107
|
+
const planned = operation && (first?.baseline ? baseline : candidate).plan;
|
|
108
|
+
const agentFailure = [baselineFailure, candidateFailure].find((failure) => failure?.location.phase === "agent");
|
|
109
|
+
const agentDivergence = firstRow < 0 && agentFailure &&
|
|
110
|
+
(baselineFailure?.category !== candidateFailure?.category || baselineFailure?.observed !== candidateFailure?.observed);
|
|
111
|
+
let location = startup ? { phase: "startup" } : agentDivergence ? agentFailure.location : undefined;
|
|
112
|
+
if (first?.phase === "step" && operation) {
|
|
113
|
+
const action = planned?.steps[operation.index]?.kind ??
|
|
114
|
+
(operation.result && "action" in operation.result ? operation.result.action : undefined);
|
|
115
|
+
if (action)
|
|
116
|
+
location = { phase: "step", index: operation.index, action };
|
|
117
|
+
}
|
|
118
|
+
if (first?.phase === "assertion" && operation) {
|
|
119
|
+
const assertion = planned?.assertions[operation.index]?.kind ??
|
|
120
|
+
(operation.result && "assertion" in operation.result ? operation.result.assertion : undefined);
|
|
121
|
+
if (assertion)
|
|
122
|
+
location = { phase: "assertion", index: operation.index, assertion };
|
|
123
|
+
}
|
|
124
|
+
return detailedComparisonSchema.parse({
|
|
125
|
+
summary: {
|
|
126
|
+
schemaVersion: SCHEMA_VERSION, baselineRunId: a.runId, candidateRunId: b.runId,
|
|
127
|
+
baselineStatus: a.status, candidateStatus: b.status,
|
|
128
|
+
firstDivergence: location && {
|
|
129
|
+
location,
|
|
130
|
+
baseline: startup || agentDivergence ? a.status : first?.baseline?.result?.status ?? "not_run",
|
|
131
|
+
candidate: startup || agentDivergence ? b.status : first?.candidate?.result?.status ?? "not_run",
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
contract, interpretation: interpretComparison(baseline, candidate, contract),
|
|
135
|
+
mode, baselineTaskId: a.taskId, candidateTaskId: b.taskId,
|
|
136
|
+
outcomes: { baseline: deriveOutcomes(baseline), candidate: deriveOutcomes(candidate), policy: comparePolicies(baseline, candidate) },
|
|
137
|
+
failure: { baseline: baselineFailure?.category, candidate: candidateFailure?.category },
|
|
138
|
+
durationDeltaMs: b.durationMs - a.durationMs,
|
|
139
|
+
rows: rows.map(({ phase, alignment, baseline: left, candidate: right, durationDeltaMs, difference, evidenceDiff }) => ({ phase, alignment, baseline: left, candidate: right, durationDeltaMs, difference, evidenceDiff })), firstRow: firstRow < 0 ? undefined : firstRow,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Runs inside Chromium. Return only bounded structural facts, never a text field's value. */
|
|
2
|
+
function readFacts(element, optionLimit) {
|
|
3
|
+
if (!element.isConnected)
|
|
4
|
+
return {};
|
|
5
|
+
if (element instanceof HTMLSelectElement) {
|
|
6
|
+
const options = Array.from({ length: Math.min(optionLimit, element.options.length) }, (_, index) => element.options[index]);
|
|
7
|
+
return {
|
|
8
|
+
nativeSelect: true,
|
|
9
|
+
...(element.multiple ? { multiple: true } : {}),
|
|
10
|
+
selected: options.map((option) => option.selected),
|
|
11
|
+
disabledOptions: options.map((option) => option.matches(":disabled")),
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
const input = element instanceof HTMLInputElement;
|
|
15
|
+
if (input && ["checkbox", "radio"].includes(element.type)) {
|
|
16
|
+
return { checkable: true, ...(element.indeterminate ? {} : { isChecked: element.checked }) };
|
|
17
|
+
}
|
|
18
|
+
if (input || element instanceof HTMLTextAreaElement) {
|
|
19
|
+
const supported = !input || ["text", "email", "search", "tel", "url", "number"].includes(element.type);
|
|
20
|
+
const autocomplete = (element.getAttribute("autocomplete") ?? "").trim().toLowerCase();
|
|
21
|
+
if (!supported || !["", "on", "off", "email", "tel", "url"].includes(autocomplete)) {
|
|
22
|
+
return { textInput: true, omitStaticText: true };
|
|
23
|
+
}
|
|
24
|
+
const hasValue = element.value !== "";
|
|
25
|
+
return { textInput: true, hasValue, ...(hasValue ? { omitStaticText: true } : {}) };
|
|
26
|
+
}
|
|
27
|
+
return element instanceof HTMLElement && element.isContentEditable ? { textInput: true, omitStaticText: true } : {};
|
|
28
|
+
}
|
|
29
|
+
/** The isolated world uses native DOM getters, separate from scripts on the observed page. */
|
|
30
|
+
export function inspectControlFacts(session, deadline, optionLimit) {
|
|
31
|
+
let world;
|
|
32
|
+
async function createWorld() {
|
|
33
|
+
const { frameTree } = await session.send("Page.getFrameTree");
|
|
34
|
+
const { executionContextId } = await session.send("Page.createIsolatedWorld", { frameId: frameTree.frame.id, worldName: "agentpath-observation" });
|
|
35
|
+
return executionContextId;
|
|
36
|
+
}
|
|
37
|
+
return async (backendNodeId) => {
|
|
38
|
+
try {
|
|
39
|
+
const executionContextId = await deadline.observe(() => world ??= createWorld());
|
|
40
|
+
const { object } = await deadline.observe(() => session.send("DOM.resolveNode", { backendNodeId, executionContextId, objectGroup: "agentpath-controls" }));
|
|
41
|
+
const reply = await deadline.observe(() => session.send("Runtime.callFunctionOn", {
|
|
42
|
+
objectId: object.objectId,
|
|
43
|
+
functionDeclaration: `function (limit) { return (${readFacts.toString()})(this, limit); }`,
|
|
44
|
+
arguments: [{ value: optionLimit }],
|
|
45
|
+
returnByValue: true,
|
|
46
|
+
}));
|
|
47
|
+
return reply.exceptionDetails ? undefined : reply.result.value;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
deadline.signal.throwIfAborted();
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
export async function readPopulation(element, deadline) {
|
|
56
|
+
try {
|
|
57
|
+
return (await deadline.observe(() => element.evaluate(readFacts, 0))).hasValue;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { errors } from "playwright";
|
|
2
|
+
export class RunFailure extends Error {
|
|
3
|
+
details;
|
|
4
|
+
constructor(details) {
|
|
5
|
+
super(details.observed);
|
|
6
|
+
this.details = details;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
const INSPECT_TARGET = "Inspect the page state and the target's accessible role, name, or label.";
|
|
10
|
+
const IF_LATER = "If the target appears later, raise the operation timeout.";
|
|
11
|
+
/**
|
|
12
|
+
* The advice to raise the timeout is written before the late check runs. When the late check then saw the
|
|
13
|
+
* condition still failing, that advice contradicts the recorded fact, so it is dropped.
|
|
14
|
+
*/
|
|
15
|
+
export function afterLateCheck(failure) {
|
|
16
|
+
if (failure.observation.lateCheck?.outcome !== "still-failing" || failure.investigation !== `${INSPECT_TARGET} ${IF_LATER}`)
|
|
17
|
+
return failure;
|
|
18
|
+
return { ...failure, investigation: INSPECT_TARGET };
|
|
19
|
+
}
|
|
20
|
+
export function missingTarget(observation) {
|
|
21
|
+
const candidates = observation.roleCandidateCount ?? 0;
|
|
22
|
+
const unnamed = candidates > 0 && observation.unnamedRoleCandidateCount === candidates;
|
|
23
|
+
const within = observation.timeoutMs === undefined ? "within the timeout" : `within the ${observation.timeoutMs} ms operation timeout`;
|
|
24
|
+
const role = observation.role ?? "element";
|
|
25
|
+
return new RunFailure({
|
|
26
|
+
category: "TARGET_NOT_FOUND",
|
|
27
|
+
expected: observation.role
|
|
28
|
+
? `One ${observation.role} with the requested accessible name.`
|
|
29
|
+
: "One control with the requested label.",
|
|
30
|
+
observed: unnamed
|
|
31
|
+
? candidates === 1
|
|
32
|
+
? `No exact match. The only ${role} in scope had an empty accessible name.`
|
|
33
|
+
: `No exact match. All ${candidates} ${role} elements in scope had an empty accessible name.`
|
|
34
|
+
: observation.nearMatches?.length
|
|
35
|
+
? `No exact match ${within}. Similar targets were on the page.`
|
|
36
|
+
: `No exact match ${within}. The cause is uncertain.`,
|
|
37
|
+
investigation: unnamed
|
|
38
|
+
? "Check whether an unnamed control is the intended target and inspect how its label is associated."
|
|
39
|
+
: observation.nearMatches?.length
|
|
40
|
+
? "Compare the requested role and name with the similar targets recorded on the page. Names match exactly, including case."
|
|
41
|
+
: `${INSPECT_TARGET} ${IF_LATER}`,
|
|
42
|
+
observation,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
export function ambiguousTarget(matchCount) {
|
|
46
|
+
return new RunFailure({
|
|
47
|
+
category: "TARGET_AMBIGUOUS",
|
|
48
|
+
expected: "One exact semantic match.",
|
|
49
|
+
observed: `${matchCount} elements matched the same semantic locator.`,
|
|
50
|
+
investigation: "Inspect the matching elements and give the intended control a distinct accessible name.",
|
|
51
|
+
observation: { matchCount },
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export function navigationFailure(observation) {
|
|
55
|
+
return new RunFailure({
|
|
56
|
+
category: "NAVIGATION_FAILURE",
|
|
57
|
+
expected: "A successful HTTP(S) navigation on an allowed host.",
|
|
58
|
+
observed: navigationObservation(observation),
|
|
59
|
+
...(observation.disallowedHost !== undefined ? {
|
|
60
|
+
investigation: "If the site redirects to this host and you trust it, add it to allowedHosts or start from it directly.",
|
|
61
|
+
} : {}),
|
|
62
|
+
observation,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function navigationObservation(observation) {
|
|
66
|
+
if (observation.disallowedHost !== undefined)
|
|
67
|
+
return "The page attempted to navigate outside the allowed hosts.";
|
|
68
|
+
if (observation.httpStatus !== undefined)
|
|
69
|
+
return `The destination returned HTTP ${observation.httpStatus}.`;
|
|
70
|
+
return "Chromium could not load the destination.";
|
|
71
|
+
}
|
|
72
|
+
export function classifyError(error, location, browserClosed, observation = {}) {
|
|
73
|
+
if (error instanceof RunFailure)
|
|
74
|
+
return error.details;
|
|
75
|
+
if (browserClosed || location.phase === "startup") {
|
|
76
|
+
return {
|
|
77
|
+
category: "BROWSER_ERROR",
|
|
78
|
+
expected: "A usable Chromium session.",
|
|
79
|
+
observed: browserClosed ? "The browser or page closed during execution." : "Chromium could not be initialized.",
|
|
80
|
+
investigation: "Check the Chromium installation and whether the browser process exited.",
|
|
81
|
+
observation: browserClosed ? { errorKind: "browser_closed" } : {},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (error instanceof Error && error.message.includes("strict mode violation")) {
|
|
85
|
+
const count = observation.matchCount;
|
|
86
|
+
if (count !== undefined && count > 1)
|
|
87
|
+
return ambiguousTarget(count).details;
|
|
88
|
+
return {
|
|
89
|
+
category: "TARGET_AMBIGUOUS",
|
|
90
|
+
expected: "One exact semantic match.",
|
|
91
|
+
observed: "Playwright reported multiple matching targets while executing the action.",
|
|
92
|
+
investigation: "Inspect how the matching controls are named during the action.",
|
|
93
|
+
observation: { ...observation, errorKind: "strict" },
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (error instanceof errors.TimeoutError) {
|
|
97
|
+
const action = location.phase === "step" ? location.action : undefined;
|
|
98
|
+
const interactable = action === "click" || action === "fill" || action === "select" || action === "press";
|
|
99
|
+
if (interactable && observation.matchCount === 1 &&
|
|
100
|
+
(observation.visible === false || observation.enabled === false || observation.editable === false)) {
|
|
101
|
+
return {
|
|
102
|
+
category: "TARGET_NOT_INTERACTABLE",
|
|
103
|
+
expected: "The matched target can receive the requested action.",
|
|
104
|
+
observed: "The action timed out. The target was then observed to be hidden, disabled, or read-only.",
|
|
105
|
+
investigation: "Inspect the recorded target state and the conditions that enable the control.",
|
|
106
|
+
observation: { ...observation, errorKind: "timeout", timeoutScope: "operation" },
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
category: "TIMEOUT",
|
|
111
|
+
expected: "The operation completes within the configured timeout.",
|
|
112
|
+
observed: "The operation exceeded its timeout.",
|
|
113
|
+
observation: { ...observation, errorKind: "timeout", timeoutScope: "operation" },
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (location.phase === "step" && location.action === "navigate" &&
|
|
117
|
+
error instanceof Error && error.message.includes("net::ERR_")) {
|
|
118
|
+
return navigationFailure({ errorKind: "navigation" }).details;
|
|
119
|
+
}
|
|
120
|
+
if (error instanceof Error && /not an? (?:<input>.*<textarea>|<select>|input|select|editable)/i.test(error.message)) {
|
|
121
|
+
return {
|
|
122
|
+
category: "TARGET_NOT_INTERACTABLE",
|
|
123
|
+
expected: "The target supports the requested action.",
|
|
124
|
+
observed: "Playwright rejected the target's control type for this action.",
|
|
125
|
+
observation: { ...observation, errorKind: "unsupported_target" },
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
category: "UNKNOWN",
|
|
130
|
+
expected: "The operation completes without an execution error.",
|
|
131
|
+
observed: "The operation threw an error without sufficient evidence for a more specific category.",
|
|
132
|
+
observation: { ...observation, errorKind: "unclassified" },
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
export function diffOperation(phase, a, b, baseline, candidate) {
|
|
2
|
+
const differences = [];
|
|
3
|
+
function value(detail, entry) {
|
|
4
|
+
if (!entry)
|
|
5
|
+
return undefined;
|
|
6
|
+
const result = entry.result;
|
|
7
|
+
const failure = detail.result?.status === "failed" && detail.result.failure.location.phase === phase &&
|
|
8
|
+
detail.result.failure.location.index === entry.index ? detail.result.failure : undefined;
|
|
9
|
+
const planned = phase === "step" ? detail.plan?.steps[entry.index] : detail.plan?.assertions[entry.index];
|
|
10
|
+
const observed = detail.operations?.operations.find((item) => item.phase === phase && item.index === entry.index)?.observation;
|
|
11
|
+
const snapshots = detail.snapshots?.find((item) => item.phase === phase && item.index === entry.index);
|
|
12
|
+
const manifestEvidence = result?.evidence.map((ref) => {
|
|
13
|
+
const issue = detail.evidenceAvailability?.issues.find((item) => item.path === ref.path);
|
|
14
|
+
return `${ref.kind} (${issue?.reason ?? (detail.evidenceAvailability ? "readable" : "unchecked")})`;
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
kind: planned?.kind ?? (result && ("action" in result ? result.action : result.assertion)),
|
|
18
|
+
target: planned?.target, observation: observed ?? failure?.observation,
|
|
19
|
+
failure, snapshots, result, manifestEvidence, expectation: planned?.expectation ?? failure?.expected,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const left = value(baseline, a);
|
|
23
|
+
const right = value(candidate, b);
|
|
24
|
+
function add(field, l, r, file, pointer, sourceFor) {
|
|
25
|
+
const sources = [
|
|
26
|
+
...(l !== undefined && a ? [{ runId: baseline.summary.runId, ...(sourceFor?.(baseline, a) ?? { path: file, pointer: pointer(a) }) }] : []),
|
|
27
|
+
...(r !== undefined && b ? [{ runId: candidate.summary.runId, ...(sourceFor?.(candidate, b) ?? { path: file, pointer: pointer(b) }) }] : []),
|
|
28
|
+
];
|
|
29
|
+
if (!sources.length)
|
|
30
|
+
return;
|
|
31
|
+
const text = (entry) => entry === undefined ? undefined : typeof entry === "string" ? entry : JSON.stringify(entry);
|
|
32
|
+
differences.push({ field, baseline: text(l), candidate: text(r), sources, changed: l !== undefined && r !== undefined && text(l) !== text(r) });
|
|
33
|
+
}
|
|
34
|
+
const resultPointer = (entry) => `/${phase === "step" ? "steps" : "assertions"}/${entry.index}`;
|
|
35
|
+
const planPointer = resultPointer;
|
|
36
|
+
add("action", left?.kind, right?.kind, "plan.json", planPointer, (detail, entry) => ({
|
|
37
|
+
path: detail.plan ? "plan.json" : "result.json",
|
|
38
|
+
pointer: resultPointer(entry) + (detail.plan ? "/kind" : phase === "step" ? "/action" : "/assertion"),
|
|
39
|
+
}));
|
|
40
|
+
add("targetRole", left?.target?.role, right?.target?.role, "plan.json", (entry) => planPointer(entry) + "/target/role");
|
|
41
|
+
add("targetName", left?.target?.nameState ? undefined : left?.target?.name, right?.target?.nameState ? undefined : right?.target?.name, "plan.json", (entry) => planPointer(entry) + "/target/name");
|
|
42
|
+
// Failures in legacy runs use result.json. New samples use operations.json.
|
|
43
|
+
const observationSources = (detail, entry, count) => count === undefined || !entry ? [] : [{
|
|
44
|
+
runId: detail.summary.runId,
|
|
45
|
+
path: detail.operations ? "operations.json" : "result.json",
|
|
46
|
+
pointer: detail.operations ? `/operations/${detail.operations.operations.findIndex((item) => item.phase === phase && item.index === entry.index)}/observation/matchCount`
|
|
47
|
+
: "/failure/observation/matchCount",
|
|
48
|
+
}];
|
|
49
|
+
const lCount = left?.observation?.matchCount;
|
|
50
|
+
const rCount = right?.observation?.matchCount;
|
|
51
|
+
const countSources = [...observationSources(baseline, a, lCount), ...observationSources(candidate, b, rCount)];
|
|
52
|
+
if (countSources.length)
|
|
53
|
+
differences.push({
|
|
54
|
+
field: "targetCardinality", baseline: lCount === undefined ? undefined : String(lCount),
|
|
55
|
+
candidate: rCount === undefined ? undefined : String(rCount), sources: countSources,
|
|
56
|
+
changed: lCount !== undefined && rCount !== undefined && lCount !== rCount,
|
|
57
|
+
});
|
|
58
|
+
add("outcome", left?.result?.status, right?.result?.status, "result.json", (entry) => resultPointer(entry) + "/status");
|
|
59
|
+
add("expected", left?.expectation, right?.expectation, "result.json", () => "/failure/expected", (detail, entry) => {
|
|
60
|
+
const planned = (phase === "step" ? detail.plan?.steps : detail.plan?.assertions)?.[entry.index];
|
|
61
|
+
return planned?.expectation ? { path: "plan.json", pointer: planPointer(entry) + "/expectation" }
|
|
62
|
+
: { path: "result.json", pointer: "/failure/expected" };
|
|
63
|
+
});
|
|
64
|
+
const observedText = (side) => side?.failure?.observed ?? (side?.result?.status === "passed"
|
|
65
|
+
? phase === "assertion" ? "Independent assertion satisfied." : "Action completed."
|
|
66
|
+
: side?.result?.status === "cancelled" ? "Operation interrupted." : undefined);
|
|
67
|
+
add("observed", observedText(left), observedText(right), "result.json", () => "/failure/observed", (detail, entry) => ({
|
|
68
|
+
path: "result.json", pointer: detail.result?.status === "failed" && detail.result.failure.location.phase === phase &&
|
|
69
|
+
detail.result.failure.location.index === entry.index ? "/failure/observed" : resultPointer(entry) + "/status",
|
|
70
|
+
}));
|
|
71
|
+
add("failure", left?.result && (left.failure?.category ?? "No failure recorded"), right?.result && (right.failure?.category ?? "No failure recorded"), "result.json", () => "/failure", (detail, entry) => ({
|
|
72
|
+
path: "result.json",
|
|
73
|
+
pointer: detail.result?.status === "failed" && detail.result.failure.location.phase === phase &&
|
|
74
|
+
detail.result.failure.location.index === entry.index ? "/failure/category" : resultPointer(entry) + "/status",
|
|
75
|
+
}));
|
|
76
|
+
add("evidence", left?.manifestEvidence, right?.manifestEvidence, "result.json", (entry) => resultPointer(entry) + "/evidence");
|
|
77
|
+
add("timing", left?.result?.durationMs, right?.result?.durationMs, "result.json", (entry) => resultPointer(entry) + "/durationMs");
|
|
78
|
+
const names = (side) => side?.snapshots?.nodes
|
|
79
|
+
.filter((node) => !node.nameState).map((node) => node.name);
|
|
80
|
+
const lNames = names(left);
|
|
81
|
+
const rNames = names(right);
|
|
82
|
+
const sources = [baseline, candidate].flatMap((detail, side) => {
|
|
83
|
+
const snapshot = (side === 0 ? left : right)?.snapshots;
|
|
84
|
+
return snapshot ? [{ runId: detail.summary.runId, path: snapshot.path, pointer: "/nodes" }] : [];
|
|
85
|
+
});
|
|
86
|
+
if (sources.length)
|
|
87
|
+
differences.push({
|
|
88
|
+
field: "accessibleNames", baseline: lNames?.length ? JSON.stringify(lNames) : undefined,
|
|
89
|
+
candidate: rNames?.length ? JSON.stringify(rNames) : undefined, sources,
|
|
90
|
+
changed: Boolean(lNames?.length && rNames?.length && JSON.stringify(lNames) !== JSON.stringify(rNames)),
|
|
91
|
+
});
|
|
92
|
+
return differences;
|
|
93
|
+
}
|