mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-21 14:11:26 +00:00
refactor: dedupe config and subagent tests
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { emitAgentEvent } from "../infra/agent-events.js";
|
||||
import "./test-helpers/fast-core-tools.js";
|
||||
import {
|
||||
@@ -8,7 +7,6 @@ import {
|
||||
resetSessionsSpawnAnnounceFlowOverride,
|
||||
resetSessionsSpawnConfigOverride,
|
||||
resetSessionsSpawnHookRunnerOverride,
|
||||
setSessionsSpawnAnnounceFlowOverride,
|
||||
setSessionsSpawnHookRunnerOverride,
|
||||
setupSessionsSpawnGatewayMock,
|
||||
setSessionsSpawnConfigOverride,
|
||||
@@ -17,7 +15,6 @@ import {
|
||||
getLatestSubagentRunByChildSessionKey,
|
||||
resetSubagentRegistryForTests,
|
||||
} from "./subagent-registry.js";
|
||||
import { resolveRequesterStoreKey } from "./subagent-requester-store-key.js";
|
||||
|
||||
const fastModeEnv = vi.hoisted(() => {
|
||||
const previous = process.env.OPENCLAW_TEST_FAST;
|
||||
@@ -60,46 +57,6 @@ vi.mock("./tools/agent-step.js", () => ({
|
||||
const callGatewayMock = getCallGatewayMock();
|
||||
const RUN_TIMEOUT_SECONDS = 1;
|
||||
|
||||
function installDeterministicAnnounceFlow() {
|
||||
setSessionsSpawnAnnounceFlowOverride(async (params) => {
|
||||
const statusLabel =
|
||||
params.outcome?.status === "timeout" ? "timed out" : "completed successfully";
|
||||
const requesterSessionKey = resolveRequesterStoreKey(loadConfig(), params.requesterSessionKey);
|
||||
|
||||
await callGatewayMock({
|
||||
method: "agent",
|
||||
params: {
|
||||
sessionKey: requesterSessionKey,
|
||||
message: `subagent task ${statusLabel}`,
|
||||
deliver: false,
|
||||
},
|
||||
});
|
||||
|
||||
if (params.label) {
|
||||
await callGatewayMock({
|
||||
method: "sessions.patch",
|
||||
params: {
|
||||
key: params.childSessionKey,
|
||||
label: params.label,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (params.cleanup === "delete") {
|
||||
await callGatewayMock({
|
||||
method: "sessions.delete",
|
||||
params: {
|
||||
key: params.childSessionKey,
|
||||
deleteTranscript: true,
|
||||
emitLifecycleHooks: params.spawnMode === "session",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
function buildDiscordCleanupHooks(onDelete: (key: string | undefined) => void) {
|
||||
return {
|
||||
onAgentSubagentSpawn: (params: unknown) => {
|
||||
@@ -204,7 +161,6 @@ describe("openclaw-tools: subagents (sessions_spawn lifecycle)", () => {
|
||||
runSubagentEnded: hookRunnerMocks.runSubagentEnded,
|
||||
});
|
||||
callGatewayMock.mockClear();
|
||||
installDeterministicAnnounceFlow();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { readConfigFileSnapshot, validateConfigObject } from "./config.js";
|
||||
import { withTempHome, writeOpenClawConfig } from "./test-helpers.js";
|
||||
|
||||
describe("config strict validation", () => {
|
||||
it("rejects unknown fields", async () => {
|
||||
const res = validateConfigObject({
|
||||
agents: { list: [{ id: "pi" }] },
|
||||
customUnknownField: { nested: "value" },
|
||||
});
|
||||
expect(res.ok).toBe(false);
|
||||
});
|
||||
|
||||
it("accepts documented agents.list[].params overrides", () => {
|
||||
const res = validateConfigObject({
|
||||
agents: {
|
||||
list: [
|
||||
{
|
||||
id: "main",
|
||||
model: "anthropic/claude-opus-4-6",
|
||||
params: {
|
||||
cacheRetention: "none",
|
||||
temperature: 0.4,
|
||||
maxTokens: 8192,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(res.ok).toBe(true);
|
||||
if (res.ok) {
|
||||
expect(res.config.agents?.list?.[0]?.params).toEqual({
|
||||
cacheRetention: "none",
|
||||
temperature: 0.4,
|
||||
maxTokens: 8192,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("does not treat resolved-only gateway.bind aliases as source-literal legacy or invalid", async () => {
|
||||
await withTempHome(async (home) => {
|
||||
await writeOpenClawConfig(home, {
|
||||
gateway: { bind: "${OPENCLAW_BIND}" },
|
||||
});
|
||||
|
||||
const prev = process.env.OPENCLAW_BIND;
|
||||
process.env.OPENCLAW_BIND = "0.0.0.0";
|
||||
try {
|
||||
const snap = await readConfigFileSnapshot();
|
||||
expect(snap.valid).toBe(true);
|
||||
expect(snap.legacyIssues).toHaveLength(0);
|
||||
expect(snap.issues).toHaveLength(0);
|
||||
} finally {
|
||||
if (prev === undefined) {
|
||||
delete process.env.OPENCLAW_BIND;
|
||||
} else {
|
||||
process.env.OPENCLAW_BIND = prev;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user