Files
documentation/scripts/browser/skills-measurement.cjs
T
jarvis-at-skic 1a2d16bc91
Build and publish Eldorado documentation / build (pull_request) Successful in 1m30s
docs: [verified] answer the six-month AI Architect assignment
2026-10-08 16:59:36 +00:00

114 lines
8.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const {chromium} = require('playwright');
const assert = require('node:assert/strict');
const fs = require('node:fs');
(async () => {
const base = process.argv[2] || 'http://127.0.0.1:4173';
const output = `.cache/measurement-${process.argv[3] || 'local'}`;
fs.mkdirSync(output, {recursive:true});
const browser = await chromium.launch({headless:true, executablePath:process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE, args:['--no-sandbox']});
const results = [];
try {
for (const width of [1440, 390, 320]) {
const context = await browser.newContext({viewport:{width,height:1000}, colorScheme:'light'});
const page = await context.newPage();
const errors = [];
page.on('pageerror', error => errors.push(error.message));
const response = await page.goto(`${base}/eldorado-v1/documentation/strategy/measurement/`, {waitUntil:'networkidle'});
assert.equal(response.status(), 200);
assert.equal(await page.locator('h1').innerText(), 'Measuring real output');
assert((await page.title()).startsWith('Measuring real output |'));
assert.equal(await page.locator('.strategy-content details').count(), 1);
assert.equal(await page.locator('.strategy-content details[open]').count(), 0);
assert((await page.locator('.strategy-content details summary').innerText()).includes('Implementation status'));
assert.equal(await page.locator('.strategy-content h2').count(), 2);
assert.deepEqual((await page.locator('.strategy-content h3').allTextContents()).map(text => text.replaceAll('\u200b', '')), ['Workflow effectiveness', 'Skills effectiveness & health']);
assert.equal(await page.locator('.strategy-content ol').count(), 2);
assert.equal(await page.locator('.strategy-content ol > li').count(), 16);
if (width < 700) await page.getByRole('button', {name:'Toggle navigation bar'}).click();
const menu = page.locator('.theme-doc-sidebar-menu .menu__link').filter({visible:true});
await menu.first().waitFor({state:'visible'});
const metrics = JSON.parse(fs.readFileSync('research/ai-adoption/measurement-migration.json','utf8')).metrics;
assert.deepEqual(await menu.allTextContents(), ['Six-month strategy','Roadmap','One bounded experiment','Measurement',...metrics.map(m => m.title),'Collection and safeguards','Run the synthetic measurement example','Baseline','Governance','Quality','Adoption','Maintenance','Beyond six months']);
if (width < 700) await page.getByRole('button', {name:'Close navigation bar'}).click();
const panel = page.locator('.archify-panel--story');
const iframe = panel.locator(width > 700 ? '.story-desktop' : '.story-mobile');
await iframe.scrollIntoViewIfNeeded();
const frame = await (await iframe.elementHandle()).contentFrame();
await frame.locator('svg[role="img"]').waitFor();
const geometry = await frame.locator('svg[role="img"]').evaluate(svg => {
const nodes = [...svg.querySelectorAll('[data-node-id]')].map(n => n.getBoundingClientRect().toJSON());
return {nodes, width:innerWidth, height:innerHeight, minLabel:Math.min(...[...svg.querySelectorAll('text[data-node-label]')].map(n => parseFloat(getComputedStyle(n).fontSize)*n.getScreenCTM().a))};
});
assert.equal(geometry.nodes.length, JSON.parse(fs.readFileSync('diagrams/strategy-measurement.architecture.json')).components.length);
for (const n of geometry.nodes) assert(n.x >= 0 && n.y >= 0 && n.right <= geometry.width + 1 && n.bottom <= geometry.height + 1);
assert(geometry.minLabel >= 10, `readable node labels: ${geometry.minLabel}`);
await frame.locator('#btn-theme').click();
await page.waitForFunction(() => document.documentElement.dataset.theme === 'dark');
await frame.locator('#btn-theme').click();
await page.waitForFunction(() => document.documentElement.dataset.theme === 'light');
for (const preset of ['signal-flow','blueprint','editorial','classic']) {
await frame.locator('#btn-preset').click();
await frame.locator(`[data-preset-value="${preset}"]`).click();
assert.equal(await frame.locator('html').getAttribute('data-preset'), preset);
}
await frame.locator('#btn-export').click();
const [download] = await Promise.all([page.waitForEvent('download'), frame.locator('[data-format="svg"]').click()]);
assert.equal(await download.failure(), null);
const path = `${output}/${width}.svg`; await download.saveAs(path);
const svg = fs.readFileSync(path, 'utf8');
assert(svg.includes('Workflow effectiveness') && svg.includes('Skills effectiveness &amp; health') && svg.includes('No mandatory collection'));
const exports = ['svg'];
for (const format of ['png','jpeg','webp','svg-light','svg-dark','webm']) {
await frame.locator('#btn-export').click();
const option = frame.locator(`[data-format="${format}"]`);
if (await option.isDisabled()) { exports.push(`${format}:unsupported`); await frame.locator('#btn-export').click(); continue; }
const [file] = await Promise.all([page.waitForEvent('download', {timeout:60000}), option.click()]);
assert.equal(await file.failure(), null);
const target = `${output}/${width}-${format}-${file.suggestedFilename()}`;
await file.saveAs(target);
const bytes = fs.readFileSync(target); assert(bytes.length > 1000);
if (format.startsWith('svg')) assert(bytes.toString().includes('eldorado-skills-typography'));
else {
const mime = {png:'image/png', jpeg:'image/jpeg', webp:'image/webp', webm:'video/webm'}[format];
const dimensions = await page.evaluate(async ({mime,data}) => {
const media = document.createElement(mime.startsWith('video') ? 'video' : 'img');
const ready = new Promise((resolve,reject) => {media[mime.startsWith('video') ? 'onloadedmetadata' : 'onload'] = resolve; media.onerror = reject;});
media.src = `data:${mime};base64,${data}`; await ready;
return [media.videoWidth || media.naturalWidth, media.videoHeight || media.naturalHeight];
}, {mime, data:bytes.toString('base64')});
assert(dimensions.every(n => n > 0));
}
exports.push(format);
}
const opener = panel.getByRole('button', {name:/^Expand /});
await opener.click();
const close = panel.getByRole('button', {name:'Close full-screen diagram', exact:true});
await close.waitFor({state:'visible'}); assert.equal(await close.innerText(), '×');
await close.click(); assert(await opener.evaluate(n => n === document.activeElement));
await opener.click(); await close.waitFor({state:'visible'}); await close.focus(); await page.keyboard.press('Escape');
await page.waitForFunction(() => !document.querySelector('.archify-panel--story dialog').open);
assert(await opener.evaluate(n => n === document.activeElement));
assert(!await page.evaluate(() => document.documentElement.scrollWidth > innerWidth));
await page.evaluate(() => scrollTo({top:0, behavior:'instant'}));
await page.screenshot({path:`${output}/${width}-top.png`});
await page.locator('.strategy-content h2').nth(1).scrollIntoViewIfNeeded();
await page.screenshot({path:`${output}/${width}-pilot.png`});
await page.screenshot({path:`${output}/${width}-full.png`, fullPage:true});
const links = await page.locator('.strategy-content a[href*="/measurement/"]').evaluateAll(nodes => nodes.map(n => n.href));
for (const href of [...new Set(links)]) {
const navigation = await page.goto(href, {waitUntil:'networkidle'});
if (navigation) assert.equal(navigation.status(), 200);
assert.equal(page.url(), href);
if (new URL(href).hash) await page.locator(new URL(href).hash).waitFor({state:'visible'});
}
assert.equal(new Set(links.map(h => new URL(h).pathname)).size, 18);
assert(!await page.evaluate(() => document.documentElement.scrollWidth > innerWidth));
assert.deepEqual(errors, []);
results.push({width, geometry, links:links.length, title:true, sidebar:true, controls:true, exports, reference:true});
fs.writeFileSync(`${output}/results.json`, JSON.stringify(results,null,2));
await context.close();
}
console.log(`PASS ${results.length} Skills Measurement viewports: title/sidebar, optional registry, diagram geometry/controls/export, all reference links and no page errors`);
} finally {await browser.close();}
})().catch(error => {console.error(error); process.exitCode = 1;});