Documentation
¶
Overview ¶
Package doctor is `weft doctor` (plan B5): it asks a running Studio what it is and how it is wired, and prints one line per check. Every line reads one field of GET /api/meta (Lines is the table) — or, for the runtime check, the two environment variables the doctor's own shell can see (WEFT_ENV, WEFT_STUDIO_URL). The doctor computes nothing Studio does not serve: a second source of truth would drift.
The logic lives here, apart from the command wiring (cmd/weft), so the command stays a thin client of it.
Index ¶
Examples ¶
Constants ¶
const Timeout = 5 * time.Second
Timeout bounds the one request the doctor makes: an unreachable or hung Studio is a clear first line, never a hang.
Variables ¶
var ErrUnhealthy = errors.New("doctor: a check failed")
ErrUnhealthy is Run's error when any check failed: the command exits 1.
var Lines = []Line{ {"studio", []string{"status", "weft_version", "studio_version"}}, {"token", []string{"status", "auth_required"}}, {"db", []string{"db.kind", "db.path", "db.size"}}, {"content", []string{"content.ingest", "content.latest.run_id", "content.latest.mark", "content.latest.note", "content.latest.fix", "content.error"}}, {"runtimes", []string{"runtimes", "capabilities", "env:WEFT_ENV", "env:WEFT_STUDIO_URL"}}, {"panel", []string{"panel_version", "studio_version"}}, {"weft.json", []string{"has_manifest", "manifest_check.source", "manifest_check.agents", "manifest_check.checked", "manifest_check.stale", "manifest_check.error"}}, }
Lines is the doctor's line table, in print order.
Functions ¶
func Run ¶
Run checks the Studio at url (token "" sends none) and prints one line per check to w. getenv reads the doctor's own environment (the runtime check reports WEFT_ENV and WEFT_STUDIO_URL as this shell sees them). It returns ErrUnhealthy when a check failed — Studio not reachable, the token refused, a stale panel bundle — and nil otherwise; warnings (no runtime connected, content stripped, a stale weft.json) do not fail it.
Example ¶
ExampleRun checks a Studio with nothing connected to it: one line per check, each read from its /api/meta. With no runtime connected the runtimes line warns, and its continuation lines name the variables this shell lacks (WEFT_ENV, WEFT_STUDIO_URL).
package main
import (
"context"
"fmt"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"github.com/weftgo/weft/internal/doctor"
"github.com/weftgo/weft/studio"
)
func main() {
dir, _ := os.MkdirTemp("", "doctor")
defer func() { _ = os.RemoveAll(dir) }()
srv := studio.New(studio.Open(filepath.Join(dir, "weft.db")))
defer func() { _ = srv.Close() }()
ts := httptest.NewServer(srv.Handler())
defer ts.Close()
var out strings.Builder
err := doctor.Run(context.Background(), &out, ts.URL, "", func(string) string { return "" })
for _, line := range strings.Split(strings.TrimSpace(out.String()), "\n") {
if f := strings.Fields(line); !strings.HasPrefix(line, " ") {
fmt.Println(f[0], f[1])
} else if strings.Contains(line, "WEFT_ENV is unset") {
fmt.Println(" names WEFT_ENV")
}
}
fmt.Println("err:", err)
}
Output: ok studio ok token ok db ok content warn runtimes names WEFT_ENV ok panel ok weft.json err: <nil>