mirror of
https://github.com/profullstack/agentbbs.git
synced 2026-12-01 01:14:47 +00:00
setup.sh rebuilds the pod image under the same tag (localhost/agentbbs-pod:latest). hasImage compared only the tag, so every existing pod looked current and kept the old image forever: the "Use c0mpute network" launcher (#183) and any Claude Code or Codex updates never reached existing members. Now an idle pod whose image ID differs from the tag's current ID is recreated (home volume kept). Unknown IDs still never trigger a heal. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
55 lines
2 KiB
Go
55 lines
2 KiB
Go
package pods
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
// When no users dir is configured the bind is disabled: both return values are
|
|
// empty and no directory is created.
|
|
func TestPublicHTMLMountDisabled(t *testing.T) {
|
|
m := &Manager{} // usersDir == ""
|
|
host, spec := m.publicHTMLMount("chovy")
|
|
if host != "" || spec != "" {
|
|
t.Fatalf("expected empty host/spec when usersDir unset, got host=%q spec=%q", host, spec)
|
|
}
|
|
}
|
|
|
|
// With a users dir set, the member's public_html is created on the host and the
|
|
// volume spec maps it to /home/dev/public_html in the pod.
|
|
func TestPublicHTMLMountCreatesAndMaps(t *testing.T) {
|
|
users := t.TempDir()
|
|
m := &Manager{usersDir: users}
|
|
|
|
host, spec := m.publicHTMLMount("chovy")
|
|
|
|
wantHost := filepath.Join(users, "chovy", "public_html")
|
|
if host != wantHost {
|
|
t.Fatalf("host = %q, want %q", host, wantHost)
|
|
}
|
|
if want := wantHost + ":/home/dev/public_html"; spec != want {
|
|
t.Fatalf("spec = %q, want %q", spec, want)
|
|
}
|
|
if fi, err := os.Stat(wantHost); err != nil || !fi.IsDir() {
|
|
t.Fatalf("expected %q to be a created directory, err=%v", wantHost, err)
|
|
}
|
|
}
|
|
|
|
func TestSameImage(t *testing.T) {
|
|
cases := []struct {
|
|
gotName, gotID, wantName, wantID string
|
|
want bool
|
|
}{
|
|
{"localhost/agentbbs-pod:latest", "62a86171b60a", "localhost/agentbbs-pod:latest", "dc18f4df01f5", false}, // rebuilt under the same tag
|
|
{"localhost/agentbbs-pod:latest", "dc18f4df01f5", "agentbbs-pod:latest", "sha256:dc18f4df01f5", true},
|
|
{"docker.io/library/ubuntu:24.04", "abc", "localhost/agentbbs-pod:latest", "abc", false}, // different image
|
|
{"localhost/agentbbs-pod:latest", "", "localhost/agentbbs-pod:latest", "dc18", true}, // unknown id: no heal
|
|
{"localhost/agentbbs-pod:latest", "dc18", "localhost/agentbbs-pod:latest", "", true},
|
|
}
|
|
for _, c := range cases {
|
|
if got := sameImage(c.gotName, c.gotID, c.wantName, c.wantID); got != c.want {
|
|
t.Errorf("sameImage(%q,%q,%q,%q) = %v, want %v", c.gotName, c.gotID, c.wantName, c.wantID, got, c.want)
|
|
}
|
|
}
|
|
}
|