test: verify gateway HTTP arguments

This commit is contained in:
Shakker
2026-05-11 17:57:47 +01:00
parent 013ef92034
commit e5d8a938a1
3 changed files with 9 additions and 10 deletions

View File

@@ -318,7 +318,8 @@ describe("fuzz: readJsonBodyOrError", () => {
}
const maxBytes = randInt(rng, 1, 1 << 20);
const result = await readJsonBodyOrError(makeRequest(), res, maxBytes);
const req = makeRequest();
const result = await readJsonBodyOrError(req, res, maxBytes);
if (pick === 0) {
expect(result).toEqual(expectedValue);
} else {
@@ -326,7 +327,7 @@ describe("fuzz: readJsonBodyOrError", () => {
expect(res.statusCode).toBe(expectedStatus);
expect(end).toHaveBeenCalledWith(expectedBody);
}
expect(readJsonBodyMock).toHaveBeenLastCalledWith(expect.anything(), maxBytes);
expect(readJsonBodyMock).toHaveBeenLastCalledWith(req, maxBytes);
}
});
});

View File

@@ -107,6 +107,7 @@ describe("handleGatewayPostJsonEndpoint", () => {
const mockedSendMissingScopeForbidden = vi.mocked(sendMissingScopeForbidden);
mockedSendMissingScopeForbidden.mockClear();
vi.mocked(readJsonBodyOrError).mockClear();
const res = {} as unknown as ServerResponse;
const result = await handleGatewayPostJsonEndpoint(
{
@@ -114,7 +115,7 @@ describe("handleGatewayPostJsonEndpoint", () => {
method: "POST",
headers: { host: "localhost" },
} as unknown as IncomingMessage,
{} as unknown as ServerResponse,
res,
{
pathname: "/v1/ok",
auth: {} as unknown as ResolvedGatewayAuth,
@@ -127,10 +128,7 @@ describe("handleGatewayPostJsonEndpoint", () => {
expect(vi.mocked(authorizeOperatorScopesForMethod)).toHaveBeenCalledWith("chat.send", [
"operator.approvals",
]);
expect(mockedSendMissingScopeForbidden).toHaveBeenCalledWith(
expect.anything(),
"operator.write",
);
expect(mockedSendMissingScopeForbidden).toHaveBeenCalledWith(res, "operator.write");
expect(vi.mocked(readJsonBodyOrError)).not.toHaveBeenCalled();
});

View File

@@ -368,9 +368,9 @@ test("sessions.delete returns unavailable when active run does not stop", async
>;
expect(store["agent:main:discord:group:dev"]?.sessionId).toBe("sess-active");
const filesAfterDeleteAttempt = await fs.readdir(dir);
expect(filesAfterDeleteAttempt).not.toContainEqual(
expect.stringMatching(/^sess-active\.jsonl\.deleted\./),
);
expect(
filesAfterDeleteAttempt.filter((fileName) => fileName.startsWith("sess-active.jsonl.deleted.")),
).toEqual([]);
ws.close();
});