Repository navigation
test: add unit and end-to-end tests - #63
Conversation
Add Vitest with v8 coverage, following cloud-registry-ui: tests of the auth routes (login redirect, callback, refresh, token, user info, logout), the registry and service info routes, and the helpers in src/lib. The covered code is at 100% and the threshold keeps it so. The tests describe the current behaviour. The concurrency guard of the WES probe is unreachable and excluded from coverage. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Add Playwright tests of the main user journey in Chromium and Firefox: browse the WES services anonymously, log in, submit a workflow with the user's token, see the run, and log out. One mock process plays the login provider, the registry and a WES service over https with a self-signed certificate; no real service is called. CI gets a Test job (unit tests with the coverage threshold) and an End-to-end tests job in the Playwright image, as in cloud-registry-ui. The README documents both. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
The rewrite lives on staging until it replaces dev, so pull requests into staging got no checks. Run them there as well. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
- Drop the unreachable guard of the WES probe instead of excluding it from coverage. - Test that deadline() aborts with a timeout; drop tests of constants. - The mock login provider checks response_type, state and the redirect URI, also at the token exchange; a new test rejects a forged callback. - Keep ports, client and the request type in e2e/settings.ts; add an accessToken() helper. - Add a timeout to the Test job; the README names the prerequisites and what isn't covered yet. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
- .dockerignore matches env files, keys and certificates at any depth and leaves out e2e/ and playwright.config.ts, so the generated test certificate never reaches the build context. - The mock serves service info for the http WES entry, so only the https rule can drop it. - setUp() unsets OIDC_SCOPE; the refresh tests check the log for a distinctive token value. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Reviewer's GuideAPIRemove the unreachable concurrency-loop guard while preserving the WES probe behavior.
ConfigurationConfigure unit and end-to-end test jobs, include staging in CI, and exclude test artifacts and sensitive files from Docker build context.
DocumentationDocument the test suites, commands, prerequisites, coverage policy, and end-to-end scope.
TestsAdd isolated Playwright fixtures, mock services, and browser journeys that exercise anonymous browsing, authentication, workflow submission, and logout.
Add Vitest coverage for registry and workflow API routes and their response and failure behavior.
Add Vitest coverage for authentication routes and session handling, including callback state validation, token refresh, logout, and user info.
Add unit tests for shared library helpers and reusable route-test setup.
Lock files and vendored codeUpdate the dependency lockfile for the newly added test tooling.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/app/auth/api/refresh/route.test.ts" line_range="152" />
<code_context>
+ it("drops the new tokens after a logout during the refresh", async () => {
+ setUp({ refresh_token: "rt-SECRET-1" });
+ vi.spyOn(await http(), "post").mockImplementation(async () => {
+ jar.set("logout_marker", { name: "logout_marker", value: "1" });
+ return { status: 200, data: tokens };
+ });
</code_context>
<issue_to_address>
**Logout leaves usable tokens**
When a logout completes while a refresh is awaiting the provider, `jar.set` mutates a shared cookie store that the in-flight refresh reads again, unlike separate request cookie snapshots. The refresh misses the completed logout and returns usable token cookies, so the test passes while the browser is reauthenticated.
Track logout state somewhere shared across requests and prevent a concurrent refresh from returning tokens after logout.
</issue_to_address>
### Comment 2
<location path="src/app/api/workflows/get-wes-servers/route.test.ts" line_range="170-180" />
<code_context>
+ expect(get).toHaveBeenCalledTimes(6);
+ });
+
+ it("keeps the list of the request that finished first", async () => {
+ let calls = 0;
+ const { GET } = await load([service("wes", urlOf("wes"))], {
+ // the second request's probe fails, but it doesn't replace the
+ // first one's list, which finished at the same time
+ wes: async () => {
+ calls++;
+ if (calls === 2) throw httpError(503);
+ return { status: 200, data: infoOf("wes") };
+ },
+ });
+ const [first, second] = await Promise.all([GET(), GET()]);
+ expect(first.headers.get("x-cache")).toBe("MISS");
</code_context>
<issue_to_address>
**Stale registry data replaces newer cache**
When overlapping requests read different registry snapshots and the older request finishes last, `GET` compares completion times, so the older request replaces the newer cache entry and callers receive stale service data for the cache TTL.
Use request start order or a generation check to prevent an older request from replacing a newer cache entry.
Also at `src/app/api/workflows/get-wes-servers/route.test.ts:181`.
</issue_to_address>
### Comment 3
<location path="e2e/mock/server.ts" line_range="248" />
<code_context>
+ return send(res, 200, { runs, next_page_token: "" }, cors);
+
+ if (req.method === "POST" && path === "/runs") {
+ await bodyOf(req);
+ const run = { run_id: `run-${runs.length + 1}`, state: "QUEUED" };
+ runs.push(run);
</code_context>
<issue_to_address>
**Invalid workflows pass the journey**
When the app sends an empty or malformed workflow request body, `bodyOf` discards the POST body and the mock creates a run for any authorized request to `/runs`, so the journey passes even when the workflow URL, type, or version is wrong.
Parse and validate the submitted workflow fields in the mock, and reject requests with missing or incorrect values.
Also at `e2e/journey.spec.ts:87-88`.
</issue_to_address>
### Comment 4
<location path="src/lib/axios.test.ts" line_range="43-44" />
<code_context>
+ });
+
+ it("rejects cancellations, which are axios errors with their own code", () => {
+ expect(isTimeoutError(new CanceledError())).toBe(false);
+ });
+
+ it("accepts cancellations of other cancel tokens", () => {
</code_context>
<issue_to_address>
**Cancellation classification is entrenched**
When a future caller passes an Axios `CanceledError` to `isTimeoutError`, `isTimeoutError` checks `axios.isAxiosError` before `axios.isCancel`, so an Axios `CanceledError` returns `false` before reaching the cancellation check. This assertion makes that inconsistent classification an expected contract for future callers.
Make the cancellation classification consistent with the helper's intended contract and test Axios `CanceledError` accordingly.
</issue_to_address>Sourcery assessment
Approval pending. 4 findings to address first.
Blocking findings: src/app/auth/api/refresh/route.test.ts:152, src/app/api/workflows/get-wes-servers/route.test.ts:180, e2e/mock/server.ts:248, src/lib/axios.test.ts:44
The mock WES service parses the run request, rejects an invalid workflow URL, type or version, and records the fields, so the journey checks what the app submits, not only that it submits. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
The route tests from #63 expected the lists before the review fixes (no verifications, errors passed on). They now cover the verified lists and fold in the integration tests of this PR, which are removed. The checks that the registry module already makes are gone from the WES list and kept as a second line of defence in the service-info route. The test of a logout during a refresh is gone with the second check (77ee55a): cookies() returns the cookies of the request, so a logout can't change them. The mock registry of the end-to-end tests serves verifications and an unverified entry. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Adds unit and end-to-end tests to the rewrite, and runs both in CI. The setup follows cloud-registry-ui (Vitest, Playwright, the same CI job pattern).
This PR targets
staging, where the rewrite lives until it replacesdev.Unit tests (Vitest), in
src/**/*.test.ts, with helpers insrc/test/routes.ts:httpsonly, probe results, cache, concurrency limit of 8, no token on registry reads), WES service info (endpoint checks:https, no user info, no port, WES path);src/lib.src/lib/,src/app/api/andsrc/app/auth/api/, and the threshold keeps it there.End-to-end tests (Playwright), Chromium and Firefox, in
e2e/:e2e/mock/server.tsis one process that plays three services: an OIDC provider (checks client,response_type,state, redirect URI), the registry, and a WES service overhttpswith a self-signed certificate. The app trusts the certificate viaNODE_EXTRA_CA_CERTS, for the test server only. No real services are called.CI (
checks.yml): new jobsTestandEnd-to-end tests. The end-to-end job runs in the Playwright image, as in cloud-registry-ui. The checks now also run forstaging, so PRs into the rewrite get checked (separate commit).Docs: a "Tests" section in the README.
.dockerignore: env files, keys and certificates are now excluded at any depth, not only at the root.e2e/andplaywright.config.tsstay out of the build context. Checked with a localdocker build.App code: one change. The unreachable guard in the WES probe loop (
get-wes-servers/route.ts) is removed, with no change in behaviour.Scope compared with the issue
The issue lists some units that the rewrite doesn't have yet: PKCE, nonce, ID token validation, the one retry after
401, tag stripping, and registry filtering by verification, version and environment. They can't be tested before they exist. They'll come with #43, #44 and #40's successor. The 100% threshold means they'll need tests when they land.The issue's end-to-end journey says "submit a task". This PR covers it with a workflow instead, because the TES pages are being reworked in #41. The README says that TES isn't covered yet.
Closes #51
Verification
bun run lint: clean.bun run test:coverage: 102 tests pass, 100% statements, branches, functions and lines.docker run … mcr.microsoft.com/playwright:v1.56.1-noble npx playwright testwithCI=true): 10 passed (5 tests × Chromium, Firefox).next build(part of the end-to-end run): passes.Lint,Build,TestandEnd-to-end testspass. The org Vercel project's deployment (Vercel – krini) fails, as it does for feat: cc wes workflows rewrite #61. That is a setting of the Vercel project, unrelated to this change.Findings while testing (not changed here)
@elixir-cloud/wes(resetForm()after settingsuccess).@elixir-cloud/design2.0.0-alpha.49 throws':host-context(.dark)' is not a valid selectorfrom the code editor. It's fixed upstream (feat: add surface, font and dark mode controls cloud-components#446). The end-to-end fixture ignores just this error until Krini upgrades./dashboard/service-info, which returns 404.isTimeoutError()insrc/lib/axios.tsisn't used anywhere. It returnsfalsefor axios cancellations, because those are axios errors with the codeERR_CANCELED.get-service-inforejects WES URLs that have a port, so the service info page can't show the mock service (https://127.0.0.1:8444). The end-to-end tests use the list, which accepts ports.Declined review findings
Dockerfilealready copies all ofnode_modulesinto the runtime stage, including Biome and TypeScript. ci: check PRs and publish images #60 (for ci: check PRs and publish images #50) replaces that with Next.js standalone output, which fixes it for all dev dependencies.checks.yml. The new jobs follow the file's existing style. The CI overhaul is ci: check PRs and publish images #50 (ci: check PRs and publish images #60).Open questions
None.
🤖 Generated with Claude Code
https://claude.ai/code/session_011FSoqMpmDCfbACLj3uy6xV
Summary by Sourcery
Establish comprehensive unit and end-to-end test coverage with isolated service mocks and enforce both test suites in CI.
New Features:
Bug Fixes:
Enhancements:
Build:
CI:
Documentation:
Tests: