refactor: dedupe gateway session guards and agent test fixtures

This commit is contained in:
Peter Steinberger
2026-02-19 14:08:50 +00:00
parent a99fd8f2dd
commit 397f243ded
3 changed files with 100 additions and 59 deletions

View File

@@ -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 () => {