Skip to content

Commit 4cb33d4

Browse files
authored
refactor(config): consolidate regression fixtures (#114459)
1 parent b869d5e commit 4cb33d4

6 files changed

Lines changed: 160 additions & 317 deletions

‎src/config/group-scope-tree.test.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,31 @@ import { describe, expect, it } from "vitest";
33
import type { OpenClawConfig } from "./config.js";
44
import { resolveChannelGroupRequireMention, resolveToolsBySender } from "./group-policy.js";
55
import {
6+
resolveScopeKeyCaseInsensitive,
67
resolveScopeIntroHint,
78
resolveScopeRequireMention,
89
resolveScopeToolsPolicy,
910
type ScopeTree,
1011
} from "./group-scope-tree.js";
1112

13+
describe("resolveScopeKeyCaseInsensitive", () => {
14+
it("preserves exact scope identity before case-insensitive fallback", () => {
15+
const tree: ScopeTree = {
16+
scopes: {
17+
"Room:Mixed": { requireMention: true },
18+
"room:mixed": { requireMention: false },
19+
},
20+
};
21+
22+
expect(resolveScopeKeyCaseInsensitive(tree, "Room:Mixed")).toBe("Room:Mixed");
23+
expect(resolveScopeKeyCaseInsensitive(tree, "ROOM:MIXED")).toBe("Room:Mixed");
24+
expect(resolveScopeKeyCaseInsensitive(tree, " room:mixed ")).toBe("Room:Mixed");
25+
expect(resolveScopeKeyCaseInsensitive(tree, "unknown")).toBeUndefined();
26+
expect(resolveScopeKeyCaseInsensitive(tree, undefined)).toBeUndefined();
27+
expect(resolveScopeKeyCaseInsensitive(tree, null)).toBeUndefined();
28+
});
29+
});
30+
1231
describe("resolveScopeRequireMention", () => {
1332
const scalarCases: Array<{
1433
name: string;

‎src/config/plugin-auto-enable.channels.test.ts‎

Lines changed: 31 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,30 @@ function applyWithApnChannelConfig(extra?: {
3434
});
3535
}
3636

37+
function materializeEnvCatalogCandidates(
38+
stateDir: string,
39+
candidates: Parameters<typeof materializePluginAutoEnableCandidates>[0]["candidates"] = [
40+
{ pluginId: "env-primary", kind: "channel-configured", channelId: "env-primary" },
41+
{ pluginId: "env-secondary", kind: "channel-configured", channelId: "env-secondary" },
42+
],
43+
) {
44+
return materializePluginAutoEnableCandidates({
45+
config: {
46+
channels: {
47+
"env-primary": { token: "primary" },
48+
"env-secondary": { token: "secondary" },
49+
},
50+
},
51+
candidates,
52+
env: {
53+
...makeIsolatedEnv(),
54+
OPENCLAW_STATE_DIR: stateDir,
55+
OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins",
56+
},
57+
manifestRegistry: makeRegistry([]),
58+
});
59+
}
60+
3761
beforeEach(() => {
3862
resetPluginAutoEnableTestState();
3963
});
@@ -73,32 +97,7 @@ describe("applyPluginAutoEnable channels", () => {
7397
"utf-8",
7498
);
7599

76-
const result = materializePluginAutoEnableCandidates({
77-
config: {
78-
channels: {
79-
"env-primary": { token: "primary" },
80-
"env-secondary": { token: "secondary" },
81-
},
82-
},
83-
candidates: [
84-
{
85-
pluginId: "env-primary",
86-
kind: "channel-configured",
87-
channelId: "env-primary",
88-
},
89-
{
90-
pluginId: "env-secondary",
91-
kind: "channel-configured",
92-
channelId: "env-secondary",
93-
},
94-
],
95-
env: {
96-
...makeIsolatedEnv(),
97-
OPENCLAW_STATE_DIR: stateDir,
98-
OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins",
99-
},
100-
manifestRegistry: makeRegistry([]),
101-
});
100+
const result = materializeEnvCatalogCandidates(stateDir);
102101

103102
expect(result.config.plugins?.entries?.["env-secondary"]?.enabled).toBe(true);
104103
expect(result.config.plugins?.entries?.["env-primary"]).toBeUndefined();
@@ -151,25 +150,14 @@ describe("applyPluginAutoEnable channels", () => {
151150
const realpathSpy = vi.spyOn(fs, "realpathSync");
152151

153152
try {
154-
materializePluginAutoEnableCandidates({
155-
config: {
156-
channels: {
157-
"env-primary": { token: "primary" },
158-
"env-secondary": { token: "secondary" },
159-
},
160-
},
161-
candidates: Array.from({ length: 20 }, (_, index) => ({
153+
materializeEnvCatalogCandidates(
154+
stateDir,
155+
Array.from({ length: 20 }, (_, index) => ({
162156
pluginId: index % 2 === 0 ? "env-primary" : "env-secondary",
163157
kind: "channel-configured" as const,
164158
channelId: index % 2 === 0 ? "env-primary" : "env-secondary",
165159
})),
166-
env: {
167-
...makeIsolatedEnv(),
168-
OPENCLAW_STATE_DIR: stateDir,
169-
OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins",
170-
},
171-
manifestRegistry: makeRegistry([]),
172-
});
160+
);
173161

174162
expect(
175163
realpathSpy.mock.calls.filter(([filePath]) =>
@@ -211,32 +199,7 @@ describe("applyPluginAutoEnable channels", () => {
211199
const catalogPath = path.join(pluginsDir, "catalog.json");
212200
fs.symlinkSync(realPath, catalogPath);
213201

214-
const result = materializePluginAutoEnableCandidates({
215-
config: {
216-
channels: {
217-
"env-primary": { token: "primary" },
218-
"env-secondary": { token: "secondary" },
219-
},
220-
},
221-
candidates: [
222-
{
223-
pluginId: "env-primary",
224-
kind: "channel-configured" as const,
225-
channelId: "env-primary",
226-
},
227-
{
228-
pluginId: "env-secondary",
229-
kind: "channel-configured" as const,
230-
channelId: "env-secondary",
231-
},
232-
],
233-
env: {
234-
...makeIsolatedEnv(),
235-
OPENCLAW_STATE_DIR: stateDir,
236-
OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins",
237-
},
238-
manifestRegistry: makeRegistry([]),
239-
});
202+
const result = materializeEnvCatalogCandidates(stateDir);
240203

241204
expect(result.config.plugins?.entries?.["env-secondary"]?.enabled).toBe(true);
242205
expect(result.config.plugins?.entries?.["env-primary"]).toBeUndefined();
@@ -257,32 +220,7 @@ describe("applyPluginAutoEnable channels", () => {
257220
fs.closeSync(fd);
258221
}
259222

260-
const result = materializePluginAutoEnableCandidates({
261-
config: {
262-
channels: {
263-
"env-primary": { token: "primary" },
264-
"env-secondary": { token: "secondary" },
265-
},
266-
},
267-
candidates: [
268-
{
269-
pluginId: "env-primary",
270-
kind: "channel-configured" as const,
271-
channelId: "env-primary",
272-
},
273-
{
274-
pluginId: "env-secondary",
275-
kind: "channel-configured" as const,
276-
channelId: "env-secondary",
277-
},
278-
],
279-
env: {
280-
...makeIsolatedEnv(),
281-
OPENCLAW_STATE_DIR: stateDir,
282-
OPENCLAW_BUNDLED_PLUGINS_DIR: "/nonexistent/bundled/plugins",
283-
},
284-
manifestRegistry: makeRegistry([]),
285-
});
223+
const result = materializeEnvCatalogCandidates(stateDir);
286224

287225
// Selection continues: env-secondary is still auto-enabled.
288226
expect(result.config.plugins?.entries?.["env-secondary"]?.enabled).toBe(true);

‎src/config/sessions/archive-compression.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import os from "node:os";
44
import path from "node:path";
55
import { afterEach, describe, expect, it } from "vitest";
66
import {
7+
decodeSessionArchiveBytes,
78
encodeSessionArchiveContent,
89
materializeSessionArchiveForRead,
910
readSessionArchiveContentSync,
@@ -30,6 +31,31 @@ function makeTempDir(): string {
3031
}
3132

3233
describe("archive compression", () => {
34+
it("decodes both plain bytes and runtime-supported compressed archive bytes", () => {
35+
const content = `${JSON.stringify({ type: "message", body: "archive round trip" })}\n`;
36+
const encoded = encodeSessionArchiveContent(content);
37+
38+
expect(decodeSessionArchiveBytes(Buffer.from(content, "utf8"), false)).toBe(content);
39+
expect(decodeSessionArchiveBytes(encoded.bytes, encoded.suffix !== "")).toBe(content);
40+
});
41+
42+
it("invalidates a materialized cache when its source archive is removed", () => {
43+
const encoded = encodeSessionArchiveContent("cached archive contents\n");
44+
if (encoded.suffix !== SESSION_ARCHIVE_ZSTD_SUFFIX) {
45+
return;
46+
}
47+
const dir = makeTempDir();
48+
const archivePath = path.join(dir, `removed.jsonl.deleted.2026-07-11${encoded.suffix}`);
49+
fs.writeFileSync(archivePath, encoded.bytes);
50+
const cachePath = materializeSessionArchiveForRead(archivePath);
51+
expect(fs.existsSync(cachePath)).toBe(true);
52+
53+
fs.rmSync(archivePath);
54+
55+
expect(() => materializeSessionArchiveForRead(archivePath)).toThrow();
56+
expect(fs.existsSync(cachePath)).toBe(false);
57+
});
58+
3359
it("round-trips archived transcript content through encode and read", () => {
3460
const content = `${JSON.stringify({ type: "message", body: "hello" })}\n`.repeat(200);
3561
const encoded = encodeSessionArchiveContent(content);

0 commit comments

Comments
 (0)