mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
A release-readiness QA pass over the whole product. The commits split into defects a user would hit and gates that were reporting green while measuring nothing. ## Fixes that change behaviour Rate limiting was bypassable on every install: TRUST_PROXY defaulted to true, so request.ip came from a client-set header and a forged X-Forwarded-For got past the login limiter. The default is now a private-network trust list. A transient Postgres outage stranded in-flight jobs, leaving finished output on disk with no row pointing at it. A reconciler now resolves those rows and adopts the bytes rather than dropping the work. A Redis connection that moved to a new address wedged every read-blocked consumer, so completions stopped signalling while health still answered 200. Socket timeouts plus subscriber pings recover it. Installing more than one AI bundle left the shared venv multi-versioned and silently broke three tools. The installer now reconciles distributions to one version each. Converting an image to JXL at quality 1 through 4 returned a 500, because libjxl 0.7 rejects the distance those values compute. The quality is floored at what the encoder honours. A missing ffmpeg was also reported to the user as a corrupt upload; it now says the engine is unavailable. RAW uploads reached an unpatched LibRaw on arm64, so it is built from source at 0.22.2, and the release scan was split so it can fail on an unfixed critical instead of hiding it behind ignore-unfixed. ## Gates that could not fail Two mutation lanes ran zero mutants because Stryker crawled the gitignored docs build; coverage discarded its whole report on any failing test; the lint gate skipped root tests, scripts, and two workspaces; and several generated matrices counted a host missing ffmpeg as a passing tool. Each now measures what it claims. Full evidence and the outstanding release items are tracked locally and are not part of this branch.
113 lines
3.6 KiB
TypeScript
113 lines
3.6 KiB
TypeScript
/**
|
|
* Integration tests for TOOL_EXECUTED audit logging.
|
|
*
|
|
* Verifies that the createToolRoute factory emits audit entries when the
|
|
* `auditToolOperations` admin setting is enabled and stays silent when it
|
|
* is disabled (the default).
|
|
*/
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
import { fixtures, readFixture } from "../../fixtures/index.js";
|
|
import {
|
|
buildTestApp,
|
|
createMultipartPayload,
|
|
loginAsAdmin,
|
|
type TestApp,
|
|
} from "../test-server.js";
|
|
|
|
const PNG = readFixture(fixtures.image.edge.px1);
|
|
|
|
let testApp: TestApp;
|
|
let adminToken: string;
|
|
|
|
beforeAll(async () => {
|
|
testApp = await buildTestApp();
|
|
adminToken = await loginAsAdmin(testApp.app);
|
|
}, 30_000);
|
|
|
|
afterAll(async () => {
|
|
await testApp.cleanup();
|
|
}, 10_000);
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Helpers */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
async function setSetting(key: string, value: string): Promise<void> {
|
|
const res = await testApp.app.inject({
|
|
method: "PUT",
|
|
url: "/api/v1/settings",
|
|
headers: { authorization: `Bearer ${adminToken}` },
|
|
payload: { [key]: value },
|
|
});
|
|
expect(res.statusCode).toBe(200);
|
|
}
|
|
|
|
async function fetchAuditLog(action: string): Promise<{ entries: any[]; total: number }> {
|
|
const res = await testApp.app.inject({
|
|
method: "GET",
|
|
url: `/api/v1/audit-log?action=${action}`,
|
|
headers: { authorization: `Bearer ${adminToken}` },
|
|
});
|
|
expect(res.statusCode).toBe(200);
|
|
return JSON.parse(res.body);
|
|
}
|
|
|
|
async function processResize(): Promise<number> {
|
|
const { body, contentType } = createMultipartPayload([
|
|
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
|
|
{ name: "settings", content: JSON.stringify({ width: 1 }) },
|
|
]);
|
|
|
|
const res = await testApp.app.inject({
|
|
method: "POST",
|
|
url: "/api/v1/tools/image/resize",
|
|
headers: {
|
|
authorization: `Bearer ${adminToken}`,
|
|
"content-type": contentType,
|
|
},
|
|
body,
|
|
});
|
|
|
|
return res.statusCode;
|
|
}
|
|
|
|
/* ------------------------------------------------------------------ */
|
|
/* Tests */
|
|
/* ------------------------------------------------------------------ */
|
|
|
|
describe("tool operation audit logging", () => {
|
|
it("does not log TOOL_EXECUTED when auditToolOperations is disabled", async () => {
|
|
await setSetting("auditToolOperations", "false");
|
|
|
|
await processResize();
|
|
|
|
// Small delay to ensure fire-and-forget audit would have landed
|
|
await new Promise((r) => setTimeout(r, 200));
|
|
|
|
const body = await fetchAuditLog("TOOL_EXECUTED");
|
|
expect(body.total).toBe(0);
|
|
});
|
|
|
|
it("logs TOOL_EXECUTED when auditToolOperations is enabled", async () => {
|
|
await setSetting("auditToolOperations", "true");
|
|
|
|
const statusCode = await processResize();
|
|
expect(statusCode).toBe(200);
|
|
|
|
// Small delay for the fire-and-forget audit write to complete
|
|
await new Promise((r) => setTimeout(r, 500));
|
|
|
|
const body = await fetchAuditLog("TOOL_EXECUTED");
|
|
expect(body.total).toBeGreaterThanOrEqual(1);
|
|
|
|
const entry = body.entries[0];
|
|
expect(entry.action).toBe("TOOL_EXECUTED");
|
|
expect(entry.details.toolId).toBe("resize");
|
|
expect(entry.details.status).toBe("success");
|
|
expect(typeof entry.details.durationMs).toBe("number");
|
|
expect(entry.details.inputFileCount).toBe(1);
|
|
expect(typeof entry.details.totalInputSize).toBe("number");
|
|
expect(entry.details.totalInputSize).toBeGreaterThan(0);
|
|
});
|
|
});
|