mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
feat: replace Python seam carving with caire Go binary
Replace the Python seam-carving library with caire (esimov/caire v1.5.0), a Go-based content-aware resize engine that is faster and supports both shrinking and enlarging via seam insertion. - Add Go builder stage in Dockerfile to compile caire from source - Rewrite seam-carving.ts to call caire via execFile (no Python sidecar) - Remove content-aware-resize from PYTHON_SIDECAR_TOOLS (60s timeout) - Add new options: blur radius, edge sensitivity, square mode, face detection - Move content-aware toggle below standard resize in UI (subtler placement) - Rename "Don't enlarge" to "Limit to original size" with hover tooltip - Add smooth progress bar for medium-duration tools - Delete seam_carve.py and remove seam-carving pip dependency - Update integration tests and visual regression screenshots
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
/**
|
||||
* Integration tests for the content-aware resize (seam carving) API endpoint.
|
||||
* Integration tests for the content-aware resize (seam carving via caire) API endpoint.
|
||||
*
|
||||
* This tool uses the Python sidecar, so in CI/test environments where Python
|
||||
* is not available the route will return 422 (Python error).
|
||||
* Tests gracefully handle both scenarios while still verifying route existence
|
||||
* and input validation.
|
||||
* This tool uses the caire Go binary. In environments where caire is not
|
||||
* installed the route will return 422. Tests gracefully handle both scenarios
|
||||
* while still verifying route existence and input validation.
|
||||
*/
|
||||
|
||||
import { readFileSync } from "node:fs";
|
||||
@@ -49,8 +48,7 @@ describe("Content-Aware Resize", () => {
|
||||
body,
|
||||
});
|
||||
|
||||
// 200 = Python available, 422 = Python error
|
||||
// Any of these proves the route is registered and reachable
|
||||
// 200 = caire available, 422 = caire not found
|
||||
expect([200, 422]).toContain(res.statusCode);
|
||||
}, 60_000);
|
||||
|
||||
@@ -72,6 +70,27 @@ describe("Content-Aware Resize", () => {
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it("rejects requests without width, height, or square", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG_200x150 },
|
||||
{ name: "settings", content: JSON.stringify({ protectFaces: false }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/content-aware-resize",
|
||||
headers: {
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
"content-type": contentType,
|
||||
},
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
const resBody = JSON.parse(res.body);
|
||||
expect(resBody.error).toContain("width, height, or square");
|
||||
});
|
||||
|
||||
it("processes with only width specified", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG_200x150 },
|
||||
@@ -88,7 +107,7 @@ describe("Content-Aware Resize", () => {
|
||||
body,
|
||||
});
|
||||
|
||||
// Accept 200 (Python available) or 422 (Python not available)
|
||||
// Accept 200 (caire available) or 422 (caire not available)
|
||||
expect([200, 422]).toContain(res.statusCode);
|
||||
|
||||
if (res.statusCode === 200) {
|
||||
@@ -123,10 +142,10 @@ describe("Content-Aware Resize", () => {
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
it("rejects enlargement beyond source dimensions", async () => {
|
||||
it("supports enlargement via seam insertion", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG_200x150 },
|
||||
{ name: "settings", content: JSON.stringify({ width: 400, protectFaces: false }) },
|
||||
{ name: "settings", content: JSON.stringify({ width: 300, protectFaces: false }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
@@ -139,14 +158,116 @@ describe("Content-Aware Resize", () => {
|
||||
body,
|
||||
});
|
||||
|
||||
// 422 = Python caught the enlargement error
|
||||
// Should never be 200 since 400 > 200px source width
|
||||
expect(res.statusCode).not.toBe(200);
|
||||
expect(res.statusCode).toBe(422);
|
||||
// 200 = caire enlarged successfully, 422 = caire not available
|
||||
expect([200, 422]).toContain(res.statusCode);
|
||||
|
||||
if (res.statusCode === 422) {
|
||||
if (res.statusCode === 200) {
|
||||
const resBody = JSON.parse(res.body);
|
||||
expect(resBody.error || resBody.details).toBeDefined();
|
||||
expect(resBody.downloadUrl).toBeDefined();
|
||||
expect(resBody.width).toBe(300);
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
it("accepts blurRadius and sobelThreshold options", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG_200x150 },
|
||||
{
|
||||
name: "settings",
|
||||
content: JSON.stringify({
|
||||
width: 150,
|
||||
protectFaces: false,
|
||||
blurRadius: 6,
|
||||
sobelThreshold: 4,
|
||||
}),
|
||||
},
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/content-aware-resize",
|
||||
headers: {
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
"content-type": contentType,
|
||||
},
|
||||
body,
|
||||
});
|
||||
|
||||
expect([200, 422]).toContain(res.statusCode);
|
||||
|
||||
if (res.statusCode === 200) {
|
||||
const resBody = JSON.parse(res.body);
|
||||
expect(resBody.downloadUrl).toBeDefined();
|
||||
expect(resBody.width).toBe(150);
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
it("supports square mode", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG_200x150 },
|
||||
{ name: "settings", content: JSON.stringify({ square: true, protectFaces: false }) },
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/content-aware-resize",
|
||||
headers: {
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
"content-type": contentType,
|
||||
},
|
||||
body,
|
||||
});
|
||||
|
||||
expect([200, 422]).toContain(res.statusCode);
|
||||
|
||||
if (res.statusCode === 200) {
|
||||
const resBody = JSON.parse(res.body);
|
||||
expect(resBody.downloadUrl).toBeDefined();
|
||||
// Square mode produces equal width and height
|
||||
expect(resBody.width).toBe(resBody.height);
|
||||
}
|
||||
}, 60_000);
|
||||
|
||||
it("rejects invalid blurRadius", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG_200x150 },
|
||||
{
|
||||
name: "settings",
|
||||
content: JSON.stringify({ width: 150, blurRadius: 50 }),
|
||||
},
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/content-aware-resize",
|
||||
headers: {
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
"content-type": contentType,
|
||||
},
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
|
||||
it("rejects invalid sobelThreshold", async () => {
|
||||
const { body, contentType } = createMultipartPayload([
|
||||
{ name: "file", filename: "test.png", contentType: "image/png", content: PNG_200x150 },
|
||||
{
|
||||
name: "settings",
|
||||
content: JSON.stringify({ width: 150, sobelThreshold: 0 }),
|
||||
},
|
||||
]);
|
||||
|
||||
const res = await app.inject({
|
||||
method: "POST",
|
||||
url: "/api/v1/tools/content-aware-resize",
|
||||
headers: {
|
||||
authorization: `Bearer ${adminToken}`,
|
||||
"content-type": contentType,
|
||||
},
|
||||
body,
|
||||
});
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user