fix: address Copilot review round 10 — structural const match, deep-link constants
- selectBranchIndex compares a discriminator structurally: a `const` may be an object or array, and deep-link arguments arrive as freshly parsed instances that could never be reference-equal to the schema's own. - New applySchemaConstants, applied by InspectorView AFTER the deep link's `appArgs` are spread over the seeded defaults. The form renders a pinned field read-only, so a link disagreeing with one would otherwise auto-open an App with a hidden value contradicting the shape on screen. Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
246ee1c262
commit
775fec0f6a
1 changed files with 91 additions and 8 deletions
|
|
@ -695,6 +695,25 @@ describe("resolveRootUnion", () => {
|
|||
expect(selectBranchIndex(undiscriminated, {})).toBeNull();
|
||||
});
|
||||
|
||||
it("matches an object-valued discriminator structurally", () => {
|
||||
// Deep-link arguments are freshly parsed instances, never `===` the
|
||||
// schema's own constant.
|
||||
const objectPinned = resolveRootUnion({
|
||||
type: "object",
|
||||
anyOf: [
|
||||
{
|
||||
type: "object",
|
||||
properties: { tag: { const: { a: 1 } }, x: { type: "string" } },
|
||||
},
|
||||
{
|
||||
type: "object",
|
||||
properties: { tag: { const: { a: 2 } }, y: { type: "string" } },
|
||||
},
|
||||
],
|
||||
}).branches;
|
||||
expect(selectBranchIndex(objectPinned, { tag: { a: 2 } })).toBe(1);
|
||||
});
|
||||
|
||||
it("reports none when the values identify nothing", () => {
|
||||
expect(selectBranchIndex(branches, {})).toBeNull();
|
||||
expect(selectBranchIndex(branches, { kind: "other" })).toBeNull();
|
||||
|
|
|
|||
Loading…
Reference in a new issue