waygraph 0.15.21 → 0.15.23
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/auto-explore-run.d.ts +2 -1
- package/dist/auto-explore-run.js +2 -1
- package/dist/auto-session.js +2 -1
- package/dist/cli.js +21 -6067
- package/dist/runner/chain-run.js +102 -0
- package/dist/runner/cursor.js +140 -0
- package/dist/runner/demo-log.js +314 -0
- package/dist/runner/device-stage.js +400 -0
- package/dist/runner/discovery.js +105 -0
- package/dist/runner/index.js +2 -0
- package/dist/runner/interaction-patch.js +353 -0
- package/dist/runner/main.js +397 -0
- package/dist/runner/overlay-css.js +342 -0
- package/dist/runner/overlay-install.js +1301 -0
- package/dist/runner/rings.js +490 -0
- package/dist/runner/seed-mem.js +110 -0
- package/dist/runner/slides.js +272 -0
- package/dist/runner/step-mode.js +776 -0
- package/dist/runner/step-panels.js +723 -0
- package/dist/runner/teardown.js +195 -0
- package/dist/runner/todo-dock.js +142 -0
- package/examples/saucedemo/.waygraph-auto/19b9eee5.log +0 -0
- package/examples/saucedemo/.waygraph-auto/422d4390.log +0 -0
- package/examples/saucedemo/.waygraph-auto/6c9f8e10.log +0 -0
- package/examples/saucedemo/.waygraph-auto/74ce745a.log +0 -0
- package/examples/saucedemo/.waygraph-auto/89477e92.log +0 -0
- package/examples/saucedemo/.waygraph-auto/b7e545f0.log +0 -0
- package/examples/saucedemo/.waygraph-auto/cb2726d7.log +0 -0
- package/package.json +8 -4
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// Moved verbatim from the former CHAIN_RUNNER_SCRIPT template string in cli.ts (see src/ARCHITECTURE.md).
|
|
2
|
+
// Runs inside the target project's own waygraph copy - keep it dependency-light and self-contained.
|
|
3
|
+
import { installOverlay } from "./overlay-install.js";
|
|
4
|
+
import { applyDeviceToPage } from "./device-stage.js";
|
|
5
|
+
import { showRing } from "./rings.js";
|
|
6
|
+
import { formatHighlightCaption } from "../highlights.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Patches Locator.prototype.fill (via any real locator's own prototype
|
|
10
|
+
* chain - Playwright doesn't export the class directly) so every fill(),
|
|
11
|
+
* regardless of how the Block built that locator (page.locator, chained
|
|
12
|
+
* .getByLabel off a scoped form locator, etc.), highlights the real target
|
|
13
|
+
* first, then types it out character by character instead of snapping the
|
|
14
|
+
* whole value in - "when something is written from mem, it should
|
|
15
|
+
* highlight then slowly input." One-time patch (idempotent - guarded so a
|
|
16
|
+
* multi-step chain doesn't re-wrap an already-wrapped fill).
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Called once the gate resolves - manual click OR autoplay timeout, both
|
|
20
|
+
* covered from here rather than duplicating this in the in-page click
|
|
21
|
+
* handler - right before the Block's own act() actually starts. Dan: "i
|
|
22
|
+
* want the button, step is running thing. so i wont be able to interrupt
|
|
23
|
+
* the playwright automation" - the "Run this step" button used to sit
|
|
24
|
+
* there still looking clickable for the entire multi-second duration a
|
|
25
|
+
* real act()/observe() takes, inviting a confusing extra click (harmless -
|
|
26
|
+
* __wgNext no-ops once already consumed - but looked live when it wasn't).
|
|
27
|
+
* Disables the button and mem-key textareas, and swaps whichever gate
|
|
28
|
+
* text was showing (manual button or "Auto-advancing...") to "Running...".
|
|
29
|
+
* ALWAYS collapses the panel while act() runs - leaving it expanded was a
|
|
30
|
+
* real bug: #wg-panel sits at z-index max with pointer-events:auto, so
|
|
31
|
+
* Playwright's login/add-to-cart clicks hit the stepper instead of the app
|
|
32
|
+
* ("subtree intercepts pointer events"). Empty/partial fills + a lucky
|
|
33
|
+
* edge click on Login then produced Sauce Demo's Epic sadface, verify
|
|
34
|
+
* still passed on the error banner, and the next block blew up. Collapse
|
|
35
|
+
* also matches Dan's "step is running / can't interrupt" ask. (_opts kept
|
|
36
|
+
* for call-site compat; autoCollapsePanel is now unconditional.)
|
|
37
|
+
*/
|
|
38
|
+
export async function markStepRunning(page, _opts) {
|
|
39
|
+
await page
|
|
40
|
+
.evaluate(() => {
|
|
41
|
+
const runBtn = document.getElementById("wg-run");
|
|
42
|
+
if (runBtn) {
|
|
43
|
+
runBtn.disabled = true;
|
|
44
|
+
runBtn.textContent = "Running \u25B6";
|
|
45
|
+
}
|
|
46
|
+
const autoEl = document.getElementById("wg-gate-auto");
|
|
47
|
+
if (autoEl) autoEl.textContent = "Running...";
|
|
48
|
+
document.querySelectorAll("#wg-panel textarea[data-key]").forEach((ta) => {
|
|
49
|
+
ta.disabled = true;
|
|
50
|
+
});
|
|
51
|
+
const panel = document.getElementById("wg-panel");
|
|
52
|
+
if (panel) {
|
|
53
|
+
panel.classList.add("wg-collapsed");
|
|
54
|
+
panel.setAttribute("data-wg-collapsed", "1");
|
|
55
|
+
panel.setAttribute("data-wg-phase", "running");
|
|
56
|
+
if (typeof window.__wgStampModal === "function") {
|
|
57
|
+
window.__wgStampModal(panel, "panel", {
|
|
58
|
+
phase: "running",
|
|
59
|
+
ready: true,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
const toggle = panel.querySelector("[data-wg-toggle]");
|
|
63
|
+
if (toggle) toggle.textContent = "Show";
|
|
64
|
+
const titleEl = panel.querySelector(".wg-chrome-title");
|
|
65
|
+
const label = panel.dataset.wgStepLabel;
|
|
66
|
+
if (titleEl && label) titleEl.textContent = label;
|
|
67
|
+
const miniNext = panel.querySelector("[data-wg-mini-next]");
|
|
68
|
+
if (miniNext) {
|
|
69
|
+
miniNext.disabled = true;
|
|
70
|
+
miniNext.classList.remove("wg-mini-next-show");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
.catch(() => {});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Real navigation wipes document + overlay helpers. Reinstall and re-paint
|
|
80
|
+
* carried todos / device / optional stubBefore ring so keep-dock and nav
|
|
81
|
+
* highlights do not vanish until the next ctx.todos() / stubAfter (PIA #15).
|
|
82
|
+
*/
|
|
83
|
+
export async function restoreTheaterAfterNavigation(page, todoDockRef, deviceRef, stubBeforeRef) {
|
|
84
|
+
const needs =
|
|
85
|
+
(await page
|
|
86
|
+
.evaluate(() => !window.__wgSyncTodos || !document.getElementById("wg-ring"))
|
|
87
|
+
.catch(() => true)) || false;
|
|
88
|
+
if (!needs) {
|
|
89
|
+
// Overlay survived (SPA / no full document wipe) - still refresh dock
|
|
90
|
+
// if Node has a carry and the DOM lost .wg-todo-dock.
|
|
91
|
+
const hasDock = await page
|
|
92
|
+
.evaluate(() => !!document.querySelector(".wg-todo-dock, #wg-todo-dock"))
|
|
93
|
+
.catch(() => false);
|
|
94
|
+
if (hasDock || !todoDockRef || !todoDockRef.current) return;
|
|
95
|
+
}
|
|
96
|
+
await installOverlay(page);
|
|
97
|
+
const dock = todoDockRef && todoDockRef.current;
|
|
98
|
+
if (dock) {
|
|
99
|
+
await page
|
|
100
|
+
.evaluate((d) => {
|
|
101
|
+
if (window.__wgSyncTodos) window.__wgSyncTodos({ sync: "set", dock: d });
|
|
102
|
+
}, dock)
|
|
103
|
+
.catch(() => {});
|
|
104
|
+
}
|
|
105
|
+
if (deviceRef && deviceRef.current) {
|
|
106
|
+
await applyDeviceToPage(page, deviceRef.current, "set").catch(() => {});
|
|
107
|
+
}
|
|
108
|
+
// Re-show first matching stubBefore ring if selector still exists (sidebar
|
|
109
|
+
// nav targets often survive the route change).
|
|
110
|
+
const stubs = (stubBeforeRef && stubBeforeRef.current) || [];
|
|
111
|
+
for (const h of stubs) {
|
|
112
|
+
if (!h || !h.selector) continue;
|
|
113
|
+
const box = await page
|
|
114
|
+
.evaluate((sel) => {
|
|
115
|
+
const el = document.querySelector(sel);
|
|
116
|
+
if (!el) return null;
|
|
117
|
+
const r = el.getBoundingClientRect();
|
|
118
|
+
if (r.width < 2 || r.height < 2) return null;
|
|
119
|
+
return { x: r.x, y: r.y, width: r.width, height: r.height };
|
|
120
|
+
}, h.selector)
|
|
121
|
+
.catch(() => null);
|
|
122
|
+
if (box) {
|
|
123
|
+
await showRing(page, box, formatHighlightCaption(h), h.tone || "planned", {
|
|
124
|
+
size: h.size,
|
|
125
|
+
weight: h.weight,
|
|
126
|
+
selector: h.selector,
|
|
127
|
+
focus: !!h.focus,
|
|
128
|
+
}).catch(() => {});
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Removes every overlay element (panel, ring, ring-label, cursor,
|
|
137
|
+
* click-pulse, banner) and stops the live resize/scroll ring tracker, once
|
|
138
|
+
* the whole chain is genuinely done - "I want to see the same page just
|
|
139
|
+
* like the demo opened for the first time," not the last step's panel and
|
|
140
|
+
* highlight ring stuck over the real app forever. installOverlay only ever
|
|
141
|
+
* ADDS these elements back on demand (idempotent, per-page-load) - nothing
|
|
142
|
+
* re-creates them once torn down here unless another Block/fill/click runs.
|
|
143
|
+
*/
|
|
144
|
+
export async function teardownOverlay(page) {
|
|
145
|
+
await page
|
|
146
|
+
.evaluate(() => {
|
|
147
|
+
if (window.__wgRingTrack) {
|
|
148
|
+
window.removeEventListener("resize", window.__wgRingTrack);
|
|
149
|
+
window.removeEventListener("scroll", window.__wgRingTrack, true);
|
|
150
|
+
window.__wgRingTrack = null;
|
|
151
|
+
}
|
|
152
|
+
window.__wgNarrateOwnsRing = false;
|
|
153
|
+
for (const id of [
|
|
154
|
+
"wg-panel",
|
|
155
|
+
"wg-ring",
|
|
156
|
+
"wg-ring-label",
|
|
157
|
+
"wg-cursor",
|
|
158
|
+
"wg-click-pulse",
|
|
159
|
+
"wg-banner",
|
|
160
|
+
"wg-todo-dock",
|
|
161
|
+
"wg-device-shell",
|
|
162
|
+
"wg-device-toast",
|
|
163
|
+
"wg-device-badge",
|
|
164
|
+
]) {
|
|
165
|
+
const el = document.getElementById(id);
|
|
166
|
+
if (el) el.remove();
|
|
167
|
+
}
|
|
168
|
+
document.querySelectorAll(".wg-todo-dock").forEach((el) => el.remove());
|
|
169
|
+
document.documentElement.classList.remove("wg-video-device-stage");
|
|
170
|
+
})
|
|
171
|
+
.catch(() => {});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Clears cookies + storage and re-navigates to a known-fresh page. Shared by
|
|
177
|
+
* the per-block session-reset check below and by the error panel's own
|
|
178
|
+
* "Retry Episode" button - a retry needs the exact same clean slate a normal
|
|
179
|
+
* episode boundary gets, not just re-running the failed block against
|
|
180
|
+
* whatever broken/half-navigated state it left the page in.
|
|
181
|
+
*/
|
|
182
|
+
export async function resetPageState(context, page, baseURL) {
|
|
183
|
+
await context.clearCookies().catch(() => {});
|
|
184
|
+
await page
|
|
185
|
+
.evaluate(() => {
|
|
186
|
+
try {
|
|
187
|
+
localStorage.clear();
|
|
188
|
+
sessionStorage.clear();
|
|
189
|
+
} catch {
|
|
190
|
+
/* storage blocked (e.g. about:blank) - nothing to clear anyway */
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
.catch(() => {});
|
|
194
|
+
await page.goto(baseURL || "about:blank").catch(() => {});
|
|
195
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Moved verbatim from the former CHAIN_RUNNER_SCRIPT template string in cli.ts (see src/ARCHITECTURE.md).
|
|
2
|
+
// Runs inside the target project's own waygraph copy - keep it dependency-light and self-contained.
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { advanceTodoDock } from "../highlights.js";
|
|
5
|
+
import { demoLog } from "./demo-log.js";
|
|
6
|
+
|
|
7
|
+
function todosHtmlFromInfo(info, escFn) {
|
|
8
|
+
const list = info.todos || [];
|
|
9
|
+
if (!list.length) return "";
|
|
10
|
+
return (
|
|
11
|
+
"<ul id=\"wg-todos\">" +
|
|
12
|
+
list
|
|
13
|
+
.map((t) => {
|
|
14
|
+
const cls = t.current ? "wg-todo-current" : t.done ? "wg-todo-done" : "wg-todo-pending";
|
|
15
|
+
const mark = t.done ? "\u2713" : t.current ? "\u2192" : "\u25CB";
|
|
16
|
+
return (
|
|
17
|
+
"<li class=\"" +
|
|
18
|
+
cls +
|
|
19
|
+
"\"><span class=\"wg-todo-mark\">" +
|
|
20
|
+
mark +
|
|
21
|
+
"</span><span>" +
|
|
22
|
+
escFn(t.text || "") +
|
|
23
|
+
"</span></li>"
|
|
24
|
+
);
|
|
25
|
+
})
|
|
26
|
+
.join("") +
|
|
27
|
+
"</ul>"
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
/** Flatten dock items in order (sequential groups). */
|
|
33
|
+
function flattenTodoDockItems(dock) {
|
|
34
|
+
const items = [];
|
|
35
|
+
if (!dock || !dock.groups) return items;
|
|
36
|
+
for (const g of dock.groups) {
|
|
37
|
+
for (const t of g.items || []) items.push(t);
|
|
38
|
+
}
|
|
39
|
+
return items;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Resolve which todo index a matched stub should advance to.
|
|
45
|
+
* Prefer stub.todo / stub.slotId / stub.id against item.id; never jump backward.
|
|
46
|
+
*/
|
|
47
|
+
function resolveTodoAdvanceIndex(dock, stub, stubIndex) {
|
|
48
|
+
const items = flattenTodoDockItems(dock);
|
|
49
|
+
if (!items.length) return stubIndex;
|
|
50
|
+
const curIdx = items.findIndex((t) => t.current);
|
|
51
|
+
let idx = stubIndex;
|
|
52
|
+
const key = stub && (stub.todo || stub.slotId || stub.id);
|
|
53
|
+
if (key) {
|
|
54
|
+
const k = String(key).trim().toLowerCase();
|
|
55
|
+
let found = items.findIndex((t) => t.id && String(t.id).toLowerCase() === k);
|
|
56
|
+
if (found < 0) {
|
|
57
|
+
// username -> login-user, password -> login-pass, submit -> login-submit
|
|
58
|
+
const aliases = {
|
|
59
|
+
username: ["login-user", "user", "email"],
|
|
60
|
+
password: ["login-pass", "pass"],
|
|
61
|
+
submit: ["login-submit", "login", "tap-login"],
|
|
62
|
+
user: ["login-user", "username"],
|
|
63
|
+
pass: ["login-pass", "password"],
|
|
64
|
+
};
|
|
65
|
+
const alts = aliases[k] || [];
|
|
66
|
+
for (const a of alts) {
|
|
67
|
+
found = items.findIndex((t) => t.id && String(t.id).toLowerCase() === a);
|
|
68
|
+
if (found >= 0) break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (found < 0) {
|
|
72
|
+
found = items.findIndex(
|
|
73
|
+
(t) =>
|
|
74
|
+
(t.id && String(t.id).toLowerCase().includes(k)) ||
|
|
75
|
+
(t.text && String(t.text).toLowerCase().includes(k)),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
if (found >= 0) idx = found;
|
|
79
|
+
}
|
|
80
|
+
// Monotonic: never retreat the walkthrough.
|
|
81
|
+
if (curIdx >= 0 && idx < curIdx) idx = curIdx;
|
|
82
|
+
return idx;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
/** Advance sequential todo dock to stubIndex and push to the page (Method act). */
|
|
87
|
+
export async function syncTodoDockAdvance(page, todoDockRef, stubIndex, stub) {
|
|
88
|
+
if (!todoDockRef || stubIndex < 0) return;
|
|
89
|
+
const prev = todoDockRef.current;
|
|
90
|
+
if (!prev) return;
|
|
91
|
+
const idx = resolveTodoAdvanceIndex(prev, stub || null, stubIndex);
|
|
92
|
+
const advanced = advanceTodoDock(prev, idx);
|
|
93
|
+
todoDockRef.current = advanced;
|
|
94
|
+
demoLog(
|
|
95
|
+
" todo advance -> idx=" +
|
|
96
|
+
idx +
|
|
97
|
+
(stub && (stub.slotId || stub.todo)
|
|
98
|
+
? " slot=" + (stub.todo || stub.slotId)
|
|
99
|
+
: " stub#" + stubIndex) +
|
|
100
|
+
' current="' +
|
|
101
|
+
String(
|
|
102
|
+
(flattenTodoDockItems(advanced).find((t) => t.current) || {}).text || "",
|
|
103
|
+
).slice(0, 40) +
|
|
104
|
+
'"',
|
|
105
|
+
);
|
|
106
|
+
await page
|
|
107
|
+
.evaluate((dock) => {
|
|
108
|
+
if (window.__wgSyncTodos) {
|
|
109
|
+
window.__wgSyncTodos({ sync: "set", dock });
|
|
110
|
+
}
|
|
111
|
+
}, advanced)
|
|
112
|
+
.catch(() => {});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export async function probeTodoDocksOnPage(page) {
|
|
116
|
+
return page
|
|
117
|
+
.evaluate(() => {
|
|
118
|
+
const docks = [...document.querySelectorAll(".wg-todo-dock, #wg-todo-dock")];
|
|
119
|
+
return docks.map((el) => {
|
|
120
|
+
const r = el.getBoundingClientRect();
|
|
121
|
+
const items = el.querySelectorAll("li");
|
|
122
|
+
let current = "";
|
|
123
|
+
items.forEach((li) => {
|
|
124
|
+
if (li.classList.contains("wg-todo-current")) {
|
|
125
|
+
current = (li.textContent || "").replace(/s+/g, " ").trim().slice(0, 48);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
return {
|
|
129
|
+
key: el.getAttribute("data-wg-todo-key") || el.id || "?",
|
|
130
|
+
pos: el.dataset.pos || "?",
|
|
131
|
+
top: Math.round(r.top),
|
|
132
|
+
left: Math.round(r.left),
|
|
133
|
+
w: Math.round(r.width),
|
|
134
|
+
h: Math.round(r.height),
|
|
135
|
+
onScreen: r.bottom > 0 && r.right > 0 && r.top < innerHeight && r.left < innerWidth,
|
|
136
|
+
n: items.length,
|
|
137
|
+
current,
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
})
|
|
141
|
+
.catch(() => []);
|
|
142
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "waygraph",
|
|
3
|
-
"version": "0.15.
|
|
3
|
+
"version": "0.15.23",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A typed graph of reusable Blocks for driving a browser through E2E flows.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
12
12
|
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./runner": {
|
|
15
|
+
"default": "./dist/runner/index.js"
|
|
13
16
|
}
|
|
14
17
|
},
|
|
15
18
|
"bin": {
|
|
@@ -34,15 +37,16 @@
|
|
|
34
37
|
"url": "git+https://github.com/deviate-dv8/waygraph.git"
|
|
35
38
|
},
|
|
36
39
|
"scripts": {
|
|
37
|
-
"build": "tsc -p tsconfig.build.json",
|
|
40
|
+
"build": "tsc -p tsconfig.build.json && node scripts/copy-runner.mjs",
|
|
38
41
|
"typecheck": "node bin/waygraph typecheck .",
|
|
39
|
-
"test": "npm run test:unit && playwright test",
|
|
42
|
+
"test": "npm run check:structure && npm run test:unit && playwright test",
|
|
40
43
|
"test:ui": "playwright test --ui",
|
|
41
44
|
"test:unit": "node --import tsx/esm --test tests/unit/*.spec.ts",
|
|
42
45
|
"docs:preview": "python3 -m http.server 4173 --directory docs",
|
|
43
46
|
"example:saucedemo:install": "npm --prefix examples/saucedemo install",
|
|
44
47
|
"example:saucedemo:test": "npm --prefix examples/saucedemo test",
|
|
45
|
-
"example:saucedemo:auto": "npm --prefix examples/saucedemo run auto"
|
|
48
|
+
"example:saucedemo:auto": "npm --prefix examples/saucedemo run auto",
|
|
49
|
+
"check:structure": "node scripts/check-structure.mjs"
|
|
46
50
|
},
|
|
47
51
|
"peerDependencies": {
|
|
48
52
|
"@playwright/test": "^1.40.0"
|