From 5ffc05c027e746a2e35ed4b5f985c8db35f4c3d4 Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Mon, 19 Oct 2026 04:37:38 -0400 Subject: [PATCH] fix(result): look up Output names as own keys only Co-Authored-By: Claude Opus 5.5 --- packages/cli/src/result-export.ts | 2 +- packages/cli/src/result-query.ts | 2 +- packages/result/src/node/store.ts | 11 +++++++---- packages/result/test/result.test.ts | 6 ++++++ 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/result-export.ts b/packages/cli/src/result-export.ts index 8e65a54da..fb9f8ee53 100644 --- a/packages/cli/src/result-export.ts +++ b/packages/cli/src/result-export.ts @@ -124,7 +124,7 @@ export async function exportBuildResultOutput( ): Promise { const manifest = await repository.read(build); if (manifest === undefined) throw new Error(`Build Result ${build} does not exist`); - const publishedOutput = manifest.outputs[output]; + const publishedOutput = Object.hasOwn(manifest.outputs, output) ? manifest.outputs[output] : undefined; if (publishedOutput === undefined) throw new Error(`Build ${build} has no Output ${output}`); const resolvedOutput = await repository.resolve(build, output); if (resolvedOutput === undefined) throw new Error(`Build ${build} Output ${output} cannot be resolved`); diff --git a/packages/cli/src/result-query.ts b/packages/cli/src/result-query.ts index 9367caf4e..0958d76de 100644 --- a/packages/cli/src/result-query.ts +++ b/packages/cli/src/result-query.ts @@ -33,7 +33,7 @@ export async function browseBuildOutputHistory( const manifest = page.results[index]!; const sameSource = source === undefined || resolve(request.projectRoot, manifest.source.id) === source; - if (sameSource && manifest.outputs[request.output] !== undefined) matches.push(manifest); + if (sameSource && Object.hasOwn(manifest.outputs, request.output)) matches.push(manifest); if (matches.length === request.limit) { const hasOlder = index < page.results.length - 1 || page.next !== undefined; return { results: matches, ...(hasOlder ? { next: manifest.id } : {}) }; diff --git a/packages/result/src/node/store.ts b/packages/result/src/node/store.ts index 89382a340..aeef8856f 100644 --- a/packages/result/src/node/store.ts +++ b/packages/result/src/node/store.ts @@ -82,7 +82,7 @@ export function applyBuildResultPresentation( if (update.highlightedOutputs !== undefined) { const highlighted = [...new Set(update.highlightedOutputs)]; for (const output of highlighted) { - assert(manifest.outputs[output] !== undefined, + assert(Object.hasOwn(manifest.outputs, output), `Build Result ${manifest.id} has no Output ${output}`); } if (highlighted.length === 0) delete base.highlightedOutputs; @@ -153,7 +153,8 @@ export async function locateRepositoryBuildResultOutput( const manifest = await repository.read(currentBuild); if (manifest === undefined) return undefined; assert(manifest.outcome !== undefined, `Build ${currentBuild} is not a finished Result`); - const entry = manifest.outputs[currentOutput]; + // Output names are data; `toString` must not resolve to Object.prototype. + const entry = Object.hasOwn(manifest.outputs, currentOutput) ? manifest.outputs[currentOutput] : undefined; if (entry === undefined) return undefined; if (entry.value.kind === "build-output") { currentBuild = entry.value.build; @@ -298,7 +299,8 @@ export async function resolveBuildResultOutput( const directory = buildResultDirectory(root, currentBuild); const manifest = await readBuildResult(directory); if (manifest === undefined) return undefined; - const entry = manifest.outputs[currentOutput]; + // Output names are data; `toString` must not resolve to Object.prototype. + const entry = Object.hasOwn(manifest.outputs, currentOutput) ? manifest.outputs[currentOutput] : undefined; if (entry === undefined) return undefined; if (entry.value.kind === "build-output") { currentBuild = entry.value.build; @@ -346,7 +348,8 @@ export async function describeBuildResultOutput( assert(!seen.has(address), `Build Output forwarding repeats ${currentBuild} / ${currentOutput}`); seen.add(address); const manifest = await readBuildResult(buildResultDirectory(root, currentBuild)); - const entry = manifest?.outputs[currentOutput]; + const entry = manifest !== undefined && Object.hasOwn(manifest.outputs, currentOutput) + ? manifest.outputs[currentOutput] : undefined; if (entry === undefined) return undefined; if (entry.value.kind === "build-output") { currentBuild = entry.value.build; diff --git a/packages/result/test/result.test.ts b/packages/result/test/result.test.ts index 3421d1220..1f973370d 100644 --- a/packages/result/test/result.test.ts +++ b/packages/result/test/result.test.ts @@ -217,6 +217,12 @@ test("one same-Build resource backs a public video and a CompositeValue payload" repository.updatePresentation("bld_20260902T100000000Z_0000000001", { highlightedOutputs: ["missing.output"] }), /has no Output missing\.output/u, ); + // Output names are data: names inherited from Object.prototype are not Outputs. + await assert.rejects( + repository.updatePresentation("bld_20260902T100000000Z_0000000001", { highlightedOutputs: ["constructor"] }), + /has no Output constructor/u, + ); + assert.equal(await repository.resolve("bld_20260902T100000000Z_0000000001", "toString"), undefined); const cleared = await repository.updatePresentation("bld_20260902T100000000Z_0000000001", { outputDisplayNames: { "shot.video": null }, title: null,