library: billion-context's version is read past the warnings bili prints first
readBili ran `bili --version` with stderr and took the output's first word. bili writes its warnings to stderr before the version; with a config key it doesn't know (models, in a sandbox HOME on mote, bili 0.1.213) the output began "2026-11-09T23:44:06.211 [warn] [v=0.1.213] ...", and that timestamp was the card's version. biliVersion takes the first word of the first line that is a version. Run: - go test -tags nogui -run 'TestBili' ./internal/library on mote: ok. - go vet ./internal/library for darwin, GOOS=linux -tags nogui and GOOS=windows: ok. gofmt -l clean. Broken by hand: readBili and the test back on the first word of the output: TestBiliVersionPastItsWarnings red (the timestamp, "[warn]", "command"). Not tried: the card showing it in the GUI (the field is the same string the card already prints).
This commit is contained in:
@@ -212,6 +212,22 @@ func biliOn(status string) bool {
|
||||
}
|
||||
|
||||
// ReadBili says whether bili is installed and which agents have its plugin.
|
||||
// biliVersion is the version in `bili --version`'s output. Its output is
|
||||
// read with stderr, where bili writes warnings first (a config key it
|
||||
// doesn't know: "2026-11-09T23:44:06.211 [warn] [v=0.1.213] ..."), so
|
||||
// the version is the first word of the line that starts with one.
|
||||
func biliVersion(out string) string {
|
||||
for _, l := range strings.Split(out, "\n") {
|
||||
w, _, _ := strings.Cut(strings.TrimSpace(l), " ")
|
||||
if biliVersionRe.MatchString(w) {
|
||||
return w
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
var biliVersionRe = lazyre.New(`^v?\d+\.\d+\.\d+([-+][0-9A-Za-z.+-]*)?$`)
|
||||
|
||||
func ReadBili() *BiliView {
|
||||
return readBili(detected())
|
||||
}
|
||||
@@ -225,7 +241,7 @@ func readBili(agents []*agent.Agent) *BiliView {
|
||||
}
|
||||
} else {
|
||||
if out, err := biliRun(v.Path, 30*time.Second, "--version"); err == nil {
|
||||
v.Version, _, _ = strings.Cut(strings.TrimSpace(out), " ")
|
||||
v.Version = biliVersion(out)
|
||||
}
|
||||
v.Saved = readBiliSaved()
|
||||
out, err := biliRun(v.Path, 30*time.Second, "plugin", "list")
|
||||
|
||||
@@ -541,3 +541,22 @@ func TestBiliZedThroughPrefix(t *testing.T) {
|
||||
t.Fatalf("served %d, ran %v", served, f.runs)
|
||||
}
|
||||
}
|
||||
|
||||
// TestBiliVersionPastItsWarnings: `bili --version` is read with stderr,
|
||||
// and bili 0.1.213 on mote wrote a config warning before the version; the
|
||||
// card said "2026-11-09T23:44:06.211" for the version.
|
||||
func TestBiliVersionPastItsWarnings(t *testing.T) {
|
||||
for out, want := range map[string]string{
|
||||
"0.1.213 (133f3525c)": "0.1.213",
|
||||
"0.1.213 (133f3525c)\n": "0.1.213",
|
||||
"2026-11-09T23:44:06.211 [warn] [v=0.1.213] [acp-config] ignoring unknown top-level config key(s): models\n0.1.213 (133f3525c)\n": "0.1.213",
|
||||
"0.1.214-beta.1": "0.1.214-beta.1",
|
||||
"[warn] something\r\n0.2.0 (abc)\r\n": "0.2.0",
|
||||
"command not found": "",
|
||||
"": "",
|
||||
} {
|
||||
if got := biliVersion(out); got != want {
|
||||
t.Errorf("biliVersion(%q) = %q, want %q", out, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user