mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix: release QA hardening across processing, media, security, and CI gates (#649)
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.
This commit is contained in:
@@ -5,6 +5,9 @@ const insertedValues = vi.hoisted(() => vi.fn());
|
||||
const queueAdd = vi.hoisted(() => vi.fn());
|
||||
const getJob = vi.hoisted(() => vi.fn());
|
||||
const queueEventClose = vi.hoisted(() => vi.fn());
|
||||
const queueEventRun = vi.hoisted(() => vi.fn());
|
||||
const queueEventOn = vi.hoisted(() => vi.fn());
|
||||
const queueEventsCtor = vi.hoisted(() => vi.fn());
|
||||
const flowProducerClose = vi.hoisted(() => vi.fn());
|
||||
const assertAiJobQuotaMock = vi.hoisted(() => vi.fn());
|
||||
const isFeatureEnabledMock = vi.hoisted(() => vi.fn());
|
||||
@@ -50,8 +53,15 @@ async function loadEnqueueModule(
|
||||
updateSetMock.mockReset();
|
||||
updateMock.mockReset();
|
||||
|
||||
queueEventRun.mockReset();
|
||||
queueEventOn.mockReset();
|
||||
queueEventsCtor.mockReset();
|
||||
|
||||
queueAdd.mockResolvedValue({ id: "job-1" });
|
||||
queueEventClose.mockResolvedValue(undefined);
|
||||
// run() resolves only when the consumer is closing; a never-settling promise
|
||||
// is the honest stand-in for a loop that stays up for the process's life.
|
||||
queueEventRun.mockReturnValue(new Promise(() => {}));
|
||||
flowProducerClose.mockResolvedValue(undefined);
|
||||
assertAiJobQuotaMock.mockResolvedValue(undefined);
|
||||
isFeatureEnabledMock.mockReturnValue(options.teamRetentionEnabled ?? false);
|
||||
@@ -73,10 +83,15 @@ async function loadEnqueueModule(
|
||||
});
|
||||
|
||||
vi.doMock("bullmq", () => ({
|
||||
QueueEvents: vi.fn(() => ({
|
||||
close: queueEventClose,
|
||||
waitUntilReady: vi.fn().mockResolvedValue(undefined),
|
||||
})),
|
||||
QueueEvents: vi.fn((name: string, opts: Record<string, unknown>) => {
|
||||
queueEventsCtor(name, opts);
|
||||
return {
|
||||
close: queueEventClose,
|
||||
waitUntilReady: vi.fn().mockResolvedValue(undefined),
|
||||
run: queueEventRun,
|
||||
on: queueEventOn,
|
||||
};
|
||||
}),
|
||||
FlowProducer: vi.fn(() => ({
|
||||
close: flowProducerClose,
|
||||
})),
|
||||
@@ -285,6 +300,65 @@ describe("job enqueue helpers", () => {
|
||||
expect(flowProducerClose).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("drives the consumer loop itself rather than relying on BullMQ autorun", async () => {
|
||||
const { mod } = await loadEnqueueModule();
|
||||
|
||||
await mod.warmQueueEvents();
|
||||
|
||||
// One consumer per pool, each opted out of autorun and started here.
|
||||
expect(queueEventsCtor).toHaveBeenCalledTimes(5);
|
||||
expect(queueEventsCtor).toHaveBeenCalledWith(
|
||||
expect.stringMatching(/-image$/),
|
||||
expect.objectContaining({ autorun: false }),
|
||||
);
|
||||
expect(queueEventRun).toHaveBeenCalledTimes(5);
|
||||
expect(queueEventOn).toHaveBeenCalledWith("error", expect.any(Function));
|
||||
});
|
||||
|
||||
it("restarts a consumer loop that stops, instead of leaving the pool deaf", async () => {
|
||||
vi.useFakeTimers();
|
||||
const errors = vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
try {
|
||||
const { mod } = await loadEnqueueModule();
|
||||
// BullMQ's autorun would emit 'error' here and never run again, so every
|
||||
// later sync request on this pool would burn the whole SYNC_WAIT_MS window.
|
||||
queueEventRun
|
||||
.mockImplementationOnce(() => Promise.reject(new Error("consumer connection lost")))
|
||||
.mockReturnValue(new Promise(() => {}));
|
||||
|
||||
getJob.mockResolvedValueOnce(undefined);
|
||||
await mod.waitForJob("image", "job-1");
|
||||
await vi.advanceTimersByTimeAsync(1100);
|
||||
|
||||
expect(queueEventRun).toHaveBeenCalledTimes(2);
|
||||
expect(errors).toHaveBeenCalledWith(
|
||||
expect.stringContaining("consumer stopped; restarting"),
|
||||
expect.any(Error),
|
||||
);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("stops supervising once the consumer has been closed", async () => {
|
||||
vi.useFakeTimers();
|
||||
vi.spyOn(console, "error").mockImplementation(() => {});
|
||||
try {
|
||||
const { mod } = await loadEnqueueModule();
|
||||
queueEventRun.mockImplementation(() => Promise.reject(new Error("consumer connection lost")));
|
||||
|
||||
getJob.mockResolvedValueOnce(undefined);
|
||||
await mod.waitForJob("image", "job-1");
|
||||
await mod.closeQueueEvents();
|
||||
const runsAtClose = queueEventRun.mock.calls.length;
|
||||
await vi.advanceTimersByTimeAsync(5000);
|
||||
|
||||
expect(queueEventRun).toHaveBeenCalledTimes(runsAtClose);
|
||||
} finally {
|
||||
vi.useRealTimers();
|
||||
}
|
||||
});
|
||||
|
||||
it("getFlowProducer returns the same cached instance on repeated calls", async () => {
|
||||
const { mod } = await loadEnqueueModule();
|
||||
const a = mod.getFlowProducer();
|
||||
|
||||
Reference in New Issue
Block a user