@mycadet/cli 0.13.0-dev.202610200020.9f20440 → 0.13.0-dev.202610201855.522ff0d
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/node_modules/@mycadet/assistant-api/constants/personality-sliders.test.ts +0 -8
- package/node_modules/@mycadet/assistant-api/constants/personality-sliders.ts +5 -41
- package/node_modules/@mycadet/assistant-api/events/message-complete.ts +0 -5
- package/node_modules/@mycadet/assistant-api/index.ts +0 -2
- package/node_modules/@mycadet/assistant-api/responses/conversation-message.ts +0 -10
- package/node_modules/@mycadet/environments/src/seeds.ts +6 -2
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/seeds.ts +6 -2
- package/node_modules/@mycadet/local-mode/src/config.ts +0 -2
- package/node_modules/@mycadet/local-mode/src/index.ts +1 -1
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +1 -22
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +26 -7
- package/node_modules/@mycadet/local-mode/src/util.ts +1 -20
- package/node_modules/@mycadet/shared/github-repository.ts +5 -0
- package/node_modules/@mycadet/shared/package.json +10 -0
- package/node_modules/@mycadet/shared/scripts/run-isolated-tests.ts +700 -0
- package/package.json +3 -2
- package/src/__tests__/app-command.test.ts +164 -0
- package/src/__tests__/client-web-config.test.ts +0 -1
- package/src/__tests__/cloud-releases.test.ts +1 -1
- package/src/__tests__/local-version.test.ts +16 -0
- package/src/__tests__/nginx-ingress.test.ts +248 -630
- package/src/__tests__/ps-cloud-status.test.ts +85 -11
- package/src/__tests__/root-process-lockfile.test.ts +29 -2
- package/src/__tests__/tunnel-holder-heal.test.ts +119 -0
- package/src/__tests__/tunnel-stop.test.ts +6 -13
- package/src/__tests__/tunnel.test.ts +50 -193
- package/src/__tests__/wake.test.ts +6 -38
- package/src/__tests__/web-dist.test.ts +267 -89
- package/src/commands/app.ts +113 -0
- package/src/commands/backup.ts +5 -4
- package/src/commands/clean.ts +2 -1
- package/src/commands/client.ts +5 -68
- package/src/commands/completions.ts +12 -1
- package/src/commands/connect.ts +2 -1
- package/src/commands/debug.ts +2 -1
- package/src/commands/exec.ts +7 -6
- package/src/commands/gateway/token.ts +2 -1
- package/src/commands/gateway.ts +2 -1
- package/src/commands/hatch.ts +74 -80
- package/src/commands/login.ts +7 -6
- package/src/commands/logs.ts +2 -1
- package/src/commands/ps.ts +136 -6
- package/src/commands/restart.ts +2 -1
- package/src/commands/restore.ts +10 -9
- package/src/commands/retire.ts +4 -3
- package/src/commands/setup.ts +5 -4
- package/src/commands/sleep.ts +3 -2
- package/src/commands/teleport.ts +2 -1
- package/src/commands/terminal.ts +7 -6
- package/src/commands/tunnel.ts +196 -242
- package/src/commands/uninstall.ts +2 -1
- package/src/commands/upgrade.ts +2 -1
- package/src/commands/use.ts +2 -1
- package/src/commands/wake.ts +3 -2
- package/src/index.ts +5 -4
- package/src/lib/__tests__/web-dist.test.ts +1 -27
- package/src/lib/assistant-config.ts +101 -37
- package/src/lib/cli-name.ts +14 -0
- package/src/lib/cloud-client.ts +2 -1
- package/src/lib/cloud-login-poll.ts +2 -1
- package/src/lib/cloud-releases.ts +1 -1
- package/src/lib/docker.ts +32 -21
- package/src/lib/hatch-local.ts +1 -3
- package/src/lib/hatch-next-steps.ts +1 -9
- package/src/lib/ingress-config.ts +0 -31
- package/src/lib/local-version.ts +25 -4
- package/src/lib/local.ts +34 -9
- package/src/lib/nginx-ingress.ts +143 -244
- package/src/lib/provider-secrets.ts +0 -5
- package/src/lib/statefulset.ts +0 -1
- package/src/lib/tunnel.ts +244 -43
- package/src/lib/tunnels/ngrok.ts +57 -9
- package/src/lib/tunnels/tailscale.ts +2 -1
- package/src/lib/web-dist.ts +134 -56
- package/src/__tests__/flags.test.ts +0 -318
- package/src/__tests__/shell-mode.test.ts +0 -83
- package/src/commands/flags.ts +0 -255
- package/src/lib/flag-args.test.ts +0 -84
- package/src/lib/flag-args.ts +0 -74
- package/src/lib/github-repository.ts +0 -2
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
afterAll,
|
|
3
3
|
afterEach,
|
|
4
|
+
beforeEach,
|
|
4
5
|
describe,
|
|
5
6
|
expect,
|
|
6
7
|
mock,
|
|
@@ -8,10 +9,18 @@ import {
|
|
|
8
9
|
test,
|
|
9
10
|
} from "bun:test";
|
|
10
11
|
import * as childProcess from "node:child_process";
|
|
11
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
mkdirSync,
|
|
14
|
+
mkdtempSync,
|
|
15
|
+
readFileSync,
|
|
16
|
+
rmSync,
|
|
17
|
+
writeFileSync,
|
|
18
|
+
} from "node:fs";
|
|
12
19
|
import { tmpdir } from "node:os";
|
|
13
20
|
import { join } from "node:path";
|
|
14
|
-
import {
|
|
21
|
+
import { PassThrough } from "node:stream";
|
|
22
|
+
import { readAppBuiltSha, stampAppBuiltSha } from "../lib/assistant-config.js";
|
|
23
|
+
import { resolveEdgeClientDists } from "../lib/web-dist.js";
|
|
15
24
|
|
|
16
25
|
const realChildProcess = { ...childProcess };
|
|
17
26
|
const spawnMock = mock(childProcess.spawn);
|
|
@@ -27,9 +36,26 @@ afterAll(() => {
|
|
|
27
36
|
mock.module("node:child_process", () => realChildProcess);
|
|
28
37
|
});
|
|
29
38
|
|
|
39
|
+
/**
|
|
40
|
+
* The HEAD sha the fixture's git boundary reports. null = a git-less tree
|
|
41
|
+
* (rev-parse fails), which keeps staleness detection inert.
|
|
42
|
+
*/
|
|
43
|
+
let fixtureHeadSha: string | null = null;
|
|
44
|
+
|
|
45
|
+
// The built-sha stamp lives in the CLI lockfile now — each test redirects it
|
|
46
|
+
// to a temp dir (the root-process-lockfile.test.ts pattern).
|
|
47
|
+
const lockfileDirs: string[] = [];
|
|
48
|
+
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
lockfileDirs.push(mkdtempSync(join(tmpdir(), "web-dist-lockfile-")));
|
|
51
|
+
process.env.CADET_LOCKFILE_DIR = lockfileDirs.at(-1);
|
|
52
|
+
});
|
|
53
|
+
|
|
30
54
|
afterEach(() => {
|
|
55
|
+
delete process.env.CADET_LOCKFILE_DIR;
|
|
31
56
|
spawnMock.mockReset();
|
|
32
57
|
spawnMock.mockImplementation(realChildProcess.spawn);
|
|
58
|
+
fixtureHeadSha = null;
|
|
33
59
|
});
|
|
34
60
|
|
|
35
61
|
const roots: string[] = [];
|
|
@@ -41,7 +67,7 @@ function makeRoot(): string {
|
|
|
41
67
|
}
|
|
42
68
|
|
|
43
69
|
afterAll(() => {
|
|
44
|
-
for (const dir of roots.splice(0)) {
|
|
70
|
+
for (const dir of [...roots.splice(0), ...lockfileDirs.splice(0)]) {
|
|
45
71
|
rmSync(dir, { recursive: true, force: true });
|
|
46
72
|
}
|
|
47
73
|
});
|
|
@@ -51,152 +77,304 @@ function resolvePackageThrows(): string {
|
|
|
51
77
|
throw new Error("no npm package in this fixture");
|
|
52
78
|
}
|
|
53
79
|
|
|
54
|
-
/** A
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
80
|
+
/** A git child that answers rev-parse with the fixture HEAD, or fails. */
|
|
81
|
+
function fakeGitChild(): childProcess.ChildProcess {
|
|
82
|
+
const child = new childProcess.ChildProcess();
|
|
83
|
+
if (fixtureHeadSha === null) {
|
|
84
|
+
Object.defineProperty(child, "stdout", { value: null });
|
|
85
|
+
setTimeout(() => child.emit("exit", 128), 0);
|
|
86
|
+
return child;
|
|
87
|
+
}
|
|
88
|
+
const stream = new PassThrough();
|
|
89
|
+
Object.defineProperty(child, "stdout", { value: stream });
|
|
90
|
+
setTimeout(() => {
|
|
91
|
+
stream.write(`${fixtureHeadSha}\n`);
|
|
92
|
+
stream.end();
|
|
93
|
+
child.emit("exit", 0);
|
|
94
|
+
}, 0);
|
|
95
|
+
return child;
|
|
59
96
|
}
|
|
60
97
|
|
|
61
98
|
/**
|
|
62
|
-
*
|
|
63
|
-
*
|
|
99
|
+
* The process-boundary fake: git rev-parse answers with the fixture HEAD,
|
|
100
|
+
* and bun spawns run the fake build — optionally "landing" the bundle files
|
|
101
|
+
* where the real build would write them — then exit with the given code.
|
|
64
102
|
*/
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
|
|
103
|
+
function fakeSpawn(
|
|
104
|
+
landBun?: () => void,
|
|
105
|
+
bunCode = 0,
|
|
68
106
|
): typeof childProcess.spawn {
|
|
69
|
-
return (() => {
|
|
70
|
-
|
|
107
|
+
return ((command: string) => {
|
|
108
|
+
if (command === "git") {
|
|
109
|
+
return fakeGitChild();
|
|
110
|
+
}
|
|
111
|
+
landBun?.();
|
|
71
112
|
const child = new childProcess.ChildProcess();
|
|
72
|
-
setTimeout(() => child.emit("exit",
|
|
113
|
+
setTimeout(() => child.emit("exit", bunCode), 10);
|
|
73
114
|
return child;
|
|
74
115
|
}) as unknown as typeof childProcess.spawn;
|
|
75
116
|
}
|
|
76
117
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
spawnMock.mockImplementation(unexpectedSpawn());
|
|
118
|
+
/** A build spawn that must never fire: a build here is a bug. */
|
|
119
|
+
function unexpectedSpawn(): typeof childProcess.spawn {
|
|
120
|
+
return (() => {
|
|
121
|
+
throw new Error("unexpected spawn");
|
|
122
|
+
}) as unknown as typeof childProcess.spawn;
|
|
123
|
+
}
|
|
84
124
|
|
|
85
|
-
|
|
125
|
+
function bunCalls(): Array<Parameters<typeof childProcess.spawn>> {
|
|
126
|
+
return spawnMock.mock.calls.filter(([command]) => command === "bun") as Array<
|
|
127
|
+
Parameters<typeof childProcess.spawn>
|
|
128
|
+
>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function seedWebDist(packageDir: string): string {
|
|
132
|
+
const distDir = join(packageDir, "dist");
|
|
133
|
+
mkdirSync(distDir, { recursive: true });
|
|
134
|
+
writeFileSync(join(distDir, "index.html"), "<html></html>");
|
|
135
|
+
return distDir;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function seedAppDist(packageDir: string): string {
|
|
139
|
+
const distDir = join(packageDir, "dist", "standalone");
|
|
140
|
+
mkdirSync(distDir, { recursive: true });
|
|
141
|
+
writeFileSync(join(distDir, "index.html"), "<html></html>");
|
|
142
|
+
return distDir;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** A fixture checkout with both client packages declared. */
|
|
146
|
+
function seedCheckout(): { root: string; web: string; app: string } {
|
|
147
|
+
const root = makeRoot();
|
|
148
|
+
const web = join(root, "clients", "web");
|
|
149
|
+
const app = join(root, "clients", "app");
|
|
150
|
+
mkdirSync(web, { recursive: true });
|
|
151
|
+
mkdirSync(app, { recursive: true });
|
|
152
|
+
writeFileSync(join(web, "package.json"), "{}");
|
|
153
|
+
writeFileSync(join(app, "package.json"), "{}");
|
|
154
|
+
return { root, web, app };
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
describe("resolveEdgeClientDists", () => {
|
|
158
|
+
test("returns both source-checkout dists without building when present", async () => {
|
|
159
|
+
const { root, web, app } = seedCheckout();
|
|
160
|
+
const webDist = seedWebDist(web);
|
|
161
|
+
const appDist = seedAppDist(app);
|
|
162
|
+
// git-less tree: staleness detection is inert, the dists serve as-is.
|
|
163
|
+
fixtureHeadSha = null;
|
|
164
|
+
spawnMock.mockImplementation(fakeSpawn());
|
|
165
|
+
|
|
166
|
+
const resolved = await resolveEdgeClientDists({
|
|
86
167
|
startDir: root,
|
|
87
168
|
resolvePackage: resolvePackageThrows,
|
|
88
169
|
});
|
|
89
170
|
|
|
90
|
-
expect(resolved).
|
|
91
|
-
expect(
|
|
171
|
+
expect(resolved).toEqual({ webDistDir: webDist, appDistDir: appDist });
|
|
172
|
+
expect(bunCalls()).toHaveLength(0);
|
|
92
173
|
});
|
|
93
174
|
|
|
94
|
-
test("builds
|
|
95
|
-
const root =
|
|
96
|
-
|
|
97
|
-
mkdirSync(packageDir, { recursive: true });
|
|
98
|
-
writeFileSync(join(packageDir, "package.json"), "{}");
|
|
175
|
+
test("builds both missing bundles once and stamps the lockfile's app record", async () => {
|
|
176
|
+
const { root, web, app } = seedCheckout();
|
|
177
|
+
fixtureHeadSha = "a".repeat(40);
|
|
99
178
|
const logSpy = spyOn(console, "log");
|
|
100
179
|
spawnMock.mockImplementation(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
180
|
+
fakeSpawn(() => {
|
|
181
|
+
seedWebDist(web);
|
|
182
|
+
seedAppDist(app);
|
|
104
183
|
}),
|
|
105
184
|
);
|
|
106
185
|
|
|
107
|
-
const resolved = await
|
|
186
|
+
const resolved = await resolveEdgeClientDists({
|
|
187
|
+
startDir: root,
|
|
188
|
+
resolvePackage: resolvePackageThrows,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
expect(resolved).toEqual({
|
|
192
|
+
webDistDir: join(web, "dist"),
|
|
193
|
+
appDistDir: join(app, "dist", "standalone"),
|
|
194
|
+
});
|
|
195
|
+
const builds = bunCalls();
|
|
196
|
+
expect(builds).toHaveLength(2);
|
|
197
|
+
for (const [command, args] of builds) {
|
|
198
|
+
expect(command).toBe("bun");
|
|
199
|
+
expect(args).toEqual(["run", "build"]);
|
|
200
|
+
}
|
|
201
|
+
// The stamp is the commit both bundles consumed, recorded on the
|
|
202
|
+
// lockfile's `app` entry.
|
|
203
|
+
expect(readAppBuiltSha()).toBe(fixtureHeadSha);
|
|
204
|
+
const rawLockfile = JSON.parse(
|
|
205
|
+
readFileSync(
|
|
206
|
+
join(process.env.CADET_LOCKFILE_DIR!, "lockfile.json"),
|
|
207
|
+
"utf-8",
|
|
208
|
+
),
|
|
209
|
+
);
|
|
210
|
+
expect(rawLockfile.app.builtSha).toBe(fixtureHeadSha);
|
|
211
|
+
logSpy.mockRestore();
|
|
212
|
+
|
|
213
|
+
// The second resolve finds a fresh stamp and does not rebuild.
|
|
214
|
+
expect(
|
|
215
|
+
await resolveEdgeClientDists({
|
|
216
|
+
startDir: root,
|
|
217
|
+
resolvePackage: resolvePackageThrows,
|
|
218
|
+
}),
|
|
219
|
+
).toEqual(resolved);
|
|
220
|
+
expect(bunCalls()).toHaveLength(2);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test("rebuilds both bundles when the checkout moved past the stamp", async () => {
|
|
224
|
+
const { root, web, app } = seedCheckout();
|
|
225
|
+
seedWebDist(web);
|
|
226
|
+
seedAppDist(app);
|
|
227
|
+
stampAppBuiltSha("b".repeat(40));
|
|
228
|
+
// The pull moved HEAD past the stamped build.
|
|
229
|
+
fixtureHeadSha = "c".repeat(40);
|
|
230
|
+
const logSpy = spyOn(console, "log");
|
|
231
|
+
spawnMock.mockImplementation(fakeSpawn());
|
|
232
|
+
|
|
233
|
+
const resolved = await resolveEdgeClientDists({
|
|
108
234
|
startDir: root,
|
|
109
235
|
resolvePackage: resolvePackageThrows,
|
|
110
236
|
});
|
|
111
237
|
|
|
112
|
-
expect(resolved).toBe(join(
|
|
238
|
+
expect(resolved.webDistDir).toBe(join(web, "dist"));
|
|
239
|
+
expect(bunCalls()).toHaveLength(2);
|
|
113
240
|
expect(
|
|
114
241
|
logSpy.mock.calls.some((call) =>
|
|
115
|
-
call.join(" ").includes("
|
|
242
|
+
call.join(" ").includes("older than the current checkout"),
|
|
116
243
|
),
|
|
117
244
|
).toBe(true);
|
|
118
245
|
logSpy.mockRestore();
|
|
246
|
+
expect(readAppBuiltSha()).toBe(fixtureHeadSha);
|
|
247
|
+
});
|
|
119
248
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
249
|
+
test("serves fresh bundles without rebuilding", async () => {
|
|
250
|
+
const { root, web, app } = seedCheckout();
|
|
251
|
+
const webDist = seedWebDist(web);
|
|
252
|
+
const appDist = seedAppDist(app);
|
|
253
|
+
fixtureHeadSha = "d".repeat(40);
|
|
254
|
+
stampAppBuiltSha(fixtureHeadSha);
|
|
255
|
+
spawnMock.mockImplementation(fakeSpawn());
|
|
256
|
+
|
|
257
|
+
const resolved = await resolveEdgeClientDists({
|
|
258
|
+
startDir: root,
|
|
259
|
+
resolvePackage: resolvePackageThrows,
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
expect(resolved).toEqual({ webDistDir: webDist, appDistDir: appDist });
|
|
263
|
+
expect(bunCalls()).toHaveLength(0);
|
|
264
|
+
});
|
|
125
265
|
|
|
126
|
-
|
|
266
|
+
test("rebuilds bundles that predate the stamp once", async () => {
|
|
267
|
+
const { root, web, app } = seedCheckout();
|
|
268
|
+
seedWebDist(web);
|
|
269
|
+
seedAppDist(app);
|
|
270
|
+
fixtureHeadSha = "e".repeat(40);
|
|
271
|
+
const logSpy = spyOn(console, "log");
|
|
272
|
+
spawnMock.mockImplementation(fakeSpawn());
|
|
273
|
+
|
|
274
|
+
const resolved = await resolveEdgeClientDists({
|
|
275
|
+
startDir: root,
|
|
276
|
+
resolvePackage: resolvePackageThrows,
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
expect(resolved.webDistDir).toBe(join(web, "dist"));
|
|
280
|
+
expect(bunCalls()).toHaveLength(2);
|
|
127
281
|
expect(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
expect(
|
|
282
|
+
logSpy.mock.calls.some((call) =>
|
|
283
|
+
call.join(" ").includes("no build stamp"),
|
|
284
|
+
),
|
|
285
|
+
).toBe(true);
|
|
286
|
+
logSpy.mockRestore();
|
|
287
|
+
expect(readAppBuiltSha()).toBe(fixtureHeadSha);
|
|
134
288
|
});
|
|
135
289
|
|
|
136
|
-
test("returns null when there is no dist and no source package
|
|
290
|
+
test("returns null dists when there is no dist and no source package", async () => {
|
|
137
291
|
const root = makeRoot();
|
|
138
292
|
spawnMock.mockImplementation(unexpectedSpawn());
|
|
139
293
|
|
|
140
|
-
const resolved = await
|
|
294
|
+
const resolved = await resolveEdgeClientDists({
|
|
141
295
|
startDir: root,
|
|
142
296
|
resolvePackage: resolvePackageThrows,
|
|
143
297
|
});
|
|
144
298
|
|
|
145
|
-
expect(resolved).
|
|
299
|
+
expect(resolved).toEqual({ webDistDir: null, appDistDir: null });
|
|
146
300
|
expect(spawnMock.mock.calls).toHaveLength(0);
|
|
147
301
|
});
|
|
148
302
|
|
|
149
303
|
test("reports a failed source build with the manual recipe", async () => {
|
|
150
|
-
const root =
|
|
151
|
-
|
|
152
|
-
mkdirSync(packageDir, { recursive: true });
|
|
153
|
-
writeFileSync(join(packageDir, "package.json"), "{}");
|
|
304
|
+
const { root } = seedCheckout();
|
|
305
|
+
fixtureHeadSha = "f".repeat(40);
|
|
154
306
|
const logSpy = spyOn(console, "log");
|
|
155
|
-
spawnMock.mockImplementation(
|
|
307
|
+
spawnMock.mockImplementation(fakeSpawn(undefined, 1));
|
|
156
308
|
|
|
157
309
|
await expect(
|
|
158
|
-
|
|
310
|
+
resolveEdgeClientDists({
|
|
159
311
|
startDir: root,
|
|
160
312
|
resolvePackage: resolvePackageThrows,
|
|
161
313
|
}),
|
|
162
|
-
).rejects.toThrow("cd clients/web &&
|
|
163
|
-
expect(
|
|
164
|
-
logSpy.mock.calls.some((call) =>
|
|
165
|
-
call.join(" ").includes("No built web bundle found"),
|
|
166
|
-
),
|
|
167
|
-
).toBe(true);
|
|
314
|
+
).rejects.toThrow("cd clients/web && bun run build");
|
|
168
315
|
logSpy.mockRestore();
|
|
169
316
|
});
|
|
170
|
-
});
|
|
171
317
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
);
|
|
318
|
+
test("records the stamp only after both builds succeed", async () => {
|
|
319
|
+
const { root, web } = seedCheckout();
|
|
320
|
+
fixtureHeadSha = "1".repeat(40);
|
|
321
|
+
let builds = 0;
|
|
322
|
+
spawnMock.mockImplementation(((command: string) => {
|
|
323
|
+
if (command === "git") {
|
|
324
|
+
return fakeGitChild();
|
|
325
|
+
}
|
|
326
|
+
builds++;
|
|
327
|
+
const child = new childProcess.ChildProcess();
|
|
328
|
+
// The web build lands; the app build fails — a half-stamped state must
|
|
329
|
+
// never pretend the second bundle is fresh.
|
|
330
|
+
if (builds === 1) {
|
|
331
|
+
seedWebDist(web);
|
|
332
|
+
setTimeout(() => child.emit("exit", 0), 10);
|
|
333
|
+
} else {
|
|
334
|
+
setTimeout(() => child.emit("exit", 1), 10);
|
|
335
|
+
}
|
|
336
|
+
return child;
|
|
337
|
+
}) as unknown as typeof childProcess.spawn);
|
|
338
|
+
|
|
339
|
+
await expect(
|
|
340
|
+
resolveEdgeClientDists({
|
|
341
|
+
startDir: root,
|
|
342
|
+
resolvePackage: resolvePackageThrows,
|
|
186
343
|
}),
|
|
187
|
-
);
|
|
344
|
+
).rejects.toThrow("Building the app bundle from source failed");
|
|
345
|
+
|
|
346
|
+
expect(readAppBuiltSha()).toBeUndefined();
|
|
347
|
+
});
|
|
188
348
|
|
|
189
|
-
|
|
349
|
+
test("leaves installed-package dists alone even with a stale source checkout", async () => {
|
|
350
|
+
const { root, web, app } = seedCheckout();
|
|
351
|
+
// The npm arm resolves first and owns the web dist; the source checkout
|
|
352
|
+
// may be as stale as it likes.
|
|
353
|
+
const npmWebDir = join(root, "npm", "@mycadet", "web");
|
|
354
|
+
seedWebDist(npmWebDir);
|
|
355
|
+
const appDist = seedAppDist(app);
|
|
356
|
+
seedWebDist(web);
|
|
357
|
+
fixtureHeadSha = "2".repeat(40);
|
|
358
|
+
// The source-built app arm is fresh at HEAD, so nothing rebuilds.
|
|
359
|
+
stampAppBuiltSha(fixtureHeadSha);
|
|
360
|
+
spawnMock.mockImplementation(((command: string) => {
|
|
361
|
+
// git HEAD is a legitimate probe (the app arm is source-built); a
|
|
362
|
+
// BUILD spawn here is a bug.
|
|
363
|
+
if (command === "git") {
|
|
364
|
+
return fakeGitChild();
|
|
365
|
+
}
|
|
366
|
+
throw new Error("unexpected spawn");
|
|
367
|
+
}) as unknown as typeof childProcess.spawn);
|
|
368
|
+
|
|
369
|
+
const resolved = await resolveEdgeClientDists({
|
|
190
370
|
startDir: root,
|
|
191
|
-
resolvePackage:
|
|
371
|
+
resolvePackage: () => join(npmWebDir, "package.json"),
|
|
192
372
|
});
|
|
193
373
|
|
|
194
|
-
expect(resolved).
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
expect(
|
|
199
|
-
expect(args).toEqual(["run", "build"]);
|
|
200
|
-
expect(options?.cwd).toBe(packageDir);
|
|
374
|
+
expect(resolved).toEqual({
|
|
375
|
+
webDistDir: join(npmWebDir, "dist"),
|
|
376
|
+
appDistDir: appDist,
|
|
377
|
+
});
|
|
378
|
+
expect(bunCalls()).toHaveLength(0);
|
|
201
379
|
});
|
|
202
380
|
});
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { loadAllAssistants } from "../lib/assistant-config";
|
|
2
|
+
import { getDefaultWorkspaceDir } from "../lib/ingress-config.js";
|
|
3
|
+
import {
|
|
4
|
+
ensureTunnelEdge,
|
|
5
|
+
isIngressRunning,
|
|
6
|
+
readIngressState,
|
|
7
|
+
stopIngressNginx,
|
|
8
|
+
type TunnelEdge,
|
|
9
|
+
} from "../lib/nginx-ingress.js";
|
|
10
|
+
import {
|
|
11
|
+
ensureNginxForEdge,
|
|
12
|
+
resolveLocalTunnelTarget,
|
|
13
|
+
toLocalTunnelTarget,
|
|
14
|
+
} from "../lib/tunnel.js";
|
|
15
|
+
import { cliCommand } from "../lib/cli-name.js";
|
|
16
|
+
|
|
17
|
+
function printAppHelp(): void {
|
|
18
|
+
console.log(
|
|
19
|
+
`Usage: ${cliCommand()} app start [options]\n ${cliCommand()} app stop`,
|
|
20
|
+
);
|
|
21
|
+
console.log("");
|
|
22
|
+
console.log(
|
|
23
|
+
"The App server hosts the assistant-agnostic frontend bundle, is the home",
|
|
24
|
+
);
|
|
25
|
+
console.log(
|
|
26
|
+
"for assistant management commands, and proxies all assistant-specific",
|
|
27
|
+
);
|
|
28
|
+
console.log("APIs & webhooks to the correct Cadet.");
|
|
29
|
+
console.log("");
|
|
30
|
+
console.log(
|
|
31
|
+
`The App server is spun up automatically as part of the \`${cliCommand()} tunnel start\` command.`,
|
|
32
|
+
);
|
|
33
|
+
process.exit(0);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `cadet app start`: bring the nginx edge up for the active local assistant. */
|
|
37
|
+
async function startAppEdge(): Promise<void> {
|
|
38
|
+
await ensureNginxForEdge();
|
|
39
|
+
|
|
40
|
+
const { entry, gatewayPort, workspaceDir } = resolveLocalTunnelTarget();
|
|
41
|
+
|
|
42
|
+
let edge: TunnelEdge;
|
|
43
|
+
try {
|
|
44
|
+
edge = await ensureTunnelEdge({
|
|
45
|
+
assistantId: entry.assistantId,
|
|
46
|
+
workspaceDir,
|
|
47
|
+
gatewayPort,
|
|
48
|
+
});
|
|
49
|
+
} catch (err) {
|
|
50
|
+
console.error(`Error: ${err instanceof Error ? err.message : String(err)}`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
console.log(
|
|
55
|
+
`${edge.started ? "Started" : "Reusing"} the app edge on 127.0.0.1:${edge.port} (app shell + remote web + webhooks).`,
|
|
56
|
+
);
|
|
57
|
+
console.log(`Stop with: ${cliCommand()} app stop`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Workspaces that could hold a running edge: every locally reachable
|
|
62
|
+
* assistant's own, then the default one container assistants share. Usually
|
|
63
|
+
* exactly one is live.
|
|
64
|
+
*/
|
|
65
|
+
function candidateEdgeWorkspaces(): string[] {
|
|
66
|
+
const workspaces: string[] = [];
|
|
67
|
+
for (const entry of loadAllAssistants()) {
|
|
68
|
+
const target = toLocalTunnelTarget(entry);
|
|
69
|
+
if (target && !workspaces.includes(target.workspaceDir)) {
|
|
70
|
+
workspaces.push(target.workspaceDir);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (!workspaces.includes(getDefaultWorkspaceDir())) {
|
|
74
|
+
workspaces.push(getDefaultWorkspaceDir());
|
|
75
|
+
}
|
|
76
|
+
return workspaces;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** `cadet app stop`: take the nginx edge down. */
|
|
80
|
+
async function stopAppEdge(): Promise<void> {
|
|
81
|
+
let stoppedAny = false;
|
|
82
|
+
for (const workspaceDir of candidateEdgeWorkspaces()) {
|
|
83
|
+
if (!isIngressRunning(workspaceDir)) continue;
|
|
84
|
+
const port = readIngressState(workspaceDir)?.listenPort;
|
|
85
|
+
if (await stopIngressNginx(workspaceDir)) {
|
|
86
|
+
stoppedAny = true;
|
|
87
|
+
console.log(`Stopped the app edge on 127.0.0.1:${port ?? "?"}.`);
|
|
88
|
+
} else {
|
|
89
|
+
console.error(
|
|
90
|
+
`Error: could not stop the app edge on 127.0.0.1:${port ?? "?"}. Check the nginx log: ${workspaceDir}/data/logs/nginx-ingress.log`,
|
|
91
|
+
);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (!stoppedAny) {
|
|
96
|
+
console.log("No app edge is running.");
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export const app = Object.assign(
|
|
101
|
+
async function app(): Promise<void> {
|
|
102
|
+
const subcommand = process.argv[3];
|
|
103
|
+
if (subcommand === "--help" || subcommand === "-h" || !subcommand) {
|
|
104
|
+
printAppHelp();
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (subcommand === "start") return startAppEdge();
|
|
108
|
+
if (subcommand === "stop") return stopAppEdge();
|
|
109
|
+
console.error(`Error: Unknown argument '${subcommand}'.`);
|
|
110
|
+
printAppHelp();
|
|
111
|
+
},
|
|
112
|
+
{ description: "Start or stop the local app edge (nginx)" },
|
|
113
|
+
);
|
package/src/commands/backup.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { stat } from "node:fs/promises";
|
|
2
|
+
import { cliCommand } from "../lib/cli-name.js";
|
|
2
3
|
import { join } from "node:path";
|
|
3
4
|
import { findAssistantByName } from "../lib/assistant-config.js";
|
|
4
5
|
import { formatSize, getBackupsDir } from "../lib/backup-ops.js";
|
|
@@ -11,25 +12,25 @@ export const backup = Object.assign(
|
|
|
11
12
|
async function backup(): Promise<void> {
|
|
12
13
|
const args = process.argv.slice(3);
|
|
13
14
|
if (args.includes("--help") || args.includes("-h")) {
|
|
14
|
-
console.log(
|
|
15
|
+
console.log(`Usage: ${cliCommand()} backup <name>`);
|
|
15
16
|
console.log(
|
|
16
17
|
"Local/Docker: gracefully stop services, capture all persistent roots as tar.gz, then resume.",
|
|
17
18
|
);
|
|
18
19
|
console.log(
|
|
19
20
|
"Cloud: create a backup through the cloud API using your cloud session.",
|
|
20
21
|
);
|
|
21
|
-
console.log(
|
|
22
|
+
console.log(`Example: ${cliCommand()} backup my-assistant`);
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
24
25
|
const name = args[0];
|
|
25
26
|
if (!name || name.startsWith("-"))
|
|
26
|
-
throw new Error(
|
|
27
|
+
throw new Error(`Usage: ${cliCommand()} backup <name>`);
|
|
27
28
|
if (args.length > 1) throw new Error(`Unknown backup option: ${args[1]}`);
|
|
28
29
|
const entry = findAssistantByName(name);
|
|
29
30
|
if (!entry) throw new Error(`No assistant found with name '${name}'.`);
|
|
30
31
|
if (isCloudHome(entry.cloud)) {
|
|
31
32
|
const token = readCloudToken();
|
|
32
|
-
if (!token) throw new Error(
|
|
33
|
+
if (!token) throw new Error(`Not logged in. Run '${cliCommand()} login' first.`);
|
|
33
34
|
await createPlatformBackup(entry, token);
|
|
34
35
|
console.log("Cloud backup is ready.");
|
|
35
36
|
return;
|
package/src/commands/clean.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { detectOrphanedProcesses } from "../lib/orphan-detection";
|
|
2
|
+
import { cliCommand } from "../lib/cli-name.js";
|
|
2
3
|
import { stopProcess } from "../lib/process";
|
|
3
4
|
|
|
4
5
|
export const clean = Object.assign(
|
|
5
6
|
async function clean(): Promise<void> {
|
|
6
7
|
const args = process.argv.slice(3);
|
|
7
8
|
if (args.includes("--help") || args.includes("-h")) {
|
|
8
|
-
console.log(
|
|
9
|
+
console.log(`Usage: ${cliCommand()} clean`);
|
|
9
10
|
console.log("");
|
|
10
11
|
console.log(
|
|
11
12
|
"Kill all orphaned cadet processes that are not tracked by any assistant.",
|