@mycadet/gateway 0.13.0-dev.202611141959.760a53b → 0.13.0-dev.202611142107.f5e00a2

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.
Files changed (40) hide show
  1. package/package.json +1 -1
  2. package/src/__tests__/actor-token-revocation.test.ts +2 -1
  3. package/src/__tests__/channel-verification-session-proxy.test.ts +2 -1
  4. package/src/__tests__/contact-prompt-submit.test.ts +2 -1
  5. package/src/__tests__/contact-record-submit.test.ts +2 -1
  6. package/src/__tests__/contacts-control-plane-proxy.test.ts +2 -1
  7. package/src/__tests__/devices-mine.test.ts +2 -1
  8. package/src/__tests__/devices.test.ts +2 -3
  9. package/src/__tests__/edge-auth.test.ts +2 -4
  10. package/src/__tests__/guardian-bootstrap-lookups.test.ts +2 -1
  11. package/src/__tests__/helpers/signing-key.ts +27 -0
  12. package/src/__tests__/lum-2783-recovery-e2e.test.ts +2 -1
  13. package/src/__tests__/oauth-callback.test.ts +2 -1
  14. package/src/__tests__/pair-origin-allowlist.test.ts +2 -1
  15. package/src/__tests__/refresh-device-binding.test.ts +2 -1
  16. package/src/__tests__/remote-web-pairing-token.test.ts +2 -1
  17. package/src/__tests__/runtime-client.test.ts +2 -1
  18. package/src/__tests__/runtime-health-proxy.test.ts +2 -1
  19. package/src/__tests__/runtime-proxy-auth.test.ts +2 -1
  20. package/src/__tests__/runtime-proxy-device-stamp.test.ts +2 -1
  21. package/src/__tests__/runtime-proxy-error-body.test.ts +2 -1
  22. package/src/__tests__/runtime-proxy.test.ts +2 -1
  23. package/src/__tests__/runtime-stream-test-utils.ts +2 -1
  24. package/src/__tests__/shared-invite-redeem.test.ts +2 -1
  25. package/src/__tests__/slack-control-plane-proxy.test.ts +2 -1
  26. package/src/__tests__/telegram-control-plane-proxy.test.ts +2 -1
  27. package/src/__tests__/telegram-webhook-handler.test.ts +5 -2
  28. package/src/__tests__/test-preload.ts +21 -3
  29. package/src/__tests__/twilio-media-websocket.test.ts +2 -1
  30. package/src/__tests__/twilio-webhooks.test.ts +2 -1
  31. package/src/__tests__/whatsapp-webhook.test.ts +2 -1
  32. package/src/auth/token-service.ts +7 -18
  33. package/src/cli/__tests__/pairing.test.ts +2 -3
  34. package/src/cli/index.ts +7 -0
  35. package/src/cli/pairing.ts +33 -3
  36. package/src/http/routes/devices.ts +15 -2
  37. package/src/http/routes/ipc-runtime-proxy.test.ts +2 -1
  38. package/src/http/routes/plugin-webhook-websocket.test.ts +2 -1
  39. package/src/http/routes/plugin-webhook.test.ts +2 -1
  40. package/src/logger.ts +3 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/gateway",
3
- "version": "0.13.0-dev.202611141959.760a53b",
3
+ "version": "0.13.0-dev.202611142107.f5e00a2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/vargasjr-dev/mycadet-temp.git"
@@ -15,8 +15,9 @@ import type { GatewayConfig } from "../config.js";
15
15
  import { initSigningKey, mintToken } from "../auth/token-service.js";
16
16
  import { CURRENT_POLICY_EPOCH } from "../auth/policy.js";
17
17
  import type { TokenClaims } from "../auth/types.js";
18
+ import { setTestSigningKey } from "./helpers/signing-key.js";
18
19
 
19
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
20
+ setTestSigningKey();
20
21
  initSigningKey();
21
22
 
22
23
  const { initGatewayDb, resetGatewayDb, getGatewayDb } =
@@ -1,8 +1,9 @@
1
1
  import { describe, test, expect, mock, afterEach } from "bun:test";
2
2
  import type { GatewayConfig } from "../config.js";
3
3
  import { initSigningKey } from "../auth/token-service.js";
4
+ import { setTestSigningKey } from "./helpers/signing-key.js";
4
5
 
5
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
6
+ setTestSigningKey();
6
7
  initSigningKey();
7
8
 
8
9
  type FetchFn = (
@@ -21,8 +21,9 @@ import {
21
21
  } from "bun:test";
22
22
 
23
23
  import { initSigningKey } from "../auth/token-service.js";
24
+ import { setTestSigningKey } from "./helpers/signing-key.js";
24
25
 
25
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
26
+ setTestSigningKey();
26
27
  initSigningKey();
27
28
 
28
29
  // ---------------------------------------------------------------------------
@@ -23,8 +23,9 @@ import {
23
23
  } from "bun:test";
24
24
 
25
25
  import { initSigningKey } from "../auth/token-service.js";
26
+ import { setTestSigningKey } from "./helpers/signing-key.js";
26
27
 
27
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
28
+ setTestSigningKey();
28
29
  initSigningKey();
29
30
 
30
31
  // ---------------------------------------------------------------------------
@@ -11,8 +11,9 @@ import {
11
11
  import { hashInviteCode, hashInviteToken } from "@mycadet/gateway-client";
12
12
  import type { GatewayConfig } from "../config.js";
13
13
  import { initSigningKey } from "../auth/token-service.js";
14
+ import { setTestSigningKey } from "./helpers/signing-key.js";
14
15
 
15
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
16
+ setTestSigningKey();
16
17
  initSigningKey();
17
18
 
18
19
  type FetchFn = (
@@ -14,8 +14,9 @@ import { join } from "node:path";
14
14
  import { eq } from "drizzle-orm";
15
15
 
16
16
  import { initSigningKey } from "../auth/token-service.js";
17
+ import { setTestSigningKey } from "./helpers/signing-key.js";
17
18
 
18
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
19
+ setTestSigningKey();
19
20
  initSigningKey();
20
21
 
21
22
  // The pair guardian-lookup reads the gateway DB; the assistant DB proxy is
@@ -12,10 +12,9 @@ import { and, eq } from "drizzle-orm";
12
12
 
13
13
  import { initSigningKey } from "../auth/token-service.js";
14
14
  import { mintPairingPayload } from "../http/routes/pair.js";
15
+ import { setTestSigningKey } from "./helpers/signing-key.js";
15
16
 
16
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from(
17
- "test-signing-key-0123456789abcde",
18
- ).toString("hex");
17
+ setTestSigningKey();
19
18
  initSigningKey();
20
19
 
21
20
  // The pair guardian-lookup reads the gateway DB; the assistant DB proxy is
@@ -23,6 +23,7 @@ import { join } from "node:path";
23
23
  import { eq } from "drizzle-orm";
24
24
 
25
25
  import "./test-preload.js";
26
+ import { setTestSigningKey } from "./helpers/signing-key.js";
26
27
 
27
28
  // --- Mocks (set BEFORE importing the module under test) -------------------
28
29
 
@@ -223,7 +224,6 @@ describe("requireEdgeAuth — DISABLE_HTTP_AUTH alone is insufficient", () => {
223
224
  // =========================================================================
224
225
 
225
226
  describe("requireEdgeAuth — JWT mode", () => {
226
-
227
227
  test("rejects edge-forwarded loopback requests when Authorization header is absent", async () => {
228
228
  const { requireEdgeAuth } = makeMiddleware();
229
229
  const res = await requireEdgeAuth(
@@ -266,7 +266,6 @@ describe("requireEdgeAuth — JWT mode", () => {
266
266
  );
267
267
  expect(res?.status).toBe(401);
268
268
  });
269
-
270
269
  });
271
270
 
272
271
  // =========================================================================
@@ -323,7 +322,6 @@ describe("requireEdgeAuthWithScope — DISABLE_HTTP_AUTH + IS_CLOUD", () => {
323
322
  });
324
323
 
325
324
  describe("requireEdgeAuthWithScope — JWT mode", () => {
326
-
327
325
  test("rejects edge-forwarded loopback requests when scoped Authorization is absent", async () => {
328
326
  const { requireEdgeAuthWithScope } = makeMiddleware();
329
327
  const res = await requireEdgeAuthWithScope(
@@ -625,7 +623,7 @@ const { contacts } = await import("../db/schema.js");
625
623
  const { bustGuardianIntegrityCache } =
626
624
  await import("../auth/guardian-integrity.js");
627
625
 
628
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
626
+ setTestSigningKey();
629
627
  initSigningKey();
630
628
 
631
629
  describe("handleCreateToken: derived actor-token identity carry-forward", () => {
@@ -18,6 +18,7 @@
18
18
  import { Database } from "bun:sqlite";
19
19
 
20
20
  import { and, eq } from "drizzle-orm";
21
+ import { setTestSigningKey } from "./helpers/signing-key.js";
21
22
 
22
23
  import {
23
24
  describe,
@@ -84,7 +85,7 @@ mock.module("../db/assistant-db-proxy.js", () => ({
84
85
  }));
85
86
 
86
87
  // Initialize signing key so bootstrapGuardian's JWT minting works.
87
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
88
+ setTestSigningKey();
88
89
  initSigningKey();
89
90
 
90
91
  /** Minimal in-memory assistant DB mirroring the contacts/contact_channels schema. */
@@ -0,0 +1,27 @@
1
+ import { mkdtempSync, mkdirSync, writeFileSync } from "node:fs";
2
+ import { tmpdir } from "node:os";
3
+ import { join } from "node:path";
4
+
5
+ import { getSigningKeyPath } from "../../auth/token-service.js";
6
+
7
+ /**
8
+ * Deterministic signing key for tests: writes the key FILE the gateway
9
+ * reads (`GATEWAY_SECURITY_DIR/actor-token-signing-key`). Call before
10
+ * `initSigningKey()`. Uses the caller's `GATEWAY_SECURITY_DIR` when one is
11
+ * already set, otherwise mints a throwaway temp dir and points the env var
12
+ * at it. Returns the security dir in effect.
13
+ */
14
+ export function setTestSigningKey(): string {
15
+ let dir = process.env["GATEWAY_SECURITY_DIR"];
16
+ if (!dir) {
17
+ dir = mkdtempSync(join(tmpdir(), "gateway-signing-key-"));
18
+ process.env["GATEWAY_SECURITY_DIR"] = dir;
19
+ }
20
+ mkdirSync(dir, { recursive: true });
21
+ writeFileSync(
22
+ getSigningKeyPath(),
23
+ // Exactly 32 bytes — the same key material the old env-var fixture held.
24
+ Buffer.from("test-signing-key-0123456789abcde"),
25
+ );
26
+ return dir;
27
+ }
@@ -22,6 +22,7 @@
22
22
  import { afterEach, beforeEach, describe, expect, test } from "bun:test";
23
23
 
24
24
  import "./test-preload.js";
25
+ import { setTestSigningKey } from "./helpers/signing-key.js";
25
26
 
26
27
  import {
27
28
  ensureCadetGuardianBinding,
@@ -37,7 +38,7 @@ import {
37
38
  import { actorTokenRecords, contacts, contactChannels } from "../db/schema.js";
38
39
  import { resolveTrustVerdict } from "../risk/trust-verdict-resolver.js";
39
40
 
40
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
41
+ setTestSigningKey();
41
42
  initSigningKey();
42
43
 
43
44
  const PRINCIPAL = "cadet-principal-0aafaf2";
@@ -1,8 +1,9 @@
1
1
  import { describe, test, expect, mock, afterEach } from "bun:test";
2
2
  import type { GatewayConfig } from "../config.js";
3
3
  import { initSigningKey } from "../auth/token-service.js";
4
+ import { setTestSigningKey } from "./helpers/signing-key.js";
4
5
 
5
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
6
+ setTestSigningKey();
6
7
  initSigningKey();
7
8
 
8
9
  type FetchFn = (
@@ -5,9 +5,10 @@
5
5
  import { describe, test, expect, mock, beforeEach } from "bun:test";
6
6
 
7
7
  import { initSigningKey } from "../auth/token-service.js";
8
+ import { setTestSigningKey } from "./helpers/signing-key.js";
8
9
 
9
10
  // Must init signing key before any module that mints tokens is imported.
10
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
11
+ setTestSigningKey();
11
12
  initSigningKey();
12
13
 
13
14
  // Mock DB — pair.ts calls resolveLocalGuardianPrincipalId() which queries the DB.
@@ -10,8 +10,9 @@ import { tmpdir } from "node:os";
10
10
  import { join } from "node:path";
11
11
 
12
12
  import { initSigningKey } from "../auth/token-service.js";
13
+ import { setTestSigningKey } from "./helpers/signing-key.js";
13
14
 
14
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
15
+ setTestSigningKey();
15
16
  initSigningKey();
16
17
 
17
18
  const { initGatewayDb, resetGatewayDb, getGatewayDb } =
@@ -7,13 +7,14 @@ import { eq } from "drizzle-orm";
7
7
 
8
8
  import { MAX_PAIRING_USER_AGENT_CHARS } from "../auth/device-identity-text.js";
9
9
  import { initSigningKey } from "../auth/token-service.js";
10
+ import { setTestSigningKey } from "./helpers/signing-key.js";
10
11
 
11
12
  import {
12
13
  PUBLIC_BASE_URL,
13
14
  TEST_REQUESTER,
14
15
  } from "./helpers/remote-web-pairing-fixtures.js";
15
16
 
16
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
17
+ setTestSigningKey();
17
18
  initSigningKey();
18
19
 
19
20
  const mockQuery = mock();
@@ -3,8 +3,9 @@ import type { RuntimeInboundPayload } from "@mycadet/gateway-client";
3
3
  import type { RuntimeAttachmentMeta } from "../runtime/client.js";
4
4
  import type { GatewayConfig } from "../config.js";
5
5
  import { initSigningKey } from "../auth/token-service.js";
6
+ import { setTestSigningKey } from "./helpers/signing-key.js";
6
7
 
7
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
8
+ setTestSigningKey();
8
9
  initSigningKey();
9
10
 
10
11
  type FetchFn = (
@@ -1,8 +1,9 @@
1
1
  import { describe, test, expect, mock, afterEach } from "bun:test";
2
2
  import type { GatewayConfig } from "../config.js";
3
3
  import { initSigningKey } from "../auth/token-service.js";
4
+ import { setTestSigningKey } from "./helpers/signing-key.js";
4
5
 
5
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
6
+ setTestSigningKey();
6
7
  initSigningKey();
7
8
 
8
9
  type FetchFn = (
@@ -2,6 +2,7 @@ import { describe, test, expect, mock, afterEach } from "bun:test";
2
2
  import type { GatewayConfig } from "../config.js";
3
3
  import { initSigningKey, mintToken } from "../auth/token-service.js";
4
4
  import { CURRENT_POLICY_EPOCH } from "../auth/policy.js";
5
+ import { setTestSigningKey } from "./helpers/signing-key.js";
5
6
 
6
7
  type FetchFn = (
7
8
  input: string | URL | Request,
@@ -23,7 +24,7 @@ mock.module("../config.js", () => ({
23
24
 
24
25
  const { handleRuntimeProxy } = await import("../http/routes/runtime-proxy.js");
25
26
 
26
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
27
+ setTestSigningKey();
27
28
  initSigningKey();
28
29
 
29
30
  /** Mint a valid edge JWT (aud=cadet-gateway) for test requests. */
@@ -20,8 +20,9 @@ import { CURRENT_POLICY_EPOCH } from "../auth/policy.js";
20
20
  import { initSigningKey, mintToken } from "../auth/token-service.js";
21
21
  import type { ScopeProfile } from "../auth/types.js";
22
22
  import type { GatewayConfig } from "../config.js";
23
+ import { setTestSigningKey } from "./helpers/signing-key.js";
23
24
 
24
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
25
+ setTestSigningKey();
25
26
  initSigningKey();
26
27
 
27
28
  // --- Upstream daemon stubs (registered before the modules under test) ------
@@ -11,6 +11,7 @@ import { describe, test, expect, mock, beforeEach } from "bun:test";
11
11
  import type { GatewayConfig } from "../config.js";
12
12
  import { initSigningKey, mintToken } from "../auth/token-service.js";
13
13
  import { CURRENT_POLICY_EPOCH } from "../auth/policy.js";
14
+ import { setTestSigningKey } from "./helpers/signing-key.js";
14
15
 
15
16
  type FetchFn = (
16
17
  input: string | URL | Request,
@@ -63,7 +64,7 @@ mock.module("../config.js", () => ({
63
64
 
64
65
  const { handleRuntimeProxy } = await import("../http/routes/runtime-proxy.js");
65
66
 
66
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
67
+ setTestSigningKey();
67
68
  initSigningKey();
68
69
 
69
70
  const TOKEN = mintToken({
@@ -1,8 +1,9 @@
1
1
  import { describe, test, expect, mock, afterEach } from "bun:test";
2
2
  import type { GatewayConfig } from "../config.js";
3
3
  import { initSigningKey } from "../auth/token-service.js";
4
+ import { setTestSigningKey } from "./helpers/signing-key.js";
4
5
 
5
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
6
+ setTestSigningKey();
6
7
  initSigningKey();
7
8
 
8
9
  type FetchFn = (
@@ -9,6 +9,7 @@ import { mock } from "bun:test";
9
9
  import type { GatewayConfig } from "../config.js";
10
10
  import { initSigningKey, mintToken } from "../auth/token-service.js";
11
11
  import { CURRENT_POLICY_EPOCH } from "../auth/policy.js";
12
+ import { setTestSigningKey } from "./helpers/signing-key.js";
12
13
 
13
14
  /** The bound guardian's actor principal, which `mintEdgeToken` defaults to. */
14
15
  export const GUARDIAN_PRINCIPAL = "test-user";
@@ -16,7 +17,7 @@ export const GUARDIAN_PRINCIPAL = "test-user";
16
17
  /** The bound guardian's platform user id, for the tunnel-attested path. */
17
18
  export const TUNNEL_USER_ID = "11111111-1111-1111-1111-111111111111";
18
19
 
19
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
20
+ setTestSigningKey();
20
21
  initSigningKey();
21
22
 
22
23
  /** Mint a valid actor edge JWT. */
@@ -17,6 +17,7 @@ import {
17
17
  mock,
18
18
  test,
19
19
  } from "bun:test";
20
+ import { setTestSigningKey } from "./helpers/signing-key.js";
20
21
 
21
22
  import {
22
23
  hashInviteToken,
@@ -85,7 +86,7 @@ await import("./test-preload.js");
85
86
 
86
87
  const { initSigningKey, verifyToken } =
87
88
  await import("../auth/token-service.js");
88
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
89
+ setTestSigningKey();
89
90
  initSigningKey();
90
91
 
91
92
  const { initGatewayDb, getGatewayDb, resetGatewayDb } =
@@ -1,8 +1,9 @@
1
1
  import { describe, test, expect, mock, afterEach } from "bun:test";
2
2
  import type { GatewayConfig } from "../config.js";
3
3
  import { initSigningKey } from "../auth/token-service.js";
4
+ import { setTestSigningKey } from "./helpers/signing-key.js";
4
5
 
5
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
6
+ setTestSigningKey();
6
7
  initSigningKey();
7
8
 
8
9
  type FetchFn = (
@@ -1,8 +1,9 @@
1
1
  import { describe, test, expect, mock, afterEach } from "bun:test";
2
2
  import type { GatewayConfig } from "../config.js";
3
3
  import { initSigningKey } from "../auth/token-service.js";
4
+ import { setTestSigningKey } from "./helpers/signing-key.js";
4
5
 
5
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
6
+ setTestSigningKey();
6
7
  initSigningKey();
7
8
 
8
9
  type FetchFn = (
@@ -3,6 +3,7 @@ import type { GatewayConfig } from "../config.js";
3
3
  import type { CredentialCache } from "../credential-cache.js";
4
4
  import { credentialKey } from "../credential-key.js";
5
5
  import { initSigningKey } from "../auth/token-service.js";
6
+ import { setTestSigningKey } from "./helpers/signing-key.js";
6
7
  import {
7
8
  initAdmissionPolicyCache,
8
9
  resetAdmissionPolicyCache,
@@ -12,7 +13,7 @@ import { writeFileSync } from "node:fs";
12
13
  import { join } from "node:path";
13
14
  import { testWorkspaceDir } from "./test-preload.js";
14
15
 
15
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
16
+ setTestSigningKey();
16
17
  initSigningKey();
17
18
 
18
19
  type FetchFn = (
@@ -286,7 +287,9 @@ describe("telegram webhook handler: replyCallbackUrl", () => {
286
287
  test("uses the saved ingress URL when the workspace records one", async () => {
287
288
  writeFileSync(
288
289
  join(testWorkspaceDir, "config.json"),
289
- JSON.stringify({ ingress: { publicBaseUrl: "https://ingress.example.test" } }),
290
+ JSON.stringify({
291
+ ingress: { publicBaseUrl: "https://ingress.example.test" },
292
+ }),
290
293
  );
291
294
  try {
292
295
  const config = makeConfig({
@@ -1,13 +1,14 @@
1
1
  /**
2
2
  * Shared test preload — runs before every gateway test file.
3
3
  *
4
- * Creates a per-file temporary directory tree and sets GATEWAY_SECURITY_DIR
5
- * and CADET_WORKSPACE_DIR so that gateway code resolves under the temp dir
6
- * instead of the real ~/.cadet paths.
4
+ * Creates a per-file temporary directory tree and sets GATEWAY_SECURITY_DIR,
5
+ * CADET_WORKSPACE_DIR, and GATEWAY_IPC_SOCKET_DIR so that gateway code resolves
6
+ * under the temp dir instead of the real ~/.cadet paths.
7
7
  *
8
8
  * Exports:
9
9
  * testSecurityDir — the per-file temp GATEWAY_SECURITY_DIR
10
10
  * testWorkspaceDir — the per-file temp CADET_WORKSPACE_DIR
11
+ * testIpcSocketDir — the per-file temp GATEWAY_IPC_SOCKET_DIR
11
12
  *
12
13
  * These are safe to import from any test file:
13
14
  *
@@ -33,9 +34,11 @@ const testRoot = realpathSync(
33
34
 
34
35
  export const testSecurityDir = join(testRoot, "protected");
35
36
  export const testWorkspaceDir = join(testRoot, "workspace");
37
+ export const testIpcSocketDir = join(testRoot, "ipc");
36
38
 
37
39
  mkdirSync(testSecurityDir, { recursive: true });
38
40
  mkdirSync(testWorkspaceDir, { recursive: true });
41
+ mkdirSync(testIpcSocketDir, { recursive: true });
39
42
 
40
43
  // ---------------------------------------------------------------------------
41
44
  // Save originals and set env vars
@@ -43,11 +46,20 @@ mkdirSync(testWorkspaceDir, { recursive: true });
43
46
 
44
47
  const savedSecurityDir = process.env.GATEWAY_SECURITY_DIR;
45
48
  const savedWorkspaceDir = process.env.CADET_WORKSPACE_DIR;
49
+ const savedIpcSocketDir = process.env.GATEWAY_IPC_SOCKET_DIR;
46
50
  const savedCesCredentialUrl = process.env.CES_CREDENTIAL_URL;
47
51
  const savedCesServiceToken = process.env.CES_SERVICE_TOKEN;
48
52
 
49
53
  process.env.GATEWAY_SECURITY_DIR = testSecurityDir;
50
54
  process.env.CADET_WORKSPACE_DIR = testWorkspaceDir;
55
+ // Pin the gateway IPC socket dir to the per-file temp tree. Without this,
56
+ // a developer environment that exports GATEWAY_IPC_SOCKET_DIR (e.g. the
57
+ // docker topology's /run/gateway-ipc) leaks into GatewayIpcServer tests,
58
+ // whose listen() removes and re-binds the socket at the PRODUCTION path —
59
+ // hijacking the live gateway's IPC (permission prompts) for the duration
60
+ // of the test run. CI never sees this because it does not export the var,
61
+ // so resolution falls back to the (sandboxed) workspace path.
62
+ process.env.GATEWAY_IPC_SOCKET_DIR = testIpcSocketDir;
51
63
 
52
64
  // Prevent tests from hitting a real CES sidecar that may be running
53
65
  // in the sandbox. Without this, readCredential() resolves secrets from
@@ -72,6 +84,12 @@ afterAll(() => {
72
84
  process.env.CADET_WORKSPACE_DIR = savedWorkspaceDir;
73
85
  }
74
86
 
87
+ if (savedIpcSocketDir === undefined) {
88
+ delete process.env.GATEWAY_IPC_SOCKET_DIR;
89
+ } else {
90
+ process.env.GATEWAY_IPC_SOCKET_DIR = savedIpcSocketDir;
91
+ }
92
+
75
93
  if (savedCesCredentialUrl === undefined) {
76
94
  delete process.env.CES_CREDENTIAL_URL;
77
95
  } else {
@@ -2,6 +2,7 @@ import { describe, test, expect, mock, beforeEach, afterAll } from "bun:test";
2
2
  import type { GatewayConfig } from "../config.js";
3
3
  import { initSigningKey, mintToken } from "../auth/token-service.js";
4
4
  import { CURRENT_POLICY_EPOCH } from "../auth/policy.js";
5
+ import { setTestSigningKey } from "./helpers/signing-key.js";
5
6
  import {
6
7
  createTwilioMediaWebsocketHandler,
7
8
  extractMediaStreamMetadata,
@@ -12,7 +13,7 @@ import {
12
13
  // Auth setup — initialize signing key so JWT minting/validation works
13
14
  // ---------------------------------------------------------------------------
14
15
 
15
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
16
+ setTestSigningKey();
16
17
  initSigningKey();
17
18
 
18
19
  /**
@@ -6,13 +6,14 @@ import type { ConfigFileCache } from "../config-file-cache.js";
6
6
  import { AdmissionPolicyStore } from "../db/admission-policy-store.js";
7
7
  import { credentialKey } from "../credential-key.js";
8
8
  import { initSigningKey } from "../auth/token-service.js";
9
+ import { setTestSigningKey } from "./helpers/signing-key.js";
9
10
  import {
10
11
  initAdmissionPolicyCache,
11
12
  resetAdmissionPolicyCache,
12
13
  } from "../risk/admission-policy-cache.js";
13
14
  import { initGatewayDb, resetGatewayDb } from "../db/connection.js";
14
15
 
15
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
16
+ setTestSigningKey();
16
17
  initSigningKey();
17
18
 
18
19
  type FetchFn = (
@@ -3,8 +3,9 @@ import { createHmac } from "node:crypto";
3
3
  import type { GatewayConfig } from "../config.js";
4
4
  import type { CredentialCache } from "../credential-cache.js";
5
5
  import { initSigningKey } from "../auth/token-service.js";
6
+ import { setTestSigningKey } from "./helpers/signing-key.js";
6
7
 
7
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
8
+ setTestSigningKey();
8
9
  initSigningKey();
9
10
 
10
11
  type FetchFn = (
@@ -40,34 +40,22 @@ export function getSigningKeyPath(): string {
40
40
  * Resolve the signing key for the gateway.
41
41
  *
42
42
  * Resolution order:
43
- * 1. ACTOR_TOKEN_SIGNING_KEY env var (hex-encoded, set by CLI for Docker)
44
- * 2. Load from disk (GATEWAY_SECURITY_DIR/actor-token-signing-key)
45
- * 3. Adopt the key the assistant's daemon era persisted under the
43
+ * 1. Load from disk (GATEWAY_SECURITY_DIR/actor-token-signing-key)
44
+ * 2. Adopt the key the assistant's daemon era persisted under the
46
45
  * workspace's transitional directory — the one-time migration for
47
46
  * instances hatched before the gateway owned key custody. Consumed
48
47
  * on read: the adopted key is persisted gateway-side and the old
49
48
  * file removed.
50
- * 4. Generate a new key and persist to disk (local mode)
49
+ * 3. Generate a new key and persist to disk (local mode)
51
50
  */
52
51
  export function loadOrCreateSigningKey(): Buffer {
53
- const envKey = process.env.ACTOR_TOKEN_SIGNING_KEY;
54
- if (envKey) {
55
- if (!/^[0-9a-f]{64}$/i.test(envKey)) {
56
- throw new Error(
57
- `Invalid ACTOR_TOKEN_SIGNING_KEY: expected 64 hex characters, got ${envKey.length} chars`,
58
- );
59
- }
60
- log.info("Signing key loaded from ACTOR_TOKEN_SIGNING_KEY env var");
61
- return Buffer.from(envKey, "hex");
62
- }
63
-
64
52
  const keyPath = getSigningKeyPath();
65
53
 
66
54
  if (existsSync(keyPath)) {
67
55
  try {
68
56
  const raw = readFileSync(keyPath);
69
57
  if (raw.length === 32) {
70
- log.info("Auth signing key loaded from disk");
58
+ log.debug("Auth signing key loaded from disk");
71
59
  return raw;
72
60
  }
73
61
  log.warn("Signing key file has unexpected length, regenerating");
@@ -142,8 +130,9 @@ function persistSigningKey(keyPath: string, key: Buffer): void {
142
130
  /**
143
131
  * Initialize (or reinitialize) the signing key. Called at gateway startup —
144
132
  * loads or creates the on-disk key via `loadOrCreateSigningKey()`, the one
145
- * path every real entrypoint shares. Tests that need a deterministic key set
146
- * ACTOR_TOKEN_SIGNING_KEY (its first resolution path) before calling.
133
+ * path every real entrypoint shares. Tests that need a deterministic key
134
+ * write one to the security dir first (see
135
+ * `src/__tests__/helpers/signing-key.ts`).
147
136
  */
148
137
  export function initSigningKey(): void {
149
138
  signingKey = loadOrCreateSigningKey();
@@ -22,6 +22,7 @@ import {
22
22
  writeFileSync,
23
23
  } from "node:fs";
24
24
  import { join } from "node:path";
25
+ import { setTestSigningKey } from "../../__tests__/helpers/signing-key.js";
25
26
  import {
26
27
  afterAll,
27
28
  afterEach,
@@ -60,9 +61,7 @@ mock.module("../../db/assistant-db-proxy.js", () => ({
60
61
  }));
61
62
 
62
63
  // Initialize signing key before any module that mints tokens is imported.
63
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from(
64
- "test-signing-key-0123456789abcde",
65
- ).toString("hex");
64
+ setTestSigningKey();
66
65
  initSigningKey();
67
66
 
68
67
  const { parsePairingArgs, parsePairingMintArgs, runPairingCommand } =
package/src/cli/index.ts CHANGED
@@ -13,6 +13,13 @@ import { runPairingCommand } from "./pairing.js";
13
13
  import { initGatewayDb } from "../db/connection.js";
14
14
  import { initSigningKey } from "../auth/token-service.js";
15
15
 
16
+ // One-shot commands print machine-readable JSON on stdout; their callers
17
+ // parse it. Silence pino entirely (no pretty stdout, no log files) — the
18
+ // lazy proxy logger builds on the first log call, which happens inside the
19
+ // command bodies below, after this flag is set. Errors surface through
20
+ // console.error + exit codes instead.
21
+ process.env["GATEWAY_LOG_SILENT"] = "1";
22
+
16
23
  function printUsage(): void {
17
24
  console.log("Usage: gateway <command>");
18
25
  console.log("");
@@ -154,7 +154,7 @@ function listLiveness(
154
154
  return challenge.expiresAtMs <= now ? "expired" : "active";
155
155
  }
156
156
 
157
- function runPairingList(json: boolean): number {
157
+ async function runPairingList(json: boolean): Promise<number> {
158
158
  const now = Date.now();
159
159
  const challenges = listPersistedRemoteWebPairingChallenges();
160
160
 
@@ -173,7 +173,6 @@ function runPairingList(json: boolean): number {
173
173
 
174
174
  if (challenges.length === 0) {
175
175
  console.log("No pairing challenges found.");
176
- return 0;
177
176
  }
178
177
 
179
178
  for (const challenge of challenges) {
@@ -190,9 +189,40 @@ function runPairingList(json: boolean): number {
190
189
  ` ${challenge.verificationUri} requester ${challenge.requesterIp}${userAgent}`,
191
190
  );
192
191
  }
192
+
193
+ // The device-bound mint (the guardian lease's door) creates no pairing
194
+ // challenge — it mints an actor token directly. Surface those leases here
195
+ // too, so a mint that just succeeded is visible from this command.
196
+ const leases = await listLocalDeviceLeases().catch(() => []);
197
+ if (leases.length > 0) {
198
+ console.log("");
199
+ console.log("Device-bound leases:");
200
+ for (const lease of leases) {
201
+ console.log(
202
+ ` ${lease.hashedDeviceId} ${lease.platform} ${
203
+ lease.clientReportedName ?? "(unnamed)"
204
+ } issued ${new Date(lease.issuedAt).toISOString()}`,
205
+ );
206
+ }
207
+ }
208
+
193
209
  return 0;
194
210
  }
195
211
 
212
+ /**
213
+ * The guardian's active device-bound leases, via the same handler the
214
+ * `gateway devices list` command renders. Best-effort context for the list
215
+ * view; an empty array on failure keeps the challenge listing working.
216
+ */
217
+ async function listLocalDeviceLeases() {
218
+ try {
219
+ const { handleListDevices } = await import("../http/routes/devices.js");
220
+ return await handleListDevices();
221
+ } catch {
222
+ return [];
223
+ }
224
+ }
225
+
196
226
  /**
197
227
  * Approve a pending pairing challenge by id — the same in-process store
198
228
  * write the old loopback approval routes did, minus the HTTP surface:
@@ -237,7 +267,7 @@ export async function runPairingCommand(args: string[]): Promise<number> {
237
267
  return subcommand ? 0 : 1;
238
268
  }
239
269
  if (subcommand === "list") {
240
- return runPairingList(args.includes("--json"));
270
+ return await runPairingList(args.includes("--json"));
241
271
  }
242
272
  if (subcommand === "approve" || subcommand === "deny") {
243
273
  const requestId = parsePairingArgs(args).positional;
@@ -102,12 +102,25 @@ export async function runDevicesCommand(args: string[]): Promise<number> {
102
102
  if (method === "list") {
103
103
  const devices = await handleListDevices();
104
104
  if (devices.length === 0) {
105
- console.log("No contacts found.");
105
+ console.log("No devices found.");
106
106
  return 0;
107
107
  }
108
+ // Hashed device ids vary in length — pad every column (header included)
109
+ // to its widest value so the rows stay aligned.
110
+ const idWidth = Math.max(
111
+ "DEVICE ID".length,
112
+ ...devices.map((d) => d.hashedDeviceId.length),
113
+ );
114
+ const platformWidth = Math.max(
115
+ "PLATFORM".length,
116
+ ...devices.map((d) => d.platform.length),
117
+ );
118
+ console.log(
119
+ `DEVICE ID${" ".repeat(idWidth - "DEVICE ID".length)} PLATFORM${" ".repeat(platformWidth - "PLATFORM".length)} NAME`,
120
+ );
108
121
  for (const device of devices) {
109
122
  console.log(
110
- `${device.hashedDeviceId} ${device.platform} ${device.clientReportedName}`,
123
+ `${device.hashedDeviceId.padEnd(idWidth)} ${device.platform.padEnd(platformWidth)} ${device.clientReportedName}`,
111
124
  );
112
125
  }
113
126
  console.log("");
@@ -13,6 +13,7 @@ import { isTrustCheckedScopeProfile } from "@mycadet/gateway-client";
13
13
 
14
14
  import { isNarrowScopeProfile } from "../../auth/scopes.js";
15
15
  import type { ScopeProfile } from "../../auth/types.js";
16
+ import { setTestSigningKey } from "../../__tests__/helpers/signing-key.js";
16
17
 
17
18
  // ---------------------------------------------------------------------------
18
19
  // Mock implementations
@@ -214,7 +215,7 @@ mock.module("../../risk/trust-verdict-resolver.js", () => ({
214
215
 
215
216
  // The HTTP proxy mints a service token for the daemon on every request.
216
217
  const { initSigningKey } = await import("../../auth/token-service.js");
217
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
218
+ setTestSigningKey();
218
219
  initSigningKey();
219
220
 
220
221
  // ---------------------------------------------------------------------------
@@ -7,6 +7,7 @@ import { initSigningKey } from "../../auth/token-service.js";
7
7
  import type { PluginIngressResolution } from "../../channels/plugin-ingress-approvals.js";
8
8
  import type { GatewayConfig } from "../../config.js";
9
9
  import { signHandshakeUrl } from "../plugin-ingress-handshake.js";
10
+ import { setTestSigningKey } from "../../__tests__/helpers/signing-key.js";
10
11
  import {
11
12
  createPluginWebhookWebsocketHandler,
12
13
  getPluginWebhookWebsocketHandlers,
@@ -15,7 +16,7 @@ import {
15
16
  } from "./plugin-webhook-websocket.js";
16
17
  import { IngressRoute } from "../../channels/plugin-ingress.js";
17
18
 
18
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
19
+ setTestSigningKey();
19
20
  initSigningKey();
20
21
 
21
22
  const CONFIG = {
@@ -1,4 +1,5 @@
1
1
  import { createHmac } from "node:crypto";
2
+ import { setTestSigningKey } from "../../__tests__/helpers/signing-key.js";
2
3
 
3
4
  import {
4
5
  afterAll,
@@ -72,7 +73,7 @@ type PluginWebhookHandlerDeps = Parameters<
72
73
  // The handler mints a real service token for the upstream hop. Initialising
73
74
  // the key beats mocking token-exchange, which is process-wide in bun and
74
75
  // would leak into every other suite in the run.
75
- process.env.ACTOR_TOKEN_SIGNING_KEY = Buffer.from("test-signing-key-0123456789abcde").toString("hex");
76
+ setTestSigningKey();
76
77
  initSigningKey();
77
78
 
78
79
  // Inbound delivery claims each message against redelivery, and that claim is
package/src/logger.ts CHANGED
@@ -113,6 +113,9 @@ function openSecureDestination(filePath: string): pino.DestinationStream {
113
113
  }
114
114
 
115
115
  function buildLogger(config: LogFileConfig | null): pino.Logger {
116
+ if (process.env["GATEWAY_LOG_SILENT"]?.trim() === "1") {
117
+ return pino({ name: "gateway", level: "silent" });
118
+ }
116
119
  if (!config?.dir) {
117
120
  return pino(
118
121
  { name: "gateway", serializers: logSerializers },