@cosmicdrift/kumiko-testing 0.297.0 → 0.299.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.
package/README.md CHANGED
@@ -47,3 +47,11 @@ test("member sees the note", async ({ seedTenant, page }) => {
47
47
  - App roles: `createE2eSeedRoutes({ extraRoles: ["TenantMember"] })` lets `tenant.addUser(["TenantMember"])` seed them;
48
48
  `SystemAdmin` is never seedable and makes the route builder throw.
49
49
  - A `SeedPart` receives `{ tenant }` and works against the in-process `seedTenant` and the HTTP tenant alike.
50
+ - Already have a custom server entry (mail transport, KMS, boot seeds, ...) that also runs in prod?
51
+ Point `serverEntry` at it instead of duplicating `e2e/server.ts`, and mount the seed routes only
52
+ when the seed condition holds: `...(isE2eSeedingEnabled() ? createE2eSeedRoutes() : [])` in its own
53
+ `extraRoutes` — prod then never registers the routes at all, not just a per-request 404.
54
+ `isE2eSeedingEnabled` is exported from `@cosmicdrift/kumiko-testing/e2e/seed-route`.
55
+ - App-wide defaults after tenant creation (e.g. a completed onboarding) belong in a `postSave` hook on
56
+ the `"tenant"` entity (`r.hook("postSave", { allOf: "tenant" }, ...)`), fired via
57
+ `seedTenant(db, options, { registry, context })` — not in `seedTenant()` itself, which stays a blank tenant.
@@ -0,0 +1,76 @@
1
+ // kumiko-framework#3120: `kumiko-testing bunfig` used to overwrite an
2
+ // existing bunfig.toml unconditionally, silently dropping app-owned sections
3
+ // (e.g. `[install.scopes]` with a private-registry token) and unmanaged keys
4
+ // (e.g. `concurrency`) alike. Foreign sections now merge back in verbatim;
5
+ // only an unmanaged key inside a *managed* section still blocks the write.
6
+
7
+ import { describe, expect, test } from "bun:test";
8
+ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
9
+ import { tmpdir } from "node:os";
10
+ import { join } from "node:path";
11
+
12
+ const CLI_PATH = join(import.meta.dir, "..", "kumiko-testing.ts");
13
+
14
+ async function runCli(args: string[], cwd: string) {
15
+ const proc = Bun.spawn(["bun", CLI_PATH, ...args], { cwd, stdout: "pipe", stderr: "pipe" });
16
+ const [stdout, stderr, exitCode] = await Promise.all([
17
+ new Response(proc.stdout).text(),
18
+ new Response(proc.stderr).text(),
19
+ proc.exited,
20
+ ]);
21
+ return { stdout, stderr, exitCode };
22
+ }
23
+
24
+ describe("kumiko-testing bunfig — existing file with a foreign section", () => {
25
+ test("merges [install.scopes] back in instead of dropping it", async () => {
26
+ const dir = mkdtempSync(join(tmpdir(), "kumiko-testing-bunfig-"));
27
+ try {
28
+ const existing =
29
+ '[install.scopes]\n"@cosmicdriftgamestudio" = { token = "$GITHUB_TOKEN" }\n\n[test]\npreload = []\n';
30
+ writeFileSync(join(dir, "bunfig.toml"), existing);
31
+
32
+ const { exitCode } = await runCli(["bunfig"], dir);
33
+
34
+ expect(exitCode).toBe(0);
35
+ const written = readFileSync(join(dir, "bunfig.toml"), "utf-8");
36
+ expect(written).toContain("Generated by kumiko-testing");
37
+ expect(written).toContain(
38
+ '[install.scopes]\n"@cosmicdriftgamestudio" = { token = "$GITHUB_TOKEN" }',
39
+ );
40
+ } finally {
41
+ rmSync(dir, { recursive: true, force: true });
42
+ }
43
+ });
44
+
45
+ test("aborts and names an unmanaged key inside [test], leaves the file untouched", async () => {
46
+ const dir = mkdtempSync(join(tmpdir(), "kumiko-testing-bunfig-"));
47
+ try {
48
+ const existing = "[test]\nconcurrency = 8\npreload = []\n";
49
+ writeFileSync(join(dir, "bunfig.toml"), existing);
50
+
51
+ const { exitCode, stderr } = await runCli(["bunfig"], dir);
52
+
53
+ expect(exitCode).toBe(1);
54
+ expect(stderr).toContain("test.concurrency");
55
+ expect(readFileSync(join(dir, "bunfig.toml"), "utf-8")).toBe(existing);
56
+ } finally {
57
+ rmSync(dir, { recursive: true, force: true });
58
+ }
59
+ });
60
+
61
+ test("regenerates a file with no foreign sections and no unmanaged keys", async () => {
62
+ const dir = mkdtempSync(join(tmpdir(), "kumiko-testing-bunfig-"));
63
+ try {
64
+ writeFileSync(join(dir, "bunfig.toml"), "[test]\npreload = []\n");
65
+
66
+ const { exitCode } = await runCli(["bunfig"], dir);
67
+
68
+ expect(exitCode).toBe(0);
69
+ expect(readFileSync(join(dir, "bunfig.toml"), "utf-8")).toContain(
70
+ "Generated by kumiko-testing",
71
+ );
72
+ } finally {
73
+ rmSync(dir, { recursive: true, force: true });
74
+ }
75
+ });
76
+ });
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env bun
2
2
  // biome-ignore-all lint/suspicious/noConsole: CLI script, console is the interface.
3
3
 
4
- import { existsSync, writeFileSync } from "node:fs";
4
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import { parseArgs } from "node:util";
6
6
  import { Glob } from "bun";
7
- import { BUNFIG_FILES, renderBunfigFiles } from "../src/bunfig";
7
+ import { BUNFIG_FILES, mergeBunfig, renderBunfigFiles } from "../src/bunfig";
8
8
  import { buildIntegrationTestArgs, selectIntegrationFiles } from "../src/integration-runner";
9
9
 
10
10
  const USAGE = `kumiko-testing <command>
@@ -31,11 +31,25 @@ function runBunfig(args: readonly string[]): number {
31
31
  coverage: values.coverage === true,
32
32
  ...(values.hoisted === true && { install: { linker: "hoisted" } }),
33
33
  });
34
+ let blocked = false;
34
35
  for (const [name, content] of Object.entries(files)) {
35
- writeFileSync(name, content);
36
+ let toWrite = content;
37
+ if (existsSync(name)) {
38
+ const merged = mergeBunfig(content, readFileSync(name, "utf-8"));
39
+ if (!merged.ok) {
40
+ const keys = merged.unknownKeys.map((k) => `${k.section}.${k.key}`).join(", ");
41
+ console.error(
42
+ `${name} has key(s) kumiko-testing does not manage: ${keys}. Regenerating would drop them silently — remove them from ${name} or move them out of [install]/[test], then rerun.`,
43
+ );
44
+ blocked = true;
45
+ continue;
46
+ }
47
+ toWrite = merged.content;
48
+ }
49
+ writeFileSync(name, toWrite);
36
50
  console.log(`wrote ${name}`);
37
51
  }
38
- return 0;
52
+ return blocked ? 1 : 0;
39
53
  }
40
54
 
41
55
  async function runIntegration(args: readonly string[]): Promise<number> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-testing",
3
- "version": "0.297.0",
3
+ "version": "0.299.0",
4
4
  "description": "Test template for Kumiko apps: per-flow seedTenant, app test stack, canonical test preloads, bunfig generator and integration runner.",
5
5
  "license": "BUSL-1.1",
6
6
  "author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
@@ -63,9 +63,9 @@
63
63
  "kumiko-testing": "./bin/kumiko-testing.ts"
64
64
  },
65
65
  "dependencies": {
66
- "@cosmicdrift/kumiko-bundled-features": "0.297.0",
67
- "@cosmicdrift/kumiko-dev-server": "0.297.0",
68
- "@cosmicdrift/kumiko-framework": "0.297.0",
66
+ "@cosmicdrift/kumiko-bundled-features": "0.299.0",
67
+ "@cosmicdrift/kumiko-dev-server": "0.299.0",
68
+ "@cosmicdrift/kumiko-framework": "0.299.0",
69
69
  "zod": "^4.4.3"
70
70
  },
71
71
  "peerDependencies": {
package/src/bunfig.ts CHANGED
@@ -83,6 +83,81 @@ export function renderBunfig(variant: BunfigVariant, opts: BunfigOptions = {}):
83
83
  return `${lines.join("\n")}\n`;
84
84
  }
85
85
 
86
+ type BunfigBlock = { readonly header: string; readonly lines: readonly string[] };
87
+
88
+ // Splits on un-indented `[header]` lines only — real bunfig files never
89
+ // indent a table header, and TOML array/inline-table values that happen to
90
+ // contain "[" are never alone on their own line. Anything before the first
91
+ // header (top-level keys like `preload`/`telemetry`/`smol`/`logLevel`, plus
92
+ // the header comments) is its own block under the synthetic header "" —
93
+ // dropping it silently lost those keys (kumiko-framework#3120).
94
+ function splitBunfigBlocks(content: string): readonly BunfigBlock[] {
95
+ const blocks: { header: string; lines: string[] }[] = [];
96
+ let current: { header: string; lines: string[] } = { header: "", lines: [] };
97
+ for (const line of content.split("\n")) {
98
+ const match = /^\[([^\]]+)\]\s*$/.exec(line);
99
+ if (match?.[1] !== undefined) {
100
+ blocks.push(current);
101
+ current = { header: match[1], lines: [] };
102
+ continue;
103
+ }
104
+ current.lines.push(line);
105
+ }
106
+ blocks.push(current);
107
+ return blocks;
108
+ }
109
+
110
+ function keysIn(lines: readonly string[]): readonly string[] {
111
+ const keys: string[] = [];
112
+ for (const line of lines) {
113
+ const match = /^([A-Za-z_][\w-]*)\s*=/.exec(line.trim());
114
+ if (match?.[1] !== undefined) keys.push(match[1]);
115
+ }
116
+ return keys;
117
+ }
118
+
119
+ export type UnknownBunfigKey = { readonly section: string; readonly key: string };
120
+
121
+ export type BunfigMergeResult =
122
+ | { readonly ok: true; readonly content: string }
123
+ | { readonly ok: false; readonly unknownKeys: readonly UnknownBunfigKey[] };
124
+
125
+ /**
126
+ * Merges freshly generated bunfig content with whatever an app already has
127
+ * on disk. A section this run's `generated` output doesn't touch at all
128
+ * (e.g. `[install]` when `--install` wasn't passed, or `[install.scopes]`
129
+ * for a private-registry token, which renderBunfig never emits) is kept
130
+ * verbatim, appended after the generated content — so a section the
131
+ * template doesn't own this run is never silently dropped. A key inside a
132
+ * section the template DOES emit that isn't in this run's own version of
133
+ * that section (e.g. `concurrency`, `timeout`, kumiko-framework#3120) fails
134
+ * the merge instead of silently disappearing.
135
+ */
136
+ export function mergeBunfig(generated: string, existingContent: string): BunfigMergeResult {
137
+ const generatedKeysBySection = new Map(
138
+ splitBunfigBlocks(generated).map((block) => [block.header, new Set(keysIn(block.lines))]),
139
+ );
140
+ const blocks = splitBunfigBlocks(existingContent);
141
+ const unknownKeys: UnknownBunfigKey[] = [];
142
+ const foreignBlocks: BunfigBlock[] = [];
143
+ for (const block of blocks) {
144
+ const allowed = generatedKeysBySection.get(block.header);
145
+ if (allowed === undefined) {
146
+ foreignBlocks.push(block);
147
+ continue;
148
+ }
149
+ for (const key of keysIn(block.lines)) {
150
+ if (!allowed.has(key)) unknownKeys.push({ section: block.header, key });
151
+ }
152
+ }
153
+ if (unknownKeys.length > 0) return { ok: false, unknownKeys };
154
+ if (foreignBlocks.length === 0) return { ok: true, content: generated };
155
+ const foreignText = foreignBlocks
156
+ .map((block) => `[${block.header}]\n${block.lines.join("\n").replace(/\n+$/, "")}\n`)
157
+ .join("\n");
158
+ return { ok: true, content: `${generated}\n${foreignText}` };
159
+ }
160
+
86
161
  export function renderBunfigFiles(opts: BunfigOptions = {}): Readonly<Record<string, string>> {
87
162
  const { dom, ...shared } = opts;
88
163
  return {
package/src/changes.json CHANGED
@@ -1,4 +1,16 @@
1
1
  [
2
+ {
3
+ "version": "0.299.0",
4
+ "type": "fix",
5
+ "title": "kumiko-testing bunfig merges app-owned sections (e.g. install.scopes) back in and only aborts, naming the key, when a managed [install]/[test] section has a key the template doesn't emit; e2e seed routes gain an isE2eSeedingEnabled() export so a custom server entry can skip mounting them in prod",
6
+ "migration": "If `kumiko-testing bunfig` exits 1 naming a section.key (e.g. test.concurrency), remove or rename that key, or move it out of [install]/[test], then rerun. If your server entry mounts createE2eSeedRoutes() directly instead of using e2e/server.ts, guard the mount with isE2eSeedingEnabled() so prod never registers the seed routes."
7
+ },
8
+ {
9
+ "version": "0.298.0",
10
+ "type": "breaking",
11
+ "title": "createE2eSeedRoutes() returns ExtraRouteDefinition[] instead of an extraRoutes callback",
12
+ "migration": "createE2eSeedRoutes() now returns readonly ExtraRouteDefinition[] instead of an (app, deps) => void callback. The call site extraRoutes: createE2eSeedRoutes() in setupTestStack is unchanged, but any code that imported createE2eSeedRoutes() to invoke it directly against app (rather than passing it through extraRoutes) must instead treat the result as a route list, e.g. register each entry through the framework's ExtraRouteDefinition handling."
13
+ },
2
14
  {
3
15
  "version": "0.295.0",
4
16
  "type": "improvement",
@@ -76,7 +76,7 @@ function assertTemplateOwnedKeysUnset(project: E2eProject): void {
76
76
  ];
77
77
  if (offending.length > 0) {
78
78
  throw new Error(
79
- `defineAppE2eConfig: project "${name}" sets ${offending.join(", ")}; timeouts, retries and workers belong to the template. Diagnose per docs/guides/test-failures.md instead of raising them.`,
79
+ `defineAppE2eConfig: project "${name}" sets ${offending.join(", ")}; timeouts, retries and workers belong to the template. Diagnose per https://github.com/CosmicDriftGameStudio/kumiko-framework/blob/main/docs/guides/test-failures.md instead of raising them.`,
80
80
  );
81
81
  }
82
82
  }
@@ -3,9 +3,13 @@ import {
3
3
  getInbox,
4
4
  mailTransportInMemoryFeature,
5
5
  } from "@cosmicdrift/kumiko-bundled-features/mail-transport-inmemory";
6
- import { tenantTable } from "@cosmicdrift/kumiko-bundled-features/tenant";
7
- import type { CreateKumikoServerOptions } from "@cosmicdrift/kumiko-dev-server";
8
- import { fetchOne } from "@cosmicdrift/kumiko-framework/bun-db";
6
+ import { TenantQueries } from "@cosmicdrift/kumiko-bundled-features/tenant";
7
+ import {
8
+ type ExtraRouteDefinition,
9
+ ExtraRouteRejection,
10
+ type SignatureExtraRouteVerifyRequest,
11
+ signatureRoute,
12
+ } from "@cosmicdrift/kumiko-framework/api";
9
13
  import type { z } from "zod";
10
14
  import {
11
15
  persistTenantRows,
@@ -13,21 +17,13 @@ import {
13
17
  type SeedWriter,
14
18
  unwrapSavedRow,
15
19
  } from "../seed-tenant";
16
- import {
17
- SEED_ENABLE_ENV,
18
- SEED_ROUTE_PREFIX,
19
- SEED_ROUTES,
20
- SEED_TOKEN_ENV,
21
- SEED_TOKEN_HEADER,
22
- } from "./constants";
20
+ import { SEED_ENABLE_ENV, SEED_ROUTES, SEED_TOKEN_ENV, SEED_TOKEN_HEADER } from "./constants";
23
21
  import {
24
22
  createSeedUserRequestSchema,
25
23
  inboxQuerySchema,
26
24
  seedTenantRequestSchema,
27
25
  } from "./seed-contract";
28
26
 
29
- type ExtraRoutes = NonNullable<CreateKumikoServerOptions["extraRoutes"]>;
30
-
31
27
  type ParsedBody<T> =
32
28
  | { readonly success: true; readonly data: T }
33
29
  | { readonly success: false; readonly error: string };
@@ -50,7 +46,18 @@ function parseJsonBody<S extends z.ZodType>(schema: S, raw: string): ParsedBody<
50
46
  }
51
47
  }
52
48
 
53
- function seedingEnabled(): boolean {
49
+ // Shared by every verify() below — a failed parse becomes a 400 the same way
50
+ // the pre-#3050 handler-level parseJsonBody/parseWith checks did.
51
+ function parseOrReject<T>(value: ParsedBody<T>): T {
52
+ if (value.success) return value.data;
53
+ throw new ExtraRouteRejection(400, { error: value.error });
54
+ }
55
+
56
+ // Exported so a server entry that already mounts its own extraRoutes (instead
57
+ // of duplicating e2e/server.ts) can gate the *registration* itself — prod
58
+ // then never carries the seed routes at all, rather than relying solely on
59
+ // each route's own per-request assertGateOpen() check.
60
+ export function isE2eSeedingEnabled(): boolean {
54
61
  return process.env[SEED_ENABLE_ENV] === "1" && process.env["NODE_ENV"] !== "production";
55
62
  }
56
63
 
@@ -62,74 +69,118 @@ function tokenMatches(expected: string, provided: string | undefined): boolean {
62
69
  return provided !== undefined && timingSafeEqual(digest(expected), digest(provided));
63
70
  }
64
71
 
72
+ // Runs first in every verify() below — replaces the old `app.use(prefix/*)`
73
+ // guard middleware now that entry:"signature" owns its own access control.
74
+ function assertGateOpen(request: SignatureExtraRouteVerifyRequest): void {
75
+ // ExtraRouteRejection(status, body) always renders via c.json(body, status)
76
+ // (buildExtraRouteHonoHandler) — the plain-text "Not Found" from the old
77
+ // middleware becomes a JSON body; no test asserts the 404 body shape.
78
+ if (!isE2eSeedingEnabled()) throw new ExtraRouteRejection(404, { error: "Not Found" });
79
+ const expected = process.env[SEED_TOKEN_ENV];
80
+ if (expected === undefined || expected === "") {
81
+ throw new ExtraRouteRejection(500, {
82
+ error: `${SEED_TOKEN_ENV} is not set; refusing to serve seed routes`,
83
+ });
84
+ }
85
+ if (!tokenMatches(expected, request.headers[SEED_TOKEN_HEADER])) {
86
+ throw new ExtraRouteRejection(401, { error: "invalid seed token" });
87
+ }
88
+ }
89
+
65
90
  export type E2eSeedRoutesOptions = {
66
91
  readonly extraRoles?: readonly string[];
67
92
  };
68
93
 
69
- export function createE2eSeedRoutes(options: E2eSeedRoutesOptions = {}): ExtraRoutes {
94
+ // Builds the route definitions unconditionally (extraRoles validation must
95
+ // still throw in every environment) — the *mounting* decision is the
96
+ // caller's: use isE2eSeedingEnabled() to keep prod from ever registering
97
+ // these route objects at all, e.g. `...(isE2eSeedingEnabled() ?
98
+ // createE2eSeedRoutes() : [])` in a server entry that also runs in prod
99
+ // (kumiko-framework#3120). Each route's own assertGateOpen() 404s outside
100
+ // the seed condition regardless — this is belt-and-suspenders, not the only gate.
101
+ export function createE2eSeedRoutes(
102
+ options: E2eSeedRoutesOptions = {},
103
+ ): readonly ExtraRouteDefinition[] {
70
104
  const seedUserRequestSchema = createSeedUserRequestSchema(options.extraRoles);
71
- return (app, deps) => {
72
- const write: SeedWriter = async (handlerQn, payload, tenantId) =>
73
- unwrapSavedRow(handlerQn, await deps.dispatchSystemWrite({ handlerQn, payload, tenantId }));
74
105
 
75
- app.use(`${SEED_ROUTE_PREFIX}/*`, async (c, next) => {
76
- // c.notFound() would let the dev server answer unmatched GETs with its HTML shell (200).
77
- if (!seedingEnabled()) return c.text("Not Found", 404);
78
- const expected = process.env[SEED_TOKEN_ENV];
79
- if (expected === undefined || expected === "") {
80
- return c.json(
81
- { error: `${SEED_TOKEN_ENV} is not set; refusing to serve seed routes` },
82
- 500,
83
- );
84
- }
85
- if (!tokenMatches(expected, c.req.header(SEED_TOKEN_HEADER))) {
86
- return c.json({ error: "invalid seed token" }, 401);
87
- }
88
- await next();
89
- });
90
-
91
- app.post(SEED_ROUTES.seedTenant, async (c) => {
92
- const body = parseJsonBody(seedTenantRequestSchema, await c.req.text());
93
- if (!body.success) return c.json({ error: body.error }, 400);
106
+ const seedTenantRoute = signatureRoute<z.infer<typeof seedTenantRequestSchema>>({
107
+ method: "POST",
108
+ path: SEED_ROUTES.seedTenant,
109
+ entry: "signature",
110
+ verify: async (request) => {
111
+ assertGateOpen(request);
112
+ return parseOrReject(parseJsonBody(seedTenantRequestSchema, request.rawBody));
113
+ },
114
+ handler: async (c, verified, deps) => {
115
+ const write: SeedWriter = async (handlerQn, payload, tenantId) =>
116
+ unwrapSavedRow(handlerQn, await deps.dispatchSystemWrite({ handlerQn, payload, tenantId }));
94
117
  try {
95
118
  return c.json(
96
- await persistTenantRows(write, { name: body.data.name, users: body.data.members }),
119
+ await persistTenantRows(write, { name: verified.name, users: verified.members }),
97
120
  );
98
121
  } catch (error) {
99
122
  return c.json({ error: error instanceof Error ? error.message : "seed failed" }, 500);
100
123
  }
101
- });
124
+ },
125
+ });
102
126
 
103
- app.post(SEED_ROUTES.seedUser, async (c) => {
104
- const body = parseJsonBody(seedUserRequestSchema, await c.req.text());
105
- if (!body.success) return c.json({ error: body.error }, 400);
106
- if ((await fetchOne(deps.db, tenantTable, { id: body.data.tenantId })) === undefined) {
107
- return c.json({ error: `unknown tenant ${body.data.tenantId}` }, 404);
127
+ const seedUserRoute = signatureRoute<z.infer<typeof seedUserRequestSchema>>({
128
+ method: "POST",
129
+ path: SEED_ROUTES.seedUser,
130
+ entry: "signature",
131
+ verify: async (request) => {
132
+ assertGateOpen(request);
133
+ return parseOrReject(parseJsonBody(seedUserRequestSchema, request.rawBody));
134
+ },
135
+ handler: async (c, verified, deps) => {
136
+ // No raw db in signature-route deps (fw#3050) — tenant:query:me, run as
137
+ // a SystemAdmin scoped to verified.tenantId, is the existing
138
+ // fetchOne(tenantTable, {id: tenantId}) lookup, just behind the dispatcher.
139
+ const tenantRow = await deps.dispatchSystemQuery({
140
+ handlerQn: TenantQueries.me,
141
+ payload: {},
142
+ tenantId: verified.tenantId,
143
+ });
144
+ if (tenantRow === null) {
145
+ return c.json({ error: `unknown tenant ${verified.tenantId}` }, 404);
108
146
  }
147
+ const write: SeedWriter = async (handlerQn, payload, tenantId) =>
148
+ unwrapSavedRow(handlerQn, await deps.dispatchSystemWrite({ handlerQn, payload, tenantId }));
109
149
  try {
110
- return c.json(await persistUserRows(write, body.data.tenantId, body.data.roles));
150
+ return c.json(await persistUserRows(write, verified.tenantId, verified.roles));
111
151
  } catch (error) {
112
152
  return c.json({ error: error instanceof Error ? error.message : "seed failed" }, 500);
113
153
  }
114
- });
154
+ },
155
+ });
115
156
 
116
- app.get(SEED_ROUTES.inbox, (c) => {
157
+ const inboxRoute = signatureRoute<z.infer<typeof inboxQuerySchema>>({
158
+ method: "GET",
159
+ path: SEED_ROUTES.inbox,
160
+ entry: "signature",
161
+ verify: async (request) => {
162
+ assertGateOpen(request);
163
+ return parseOrReject(
164
+ parseWith(inboxQuerySchema, {
165
+ tenantId: request.query["tenantId"],
166
+ to: request.query["to"],
167
+ }),
168
+ );
169
+ },
170
+ handler: async (c, verified, deps) => {
117
171
  if (!deps.registry.features.has(mailTransportInMemoryFeature.name)) {
118
172
  return c.json(
119
173
  { error: `${mailTransportInMemoryFeature.name} is not mounted; no inbox to read` },
120
174
  501,
121
175
  );
122
176
  }
123
- const query = parseWith(inboxQuerySchema, {
124
- tenantId: c.req.query("tenantId"),
125
- to: c.req.query("to"),
126
- });
127
- if (!query.success) return c.json({ error: query.error }, 400);
128
- const recipient = query.data.to.toLowerCase();
129
- const messages = getInbox(query.data.tenantId).filter(
177
+ const recipient = verified.to.toLowerCase();
178
+ const messages = getInbox(verified.tenantId).filter(
130
179
  (message) => message.to.toLowerCase() === recipient,
131
180
  );
132
181
  return c.json({ messages });
133
- });
134
- };
182
+ },
183
+ });
184
+
185
+ return [seedTenantRoute, seedUserRoute, inboxRoute];
135
186
  }
package/src/scaffold.ts CHANGED
@@ -35,7 +35,7 @@ const RULES_MARKDOWN = [
35
35
  `- Real-provider tests only run with \`${REAL_PROVIDERS_ENV}=1\`, via \`bun run test:real\` / \`bun run e2e:real\`, locally and never in CI.`,
36
36
  "- Tests run in parallel by default. Timeouts, retries and workers live in the scripts, the bunfig files and `playwright.config.ts`; never raise them inside a test. The only exception carries a marker: `// @timeout-exception: #<issue> <reason>`.",
37
37
  "- Every flow seeds its own tenant: `seedTenant(stack)` in integration tests, the `seedTenant` fixture in e2e. No shared tenant, no widened seed helper.",
38
- "- Red or flaky? Diagnose the cause first (`docs/guides/test-failures.md` in the kumiko-framework repo). A longer timeout, a retry or `serial` is not a fix.",
38
+ "- Red or flaky? Diagnose the cause first (https://github.com/CosmicDriftGameStudio/kumiko-framework/blob/main/docs/guides/test-failures.md). A longer timeout, a retry or `serial` is not a fix.",
39
39
  "- Run Playwright as `bunx --bun playwright`, as the scripts do.",
40
40
  `- Playwright configs and e2e files start with \`${TEST_RUNTIME_DIRECTIVE}\`; without it the runtime-isolation guard flags their import of the test package.`,
41
41
  "",