fix: un-collapse evidence gate 1 from gate 2 to close a raw-Error escape
Fix round 2 (review of 9864958):
Round 1's I2 fix made gate 1 (supportsEvidenceKeyIn) read the same
merged catalog gate 2 already checks, so gate 1 stopped asking "does a
real Asset (or the legacy key) back this key" and started asking the
identical question gate 2 asks ("is there any EVIDENCE catalog row for
it"). A real EVIDENCE catalog row that exists for something other than
media (fixtures.ts's row for a QUESTION resolution target) then passed
gate 1 with nothing backing it as evidence. validateDocument reported
VALID; createPreview's resolver -- which only ever knew the legacy key
and real Assets -- threw a raw, unwrapped Error, violating the port's
StudioGatewayError-only contract. I2's disagreement reproduced in the
opposite direction.
Rebuilt gate 1 in all three callers (validate-working-copy.ts,
adapters/mock/project-public-render-model.ts, instant-preview.tsx) as
"legacy key OR an Asset-derived catalog entry only" -- never the
merged document catalog -- while gate 2 keeps reading the merged
catalog as before. Also stopped emitting the real Asset UUID as the
synthesized CatalogEntry's id (prefixed instead), closing a path where
pasting an Asset's real id -- never something the Picker itself
produces -- would have resolved as an evidence key.
Restored content-format.test.ts's domain tests to exercise the same
gate-1 composition production callers now use instead of a bare
hand-injected predicate, and added coverage for: a real non-asset
EVIDENCE row still being rejected, an Asset-backed key being accepted
with no document-catalog row at all, the fixture-UUID case failing
both mock paths with no raw Error crossing the gateway port, and the
EVIDENCE_ALT_REQUIRED decorative-Asset pairing that had no test.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
98649585e6
commit
7ff9728a5c
@@ -17,14 +17,22 @@ type CatalogEntry = components["schemas"]["CatalogEntry"];
|
||||
* preview perfectly and then fail validation. Both paths now call this one
|
||||
* function instead.
|
||||
*
|
||||
* Every `EVIDENCE` `CatalogEntry` the document catalog issues today already
|
||||
* carries the referenced key in `label` (see the one pre-existing fixture:
|
||||
* `{ type: "EVIDENCE", label: "fetch-strategy-boundary" }`), so a `READY`
|
||||
* Asset is mapped the same way: `label` <- `assetKey`. A key backed by no
|
||||
* loaded `READY` Asset and no catalog row synthesizes no entry here, so
|
||||
* `evidenceCatalogEntryFor` (the domain's one matching rule, shared by both
|
||||
* gates) still rejects it -- this cannot forge a pass for a dangling
|
||||
* reference.
|
||||
* 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).
|
||||
*/
|
||||
export function evidenceCatalogEntriesFromAssets(
|
||||
assets: readonly Asset[],
|
||||
@@ -32,7 +40,14 @@ export function evidenceCatalogEntriesFromAssets(
|
||||
return assets
|
||||
.filter((asset) => asset.managementStatus === "READY")
|
||||
.map((asset) => ({
|
||||
id: asset.id,
|
||||
// Not `asset.id` (fix round 2): `evidenceCatalogEntryFor` also matches
|
||||
// on `id`, so reusing the real Asset UUID here would let anyone who
|
||||
// has seen that UUID elsewhere (an API response, an admin view) type
|
||||
// it directly as a directive key and have it resolve — a path the
|
||||
// Picker never produces (it always emits `assetKey`) and that widens
|
||||
// the reference surface for no benefit. Prefixed so it can never
|
||||
// collide with a real `asset.id` a caller might paste in.
|
||||
id: `asset-evidence:${asset.id}`,
|
||||
type: "EVIDENCE",
|
||||
label: asset.assetKey,
|
||||
publicPath: asset.publicPath ?? undefined,
|
||||
|
||||
Reference in New Issue
Block a user