fix: rebuild gate 1 from the resolver's own predicate, not a catalog lookup
Fix round 3 (review of 7ff9728):
Round 2's gate 1 (supportsEvidenceKeyIn(evidenceCatalogEntriesFromAssets(assets)))
still routed through evidenceCatalogEntryFor, matching on id || label ||
publicPath -- gate 2's question, asked over fewer rows, not the resolver's
actual success condition (assetKey === key && managementStatus === "READY"
&& Boolean(publicPath)). Two Asset shapes made the two predicates disagree:
a READY asset with publicPath null/"", and a READY asset whose publicPath
happens to satisfy the legacy /media/${someOtherKey}.svg convention for a
key that isn't its own assetKey. Both passed gate 1 while the resolver
could not produce real pixels, reproducing the validateDocument-VALID /
createPreview-throws-raw-Error disagreement a second time.
Rebuilt gate 1 in validate-working-copy.ts and
adapters/mock/project-public-render-model.ts directly from a new domain
function, supportsEvidenceKeyFromReadyAssets, that mirrors the resolver's
exact condition -- never through evidenceCatalogEntryFor again. Gate 2
keeps reading the merged catalog. Made the mock resolver total (returns a
placeholder instead of throwing, matching instant-preview.tsx's resolver),
removing a comment that asserted an invariant the code did not hold.
Wrapped mock-studio-gateway.ts's idempotent() so any non-StudioGatewayError
that reaches its catch is normalized before crossing the port -- closing
the class generally, not just this instance.
Reverted instant-preview.tsx's own gate 1 to the merged catalog (unlike
the mock adapters, its resolver is provably total, so a loose gate there
only ever degrades to a placeholder) -- round 2's narrowing there was a
separate regression: a CASE referencing a document-catalog-backed key
outside the editor's currently-loaded Asset list blanked the entire
preview instead of degrading one figure.
Pinned both slip-through shapes failing on both mock paths with the
thrown/rejected error's type asserted (StudioGatewayError, never a raw
Error), pinned idempotent()'s new wrapping via a validate/preview race,
pinned EVIDENCE_NOT_FOUND as reachable through validateWorkingCopy
directly, and pinned Instant Preview's graceful degradation.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
7ff9728a5c
commit
783e9b2cf1
@@ -17,22 +17,34 @@ type CatalogEntry = components["schemas"]["CatalogEntry"];
|
||||
* preview perfectly and then fail validation. Both paths now call this one
|
||||
* function instead.
|
||||
*
|
||||
* Fix round 2 (I2 regression): this module supplies the *building blocks* for
|
||||
* gate 1 (`supportsEvidenceKey` — "may this document reference this key at
|
||||
* all") and gate 2 (`evidenceCatalogEntryFor` — "does some catalog actually
|
||||
* carry it"); it deliberately does not hand callers a single combined
|
||||
* predicate. Round 1 called `supportsEvidenceKeyIn(mergedCatalog)` for BOTH
|
||||
* gates, which made gate 1 ask the identical question gate 2 already asks —
|
||||
* so any `EVIDENCE` catalog row backing something other than an Asset (e.g.
|
||||
* the pre-existing "Fetch Join Case" row that exists for QUESTION resolution
|
||||
* targets, not media) passed gate 1 even though no Asset and no legacy key
|
||||
* back it. Callers must instead compose gate 1 from *asset-backing only*:
|
||||
* `(key) => isSupportedEvidenceKey(key) || supportsEvidenceKeyIn(evidenceCatalogEntriesFromAssets(assets))(key)`,
|
||||
* then hand gate 2 the merged catalog (`[...documentCatalog,
|
||||
* ...evidenceCatalogEntriesFromAssets(assets)]`) separately. See
|
||||
* `validate-working-copy.ts`, `adapters/mock/project-public-render-model.ts`,
|
||||
* and `instant-preview.tsx` for the three compositions (each has its own
|
||||
* notion of "legacy key" per its layer).
|
||||
* Fix round 2 (I2 regression): gate 1 ("may this document reference this key
|
||||
* at all") and gate 2 ("does some catalog actually carry it") must ask
|
||||
* different questions. Round 1 called `supportsEvidenceKeyIn(mergedCatalog)`
|
||||
* for BOTH gates, so any `EVIDENCE` catalog row backing something other than
|
||||
* an Asset (e.g. the pre-existing "Fetch Join Case" row that exists for
|
||||
* QUESTION resolution targets, not media) passed gate 1 even though no Asset
|
||||
* and no legacy key back it. Round 2 narrowed gate 1 to
|
||||
* `supportsEvidenceKeyIn(evidenceCatalogEntriesFromAssets(assets))` --
|
||||
* still `evidenceCatalogEntryFor` under the hood, matching on
|
||||
* `id || label || publicPath`.
|
||||
*
|
||||
* Fix round 3 (same regression, third instance): `evidenceCatalogEntryFor`
|
||||
* is gate 2's question, asked over fewer rows -- it is still not the same
|
||||
* predicate as the resolver's actual success condition (`assetKey === key &&
|
||||
* managementStatus === "READY" && Boolean(publicPath)`), so a `READY` Asset
|
||||
* with `publicPath: null`/`""`, or one whose `publicPath` happens to match
|
||||
* `/media/${someOtherKey}.svg` for a key that isn't its own `assetKey`,
|
||||
* still passed gate 1 while the resolver could not produce real pixels for
|
||||
* it. Gate 1 must therefore be built directly from
|
||||
* `supportsEvidenceKeyFromReadyAssets` below -- the resolver's own
|
||||
* condition, not a catalog lookup -- never through
|
||||
* `evidenceCatalogEntryFor`/`supportsEvidenceKeyIn`. Gate 2 keeps using the
|
||||
* merged catalog via `evidenceCatalogEntryFor` as before. See
|
||||
* `validate-working-copy.ts` and `adapters/mock/project-public-render-model.ts`
|
||||
* for the compositions; `instant-preview.tsx` deliberately keeps gate 1 on
|
||||
* the merged catalog (its resolver can never throw, so a loose gate there
|
||||
* only ever degrades to a placeholder, and a strict assets-only gate was
|
||||
* itself a regression -- see that file's comment).
|
||||
*/
|
||||
export function evidenceCatalogEntriesFromAssets(
|
||||
assets: readonly Asset[],
|
||||
@@ -55,9 +67,43 @@ export function evidenceCatalogEntriesFromAssets(
|
||||
}));
|
||||
}
|
||||
|
||||
/** `SupportsEvidenceKey` built from the same rule the catalog-entry gate uses. */
|
||||
/**
|
||||
* `SupportsEvidenceKey` built from the same rule the catalog-entry gate
|
||||
* uses. Deliberately kept -- `instant-preview.tsx`'s gate 1 still uses this
|
||||
* over the merged catalog on purpose (see that file), but fix round 3
|
||||
* removed it from `validate-working-copy.ts` and
|
||||
* `adapters/mock/project-public-render-model.ts`'s gate 1: it answers gate
|
||||
* 2's question, not "can a real Asset resolve this key", and reusing it for
|
||||
* gate 1 is what let this bug recur twice.
|
||||
*/
|
||||
export function supportsEvidenceKeyIn(
|
||||
catalog: ReadonlyArray<CatalogEntry>,
|
||||
): SupportsEvidenceKey {
|
||||
return (key: string) => Boolean(evidenceCatalogEntryFor(catalog, key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix round 3. The resolver's own success condition, extracted so gate 1 can
|
||||
* be built from the *exact* predicate that decides whether a key actually
|
||||
* produces pixels, instead of a catalog lookup that can diverge from it
|
||||
* (`evidenceCatalogEntryFor` matches on `id || label || publicPath` against
|
||||
* whatever `evidenceCatalogEntriesFromAssets` happened to synthesize, which
|
||||
* is not the same expression as "does some `READY` Asset's own `assetKey`
|
||||
* equal this key and does it have real `publicPath`"). Two shapes where they
|
||||
* disagreed: a `READY` Asset with `publicPath: null`/`""`, and a `READY`
|
||||
* Asset whose `publicPath` happens to satisfy the legacy
|
||||
* `/media/${someOtherKey}.svg` convention for a key that is not its own
|
||||
* `assetKey`. Both passed the catalog-based gate while the resolver could
|
||||
* not produce a real descriptor for them.
|
||||
*/
|
||||
export function supportsEvidenceKeyFromReadyAssets(
|
||||
assets: readonly Asset[],
|
||||
): SupportsEvidenceKey {
|
||||
return (key: string) =>
|
||||
assets.some(
|
||||
(asset) =>
|
||||
asset.assetKey === key &&
|
||||
asset.managementStatus === "READY" &&
|
||||
Boolean(asset.publicPath),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user