mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:00:42 +00:00
refactor: eliminate remaining duplicate blocks across draft streams and tests
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import fs from "node:fs/promises";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import { loadSessionStore } from "../config/sessions.js";
|
||||
import {
|
||||
@@ -6,6 +5,7 @@ import {
|
||||
loadGetReplyFromConfig,
|
||||
MAIN_SESSION_KEY,
|
||||
makeWhatsAppElevatedCfg,
|
||||
readSessionStore,
|
||||
requireSessionStorePath,
|
||||
runDirectElevatedToggleAndLoadStore,
|
||||
withTempHome,
|
||||
@@ -66,8 +66,7 @@ describe("trigger handling", () => {
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toContain("Elevated mode set to ask");
|
||||
|
||||
const storeRaw = await fs.readFile(requireSessionStorePath(cfg), "utf-8");
|
||||
const store = JSON.parse(storeRaw) as Record<string, { elevatedLevel?: string }>;
|
||||
const store = await readSessionStore(cfg);
|
||||
expect(store["agent:main:whatsapp:group:123@g.us"]?.elevatedLevel).toBe("on");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import fs from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
@@ -9,7 +8,7 @@ import {
|
||||
MAIN_SESSION_KEY,
|
||||
makeCfg,
|
||||
makeWhatsAppElevatedCfg,
|
||||
requireSessionStorePath,
|
||||
readSessionStore,
|
||||
withTempHome,
|
||||
} from "./reply.triggers.trigger-handling.test-harness.js";
|
||||
|
||||
@@ -78,8 +77,7 @@ describe("trigger handling", () => {
|
||||
const text = Array.isArray(res) ? res[0]?.text : res?.text;
|
||||
expect(text).toContain("Elevated mode set to ask");
|
||||
|
||||
const storeRaw = await fs.readFile(requireSessionStorePath(cfg), "utf-8");
|
||||
const store = JSON.parse(storeRaw) as Record<string, { elevatedLevel?: string }>;
|
||||
const store = await readSessionStore(cfg);
|
||||
expect(store[MAIN_SESSION_KEY]?.elevatedLevel).toBe("on");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -147,6 +147,13 @@ export function requireSessionStorePath(cfg: { session?: { store?: string } }):
|
||||
return storePath;
|
||||
}
|
||||
|
||||
export async function readSessionStore(cfg: {
|
||||
session?: { store?: string };
|
||||
}): Promise<Record<string, { elevatedLevel?: string }>> {
|
||||
const storeRaw = await fs.readFile(requireSessionStorePath(cfg), "utf-8");
|
||||
return JSON.parse(storeRaw) as Record<string, { elevatedLevel?: string }>;
|
||||
}
|
||||
|
||||
export function makeWhatsAppElevatedCfg(
|
||||
home: string,
|
||||
opts?: { elevatedEnabled?: boolean; requireMentionInGroups?: boolean },
|
||||
@@ -196,8 +203,7 @@ export async function runDirectElevatedToggleAndLoadStore(params: {
|
||||
if (!storePath) {
|
||||
throw new Error("session.store is required in test config");
|
||||
}
|
||||
const storeRaw = await fs.readFile(storePath, "utf-8");
|
||||
const store = JSON.parse(storeRaw) as Record<string, { elevatedLevel?: string }>;
|
||||
const store = await readSessionStore(params.cfg);
|
||||
return { text, store };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user