fix(ops): make server diagnostics release-safe

This commit is contained in:
User
2026-09-07 01:15:28 +02:00
parent cffa60772e
commit 28db30bd78
10 changed files with 297 additions and 38 deletions
+54
View File
@@ -89,6 +89,38 @@ func TestValidateVolumesRequiresAuthState(t *testing.T) {
}
}
// Catches rejecting a server installation whose durable state is provided by bind mounts.
func TestRunAcceptsServerBindMountPersistence(t *testing.T) {
installation := doctorInstallation(t, "")
installation.Profile = "server"
runner := &doctorRunner{services: healthyServices, rendered: serverRenderedConfig}
report, err := Run(context.Background(), installation, runner)
if err != nil {
t.Fatal(err)
}
if !report.OK {
t.Fatalf("Run() report = %#v, want healthy server bind-mount installation", report)
}
if checkStatus(report, "configuration") != StatusPassed ||
checkStatus(report, "authentication") != StatusPassed ||
checkStatus(report, "workspace-registry") != StatusPassed {
t.Fatalf("Run() report = %#v, want server configuration and dependent checks passed", report)
}
}
func TestValidateVolumesRejectsIncompleteServerBindMountPersistence(t *testing.T) {
withoutPiState := strings.Replace(
serverRenderedConfig,
`{"type": "bind", "source": "/srv/thothii/pi-state", "target": "/home/thoth/.pi"}`,
`{"type": "bind", "source": "/srv/thothii/pi-state", "target": "/tmp/pi-state"}`,
1,
)
if err := ValidateVolumes(withoutPiState); err == nil || !strings.Contains(err.Error(), "pi-state") {
t.Fatalf("ValidateVolumes() error = %v, want missing pi-state persistence", err)
}
}
// Catches Docker availability short-circuiting a host file-permission failure.
func TestRunChecksUnsafeFilesEvenWhenDockerIsUnavailable(t *testing.T) {
installation := doctorInstallation(t, "")
@@ -302,6 +334,7 @@ type doctorRunner struct {
calls []string
dockerUnavailable bool
services string
rendered string
workflowFailure string
registryInvalid bool
}
@@ -320,6 +353,9 @@ func (r *doctorRunner) Run(_ context.Context, args []string, _ io.Reader) (compo
case strings.Contains(call, "config --quiet"):
return compose.Result{}, nil
case strings.Contains(call, "config --format json"):
if r.rendered != "" {
return compose.Result{Stdout: r.rendered}, nil
}
return compose.Result{Stdout: renderedConfig}, nil
case strings.Contains(call, "ps --all --format json"):
if r.services == "" {
@@ -395,6 +431,24 @@ func assertChecklist(t *testing.T, report Report, want []string) {
const renderedConfig = `{"volumes":{"settings":{},"pi-state":{},"workspace-registry":{},"workspace-secrets":{},"sessions":{},"qdrant-data":{},"embedding-models":{},"auth-state":{}},"services":{"core":{"image":"thothii-core:local","environment":{"THT_LLM_URL":"https://llm.example.invalid"}}}}`
const serverRenderedConfig = `{
"volumes": {"catalog-data": {}, "qdrant-data": {}, "embedding-models": {}},
"services": {
"core": {
"image": "thothii-core:server",
"environment": {"THT_LLM_URL": "https://llm.example.invalid"},
"volumes": [
{"type": "bind", "source": "/srv/thothii/data", "target": "/data"},
{"type": "bind", "source": "/srv/thothii/pi-state", "target": "/home/thoth/.pi"},
{"type": "bind", "source": "/srv/thothii/workspace-registry", "target": "/data/workspace-registry"}
]
},
"catalog-db": {"volumes": [{"type": "volume", "source": "catalog-data", "target": "/var/lib/postgresql/data"}]},
"qdrant": {"volumes": [{"type": "volume", "source": "qdrant-data", "target": "/qdrant/storage"}]},
"embedding": {"volumes": [{"type": "volume", "source": "embedding-models", "target": "/root/.ollama"}]}
}
}`
const healthyServices = `[
{"Service":"core","State":"running","Health":"healthy"},
{"Service":"frontend","State":"running","Health":"healthy"},