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
21 changes: 20 additions & 1 deletion skills/rig/rig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ function validateSchema(value: unknown, schema: Schema, path: string, optional:
const fieldPath = `${path}.${key}`;
const isOptional = isOptionalSchema(fieldSchema);
if (fieldValue === undefined && !isOptional) {
const expectedType = "type" in fieldSchema ? (fieldSchema as { type: string }).type : "enum" in fieldSchema ? "enum value" : "value";
const expectedType = describeSchemaType(fieldSchema);
return { ok: false, error: `${fieldPath}: missing required field (expected ${expectedType})` };
}
const result = validateSchema(fieldValue, fieldSchema, fieldPath, false);
Expand Down Expand Up @@ -1789,6 +1789,25 @@ function previewWithFirstDiff(value: string | undefined, expected: string, maxPr
return `${prefixEllipsis}${preview}${suffixEllipsis}`;
}

function describeSchemaType(schema: Schema): string {
if ("nullable" in schema && schema.nullable === true) {
return `${describeSchemaType((schema as NullableSchema).inner)} | null`;
}
if ("type" in schema) {
return (schema as { type: string }).type;
}
if ("enum" in schema) {
return (schema as EnumSchema).enum.map((v: Json) => JSON.stringify(v)).join(" | ");
}
if ("items" in schema) {
return "array";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] The "object" branch in describeSchemaType (the properties / additionalProperties check) has no corresponding test. If that branch regresses, the repair prompt silently falls back to "value" — the exact issue this PR was designed to fix.

💡 Suggested test
it("reports a missing required object field with type 'object'", () => {
  const schema = s.object({ meta: s.object({ key: s.string }), name: s.string });
  const result = analyzeResponse(JSON.stringify({ name: "x" }), schema, "test", 1);
  expect(result.ok).toBe(false);
  if (!result.ok) {
    expect(result.error.message).toContain("missing required field");
    expect(result.error.message).toContain("$.meta");
    expect(result.error.message).toContain("object");
  }
});

All four describeSchemaType non-trivial branches (array, nullable, enum, object) should have coverage to match the precision the other three tests establish.

}
if ("properties" in schema || "additionalProperties" in schema) {
return "object";
}
return "value";
}

function bad(path: string, expected: string, actual: unknown): ValidationResult {
const actualType = actual === null ? "null" : Array.isArray(actual) ? "array" : typeof actual;
const actualRepr = JSON.stringify(actual);
Expand Down
33 changes: 33 additions & 0 deletions src/rig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1246,4 +1246,37 @@ describe("missing required field error message", () => {
const result = analyzeResponse(JSON.stringify({ name: "Alice" }), schema, "test", 1);
expect(result.ok).toBe(true);
});

it("reports a missing required array field with type 'array'", () => {
const schema = s.object({ items: s.array(s.string), name: s.string });
const result = analyzeResponse(JSON.stringify({ name: "x" }), schema, "test", 1);
expect(result.ok).toBe(false);
if (!result.ok) {
expect(result.error.message).toContain("missing required field");
expect(result.error.message).toContain("$.items");
expect(result.error.message).toContain("array");
}
});

it("reports a missing required nullable field with '<inner> | null'", () => {
const schema = s.object({ score: s.nullable(s.number), name: s.string });
const result = analyzeResponse(JSON.stringify({ name: "x" }), schema, "test", 1);
expect(result.ok).toBe(false);
if (!result.ok) {
expect(result.error.message).toContain("missing required field");
expect(result.error.message).toContain("$.score");
expect(result.error.message).toContain("number | null");
}
});

it("reports a missing required enum field with enum values", () => {
const schema = s.object({ status: s.enum("open", "closed"), name: s.string });
const result = analyzeResponse(JSON.stringify({ name: "x" }), schema, "test", 1);
expect(result.ok).toBe(false);
if (!result.ok) {
expect(result.error.message).toContain("missing required field");
expect(result.error.message).toContain("$.status");
expect(result.error.message).toContain('"open"');
}
});
});
Loading