mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-11 10:33:18 +08:00
重构主控编排与运行时预热链路,统一工作区提示词/专家调度协议并补齐 wiki 记忆注入与写回闭环。
同时收敛启动与运维脚本默认行为(含 wiki worker)、更新 Admin 可观测性与相关测试,降低首轮时延并提高运行稳定性。 Made-with: Cursor
This commit is contained in:
parent
4a23b715a2
commit
dbbe3add6a
14438 changed files with 2693620 additions and 2546 deletions
154
openclaw/extensions/device-pair/notify.test.ts
Normal file
154
openclaw/extensions/device-pair/notify.test.ts
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { createTestPluginApi } from "../../test/helpers/plugins/plugin-api.js";
|
||||
|
||||
const listDevicePairingMock = vi.hoisted(() => vi.fn(async () => ({ pending: [] })));
|
||||
|
||||
vi.mock("./api.js", () => ({
|
||||
listDevicePairing: listDevicePairingMock,
|
||||
}));
|
||||
|
||||
import { handleNotifyCommand } from "./notify.js";
|
||||
|
||||
describe("device-pair notify persistence", () => {
|
||||
let stateDir: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
vi.clearAllMocks();
|
||||
listDevicePairingMock.mockResolvedValue({ pending: [] });
|
||||
stateDir = await fs.mkdtemp(path.join(os.tmpdir(), "device-pair-notify-"));
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await fs.rm(stateDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("matches persisted telegram thread ids across number and string roundtrips", async () => {
|
||||
await fs.writeFile(
|
||||
path.join(stateDir, "device-pair-notify.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
subscribers: [
|
||||
{
|
||||
to: "chat-123",
|
||||
accountId: "telegram-default",
|
||||
messageThreadId: 271,
|
||||
mode: "persistent",
|
||||
addedAtMs: 1,
|
||||
},
|
||||
],
|
||||
notifiedRequestIds: {},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
const api = createTestPluginApi({
|
||||
runtime: {
|
||||
state: {
|
||||
resolveStateDir: () => stateDir,
|
||||
},
|
||||
} as never,
|
||||
});
|
||||
|
||||
const status = await handleNotifyCommand({
|
||||
api,
|
||||
ctx: {
|
||||
channel: "telegram",
|
||||
senderId: "chat-123",
|
||||
accountId: "telegram-default",
|
||||
messageThreadId: "271",
|
||||
},
|
||||
action: "status",
|
||||
});
|
||||
|
||||
expect(status.text).toContain("Pair request notifications: enabled for this chat.");
|
||||
expect(status.text).toContain("Mode: persistent");
|
||||
|
||||
await handleNotifyCommand({
|
||||
api,
|
||||
ctx: {
|
||||
channel: "telegram",
|
||||
senderId: "chat-123",
|
||||
accountId: "telegram-default",
|
||||
messageThreadId: "271",
|
||||
},
|
||||
action: "off",
|
||||
});
|
||||
|
||||
const persisted = JSON.parse(
|
||||
await fs.readFile(path.join(stateDir, "device-pair-notify.json"), "utf8"),
|
||||
) as { subscribers: unknown[] };
|
||||
expect(persisted.subscribers).toEqual([]);
|
||||
});
|
||||
|
||||
it("does not remove a different persisted subscriber when notify fields contain pipes", async () => {
|
||||
await fs.writeFile(
|
||||
path.join(stateDir, "device-pair-notify.json"),
|
||||
JSON.stringify(
|
||||
{
|
||||
subscribers: [
|
||||
{
|
||||
to: "chat|123",
|
||||
accountId: "acct",
|
||||
mode: "persistent",
|
||||
addedAtMs: 1,
|
||||
},
|
||||
{
|
||||
to: "chat",
|
||||
accountId: "123|acct",
|
||||
mode: "persistent",
|
||||
addedAtMs: 2,
|
||||
},
|
||||
],
|
||||
notifiedRequestIds: {},
|
||||
},
|
||||
null,
|
||||
2,
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
const api = createTestPluginApi({
|
||||
runtime: {
|
||||
state: {
|
||||
resolveStateDir: () => stateDir,
|
||||
},
|
||||
} as never,
|
||||
});
|
||||
|
||||
await handleNotifyCommand({
|
||||
api,
|
||||
ctx: {
|
||||
channel: "telegram",
|
||||
senderId: "chat",
|
||||
accountId: "123|acct",
|
||||
},
|
||||
action: "off",
|
||||
});
|
||||
|
||||
const status = await handleNotifyCommand({
|
||||
api,
|
||||
ctx: {
|
||||
channel: "telegram",
|
||||
senderId: "chat",
|
||||
accountId: "123|acct",
|
||||
},
|
||||
action: "status",
|
||||
});
|
||||
expect(status.text).toContain("Pair request notifications: disabled for this chat.");
|
||||
|
||||
const persisted = JSON.parse(
|
||||
await fs.readFile(path.join(stateDir, "device-pair-notify.json"), "utf8"),
|
||||
) as { subscribers: Array<{ to: string; accountId?: string }> };
|
||||
expect(persisted.subscribers).toHaveLength(1);
|
||||
expect(persisted.subscribers[0]).toMatchObject({
|
||||
to: "chat|123",
|
||||
accountId: "acct",
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue