feat(cli): add version diagnostics and build-aware start
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/aritmolab/thothii/tools/tht/internal/compose"
|
||||
"github.com/aritmolab/thothii/tools/tht/internal/config"
|
||||
)
|
||||
|
||||
// Catches --build being ignored, which would run stale images after a checkout update.
|
||||
func TestStartBuildsBeforeStartingAndCheckingHealth(t *testing.T) {
|
||||
runner := &recordingRunner{}
|
||||
installation := testInstallation()
|
||||
|
||||
if err := Start(context.Background(), installation, runner, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, want := strings.Join(runner.stages, " -> "), "build -> up -> health"; got != want {
|
||||
t.Fatalf("Start(..., build=true) stages = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
// Catches a normal start unnecessarily rebuilding images.
|
||||
func TestStartSkipsBuildUnlessRequested(t *testing.T) {
|
||||
runner := &recordingRunner{}
|
||||
installation := testInstallation()
|
||||
|
||||
if err := Start(context.Background(), installation, runner, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, want := strings.Join(runner.stages, " -> "), "up -> health"; got != want {
|
||||
t.Fatalf("Start(..., build=false) stages = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
type recordingRunner struct{ stages []string }
|
||||
|
||||
func (r *recordingRunner) Run(_ context.Context, args []string, _ io.Reader) (compose.Result, error) {
|
||||
joined := strings.Join(args, " ")
|
||||
switch {
|
||||
case strings.HasSuffix(joined, " build"):
|
||||
r.stages = append(r.stages, "build")
|
||||
case strings.HasSuffix(joined, " up --detach --remove-orphans"):
|
||||
r.stages = append(r.stages, "up")
|
||||
case strings.HasSuffix(joined, " ps --all --format json"):
|
||||
r.stages = append(r.stages, "health")
|
||||
return compose.Result{Stdout: healthyServices}, nil
|
||||
}
|
||||
return compose.Result{}, nil
|
||||
}
|
||||
|
||||
func testInstallation() config.Installation {
|
||||
return config.Installation{
|
||||
Path: "/tmp/thothii/deploy/local/thothii-installation.yaml",
|
||||
Profile: "local",
|
||||
ProjectDirectory: "/tmp/thothii",
|
||||
EnvFile: "/tmp/thothii/deploy/local/operator.env",
|
||||
}
|
||||
}
|
||||
|
||||
const healthyServices = `[
|
||||
{"Service":"core","State":"running","Health":"healthy"},
|
||||
{"Service":"frontend","State":"running","Health":"healthy"},
|
||||
{"Service":"qdrant","State":"running","Health":"healthy"},
|
||||
{"Service":"embedding","State":"running","Health":"healthy"},
|
||||
{"Service":"embedding-model-init","State":"exited","ExitCode":0}
|
||||
]`
|
||||
Reference in New Issue
Block a user