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.
172 lines
5.6 KiB
TypeScript
172 lines
5.6 KiB
TypeScript
import { qoiDecode, qoiEncode } from "@snapotter/image-engine";
|
|
import { describe, expect, it } from "vitest";
|
|
import { fixtures, readFixture } from "../../fixtures/index.js";
|
|
|
|
describe("QOI codec", () => {
|
|
it("round-trips RGBA pixel data", () => {
|
|
const w = 4,
|
|
h = 4;
|
|
const pixels = new Uint8Array(w * h * 4);
|
|
for (let i = 0; i < w * h; i++) {
|
|
pixels[i * 4] = (i * 17) & 0xff;
|
|
pixels[i * 4 + 1] = (i * 31) & 0xff;
|
|
pixels[i * 4 + 2] = (i * 53) & 0xff;
|
|
pixels[i * 4 + 3] = 255;
|
|
}
|
|
const encoded = qoiEncode(pixels, w, h, 4);
|
|
const { header, pixels: decoded } = qoiDecode(encoded);
|
|
expect(header.width).toBe(w);
|
|
expect(header.height).toBe(h);
|
|
for (let i = 0; i < w * h * 4; i++) expect(decoded[i]).toBe(pixels[i]);
|
|
});
|
|
|
|
it("encodes 3-channel data", () => {
|
|
const w = 3,
|
|
h = 3;
|
|
const pixels = new Uint8Array(w * h * 3);
|
|
for (let i = 0; i < pixels.length; i++) pixels[i] = (i * 41) & 0xff;
|
|
const encoded = qoiEncode(pixels, w, h, 3);
|
|
const { header, pixels: decoded } = qoiDecode(encoded);
|
|
expect(header.channels).toBe(3);
|
|
for (let i = 0; i < w * h; i++) {
|
|
expect(decoded[i * 4 + 3]).toBe(255);
|
|
}
|
|
});
|
|
|
|
it("writes correct header magic", () => {
|
|
const encoded = qoiEncode(new Uint8Array(4), 1, 1, 4);
|
|
const view = new DataView(encoded.buffer, encoded.byteOffset);
|
|
expect(view.getUint32(0)).toBe(0x716f6966);
|
|
});
|
|
|
|
it("writes correct header dimensions", () => {
|
|
const encoded = qoiEncode(new Uint8Array(20 * 15 * 4), 20, 15, 4);
|
|
const view = new DataView(encoded.buffer, encoded.byteOffset);
|
|
expect(view.getUint32(4)).toBe(20);
|
|
expect(view.getUint32(8)).toBe(15);
|
|
expect(encoded[12]).toBe(4);
|
|
});
|
|
|
|
it("round-trips 1x1 image", () => {
|
|
const pixels = new Uint8Array([42, 128, 200, 255]);
|
|
const { pixels: decoded } = qoiDecode(qoiEncode(pixels, 1, 1, 4));
|
|
expect(decoded[0]).toBe(42);
|
|
expect(decoded[3]).toBe(255);
|
|
});
|
|
|
|
it("round-trips solid color image", () => {
|
|
const w = 8,
|
|
h = 8;
|
|
const pixels = new Uint8Array(w * h * 4);
|
|
for (let i = 0; i < w * h; i++) {
|
|
pixels[i * 4] = 100;
|
|
pixels[i * 4 + 1] = 150;
|
|
pixels[i * 4 + 2] = 200;
|
|
pixels[i * 4 + 3] = 255;
|
|
}
|
|
const { pixels: decoded } = qoiDecode(qoiEncode(pixels, w, h, 4));
|
|
for (let i = 0; i < pixels.length; i++) expect(decoded[i]).toBe(pixels[i]);
|
|
});
|
|
|
|
it("compresses solid color efficiently", () => {
|
|
const w = 100,
|
|
h = 100;
|
|
const pixels = new Uint8Array(w * h * 4);
|
|
for (let i = 0; i < w * h; i++) {
|
|
pixels[i * 4] = 50;
|
|
pixels[i * 4 + 1] = 100;
|
|
pixels[i * 4 + 2] = 150;
|
|
pixels[i * 4 + 3] = 255;
|
|
}
|
|
const encoded = qoiEncode(pixels, w, h, 4);
|
|
expect(encoded.length).toBeLessThan(pixels.length / 10);
|
|
});
|
|
|
|
it("round-trips gradient", () => {
|
|
const w = 16,
|
|
h = 1;
|
|
const pixels = new Uint8Array(w * 4);
|
|
for (let i = 0; i < w; i++) {
|
|
const v = Math.round((i / (w - 1)) * 255);
|
|
pixels[i * 4] = v;
|
|
pixels[i * 4 + 1] = v;
|
|
pixels[i * 4 + 2] = v;
|
|
pixels[i * 4 + 3] = 255;
|
|
}
|
|
const { pixels: decoded } = qoiDecode(qoiEncode(pixels, w, h, 4));
|
|
for (let i = 0; i < pixels.length; i++) expect(decoded[i]).toBe(pixels[i]);
|
|
});
|
|
|
|
it("round-trips random-ish data", () => {
|
|
const w = 10,
|
|
h = 10;
|
|
const pixels = new Uint8Array(w * h * 4);
|
|
for (let i = 0; i < pixels.length; i++) pixels[i] = (i * 97 + 53) & 0xff;
|
|
const { pixels: decoded } = qoiDecode(qoiEncode(pixels, w, h, 4));
|
|
for (let i = 0; i < pixels.length; i++) expect(decoded[i]).toBe(pixels[i]);
|
|
});
|
|
|
|
it("round-trips varying alpha", () => {
|
|
const pixels = new Uint8Array([
|
|
100, 150, 200, 0, 100, 150, 200, 128, 100, 150, 200, 255, 0, 0, 0, 0,
|
|
]);
|
|
const { pixels: decoded } = qoiDecode(qoiEncode(pixels, 4, 1, 4));
|
|
for (let i = 0; i < pixels.length; i++) expect(decoded[i]).toBe(pixels[i]);
|
|
});
|
|
|
|
it("throws on invalid magic", () => {
|
|
expect(() => qoiDecode(new Uint8Array(20))).toThrow();
|
|
});
|
|
|
|
it("throws on zero width", () => {
|
|
const buf = new Uint8Array(14);
|
|
const v = new DataView(buf.buffer);
|
|
v.setUint32(0, 0x716f6966);
|
|
v.setUint32(4, 0);
|
|
v.setUint32(8, 1);
|
|
buf[12] = 4;
|
|
expect(() => qoiDecode(buf)).toThrow();
|
|
});
|
|
|
|
it("throws on zero height", () => {
|
|
const buf = new Uint8Array(14);
|
|
const v = new DataView(buf.buffer);
|
|
v.setUint32(0, 0x716f6966);
|
|
v.setUint32(4, 1);
|
|
v.setUint32(8, 0);
|
|
buf[12] = 4;
|
|
expect(() => qoiDecode(buf)).toThrow();
|
|
});
|
|
|
|
it("throws on invalid channels", () => {
|
|
const buf = new Uint8Array(14);
|
|
const v = new DataView(buf.buffer);
|
|
v.setUint32(0, 0x716f6966);
|
|
v.setUint32(4, 1);
|
|
v.setUint32(8, 1);
|
|
buf[12] = 5;
|
|
expect(() => qoiDecode(buf)).toThrow();
|
|
});
|
|
|
|
it("ends with correct end marker", () => {
|
|
const encoded = qoiEncode(new Uint8Array([1, 2, 3, 255]), 1, 1, 4);
|
|
expect(Array.from(encoded.slice(-8))).toEqual([0, 0, 0, 0, 0, 0, 0, 1]);
|
|
});
|
|
|
|
it("decodes real fixture with correct header", () => {
|
|
const data = readFixture(fixtures.image.formats("qoi"));
|
|
const { header } = qoiDecode(new Uint8Array(data));
|
|
expect(header.width).toBe(10);
|
|
expect(header.height).toBe(10);
|
|
expect(header.channels).toBe(4);
|
|
});
|
|
|
|
it("re-encodes real fixture with matching pixels", () => {
|
|
const data = readFixture(fixtures.image.formats("qoi"));
|
|
const { header, pixels } = qoiDecode(new Uint8Array(data));
|
|
const reEncoded = qoiEncode(pixels, header.width, header.height, 4);
|
|
const { pixels: reDecoded } = qoiDecode(reEncoded);
|
|
for (let i = 0; i < pixels.length; i++) expect(reDecoded[i]).toBe(pixels[i]);
|
|
});
|
|
});
|