Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

windows: magpie.com is written again only when the launcher changes, not on every update

yetone6b253dbb3fad
diff --git a/Makefile b/Makefile
index 1e9005a42..08b67ba7c 100644
--- a/Makefile
+++ b/Makefile
@@ -105,6 +105,10 @@ release-cli:
# the icon, version and a DPI-aware manifest from build/windows. It carries
# magpie.com, the console program a terminal runs for `magpie` and waits
# for, which it writes beside itself (internal/update/com.go, #3737).
+# The launcher is built without the commit stamped in (-buildvcs=false):
+# magpie.com is written again whenever its bytes differ, and with the
+# commit in them every release wrote a new one though the launcher was the
+# same (TestLauncherSameAtEveryCommit).
WINVER = $(shell echo $(VERSION) | sed -E 's/^v//; s/[^0-9.].*//')
release-windows:
@mkdir -p dist
@@ -112,7 +116,7 @@ release-windows:
--file-version "$(or $(WINVER),0.0.0)" --product-version "$(or $(WINVER),0.0.0)"
@for arch in amd64 arm64; do \
echo " windows/$$arch (app)"; \
- CGO_ENABLED=0 GOOS=windows GOARCH=$$arch go build -trimpath -ldflags="-s -w" -o internal/update/launcher-$$arch.com ./internal/update/launcher || exit 1; \
+ CGO_ENABLED=0 GOOS=windows GOARCH=$$arch go build -trimpath -buildvcs=false -ldflags="-s -w" -o internal/update/launcher-$$arch.com ./internal/update/launcher || exit 1; \
CGO_ENABLED=0 GOOS=windows GOARCH=$$arch go build -tags production,comlauncher -trimpath -ldflags="$(LDFLAGS) -H windowsgui" -o dist/magpie-windows-$$arch.exe . || exit 1; \
done; rm -f rsrc_windows_*.syso internal/update/launcher-*.com
diff --git a/internal/update/com.go b/internal/update/com.go
index 8cbd11f9b..410602ec4 100644
--- a/internal/update/com.go
+++ b/internal/update/com.go
@@ -21,7 +21,10 @@ import (
// It is written wherever a terminal runs magpie from: when the app's
// folder is on PATH, where Settings › Command line puts it, or a magpie.com
// or magpie.cmd is there already. The app writes it again as it starts
-// when its bytes differ, so an update brings it along.
+// when its bytes differ, so an update brings it along. They differ only
+// when the launcher does: it is built without the release's commit in it
+// (the Makefile's -buildvcs=false), or every update wrote a new magpie.com
+// (lucky_eagle_38410 on Discord, TestLauncherSameAtEveryCommit).
// ComEnv is set by magpie.com for the app it runs: the standard handles it
// hands over are the terminal's console or a redirection, and its console
diff --git a/internal/update/com_build_test.go b/internal/update/com_build_test.go
new file mode 100644
index 000000000..712ce528d
--- /dev/null
+++ b/internal/update/com_build_test.go
@@ -0,0 +1,93 @@
+package update
+
+import (
+ "bytes"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "regexp"
+ "strings"
+ "testing"
+
+ "github.com/yetone/magpie/internal/proc"
+)
+
+// launcherFlags are the go build flags `make release-windows` builds the
+// launcher with: what stands between "go build" and "-o" on the Makefile
+// line that builds ./internal/update/launcher.
+func launcherFlags(t *testing.T) []string {
+ t.Helper()
+ mk, err := os.ReadFile(filepath.Join("..", "..", "Makefile"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ for _, line := range strings.Split(string(mk), "\n") {
+ if !strings.Contains(line, "./internal/update/launcher") {
+ continue
+ }
+ _, rest, ok := strings.Cut(line, "go build ")
+ if !ok {
+ continue
+ }
+ rest, _, _ = strings.Cut(rest, " -o ")
+ var flags []string
+ for _, f := range regexp.MustCompile(`(?:[^\s"]+|"[^"]*")+`).FindAllString(rest, -1) {
+ flags = append(flags, strings.ReplaceAll(f, `"`, ""))
+ }
+ return flags
+ }
+ t.Fatal("no line in the Makefile builds ./internal/update/launcher")
+ return nil
+}
+
+// The launcher is built into every Windows release and written out as
+// magpie.com wherever its bytes differ from the one there (writeCom). Built
+// from a git checkout with Go's default -buildvcs, it carried the release's
+// commit and time, so every update wrote a new magpie.com though the
+// launcher hadn't changed (lucky_eagle_38410 on Discord, 10-28). Built as
+// the Makefile builds it, the same source at two commits is the same bytes.
+func TestLauncherSameAtEveryCommit(t *testing.T) {
+ if _, err := exec.LookPath("git"); err != nil {
+ t.Skip("no git")
+ }
+ flags := launcherFlags(t)
+ dir := t.TempDir()
+ for name, text := range map[string]string{
+ "go.mod": "module launcher\n\ngo 1.26\n",
+ "main.go": "package main\n\nfunc main() {}\n",
+ } {
+ if err := os.WriteFile(filepath.Join(dir, name), []byte(text), 0o644); err != nil {
+ t.Fatal(err)
+ }
+ }
+ run := func(name string, args ...string) {
+ t.Helper()
+ cmd := proc.Command(name, args...)
+ cmd.Dir = dir
+ cmd.Env = append(os.Environ(), "GOWORK=off", "GOFLAGS=", "GOTOOLCHAIN=local",
+ "CGO_ENABLED=0", "GOOS=windows", "GOARCH=amd64",
+ "GIT_AUTHOR_NAME=t", "[email protected]", "GIT_COMMITTER_NAME=t", "[email protected]")
+ if out, err := cmd.CombinedOutput(); err != nil {
+ t.Fatalf("%s %q: %v\n%s", name, args, err, out)
+ }
+ }
+ build := func(out string) []byte {
+ t.Helper()
+ run("go", append(append([]string{"build"}, flags...), "-o", out, ".")...)
+ b, err := os.ReadFile(out)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return b
+ }
+ run("git", "init", "-q")
+ run("git", "add", "go.mod", "main.go")
+ run("git", "commit", "-q", "-m", "one")
+ // outside the checkout, so the build sees no untracked file
+ out := t.TempDir()
+ first := build(filepath.Join(out, "1.com"))
+ run("git", "commit", "-q", "--allow-empty", "-m", "two")
+ if second := build(filepath.Join(out, "2.com")); !bytes.Equal(first, second) {
+ t.Fatalf("the launcher built at the next commit differs (%v): magpie.com would be written again on every update", flags)
+ }
+}