Skip to content

Commit 6c3e932

Browse files
committed
test(config): preserve group scope and archive cache branch coverage
1 parent b7caef7 commit 6c3e932

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

‎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/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)