@akanjs/devkit 3.3.0-rc.0 → 3.3.0-rc.10

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 (85) hide show
  1. package/CHANGELOG.md +229 -2
  2. package/README.ko.md +3 -2
  3. package/README.md +3 -3
  4. package/akanApp/akanApp.host.test.ts +22 -5
  5. package/akanApp/akanApp.host.ts +46 -9
  6. package/akanApp/akanApp.host.wiring.test.ts +206 -2
  7. package/akanApp/devBackend.ts +3 -1
  8. package/akanApp/devBuilder.ts +5 -1
  9. package/akanApp/devStartTimeline.test.ts +115 -0
  10. package/akanApp/devStartTimeline.ts +69 -0
  11. package/akanConfig/akanConfig.test.ts +57 -8
  12. package/akanConfig/akanConfig.ts +12 -65
  13. package/akanConfig/dockerImage.ts +17 -0
  14. package/akanConfig/nativeKeys.ts +52 -0
  15. package/app/applicationBuildRunner.test.ts +49 -1
  16. package/app/applicationBuildRunner.ts +3 -1
  17. package/codeAgent/agent/CodeAgent.ts +36 -16
  18. package/codeAgent/agent/CodeAgentAllowed.ts +35 -0
  19. package/codeAgent/agent/CodeAgentCommandLine.ts +372 -0
  20. package/codeAgent/agent/CodeAgentGate.ts +23 -4
  21. package/codeAgent/agent/CodeAgentRpcHost.ts +1 -1
  22. package/codeAgent/agent/codeAgent.test.ts +62 -0
  23. package/codeAgent/agent/codeAgentCommandLine.test.ts +212 -0
  24. package/codeAgent/agent/codeAgentContract.test.ts +117 -5
  25. package/codeAgent/skills/akan-agent/SKILL.md +8 -1
  26. package/codeAgent/skills/akan-code/SKILL.md +38 -3
  27. package/codeAgent/skills/akan-page/SKILL.md +18 -13
  28. package/codeAgent/skills/akan-runtime/SKILL.md +21 -16
  29. package/codeAgent/skills/akan-service/SKILL.md +2 -2
  30. package/docs/apiReference.test.ts +5 -0
  31. package/docs/apiReference.ts +7 -3
  32. package/docs/declarationReader.ts +28 -1
  33. package/executors/appExecutor.ts +35 -11
  34. package/executors/executors.test.ts +30 -3
  35. package/frontendBuild/buildCacheStamp.test.ts +42 -0
  36. package/frontendBuild/buildCacheStamp.ts +23 -0
  37. package/frontendBuild/buildRouteClient.test.ts +2 -7
  38. package/frontendBuild/clientEntryDiscovery.ts +2 -2
  39. package/frontendBuild/cssCandidateCache.test.ts +70 -1
  40. package/frontendBuild/cssCandidateCache.ts +17 -10
  41. package/frontendBuild/cssCompiler.test.ts +112 -0
  42. package/frontendBuild/cssCompiler.ts +41 -21
  43. package/frontendBuild/devBarrelImports.test.ts +30 -0
  44. package/frontendBuild/devBarrelImports.ts +2 -2
  45. package/frontendBuild/fontOptimizer.test.ts +144 -3
  46. package/frontendBuild/fontOptimizer.ts +103 -18
  47. package/frontendBuild/pagesBundleBuilder.ts +3 -1
  48. package/frontendBuild/plainStylesheet.test.ts +155 -0
  49. package/frontendBuild/plainStylesheet.ts +197 -0
  50. package/frontendBuild/rscServerRendererGuard.test.ts +60 -0
  51. package/frontendBuild/rscServerRendererGuard.ts +68 -0
  52. package/frontendBuild/ssrBaseArtifactBuilder.test.ts +30 -1
  53. package/frontendBuild/ssrBaseArtifactBuilder.ts +40 -12
  54. package/guideline/agentAssets.test.ts +10 -0
  55. package/guideline/agentAssets.ts +52 -11
  56. package/incrementalBuilder/buildBatch.proc.ts +11 -10
  57. package/incrementalBuilder/buildBatchProtocol.ts +2 -1
  58. package/incrementalBuilder/builderBoot.ts +14 -7
  59. package/incrementalBuilder/builderChannel.ts +8 -2
  60. package/incrementalBuilder/builderGraphPayloads.ts +4 -4
  61. package/incrementalBuilder/builderLanes.ts +2 -2
  62. package/incrementalBuilder/builderWatch.ts +8 -8
  63. package/incrementalBuilder/csrRegistry.ts +4 -4
  64. package/incrementalBuilder/incrementalBuilder.host.test.ts +16 -0
  65. package/incrementalBuilder/incrementalBuilder.host.ts +7 -1
  66. package/incrementalBuilder/incrementalBuilder.proc.test.ts +41 -0
  67. package/incrementalBuilder/incrementalBuilder.proc.ts +9 -8
  68. package/incrementalBuilder/ssrRegistry.ts +6 -6
  69. package/index.ts +1 -1
  70. package/integration/renderAdmissionSoak.test.ts +99 -0
  71. package/integration/renderAdmissionSoak.ts +609 -0
  72. package/mobile/nativeConfig.test.ts +100 -0
  73. package/mobile/nativeConfig.ts +55 -16
  74. package/mobile/nativePublicEnv.ts +2 -1
  75. package/package.json +14 -169
  76. package/packageExports.test.ts +38 -24
  77. package/transforms/barrelAnalyzer.ts +2 -2
  78. package/transforms/transforms.test.ts +3 -3
  79. package/tunnel/createTunnel.test.ts +29 -8
  80. package/tunnel/createTunnel.ts +18 -11
  81. package/util/fileEditor.ts +1 -0
  82. package/util/fileSys.test.ts +13 -0
  83. package/util/fileSys.ts +2 -2
  84. package/util/selectModel.ts +1 -0
  85. package/workspace/getRelatedCnsts.ts +7 -0
@@ -1,6 +1,12 @@
1
1
  import type { Logger } from "akanjs/common";
2
2
  import type { BuilderMessage } from "akanjs/server";
3
3
 
4
+ //? For the host alone, never relayed: the boot artifact is on disk, and `builder-ready` follows once the watcher is up.
5
+ export interface BaseBuiltMessage {
6
+ type: "base-built";
7
+ phaseMs: Record<string, number>;
8
+ }
9
+
4
10
  // `process.exit` drops an ipc write that has not flushed (a natural exit does not), and whether one survives
5
11
  // depends on the message's shape as well as its size — so every send reports its flush and `shutdown` drains.
6
12
  export class BuilderChannel {
@@ -8,7 +14,7 @@ export class BuilderChannel {
8
14
  static readonly #flushTimeoutMs = 5_000;
9
15
  static readonly #flushing = new Set<Promise<void>>();
10
16
 
11
- static send(message: BuilderMessage): Promise<void> {
17
+ static send(message: BuilderMessage | BaseBuiltMessage): Promise<void> {
12
18
  const send = process.send;
13
19
  if (!send) return Promise.resolve();
14
20
  const flushed = new Promise<void>((resolve) => {
@@ -25,7 +31,7 @@ export class BuilderChannel {
25
31
  }
26
32
 
27
33
  // Tracked like `send`: for an event nobody awaits, `drain` is all that stands between it and the exit.
28
- static emit(message: BuilderMessage): void {
34
+ static emit(message: BuilderMessage | BaseBuiltMessage): void {
29
35
  void BuilderChannel.send(message);
30
36
  }
31
37
 
@@ -1,8 +1,8 @@
1
- import type { App } from "@akanjs/devkit/commandDecorators";
2
- import { FrameworkGraph } from "@akanjs/devkit/docs/frameworkGraph";
3
- import { GitRevision } from "@akanjs/devkit/workspace/gitRevision";
4
- import { WorkspaceGraph } from "@akanjs/devkit/workspace/workspaceGraph";
5
1
  import type { BuildChangesPayload, BuilderGraphReq, BuildFrameworkPayload, BuildGraphPayload } from "akanjs/server";
2
+ import type { App } from "../commandDecorators";
3
+ import { FrameworkGraph } from "../docs/frameworkGraph";
4
+ import { GitRevision } from "../workspace/gitRevision";
5
+ import { WorkspaceGraph } from "../workspace/workspaceGraph";
6
6
 
7
7
  export class BuilderGraphPayloads {
8
8
  readonly #app: App;
@@ -1,6 +1,6 @@
1
- import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
2
- import type { App } from "@akanjs/devkit/commandDecorators";
3
1
  import type { Logger } from "akanjs/common";
2
+ import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
3
+ import type { App } from "../commandDecorators";
4
4
  import type { BatchWork, BuildBatchResult } from "./buildBatchProtocol";
5
5
  import { sendBuildStatus } from "./builderBuildStatus";
6
6
  import { BuilderChannel } from "./builderChannel";
@@ -1,14 +1,14 @@
1
1
  import path from "node:path";
2
- import type { App } from "@akanjs/devkit/commandDecorators";
3
- import type { PageRoot } from "@akanjs/devkit/executors";
4
- import { AutoImportSync } from "@akanjs/devkit/frontendBuild/autoImportSync";
5
- import { DevChangePlanner } from "@akanjs/devkit/frontendBuild/devChangePlanner";
6
- import { DevGeneratedIndexSync } from "@akanjs/devkit/frontendBuild/devGeneratedIndexSync";
7
- import { HmrWatcher } from "@akanjs/devkit/frontendBuild/hmrWatcher";
8
- import { WatchRootResolver } from "@akanjs/devkit/frontendBuild/watchRootResolver";
9
- import { CodegenLock } from "@akanjs/devkit/workspace/codegenLock";
10
2
  import type { Logger } from "akanjs/common";
11
3
  import type { ChangeBatch } from "akanjs/server";
4
+ import type { App } from "../commandDecorators";
5
+ import type { PageRoot } from "../executors";
6
+ import { AutoImportSync } from "../frontendBuild/autoImportSync";
7
+ import { DevChangePlanner } from "../frontendBuild/devChangePlanner";
8
+ import { DevGeneratedIndexSync } from "../frontendBuild/devGeneratedIndexSync";
9
+ import { HmrWatcher } from "../frontendBuild/hmrWatcher";
10
+ import { WatchRootResolver } from "../frontendBuild/watchRootResolver";
11
+ import { CodegenLock } from "../workspace/codegenLock";
12
12
  import type { BuildBatchNeed } from "./buildBatchProtocol";
13
13
  import { sendBuildStatus } from "./builderBuildStatus";
14
14
  import { BuilderChannel } from "./builderChannel";
@@ -1,12 +1,12 @@
1
1
  import { rm } from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
4
- import type { App } from "@akanjs/devkit/commandDecorators";
5
- import { CsrDevBundler } from "@akanjs/devkit/frontendBuild/csrDevBundler";
6
- import { CsrDevPatcher } from "@akanjs/devkit/frontendBuild/csrDevPatcher";
7
3
  import type { Logger } from "akanjs/common";
8
4
  import type { BaseBuildArtifact, BuilderCsrReq, HmrTrace } from "akanjs/server";
9
5
  import { CSR_DEV_PATCHING_MARKER } from "akanjs/server/hmr/csrDevManifest";
6
+ import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
7
+ import type { App } from "../commandDecorators";
8
+ import { CsrDevBundler } from "../frontendBuild/csrDevBundler";
9
+ import { CsrDevPatcher } from "../frontendBuild/csrDevPatcher";
10
10
  import type { BatchWork, BuildBatchRequest } from "./buildBatchProtocol";
11
11
  import type { BuildBatchRunner } from "./buildBatchRunner";
12
12
  import { isCompileError, sendBuildStatus } from "./builderBuildStatus";
@@ -43,6 +43,22 @@ const startRecordingHost = () => {
43
43
  };
44
44
 
45
45
  describe("IncrementalBuilderHost", () => {
46
+ test("tells its starter the boot artifact is built, ahead of ready, and relays nothing for it", () => {
47
+ const spawns = mockSpawns();
48
+ const messages: unknown[] = [];
49
+ const onBaseBuilt = mock();
50
+ const host = createHost((message) => messages.push(message));
51
+
52
+ host.start({ onBaseBuilt });
53
+ spawns[0]?.options.ipc?.({ type: "base-built", phaseMs: { pages: 5, total: 9 } });
54
+
55
+ expect(onBaseBuilt).toHaveBeenCalledWith({ pages: 5, total: 9 });
56
+ expect(host.status).toBe("starting");
57
+ expect(messages).toEqual([]);
58
+
59
+ host.stop();
60
+ });
61
+
46
62
  test("restarts after a ready builder exits", async () => {
47
63
  const spawns = mockSpawns();
48
64
 
@@ -5,6 +5,7 @@ import type { BuilderMessage, BuilderRequest } from "akanjs/server";
5
5
  import { CSR_DEV_DIRNAME, CSR_DEV_PATCHING_MARKER, SSR_DEV_DIRNAME } from "akanjs/server/hmr/csrDevManifest";
6
6
  import { MemoryLimit } from "akanjs/server/memoryLimit";
7
7
  import type { App } from "../commandDecorators";
8
+ import type { BaseBuiltMessage } from "./builderChannel";
8
9
 
9
10
  const builderMsgTypeSet = new Set<BuilderMessage["type"]>([
10
11
  "build-route-res",
@@ -41,6 +42,7 @@ export type IncrementalBuilderStatus = "starting" | "ready" | "recycling" | "res
41
42
  interface IncrementalBuilderStartOptions {
42
43
  onExit?: () => void;
43
44
  onReady?: () => void;
45
+ onBaseBuilt?: (phaseMs: Record<string, number>) => void;
44
46
  onRestartReady?: () => void;
45
47
  /** The builder is gone and a replacement is coming (unwatched until then); `onExit` means it gave up. */
46
48
  onAway?: () => void;
@@ -124,9 +126,13 @@ export class IncrementalBuilderHost {
124
126
  ...(this.#patcherOff ? { AKAN_DEV_CSR_PATCHER: "off" } : {}),
125
127
  },
126
128
  stdio: ["ignore", this.#stdio, this.#stdio],
127
- ipc: (msg: BuilderMessage) => {
129
+ ipc: (msg: BuilderMessage | BaseBuiltMessage) => {
128
130
  if (this.#proc !== proc) return;
129
131
  if (!msg || typeof msg !== "object") return;
132
+ if (msg.type === "base-built") {
133
+ this.#startOptions.onBaseBuilt?.(msg.phaseMs);
134
+ return;
135
+ }
130
136
  if (msg.type === "build-route-res" || msg.type === "build-csr-res" || msg.type === "build-graph-res")
131
137
  this.#inFlight.delete(msg.id);
132
138
  if (builderMsgTypeSet.has(msg.type)) this.#onMessage(msg);
@@ -86,6 +86,47 @@ process.send({ type: "build-batch-result", data: { generation, errors: {}, artif
86
86
  expect(log).toContain(reason);
87
87
  }, 30_000);
88
88
 
89
+ test("says its boot artifact is built, with the build's parts, before it says it is ready", async () => {
90
+ const { root } = track(await createTempApp("demo"));
91
+ const appDir = path.join(root, "apps/demo");
92
+ await writeText(
93
+ path.join(root, "pkgs/@akanjs/devkit/incrementalBuilder/buildBatch.proc.ts"),
94
+ `const { generation } = JSON.parse(process.argv[2]);
95
+ process.once("disconnect", () => {});
96
+ process.send({ type: "build-batch-result", data: { generation, errors: {}, artifact: {}, optimizedFonts: { css: "", files: [] }, basePhaseMs: { styles: 7, pages: 5, total: 9 } } });
97
+ `,
98
+ );
99
+ await writeText(path.join(appDir, "page/_index.tsx"), "export default () => null;\n");
100
+ const messages: { type: string; phaseMs?: Record<string, number> }[] = [];
101
+ const proc = Bun.spawn(["bun", path.join(import.meta.dir, "incrementalBuilder.proc.ts")], {
102
+ cwd: appDir,
103
+ env: {
104
+ ...process.env,
105
+ AKAN_WORKSPACE_ROOT: root,
106
+ AKAN_PUBLIC_APP_NAME: "demo",
107
+ AKAN_PUBLIC_REPO_NAME: "repo",
108
+ AKAN_PUBLIC_SERVE_DOMAIN: "localhost",
109
+ AKAN_PUBLIC_ENV: "local",
110
+ AKAN_WATCH: "0",
111
+ },
112
+ stdio: ["ignore", "ignore", "ignore"],
113
+ serialization: "advanced",
114
+ ipc: (message: { type: string; phaseMs?: Record<string, number> }) => {
115
+ messages.push(message);
116
+ },
117
+ });
118
+ try {
119
+ await until(proc, "builder-ready", () => messages.some((message) => message.type === "builder-ready"));
120
+ } finally {
121
+ proc.kill();
122
+ await proc.exited;
123
+ }
124
+
125
+ const types = messages.map((message) => message.type);
126
+ expect(types.slice(0, 2)).toEqual(["base-built", "builder-ready"]);
127
+ expect(messages[0]).toEqual({ type: "base-built", phaseMs: { styles: 7, pages: 5, total: 9 } });
128
+ }, 30_000);
129
+
89
130
  test("builds a view's shell once on request, answers with its failure, and reports it to no tab", async () => {
90
131
  const { root } = track(await createTempApp("demo"));
91
132
  const appDir = path.join(root, "apps/demo");
@@ -1,12 +1,4 @@
1
1
  import path from "node:path";
2
- // Module paths, never a barrel: the devkit and `frontendBuild` barrels would hold tailwindcss (~40MB), ssh2, ink
3
- // and the cloud stack for the whole dev session (`entryModuleGraph.test.ts` enforces it).
4
- import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
5
- import type { App } from "@akanjs/devkit/commandDecorators";
6
- import { AppExecutor, type PageRoot, WorkspaceExecutor } from "@akanjs/devkit/executors";
7
- import type { ClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientBuildTypes";
8
- import { GraphClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientEntryDiscovery";
9
- import { RouteClientBuilder } from "@akanjs/devkit/frontendBuild/routeClientBuilder";
10
2
  import { Logger } from "akanjs/common";
11
3
  import type {
12
4
  BaseBuildArtifact,
@@ -18,6 +10,14 @@ import type {
18
10
  BuildRouteResultPayload,
19
11
  ChangeBatch,
20
12
  } from "akanjs/server";
13
+ // Module paths, never a barrel: the devkit and `frontendBuild` barrels would hold tailwindcss (~40MB), ssh2, ink
14
+ // and the cloud stack for the whole dev session (`entryModuleGraph.test.ts` enforces it).
15
+ import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
16
+ import type { App } from "../commandDecorators";
17
+ import { AppExecutor, type PageRoot, WorkspaceExecutor } from "../executors";
18
+ import type { ClientEntryDiscovery } from "../frontendBuild/clientBuildTypes";
19
+ import { GraphClientEntryDiscovery } from "../frontendBuild/clientEntryDiscovery";
20
+ import { RouteClientBuilder } from "../frontendBuild/routeClientBuilder";
21
21
  import type { BatchWork, BuildBatchRequest, BuildBatchResult, OptimizedFonts } from "./buildBatchProtocol";
22
22
  import { BuildBatchRunner } from "./buildBatchRunner";
23
23
  import { BuilderBoot, type IncrementalBuilderOptions } from "./builderBoot";
@@ -381,6 +381,7 @@ class IncrementalBuilder {
381
381
  const initialGeneration = BuilderBoot.initialGeneration();
382
382
  try {
383
383
  const deps = await BuilderBoot.buildBootDeps(app, bootRunner);
384
+ BuilderChannel.emit({ type: "base-built", phaseMs: deps.basePhaseMs });
384
385
  builder = new IncrementalBuilder({ app, watch, initialGeneration, ...deps });
385
386
  } catch (err) {
386
387
  if (!watch) throw err;
@@ -1,14 +1,14 @@
1
1
  import { rm } from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { ApplicationBuildReporter } from "@akanjs/devkit/app/applicationBuildReporter";
4
- import type { App } from "@akanjs/devkit/commandDecorators";
5
- import type { ClientEntryDiscovery } from "@akanjs/devkit/frontendBuild/clientBuildTypes";
6
- import { CsrDevPatcher } from "@akanjs/devkit/frontendBuild/csrDevPatcher";
7
- import { ServerGraphFile } from "@akanjs/devkit/frontendBuild/serverGraphFile";
8
- import { SsrDevBundler } from "@akanjs/devkit/frontendBuild/ssrDevBundler";
9
3
  import type { Logger } from "akanjs/common";
10
4
  import type { HmrTrace } from "akanjs/server";
11
5
  import { CSR_DEV_PATCHING_MARKER } from "akanjs/server/hmr/csrDevManifest";
6
+ import { ApplicationBuildReporter } from "../app/applicationBuildReporter";
7
+ import type { App } from "../commandDecorators";
8
+ import type { ClientEntryDiscovery } from "../frontendBuild/clientBuildTypes";
9
+ import { CsrDevPatcher } from "../frontendBuild/csrDevPatcher";
10
+ import { ServerGraphFile } from "../frontendBuild/serverGraphFile";
11
+ import { SsrDevBundler } from "../frontendBuild/ssrDevBundler";
12
12
  import type { BatchWork, BuildBatchResult } from "./buildBatchProtocol";
13
13
  import { isCompileError, sendBuildStatus } from "./builderBuildStatus";
14
14
  import { BuilderChannel } from "./builderChannel";
package/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // XXX: types only. A value import from this barrel loads every facet (ink, typescript, ssh2, …) into the process;
2
- // `export type *` erases at runtime. Import values from the owning facet (`@akanjs/devkit/util/fileSys`) and never
2
+ // `export type *` erases at runtime. Import values from the owning facet (`@akanjs/devkit/frontendBuild`) and never
3
3
  // "fix" a TS1362 by widening an entry back to `export *`.
4
4
  export type * from "./akanApp";
5
5
  export type * from "./akanConfig";
@@ -0,0 +1,99 @@
1
+ import { afterEach, describe, expect, test } from "bun:test";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import { RenderAdmissionSoak } from "./renderAdmissionSoak";
6
+
7
+ const roots: string[] = [];
8
+
9
+ const workspace = () => {
10
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), "akan-soak-"));
11
+ roots.push(root);
12
+ fs.mkdirSync(path.join(root, "apps", "shop", "page"), { recursive: true });
13
+ return { root, pageDir: RenderAdmissionSoak.pageDirOf(root, "shop") };
14
+ };
15
+
16
+ const until = async (check: () => boolean, what: string) => {
17
+ const deadline = Date.now() + 20_000;
18
+ while (!check()) {
19
+ if (Date.now() > deadline) throw new Error(`timed out waiting for ${what}`);
20
+ await Bun.sleep(20);
21
+ }
22
+ };
23
+
24
+ afterEach(() => {
25
+ for (const root of roots.splice(0)) fs.rmSync(root, { recursive: true, force: true });
26
+ });
27
+
28
+ describe("RenderAdmissionSoak page", () => {
29
+ test("refuses a `page/soak` the app already has, and leaves it as it was", () => {
30
+ const { pageDir } = workspace();
31
+ fs.mkdirSync(pageDir);
32
+ fs.writeFileSync(path.join(pageDir, "_index.tsx"), "export default null;");
33
+
34
+ expect(() => RenderAdmissionSoak.injectPage(pageDir)).toThrow("this script did not create it");
35
+ expect(fs.readdirSync(pageDir)).toEqual(["_index.tsx"]);
36
+ RenderAdmissionSoak.removePage(pageDir);
37
+ expect(fs.readdirSync(pageDir)).toEqual(["_index.tsx"]);
38
+ });
39
+
40
+ test("removes only what it wrote, and the directory only when nothing else is left in it", () => {
41
+ const { pageDir } = workspace();
42
+ RenderAdmissionSoak.injectPage(pageDir);
43
+ expect(fs.readdirSync(pageDir).sort()).toEqual([".render-admission-soak.json", "io.tsx"]);
44
+ fs.writeFileSync(path.join(pageDir, "notes.tsx"), "export default null;");
45
+
46
+ RenderAdmissionSoak.removePage(pageDir);
47
+ expect(fs.readdirSync(pageDir)).toEqual(["notes.tsx"]);
48
+
49
+ const fresh = workspace().pageDir;
50
+ RenderAdmissionSoak.injectPage(fresh);
51
+ RenderAdmissionSoak.removePage(fresh);
52
+ expect(fs.existsSync(fresh)).toBe(false);
53
+ });
54
+
55
+ test("takes over the page an earlier run of its own left behind", () => {
56
+ const { pageDir } = workspace();
57
+ RenderAdmissionSoak.injectPage(pageDir);
58
+ fs.writeFileSync(path.join(pageDir, "io.tsx"), "stale");
59
+
60
+ RenderAdmissionSoak.injectPage(pageDir);
61
+ expect(fs.readFileSync(path.join(pageDir, "io.tsx"), "utf8")).toContain("akanjs/client");
62
+ });
63
+
64
+ test("a soak stopped while it builds removes its page and stops the build", async () => {
65
+ const { root, pageDir } = workspace();
66
+ const cli = path.join(root, "cli.ts");
67
+ const started = path.join(root, "build.pid");
68
+ fs.writeFileSync(
69
+ cli,
70
+ `await Bun.write(${JSON.stringify(started)}, String(process.pid));\nawait Bun.sleep(60_000);\n`,
71
+ );
72
+ const soak = Bun.spawn(
73
+ [
74
+ "bun",
75
+ path.join(import.meta.dir, "renderAdmissionSoak.ts"),
76
+ "shop",
77
+ "--prepare",
78
+ `--root=${root}`,
79
+ `--cli=${cli}`,
80
+ ],
81
+ { stdout: "ignore", stderr: "ignore" },
82
+ );
83
+ await until(() => fs.existsSync(started), "the build to start");
84
+ expect(fs.existsSync(path.join(pageDir, "io.tsx"))).toBe(true);
85
+ const buildPid = Number(fs.readFileSync(started, "utf8"));
86
+
87
+ soak.kill("SIGTERM");
88
+ expect(await soak.exited).toBe(130);
89
+ expect(fs.existsSync(pageDir)).toBe(false);
90
+ await until(() => {
91
+ try {
92
+ process.kill(buildPid, 0);
93
+ return false;
94
+ } catch {
95
+ return true;
96
+ }
97
+ }, "the build to stop");
98
+ }, 30_000);
99
+ });