Implement independent presentation readiness boundaries
This commit is contained in:
@@ -124,19 +124,20 @@ async function fixture(replacement = "First", change?: (artifact: ReactPreparati
|
||||
test("workspace expands distinct providers' private inputs without parent field declarations", async () => {
|
||||
const { pkg } = await fixture();
|
||||
const parent = pkg.checkedQueries!.find((query) => query.declaration.id === "react:input:library-card:data")!;
|
||||
assert.match(parent.document, /title/);
|
||||
assert.match(parent.document, /detail/);
|
||||
const acquisition = pkg.checkedQueries!.find(
|
||||
(query) =>
|
||||
query.declaration.id ===
|
||||
(parent.declaration.placement?.kind === "local" ? parent.declaration.placement.sourceQueryId : ""),
|
||||
)!;
|
||||
assert.match(acquisition.document, /title/);
|
||||
assert.match(acquisition.document, /detail/);
|
||||
const plan = pkg.queryCompositions!.find((composition) => composition.id === "react:inputs:library-card")!;
|
||||
assert.equal(plan.steps[0]!.query, parent.declaration.id);
|
||||
assert.equal(Object.keys(parent.fragmentContracts ?? {}).length, 2);
|
||||
const discovery = pkg.queryCompositions!.find(
|
||||
(composition) => composition.id === "react:inputs:library-card:discovery",
|
||||
)!;
|
||||
assert.equal(
|
||||
discovery.steps[0]!.query,
|
||||
"LibraryData",
|
||||
"Cold child data cannot block discovering its selected reference",
|
||||
);
|
||||
assert(!pkg.queryCompositions!.some((composition) => composition.id.endsWith(":discovery")));
|
||||
const original = pkg.checkedQueries!.find((query) => query.declaration.id === "LibraryData")!;
|
||||
assert.deepEqual(parent.output, original.output, "Acquisition-only child fields are not parent requirements");
|
||||
assert(Object.values(parent.fragmentContracts!).every((entry) => entry.mode === "reference"));
|
||||
});
|
||||
|
||||
test("eager cycles and wrongly typed child bindings fail before runtime", async () => {
|
||||
@@ -167,7 +168,16 @@ test("eager cycles and wrongly typed child bindings fail before runtime", async
|
||||
test("workspace replacement changes acquisition requirements without changing the parent", async () => {
|
||||
const { pkg } = await fixture("Second");
|
||||
const parent = pkg.checkedQueries!.find((query) => query.declaration.id === "react:input:library-card:data")!;
|
||||
assert.doesNotMatch(parent.document, /\btitle\b/);
|
||||
assert.match(parent.document, /detail/);
|
||||
const acquisition = pkg.checkedQueries!.find(
|
||||
(query) =>
|
||||
query.declaration.id ===
|
||||
(parent.declaration.placement?.kind === "local" ? parent.declaration.placement.sourceQueryId : ""),
|
||||
)!;
|
||||
assert.doesNotMatch(acquisition.document, /\btitle\b/);
|
||||
assert.match(acquisition.document, /detail/);
|
||||
assert.equal(Object.keys(parent.fragmentContracts ?? {}).length, 1);
|
||||
const previous = (await fixture()).pkg.checkedQueries!.find(
|
||||
(query) => query.declaration.id === parent.declaration.id,
|
||||
)!;
|
||||
assert.deepEqual(parent.output, previous.output);
|
||||
});
|
||||
|
||||
@@ -62,6 +62,21 @@ test("imported fragments retain checked occurrences and require exact roots", as
|
||||
assert.equal(result.selection[0]!.selection[0]!.fragmentSpread?.digest, checked.definitionDigest);
|
||||
assert.equal(result.selection[0]!.selection[0]!.fragmentSpread?.root, item.revisionId);
|
||||
assert.ok(result.effects.some((e) => e.memberId === "title"));
|
||||
const bound = await compileQuery(
|
||||
{
|
||||
...consumer.queries![0]!,
|
||||
importedFragments: consumer.queries![0]!.importedFragments!.map((entry) => ({ ...entry, mode: "reference" })),
|
||||
},
|
||||
[item],
|
||||
async () => "query Screen {root {...Row}}",
|
||||
async () => checked,
|
||||
);
|
||||
assert.equal(bound.selection[0]!.selection.find((entry) => entry.fragmentSpread)?.fragmentSpread?.mode, "reference");
|
||||
assert(
|
||||
!bound.selection[0]!.selection.some((entry) => entry.memberId === "title"),
|
||||
"A fragment binding does not evaluate its fields in the parent",
|
||||
);
|
||||
assert(!JSON.stringify(bound.output).includes('"title"'), "Parent output excludes separately observed fields");
|
||||
const wrong = {
|
||||
...checked,
|
||||
declaration: {
|
||||
@@ -113,6 +128,39 @@ test("fragment variable mappings are explicit and checked", async () => {
|
||||
async () => checked,
|
||||
);
|
||||
assert.deepEqual(result.selection[0]!.selection[0]!.fragmentSpread?.variables, { show: "visible" });
|
||||
const referenceDeclaration = build("with {show to visible;}");
|
||||
referenceDeclaration.importedFragments = referenceDeclaration.importedFragments!.map((entry) => ({
|
||||
...entry,
|
||||
mode: "reference",
|
||||
}));
|
||||
const binding = await compileQuery(
|
||||
referenceDeclaration,
|
||||
[item],
|
||||
async () => document,
|
||||
async () => checked,
|
||||
);
|
||||
assert.deepEqual(binding.selection[0]!.selection[0]!.fragmentSpread?.variables, { show: "visible" });
|
||||
assert.notEqual(binding.definitionDigest, result.definitionDigest);
|
||||
await assert.rejects(
|
||||
compileQuery(
|
||||
referenceDeclaration,
|
||||
[item],
|
||||
async () => document.replace("$visible: Boolean!", "$visible: Boolean!, $unused: Boolean!"),
|
||||
async () => checked,
|
||||
),
|
||||
/never used/,
|
||||
);
|
||||
const changedDigest = await compileQuery(
|
||||
referenceDeclaration,
|
||||
[item],
|
||||
async () => document,
|
||||
async () => ({ ...checked, definitionDigest: "b".repeat(64) }),
|
||||
);
|
||||
assert.notEqual(
|
||||
changedDigest.definitionDigest,
|
||||
binding.definitionDigest,
|
||||
"A bound fragment's identity remains in the parent contract digest",
|
||||
);
|
||||
await assert.rejects(
|
||||
compileQuery(
|
||||
build("with {show to visible;}"),
|
||||
|
||||
Reference in New Issue
Block a user