diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index c263d83..2648a30 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -24,3 +24,14 @@ jobs: bun-version: 1.4.0 - run: bun install --frozen-lockfile - run: bun run build + - run: bunx --no-install playwright install --with-deps chromium + - run: bun run test:browser + - name: Upload browser report + if: ${{ failure() }} + uses: actions/upload-artifact@v4 + with: + name: browser-report + path: | + playwright-report/ + test-results/ + retention-days: 7 diff --git a/.github/workflows/starlight-update.yml b/.github/workflows/starlight-update.yml new file mode 100644 index 0000000..93fe5d9 --- /dev/null +++ b/.github/workflows/starlight-update.yml @@ -0,0 +1,30 @@ +name: Update shared Starlight + +on: + repository_dispatch: + types: [starlight-release] + workflow_dispatch: + inputs: + version: + description: Published stable Starlight version (x.y.z) + required: true + type: string + +permissions: + contents: read + packages: read + +jobs: + update: + if: >- + (github.event_name == 'repository_dispatch' && + github.event.client_payload.package == '@tech0ver/starlight') || + (github.event_name == 'workflow_dispatch' && + github.ref == format('refs/heads/{0}', github.event.repository.default_branch)) + uses: tech0ver/starlight/.github/workflows/update-consumer.yml@343a40df718723aed65150befe6e323f0b7bac98 + with: + version: ${{ github.event.client_payload.version || inputs.version }} + release-url: ${{ github.event.client_payload.release_url || '' }} + secrets: + UPDATE_APP_ID: ${{ secrets.UPDATE_APP_ID }} + UPDATE_APP_PRIVATE_KEY: ${{ secrets.UPDATE_APP_PRIVATE_KEY }} diff --git a/.gitignore b/.gitignore index e6b7f22..3ff8956 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # build output dist/ +playwright-report/ +test-results/ # generated types .astro/ diff --git a/README.md b/README.md index f02d1a9..37669e6 100644 --- a/README.md +++ b/README.md @@ -25,12 +25,39 @@ production preview to check search results. ## Shared UI updates -Update `@tech0ver/starlight` in `package.json` and `bun.lock`, then rebuild. -Use the peer dependency versions documented by that release. Site settings are -in `astro.config.mjs`; articles, glossary entries, diagrams, and site extensions -stay in this repository. Shared visual changes belong in the package. +After a successful package publication, Starlight sends a `starlight-release` +event to this repository. **Update shared Starlight** calls the shared updater +pinned in `.github/workflows/starlight-update.yml`. It opens a PR with the package +version, required peer dependency versions, and `bun.lock`. Run the same workflow +manually from `main` with a published version to retry an update. Repeated events +do not create duplicate PRs or downgrade the dependency. Review release notes and +any migration before approving; updates do not merge automatically. + +The receiver must be on the default branch. Configure Actions secrets +`UPDATE_APP_ID` and `UPDATE_APP_PRIVATE_KEY` for the update GitHub App, installed +on this repository with **Contents: Read and write** and **Pull requests: Read +and write** permissions. Organization secrets can be shared with selected +repositories. See the [Starlight rollout instructions](https://github.com/tech0ver/starlight/blob/main/WORKFLOW.md#consumer-update-notifications) +for publisher setup and enabling delivery after the receiver is ready. + +To update manually, change `@tech0ver/starlight` in `package.json` and `bun.lock` +using the peer dependency versions documented by that release, then rebuild. +Site settings are in `astro.config.mjs`; articles, glossary entries, diagrams, +and site extensions stay in this repository. Shared visual changes belong in +the package. + +Pull requests run a frozen install, production build, and Chromium checks on +desktop and mobile in light and dark themes. The checks cover the home page, +articles, glossary, Markdown exports, search, theme persistence, navigation, and +browser errors. Run them against a fresh production build locally: -Pull requests run a frozen install and production build. GitHub Actions uses +```sh +bunx --no-install playwright install --with-deps chromium +bun run build +bun run test:browser +``` + +Failed CI runs upload a browser report with screenshots and traces. GitHub Actions uses `GITHUB_TOKEN` with `packages: read`; this repository must have read access under the package's **Manage Actions access** settings. Pushes to `main` build and deploy to GitHub Pages. diff --git a/bun.lock b/bun.lock index 8c5f4d5..7553a71 100644 --- a/bun.lock +++ b/bun.lock @@ -12,6 +12,7 @@ "sharp": "^0.35.3", }, "devDependencies": { + "@playwright/test": "1.64.1", "skills": "1.7.4", }, }, @@ -235,6 +236,8 @@ "@pagefind/windows-x64": ["@pagefind/windows-x64@1.5.2", "", { "os": "win32", "cpu": "x64" }, "sha512-Fa2Iyw7kaDRzGMfNYNUXNW2zbL5FQVDgSOcbDHdzBrDEdpqOqg8TcZ68F22ol6NJ9IGzvUdmeyZypLW5dyhqsg=="], + "@playwright/test": ["@playwright/test@1.64.1", "", { "dependencies": { "playwright": "1.64.1" }, "bin": { "playwright": "cli.js" } }, "sha512-IaYGml/nSOiZWROfPtuIL7neuu9qDOZ3TNvNljUIrhDMxiGTgPjzj/g9p9RxpS2tSepPDRY+UwAaEeiKtUvIAg=="], + "@rolldown/binding-android-arm-eabi": ["@rolldown/binding-android-arm-eabi@1.2.12", "", { "os": "android", "cpu": "arm" }, "sha512-dB/a1214qKfHMXCpgqR4OZT+jS4kTyEXbQGJPqzobt5EwH5rX080pxE37alt3RzvR1bf1Yz/yGqRfrYAxuPw0A=="], "@rolldown/binding-android-arm64": ["@rolldown/binding-android-arm64@1.2.12", "", { "os": "android", "cpu": "arm64" }, "sha512-7KHFgQ5VJxIHcLlrwrc3Xbds7oTNQT7Pgi9gQCJKrd2VGab/UksIOYp6VD8MzCstGxOKMgNamPwUCfxPdP1OHg=="], @@ -643,6 +646,10 @@ "picomatch": ["picomatch@4.0.7", "", {}, "sha512-qcJu88Q2IWqJsDD529JKMdwGm/dvInW4HvQnRwiH9JtihJvzGOscDtHE3x1pBKeUOTysQ8kVmLnJ2kJu7yhcGA=="], + "playwright": ["playwright@1.64.1", "", { "dependencies": { "playwright-core": "1.64.1" }, "bin": { "playwright": "cli.js" } }, "sha512-HCrVhHr5QQuwYoswEUGTb7gGp522yflbv/ST8nF4sFWGuLjQCt17Q/EubpGGSNKYn1tsTCPZxqHhHCfVURu7UA=="], + + "playwright-core": ["playwright-core@1.64.1", "", { "bin": { "playwright-core": "cli.js" } }, "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ=="], + "postcss": ["postcss@8.5.29", "", { "dependencies": { "nanoid": "^3.3.19", "picocolors": "^1.1.1", "source-map-js": "^1.2.2" } }, "sha512-49cGhUbXj8Qenv0iTMxA1cFBzxXoctpC9Ujd77t1WcbJIr6nF/eI7g/8MgxrYldFRuAXvja7xQRwavoW7kgrxQ=="], "postcss-nested": ["postcss-nested@6.2.0", "", { "dependencies": { "postcss-selector-parser": "^6.1.1" }, "peerDependencies": { "postcss": "^8.2.14" } }, "sha512-HQbt28KulC5AJzG+cZtj9kvKB93CFCdLvog1WFLf1D+xmMvPGlBstkpTEZfK5+AN9hfJocyBFCNiqyS48bpgzQ=="], diff --git a/package.json b/package.json index 1626e27..ef0de5d 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "dev": "astro dev", "build": "astro build", "preview": "astro preview", + "test:browser": "playwright test", "astro": "astro", "skills": "skills", "skills:list": "skills list --agent codex claude-code", @@ -19,6 +20,7 @@ "sharp": "^0.35.3" }, "devDependencies": { + "@playwright/test": "1.64.1", "skills": "1.7.4" } } diff --git a/playwright.config.ts b/playwright.config.ts new file mode 100644 index 0000000..b1ab994 --- /dev/null +++ b/playwright.config.ts @@ -0,0 +1,30 @@ +import { defineConfig } from '@playwright/test'; + +export default defineConfig({ + testDir: './tests/browser', + fullyParallel: true, + forbidOnly: Boolean(process.env.CI), + workers: process.env.CI ? 2 : undefined, + reporter: [['list'], ['html', { open: 'never' }]], + use: { + baseURL: 'http://127.0.0.1:4322/sysdes/', + browserName: 'chromium', + trace: 'retain-on-failure', + screenshot: 'only-on-failure', + }, + projects: (['light', 'dark'] as const).flatMap((colorScheme) => [ + { + name: `desktop-${colorScheme}`, + use: { viewport: { width: 1440, height: 900 }, colorScheme }, + }, + { + name: `mobile-${colorScheme}`, + use: { viewport: { width: 393, height: 851 }, isMobile: true, hasTouch: true, colorScheme }, + }, + ]), + webServer: { + command: 'bun run preview --host 127.0.0.1 --port 4322 --ignore-lock', + url: 'http://127.0.0.1:4322/sysdes/', + reuseExistingServer: false, + }, +}); diff --git a/tests/browser/site.spec.ts b/tests/browser/site.spec.ts new file mode 100644 index 0000000..1500818 --- /dev/null +++ b/tests/browser/site.spec.ts @@ -0,0 +1,78 @@ +import { test as base, expect } from '@playwright/test'; + +const test = base.extend({ + page: async ({ page }, use) => { + const errors: string[] = []; + 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.url().startsWith('http://127.0.0.1:4322/') && response.status() >= 400) { + errors.push(`${response.status()} ${response.url()}`); + } + }); + // Keep checks independent of analytics availability and avoid sending test visits. + await page.route('https://www.googletagmanager.com/**', (route) => + route.fulfill({ contentType: 'application/javascript', body: '' })); + await page.route('https://**.google-analytics.com/**', (route) => + route.fulfill({ status: 204 })); + await use(page); + expect(errors, 'Browser errors and missing local assets').toEqual([]); + }, +}); + +test('home, article, glossary, and article exports work under the site base', async ({ page, request }) => { + await page.goto('./'); + await expect(page.getByRole('heading', { level: 1 })).toContainText('SystemDesign0ver'); + await page.goto('fundamentals/networking/'); + await expect(page.getByRole('heading', { level: 1 })).toHaveText('Networking'); + await page.goto('glossary/'); + await expect(page.getByRole('heading', { level: 1 })).toHaveText('Glossary'); + await expect(page.getByRole('heading', { level: 2 }).first()).toBeVisible(); + const index = await request.get('llms.txt'); + expect(index.ok()).toBeTruthy(); + expect(await index.text()).toContain('/sysdes/fundamentals/networking.md'); + const article = await request.get('fundamentals/networking.md'); + expect(article.ok()).toBeTruthy(); + expect(await article.text()).toContain('Networking'); +}); + +test('theme follows the browser and preserves an explicit choice after reload', async ({ page }, testInfo) => { + await page.goto('fundamentals/networking/'); + const initial = testInfo.project.use.colorScheme; + const selected = initial === 'dark' ? 'light' : 'dark'; + await expect(page.locator('html')).toHaveAttribute('data-theme', initial!); + await page.getByRole('button', { name: 'Toggle theme' }).click(); + await expect(page.locator('html')).toHaveAttribute('data-theme', selected); + await page.reload(); + await expect(page.locator('html')).toHaveAttribute('data-theme', selected); +}); + +test('search loads the production index and opens an article', async ({ page }) => { + await page.goto('./'); + await page.getByRole('button', { name: 'Search', exact: true }).click(); + const dialog = page.getByRole('dialog', { name: 'Search' }); + await expect(dialog).toBeVisible(); + await dialog.getByRole('textbox', { name: 'Search', exact: true }).fill('networking'); + const result = dialog.getByRole('link', { name: 'Networking', exact: true }) + .and(dialog.locator('a[href="/sysdes/fundamentals/networking/"]')); + await expect(result).toBeVisible(); + await result.click(); + await expect(page).toHaveURL(/\/sysdes\/fundamentals\/networking\/$/); + await expect(page.getByRole('heading', { level: 1 })).toHaveText('Networking'); +}); + +test('sidebar navigation works on desktop and through the mobile menu', async ({ page }, testInfo) => { + await page.goto('./'); + const sidebar = page.locator('#starlight__sidebar'); + if (testInfo.project.use.isMobile) { + await expect(sidebar).toBeHidden(); + await page.getByRole('button', { name: 'Menu', exact: true }).click(); + } + await expect(sidebar).toBeVisible(); + await sidebar.getByRole('link', { name: /^Networking\b/ }).click(); + await expect(page).toHaveURL(/\/sysdes\/fundamentals\/networking\/$/); + await expect(page.getByRole('heading', { level: 1 })).toHaveText('Networking'); + if (testInfo.project.use.isMobile) await expect(sidebar).toBeHidden(); +});