Plan — Centralize viewer URL construction and E2E_REPOS#
Summary#
Extract the duplicated viewerUrl() function and E2E_REPOS constant from three page components into a single lib/viewer.ts helper. Add a source-of-truth comment referencing agent-core's ArtefactsService.getArtefactsSubdir(), and add unit tests for the subdir selection logic.
Files#
| File | Action | Description |
|---|---|---|
lib/viewer.ts | create | Shared helper: E2E_REPOS, VIEWER_BASE, getArtefactsSubdir(), getViewerUrl() |
lib/viewer.test.ts | create | Unit tests for subdir selection (e2e repo, production repo, owner/repo format) |
app/pipeline/page.tsx | modify | Remove local E2E_REPOS, VIEWER_BASE, viewerUrl(); import from lib/viewer |
app/pipeline/[taskId]/page.tsx | modify | Remove local E2E_REPOS, VIEWER_BASE, viewerUrl(); import from lib/viewer |
app/agents/page.tsx | modify | Remove local E2E_REPOS, VIEWER_BASE, viewerUrl(); import from lib/viewer |
package.json | modify | Add vitest as dev dependency + test script |
Steps#
- Add vitest — Install vitest as a dev dependency, add
"test": "vitest run"script topackage.json. Configure vitest to resolve the@/*path alias matchingtsconfig.json. - Create
lib/viewer.ts— ExportE2E_REPOSarray,VIEWER_BASEconstant,getArtefactsSubdir(repo)helper returning'tasks/e2e'or'tasks/production', andgetViewerUrl(issue, repo)composing the full URL. Add a doc comment onE2E_REPOSreferencingagent-core/src/artefacts/artefacts.service.ts → E2E_SOURCE_REPOSas the canonical source of truth. - Create
lib/viewer.test.ts— TestgetArtefactsSubdir: returnstasks/e2efor'agent-core-e2e', returnstasks/productionfor'agent-core', handles'AgentSDE/agent-core-e2e'owner/repo format. TestgetViewerUrlproduces expected URL shape. - Refactor
app/pipeline/page.tsx— Delete lines 21-28 (localE2E_REPOS,VIEWER_BASE,viewerUrl). ImportgetViewerUrlfrom@/lib/viewer. Update call sites (lines 68, 216). - Refactor
app/pipeline/[taskId]/page.tsx— Delete lines 25-32 (local constants + function). ImportgetViewerUrlfrom@/lib/viewer. Update call site (line 164). - Refactor
app/agents/page.tsx— Delete lines 56-63 (local constants + function). ImportgetViewerUrlfrom@/lib/viewer. Update call site at line 145 to pass(task.issue, task.repo)instead of(task).
Verification#
npm run lintpasses with zero warningsnpm run buildcompiles successfullynpm testpasses — subdir selection tests for e2e and production repos
Risks#
- Test framework bootstrap — AGENTS.md notes no test runner exists. Adding vitest is required by acceptance criteria (unit tests). Vitest is the lightest option for a Next.js project and requires minimal config.
- E2E_REPOS drift — The list is still manually mirrored from agent-core. The source-of-truth comment + unit tests make drift detectable during review/CI but don't eliminate it.