Files
punimtag/e2e/tests/viewer.write-gates.spec.ts
T
ilia c0c997f796
CI / skip-ci-check (pull_request) Successful in 5s
CI / docker-ci (pull_request) Successful in 7s
CI / secret-scan (pull_request) Successful in 12s
CI / viewer-unit (pull_request) Successful in 1m29s
CI / e2e (pull_request) Successful in 4m8s
CI / admin-unit (pull_request) Successful in 4m24s
test: timing budgets + CI hardening (artifact v3 pin, npm cache retry)
Closes three items from the outstanding e2e/CI gap list:

- Timing budgets: timings.measure() only ever recorded durations for the
  (still-unwired) Pushgateway export — nothing failed CI when a step got
  slow. Add e2e/timing-budgets.ts (expectWithinBudget + shared BUDGET_MS
  buckets) and wire it into every measure() call site across the suite.
  Mail-wait steps are deliberately left unbudgeted (external mail-trap
  delivery latency, not a code performance signal).

- actions/upload-artifact@v4 doesn't work against this Gitea/act runner's
  artifact backend — pin to v3 for the e2e failure-report upload.

- Shared act_runner npm cache has corrupted platform-native tarballs before
  (@next/swc-linux-x64-musl) and reds viewer-unit/admin-unit/e2e with no
  product bug involved. All three npm ci steps now retry once after
  `npm cache clean --force` on first failure.

Verified: full local suite green against DEV (37 passed, 6 skipped, no
budget assertion failures) before wiring into CI.
2026-07-15 08:56:31 -04:00

64 lines
2.6 KiB
TypeScript

import path from 'node:path';
import { test, expect } from '../fixtures';
import { BUDGET_MS, expectWithinBudget } from '../timing-budgets';
/**
* NextAuth (browser-session) write gates — `session.user.hasWriteAccess`
* checks in viewer-frontend route handlers (see
* `app/api/faces/[id]/identify/route.ts`). Distinct from the FastAPI
* role-permission gates in `api.role-permissions.spec.ts` (separate user
* store, bearer auth instead of session cookies).
*
* Requires `E2E_VIEWER_EMAIL`/`PASSWORD` (auth-DB viewer, hasWriteAccess=false)
* and the admin storageState from `auth.setup.ts`.
*
* Uses a nonexistent face id so the *write-access* gate is what's being
* proven, not a real mutation: the route checks `hasWriteAccess` before
* loading the face, so viewer never reaches the 404 branch.
*/
const nonExistentFaceId = 999999999;
const viewerReady = Boolean(process.env.E2E_VIEWER_EMAIL && process.env.E2E_VIEWER_PASSWORD);
test.describe('viewer write gates (NextAuth, viewer) @smoke', () => {
test.use({ storageState: path.join(__dirname, '../.auth/viewer.json') });
test.skip(!viewerReady, 'E2E_VIEWER_EMAIL/PASSWORD required');
test('viewer without write access is denied on POST /api/faces/{id}/identify', async ({
page,
playkitConfig,
timings,
}) => {
const res = await timings.measure('viewer_identify', () =>
page.request.post(`${playkitConfig.baseUrl}/api/faces/${nonExistentFaceId}/identify`, {
data: { firstName: 'Test', lastName: 'Viewer' },
}),
);
expectWithinBudget(timings, 'viewer_identify', BUDGET_MS.api);
expect(res.status()).toBe(403);
const body = await res.json();
expect(body).toMatchObject({ error: expect.stringMatching(/write access/i) });
});
});
test.describe('viewer write gates (NextAuth, admin) @smoke', () => {
test.use({ storageState: path.join(__dirname, '../.auth/admin.json') });
test('admin (write access) passes the gate on POST /api/faces/{id}/identify', async ({
page,
playkitConfig,
timings,
}) => {
const res = await timings.measure('admin_identify', () =>
page.request.post(`${playkitConfig.baseUrl}/api/faces/${nonExistentFaceId}/identify`, {
data: { firstName: 'Test', lastName: 'Admin' },
}),
);
expectWithinBudget(timings, 'admin_identify', BUDGET_MS.api);
// Admin clears the write-access gate; a nonexistent face id then 404s —
// proves the gate didn't block a legitimate write-access user.
expect(res.status()).toBe(404);
const body = await res.json();
expect(body).toMatchObject({ error: expect.stringMatching(/face not found/i) });
});
});