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.
260 lines
7.9 KiB
TypeScript
260 lines
7.9 KiB
TypeScript
/**
|
|
* Integration tests for the rotate tool (/api/v1/tools/image/rotate).
|
|
*
|
|
* This is a Sharp-based tool (no AI sidecar). All processing tests should
|
|
* return 200. Output dimensions are verified by downloading the result and
|
|
* reading metadata with sharp. Rotation by 90/270 swaps width and height.
|
|
*/
|
|
|
|
import sharp from "sharp";
|
|
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.base.png200);
|
|
const JPG = readFixture(fixtures.image.base.jpg100);
|
|
const HEIC = readFixture(fixtures.image.base.heic200);
|
|
const TINY = readFixture(fixtures.image.edge.px1);
|
|
|
|
let testApp: TestApp;
|
|
let app: TestApp["app"];
|
|
let adminToken: string;
|
|
|
|
beforeAll(async () => {
|
|
testApp = await buildTestApp();
|
|
app = testApp.app;
|
|
adminToken = await loginAsAdmin(app);
|
|
}, 30_000);
|
|
|
|
afterAll(async () => {
|
|
await testApp.cleanup();
|
|
}, 10_000);
|
|
|
|
/** Helper: POST to rotate, assert 200, download result, return sharp metadata. */
|
|
async function rotateAndMeta(
|
|
settings: Record<string, unknown>,
|
|
file = PNG,
|
|
filename = "test.png",
|
|
fileCt = "image/png",
|
|
) {
|
|
const { body, contentType } = createMultipartPayload([
|
|
{ name: "file", filename, contentType: fileCt, content: file },
|
|
{ name: "settings", content: JSON.stringify(settings) },
|
|
]);
|
|
|
|
const res = await app.inject({
|
|
method: "POST",
|
|
url: "/api/v1/tools/image/rotate",
|
|
headers: {
|
|
authorization: `Bearer ${adminToken}`,
|
|
"content-type": contentType,
|
|
},
|
|
body,
|
|
});
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
const result = JSON.parse(res.body);
|
|
expect(result.downloadUrl).toBeDefined();
|
|
|
|
const dlRes = await app.inject({
|
|
method: "GET",
|
|
url: result.downloadUrl,
|
|
headers: { authorization: `Bearer ${adminToken}` },
|
|
});
|
|
expect(dlRes.statusCode).toBe(200);
|
|
|
|
return sharp(dlRes.rawPayload).metadata();
|
|
}
|
|
|
|
describe("Rotate", () => {
|
|
// ── Processing with dimension verification ───────────────────────
|
|
|
|
it("route exists and responds to POST", async () => {
|
|
const { body, contentType } = createMultipartPayload([
|
|
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
|
|
{ name: "settings", content: JSON.stringify({ angle: 90 }) },
|
|
]);
|
|
|
|
const res = await app.inject({
|
|
method: "POST",
|
|
url: "/api/v1/tools/image/rotate",
|
|
headers: {
|
|
authorization: `Bearer ${adminToken}`,
|
|
"content-type": contentType,
|
|
},
|
|
body,
|
|
});
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
});
|
|
|
|
it("rotates 90 degrees (swaps width and height)", async () => {
|
|
const meta = await rotateAndMeta({ angle: 90 });
|
|
// 200x150 rotated 90 -> 150x200
|
|
expect(meta.width).toBe(150);
|
|
expect(meta.height).toBe(200);
|
|
});
|
|
|
|
it("rotates 180 degrees (dimensions unchanged)", async () => {
|
|
const meta = await rotateAndMeta({ angle: 180 });
|
|
expect(meta.width).toBe(200);
|
|
expect(meta.height).toBe(150);
|
|
});
|
|
|
|
it("rotates 270 degrees (swaps width and height)", async () => {
|
|
const meta = await rotateAndMeta({ angle: 270 });
|
|
expect(meta.width).toBe(150);
|
|
expect(meta.height).toBe(200);
|
|
});
|
|
|
|
it("normalizes large finite angles before passing them to Sharp", async () => {
|
|
const meta = await rotateAndMeta({ angle: 10_000_000.000000002 });
|
|
expect(meta.width).toBeGreaterThan(0);
|
|
expect(meta.height).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("rotates 0 degrees (no-op)", async () => {
|
|
const meta = await rotateAndMeta({ angle: 0 });
|
|
expect(meta.width).toBe(200);
|
|
expect(meta.height).toBe(150);
|
|
});
|
|
|
|
it("uses default settings (angle: 0, no flip)", async () => {
|
|
const meta = await rotateAndMeta({});
|
|
expect(meta.width).toBe(200);
|
|
expect(meta.height).toBe(150);
|
|
});
|
|
|
|
it("flips horizontally", async () => {
|
|
const meta = await rotateAndMeta({ horizontal: true });
|
|
// Horizontal flip does not change dimensions
|
|
expect(meta.width).toBe(200);
|
|
expect(meta.height).toBe(150);
|
|
});
|
|
|
|
it("flips vertically", async () => {
|
|
const meta = await rotateAndMeta({ vertical: true });
|
|
// Vertical flip does not change dimensions
|
|
expect(meta.width).toBe(200);
|
|
expect(meta.height).toBe(150);
|
|
});
|
|
|
|
it("flips both horizontal and vertical", async () => {
|
|
const meta = await rotateAndMeta({ horizontal: true, vertical: true });
|
|
expect(meta.width).toBe(200);
|
|
expect(meta.height).toBe(150);
|
|
});
|
|
|
|
it("rotates 90 degrees and flips horizontally", async () => {
|
|
const meta = await rotateAndMeta({ angle: 90, horizontal: true });
|
|
// 90 degree rotation swaps dimensions, flip preserves them
|
|
expect(meta.width).toBe(150);
|
|
expect(meta.height).toBe(200);
|
|
});
|
|
|
|
it("rotates negative angle (-90 = 270)", async () => {
|
|
const meta = await rotateAndMeta({ angle: -90 });
|
|
// -90 degrees is equivalent to 270 degrees
|
|
expect(meta.width).toBe(150);
|
|
expect(meta.height).toBe(200);
|
|
});
|
|
|
|
it("works with JPEG input", async () => {
|
|
const meta = await rotateAndMeta({ angle: 90 }, JPG, "test.jpg", "image/jpeg");
|
|
// 100x100 square stays 100x100 after any rotation
|
|
expect(meta.width).toBe(100);
|
|
expect(meta.height).toBe(100);
|
|
});
|
|
|
|
it("handles HEIC input", { timeout: 120_000 }, async () => {
|
|
const { body, contentType } = createMultipartPayload([
|
|
{ name: "file", filename: "photo.heic", contentType: "image/heic", content: HEIC },
|
|
{ name: "settings", content: JSON.stringify({ angle: 90 }) },
|
|
]);
|
|
|
|
const res = await app.inject({
|
|
method: "POST",
|
|
url: "/api/v1/tools/image/rotate",
|
|
headers: {
|
|
authorization: `Bearer ${adminToken}`,
|
|
"content-type": contentType,
|
|
},
|
|
body,
|
|
});
|
|
|
|
expect(res.statusCode).toBe(200);
|
|
const result = JSON.parse(res.body);
|
|
expect(result.processedSize).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("handles 1x1 pixel input", async () => {
|
|
const meta = await rotateAndMeta({ angle: 90 }, TINY, "tiny.png", "image/png");
|
|
expect(meta.width).toBe(1);
|
|
expect(meta.height).toBe(1);
|
|
});
|
|
|
|
// ── Validation ───────────────────────────────────────────────────
|
|
|
|
it("rejects requests without a file", async () => {
|
|
const { body, contentType } = createMultipartPayload([
|
|
{ name: "settings", content: JSON.stringify({ angle: 90 }) },
|
|
]);
|
|
|
|
const res = await app.inject({
|
|
method: "POST",
|
|
url: "/api/v1/tools/image/rotate",
|
|
headers: {
|
|
authorization: `Bearer ${adminToken}`,
|
|
"content-type": contentType,
|
|
},
|
|
body,
|
|
});
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
const result = JSON.parse(res.body);
|
|
expect(result.error).toMatch(/no file/i);
|
|
});
|
|
|
|
it("rejects invalid settings JSON", async () => {
|
|
const { body, contentType } = createMultipartPayload([
|
|
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
|
|
{ name: "settings", content: "not json{{{" },
|
|
]);
|
|
|
|
const res = await app.inject({
|
|
method: "POST",
|
|
url: "/api/v1/tools/image/rotate",
|
|
headers: {
|
|
authorization: `Bearer ${adminToken}`,
|
|
"content-type": contentType,
|
|
},
|
|
body,
|
|
});
|
|
|
|
expect(res.statusCode).toBe(400);
|
|
const result = JSON.parse(res.body);
|
|
expect(result.error).toMatch(/json/i);
|
|
});
|
|
|
|
it("rejects unauthenticated requests", async () => {
|
|
const { body, contentType } = createMultipartPayload([
|
|
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG },
|
|
{ name: "settings", content: JSON.stringify({ angle: 90 }) },
|
|
]);
|
|
|
|
const res = await app.inject({
|
|
method: "POST",
|
|
url: "/api/v1/tools/image/rotate",
|
|
headers: { "content-type": contentType },
|
|
body,
|
|
});
|
|
|
|
expect(res.statusCode).toBe(401);
|
|
});
|
|
});
|