Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,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:
Expand All @@ -277,6 +278,26 @@ 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 upstream browser test dependencies
working-directory: maintainer/browser-tests
run: npm ci
- name: Install Chromium headless shell
working-directory: maintainer/browser-tests
run: npm exec -- playwright install --with-deps --only-shell chromium
- name: Exercise the staged website in Chromium
id: browser-test
working-directory: maintainer/browser-tests
env:
SKLC_SITE_DIR: ${{ runner.temp }}/static-site/public
SKLC_SITE_REVISION: ${{ github.event.pull_request.head.sha || github.sha }}
run: npm test
- 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: maintainer/browser-tests/test-results/
retention-days: 7
- name: Upload static site
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
Expand Down
4 changes: 4 additions & 0 deletions CI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `maintainer/browser-tests/`, 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 test`. 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. A website-data failure can indicate missing or outdated assessment reports. Read the diagnostics before changing anything; do not edit reports to make them appear current.
Expand Down
2 changes: 2 additions & 0 deletions maintainer/browser-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
test-results/
58 changes: 58 additions & 0 deletions maintainer/browser-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions maintainer/browser-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "sklc-browser-tests",
"private": true,
"scripts": {
"test": "playwright test"
},
"devDependencies": {
"@playwright/test": "1.65.1"
}
}
27 changes: 27 additions & 0 deletions maintainer/browser-tests/playwright.config.mjs
Original file line number Diff line number Diff line change
@@ -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",
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",
})),
});
88 changes: 88 additions & 0 deletions maintainer/browser-tests/tests/catalog.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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 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();
}

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" });
// The catalog renders before React attaches the search handler.
await expect(page.locator("astro-island:not([ssr])").filter({ has: search })).toHaveCount(1);
const unrelatedSkill = skills.filter({ hasNotText: skillId }).first().getByRole("heading").getByRole("link");
const unrelatedId = await unrelatedSkill.innerText();
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 expect(skills.getByRole("link", { name: unrelatedId, exact: true })).toHaveCount(0);
await skills.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([]);
});