solver-api: standardize error contracts and harden parsing paths

Add structured 4xx responses and defensive parser/process behavior so clients receive consistent failures and malformed inputs are rejected deterministically.

Made-with: Cursor
This commit is contained in:
2026-04-17 08:23:25 -06:00
parent bf5e15b909
commit 01710af161
4 changed files with 90 additions and 25 deletions

View File

@@ -78,6 +78,23 @@ describe("solver-api", () => {
expect(Array.isArray(response.body.parsed.unsupportedFields)).toBe(true);
});
it("rejects /solve without xml and returns schema metadata", async () => {
const app = buildApp();
const response = await request(app).post("/solve").send({});
expect(response.status).toBe(400);
expect(response.body.schemaVersion).toBe(2);
expect(response.body.code).toBe("missing_xml");
});
it("rejects diagnostic workflow without surface card", async () => {
const app = buildApp();
const response = await request(app)
.post("/solve")
.send({ xml, solverModel: "fdm", workflow: "diagnostic" });
expect(response.status).toBe(400);
expect(response.body.code).toBe("missing_surface_card");
});
it("is deterministic for the same input", async () => {
const app = buildApp();
const a = await request(app).post("/solve").send({ xml });