From d5a7271ddde581fc49622503b250918d4e80579e Mon Sep 17 00:00:00 2001 From: paula-alves Date: Fri, 6 Nov 2026 22:29:10 +0000 Subject: [PATCH] fix(faces,autopilot): align crop-scale tests with linear semantics, fix dead vote gate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The crop-geometry refactor moved the area→linear sqrt conversion into cropBiasOf but left two learning.ts test expectations on the old area-ratio values, and a FoldedCrop.x0/.x1/.y0/.y1 access that no longer exists now that FoldedCrop is { rect, angle } (silently NaN -> null through the JSON round-trip, collapsing the learnt crop factor to null). In faces/service.ts, the conflicting-number score penalty required read.votes >= 2, but majorityNumber() already only returns a result once it has a real majority -- for a single-face group votes is always 1, so the penalty could never fire. --- apps/api/src/faces/service.ts | 2 +- apps/api/test/autopilot.test.ts | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/apps/api/src/faces/service.ts b/apps/api/src/faces/service.ts index 613dfa1..d002023 100644 --- a/apps/api/src/faces/service.ts +++ b/apps/api/src/faces/service.ts @@ -621,7 +621,7 @@ export class FaceService { const onTeam = team ? await this.playersOfTeam([first.p], team.teamId) : null; if (team && onTeam?.has(first.p.id)) suggestionScore = faceNumberKitScore(first.s, read.score, team.sure); else suggestionScore = faceAndNumberScore(first.s, read.score); - } else if (read && firstNumber && firstNumber !== read.number && read.votes >= 2) { + } else if (read && firstNumber && firstNumber !== read.number) { suggestionScore = Math.round(first.s * 0.8 * 1000) / 1000; } } else if (read && allowNumber) { diff --git a/apps/api/test/autopilot.test.ts b/apps/api/test/autopilot.test.ts index c1c0224..f0891e8 100644 --- a/apps/api/test/autopilot.test.ts +++ b/apps/api/test/autopilot.test.ts @@ -135,8 +135,9 @@ describe("learning from corrections", () => { expect(c?.deltas["light.exposure"]).toBe(0.35); expect(c?.deltas["light.shadows"]).toBe(12); expect(c?.deltas["wb.temp"]).toBe(300); - expect(c?.cropScale).toBeCloseTo(0.75, 2); - expect(c?.cropBias?.scale).toBeCloseTo(0.75, 2); + // Scale is linear (cropBias.ts): the crop only narrows in x here, so it is the geometric mean of the two axes. + expect(c?.cropScale).toBeCloseTo(0.866, 2); + expect(c?.cropBias?.scale).toBeCloseTo(0.866, 2); // A reset is "less of everything the autopilot did" for tone; white balance says nothing then. expect(correctionOf(auto, fold([set({ "light.exposure": 0.2, "wb.temp": 5200 }), { command: "develop.reset" }]))).toEqual({ deltas: { "light.exposure": -0.2 }, @@ -151,7 +152,8 @@ describe("learning from corrections", () => { const rows = [0.3, 0.25, 0.35, 0.3, -0.1].map((e, i) => ({ deltas: { "light.exposure": e, "light.contrast": i % 2 ? 8 : -8 }, cropScale: 0.7 })); const style = styleOf(rows, null); expect(style.offsets).toEqual({ "light.exposure": 0.3 }); - expect(style.cropFactor).toBeCloseTo(0.7, 2); + // 0.7 is below the 0.75 floor (never suggest tighter than that), so it saturates there. + expect(style.cropFactor).toBeCloseTo(0.75, 2); expect(styleOf(rows.slice(0, 4), null).offsets).toEqual({}); const open = [1.1, 1.12, 1.08, 1.15, 1.09].map((s) => ({ deltas: { "__crop.scale": s, "__crop.dx": 0.02, "__crop.dy": -0.03, "__crop.dAngle": 0 }, @@ -394,7 +396,7 @@ describe("autopilot", () => { // The photographer lifts the exposure (0.2 -> 0.5) and crops tighter on five of them. for (const id of photos.slice(0, 5)) { const auto = fold((await ctx.db.photoEdit.findMany({ where: { photoId: id }, orderBy: { seq: "asc" } })).map((e) => e.command as never)); - const r = auto.crop!; + const r = auto.crop!.rect; 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); @@ -412,8 +414,8 @@ describe("autopilot", () => { await autopilot.decideBursts(new Date(Date.now() + 20_000)); const edits = await ctx.db.photoEdit.findMany({ where: { photoId: next }, orderBy: { seq: "asc" } }); expect((edits[0]!.command as { params: { values: Record } }).params.values).toEqual({ "light.exposure": 0.5, "light.contrast": 10 }); - const before = fold((await ctx.db.photoEdit.findMany({ where: { photoId: photos[5]! }, orderBy: { seq: "asc" } })).map((e) => e.command as never)).crop!; - const after = fold(edits.map((e) => e.command as never)).crop!; + const before = fold((await ctx.db.photoEdit.findMany({ where: { photoId: photos[5]! }, orderBy: { seq: "asc" } })).map((e) => e.command as never)).crop!.rect; + const after = fold(edits.map((e) => e.command as never)).crop!.rect; expect(after.x1 - after.x0).toBeLessThan(before.x1 - before.x0); expect(((await ctx.db.photo.findUniqueOrThrow({ where: { id: next } })).autopilot as { style: { samples: number } }).style.samples).toBe(5);