From d77ccae8cbbcdb3fab4d7454f8c4e0250c335b1e Mon Sep 17 00:00:00 2001 From: Kenichiro Goto Date: Fri, 30 Oct 2026 19:17:22 +0900 Subject: [PATCH 1/2] Build for Linux and check rex in install The viewer runs without Rex, so release Linux binaries too. The install command is the only Rex integration; it now checks that the rex command exists before it writes rexdiff.lua. install.sh picks the macOS or Linux archive, and checks the checksum with shasum or sha256sum. --- .github/workflows/ci.yml | 13 ++++++++++++- .goreleaser.yml | 2 +- README.md | 13 ++++++++----- cmd/rexdiff/install.go | 6 ++++++ cmd/rexdiff/install_test.go | 18 ++++++++++++++++++ install.sh | 26 +++++++++++++++++++------- rex/rex.go | 28 +++++++++++++++++++++++++--- rex/rex_test.go | 37 +++++++++++++++++++++++++++++++++++++ 8 files changed, 126 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c84da4a..5eed097 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,8 @@ permissions: contents: read jobs: - # Rex runs only on macOS, so rexdiff is tested there. + # Rex runs only on macOS, so the Rex integration is tested there. The + # viewer also runs on Linux, without Rex. test: runs-on: macos-latest steps: @@ -20,6 +21,16 @@ jobs: - run: go vet ./... - run: go test -race -count=1 ./... + test-linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + - run: go vet ./... + - run: go test -race -count=1 ./... + lint: runs-on: ubuntu-latest steps: diff --git a/.goreleaser.yml b/.goreleaser.yml index ce4360d..08848b5 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -10,7 +10,7 @@ builds: - -trimpath ldflags: - -s -w -X main.version={{ .Version }} - goos: [darwin] + goos: [darwin, linux] goarch: [arm64, amd64] # The name has no version, so that the link of the latest release works in diff --git a/README.md b/README.md index 30f6b5e..8288391 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ rexdiff A diff viewer for coding agents in [Rex]. Think [herdr-reviewr], but for Rex. +It runs on macOS and Linux. It opens next to the agent and shows the changes. You comment on lines and send @@ -24,9 +25,9 @@ With curl: curl -fsSL https://raw.githubusercontent.com/frinfo702/rexdiff/main/install.sh | sh ``` -The script downloads the release for this Mac, checks its checksum, and puts -the binary in `~/.local/bin`, or in `REXDIFF_BIN_DIR`. It also says how to add -the directory to `PATH` if it is not there. +The script downloads the release for this system, checks its checksum, and +puts the binary in `~/.local/bin`, or in `REXDIFF_BIN_DIR`. It also says how +to add the directory to `PATH` if it is not there. With Go: @@ -41,7 +42,8 @@ rexdiff install ``` This adds the "Toggle rexdiff" action and binds it to Shift+Cmd+R. To remove -them, run `rexdiff uninstall`. +them, run `rexdiff uninstall`. The install command needs the `rex` command; +it says so when Rex is not installed. The viewer itself runs without Rex. ## Use @@ -128,7 +130,8 @@ After a change: ## Requirements -- Rex +- Rex for the action in Rex. Rex runs on macOS; the viewer also runs on its + own, on macOS and Linux. - git - `gh`, `glab`, or `az` for the pull request tab. You must be logged in. diff --git a/cmd/rexdiff/install.go b/cmd/rexdiff/install.go index 8764031..317d64e 100644 --- a/cmd/rexdiff/install.go +++ b/cmd/rexdiff/install.go @@ -274,6 +274,12 @@ func install( "in the settings in %s)", fs.Arg(0), luaPath()) } + // The action runs in Rex, and install reloads its configuration. Without + // the rex command, there is nothing to configure. + if !rex.Available() { + return errors.New("rex is not installed: install Rex, or put the rex command in PATH") + } + // Make the new content first. Then a bad rexdiff.lua stops the install // before it changes a file. lua := luaPath() diff --git a/cmd/rexdiff/install_test.go b/cmd/rexdiff/install_test.go index 264c082..5c320c1 100644 --- a/cmd/rexdiff/install_test.go +++ b/cmd/rexdiff/install_test.go @@ -1,6 +1,7 @@ package main import ( + "io" "os" "path/filepath" "strings" @@ -20,6 +21,23 @@ func fakeRexDir(t *testing.T, log string) string { return dir } +// TestInstallWithoutRex checks that install stops before it writes a file +// when rex is not installed. +func TestInstallWithoutRex(t *testing.T) { + t.Setenv("HOME", t.TempDir()) + t.Setenv("XDG_CONFIG_HOME", "") + t.Setenv("REX_CONFIG", "") + t.Setenv("REX_BIN_DIR", "") + t.Setenv("PATH", t.TempDir()) + err := install(t.Context(), "/opt/rexdiff", nil, io.Discard, io.Discard) + if err == nil || !strings.Contains(err.Error(), "rex is not installed") { + t.Errorf("install without rex = %v, want the rex error", err) + } + if _, err := os.Stat(filepath.Dir(luaPath())); !os.IsNotExist(err) { + t.Errorf("install without rex made %s", filepath.Dir(luaPath())) + } +} + // TestUpgrade checks that upgrade replaces the code of rexdiff.lua if it // differs from the code of the binary, and keeps the settings. func TestUpgrade(t *testing.T) { diff --git a/install.sh b/install.sh index 40d4921..601a9cb 100755 --- a/install.sh +++ b/install.sh @@ -1,5 +1,5 @@ #!/bin/sh -# install.sh installs the latest rexdiff release for this Mac: +# install.sh installs the latest rexdiff release for this Mac or Linux: # # curl -fsSL https://raw.githubusercontent.com/frinfo702/rexdiff/main/install.sh | sh # @@ -17,15 +17,19 @@ fail() { exit 1 } -[ "$(uname -s)" = Darwin ] || fail "rexdiff runs on macOS only" +case $(uname -s) in +Darwin) os=darwin ;; +Linux) os=linux ;; +*) fail "unsupported system: $(uname -s)" ;; +esac case $(uname -m) in -arm64) arch=arm64 ;; -x86_64) arch=amd64 ;; +arm64 | aarch64) arch=arm64 ;; +x86_64 | amd64) arch=amd64 ;; *) fail "unsupported machine: $(uname -m)" ;; esac -name="rexdiff-darwin-$arch.tar.gz" +name="rexdiff-$os-$arch.tar.gz" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT HUP INT TERM @@ -34,9 +38,17 @@ curl -fsSL "$base/$name" -o "$tmp/$name" || curl -fsSL "$base/sha256sums.txt" -o "$tmp/sha256sums.txt" || fail "cannot download $base/sha256sums.txt" +if command -v sha256sum >/dev/null 2>&1; then + got=$(sha256sum "$tmp/$name") +elif command -v shasum >/dev/null 2>&1; then + got=$(shasum -a 256 "$tmp/$name") +else + fail "need sha256sum or shasum to check the checksum" +fi +got=${got%% *} + want=$(awk -v name="$name" '$2 == name { print $1 }' "$tmp/sha256sums.txt") [ -n "$want" ] || fail "the checksums have no $name" -got=$(shasum -a 256 "$tmp/$name" | awk '{ print $1 }') [ "$want" = "$got" ] || fail "$name does not match its checksum" tar -xzf "$tmp/$name" -C "$tmp" rexdiff || fail "cannot unpack $name" @@ -48,7 +60,7 @@ printf 'installed %s\n' "$dir/rexdiff" case ":$PATH:" in *":$dir:"*) ;; *) - printf 'add %s to PATH, for example in ~/.zshrc:\n' "$dir" + printf 'add %s to PATH, for example:\n' "$dir" printf ' export PATH="%s:$PATH"\n' "$dir" ;; esac diff --git a/rex/rex.go b/rex/rex.go index 115823d..dd52b17 100644 --- a/rex/rex.go +++ b/rex/rex.go @@ -56,16 +56,38 @@ func binFromEnv() string { if _, err := exec.LookPath("rex"); err == nil { return "" } + bin, _ := appBin() + return bin +} + +// appBin returns the path of the rex command of the Rex server app on +// macOS. +func appBin() (string, error) { dir, err := os.UserConfigDir() if err != nil { - return "" + return "", err } bin := filepath.Join(dir, "com.superlogical.rex", "RexServer", "Versions", "Current", "Rex Server.app", "Contents", "MacOS", "rex") if _, err := os.Stat(bin); err != nil { - return "" + return "", err } - return bin + return bin, nil +} + +// Available reports whether the rex command exists: REX_BIN_DIR/rex, rex +// in PATH, or the rex of the Rex server app. On Linux, rex comes from +// REX_BIN_DIR or PATH. +func Available() bool { + if dir := os.Getenv("REX_BIN_DIR"); dir != "" { + _, err := exec.LookPath(filepath.Join(dir, "rex")) + return err == nil + } + if _, err := exec.LookPath("rex"); err == nil { + return true + } + _, err := appBin() + return err == nil } // command returns the command "rex args...". diff --git a/rex/rex_test.go b/rex/rex_test.go index 752cc50..e539c7a 100644 --- a/rex/rex_test.go +++ b/rex/rex_test.go @@ -215,6 +215,40 @@ func TestFromEnv(t *testing.T) { } } +// TestAvailable checks that Available finds rex in PATH and in REX_BIN_DIR, +// and that it is false without rex. +func TestAvailable(t *testing.T) { + // No rex in PATH and no Rex app in HOME. + t.Setenv("HOME", t.TempDir()) + t.Setenv("XDG_CONFIG_HOME", "") + t.Setenv("REX_BIN_DIR", "") + t.Setenv("PATH", t.TempDir()) + if rex.Available() { + t.Error("Available without rex = true") + } + + // rex in PATH, as go install leaves it. + bin := t.TempDir() + if err := os.WriteFile(filepath.Join(bin, "rex"), []byte("#!/bin/sh\n"), 0o755); err != nil { + t.Fatal(err) + } + t.Setenv("PATH", bin) + if !rex.Available() { + t.Error("Available with rex in PATH = false") + } + + // rex in REX_BIN_DIR, which Rex sets in its terminals. + dir := t.TempDir() + if err := os.WriteFile(filepath.Join(dir, "rex"), []byte("#!/bin/sh\n"), 0o755); err != nil { + t.Fatal(err) + } + t.Setenv("PATH", t.TempDir()) + t.Setenv("REX_BIN_DIR", dir) + if !rex.Available() { + t.Error("Available with rex in REX_BIN_DIR = false") + } +} + // TestReloadConfigOutsideRex checks that ReloadConfig runs the rex of the // Rex server app outside a Rex terminal. There, for example under brew, // REX_BIN_DIR is not set and rex is not in PATH. @@ -236,6 +270,9 @@ func TestReloadConfigOutsideRex(t *testing.T) { if err := os.WriteFile(filepath.Join(dir, "rex"), []byte(script), 0o755); err != nil { t.Fatal(err) } + if !rex.Available() { + t.Error("Available with the rex of the app = false") + } out, err := rex.ReloadConfig(t.Context()) if err != nil || out != "reloaded: config reload\n" { t.Errorf("ReloadConfig = %q, %v, want the report of the app rex", out, err) From fbf4d589c850c6fdcaf4f1cf11a4367031a6c59c Mon Sep 17 00:00:00 2001 From: Kenichiro Goto Date: Fri, 30 Oct 2026 19:22:20 +0900 Subject: [PATCH 2/2] Make the pull request test independent of the runner fakePath linked git but kept /bin and /usr/bin in PATH. On the Ubuntu runner, that found the real gh in /usr/bin, but the test wants the missing-tool error. Link cat too, and use only the test directory. --- vcs/pr_test.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/vcs/pr_test.go b/vcs/pr_test.go index 31616f5..ecacd49 100644 --- a/vcs/pr_test.go +++ b/vcs/pr_test.go @@ -196,16 +196,18 @@ func TestPullRequestErrors(t *testing.T) { } } -// fakePath sets PATH to dir and the system directories, and links git into -// dir. Then PATH has the fake forge tools and no real ones. +// fakePath sets PATH to dir, which has git and cat, so that PATH has the +// fake forge tools and no real ones. func fakePath(t *testing.T, dir string) { t.Helper() - p, err := exec.LookPath("git") - if err != nil { - t.Fatal(err) - } - if err := os.Symlink(p, filepath.Join(dir, "git")); err != nil { - t.Fatal(err) + for _, name := range []string{"cat", "git"} { + p, err := exec.LookPath(name) + if err != nil { + t.Fatal(err) + } + if err := os.Symlink(p, filepath.Join(dir, name)); err != nil { + t.Fatal(err) + } } - t.Setenv("PATH", dir+":/bin:/usr/bin") + t.Setenv("PATH", dir) }