From 2ce66220551f9d6bcd47c09587ac5d4a5831e17b Mon Sep 17 00:00:00 2001 From: Jon Chery Date: Tue, 4 Aug 2026 01:43:57 +0000 Subject: [PATCH] =?UTF-8?q?test(cmd/orca):=20smoke=20test=20=E2=89=A550%?= =?UTF-8?q?=20toe-hold,=20main=E2=86=92run=20refactor=20(T01.11,=20REQ-057?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactor main() into run() int (main calls os.Exit(run())) so the test can exercise the CLI directly without os.Exit terminating the test process. Add main_test.go with two cases: run() success path (version command → exit 0) and run() error path (job run with missing spec → exit 1, stderr contains "error:"). Low-effort toe-hold per RESEARCH §1.1/§1.4 — do not over-invest in glue-code coverage. Coverage: go test -cover ./cmd/orca → 80.0% (was 0%, target ≥50%). go test -race PASS. ---ci--- project: orca phase: 1 milestone: v0.8 status: execute ---/ci--- --- cmd/orca/main.go | 10 +++++++++- cmd/orca/main_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 cmd/orca/main_test.go diff --git a/cmd/orca/main.go b/cmd/orca/main.go index c82f7e1..fd38c05 100644 --- a/cmd/orca/main.go +++ b/cmd/orca/main.go @@ -8,8 +8,16 @@ import ( ) func main() { + os.Exit(run()) +} + +// run executes the orca CLI and returns the process exit code. It is +// extracted from main so tests can exercise the error path without +// os.Exit terminating the test process. +func run() int { if err := cli.Execute(); err != nil { fmt.Fprintf(os.Stderr, "error: %v\n", err) - os.Exit(1) + return 1 } + return 0 } diff --git a/cmd/orca/main_test.go b/cmd/orca/main_test.go new file mode 100644 index 0000000..7bd84fd --- /dev/null +++ b/cmd/orca/main_test.go @@ -0,0 +1,41 @@ +package main + +import ( + "io" + "os" + "strings" + "testing" +) + +func TestRunSuccess(t *testing.T) { + orig := os.Args + t.Cleanup(func() { os.Args = orig }) + os.Args = []string{"orca", "version"} + if code := run(); code != 0 { + t.Errorf("run() = %d, want 0", code) + } +} + +func TestRunError(t *testing.T) { + origArgs := os.Args + t.Cleanup(func() { os.Args = origArgs }) + os.Args = []string{"orca", "job", "run", "/nonexistent/spec.hcl"} + + r, w, err := os.Pipe() + if err != nil { + t.Fatalf("pipe: %v", err) + } + origStderr := os.Stderr + os.Stderr = w + t.Cleanup(func() { os.Stderr = origStderr }) + + code := run() + w.Close() + out, _ := io.ReadAll(r) + if code != 1 { + t.Errorf("run() = %d, want 1", code) + } + if !strings.Contains(string(out), "error:") { + t.Errorf("stderr missing 'error:' prefix: %s", out) + } +}