@vellumai/vellum-gateway 0.8.3 → 0.8.5

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 (38) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/package.json +1 -1
  3. package/src/__tests__/auto-approve-conversation-thresholds.test.ts +14 -6
  4. package/src/__tests__/config.test.ts +49 -0
  5. package/src/__tests__/feature-flag-watcher-callback.test.ts +85 -0
  6. package/src/__tests__/feature-flags-route.test.ts +40 -1
  7. package/src/__tests__/ipc-feature-flag-routes.test.ts +24 -0
  8. package/src/__tests__/ipc-slack-thread-routes.test.ts +157 -0
  9. package/src/__tests__/remote-feature-flag-sync.test.ts +75 -5
  10. package/src/__tests__/route-schema-guard.test.ts +2 -0
  11. package/src/__tests__/slack-display-name.test.ts +218 -0
  12. package/src/__tests__/slack-socket-mode-thread-tracking.test.ts +98 -4
  13. package/src/auth/ipc-route-policy.ts +5 -0
  14. package/src/channels/inbound-event.ts +4 -0
  15. package/src/config.ts +35 -1
  16. package/src/db/slack-store.ts +10 -0
  17. package/src/feature-flag-registry.json +115 -3
  18. package/src/feature-flag-remote-store.ts +7 -1
  19. package/src/feature-flag-watcher.ts +8 -1
  20. package/src/handlers/handle-inbound.ts +11 -5
  21. package/src/http/middleware/cors.ts +10 -2
  22. package/src/http/routes/auto-approve-thresholds.ts +10 -4
  23. package/src/http/routes/email-webhook.ts +10 -2
  24. package/src/http/routes/feature-flags.ts +7 -3
  25. package/src/http/routes/guardian-channel-create.test.ts +198 -0
  26. package/src/http/routes/guardian-channel-create.ts +137 -0
  27. package/src/http/routes/inbound-register.ts +27 -15
  28. package/src/http/routes/vellum-identity.ts +24 -0
  29. package/src/index.ts +19 -11
  30. package/src/ipc/feature-flag-handlers.ts +8 -3
  31. package/src/ipc/slack-thread-handlers.ts +39 -0
  32. package/src/post-assistant-ready.ts +8 -4
  33. package/src/remote-feature-flag-sync.ts +10 -3
  34. package/src/risk/command-registry/commands/assistant.ts +13 -0
  35. package/src/runtime/client.ts +2 -0
  36. package/src/schema.ts +13 -9
  37. package/src/slack/normalize.ts +78 -26
  38. package/src/slack/socket-mode.ts +2 -2
package/ARCHITECTURE.md CHANGED
@@ -95,11 +95,11 @@ The gateway exposes a REST API for reading and mutating assistant feature flags.
95
95
  | GET | `/v1/feature-flags` | List all declared assistant feature flags from the defaults registry, merged with persisted values from the feature flag store. Returns `{ flags: FeatureFlagEntry[] }` where each entry has `key`, `enabled`, `defaultEnabled`, and `description`. |
96
96
  | PATCH | `/v1/feature-flags/:key` | Set a single assistant feature flag. Body: `{ "enabled": true\|false }`. Key must be a simple kebab-case flag key declared in the defaults registry. Writes to `~/.vellum/protected/feature-flags.json`. |
97
97
 
98
- **Unified registry:** All declared feature flags and their default values are defined in the unified registry at `meta/feature-flags/feature-flag-registry.json` (bundled copy at `gateway/src/feature-flag-registry.json`). The gateway loads this registry on startup via `gateway/src/feature-flag-defaults.ts`, filtering to `scope: "assistant"` flags. Labels come from the registry. The GET endpoint merges persisted overrides with registry defaults to produce the full flag list. The PATCH endpoint validates that the target flag key exists in the registry before accepting a write. Only declared keys are exposed by this API.
98
+ **Unified registry:** All declared feature flags and their default values are defined in the unified registry at `meta/feature-flags/feature-flag-registry.json` (bundled copy at `gateway/src/feature-flag-registry.json`). The gateway loads this registry on startup via `gateway/src/feature-flag-defaults.ts`, filtering to `scope: "assistant"` flags. Labels come from the registry. The GET endpoint merges persisted overrides with remote values and registry defaults to produce the full flag list. Once a remote snapshot exists, declared flags missing from that snapshot fail closed to `false`; this handles flags that are declared locally but unregistered on the platform. The PATCH endpoint validates that the target flag key exists in the registry before accepting a write. Only declared keys are exposed by this API.
99
99
 
100
100
  **Flag key format:** The canonical key format is simple kebab-case (e.g., `browser`, `ces-tools`). Only keys matching this pattern and declared in the registry are accepted by the PATCH endpoint; other patterns are rejected with 400. All writes use the canonical format and are stored in the protected feature flag store (`~/.vellum/protected/feature-flags.json`).
101
101
 
102
- **Storage:** Flag overrides are persisted in `~/.vellum/protected/feature-flags.json` (local) or `GATEWAY_SECURITY_DIR/feature-flags.json` (Docker). The store uses a versioned JSON format (`{ version: 1, values: Record<string, boolean> }`). The GET endpoint reads from the feature flag store and merges with registry defaults. The gateway writes atomically (temp file + rename, 0o600 permissions). The daemon's config watcher monitors the protected directory and hot-reloads changes, so flag mutations take effect on the next session or tool resolution without a restart.
102
+ **Storage:** Flag overrides are persisted in `~/.vellum/protected/feature-flags.json` (local) or `GATEWAY_SECURITY_DIR/feature-flags.json` (Docker). The store uses a versioned JSON format (`{ version: 1, values: Record<string, boolean> }`). Remote platform snapshots are persisted separately in `feature-flags-remote.json`; local overrides win over remote values, remote values win over registry defaults, and missing remote values fail closed when a remote snapshot exists. The gateway writes atomically (temp file + rename, 0o600 permissions). The daemon's config watcher monitors the protected directory and hot-reloads flag changes, so flag mutations take effect on the next session or tool resolution without a restart.
103
103
 
104
104
  **Token separation (authentication boundary):**
105
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vellumai/vellum-gateway",
3
- "version": "0.8.3",
3
+ "version": "0.8.5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -60,15 +60,21 @@ function makeDelete(conversationId: string): [Request, string[]] {
60
60
  // ---------------------------------------------------------------------------
61
61
 
62
62
  describe("GET /v1/permissions/thresholds/conversations/:conversationId", () => {
63
- test("returns 404 for nonexistent conversation", async () => {
63
+ test("returns 200 with threshold:null when no override exists", async () => {
64
+ // "No override" is the common case — every conversation reads this
65
+ // endpoint to decide whether to apply a per-conversation threshold,
66
+ // and only a small fraction have one configured. Returning 200 with
67
+ // `{ threshold: null }` (rather than 404) avoids surfacing a
68
+ // misleading network error in the browser console for the default
69
+ // case and matches the IPC contract, which also returns null.
64
70
  const handler = createConversationThresholdGetHandler();
65
71
  const [req, params] = makeGet("conv-xyz");
66
72
 
67
73
  const res = await handler(req, params);
68
- expect(res.status).toBe(404);
74
+ expect(res.status).toBe(200);
69
75
 
70
76
  const body = await res.json();
71
- expect(body.error).toBe("No override for this conversation");
77
+ expect(body).toEqual({ threshold: null });
72
78
  });
73
79
 
74
80
  test("returns threshold after PUT creates it", async () => {
@@ -160,7 +166,7 @@ describe("PUT /v1/permissions/thresholds/conversations/:conversationId", () => {
160
166
  });
161
167
 
162
168
  describe("DELETE /v1/permissions/thresholds/conversations/:conversationId", () => {
163
- test("removes existing override, subsequent GET returns 404", async () => {
169
+ test("removes existing override, subsequent GET returns threshold:null", async () => {
164
170
  const putHandler = createConversationThresholdPutHandler();
165
171
  const getHandler = createConversationThresholdGetHandler();
166
172
  const deleteHandler = createConversationThresholdDeleteHandler();
@@ -174,10 +180,12 @@ describe("DELETE /v1/permissions/thresholds/conversations/:conversationId", () =
174
180
  const delRes = await deleteHandler(delReq, delParams);
175
181
  expect(delRes.status).toBe(204);
176
182
 
177
- // Verify gone
183
+ // Verify gone — GET now reports the absence as a normal 200 result.
178
184
  const [getReq, getParams] = makeGet("conv-del");
179
185
  const getRes = await getHandler(getReq, getParams);
180
- expect(getRes.status).toBe(404);
186
+ expect(getRes.status).toBe(200);
187
+ const body = await getRes.json();
188
+ expect(body).toEqual({ threshold: null });
181
189
  });
182
190
 
183
191
  test("returns 204 on nonexistent conversation (idempotent)", async () => {
@@ -1,4 +1,9 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
1
4
  import { describe, test, expect } from "bun:test";
5
+
6
+ import { testWorkspaceDir } from "./test-preload.js";
2
7
  import { loadConfig } from "../config.js";
3
8
 
4
9
  describe("config: hardcoded defaults", () => {
@@ -61,6 +66,50 @@ describe("config: hardcoded defaults", () => {
61
66
  }
62
67
  });
63
68
 
69
+ test("runtimeTimeoutMs is configurable via env var", () => {
70
+ const saved = process.env.RUNTIME_TIMEOUT_MS;
71
+ process.env.RUNTIME_TIMEOUT_MS = "300000";
72
+ try {
73
+ const config = loadConfig();
74
+ expect(config.runtimeTimeoutMs).toBe(300000);
75
+ } finally {
76
+ if (saved !== undefined) process.env.RUNTIME_TIMEOUT_MS = saved;
77
+ else delete process.env.RUNTIME_TIMEOUT_MS;
78
+ }
79
+ });
80
+
81
+ test("runtimeTimeoutMs rejects invalid env var", () => {
82
+ const saved = process.env.RUNTIME_TIMEOUT_MS;
83
+ process.env.RUNTIME_TIMEOUT_MS = "0";
84
+ try {
85
+ expect(() => loadConfig()).toThrow(
86
+ "RUNTIME_TIMEOUT_MS must be a positive integer",
87
+ );
88
+ } finally {
89
+ if (saved !== undefined) process.env.RUNTIME_TIMEOUT_MS = saved;
90
+ else delete process.env.RUNTIME_TIMEOUT_MS;
91
+ }
92
+ });
93
+
94
+ test("runtimeTimeoutMs rejects non-numeric workspace config values", () => {
95
+ const saved = process.env.RUNTIME_TIMEOUT_MS;
96
+ delete process.env.RUNTIME_TIMEOUT_MS;
97
+ writeFileSync(
98
+ join(testWorkspaceDir, "config.json"),
99
+ JSON.stringify({ gateway: { runtimeTimeoutMs: true } }),
100
+ );
101
+
102
+ try {
103
+ expect(() => loadConfig()).toThrow(
104
+ "gateway.runtimeTimeoutMs must be a positive integer",
105
+ );
106
+ } finally {
107
+ if (saved !== undefined) process.env.RUNTIME_TIMEOUT_MS = saved;
108
+ else delete process.env.RUNTIME_TIMEOUT_MS;
109
+ writeFileSync(join(testWorkspaceDir, "config.json"), "{}");
110
+ }
111
+ });
112
+
64
113
  test("gatewayInternalBaseUrl derives from port", () => {
65
114
  const saved = process.env.GATEWAY_PORT;
66
115
  process.env.GATEWAY_PORT = "8080";
@@ -0,0 +1,85 @@
1
+ import { describe, test, expect, beforeEach, afterEach, mock } from "bun:test";
2
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+
6
+ // Each test gets a fresh, uniquely-named flag directory. Reusing one path
7
+ // across tests (rm + recreate) leaves fs.watch bound to a stale inode, so
8
+ // file events on the recreated directory are silently dropped.
9
+ let flagDir = "";
10
+
11
+ mock.module("../feature-flag-store.js", () => ({
12
+ clearFeatureFlagStoreCache: mock(() => {}),
13
+ getFeatureFlagStorePath: () => join(flagDir, "feature-flags.json"),
14
+ }));
15
+
16
+ mock.module("../feature-flag-remote-store.js", () => ({
17
+ refreshRemoteFeatureFlagStoreCache: mock(() => {}),
18
+ getRemoteFeatureFlagStorePath: () =>
19
+ join(flagDir, "remote-feature-flags.json"),
20
+ }));
21
+
22
+ const { FeatureFlagWatcher } = await import("../feature-flag-watcher.js");
23
+
24
+ describe("FeatureFlagWatcher onChanged callback", () => {
25
+ beforeEach(() => {
26
+ flagDir = mkdtempSync(join(tmpdir(), "ff-watcher-test-"));
27
+ mkdirSync(flagDir, { recursive: true });
28
+ writeFileSync(join(flagDir, "feature-flags.json"), "{}");
29
+ });
30
+
31
+ afterEach(() => {
32
+ try {
33
+ rmSync(flagDir, { recursive: true, force: true });
34
+ } catch {
35
+ // best effort
36
+ }
37
+ });
38
+
39
+ test("calls onChanged after debounce fires on local flag file change", async () => {
40
+ const onChanged = mock(() => {});
41
+ const watcher = new FeatureFlagWatcher({ onChanged });
42
+ watcher.start();
43
+
44
+ writeFileSync(
45
+ join(flagDir, "feature-flags.json"),
46
+ JSON.stringify({ test: true }),
47
+ );
48
+
49
+ await new Promise((r) => setTimeout(r, 700));
50
+
51
+ expect(onChanged).toHaveBeenCalledTimes(1);
52
+ watcher.stop();
53
+ });
54
+
55
+ test("calls onChanged after debounce fires on remote flag file change", async () => {
56
+ const onChanged = mock(() => {});
57
+ const watcher = new FeatureFlagWatcher({ onChanged });
58
+ watcher.start();
59
+
60
+ writeFileSync(
61
+ join(flagDir, "remote-feature-flags.json"),
62
+ JSON.stringify({ remote: true }),
63
+ );
64
+
65
+ await new Promise((r) => setTimeout(r, 700));
66
+
67
+ expect(onChanged).toHaveBeenCalledTimes(1);
68
+ watcher.stop();
69
+ });
70
+
71
+ test("does not call onChanged when no callback is provided", async () => {
72
+ const watcher = new FeatureFlagWatcher();
73
+ watcher.start();
74
+
75
+ writeFileSync(
76
+ join(flagDir, "feature-flags.json"),
77
+ JSON.stringify({ test: true }),
78
+ );
79
+
80
+ await new Promise((r) => setTimeout(r, 700));
81
+
82
+ // No assertion needed — just verify no error is thrown
83
+ watcher.stop();
84
+ });
85
+ });
@@ -324,7 +324,7 @@ describe("GET /v1/feature-flags handler", () => {
324
324
  });
325
325
 
326
326
  test("reflects updated flags after remote sync writes new values (stale cache regression)", async () => {
327
- // Scenario: the LD poller (RemoteFeatureFlagSync) writes
327
+ // Scenario: the remote poller (RemoteFeatureFlagSync) writes
328
328
  // email-channel: false, the gateway caches it, then a subsequent
329
329
  // poll writes email-channel: true. The GET handler should return
330
330
  // the updated value because writeRemoteFeatureFlags() updates
@@ -398,6 +398,45 @@ describe("GET /v1/feature-flags handler", () => {
398
398
  expect(browserFlag.defaultEnabled).toBe(true);
399
399
  });
400
400
 
401
+ test("declared flags missing from a remote snapshot default to disabled", async () => {
402
+ // No local override
403
+ if (existsSync(featureFlagStorePath)) {
404
+ rmSync(featureFlagStorePath);
405
+ }
406
+ clearFeatureFlagStoreCache();
407
+
408
+ // Remote snapshot exists, but browser is absent as it would be when the
409
+ // platform has no LaunchDarkly value for that key.
410
+ writeFileSync(
411
+ remoteFeatureFlagStorePath,
412
+ JSON.stringify({
413
+ version: 1,
414
+ values: { "email-channel": true },
415
+ }),
416
+ );
417
+ clearRemoteFeatureFlagStoreCache();
418
+
419
+ const handler = createFeatureFlagsGetHandler();
420
+ const res = await handler(
421
+ new Request("http://gateway.test/v1/feature-flags"),
422
+ );
423
+
424
+ expect(res.status).toBe(200);
425
+ const body = await res.json();
426
+
427
+ const emailFlag = body.flags.find(
428
+ (f: { key: string }) => f.key === "email-channel",
429
+ );
430
+ expect(emailFlag.enabled).toBe(true);
431
+
432
+ const browserFlag = body.flags.find(
433
+ (f: { key: string }) => f.key === "browser",
434
+ );
435
+ expect(browserFlag).toBeDefined();
436
+ expect(browserFlag.enabled).toBe(false);
437
+ expect(browserFlag.defaultEnabled).toBe(true);
438
+ });
439
+
401
440
  test("returns flags when invoked via assistants path without trailing slash", async () => {
402
441
  // The macOS client sends GET /v1/assistants/<id>/feature-flags (no trailing slash).
403
442
  // The gateway route regex must accept this path.
@@ -215,6 +215,30 @@ describe("IPC feature flag routes", () => {
215
215
  expect(flags["email-channel"]).toBe(true); // remote overrides default
216
216
  });
217
217
 
218
+ test("get_feature_flags disables declared flags missing from a remote snapshot", async () => {
219
+ writeFileSync(
220
+ remoteFeatureFlagStorePath,
221
+ JSON.stringify({
222
+ version: 1,
223
+ values: { "email-channel": true },
224
+ }),
225
+ );
226
+ clearRemoteFeatureFlagStoreCache();
227
+
228
+ if (existsSync(featureFlagStorePath)) {
229
+ rmSync(featureFlagStorePath);
230
+ }
231
+ clearFeatureFlagStoreCache();
232
+
233
+ await startServerAndConnect();
234
+ const res = await sendRequest(client, "get_feature_flags");
235
+
236
+ expect(res.error).toBeUndefined();
237
+ const flags = res.result as Record<string, boolean>;
238
+ expect(flags["email-channel"]).toBe(true);
239
+ expect(flags["browser"]).toBe(false);
240
+ });
241
+
218
242
  test("get_feature_flag returns value for a known flag", async () => {
219
243
  await startServerAndConnect();
220
244
  const res = await sendRequest(client, "get_feature_flag", {
@@ -0,0 +1,157 @@
1
+ import {
2
+ afterAll,
3
+ afterEach,
4
+ beforeAll,
5
+ beforeEach,
6
+ describe,
7
+ expect,
8
+ test,
9
+ } from "bun:test";
10
+ import { randomBytes } from "node:crypto";
11
+ import { createConnection, type Socket } from "node:net";
12
+
13
+ import {
14
+ getGatewayDb,
15
+ initGatewayDb,
16
+ resetGatewayDb,
17
+ } from "../db/connection.js";
18
+ import { SlackStore } from "../db/slack-store.js";
19
+ import { slackActiveThreads } from "../db/schema.js";
20
+ import { GatewayIpcServer } from "../ipc/server.js";
21
+ import { slackThreadRoutes } from "../ipc/slack-thread-handlers.js";
22
+
23
+ const CHANNEL_ID = "CFAKE00001";
24
+ const OTHER_CHANNEL_ID = "COTHER0001";
25
+ const THREAD_TS = "1700000000.000000";
26
+ const OTHER_THREAD_TS = "1700000001.000000";
27
+
28
+ beforeAll(async () => {
29
+ await initGatewayDb();
30
+ });
31
+
32
+ beforeEach(() => {
33
+ getGatewayDb().delete(slackActiveThreads).run();
34
+ });
35
+
36
+ afterAll(() => {
37
+ resetGatewayDb();
38
+ });
39
+
40
+ function connectClient(path: string): Promise<Socket> {
41
+ return new Promise((resolve, reject) => {
42
+ const client = createConnection(path, () => resolve(client));
43
+ client.on("error", reject);
44
+ });
45
+ }
46
+
47
+ function sendRequest(
48
+ client: Socket,
49
+ method: string,
50
+ params?: Record<string, unknown>,
51
+ ): Promise<{ id: string; result?: unknown; error?: string }> {
52
+ return new Promise((resolve, reject) => {
53
+ const id = randomBytes(4).toString("hex");
54
+ let buffer = "";
55
+
56
+ const onData = (chunk: Buffer) => {
57
+ buffer += chunk.toString();
58
+ const newlineIdx = buffer.indexOf("\n");
59
+ if (newlineIdx !== -1) {
60
+ const line = buffer.slice(0, newlineIdx).trim();
61
+ buffer = buffer.slice(newlineIdx + 1);
62
+ client.off("data", onData);
63
+ try {
64
+ resolve(JSON.parse(line));
65
+ } catch (err) {
66
+ reject(err);
67
+ }
68
+ }
69
+ };
70
+
71
+ client.on("data", onData);
72
+ client.write(JSON.stringify({ id, method, params }) + "\n");
73
+ });
74
+ }
75
+
76
+ function activeThreadRows(): Array<{ threadTs: string; channelId: string }> {
77
+ return new SlackStore(getGatewayDb()).listActiveThreadsWithChannel();
78
+ }
79
+
80
+ function trackThread(): void {
81
+ new SlackStore(getGatewayDb()).trackThread(THREAD_TS, CHANNEL_ID, 60_000);
82
+ }
83
+
84
+ describe("IPC Slack thread routes", () => {
85
+ let server: InstanceType<typeof GatewayIpcServer>;
86
+ let client: Socket;
87
+
88
+ afterEach(() => {
89
+ client?.destroy();
90
+ server?.stop();
91
+ });
92
+
93
+ async function startServerAndConnect(): Promise<void> {
94
+ server = new GatewayIpcServer([...slackThreadRoutes]);
95
+ server.start();
96
+ await new Promise((resolve) => setTimeout(resolve, 50));
97
+ client = await connectClient(server.getSocketPath());
98
+ }
99
+
100
+ test("detach_slack_active_thread removes a matching active thread", async () => {
101
+ trackThread();
102
+
103
+ await startServerAndConnect();
104
+ const res = await sendRequest(client, "detach_slack_active_thread", {
105
+ channelId: CHANNEL_ID,
106
+ threadTs: THREAD_TS,
107
+ });
108
+
109
+ expect(res.error).toBeUndefined();
110
+ expect(res.result).toEqual({
111
+ detached: true,
112
+ channelId: CHANNEL_ID,
113
+ threadTs: THREAD_TS,
114
+ });
115
+ expect(activeThreadRows()).toEqual([]);
116
+ });
117
+
118
+ test("detach_slack_active_thread is idempotent for an unknown thread", async () => {
119
+ trackThread();
120
+
121
+ await startServerAndConnect();
122
+ const res = await sendRequest(client, "detach_slack_active_thread", {
123
+ channelId: CHANNEL_ID,
124
+ threadTs: OTHER_THREAD_TS,
125
+ });
126
+
127
+ expect(res.error).toBeUndefined();
128
+ expect(res.result).toEqual({
129
+ detached: false,
130
+ channelId: CHANNEL_ID,
131
+ threadTs: OTHER_THREAD_TS,
132
+ });
133
+ expect(activeThreadRows()).toEqual([
134
+ { threadTs: THREAD_TS, channelId: CHANNEL_ID },
135
+ ]);
136
+ });
137
+
138
+ test("detach_slack_active_thread does not remove channel mismatches", async () => {
139
+ trackThread();
140
+
141
+ await startServerAndConnect();
142
+ const res = await sendRequest(client, "detach_slack_active_thread", {
143
+ channelId: OTHER_CHANNEL_ID,
144
+ threadTs: THREAD_TS,
145
+ });
146
+
147
+ expect(res.error).toBeUndefined();
148
+ expect(res.result).toEqual({
149
+ detached: false,
150
+ channelId: OTHER_CHANNEL_ID,
151
+ threadTs: THREAD_TS,
152
+ });
153
+ expect(activeThreadRows()).toEqual([
154
+ { threadTs: THREAD_TS, channelId: CHANNEL_ID },
155
+ ]);
156
+ });
157
+ });
@@ -38,7 +38,7 @@ const { resetFeatureFlagDefaultsCache, _setRegistryCandidateOverrides } =
38
38
 
39
39
  // ---------------------------------------------------------------------------
40
40
  // Test-local registry with a GA flag (defaultEnabled: true) for the
41
- // "ignores remote false for GA flags" test. Written to an isolated temp path
41
+ // "normalizes remote false for GA flags" test. Written to an isolated temp path
42
42
  // so we never touch the committed registry file.
43
43
  // ---------------------------------------------------------------------------
44
44
  const testRegistryPath = join(protectedDir, "feature-flag-registry.json");
@@ -459,7 +459,7 @@ describe("RemoteFeatureFlagSync", () => {
459
459
  );
460
460
  });
461
461
 
462
- test("ignores remote false for GA flags (defaultEnabled: true in registry)", async () => {
462
+ test("normalizes remote false for GA flags (defaultEnabled: true in registry)", async () => {
463
463
  // The platform sends false for all flags it knows about (blanket-deny).
464
464
  // GA flags (defaultEnabled: true in the registry) should not be disabled
465
465
  // by remote overrides — only local persisted overrides can do that.
@@ -468,7 +468,8 @@ describe("RemoteFeatureFlagSync", () => {
468
468
  fetchMock = mock(async () =>
469
469
  Response.json({
470
470
  flags: {
471
- // GA flag (defaultEnabled: true) — remote false should be dropped
471
+ // GA flag (defaultEnabled: true) — remote false should be normalized
472
+ // to true so the missing-key fallback does not disable it.
472
473
  "test-ga-flag": false,
473
474
  // Gated flag (defaultEnabled: false) — remote false is kept
474
475
  "email-channel": false,
@@ -488,8 +489,8 @@ describe("RemoteFeatureFlagSync", () => {
488
489
 
489
490
  clearRemoteFeatureFlagStoreCache();
490
491
  const cached = readRemoteFeatureFlags();
491
- // test-ga-flag (GA, remote false) should be absent
492
- expect(cached["test-ga-flag"]).toBeUndefined();
492
+ // test-ga-flag (GA, remote false) should be normalized to true
493
+ expect(cached["test-ga-flag"]).toBe(true);
493
494
  // email-channel (gated, remote false) should be present
494
495
  expect(cached["email-channel"]).toBe(false);
495
496
  // test-ga-flag-true (unknown but true) should be present
@@ -498,6 +499,75 @@ describe("RemoteFeatureFlagSync", () => {
498
499
  expect(cached["unknown-flag"]).toBe(false);
499
500
  });
500
501
 
502
+ test("calls onChanged when remote flags change", async () => {
503
+ fetchMock = mock(async () =>
504
+ Response.json({
505
+ flags: { "new-flag": true },
506
+ }),
507
+ );
508
+
509
+ const onChanged = mock(() => {});
510
+ const sync = new RemoteFeatureFlagSync({
511
+ credentials: fakeCredentialCache(defaultCredentials()),
512
+ onChanged,
513
+ });
514
+ await sync.start();
515
+ sync.stop();
516
+
517
+ expect(fetchMock).toHaveBeenCalledTimes(1);
518
+ expect(onChanged).toHaveBeenCalledTimes(1);
519
+ });
520
+
521
+ test("does not call onChanged when remote flags have not changed", async () => {
522
+ // First sync to seed the file
523
+ fetchMock = mock(async () =>
524
+ Response.json({
525
+ flags: { "stable-flag": true },
526
+ }),
527
+ );
528
+
529
+ const onChanged1 = mock(() => {});
530
+ const sync1 = new RemoteFeatureFlagSync({
531
+ credentials: fakeCredentialCache(defaultCredentials()),
532
+ onChanged: onChanged1,
533
+ });
534
+ await sync1.start();
535
+ sync1.stop();
536
+ expect(onChanged1).toHaveBeenCalledTimes(1);
537
+
538
+ // Second sync with same data — onChanged should NOT fire
539
+ fetchMock = mock(async () =>
540
+ Response.json({
541
+ flags: { "stable-flag": true },
542
+ }),
543
+ );
544
+
545
+ const onChanged2 = mock(() => {});
546
+ const sync2 = new RemoteFeatureFlagSync({
547
+ credentials: fakeCredentialCache(defaultCredentials()),
548
+ onChanged: onChanged2,
549
+ });
550
+ await sync2.start();
551
+ sync2.stop();
552
+ expect(onChanged2).not.toHaveBeenCalled();
553
+ });
554
+
555
+ test("does not call onChanged on fetch failure", async () => {
556
+ fetchMock = mock(
557
+ async () => new Response("Internal Server Error", { status: 500 }),
558
+ );
559
+
560
+ const onChanged = mock(() => {});
561
+ const sync = new RemoteFeatureFlagSync({
562
+ credentials: fakeCredentialCache(defaultCredentials()),
563
+ onChanged,
564
+ });
565
+ await sync.start();
566
+ sync.stop();
567
+
568
+ expect(onChanged).not.toHaveBeenCalled();
569
+ });
570
+
501
571
  test("trims whitespace from credential values", async () => {
502
572
  fetchMock = mock(async () => Response.json({ flags: {} }));
503
573
 
@@ -173,6 +173,8 @@ const EXCLUDED_FROM_SCHEMA = new Set([
173
173
  "/v1/pair",
174
174
  // A2A agent card discovery — read-only, unauthenticated per spec
175
175
  "/.well-known/agent-card.json",
176
+ // Internal-only: reachable only via vembda's trusted gateway-query proxy
177
+ "/v1/contacts/guardian/channel",
176
178
  ]);
177
179
 
178
180
  // ── Schema paths that don't map to a discrete route definition ──