From 55213c1b4d27bc39521b35dfd98130b4edfc0eb5 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 13 Oct 2026 04:55:17 +0800 Subject: [PATCH] agent: the Windows Codex app's version comes from its main Store package only, and agent tests never read the machine's AppX registry (#1334) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review follow-up to 46e4107 (AwadYoo). What: - storeAppVersion counts only the main package (empty resource id). The Windows box's AppX registry key keeps a resource package that Get-AppxPackage no longer lists (Clipchamp.Clipchamp_4.6.10420.0_neutral_split.scale-125_… beside the installed 4.7.10020.0_x64__…). A stale entry like that is no sign the app is installed, and a newer-numbered one would win "newest". - internal/agent's TestMain stubs windowsStorePackages, as it already does for nodeModulesOf and the other machine readers (#1823's rule): on a Windows box with the Codex app installed, tests read nothing of it. - the doc comment for storeAppVersion had a blank line in the middle of it. It is joined, and windowsStorePackages has its own comment. Run (go1.26.8, sandbox HOME, private GOCACHE): - Windows box (Win 11 x64): installed the real Store app (winget 9PLM9XGG6VKS, "ChatGPT", OpenAI.Codex_26.1007.2314.0_x64__2p2nqsd0c76g0). A probe built from origin/main printed AppVersion="" HasApp=false; built from this series: AppVersion="26.1007.2314.0" HasApp=true, and CLI() ok=true App="26.1007.2314.0" with no codex CLI on PATH. - break checks: the resource-id filter put back to len(fields) < 3 -> TestCodexWindowsStoreAppVersion FAIL `Codex Store app: "27.0.0.0"`; AppVersion without the Store read -> FAIL `Codex Store app: ""`. Restored: pass on darwin and on the Windows box (test binary built with GOOS=windows GOARCH=amd64, run there with the real app installed). --- internal/agent/desktopapp.go | 12 +++++++++--- internal/agent/desktopapp_test.go | 7 +++++++ internal/agent/main_test.go | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) 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