Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ If the frontend needs Supabase locally, copy `.env.example` to `.env.local` in `

- `NEXT_PUBLIC_SUPABASE_URL` — the local API URL.
- `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY` — the local publishable (anon) key.
- `SUPABASE_SECRET_KEY` — the local secret key used only by Next.js route handlers.

The local assignment API is available from the Next.js development server at
`GET /api/probes`, `GET /api/test-revisions`, and
`PUT /api/probes/<probe-id>/assignment`. The PUT body is
`{"test_revision_id":"<revision UUID>"}` to assign a revision or
`{"test_revision_id":null}` to clear it. These routes return 404 outside
development until dashboard authentication and authorization are implemented.

## Playwright

Expand Down
1 change: 1 addition & 0 deletions server/frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54421
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=dummy-publishable-key
SUPABASE_SECRET_KEY=dummy-secret-key
76 changes: 76 additions & 0 deletions server/frontend/app/api/probes/[probeId]/assignment/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import {
AssignmentNotFoundError,
InvalidAssignmentInputError,
setProbeAssignment,
} from "@/server/assignments/service";

/**
* PUT /api/probes/:probeId/assignment
*
* Assigns a test revision to a probe, or clears its assignment when
* `test_revision_id` is `null`.
*
* @param request JSON body containing only `test_revision_id` as a UUID or
* `null`.
* @param context Route parameters containing the probe UUID.
* @returns The saved assignment, `400` for invalid input, `404` when unavailable
* or not found, or `500` on failure.
*/
export async function PUT(
request: Request,
context: { params: Promise<{ probeId: string }> },
) {
// TODO: Replace this temporary development-only guard with authentication
// and authorization once they are available.
if (process.env.NODE_ENV !== "development") {
return Response.json({ error: "Not found" }, { status: 404 });
}

const { probeId } = await context.params;
try {
const testRevisionId = await parseAssignmentRequest(request);
const assignment = await setProbeAssignment(probeId, testRevisionId);
return Response.json({
assignment: assignment
? { test_revision_id: assignment.testRevisionId }
: null,
});
} catch (error) {
if (error instanceof InvalidAssignmentInputError) {
return Response.json({ error: error.message }, { status: 400 });
}
if (error instanceof AssignmentNotFoundError) {
return Response.json({ error: error.message }, { status: 404 });
}

console.error("Unable to save probe assignment", error);
return Response.json(
{ error: "Unable to save assignment" },
{ status: 500 },
);
}
}

async function parseAssignmentRequest(request: Request) {
let body: unknown;
try {
body = await request.json();
} catch {
throw new InvalidAssignmentInputError("Expected a JSON body");
}

if (
!body ||
typeof body !== "object" ||
Object.keys(body).length !== 1 ||
!("test_revision_id" in body) ||
(body.test_revision_id !== null &&
typeof body.test_revision_id !== "string")
) {
throw new InvalidAssignmentInputError(
"Expected only test_revision_id, as a UUID or null",
);
}

return body.test_revision_id;
}
23 changes: 23 additions & 0 deletions server/frontend/app/api/probes/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { listProbes } from "@/server/assignments/service";

/**
* GET /api/probes
*
* Lists the probes available for test assignment.
*
* @returns A `probes` array, `404` outside development, or `500` on failure.
*/
export async function GET() {
// TODO: Replace this temporary development-only guard with authentication
// and authorization once they are available.
if (process.env.NODE_ENV !== "development") {
return Response.json({ error: "Not found" }, { status: 404 });
}

try {
return Response.json({ probes: await listProbes() });
} catch (error) {
console.error("Unable to list probes", error);
return Response.json({ error: "Unable to list probes" }, { status: 500 });
}
}
29 changes: 29 additions & 0 deletions server/frontend/app/api/test-revisions/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { listTestRevisions } from "@/server/assignments/service";

/**
* GET /api/test-revisions
*
* Lists the test revisions that can be assigned to probes.
*
* @returns A `test_revisions` array, `404` outside development, or `500` on
* failure.
*/
export async function GET() {
// TODO: Replace this temporary development-only guard with authentication
// and authorization once they are available.
if (process.env.NODE_ENV !== "development") {
return Response.json({ error: "Not found" }, { status: 404 });
}

try {
return Response.json({
test_revisions: await listTestRevisions(),
});
} catch (error) {
console.error("Unable to list test revisions", error);
return Response.json(
{ error: "Unable to list test revisions" },
{ status: 500 },
);
}
}
132 changes: 132 additions & 0 deletions server/frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"test:unit": "playwright test --config=playwright.unit.config.ts"
},
"dependencies": {
"@supabase/supabase-js": "2.119.2",
"next": "^16.0.0",
"react": "^19.2.0",
"react-dom": "^19.2.0"
Expand Down
Loading