Download automation/scripts/check-live-view.ts from EnergyVenom/patchwise-agent-studio: direct link, hf CLI and curl.
- Browser
- Download file 4.3 kB
-
https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/automation/scripts/check-live-view.ts
- Command line
-
hf download hf://spaces/EnergyVenom/patchwise-agent-studio/automation/scripts/check-live-view.ts
-
curl -L -o check-live-view.ts https://huggingface.co/spaces/EnergyVenom/patchwise-agent-studio/resolve/main/automation/scripts/check-live-view.ts
4.3 kB
| // Checks the live-view hook in a real Chromium, outside the test suite (so the 201/18 baseline is not affected): | |
| // 1. browser actions become plain sentences, and typed sign-in details are never captioned | |
| // 2. a page with a password field produces NO frame and sets status.masked | |
| // 3. a normal page produces frames again | |
| // Run: npm run check:live-view (exit 1 on any failed check) | |
| import * as fs from 'fs'; | |
| import * as os from 'os'; | |
| import * as path from 'path'; | |
| import { chromium, type TestInfo } from '@playwright/test'; | |
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'fpt-live-check-')); | |
| process.env.FPT_LIVE_VIEW_DIR = dir; | |
| let failed = 0; | |
| const check = (name: string, ok: boolean, detail = '') => { console.log(`${ok ? ' ok ' : ' FAIL'} ${name}${ok || !detail ? '' : ` -> ${detail}`}`); if (!ok) failed += 1; }; | |
| const status = () => JSON.parse(fs.readFileSync(path.join(dir, 'status.json'), 'utf8')); | |
| const frame = () => path.join(dir, 'frame.jpg'); | |
| const wait = (ms: number) => new Promise((r) => setTimeout(r, ms)); | |
| const html = (body: string) => `data:text/html,${encodeURIComponent(`<html><title>t</title><body style="font:20px sans-serif">${body}</body></html>`)}`; | |
| (async () => { | |
| const { actionSentence, beginLiveStatus, describeLocator, startLiveView } = await import('../src/live-view'); | |
| check('caption: click a named button', actionSentence('click', "getByRole('button', { name: 'Submit' })", []) === "Click 'Submit'"); | |
| check('caption: fill a labelled field', actionSentence('fill', "getByLabel('Quantity')", ['10']) === "Enter '10' in 'Quantity'"); | |
| check('caption: last part of a chained locator', describeLocator("getByRole('table', { name: 'Lines' }).getByRole('row').getByRole('checkbox', { name: 'Select' })").name === 'Select'); | |
| check('caption: a password is never shown', actionSentence('fill', "getByLabel('Password')", ['S3cret!']) === 'Enter the sign-in details'); | |
| check('caption: nothing typed on a sign-in page is shown', !actionSentence('fill', "getByLabel('User ID')", ['zz.buyer'], true).includes('zz.buyer')); | |
| const testInfo = { tags: ['@P2P-APR-001'], title: 'P2P-APR-001 demo', status: 'passed', expectedStatus: 'passed' } as unknown as TestInfo; | |
| const done = beginLiveStatus(testInfo); | |
| const browser = await chromium.launch(); | |
| const page = await browser.newPage(); | |
| const stop = await startLiveView(page, testInfo); | |
| check('hook started', !!stop && !!done); | |
| // a sign-in page: no frame may ever be written | |
| await page.goto(html('<label>User ID <input></label><label>Password <input type="password"></label><button>Sign In</button>')); | |
| await page.getByLabel('User ID').fill('zz.buyer'); | |
| await page.getByLabel('Password').fill('S3cret!'); | |
| await wait(1800); | |
| check('sign-in page: masked flag set', status().masked === true, JSON.stringify(status().masked)); | |
| check('sign-in page: no frame written', !fs.existsSync(frame())); | |
| check('sign-in page: typed values not in the status file', !fs.readFileSync(path.join(dir, 'status.json'), 'utf8').includes('S3cret') && !JSON.stringify(status()).includes('zz.buyer')); | |
| // a normal page: frames resume and the action is captioned | |
| await page.goto(html('<label>Quantity <input></label><button>Add to Cart</button><div id="t"></div><script>setInterval(()=>{document.getElementById("t").textContent=Date.now()},100)</script>')); | |
| await page.getByLabel('Quantity').fill('10'); | |
| await page.getByRole('button', { name: 'Add to Cart' }).click(); | |
| await wait(2500); | |
| check('normal page: masked flag cleared', status().masked === false, JSON.stringify(status().masked)); | |
| check('normal page: frame written', fs.existsSync(frame()) && fs.statSync(frame()).size > 1000); | |
| check('normal page: current action captioned', status().action === "Click 'Add to Cart'", String(status().action)); | |
| check('normal page: actions counted', status().action_n === 4, String(status().action_n)); | |
| if (stop) await stop(); | |
| if (done) done(); | |
| await browser.close(); | |
| fs.rmSync(dir, { recursive: true, force: true }); | |
| console.log(failed ? `check-live-view: ${failed} check(s) FAILED` : 'check-live-view: all checks passed'); | |
| process.exit(failed ? 1 : 0); | |
| })().catch((e) => { console.error(e); process.exit(1); }); | |