diff --git a/internal/agent/desktopapp.go b/internal/agent/desktopapp.go index c7e260841..60a634b18 100644 --- a/internal/agent/desktopapp.go +++ b/internal/agent/desktopapp.go @@ -73,6 +73,9 @@ func macAppFolders(home string) []string { return append(proc.SystemDirs("/Applications"), filepath.Join(home, "Applications")) } +// windowsStorePackages lists the package full names registered for the +// current user on Windows, nil elsewhere; a var so tests never read the +// machine's own registry. var windowsStorePackages = installedWindowsStorePackages var ( @@ -106,9 +109,12 @@ func (a *Agent) AppVersion() string { } return "" } -// storeAppVersion finds the newest version of an app among Microsoft Store -// package full names (name_version_architecture_resourceid_publisher). +// storeAppVersion finds the newest version of an app among Microsoft Store +// package full names (name_version_architecture_resourceid_publisher). Only +// the main package counts, the one with no resource id: the AppX registry +// keeps a resource package (…_neutral_split.scale-125_…) of a version the +// main package has moved past, so one is no sign the app is installed. func storeAppVersion(packages []string, name, publisher string) string { prefix, suffix := name+"_", "_"+publisher var newest [4]uint64 @@ -118,7 +124,7 @@ func storeAppVersion(packages []string, name, publisher string) string { continue } fields := strings.Split(strings.TrimSuffix(strings.TrimPrefix(pkg, prefix), suffix), "_") - if len(fields) < 3 { + if len(fields) != 3 || fields[2] != "" { continue } parts := strings.Split(fields[0], ".") diff --git a/internal/agent/desktopapp_test.go b/internal/agent/desktopapp_test.go index fa6faaa09..77b91c528 100644 --- a/internal/agent/desktopapp_test.go +++ b/internal/agent/desktopapp_test.go @@ -151,6 +151,10 @@ func TestCodexAppVersion(t *testing.T) { } } +// TestCodexWindowsStoreAppVersion: on Windows the Codex app is the Microsoft +// Store's OpenAI.Codex package (#1334, laacmilan: C:\Program Files\ +// WindowsApps\OpenAI.Codex_26.1002.7124.0_x64__2p2nqsd0c76g0), read from the +// newest main package registered for the user. func TestCodexWindowsStoreAppVersion(t *testing.T) { was, wasStore := appFolders, windowsStorePackages appFolders = func() []string { return nil } @@ -160,6 +164,9 @@ func TestCodexWindowsStoreAppVersion(t *testing.T) { "OpenAI.Codex_26.928.2636.0_x64__2p2nqsd0c76g0", "OpenAI.Codex_26.1002.7124.0_arm64__2p2nqsd0c76g0", "OpenAI.Codex_99.0.0.0_x64__wrong-publisher", + // a resource package left behind, as the Windows box's registry + // keeps Clipchamp's after its main package moved on + "OpenAI.Codex_27.0.0.0_neutral_split.scale-125_2p2nqsd0c76g0", } } t.Cleanup(func() { appFolders, windowsStorePackages = was, wasStore }) diff --git a/internal/agent/main_test.go b/internal/agent/main_test.go index 545738281..a21d300ba 100644 --- a/internal/agent/main_test.go +++ b/internal/agent/main_test.go @@ -32,6 +32,9 @@ func TestMain(m *testing.M) { // Pi's and omp's model registries are read from their installs; never // this machine's nodeModulesOf = func(string, []string) []string { return nil } + // Microsoft Store apps are read from the current user's AppX registry; + // never this machine's (a Windows box with the Codex app installed) + windowsStorePackages = func() []string { return nil } // Aside's default is changed through the aside binary, which answers for // the account the developer is actually running: a test that picks a // model would change the real Aside's default, and the running one would