mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 02:01:25 +00:00
fix: stabilize model catalog and pi discovery auth storage compatibility
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { ChannelId } from "../channels/plugins/types.js";
|
||||
import type { ChannelAccountSnapshot } from "../channels/plugins/types.js";
|
||||
import type { ChannelManager, ChannelRuntimeSnapshot } from "./server-channels.js";
|
||||
import { startChannelHealthMonitor } from "./channel-health-monitor.js";
|
||||
import type { ChannelManager, ChannelRuntimeSnapshot } from "./server-channels.js";
|
||||
|
||||
function createMockChannelManager(overrides?: Partial<ChannelManager>): ChannelManager {
|
||||
return {
|
||||
@@ -322,9 +322,9 @@ describe("channel-health-monitor", () => {
|
||||
});
|
||||
|
||||
it("runs checks single-flight when restart work is still in progress", async () => {
|
||||
let releaseStart: (() => void) | null = null;
|
||||
let releaseStart: (() => void) | undefined;
|
||||
const startGate = new Promise<void>((resolve) => {
|
||||
releaseStart = resolve;
|
||||
releaseStart = () => resolve();
|
||||
});
|
||||
const manager = createMockChannelManager({
|
||||
getRuntimeSnapshot: vi.fn(() =>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ChannelId } from "../channels/plugins/types.js";
|
||||
import type { ChannelManager } from "./server-channels.js";
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import type { ChannelManager } from "./server-channels.js";
|
||||
|
||||
const log = createSubsystemLogger("gateway/health-monitor");
|
||||
|
||||
|
||||
@@ -1,4 +1,28 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { loadSessionEntry as loadSessionEntryType } from "./session-utils.js";
|
||||
|
||||
const buildSessionLookup = (
|
||||
sessionKey: string,
|
||||
entry: {
|
||||
sessionId?: string;
|
||||
lastChannel?: string;
|
||||
lastTo?: string;
|
||||
updatedAt?: number;
|
||||
} = {},
|
||||
): ReturnType<typeof loadSessionEntryType> => ({
|
||||
cfg: { session: { mainKey: "agent:main:main" } } as OpenClawConfig,
|
||||
storePath: "/tmp/sessions.json",
|
||||
store: {} as ReturnType<typeof loadSessionEntryType>["store"],
|
||||
entry: {
|
||||
sessionId: entry.sessionId ?? `sid-${sessionKey}`,
|
||||
updatedAt: entry.updatedAt ?? Date.now(),
|
||||
lastChannel: entry.lastChannel,
|
||||
lastTo: entry.lastTo,
|
||||
},
|
||||
canonicalKey: sessionKey,
|
||||
legacyKey: undefined,
|
||||
});
|
||||
|
||||
vi.mock("../infra/system-events.js", () => ({
|
||||
enqueueSystemEvent: vi.fn(),
|
||||
@@ -17,11 +41,7 @@ vi.mock("../config/sessions.js", () => ({
|
||||
updateSessionStore: vi.fn(),
|
||||
}));
|
||||
vi.mock("./session-utils.js", () => ({
|
||||
loadSessionEntry: vi.fn((sessionKey: string) => ({
|
||||
storePath: "/tmp/sessions.json",
|
||||
entry: { sessionId: `sid-${sessionKey}` },
|
||||
canonicalKey: sessionKey,
|
||||
})),
|
||||
loadSessionEntry: vi.fn((sessionKey: string) => buildSessionLookup(sessionKey)),
|
||||
pruneLegacyStoreKeys: vi.fn(),
|
||||
resolveGatewaySessionStoreTarget: vi.fn(({ key }: { key: string }) => ({
|
||||
canonicalKey: key,
|
||||
@@ -30,12 +50,12 @@ vi.mock("./session-utils.js", () => ({
|
||||
}));
|
||||
|
||||
import type { CliDeps } from "../cli/deps.js";
|
||||
import type { HealthSummary } from "../commands/health.js";
|
||||
import type { NodeEventContext } from "./server-node-events-types.js";
|
||||
import { agentCommand } from "../commands/agent.js";
|
||||
import type { HealthSummary } from "../commands/health.js";
|
||||
import { updateSessionStore } from "../config/sessions.js";
|
||||
import { requestHeartbeatNow } from "../infra/heartbeat-wake.js";
|
||||
import { enqueueSystemEvent } from "../infra/system-events.js";
|
||||
import type { NodeEventContext } from "./server-node-events-types.js";
|
||||
import { handleNodeEvent } from "./server-node-events.js";
|
||||
import { loadSessionEntry } from "./session-utils.js";
|
||||
|
||||
@@ -279,11 +299,7 @@ describe("agent request events", () => {
|
||||
updateSessionStoreMock.mockImplementation(async (_storePath, update) => {
|
||||
update({});
|
||||
});
|
||||
loadSessionEntryMock.mockImplementation((sessionKey: string) => ({
|
||||
storePath: "/tmp/sessions.json",
|
||||
entry: { sessionId: `sid-${sessionKey}` },
|
||||
canonicalKey: sessionKey,
|
||||
}));
|
||||
loadSessionEntryMock.mockImplementation((sessionKey: string) => buildSessionLookup(sessionKey));
|
||||
});
|
||||
|
||||
it("disables delivery when route is unresolved instead of falling back globally", async () => {
|
||||
@@ -317,12 +333,11 @@ describe("agent request events", () => {
|
||||
it("reuses the current session route when delivery target is omitted", async () => {
|
||||
const ctx = buildCtx();
|
||||
loadSessionEntryMock.mockReturnValueOnce({
|
||||
storePath: "/tmp/sessions.json",
|
||||
entry: {
|
||||
...buildSessionLookup("agent:main:main", {
|
||||
sessionId: "sid-current",
|
||||
lastChannel: "telegram",
|
||||
lastTo: "123",
|
||||
},
|
||||
}),
|
||||
canonicalKey: "agent:main:main",
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import type { NodeEvent, NodeEventContext } from "./server-node-events-types.js";
|
||||
import { resolveSessionAgentId } from "../agents/agent-scope.js";
|
||||
import { normalizeChannelId } from "../channels/plugins/index.js";
|
||||
import { createOutboundSendDeps } from "../cli/outbound-send-deps.js";
|
||||
@@ -14,6 +13,7 @@ import { normalizeMainKey } from "../routing/session-key.js";
|
||||
import { defaultRuntime } from "../runtime.js";
|
||||
import { parseMessageWithAttachments } from "./chat-attachments.js";
|
||||
import { normalizeRpcAttachmentsToChatAttachments } from "./server-methods/attachment-normalize.js";
|
||||
import type { NodeEvent, NodeEventContext } from "./server-node-events-types.js";
|
||||
import {
|
||||
loadSessionEntry,
|
||||
pruneLegacyStoreKeys,
|
||||
|
||||
Reference in New Issue
Block a user