Chicring: Settings showed "网关端口" (gateway port), but the row showed
MAGPIE_ADDR's host:port.
What the field takes, from the code: renderPort posts to
/api/settings/port, and setPort (internal/gui/port.go) accepts only a port
from 1024 to 65535 (settings.CheckPort). The gateway listens on that port,
on 127.0.0.1, or on 0.0.0.0 while shared on the LAN. When MAGPIE_ADDR is
set, it is the whole host:port and comes first. The row then shows its
value and is disabled. So the row is the gateway's address, but only its
port is typed here; it isn't a second way to write MAGPIE_ADDR.
The row is renamed in every language: Gateway address / 网关地址 / 閘道位址 /
ゲートウェイのアドレス / Adresse des Zugangspunkts. The new hint says "Only
the port is set here, 1024 to 65535; MAGPIE_ADDR=host:port sets the whole
address instead. Agents magpie connected move with it. Now {url}". With
MAGPIE_ADDR set, the hint says "MAGPIE_ADDR={addr} sets the gateway's whole
address, host:port: unset it to set the port here". The CLI help (cpu,
healthcheck, heap, quota, statusline) and setPort's comment named
"Settings' Gateway port". They now say "the port in Settings' Gateway
address".
Test: gateway-port.test.cjs pins the new name and hints in en and zh. With
MAGPIE_ADDR set, it now also checks that the field shows 127.0.0.1:3426
and that the row's name and aria-label say the address. gui-zh-tw, gui-ja,
gui-de and i18n-keys cover the other languages. Broken by hand: on the old
app.js it is red, "not ok 1 - en expected: 'Gateway address' actual:
'Gateway port'", and zh red against '网关地址'.
What was run. The whole suites ran at dcf7eeae3, which was these two commits
on origin/main 592899467. They were rebased cleanly onto 5c557c793 and
re-checked there.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./... and
GOOS=windows go vet ./...: ok, at both heads.
- GOMODCACHE=... go test -timeout 45m ./... in a sandbox HOME: 63 ok.
internal/agent, internal/gateway and internal/library hit the 45m package
timeout while other sessions' full suites ran (load ~27-40). Their stacks
were in short tests (TestDisconnectStaysThroughSync 21s,
TestSub2APIThinkingOffRefused 0s, TestSkillHow 10s), so nothing hung.
Each passed when run alone:
"ok internal/agent 1127.439s", "ok internal/gateway 1044.808s",
"ok internal/library 1029.999s".
- The whole GUI suite, node --test --test-concurrency=2
internal/gui/tests/*.test.cjs, with playwright 1.62.0:
- BROWSER=chromium: "# tests 5862 # pass 5844 # fail 18".
- BROWSER=webkit: "# tests 5854 # pass 5835 # fail 19".
Every red file was rerun alone on a freshly fetched origin/main
(a3ebed202 / 5c557c793) and is red there too:
- library-row-remove (chromium, 4 of 8 runs on main): filed #3099.
- quota-count-wrap and quota-name-translated (webkit): #2228.
- usage-agents-hide (both engines): #2276.
- usage-fold (chromium): #2163.
- plugin-card-update (webkit, 2 of 4 runs on 5c557c793): #3079.
- s3-sync (webkit): #2448.
- usage-checkin's Qoder tab (webkit): #2549.
- tray-usages and routing-rule-remove: passed alone on both trees.
None of these files touch the provider editor or the gateway address row.
- At 5c557c793 + these commits: decide-endpoint-label, gateway-port,
system-one, remote-magpie, i18n-keys, gui-zh-tw, gui-ja, gui-de and
lan-docker in both engines: "# tests 54 # pass 54 # fail 0".
go test ./internal/gui ./internal/cli: ok.
50 lines
1.4 KiB
Go
50 lines
1.4 KiB
Go
package cli
|
|
|
|
import (
|
|
"bytes"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
)
|
|
|
|
// healthcheck: magpie healthcheck — exits 0 when a magpie gateway answers
|
|
// at its address (MAGPIE_ADDR, else the port in Settings' Gateway address on 127.0.0.1,
|
|
// 3425 unless set), for a container's
|
|
// HEALTHCHECK, which has no curl to ask it with.
|
|
func healthcheck() error {
|
|
c := &http.Client{Timeout: 3 * time.Second}
|
|
res, err := c.Get(gateway.URL() + "/")
|
|
if err != nil {
|
|
return fmt.Errorf("no gateway at %s: %w", gateway.URL(), err)
|
|
}
|
|
defer res.Body.Close()
|
|
b, _ := io.ReadAll(io.LimitReader(res.Body, 4096))
|
|
if res.StatusCode != http.StatusOK || !bytes.Contains(b, []byte(`"magpie"`)) {
|
|
return fmt.Errorf("%s answers %s, not as a magpie gateway", gateway.URL(), res.Status)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// makeDirs creates $HOME and the XDG folders the environment names when
|
|
// they don't exist yet. The Docker image points them all into its volume
|
|
// (/config/home, /config/cache…), and a volume made by an older image has
|
|
// none of them: whatever writes there first must not find its parent
|
|
// missing.
|
|
func makeDirs() {
|
|
for _, k := range []string{"HOME", "XDG_CONFIG_HOME", "XDG_CACHE_HOME", "XDG_DATA_HOME", "XDG_STATE_HOME"} {
|
|
d := os.Getenv(k)
|
|
if d == "" || !filepath.IsAbs(d) {
|
|
continue
|
|
}
|
|
if _, err := os.Stat(d); errors.Is(err, os.ErrNotExist) {
|
|
_ = os.MkdirAll(d, 0o700)
|
|
}
|
|
}
|
|
}
|