161 lines
9.6 KiB
JavaScript
161 lines
9.6 KiB
JavaScript
// A real-page lost-ack regression driven only by a Go httptest server. The Go
|
|
// fixture supplies a fake executor and checks that precisely one run exists.
|
|
import assert from "node:assert/strict";
|
|
import { spawn } from "node:child_process";
|
|
import { mkdir } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import net from "node:net";
|
|
import { request } from "node:http";
|
|
import { fileURLToPath } from "node:url";
|
|
import { eventually, launchChrome } from "./browser.mjs";
|
|
|
|
const [target, pipelineId, workspace] = process.argv.slice(2);
|
|
assert.match(target ?? "", /^127\.0\.0\.1:\d+$/);
|
|
const reserve = net.createServer();
|
|
await new Promise((resolve) => reserve.listen(0, "127.0.0.1", resolve));
|
|
const port = reserve.address().port;
|
|
await new Promise((resolve) => reserve.close(resolve));
|
|
const serve = spawn(process.execPath, ["serve.mjs", "--port", String(port), "--pipelines", target], {
|
|
cwd: fileURLToPath(new URL("..", import.meta.url)),
|
|
env: { ...process.env, PIPELINES_WEB_AUTH: "disabled" },
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
let logs = "";
|
|
serve.stdout.on("data", (data) => { logs += data; });
|
|
serve.stderr.on("data", (data) => { logs += data; });
|
|
let browser;
|
|
try {
|
|
await eventually(async () => {
|
|
if (serve.exitCode != null) throw Error(logs);
|
|
return fetch(`http://127.0.0.1:${port}/`).then((r) => r.ok).catch(() => false);
|
|
});
|
|
const refused = await new Promise((resolve, reject) => {
|
|
const req = request({ host: "127.0.0.1", port, path: "/connect", headers: { Connection: "Upgrade", Upgrade: "websocket", Origin: "https://untrusted.example", "Sec-WebSocket-Version": "13", "Sec-WebSocket-Key": "dGhlIHNhbXBsZSBub25jZQ==" } });
|
|
req.on("response", (res) => { res.resume(); resolve(res.statusCode); });
|
|
req.on("upgrade", (_res, socket) => { socket.destroy(); resolve(101); });
|
|
req.on("error", reject);
|
|
req.end();
|
|
});
|
|
assert.equal(refused, 403, "proxy must reject foreign Origin before stripping it upstream");
|
|
browser = await launchChrome({ width: 390, height: 844 });
|
|
const page = await browser.openPage("about:blank");
|
|
await page.addInitScript(`(() => {
|
|
const Native = window.WebSocket;
|
|
window.WebSocket = class extends Native {
|
|
send(data) {
|
|
const frame = JSON.parse(data);
|
|
if (frame.type === 'run_pipeline') {
|
|
const keys = JSON.parse(sessionStorage.getItem('probe-launches') || '[]');
|
|
keys.push(frame.request_key);
|
|
sessionStorage.setItem('probe-launches', JSON.stringify(keys));
|
|
}
|
|
super.send(data);
|
|
}
|
|
set onmessage(handler) {
|
|
super.onmessage = (event) => {
|
|
const frame = JSON.parse(event.data);
|
|
if (frame.type === 'run_started' && !sessionStorage.getItem('probe-dropped')) {
|
|
sessionStorage.setItem('probe-dropped', 'yes');
|
|
this.close(4000, 'scratch lost ack');
|
|
return;
|
|
}
|
|
handler(event);
|
|
};
|
|
}
|
|
};
|
|
})()`);
|
|
const pipeline = `http://127.0.0.1:${port}/pipelines/${pipelineId}`;
|
|
await page.goto(pipeline);
|
|
await page.waitForSelector(".run-pipeline");
|
|
await page.click(".run-pipeline");
|
|
await page.waitForSelector("#runPrompt");
|
|
await page.fill("#runPrompt", "Scratch admission reconciliation with a deliberately long title that must wrap cleanly across the run list without clipping or widening the selected row");
|
|
await page.fill("#runWorkspace", workspace);
|
|
await page.click(".run-start-confirm");
|
|
await eventually(() => page.evaluate("sessionStorage.getItem('probe-dropped') === 'yes'"));
|
|
// Reload before any manual retry: the tab's launch identity must survive.
|
|
await page.goto(pipeline);
|
|
await page.waitForSelector(".run-pipeline");
|
|
await page.click(".run-pipeline");
|
|
await page.waitForSelector(".run-start-confirm");
|
|
assert.equal(await page.evaluate("document.querySelector('.run-start-confirm').textContent"), "Check / retry");
|
|
assert.equal(await page.evaluate("document.querySelector('#runPrompt').disabled"), true);
|
|
if (process.env.PIPELINES_CAPTURE_DIR) {
|
|
await mkdir(process.env.PIPELINES_CAPTURE_DIR, { recursive: true });
|
|
await eventually(() => page.evaluate("document.querySelector('.run-start-dialog').getAnimations({subtree:true}).every(a => a.playState !== 'running')"));
|
|
await page.screenshot(join(process.env.PIPELINES_CAPTURE_DIR, "uncertain-run-recovered.png"));
|
|
}
|
|
await page.click(".run-start-confirm");
|
|
await eventually(() => page.evaluate("/^\\/runs\\/\\d+$/.test(location.pathname)"));
|
|
assert.equal(await page.evaluate("JSON.parse(sessionStorage.getItem('probe-launches')).length"), 1);
|
|
if (process.env.PIPELINES_CAPTURE_DIR) {
|
|
await page.screenshot(join(process.env.PIPELINES_CAPTURE_DIR, "single-admitted-run.png"));
|
|
}
|
|
const runId = await page.evaluate("Number(location.pathname.split('/')[2])");
|
|
assert.equal((await fetch(`http://${target}/complete-fixture`, { method: "POST" })).status, 204);
|
|
await page.goto(`http://127.0.0.1:${port}/runs/${runId}/stage/work`);
|
|
await page.waitForSelector(".stage-pane-back");
|
|
const back = await page.evaluate("(() => { const b=document.querySelector('.stage-pane-back'); const r=b.getBoundingClientRect(); return {width:r.width,height:r.height,svg:!!b.querySelector('svg'),text:b.textContent}; })()");
|
|
assert.equal(Math.round(back.width), 48);
|
|
assert.equal(Math.round(back.height), 48);
|
|
assert.equal(back.svg, true);
|
|
assert.equal(back.text, "");
|
|
await page.click(".audit-open");
|
|
await page.waitForSelector(".audit-viewer");
|
|
for (const width of [390, 420]) {
|
|
await page.resize(width, 844);
|
|
await eventually(() => page.evaluate("document.querySelector('.audit-viewer').getAnimations({subtree:true}).every(a => a.playState !== 'running')"));
|
|
const measured = await page.evaluate("(() => { const v=document.querySelector('.audit-panel'); const tab=v.querySelector('.audit-tab.active'); const b=v.querySelector('.audit-back'); return {radius:getComputedStyle(tab).borderRadius,tabHeight:tab.getBoundingClientRect().height,backWidth:b.getBoundingClientRect().width,backHeight:b.getBoundingClientRect().height,panelWidth:v.getBoundingClientRect().width,pageWidth:document.documentElement.scrollWidth}; })()");
|
|
assert.equal(measured.radius, "0px");
|
|
assert.ok(Math.round(measured.tabHeight) >= 48);
|
|
assert.equal(Math.round(measured.backWidth), 48);
|
|
assert.equal(Math.round(measured.backHeight), 48);
|
|
assert.ok(measured.pageWidth <= width && measured.panelWidth <= width);
|
|
if (process.env.PIPELINES_CAPTURE_DIR) {
|
|
await eventually(() => page.evaluate("document.querySelector('.audit-viewer').getAnimations({subtree:true}).every(a => a.playState !== 'running')"));
|
|
await page.screenshot(join(process.env.PIPELINES_CAPTURE_DIR, `mobile-audit-${width}.png`));
|
|
}
|
|
}
|
|
await page.click(".audit-back");
|
|
await page.click(".stage-pane-back");
|
|
await page.goto(pipeline);
|
|
await page.waitForSelector(".pipeline-runs");
|
|
await page.click(".pipeline-runs");
|
|
await eventually(() => page.evaluate(`location.pathname === '/runs' && location.search === '?pipeline=${pipelineId}'`));
|
|
await page.waitForSelector(".pipeline-filter-chip");
|
|
assert.equal(await page.evaluate("document.querySelectorAll('.list.runs .run-row').length"), 1);
|
|
await page.goto(`http://127.0.0.1:${port}/runs?pipeline=${pipelineId}`);
|
|
await page.waitForSelector(".pipeline-filter-chip");
|
|
assert.equal(await page.evaluate("document.querySelectorAll('.list.runs .run-row').length"), 1);
|
|
if (process.env.PIPELINES_CAPTURE_DIR) await page.screenshot(join(process.env.PIPELINES_CAPTURE_DIR, "pipeline-filtered-runs.png"));
|
|
for(const width of [390,420]) {
|
|
await page.resize(width,844);
|
|
await eventually(() => page.evaluate("document.getAnimations().every(a=>a.playState!=='running')"));
|
|
const dimensions=await page.evaluate(`(() => {
|
|
const toolbar=document.querySelector('.run-toolbar').getBoundingClientRect();
|
|
const applied=document.querySelector('.run-applied-filters').getBoundingClientRect();
|
|
const title=document.querySelector('.run-row-title');
|
|
const row=document.querySelector('.run-row').getBoundingClientRect();
|
|
const scroll=document.querySelector('.run-scroll');
|
|
return {toolbarBottom:toolbar.bottom,filterTop:applied.top,titleHeight:title.getBoundingClientRect().height,lineHeight:parseFloat(getComputedStyle(title).lineHeight),whiteSpace:getComputedStyle(title).whiteSpace,rowWidth:row.width,listWidth:scroll.clientWidth,scrollWidth:scroll.scrollWidth,pageWidth:document.documentElement.scrollWidth};
|
|
})()`);
|
|
assert.ok(dimensions.filterTop>=dimensions.toolbarBottom-1);
|
|
assert.equal(dimensions.whiteSpace,'normal');
|
|
assert.ok(dimensions.titleHeight>dimensions.lineHeight*1.5);
|
|
assert.ok(Math.abs(dimensions.rowWidth-dimensions.listWidth)<1);
|
|
assert.ok(dimensions.scrollWidth<=dimensions.listWidth && dimensions.pageWidth<=width);
|
|
if(process.env.PIPELINES_CAPTURE_DIR) await page.screenshot(join(process.env.PIPELINES_CAPTURE_DIR,`wrapped-run-title-${width}.png`));
|
|
}
|
|
await page.resize(1100,844);
|
|
await page.click('.run-row');
|
|
await page.waitForSelector('.run-row.selected');
|
|
await eventually(() => page.evaluate("document.getAnimations().every(a=>a.playState!=='running')"));
|
|
assert.equal(await page.evaluate("Math.round(document.querySelector('.run-row.selected').getBoundingClientRect().width)===document.querySelector('.run-scroll').clientWidth"),true);
|
|
if(process.env.PIPELINES_CAPTURE_DIR) await page.screenshot(join(process.env.PIPELINES_CAPTURE_DIR,'full-width-selected-run.png'));
|
|
console.log("Lost launch acknowledgement + reload reconciled to the single admitted run.");
|
|
} finally {
|
|
await browser?.close();
|
|
serve.kill("SIGTERM");
|
|
await new Promise((resolve) => serve.exitCode != null ? resolve() : serve.once("exit", resolve));
|
|
}
|