Skip to content

Commit bd20b12

Browse files
committed
refactor(channels): remove private persisted-auth probe seam
1 parent a7a0af2 commit bd20b12

2 files changed

Lines changed: 24 additions & 52 deletions

File tree

‎src/channels/config-presence.test.ts‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import fs from "node:fs";
33
import os from "node:os";
44
import path from "node:path";
5-
import { afterEach, describe, expect, it } from "vitest";
5+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
66
import type { OpenClawConfig } from "../config/config.js";
77
import { isChannelConfigMetadataKey } from "./config-metadata.js";
88
import {
@@ -11,17 +11,21 @@ import {
1111
listPotentialConfiguredChannelPresenceSignals,
1212
listPotentialConfiguredChannelIds,
1313
} from "./config-presence.js";
14+
import * as persistedAuthState from "./plugins/persisted-auth-state.js";
1415

1516
const tempDirs: string[] = [];
1617

17-
const matrixPresenceOptions = {
18-
channelIds: ["matrix"],
19-
persistedAuthStateProbe: {
20-
listChannelIds: () => ["matrix"],
21-
hasState: ({ channelId, env }: { channelId: string; env?: NodeJS.ProcessEnv }) =>
18+
const matrixPresenceOptions = { channelIds: ["matrix"] };
19+
20+
beforeEach(() => {
21+
vi.spyOn(persistedAuthState, "listBundledChannelIdsWithPersistedAuthState").mockReturnValue([
22+
"matrix",
23+
]);
24+
vi.spyOn(persistedAuthState, "hasBundledChannelPersistedAuthState").mockImplementation(
25+
({ channelId, env }) =>
2226
channelId === "matrix" && Boolean(env?.OPENCLAW_STATE_DIR?.includes("persisted-matrix")),
23-
},
24-
};
27+
);
28+
});
2529

2630
function makeTempStateDir() {
2731
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-channel-config-presence-"));
@@ -42,6 +46,7 @@ function expectPotentialConfiguredChannelCase(params: {
4246
}
4347

4448
afterEach(() => {
49+
vi.restoreAllMocks();
4550
while (tempDirs.length > 0) {
4651
const dir = tempDirs.pop();
4752
if (dir) {
@@ -154,12 +159,7 @@ describe("config presence", () => {
154159
cfg: {},
155160
env,
156161
expectedIds: ["matrix"],
157-
options: {
158-
persistedAuthStateProbe: {
159-
listChannelIds: () => ["matrix"],
160-
hasState: () => true,
161-
},
162-
},
162+
options: {},
163163
});
164164
});
165165
});

‎src/channels/config-presence.ts‎

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ type ChannelPresenceOptions = {
2929
discovery?: PluginDiscoveryResult;
3030
includePersistedAuthState?: boolean;
3131
ambientEnvTriggers?: AmbientEnvTriggerPolicy;
32-
persistedAuthStateProbe?: {
33-
listChannelIds: () => readonly string[];
34-
hasState: (params: {
35-
channelId: string;
36-
cfg: OpenClawConfig;
37-
env: NodeJS.ProcessEnv;
38-
}) => boolean;
39-
};
4032
};
4133

4234
/** Source that made a channel look potentially configured. */
@@ -85,31 +77,6 @@ function hasPersistedChannelState(env: NodeJS.ProcessEnv): boolean {
8577
return fs.existsSync(resolveStateDir(env, os.homedir));
8678
}
8779

88-
function listPersistedAuthStateChannelIds(options: ChannelPresenceOptions): readonly string[] {
89-
return (
90-
options.persistedAuthStateProbe?.listChannelIds() ??
91-
listBundledChannelIdsWithPersistedAuthState(options.discovery)
92-
);
93-
}
94-
95-
function hasPersistedAuthState(params: {
96-
channelId: string;
97-
cfg: OpenClawConfig;
98-
env: NodeJS.ProcessEnv;
99-
options: ChannelPresenceOptions;
100-
}): boolean {
101-
const override = params.options.persistedAuthStateProbe;
102-
if (override) {
103-
return override.hasState(params);
104-
}
105-
return hasBundledChannelPersistedAuthState({
106-
channelId: params.channelId,
107-
cfg: params.cfg,
108-
env: params.env,
109-
discovery: params.options.discovery,
110-
});
111-
}
112-
11380
/** Lists channel ids detected from config, env vars, or persisted auth state. */
11481
export function listPotentialConfiguredChannelIds(
11582
cfg: OpenClawConfig,
@@ -131,7 +98,6 @@ export function listPotentialConfiguredChannelPresenceSignals(
13198
): ChannelPresenceSignal[] {
13299
const signals: ChannelPresenceSignal[] = [];
133100
const seenSignals = new Set<string>();
134-
const configuredChannelIds = new Set<string>();
135101
const addSignal = (rawChannelId: string, source: ChannelPresenceSignalSource) => {
136102
const channelId = rawChannelId.trim();
137103
if (!channelId || isChannelConfigMetadataKey(channelId)) {
@@ -142,7 +108,6 @@ export function listPotentialConfiguredChannelPresenceSignals(
142108
return;
143109
}
144110
seenSignals.add(key);
145-
configuredChannelIds.add(channelId);
146111
signals.push({ channelId, source });
147112
};
148113
const channelIds = options.channelIds ?? listBundledChannelIds(env, options.discovery);
@@ -192,12 +157,19 @@ export function listPotentialConfiguredChannelPresenceSignals(
192157
if (options.includePersistedAuthState !== false && hasPersistedChannelState(env)) {
193158
// Persisted auth can make a channel usable even when config/env is empty, but only probe it
194159
// when the state directory exists to keep startup/status checks cheap.
195-
for (const channelId of listPersistedAuthStateChannelIds(options)) {
196-
if (hasPersistedAuthState({ channelId, cfg, env, options })) {
160+
for (const channelId of listBundledChannelIdsWithPersistedAuthState(options.discovery)) {
161+
if (
162+
hasBundledChannelPersistedAuthState({
163+
channelId,
164+
cfg,
165+
env,
166+
discovery: options.discovery,
167+
})
168+
) {
197169
addSignal(channelId, "persisted-auth");
198170
}
199171
}
200172
}
201173

202-
return signals.filter((signal) => configuredChannelIds.has(signal.channelId));
174+
return signals;
203175
}

0 commit comments

Comments
 (0)