Skip to content

Fix usage records visibility and test case run links#42

Merged
joyzoursky merged 6 commits intomainfrom
fix-usage
Mar 10, 2026
Merged

Fix usage records visibility and test case run links#42
joyzoursky merged 6 commits intomainfrom
fix-usage

Conversation

@joyzoursky
Copy link
Copy Markdown
Collaborator

Summary

  • Fix team usage records not appearing in Team Settings > API Key & Usage by wiring usage recording and query paths consistently.
  • Make usage persistence idempotent per test run to prevent duplicate usage rows.
  • Improve navigation from usage/history views so test-case links route to the intended run pages.
  • Enforce Test Case ID as required on create/update flows (UI and API) to prevent incomplete records.

Changes

  • Usage recording and retrieval

  • src/lib/runtime/usage.ts: stabilized usage write behavior and test-run linkage.

  • src/lib/runtime/local-browser-runner.ts, src/lib/runners/event-service.ts: ensured usage events are persisted correctly.

  • src/app/api/teams/[id]/usage/route.ts: fixed usage list mapping/linking for table rendering.

  • prisma/schema.prisma: added @unique on UsageRecord.testRunId for idempotency.

  • UI navigation fixes

  • src/components/features/team-usage/ui/TeamUsage.tsx: made the ID column link to test run history.

  • src/app/test-cases/[id]/history/[runId]/page.tsx: breadcrumb test-case link now points to Run Test page (/run?testCaseId=...) instead of history list.

  • Required Test Case ID enforcement

  • src/components/features/test-form/ui/TestForm.tsx: Test Case ID required in form behavior (run + save draft guardrails).

  • src/app/run/page.tsx: save/create paths now validate non-empty trimmed displayId.

  • src/app/api/projects/[id]/test-cases/route.ts and src/app/api/test-cases/[id]/route.ts: reject missing/blank Test Case ID with 400.

  • src/i18n/messages.ts: added localized run.error.testCaseIdRequired.

  • Regression tests

  • src/app/api/teams/[id]/usage/route.test.ts

  • src/lib/runners/__tests__/event-service.test.ts

  • src/lib/runtime/__tests__/local-browser-runner.usage.test.ts

Validation

  • npm run verify passed (lint + typecheck + audit).
  • Manual spot checks performed during fixes:
  • Usage table ID links to /test-cases/{testCaseId}/history/{runId}.
  • Run-detail breadcrumb now links to /run?testCaseId={id} (with project context when available).

Breaking Changes

  • POST /api/projects/:id/test-cases now requires non-empty displayId (Test Case ID).
  • PUT /api/test-cases/:id now requires non-empty displayId (Test Case ID).
  • UsageRecord.testRunId is now unique at schema level.

Risks

  • If existing environments contain duplicate UsageRecord.testRunId values, schema deployment may fail until duplicates are resolved.
  • Clients that previously omitted displayId on test-case create/update will now receive 400.

Follow-ups

  • Confirm production/staging data has no duplicate UsageRecord.testRunId before applying schema changes.
  • Validate team usage table behavior in staging with historical and newly created runs.

@joyzoursky joyzoursky changed the title Fix usage records visibility and harden test case run links/ID validation Fix usage records visibility and test case run links Mar 10, 2026
@joyzoursky joyzoursky merged commit 28d5792 into main Mar 10, 2026
1 check passed
@joyzoursky joyzoursky deleted the fix-usage branch March 10, 2026 09:07
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