@mycadet/cli 0.13.0-dev.202610270211.c5ac091 → 0.13.0-dev.202610280329.ad222b0
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/__tests__/environment.test.ts +1 -1
- package/node_modules/@mycadet/local-mode/src/__tests__/gateway-proxy.test.ts +60 -79
- package/node_modules/@mycadet/local-mode/src/__tests__/guardian-token-refresh.test.ts +5 -25
- package/node_modules/@mycadet/local-mode/src/__tests__/guardian-token.test.ts +40 -70
- package/node_modules/@mycadet/local-mode/src/__tests__/loopback-auth.test.ts +21 -15
- package/node_modules/@mycadet/local-mode/src/__tests__/pair.test.ts +175 -299
- package/node_modules/@mycadet/local-mode/src/__tests__/status.test.ts +24 -24
- package/node_modules/@mycadet/local-mode/src/__tests__/unpair.test.ts +24 -25
- package/node_modules/@mycadet/local-mode/src/avatar.test.ts +7 -6
- package/node_modules/@mycadet/local-mode/src/avatar.ts +1 -2
- package/node_modules/@mycadet/local-mode/src/config.ts +6 -6
- package/node_modules/@mycadet/local-mode/src/gateway-proxy.ts +6 -5
- package/node_modules/@mycadet/local-mode/src/guardian-token.ts +4 -7
- package/node_modules/@mycadet/local-mode/src/index.ts +1 -5
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +13 -38
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +31 -54
- package/node_modules/@mycadet/local-mode/src/lockfile-lock.test.ts +30 -19
- package/node_modules/@mycadet/local-mode/src/lockfile-lock.ts +4 -6
- package/node_modules/@mycadet/local-mode/src/lockfile.test.ts +95 -229
- package/node_modules/@mycadet/local-mode/src/lockfile.ts +48 -160
- package/node_modules/@mycadet/local-mode/src/pair.ts +49 -226
- package/node_modules/@mycadet/local-mode/src/served-config.test.ts +1 -3
- package/node_modules/@mycadet/local-mode/src/status.ts +3 -18
- package/node_modules/@mycadet/local-mode/src/unpair.ts +66 -86
- 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__/app-command.test.ts +3 -8
- package/src/__tests__/assistant-client-cloud-auth.test.ts +10 -2
- package/src/__tests__/assistant-client-refresh.test.ts +0 -2
- package/src/__tests__/assistant-config.test.ts +22 -21
- package/src/__tests__/backup.test.ts +0 -4
- package/src/__tests__/client-tui-refresh.test.ts +12 -11
- package/src/__tests__/connect-import.test.ts +3 -42
- package/src/__tests__/debug.test.ts +1 -1
- package/src/__tests__/devices.test.ts +3 -5
- package/src/__tests__/gateway-token.test.ts +0 -2
- package/src/__tests__/guardian-token.test.ts +7 -22
- package/src/__tests__/host-teleport-docker.test.ts +10 -19
- package/src/__tests__/host-teleport.test.ts +0 -1
- package/src/__tests__/multi-local.test.ts +0 -3
- package/src/__tests__/nginx-ingress.test.ts +313 -443
- package/src/__tests__/ps-cloud-status.test.ts +3 -7
- package/src/__tests__/restore.test.ts +0 -1
- package/src/__tests__/root-backup-docker.test.ts +0 -1
- package/src/__tests__/root-backup.test.ts +0 -1
- package/src/__tests__/root-restore-command.test.ts +3 -4
- package/src/__tests__/runtime-url.test.ts +5 -21
- package/src/__tests__/setup.test.ts +49 -20
- package/src/__tests__/teleport.test.ts +0 -1
- package/src/__tests__/tui-midsession-refresh.test.ts +13 -8
- package/src/__tests__/tunnel-stop.test.ts +0 -1
- package/src/__tests__/tunnel.test.ts +42 -87
- package/src/__tests__/upgrade-local.test.ts +0 -1
- package/src/__tests__/upgrade-root-recovery.test.ts +5 -5
- package/src/__tests__/wake.test.ts +21 -51
- package/src/commands/app.ts +16 -48
- package/src/commands/completions.test.ts +0 -1
- package/src/commands/connect/import.ts +26 -57
- package/src/commands/ps.ts +6 -20
- package/src/commands/retire.ts +1 -4
- package/src/commands/sleep.ts +1 -1
- package/src/commands/tunnel.ts +4 -6
- package/src/commands/upgrade.ts +1 -11
- package/src/commands/wake.ts +1 -6
- package/src/lib/__tests__/port-heal.test.ts +2 -3
- package/src/lib/__tests__/runtime-url.test.ts +0 -1
- package/src/lib/assistant-config.ts +2 -4
- package/src/lib/guardian-token.ts +4 -4
- package/src/lib/hatch-local.ts +142 -147
- package/src/lib/host-teleport.ts +4 -1
- package/src/lib/local.ts +1 -1
- package/src/lib/nginx-ingress.ts +159 -175
- package/src/lib/retire-local.ts +1 -1
- package/src/lib/sync-cloud-assistants.ts +0 -1
- package/src/lib/tunnel.ts +46 -52
|
@@ -217,7 +217,7 @@ describe("Windows path resolution", () => {
|
|
|
217
217
|
expect(() => resolveInstanceDir(assistantId)).toThrow(
|
|
218
218
|
"Invalid assistant ID",
|
|
219
219
|
);
|
|
220
|
-
expect(() => guardianTokenPath(
|
|
220
|
+
expect(() => guardianTokenPath(assistantId)).toThrow(
|
|
221
221
|
"Invalid assistant ID",
|
|
222
222
|
);
|
|
223
223
|
}
|
|
@@ -3,6 +3,7 @@ import fs from "node:fs";
|
|
|
3
3
|
import os from "node:os";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
|
|
6
|
+
import { GATEWAY_PORT } from "../lockfile-contract";
|
|
6
7
|
import {
|
|
7
8
|
authorizePairedForwardHeaders,
|
|
8
9
|
gatewayTargetsFromLockfile,
|
|
@@ -192,26 +193,27 @@ describe("resolveGatewayProxyTarget", () => {
|
|
|
192
193
|
});
|
|
193
194
|
|
|
194
195
|
describe("gatewayTargetsFromLockfile", () => {
|
|
195
|
-
test("resolves a paired entry
|
|
196
|
+
test("resolves a paired entry's custom addressing to a remote target", () => {
|
|
196
197
|
expect(
|
|
197
198
|
gatewayTargetsFromLockfile({
|
|
198
199
|
assistants: [
|
|
199
200
|
{
|
|
200
201
|
assistantId: "abc-123",
|
|
201
|
-
|
|
202
|
-
|
|
202
|
+
cloud: "custom",
|
|
203
|
+
ipAddress: "gw.example.com",
|
|
204
|
+
port: 443,
|
|
203
205
|
},
|
|
204
206
|
],
|
|
205
207
|
}),
|
|
206
208
|
).toEqual(targets({ "abc-123": remote("https://gw.example.com") })());
|
|
207
209
|
});
|
|
208
210
|
|
|
209
|
-
test("omits
|
|
211
|
+
test("omits loopback entries with no recorded port beyond the default's loopback form", () => {
|
|
210
212
|
expect(
|
|
211
213
|
gatewayTargetsFromLockfile({
|
|
212
214
|
assistants: [
|
|
213
|
-
{ assistantId: "abc-123",
|
|
214
|
-
{ assistantId: "def-456",
|
|
215
|
+
{ assistantId: "abc-123", cloud: "custom" },
|
|
216
|
+
{ assistantId: "def-456", cloud: "cloud" },
|
|
215
217
|
],
|
|
216
218
|
}),
|
|
217
219
|
).toEqual(new Map());
|
|
@@ -231,42 +233,12 @@ describe("gatewayTargetsFromLockfile", () => {
|
|
|
231
233
|
).toEqual(targets({ "abc-123": loopback(8080) })());
|
|
232
234
|
});
|
|
233
235
|
|
|
234
|
-
test("
|
|
236
|
+
test("a docker entry without a recorded port derives the default gateway port", () => {
|
|
235
237
|
expect(
|
|
236
238
|
gatewayTargetsFromLockfile({
|
|
237
|
-
assistants: [
|
|
238
|
-
{
|
|
239
|
-
assistantId: "abc-123",
|
|
240
|
-
cloud: "docker",
|
|
241
|
-
runtimeUrl: "http://127.0.0.1:9000",
|
|
242
|
-
},
|
|
243
|
-
],
|
|
239
|
+
assistants: [{ assistantId: "abc-123", cloud: "docker" }],
|
|
244
240
|
}),
|
|
245
|
-
).toEqual(new Map([["abc-123", loopback(
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
test("resolves a loopback-cloud entry whose runtimeUrl is remote as paired", () => {
|
|
249
|
-
// Paired-ness derives from the addressing (no stored flag): a
|
|
250
|
-
// loopback-gateway cloud whose runtimeUrl points off-machine is a
|
|
251
|
-
// connect import, so it targets that remote runtimeUrl.
|
|
252
|
-
expect(
|
|
253
|
-
gatewayTargetsFromLockfile({
|
|
254
|
-
assistants: [
|
|
255
|
-
{
|
|
256
|
-
assistantId: "abc-123",
|
|
257
|
-
cloud: "local",
|
|
258
|
-
runtimeUrl: "https://elsewhere.example.com",
|
|
259
|
-
},
|
|
260
|
-
],
|
|
261
|
-
}),
|
|
262
|
-
).toEqual(
|
|
263
|
-
new Map([
|
|
264
|
-
[
|
|
265
|
-
"abc-123",
|
|
266
|
-
{ kind: "remote", runtimeUrl: "https://elsewhere.example.com" },
|
|
267
|
-
],
|
|
268
|
-
]),
|
|
269
|
-
);
|
|
241
|
+
).toEqual(new Map([["abc-123", loopback(GATEWAY_PORT)]]));
|
|
270
242
|
});
|
|
271
243
|
|
|
272
244
|
test("omits ports outside the 1024-65535 proxy range", () => {
|
|
@@ -281,7 +253,7 @@ describe("gatewayTargetsFromLockfile", () => {
|
|
|
281
253
|
{
|
|
282
254
|
assistantId: "def-456",
|
|
283
255
|
cloud: "docker",
|
|
284
|
-
|
|
256
|
+
resources: { gatewayPort: 70000 },
|
|
285
257
|
},
|
|
286
258
|
],
|
|
287
259
|
}),
|
|
@@ -293,31 +265,29 @@ describe("gatewayTargetsFromLockfile", () => {
|
|
|
293
265
|
gatewayTargetsFromLockfile({
|
|
294
266
|
assistants: [
|
|
295
267
|
{ assistantId: "a", cloud: "cloud" },
|
|
296
|
-
|
|
297
|
-
//
|
|
298
|
-
|
|
299
|
-
{ assistantId: "d", cloud: "gcp" },
|
|
268
|
+
// A retired spelling parses as "local": loopback-gated, so it
|
|
269
|
+
// derives the default loopback port rather than being omitted.
|
|
270
|
+
{ assistantId: "b", cloud: "gcp" },
|
|
300
271
|
],
|
|
301
272
|
}),
|
|
302
|
-
).toEqual(new Map());
|
|
273
|
+
).toEqual(new Map([["b", { kind: "loopback", port: GATEWAY_PORT }]]));
|
|
303
274
|
});
|
|
304
275
|
|
|
305
|
-
test("a custom entry's
|
|
306
|
-
// Targeting keys on the addressing alone: an entry whose runtimeUrl
|
|
307
|
-
// points off this machine resolves as remote, whatever its cloud says.
|
|
276
|
+
test("a custom entry's recorded addressing is targetable", () => {
|
|
308
277
|
expect(
|
|
309
278
|
gatewayTargetsFromLockfile({
|
|
310
279
|
assistants: [
|
|
311
280
|
{
|
|
312
281
|
assistantId: "c",
|
|
313
282
|
cloud: "custom",
|
|
314
|
-
|
|
283
|
+
ipAddress: "gw.example.com",
|
|
284
|
+
port: 7831,
|
|
315
285
|
},
|
|
316
286
|
],
|
|
317
287
|
}),
|
|
318
288
|
).toEqual(
|
|
319
289
|
new Map([
|
|
320
|
-
["c", { kind: "remote", runtimeUrl: "https://gw.example.com" }],
|
|
290
|
+
["c", { kind: "remote", runtimeUrl: "https://gw.example.com:7831" }],
|
|
321
291
|
]),
|
|
322
292
|
);
|
|
323
293
|
});
|
|
@@ -342,27 +312,41 @@ describe("gatewayTargetsFromLockfile", () => {
|
|
|
342
312
|
});
|
|
343
313
|
|
|
344
314
|
describe("readGatewayTargets", () => {
|
|
345
|
-
|
|
315
|
+
// The reader resolves its path from the environment; a per-test XDG home
|
|
316
|
+
// points it at the fixture's cadet dir.
|
|
317
|
+
const withAmbientLockfile = (
|
|
318
|
+
write: (lockfilePath: string) => void,
|
|
319
|
+
): string => {
|
|
346
320
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "gateway-proxy-"));
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
321
|
+
process.env.XDG_CONFIG_HOME = dir;
|
|
322
|
+
const lockfilePath = path.join(dir, "cadet", "lockfile.json");
|
|
323
|
+
fs.mkdirSync(path.dirname(lockfilePath), { recursive: true });
|
|
324
|
+
write(lockfilePath);
|
|
325
|
+
return dir;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
test("reads the id-keyed target map from disk", () => {
|
|
329
|
+
const dir = withAmbientLockfile((lockfilePath) =>
|
|
330
|
+
fs.writeFileSync(
|
|
331
|
+
lockfilePath,
|
|
332
|
+
JSON.stringify({
|
|
333
|
+
assistants: [
|
|
334
|
+
{
|
|
335
|
+
assistantId: "abc-123",
|
|
336
|
+
cloud: "local",
|
|
337
|
+
resources: { gatewayPort: 8080, daemonPort: 8501 },
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
assistantId: "def-456",
|
|
341
|
+
cloud: "custom",
|
|
342
|
+
ipAddress: "gw.example.com",
|
|
343
|
+
port: 443,
|
|
344
|
+
},
|
|
345
|
+
],
|
|
346
|
+
}),
|
|
347
|
+
),
|
|
364
348
|
);
|
|
365
|
-
expect(readGatewayTargets(
|
|
349
|
+
expect(readGatewayTargets()).toEqual(
|
|
366
350
|
targets({
|
|
367
351
|
"abc-123": loopback(8080),
|
|
368
352
|
"def-456": remote("https://gw.example.com"),
|
|
@@ -372,21 +356,18 @@ describe("readGatewayTargets", () => {
|
|
|
372
356
|
});
|
|
373
357
|
|
|
374
358
|
test("an empty lockfile yields an empty map", () => {
|
|
375
|
-
const dir =
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
expect(readGatewayTargets(
|
|
359
|
+
const dir = withAmbientLockfile((lockfilePath) =>
|
|
360
|
+
fs.writeFileSync(lockfilePath, JSON.stringify({ assistants: [] })),
|
|
361
|
+
);
|
|
362
|
+
expect(readGatewayTargets()).toEqual(new Map());
|
|
379
363
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
380
364
|
});
|
|
381
365
|
|
|
382
366
|
test("an unreadable or absent lockfile yields an empty map", () => {
|
|
383
|
-
const dir =
|
|
384
|
-
|
|
385
|
-
fs.writeFileSync(unreadable, "{ not json");
|
|
386
|
-
expect(readGatewayTargets(unreadable)).toEqual(new Map());
|
|
387
|
-
expect(readGatewayTargets(path.join(dir, "absent.json"))).toEqual(
|
|
388
|
-
new Map(),
|
|
367
|
+
const dir = withAmbientLockfile((lockfilePath) =>
|
|
368
|
+
fs.writeFileSync(lockfilePath, "{ not json"),
|
|
389
369
|
);
|
|
370
|
+
expect(readGatewayTargets()).toEqual(new Map());
|
|
390
371
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
391
372
|
});
|
|
392
373
|
});
|
|
@@ -64,7 +64,7 @@ describe("getGuardianAccessToken refresh spawn", () => {
|
|
|
64
64
|
|
|
65
65
|
beforeEach(() => {
|
|
66
66
|
configDir = fs.mkdtempSync(path.join(os.tmpdir(), "guardian-refresh-"));
|
|
67
|
-
saveGuardianToken(
|
|
67
|
+
saveGuardianToken("asst-1", makeTokenData({}));
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
afterEach(() => {
|
|
@@ -72,12 +72,7 @@ describe("getGuardianAccessToken refresh spawn", () => {
|
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
test("a labeled CLI 503 is an unreachable gateway, not a spent token", async () => {
|
|
75
|
-
const pending = getGuardianAccessToken(
|
|
76
|
-
"asst-1",
|
|
77
|
-
configDir,
|
|
78
|
-
invocation,
|
|
79
|
-
true,
|
|
80
|
-
);
|
|
75
|
+
const pending = getGuardianAccessToken("asst-1", invocation, true);
|
|
81
76
|
await tick();
|
|
82
77
|
lastChild.stderr.emit(
|
|
83
78
|
"data",
|
|
@@ -95,12 +90,7 @@ describe("getGuardianAccessToken refresh spawn", () => {
|
|
|
95
90
|
});
|
|
96
91
|
|
|
97
92
|
test("a labeled CLI 401 is a spent credential", async () => {
|
|
98
|
-
const pending = getGuardianAccessToken(
|
|
99
|
-
"asst-1",
|
|
100
|
-
configDir,
|
|
101
|
-
invocation,
|
|
102
|
-
true,
|
|
103
|
-
);
|
|
93
|
+
const pending = getGuardianAccessToken("asst-1", invocation, true);
|
|
104
94
|
await tick();
|
|
105
95
|
lastChild.stderr.emit(
|
|
106
96
|
"data",
|
|
@@ -118,12 +108,7 @@ describe("getGuardianAccessToken refresh spawn", () => {
|
|
|
118
108
|
});
|
|
119
109
|
|
|
120
110
|
test("a labeled CLI 403 is a local confidentiality refusal, not a spent credential", async () => {
|
|
121
|
-
const pending = getGuardianAccessToken(
|
|
122
|
-
"asst-1",
|
|
123
|
-
configDir,
|
|
124
|
-
invocation,
|
|
125
|
-
true,
|
|
126
|
-
);
|
|
111
|
+
const pending = getGuardianAccessToken("asst-1", invocation, true);
|
|
127
112
|
await tick();
|
|
128
113
|
lastChild.stderr.emit(
|
|
129
114
|
"data",
|
|
@@ -141,12 +126,7 @@ describe("getGuardianAccessToken refresh spawn", () => {
|
|
|
141
126
|
});
|
|
142
127
|
|
|
143
128
|
test("an unlabeled non-zero CLI exit is a 503, not a 401", async () => {
|
|
144
|
-
const pending = getGuardianAccessToken(
|
|
145
|
-
"asst-1",
|
|
146
|
-
configDir,
|
|
147
|
-
invocation,
|
|
148
|
-
true,
|
|
149
|
-
);
|
|
129
|
+
const pending = getGuardianAccessToken("asst-1", invocation, true);
|
|
150
130
|
await tick();
|
|
151
131
|
lastChild.stderr.emit(
|
|
152
132
|
"data",
|
|
@@ -41,30 +41,38 @@ describe("getGuardianAccessToken", () => {
|
|
|
41
41
|
let configDir: string;
|
|
42
42
|
|
|
43
43
|
beforeEach(() => {
|
|
44
|
-
|
|
44
|
+
// The token paths resolve from the environment: XDG config home plus the
|
|
45
|
+
// production environment dir, so the fixture points XDG at the tmp home
|
|
46
|
+
// and reads back through the same ambient resolution.
|
|
47
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), "guardian-token-test-"));
|
|
48
|
+
process.env.XDG_CONFIG_HOME = home;
|
|
49
|
+
configDir = path.join(home, "cadet");
|
|
45
50
|
});
|
|
46
51
|
|
|
47
52
|
afterEach(() => {
|
|
48
|
-
|
|
53
|
+
Reflect.deleteProperty(process.env, "XDG_CONFIG_HOME");
|
|
54
|
+
fs.rmSync(path.dirname(configDir), { recursive: true, force: true });
|
|
49
55
|
});
|
|
50
56
|
|
|
51
57
|
test("returns the stored token while the access token is fresh", async () => {
|
|
52
|
-
saveGuardianToken(
|
|
58
|
+
saveGuardianToken("asst-1", makeTokenData({}));
|
|
53
59
|
|
|
54
|
-
expect(
|
|
55
|
-
|
|
56
|
-
|
|
60
|
+
expect(await getGuardianAccessToken("asst-1", invocation, true)).toEqual({
|
|
61
|
+
ok: true,
|
|
62
|
+
accessToken: "access",
|
|
63
|
+
});
|
|
57
64
|
});
|
|
58
65
|
|
|
59
66
|
test("returns a structured 404 when no token file exists", async () => {
|
|
60
|
-
expect(
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
expect(await getGuardianAccessToken("missing", invocation, true)).toEqual({
|
|
68
|
+
ok: false,
|
|
69
|
+
status: 404,
|
|
70
|
+
error: "Guardian token not found",
|
|
71
|
+
});
|
|
63
72
|
});
|
|
64
73
|
|
|
65
74
|
test("expired refresh token yields hatch/wake guidance by default", async () => {
|
|
66
75
|
saveGuardianToken(
|
|
67
|
-
configDir,
|
|
68
76
|
"asst-1",
|
|
69
77
|
makeTokenData({
|
|
70
78
|
accessTokenExpiresAt: PAST,
|
|
@@ -72,12 +80,7 @@ describe("getGuardianAccessToken", () => {
|
|
|
72
80
|
}),
|
|
73
81
|
);
|
|
74
82
|
|
|
75
|
-
const result = await getGuardianAccessToken(
|
|
76
|
-
"asst-1",
|
|
77
|
-
configDir,
|
|
78
|
-
invocation,
|
|
79
|
-
true,
|
|
80
|
-
);
|
|
83
|
+
const result = await getGuardianAccessToken("asst-1", invocation, true);
|
|
81
84
|
|
|
82
85
|
expect(result).toEqual({
|
|
83
86
|
ok: false,
|
|
@@ -88,7 +91,6 @@ describe("getGuardianAccessToken", () => {
|
|
|
88
91
|
|
|
89
92
|
test("expired refresh token yields re-pair guidance for a paired entry", async () => {
|
|
90
93
|
saveGuardianToken(
|
|
91
|
-
configDir,
|
|
92
94
|
"asst-1",
|
|
93
95
|
makeTokenData({
|
|
94
96
|
accessTokenExpiresAt: PAST,
|
|
@@ -96,16 +98,10 @@ describe("getGuardianAccessToken", () => {
|
|
|
96
98
|
}),
|
|
97
99
|
);
|
|
98
100
|
|
|
99
|
-
const result = await getGuardianAccessToken(
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
true,
|
|
104
|
-
{
|
|
105
|
-
paired: true,
|
|
106
|
-
pairedGatewayUrl: "https://gateway.example.com",
|
|
107
|
-
},
|
|
108
|
-
);
|
|
101
|
+
const result = await getGuardianAccessToken("asst-1", invocation, true, {
|
|
102
|
+
paired: true,
|
|
103
|
+
pairedGatewayUrl: "https://gateway.example.com",
|
|
104
|
+
});
|
|
109
105
|
|
|
110
106
|
expect(result).toEqual({
|
|
111
107
|
ok: false,
|
|
@@ -117,7 +113,6 @@ describe("getGuardianAccessToken", () => {
|
|
|
117
113
|
|
|
118
114
|
test("an explicit paired: false keeps the hatch/wake guidance", async () => {
|
|
119
115
|
saveGuardianToken(
|
|
120
|
-
configDir,
|
|
121
116
|
"asst-1",
|
|
122
117
|
makeTokenData({
|
|
123
118
|
accessTokenExpiresAt: PAST,
|
|
@@ -125,13 +120,9 @@ describe("getGuardianAccessToken", () => {
|
|
|
125
120
|
}),
|
|
126
121
|
);
|
|
127
122
|
|
|
128
|
-
const result = await getGuardianAccessToken(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
invocation,
|
|
132
|
-
true,
|
|
133
|
-
{ paired: false },
|
|
134
|
-
);
|
|
123
|
+
const result = await getGuardianAccessToken("asst-1", invocation, true, {
|
|
124
|
+
paired: false,
|
|
125
|
+
});
|
|
135
126
|
|
|
136
127
|
expect(result.ok).toBe(false);
|
|
137
128
|
if (result.ok) {
|
|
@@ -142,62 +133,41 @@ describe("getGuardianAccessToken", () => {
|
|
|
142
133
|
|
|
143
134
|
test("returns a paired token only for its stored gateway target", async () => {
|
|
144
135
|
saveGuardianToken(
|
|
145
|
-
configDir,
|
|
146
136
|
"paired-1",
|
|
147
137
|
makeTokenData({ pairedGatewayUrl: "https://gateway.example.com" }),
|
|
148
138
|
);
|
|
149
139
|
|
|
150
|
-
expect(
|
|
151
|
-
await getGuardianAccessToken("paired-1", configDir, invocation, true),
|
|
152
|
-
).toEqual({
|
|
140
|
+
expect(await getGuardianAccessToken("paired-1", invocation, true)).toEqual({
|
|
153
141
|
ok: false,
|
|
154
142
|
status: 403,
|
|
155
143
|
error: PAIRED_GUARDIAN_TOKEN_HOST_ONLY_ERROR,
|
|
156
144
|
});
|
|
157
145
|
expect(
|
|
158
|
-
await getGuardianAccessToken(
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
true,
|
|
163
|
-
{
|
|
164
|
-
paired: true,
|
|
165
|
-
pairedGatewayUrl: "https://attacker.example.com",
|
|
166
|
-
},
|
|
167
|
-
),
|
|
146
|
+
await getGuardianAccessToken("paired-1", invocation, true, {
|
|
147
|
+
paired: true,
|
|
148
|
+
pairedGatewayUrl: "https://attacker.example.com",
|
|
149
|
+
}),
|
|
168
150
|
).toEqual({
|
|
169
151
|
ok: false,
|
|
170
152
|
status: 403,
|
|
171
153
|
error: PAIRED_GUARDIAN_TARGET_MISMATCH_ERROR,
|
|
172
154
|
});
|
|
173
155
|
expect(
|
|
174
|
-
await getGuardianAccessToken(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
true,
|
|
179
|
-
{
|
|
180
|
-
paired: true,
|
|
181
|
-
pairedGatewayUrl: "https://gateway.example.com",
|
|
182
|
-
},
|
|
183
|
-
),
|
|
156
|
+
await getGuardianAccessToken("paired-1", invocation, true, {
|
|
157
|
+
paired: true,
|
|
158
|
+
pairedGatewayUrl: "https://gateway.example.com",
|
|
159
|
+
}),
|
|
184
160
|
).toEqual({ ok: true, accessToken: "access" });
|
|
185
161
|
});
|
|
186
162
|
|
|
187
163
|
test("binds a legacy paired token before returning it", async () => {
|
|
188
|
-
saveGuardianToken(
|
|
164
|
+
saveGuardianToken("paired-1", makeTokenData({}));
|
|
189
165
|
|
|
190
166
|
expect(
|
|
191
|
-
await getGuardianAccessToken(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
true,
|
|
196
|
-
{
|
|
197
|
-
paired: true,
|
|
198
|
-
pairedGatewayUrl: "https://gateway.example.com",
|
|
199
|
-
},
|
|
200
|
-
),
|
|
167
|
+
await getGuardianAccessToken("paired-1", invocation, true, {
|
|
168
|
+
paired: true,
|
|
169
|
+
pairedGatewayUrl: "https://gateway.example.com",
|
|
170
|
+
}),
|
|
201
171
|
).toEqual({ ok: true, accessToken: "access" });
|
|
202
172
|
|
|
203
173
|
const stored = JSON.parse(
|
|
@@ -105,59 +105,65 @@ describe("isActiveAssistant", () => {
|
|
|
105
105
|
|
|
106
106
|
test("returns true for the active assistant", () => {
|
|
107
107
|
const dir = makeTempDir();
|
|
108
|
-
|
|
108
|
+
process.env.XDG_CONFIG_HOME = dir;
|
|
109
|
+
fs.mkdirSync(path.join(dir, "cadet"), { recursive: true });
|
|
109
110
|
fs.writeFileSync(
|
|
110
|
-
|
|
111
|
+
path.join(dir, "cadet", "lockfile.json"),
|
|
111
112
|
JSON.stringify({
|
|
112
113
|
assistants: [{ assistantId: "active" }, { assistantId: "inactive" }],
|
|
113
114
|
activeAssistant: "active",
|
|
114
115
|
}),
|
|
115
116
|
);
|
|
116
|
-
expect(isActiveAssistant(
|
|
117
|
+
expect(isActiveAssistant("active")).toBe(true);
|
|
117
118
|
});
|
|
118
119
|
|
|
119
120
|
test("returns true for the sole assistant when activeAssistant is empty", () => {
|
|
120
121
|
const dir = makeTempDir();
|
|
121
|
-
|
|
122
|
+
process.env.XDG_CONFIG_HOME = dir;
|
|
123
|
+
fs.mkdirSync(path.join(dir, "cadet"), { recursive: true });
|
|
122
124
|
fs.writeFileSync(
|
|
123
|
-
|
|
125
|
+
path.join(dir, "cadet", "lockfile.json"),
|
|
124
126
|
JSON.stringify({
|
|
125
127
|
assistants: [{ assistantId: "only" }],
|
|
126
128
|
activeAssistant: null,
|
|
127
129
|
}),
|
|
128
130
|
);
|
|
129
|
-
expect(isActiveAssistant(
|
|
131
|
+
expect(isActiveAssistant("only")).toBe(true);
|
|
130
132
|
});
|
|
131
133
|
|
|
132
134
|
test("returns true for the sole assistant when activeAssistant is stale", () => {
|
|
133
135
|
const dir = makeTempDir();
|
|
134
|
-
|
|
136
|
+
process.env.XDG_CONFIG_HOME = dir;
|
|
137
|
+
fs.mkdirSync(path.join(dir, "cadet"), { recursive: true });
|
|
135
138
|
fs.writeFileSync(
|
|
136
|
-
|
|
139
|
+
path.join(dir, "cadet", "lockfile.json"),
|
|
137
140
|
JSON.stringify({
|
|
138
141
|
assistants: [{ assistantId: "only" }],
|
|
139
142
|
activeAssistant: "missing",
|
|
140
143
|
}),
|
|
141
144
|
);
|
|
142
|
-
expect(isActiveAssistant(
|
|
145
|
+
expect(isActiveAssistant("only")).toBe(true);
|
|
143
146
|
});
|
|
144
147
|
|
|
145
148
|
test("returns false for a non-active assistant", () => {
|
|
146
149
|
const dir = makeTempDir();
|
|
147
|
-
|
|
150
|
+
process.env.XDG_CONFIG_HOME = dir;
|
|
151
|
+
fs.mkdirSync(path.join(dir, "cadet"), { recursive: true });
|
|
148
152
|
fs.writeFileSync(
|
|
149
|
-
|
|
153
|
+
path.join(dir, "cadet", "lockfile.json"),
|
|
150
154
|
JSON.stringify({
|
|
151
155
|
assistants: [{ assistantId: "active" }, { assistantId: "inactive" }],
|
|
152
156
|
activeAssistant: "active",
|
|
153
157
|
}),
|
|
154
158
|
);
|
|
155
|
-
expect(isActiveAssistant(
|
|
159
|
+
expect(isActiveAssistant("inactive")).toBe(false);
|
|
156
160
|
});
|
|
157
161
|
|
|
158
162
|
test("returns false when lockfile does not exist", () => {
|
|
159
|
-
expect(isActiveAssistant("
|
|
160
|
-
|
|
161
|
-
|
|
163
|
+
expect(isActiveAssistant("any")).toBe(false);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
afterEach(() => {
|
|
167
|
+
Reflect.deleteProperty(process.env, "XDG_CONFIG_HOME");
|
|
162
168
|
});
|
|
163
169
|
});
|