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.
109 lines
3.7 KiB
TypeScript
109 lines
3.7 KiB
TypeScript
/**
|
|
* A terminal job row must survive a late progress frame.
|
|
*
|
|
* Tool progress is published fire and forget (`void updateSingleFileProgress`
|
|
* in the worker), so a nonterminal frame can still be in flight when the job
|
|
* reaches a terminal state. persistSingleFileProgress wrote
|
|
* `status: "processing", completedAt: null, error: null` unconditionally, so a
|
|
* frame that landed late resurrected a finished row.
|
|
*
|
|
* Observed on the release container: cancelling a stabilize-video job just
|
|
* after submit left the row permanently `status = processing`,
|
|
* `completed_at = null`, `error = null`, `duration_ms = 59`, with
|
|
* `progress = {"stage":"Analyzing","percent":5}` -- the tool's first frame,
|
|
* written after the worker's cancel row. One in three attempts reproduced it,
|
|
* and the row never recovered because nothing else revisits it.
|
|
*
|
|
* The completion path is already safe: it goes through
|
|
* updateSingleFileProgressAtomically, whose per-job queue drains earlier
|
|
* nonterminal writes first. The cancel and failure paths in the worker use a
|
|
* plain db.update outside that queue, so the guard has to live in the write
|
|
* itself.
|
|
*/
|
|
|
|
import { randomUUID } from "node:crypto";
|
|
import { eq } from "drizzle-orm";
|
|
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
import { db, schema } from "../../../apps/api/src/db/index.js";
|
|
import { updateSingleFileProgress } from "../../../apps/api/src/routes/progress.js";
|
|
import { buildTestApp, type TestApp } from "../test-server.js";
|
|
|
|
let testApp: TestApp;
|
|
|
|
beforeAll(async () => {
|
|
testApp = await buildTestApp();
|
|
}, 30_000);
|
|
|
|
afterAll(async () => {
|
|
await testApp.cleanup();
|
|
}, 10_000);
|
|
|
|
async function seedJob(
|
|
status: "canceled" | "failed" | "completed" | "processing",
|
|
): Promise<string> {
|
|
const id = randomUUID();
|
|
await db.insert(schema.jobs).values({
|
|
id,
|
|
type: "single",
|
|
status,
|
|
inputRefs: [],
|
|
completedAt: status === "processing" ? null : new Date(),
|
|
durationMs: 59,
|
|
error: status === "failed" ? { message: "boom" } : null,
|
|
});
|
|
return id;
|
|
}
|
|
|
|
async function readJob(id: string) {
|
|
const [row] = await db.select().from(schema.jobs).where(eq(schema.jobs.id, id));
|
|
return row;
|
|
}
|
|
|
|
describe("late progress frames against a terminal job row", () => {
|
|
for (const terminal of ["canceled", "failed", "completed"] as const) {
|
|
it(`leaves a ${terminal} row terminal`, async () => {
|
|
const id = await seedJob(terminal);
|
|
|
|
// The frame the worker had already queued before the job ended.
|
|
await updateSingleFileProgress({
|
|
jobId: id,
|
|
phase: "processing",
|
|
percent: 5,
|
|
stage: "Analyzing",
|
|
});
|
|
|
|
const row = await readJob(id);
|
|
expect(row.status, `${terminal} row was rewritten to ${row.status}`).toBe(terminal);
|
|
expect(row.completedAt, "completedAt was cleared by a late progress frame").not.toBeNull();
|
|
if (terminal === "failed") {
|
|
expect(row.error, "the failure reason was cleared by a late progress frame").not.toBeNull();
|
|
}
|
|
});
|
|
}
|
|
|
|
it("still advances a job that is genuinely still running", async () => {
|
|
const id = await seedJob("processing");
|
|
|
|
await updateSingleFileProgress({
|
|
jobId: id,
|
|
phase: "processing",
|
|
percent: 42,
|
|
stage: "Working",
|
|
});
|
|
|
|
const row = await readJob(id);
|
|
expect(row.status).toBe("processing");
|
|
expect((row.progress as { percent?: number } | null)?.percent).toBe(42);
|
|
});
|
|
|
|
it("still records a terminal frame on a running job", async () => {
|
|
const id = await seedJob("processing");
|
|
|
|
await updateSingleFileProgress({ jobId: id, phase: "complete", percent: 100 });
|
|
|
|
const row = await readJob(id);
|
|
expect(row.status).toBe("completed");
|
|
expect(row.completedAt).not.toBeNull();
|
|
});
|
|
});
|