Skip to content

test: add unit and end-to-end tests - #63

Merged
AnonymousXC merged 6 commits into
stagingfrom
test/51-unit-e2e
Nov 13, 2026
Merged

AnonymousXC merged 6 commits into
stagingfrom
test/51-unit-e2e

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

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 replaces dev.

  • Unit tests (Vitest), in src/**/*.test.ts, with helpers in src/test/routes.ts:

    • auth routes: login redirect (state cookie), callback (state check, code exchange, cookie flags, expiry, error categories without secrets in logs), refresh (rotation, logout during refresh, 401 ends the session), token, user info, logout (origin check);
    • registry routes: TES and WES lists (type filter, https only, 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.
    • Coverage is 100% for src/lib/, src/app/api/ and src/app/auth/api/, and the threshold keeps it there.
  • End-to-end tests (Playwright), Chromium and Firefox, in e2e/:

    • The journey: browse the WES services anonymously, log in, reject a forged login callback, submit a workflow, check that the WES service got it with the user's bearer token, see the run, log out.
    • e2e/mock/server.ts is one process that plays three services: an OIDC provider (checks client, response_type, state, redirect URI), the registry, and a WES service over https with a self-signed certificate. The app trusts the certificate via NODE_EXTRA_CA_CERTS, for the test server only. No real services are called.
  • CI (checks.yml): new jobs Test and End-to-end tests. The end-to-end job runs in the Playwright image, as in cloud-registry-ui. The checks now also run for staging, 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/ and playwright.config.ts stay out of the build context. Checked with a local docker 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.
  • End-to-end tests, run the way CI runs them (docker run … mcr.microsoft.com/playwright:v1.56.1-noble npx playwright test with CI=true): 10 passed (5 tests × Chromium, Firefox).
  • next build (part of the end-to-end run): passes.
  • CI: Lint, Build, Test and End-to-end tests pass. 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)

  • After a successful submission, the WES create form resets right away. It clears its own success message, so users get no confirmation. This is in @elixir-cloud/wes (resetForm() after setting success).
  • In Firefox, @elixir-cloud/design 2.0.0-alpha.49 throws ':host-context(.dark)' is not a valid selector from 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.
  • The "Service Info" icon in the top bar links to /dashboard/service-info, which returns 404.
  • isTimeoutError() in src/lib/axios.ts isn't used anywhere. It returns false for axios cancellations, because those are axios errors with the code ERR_CANCELED.
  • get-service-info rejects 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

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:

  • Add comprehensive Vitest unit coverage for authentication, registry, workflow, and library behavior.
  • Add Playwright end-to-end coverage for anonymous browsing, authentication, workflow submission, run listing, and logout using isolated mock services.

Bug Fixes:

  • Remove an unreachable guard from the WES probe loop without changing behavior.

Enhancements:

  • Add shared test helpers and enforce 100% coverage for library and API route code.
  • Provide self-contained OIDC, registry, and HTTPS WES mocks for end-to-end testing.

Build:

  • Add Vitest and Playwright configuration, scripts, and development dependencies.
  • Expand Docker ignore rules to exclude sensitive files and end-to-end test assets.

CI:

  • Run unit and end-to-end tests in CI, including checks for the staging branch and Playwright failure reports.

Documentation:

  • Document unit and end-to-end test commands, coverage requirements, and test environment setup in the README.

Tests:

  • Add unit tests for authentication routes, registry and service discovery routes, and shared utilities.

uniqueg and others added 5 commits November 12, 2026 05:49
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
@vercel

vercel Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
krini Ready Ready Preview Nov 12, 2026 7:17am UTC

@sourcery-ai

sourcery-ai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Remove the unreachable concurrency-loop guard while preserving the WES probe behavior.

  • src/app/api/workflows/get-wes-servers/route.ts L91

Configuration

Configure unit and end-to-end test jobs, include staging in CI, and exclude test artifacts and sensitive files from Docker build context.

  • .dockerignore L2-6, L15-18
  • .github/workflows/checks.yml L8, L13, L57-114
  • .gitignore L15-17
  • package.json L10-13, L35, L40-44
  • playwright.config.ts L1-68
  • vitest.config.mts L1-29

Documentation

Document the test suites, commands, prerequisites, coverage policy, and end-to-end scope.

  • README.md L93-112

Tests

Add isolated Playwright fixtures, mock services, and browser journeys that exercise anonymous browsing, authentication, workflow submission, and logout.

  • e2e/fixtures.ts L1-98
  • e2e/journey.spec.ts L1-108
  • e2e/mock/server.ts L1-332
  • e2e/settings.ts L1-36

Add Vitest coverage for registry and workflow API routes and their response and failure behavior.

  • src/app/api/tasks/get-tes-servers/route.test.ts L1-91
  • src/app/api/workflows/get-service-info/route.test.ts L1-142
  • src/app/api/workflows/get-wes-servers/route.test.ts L1-244

Add Vitest coverage for authentication routes and session handling, including callback state validation, token refresh, logout, and user info.

  • src/app/auth/api/callback/route.test.ts L1-194
  • src/app/auth/api/login-redirect/route.test.ts L1-82
  • src/app/auth/api/logout/route.test.ts L1-86
  • src/app/auth/api/refresh/route.test.ts L1-196
  • src/app/auth/api/token/route.test.ts L1-26
  • src/app/auth/api/user-info/route.test.ts L1-63

Add unit tests for shared library helpers and reusable route-test setup.

  • src/lib/axios.test.ts L1-63
  • src/lib/utils.test.ts L1-12
  • src/test/routes.ts L1-115

Lock files and vendored code

Update the dependency lockfile for the newly added test tooling.

  • bun.lock L259-296, L363-378, L1156-1177 (+31 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@uniqueg
uniqueg marked this pull request as ready for review November 12, 2026 07:03

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/app/auth/api/refresh/route.test.ts Resolved
Comment thread e2e/mock/server.ts Resolved
Comment thread src/lib/axios.test.ts Resolved
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
@vercel
vercel Bot temporarily deployed to Preview – krini November 12, 2026 07:17 Inactive

@AnonymousXC AnonymousXC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AnonymousXC
AnonymousXC merged commit 331e7b2 into staging Nov 13, 2026
7 checks passed
@AnonymousXC
AnonymousXC deleted the test/51-unit-e2e branch November 14, 2026 05:50
uniqueg added a commit that referenced this pull request Nov 14, 2026
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]>

This branch was previously deployed

1 inactive deployment
Preview – krini — 6dc460b2 Deployed Nov 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants