Select checked implementations explicitly by target and ABI

This commit is contained in:
Timothy J. Aveni
2026-09-20 19:51:15 -07:00
parent d701464312
commit 619b3d61c7
3 changed files with 87 additions and 0 deletions
+29
View File
@@ -28,6 +28,35 @@ export interface PackageArtifacts {
versions: ExecutionPlan["definition"]["versions"];
implementations: ArtifactImplementation[];
}
export interface ImplementationSelection {
target: string;
compatibility: ArtifactImplementation["compatibility"];
/** Optional only when exactly one compatible implementation covers these exports. */
id?: string;
exports: readonly string[];
}
/** Select from a checked manifest; selection does not establish package trust or isolation.
* Never resolve ambiguity by manifest order or silently substitute a requested implementation.
*/
export function selectArtifactImplementation(
manifest: PackageArtifacts,
selection: ImplementationSelection,
): ArtifactImplementation {
const candidates = manifest.implementations.filter(
(entry) =>
(selection.id === undefined || entry.id === selection.id) &&
entry.target === selection.target &&
entry.compatibility === selection.compatibility &&
selection.exports.every((id) => entry.exports.includes(id)),
);
if (candidates.length !== 1)
throw new ExecutionPlanError(
candidates.length ? "AMBIGUOUS_IMPLEMENTATION" : "IMPLEMENTATION_UNAVAILABLE",
manifest.packageRevisionId,
`${selection.id ?? "Select an explicit implementation ID"}: expected one ${selection.target}/${selection.compatibility} implementation covering the requested exports; found ${candidates.length}`,
);
return candidates[0]!;
}
export interface CheckedWorld {
codec: "camino-world-v1";
plan: string;