feat(cli): discover ThothII projects and installations

This commit is contained in:
2026-08-15 22:24:15 +02:00
parent 4fc03574e1
commit 66614fe8cf
6 changed files with 583 additions and 6 deletions
+68
View File
@@ -74,6 +74,31 @@ func TestRootCommandIdentity(t *testing.T) {
}
}
func TestBootstrapCommandsDoNotRequireAnInstallationDescriptor(t *testing.T) {
projectRoot := newProjectWithoutInstallation(t)
previousDirectory, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
if err := os.Chdir(filepath.Join(projectRoot, "frontend")); err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if restoreErr := os.Chdir(previousDirectory); restoreErr != nil {
t.Errorf("restore working directory: %v", restoreErr)
}
})
t.Setenv("THOTHII_INSTALLATION", "")
for _, args := range [][]string{nil, {"help"}, {"version"}, {"setup"}} {
var stdout, stderr bytes.Buffer
_ = run(context.Background(), args, &stdout, &stderr)
if output := stdout.String() + stderr.String(); strings.Contains(output, "installation descriptor") {
t.Fatalf("run(%v) required a descriptor: %q", args, output)
}
}
}
// Catches interactive configuration prompts that use retired model-only data instead of the
// provider, model, and reasoning choices supplied by the dedicated Pi Management API.
func TestResolvePiConfigureUsesNumberedClosedChoicesOnlyForTTY(t *testing.T) {
@@ -126,6 +151,35 @@ func TestLogsRejectsFollowAndOtherArguments(t *testing.T) {
}
}
func TestParseArgsMakesInstallationOptionalAndAcceptsOverrideAfterCommand(t *testing.T) {
if installation, command, commandArgs, err := parseArgs([]string{"pi", "status"}); err != nil || installation != "" || command != "pi" || strings.Join(commandArgs, " ") != "status" {
t.Fatalf("implicit parse = %q, %q, %v, %v", installation, command, commandArgs, err)
}
want := "/tmp/thothii-installation.yaml"
installation, command, commandArgs, err := parseArgs([]string{"pi", "update", "--installation", want})
if err != nil {
t.Fatal(err)
}
if installation != want || command != "pi" || strings.Join(commandArgs, " ") != "update" {
t.Fatalf("trailing override parse = %q, %q, %v", installation, command, commandArgs)
}
}
func TestRunPiStatusUsesInstallationEnvironmentWithoutFlag(t *testing.T) {
fixture := newCLIFixture(t, "THT_LLM_URL=https://llm.example.invalid\n")
fixture.setEnvironment(t)
t.Setenv("THOTHII_INSTALLATION", fixture.installationPath)
var stdout, stderr bytes.Buffer
if code := run(context.Background(), []string{"pi", "status"}, &stdout, &stderr); code != 0 {
t.Fatalf("run() exit code = %d, stderr = %s", code, stderr.String())
}
if stdout.String() != "Pi version: 0.80.3\n" {
t.Fatalf("stdout = %q, want image-bundled Pi version", stdout.String())
}
}
func TestUsageDocumentsClosedConfigureUpdateSourcesRestartAndMaintenanceRecovery(t *testing.T) {
if strings.Contains(usage, "--follow") {
t.Fatal("usage still advertises unbounded log following")
@@ -1078,6 +1132,20 @@ type cliFixture struct {
envTemplate string
}
func newProjectWithoutInstallation(t *testing.T) string {
t.Helper()
root := t.TempDir()
for _, directory := range []string{"backend", "frontend", "harness", "tools", "deploy", ".git"} {
if err := os.MkdirAll(filepath.Join(root, directory), 0o755); err != nil {
t.Fatal(err)
}
}
if err := os.WriteFile(filepath.Join(root, "compose.yaml"), []byte("services: {}\n"), 0o600); err != nil {
t.Fatal(err)
}
return root
}
func newCLIFixture(t *testing.T, envTemplate string) cliFixture {
t.Helper()
temporaryRoot, err := filepath.EvalSymlinks(os.TempDir())