test: cover the non-object property-declaration paths in rootUnion

The previous commit's coverage gate failed on `core/json/rootUnion.ts`
branches (89.81%). A property declared with JSON Schema's boolean form has no
keywords to merge, so the two sides agree only by being the same declaration —
now tested both ways, and the dead `baseProperty !== undefined` guard is gone
(`conflicts` is only reached for a name the base declares).

Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-26 02:09:44 -04:00
commit d8e9e502be
2 changed files with 32 additions and 3 deletions

View file

@ -202,6 +202,33 @@ describe("resolveRootUnion", () => {
});
});
it("carries an identical non-object declaration across", () => {
// JSON Schema's boolean form is legal as a property schema. There are no
// keywords to merge, so the two agree only by being the same declaration.
const { branches } = resolveRootUnion({
type: "object",
properties: { x: true as unknown },
anyOf: [
{ type: "object", properties: { x: true as unknown } },
{ type: "object", properties: { other: { type: "string" } } },
],
});
expect(branches).toHaveLength(2);
expect(branches[0].schema.properties?.x).toBe(true);
});
it("declines a union whose branch redeclares a non-object property differently", () => {
const { branches } = resolveRootUnion({
type: "object",
properties: { x: true as unknown },
anyOf: [
{ type: "object", properties: { x: false as unknown } },
{ type: "object", properties: { other: { type: "string" } } },
],
});
expect(branches).toEqual([]);
});
it("declines a union whose branch contradicts the root's type for a field", () => {
// `string` under a base `number` describes a value that cannot exist, so
// flattening it would render one type and accept what the schema rejects.

View file

@ -183,9 +183,11 @@ function conflicts(baseProperty: unknown, branchProperty: unknown): boolean {
const a = toBranch(baseProperty);
const b = toBranch(branchProperty);
if (a === null || b === null) {
return (
baseProperty !== undefined && !sameValue(baseProperty, branchProperty)
);
// At least one side is not a readable schema object — JSON Schema's boolean
// form, or something malformed. Nothing can be merged keyword-wise, so the
// two agree only if they are the same declaration. (Only reached for a name
// the base declares, so `baseProperty` is never simply absent here.)
return !sameValue(baseProperty, branchProperty);
}
const left = a as Record<string, unknown>;
const right = b as Record<string, unknown>;