Strengthen CLI action preflight and coverage

This commit is contained in:
2026-08-13 00:28:31 +00:00
parent 4d5a1d9709
commit 2d956f7315
6 changed files with 248 additions and 42 deletions

View File

@@ -193,6 +193,66 @@ func TestRunActionReturnsFailureForBatchNotificationFailure(t *testing.T) {
}
}
func TestRunCommandProjectsSuccessAndReportFailure(t *testing.T) {
configPath := actionConfigPath(t)
for _, tt := range []struct {
name string
result *app.BatchResult
wantStatus string
wantError bool
statusLine string
}{
{
name: "Success",
result: &app.BatchResult{Batch: app.BatchMorning, Total: 1, Succeeded: 1, Reports: []app.BatchReportResult{{ReportID: "today", Status: "succeeded", OutputPath: "/reports/today.md"}}},
wantStatus: summaryStatusSucceeded,
statusLine: `report=today status=succeeded output="/reports/today.md"`,
},
{
name: "ReportFailure",
result: &app.BatchResult{Batch: app.BatchMorning, Total: 1, Failed: 1, Reports: []app.BatchReportResult{{ReportID: "today", Status: "failed", Error: "prompt execution failed"}}},
wantStatus: summaryStatusFailed,
wantError: true,
statusLine: `report=today status=failed error="prompt execution failed"`,
},
} {
t.Run(tt.name, func(t *testing.T) {
factoryCalls, applicationCalls := 0, 0
runner := Runner{
Clock: timeutil.FixedClock{Time: time.Date(2026, 5, 29, 8, 0, 0, 0, time.UTC)},
ExecutorFactory: func(PromptExecutorConfig) (promptexec.Executor, error) {
factoryCalls++
return &factoryExecutor{}, nil
},
runBatchDetailed: func(context.Context, app.BatchRequest) (*app.BatchResult, error) {
applicationCalls++
return tt.result, nil
},
}
var stdout, stderr bytes.Buffer
err := runner.Run(context.Background(), []string{"run", "morning", "--config", configPath}, &stdout, &stderr)
if factoryCalls != 1 || applicationCalls != 1 || !strings.Contains(stderr.String(), tt.statusLine) {
t.Fatalf("calls/stderr = %d/%d/%q", factoryCalls, applicationCalls, stderr.String())
}
if tt.wantError {
var batchErr app.BatchError
if !errors.As(err, &batchErr) {
t.Fatalf("Run() error = %v, want BatchError", err)
}
} else if err != nil {
t.Fatalf("Run() error = %v", err)
}
var summary batchSummary
if err := json.Unmarshal(stdout.Bytes(), &summary); err != nil {
t.Fatalf("decode summary: %v", err)
}
if summary.Command != commandRun || summary.Status != tt.wantStatus || (summary.Error != "") != tt.wantError {
t.Fatalf("summary = %#v", summary)
}
})
}
}
func TestInspectCommandIsUnknownAndAbsentFromHelp(t *testing.T) {
var stdout, stderr bytes.Buffer
err := (Runner{}).Run(context.Background(), []string{"inspect", "reports"}, &stdout, &stderr)