feat(setup): build start and verify ThothII

This commit is contained in:
2026-08-15 23:09:10 +02:00
parent 2856964654
commit 47e0b2a385
7 changed files with 719 additions and 31 deletions
+34 -4
View File
@@ -9,6 +9,8 @@ import (
"io"
"os"
"os/exec"
"github.com/aritmolab/thothii/tools/tht/internal/config"
)
// Result is the captured output and process exit code for one Docker invocation.
@@ -18,8 +20,13 @@ type Result struct {
ExitCode int
}
// Runner executes the Docker CLI. It never invokes a shell.
type Runner struct {
// Runner is the shell-free Docker command boundary used by the host CLI.
type Runner interface {
Run(context.Context, []string, io.Reader) (Result, error)
}
// execRunner executes the Docker CLI. It never invokes a shell.
type execRunner struct {
binary string
}
@@ -28,11 +35,11 @@ func NewRunner(binary string) Runner {
if binary == "" {
binary = "docker"
}
return Runner{binary: binary}
return execRunner{binary: binary}
}
// Run invokes Docker with the supplied argument array and optional standard input.
func (r Runner) Run(ctx context.Context, args []string, stdin io.Reader) (Result, error) {
func (r execRunner) Run(ctx context.Context, args []string, stdin io.Reader) (Result, error) {
command := exec.CommandContext(ctx, r.binary, args...)
command.Stdin = stdin
var stdout, stderr bytes.Buffer
@@ -54,3 +61,26 @@ func (r Runner) Run(ctx context.Context, args []string, stdin io.Reader) (Result
}
return result, err
}
// InstallationRunner applies an installation's validated Compose arguments to commands that
// explicitly start with compose. Direct Docker image commands remain host-side.
type InstallationRunner struct {
Installation config.Installation
Runner Runner
}
// SessionInventoryScope supplies the installation's intended visibility to lifecycle callers.
func (r InstallationRunner) SessionInventoryScope() string {
if r.Installation.Profile == "local" {
return "mine"
}
return "all"
}
// Run transforms only Compose invocations. It never performs shell interpolation.
func (r InstallationRunner) Run(ctx context.Context, args []string, stdin io.Reader) (Result, error) {
if len(args) > 0 && args[0] == "compose" {
return r.Runner.Run(ctx, r.Installation.ComposeArgs(args[1:]...), stdin)
}
return r.Runner.Run(ctx, args, stdin)
}
+36
View File
@@ -3,11 +3,14 @@ package compose
import (
"context"
"errors"
"io"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
"github.com/aritmolab/thothii/tools/tht/internal/config"
)
func TestRunnerPassesEachArgumentWithoutShellSplitting(t *testing.T) {
@@ -56,6 +59,39 @@ func TestRunnerReportsMissingDocker(t *testing.T) {
}
}
func TestInstallationRunnerAppliesComposeArgumentsWithoutRewritingHostDockerCommands(t *testing.T) {
t.Parallel()
recorded := &recordingRunner{}
installation := config.Installation{
Path: "/tmp/thothii/deploy/local/thothii-installation.yaml",
Profile: "local",
ProjectDirectory: "/tmp/thothii",
EnvFile: "/tmp/thothii/deploy/local/operator.env",
}
runner := InstallationRunner{Installation: installation, Runner: recorded}
if _, err := runner.Run(context.Background(), []string{"compose", "ps"}, nil); err != nil {
t.Fatal(err)
}
if _, err := runner.Run(context.Background(), []string{"inspect", "core-id"}, nil); err != nil {
t.Fatal(err)
}
if got, want := strings.Join(recorded.calls[0], " "), strings.Join(installation.ComposeArgs("ps"), " "); got != want {
t.Fatalf("Compose call = %q, want %q", got, want)
}
if got, want := strings.Join(recorded.calls[1], " "), "inspect core-id"; got != want {
t.Fatalf("host Docker call = %q, want %q", got, want)
}
}
type recordingRunner struct{ calls [][]string }
func (r *recordingRunner) Run(_ context.Context, args []string, _ io.Reader) (Result, error) {
r.calls = append(r.calls, append([]string(nil), args...))
return Result{}, nil
}
func writeExecutable(t *testing.T, contents string) string {
t.Helper()
path := filepath.Join(t.TempDir(), "fake-docker")