fix: address Copilot review round 17 — shared branch narrowing, null admissibility

- The name-based narrowing is extracted as `narrowBySuppliedNames` and used
  by the CLI coercion as well as the form: an undiscriminated union whose
  branches type a shared name differently was losing the coercion for every
  argument, including the ones that identify the branch unambiguously. The
  type-agreement fallback now also polls only the const-compatible branches.
- TUI missingRequiredFields accepts `null` only where the property admits it,
  matching the web gate: branch fields are rendered optional, so a
  `default: null` on a non-nullable required field reached the check and the
  call went out with a value the schema rejects.

Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-26 06:38:46 -04:00
commit 95030cfdb6

View file

@ -819,6 +819,24 @@ describe("schemaToForm", () => {
expect(missingRequiredFields(schema, {})).toEqual(["constructor"]);
});
it("accepts null only where the schema admits it", () => {
// Branch fields render optional, so a `default: null` on a non-nullable
// required field reaches this check — and `type: "string"` rejects it.
const strict = {
type: "object",
properties: { a: { type: "string" } },
required: ["a"],
};
expect(missingRequiredFields(strict, { a: null })).toEqual(["a"]);
const nullable = {
type: "object",
properties: { a: { type: ["string", "null"] } },
required: ["a"],
};
expect(missingRequiredFields(nullable, { a: null })).toEqual([]);
});
it("checks the root's own required fields when there is no union", () => {
const schema = {
type: "object",