@mycadet/cli 0.13.0-dev.202610290143.526d7ca → 0.13.0-dev.202610290231.835a903
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/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/environments/package.json +1 -1
- package/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +1 -1
- package/node_modules/@mycadet/local-mode/package.json +1 -1
- package/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/shared/package.json +1 -1
- package/package.json +1 -1
- package/src/__tests__/wake.test.ts +4 -58
- package/src/lib/ingress-config.ts +0 -45
- package/src/lib/root-signing-key.ts +0 -6
- package/src/lib/tunnel.ts +3 -12
package/package.json
CHANGED
|
@@ -17,7 +17,6 @@ import * as localModeModule from "@mycadet/local-mode";
|
|
|
17
17
|
import * as docker from "../lib/docker.js";
|
|
18
18
|
import * as guardianToken from "../lib/guardian-token.js";
|
|
19
19
|
import * as httpClient from "../lib/http-client.js";
|
|
20
|
-
import * as ingressConfig from "../lib/ingress-config.js";
|
|
21
20
|
import * as local from "../lib/local.js";
|
|
22
21
|
import * as nginxIngress from "../lib/nginx-ingress.js";
|
|
23
22
|
import * as ngrok from "../lib/tunnels/ngrok.js";
|
|
@@ -176,15 +175,11 @@ mock.module("../lib/tunnels/ngrok", () => ({
|
|
|
176
175
|
},
|
|
177
176
|
}));
|
|
178
177
|
|
|
179
|
-
const realIngressConfig = { ...ingressConfig };
|
|
180
178
|
const realNginxIngress = { ...nginxIngress };
|
|
181
179
|
|
|
182
|
-
const loadRawConfigMock = mock<typeof ingressConfig.loadRawConfig>(() => ({}));
|
|
183
180
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
loadRawConfig: loadRawConfigMock,
|
|
187
|
-
}));
|
|
181
|
+
|
|
182
|
+
|
|
188
183
|
|
|
189
184
|
const ensureAppServerMock = mock<typeof nginxIngress.ensureAppServer>(
|
|
190
185
|
async () => ({ port: 7840, started: true, shellMode: "web" }),
|
|
@@ -322,8 +317,6 @@ beforeEach(() => {
|
|
|
322
317
|
publicUrl: "https://tunnel.example.com",
|
|
323
318
|
waitForExit: Promise.resolve(),
|
|
324
319
|
}));
|
|
325
|
-
loadRawConfigMock.mockReset();
|
|
326
|
-
loadRawConfigMock.mockReturnValue({});
|
|
327
320
|
ensureAppServerMock.mockReset();
|
|
328
321
|
ensureAppServerMock.mockResolvedValue({
|
|
329
322
|
port: 7840,
|
|
@@ -354,7 +347,6 @@ afterAll(() => {
|
|
|
354
347
|
mock.module("../lib/port-allocator.js", () => realPortAllocator);
|
|
355
348
|
mock.module("../lib/local", () => realLocal);
|
|
356
349
|
mock.module("../lib/tunnels/ngrok", () => realNgrok);
|
|
357
|
-
mock.module("../lib/ingress-config.js", () => realIngressConfig);
|
|
358
350
|
mock.module("../lib/nginx-ingress.js", () => realNginxIngress);
|
|
359
351
|
mock.module("../lib/http-client.js", () => realHttpClient);
|
|
360
352
|
mock.module("../lib/root-signing-key.js", () => realRootSigningKey);
|
|
@@ -569,10 +561,6 @@ describe("cadet wake: daemon startup failure", () => {
|
|
|
569
561
|
});
|
|
570
562
|
|
|
571
563
|
describe("cadet wake — app server restore", () => {
|
|
572
|
-
const webhookConfig = { telegram: { botUsername: "bot" } };
|
|
573
|
-
const enabledConfig = {
|
|
574
|
-
ingress: { enabled: true, publicBaseUrl: "https://assistant.example.com" },
|
|
575
|
-
};
|
|
576
564
|
let lockfileDir = "";
|
|
577
565
|
|
|
578
566
|
beforeEach(() => {
|
|
@@ -611,22 +599,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
611
599
|
}
|
|
612
600
|
|
|
613
601
|
test("a recorded app server wakes the edge back up and tunnels the edge port", async () => {
|
|
614
|
-
loadRawConfigMock.mockReturnValue(webhookConfig);
|
|
615
|
-
stampRecordedAppServer();
|
|
616
|
-
stampRecordedTunnel("ngrok");
|
|
617
|
-
|
|
618
|
-
await wake();
|
|
619
|
-
|
|
620
|
-
expect(ensureAppServerMock).toHaveBeenCalledWith();
|
|
621
|
-
expect(ngrokRunMock).toHaveBeenCalledWith({
|
|
622
|
-
port: 7840,
|
|
623
|
-
assistantId: "local-assistant",
|
|
624
|
-
});
|
|
625
|
-
expect(logSpy).toHaveBeenCalledWith("Wake complete.");
|
|
626
|
-
});
|
|
627
|
-
|
|
628
|
-
test("a recorded app server wakes the edge even without webhook integrations", async () => {
|
|
629
|
-
loadRawConfigMock.mockReturnValue(enabledConfig);
|
|
630
602
|
stampRecordedAppServer();
|
|
631
603
|
stampRecordedTunnel("ngrok");
|
|
632
604
|
|
|
@@ -649,7 +621,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
649
621
|
cloud: "docker",
|
|
650
622
|
resources: { gatewayPort: 7930, daemonPort: 7821 },
|
|
651
623
|
});
|
|
652
|
-
loadRawConfigMock.mockReturnValue(enabledConfig);
|
|
653
624
|
stampRecordedAppServer("docker-1");
|
|
654
625
|
stampRecordedTunnel("ngrok");
|
|
655
626
|
process.argv = ["bun", "cadet", "wake", "docker-1"];
|
|
@@ -689,7 +660,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
689
660
|
},
|
|
690
661
|
};
|
|
691
662
|
resolveTargetAssistantMock.mockReturnValue(migratedEntry);
|
|
692
|
-
loadRawConfigMock.mockReturnValue(enabledConfig);
|
|
693
663
|
// The v0.0.10 run feedback: the containers were never created —
|
|
694
664
|
// `docker start` answers "No such container".
|
|
695
665
|
wakeContainersMock.mockImplementation(async () => {
|
|
@@ -725,7 +695,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
725
695
|
cloud: "docker",
|
|
726
696
|
resources: { gatewayPort: 7930, daemonPort: 7821 },
|
|
727
697
|
});
|
|
728
|
-
loadRawConfigMock.mockReturnValue(enabledConfig);
|
|
729
698
|
isIngressRunningMock.mockReturnValue(true);
|
|
730
699
|
readIngressStateMock.mockReturnValue({
|
|
731
700
|
listenPort: 7840,
|
|
@@ -757,7 +726,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
757
726
|
cloud: "docker",
|
|
758
727
|
resources: { gatewayPort: 7930, daemonPort: 7821 },
|
|
759
728
|
});
|
|
760
|
-
loadRawConfigMock.mockReturnValue(enabledConfig);
|
|
761
729
|
stampRecordedAppServer("docker-1");
|
|
762
730
|
isIngressRunningMock.mockReturnValue(true);
|
|
763
731
|
readIngressStateMock.mockReturnValue({
|
|
@@ -798,7 +766,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
798
766
|
cloud: "docker",
|
|
799
767
|
resources: { gatewayPort: 7930, daemonPort: 7821 },
|
|
800
768
|
});
|
|
801
|
-
loadRawConfigMock.mockReturnValue(enabledConfig);
|
|
802
769
|
stampRecordedAppServer("docker-1");
|
|
803
770
|
ensureAppServerMock.mockRejectedValue(new Error("nginx is not installed."));
|
|
804
771
|
process.argv = ["bun", "cadet", "wake", "docker-1"];
|
|
@@ -874,7 +841,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
874
841
|
cloud: "docker",
|
|
875
842
|
resources: { gatewayPort: 7930, daemonPort: 7821 },
|
|
876
843
|
});
|
|
877
|
-
loadRawConfigMock.mockReturnValue(enabledConfig);
|
|
878
844
|
stampRecordedAppServer("docker-1");
|
|
879
845
|
process.argv = ["bun", "cadet", "wake", "docker-1"];
|
|
880
846
|
|
|
@@ -902,7 +868,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
902
868
|
cloud: "docker",
|
|
903
869
|
resources: { gatewayPort: 7930, daemonPort: 7821 },
|
|
904
870
|
});
|
|
905
|
-
loadRawConfigMock.mockReturnValue(enabledConfig);
|
|
906
871
|
stampRecordedAppServer("docker-1");
|
|
907
872
|
waitForDaemonReadyMock.mockImplementation(async () => false);
|
|
908
873
|
process.argv = ["bun", "cadet", "wake", "docker-1"];
|
|
@@ -968,7 +933,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
968
933
|
cloud: "docker",
|
|
969
934
|
},
|
|
970
935
|
]);
|
|
971
|
-
loadRawConfigMock.mockReturnValue(enabledConfig);
|
|
972
936
|
stampRecordedAppServer("docker-1");
|
|
973
937
|
isIngressRunningMock.mockReturnValue(false);
|
|
974
938
|
process.argv = ["bun", "cadet", "wake", "docker-1"];
|
|
@@ -1026,8 +990,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
1026
990
|
});
|
|
1027
991
|
|
|
1028
992
|
test("a wake with no recorded app server or tunnel skips the edge and the tunnel", async () => {
|
|
1029
|
-
loadRawConfigMock.mockReturnValue({ ingress: { enabled: true } });
|
|
1030
|
-
|
|
1031
993
|
await wake();
|
|
1032
994
|
|
|
1033
995
|
expect(ensureAppServerMock).not.toHaveBeenCalled();
|
|
@@ -1040,7 +1002,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
1040
1002
|
// predating the current edge template (one serving no assistantId, which
|
|
1041
1003
|
// makes the identity probe degrade to always-healthy) must be rebuilt
|
|
1042
1004
|
// rather than carried across the wake at its recorded listen port.
|
|
1043
|
-
loadRawConfigMock.mockReturnValue(webhookConfig);
|
|
1044
1005
|
stampRecordedAppServer();
|
|
1045
1006
|
stampRecordedTunnel("ngrok");
|
|
1046
1007
|
isIngressRunningMock.mockReturnValue(true);
|
|
@@ -1064,7 +1025,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
1064
1025
|
// edge whose stop fails reports staleRemoteWebConfig; both throw while the
|
|
1065
1026
|
// edge keeps serving. Tunneling the gateway directly would put the
|
|
1066
1027
|
// sensitive-route denylist behind the tunnel instead of in front of it.
|
|
1067
|
-
loadRawConfigMock.mockReturnValue(webhookConfig);
|
|
1068
1028
|
stampRecordedAppServer();
|
|
1069
1029
|
stampRecordedTunnel("ngrok");
|
|
1070
1030
|
isIngressRunningMock.mockReturnValue(true);
|
|
@@ -1094,7 +1054,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
1094
1054
|
});
|
|
1095
1055
|
|
|
1096
1056
|
test("a failed rebuild falls back to the gateway port when the running edge fronts another gateway", async () => {
|
|
1097
|
-
loadRawConfigMock.mockReturnValue(webhookConfig);
|
|
1098
1057
|
stampRecordedAppServer();
|
|
1099
1058
|
stampRecordedTunnel("ngrok");
|
|
1100
1059
|
isIngressRunningMock.mockReturnValue(true);
|
|
@@ -1115,7 +1074,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
1115
1074
|
});
|
|
1116
1075
|
|
|
1117
1076
|
test("nginx-missing falls back to the gateway-port tunnel with a warning", async () => {
|
|
1118
|
-
loadRawConfigMock.mockReturnValue(webhookConfig);
|
|
1119
1077
|
stampRecordedAppServer();
|
|
1120
1078
|
stampRecordedTunnel("ngrok");
|
|
1121
1079
|
ensureAppServerMock.mockRejectedValue(
|
|
@@ -1144,7 +1102,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
1144
1102
|
});
|
|
1145
1103
|
|
|
1146
1104
|
test("a failed rebuild names the provider that last tunneled here", async () => {
|
|
1147
|
-
loadRawConfigMock.mockReturnValue(webhookConfig);
|
|
1148
1105
|
stampRecordedAppServer();
|
|
1149
1106
|
stampRecordedTunnel("cloudflare");
|
|
1150
1107
|
ensureAppServerMock.mockRejectedValue(new Error("edge rebuild failed"));
|
|
@@ -1159,18 +1116,8 @@ describe("cadet wake — app server restore", () => {
|
|
|
1159
1116
|
});
|
|
1160
1117
|
|
|
1161
1118
|
test("a failed rebuild names the record's tunnel, not the workspace's stale one", async () => {
|
|
1162
|
-
//
|
|
1163
|
-
//
|
|
1164
|
-
// this assistant: the root lockfile's record, never the workspace's.
|
|
1165
|
-
loadRawConfigMock.mockReturnValue({
|
|
1166
|
-
...webhookConfig,
|
|
1167
|
-
ingress: {
|
|
1168
|
-
lastTunnel: {
|
|
1169
|
-
provider: "cloudflare",
|
|
1170
|
-
publicBaseUrl: "https://assistant.example.com",
|
|
1171
|
-
},
|
|
1172
|
-
},
|
|
1173
|
-
});
|
|
1119
|
+
// The advice names the tunnel actually in front of this assistant: the
|
|
1120
|
+
// root lockfile's record, which is the only record there is.
|
|
1174
1121
|
stampRecordedAppServer();
|
|
1175
1122
|
// A pairing-only run published no ingress base URL — the record shape
|
|
1176
1123
|
// that says the tunnel in front is the tailnet serve.
|
|
@@ -1187,7 +1134,6 @@ describe("cadet wake — app server restore", () => {
|
|
|
1187
1134
|
});
|
|
1188
1135
|
|
|
1189
1136
|
test("a reused edge still points the tunnel at its listen port", async () => {
|
|
1190
|
-
loadRawConfigMock.mockReturnValue(enabledConfig);
|
|
1191
1137
|
stampRecordedAppServer();
|
|
1192
1138
|
stampRecordedTunnel("ngrok");
|
|
1193
1139
|
ensureAppServerMock.mockResolvedValue({
|
|
@@ -1,51 +1,6 @@
|
|
|
1
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { dirname, join } from "node:path";
|
|
3
|
-
|
|
4
1
|
import type { LockfileAssistant } from "./assistant-config.js";
|
|
5
|
-
import { resolveDataDir } from "@mycadet/local-mode";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Workspace-config helpers: where the machine-level default workspace lives
|
|
9
|
-
* and how its `config.json` is read. The tunnel layer writes none of it —
|
|
10
|
-
* tunnel state lives in the root lockfile's `tunnel` record.
|
|
11
|
-
*/
|
|
12
2
|
|
|
13
3
|
/** Container topologies whose gateway runs on this machine without host `resources`. */
|
|
14
4
|
export function isLocalContainerEntry(entry: LockfileAssistant): boolean {
|
|
15
5
|
return entry.cloud === "docker" || entry.cloud === "apple-container";
|
|
16
6
|
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Default workspace dir: `$CADET_WORKSPACE_DIR` or the XDG data root's
|
|
20
|
-
* workspace (`$XDG_DATA_HOME/cadet[-<env>]/workspace`).
|
|
21
|
-
*/
|
|
22
|
-
export function getDefaultWorkspaceDir(): string {
|
|
23
|
-
return (
|
|
24
|
-
process.env.CADET_WORKSPACE_DIR?.trim() ||
|
|
25
|
-
join(resolveDataDir(), "workspace")
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getConfigPath(workspaceDir: string): string {
|
|
30
|
-
return join(workspaceDir, "config.json");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Read the workspace `config.json`, or an empty object when it is absent. */
|
|
34
|
-
export function loadRawConfig(workspaceDir: string): Record<string, unknown> {
|
|
35
|
-
const configPath = getConfigPath(workspaceDir);
|
|
36
|
-
if (!existsSync(configPath)) return {};
|
|
37
|
-
return JSON.parse(readFileSync(configPath, "utf-8")) as Record<
|
|
38
|
-
string,
|
|
39
|
-
unknown
|
|
40
|
-
>;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/** Write the workspace `config.json`, creating parent directories as needed. */
|
|
44
|
-
export function saveRawConfig(
|
|
45
|
-
workspaceDir: string,
|
|
46
|
-
config: Record<string, unknown>,
|
|
47
|
-
): void {
|
|
48
|
-
const configPath = getConfigPath(workspaceDir);
|
|
49
|
-
mkdirSync(dirname(configPath), { recursive: true });
|
|
50
|
-
writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
51
|
-
}
|
|
@@ -31,12 +31,6 @@ export function persistRootSigningKey(root: string, key: string): void {
|
|
|
31
31
|
rmSync(target, { recursive: true });
|
|
32
32
|
}
|
|
33
33
|
renameSync(temporary, target);
|
|
34
|
-
// The persisted key is the identity: a deprecated migration-source copy
|
|
35
|
-
// is stale the moment a replacement lands, and leaving it would read as
|
|
36
|
-
// a conflict on the next resolve.
|
|
37
|
-
rmSync(join(root, "workspace", "deprecated", "actor-token-signing-key"), {
|
|
38
|
-
force: true,
|
|
39
|
-
});
|
|
40
34
|
} finally {
|
|
41
35
|
rmSync(temporary, { force: true });
|
|
42
36
|
}
|
package/src/lib/tunnel.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { join } from "path";
|
|
3
2
|
import { TUNNEL_PROVIDERS } from "@mycadet/service-contracts/ingress";
|
|
4
3
|
import {
|
|
5
4
|
clearRootProcess,
|
|
@@ -15,10 +14,7 @@ import {
|
|
|
15
14
|
getLoopbackGatewayPort,
|
|
16
15
|
} from "@mycadet/local-mode/contract";
|
|
17
16
|
|
|
18
|
-
import {
|
|
19
|
-
getDefaultWorkspaceDir,
|
|
20
|
-
isLocalContainerEntry,
|
|
21
|
-
} from "./ingress-config.js";
|
|
17
|
+
import { isLocalContainerEntry } from "./ingress-config.js";
|
|
22
18
|
import {
|
|
23
19
|
ensureAppServer,
|
|
24
20
|
getNginxIngressPort,
|
|
@@ -201,7 +197,6 @@ const providerNameSchema = z.enum(TUNNEL_PROVIDERS);
|
|
|
201
197
|
export interface LocalTunnelTarget {
|
|
202
198
|
entry: LockfileAssistant;
|
|
203
199
|
gatewayPort: number;
|
|
204
|
-
workspaceDir: string;
|
|
205
200
|
}
|
|
206
201
|
|
|
207
202
|
/**
|
|
@@ -216,16 +211,12 @@ export function toLocalTunnelTarget(
|
|
|
216
211
|
entry: LockfileAssistant,
|
|
217
212
|
): LocalTunnelTarget | null {
|
|
218
213
|
if (entry.resources?.instanceDir) {
|
|
219
|
-
return {
|
|
220
|
-
entry,
|
|
221
|
-
gatewayPort: entry.resources.gatewayPort,
|
|
222
|
-
workspaceDir: join(entry.resources.instanceDir, "workspace"),
|
|
223
|
-
};
|
|
214
|
+
return { entry, gatewayPort: entry.resources.gatewayPort };
|
|
224
215
|
}
|
|
225
216
|
if (isLocalContainerEntry(entry)) {
|
|
226
217
|
const gatewayPort = getLoopbackGatewayPort(entry);
|
|
227
218
|
if (gatewayPort !== undefined) {
|
|
228
|
-
return { entry, gatewayPort
|
|
219
|
+
return { entry, gatewayPort };
|
|
229
220
|
}
|
|
230
221
|
}
|
|
231
222
|
return null;
|