mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 18:38:28 +00:00
test(gateway): cover mixed-id config.patch rollback
This commit is contained in:
@@ -29,6 +29,30 @@ afterAll(async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("gateway config methods", () => {
|
describe("gateway config methods", () => {
|
||||||
|
type AgentConfigEntry = {
|
||||||
|
id: string;
|
||||||
|
default?: boolean;
|
||||||
|
workspace?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
const seedAgentsConfig = async (list: AgentConfigEntry[]) => {
|
||||||
|
const setRes = await rpcReq<{ ok?: boolean }>(ws, "config.set", {
|
||||||
|
raw: JSON.stringify({
|
||||||
|
agents: {
|
||||||
|
list,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
expect(setRes.ok).toBe(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
const readConfigHash = async () => {
|
||||||
|
const snapshotRes = await rpcReq<{ hash?: string }>(ws, "config.get", {});
|
||||||
|
expect(snapshotRes.ok).toBe(true);
|
||||||
|
expect(typeof snapshotRes.payload?.hash).toBe("string");
|
||||||
|
return snapshotRes.payload?.hash ?? "";
|
||||||
|
};
|
||||||
|
|
||||||
it("returns a config snapshot", async () => {
|
it("returns a config snapshot", async () => {
|
||||||
const res = await rpcReq<{ hash?: string; raw?: string }>(ws, "config.get", {});
|
const res = await rpcReq<{ hash?: string; raw?: string }>(ws, "config.get", {});
|
||||||
expect(res.ok).toBe(true);
|
expect(res.ok).toBe(true);
|
||||||
@@ -45,20 +69,11 @@ describe("gateway config methods", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("merges agents.list entries by id instead of replacing the full array", async () => {
|
it("merges agents.list entries by id instead of replacing the full array", async () => {
|
||||||
const setRes = await rpcReq<{ ok?: boolean }>(ws, "config.set", {
|
await seedAgentsConfig([
|
||||||
raw: JSON.stringify({
|
{ id: "primary", default: true, workspace: "/tmp/primary" },
|
||||||
agents: {
|
{ id: "secondary", workspace: "/tmp/secondary" },
|
||||||
list: [
|
]);
|
||||||
{ id: "primary", default: true, workspace: "/tmp/primary" },
|
const baseHash = await readConfigHash();
|
||||||
{ id: "secondary", workspace: "/tmp/secondary" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
expect(setRes.ok).toBe(true);
|
|
||||||
const snapshotRes = await rpcReq<{ hash?: string }>(ws, "config.get", {});
|
|
||||||
expect(snapshotRes.ok).toBe(true);
|
|
||||||
expect(typeof snapshotRes.payload?.hash).toBe("string");
|
|
||||||
|
|
||||||
const patchRes = await rpcReq<{
|
const patchRes = await rpcReq<{
|
||||||
config?: {
|
config?: {
|
||||||
@@ -70,7 +85,7 @@ describe("gateway config methods", () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
}>(ws, "config.patch", {
|
}>(ws, "config.patch", {
|
||||||
baseHash: snapshotRes.payload?.hash,
|
baseHash,
|
||||||
raw: JSON.stringify({
|
raw: JSON.stringify({
|
||||||
agents: {
|
agents: {
|
||||||
list: [
|
list: [
|
||||||
@@ -93,24 +108,14 @@ describe("gateway config methods", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("rejects mixed-id agents.list patches without mutating persisted config", async () => {
|
it("rejects mixed-id agents.list patches without mutating persisted config", async () => {
|
||||||
const setRes = await rpcReq<{ ok?: boolean }>(ws, "config.set", {
|
await seedAgentsConfig([
|
||||||
raw: JSON.stringify({
|
{ id: "primary", default: true, workspace: "/tmp/primary" },
|
||||||
agents: {
|
{ id: "secondary", workspace: "/tmp/secondary" },
|
||||||
list: [
|
]);
|
||||||
{ id: "primary", default: true, workspace: "/tmp/primary" },
|
const beforeHash = await readConfigHash();
|
||||||
{ id: "secondary", workspace: "/tmp/secondary" },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
expect(setRes.ok).toBe(true);
|
|
||||||
|
|
||||||
const beforeRes = await rpcReq<{ hash?: string }>(ws, "config.get", {});
|
|
||||||
expect(beforeRes.ok).toBe(true);
|
|
||||||
expect(typeof beforeRes.payload?.hash).toBe("string");
|
|
||||||
|
|
||||||
const patchRes = await rpcReq<{ ok?: boolean }>(ws, "config.patch", {
|
const patchRes = await rpcReq<{ ok?: boolean }>(ws, "config.patch", {
|
||||||
baseHash: beforeRes.payload?.hash,
|
baseHash: beforeHash,
|
||||||
raw: JSON.stringify({
|
raw: JSON.stringify({
|
||||||
agents: {
|
agents: {
|
||||||
list: [
|
list: [
|
||||||
@@ -128,9 +133,8 @@ describe("gateway config methods", () => {
|
|||||||
expect(patchRes.ok).toBe(false);
|
expect(patchRes.ok).toBe(false);
|
||||||
expect(patchRes.error?.message ?? "").toContain("invalid config");
|
expect(patchRes.error?.message ?? "").toContain("invalid config");
|
||||||
|
|
||||||
const afterRes = await rpcReq<{ hash?: string }>(ws, "config.get", {});
|
const afterHash = await readConfigHash();
|
||||||
expect(afterRes.ok).toBe(true);
|
expect(afterHash).toBe(beforeHash);
|
||||||
expect(afterRes.payload?.hash).toBe(beforeRes.payload?.hash);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user