From d2b6f4383c91096b2042bfb6542765d2c4fd673a Mon Sep 17 00:00:00 2001 From: paula-alves Date: Wed, 25 Nov 2026 01:04:05 +0000 Subject: [PATCH 1/2] Define the full-frame size the autopilot tests already record. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The suite keeps a 600 px JPEG so it does not time out, and the planner reads 6000×4000. That clears the delivery floor, so focus still ranks a burst and a learnt crop stays tighter. Those names were used before they existed. Paperclip-Issue: BIT-33293 --- apps/api/src/composition/planFrame.test.ts | 27 ++++++++++++++++++++++ apps/api/test/autopilot.test.ts | 6 ++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/apps/api/src/composition/planFrame.test.ts b/apps/api/src/composition/planFrame.test.ts index 8b1e7e3..56efc03 100644 --- a/apps/api/src/composition/planFrame.test.ts +++ b/apps/api/src/composition/planFrame.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "vitest"; import { keepPhotoAspect } from "./geometry.js"; +import { frameScore } from "./compose.js"; import { cropTooHard, levelWithoutChopping, planFrame, type PlanSettings } from "./planFrame.js"; const settings: PlanSettings = { @@ -55,6 +56,32 @@ describe("planFrame", () => { expect(crop.params.aspect).toEqual([6000, 4000]); }); + it("on a full-size file ranks the sharper frame and keeps a learnt crop tighter", () => { + const person = { x0: 0.42, y0: 0.2, x1: 0.58, y1: 0.85, score: 0.9, sharpness: 1 }; + const at = (focus: number) => ({ + detections: { width: 600, height: 400, people: [{ ...person, focus }], balls: [] as [] }, + width: 6000, + height: 4000, + reportage: false, + values: { "light.exposure": 0.2, "light.contrast": 10 }, + angle: 1.5, + settings: { ...settings, toneStrength: 0.5, framing: "full" as const, minLongEdge: 2400 }, + }); + const soft = planFrame(at(100)); + const sharp = planFrame(at(900)); + expect(soft.composition).not.toBeNull(); + expect(sharp.composition).not.toBeNull(); + expect(frameScore(at(900).detections, sharp.composition)).toBeGreaterThan(frameScore(at(100).detections, soft.composition)); + const widthOf = (planned: ReturnType) => { + const crop = planned.ops.find((op) => op.command === "crop.set"); + if (!crop || crop.command !== "crop.set") return 1; + return crop.params.rect.x1 - crop.params.rect.x0; + }; + const plain = widthOf(planFrame(at(300))); + const learnt = widthOf(planFrame({ ...at(300), cropFactor: 0.84 })); + expect(learnt).toBeLessThan(plain); + }); + it("crops one clear person in reportage and ignores a learnt sports cut", () => { const person = { x0: 0.35, y0: 0.28, x1: 0.52, y1: 0.72 }; const planned = planFrame({ diff --git a/apps/api/test/autopilot.test.ts b/apps/api/test/autopilot.test.ts index 5942fe7..7c97844 100644 --- a/apps/api/test/autopilot.test.ts +++ b/apps/api/test/autopilot.test.ts @@ -218,6 +218,10 @@ describe("learning from corrections", () => { }); }); +/** The JPEG stays 600 px so the suite does not time out. The planner reads this size, which clears the 2400 px floor. */ +const PHOTO_W = 6000; +const PHOTO_H = 4000; + describe("autopilot", () => { let ctx: TestContext; let dir: string; @@ -454,7 +458,7 @@ describe("autopilot", () => { const shrink = (a: number, b: number) => [a + (b - a) * 0.08, b - (b - a) * 0.08] as const; const [x0, x1] = shrink(r.x0, r.x1); const [y0, y1] = shrink(r.y0, r.y1); - await develop.append(id, userId, { clientId: "web-1", ops: [{ opId: `h-${id}-1`, command: { command: "develop.set", params: { values: { "light.exposure": 0.5 } } } }, { opId: `h-${id}-2`, command: { command: "crop.set", params: { rect: { x0, y0, x1, y1 }, angle: 1.5, aspect: [600, 400] } } }] }); + await develop.append(id, userId, { clientId: "web-1", ops: [{ opId: `h-${id}-1`, command: { command: "develop.set", params: { values: { "light.exposure": 0.5 } } } }, { opId: `h-${id}-2`, command: { command: "crop.set", params: { rect: { x0, y0, x1, y1 }, angle: 1.5, aspect: [PHOTO_W, PHOTO_H] } } }] }); expect(await recordCorrection(ctx.db, id)).toBe(true); } // Untouched photos and the autopilot's own edits teach nothing. -- 2.47.3 From 7372aff0ff6858768cd25ffd0936c9525186f8aa Mon Sep 17 00:00:00 2001 From: paula-alves Date: Wed, 25 Nov 2026 01:19:33 +0000 Subject: [PATCH 2/2] Apply a learnt tighter crop when the body cut would take the feet. The recorded cut is refused so the player stays whole, and the scale is what still narrows the frame. The gallery tests get a longer budget now that each frame is actually planned. Paperclip-Issue: BIT-33293 --- apps/api/src/composition/planFrame.test.ts | 7 +++++++ apps/api/src/composition/planFrame.ts | 4 +++- apps/api/test/autopilot.test.ts | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/api/src/composition/planFrame.test.ts b/apps/api/src/composition/planFrame.test.ts index 56efc03..35b88c1 100644 --- a/apps/api/src/composition/planFrame.test.ts +++ b/apps/api/src/composition/planFrame.test.ts @@ -80,6 +80,13 @@ describe("planFrame", () => { const plain = widthOf(planFrame(at(300))); const learnt = widthOf(planFrame({ ...at(300), cropFactor: 0.84 })); expect(learnt).toBeLessThan(plain); + // A uniform shrink is stored as a body cut. If that cut would take the feet, the scale still applies. + const fromCut = widthOf(planFrame({ + ...at(300), + cropFactor: 0.84, + cropBias: { dx: 0, dy: 0, scale: 0.84, dAngle: 0, cut: 0.935, head: 0.067, sides: 0 }, + })); + expect(fromCut).toBeLessThan(plain); }); it("crops one clear person in reportage and ignores a learnt sports cut", () => { diff --git a/apps/api/src/composition/planFrame.ts b/apps/api/src/composition/planFrame.ts index bab62ab..ef3f884 100644 --- a/apps/api/src/composition/planFrame.ts +++ b/apps/api/src/composition/planFrame.ts @@ -210,9 +210,11 @@ export function planFrame(input: { } if (bias && typeof bias.cut === "number") { // The photographer's cut on the body (legs, head, arms), not a uniform shrink. - // It must not chop a player this photograph had kept whole. + // It must not chop a player this photograph had kept whole. When the cut would, + // the scale still applies: a tighter frame that keeps the player inside. const placed = frameOnSubject(composition.rect, composition.subject, bias); if (!chopsKeptPlayer(composition.rect, placed, composition.subject)) rect = placed; + else if (factor && factor !== 1) rect = factor < 1 ? tighter(composition.rect, composition.subject, factor) : biasCrop(composition.rect, composition.subject, { dx: bias.dx, dy: bias.dy, scale: factor }); if (bias.dx) { const w = rect.x1 - rect.x0; const x0 = Math.min(Math.max(0, rect.x0 + bias.dx), 1 - w); diff --git a/apps/api/test/autopilot.test.ts b/apps/api/test/autopilot.test.ts index 7c97844..3bb35c7 100644 --- a/apps/api/test/autopilot.test.ts +++ b/apps/api/test/autopilot.test.ts @@ -355,7 +355,7 @@ describe("autopilot", () => { expect(await chosen()).toEqual({ [w0a]: true, [w0b]: false, [w2a]: true, [w2b]: true, [w2c]: false }); // The burst picks are still flagged for the photographer. expect((await ctx.db.photo.findUniqueOrThrow({ where: { id: w2c } })).flag).toBe("PICK"); - }); + }, 60_000); it("two clients: gallery gets the best moments; rest gets seconds and every other pick (warm-up included)", async () => { const { eventId, orgId, userId } = await setup(); @@ -397,7 +397,7 @@ describe("autopilot", () => { await service.decideBursts(new Date(start.getTime() + 8 * 60_000)); expect(to(record)).toEqual([a1]); expect(to(fap).sort()).toEqual([warm, a2, b1, b2].sort()); - }); + }, 60_000); it("never edits over a person's edit (made on the desktop app before the photo was uploaded)", async () => { const { orgId, userId, eventId } = await setup(); @@ -484,7 +484,7 @@ describe("autopilot", () => { const gone = await ctx.app.inject({ method: "DELETE", url: `/v1/orgs/${orgId}/autopilot/style`, headers: bearer(token) }); expect(gone.json()).toEqual({ forgotten: 5 }); expect(await learntStyle(ctx.db, orgId, userId)).toBeNull(); - }); + }, 60_000); it("tells the learner when a person (not the autopilot) edits", async () => { const { orgId, userId, eventId } = await setup(); -- 2.47.3