Skip to content

Commit 0245765

Browse files
ml12580claude
andauthored
fix(tlon): wire autoDiscoverChannels through the settings-store round-trip (#114949)
parseSettingsResponse and applySettingsUpdate read/wrote a dead `autoDiscover` key, while every consumer (monitor/settings-helpers.ts) and the settings migration use `autoDiscoverChannels`. As a result the settings-store hot-reload override for auto-discover-channels never took effect and the migration re-fired on every restart. Align the field name and add a regression test covering both the load and subscription paths. Co-authored-by: Claude <[email protected]>
1 parent 65f3e42 commit 0245765

2 files changed

Lines changed: 77 additions & 4 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Tlon tests cover settings store behavior.
2+
import { describe, expect, it } from "vitest";
3+
import { createSettingsManager } from "./settings.js";
4+
import type { UrbitSSEClient } from "./urbit/sse-client.js";
5+
6+
type SubscriptionHandlers = {
7+
event?: (data: unknown) => Promise<void> | void;
8+
};
9+
10+
function createMockSettingsApi(scryResult: unknown): {
11+
api: UrbitSSEClient;
12+
emitSettingsEvent: (event: unknown) => Promise<void>;
13+
} {
14+
const handlers: SubscriptionHandlers = {};
15+
const api = {
16+
async scry() {
17+
return scryResult;
18+
},
19+
async subscribe(params: {
20+
app: string;
21+
path: string;
22+
event?: (data: unknown) => Promise<void> | void;
23+
}) {
24+
handlers.event = params.event;
25+
return 1;
26+
},
27+
} as unknown as UrbitSSEClient;
28+
return {
29+
api,
30+
emitSettingsEvent: async (event: unknown) => {
31+
await handlers.event?.(event);
32+
},
33+
};
34+
}
35+
36+
describe("tlon settings store", () => {
37+
it("loads autoDiscoverChannels from the settings-store scry response", async () => {
38+
const { api } = createMockSettingsApi({
39+
all: { moltbot: { tlon: { autoDiscoverChannels: true } } },
40+
});
41+
42+
const manager = createSettingsManager(api);
43+
await manager.load();
44+
45+
// Regression: parseSettingsResponse previously read the dead `autoDiscover`
46+
// key, so the live `autoDiscoverChannels` override never reached the monitor.
47+
expect(manager.current.autoDiscoverChannels).toBe(true);
48+
});
49+
50+
it("applies live autoDiscoverChannels updates delivered over the subscription", async () => {
51+
const { api, emitSettingsEvent } = createMockSettingsApi({
52+
all: { moltbot: { tlon: {} } },
53+
});
54+
55+
const manager = createSettingsManager(api);
56+
await manager.load();
57+
expect(manager.current.autoDiscoverChannels).toBeUndefined();
58+
59+
await manager.startSubscription();
60+
await emitSettingsEvent({
61+
"put-entry": {
62+
desk: "moltbot",
63+
"bucket-key": "tlon",
64+
"entry-key": "autoDiscoverChannels",
65+
value: false,
66+
},
67+
});
68+
69+
expect(manager.current.autoDiscoverChannels).toBe(false);
70+
});
71+
});

‎extensions/tlon/src/settings.ts‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export type PendingApproval = {
3434
export type TlonSettingsStore = {
3535
groupChannels?: string[];
3636
dmAllowlist?: string[];
37-
autoDiscover?: boolean;
3837
showModelSig?: boolean;
3938
autoAcceptDmInvites?: boolean;
4039
autoDiscoverChannels?: boolean;
@@ -118,7 +117,10 @@ function parseSettingsResponse(raw: unknown): TlonSettingsStore {
118117
dmAllowlist: Array.isArray(settings.dmAllowlist)
119118
? settings.dmAllowlist.filter((x): x is string => typeof x === "string")
120119
: undefined,
121-
autoDiscover: typeof settings.autoDiscover === "boolean" ? settings.autoDiscover : undefined,
120+
autoDiscoverChannels:
121+
typeof settings.autoDiscoverChannels === "boolean"
122+
? settings.autoDiscoverChannels
123+
: undefined,
122124
showModelSig: typeof settings.showModelSig === "boolean" ? settings.showModelSig : undefined,
123125
autoAcceptDmInvites:
124126
typeof settings.autoAcceptDmInvites === "boolean" ? settings.autoAcceptDmInvites : undefined,
@@ -249,8 +251,8 @@ function applySettingsUpdate(
249251
? value.filter((x): x is string => typeof x === "string")
250252
: undefined;
251253
break;
252-
case "autoDiscover":
253-
next.autoDiscover = typeof value === "boolean" ? value : undefined;
254+
case "autoDiscoverChannels":
255+
next.autoDiscoverChannels = typeof value === "boolean" ? value : undefined;
254256
break;
255257
case "showModelSig":
256258
next.showModelSig = typeof value === "boolean" ? value : undefined;

0 commit comments

Comments
 (0)