Finalize profile comparison implementation
This commit is contained in:
@@ -137,23 +137,25 @@ func TestComparisonInputFailuresDoNotConstructOrExecute(t *testing.T) {
|
||||
return nil, nil
|
||||
},
|
||||
}
|
||||
if _, err := runner.executeComparison(context.Background(), test.args); err == nil {
|
||||
t.Fatal("executeComparison() error = nil")
|
||||
var stdout, stderr bytes.Buffer
|
||||
if err := runner.Run(context.Background(), append([]string{"compare"}, test.args...), &stdout, &stderr); err == nil {
|
||||
t.Fatal("Run() error = nil")
|
||||
}
|
||||
if factoryCalls != 0 || applicationCalls != 0 {
|
||||
t.Fatalf("factory/application calls = %d/%d", factoryCalls, applicationCalls)
|
||||
if factoryCalls != 0 || applicationCalls != 0 || stdout.Len() != 0 || stderr.Len() != 0 {
|
||||
t.Fatalf("factory/application calls/output = %d/%d/%q/%q", factoryCalls, applicationCalls, stdout.String(), stderr.String())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecuteComparisonUsesOneExecutorAndInjectedApplication(t *testing.T) {
|
||||
func TestCompareCommandUsesOneExecutorAndInjectedApplication(t *testing.T) {
|
||||
workingDir := t.TempDir()
|
||||
configPath := comparisonConfigPath(t, "weather_api:\n base_url: https://weather.api.example.com/\n")
|
||||
executor := &factoryExecutor{}
|
||||
factoryCalls, applicationCalls := 0, 0
|
||||
var received app.ComparisonRequest
|
||||
wantResult := &app.ComparisonResult{ComparisonID: "comparison_test"}
|
||||
comparisonErr := errors.New("comparison completed with 1 failed profiles")
|
||||
runner := Runner{
|
||||
Clock: timeutil.FixedClock{Time: time.Date(2026, 5, 29, 8, 30, 0, 0, time.UTC)}, WorkingDir: workingDir,
|
||||
ExecutorFactory: func(PromptExecutorConfig) (promptexec.Executor, error) {
|
||||
@@ -163,14 +165,15 @@ func TestExecuteComparisonUsesOneExecutorAndInjectedApplication(t *testing.T) {
|
||||
compareDetailed: func(_ context.Context, req app.ComparisonRequest) (*app.ComparisonResult, error) {
|
||||
applicationCalls++
|
||||
received = req
|
||||
return wantResult, errors.New("comparison completed with 1 failed profiles")
|
||||
return wantResult, comparisonErr
|
||||
},
|
||||
}
|
||||
result, err := runner.executeComparison(context.Background(), []string{
|
||||
"daily", "--date", "2026-05-29", "--profile", "weather-light", "--profile", "weather-deep", "--out-dir", "comparison", "--replace", "--config", configPath,
|
||||
})
|
||||
if result != wantResult || err == nil || factoryCalls != 1 || applicationCalls != 1 || received.Executor != executor || received.OutputDir != filepath.Join(workingDir, "comparison") || !received.Replace {
|
||||
t.Fatalf("result/error/calls/request = %#v/%v/%d/%d/%#v", result, err, factoryCalls, applicationCalls, received)
|
||||
var stdout, stderr bytes.Buffer
|
||||
err := runner.Run(context.Background(), []string{
|
||||
"compare", "daily", "--date", "2026-05-29", "--profile", "weather-light", "--profile", "weather-deep", "--out-dir", "comparison", "--replace", "--config", configPath,
|
||||
}, &stdout, &stderr)
|
||||
if !errors.Is(err, comparisonErr) || factoryCalls != 1 || applicationCalls != 1 || received.Executor != executor || received.OutputDir != filepath.Join(workingDir, "comparison") || !received.Replace || stdout.Len() == 0 || stderr.Len() != 0 {
|
||||
t.Fatalf("error/calls/request/output = %v/%d/%d/%#v/%q/%q", err, factoryCalls, applicationCalls, received, stdout.String(), stderr.String())
|
||||
}
|
||||
if !reflect.DeepEqual(received.ProfileIDs, []string{"weather-light", "weather-deep"}) {
|
||||
t.Fatalf("profile IDs = %#v", received.ProfileIDs)
|
||||
@@ -320,6 +323,13 @@ func TestCompareHelpIncludesCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCompareHelpDoesNotRequireConfiguration(t *testing.T) {
|
||||
var stdout, stderr bytes.Buffer
|
||||
if err := (Runner{}).Run(context.Background(), []string{"compare", "--help"}, &stdout, &stderr); err != nil || !strings.Contains(stdout.String(), "weatherreporter compare REPORT") || stderr.Len() != 0 {
|
||||
t.Fatalf("help/error/stderr = %q/%v/%q", stdout.String(), err, stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
func comparisonRunner(t *testing.T, workingDir string) Runner {
|
||||
t.Helper()
|
||||
return Runner{
|
||||
|
||||
Reference in New Issue
Block a user