Skip to content

chore/test: add more tests for frontend - #100

Merged
HardMax71 merged 11 commits into
mainfrom
test/frontend-e2e
Jan 25, 2026
Merged

chore/test: add more tests for frontend#100
HardMax71 merged 11 commits into
mainfrom
test/frontend-e2e

Conversation

@HardMax71

@HardMax71 HardMax71 commented Jan 24, 2026

Copy link
Copy Markdown
Owner

Summary by cubic

Configured Codecov component coverage and updated badges. Migrated the frontend to svelte-sonner toasts and event-source-plus for notifications, refactored execution streaming to a fetch-based SSE reader with abort support, aligned admin events and rate-limit responses to typed models, added SSE endpoint schemas, and regenerated the API SDK/types with a fix for empty 200 JSON responses.

  • Refactors
    • Added Codecov component_management for backend/frontend and ignored test files; switched README badges to component badges.
    • Replaced custom toast store and SSE handling with svelte-sonner and event-source-plus (notificationStream); updated NotificationCenter, routes, tests, and e2e selectors.
    • Refactored execution stream from EventSource to fetch-based SSE parsing with abort/cancellation and fallback result fetch; updated result endpoint usage.
    • Regenerated OpenAPI SDK/types and updated config; fixed client JSON parsing for empty bodies, improved request body serialization, and typed admin events (DomainEvent/EventSummary), rate limit models (EndpointGroup/RateLimitAlgorithm), and SSE event data.

Written for commit ad89e21. Summary will update on new commits.

Summary by CodeRabbit

  • Chores

    • Component-aware coverage config and updated backend/frontend badges; added frontend deps for streaming and toast UI.
  • New Features

    • Centralized notification stream client and event delivery; execution streaming now supports abort and resilient fallback.
  • Refactor

    • Replaced local toast store/UI with a third‑party toast component across the frontend.
  • Bug Fixes

    • Safer JSON handling for empty responses; client-side 1MB upload size validation.
  • Tests

    • Updated and removed toast/notification tests to match new APIs.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Jan 24, 2026

Copy link
Copy Markdown

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds Codecov component configuration and badge updates; replaces a custom Svelte toast/store with svelte-sonner; introduces a NotificationStream SSE wrapper and integrates it into NotificationCenter; swaps several SSE flows for fetch-based streaming and updates generated API/client types and backend event schemas.

Changes

Cohort / File(s) Summary
Codecov config
\.github/codecov.yml
Add component_management with backend/frontend path globs and extend ignore globs for test files.
Docs / badges
README.md
Update backend/frontend Codecov badge URLs and links to component-specific endpoints.
Frontend deps & OpenAPI config
frontend/package.json, frontend/openapi-ts.config.ts
Add svelte-sonner and event-source-plus; change OpenAPI output config from format: 'prettier'postProcess: ['prettier'].
Toast system removed
frontend/src/components/ToastContainer.svelte, frontend/src/stores/toastStore.ts, frontend/src/stores/__tests__/toastStore.test.ts, frontend/src/components/__tests__/ToastContainer.test.ts
Remove custom toast UI/store and their tests (exports/types/functions deleted).
Toast migration (call sites & tests)
frontend/src/App.svelte, frontend/src/components/editor/OutputPanel.svelte, frontend/src/lib/api-interceptors.ts, frontend/src/routes/*.svelte, frontend/src/routes/admin/*.svelte, frontend/src/routes/admin/__tests__/*, ...
Replace addToast imports/usages with import { toast } from 'svelte-sonner' and toast.success/error/info/warning; update tests to mock svelte-sonner toast API and expectations.
Notification stream impl & integration
frontend/src/lib/notifications/stream.svelte.ts, frontend/src/components/NotificationCenter.svelte, frontend/src/components/__tests__/NotificationCenter.test.ts
Add NotificationStream (EventSourcePlus) singleton; refactor NotificationCenter to use notificationStream.connect/disconnect; update tests to mock the stream instead of global EventSource.
API client: SSE & JSON handling
frontend/src/lib/api/client/client.gen.ts
JSON parsing guards against empty body; SSE client creation now passes serializedBody derived from request body.
API surface & generated types
frontend/src/lib/api/index.ts, frontend/src/lib/api/sdk.gen.ts, frontend/src/lib/api/types.gen.ts
Rename several API functions to include Executions path segment; expand/reorder exported types; remove three EventType literals; extend ReplayFilter with event_ids, correlation_id, aggregate_id, and exclude_event_types.
Execution streaming & abort
frontend/src/lib/editor/execution.svelte.ts
Replace SSE streaming with abortable fetch-based streaming; add exported abort() on execution state; add fetchResult fallback and phase handling refactor.
Backend event schemas & routes
backend/app/api/routes/admin/events.py, backend/app/schemas_pydantic/admin_events.py, backend/app/schemas_pydantic/events.py, backend/app/api/routes/events.py, backend/app/api/routes/execution.py, backend/app/domain/events/typed.py, backend/app/services/admin/admin_events_service.py, backend/tests/e2e/test_admin_events_routes.py
Replace dict-based event responses with domain DomainEvent/EventSummary types; add EventSummaryResponse; remove TypeAdapter adapters and return domain event objects directly; update tests to use attribute access.
Frontend admin/user rate limits & types
frontend/src/components/admin/users/RateLimitsModal.svelte, frontend/src/lib/admin/users/rateLimits.ts
Switch API types from UserRateLimit/RateLimitRule to UserRateLimitConfigResponse/RateLimitRuleResponse; update interfaces, defaults, and function signatures.
Notification tests & e2e
frontend/e2e/fixtures.ts, various tests
Update e2e toast selector to Sonner data attribute and adapt tests to new toast API and notificationStream mocks.
Misc small edits
frontend/src/stores/auth.ts, frontend/src/stores/errorStore.ts, frontend/src/components/ErrorDisplay.svelte, frontend/src/components/admin/events/EventDetailsModal.svelte, frontend/src/components/admin/events/EventsTable.svelte, frontend/src/routes/admin/__tests__/test-utils.ts
Remove unused imports/destructured bindings, adapt derived store API usage, move correlation_id into nested metadata, adjust test fixtures and event mock utilities to nested metadata shape.

Sequence Diagram(s)

sequenceDiagram
  participant NC as NotificationCenter
  participant NS as notificationStream
  participant ES as EventSourcePlus
  participant Store as notificationStore

  NC->>NS: connect(token, onNotification)
  NS->>ES: open /api/v1/events/notifications/stream
  ES-->>NS: event(payload)
  NS->>NS: parse & filter (ignore heartbeat/connected/subscribed)
  NS->>NC: onNotification(notification)
  NC->>Store: push notification
  Note over NC,Store: optionally show Browser Notification if permitted
  NC->>NS: disconnect() on logout/destroy
  NS->>ES: abort/close connection
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • chore: frontend updates #44 — overlaps toast/notification migration and related test updates (migration to svelte-sonner and notificationStream).
  • chore: type fixes #74 — related backend/frontend event domain changes (DomainEvent/EventSummary and schema/typing updates).
  • codecov fix #41 — related to CI/Codecov configuration and component-level coverage settings.

Suggested labels

enhancement

Poem

🐰 I hopped in with a tiny cheer,
Tossed old toasts and called sonner near,
Streams now hum and badges gleam,
Events march tidy, types redeem,
🥕

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title 'chore/test: add more tests for frontend' is vague and misleading. The PR does not primarily add tests; it performs major migrations (toast system, SSE handling, execution streaming, API types) and configuration updates across both frontend and backend. Revise the title to reflect the main changes, such as 'refactor: migrate to svelte-sonner and event-source-plus with API updates' or describe the primary objective more accurately.
Docstring Coverage ⚠️ Warning Docstring coverage is 24.39% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cubic-dev-ai cubic-dev-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.

No issues found across 2 files

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@frontend/src/lib/api/client/client.gen.ts`:
- Around line 188-194: Update the JSON response handling in the case 'json'
block so that whitespace-only bodies don't cause JSON.parse to throw: after
reading response.text() trim the text and treat empty trimmed strings as an
empty object, otherwise call JSON.parse on the trimmed text; apply the same
change to the generator template if client.gen.ts is generated so future outputs
include the trim before parsing.

Comment thread frontend/src/lib/api/client/client.gen.ts

@cubic-dev-ai cubic-dev-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.

1 issue found across 5 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="frontend/src/components/NotificationCenter.svelte">

<violation number="1" location="frontend/src/components/NotificationCenter.svelte:35">
P2: The stream connection runs unconditionally after the async load completes. If the user logs out before the promise resolves, this reconnects while unauthenticated. Add an auth check inside the callback to avoid connecting after logout.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread frontend/src/components/NotificationCenter.svelte

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@frontend/src/components/NotificationCenter.svelte`:
- Around line 29-47: The reactive effect around $isAuthenticated can race: if
logout occurs before notificationStore.load(20) resolves the .then() will still
call notificationStream.connect and hasLoadedInitialData is set prematurely; fix
by introducing a per-effect cancellation guard (e.g., let cancelled = false and
a cleanup that sets cancelled = true and disconnects) inside the $effect so
callbacks check !cancelled and $isAuthenticated before calling
notificationStream.connect, only set hasLoadedInitialData after a successful
load, add .catch to handle load errors (reset hasLoadedInitialData to false and
log/handle the error), and ensure onDestroy also triggers the same cleanup to
prevent stale reconnects.

In `@frontend/src/lib/notifications/stream.svelte.ts`:
- Around line 18-24: The EventSourcePlus initialization for
'/api/v1/events/notifications/stream' is missing auth; update the
EventSourcePlus options in the EventSourcePlus(...) call to include
authentication: if your backend expects bearer JWT, read the token from your
auth store/session and add an Authorization: Bearer <token> header to the
headers object; if your backend uses cookie/session auth, add credentials:
'include' to the options instead (you may include both if appropriate). Ensure
the modified EventSourcePlus(...) call retains existing options (maxRetryCount,
maxRetryInterval, Accept header) while adding the chosen auth configuration.

Comment thread frontend/src/components/NotificationCenter.svelte
Comment thread frontend/src/lib/notifications/stream.svelte.ts

@cubic-dev-ai cubic-dev-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.

2 issues found across 2 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="frontend/src/lib/editor/execution.svelte.ts">

<violation number="1" location="frontend/src/lib/editor/execution.svelte.ts:66">
P2: Terminal failure paths return without cancelling the SSE fetch, leaving the stream open. Abort or cancel before returning the fallback result.</violation>

<violation number="2" location="frontend/src/lib/editor/execution.svelte.ts:95">
P2: Terminal SSE events return without cancelling the fetch stream, which can leave the connection open. Abort or cancel the reader before returning a result.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread frontend/src/lib/editor/execution.svelte.ts
Comment thread frontend/src/lib/editor/execution.svelte.ts

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@frontend/src/lib/editor/execution.svelte.ts`:
- Around line 55-110: The streamResult function assumes response.body is
non-null and calls response.body!.getReader(), which can throw; update
streamResult to guard that response.body exists before calling getReader():
after confirming response.ok, check if response.body is truthy and if not,
release the abortController (if needed) and fall back to returning
fetchResult(executionId) (or throw a clear error), otherwise call
response.body.getReader(); ensure you reference streamResult, response,
reader/getReader, and fetchResult in your change so the null-body case is
handled safely.
- Around line 32-52: The execute function can update shared state from stale
async runs; add a per-run token (e.g., const runToken = Symbol() or unique id)
assigned to a local variable at start and store it on the instance (e.g.,
currentRunToken = runToken) when creating the per-run abortController, then
guard every async state update (setting phase, result, error, and clearing
abortController) by checking that currentRunToken === runToken so only the
latest run mutates shared variables; ensure streamResult and the catch/finally
blocks check the token before writing phase/error/abortController and avoid
overriding newer runs when an older run is aborted.

Comment thread frontend/src/lib/editor/execution.svelte.ts
Comment thread frontend/src/lib/editor/execution.svelte.ts

@cubic-dev-ai cubic-dev-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.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="frontend/src/routes/Editor.svelte">

<violation number="1" location="frontend/src/routes/Editor.svelte:251">
P3: Clear the file input before returning on an oversized upload so users can re-select the same file after the error.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread frontend/src/routes/Editor.svelte

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@frontend/src/routes/Editor.svelte`:
- Around line 244-253: The handleFileUpload handler (and any similar file
handlers between lines 246-281) returns early on oversize/invalid type without
clearing the file input, preventing subsequent identical selections from firing
change; modify handleFileUpload to always reset the input value (e.g.,
(event.target as HTMLInputElement).value = '') in a finally block so the input
is cleared whether the file is accepted or not, referencing MAX_FILE_SIZE and
the handleFileUpload function to locate the logic that currently calls
toast.error and returns early.

Comment thread frontend/src/routes/Editor.svelte

@cubic-dev-ai cubic-dev-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.

1 issue found across 17 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="frontend/src/lib/api-interceptors.ts">

<violation number="1" location="frontend/src/lib/api-interceptors.ts:148">
P2: unwrap now throws on undefined data, but several API calls (e.g., DELETE returning 204/void) legitimately return no body. This will convert successful deletes into errors. Consider allowing empty responses (e.g., an `allowEmpty` flag or skipping the empty check for void endpoints).</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread frontend/src/lib/api-interceptors.ts

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@frontend/src/lib/editor/execution.svelte.ts`:
- Around line 125-131: In fetchResult, avoid the non-null assertion on data;
after calling getResultApiV1ExecutionsExecutionIdResultGet check whether data is
defined and valid and if not throw a descriptive error (e.g., "Empty or
malformed response for executionId: <executionId>") so callers get a clear
failure instead of a runtime crash; update fetchResult to validate data before
returning.
♻️ Duplicate comments (4)
frontend/src/lib/editor/execution.svelte.ts (4)

72-75: Abort controller not cancelled before fallback return.

When response.ok is false (except 401), the function returns fetchResult() without aborting the controller created at line 64. This leaves the abort controller in an inconsistent state.


77-77: Guard against response.body being null.

The non-null assertion response.body! can throw in edge cases where body is null even on successful responses.


106-114: Terminal event handlers don't abort the stream.

Both result_stored (line 108) and terminal failure paths (line 113) return without calling abortController.abort(). While the finally block releases the reader lock, the underlying fetch connection may remain open.


40-60: Race condition risk with concurrent executions.

If execute() is called again while a previous call is still in progress, the older async operation can still update shared state (phase, error, result) after being aborted, potentially overwriting newer run state.

Comment thread frontend/src/lib/editor/execution.svelte.ts
@sonarqubecloud

Copy link
Copy Markdown

@HardMax71
HardMax71 merged commit f2307de into main Jan 25, 2026
24 checks passed
@HardMax71
HardMax71 deleted the test/frontend-e2e branch January 25, 2026 17:34
@coderabbitai coderabbitai Bot mentioned this pull request Jan 30, 2026
This was referenced Feb 21, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Mar 5, 2026
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.

1 participant