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

@ -4,6 +4,7 @@
import type { FormStructure, FormSection, FormField } from "ink-form";
import {
admitsNull,
isStringEnum,
normalizeNullableUnion,
} from "@inspector/core/json/nullableUnion.js";
@ -461,12 +462,25 @@ export function missingRequiredFields(
branches.length === 0
? base
: branches[selectedBranchIndex(base, branches, rawValues)]!.schema;
const properties = effective.properties ?? {};
return (effective.required ?? []).filter((name) => {
// `hasOwn` first: an argument legally named `constructor` would otherwise
// resolve to the inherited one and read as supplied, and the call would go
// out without it.
if (!Object.hasOwn(decoded, name)) return true;
const value = decoded[name];
if (value === null) {
// `null` counts as supplied only where the schema admits it — the same
// test the web gate applies. A branch field is rendered optional here, so
// a `default: null` on a non-nullable one reaches this check and would
// otherwise send a value the schema rejects.
const property = properties[name];
return (
typeof property !== "object" ||
property === null ||
!admitsNull(property)
);
}
return value === undefined || value === "";
});
}