mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 17:18:25 +00:00
refactor: dedupe gateway session guards and agent test fixtures
This commit is contained in:
@@ -156,6 +156,15 @@ async function listAgentFileNames(agentId = "main") {
|
||||
return files.map((file) => file.name);
|
||||
}
|
||||
|
||||
function expectNotFoundResponseAndNoWrite(respond: ReturnType<typeof vi.fn>) {
|
||||
expect(respond).toHaveBeenCalledWith(
|
||||
false,
|
||||
undefined,
|
||||
expect.objectContaining({ message: expect.stringContaining("not found") }),
|
||||
);
|
||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.fsReadFile.mockImplementation(async () => {
|
||||
throw createEnoentError();
|
||||
@@ -319,12 +328,7 @@ describe("agents.update", () => {
|
||||
});
|
||||
await promise;
|
||||
|
||||
expect(respond).toHaveBeenCalledWith(
|
||||
false,
|
||||
undefined,
|
||||
expect.objectContaining({ message: expect.stringContaining("not found") }),
|
||||
);
|
||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
||||
expectNotFoundResponseAndNoWrite(respond);
|
||||
});
|
||||
|
||||
it("ensures workspace when workspace changes", async () => {
|
||||
@@ -408,12 +412,7 @@ describe("agents.delete", () => {
|
||||
});
|
||||
await promise;
|
||||
|
||||
expect(respond).toHaveBeenCalledWith(
|
||||
false,
|
||||
undefined,
|
||||
expect.objectContaining({ message: expect.stringContaining("not found") }),
|
||||
);
|
||||
expect(mocks.writeConfigFile).not.toHaveBeenCalled();
|
||||
expectNotFoundResponseAndNoWrite(respond);
|
||||
});
|
||||
|
||||
it("rejects invalid params (missing agentId)", async () => {
|
||||
|
||||
Reference in New Issue
Block a user