provider: a Claude sign-in with no Claude Code downloads it first (Kabubu01)
Kabubu01 (X, 2117435171205259713) added a Claude account in the GUI on a
computer with no Claude Code: the card ended "登录未完成" with the English
"install Claude Code first, the `claude` command line … magpie signs in to
Claude through it; … `magpie claude-code install`". Every other
subscription used through its vendor's CLI (Devin, Cursor, Grok) installs
it when its sign-in starts; Claude's only said how.
cliFor("claude") is now Claude Code: found by findClaudeCLI (this
computer's, magpie's download, or WSL's), installed by
downloadClaudeCode, which is what `magpie claude-code install` does:
claudecode.Latest, then claudecode.Install, Anthropic's own build checked
against its manifest's SHA-256 and size, into magpie's cache, not on
PATH. claudeExecutable (claudecode.Find) finds it there, so the sign-in
goes on as before. The card shows the existing "Installing Claude Code…"
state (strings already translated). runInstaller uses a CLI's native
installer on every OS when it has no shell one-liner, and a failed
download's error names `magpie claude-code install` as the manual way.
What was run:
- TestClaudeSignInDownloadsClaudeCode (installing → paste page → done
after the fake download) and TestClaudeSignInDownloadFails (the error
carries the cause and `magpie claude-code install`), new, plus every
-run 'SignIn' test, on mote: ok. isolate() fakes the download, so no
test reaches downloads.claude.ai.
- Broken by hand: with cliFor's claude case renamed, both new tests red.
- go test ./internal/provider on mote: ok (160s).
- Windows (win-run, xiaomi-gpu): TestClaudeSignInDownloadFails,
TestSignInInstallFails, TestSignInCanceledWhileInstalling,
TestWindowsInstallerNotOnCommandLine ok; the download-then-sign-in test
skips there, as every fake-claude sign-in test does (shell fakes).
- GOOS=linux go vet -tags nogui and GOOS=windows go vet of
./internal/provider on mote: ok. gofmt -l clean.
- Real download in a sandbox HOME on mote, PATH=/usr/bin:/bin:
`magpie claude-code install --yes` (the same Latest+Install calls)
fetched and checked Claude Code 2.1.317 into .cache/magpie/claude-code,
and it ran (`2.1.317 (Claude Code)`).
- Rebased on a92e85ab2 (two provider commits): go test ./internal/provider
on mote again: ok (138s).
Not changed: the gateway's "Claude Code is not installed" (a request
path; a 240MB download doesn't belong under a request).
Not tried: the GUI sign-in end to end with a real download, and a
download slower than installTimeout's 10 minutes (it fails with the
manual command).
This commit is contained in:
@@ -76,6 +76,10 @@ func isolate(t testing.TB) {
|
||||
oldDevin := DevinExecutable
|
||||
claudeKeychain = false
|
||||
claudeExecutable = func() string { return "" }
|
||||
// a Claude sign-in with no Claude Code downloads one: never in a test
|
||||
oldDownload := downloadClaudeCode
|
||||
downloadClaudeCode = func(context.Context) error { return errors.New("no Claude Code download in tests") }
|
||||
t.Cleanup(func() { downloadClaudeCode = oldDownload })
|
||||
// the machine's own devin, if it has one, is no test's
|
||||
DevinExecutable = func() string { return "" }
|
||||
forgetClaudeCredential()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package provider
|
||||
|
||||
// Some subscriptions are used through the vendor's own CLI — Cursor's,
|
||||
// Grok's, Devin's — and signed in with it too. One that isn't installed is
|
||||
// Some subscriptions are used through the vendor's own CLI — Claude
|
||||
// Code, Cursor's, Grok's, Devin's — and signed in with it too. One that isn't installed is
|
||||
// installed with the vendor's own installer when its sign-in starts, as the
|
||||
// vendor's page tells a person to, rather than leaving the sign-in to fail
|
||||
// or, as Devin's did, to finish with nothing to show for it.
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/claudecode"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
@@ -24,18 +25,34 @@ import (
|
||||
// when there is one, does what the shell one does without a shell, for a
|
||||
// magpie with none (its Docker image had no bash, curl or wget until #2834). setup: the
|
||||
// installer ends by running the CLI's own setup, which asks how to sign in;
|
||||
// magpie signs in itself once the CLI is there.
|
||||
// magpie signs in itself once the CLI is there. manual, when set, is how
|
||||
// a person installs it, told when the install fails, where a CLI with no
|
||||
// one-liner (Claude Code's, which magpie downloads itself) has native only.
|
||||
type agentCLI struct {
|
||||
Name string
|
||||
find func() string
|
||||
sh string
|
||||
ps string
|
||||
native func(ctx context.Context) error
|
||||
manual string
|
||||
setup bool
|
||||
}
|
||||
|
||||
func cliFor(agent string) (agentCLI, bool) {
|
||||
switch agent {
|
||||
case "claude":
|
||||
// Kabubu01 (X): the GUI's Claude sign-in failed with "install
|
||||
// Claude Code first … or run `magpie claude-code install`". The
|
||||
// sign-in now downloads it as that command does: Anthropic's own
|
||||
// build, checked against its manifest, kept in magpie's cache and
|
||||
// not put on PATH
|
||||
return agentCLI{Name: "Claude Code", find: func() string {
|
||||
c, ok := findClaudeCLI()
|
||||
if ok && c.wsl != nil {
|
||||
return "wsl:" + c.wsl.Distro
|
||||
}
|
||||
return c.path
|
||||
}, native: downloadClaudeCode, manual: "magpie claude-code install"}, true
|
||||
case "devin":
|
||||
return agentCLI{Name: "Devin CLI", find: func() string { return DevinExecutable() },
|
||||
sh: "curl -fsSL https://cli.devin.ai/install.sh | bash",
|
||||
@@ -68,7 +85,7 @@ var installTimeout = 10 * time.Minute
|
||||
|
||||
// runInstaller runs a vendor's installer; a var so tests can fake it.
|
||||
var runInstaller = func(ctx context.Context, c agentCLI) ([]byte, error) {
|
||||
if runtime.GOOS != "windows" && c.native != nil && !shellInstallerRuns() {
|
||||
if c.native != nil && (c.sh == "" && c.ps == "" || runtime.GOOS != "windows" && !shellInstallerRuns()) {
|
||||
return nil, c.native(ctx)
|
||||
}
|
||||
var cmd *exec.Cmd
|
||||
@@ -144,6 +161,18 @@ func runUntilInstalled(ctx context.Context, cmd *exec.Cmd, c agentCLI) ([]byte,
|
||||
return out.Bytes(), err
|
||||
}
|
||||
|
||||
// downloadClaudeCode downloads the newest Claude Code into magpie's cache
|
||||
// (claudecode.Install), where claudecode.Find, and so the sign-in, finds
|
||||
// it; a var so tests never reach the network.
|
||||
var downloadClaudeCode = func(ctx context.Context) error {
|
||||
r, err := claudecode.Latest(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = claudecode.Install(ctx, r, nil)
|
||||
return err
|
||||
}
|
||||
|
||||
// shellInstallerRuns is whether a vendor's `curl … | bash` can run here:
|
||||
// bash, and curl, which every one-liner (and the scripts behind them)
|
||||
// downloads with. magpie's Docker image had none of them, and the install
|
||||
@@ -174,6 +203,9 @@ func installCLI(ctx context.Context, c agentCLI) error {
|
||||
if runtime.GOOS == "windows" {
|
||||
manual = c.ps
|
||||
}
|
||||
if c.manual != "" {
|
||||
manual = c.manual
|
||||
}
|
||||
if ctx.Err() == context.Canceled {
|
||||
return ctx.Err()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// Kabubu01 (X): with no Claude Code on the computer, the GUI's Claude
|
||||
// sign-in failed with "install Claude Code first … or run `magpie
|
||||
// claude-code install`". The sign-in downloads it now, as Devin's,
|
||||
// Cursor's and Grok's install their CLIs, and goes on to the sign-in page.
|
||||
func TestClaudeSignInDownloadsClaudeCode(t *testing.T) {
|
||||
claudeHome(t)
|
||||
noAnthropic(t)
|
||||
exe := fakeClaudeLogin(t, fakeClaudeAccount{email: "dl@example.com", plan: "max", refresh: "sk-ant-ort01-dl"}, "", false)
|
||||
var downloaded atomic.Bool
|
||||
claudeExecutable = func() string {
|
||||
if downloaded.Load() {
|
||||
return exe
|
||||
}
|
||||
return ""
|
||||
}
|
||||
downloadClaudeCode = func(context.Context) error {
|
||||
downloaded.Store(true)
|
||||
return nil
|
||||
}
|
||||
|
||||
st, err := StartSignIn("claude")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if st.State != "installing" || st.Installing != "Claude Code" {
|
||||
t.Fatalf("with no Claude Code: %+v", st)
|
||||
}
|
||||
st = waitPast(t, st.ID, "installing")
|
||||
if !downloaded.Load() || !st.PasteCode {
|
||||
t.Fatalf("after the download: %+v", st)
|
||||
}
|
||||
if err := SubmitSignInCallback(st.ID, "the-code#st"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if st = waitDone(t, st.ID); st.State != "done" || st.User != "dl@example.com" {
|
||||
t.Fatalf("state %+v", st)
|
||||
}
|
||||
}
|
||||
|
||||
// a download that fails says so, and the command that does it by hand
|
||||
func TestClaudeSignInDownloadFails(t *testing.T) {
|
||||
claudeHome(t)
|
||||
downloadClaudeCode = func(context.Context) error { return errors.New("downloads.claude.ai: 403 Forbidden") }
|
||||
|
||||
st, err := StartSignIn("claude")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
st = waitPast(t, st.ID, "installing")
|
||||
if st.State != "failed" || !strings.Contains(st.Error, "403 Forbidden") || !strings.Contains(st.Error, "magpie claude-code install") {
|
||||
t.Fatalf("state %+v", st)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user