Adds the server side of the admin and the automatic game discovery. The catalog stays JSON in this repo; the Worker writes it as a GitHub App (GraphQL createCommitOnBranch with expectedHeadOid: verified commits, retried on a race) and keeps only the review queue in D1. - worker/admin.ts: /api/admin/* (queue list, approve/reject, add, edit the three maintainer fields, remove with reason + R2 cover cleanup, restore) and the /admin shell with its own CSP. Every request re-verifies the Cloudflare Access JWT (aud + maintainer email + same-origin writes). Approving commits to scripts/temp_link.json, which starts update.yml. The maintainer's email goes to the D1 audit log only, never a commit. - worker/ingest.ts: POST /api/ingest for the browser extension (Access service token, per-client rate limit, Idempotency-Key replay, <= 150 items / 64 KB), replacing its PAT commits. - worker/suggest.ts: public POST /api/suggest (same-origin, per-IP rate limit, Turnstile siteverify, canonical itch.io URL) into the queue. - worker/discover.ts + scheduled(): every 4 h, one itch.io RSS feed (round-robin, 6 h back-off on 429) into the queue, then reconcile (queued -> ingested / failed) and retention (idempotency 7 d, form notes 180 d). - worker/queue.ts: URL classification (catalog, pending, deleted, blocklist) and the D1 store; worker/repo.ts builds each admin commit from the files at the head of main, byte-compatible with the Python pipeline (golden fixtures). - wrangler.jsonc: D1 (bound by name; migrations applied by hand), rate limits, cron, non-secret settings as vars (empty until setup: features answer 503 until configured), staging env without the cron. `npm run cf:types` ignores .dev.vars so the committed types are stable. - Tests: 159 passing; the SQL runs against a real local D1 (workerd via wrangler's platform proxy). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
16 lines
544 B
TypeScript
16 lines
544 B
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { canonicalize } from './canonical'
|
|
// Shared with the Python pipeline (tests/test_canonical.py).
|
|
import vectors from '../../tests/fixtures/url_vectors.json'
|
|
|
|
describe('canonicalize (shared vectors)', () => {
|
|
it.each(vectors.map((v) => [v.input, v.expected] as const))('%j → %j', (input, expected) => {
|
|
expect(canonicalize(input)).toBe(expected)
|
|
})
|
|
|
|
it('rejects non-strings', () => {
|
|
expect(canonicalize(undefined)).toBeNull()
|
|
expect(canonicalize(42)).toBeNull()
|
|
})
|
|
})
|