Skip to content

Commit 8cf85e3

Browse files
authored
fix: restore release-validation fixture coverage (#124401)
* test(release): refresh validation fixtures * test(release): satisfy fixture lint gates * test(release): preserve fixture owner contracts
1 parent 6335e35 commit 8cf85e3

11 files changed

Lines changed: 106 additions & 85 deletions

‎extensions/telegram/src/bot.media.e2e.test-harness.ts‎

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import { mkdtempSync, rmSync } from "node:fs";
33
import os from "node:os";
44
import path from "node:path";
55
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
6-
import { resetPluginStateStoreForTests } from "openclaw/plugin-sdk/plugin-state-test-runtime";
6+
import {
7+
createPluginStateKeyedStoreForTests,
8+
resetPluginStateStoreForTests,
9+
} from "openclaw/plugin-sdk/plugin-state-test-runtime";
710
import { finalizeInboundContext, resetInboundDedupe } from "openclaw/plugin-sdk/reply-runtime";
811
import type { GetReplyOptions, MsgContext } from "openclaw/plugin-sdk/reply-runtime";
912
import { afterEach, beforeEach, vi, type Mock } from "vitest";
@@ -135,36 +138,14 @@ const defaultRuntimeConfig = (() =>
135138
channels: { telegram: { dmPolicy: "open", allowFrom: ["*"] } },
136139
}) as OpenClawConfig) as TelegramBotDeps["getRuntimeConfig"];
137140

138-
type TopicNameEntry = {
139-
name: string;
140-
iconColor?: number;
141-
iconCustomEmojiId?: string;
142-
closed?: boolean;
143-
updatedAt: number;
144-
};
145-
146-
const topicNameStoresForTest = new Map<string, Map<string, TopicNameEntry>>();
147-
148141
function installTopicNameRuntimeForTest(): void {
149142
setTelegramRuntime({
150143
state: {
151-
openKeyedStore: (({ namespace }: { namespace: string }) => {
152-
let store = topicNameStoresForTest.get(namespace);
153-
if (!store) {
154-
store = new Map();
155-
topicNameStoresForTest.set(namespace, store);
156-
}
157-
return {
158-
register: async (key: string, value: TopicNameEntry) => {
159-
store.set(key, value);
160-
},
161-
entries: async () => [...store.entries()].map(([key, value]) => ({ key, value })),
162-
delete: async (key: string) => store.delete(key),
163-
clear: async () => {
164-
store.clear();
165-
},
166-
};
167-
}) as unknown as TelegramRuntime["state"]["openKeyedStore"],
144+
openKeyedStore: ((options) =>
145+
createPluginStateKeyedStoreForTests(
146+
"telegram",
147+
options,
148+
)) as TelegramRuntime["state"]["openKeyedStore"],
168149
},
169150
channel: {},
170151
} as TelegramRuntime);
@@ -285,7 +266,6 @@ beforeEach(() => {
285266
process.env.OPENCLAW_STATE_DIR = ensureMediaHarnessStoreRoot();
286267
telegramBotDepsForTest.getRuntimeConfig = defaultRuntimeConfig;
287268
resetInboundDedupe();
288-
topicNameStoresForTest.clear();
289269
resetTelegramTopicNameCacheForTest();
290270
installTopicNameRuntimeForTest();
291271
resetSaveMediaBufferMock();

‎src/agents/embedded-agent-runner.e2e.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import path from "node:path";
33
import "./test-helpers/fast-coding-tools.js";
44
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
55
import { wrapRunWithTestPreparedAdmission } from "./admitted-run-context.test-support.js";
6+
import { resolveEmbeddedAuthCooldownProbePolicy as resolveEmbeddedAuthCooldownProbePolicyActual } from "./embedded-agent-runner/run/auth-controller.js";
67
import {
78
buildEmbeddedRunnerAssistant,
89
cleanupEmbeddedAgentRunnerTestWorkspace,
@@ -158,6 +159,7 @@ const installRunEmbeddedMocks = () => {
158159
}),
159160
stopRuntimeAuthRefreshTimer: vi.fn(),
160161
}),
162+
resolveEmbeddedAuthCooldownProbePolicy: resolveEmbeddedAuthCooldownProbePolicyActual,
161163
}));
162164
vi.doMock("./models-config.js", async () => {
163165
const mod = await vi.importActual<typeof import("./models-config.js")>("./models-config.js");
@@ -185,10 +187,14 @@ let sessionStorePath: string;
185187
let sessionCounter = 0;
186188
let runCounter = 0;
187189

188-
const createEmbeddedAgentRunnerOpenAiConfig = (modelIds: string[]) => ({
189-
...createBaseEmbeddedAgentRunnerOpenAiConfig(modelIds),
190-
session: { store: sessionStorePath },
191-
});
190+
const createEmbeddedAgentRunnerOpenAiConfig = (modelIds: string[]) => {
191+
const config = createBaseEmbeddedAgentRunnerOpenAiConfig(modelIds);
192+
const mainAgent = config.agents?.list?.find((entry) => entry.id === "main");
193+
if (mainAgent) {
194+
mainAgent.default = true;
195+
}
196+
return { ...config, session: { store: sessionStorePath } };
197+
};
192198

193199
beforeAll(async () => {
194200
vi.useRealTimers();

‎src/agents/embedded-agent-runner.run-embedded-agent.fault-sequences.e2e.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import os from "node:os";
44
import path from "node:path";
55
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
66
import type { OpenClawConfig } from "../config/config.js";
7+
import { wrapRunWithTestAdmission } from "./admitted-run-context.test-support.js";
78
import { ensureAuthProfileStore, saveAuthProfileStore } from "./auth-profiles/store.js";
89
import {
910
classifyEmbeddedAgentRunResultForModelFallback,
@@ -64,7 +65,11 @@ vi.mock("./models-config.js", async () => {
6465
return { ...actual, ensureOpenClawModelsJson: vi.fn(async () => ({ wrote: false })) };
6566
});
6667

67-
let runEmbeddedAgent: typeof import("./embedded-agent-runner/run.js").runEmbeddedAgent;
68+
type ProductionRunEmbeddedAgent = typeof import("./embedded-agent-runner/run.js").runEmbeddedAgent;
69+
type TestRunEmbeddedAgent = (
70+
params: Omit<Parameters<ProductionRunEmbeddedAgent>[0], "admittedRunContext">,
71+
) => ReturnType<ProductionRunEmbeddedAgent>;
72+
let runEmbeddedAgent: TestRunEmbeddedAgent;
6873
let runWithModelFallback: typeof import("./model-fallback-runner.js").runWithModelFallback;
6974

7075
beforeAll(async () => {
@@ -82,7 +87,9 @@ beforeAll(async () => {
8287
createResolvedEmbeddedRunnerModel(provider, modelId),
8388
}));
8489

85-
({ runEmbeddedAgent } = await import("./embedded-agent-runner/run.js"));
90+
runEmbeddedAgent = wrapRunWithTestAdmission(
91+
(await import("./embedded-agent-runner/run.js")).runEmbeddedAgent,
92+
);
8693
({ runWithModelFallback } = await import("./model-fallback-runner.js"));
8794
});
8895

‎src/agents/model-fallback.run-embedded.e2e.test.ts‎

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -208,16 +208,6 @@ async function readUsageStats(agentDir: string) {
208208
return ensureAuthProfileStore(agentDir, { syncExternalCli: false }).usageStats ?? {};
209209
}
210210

211-
function expectFailureCount(
212-
usageStats: Record<string, Record<string, unknown> | undefined>,
213-
profileId: string,
214-
reason: AuthProfileFailureReason,
215-
expected: number,
216-
) {
217-
const failureCounts = usageStats[profileId]?.failureCounts as Record<string, unknown> | undefined;
218-
expect(failureCounts?.[reason]).toBe(expected);
219-
}
220-
221211
async function writeMultiProfileAuthStore(
222212
agentDir: string,
223213
options?: { openAiProfileCount?: 2 | 3 },
@@ -550,7 +540,7 @@ describe("runWithModelFallback + runEmbeddedAgent failover behavior", () => {
550540
});
551541
});
552542

553-
it("falls back across providers after overloaded primary failure and persists transient cooldown", async () => {
543+
it("falls back after overloaded primary failure without poisoning profile health", async () => {
554544
await withAgentWorkspace(async ({ agentDir, workspaceDir }) => {
555545
await writeAuthStore(agentDir);
556546
mockPrimaryOverloadedThenFallbackSuccess();
@@ -568,8 +558,8 @@ describe("runWithModelFallback + runEmbeddedAgent failover behavior", () => {
568558
expect(result.result.payloads?.[0]?.text ?? "").toContain("fallback ok");
569559

570560
const usageStats = await readUsageStats(agentDir);
571-
expect(typeof usageStats["openai:p1"]?.cooldownUntil).toBe("number");
572-
expectFailureCount(usageStats, "openai:p1", "overloaded", 1);
561+
expect(usageStats["openai:p1"]?.cooldownUntil).toBeUndefined();
562+
expect(usageStats["openai:p1"]?.failureCounts?.overloaded).toBeUndefined();
573563
expect(typeof usageStats["groq:p1"]?.lastUsed).toBe("number");
574564

575565
expectOpenAiThenGroqAttemptOrder();
@@ -756,7 +746,7 @@ describe("runWithModelFallback + runEmbeddedAgent failover behavior", () => {
756746
});
757747
});
758748

759-
it("persists overloaded cooldown across turns while still allowing one probe and fallback", async () => {
749+
it("keeps overloaded failures provider-scoped across turns while continuing fallback", async () => {
760750
await withAgentWorkspace(async ({ agentDir, workspaceDir }) => {
761751
await writeAuthStore(agentDir);
762752
mockPrimaryOverloadedThenFallbackSuccess();
@@ -787,14 +777,14 @@ describe("runWithModelFallback + runEmbeddedAgent failover behavior", () => {
787777
expectOpenAiThenGroqAttemptOrder({ expectOpenAiAuthProfileId: "openai:p1" });
788778

789779
const usageStats = await readUsageStats(agentDir);
790-
expect(typeof usageStats["openai:p1"]?.cooldownUntil).toBe("number");
791-
expectFailureCount(usageStats, "openai:p1", "overloaded", 2);
780+
expect(usageStats["openai:p1"]?.cooldownUntil).toBeUndefined();
781+
expect(usageStats["openai:p1"]?.failureCounts?.overloaded).toBeUndefined();
792782
expect(computeBackoffMock).not.toHaveBeenCalled();
793783
expect(sleepWithAbortMock).not.toHaveBeenCalled();
794784
});
795785
});
796786

797-
it("keeps bare service-unavailable failures in the timeout lane without persisting cooldown", async () => {
787+
it("classifies bare service-unavailable failures as overloaded without cooling the profile", async () => {
798788
await withAgentWorkspace(async ({ agentDir, workspaceDir }) => {
799789
await writeAuthStore(agentDir);
800790
mockPrimaryErrorThenFallbackSuccess("LLM error: service unavailable");
@@ -807,7 +797,7 @@ describe("runWithModelFallback + runEmbeddedAgent failover behavior", () => {
807797
});
808798

809799
expect(result.provider).toBe("groq");
810-
expect(result.attempts[0]?.reason).toBe("timeout");
800+
expect(result.attempts[0]?.reason).toBe("overloaded");
811801

812802
const usageStats = await readUsageStats(agentDir);
813803
expect(usageStats["openai:p1"]?.cooldownUntil).toBeUndefined();

‎src/auto-reply/reply.triggers.trigger-handling.e2e.test.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,17 @@ describe("trigger handling", () => {
545545
const storePath = join(home, "compact-main.sessions.json");
546546
const cfg = makeCfg(home);
547547
cfg.session = { ...cfg.session, store: storePath };
548-
mockSuccessfulCompaction();
549-
550548
const request = {
551549
Body: "/compact focus on decisions",
552550
From: "+1003",
553551
To: "+2000",
554552
};
553+
const sessionKey = resolveSessionKey("per-sender", request, undefined, "main");
554+
await replaceSessionEntry(
555+
{ storePath, sessionKey },
556+
{ sessionId: "compact-main-session", updatedAt: Date.now() },
557+
);
558+
mockSuccessfulCompaction();
555559

556560
const res = await getReplyFromConfig(
557561
{
@@ -564,7 +568,6 @@ describe("trigger handling", () => {
564568
const text = maybeReplyText(res);
565569
expect(text).toMatch(/^⚙️ Compacted/u);
566570
expect(getCompactEmbeddedAgentSessionMock()).toHaveBeenCalledOnce();
567-
const sessionKey = resolveSessionKey("per-sender", request, undefined, "main");
568571
expect(loadSessionEntry({ storePath, sessionKey })?.compactionCount).toBe(1);
569572
});
570573
});
@@ -574,13 +577,19 @@ describe("trigger handling", () => {
574577
getCompactEmbeddedAgentSessionMock().mockReset();
575578
mockSuccessfulCompaction();
576579
const cfg = makeCfg(home);
577-
cfg.session = { ...cfg.session, store: join(home, "compact-worker.sessions.json") };
580+
const storePath = join(home, "compact-worker.sessions.json");
581+
const sessionKey = "agent:worker1:telegram:12345";
582+
cfg.session = { ...cfg.session, store: storePath };
583+
await replaceSessionEntry(
584+
{ storePath, sessionKey },
585+
{ sessionId: "compact-worker-session", updatedAt: Date.now() },
586+
);
578587
const res = await getReplyFromConfig(
579588
{
580589
Body: "/compact",
581590
From: "+1004",
582591
To: "+2000",
583-
SessionKey: "agent:worker1:telegram:12345",
592+
SessionKey: sessionKey,
584593
CommandAuthorized: true,
585594
},
586595
{},

‎src/claws/lifecycle.e2e.test.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe("claws lifecycle cli e2e", () => {
154154
const config = JSON.parse(await readFile(join(result.stateDir, "openclaw.json"), "utf8"));
155155
const canonicalStateDir = await realpath(result.stateDir);
156156
expect(config.agents.entries).toEqual({
157-
main: { default: true },
157+
main: { workspace: join(canonicalStateDir, "workspace") },
158158
"internal-triage": expect.objectContaining({
159159
name: "Internal Triage",
160160
tools: { deny: ["exec", "browser"] },
@@ -275,7 +275,14 @@ describe("claws lifecycle cli e2e", () => {
275275
agentRemoved: true,
276276
});
277277
const config = JSON.parse(await readFile(join(added.stateDir, "openclaw.json"), "utf8"));
278-
expect(config.agents).toEqual({ entries: { main: { default: true } } });
278+
const canonicalStateDir = await realpath(added.stateDir);
279+
expect(config.agents).toEqual({
280+
defaults: {
281+
heartbeat: { agentId: "main" },
282+
systemAgent: { agentId: "main" },
283+
},
284+
entries: { main: { workspace: join(canonicalStateDir, "workspace") } },
285+
});
279286
});
280287

281288
it("exports an installed agent as a self-contained grouped package", async () => {

‎src/commands/doctor.e2e-harness.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ vi.mock("./doctor-state-migrations.js", () => ({
615615
autoMigrateLegacyStateDir,
616616
autoMigrateLegacyTaskStateSidecars,
617617
detectLegacyStateMigrations,
618+
migrateLegacyConfigMachineState: vi.fn(() => ({ changes: [], warnings: [] })),
618619
runLegacyStateMigrations,
619620
}));
620621

‎src/plugins/install.npm-spec.e2e.test.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,8 @@ describe("installPluginFromNpmSpec e2e", () => {
750750
expect(result.ok).toBe(false);
751751
if (!result.ok) {
752752
expect(result.code).toBe(PLUGIN_INSTALL_ERROR_CODE.SECURITY_SCAN_BLOCKED);
753-
expect(result.error).toContain("blocked by install policy: blocked installed package tree");
753+
expect(result.error).toContain("Install blocked by policy");
754+
expect(result.error).toContain("Reason: blocked installed package tree");
754755
}
755756
const projectRoot = pluginNpmProjectRoot(npmRoot, blockedPlugin);
756757
try {
@@ -839,7 +840,8 @@ describe("installPluginFromNpmSpec e2e", () => {
839840
expect(result.ok).toBe(false);
840841
if (!result.ok) {
841842
expect(result.code).toBe(PLUGIN_INSTALL_ERROR_CODE.SECURITY_SCAN_BLOCKED);
842-
expect(result.error).toContain("blocked by install policy: blocked installed package tree");
843+
expect(result.error).toContain("Install blocked by policy");
844+
expect(result.error).toContain("Reason: blocked installed package tree");
843845
}
844846
const rootManifest = await readJson<{
845847
dependencies?: Record<string, string>;

‎test/e2e/qa-lab/runtime/gateway-rpc-automation.e2e.test.ts‎

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -398,28 +398,41 @@ describe("Gateway task and automation RPCs", () => {
398398
await expect
399399
.poll(() => providerRequests.length, { timeout: 15_000, interval: 50 })
400400
.toBeGreaterThan(requestsBeforeWake);
401-
await expect
402-
.poll(
403-
async () => {
404-
const lastHeartbeat = await client.request<{
405-
ts: number;
406-
status: string;
407-
reason?: string;
408-
message?: string;
409-
preview?: string;
410-
}>("last-heartbeat", {});
411-
return (
412-
lastHeartbeat.ts >= wakeRequestedAt &&
413-
lastHeartbeat.status === "skipped" &&
414-
lastHeartbeat.reason === "target-none" &&
415-
lastHeartbeat.message ===
416-
"Heartbeat delivery is disabled by configuration (target: none)." &&
417-
lastHeartbeat.preview === `Heartbeat handled: ${wakeText}`
418-
);
419-
},
420-
{ timeout: 15_000, interval: 50 },
421-
)
422-
.toBe(true);
401+
let observedHeartbeat: {
402+
ts: number;
403+
status: string;
404+
reason?: string;
405+
message?: string;
406+
preview?: string;
407+
} | null = null;
408+
try {
409+
await expect
410+
.poll(
411+
async () => {
412+
observedHeartbeat = await client.request<{
413+
ts: number;
414+
status: string;
415+
reason?: string;
416+
message?: string;
417+
preview?: string;
418+
}>("last-heartbeat", {});
419+
return (
420+
observedHeartbeat.ts >= wakeRequestedAt &&
421+
observedHeartbeat.status === "skipped" &&
422+
observedHeartbeat.reason === "target-none" &&
423+
observedHeartbeat.message ===
424+
"Heartbeat delivery is disabled by configuration (target: none)." &&
425+
observedHeartbeat.preview === `Heartbeat handled: ${wakeText}`
426+
);
427+
},
428+
{ timeout: 15_000, interval: 50 },
429+
)
430+
.toBe(true);
431+
} catch (error) {
432+
throw new Error(`Unexpected last-heartbeat state: ${JSON.stringify(observedHeartbeat)}`, {
433+
cause: error,
434+
});
435+
}
423436
} finally {
424437
if (gateway) {
425438
await disconnectGatewayClient(gateway.client);

‎test/gateway-steer-fifo.e2e.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,12 @@ async function connectDiagnosticsClient(instance: OpenClawTestInstance): Promise
486486
mode: GATEWAY_CLIENT_MODES.UI,
487487
role: "operator",
488488
scopes: ["operator.admin", "operator.read", "operator.write"],
489-
caps: [GATEWAY_CLIENT_CAPS.TASK_SUGGESTIONS],
489+
caps: [
490+
GATEWAY_CLIENT_CAPS.AGENT_KIND,
491+
GATEWAY_CLIENT_CAPS.PLUGIN_APPROVALS,
492+
GATEWAY_CLIENT_CAPS.TASK_SUGGESTIONS,
493+
GATEWAY_CLIENT_CAPS.TOOL_EVENTS,
494+
],
490495
platform: process.platform,
491496
requestTimeoutMs: 30_000,
492497
onHelloOk: resolveHello,

0 commit comments

Comments
 (0)