From be93b28b776bb7d8f276542b29b3804366e24275 Mon Sep 17 00:00:00 2001 From: Nicholas Louque Date: Tue, 24 Nov 2026 12:11:42 -0700 Subject: [PATCH 1/3] test(site): exercise the staged exchange in Chromium --- .github/workflows/ci.yml | 20 ++++- CI.md | 4 + .../deployment-kit/operator/site/.gitignore | 1 + .../operator/site/package-lock.json | 46 +++++++++++ .../deployment-kit/operator/site/package.json | 2 + .../operator/site/playwright.config.mjs | 27 +++++++ .../operator/site/tests/e2e/catalog.spec.mjs | 76 +++++++++++++++++++ 7 files changed, 175 insertions(+), 1 deletion(-) create mode 100644 products/deployment-kit/operator/site/playwright.config.mjs create mode 100644 products/deployment-kit/operator/site/tests/e2e/catalog.spec.mjs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5196c49..f9a07f0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -442,12 +442,13 @@ jobs: - markdown - workflows runs-on: ubuntu-latest - timeout-minutes: 15 + timeout-minutes: 20 steps: - name: Check out repository uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: ref: ${{ github.event.pull_request.head.sha || github.sha }} + persist-credentials: false - name: Download exchange data uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 with: @@ -472,6 +473,23 @@ jobs: python -m sklc_maintainer.packaging prebuilt --stage --repo-root . --site-dir products/deployment-kit/operator/site/dist --output-dir "$RUNNER_TEMP/static-site" + - name: Install Chromium headless shell + working-directory: products/deployment-kit/operator/site + run: npm exec -- playwright install --with-deps --only-shell chromium + - name: Exercise the staged website in Chromium + id: browser-test + working-directory: products/deployment-kit/operator/site + env: + SKLC_SITE_DIR: ${{ runner.temp }}/static-site/public + SKLC_SITE_REVISION: ${{ github.event.pull_request.head.sha || github.sha }} + run: npm run test:e2e + - name: Save browser failure traces + if: failure() && steps.browser-test.outcome == 'failure' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: browser-test-results + path: products/deployment-kit/operator/site/test-results/ + retention-days: 7 - name: Upload static site uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 with: diff --git a/CI.md b/CI.md index 3fdddce..95398c0 100644 --- a/CI.md +++ b/CI.md @@ -66,6 +66,10 @@ Python prepares the website's data and downloads under `products/deployment-kit/ ### Find a result and decide what to do +Before uploading the Prebuilt website, the **Static site artifact** job serves its staged files at the root of one local server and under `/public/` on another. Chromium searches the catalog, opens a skill, reads its assessment reports and downloads its ZIP at both addresses. A failed journey stops the upload. Open the failed step for the assertion and download `browser-test-results` from the run summary for the Playwright trace. + +To repeat the check locally, extract the `static-site` artifact into its own directory. From `products/deployment-kit/operator/site/`, run `npm ci` and `npm exec -- playwright install --only-shell chromium` (on Linux, add `--with-deps`). Set `SKLC_SITE_DIR` to the absolute path of the extracted `public/` directory and `SKLC_SITE_REVISION` to the commit used to build it, then run `npm run test:e2e`. The test uses Python on PATH and loopback ports 4173 and 4174. + Open the PR's checks, or select the relevant run on the [CI Actions page](https://github.com/Code-dot-mil/SkLC/actions/workflows/ci.yml). Confirm that the run belongs to the commit you want to inspect. Open a failed job and its failed step to read the log, the recorded output of its commands. For a failed test or lint check, use the log to identify whether the affected code or file needs correction, or whether the job could not run its tools. An assessment or website-data failure may instead mean missing provider access, a failed review, or reports that do not match the skills. Read the diagnostics before changing anything; do not edit reports to make them appear current. diff --git a/products/deployment-kit/operator/site/.gitignore b/products/deployment-kit/operator/site/.gitignore index f769e76..ff67cd1 100644 --- a/products/deployment-kit/operator/site/.gitignore +++ b/products/deployment-kit/operator/site/.gitignore @@ -2,3 +2,4 @@ node_modules/ dist/ .astro/ public/downloads/ +test-results/ diff --git a/products/deployment-kit/operator/site/package-lock.json b/products/deployment-kit/operator/site/package-lock.json index 85d5917..2222859 100644 --- a/products/deployment-kit/operator/site/package-lock.json +++ b/products/deployment-kit/operator/site/package-lock.json @@ -14,6 +14,7 @@ "devDependencies": { "@astrojs/check": "0.9.12", "@eslint/js": "10.0.1", + "@playwright/test": "1.65.1", "@types/react": "19.3.0", "@types/react-dom": "19.3.0", "eslint": "10.15.0", @@ -2018,6 +2019,22 @@ "url": "https://opencollective.com/pkgr" } }, + "node_modules/@playwright/test": { + "version": "1.65.1", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.65.1.tgz", + "integrity": "sha512-y+NCIRm2LvY4slUVWvGh1nujJ8RF/hEisIsq2mtUPgdQC4L701bq5hZGMhrpeXjACvwvO9tj5dJqhvM6TP9lbw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright": "1.65.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/@rolldown/binding-android-arm-eabi": { "version": "1.2.19", "resolved": "https://registry.npmjs.org/@rolldown/binding-android-arm-eabi/-/binding-android-arm-eabi-1.2.19.tgz", @@ -7150,6 +7167,35 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/playwright": { + "version": "1.65.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.65.1.tgz", + "integrity": "sha512-vJ1FuoOrNwOKHUIVEvSt3jT1L+wjjDpwhwIstKtfvTh8XIG4FG4bIFuvNdMxi81LGfAhUgUZleVFaOLY4RIUUw==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.65.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/playwright-core": { + "version": "1.65.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.65.1.tgz", + "integrity": "sha512-hqPpz7blSMPxWVdoeE1yiBSzXsKiVOd2k+kjCvmUywD2GPO2Dd9HfcWnq9NN0GHbNZDFgZ9JfBFr+X5/BLo0qw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, "node_modules/postcss": { "version": "8.5.32", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.5.32.tgz", diff --git a/products/deployment-kit/operator/site/package.json b/products/deployment-kit/operator/site/package.json index 1f672b5..cb00b89 100644 --- a/products/deployment-kit/operator/site/package.json +++ b/products/deployment-kit/operator/site/package.json @@ -7,6 +7,7 @@ "lint:code": "eslint .", "typecheck:astro": "astro check", "test": "node --test tests/*.test.mjs", + "test:e2e": "playwright test", "typecheck": "tsc --noEmit" }, "dependencies": { @@ -19,6 +20,7 @@ "devDependencies": { "@astrojs/check": "0.9.12", "@eslint/js": "10.0.1", + "@playwright/test": "1.65.1", "@types/react": "19.3.0", "@types/react-dom": "19.3.0", "eslint": "10.15.0", diff --git a/products/deployment-kit/operator/site/playwright.config.mjs b/products/deployment-kit/operator/site/playwright.config.mjs new file mode 100644 index 0000000..41e61a1 --- /dev/null +++ b/products/deployment-kit/operator/site/playwright.config.mjs @@ -0,0 +1,27 @@ +import { basename, dirname, resolve } from "node:path"; +import { defineConfig } from "@playwright/test"; + +if (!process.env.SKLC_SITE_DIR || !process.env.SKLC_SITE_REVISION) { + throw new Error("Set SKLC_SITE_DIR to the staged public directory and SKLC_SITE_REVISION to its source commit."); +} +const site = resolve(process.env.SKLC_SITE_DIR); +if (basename(site) !== "public") throw new Error("Expected the Prebuilt artifact's public directory."); + +const mounts = [ + { name: "root", cwd: site, port: 4173, path: "/" }, + { name: "nested", cwd: dirname(site), port: 4174, path: "/public/" }, +]; +const url = mount => `http://127.0.0.1:${mount.port}${mount.path}`; + +export default defineConfig({ + testDir: "./tests/e2e", + workers: 1, + globalTimeout: 180_000, + use: { trace: "retain-on-failure" }, + projects: mounts.map(mount => ({ name: mount.name, use: { baseURL: url(mount) } })), + webServer: mounts.map(mount => ({ + command: `python -m http.server ${mount.port} --bind 127.0.0.1`, + cwd: mount.cwd, + url: url(mount) + "index.html", + })), +}); diff --git a/products/deployment-kit/operator/site/tests/e2e/catalog.spec.mjs b/products/deployment-kit/operator/site/tests/e2e/catalog.spec.mjs new file mode 100644 index 0000000..3ebb087 --- /dev/null +++ b/products/deployment-kit/operator/site/tests/e2e/catalog.spec.mjs @@ -0,0 +1,76 @@ +import { execFileSync } from "node:child_process"; +import { readFile } from "node:fs/promises"; +import { join } from "node:path"; +import { expect, test } from "@playwright/test"; + +async function followDownload(page, link, filename) { + const [download] = await Promise.all([page.waitForEvent("download"), link.click()]); + expect(download.suggestedFilename()).toBe(filename); + expect(await download.failure()).toBeNull(); + return download.path(); +} + +test("find a skill, read its evidence and download its package", async ({ page, baseURL }) => { + const errors = []; + page.on("pageerror", error => errors.push(error.message)); + page.on("console", message => { + if (message.type() === "error") errors.push(message.text()); + }); + page.on("response", response => { + if (response.status() >= 400) errors.push(`${response.status()} ${response.url()}`); + }); + + await page.goto("./"); + await expect(page.getByRole("contentinfo")).toContainText(process.env.SKLC_SITE_REVISION.slice(0, 8)); + const skills = page.getByRole("article"); + const firstSkill = skills.first().getByRole("heading").getByRole("link"); + await expect(firstSkill).toBeVisible(); + const skillId = await firstSkill.innerText(); + const initialCount = await skills.count(); + const search = page.getByRole("textbox", { name: "Search" }); + await search.fill("sklc-e2e-no-such-skill-73c92e1a"); + await expect(skills).toHaveCount(0); + await search.fill(""); + await expect(skills).toHaveCount(initialCount); + await search.fill(skillId); + await page.getByRole("link", { name: skillId, exact: true }).click(); + await expect(page.locator("header").getByRole("heading", { level: 1, name: skillId, exact: true })).toBeVisible(); + const instructions = page.getByRole("tabpanel", { name: "Instructions", exact: true }).locator(".markdown-body"); + await expect(instructions).toBeVisible(); + await expect(instructions).toHaveText(/\S/, { useInnerText: true }); + + const files = join(process.env.SKLC_SITE_DIR, "downloads"); + const filename = `${skillId}.zip`; + const archive = await followDownload(page, page.getByRole("link", { name: "Download skill package" }), filename); + expect(await readFile(archive)).toEqual(await readFile(join(files, filename))); + // Reading the ZIP entry checks its CRC and UTF-8 text. + const instructionLength = execFileSync("python", [ + "-c", `import sys, zipfile +with zipfile.ZipFile(sys.argv[1]) as package: + print(len(package.read(sys.argv[2]).decode("utf-8").strip()))`, + archive, `${skillId}/SKILL.md`, + ], { encoding: "utf8" }); + expect(Number(instructionLength)).toBeGreaterThan(0); + + await page.getByRole("tab", { name: "Assessment Evidence" }).click(); + const reports = join(files, "assessments", skillId); + const adjudication = await followDownload(page, page.getByRole("link", { name: "Download adjudication.json" }), "adjudication.json"); + const decision = await readFile(adjudication); + expect(JSON.parse(decision).findings).toEqual(expect.any(Array)); + expect(decision).toEqual(await readFile(join(reports, "adjudication.json"))); + + // The scanner link opens its native JSON report in the browser. + const [scannerResponse] = await Promise.all([ + page.waitForResponse(response => response.request().isNavigationRequest()), + page.getByRole("link", { name: /download .*scanner output/i }).click(), + ]); + expect(scannerResponse.ok()).toBe(true); + const scan = await scannerResponse.body(); + expect(JSON.parse(scan).issues).toEqual(expect.any(Array)); + expect(scan).toEqual(await readFile(join(reports, "skillspector.json"))); + await page.goBack(); + await page.getByRole("link", { name: "Back to catalog" }).click(); + await expect(page).toHaveURL(baseURL); + await expect(skills).toHaveCount(initialCount); + expect(errors).toEqual([]); +}); From b35b33cc0fc74d90c859077be6900b7720a0222e Mon Sep 17 00:00:00 2001 From: Nicholas Louque Date: Tue, 24 Nov 2026 12:15:59 -0700 Subject: [PATCH 2/3] test(site): report HTTP errors for broken download links --- .../operator/site/tests/e2e/catalog.spec.mjs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/products/deployment-kit/operator/site/tests/e2e/catalog.spec.mjs b/products/deployment-kit/operator/site/tests/e2e/catalog.spec.mjs index 3ebb087..ed11b5e 100644 --- a/products/deployment-kit/operator/site/tests/e2e/catalog.spec.mjs +++ b/products/deployment-kit/operator/site/tests/e2e/catalog.spec.mjs @@ -4,7 +4,14 @@ import { join } from "node:path"; import { expect, test } from "@playwright/test"; async function followDownload(page, link, filename) { - const [download] = await Promise.all([page.waitForEvent("download"), link.click()]); + const target = await link.evaluate(anchor => anchor.href); + const httpFailure = page.waitForResponse(response => response.url() === target && response.status() >= 400).then(response => { + throw new Error(`Download failed with HTTP ${response.status()}: ${target}`); + }); + const [download] = await Promise.all([ + Promise.race([page.waitForEvent("download"), httpFailure]), + link.click(), + ]); expect(download.suggestedFilename()).toBe(filename); expect(await download.failure()).toBeNull(); return download.path(); From 8d0c0c986c1bc3458049e1d8dbae1c1b0039fe92 Mon Sep 17 00:00:00 2001 From: Nicholas Louque Date: Wed, 2 Dec 2026 10:47:12 -0700 Subject: [PATCH 3/3] ci: rerun checks after resolving merge conflicts GitHub did not schedule a run when the merge conflict was resolved. This commit retriggers PR CI without changing the reviewed tree.