@tooluminati/testing 0.1.0
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 +21 -0
- package/dist/browser-helpers-RSQLRHHZ.js +8 -0
- package/dist/browser-helpers.d.ts +6 -0
- package/dist/browser-helpers.d.ts.map +1 -0
- package/dist/browser-helpers.js +23 -0
- package/dist/chunk-6YAIOYYZ.js +30 -0
- package/dist/chunk-EG3BG65X.js +146 -0
- package/dist/comparative-proof-QUN7C3KM.js +11 -0
- package/dist/comparative-proof.d.ts +22 -0
- package/dist/comparative-proof.d.ts.map +1 -0
- package/dist/comparative-proof.js +29 -0
- package/dist/devtools-mcp-helper.d.ts +17 -0
- package/dist/devtools-mcp-helper.d.ts.map +1 -0
- package/dist/devtools-mcp-helper.js +34 -0
- package/dist/dom-only-inspection.d.ts +13 -0
- package/dist/dom-only-inspection.d.ts.map +1 -0
- package/dist/dom-only-inspection.js +86 -0
- package/dist/dom-only-inspection.test.d.ts +2 -0
- package/dist/dom-only-inspection.test.d.ts.map +1 -0
- package/dist/dom-only-inspection.test.js +25 -0
- package/dist/index.cjs +473 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +245 -0
- package/dist/install-model-context-mock.d.ts +3 -0
- package/dist/install-model-context-mock.d.ts.map +1 -0
- package/dist/install-model-context-mock.js +10 -0
- package/dist/mock-model-context.d.ts +14 -0
- package/dist/mock-model-context.d.ts.map +1 -0
- package/dist/mock-model-context.js +45 -0
- package/dist/model-context-mock-script.d.ts +2 -0
- package/dist/model-context-mock-script.d.ts.map +1 -0
- package/dist/model-context-mock-script.js +40 -0
- package/dist/webmcp-evals.d.ts +32 -0
- package/dist/webmcp-evals.d.ts.map +1 -0
- package/dist/webmcp-evals.js +81 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jitterbox
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export interface WebMcpTestPage {
|
|
2
|
+
evaluate<T, A>(callback: (arg: A) => T | Promise<T>, arg: A): Promise<T>;
|
|
3
|
+
}
|
|
4
|
+
export declare function expectWebMcpTool(page: WebMcpTestPage, name: string): Promise<void>;
|
|
5
|
+
export declare function invokeWebMcpTool<T>(page: WebMcpTestPage, name: string, args: unknown): Promise<T>;
|
|
6
|
+
//# sourceMappingURL=browser-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-helpers.d.ts","sourceRoot":"","sources":["../src/browser-helpers.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,CAAC,EAAE,CAAC,EACX,QAAQ,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,EACpC,GAAG,EAAE,CAAC,GACL,OAAO,CAAC,CAAC,CAAC,CAAC;CACf;AAED,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,IAAI,CAAC,CAef;AAED,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,GACZ,OAAO,CAAC,CAAC,CAAC,CAoBZ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export async function expectWebMcpTool(page, name) {
|
|
2
|
+
const exists = await page.evaluate(async (toolName) => {
|
|
3
|
+
const context = document
|
|
4
|
+
.modelContext;
|
|
5
|
+
const tools = (await context?.getTools?.()) ?? [];
|
|
6
|
+
return tools.some((tool) => tool.name === toolName);
|
|
7
|
+
}, name);
|
|
8
|
+
if (!exists) {
|
|
9
|
+
throw new Error(`Expected WebMCP tool "${name}" to be registered.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export async function invokeWebMcpTool(page, name, args) {
|
|
13
|
+
return page.evaluate(async ({ toolName, input }) => {
|
|
14
|
+
const context = document
|
|
15
|
+
.modelContext;
|
|
16
|
+
const tools = (await context?.getTools?.()) ?? [];
|
|
17
|
+
const tool = tools.find((candidate) => candidate.name === toolName);
|
|
18
|
+
if (!tool || !context?.executeTool) {
|
|
19
|
+
throw new Error(`WebMCP tool "${toolName}" cannot be invoked.`);
|
|
20
|
+
}
|
|
21
|
+
return context.executeTool(tool, JSON.stringify(input));
|
|
22
|
+
}, { toolName: name, input: args });
|
|
23
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/browser-helpers.ts
|
|
2
|
+
async function expectWebMcpTool(page, name) {
|
|
3
|
+
const exists = await page.evaluate(async (toolName) => {
|
|
4
|
+
const context = document.modelContext;
|
|
5
|
+
const tools = await context?.getTools?.() ?? [];
|
|
6
|
+
return tools.some((tool) => tool.name === toolName);
|
|
7
|
+
}, name);
|
|
8
|
+
if (!exists) {
|
|
9
|
+
throw new Error(`Expected WebMCP tool "${name}" to be registered.`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
async function invokeWebMcpTool(page, name, args) {
|
|
13
|
+
return page.evaluate(
|
|
14
|
+
async ({ toolName, input }) => {
|
|
15
|
+
const context = document.modelContext;
|
|
16
|
+
const tools = await context?.getTools?.() ?? [];
|
|
17
|
+
const tool = tools.find((candidate) => candidate.name === toolName);
|
|
18
|
+
if (!tool || !context?.executeTool) {
|
|
19
|
+
throw new Error(`WebMCP tool "${toolName}" cannot be invoked.`);
|
|
20
|
+
}
|
|
21
|
+
return context.executeTool(tool, JSON.stringify(input));
|
|
22
|
+
},
|
|
23
|
+
{ toolName: name, input: args }
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
expectWebMcpTool,
|
|
29
|
+
invokeWebMcpTool
|
|
30
|
+
};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import {
|
|
2
|
+
invokeWebMcpTool
|
|
3
|
+
} from "./chunk-6YAIOYYZ.js";
|
|
4
|
+
|
|
5
|
+
// src/dom-only-inspection.ts
|
|
6
|
+
function pushUnique(target, value) {
|
|
7
|
+
const trimmed = value?.trim();
|
|
8
|
+
if (!trimmed || target.includes(trimmed)) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
target.push(trimmed);
|
|
12
|
+
}
|
|
13
|
+
function collectDisabledActionReasonsFromDom(root, buttonLabel) {
|
|
14
|
+
const buttons = [...root.querySelectorAll("button")];
|
|
15
|
+
const button = buttons.find(
|
|
16
|
+
(candidate) => candidate.textContent?.includes(buttonLabel)
|
|
17
|
+
);
|
|
18
|
+
if (!button) {
|
|
19
|
+
return {
|
|
20
|
+
label: buttonLabel,
|
|
21
|
+
disabled: false,
|
|
22
|
+
visibleBlockerReasons: []
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const visibleBlockerReasons = [];
|
|
26
|
+
pushUnique(visibleBlockerReasons, button.getAttribute("title"));
|
|
27
|
+
pushUnique(
|
|
28
|
+
visibleBlockerReasons,
|
|
29
|
+
button.getAttribute("aria-label")?.includes("because") ? button.getAttribute("aria-label") : null
|
|
30
|
+
);
|
|
31
|
+
const describedBy = button.getAttribute("aria-describedby");
|
|
32
|
+
if (describedBy) {
|
|
33
|
+
for (const id of describedBy.split(/\s+/)) {
|
|
34
|
+
pushUnique(
|
|
35
|
+
visibleBlockerReasons,
|
|
36
|
+
root.getElementById(id)?.textContent
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const fieldset = button.closest("fieldset");
|
|
41
|
+
if (fieldset) {
|
|
42
|
+
pushUnique(
|
|
43
|
+
visibleBlockerReasons,
|
|
44
|
+
fieldset.querySelector("legend")?.textContent
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
const row = button.closest('[data-testid="checkout-row"]');
|
|
48
|
+
if (row) {
|
|
49
|
+
pushUnique(
|
|
50
|
+
visibleBlockerReasons,
|
|
51
|
+
row.querySelector("[data-dom-blocker-hint]")?.textContent
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
label: buttonLabel,
|
|
56
|
+
disabled: button.disabled,
|
|
57
|
+
visibleBlockerReasons
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async function inspectDisabledActionFromDom(page, buttonLabel) {
|
|
61
|
+
return page.evaluate((label) => {
|
|
62
|
+
const buttons = [...document.querySelectorAll("button")];
|
|
63
|
+
const button = buttons.find(
|
|
64
|
+
(candidate) => candidate.textContent?.includes(label)
|
|
65
|
+
);
|
|
66
|
+
if (!button) {
|
|
67
|
+
return {
|
|
68
|
+
label,
|
|
69
|
+
disabled: false,
|
|
70
|
+
visibleBlockerReasons: []
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const visibleBlockerReasons = [];
|
|
74
|
+
const push = (value) => {
|
|
75
|
+
const trimmed = value?.trim();
|
|
76
|
+
if (trimmed && !visibleBlockerReasons.includes(trimmed)) {
|
|
77
|
+
visibleBlockerReasons.push(trimmed);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
push(button.getAttribute("title"));
|
|
81
|
+
const ariaLabel = button.getAttribute("aria-label");
|
|
82
|
+
if (ariaLabel?.includes("because")) {
|
|
83
|
+
push(ariaLabel);
|
|
84
|
+
}
|
|
85
|
+
const describedBy = button.getAttribute("aria-describedby");
|
|
86
|
+
if (describedBy) {
|
|
87
|
+
for (const id of describedBy.split(/\s+/)) {
|
|
88
|
+
push(document.getElementById(id)?.textContent);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const fieldset = button.closest("fieldset");
|
|
92
|
+
if (fieldset) {
|
|
93
|
+
push(fieldset.querySelector("legend")?.textContent);
|
|
94
|
+
}
|
|
95
|
+
const row = button.closest('[data-testid="checkout-row"]');
|
|
96
|
+
if (row) {
|
|
97
|
+
push(row.querySelector("[data-dom-blocker-hint]")?.textContent);
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
label,
|
|
101
|
+
disabled: button.disabled,
|
|
102
|
+
visibleBlockerReasons
|
|
103
|
+
};
|
|
104
|
+
}, buttonLabel);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// src/comparative-proof.ts
|
|
108
|
+
async function diagnoseCheckoutBlockerFromDomOnly(page, buttonLabel) {
|
|
109
|
+
return inspectDisabledActionFromDom(page, buttonLabel);
|
|
110
|
+
}
|
|
111
|
+
async function diagnoseCheckoutBlockerFromWebMcp(page, actionId, toolName = "why_is_action_unavailable") {
|
|
112
|
+
const result = await invokeWebMcpTool(page, toolName, { actionId });
|
|
113
|
+
return {
|
|
114
|
+
actionId: result.actionId,
|
|
115
|
+
available: result.available,
|
|
116
|
+
reasons: result.reasons ?? []
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async function runComparativeProof(page, options) {
|
|
120
|
+
const domOnly = await diagnoseCheckoutBlockerFromDomOnly(
|
|
121
|
+
page,
|
|
122
|
+
options.buttonLabel
|
|
123
|
+
);
|
|
124
|
+
const webMcp = await diagnoseCheckoutBlockerFromWebMcp(
|
|
125
|
+
page,
|
|
126
|
+
options.actionId,
|
|
127
|
+
options.toolName
|
|
128
|
+
);
|
|
129
|
+
const domBlockerCount = domOnly.visibleBlockerReasons.length;
|
|
130
|
+
const webMcpBlockerCount = webMcp.reasons.length;
|
|
131
|
+
return {
|
|
132
|
+
domOnly,
|
|
133
|
+
webMcp,
|
|
134
|
+
domBlockerCount,
|
|
135
|
+
webMcpBlockerCount,
|
|
136
|
+
webMcpIsStrictlyMoreInformative: domOnly.disabled && domBlockerCount === 0 && webMcpBlockerCount > 0 && !webMcp.available
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export {
|
|
141
|
+
collectDisabledActionReasonsFromDom,
|
|
142
|
+
inspectDisabledActionFromDom,
|
|
143
|
+
diagnoseCheckoutBlockerFromDomOnly,
|
|
144
|
+
diagnoseCheckoutBlockerFromWebMcp,
|
|
145
|
+
runComparativeProof
|
|
146
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
diagnoseCheckoutBlockerFromDomOnly,
|
|
3
|
+
diagnoseCheckoutBlockerFromWebMcp,
|
|
4
|
+
runComparativeProof
|
|
5
|
+
} from "./chunk-EG3BG65X.js";
|
|
6
|
+
import "./chunk-6YAIOYYZ.js";
|
|
7
|
+
export {
|
|
8
|
+
diagnoseCheckoutBlockerFromDomOnly,
|
|
9
|
+
diagnoseCheckoutBlockerFromWebMcp,
|
|
10
|
+
runComparativeProof
|
|
11
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { invokeWebMcpTool } from './browser-helpers';
|
|
2
|
+
import { inspectDisabledActionFromDom, type DisabledActionDomFinding } from './dom-only-inspection';
|
|
3
|
+
export interface WebMcpActionDiagnosis {
|
|
4
|
+
actionId: string;
|
|
5
|
+
available: boolean;
|
|
6
|
+
reasons: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface ComparativeProofResult {
|
|
9
|
+
domOnly: DisabledActionDomFinding;
|
|
10
|
+
webMcp: WebMcpActionDiagnosis;
|
|
11
|
+
domBlockerCount: number;
|
|
12
|
+
webMcpBlockerCount: number;
|
|
13
|
+
webMcpIsStrictlyMoreInformative: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function diagnoseCheckoutBlockerFromDomOnly(page: Parameters<typeof inspectDisabledActionFromDom>[0], buttonLabel: string): Promise<DisabledActionDomFinding>;
|
|
16
|
+
export declare function diagnoseCheckoutBlockerFromWebMcp(page: Parameters<typeof invokeWebMcpTool>[0], actionId: string, toolName?: string): Promise<WebMcpActionDiagnosis>;
|
|
17
|
+
export declare function runComparativeProof(page: Parameters<typeof inspectDisabledActionFromDom>[0], options: {
|
|
18
|
+
buttonLabel: string;
|
|
19
|
+
actionId: string;
|
|
20
|
+
toolName?: string;
|
|
21
|
+
}): Promise<ComparativeProofResult>;
|
|
22
|
+
//# sourceMappingURL=comparative-proof.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comparative-proof.d.ts","sourceRoot":"","sources":["../src/comparative-proof.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EACL,4BAA4B,EAC5B,KAAK,wBAAwB,EAC9B,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,wBAAwB,CAAC;IAClC,MAAM,EAAE,qBAAqB,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,+BAA+B,EAAE,OAAO,CAAC;CAC1C;AAED,wBAAsB,kCAAkC,CACtD,IAAI,EAAE,UAAU,CAAC,OAAO,4BAA4B,CAAC,CAAC,CAAC,CAAC,EACxD,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,wBAAwB,CAAC,CAEnC;AAED,wBAAsB,iCAAiC,CACrD,IAAI,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,EAC5C,QAAQ,EAAE,MAAM,EAChB,QAAQ,SAA8B,GACrC,OAAO,CAAC,qBAAqB,CAAC,CAYhC;AAED,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,UAAU,CAAC,OAAO,4BAA4B,CAAC,CAAC,CAAC,CAAC,EACxD,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GACA,OAAO,CAAC,sBAAsB,CAAC,CAyBjC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { invokeWebMcpTool } from './browser-helpers';
|
|
2
|
+
import { inspectDisabledActionFromDom, } from './dom-only-inspection';
|
|
3
|
+
export async function diagnoseCheckoutBlockerFromDomOnly(page, buttonLabel) {
|
|
4
|
+
return inspectDisabledActionFromDom(page, buttonLabel);
|
|
5
|
+
}
|
|
6
|
+
export async function diagnoseCheckoutBlockerFromWebMcp(page, actionId, toolName = 'why_is_action_unavailable') {
|
|
7
|
+
const result = await invokeWebMcpTool(page, toolName, { actionId });
|
|
8
|
+
return {
|
|
9
|
+
actionId: result.actionId,
|
|
10
|
+
available: result.available,
|
|
11
|
+
reasons: result.reasons ?? [],
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export async function runComparativeProof(page, options) {
|
|
15
|
+
const domOnly = await diagnoseCheckoutBlockerFromDomOnly(page, options.buttonLabel);
|
|
16
|
+
const webMcp = await diagnoseCheckoutBlockerFromWebMcp(page, options.actionId, options.toolName);
|
|
17
|
+
const domBlockerCount = domOnly.visibleBlockerReasons.length;
|
|
18
|
+
const webMcpBlockerCount = webMcp.reasons.length;
|
|
19
|
+
return {
|
|
20
|
+
domOnly,
|
|
21
|
+
webMcp,
|
|
22
|
+
domBlockerCount,
|
|
23
|
+
webMcpBlockerCount,
|
|
24
|
+
webMcpIsStrictlyMoreInformative: domOnly.disabled &&
|
|
25
|
+
domBlockerCount === 0 &&
|
|
26
|
+
webMcpBlockerCount > 0 &&
|
|
27
|
+
!webMcp.available,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface WebMcpToolListing {
|
|
2
|
+
name: string;
|
|
3
|
+
description?: string | undefined;
|
|
4
|
+
}
|
|
5
|
+
type ModelContextHost = Document | Navigator;
|
|
6
|
+
/**
|
|
7
|
+
* Lists registered WebMCP tools from the browser model context.
|
|
8
|
+
* Returns an empty array when WebMCP is unavailable (e.g. CI without Chrome 149).
|
|
9
|
+
*/
|
|
10
|
+
export declare function listWebMcpTools(host?: ModelContextHost): Promise<WebMcpToolListing[]>;
|
|
11
|
+
/**
|
|
12
|
+
* Executes a registered WebMCP tool by name.
|
|
13
|
+
* Throws when WebMCP is unavailable or the tool cannot be resolved.
|
|
14
|
+
*/
|
|
15
|
+
export declare function executeWebMcpTool(name: string, args?: unknown, host?: ModelContextHost): Promise<unknown>;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=devtools-mcp-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools-mcp-helper.d.ts","sourceRoot":"","sources":["../src/devtools-mcp-helper.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAClC;AAED,KAAK,gBAAgB,GAAG,QAAQ,GAAG,SAAS,CAAC;AAsB7C;;;GAGG;AACH,wBAAsB,eAAe,CACnC,IAAI,GAAE,gBAA2B,GAChC,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAW9B;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,OAAY,EAClB,IAAI,GAAE,gBAA2B,GAChC,OAAO,CAAC,OAAO,CAAC,CAelB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
function getModelContext(host = document) {
|
|
2
|
+
return host.modelContext;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Lists registered WebMCP tools from the browser model context.
|
|
6
|
+
* Returns an empty array when WebMCP is unavailable (e.g. CI without Chrome 149).
|
|
7
|
+
*/
|
|
8
|
+
export async function listWebMcpTools(host = document) {
|
|
9
|
+
const context = getModelContext(host);
|
|
10
|
+
if (!context?.getTools) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
const tools = await context.getTools();
|
|
14
|
+
return tools.map((tool) => ({
|
|
15
|
+
name: tool.name,
|
|
16
|
+
description: tool.description,
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Executes a registered WebMCP tool by name.
|
|
21
|
+
* Throws when WebMCP is unavailable or the tool cannot be resolved.
|
|
22
|
+
*/
|
|
23
|
+
export async function executeWebMcpTool(name, args = {}, host = document) {
|
|
24
|
+
const context = getModelContext(host);
|
|
25
|
+
if (!context?.getTools || !context.executeTool) {
|
|
26
|
+
throw new Error('WebMCP model context is unavailable. Use installModelContextMock() in tests.');
|
|
27
|
+
}
|
|
28
|
+
const tools = await context.getTools();
|
|
29
|
+
const tool = tools.find((candidate) => candidate.name === name);
|
|
30
|
+
if (!tool) {
|
|
31
|
+
throw new Error(`WebMCP tool not found: ${name}`);
|
|
32
|
+
}
|
|
33
|
+
return context.executeTool(tool, JSON.stringify(args));
|
|
34
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simulates what a DOM-only agent can infer about disabled actions.
|
|
3
|
+
* Mirrors accessibility-tree inspection: labels, aria-* , title, nearby text.
|
|
4
|
+
*/
|
|
5
|
+
import type { WebMcpTestPage } from './browser-helpers';
|
|
6
|
+
export interface DisabledActionDomFinding {
|
|
7
|
+
label: string;
|
|
8
|
+
disabled: boolean;
|
|
9
|
+
visibleBlockerReasons: string[];
|
|
10
|
+
}
|
|
11
|
+
export declare function collectDisabledActionReasonsFromDom(root: Pick<Document, 'querySelectorAll' | 'getElementById'>, buttonLabel: string): DisabledActionDomFinding;
|
|
12
|
+
export declare function inspectDisabledActionFromDom(page: WebMcpTestPage, buttonLabel: string): Promise<DisabledActionDomFinding>;
|
|
13
|
+
//# sourceMappingURL=dom-only-inspection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-only-inspection.d.ts","sourceRoot":"","sources":["../src/dom-only-inspection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,OAAO,CAAC;IAClB,qBAAqB,EAAE,MAAM,EAAE,CAAC;CACjC;AAWD,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,kBAAkB,GAAG,gBAAgB,CAAC,EAC3D,WAAW,EAAE,MAAM,GAClB,wBAAwB,CAsD1B;AAED,wBAAsB,4BAA4B,CAChD,IAAI,EAAE,cAAc,EACpB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,wBAAwB,CAAC,CAoDnC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
function pushUnique(target, value) {
|
|
2
|
+
const trimmed = value?.trim();
|
|
3
|
+
if (!trimmed || target.includes(trimmed)) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
target.push(trimmed);
|
|
7
|
+
}
|
|
8
|
+
export function collectDisabledActionReasonsFromDom(root, buttonLabel) {
|
|
9
|
+
const buttons = [...root.querySelectorAll('button')];
|
|
10
|
+
const button = buttons.find((candidate) => candidate.textContent?.includes(buttonLabel));
|
|
11
|
+
if (!button) {
|
|
12
|
+
return {
|
|
13
|
+
label: buttonLabel,
|
|
14
|
+
disabled: false,
|
|
15
|
+
visibleBlockerReasons: [],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const visibleBlockerReasons = [];
|
|
19
|
+
pushUnique(visibleBlockerReasons, button.getAttribute('title'));
|
|
20
|
+
pushUnique(visibleBlockerReasons, button.getAttribute('aria-label')?.includes('because')
|
|
21
|
+
? button.getAttribute('aria-label')
|
|
22
|
+
: null);
|
|
23
|
+
const describedBy = button.getAttribute('aria-describedby');
|
|
24
|
+
if (describedBy) {
|
|
25
|
+
for (const id of describedBy.split(/\s+/)) {
|
|
26
|
+
pushUnique(visibleBlockerReasons, root.getElementById(id)?.textContent);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const fieldset = button.closest('fieldset');
|
|
30
|
+
if (fieldset) {
|
|
31
|
+
pushUnique(visibleBlockerReasons, fieldset.querySelector('legend')?.textContent);
|
|
32
|
+
}
|
|
33
|
+
const row = button.closest('[data-testid="checkout-row"]');
|
|
34
|
+
if (row) {
|
|
35
|
+
pushUnique(visibleBlockerReasons, row.querySelector('[data-dom-blocker-hint]')?.textContent);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
label: buttonLabel,
|
|
39
|
+
disabled: button.disabled,
|
|
40
|
+
visibleBlockerReasons,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export async function inspectDisabledActionFromDom(page, buttonLabel) {
|
|
44
|
+
return page.evaluate((label) => {
|
|
45
|
+
const buttons = [...document.querySelectorAll('button')];
|
|
46
|
+
const button = buttons.find((candidate) => candidate.textContent?.includes(label));
|
|
47
|
+
if (!button) {
|
|
48
|
+
return {
|
|
49
|
+
label,
|
|
50
|
+
disabled: false,
|
|
51
|
+
visibleBlockerReasons: [],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const visibleBlockerReasons = [];
|
|
55
|
+
const push = (value) => {
|
|
56
|
+
const trimmed = value?.trim();
|
|
57
|
+
if (trimmed && !visibleBlockerReasons.includes(trimmed)) {
|
|
58
|
+
visibleBlockerReasons.push(trimmed);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
push(button.getAttribute('title'));
|
|
62
|
+
const ariaLabel = button.getAttribute('aria-label');
|
|
63
|
+
if (ariaLabel?.includes('because')) {
|
|
64
|
+
push(ariaLabel);
|
|
65
|
+
}
|
|
66
|
+
const describedBy = button.getAttribute('aria-describedby');
|
|
67
|
+
if (describedBy) {
|
|
68
|
+
for (const id of describedBy.split(/\s+/)) {
|
|
69
|
+
push(document.getElementById(id)?.textContent);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const fieldset = button.closest('fieldset');
|
|
73
|
+
if (fieldset) {
|
|
74
|
+
push(fieldset.querySelector('legend')?.textContent);
|
|
75
|
+
}
|
|
76
|
+
const row = button.closest('[data-testid="checkout-row"]');
|
|
77
|
+
if (row) {
|
|
78
|
+
push(row.querySelector('[data-dom-blocker-hint]')?.textContent);
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
label,
|
|
82
|
+
disabled: button.disabled,
|
|
83
|
+
visibleBlockerReasons,
|
|
84
|
+
};
|
|
85
|
+
}, buttonLabel);
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-only-inspection.test.d.ts","sourceRoot":"","sources":["../src/dom-only-inspection.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { collectDisabledActionReasonsFromDom } from './dom-only-inspection';
|
|
3
|
+
describe('collectDisabledActionReasonsFromDom', () => {
|
|
4
|
+
it('finds no checkout blockers when none are exposed in the DOM', () => {
|
|
5
|
+
document.body.innerHTML = `
|
|
6
|
+
<section data-testid="checkout-row">
|
|
7
|
+
<p>Status: waiting for customer action.</p>
|
|
8
|
+
<button disabled type="button">Complete checkout</button>
|
|
9
|
+
</section>
|
|
10
|
+
`;
|
|
11
|
+
const finding = collectDisabledActionReasonsFromDom(document, 'Complete checkout');
|
|
12
|
+
expect(finding.disabled).toBe(true);
|
|
13
|
+
expect(finding.visibleBlockerReasons).toEqual([]);
|
|
14
|
+
});
|
|
15
|
+
it('finds visible hints when the DOM exposes them', () => {
|
|
16
|
+
document.body.innerHTML = `
|
|
17
|
+
<section data-testid="checkout-row">
|
|
18
|
+
<p data-dom-blocker-hint>Terms must be accepted first.</p>
|
|
19
|
+
<button disabled type="button">Complete checkout</button>
|
|
20
|
+
</section>
|
|
21
|
+
`;
|
|
22
|
+
const finding = collectDisabledActionReasonsFromDom(document, 'Complete checkout');
|
|
23
|
+
expect(finding.visibleBlockerReasons).toContain('Terms must be accepted first.');
|
|
24
|
+
});
|
|
25
|
+
});
|