Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(ci): browser test fixes/optimization

justinc2b0b4cf0395
diff --git a/.github/workflows/browser-tests.yml b/.github/workflows/browser-tests.yml
index c1e2b9443..7c10ee2f1 100644
--- a/.github/workflows/browser-tests.yml
+++ b/.github/workflows/browser-tests.yml
@@ -13,12 +13,12 @@ concurrency:
jobs:
smoke:
name: Chromium smoke tests
- runs-on: ubuntu-24.04
+ runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 30
env:
KANEO_E2E_HOST: localhost
steps:
- - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ - uses: useblacksmith/checkout@25227e61ff9dafe400e22fa487b673eac4e4409a # v1
with:
persist-credentials: false
- uses: pnpm/action-setup@ea17c68df8912ef543352723c149a84f56e3d413 # v6.1.0
@@ -32,16 +32,19 @@ jobs:
- run: pnpm --dir tests/e2e exec playwright install --with-deps chromium
- - uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4
+ - name: Setup Blacksmith Builder
+ uses: useblacksmith/setup-docker-builder@19215110ab936351210feebdfa5b440b4493e184 # v2.2.0
+ with:
+ cache-key: ${{ github.repository }}/kaneo
- name: Build this revision of Kaneo
- uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
+ uses: useblacksmith/build-push-action@9b0579bbec7a6cad2f171596c57e7ac1e7658850 # v2
with:
context: .
file: Dockerfile.kaneo
+ platforms: linux/amd64
+ push: false
load: true
tags: kaneo-browserstack:test
- cache-from: type=gha,scope=browser-tests
- cache-to: type=gha,mode=max,scope=browser-tests
- name: Start disposable test instance
run: docker compose -f tests/e2e/compose.yml up --no-build --wait --wait-timeout 180
diff --git a/scripts/ci/browser-build-contract.test.mjs b/scripts/ci/browser-build-contract.test.mjs
new file mode 100644
index 000000000..5a20fdccd
--- /dev/null
+++ b/scripts/ci/browser-build-contract.test.mjs
@@ -0,0 +1,200 @@
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import { fileURLToPath } from "node:url";
+import test from "node:test";
+
+const repoRoot = fileURLToPath(new URL("../..", import.meta.url));
+const browserWorkflow = readFileSync(
+ `${repoRoot}/.github/workflows/browser-tests.yml`,
+ "utf8",
+);
+const ciWorkflow = readFileSync(`${repoRoot}/.github/workflows/ci.yml`, "utf8");
+
+// Slice a workflow at a job's body, stopping at the next sibling job so
+// later jobs (e.g. ci.yml's split-images, which reuses some of the same
+// actions with a different cache-key) cannot leak into the comparison.
+function jobSection(workflow, jobName) {
+ const header = ` ${jobName}:`;
+ const start = workflow.indexOf(header);
+ if (start === -1) return null;
+ const tail = workflow.slice(start + header.length);
+ const end = tail.search(/^ [a-z][\w-]*:/m);
+ return end === -1 ? tail : tail.slice(0, end);
+}
+
+// The action identifier is the `name@sha` part of a `uses:` line; the
+// trailing `# vX.Y.Z` comment is a human aid, not a behavioral contract.
+function actionRef(line) {
+ const match = line.match(/uses:\s*(\S+)/);
+ if (!match) return null;
+ return match[1].split("#")[0].trim();
+}
+
+function firstInput(section, key) {
+ const re = new RegExp(`^\\s+${key}:\\s*(.+)$`, "m");
+ const match = section.match(re);
+ return match ? match[1].trim() : null;
+}
+
+const dockerBuild = jobSection(ciWorkflow, "docker-build");
+const smoke = jobSection(browserWorkflow, "smoke");
+assert.ok(dockerBuild, "ci.yml must contain a docker-build job");
+assert.ok(smoke, "browser-tests.yml must contain a smoke job");
+
+const ciBuilder = dockerBuild
+ .split("\n")
+ .filter((line) => /useblacksmith\/setup-docker-builder@/.test(line))
+ .map(actionRef)[0];
+const ciBuildAction = dockerBuild
+ .split("\n")
+ .filter((line) => /useblacksmith\/build-push-action@/.test(line))
+ .map(actionRef)[0];
+const ciCheckout = dockerBuild
+ .split("\n")
+ .filter((line) => /useblacksmith\/checkout@/.test(line))
+ .map(actionRef)[0];
+const ciCacheKey = firstInput(dockerBuild, "cache-key");
+const ciRunsOn = firstInput(dockerBuild, "runs-on");
+assert.ok(
+ ciBuilder,
+ "ci.yml docker-build must pin useblacksmith/setup-docker-builder",
+);
+assert.ok(
+ ciBuildAction,
+ "ci.yml docker-build must pin useblacksmith/build-push-action",
+);
+assert.ok(ciCheckout, "ci.yml docker-build must pin useblacksmith/checkout");
+assert.ok(ciCacheKey, "ci.yml docker-build must declare a cache-key");
+assert.ok(ciRunsOn, "ci.yml docker-build must declare a runs-on");
+
+const smokeBuilder = smoke
+ .split("\n")
+ .filter((line) => /useblacksmith\/setup-docker-builder@/.test(line))
+ .map(actionRef)[0];
+const smokeBuildAction = smoke
+ .split("\n")
+ .filter((line) => /useblacksmith\/build-push-action@/.test(line))
+ .map(actionRef)[0];
+const smokeCheckout = smoke
+ .split("\n")
+ .filter((line) => /checkout@/.test(line))
+ .map(actionRef)[0];
+const smokeCacheKey = firstInput(smoke, "cache-key");
+const smokeRunsOn = firstInput(smoke, "runs-on");
+
+test("browser smoke runs on the same Blacksmith runner as CI docker-build", () => {
+ // The shared builder/cache contract only works while both jobs run on
+ // Blacksmith's remote-builder runtime. A non-Blacksmith runner leaves
+ // the shared cache namespace unreachable from this workflow.
+ assert.equal(
+ smokeRunsOn,
+ ciRunsOn,
+ `smoke job runs-on must match ci.yml docker-build runs-on (${ciRunsOn})`,
+ );
+});
+
+test("browser smoke build pins the same Blacksmith setup-docker-builder as CI docker-build", () => {
+ // A different builder setup action means the smoke job no longer
+ // participates in the shared builder contract, even with a matching
+ // cache-key.
+ assert.equal(smokeBuilder, ciBuilder, `smoke job must pin ${ciBuilder}`);
+ assert.ok(
+ !/docker\/setup-buildx-action@/.test(smoke),
+ "smoke job must not fall back to docker/setup-buildx-action",
+ );
+});
+
+test("browser smoke build pins the same Blacksmith build-push-action as CI docker-build", () => {
+ // The build action identity is the source-of-truth pin. platforms, push,
+ // and load are workflow inputs read by this action, not behaviors it
+ // enforces.
+ assert.equal(
+ smokeBuildAction,
+ ciBuildAction,
+ `smoke job must pin ${ciBuildAction}`,
+ );
+ assert.ok(
+ !/docker\/build-push-action@/.test(smoke),
+ "smoke job must not fall back to docker/build-push-action",
+ );
+});
+
+test("browser smoke build shares the CI docker-build cache-key and drops the GHA cache inputs", () => {
+ // The cache-key determines the Blacksmith cache namespace. Matching the
+ // CI docker-build key is necessary for the two jobs to share warmed
+ // layers; sharing the key does not, on its own, guarantee every run
+ // is warm.
+ assert.equal(
+ smokeCacheKey,
+ ciCacheKey,
+ `smoke job must declare cache-key: ${ciCacheKey}`,
+ );
+ assert.ok(
+ !/^\s*cache-from:/m.test(smoke),
+ "smoke job must not declare cache-from (Blacksmith cache replaces GHA cache)",
+ );
+ assert.ok(
+ !/^\s*cache-to:/m.test(smoke),
+ "smoke job must not declare cache-to (Blacksmith cache replaces GHA cache)",
+ );
+});
+
+test("browser smoke build keeps the same explicit platforms/push/load and overrides only the image tag", () => {
+ // platforms, push, and load are workflow inputs the build action reads;
+ // they are not enforced by the action pin. The smoke job must keep
+ // them so the same single-platform load behavior holds. The image tag
+ // is the one knob the smoke job changes to avoid colliding with
+ // kaneo:ci in the local daemon.
+ assert.match(
+ smoke,
+ /^\s+platforms:\s*linux\/amd64/m,
+ "smoke job must pin platforms: linux/amd64",
+ );
+ assert.match(
+ smoke,
+ /^\s+push:\s*false\b/m,
+ "smoke job must declare push: false",
+ );
+ assert.match(
+ smoke,
+ /^\s+load:\s*true\b/m,
+ "smoke job must declare load: true",
+ );
+ assert.match(
+ smoke,
+ /^\s+tags:\s*kaneo-browserstack:test\b/m,
+ "smoke job must keep the kaneo-browserstack:test tag used by tests/e2e/compose.yml",
+ );
+ assert.ok(
+ !/^\s+tags:\s*kaneo:ci\b/m.test(smoke),
+ "smoke job must not reuse the CI kaneo:ci tag",
+ );
+});
+
+test("browser smoke checkout uses the Blacksmith action and persist-credentials:false", () => {
+ // persist-credentials:false prevents the checkout action from leaving
+ // its credentials available to subsequent steps. It does not, on its
+ // own, stop the runner from inheriting GITHUB_TOKEN or prove the
+ // workflow is secret-safe.
+ assert.ok(smokeCheckout, "smoke job must declare a checkout step");
+ assert.equal(
+ smokeCheckout,
+ ciCheckout,
+ `smoke job must pin the same useblacksmith/checkout action as CI (${ciCheckout})`,
+ );
+ const checkoutLine = smoke.split("\n").find((line) => /checkout@/.test(line));
+ const checkoutStart = smoke.indexOf(checkoutLine);
+ const nextStep = smoke.indexOf(
+ "\n -",
+ checkoutStart + checkoutLine.length,
+ );
+ const checkoutBlock = smoke.slice(
+ checkoutStart,
+ nextStep === -1 ? smoke.length : nextStep,
+ );
+ assert.match(
+ checkoutBlock,
+ /^\s+persist-credentials:\s*false/m,
+ "checkout step must set persist-credentials: false",
+ );
+});