From f50f8505ab30b4c88c9a27eaff55ba1b6adc3a4d Mon Sep 17 00:00:00 2001 From: Victor Hugo dos Santos Date: Thu, 12 Nov 2026 10:11:01 -0300 Subject: [PATCH 1/2] feat(util): add Homebrew update instructions based on tap name from INSTALL_RECEIPT.json - Introduced a new function to determine the full Homebrew formula name based on the tap specified in the INSTALL_RECEIPT.json file. - Updated the getUpdateInstructions function to return the correct update command for Homebrew based on the formula name. - Added unit tests to validate the behavior of the new update instructions based on various receipt scenarios. --- packages/util/check-for-update.go | 29 ++++++++++++++++++++++- packages/util/check-for-update_test.go | 32 ++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/packages/util/check-for-update.go b/packages/util/check-for-update.go index 33289140d..6c49a68cb 100644 --- a/packages/util/check-for-update.go +++ b/packages/util/check-for-update.go @@ -9,6 +9,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "runtime" "strings" "sync" @@ -296,6 +297,32 @@ func GetUpdateInstructions() string { return getUpdateInstructions(runtime.GOOS, execPath) } +var homebrewTapName = regexp.MustCompile(`^[a-z0-9][a-z0-9_.-]*/[a-z0-9][a-z0-9_.-]*$`) + +// homebrewFormula names the formula the way `brew upgrade` will act on it. Homebrew skips a formula +// from a tap the user hasn't trusted when it's named by its short name, but trusts it when it's named +// in full, so an install from a tap gets its full name. The tap comes from the receipt Homebrew writes +// next to the binary (Cellar/infisical//INSTALL_RECEIPT.json). +func homebrewFormula(execPath string) string { + receipt, err := os.ReadFile(filepath.Join(filepath.Dir(filepath.Dir(execPath)), "INSTALL_RECEIPT.json")) + if err != nil { + return "infisical" + } + var parsed struct { + Source struct { + Tap string `json:"tap"` + } `json:"source"` + } + if json.Unmarshal(receipt, &parsed) != nil { + return "infisical" + } + tap := parsed.Source.Tap + if tap == "" || tap == "homebrew/core" || !homebrewTapName.MatchString(tap) { + return "infisical" + } + return tap + "/infisical" +} + func getUpdateInstructions(goos string, execPath string) string { p := strings.ToLower(execPath) isNpm := strings.Contains(p, "node_modules") @@ -306,7 +333,7 @@ func getUpdateInstructions(goos string, execPath string) string { return "To update, run: npm update -g @infisical/cli" } if strings.Contains(p, "/homebrew/") || strings.Contains(p, "/cellar/") { - return "To update, run: brew update && brew upgrade infisical" + return "To update, run: brew update && brew upgrade " + homebrewFormula(execPath) } return "" case "windows": diff --git a/packages/util/check-for-update_test.go b/packages/util/check-for-update_test.go index f460118fb..6a324bb4b 100644 --- a/packages/util/check-for-update_test.go +++ b/packages/util/check-for-update_test.go @@ -397,3 +397,35 @@ func TestWriteUpdateCheckCache_AtomicWrite(t *testing.T) { t.Errorf("got permissions %o, want 0600", perm) } } + +func TestHomebrewUpdateInstructionsNameTheTap(t *testing.T) { + keg := func(t *testing.T, receipt string) string { + dir := filepath.Join(t.TempDir(), "Cellar", "infisical", "0.45.0") + if err := os.MkdirAll(filepath.Join(dir, "bin"), 0o755); err != nil { + t.Fatal(err) + } + if receipt != "" { + if err := os.WriteFile(filepath.Join(dir, "INSTALL_RECEIPT.json"), []byte(receipt), 0o644); err != nil { + t.Fatal(err) + } + } + return filepath.Join(dir, "bin", "infisical") + } + tests := []struct { + name, receipt, want string + }{ + {"infisical tap", `{"source":{"tap":"infisical/get-cli"}}`, "brew update && brew upgrade infisical/get-cli/infisical"}, + {"homebrew core", `{"source":{"tap":"homebrew/core"}}`, "brew update && brew upgrade infisical"}, + {"no receipt", "", "brew update && brew upgrade infisical"}, + {"unreadable receipt", `not json`, "brew update && brew upgrade infisical"}, + {"no tap in receipt", `{"source":{}}`, "brew update && brew upgrade infisical"}, + {"unsafe tap name", `{"source":{"tap":"evil/tap; rm -rf ~"}}`, "brew update && brew upgrade infisical"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := getUpdateInstructions("darwin", keg(t, tt.receipt)); got != "To update, run: "+tt.want { + t.Errorf("got %q, want %q", got, "To update, run: "+tt.want) + } + }) + } +} From a427612b094ae3188f7786fbf9fe11ef7234cdf7 Mon Sep 17 00:00:00 2001 From: Victor Hugo dos Santos Date: Thu, 12 Nov 2026 10:21:28 -0300 Subject: [PATCH 2/2] fix(util): normalize file paths in Homebrew update instructions test - Updated the test for getUpdateInstructions to use filepath.ToSlash for consistent file path formatting on macOS. - Ensured that the test accurately reflects the expected output for Homebrew update commands. --- packages/util/check-for-update_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/util/check-for-update_test.go b/packages/util/check-for-update_test.go index 6a324bb4b..db2d6973c 100644 --- a/packages/util/check-for-update_test.go +++ b/packages/util/check-for-update_test.go @@ -423,7 +423,7 @@ func TestHomebrewUpdateInstructionsNameTheTap(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - if got := getUpdateInstructions("darwin", keg(t, tt.receipt)); got != "To update, run: "+tt.want { + if got := getUpdateInstructions("darwin", filepath.ToSlash(keg(t, tt.receipt))); got != "To update, run: "+tt.want { t.Errorf("got %q, want %q", got, "To update, run: "+tt.want) } })