@mycadet/cli 0.13.0-dev.202610261443.fed5783 → 0.13.0-dev.202610261745.ff07088
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/local-mode/src/index.ts +2 -1
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +2 -0
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +4 -0
- package/node_modules/@mycadet/local-mode/src/served-config.test.ts +77 -0
- package/node_modules/@mycadet/local-mode/src/served-config.ts +15 -0
- 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__/runtime-url.test.ts +67 -0
- package/src/__tests__/tailscale.test.ts +0 -44
- package/src/__tests__/tunnel.test.ts +124 -145
- package/src/__tests__/upgrade-local.test.ts +24 -11
- package/src/__tests__/wake.test.ts +20 -20
- package/src/lib/runtime-url.ts +21 -1
- package/src/lib/tunnel.ts +40 -25
- package/src/lib/tunnels/cloudflare.ts +132 -54
- package/src/lib/tunnels/ngrok.ts +83 -196
- package/src/lib/tunnels/tailscale.ts +11 -99
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mycadet/local-mode
|
|
2
|
+
* @mycadet/local-mode - shared host library for serving the local-assistant
|
|
3
3
|
* surface (lockfile reads, guardian-token issuance, gateway proxying, and the
|
|
4
4
|
* hatch/retire/wake lifecycle ops) over a loopback HTTP boundary. Consumed by the
|
|
5
5
|
* CLI `client` server and the web app's dev-server middleware so the local
|
|
@@ -55,6 +55,7 @@ export {
|
|
|
55
55
|
isActiveAssistant,
|
|
56
56
|
isPairedLockfileEntry,
|
|
57
57
|
} from "./lockfile";
|
|
58
|
+
export { servedConfigFromLockfile } from "./served-config";
|
|
58
59
|
export type { LockfileResult, WriteResult } from "./lockfile";
|
|
59
60
|
export { withLockfileLock } from "./lockfile-lock";
|
|
60
61
|
export type { LockfileLockResult } from "./lockfile-lock";
|
|
@@ -238,6 +238,10 @@ export const LockfileAssistantSchema = z.object({
|
|
|
238
238
|
name: z.string().optional(),
|
|
239
239
|
/** Deployment topology; absent or unknown on-disk values parse as "local". */
|
|
240
240
|
cloud: RemoteSchema.catch("local"),
|
|
241
|
+
/** Host address of a custom remote's gateway (cloud "custom"). */
|
|
242
|
+
ipAddress: z.string().optional(),
|
|
243
|
+
/** Gateway port on a custom remote (cloud "custom"). */
|
|
244
|
+
port: z.number().optional(),
|
|
241
245
|
runtimeUrl: z.string().optional(),
|
|
242
246
|
hatchedAt: z.string().optional(),
|
|
243
247
|
/**
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import type { Lockfile } from "./lockfile-contract";
|
|
4
|
+
import { servedConfigFromLockfile } from "./served-config";
|
|
5
|
+
|
|
6
|
+
describe("servedConfigFromLockfile", () => {
|
|
7
|
+
test("selects the active entry and exposes only public config fields", () => {
|
|
8
|
+
const lockfile: Lockfile = {
|
|
9
|
+
assistants: [
|
|
10
|
+
{ assistantId: "other", cloud: "local" },
|
|
11
|
+
{
|
|
12
|
+
assistantId: "active",
|
|
13
|
+
name: "Example Assistant",
|
|
14
|
+
cloud: "docker",
|
|
15
|
+
bearerToken: "example-host-token",
|
|
16
|
+
guardianBootstrapSecret: "example-bootstrap-secret",
|
|
17
|
+
resources: { gatewayPort: 7830, daemonPort: 7831 },
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
activeAssistant: "active",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
expect(servedConfigFromLockfile(lockfile)).toEqual({
|
|
24
|
+
assistantId: "active",
|
|
25
|
+
assistantName: "Example Assistant",
|
|
26
|
+
remote: "docker",
|
|
27
|
+
});
|
|
28
|
+
expect(lockfile.assistants[1]?.bearerToken).toBe("example-host-token");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("uses the sole entry when no active entry matches", () => {
|
|
32
|
+
expect(
|
|
33
|
+
servedConfigFromLockfile({
|
|
34
|
+
assistants: [{ assistantId: "sole", cloud: "local" }],
|
|
35
|
+
activeAssistant: "removed",
|
|
36
|
+
}).assistantId,
|
|
37
|
+
).toBe("sole");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("does not select an arbitrary entry from an ambiguous registry", () => {
|
|
41
|
+
expect(
|
|
42
|
+
servedConfigFromLockfile({
|
|
43
|
+
assistants: [
|
|
44
|
+
{ assistantId: "first", cloud: "local" },
|
|
45
|
+
{ assistantId: "second", cloud: "local" },
|
|
46
|
+
],
|
|
47
|
+
activeAssistant: null,
|
|
48
|
+
}).assistantId,
|
|
49
|
+
).toBeUndefined();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("an empty registry has no served assistant", () => {
|
|
53
|
+
expect(
|
|
54
|
+
servedConfigFromLockfile({ assistants: [], activeAssistant: null })
|
|
55
|
+
.assistantId,
|
|
56
|
+
).toBeUndefined();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("never exposes the guardian credential, even for a paired entry", () => {
|
|
60
|
+
const config = servedConfigFromLockfile({
|
|
61
|
+
assistants: [
|
|
62
|
+
{
|
|
63
|
+
assistantId: "paired",
|
|
64
|
+
cloud: "local",
|
|
65
|
+
runtimeUrl: "https://gateway.example.com",
|
|
66
|
+
bearerToken: "example-host-token",
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
activeAssistant: "paired",
|
|
70
|
+
});
|
|
71
|
+
expect(config.assistantId).toBe("paired");
|
|
72
|
+
expect(config.remote).toBe("local");
|
|
73
|
+
// The stamp carries public identity only - no runtime URL, no secrets.
|
|
74
|
+
expect(JSON.stringify(config)).not.toContain("example-host-token");
|
|
75
|
+
expect(JSON.stringify(config)).not.toContain("gateway.example.com");
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Lockfile } from "./lockfile-contract";
|
|
2
|
+
|
|
3
|
+
/** Public identity of the active assistant, or the sole entry before selection. */
|
|
4
|
+
export function servedConfigFromLockfile(lockfile: Lockfile) {
|
|
5
|
+
const served =
|
|
6
|
+
lockfile.assistants.find(
|
|
7
|
+
(assistant) => assistant.assistantId === lockfile.activeAssistant,
|
|
8
|
+
) ??
|
|
9
|
+
(lockfile.assistants.length === 1 ? lockfile.assistants[0] : undefined);
|
|
10
|
+
return {
|
|
11
|
+
assistantId: served?.assistantId,
|
|
12
|
+
assistantName: served?.name,
|
|
13
|
+
remote: served?.cloud,
|
|
14
|
+
};
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import { GATEWAY_PORT } from "../lib/constants.js";
|
|
4
|
+
import { getGatewayUrl } from "../lib/runtime-url.js";
|
|
5
|
+
import { getCloudUrl } from "../lib/cloud-client.js";
|
|
6
|
+
import type { LockfileAssistant } from "../lib/assistant-config.js";
|
|
7
|
+
|
|
8
|
+
const entry = (overrides: Partial<LockfileAssistant>): LockfileAssistant =>
|
|
9
|
+
({
|
|
10
|
+
assistantId: "asst_1",
|
|
11
|
+
...overrides,
|
|
12
|
+
}) as LockfileAssistant;
|
|
13
|
+
|
|
14
|
+
describe("getGatewayUrl", () => {
|
|
15
|
+
test("custom remotes derive from their recorded host and port", () => {
|
|
16
|
+
expect(
|
|
17
|
+
getGatewayUrl(
|
|
18
|
+
entry({ cloud: "custom", ipAddress: "203.0.113.7", port: 7830 }),
|
|
19
|
+
),
|
|
20
|
+
).toBe("http://203.0.113.7:7830");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("custom remotes with no recorded address fall back to the legacy runtimeUrl", () => {
|
|
24
|
+
expect(
|
|
25
|
+
getGatewayUrl(
|
|
26
|
+
entry({ cloud: "custom", runtimeUrl: "http://203.0.113.7:9000/" }),
|
|
27
|
+
),
|
|
28
|
+
).toBe("http://203.0.113.7:9000");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("cloud-managed entries dial the URL they were hatched under", () => {
|
|
32
|
+
expect(
|
|
33
|
+
getGatewayUrl(
|
|
34
|
+
entry({ cloud: "cloud", runtimeUrl: "https://cloud.example.com/" }),
|
|
35
|
+
),
|
|
36
|
+
).toBe("https://cloud.example.com");
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("cloud-managed entries without a recorded URL resolve through the environment stack", () => {
|
|
40
|
+
expect(getGatewayUrl(entry({ cloud: "cloud" }))).toBe(getCloudUrl());
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("loopback topologies derive from the recorded gateway port", () => {
|
|
44
|
+
expect(
|
|
45
|
+
getGatewayUrl(
|
|
46
|
+
entry({
|
|
47
|
+
cloud: "local",
|
|
48
|
+
resources: { gatewayPort: 7900, daemonPort: 7901 },
|
|
49
|
+
}),
|
|
50
|
+
),
|
|
51
|
+
).toBe("http://127.0.0.1:7900");
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("loopback topologies whose port lives only in a legacy loopback runtimeUrl still resolve", () => {
|
|
55
|
+
expect(
|
|
56
|
+
getGatewayUrl(
|
|
57
|
+
entry({ cloud: "docker", runtimeUrl: "http://127.0.0.1:7842" }),
|
|
58
|
+
),
|
|
59
|
+
).toBe("http://127.0.0.1:7842");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("an entry with nothing derives the default gateway port", () => {
|
|
63
|
+
expect(getGatewayUrl(entry({ cloud: "local" }))).toBe(
|
|
64
|
+
`http://127.0.0.1:${GATEWAY_PORT}`,
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -18,7 +18,6 @@ import {
|
|
|
18
18
|
shouldClearIngressUrl,
|
|
19
19
|
startTailscaleServe,
|
|
20
20
|
stopTailscaleServe,
|
|
21
|
-
TAILSCALE_PROVIDER,
|
|
22
21
|
type TailscaleCommandResult,
|
|
23
22
|
type TailscaleDeps,
|
|
24
23
|
} from "../lib/tunnels/tailscale.js";
|
|
@@ -360,46 +359,3 @@ describe("shouldClearIngressUrl", () => {
|
|
|
360
359
|
expect(shouldClearIngressUrl(null)).toBe(false);
|
|
361
360
|
});
|
|
362
361
|
});
|
|
363
|
-
|
|
364
|
-
describe("TAILSCALE_PROVIDER.start — the restore-path start piece", () => {
|
|
365
|
-
test("a pairing-only tailnet run leaves lastTunnel on the webhook provider, so nothing re-establishes", async () => {
|
|
366
|
-
const workspaceDir = makeWorkspace();
|
|
367
|
-
writeFileSync(
|
|
368
|
-
join(workspaceDir, "config.json"),
|
|
369
|
-
JSON.stringify({
|
|
370
|
-
ingress: {
|
|
371
|
-
enabled: true,
|
|
372
|
-
publicBaseUrl: "https://x.ngrok.app",
|
|
373
|
-
lastTunnel: {
|
|
374
|
-
provider: "ngrok",
|
|
375
|
-
publicBaseUrl: "https://x.ngrok.app",
|
|
376
|
-
},
|
|
377
|
-
},
|
|
378
|
-
}),
|
|
379
|
-
);
|
|
380
|
-
|
|
381
|
-
const url = await TAILSCALE_PROVIDER.start?.({
|
|
382
|
-
port: 7840,
|
|
383
|
-
workspaceDir,
|
|
384
|
-
assistantId: "assistant-1",
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
expect(url).toBeNull();
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
test("a workspace whose config never recorded a tunnel declines too", async () => {
|
|
391
|
-
const workspaceDir = makeWorkspace();
|
|
392
|
-
writeFileSync(
|
|
393
|
-
join(workspaceDir, "config.json"),
|
|
394
|
-
JSON.stringify({ ingress: { enabled: true } }),
|
|
395
|
-
);
|
|
396
|
-
|
|
397
|
-
const url = await TAILSCALE_PROVIDER.start?.({
|
|
398
|
-
port: 7840,
|
|
399
|
-
workspaceDir,
|
|
400
|
-
assistantId: "assistant-1",
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
expect(url).toBeNull();
|
|
404
|
-
});
|
|
405
|
-
});
|