Skip to content

Canvix — Free & open-source graphic design tool. A community-built Canva alternative with a drag-and-drop editor, templates, shapes, text, images & one-click export. Works on desktop, tablet & mobile.

fix(e2e): the provenance spec asserted the REST-rail 404 convention — the designs family answers differently

Ashiq Hussain Mireccdb4368850
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0934b83..4e774ed 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,8 +15,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
generation was verified against, stored on the applied design; the
design GET returns it as `aiProvenance` and the editor hydrates it.
- `PUT|GET /api/designs/[id]/ai-provenance` — edit-gated persistence
- (same-origin, its own rate budget, flat 404 on foreign designs), plus
- a live-DB e2e spec (`tests/e2e/unified-ai-provenance.spec.ts`).
+ (same-origin, its own rate budget, NOT_YOUR_DESIGN on foreign
+ designs, flat 404 on missing ids), plus a live-DB e2e spec
+ (`tests/e2e/unified-ai-provenance.spec.ts`).
- `mergeBriefs` / `normalizeStoredBrief` (`src/lib/agent/brief.ts`): the
stored contract merges with every chat-agent run on that design —
union semantics, hostile input capped, dimensions dropped (the design
diff --git a/docs/UNIFIED-AI-MILESTONE.md b/docs/UNIFIED-AI-MILESTONE.md
index 912acb3..98f07ff 100644
--- a/docs/UNIFIED-AI-MILESTONE.md
+++ b/docs/UNIFIED-AI-MILESTONE.md
@@ -100,8 +100,10 @@ the enforcement needed no new client-side gate code).
- Live-DB e2e: `tests/e2e/unified-ai-provenance.spec.ts` — the
provenance PUT/GET round trip through the real API against real
Postgres, normalization asserted, junk/dimension-only briefs 422,
- foreign designs a flat 404 (no existence oracle), the design GET
- carrying `aiProvenance` back (the hydration path).
+ foreign designs follow the designs family (GET link-view 200 with
+ null provenance — that viewer can already GET the design itself;
+ PUT answers NOT_YOUR_DESIGN 403), missing ids a flat 404, and the
+ design GET carrying `aiProvenance` back (the hydration path).
## Decisions and disclosed limits
diff --git a/tests/e2e/unified-ai-provenance.spec.ts b/tests/e2e/unified-ai-provenance.spec.ts
index 2150239..091ef86 100644
--- a/tests/e2e/unified-ai-provenance.spec.ts
+++ b/tests/e2e/unified-ai-provenance.spec.ts
@@ -16,8 +16,10 @@ import { Client } from 'pg'
// as aiProvenance — this is what hydrates the editor store
// 3. GET /api/designs/[id]/ai-provenance returns it too
// 4. a brief with nothing usable is a 422 (honest rejection)
-// 5. a foreign design is a flat 404 on both GET and PUT — no
-// existence oracle
+// 5. foreign designs follow the designs family: GET is link-view
+// (200, null provenance — that viewer can already GET the design
+// itself), PUT answers NOT_YOUR_DESIGN (403); a missing id is a
+// flat 404 on both verbs (no existence oracle)
// 6. dimension-only briefs are rejected too (the design owns the
// geometry after apply — a stored size would fail every
// refinement on a legitimately resized design)
@@ -146,18 +148,36 @@ test.describe('design AI provenance (Unified Canvix AI)', () => {
await ctx.close()
})
- test('a foreign design is a flat 404 on both GET and PUT — no existence oracle', async ({ browser }) => {
+ test('foreign designs follow the designs family — viewable, never writable; a missing id is a flat 404', async ({ browser }) => {
const ctx = await signedInContext(browser)
const api = ctx.request
+ // GET: link-view semantics, same as GET /api/designs/[id] itself —
+ // that viewer can already read the whole design, so the (less
+ // sensitive) provenance rides the same rule: null when none stored
const got = await api.fetch(`${BASE}/api/designs/d_e2e_prov_other/ai-provenance`)
- expect(got.status()).toBe(404)
+ expect(got.status()).toBe(200)
+ expect(((await got.json()) as { provenance?: unknown }).provenance).toBeNull()
+
+ // PUT: the family's NOT_YOUR_DESIGN — a foreign design is never
+ // writable, and the response says exactly that
const put = await api.fetch(`${BASE}/api/designs/d_e2e_prov_other/ai-provenance`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json', origin: BASE },
data: { brief: { requiredTexts: [{ text: 'nope' }] } },
})
- expect(put.status()).toBe(404)
+ expect(put.status()).toBe(403)
+
+ // a design that does not exist is a flat 404 on both verbs — no
+ // existence oracle
+ const gotMissing = await api.fetch(`${BASE}/api/designs/d_e2e_prov_does_not_exist/ai-provenance`)
+ expect(gotMissing.status()).toBe(404)
+ const putMissing = await api.fetch(`${BASE}/api/designs/d_e2e_prov_does_not_exist/ai-provenance`, {
+ method: 'PUT',
+ headers: { 'Content-Type': 'application/json', origin: BASE },
+ data: { brief: { requiredTexts: [{ text: 'nope' }] } },
+ })
+ expect(putMissing.status()).toBe(404)
await ctx.close()
})