@pplethai/cli 0.21.0 → 0.23.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 (117) hide show
  1. package/README.md +12 -14
  2. package/dist/bin.js +102 -102
  3. package/package.json +3 -6
  4. package/templates/golden-path/.dev.vars.example +0 -33
  5. package/templates/golden-path/.env.example +0 -10
  6. package/templates/golden-path/.github/workflows/ci.yml +0 -22
  7. package/templates/golden-path/AGENTS.md +0 -1
  8. package/templates/golden-path/CLAUDE.md +0 -187
  9. package/templates/golden-path/README.md +0 -118
  10. package/templates/golden-path/gitignore +0 -17
  11. package/templates/golden-path/index.html +0 -16
  12. package/templates/golden-path/migrations/0001_init.sql +0 -10
  13. package/templates/golden-path/overlay-mtime.mjs +0 -30
  14. package/templates/golden-path/package-lock.json +0 -4318
  15. package/templates/golden-path/package.json +0 -41
  16. package/templates/golden-path/scripts/assert-dev-compiled-out.mjs +0 -45
  17. package/templates/golden-path/shared/api.ts +0 -325
  18. package/templates/golden-path/src/auth.ts +0 -230
  19. package/templates/golden-path/src/call-service.ts +0 -147
  20. package/templates/golden-path/src/dataset-query.ts +0 -470
  21. package/templates/golden-path/src/dataset-schema.ts +0 -398
  22. package/templates/golden-path/src/db.ts +0 -32
  23. package/templates/golden-path/src/dev-call-service.ts +0 -392
  24. package/templates/golden-path/src/dev-personas.ts +0 -186
  25. package/templates/golden-path/src/dev-read-dataset.ts +0 -444
  26. package/templates/golden-path/src/dev-registry.ts +0 -294
  27. package/templates/golden-path/src/email.ts +0 -224
  28. package/templates/golden-path/src/entry-name.ts +0 -114
  29. package/templates/golden-path/src/env.ts +0 -38
  30. package/templates/golden-path/src/files.ts +0 -38
  31. package/templates/golden-path/src/identity-header.ts +0 -17
  32. package/templates/golden-path/src/index.ts +0 -276
  33. package/templates/golden-path/src/legal-identity.ts +0 -180
  34. package/templates/golden-path/src/levels.ts +0 -132
  35. package/templates/golden-path/src/notification-response.ts +0 -55
  36. package/templates/golden-path/src/notify.ts +0 -311
  37. package/templates/golden-path/src/payment.ts +0 -554
  38. package/templates/golden-path/src/read-dataset.ts +0 -490
  39. package/templates/golden-path/src/registry.ts +0 -128
  40. package/templates/golden-path/src/vite-env.d.ts +0 -27
  41. package/templates/golden-path/test/apply-migrations.ts +0 -4
  42. package/templates/golden-path/test/call-service.test.ts +0 -288
  43. package/templates/golden-path/test/dev-call-service.test.ts +0 -455
  44. package/templates/golden-path/test/dev-read-dataset.test.ts +0 -379
  45. package/templates/golden-path/test/dev-registry.test.ts +0 -404
  46. package/templates/golden-path/test/effective-sub.test.ts +0 -101
  47. package/templates/golden-path/test/email-offline.test.ts +0 -51
  48. package/templates/golden-path/test/email.test.ts +0 -117
  49. package/templates/golden-path/test/env.d.ts +0 -17
  50. package/templates/golden-path/test/fixtures/overlay/branch-list/entry.md +0 -85
  51. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/audience.json +0 -3
  52. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/named.json +0 -3
  53. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/offices.json +0 -6
  54. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/roster.json +0 -3
  55. package/templates/golden-path/test/fixtures/overlay/branch-list/mocks/summary.json +0 -1
  56. package/templates/golden-path/test/fixtures/overlay/catalog/entry.md +0 -8
  57. package/templates/golden-path/test/fixtures/overlay/catalog/mocks/responses.json +0 -7
  58. package/templates/golden-path/test/fixtures/overlay/election/2027/score/entry.md +0 -11
  59. package/templates/golden-path/test/fixtures/overlay/election/2027/score/mocks/responses.json +0 -7
  60. package/templates/golden-path/test/fixtures/overlay/election/results/entry.md +0 -24
  61. package/templates/golden-path/test/fixtures/overlay/election/results/mocks/turnout.json +0 -1
  62. package/templates/golden-path/test/fixtures/overlay/orders/entry.md +0 -12
  63. package/templates/golden-path/test/fixtures/overlay/orders/mocks/responses.json +0 -36
  64. package/templates/golden-path/test/fixtures/overlay/platform/email/entry.md +0 -12
  65. package/templates/golden-path/test/fixtures/overlay/platform/email/mocks/responses.json +0 -11
  66. package/templates/golden-path/test/fixtures/overlay/platform/legal-identity/entry.md +0 -8
  67. package/templates/golden-path/test/fixtures/overlay/platform/legal-identity/mocks/responses.json +0 -13
  68. package/templates/golden-path/test/fixtures/overlay/platform/payments/entry.md +0 -12
  69. package/templates/golden-path/test/fixtures/overlay/platform/payments/mocks/responses.json +0 -71
  70. package/templates/golden-path/test/fixtures/overlay/platform/sms/entry.md +0 -10
  71. package/templates/golden-path/test/fixtures/overlay/platform/sms/mocks/responses.json +0 -7
  72. package/templates/golden-path/test/fixtures/overlay/score/entry.md +0 -10
  73. package/templates/golden-path/test/fixtures/overlay/score/mocks/responses.json +0 -7
  74. package/templates/golden-path/test/harness.ts +0 -153
  75. package/templates/golden-path/test/interaction.test.ts +0 -230
  76. package/templates/golden-path/test/legal-identity.test.ts +0 -323
  77. package/templates/golden-path/test/membership.test.ts +0 -105
  78. package/templates/golden-path/test/notification-response.test.ts +0 -79
  79. package/templates/golden-path/test/payment-app.test.ts +0 -210
  80. package/templates/golden-path/test/payment-offline.test.ts +0 -91
  81. package/templates/golden-path/test/payment.test.ts +0 -427
  82. package/templates/golden-path/test/payments-offline.ts +0 -33
  83. package/templates/golden-path/test/read-dataset.test.ts +0 -387
  84. package/templates/golden-path/test/service-call.test.ts +0 -166
  85. package/templates/golden-path/test/smoke.test.ts +0 -464
  86. package/templates/golden-path/tsconfig.json +0 -20
  87. package/templates/golden-path/tsconfig.worker.json +0 -21
  88. package/templates/golden-path/vite.config.ts +0 -12
  89. package/templates/golden-path/vitest.config.ts +0 -28
  90. package/templates/golden-path/web/App.tsx +0 -478
  91. package/templates/golden-path/web/app.css +0 -83
  92. package/templates/golden-path/web/main.tsx +0 -51
  93. package/templates/golden-path/web/pple.ts +0 -124
  94. package/templates/golden-path/web/vite-env.d.ts +0 -10
  95. package/templates/golden-path/wrangler.jsonc +0 -89
  96. package/templates/payment-bridge/.github/workflows/ci.yml +0 -21
  97. package/templates/payment-bridge/CLAUDE.md +0 -9
  98. package/templates/payment-bridge/README.md +0 -57
  99. package/templates/payment-bridge/docs/verify-webhook.md +0 -80
  100. package/templates/payment-bridge/docs/verify-webhook.ts +0 -29
  101. package/templates/payment-bridge/gitignore +0 -5
  102. package/templates/payment-bridge/package-lock.json +0 -4198
  103. package/templates/payment-bridge/package.json +0 -21
  104. package/templates/payment-bridge/src/bridge-key.ts +0 -18
  105. package/templates/payment-bridge/src/env.ts +0 -14
  106. package/templates/payment-bridge/src/index.ts +0 -39
  107. package/templates/payment-bridge/src/platform.ts +0 -49
  108. package/templates/payment-bridge/src/webhook.ts +0 -86
  109. package/templates/payment-bridge/test/docs.test.ts +0 -9
  110. package/templates/payment-bridge/test/fixtures/payments-responses.json +0 -71
  111. package/templates/payment-bridge/test/harness.ts +0 -78
  112. package/templates/payment-bridge/test/inbound.test.ts +0 -138
  113. package/templates/payment-bridge/test/webhook.test.ts +0 -174
  114. package/templates/payment-bridge/tsconfig.json +0 -22
  115. package/templates/payment-bridge/vitest.config.ts +0 -8
  116. package/templates/payment-bridge/wrangler.jsonc +0 -15
  117. package/templates/payment-bridge.version +0 -1
@@ -1,455 +0,0 @@
1
- // Offline callService (issue #261, ADR-0026). Vitest never lets callService
2
- // read `.pple/`. These tests feed the same matcher a fixture glob and read
3
- // the status, headers, and body a Builder would see.
4
-
5
- import { beforeAll, describe, expect, it, vi } from "vitest";
6
- import { platformError } from "../src/call-service";
7
- import { answerFromOverlay, matchMockCase, type OverlayCall } from "../src/dev-call-service";
8
-
9
- const overlay: Record<string, unknown> = import.meta.glob("./fixtures/overlay/**/*", {
10
- eager: true,
11
- query: "?raw",
12
- import: "default",
13
- });
14
-
15
- beforeAll(() => {
16
- const keys = Object.keys(overlay).join("\n");
17
- expect(keys).toContain("orders/mocks/responses.json");
18
- expect(keys).toContain("orders/entry.md");
19
- expect(keys).toContain("platform/legal-identity/mocks/responses.json");
20
- expect(keys).toContain("election/2027/score/entry.md");
21
- });
22
-
23
- const cases = [
24
- null,
25
- { method: "GET", path: "/items/:id", persona: "hq-staff", body: "hq" },
26
- { method: "GET", path: "/items/:id", persona: ["delegate", "platform-admin"], body: "listed" },
27
- { method: "GET", path: "items/:id", body: "open" },
28
- { method: "POST", path: "/", body: "root" },
29
- { path: "/files/*", body: "files" },
30
- { method: "GET", path: "/empty", persona: [], body: "no" },
31
- { method: "PUT", path: "/a/*/b", body: "bad" },
32
- { method: "DELETE", body: "any" },
33
- ];
34
-
35
- describe("matchMockCase", () => {
36
- it.each([
37
- ["first matching persona wins", "GET", "/items/1", "hq-staff", "hq"],
38
- ["a persona list matches", "GET", "/items/1", "delegate", "listed"],
39
- ["a persona the Builder added gets only an unscoped case", "GET", "/items/1", "intern", "open"],
40
- ["the query is not part of the match", "GET", "/items/1?limit=2", "hq-staff", "hq"],
41
- ["a pattern without a leading slash matches a slash tail", "GET", "/items/9", "unverified", "open"],
42
- ["a request without a leading slash matches a slash pattern", "get", "items/9", "hq-staff", "hq"],
43
- ["a param does not swallow a second segment", "GET", "/items/1/extra", "hq-staff", null],
44
- ["/ is the empty tail", "POST", "", "hq-staff", "root"],
45
- ["a slash tail is the same root", "POST", "/", "intern", "root"],
46
- ["a query on the root stays the root", "POST", "?dry=1", "hq-staff", "root"],
47
- ["the root does not match a longer tail", "POST", "/items", "hq-staff", null],
48
- ["a trailing star matches the rest of the tail", "POST", "/files/a/b", "intern", "files"],
49
- ["a trailing star does not match an empty rest", "GET", "/files", "hq-staff", null],
50
- ["an omitted path matches whatever is left", "DELETE", "/nope", "intern", "any"],
51
- ["an omitted path matches the root too", "DELETE", "", "hq-staff", "any"],
52
- ["an empty persona list matches nobody", "GET", "/empty", "hq-staff", null],
53
- ["a star that is not the last segment matches nothing", "PUT", "/a/x/b", "hq-staff", null],
54
- ] as const)("%s", (_name, method, path, persona, body) => {
55
- const matched = matchMockCase(cases, method, path, persona);
56
- expect(matched?.body ?? null).toBe(body);
57
- });
58
-
59
- it("returns the earlier case when two would match", () => {
60
- const matched = matchMockCase(
61
- [
62
- { method: "GET", path: "/dup", body: "first" },
63
- { method: "GET", path: "/dup", body: "second" },
64
- ],
65
- "GET",
66
- "/dup",
67
- "hq-staff",
68
- );
69
- expect(matched?.body).toBe("first");
70
- });
71
- });
72
-
73
- describe("overlay fixture", () => {
74
- it("matches method, path and persona, and marks the mock", async () => {
75
- const res = await call({ entry: "orders", path: "/items/7?limit=2", method: "GET", persona: "hq-staff", userToken: "t" });
76
- expect(res.status).toBe(200);
77
- expect(res.headers.get("x-pple-mock")).toBe("orders");
78
- expect(res.headers.get("x-pple-error")).toBeNull();
79
- expect(res.headers.get("x-shop")).toBe("hq");
80
- expect(platformError(res)).toBeNull();
81
- expect(await res.json()).toEqual({ item: "hq" });
82
- });
83
-
84
- it("uses the first match, then an unscoped case for a persona the Builder added", async () => {
85
- const listed = await call({ entry: "orders", path: "/items/7", method: "GET", persona: "delegate", userToken: "t" });
86
- expect(await listed.json()).toEqual({ item: "listed" });
87
-
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");
90
- expect(await added.json()).toEqual({ item: "open" });
91
- });
92
-
93
- it("treats / as the entry root and sends a string body as text", async () => {
94
- const root = await call({ entry: "orders", path: "", method: "POST", persona: "hq-staff", userToken: "t" });
95
- expect(root.status).toBe(201);
96
- expect(root.headers.get("x-pple-mock")).toBe("orders");
97
- expect(await root.json()).toEqual({ created: true });
98
-
99
- const longer = await call({ entry: "orders", path: "/created", method: "POST", persona: "hq-staff", userToken: "t" });
100
- expect(longer.status).toBe(404);
101
- expect(longer.headers.get("x-pple-error")).toBe("no_mock");
102
-
103
- const files = await call({ entry: "orders", path: "/files/a/b", method: "GET", persona: "intern", userToken: "t" });
104
- expect(files.headers.get("content-type")).toContain("text/plain");
105
- expect(await files.text()).toBe("listed");
106
- });
107
-
108
- it("answers a userToken none entry with no token", async () => {
109
- const res = await call({ entry: "catalog", path: "/search", method: "GET", persona: "hq-staff" });
110
- expect(res.status).toBe(200);
111
- expect(res.headers.get("x-pple-mock")).toBe("catalog");
112
- expect(await res.json()).toEqual({ ok: true });
113
- });
114
-
115
- it("refuses a required entry that was called with no token", async () => {
116
- for (const userToken of [undefined, "", " "]) {
117
- const res = await call({ entry: "orders", path: "/items/7", method: "GET", persona: "hq-staff", userToken });
118
- expect(res.status).toBe(401);
119
- expect(res.headers.get("x-pple-error")).toBe("user_token_invalid");
120
- expect(res.headers.get("x-pple-mock")).toBeNull();
121
- expect(platformError(res)).toBe("user_token_invalid");
122
- expect(await res.json()).toEqual({ error: "user_token_invalid" });
123
- }
124
- });
125
-
126
- it("says when the entry is missing, and when the route is", async () => {
127
- const missing = await call({ entry: "missing", path: "/items/1", method: "GET", persona: "hq-staff", userToken: "t" });
128
- expect(missing.status).toBe(404);
129
- expect(missing.headers.get("x-pple-error")).toBe("no_mock");
130
- expect(missing.headers.get("x-pple-mock")).toBeNull();
131
- expect(platformError(missing)).toBeNull();
132
- const missingBody = await missing.json<{ error: string; message: string }>();
133
- expect(missingBody.error).toBe("no_mock");
134
- expect(missingBody.message).toContain("pple registry");
135
- expect(missingBody.message).toContain(".pple/registry/");
136
- expect(missingBody.message).toMatch(/[\u0E00-\u0E7F]/);
137
-
138
- const route = await call({ entry: "orders", path: "/nope", method: "GET", persona: "hq-staff", userToken: "t" });
139
- const routeBody = await route.json<{ error: string; message: string }>();
140
- expect(route.status).toBe(404);
141
- expect(route.headers.get("x-pple-error")).toBe("no_mock");
142
- expect(routeBody.error).toBe("no_mock");
143
- expect(routeBody.message).toContain("pple registry");
144
- expect(routeBody.message).toContain("GET /nope");
145
- expect(routeBody.message).toMatch(/[\u0E00-\u0E7F]/);
146
- expect(routeBody.message).not.toContain(".pple/registry/");
147
- });
148
-
149
- it("keeps a root mock off every other tail", async () => {
150
- const root = await call({
151
- entry: "platform/legal-identity",
152
- path: "",
153
- method: "POST",
154
- persona: "kyc-verified-nonmember",
155
- userToken: "t",
156
- });
157
- expect(await root.json()).toEqual({ source: "default" });
158
-
159
- const member = await call({
160
- entry: "platform/legal-identity",
161
- path: "/",
162
- method: "POST",
163
- persona: "hq-staff",
164
- userToken: "t",
165
- });
166
- expect(await member.json()).toEqual({ source: "membership" });
167
-
168
- const other = await call({
169
- entry: "platform/legal-identity",
170
- path: "/extra",
171
- method: "POST",
172
- persona: "hq-staff",
173
- userToken: "t",
174
- });
175
- expect(other.status).toBe(404);
176
- expect(other.headers.get("x-pple-error")).toBe("no_mock");
177
- });
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
-
242
- describe("DEV_REGISTRY_ERROR", () => {
243
- const statuses: [string, number][] = [
244
- ["invalid_app_key", 401],
245
- ["not_listed", 404],
246
- ["not_granted", 403],
247
- ["needs_beta", 403],
248
- ["user_token_invalid", 401],
249
- ["identity_unavailable", 503],
250
- ["provider_unavailable", 502],
251
- ["provider_timeout", 504],
252
- ["method_not_allowed", 405],
253
- ["not_found", 404],
254
- ["invalid_query", 400],
255
- ["level_not_met", 403],
256
- ["renamed", 410],
257
- ];
258
-
259
- it.each(statuses)("global %s is %i", async (code, status) => {
260
- const res = await call({
261
- entry: "orders",
262
- path: "/items/1",
263
- method: "GET",
264
- persona: "hq-staff",
265
- userToken: "t",
266
- devRegistryError: code,
267
- });
268
- expect(res.status).toBe(status);
269
- expect(res.headers.get("x-pple-error")).toBe(code);
270
- expect(res.headers.get("x-pple-mock")).toBeNull();
271
- expect(platformError(res)).toBe(code);
272
- expect(await res.json()).toEqual({ error: code });
273
- });
274
-
275
- it("lets a per-entry code win over a global one, in either order", async () => {
276
- for (const spec of ["not_granted, orders=provider_timeout", "orders = provider_timeout, not_granted"]) {
277
- const orders = await call({
278
- entry: "orders",
279
- path: "/items/1",
280
- method: "GET",
281
- persona: "hq-staff",
282
- userToken: "t",
283
- devRegistryError: spec,
284
- });
285
- expect(orders.status).toBe(504);
286
- expect(orders.headers.get("x-pple-error")).toBe("provider_timeout");
287
-
288
- const catalog = await call({
289
- entry: "catalog",
290
- path: "/search",
291
- method: "GET",
292
- persona: "hq-staff",
293
- devRegistryError: spec,
294
- });
295
- expect(catalog.status).toBe(403);
296
- expect(await catalog.json()).toEqual({ error: "not_granted" });
297
- }
298
- });
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
-
412
- it("ignores an unknown code and still applies a global one", async () => {
413
- const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
414
- try {
415
- const mocked = await call({
416
- entry: "catalog",
417
- path: "/search",
418
- method: "GET",
419
- persona: "hq-staff",
420
- devRegistryError: "not_a_code",
421
- });
422
- expect(mocked.status).toBe(200);
423
- expect(await mocked.json()).toEqual({ ok: true });
424
-
425
- const forced = await call({
426
- entry: "orders",
427
- path: "/items/1",
428
- method: "GET",
429
- persona: "hq-staff",
430
- devRegistryError: "orders=not_a_code, needs_beta",
431
- });
432
- expect(forced.status).toBe(403);
433
- expect(forced.headers.get("x-pple-error")).toBe("needs_beta");
434
- expect(warn.mock.calls.some((args) => String(args[0]).includes("not_a_code"))).toBe(true);
435
- } finally {
436
- warn.mockRestore();
437
- }
438
- });
439
-
440
- it("applies before the missing-token refusal", async () => {
441
- const res = await call({
442
- entry: "orders",
443
- path: "/items/1",
444
- method: "GET",
445
- persona: "hq-staff",
446
- devRegistryError: "not_granted",
447
- });
448
- expect(res.status).toBe(403);
449
- expect(await res.json()).toEqual({ error: "not_granted" });
450
- });
451
- });
452
-
453
- function call(input: OverlayCall): Promise<Response> {
454
- return Promise.resolve(answerFromOverlay(overlay, { overlayRoot: "fixtures/overlay/", ...input }));
455
- }