test: add elevated mode regressions

This commit is contained in:
Peter Steinberger
2026-01-10 05:31:48 +01:00
parent 66db6c749d
commit 920b3880c1
4 changed files with 313 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
import { describe, expect, test } from "vitest";
import type { ClawdbotConfig } from "../config/config.js";
import type { SessionEntry } from "../config/sessions.js";
import { applySessionsPatchToStore } from "./sessions-patch.js";
describe("gateway sessions patch", () => {
test("persists elevatedLevel=off (does not clear)", async () => {
const store: Record<string, SessionEntry> = {};
const res = await applySessionsPatchToStore({
cfg: {} as ClawdbotConfig,
store,
storeKey: "agent:main:main",
patch: { elevatedLevel: "off" },
});
expect(res.ok).toBe(true);
if (!res.ok) return;
expect(res.entry.elevatedLevel).toBe("off");
});
test("persists elevatedLevel=on", async () => {
const store: Record<string, SessionEntry> = {};
const res = await applySessionsPatchToStore({
cfg: {} as ClawdbotConfig,
store,
storeKey: "agent:main:main",
patch: { elevatedLevel: "on" },
});
expect(res.ok).toBe(true);
if (!res.ok) return;
expect(res.entry.elevatedLevel).toBe("on");
});
test("clears elevatedLevel when patch sets null", async () => {
const store: Record<string, SessionEntry> = {
"agent:main:main": { elevatedLevel: "off" } as SessionEntry,
};
const res = await applySessionsPatchToStore({
cfg: {} as ClawdbotConfig,
store,
storeKey: "agent:main:main",
patch: { elevatedLevel: null },
});
expect(res.ok).toBe(true);
if (!res.ok) return;
expect(res.entry.elevatedLevel).toBeUndefined();
});
test("rejects invalid elevatedLevel values", async () => {
const store: Record<string, SessionEntry> = {};
const res = await applySessionsPatchToStore({
cfg: {} as ClawdbotConfig,
store,
storeKey: "agent:main:main",
patch: { elevatedLevel: "maybe" },
});
expect(res.ok).toBe(false);
if (res.ok) return;
expect(res.error.message).toContain("invalid elevatedLevel");
});
});