@cosmicdrift/kumiko-dev-server 1.0.0 → 2.0.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 (66) hide show
  1. package/bin/kumiko-schema-check.ts +7 -0
  2. package/package.json +12 -7
  3. package/src/__tests__/build-prod-bundle.integration.test.ts +1 -1
  4. package/src/__tests__/build-server-bundle.test.ts +62 -0
  5. package/src/__tests__/compose-stacks.test.ts +271 -0
  6. package/src/__tests__/create-kumiko-server-errors.test.ts +54 -0
  7. package/src/__tests__/create-kumiko-server-options.test.ts +33 -0
  8. package/src/__tests__/create-kumiko-server.integration.test.ts +128 -1
  9. package/src/__tests__/discover-format.test.ts +1 -1
  10. package/src/__tests__/env-schema.integration.test.ts +1 -1
  11. package/src/__tests__/few-shot-corpus.test.ts +16 -11
  12. package/src/__tests__/merge-extra-context.test.ts +56 -0
  13. package/src/__tests__/resolve-stylesheet.test.ts +16 -0
  14. package/src/__tests__/saas-identity-wire.integration.test.ts +430 -0
  15. package/src/__tests__/scaffold-app-feature.test.ts +59 -6
  16. package/src/__tests__/scaffold-app.test.ts +34 -2
  17. package/src/__tests__/schema-apply.integration.test.ts +5 -2
  18. package/src/__tests__/setup-test-stack-from-features.integration.test.ts +30 -0
  19. package/src/__tests__/walkthrough.integration.test.ts +22 -6
  20. package/src/build-server-bundle.ts +33 -15
  21. package/src/build.ts +1 -2
  22. package/src/codegen/__tests__/render-codegen.test.ts +2 -1
  23. package/src/codegen/__tests__/run-codegen.test.ts +2 -2
  24. package/src/codegen/__tests__/strict-mode-diagnostics.test.ts +6 -1
  25. package/src/codegen/__tests__/watch.test.ts +1 -2
  26. package/src/codegen/render.ts +6 -1
  27. package/src/codegen/scan-events.ts +7 -5
  28. package/src/codegen/watch.ts +7 -4
  29. package/src/compose-stacks.ts +184 -0
  30. package/src/create-kumiko-server.ts +28 -5
  31. package/src/few-shot-corpus.ts +4 -3
  32. package/src/index.ts +30 -12
  33. package/src/run-dev-app.ts +195 -61
  34. package/src/scaffold-app-feature.ts +118 -15
  35. package/src/scaffold-app.ts +151 -79
  36. package/src/scaffold-demo-tasks.ts +233 -0
  37. package/src/schema-apply.ts +15 -2
  38. package/src/schema-check-core.ts +1 -1
  39. package/src/setup-test-stack-from-features.ts +61 -0
  40. package/src/welcome-banner.ts +1 -4
  41. package/src/__tests__/boot-extra-context.test.ts +0 -140
  42. package/src/__tests__/build-prod-bundle.test.ts +0 -311
  43. package/src/__tests__/cache-headers.test.ts +0 -83
  44. package/src/__tests__/compose-features-wiring.integration.test.ts +0 -382
  45. package/src/__tests__/compose-features.test.ts +0 -129
  46. package/src/__tests__/config-seed-boot.integration.test.ts +0 -158
  47. package/src/__tests__/inject-schema.test.ts +0 -62
  48. package/src/__tests__/renderer-web-css-relocation.integration.test.ts +0 -85
  49. package/src/__tests__/renderer-web-shell-sentinel.test.ts +0 -35
  50. package/src/__tests__/require-env.test.ts +0 -29
  51. package/src/__tests__/resolve-auth-mail.test.ts +0 -69
  52. package/src/__tests__/resolve-tailwind-cli.test.ts +0 -81
  53. package/src/__tests__/run-prod-app-env-source.test.ts +0 -157
  54. package/src/__tests__/run-prod-app-spec.test.ts +0 -57
  55. package/src/__tests__/run-prod-app.integration.test.ts +0 -840
  56. package/src/__tests__/session-wiring.test.ts +0 -51
  57. package/src/__tests__/try-hono-first.test.ts +0 -63
  58. package/src/boot/apply-boot-seeds.ts +0 -18
  59. package/src/build-prod-bundle.ts +0 -697
  60. package/src/compose-features.ts +0 -145
  61. package/src/extra-routes-deps.ts +0 -47
  62. package/src/inject-schema.ts +0 -24
  63. package/src/resolve-tailwind-cli.ts +0 -45
  64. package/src/run-prod-app.ts +0 -1492
  65. package/src/session-wiring.ts +0 -29
  66. package/src/try-hono-first.ts +0 -46
@@ -1,311 +0,0 @@
1
- // Unit-Tests für die Pure-Logic-Helpers von build-prod-bundle.
2
- //
3
- // Bun.build und Tailwind-CLI brauchen einen Bun-Runtime, deshalb
4
- // werden die hier nicht aufgerufen — nur Discovery + HTML-Injection
5
- // die unter Node funktionieren. End-to-End-Tests (mit echtem Bun.build)
6
- // laufen im CI als `bun run build` auf der Showcase-App; das ist der
7
- // ehrlichere Smoke-Test.
8
-
9
- import { afterEach, beforeEach, describe, expect, test } from "bun:test";
10
- import { existsSync } from "node:fs";
11
- import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises";
12
- import { tmpdir } from "node:os";
13
- import { join } from "node:path";
14
- import {
15
- type ClientEntry,
16
- computeBuildId,
17
- discoverClientEntries,
18
- discoverClientEntry,
19
- discoverHtmlTemplate,
20
- injectAssetTags,
21
- } from "../build-prod-bundle";
22
-
23
- // Synthetic single-entry helper. Realer Build erzeugt das via
24
- // discoverClientEntries; hier reicht die Form für injectAssetTags-Tests.
25
- function clientEntry(): ClientEntry {
26
- return {
27
- name: "client",
28
- sourceFile: "src/client.tsx",
29
- manifestKey: "client.js",
30
- htmlPath: "index.html",
31
- };
32
- }
33
-
34
- function namedEntry(name: string): ClientEntry {
35
- return {
36
- name,
37
- sourceFile: `src/client-${name}.tsx`,
38
- manifestKey: `client-${name}.js`,
39
- htmlPath: name === "public" ? "index.html" : `${name}.html`,
40
- };
41
- }
42
-
43
- describe("build-prod-bundle/discovery", () => {
44
- let workDir = "";
45
-
46
- beforeEach(async () => {
47
- workDir = await mkdtemp(join(tmpdir(), "kumiko-build-test-"));
48
- });
49
-
50
- afterEach(async () => {
51
- await rm(workDir, { recursive: true, force: true });
52
- });
53
-
54
- test("discoverClientEntry findet src/client.tsx wenn vorhanden", async () => {
55
- await mkdir(join(workDir, "src"), { recursive: true });
56
- await writeFile(join(workDir, "src/client.tsx"), "// noop");
57
-
58
- const entry = discoverClientEntry(workDir);
59
-
60
- expect(entry).toBe(join(workDir, "src/client.tsx"));
61
- });
62
-
63
- test("discoverClientEntry findet src/client.ts als Fallback", async () => {
64
- await mkdir(join(workDir, "src"), { recursive: true });
65
- await writeFile(join(workDir, "src/client.ts"), "// noop");
66
-
67
- const entry = discoverClientEntry(workDir);
68
-
69
- expect(entry).toBe(join(workDir, "src/client.ts"));
70
- });
71
-
72
- test("discoverClientEntry bevorzugt .tsx über .ts wenn beide existieren", async () => {
73
- await mkdir(join(workDir, "src"), { recursive: true });
74
- await writeFile(join(workDir, "src/client.tsx"), "// jsx");
75
- await writeFile(join(workDir, "src/client.ts"), "// ts");
76
-
77
- const entry = discoverClientEntry(workDir);
78
-
79
- expect(entry).toBe(join(workDir, "src/client.tsx"));
80
- });
81
-
82
- test("discoverClientEntry gibt undefined zurück wenn nichts da ist", () => {
83
- expect(discoverClientEntry(workDir)).toBeUndefined();
84
- });
85
-
86
- test("discoverClientEntries findet single-mode src/client.tsx", async () => {
87
- await mkdir(join(workDir, "src"), { recursive: true });
88
- await writeFile(join(workDir, "src/client.tsx"), "// single");
89
-
90
- const entries = discoverClientEntries(workDir);
91
-
92
- expect(entries).toHaveLength(1);
93
- expect(entries[0]?.name).toBe("client");
94
- expect(entries[0]?.manifestKey).toBe("client.js");
95
- expect(entries[0]?.htmlPath).toBe("index.html");
96
- });
97
-
98
- test("discoverClientEntries findet multi-mode client-public + client-admin", async () => {
99
- await mkdir(join(workDir, "src"), { recursive: true });
100
- await writeFile(join(workDir, "src/client-public.tsx"), "// public");
101
- await writeFile(join(workDir, "src/client-admin.tsx"), "// admin");
102
-
103
- const entries = discoverClientEntries(workDir);
104
-
105
- // Sortiert nach name.
106
- expect(entries.map((e) => e.name)).toEqual(["admin", "public"]);
107
-
108
- const admin = entries.find((e) => e.name === "admin");
109
- expect(admin?.manifestKey).toBe("client-admin.js");
110
- expect(admin?.htmlPath).toBe("admin.html");
111
-
112
- const pub = entries.find((e) => e.name === "public");
113
- expect(pub?.manifestKey).toBe("client-public.js");
114
- // "public" mappt auf das Default-Template (index.html), nicht
115
- // public.html — das ist Convention damit das default-served-Template
116
- // den vom-User-erwarteten Namen behält.
117
- expect(pub?.htmlPath).toBe("index.html");
118
- });
119
-
120
- test("discoverClientEntries multi-mode dominiert über single-mode wenn beide da", async () => {
121
- await mkdir(join(workDir, "src"), { recursive: true });
122
- await writeFile(join(workDir, "src/client.tsx"), "// single");
123
- await writeFile(join(workDir, "src/client-admin.tsx"), "// admin");
124
-
125
- const entries = discoverClientEntries(workDir);
126
-
127
- // Multi-mode aktiv → "client" wird ignoriert.
128
- expect(entries.map((e) => e.name)).toEqual(["admin"]);
129
- });
130
-
131
- test("discoverClientEntries gibt leeres Array zurück wenn nichts da", () => {
132
- expect(discoverClientEntries(workDir)).toEqual([]);
133
- });
134
-
135
- test("discoverHtmlTemplate findet index.html im cwd", async () => {
136
- await writeFile(join(workDir, "index.html"), "<html></html>");
137
-
138
- expect(discoverHtmlTemplate(workDir)).toBe(join(workDir, "index.html"));
139
- });
140
-
141
- test("discoverHtmlTemplate findet public/index.html als Fallback", async () => {
142
- await mkdir(join(workDir, "public"), { recursive: true });
143
- await writeFile(join(workDir, "public/index.html"), "<html></html>");
144
-
145
- expect(discoverHtmlTemplate(workDir)).toBe(join(workDir, "public/index.html"));
146
- });
147
-
148
- test("discoverHtmlTemplate bevorzugt cwd-index.html über public/index.html", async () => {
149
- await mkdir(join(workDir, "public"), { recursive: true });
150
- await writeFile(join(workDir, "index.html"), "<!-- root -->");
151
- await writeFile(join(workDir, "public/index.html"), "<!-- public -->");
152
-
153
- expect(discoverHtmlTemplate(workDir)).toBe(join(workDir, "index.html"));
154
- });
155
-
156
- test("discoverHtmlTemplate gibt undefined zurück wenn nichts da ist", () => {
157
- expect(existsSync(workDir)).toBe(true);
158
- expect(discoverHtmlTemplate(workDir)).toBeUndefined();
159
- });
160
- });
161
-
162
- describe("build-prod-bundle/injectAssetTags", () => {
163
- test("ersetzt /client.js durch hashed URL im script-tag", () => {
164
- const html = `<html><body><script type="module" src="/client.js"></script></body></html>`;
165
- const result = injectAssetTags(
166
- html,
167
- { "client.js": "/assets/client-abc123.js" },
168
- clientEntry(),
169
- );
170
-
171
- expect(result).toContain('src="/assets/client-abc123.js"');
172
- expect(result).not.toContain('src="/client.js"');
173
- });
174
-
175
- test("ersetzt /styles.css durch hashed URL im link-tag", () => {
176
- const html = `<html><head><link rel="stylesheet" href="/styles.css" /></head><body></body></html>`;
177
- const result = injectAssetTags(
178
- html,
179
- { "styles.css": "/assets/styles-def456.css" },
180
- clientEntry(),
181
- );
182
-
183
- expect(result).toContain('href="/assets/styles-def456.css"');
184
- expect(result).not.toContain('href="/styles.css"');
185
- });
186
-
187
- test("wirft mit Anweisung wenn /client.js Placeholder fehlt", () => {
188
- const html = `<html><body><div id="root"></div></body></html>`;
189
-
190
- expect(() =>
191
- injectAssetTags(html, { "client.js": "/assets/client-abc.js" }, clientEntry()),
192
- ).toThrow(/keinen Entry-Tag für \/client\.js/);
193
- expect(() =>
194
- injectAssetTags(html, { "client.js": "/assets/client-abc.js" }, clientEntry()),
195
- ).toThrow(/<script type="module" src="\/client\.js"><\/script>/);
196
- });
197
-
198
- test("wirft mit Anweisung wenn /styles.css Placeholder fehlt", () => {
199
- const html = `<html><head><title>App</title></head><body></body></html>`;
200
-
201
- expect(() =>
202
- injectAssetTags(html, { "styles.css": "/assets/styles-xyz.css" }, clientEntry()),
203
- ).toThrow(/keinen Entry-Tag für \/styles\.css/);
204
- expect(() =>
205
- injectAssetTags(html, { "styles.css": "/assets/styles-xyz.css" }, clientEntry()),
206
- ).toThrow(/<link rel="stylesheet" href="\/styles\.css" \/>/);
207
- });
208
-
209
- test("ist idempotent — zweite Injection auf bereits ersetztem HTML ändert nichts", () => {
210
- const html = `<html><body><script type="module" src="/client.js"></script></body></html>`;
211
- const manifest = { "client.js": "/assets/client-abc.js" };
212
- const first = injectAssetTags(html, manifest, clientEntry());
213
- const second = injectAssetTags(first, manifest, clientEntry());
214
-
215
- expect(first).toBe(second);
216
- expect(first).toContain('src="/assets/client-abc.js"');
217
- });
218
-
219
- test("ändert template ohne client/styles im manifest nicht", () => {
220
- const html = `<html><body>Hello</body></html>`;
221
- const result = injectAssetTags(html, {}, clientEntry());
222
-
223
- expect(result).toBe(html);
224
- });
225
-
226
- test("verträgt mehrere script-tags und ersetzt nur den /client.js", () => {
227
- const html = `<html><body>
228
- <script>console.log("inline");</script>
229
- <script type="module" src="/client.js"></script>
230
- </body></html>`;
231
- const result = injectAssetTags(html, { "client.js": "/assets/client-x.js" }, clientEntry());
232
-
233
- expect(result).toContain('console.log("inline")');
234
- expect(result).toContain('src="/assets/client-x.js"');
235
- expect(result).not.toContain('src="/client.js"');
236
- });
237
-
238
- test("multi-mode: admin-entry ersetzt nur /client-admin.js, lässt /client-public.js liegen", () => {
239
- const html = `<html><body>
240
- <script type="module" src="/client-admin.js"></script>
241
- <script type="module" src="/client-public.js"></script>
242
- </body></html>`;
243
- const manifest = {
244
- "client-admin.js": "/assets/client-admin-aaa.js",
245
- "client-public.js": "/assets/client-public-bbb.js",
246
- };
247
- const result = injectAssetTags(html, manifest, namedEntry("admin"));
248
-
249
- expect(result).toContain('src="/assets/client-admin-aaa.js"');
250
- // public-bundle bleibt unangetastet — admin.html lädt nur sein eigenes Bundle.
251
- expect(result).toContain('src="/client-public.js"');
252
- expect(result).not.toContain('src="/client-admin.js"');
253
- });
254
-
255
- test("multi-mode: error-message nennt den richtigen Template-Namen", () => {
256
- const html = `<html><body>no admin script</body></html>`;
257
- const manifest = { "client-admin.js": "/assets/client-admin-x.js" };
258
-
259
- expect(() => injectAssetTags(html, manifest, namedEntry("admin"))).toThrow(
260
- /admin\.html hat keinen Entry-Tag für \/client-admin\.js/,
261
- );
262
- });
263
- });
264
-
265
- describe("build-prod-bundle/computeBuildId", () => {
266
- test("identisches Manifest → gleiche id", () => {
267
- const manifest = {
268
- "client.js": "/assets/client-abc.js",
269
- "styles.css": "/assets/styles-xyz.css",
270
- };
271
- expect(computeBuildId(manifest)).toBe(computeBuildId({ ...manifest }));
272
- });
273
-
274
- test("Key-Reihenfolge egal — nur die URL-Werte zählen", () => {
275
- const a = { "client.js": "/assets/client-abc.js", "styles.css": "/assets/styles-xyz.css" };
276
- const b = { "styles.css": "/assets/styles-xyz.css", "client.js": "/assets/client-abc.js" };
277
- expect(computeBuildId(a)).toBe(computeBuildId(b));
278
- });
279
-
280
- test("geändertes Asset (neuer Hash) → andere id", () => {
281
- const before = { "client.js": "/assets/client-abc.js" };
282
- const after = { "client.js": "/assets/client-def.js" };
283
- expect(computeBuildId(before)).not.toBe(computeBuildId(after));
284
- });
285
-
286
- test("12 Hex-Zeichen", () => {
287
- expect(computeBuildId({ "client.js": "/assets/client-abc.js" })).toMatch(/^[0-9a-f]{12}$/);
288
- });
289
- });
290
-
291
- describe("build-prod-bundle/injectAssetTags build-info", () => {
292
- test("bäckt window.__KUMIKO_BUILD__ vor </head> wenn buildInfo gesetzt", () => {
293
- const html = `<html><head><title>x</title></head><body><script type="module" src="/client.js"></script></body></html>`;
294
- const result = injectAssetTags(html, { "client.js": "/assets/client-abc.js" }, clientEntry(), {
295
- id: "deadbeef0000",
296
- builtAt: "2026-06-18T12:00:00.000Z",
297
- });
298
-
299
- expect(result).toContain(
300
- 'window.__KUMIKO_BUILD__={"id":"deadbeef0000","builtAt":"2026-06-18T12:00:00.000Z"}',
301
- );
302
- expect(result.indexOf("__KUMIKO_BUILD__")).toBeLessThan(result.indexOf("</head>"));
303
- });
304
-
305
- test("ohne buildInfo kein __KUMIKO_BUILD__-Script", () => {
306
- const html = `<html><head></head><body><script type="module" src="/client.js"></script></body></html>`;
307
- const result = injectAssetTags(html, { "client.js": "/assets/client-abc.js" }, clientEntry());
308
-
309
- expect(result).not.toContain("__KUMIKO_BUILD__");
310
- });
311
- });
@@ -1,83 +0,0 @@
1
- // Unit-Tests für staticCachePolicy — die Cache-Strategie hinter
2
- // runProdApp's static-fallback. Pure function, leicht zu testen.
3
- //
4
- // Strategie (siehe run-prod-app.ts):
5
- // /assets/* → immutable
6
- // /, /index.html → revalidate (max-age=0, must-revalidate)
7
- // /manifest.json, /sw.js,
8
- // /build-info.json → no-cache
9
- // alles andere → none
10
-
11
- import { describe, expect, test } from "bun:test";
12
- import { cacheControlHeader } from "@cosmicdrift/kumiko-framework/api";
13
- import { staticCachePolicy } from "../run-prod-app";
14
-
15
- function cacheControlFor(pathname: string): Record<string, string> {
16
- const header = cacheControlHeader(staticCachePolicy(pathname));
17
- return header === undefined ? {} : { "cache-control": header };
18
- }
19
-
20
- describe("staticCachePolicy", () => {
21
- test("hashed asset → immutable + 1 Jahr", () => {
22
- expect(cacheControlFor("/assets/client-abc123.js")).toEqual({
23
- "cache-control": "public, max-age=31536000, immutable",
24
- });
25
- });
26
-
27
- test("hashed CSS asset → immutable + 1 Jahr", () => {
28
- expect(cacheControlFor("/assets/styles-def456.css")).toEqual({
29
- "cache-control": "public, max-age=31536000, immutable",
30
- });
31
- });
32
-
33
- test("nested asset path → immutable", () => {
34
- expect(cacheControlFor("/assets/chunks/foo-789.js")).toEqual({
35
- "cache-control": "public, max-age=31536000, immutable",
36
- });
37
- });
38
-
39
- test("/ → revalidate", () => {
40
- expect(cacheControlFor("/")).toEqual({
41
- "cache-control": "public, max-age=0, must-revalidate",
42
- });
43
- });
44
-
45
- test("/index.html → revalidate", () => {
46
- expect(cacheControlFor("/index.html")).toEqual({
47
- "cache-control": "public, max-age=0, must-revalidate",
48
- });
49
- });
50
-
51
- test("/manifest.json → no-cache", () => {
52
- expect(cacheControlFor("/manifest.json")).toEqual({
53
- "cache-control": "no-cache",
54
- });
55
- });
56
-
57
- test("/sw.js → no-cache", () => {
58
- expect(cacheControlFor("/sw.js")).toEqual({
59
- "cache-control": "no-cache",
60
- });
61
- });
62
-
63
- test("/build-info.json → no-cache (sonst pollt UpdateChecker eine veraltete id)", () => {
64
- expect(cacheControlFor("/build-info.json")).toEqual({
65
- "cache-control": "no-cache",
66
- });
67
- });
68
-
69
- test("public-folder file (favicon) → kein expliziter Header", () => {
70
- expect(cacheControlFor("/favicon.ico")).toEqual({});
71
- });
72
-
73
- test("public-folder file (og-image) → kein expliziter Header", () => {
74
- expect(cacheControlFor("/og-image.png")).toEqual({});
75
- });
76
-
77
- test("path mit assets als Substring (kein /assets/ prefix) → kein immutable", () => {
78
- // Schutz: /myassets/foo.js soll NICHT immutable kriegen — wäre ein Bug
79
- // weil die nicht gehashed sind.
80
- expect(cacheControlFor("/myassets/foo.js")).toEqual({});
81
- expect(cacheControlFor("/foo/assets/bar.js")).toEqual({});
82
- });
83
- });