@pplethai/cli 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/dist/bin.js +126 -124
  2. package/package.json +1 -1
  3. package/templates/golden-path/.dev.vars.example +4 -3
  4. package/templates/golden-path/CLAUDE.md +10 -5
  5. package/templates/golden-path/README.md +5 -4
  6. package/templates/golden-path/src/call-service.ts +17 -10
  7. package/templates/golden-path/src/dev-call-service.ts +21 -20
  8. package/templates/golden-path/src/dev-read-dataset.ts +23 -34
  9. package/templates/golden-path/src/dev-registry.ts +25 -7
  10. package/templates/golden-path/src/entry-name.ts +114 -0
  11. package/templates/golden-path/src/env.ts +2 -2
  12. package/templates/golden-path/src/read-dataset.ts +6 -4
  13. package/templates/golden-path/src/registry.ts +1 -1
  14. package/templates/golden-path/test/call-service.test.ts +118 -8
  15. package/templates/golden-path/test/dev-call-service.test.ts +201 -25
  16. package/templates/golden-path/test/dev-read-dataset.test.ts +52 -13
  17. package/templates/golden-path/test/dev-registry.test.ts +35 -6
  18. package/templates/golden-path/test/fixtures/overlay/catalog/entry.md +8 -0
  19. package/templates/golden-path/test/fixtures/overlay/election/2027/score/entry.md +11 -0
  20. package/templates/golden-path/test/fixtures/overlay/election/2027/score/mocks/responses.json +7 -0
  21. package/templates/golden-path/test/fixtures/overlay/election/results/entry.md +24 -0
  22. package/templates/golden-path/test/fixtures/overlay/election/results/mocks/turnout.json +1 -0
  23. package/templates/golden-path/test/fixtures/overlay/platform/sms/entry.md +10 -0
  24. package/templates/golden-path/test/fixtures/overlay/platform/sms/mocks/responses.json +7 -0
  25. package/templates/golden-path/test/fixtures/overlay/score/entry.md +10 -0
  26. package/templates/golden-path/test/fixtures/overlay/score/mocks/responses.json +7 -0
  27. package/templates/golden-path/test/harness.ts +1 -1
  28. package/templates/golden-path/test/read-dataset.test.ts +45 -12
  29. package/templates/golden-path/test/fixtures/overlay/shop/catalog/entry.md +0 -8
  30. /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/entry.md +0 -0
  31. /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/mocks/audience.json +0 -0
  32. /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/mocks/named.json +0 -0
  33. /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/mocks/offices.json +0 -0
  34. /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/mocks/roster.json +0 -0
  35. /package/templates/golden-path/test/fixtures/overlay/{directory/branches → branch-list}/mocks/summary.json +0 -0
  36. /package/templates/golden-path/test/fixtures/overlay/{shop/catalog → catalog}/mocks/responses.json +0 -0
  37. /package/templates/golden-path/test/fixtures/overlay/{shop/orders → orders}/entry.md +0 -0
  38. /package/templates/golden-path/test/fixtures/overlay/{shop/orders → orders}/mocks/responses.json +0 -0
@@ -3,7 +3,7 @@
3
3
  // keeps no App Key and no user token.
4
4
 
5
5
  import { describe, expect, it, vi } from "vitest";
6
- import { callService, platformError } from "../src/call-service";
6
+ import { callService, PLATFORM_ERROR_CODES, platformError } from "../src/call-service";
7
7
  import { makeHarness, serviceRefusal } from "./harness";
8
8
 
9
9
  const env = {
@@ -73,7 +73,7 @@ describe("callService", () => {
73
73
 
74
74
  await callService(
75
75
  h.testEnv,
76
- "shop/orders",
76
+ "orders",
77
77
  "items/1?limit=2",
78
78
  { method: "GET", headers: { "x-pple-user-token": "smuggled" } },
79
79
  { fetchImpl: h.fetchImpl },
@@ -81,7 +81,7 @@ describe("callService", () => {
81
81
 
82
82
  expect(userToken).toBeNull();
83
83
  expect(h.calls.services).toEqual([
84
- { path: "/shop/orders/items/1?limit=2", method: "GET", headers: {} },
84
+ { path: "/orders/items/1?limit=2", method: "GET", headers: {} },
85
85
  ]);
86
86
  });
87
87
 
@@ -108,14 +108,91 @@ describe("callService", () => {
108
108
  const fetchImpl = vi.fn<typeof fetch>(async () => new Response("from-injected"));
109
109
  const res = await callService(
110
110
  { ...env, DEV_PERSONA: "hq-staff", DEV_REGISTRY_ERROR: "not_granted" },
111
- "shop/orders",
111
+ "orders",
112
112
  "/items/1",
113
113
  { method: "GET" },
114
114
  { userToken: "t", fetchImpl },
115
115
  );
116
116
  expect(await res.text()).toBe("from-injected");
117
117
  expect(fetchImpl).toHaveBeenCalledOnce();
118
- expect(String(fetchImpl.mock.calls[0]?.[0])).toBe("https://services.test/shop/orders/items/1");
118
+ expect(String(fetchImpl.mock.calls[0]?.[0])).toBe("https://services.test/orders/items/1");
119
+ });
120
+
121
+ it("calls an app's entry by its bare name, with no provider in the URL", async () => {
122
+ const fetchImpl = vi.fn<typeof fetch>(async () => new Response("ok"));
123
+ await callService(env, "branch-list", "/offices", { method: "GET" }, { fetchImpl });
124
+ expect(String(fetchImpl.mock.calls[0]?.[0])).toBe("https://services.test/branch-list/offices");
125
+ });
126
+
127
+ it('builds services.<domain>/platform/sms/… for the platform\'s "platform/sms"', async () => {
128
+ const fetchImpl = vi.fn<typeof fetch>(async () => new Response("ok"));
129
+ await callService(env, "platform/sms", "", { method: "POST" }, { userToken: "tok", fetchImpl });
130
+ await callService(env, "platform/sms", "/send", { method: "POST" }, { fetchImpl });
131
+ await callService(env, "platform/legal-identity", "?dry=1", { method: "POST" }, { fetchImpl });
132
+ expect(fetchImpl.mock.calls.map((call) => String(call[0]))).toEqual([
133
+ "https://services.test/platform/sms",
134
+ "https://services.test/platform/sms/send",
135
+ "https://services.test/platform/legal-identity?dry=1",
136
+ ]);
137
+ const headers = new Headers(fetchImpl.mock.calls[0]?.[1]?.headers);
138
+ expect(headers.get("authorization")).toBe("Bearer app-key");
139
+ expect(headers.get("x-pple-user-token")).toBe("tok");
140
+ });
141
+
142
+ it("builds services.<domain>/<full name>/… for a Namespace name, up to four segments", async () => {
143
+ const fetchImpl = vi.fn<typeof fetch>(async () => new Response("ok"));
144
+ await callService(env, "election/2027/score", "/units/7?limit=2", { method: "GET" }, { fetchImpl });
145
+ await callService(env, "election/score", "", {}, { fetchImpl });
146
+ await callService(env, "election/2027/regional/score", "units", {}, { fetchImpl });
147
+ expect(fetchImpl.mock.calls.map((call) => String(call[0]))).toEqual([
148
+ "https://services.test/election/2027/score/units/7?limit=2",
149
+ "https://services.test/election/score",
150
+ "https://services.test/election/2027/regional/score/units",
151
+ ]);
152
+ });
153
+
154
+ it("sends the App Key for a full name, as for a bare one", async () => {
155
+ const fetchImpl = vi.fn<typeof fetch>(async () => new Response("ok"));
156
+ await callService(env, "election/score", "/", {}, { userToken: "tok", fetchImpl });
157
+ const init = fetchImpl.mock.calls[0]?.[1];
158
+ const headers = new Headers(init?.headers);
159
+ expect(headers.get("authorization")).toBe("Bearer app-key");
160
+ expect(headers.get("x-pple-user-token")).toBe("tok");
161
+ });
162
+
163
+ it.each([
164
+ ["health", /"health" is reserved/],
165
+ ["overlay/x", /"overlay" is reserved/],
166
+ ["platform", /"platform" belongs to the platform.*such as "platform\/sms"/],
167
+ ])('rejects the reserved name "%s"', async (id, message) => {
168
+ const fetchImpl = vi.fn<typeof fetch>();
169
+ await expect(callService(env, id, "", {}, { fetchImpl })).rejects.toThrow(message);
170
+ expect(fetchImpl).not.toHaveBeenCalled();
171
+ });
172
+
173
+ it.each([
174
+ "",
175
+ "Election/score",
176
+ "election//score",
177
+ "/election/score",
178
+ "election/score/",
179
+ "election/ score",
180
+ "election/a/b/c/d",
181
+ "-election/score",
182
+ "election_2027/score",
183
+ `${"a".repeat(64)}/score`,
184
+ `${"a".repeat(63)}/${"b".repeat(63)}/c`,
185
+ ])('rejects the name "%s" as not an entry name', async (id) => {
186
+ const fetchImpl = vi.fn<typeof fetch>();
187
+ await expect(callService(env, id, "", {}, { fetchImpl })).rejects.toThrow(/is not an entry name/);
188
+ expect(fetchImpl).not.toHaveBeenCalled();
189
+ });
190
+
191
+ it("accepts the longest names the validator allows", async () => {
192
+ const fetchImpl = vi.fn<typeof fetch>(async () => new Response("ok"));
193
+ const full = `${"a".repeat(63)}/${"b".repeat(63)}`; // 127 characters
194
+ await callService(env, full, "", {}, { fetchImpl });
195
+ expect(String(fetchImpl.mock.calls[0]?.[0])).toBe(`https://services.test/${full}`);
119
196
  });
120
197
 
121
198
  it("does not call out without the services URL or the App Key", async () => {
@@ -130,6 +207,38 @@ describe("callService", () => {
130
207
  });
131
208
  });
132
209
 
210
+ describe("a renamed entry", () => {
211
+ // pple-services answers an old full name with 410, `x-pple-error: renamed`
212
+ // and the new name in the body (ADR-0032, #346).
213
+ const renamedAnswer = () =>
214
+ Response.json(
215
+ {
216
+ error: "renamed",
217
+ renamed: "entry",
218
+ renamedTo: "vote/score",
219
+ message: "renamed to vote/score",
220
+ },
221
+ { status: 410, headers: { "x-pple-error": "renamed" } },
222
+ );
223
+
224
+ it("is a typed platform refusal on callService, and the body still names the new entry", async () => {
225
+ const h = makeHarness({ services: renamedAnswer }, env);
226
+
227
+ const res = await callService(h.testEnv, "election/score", "/results", { method: "GET" }, {
228
+ fetchImpl: h.fetchImpl,
229
+ });
230
+
231
+ expect(h.calls.services[0]?.path).toBe("/election/score/results");
232
+ expect(res.status).toBe(410);
233
+ expect(platformError(res)).toBe("renamed");
234
+ expect(await res.json()).toMatchObject({ renamedTo: "vote/score" });
235
+ });
236
+
237
+ it("is listed with the other codes", () => {
238
+ expect(PLATFORM_ERROR_CODES).toContain("renamed");
239
+ });
240
+ });
241
+
133
242
  describe("services fake", () => {
134
243
  it("answers as any Provider and refuses with any x-pple-error code", async () => {
135
244
  const codes = [
@@ -141,13 +250,14 @@ describe("services fake", () => {
141
250
  "identity_unavailable",
142
251
  "provider_unavailable",
143
252
  "provider_timeout",
253
+ "renamed",
144
254
  "no_mock",
145
255
  "made_up",
146
256
  ];
147
257
  let next = Response.json({ items: ["a"] });
148
258
  const h = makeHarness({ services: () => next }, env);
149
259
 
150
- const answered = await callService(h.testEnv, "shop/catalog", "/search", { method: "GET" }, {
260
+ const answered = await callService(h.testEnv, "catalog", "/search", { method: "GET" }, {
151
261
  fetchImpl: h.fetchImpl,
152
262
  });
153
263
  expect(answered.status).toBe(200);
@@ -156,7 +266,7 @@ describe("services fake", () => {
156
266
 
157
267
  for (const code of codes) {
158
268
  next = serviceRefusal(code, 418);
159
- const res = await callService(h.testEnv, "shop/catalog", "", { method: "POST" }, {
269
+ const res = await callService(h.testEnv, "catalog", "", { method: "POST" }, {
160
270
  userToken: "t",
161
271
  fetchImpl: h.fetchImpl,
162
272
  });
@@ -168,7 +278,7 @@ describe("services fake", () => {
168
278
  else expect(known).toBe(code);
169
279
  }
170
280
 
171
- expect(h.calls.services[0]).toEqual({ path: "/shop/catalog/search", method: "GET", headers: {} });
281
+ expect(h.calls.services[0]).toEqual({ path: "/catalog/search", method: "GET", headers: {} });
172
282
  expect(h.calls.services).toHaveLength(1 + codes.length);
173
283
  for (const call of h.calls.services) {
174
284
  expect(call.headers).not.toHaveProperty("authorization");
@@ -14,9 +14,10 @@ const overlay: Record<string, unknown> = import.meta.glob("./fixtures/overlay/**
14
14
 
15
15
  beforeAll(() => {
16
16
  const keys = Object.keys(overlay).join("\n");
17
- expect(keys).toContain("shop/orders/mocks/responses.json");
18
- expect(keys).toContain("shop/orders/entry.md");
17
+ expect(keys).toContain("orders/mocks/responses.json");
18
+ expect(keys).toContain("orders/entry.md");
19
19
  expect(keys).toContain("platform/legal-identity/mocks/responses.json");
20
+ expect(keys).toContain("election/2027/score/entry.md");
20
21
  });
21
22
 
22
23
  const cases = [
@@ -71,9 +72,9 @@ describe("matchMockCase", () => {
71
72
 
72
73
  describe("overlay fixture", () => {
73
74
  it("matches method, path and persona, and marks the mock", async () => {
74
- const res = await call({ entry: "shop/orders", path: "/items/7?limit=2", method: "GET", persona: "hq-staff", userToken: "t" });
75
+ const res = await call({ entry: "orders", path: "/items/7?limit=2", method: "GET", persona: "hq-staff", userToken: "t" });
75
76
  expect(res.status).toBe(200);
76
- expect(res.headers.get("x-pple-mock")).toBe("shop/orders");
77
+ expect(res.headers.get("x-pple-mock")).toBe("orders");
77
78
  expect(res.headers.get("x-pple-error")).toBeNull();
78
79
  expect(res.headers.get("x-shop")).toBe("hq");
79
80
  expect(platformError(res)).toBeNull();
@@ -81,39 +82,39 @@ describe("overlay fixture", () => {
81
82
  });
82
83
 
83
84
  it("uses the first match, then an unscoped case for a persona the Builder added", async () => {
84
- const listed = await call({ entry: "shop/orders", path: "/items/7", method: "GET", persona: "delegate", userToken: "t" });
85
+ const listed = await call({ entry: "orders", path: "/items/7", method: "GET", persona: "delegate", userToken: "t" });
85
86
  expect(await listed.json()).toEqual({ item: "listed" });
86
87
 
87
- const added = await call({ entry: "shop/orders", path: "/items/7", method: "GET", persona: "intern", userToken: "t" });
88
- expect(added.headers.get("x-pple-mock")).toBe("shop/orders");
88
+ const added = await call({ entry: "orders", path: "/items/7", method: "GET", persona: "intern", userToken: "t" });
89
+ expect(added.headers.get("x-pple-mock")).toBe("orders");
89
90
  expect(await added.json()).toEqual({ item: "open" });
90
91
  });
91
92
 
92
93
  it("treats / as the entry root and sends a string body as text", async () => {
93
- const root = await call({ entry: "shop/orders", path: "", method: "POST", persona: "hq-staff", userToken: "t" });
94
+ const root = await call({ entry: "orders", path: "", method: "POST", persona: "hq-staff", userToken: "t" });
94
95
  expect(root.status).toBe(201);
95
- expect(root.headers.get("x-pple-mock")).toBe("shop/orders");
96
+ expect(root.headers.get("x-pple-mock")).toBe("orders");
96
97
  expect(await root.json()).toEqual({ created: true });
97
98
 
98
- const longer = await call({ entry: "shop/orders", path: "/created", method: "POST", persona: "hq-staff", userToken: "t" });
99
+ const longer = await call({ entry: "orders", path: "/created", method: "POST", persona: "hq-staff", userToken: "t" });
99
100
  expect(longer.status).toBe(404);
100
101
  expect(longer.headers.get("x-pple-error")).toBe("no_mock");
101
102
 
102
- const files = await call({ entry: "shop/orders", path: "/files/a/b", method: "GET", persona: "intern", userToken: "t" });
103
+ const files = await call({ entry: "orders", path: "/files/a/b", method: "GET", persona: "intern", userToken: "t" });
103
104
  expect(files.headers.get("content-type")).toContain("text/plain");
104
105
  expect(await files.text()).toBe("listed");
105
106
  });
106
107
 
107
108
  it("answers a userToken none entry with no token", async () => {
108
- const res = await call({ entry: "shop/catalog", path: "/search", method: "GET", persona: "hq-staff" });
109
+ const res = await call({ entry: "catalog", path: "/search", method: "GET", persona: "hq-staff" });
109
110
  expect(res.status).toBe(200);
110
- expect(res.headers.get("x-pple-mock")).toBe("shop/catalog");
111
+ expect(res.headers.get("x-pple-mock")).toBe("catalog");
111
112
  expect(await res.json()).toEqual({ ok: true });
112
113
  });
113
114
 
114
115
  it("refuses a required entry that was called with no token", async () => {
115
116
  for (const userToken of [undefined, "", " "]) {
116
- const res = await call({ entry: "shop/orders", path: "/items/7", method: "GET", persona: "hq-staff", userToken });
117
+ const res = await call({ entry: "orders", path: "/items/7", method: "GET", persona: "hq-staff", userToken });
117
118
  expect(res.status).toBe(401);
118
119
  expect(res.headers.get("x-pple-error")).toBe("user_token_invalid");
119
120
  expect(res.headers.get("x-pple-mock")).toBeNull();
@@ -123,7 +124,7 @@ describe("overlay fixture", () => {
123
124
  });
124
125
 
125
126
  it("says when the entry is missing, and when the route is", async () => {
126
- const missing = await call({ entry: "shop/missing", path: "/items/1", method: "GET", persona: "hq-staff", userToken: "t" });
127
+ const missing = await call({ entry: "missing", path: "/items/1", method: "GET", persona: "hq-staff", userToken: "t" });
127
128
  expect(missing.status).toBe(404);
128
129
  expect(missing.headers.get("x-pple-error")).toBe("no_mock");
129
130
  expect(missing.headers.get("x-pple-mock")).toBeNull();
@@ -134,7 +135,7 @@ describe("overlay fixture", () => {
134
135
  expect(missingBody.message).toContain(".pple/registry/");
135
136
  expect(missingBody.message).toMatch(/[\u0E00-\u0E7F]/);
136
137
 
137
- const route = await call({ entry: "shop/orders", path: "/nope", method: "GET", persona: "hq-staff", userToken: "t" });
138
+ const route = await call({ entry: "orders", path: "/nope", method: "GET", persona: "hq-staff", userToken: "t" });
138
139
  const routeBody = await route.json<{ error: string; message: string }>();
139
140
  expect(route.status).toBe(404);
140
141
  expect(route.headers.get("x-pple-error")).toBe("no_mock");
@@ -176,6 +177,68 @@ describe("overlay fixture", () => {
176
177
  });
177
178
  });
178
179
 
180
+ describe("offline answers from nested overlay folders", () => {
181
+ it("answers election/2027/score from .pple/registry/election/2027/score/", async () => {
182
+ const res = await call({
183
+ entry: "election/2027/score",
184
+ path: "/units/7",
185
+ method: "GET",
186
+ persona: "hq-staff",
187
+ });
188
+ expect(res.status).toBe(200);
189
+ expect(res.headers.get("x-pple-mock")).toBe("election/2027/score");
190
+ expect(await res.json()).toEqual({ from: "election/2027/score" });
191
+ });
192
+
193
+ it("answers platform/legal-identity and platform/sms from .pple/registry/platform/<name>/", async () => {
194
+ const legal = await call({
195
+ entry: "platform/legal-identity",
196
+ path: "",
197
+ method: "POST",
198
+ persona: "hq-staff",
199
+ userToken: "t",
200
+ });
201
+ expect(legal.headers.get("x-pple-mock")).toBe("platform/legal-identity");
202
+ expect(await legal.json()).toEqual({ source: "membership" });
203
+
204
+ const sms = await call({ entry: "platform/sms", path: "/", method: "POST", persona: "hq-staff" });
205
+ expect(sms.headers.get("x-pple-mock")).toBe("platform/sms");
206
+ expect(await sms.json()).toEqual({ sent: 1, rejected: [], credits: 1 });
207
+
208
+ // The platform has no bare names: the folder's own name is no entry.
209
+ for (const entry of ["legal-identity", "sms"]) {
210
+ const bare = await call({ entry, path: "/", method: "POST", persona: "hq-staff", userToken: "t" });
211
+ expect(bare.status).toBe(404);
212
+ expect(bare.headers.get("x-pple-error")).toBe("no_mock");
213
+ }
214
+ });
215
+
216
+ it("keeps a bare entry apart from a nested one that ends the same way", async () => {
217
+ const res = await call({ entry: "score", path: "/units/7", persona: "hq-staff" });
218
+ expect(await res.json()).toEqual({ from: "score" });
219
+ });
220
+
221
+ it("does not answer a name that is only the tail of a nested path", async () => {
222
+ for (const entry of ["2027/score", "election/score"]) {
223
+ const res = await call({ entry, path: "/units/7", persona: "hq-staff" });
224
+ expect(res.status).toBe(404);
225
+ expect(res.headers.get("x-pple-error")).toBe("no_mock");
226
+ expect(((await res.json()) as { message: string }).message).toContain(`ไม่มี ${entry} ใน .pple/registry/`);
227
+ }
228
+ });
229
+
230
+ it("reads the real overlay path, which has no fixture root", () => {
231
+ const res = answerFromOverlay(
232
+ {
233
+ "../.pple/registry/election/2027/score/entry.md": "---\nkind: service\nuserToken: none\n---\n",
234
+ "../.pple/registry/election/2027/score/mocks/responses.json": '[{ "body": "real" }]',
235
+ },
236
+ { entry: "election/2027/score", path: "/", persona: "hq-staff" },
237
+ );
238
+ return expect(res.text()).resolves.toBe("real");
239
+ });
240
+ });
241
+
179
242
  describe("DEV_REGISTRY_ERROR", () => {
180
243
  const statuses: [string, number][] = [
181
244
  ["invalid_app_key", 401],
@@ -190,11 +253,12 @@ describe("DEV_REGISTRY_ERROR", () => {
190
253
  ["not_found", 404],
191
254
  ["invalid_query", 400],
192
255
  ["level_not_met", 403],
256
+ ["renamed", 410],
193
257
  ];
194
258
 
195
259
  it.each(statuses)("global %s is %i", async (code, status) => {
196
260
  const res = await call({
197
- entry: "shop/orders",
261
+ entry: "orders",
198
262
  path: "/items/1",
199
263
  method: "GET",
200
264
  persona: "hq-staff",
@@ -209,9 +273,9 @@ describe("DEV_REGISTRY_ERROR", () => {
209
273
  });
210
274
 
211
275
  it("lets a per-entry code win over a global one, in either order", async () => {
212
- for (const spec of ["not_granted, shop/orders=provider_timeout", "shop/orders = provider_timeout, not_granted"]) {
276
+ for (const spec of ["not_granted, orders=provider_timeout", "orders = provider_timeout, not_granted"]) {
213
277
  const orders = await call({
214
- entry: "shop/orders",
278
+ entry: "orders",
215
279
  path: "/items/1",
216
280
  method: "GET",
217
281
  persona: "hq-staff",
@@ -222,7 +286,7 @@ describe("DEV_REGISTRY_ERROR", () => {
222
286
  expect(orders.headers.get("x-pple-error")).toBe("provider_timeout");
223
287
 
224
288
  const catalog = await call({
225
- entry: "shop/catalog",
289
+ entry: "catalog",
226
290
  path: "/search",
227
291
  method: "GET",
228
292
  persona: "hq-staff",
@@ -233,11 +297,123 @@ describe("DEV_REGISTRY_ERROR", () => {
233
297
  }
234
298
  });
235
299
 
300
+ it("takes renamed for one full name, as election/score=renamed", async () => {
301
+ const spec = "election/score=renamed";
302
+ const hit = await call({
303
+ entry: "election/score",
304
+ path: "/results",
305
+ method: "GET",
306
+ persona: "hq-staff",
307
+ userToken: "t",
308
+ devRegistryError: spec,
309
+ });
310
+ expect(hit.status).toBe(410);
311
+ expect(platformError(hit)).toBe("renamed");
312
+
313
+ const other = await call({
314
+ entry: "election/turnout",
315
+ path: "/results",
316
+ method: "GET",
317
+ persona: "hq-staff",
318
+ userToken: "t",
319
+ devRegistryError: spec,
320
+ });
321
+ expect(platformError(other)).toBeNull();
322
+ });
323
+
324
+ it("takes a full name: election/2027/score=503 fails only that entry", async () => {
325
+ const spec = "election/2027/score=provider_unavailable";
326
+ const nested = await call({
327
+ entry: "election/2027/score",
328
+ path: "/units/1",
329
+ method: "GET",
330
+ persona: "hq-staff",
331
+ devRegistryError: spec,
332
+ });
333
+ expect(nested.status).toBe(502);
334
+ expect(nested.headers.get("x-pple-error")).toBe("provider_unavailable");
335
+
336
+ // The same last segment, bare, is a different entry.
337
+ const bare = await call({
338
+ entry: "score",
339
+ path: "/units/1",
340
+ method: "GET",
341
+ persona: "hq-staff",
342
+ devRegistryError: spec,
343
+ });
344
+ expect(bare.status).toBe(200);
345
+ const orders = await call({
346
+ entry: "orders",
347
+ path: "/items/1",
348
+ method: "GET",
349
+ persona: "hq-staff",
350
+ userToken: "t",
351
+ devRegistryError: spec,
352
+ });
353
+ expect(orders.status).toBe(200);
354
+ });
355
+
356
+ it("answers 503 for election/2027/score=503-style specs written with the platform code", async () => {
357
+ const res = await call({
358
+ entry: "election/2027/score",
359
+ path: "/units/1",
360
+ persona: "hq-staff",
361
+ devRegistryError: "election/2027/score=identity_unavailable, orders=not_granted",
362
+ });
363
+ expect(res.status).toBe(503);
364
+ });
365
+
366
+ it("applies a platform/<name> rule to that platform entry only", async () => {
367
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
368
+ try {
369
+ const forced = await call({
370
+ entry: "platform/sms",
371
+ path: "/",
372
+ method: "POST",
373
+ persona: "hq-staff",
374
+ devRegistryError: "platform/sms=provider_timeout",
375
+ });
376
+ expect(forced.status).toBe(504);
377
+ expect(forced.headers.get("x-pple-error")).toBe("provider_timeout");
378
+
379
+ const other = await call({
380
+ entry: "orders",
381
+ path: "/items/1",
382
+ method: "GET",
383
+ persona: "hq-staff",
384
+ userToken: "t",
385
+ devRegistryError: "platform/sms=provider_timeout",
386
+ });
387
+ expect(other.status).toBe(200);
388
+ expect(warn).not.toHaveBeenCalled();
389
+ } finally {
390
+ warn.mockRestore();
391
+ }
392
+ });
393
+
394
+ it("ignores a rule whose name is not an entry name", async () => {
395
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
396
+ try {
397
+ const res = await call({
398
+ entry: "orders",
399
+ path: "/items/1",
400
+ method: "GET",
401
+ persona: "hq-staff",
402
+ userToken: "t",
403
+ devRegistryError: "Orders/x=not_granted",
404
+ });
405
+ expect(res.status).toBe(200);
406
+ expect(warn).toHaveBeenCalled();
407
+ } finally {
408
+ warn.mockRestore();
409
+ }
410
+ });
411
+
236
412
  it("ignores an unknown code and still applies a global one", async () => {
237
413
  const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
238
414
  try {
239
415
  const mocked = await call({
240
- entry: "shop/catalog",
416
+ entry: "catalog",
241
417
  path: "/search",
242
418
  method: "GET",
243
419
  persona: "hq-staff",
@@ -247,11 +423,11 @@ describe("DEV_REGISTRY_ERROR", () => {
247
423
  expect(await mocked.json()).toEqual({ ok: true });
248
424
 
249
425
  const forced = await call({
250
- entry: "shop/orders",
426
+ entry: "orders",
251
427
  path: "/items/1",
252
428
  method: "GET",
253
429
  persona: "hq-staff",
254
- devRegistryError: "shop/orders=not_a_code, needs_beta",
430
+ devRegistryError: "orders=not_a_code, needs_beta",
255
431
  });
256
432
  expect(forced.status).toBe(403);
257
433
  expect(forced.headers.get("x-pple-error")).toBe("needs_beta");
@@ -263,7 +439,7 @@ describe("DEV_REGISTRY_ERROR", () => {
263
439
 
264
440
  it("applies before the missing-token refusal", async () => {
265
441
  const res = await call({
266
- entry: "shop/orders",
442
+ entry: "orders",
267
443
  path: "/items/1",
268
444
  method: "GET",
269
445
  persona: "hq-staff",
@@ -275,5 +451,5 @@ describe("DEV_REGISTRY_ERROR", () => {
275
451
  });
276
452
 
277
453
  function call(input: OverlayCall): Promise<Response> {
278
- return Promise.resolve(answerFromOverlay(overlay, input));
454
+ return Promise.resolve(answerFromOverlay(overlay, { overlayRoot: "fixtures/overlay/", ...input }));
279
455
  }