Public: anyone can read this; the crew can change it.
Red after landing: test/boundary-tenancy-cell.test.ts fails on main #12686
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/12655-red-after-landing-test-boundary-tenancy → main 1 commit fork
2 files
changed +103
−75
test/capture-chromium.looks.test.ts added +102
| @@ -0,0 +1,102 @@ | ||
| 1 | /** | |
| 2 | * A real Chromium takes the look (#12655): the standalone browser captures, | |
| 3 | * in the looks lane (outside the gate's per-test budget) because each | |
| 4 | * starts a browser. The one that needs the deployed app stays in looks.test.ts. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { existsSync, readFileSync } from "node:fs"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { decodePng } from "../src/design/image/png.ts"; | |
| 12 | import { findChromium, takeLook } from "../src/looks/capture.ts"; | |
| 13 | import { chromiumRuns } from "./helpers/chrome.ts"; | |
| 14 | ||
| 15 | const found = findChromium(); | |
| 16 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | |
| 17 | if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so no real capture is taken"); | |
| 18 | ||
| 19 | describe.skipIf(chromium === undefined)("a real capture", () => { | |
| 20 | let dataDir: string; | |
| 21 | beforeAll(async () => { | |
| 22 | dataDir = await mkdtemp(join(tmpdir(), "forge-capture-")); | |
| 23 | }); | |
| 24 | afterAll(async () => { | |
| 25 | await rm(dataDir, { recursive: true, force: true }); | |
| 26 | }); | |
| 27 | ||
| 28 | test( | |
| 29 | "a capture that ends on the browser's error page fails with its reason and writes no picture", | |
| 30 | async () => { | |
| 31 | const page: ReturnType<typeof Bun.serve> = Bun.serve({ | |
| 32 | port: 0, | |
| 33 | hostname: "127.0.0.1", | |
| 34 | // Off the app's host, on a name that resolves to loopback without DNS. | |
| 35 | fetch: (request): Response => | |
| 36 | new URL(request.url).pathname === "/" | |
| 37 | ? new Response(null, { | |
| 38 | status: 302, | |
| 39 | headers: { location: `http://localhost:${page.port}/landed` }, | |
| 40 | }) | |
| 41 | : new Response("<!doctype html><p>elsewhere</p>", { | |
| 42 | headers: { "content-type": "text/html" }, | |
| 43 | }), | |
| 44 | }); | |
| 45 | try { | |
| 46 | const out = join(dataDir, "refused.png"); | |
| 47 | const taken = await takeLook({ | |
| 48 | url: `http://127.0.0.1:${page.port}/`, | |
| 49 | out, | |
| 50 | width: 390, | |
| 51 | height: 844, | |
| 52 | timeoutMs: 30_000, | |
| 53 | }); | |
| 54 | expect(JSON.stringify(taken)).toContain("left the app's host for localhost"); | |
| 55 | // The guard throws before the screenshot: no picture was written. | |
| 56 | expect(existsSync(out)).toBe(false); | |
| 57 | } finally { | |
| 58 | page.stop(true); | |
| 59 | } | |
| 60 | }, | |
| 61 | 120_000, | |
| 62 | ); | |
| 63 | test( | |
| 64 | "a dark capture is truly dark: the same page, light and dark, differs in its pixels", | |
| 65 | async () => { | |
| 66 | const page = Bun.serve({ | |
| 67 | port: 0, | |
| 68 | hostname: "127.0.0.1", | |
| 69 | fetch: () => | |
| 70 | new Response( | |
| 71 | "<!doctype html><style>body{margin:0;background:#fff}@media (prefers-color-scheme: dark){body{background:#000}}</style><p>hi</p>", | |
| 72 | { headers: { "content-type": "text/html" } }, | |
| 73 | ), | |
| 74 | }); | |
| 75 | try { | |
| 76 | const corner = async (dark: boolean): Promise<number> => { | |
| 77 | const out = join(dataDir, `scheme-${dark ? "dark" : "light"}.png`); | |
| 78 | const taken = await takeLook({ | |
| 79 | url: `http://127.0.0.1:${page.port}/`, | |
| 80 | out, | |
| 81 | width: 390, | |
| 82 | height: 844, | |
| 83 | dark, | |
| 84 | timeoutMs: 30_000, | |
| 85 | }); | |
| 86 | expect(taken.ok).toBe(true); | |
| 87 | const image = decodePng(readFileSync(out)); | |
| 88 | if (!image.ok) throw new Error(image.error); | |
| 89 | const last = image.value.rgba.length - 4; | |
| 90 | return image.value.rgba[last]!; | |
| 91 | }; | |
| 92 | // Side by side: two browsers at once, half the wall time of one after the other. | |
| 93 | const [light, dark] = await Promise.all([corner(false), corner(true)]); | |
| 94 | expect(light).toBe(255); | |
| 95 | expect(dark).toBe(0); | |
| 96 | } finally { | |
| 97 | page.stop(true); | |
| 98 | } | |
| 99 | }, | |
| 100 | 120_000, | |
| 101 | ); | |
| 102 | }); |
test/looks.test.ts +1 −75
| @@ -25,7 +25,7 @@ import { AppsRuntime } from "../src/apps/runtime.ts"; | ||
| 25 | 25 | import type { AppRecord } from "../src/core/apps.ts"; |
| 26 | 26 | import { listEvents } from "../src/core/events.ts"; |
| 27 | 27 | import { lookSlot, lookUrl, looksForEnv, recordLook, type Look } from "../src/core/looks.ts"; |
| 28 | import { decodePng, encodePng } from "../src/design/image/png.ts"; | |
| 28 | import { encodePng } from "../src/design/image/png.ts"; | |
| 29 | 29 | import { setAppMembers } from "../src/core/app_members.ts"; |
| 30 | 30 | import type { Pull } from "../src/core/pulls.ts"; |
| 31 | 31 | import type { Repo } from "../src/core/repos.ts"; |
| @@ -1515,78 +1515,4 @@ describe("the look", () => { | ||
| 1515 | 1515 | }, |
| 1516 | 1516 | 120_000, |
| 1517 | 1517 | ); |
| 1518 | test.skipIf(chromium === undefined)( | |
| 1519 | "a capture that ends on the browser's error page fails with its reason and writes no picture", | |
| 1520 | async () => { | |
| 1521 | const page: ReturnType<typeof Bun.serve> = Bun.serve({ | |
| 1522 | port: 0, | |
| 1523 | hostname: "127.0.0.1", | |
| 1524 | // Off the app's host, on a name that resolves to loopback without DNS. | |
| 1525 | fetch: (request): Response => | |
| 1526 | new URL(request.url).pathname === "/" | |
| 1527 | ? new Response(null, { | |
| 1528 | status: 302, | |
| 1529 | headers: { location: `http://localhost:${page.port}/landed` }, | |
| 1530 | }) | |
| 1531 | : new Response("<!doctype html><p>elsewhere</p>", { | |
| 1532 | headers: { "content-type": "text/html" }, | |
| 1533 | }), | |
| 1534 | }); | |
| 1535 | try { | |
| 1536 | const out = join(dataDir, "refused.png"); | |
| 1537 | const taken = await takeLook({ | |
| 1538 | url: `http://127.0.0.1:${page.port}/`, | |
| 1539 | out, | |
| 1540 | width: 390, | |
| 1541 | height: 844, | |
| 1542 | timeoutMs: 30_000, | |
| 1543 | }); | |
| 1544 | expect(JSON.stringify(taken)).toContain("left the app's host for localhost"); | |
| 1545 | // The guard throws before the screenshot: no picture was written. | |
| 1546 | expect(existsSync(out)).toBe(false); | |
| 1547 | } finally { | |
| 1548 | page.stop(true); | |
| 1549 | } | |
| 1550 | }, | |
| 1551 | 120_000, | |
| 1552 | ); | |
| 1553 | test.skipIf(chromium === undefined)( | |
| 1554 | "a dark capture is truly dark: the same page, light and dark, differs in its pixels", | |
| 1555 | async () => { | |
| 1556 | const page = Bun.serve({ | |
| 1557 | port: 0, | |
| 1558 | hostname: "127.0.0.1", | |
| 1559 | fetch: () => | |
| 1560 | new Response( | |
| 1561 | "<!doctype html><style>body{margin:0;background:#fff}@media (prefers-color-scheme: dark){body{background:#000}}</style><p>hi</p>", | |
| 1562 | { headers: { "content-type": "text/html" } }, | |
| 1563 | ), | |
| 1564 | }); | |
| 1565 | try { | |
| 1566 | const corner = async (dark: boolean): Promise<number> => { | |
| 1567 | const out = join(dataDir, `scheme-${dark ? "dark" : "light"}.png`); | |
| 1568 | const taken = await takeLook({ | |
| 1569 | url: `http://127.0.0.1:${page.port}/`, | |
| 1570 | out, | |
| 1571 | width: 390, | |
| 1572 | height: 844, | |
| 1573 | dark, | |
| 1574 | timeoutMs: 30_000, | |
| 1575 | }); | |
| 1576 | expect(taken.ok).toBe(true); | |
| 1577 | const image = decodePng(readFileSync(out)); | |
| 1578 | if (!image.ok) throw new Error(image.error); | |
| 1579 | const last = image.value.rgba.length - 4; | |
| 1580 | return image.value.rgba[last]!; | |
| 1581 | }; | |
| 1582 | // Side by side: two browsers at once, half the wall time of one after the other. | |
| 1583 | const [light, dark] = await Promise.all([corner(false), corner(true)]); | |
| 1584 | expect(light).toBe(255); | |
| 1585 | expect(dark).toBe(0); | |
| 1586 | } finally { | |
| 1587 | page.stop(true); | |
| 1588 | } | |
| 1589 | }, | |
| 1590 | 120_000, | |
| 1591 | ); | |
| 1592 | 1518 | }); |
new above
offline