Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/utils/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,15 @@ describe("validateResult", () => {
assert.match(validateResult(result)!, /scoring/);
});

it("rejects missing scoring", () => {
it("accepts missing scoring (backward compat — defaults to weighted)", () => {
const result = makeValidResult();
delete result.scoring;
assert.equal(validateResult(result), null);
});

it("rejects invalid scoring value", () => {
const result = makeValidResult();
result.scoring = "invalid";
assert.match(validateResult(result)!, /scoring/);
});

Expand Down Expand Up @@ -126,10 +132,10 @@ describe("validateResult", () => {
assert.match(validateResult(result)!, /recommended/);
});

it("rejects missing scores", () => {
it("accepts missing scores (backward compat)", () => {
const result = makeValidResult();
delete result.scores;
assert.match(validateResult(result)!, /scores/);
assert.equal(validateResult(result), null);
});

it("rejects non-array scores", () => {
Expand Down
8 changes: 4 additions & 4 deletions src/utils/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export function validateResult(data: unknown): string | null {
if (typeof obj.timestamp !== "string") {
return "missing or invalid field: timestamp (expected string)";
}
if (obj.scoring !== "weighted" && obj.scoring !== "copeland") {
return 'missing or invalid field: scoring (expected "weighted" or "copeland")';
if (obj.scoring !== undefined && obj.scoring !== "weighted" && obj.scoring !== "copeland") {
return 'invalid field: scoring (expected "weighted", "copeland", or omitted)';
}
if (!Array.isArray(obj.agents)) {
return "missing or invalid field: agents (expected array)";
Expand All @@ -35,8 +35,8 @@ export function validateResult(data: unknown): string | null {
if (obj.recommended !== null && typeof obj.recommended !== "number") {
return "missing or invalid field: recommended (expected number or null)";
}
if (!Array.isArray(obj.scores)) {
return "missing or invalid field: scores (expected array)";
if (obj.scores !== undefined && !Array.isArray(obj.scores)) {
return "invalid field: scores (expected array or omitted)";
}

return null;
Expand Down
Loading