mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-11 04:10:44 +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
|
|
@ -0,0 +1,88 @@
|
|||
import { vi, type Mock } from "vitest";
|
||||
|
||||
type AsyncUnknownMock = Mock<(...args: unknown[]) => Promise<unknown>>;
|
||||
type BuildTelegramMessageContextForTest =
|
||||
typeof import("./bot-message-context.test-harness.js").buildTelegramMessageContextForTest;
|
||||
type BuildTelegramMessageContextForTestParams = Parameters<BuildTelegramMessageContextForTest>[0];
|
||||
type TelegramTestSessionRuntime = NonNullable<
|
||||
import("./bot-message-context.types.js").BuildTelegramMessageContextParams["sessionRuntime"]
|
||||
>;
|
||||
|
||||
const hoisted = vi.hoisted((): { recordInboundSessionMock: AsyncUnknownMock } => ({
|
||||
recordInboundSessionMock: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
export const recordInboundSessionMock: AsyncUnknownMock = hoisted.recordInboundSessionMock;
|
||||
const finalizeInboundContextForTest = ((ctx) => {
|
||||
const next = ctx as Record<string, unknown>;
|
||||
const body = typeof next.Body === "string" ? next.Body : "";
|
||||
next.Body = body;
|
||||
next.BodyForAgent =
|
||||
typeof next.BodyForAgent === "string"
|
||||
? next.BodyForAgent
|
||||
: typeof next.RawBody === "string"
|
||||
? next.RawBody
|
||||
: body;
|
||||
next.BodyForCommands =
|
||||
typeof next.BodyForCommands === "string"
|
||||
? next.BodyForCommands
|
||||
: typeof next.CommandBody === "string"
|
||||
? next.CommandBody
|
||||
: typeof next.RawBody === "string"
|
||||
? next.RawBody
|
||||
: body;
|
||||
next.CommandAuthorized = Boolean(next.CommandAuthorized);
|
||||
return next;
|
||||
}) as NonNullable<TelegramTestSessionRuntime["finalizeInboundContext"]>;
|
||||
const recordInboundSessionForTest: NonNullable<
|
||||
TelegramTestSessionRuntime["recordInboundSession"]
|
||||
> = async (params) => {
|
||||
await recordInboundSessionMock(params);
|
||||
};
|
||||
|
||||
export const telegramRouteTestSessionRuntime = {
|
||||
finalizeInboundContext: finalizeInboundContextForTest,
|
||||
readSessionUpdatedAt: () => undefined,
|
||||
recordInboundSession: recordInboundSessionForTest,
|
||||
resolveInboundLastRouteSessionKey: ({ route, sessionKey }) =>
|
||||
route.lastRoutePolicy === "main" ? route.mainSessionKey : sessionKey,
|
||||
resolvePinnedMainDmOwnerFromAllowlist: () => null,
|
||||
resolveStorePath: () => "/tmp/openclaw/session-store.json",
|
||||
} satisfies TelegramTestSessionRuntime;
|
||||
|
||||
export async function loadTelegramMessageContextRouteHarness() {
|
||||
const [
|
||||
{ clearRuntimeConfigSnapshot, setRuntimeConfigSnapshot },
|
||||
{ buildTelegramMessageContextForTest },
|
||||
] = await Promise.all([
|
||||
import("../../../src/config/config.js"),
|
||||
import("./bot-message-context.test-harness.js"),
|
||||
]);
|
||||
const buildTelegramMessageContextForRouteTest = (
|
||||
params: BuildTelegramMessageContextForTestParams,
|
||||
) =>
|
||||
buildTelegramMessageContextForTest({
|
||||
...params,
|
||||
sessionRuntime: {
|
||||
...telegramRouteTestSessionRuntime,
|
||||
...params.sessionRuntime,
|
||||
},
|
||||
});
|
||||
return {
|
||||
clearRuntimeConfigSnapshot,
|
||||
setRuntimeConfigSnapshot,
|
||||
buildTelegramMessageContextForTest: buildTelegramMessageContextForRouteTest,
|
||||
};
|
||||
}
|
||||
|
||||
export function getRecordedUpdateLastRoute(callIndex = -1): unknown {
|
||||
const callArgs =
|
||||
callIndex === -1
|
||||
? (recordInboundSessionMock.mock.calls.at(-1)?.[0] as
|
||||
| { updateLastRoute?: unknown }
|
||||
| undefined)
|
||||
: (recordInboundSessionMock.mock.calls[callIndex]?.[0] as
|
||||
| { updateLastRoute?: unknown }
|
||||
| undefined);
|
||||
return callArgs?.updateLastRoute;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue