@akanjs/devkit 3.2.0-rc.18 → 3.2.0-rc.19
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/CHANGELOG.md +44 -4
- package/DEV_RUNTIME_KNOBS.md +4 -3
- package/akanApp/akanApp.host.test.ts +18 -2
- package/akanApp/akanApp.host.wiring.test.ts +723 -0
- package/akanApp/devIdleSuspend.test.ts +107 -20
- package/akanApp/devIdleSuspend.ts +31 -14
- package/akanApp/devIdleSuspend.watcher.test.ts +77 -0
- package/apiReport/apiReport.test.ts +29 -0
- package/apiReport/apiReportDiff.ts +35 -1
- package/app/applicationBuildReporter.ts +2 -49
- package/artifact/implicitRootLayoutRender.test.tsx +23 -3
- package/codeAgent/agent/akanSystemPrompt.ts +1 -1
- package/codeAgent/skills/akan-scaffold/SKILL.md +1 -1
- package/commandDecorators/command.ts +2 -1
- package/commandDecorators/commandBuilder.ts +1 -1
- package/commandDecorators/commandDecorators.test.ts +28 -4
- package/context/akanContext.ts +20 -527
- package/context/akanContextInspection.ts +296 -0
- package/context/akanMcpContract.ts +13 -253
- package/context/doctor/agentGuideCheck.ts +81 -0
- package/context/doctor/configLeftoverCheck.ts +35 -0
- package/context/doctor/doctorFindings.ts +70 -0
- package/context/doctor/generatedFreshness.ts +56 -0
- package/context/doctor/moduleShapeCheck.ts +88 -0
- package/context/doctor/recipeDuplicateCheck.ts +39 -0
- package/context/doctor/recipeIndexCheck.ts +87 -0
- package/context/doctor/rootShapeCheck.ts +55 -0
- package/context/doctor/workflowScope.ts +97 -0
- package/context/safeRead.ts +9 -0
- package/devkitUtils.test.ts +34 -0
- package/executors/executors.test.ts +1 -4
- package/executors/workspaceExecutor.ts +1 -2
- package/frontendBuild/hmrWatcher.stop.test.ts +36 -0
- package/frontendBuild/hmrWatcher.ts +2 -0
- package/incrementalBuilder/buildBatch.proc.ts +13 -3
- package/incrementalBuilder/buildBatchProtocol.ts +2 -0
- package/incrementalBuilder/buildBatchRunner.test.ts +61 -0
- package/incrementalBuilder/buildBatchRunner.ts +6 -3
- package/incrementalBuilder/builderBoot.ts +106 -0
- package/incrementalBuilder/builderBuildStatus.ts +23 -0
- package/incrementalBuilder/builderChannel.ts +11 -0
- package/incrementalBuilder/builderLanes.ts +157 -0
- package/incrementalBuilder/builderWatch.ts +213 -0
- package/incrementalBuilder/csrRegistry.ts +234 -0
- package/incrementalBuilder/incrementalBuilder.proc.test.ts +92 -1
- package/incrementalBuilder/incrementalBuilder.proc.ts +80 -822
- package/incrementalBuilder/ssrRegistry.ts +278 -0
- package/integration/devStability.integration.test.ts +62 -56
- package/package.json +3 -3
- package/test/testHelpers.ts +36 -0
- package/util/errorReport.ts +66 -0
- package/workflow/constantSource.ts +187 -0
- package/workflow/dictionarySource.ts +184 -0
- package/workflow/executor.ts +5 -8
- package/workflow/fieldExpression.ts +153 -0
- package/workflow/fieldLabel.ts +61 -0
- package/workflow/fieldOrder.ts +117 -0
- package/workflow/fieldType.ts +2 -1
- package/workflow/keyRename.ts +1 -1
- package/workflow/moduleIndex.ts +1 -1
- package/workflow/modulePaths.ts +27 -0
- package/workflow/mutationScaffold.ts +7 -15
- package/workflow/mutationSource.ts +2 -1
- package/workflow/plan.ts +2 -1
- package/workflow/primitiveReport.ts +78 -0
- package/workflow/serviceSource.ts +33 -0
- package/workflow/signalSource.ts +96 -0
- package/workflow/source.ts +50 -1100
- package/workflow/sourceAst.ts +30 -0
- package/workflow/sourceImports.ts +105 -0
- package/workflow/sourceText.ts +13 -0
- package/workflow/templateSource.ts +30 -0
- package/workflow/testSource.ts +31 -0
- package/workflow/types.ts +1 -1
- package/workflow/uiPolicy.ts +1 -1
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
|
|
2
2
|
import type { Logger } from "akanjs/common";
|
|
3
|
+
import type { BuilderMessage } from "akanjs/server";
|
|
3
4
|
import type { App } from "../commandDecorators";
|
|
5
|
+
import type { IncrementalBuilderHost } from "../incrementalBuilder";
|
|
6
|
+
import { BuilderRequestRelay } from "./builderRequestRelay";
|
|
4
7
|
|
|
5
|
-
const watchers: { stopped: number }[] = [];
|
|
6
|
-
|
|
8
|
+
const watchers: { stopped: number; started: PromiseWithResolvers<void> }[] = [];
|
|
9
|
+
const releaseStart = () => watchers.at(-1)?.started.resolve();
|
|
7
10
|
|
|
8
11
|
mock.module("../frontendBuild/watchRootResolver", () => ({
|
|
9
12
|
WatchRootResolver: class {
|
|
@@ -14,14 +17,12 @@ mock.module("../frontendBuild/watchRootResolver", () => ({
|
|
|
14
17
|
}));
|
|
15
18
|
mock.module("../frontendBuild/hmrWatcher", () => ({
|
|
16
19
|
HmrWatcher: class {
|
|
17
|
-
readonly #record = { stopped: 0 };
|
|
20
|
+
readonly #record = { stopped: 0, started: Promise.withResolvers<void>() };
|
|
18
21
|
constructor() {
|
|
19
22
|
watchers.push(this.#record);
|
|
20
23
|
}
|
|
21
24
|
start() {
|
|
22
|
-
return
|
|
23
|
-
releaseStart = resolve;
|
|
24
|
-
});
|
|
25
|
+
return this.#record.started.promise;
|
|
25
26
|
}
|
|
26
27
|
stop() {
|
|
27
28
|
this.#record.stopped++;
|
|
@@ -36,6 +37,7 @@ const tick = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
|
36
37
|
|
|
37
38
|
const suspendOf = () => {
|
|
38
39
|
const calls = { readiness: 0, release: 0, wake: 0, awake: 0 };
|
|
40
|
+
const readiness = { builderReady: true, backendReady: true, buildFailed: false, restartPending: false };
|
|
39
41
|
let finishWake: () => void = () => undefined;
|
|
40
42
|
const idle = new DevIdleSuspend(
|
|
41
43
|
{} as App,
|
|
@@ -43,7 +45,7 @@ const suspendOf = () => {
|
|
|
43
45
|
{
|
|
44
46
|
readiness: () => {
|
|
45
47
|
calls.readiness++;
|
|
46
|
-
return {
|
|
48
|
+
return { ...readiness };
|
|
47
49
|
},
|
|
48
50
|
release: () => {
|
|
49
51
|
calls.release++;
|
|
@@ -61,21 +63,21 @@ const suspendOf = () => {
|
|
|
61
63
|
},
|
|
62
64
|
},
|
|
63
65
|
);
|
|
64
|
-
return { idle, calls, finishWake: () => finishWake() };
|
|
66
|
+
return { idle, calls, readiness, finishWake: () => finishWake() };
|
|
65
67
|
};
|
|
66
68
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
69
|
+
let previous: string | undefined;
|
|
70
|
+
beforeEach(() => {
|
|
71
|
+
previous = process.env.AKAN_DEV_IDLE_SUSPEND_MS;
|
|
72
|
+
process.env.AKAN_DEV_IDLE_SUSPEND_MS = "5";
|
|
73
|
+
watchers.length = 0;
|
|
74
|
+
});
|
|
75
|
+
afterEach(() => {
|
|
76
|
+
if (previous === undefined) delete process.env.AKAN_DEV_IDLE_SUSPEND_MS;
|
|
77
|
+
else process.env.AKAN_DEV_IDLE_SUSPEND_MS = previous;
|
|
78
|
+
});
|
|
78
79
|
|
|
80
|
+
describe("DevIdleSuspend after stop", () => {
|
|
79
81
|
test("stops a watcher that finished starting after the host stopped, and suspends nothing", async () => {
|
|
80
82
|
const { idle, calls } = suspendOf();
|
|
81
83
|
idle.arm();
|
|
@@ -102,7 +104,7 @@ describe("DevIdleSuspend after stop", () => {
|
|
|
102
104
|
await woken;
|
|
103
105
|
await tick(20);
|
|
104
106
|
expect(calls.awake).toBe(0);
|
|
105
|
-
expect(calls.readiness).toBe(
|
|
107
|
+
expect(calls.readiness).toBe(2);
|
|
106
108
|
});
|
|
107
109
|
|
|
108
110
|
test("a suspended host stops being away once stopped, so a late request is refused instead of held", async () => {
|
|
@@ -128,3 +130,88 @@ describe("DevIdleSuspend after stop", () => {
|
|
|
128
130
|
expect(calls.readiness).toBe(0);
|
|
129
131
|
});
|
|
130
132
|
});
|
|
133
|
+
|
|
134
|
+
describe("DevIdleSuspend while the idle watcher starts", () => {
|
|
135
|
+
const suspendOnNextIdle = async (calls: { release: number }) => {
|
|
136
|
+
await tick(20);
|
|
137
|
+
expect(watchers).toHaveLength(2);
|
|
138
|
+
releaseStart();
|
|
139
|
+
await tick(0);
|
|
140
|
+
expect(calls.release).toBe(1);
|
|
141
|
+
expect(watchers[1].stopped).toBe(0);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
test("a builder request that lands meanwhile keeps the builder, and a later idle period still suspends", async () => {
|
|
145
|
+
const { idle, calls } = suspendOf();
|
|
146
|
+
const sent: BuilderMessage[] = [];
|
|
147
|
+
const builder = {
|
|
148
|
+
status: "ready",
|
|
149
|
+
send: (message: BuilderMessage) => {
|
|
150
|
+
sent.push(message);
|
|
151
|
+
return true;
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
const relay = new BuilderRequestRelay(
|
|
155
|
+
{ logger: logger as unknown as Logger, env: {} },
|
|
156
|
+
{
|
|
157
|
+
builder: () => builder as unknown as IncrementalBuilderHost,
|
|
158
|
+
toBackend: () => undefined,
|
|
159
|
+
markActivity: () => idle.markActivity(),
|
|
160
|
+
away: () => idle.away,
|
|
161
|
+
wake: (reason) => void idle.wake(reason),
|
|
162
|
+
},
|
|
163
|
+
);
|
|
164
|
+
idle.arm();
|
|
165
|
+
await tick(20);
|
|
166
|
+
expect(watchers).toHaveLength(1);
|
|
167
|
+
relay.send({ type: "build-graph", id: 1 } as BuilderMessage);
|
|
168
|
+
releaseStart();
|
|
169
|
+
await tick(0);
|
|
170
|
+
expect(sent).toHaveLength(1);
|
|
171
|
+
expect(calls.release).toBe(0);
|
|
172
|
+
expect(watchers[0].stopped).toBe(1);
|
|
173
|
+
await suspendOnNextIdle(calls);
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("a backend that went down meanwhile keeps the builder", async () => {
|
|
177
|
+
const { idle, calls, readiness } = suspendOf();
|
|
178
|
+
idle.arm();
|
|
179
|
+
await tick(20);
|
|
180
|
+
readiness.backendReady = false;
|
|
181
|
+
releaseStart();
|
|
182
|
+
await tick(0);
|
|
183
|
+
expect(calls.release).toBe(0);
|
|
184
|
+
expect(watchers[0].stopped).toBe(1);
|
|
185
|
+
readiness.backendReady = true;
|
|
186
|
+
await suspendOnNextIdle(calls);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test("a stop that lands as the start settles stops that watcher and releases nothing", async () => {
|
|
190
|
+
const { idle, calls } = suspendOf();
|
|
191
|
+
idle.arm();
|
|
192
|
+
await tick(20);
|
|
193
|
+
//? Queued behind the start's own await, so the stop lands after the start settles and before the suspend resumes.
|
|
194
|
+
void watchers[0].started.promise.then(() => idle.stop());
|
|
195
|
+
releaseStart();
|
|
196
|
+
await tick(0);
|
|
197
|
+
expect(calls.release).toBe(0);
|
|
198
|
+
expect(watchers[0].stopped).toBe(1);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("a watcher that fails to start stops only itself, not the one a later suspend committed", async () => {
|
|
202
|
+
const { idle, calls } = suspendOf();
|
|
203
|
+
idle.arm();
|
|
204
|
+
await tick(20);
|
|
205
|
+
idle.markActivity();
|
|
206
|
+
await tick(20);
|
|
207
|
+
expect(watchers).toHaveLength(2);
|
|
208
|
+
releaseStart();
|
|
209
|
+
await tick(0);
|
|
210
|
+
expect(calls.release).toBe(1);
|
|
211
|
+
watchers[0].started.reject(new Error("no watch roots"));
|
|
212
|
+
await tick(0);
|
|
213
|
+
expect(watchers[0].stopped).toBe(1);
|
|
214
|
+
expect(watchers[1].stopped).toBe(0);
|
|
215
|
+
idle.stop();
|
|
216
|
+
});
|
|
217
|
+
});
|
|
@@ -4,7 +4,7 @@ import type { App } from "../commandDecorators";
|
|
|
4
4
|
// Not via `../frontendBuild`: that barrel loads typescript and tailwind, which a suspended dev host must not hold.
|
|
5
5
|
import { HmrWatcher } from "../frontendBuild/hmrWatcher";
|
|
6
6
|
import { WatchRootResolver } from "../frontendBuild/watchRootResolver";
|
|
7
|
-
import { decideIdleSuspend, resolveIdleSuspendMs } from "./devHostPolicy";
|
|
7
|
+
import { decideIdleSuspend, type IdleSuspendDecision, resolveIdleSuspendMs } from "./devHostPolicy";
|
|
8
8
|
|
|
9
9
|
interface DevIdleSuspendLinks {
|
|
10
10
|
readiness: () => { builderReady: boolean; backendReady: boolean; buildFailed: boolean; restartPending: boolean };
|
|
@@ -23,6 +23,7 @@ export class DevIdleSuspend {
|
|
|
23
23
|
#suspended = false;
|
|
24
24
|
#waking = false;
|
|
25
25
|
#stopped = false;
|
|
26
|
+
#activity = 0;
|
|
26
27
|
#wokeAtMono: number | null = null;
|
|
27
28
|
#watcher: HmrWatcher | null = null;
|
|
28
29
|
#suspendedChanges: ChangeBatch | null = null;
|
|
@@ -42,6 +43,7 @@ export class DevIdleSuspend {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
markActivity(): void {
|
|
46
|
+
this.#activity++;
|
|
45
47
|
if (this.#suspended || this.#waking) return;
|
|
46
48
|
this.arm();
|
|
47
49
|
}
|
|
@@ -103,23 +105,42 @@ export class DevIdleSuspend {
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
+
#decide(): IdleSuspendDecision {
|
|
109
|
+
return decideIdleSuspend({
|
|
108
110
|
enabled: true,
|
|
109
111
|
suspended: this.#suspended,
|
|
110
112
|
...this.#links.readiness(),
|
|
111
113
|
msSinceWake: this.#wokeAtMono === null ? null : performance.now() - this.#wokeAtMono,
|
|
112
114
|
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async #suspendWhenIdle(idleMs: number): Promise<void> {
|
|
118
|
+
const decision = this.#decide();
|
|
113
119
|
if (decision !== "suspend") {
|
|
114
120
|
this.#logger.verbose(`[idle-suspend] skipped (${decision}); re-arming`);
|
|
115
121
|
this.arm();
|
|
116
122
|
return;
|
|
117
123
|
}
|
|
124
|
+
const activity = this.#activity;
|
|
118
125
|
// Watch before stopping: an edit in the gap would be lost, and nothing would wake the dev server.
|
|
119
|
-
|
|
126
|
+
const watcher = await this.#startWatcher();
|
|
127
|
+
if (!watcher) {
|
|
128
|
+
this.arm();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (this.#stopped) {
|
|
132
|
+
watcher.stop();
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
//? Decided again: a request or builder message that marked activity meanwhile is on the awake builder.
|
|
136
|
+
const recheck = this.#activity === activity ? this.#decide() : "busy";
|
|
137
|
+
if (recheck !== "suspend") {
|
|
138
|
+
this.#logger.verbose(`[idle-suspend] skipped (${recheck} while the idle watcher started); re-arming`);
|
|
139
|
+
watcher.stop();
|
|
120
140
|
this.arm();
|
|
121
141
|
return;
|
|
122
142
|
}
|
|
143
|
+
this.#watcher = watcher;
|
|
123
144
|
this.#suspended = true;
|
|
124
145
|
this.#links.release(`idle ${Math.round(idleMs / 1000)}s`);
|
|
125
146
|
this.#logger.info(
|
|
@@ -127,10 +148,11 @@ export class DevIdleSuspend {
|
|
|
127
148
|
);
|
|
128
149
|
}
|
|
129
150
|
|
|
130
|
-
async #startWatcher(): Promise<
|
|
151
|
+
async #startWatcher(): Promise<HmrWatcher | null> {
|
|
152
|
+
let watcher: HmrWatcher | null = null;
|
|
131
153
|
try {
|
|
132
154
|
const roots = await new WatchRootResolver(this.#app).resolve();
|
|
133
|
-
|
|
155
|
+
watcher = new HmrWatcher({
|
|
134
156
|
roots,
|
|
135
157
|
logger: this.#logger,
|
|
136
158
|
onBatch: (batch) => {
|
|
@@ -140,18 +162,13 @@ export class DevIdleSuspend {
|
|
|
140
162
|
});
|
|
141
163
|
// Awaited so the mtime baseline exists before the first edit; a file missing from the batch is never rebuilt.
|
|
142
164
|
await watcher.start();
|
|
143
|
-
|
|
144
|
-
watcher.stop();
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
this.#watcher = watcher;
|
|
148
|
-
return true;
|
|
165
|
+
return watcher;
|
|
149
166
|
} catch (err) {
|
|
150
167
|
this.#logger.warn(
|
|
151
168
|
`[idle-suspend] could not install the idle watcher; staying awake: ${err instanceof Error ? err.message : String(err)}`,
|
|
152
169
|
);
|
|
153
|
-
|
|
154
|
-
return
|
|
170
|
+
watcher?.stop();
|
|
171
|
+
return null;
|
|
155
172
|
}
|
|
156
173
|
}
|
|
157
174
|
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { afterEach, beforeEach, expect, mock, test } from "bun:test";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import type { Logger } from "akanjs/common";
|
|
4
|
+
import type { ChangeBatch } from "akanjs/server";
|
|
5
|
+
import type { App } from "../commandDecorators";
|
|
6
|
+
import { heldMtimeIndex, saveUntil, tempDirs, writeText } from "../test/testHelpers";
|
|
7
|
+
|
|
8
|
+
const held = heldMtimeIndex();
|
|
9
|
+
let root = "";
|
|
10
|
+
mock.module("../frontendBuild/sourceMtimeIndex", () => ({ SourceMtimeIndex: held.SourceMtimeIndex }));
|
|
11
|
+
mock.module("../frontendBuild/watchRootResolver", () => ({
|
|
12
|
+
WatchRootResolver: class {
|
|
13
|
+
async resolve() {
|
|
14
|
+
return [root];
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const { DevIdleSuspend } = await import("./devIdleSuspend");
|
|
20
|
+
|
|
21
|
+
const logger = {
|
|
22
|
+
info: () => undefined,
|
|
23
|
+
verbose: () => undefined,
|
|
24
|
+
warn: () => undefined,
|
|
25
|
+
error: () => undefined,
|
|
26
|
+
} as unknown as Logger;
|
|
27
|
+
const tick = (ms = 0) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
28
|
+
const makeRoot = tempDirs("akan-idle-suspend-watcher-");
|
|
29
|
+
|
|
30
|
+
let previous: string | undefined;
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
previous = process.env.AKAN_DEV_IDLE_SUSPEND_MS;
|
|
33
|
+
process.env.AKAN_DEV_IDLE_SUSPEND_MS = "5";
|
|
34
|
+
});
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
if (previous === undefined) delete process.env.AKAN_DEV_IDLE_SUSPEND_MS;
|
|
37
|
+
else process.env.AKAN_DEV_IDLE_SUSPEND_MS = previous;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("a save while the idle watcher primes stays with the awake builder, and the next wake does not replay it", async () => {
|
|
41
|
+
root = await makeRoot();
|
|
42
|
+
const source = path.join(root, "lib/a.ts");
|
|
43
|
+
await writeText(source, "export const x = 0;\n");
|
|
44
|
+
let released = 0;
|
|
45
|
+
const wokenWith: (ChangeBatch | null)[] = [];
|
|
46
|
+
const idle = new DevIdleSuspend(
|
|
47
|
+
{} as App,
|
|
48
|
+
{ logger },
|
|
49
|
+
{
|
|
50
|
+
readiness: () => ({ builderReady: true, backendReady: true, buildFailed: false, restartPending: false }),
|
|
51
|
+
release: () => {
|
|
52
|
+
released++;
|
|
53
|
+
},
|
|
54
|
+
wake: async (batch) => {
|
|
55
|
+
wokenWith.push(batch);
|
|
56
|
+
},
|
|
57
|
+
wakeFailed: () => undefined,
|
|
58
|
+
flushHeld: () => undefined,
|
|
59
|
+
awake: () => undefined,
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
idle.arm();
|
|
63
|
+
expect(await saveUntil(source, () => held.scans.length > 0)).toBe(true);
|
|
64
|
+
idle.markActivity();
|
|
65
|
+
held.primes[0].resolve();
|
|
66
|
+
await tick();
|
|
67
|
+
expect(released).toBe(0);
|
|
68
|
+
held.scans[0].resolve([]);
|
|
69
|
+
await tick(20);
|
|
70
|
+
expect(held.primes).toHaveLength(2);
|
|
71
|
+
held.primes[1].resolve();
|
|
72
|
+
await tick();
|
|
73
|
+
expect(released).toBe(1);
|
|
74
|
+
await idle.wake("a route request");
|
|
75
|
+
expect(wokenWith).toEqual([null]);
|
|
76
|
+
idle.stop();
|
|
77
|
+
}, 15_000);
|
|
@@ -383,6 +383,35 @@ describe("ApiReportDiff", () => {
|
|
|
383
383
|
{ report: "demo.old.api.md", name: "Old", kind: "removed", before: "export type Old = string;" },
|
|
384
384
|
]);
|
|
385
385
|
});
|
|
386
|
+
test("reads a union or an object type whose members only moved as the same declaration", () => {
|
|
387
|
+
const recipe = (first: string, second: string, sizes: string) =>
|
|
388
|
+
reportOf([
|
|
389
|
+
`export declare const recipe: (variants?: Omit<({\n size?: ${sizes} | undefined;\n ${first}\n ${second}\n} & {\n class?: string;\n}), "class">) => string;`,
|
|
390
|
+
]);
|
|
391
|
+
const before = new Map([["demo.api.md", recipe("variant?: boolean;", "outline?: boolean;", '"lg" | "sm"')]]);
|
|
392
|
+
const moved = new Map([["demo.api.md", recipe("outline?: boolean;", "variant?: boolean;", '"sm" | "lg"')]]);
|
|
393
|
+
const retyped = new Map([["demo.api.md", recipe("outline?: boolean;", "variant?: string;", '"sm" | "lg"')]]);
|
|
394
|
+
expect(ApiReportDiff.breaks(before, moved)).toEqual([]);
|
|
395
|
+
expect(ApiReportDiff.breaks(before, retyped).map(({ name, kind }) => `${kind} ${name}`)).toEqual([
|
|
396
|
+
"changed recipe",
|
|
397
|
+
]);
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
test("compares a block that fails to parse as text, since parser recovery can drop what differs", () => {
|
|
401
|
+
const broken = (member: string) =>
|
|
402
|
+
new Map([["demo.api.md", reportOf([`export type T = {\n a: 1;\n @@@ ${member}\n};`])]]);
|
|
403
|
+
expect(ApiReportDiff.breaks(broken("b: 2;"), broken("c: 2;")).map(({ name, kind }) => `${kind} ${name}`)).toEqual([
|
|
404
|
+
"changed T",
|
|
405
|
+
]);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test("still reads reordered overloads as a change, since their order picks the signature", () => {
|
|
409
|
+
const overloads = (first: string, second: string) =>
|
|
410
|
+
new Map([["demo.api.md", reportOf([`export declare const on: {\n ${first}\n ${second}\n};`])]]);
|
|
411
|
+
const before = overloads("(value: string): string;", "(value: number): number;");
|
|
412
|
+
const after = overloads("(value: number): number;", "(value: string): string;");
|
|
413
|
+
expect(ApiReportDiff.breaks(before, after).map(({ name, kind }) => `${kind} ${name}`)).toEqual(["changed on"]);
|
|
414
|
+
});
|
|
386
415
|
});
|
|
387
416
|
|
|
388
417
|
describe("ChangesetBump", () => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
1
2
|
import { ApiReport } from "./apiReport";
|
|
2
3
|
|
|
3
4
|
export interface ApiBreak {
|
|
@@ -22,6 +23,7 @@ export class ApiReportDiff {
|
|
|
22
23
|
static readonly #reexportPattern = /^export \{ (\S+)(?: as (\S+))? \} from /;
|
|
23
24
|
static readonly #namespaceReexportPattern = /^export \* as (\S+) from /;
|
|
24
25
|
static readonly #tagLine = /^\/\*\* (?:@\w+ ?)+\*\/$/;
|
|
26
|
+
static readonly #printer = ts.createPrinter({ removeComments: true, newLine: ts.NewLineKind.LineFeed });
|
|
25
27
|
static readonly #subpathPattern = /^- `(\S+)`$/gm;
|
|
26
28
|
static readonly #referencedSuffix = " (referenced)";
|
|
27
29
|
static readonly #referencedMark = " (referenced";
|
|
@@ -113,7 +115,39 @@ export class ApiReportDiff {
|
|
|
113
115
|
}
|
|
114
116
|
|
|
115
117
|
static #sameDeclaration(a: string, b: string) {
|
|
116
|
-
|
|
118
|
+
const [left, right] = [ApiReportDiff.#declarationOf(a), ApiReportDiff.#declarationOf(b)];
|
|
119
|
+
return left === right || ApiReportDiff.#unorderedOf(left) === ApiReportDiff.#unorderedOf(right);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
//? The checker orders union members and mapped keys by first sight, so checking files in another order moves them.
|
|
123
|
+
static #unorderedOf(declaration: string) {
|
|
124
|
+
const source = ts.createSourceFile("block.d.ts", declaration, ts.ScriptTarget.Latest, false, ts.ScriptKind.TS);
|
|
125
|
+
//? `parseDiagnostics` is internal: parser recovery can drop tokens, so a block that failed to parse stays as text.
|
|
126
|
+
if ("parseDiagnostics" in source && Array.isArray(source.parseDiagnostics) && source.parseDiagnostics.length)
|
|
127
|
+
return declaration;
|
|
128
|
+
const textOf = (node: ts.Node) => ApiReportDiff.#printer.printNode(ts.EmitHint.Unspecified, node, source);
|
|
129
|
+
const byText = (a: ts.Node, b: ts.Node) => ApiReport.compare(textOf(a), textOf(b));
|
|
130
|
+
const byName = (a: ts.TypeElement, b: ts.TypeElement) =>
|
|
131
|
+
ApiReport.compare(a.name ? textOf(a.name) : "", b.name ? textOf(b.name) : "");
|
|
132
|
+
const sortMembers: ts.TransformerFactory<ts.SourceFile> = (context) => {
|
|
133
|
+
const visit = (node: ts.Node): ts.Node => {
|
|
134
|
+
const next = ts.visitEachChild(node, visit, context);
|
|
135
|
+
if (ts.isUnionTypeNode(next))
|
|
136
|
+
return context.factory.updateUnionTypeNode(
|
|
137
|
+
next,
|
|
138
|
+
context.factory.createNodeArray([...next.types].sort(byText)),
|
|
139
|
+
);
|
|
140
|
+
if (ts.isTypeLiteralNode(next))
|
|
141
|
+
return context.factory.updateTypeLiteralNode(
|
|
142
|
+
next,
|
|
143
|
+
context.factory.createNodeArray([...next.members].sort(byName)),
|
|
144
|
+
);
|
|
145
|
+
return next;
|
|
146
|
+
};
|
|
147
|
+
return (file) => ts.visitEachChild(file, visit, context);
|
|
148
|
+
};
|
|
149
|
+
const [sorted = source] = ts.transform(source, [sortMembers]).transformed;
|
|
150
|
+
return ApiReportDiff.#printer.printFile(sorted);
|
|
117
151
|
}
|
|
118
152
|
|
|
119
153
|
static #declarationOf(block: string) {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { realpathSync } from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
1
|
import { Logger } from "akanjs/common";
|
|
2
|
+
import { ErrorReport } from "../util/errorReport";
|
|
4
3
|
import { RouteJsBudget, type RouteJsBudgetWarning, type RouteJsSize } from "./routeJsBudget";
|
|
5
4
|
|
|
6
5
|
export interface ApplicationBuildPhaseResult {
|
|
@@ -58,53 +57,7 @@ export class ApplicationBuildReporter {
|
|
|
58
57
|
"Built for local: the server runs without endpoint rate limits, and boots on local defaults (Redis on localhost, the first database mode) where a deployment would stop to ask. For a host others can reach, run `akan build <app> --env main` with AKAN_PUBLIC_REPO_NAME and AKAN_PUBLIC_SERVE_DOMAIN set in the shell or the workspace .env.";
|
|
59
58
|
|
|
60
59
|
static formatError(error: unknown, workspaceRoot = process.cwd()): string {
|
|
61
|
-
|
|
62
|
-
const nestedMessages = error.errors
|
|
63
|
-
.map(
|
|
64
|
-
(nestedError, index) =>
|
|
65
|
-
ApplicationBuildReporter.formatError(nestedError, workspaceRoot).trim() || `Unknown error ${index + 1}`,
|
|
66
|
-
)
|
|
67
|
-
.map((message) => message.replace(/^/gm, " "))
|
|
68
|
-
.join("\n");
|
|
69
|
-
|
|
70
|
-
return nestedMessages ? `${error.message}\n${nestedMessages}` : error.message;
|
|
71
|
-
}
|
|
72
|
-
if (error instanceof Error) {
|
|
73
|
-
const causeMessage = error.cause
|
|
74
|
-
? `\nCaused by: ${ApplicationBuildReporter.formatError(error.cause, workspaceRoot)}`
|
|
75
|
-
: "";
|
|
76
|
-
return `${ApplicationBuildReporter.#withLocation(error.message, error, workspaceRoot)}${causeMessage}`;
|
|
77
|
-
}
|
|
78
|
-
if (typeof error === "object" && error !== null && "message" in error)
|
|
79
|
-
return ApplicationBuildReporter.#withLocation(String(error.message), error, workspaceRoot);
|
|
80
|
-
return String(error);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
static #withLocation(message: string, error: object, workspaceRoot: string): string {
|
|
84
|
-
const { position } = error as { position?: { file: string; line: number; column: number } | null };
|
|
85
|
-
if (!position?.file) return message;
|
|
86
|
-
const file = ApplicationBuildReporter.#relativeToWorkspace(position.file, workspaceRoot);
|
|
87
|
-
const location = position.line > 0 ? `${file}:${position.line}:${position.column}` : file;
|
|
88
|
-
return message.includes(location) ? message : message.replace(/^.*/, (headline) => `${headline} (${location})`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Bun names the file by its realpath, so a workspace root reached through a symlink is matched by its own too.
|
|
92
|
-
static #relativeToWorkspace(file: string, workspaceRoot: string): string {
|
|
93
|
-
if (!path.isAbsolute(file)) return file;
|
|
94
|
-
for (const root of [workspaceRoot, ApplicationBuildReporter.#realpathOf(workspaceRoot)]) {
|
|
95
|
-
const relative = path.relative(root, file);
|
|
96
|
-
if (!relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative))
|
|
97
|
-
return relative.replaceAll(path.sep, "/");
|
|
98
|
-
}
|
|
99
|
-
return file;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
static #realpathOf(dir: string): string {
|
|
103
|
-
try {
|
|
104
|
-
return realpathSync(dir);
|
|
105
|
-
} catch {
|
|
106
|
-
return dir;
|
|
107
|
-
}
|
|
60
|
+
return ErrorReport.format(error, workspaceRoot);
|
|
108
61
|
}
|
|
109
62
|
|
|
110
63
|
static formatDuration(ms: number): string {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, spyOn, test } from "bun:test";
|
|
2
|
-
import { mkdir, readdir, symlink } from "node:fs/promises";
|
|
2
|
+
import { mkdir, readdir, rm, symlink } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { Readable } from "node:stream";
|
|
5
5
|
import { act, Children, createElement, Fragment, isValidElement, type ReactElement, type ReactNode } from "react";
|
|
@@ -34,11 +34,12 @@ const idsLayoutSource = `import { rootLayout } from "akanjs/client";
|
|
|
34
34
|
import { UsesId } from "../usesId";
|
|
35
35
|
export default rootLayout().render(({ children }) => <section id="user"><UsesId />{children}</section>);
|
|
36
36
|
`;
|
|
37
|
+
//? Throws only once the test has read the shell's body, so the boundary streams pending whatever the payload's size.
|
|
37
38
|
const lateLayoutSource = `import { rootLayout } from "akanjs/client";
|
|
38
39
|
export default rootLayout()
|
|
39
40
|
.loading(() => <i>root loading</i>)
|
|
40
41
|
.render(async () => {
|
|
41
|
-
await Bun.sleep(
|
|
42
|
+
while (!(await Bun.file(process.env.AKAN_TEST_SHELL_READ ?? "").exists())) await Bun.sleep(5);
|
|
42
43
|
throw new Error("root layout broke");
|
|
43
44
|
});
|
|
44
45
|
`;
|
|
@@ -88,6 +89,21 @@ const clientReferenceIds = async (serverDir: string) => {
|
|
|
88
89
|
|
|
89
90
|
const ssrManifest: { moduleLoading: null; moduleMap: Record<string, unknown> } = { moduleLoading: null, moduleMap: {} };
|
|
90
91
|
|
|
92
|
+
const readHtml = async (stream: ReadableStream<Uint8Array>, onBody: () => Promise<unknown>) => {
|
|
93
|
+
const reader = stream.getReader();
|
|
94
|
+
const decoder = new TextDecoder();
|
|
95
|
+
let html = "";
|
|
96
|
+
let bodyRead = false;
|
|
97
|
+
for (;;) {
|
|
98
|
+
const { value, done } = await reader.read();
|
|
99
|
+
if (done) return html + decoder.decode();
|
|
100
|
+
html += decoder.decode(value, { stream: true });
|
|
101
|
+
if (bodyRead || !html.includes("<body")) continue;
|
|
102
|
+
bodyRead = true;
|
|
103
|
+
await onBody();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
91
107
|
interface Rendered {
|
|
92
108
|
html: string;
|
|
93
109
|
status: number;
|
|
@@ -125,6 +141,8 @@ const withBuiltPages = async (
|
|
|
125
141
|
return [id, { "*": { id: file, chunks: [file, file], name: "*" } }];
|
|
126
142
|
}),
|
|
127
143
|
);
|
|
144
|
+
const shellRead = path.join(root, "shell-read");
|
|
145
|
+
process.env.AKAN_TEST_SHELL_READ = shellRead;
|
|
128
146
|
const rsc = new RscWorker({
|
|
129
147
|
pagesBundlePath: bundlePath,
|
|
130
148
|
pagesBundleBuildId: 1,
|
|
@@ -145,11 +163,13 @@ const withBuiltPages = async (
|
|
|
145
163
|
ssrManifest,
|
|
146
164
|
lateControl: result.lateControl,
|
|
147
165
|
} as never);
|
|
148
|
-
const html = await
|
|
166
|
+
const html = await readHtml(stream, () => Bun.write(shellRead, ""));
|
|
167
|
+
await rm(shellRead, { force: true });
|
|
149
168
|
return { html, status: result.status ?? 200, payload: new Uint8Array(await payload) };
|
|
150
169
|
});
|
|
151
170
|
} finally {
|
|
152
171
|
rsc.kill();
|
|
172
|
+
delete process.env.AKAN_TEST_SHELL_READ;
|
|
153
173
|
}
|
|
154
174
|
};
|
|
155
175
|
|
|
@@ -41,7 +41,7 @@ export const akanSystemPrompt = (profile: CodeAgentProfile) => {
|
|
|
41
41
|
"## How to answer",
|
|
42
42
|
"",
|
|
43
43
|
"- Answer in as few words as carry the answer. A short question gets one sentence with no heading.",
|
|
44
|
-
"- Do not open with what you are about to do, and do not
|
|
44
|
+
"- Do not open with what you are about to do, and do not retell the tool calls at the end; they are already on the user's screen. A turn that changed files closes with those files and what `akan_verify` said.",
|
|
45
45
|
"- Skip headings, bold labels and bullet lists unless the answer is genuinely a list. Prose is shorter.",
|
|
46
46
|
"- State a file as `path:line`. Do not paste a file back that the user can open.",
|
|
47
47
|
"- Say what you could not do, and why, in one line. Do not offer alternatives nobody asked for.",
|
|
@@ -16,7 +16,7 @@ Everything else is pages, sections, and props.
|
|
|
16
16
|
- A page or section whose content you can write as static JSX or props is not an entity. "A self-intro page
|
|
17
17
|
with two detail pages" is pages only — no `profile` module.
|
|
18
18
|
- Never invent a supporting entity (profile, category, tag, author, like) to round out a design. If one looks
|
|
19
|
-
genuinely necessary, say
|
|
19
|
+
genuinely necessary, build the request without it and say in your reply why it may be needed; the user decides.
|
|
20
20
|
- "… plus a comment zone that saves to a database" is exactly one new module: `comment`.
|
|
21
21
|
- Check what exists first (`list_modules`) and extend it when it already fits — `add-field` / `add-slice` /
|
|
22
22
|
`create-ui` beat a whole new module.
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
type SysExecutor,
|
|
18
18
|
WorkspaceExecutor,
|
|
19
19
|
} from "../executors";
|
|
20
|
+
import { ErrorReport } from "../util/errorReport";
|
|
20
21
|
// Never the root barrel: it drags ink, ssh2 and the cloud stack into every command process.
|
|
21
22
|
import { FileSys, getDirname } from "../util/fileSys";
|
|
22
23
|
import { AppSelectionMemory } from "../workspace/appSelectionMemory";
|
|
@@ -57,7 +58,7 @@ const printCliError = (error: unknown, stream: "log" | "error" = "log") => {
|
|
|
57
58
|
if (loggedCliErrorObjects.has(error)) return;
|
|
58
59
|
loggedCliErrorObjects.add(error);
|
|
59
60
|
}
|
|
60
|
-
const message = CliError.messageOf(error);
|
|
61
|
+
const message = error instanceof Error ? ErrorReport.format(error) || error.name : CliError.messageOf(error);
|
|
61
62
|
if (loggedCliErrorMessages.has(message)) return;
|
|
62
63
|
loggedCliErrorMessages.add(message);
|
|
63
64
|
Logger.rawLog(`\n${chalk.red(message)}`, undefined, stream);
|
|
@@ -137,7 +137,7 @@ class TargetBuilder<Deps extends readonly DependencyCls[], Params extends unknow
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
type TargetDefinition = ReturnType<TargetBuilder<readonly DependencyCls[], unknown[]>["exec"]>;
|
|
140
|
-
type CommandBuilderContext<Deps extends readonly DependencyCls[]> = {
|
|
140
|
+
export type CommandBuilderContext<Deps extends readonly DependencyCls[]> = {
|
|
141
141
|
public: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
|
|
142
142
|
cloud: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
|
|
143
143
|
dev: (targetOption?: Omit<TargetOption, "type">) => TargetBuilder<Deps>;
|