@beyondwork/wb-cli 0.1.39 → 0.1.40
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/CHANGELOG.md +7 -0
- package/out/cli.js +1103 -219
- package/out/extension.js +97 -97
- package/out/headless-host.js +71 -0
- package/package.json +1 -1
- package/wb-cli/skills/bw-workblock/SKILL.md +10 -8
- package/wb-cli/skills/bw-workblock/references/browser-validation.md +166 -78
- package/wb-cli/skills/bw-workblock/references/browser-run.sh +0 -104
- package/wb-cli/skills/bw-workblock/references/validate-ui.mjs +0 -279
|
@@ -1,279 +0,0 @@
|
|
|
1
|
-
// validate-ui.mjs: start a module with Studio's Start button, drive its task UI in the
|
|
2
|
-
// workspace, submit it, and prove the submit landed. Copy it next to your checkout, edit useTheUi(), and run:
|
|
3
|
-
//
|
|
4
|
-
// WORKSPACE_ROOT=<repo> <repo>/bin/node validate-ui.mjs
|
|
5
|
-
//
|
|
6
|
-
// with these environment variables:
|
|
7
|
-
// BW_REPO the monorepo checkout; @playwright/test is loaded from its src/ts/neui
|
|
8
|
-
// (default: WORKSPACE_ROOT)
|
|
9
|
-
// WB_WORKSPACE_URL https://<tenant-host>/w/studio/s/<workspace-id>, from `bin/wb-cli status`
|
|
10
|
-
// (not the /w/studio/detail/<id> page: that one shows no task UI)
|
|
11
|
-
// BW_SAML_COOKIE_FILE file that holds the testcookies output (chmod 600; never print it)
|
|
12
|
-
// SHOTS_DIR where the screenshots go (default: ./shots)
|
|
13
|
-
// WB_START_MODULE the module to start with Studio's Start button, the way a person does;
|
|
14
|
-
// leave it unset when a run already waits at the UI (`bin/wb-cli run`)
|
|
15
|
-
// WB_UI_STEP which UI of the run this is, 1 for the first; useTheUi gets it
|
|
16
|
-
// WB_RESULT the module that ran, after the run has ended: drive no UI, and screenshot
|
|
17
|
-
// the end of the run as Studio shows it, that module's graph and outputs.
|
|
18
|
-
// Run it from the checkout, whose manifest.yaml gives the module's id.
|
|
19
|
-
//
|
|
20
|
-
// Exit codes: 0 submitted or closed, 5 left open (a UI with its own actions and no Submit),
|
|
21
|
-
// 2 login or page problem, 3 submit rejected or Start opened the generic input form, 4 no task
|
|
22
|
-
// UI appeared (with WB_RESULT: no graph appeared), 1 anything else.
|
|
23
|
-
// After exit 0, read the outputs: from the checkout, `bin/wb-cli run --wait-for latest`.
|
|
24
|
-
|
|
25
|
-
import { createRequire } from 'node:module';
|
|
26
|
-
import fs from 'node:fs';
|
|
27
|
-
import path from 'node:path';
|
|
28
|
-
|
|
29
|
-
const resultModule = process.env.WB_RESULT;
|
|
30
|
-
const resultMode = Boolean(resultModule);
|
|
31
|
-
const shotsDir = path.resolve(process.env.SHOTS_DIR ?? 'shots');
|
|
32
|
-
fs.mkdirSync(shotsDir, { recursive: true });
|
|
33
|
-
// The result screenshots have fixed names: remove an earlier run's before anything can fail, so
|
|
34
|
-
// none of them passes for this run's.
|
|
35
|
-
if (resultMode) {
|
|
36
|
-
for (const file of fs.readdirSync(shotsDir)) {
|
|
37
|
-
if (/^result-.*\.png$/.test(file)) fs.rmSync(path.join(shotsDir, file));
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// NODE_PATH does not apply to ESM `import`, so load Playwright through require from neui.
|
|
42
|
-
const repo = process.env.BW_REPO ?? process.env.WORKSPACE_ROOT;
|
|
43
|
-
if (!repo) throw new Error('Set BW_REPO (or WORKSPACE_ROOT) to the monorepo checkout.');
|
|
44
|
-
const require = createRequire(path.join(repo, 'src/ts/neui/package.json'));
|
|
45
|
-
let chromium;
|
|
46
|
-
try {
|
|
47
|
-
({ chromium } = require('@playwright/test'));
|
|
48
|
-
} catch {
|
|
49
|
-
console.error(`Playwright is not installed in ${repo}/src/ts. Run \`cd ${repo}/src/ts && ../../bin/pnpm install --frozen-lockfile\`, then this again.`);
|
|
50
|
-
process.exit(1);
|
|
51
|
-
}
|
|
52
|
-
// Installing the packages does not fetch the browser; this does, at the version the package expects.
|
|
53
|
-
const installBrowser = `cd ${repo}/src/ts/neui && ../../../bin/pnpm exec playwright install chromium`;
|
|
54
|
-
|
|
55
|
-
const url = process.env.WB_WORKSPACE_URL;
|
|
56
|
-
const cookieFile = process.env.BW_SAML_COOKIE_FILE;
|
|
57
|
-
const startModule = process.env.WB_START_MODULE;
|
|
58
|
-
const uiStep = Number(process.env.WB_UI_STEP ?? '1');
|
|
59
|
-
if (!url || !cookieFile) throw new Error('Set WB_WORKSPACE_URL and BW_SAML_COOKIE_FILE.');
|
|
60
|
-
const host = new URL(url).hostname;
|
|
61
|
-
// Studio opens a workspace on the entrypoint module's graph. The result pass opens the graph of
|
|
62
|
-
// the module that ran instead, found in the checkout's manifest by its name.
|
|
63
|
-
const pageUrl = resultMode ? moduleGraphUrl(resultModule) : url;
|
|
64
|
-
const cookie = fs.readFileSync(cookieFile, 'utf8').trim();
|
|
65
|
-
if (!cookie) throw new Error(`${cookieFile} is empty: mint the cookie again with testcookies.`);
|
|
66
|
-
|
|
67
|
-
let shots = 0;
|
|
68
|
-
async function shot(page, name) {
|
|
69
|
-
const prefix = resultMode ? 'result' : `ui${uiStep}`;
|
|
70
|
-
const file = path.join(shotsDir, `${prefix}-${String(++shots).padStart(2, '0')}-${name}.png`);
|
|
71
|
-
await page.screenshot({ path: file });
|
|
72
|
-
console.log(`screenshot ${file}`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// ---- Edit this: use the UI the way the user would. `ui` is the component inside
|
|
76
|
-
// iframe[srcdoc]; buttons such as Submit are on `page`, outside the iframe. A run that shows
|
|
77
|
-
// several UIs calls this once for each, with `step` 1, 2, …: branch on it. ----
|
|
78
|
-
async function useTheUi(page, ui, step) {
|
|
79
|
-
await ui.getByLabel('Name').fill('Grace');
|
|
80
|
-
await shot(page, 'filled');
|
|
81
|
-
await ui.getByRole('button', { name: 'Shout' }).click();
|
|
82
|
-
await ui.getByText('GRACE!').waitFor();
|
|
83
|
-
await shot(page, 'after-shout');
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Presses Start as a person does. Returns 0 when a task UI appears, 2 when Start is missing,
|
|
87
|
-
// 3 when it opens the "Configure & Run module" form (a finding, not a step), 4 when nothing appears.
|
|
88
|
-
async function pressStart(page, moduleName) {
|
|
89
|
-
const named = page.getByRole('button', { name: `Start ${moduleName}`, exact: true });
|
|
90
|
-
const tryChanges = page.getByRole('button', { name: 'Try changes', exact: true });
|
|
91
|
-
const menu = page.getByRole('button', { name: 'Start specific module', exact: true });
|
|
92
|
-
try {
|
|
93
|
-
await named.or(tryChanges).or(menu).first().waitFor({ timeout: 60_000 });
|
|
94
|
-
} catch {
|
|
95
|
-
await shot(page, 'no-start-button');
|
|
96
|
-
console.error(`No Start button for module "${moduleName}" after 60 s. Check the module name and that the workblock validates.`);
|
|
97
|
-
return 2;
|
|
98
|
-
}
|
|
99
|
-
await shot(page, 'before-start');
|
|
100
|
-
if (await named.isVisible()) {
|
|
101
|
-
await named.click();
|
|
102
|
-
} else if (await menu.isVisible()) {
|
|
103
|
-
await menu.click();
|
|
104
|
-
// The entrypoint's item also carries an "entry" badge, so match the name's own text.
|
|
105
|
-
await page.getByRole('menuitem').filter({ has: page.getByText(moduleName, { exact: true }) }).click();
|
|
106
|
-
} else {
|
|
107
|
-
await tryChanges.click();
|
|
108
|
-
}
|
|
109
|
-
// The loser of the race times out later; both branches settle, so neither rejects unhandled.
|
|
110
|
-
const outcome = await Promise.race([
|
|
111
|
-
page.getByRole('dialog', { name: 'Configure & Run module' }).waitFor({ timeout: 60_000 }).then(() => 'form', () => 'timeout'),
|
|
112
|
-
page.locator('iframe[srcdoc]').first().waitFor({ timeout: 60_000 }).then(() => 'ui', () => 'timeout'),
|
|
113
|
-
]);
|
|
114
|
-
if (outcome === 'form') {
|
|
115
|
-
await shot(page, 'start-input-form');
|
|
116
|
-
console.error(
|
|
117
|
-
`Start opened the generic "Configure & Run module" form: module "${moduleName}" has inputs, so a person who presses Start types raw values before any task UI. Give the module a first task with a UI and no module inputs, or set START=cli when people never start this module.`,
|
|
118
|
-
);
|
|
119
|
-
return 3;
|
|
120
|
-
}
|
|
121
|
-
if (outcome === 'timeout') {
|
|
122
|
-
await shot(page, 'no-task-ui');
|
|
123
|
-
console.error('No task UI and no input form 60 s after Start. Read the run with `bin/wb-cli run --wait-for latest`.');
|
|
124
|
-
return 4;
|
|
125
|
-
}
|
|
126
|
-
return 0;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// A module matches as `wb-cli run` matches it: by its id, its name, or the directory name that the
|
|
130
|
-
// checkout gives it.
|
|
131
|
-
function moduleGraphUrl(selector) {
|
|
132
|
-
const lower = (name) => name.trim().toLowerCase();
|
|
133
|
-
const dir = (name) =>
|
|
134
|
-
path.basename(name).toLowerCase().replace(/[^a-z0-9.-]+/g, '_').replace(/^_+|_+$/g, '').replace(/^\.+/, '');
|
|
135
|
-
const { modules = [] } = require('yaml').parse(fs.readFileSync('manifest.yaml', 'utf8'));
|
|
136
|
-
const module = modules.find(
|
|
137
|
-
(m) => m.id === selector || lower(m.name) === lower(selector) || dir(m.name) === dir(selector),
|
|
138
|
-
);
|
|
139
|
-
if (!module) throw new Error(`No module "${selector}" in ./manifest.yaml. Run this from the checkout.`);
|
|
140
|
-
const graph = new URL(url);
|
|
141
|
-
graph.searchParams.set('v', 'graph');
|
|
142
|
-
graph.searchParams.set('m', module.id);
|
|
143
|
-
return graph.href;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Screenshots the end of the run as Studio shows it: the graph, then the dialog that the module's
|
|
147
|
-
// output node opens, which lists every module output as raw data. A Space shows neither; there a
|
|
148
|
-
// person sees only the task UIs.
|
|
149
|
-
async function showResult(page) {
|
|
150
|
-
try {
|
|
151
|
-
await page.locator('.react-flow__node').first().waitFor({ timeout: 60_000 });
|
|
152
|
-
} catch {
|
|
153
|
-
await shot(page, 'no-graph');
|
|
154
|
-
console.error('No graph 60 s after the page loaded. Report the result view as not checked.');
|
|
155
|
-
return 4;
|
|
156
|
-
}
|
|
157
|
-
// Fit the whole graph, output node included, into the screenshot.
|
|
158
|
-
await page.getByRole('button', { name: 'fit view' }).click({ timeout: 5_000 }).catch(() => {});
|
|
159
|
-
await page.waitForTimeout(1_000);
|
|
160
|
-
await shot(page, 'graph');
|
|
161
|
-
const outputNode = page.locator('.react-flow__node-moduleOutput').first();
|
|
162
|
-
if ((await outputNode.count()) === 0) {
|
|
163
|
-
console.log('The module has no outputs: a person sees only its task UIs.');
|
|
164
|
-
return 0;
|
|
165
|
-
}
|
|
166
|
-
// The node's title button, pressed from the keyboard: Studio's floating graph toolbar can cover
|
|
167
|
-
// the node and take a mouse click.
|
|
168
|
-
await outputNode.getByRole('button').first().press('Enter');
|
|
169
|
-
const dialog = page.getByRole('dialog');
|
|
170
|
-
await dialog.waitFor();
|
|
171
|
-
// The values render in an editor that loads after the dialog opens; an output without a value
|
|
172
|
-
// shows none, so a timeout here still takes the screenshot.
|
|
173
|
-
await dialog.locator('.monaco-editor .view-lines').first().waitFor({ timeout: 15_000 }).catch(() => {});
|
|
174
|
-
await page.waitForTimeout(1_000);
|
|
175
|
-
await shot(page, 'outputs');
|
|
176
|
-
return 0;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
let browser;
|
|
180
|
-
try {
|
|
181
|
-
browser = await chromium.launch();
|
|
182
|
-
} catch (e) {
|
|
183
|
-
if (!String(e?.message).includes("Executable doesn't exist")) throw e;
|
|
184
|
-
console.error(`Playwright's Chromium is not installed. Run \`${installBrowser}\`, then this again.`);
|
|
185
|
-
process.exit(1);
|
|
186
|
-
}
|
|
187
|
-
let exitCode = 1;
|
|
188
|
-
try {
|
|
189
|
-
const context = await browser.newContext({ viewport: { width: 1440, height: 900 } });
|
|
190
|
-
await context.addCookies([
|
|
191
|
-
{ name: '_saml_session', value: cookie, domain: host, path: '/', httpOnly: true, secure: true, sameSite: 'None' },
|
|
192
|
-
]);
|
|
193
|
-
const page = await context.newPage();
|
|
194
|
-
page.setDefaultTimeout(30_000);
|
|
195
|
-
// Console messages of the page and of the component iframe. A rejected submit shows only
|
|
196
|
-
// "Submission rejected" on screen; the reason thrown by the submit handler is logged here.
|
|
197
|
-
const consoleLines = [];
|
|
198
|
-
page.on('console', (m) => {
|
|
199
|
-
if (m.type() === 'error' || m.type() === 'warning') consoleLines.push(`console.${m.type()}: ${m.text()}`);
|
|
200
|
-
});
|
|
201
|
-
page.on('pageerror', (e) => consoleLines.push(`pageerror: ${e.message}`));
|
|
202
|
-
|
|
203
|
-
const response = await page.goto(pageUrl);
|
|
204
|
-
if (response?.status() === 403) {
|
|
205
|
-
console.error('403 Forbidden: the cookie email is not a user of this tenant. Use the email that `bin/wb-cli tenants <host>` prints.');
|
|
206
|
-
exitCode = 2;
|
|
207
|
-
} else if (new URL(page.url()).hostname !== host) {
|
|
208
|
-
console.error(`Redirected to ${new URL(page.url()).hostname}: the cookie was rejected or expired. Mint a new one.`);
|
|
209
|
-
exitCode = 2;
|
|
210
|
-
} else if (resultMode) {
|
|
211
|
-
exitCode = await showResult(page);
|
|
212
|
-
} else {
|
|
213
|
-
const started = startModule ? await pressStart(page, startModule) : 0;
|
|
214
|
-
if (started !== 0) {
|
|
215
|
-
exitCode = started;
|
|
216
|
-
} else {
|
|
217
|
-
// A spinner and a read-only header show first; the component follows a few seconds later.
|
|
218
|
-
const frame = page.locator('iframe[srcdoc]').first();
|
|
219
|
-
const ui = page.frameLocator('iframe[srcdoc]').first();
|
|
220
|
-
try {
|
|
221
|
-
// The iframe is attached before the component renders into its #root: wait for both.
|
|
222
|
-
await frame.waitFor({ timeout: 60_000 });
|
|
223
|
-
await ui.locator('#root > *').first().waitFor({ timeout: 30_000 });
|
|
224
|
-
} catch {
|
|
225
|
-
await shot(page, 'no-task-ui');
|
|
226
|
-
console.error('No task UI after 60 s. Check that the run is still waiting (`bin/wb-cli run --wait-for latest`) and that the URL is the workspace URL.');
|
|
227
|
-
exitCode = 4;
|
|
228
|
-
}
|
|
229
|
-
if (exitCode !== 4) {
|
|
230
|
-
await shot(page, 'ui-loaded');
|
|
231
|
-
// Taken while the iframe is still attached: a continue action pressed in useTheUi removes
|
|
232
|
-
// it, and looking it up afterwards would wait out the page timeout and fail.
|
|
233
|
-
const frameHandle = await frame.elementHandle();
|
|
234
|
-
await useTheUi(page, ui, uiStep);
|
|
235
|
-
|
|
236
|
-
// Studio shows Submit unless the UI set its own actions (bw.setActions). Then a continue
|
|
237
|
-
// action pressed in useTheUi closes the UI, and anything else leaves it open.
|
|
238
|
-
const submit = page.getByRole('button', { name: 'Submit', exact: true });
|
|
239
|
-
// A submit handler that throws shows "Submission rejected"; a server error "Failed to submit".
|
|
240
|
-
const rejected = page.getByText('Submission rejected').or(page.getByText('Failed to submit')).first();
|
|
241
|
-
if (await submit.waitFor({ timeout: 3_000 }).then(() => true, () => false)) {
|
|
242
|
-
await submit.click();
|
|
243
|
-
// Accepted: the component's iframe goes away. Rejected: the toast.
|
|
244
|
-
const outcome = await Promise.race([
|
|
245
|
-
frameHandle.waitForElementState('hidden', { timeout: 60_000 }).then(() => 'accepted'),
|
|
246
|
-
rejected.waitFor({ timeout: 60_000 }).then(() => 'rejected'),
|
|
247
|
-
]);
|
|
248
|
-
await shot(page, `submit-${outcome}`);
|
|
249
|
-
if (outcome === 'rejected') {
|
|
250
|
-
console.error('Submit rejected by the component; the reason is in the console lines below.');
|
|
251
|
-
exitCode = 3;
|
|
252
|
-
} else {
|
|
253
|
-
console.log('Submit accepted. Next: bin/wb-cli run --wait-for latest in the checkout.');
|
|
254
|
-
exitCode = 0;
|
|
255
|
-
}
|
|
256
|
-
} else {
|
|
257
|
-
const outcome = await Promise.race([
|
|
258
|
-
frameHandle.waitForElementState('hidden', { timeout: 10_000 }).then(() => 'closed', () => 'open'),
|
|
259
|
-
rejected.waitFor({ timeout: 10_000 }).then(() => 'rejected', () => 'open'),
|
|
260
|
-
]);
|
|
261
|
-
await shot(page, outcome === 'open' ? 'left-open' : outcome);
|
|
262
|
-
if (outcome === 'rejected') {
|
|
263
|
-
console.error('The action pressed in useTheUi was rejected; the reason is in the console lines below.');
|
|
264
|
-
exitCode = 3;
|
|
265
|
-
} else if (outcome === 'closed') {
|
|
266
|
-
exitCode = 0;
|
|
267
|
-
} else {
|
|
268
|
-
console.log('No Submit button and the UI stays open: it set its own actions, and none pressed in useTheUi continued the run.');
|
|
269
|
-
exitCode = 5;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
if (consoleLines.length > 0) console.error(consoleLines.map((l) => l.slice(0, 500)).join('\n'));
|
|
276
|
-
} finally {
|
|
277
|
-
await browser.close();
|
|
278
|
-
}
|
|
279
|
-
process.exit(exitCode);
|