Skip to content
Closed
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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ demand. Read the matching entry before starting a task it covers.
| When the task is… | Read |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| **UI-only** change to the web app (`web/`) — buttons/links, labels, layout, responsiveness, tooltips, table columns, rendering data the API already returns | [`.agents/skills/heimdall-ui.md`](.agents/skills/heimdall-ui.md) |
| **Any** change to the web app (`web/`) — points at the Next.js docs matching the installed version, and explains how to run and write tests (`pnpm test`) | [`web/AGENTS.md`](web/AGENTS.md) |
| **Any** change to the web app (`web/`) — points at the Next.js docs matching the installed version, and explains how to run and write tests (`pnpm test`), quarantine flaky tests, and keep the bundle-size budget | [`web/AGENTS.md`](web/AGENTS.md) |

## Personas — `.agents/personas/`

Expand Down
2 changes: 2 additions & 0 deletions web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

# testing
/coverage
/reports
/.stryker-tmp

# next.js
/.next/
Expand Down
40 changes: 40 additions & 0 deletions web/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,43 @@ Layout:
- `*ByTestId` queries read the `qa-test-id` attribute.

Coverage thresholds are in `vitest.config.mts` (`coverage.thresholds`). Raise them when coverage goes up. Do not lower them to make a change pass.

## Flaky tests

A flaky test passes and fails on the same code. Do not retry it until it passes, and do not add `retry` to hide it. Quarantine it, then fix it or delete it.

To quarantine a flaky test:

1. Make a ClickUp ticket for the flaky test. Write the test name, the error, and how often it fails (for example a CI run link).
2. Add the `flaky` tag to the test, and a comment with the ticket link and the fix-by date. The fix-by date is **14 days** after the day that you add the tag.

```ts
// Quarantined: https://app.clickup.com/t/<ticket-id> (fix by 2026-12-14)
it(
'applies a filter typed in the filter menu',
{ tags: ['flaky'] },
async () => {
// ...
},
)
```

3. Do one test per tag. Do not tag a full `describe` block, because that also hides the stable tests in it.

Where quarantined tests run:

- `vitest.config.mts` defines the `flaky` tag (`test.tags`). A test with this tag is skipped in `pnpm test`, in the **Build and Test** CI check, and in the mutation run. It shows as skipped in the output.
- `pnpm test:quarantine` runs only the quarantined tests (`VITEST_QUARANTINE=1 vitest run --tags-filter=flaky --passWithNoTests`). Use it to reproduce the failure and to make sure that your fix works. No CI check runs it.
- An unknown tag (for example `flakey`) fails the run, because Vitest checks tags against the config (`strictTags`).

Before the fix-by date, do one of these:

- Fix the cause (for example a missing `await`, a shared state between tests, or a timer), remove the tag, and close the ticket.
- Delete the test if it gives no value, and close the ticket with the reason.

If you cannot fix it in 14 days, write the reason in the ticket and set a new date. Do not move the date more than one time. To find all quarantined tests, search for `tags: ['flaky']` in `src/`.

## Bundle size and mutation testing

- `pnpm build` runs `pnpm check:bundle-size` after `next build`. It fails when a list page is over its JS budget in `bundle-budgets.json`. Read "Bundle-size budget" in `README.md` before you change a budget.
- `pnpm test:mutation` runs StrykerJS (`stryker.config.mjs`) on `src/common` and `src/modules/*/Helper.tsx`. It is not a PR check. The scheduled workflow for it is pending ([#190](https://github.com/patterninc/heimdall/issues/190)), so run it locally. Read "Mutation testing" in `README.md`.
50 changes: 50 additions & 0 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,53 @@ To see the API logs, run `docker compose logs -f heimdall` from the repository r
| `pnpm build` | Makes a production build (`next build`). |

CI runs `./build.sh --go --ui --test` from the repository root. That command installs the dependencies and runs `pnpm run build`.

## Bundle-size budget

`pnpm build` runs `next build`, then `pnpm check:bundle-size` (`scripts/check-bundle-size.mjs`). The check fails the build when a list page has more JavaScript than its budget. CI runs `pnpm run build` in the required **Build and Test** check (`./build.sh --ui`), so a page over budget fails the check.

The list pages are `/` (the jobs list), `/jobs`, `/commands` and `/clusters`. The budgets are in `bundle-budgets.json`. All sizes are gzip, in kB (1 kB = 1024 bytes).

The check reads `.next/diagnostics/route-bundle-stats.json`. `next build` writes this file when it uses Turbopack (the default in Next.js 16). For each list page, the check measures two values:

- **First load** (`firstLoadGzipKb`): the JS files in the page HTML. The data is from the route list that `next build` makes.
- **With page module** (`totalGzipKb`): the first-load files and all the chunks that they refer to. The list pages load their module with `next/dynamic` and `ssr: false`, so most of the list-page code is not in the first load. The browser gets these chunks immediately after the page starts. This value is the JS that the browser downloads for the page.

Baseline (measured on 2026-11-30, Next.js 16.4.3) and budgets:

| Route | First load | First-load budget | With page module | With-module budget |
| ----------- | ---------- | ----------------- | ---------------- | ------------------ |
| `/` | 220.6 kB | 245 kB | 500.8 kB | 555 kB |
| `/jobs` | 220.6 kB | 245 kB | 500.8 kB | 555 kB |
| `/commands` | 220.6 kB | 245 kB | 499.1 kB | 555 kB |
| `/clusters` | 220.6 kB | 245 kB | 498.6 kB | 555 kB |

Each budget is the baseline plus approximately 10%, rounded up to 5 kB.

To change a budget:

1. Run `pnpm build`. The check prints a table with the current sizes.
2. If a page is over budget, first try to make the bundle smaller (for example, a large import that only one page uses, or a dependency that you can load with `next/dynamic`).
3. If the increase is necessary, set the new budget in `bundle-budgets.json` to the new size plus approximately 10%. Write the old size, the new size, and the reason in the PR description.
4. If you add a list page, add its route to `bundle-budgets.json`. The check fails when a route in the file is not in the build.

To run only the check on an existing build, run `pnpm check:bundle-size`.

## Mutation testing

[StrykerJS](https://stryker-mutator.io/) with the Vitest runner changes (mutates) the code and runs the tests on each change. A change that no test catches ("survived") shows a missing assertion. The configuration is `stryker.config.mjs`. It mutates:

- `src/common/**` (not the test files)
- `src/modules/*/Helper.tsx`

Run it locally:

```bash
pnpm test:mutation
```

A full run takes approximately 4 minutes (measured on 2026-11-30 with `concurrency: 4`). The HTML report is `reports/mutation/mutation.html` and the JSON report is `reports/mutation/mutation.json`. Git ignores `reports/`.

A scheduled **Mutation Testing** workflow is pending. Until it is added, CI does not run Stryker, so run it locally. [#190](https://github.com/patterninc/heimdall/issues/190) adds `.github/workflows/mutation.yml`. It will run every Monday at 04:00 UTC and on `workflow_dispatch`, and upload the HTML and JSON reports as the `mutation-report` artifact. It will not be a PR check. Do not make it a required check. A low score does not fail Stryker (`thresholds.break` is `null`).

Stryker runs 4 Vitest processes at the same time (`concurrency: 4`). With more processes, the integration tests that wait for a debounced filter can time out in the initial test run.
8 changes: 8 additions & 0 deletions web/bundle-budgets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"routes": {
"/": { "firstLoadGzipKb": 245, "totalGzipKb": 555 },
"/clusters": { "firstLoadGzipKb": 245, "totalGzipKb": 555 },
"/commands": { "firstLoadGzipKb": 245, "totalGzipKb": 555 },
"/jobs": { "firstLoadGzipKb": 245, "totalGzipKb": 555 }
}
}
9 changes: 7 additions & 2 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"dev": "PORT=4000 next dev",
"dev:stack": "sh scripts/dev-stack.sh",
"dev:stack:down": "sh scripts/dev-stack.sh --down",
"build": "next build",
"build": "next build && pnpm check:bundle-size",
"check:bundle-size": "node scripts/check-bundle-size.mjs",
"start": "next start",
"lint": "eslint .",
"prettier": "prettier --write .",
Expand All @@ -17,7 +18,9 @@
"format": "prettier --check \"**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
"type-check": "next typegen && tsc --noEmit",
"test": "vitest run --coverage",
"test:watch": "vitest"
"test:watch": "vitest",
"test:quarantine": "VITEST_QUARANTINE=1 vitest run --tags-filter=flaky --passWithNoTests",
"test:mutation": "stryker run"
},
"dependencies": {
"@patterninc/pattern-ui": "latest",
Expand All @@ -36,6 +39,8 @@
"usehooks-ts": "^3.1.1"
},
"devDependencies": {
"@stryker-mutator/core": "^10.1.1",
"@stryker-mutator/vitest-runner": "^10.1.1",
"@tailwindcss/postcss": "^4.1.11",
"@testing-library/dom": "^10.4.2",
"@testing-library/jest-dom": "^8.0.0",
Expand Down
Loading