feat(canvas): implement local node size pinning and reconciliation logic

- Added functions to handle local node size pins, ensuring that node sizes are preserved during reconciliation.
- Updated `reconcileCanvasFlowNodes` to incorporate size pinning logic.
- Enhanced tests to verify the correct behavior of size pinning in various scenarios.
- Updated related components to support new size pinning functionality.
This commit is contained in:
2026-04-10 08:48:34 +02:00
parent 26d008705f
commit 463830f178
12 changed files with 711 additions and 10 deletions

View File

@@ -1,4 +1,5 @@
import { describe, expect, it } from "vitest";
import { ConvexError } from "convex/values";
import { FreepikApiError } from "@/convex/freepik";
import {
categorizeError,
@@ -31,6 +32,42 @@ describe("ai error helpers", () => {
);
});
it("formats structured-output invalid json with human-readable provider message", () => {
expect(
formatTerminalStatusMessage(
new ConvexError({ code: "OPENROUTER_STRUCTURED_OUTPUT_INVALID_JSON" }),
),
).toBe("Provider: Strukturierte Antwort konnte nicht gelesen werden");
});
it("formats structured-output missing content with human-readable provider message", () => {
expect(
formatTerminalStatusMessage(
new ConvexError({ code: "OPENROUTER_STRUCTURED_OUTPUT_MISSING_CONTENT" }),
),
).toBe("Provider: Strukturierte Antwort fehlt");
});
it("formats structured-output http error with provider prefix and server message", () => {
expect(
formatTerminalStatusMessage(
new ConvexError({
code: "OPENROUTER_STRUCTURED_OUTPUT_HTTP_ERROR",
status: 503,
message: "OpenRouter API error 503: Upstream timeout",
}),
),
).toBe("Provider: OpenRouter API error 503: Upstream timeout");
});
it("formats structured-output http error without falling back to raw code", () => {
expect(
formatTerminalStatusMessage(
new ConvexError({ code: "OPENROUTER_STRUCTURED_OUTPUT_HTTP_ERROR" }),
),
).toBe("Provider: Anfrage fehlgeschlagen");
});
it("uses staged poll delays", () => {
expect(getVideoPollDelayMs(1)).toBe(5000);
expect(getVideoPollDelayMs(9)).toBe(10000);

View File

@@ -104,9 +104,108 @@ describe("generateStructuredObjectViaOpenRouter", () => {
schema,
},
},
plugins: [{ id: "response-healing" }],
});
});
it("parses content when provider returns array text parts", async () => {
fetchMock.mockResolvedValueOnce(
createMockResponse({
ok: true,
status: 200,
json: {
choices: [
{
message: {
content: [
{ type: "text", text: '{"title": "Lemon"' },
{ type: "text", text: ', "confidence": 0.75}' },
],
},
},
],
},
}),
);
const result = await generateStructuredObjectViaOpenRouter<{
title: string;
confidence: number;
}>("test-api-key", {
model: "openai/gpt-5-mini",
messages: [{ role: "user", content: "hello" }],
schemaName: "test_schema",
schema: { type: "object" },
});
expect(result).toEqual({ title: "Lemon", confidence: 0.75 });
});
it("parses fenced json content", async () => {
fetchMock.mockResolvedValueOnce(
createMockResponse({
ok: true,
status: 200,
json: {
choices: [
{
message: {
content:
"Here is the result:\n```json\n{\n \"title\": \"LemonSpace\",\n \"confidence\": 0.88\n}\n```\nThanks.",
},
},
],
},
}),
);
const result = await generateStructuredObjectViaOpenRouter<{
title: string;
confidence: number;
}>("test-api-key", {
model: "openai/gpt-5-mini",
messages: [{ role: "user", content: "hello" }],
schemaName: "test_schema",
schema: { type: "object" },
});
expect(result).toEqual({ title: "LemonSpace", confidence: 0.88 });
});
it("returns message.parsed directly when provided", async () => {
fetchMock.mockResolvedValueOnce(
createMockResponse({
ok: true,
status: 200,
json: {
choices: [
{
message: {
parsed: {
title: "Parsed Result",
confidence: 0.99,
},
content: "not valid json",
},
},
],
},
}),
);
const result = await generateStructuredObjectViaOpenRouter<{
title: string;
confidence: number;
}>("test-api-key", {
model: "openai/gpt-5-mini",
messages: [{ role: "user", content: "hello" }],
schemaName: "test_schema",
schema: { type: "object" },
});
expect(result).toEqual({ title: "Parsed Result", confidence: 0.99 });
});
it("throws ConvexError code when response content is missing", async () => {
fetchMock.mockResolvedValueOnce(
createMockResponse({