From eabe09b2e24f4030425ff19fe11b5a8e6ef4fa3e Mon Sep 17 00:00:00 2001 From: gensokyo-dev Date: Sat, 28 Nov 2026 18:09:54 +0000 Subject: [PATCH] refactor(setup): record which installation an owned launcher selects Ownership of an absolute launcher now carries whether it selects this installation, and launcher equivalence requires that fact instead of inferring it from ownership alone. Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> --- src/application/ClientRegistrationIdentity.ts | 52 ++++++++++++++----- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/src/application/ClientRegistrationIdentity.ts b/src/application/ClientRegistrationIdentity.ts index e6abb82327..bbeb1a3c93 100644 --- a/src/application/ClientRegistrationIdentity.ts +++ b/src/application/ClientRegistrationIdentity.ts @@ -228,6 +228,18 @@ const entrypointIdentity = ( } }; +/** Ownership of an absolute REA entry and which installation it selects. */ +type EntrypointOwnership = Pick< + ClientRegistrationCommandFacts, + "identity" | "installation" +>; + +/** An owned absolute entry selects this installation. */ +const entrypointOwnership = ( + identity: ClientRegistrationCommandIdentity, +): EntrypointOwnership => + identity === "owned" ? { identity, installation: "current" } : { identity }; + /** A direct launcher may be a native executable or a Node shebang script. */ const directEntrypointIdentity = ( candidate: string, @@ -449,6 +461,7 @@ export const equivalentClientRegistrationCommands = ( return ( prior.entrypoint !== undefined && prior.identity === "owned" && + prior.installation === "current" && prior.launch === requestedFacts.launch && (prior.launch !== "managed_shim" || prior.independentFallback === true) ); @@ -465,6 +478,11 @@ export interface ClientRegistrationCommandFacts { | "unknown"; /** Selected absolute launcher/script path; excludes package and unresolved PATH commands. */ readonly entrypoint: string | undefined; + /** + * Present when an owned absolute launcher selects this installation + * (runtime and REA entry); absent when none was resolved. + */ + readonly installation?: "current"; /** The fallback must reach the current interpreter without the shim's sibling. */ readonly independentFallback?: boolean; readonly package: @@ -526,10 +544,11 @@ const inspectDirectRegistrationCommand = ( : inspectAubeShim(managed.shim, process.execPath, managed); return { launch: "managed_shim", - identity: - shim === undefined || !currentPathAvailable - ? "unknown" - : entrypointIdentity(shim.target, currentCommandPath), + ...(shim === undefined || !currentPathAvailable + ? { identity: "unknown" } + : entrypointOwnership( + entrypointIdentity(shim.target, currentCommandPath), + )), entrypoint: shim?.target, independentFallback: shim !== undefined && @@ -569,10 +588,11 @@ const inspectDirectRegistrationCommand = ( const selectedEntrypoint = normalizeEntrypointPath(entrypoint); return { launch: "runtime_script", - identity: - selectedEntrypoint === undefined || !currentPathAvailable - ? "unknown" - : entrypointIdentity(selectedEntrypoint, currentCommandPath), + ...(selectedEntrypoint === undefined || !currentPathAvailable + ? { identity: "unknown" } + : entrypointOwnership( + entrypointIdentity(selectedEntrypoint, currentCommandPath), + )), entrypoint: selectedEntrypoint, package: undefined, }; @@ -594,18 +614,22 @@ const inspectDirectRegistrationCommand = ( if (managedTarget !== undefined) return { launch: "direct", - identity: currentPathAvailable - ? entrypointIdentity(managedTarget, currentCommandPath) - : "unknown", + ...(currentPathAvailable + ? entrypointOwnership( + entrypointIdentity(managedTarget, currentCommandPath), + ) + : { identity: "unknown" }), entrypoint: managedTarget, package: undefined, }; if (isAbsolute(executable)) return { launch: "direct", - identity: currentPathAvailable - ? directEntrypointIdentity(executable, currentCommandPath) - : "unknown", + ...(currentPathAvailable + ? entrypointOwnership( + directEntrypointIdentity(executable, currentCommandPath), + ) + : { identity: "unknown" }), entrypoint: executable, package: undefined, };