diff options
Diffstat (limited to 'internal/hexaicli')
| -rw-r--r-- | internal/hexaicli/editor_integration_test.go | 6 | ||||
| -rw-r--r-- | internal/hexaicli/run_editor_behavior_test.go | 2 | ||||
| -rw-r--r-- | internal/hexaicli/runner.go | 8 | ||||
| -rw-r--r-- | internal/hexaicli/runner_test.go | 6 |
4 files changed, 12 insertions, 10 deletions
diff --git a/internal/hexaicli/editor_integration_test.go b/internal/hexaicli/editor_integration_test.go index 7d53d1f..e5580be 100644 --- a/internal/hexaicli/editor_integration_test.go +++ b/internal/hexaicli/editor_integration_test.go @@ -28,7 +28,9 @@ func TestRun_NoArgs_OpensEditor(t *testing.T) { newClientFromApp = func(_ appconfig.App) (llm.Client, error) { return cliFake{}, nil } t.Cleanup(func() { newClientFromApp = oldNew }) oldRun := editor.RunEditor - editor.RunEditor = func(_ string, path string) error { return os.WriteFile(path, []byte("PROMPT"), 0o600) } + editor.RunEditor = func(_ context.Context, _ string, path string) error { + return os.WriteFile(path, []byte("PROMPT"), 0o600) + } t.Cleanup(func() { editor.RunEditor = oldRun }) t.Setenv("HEXAI_EDITOR", "dummy") @@ -50,7 +52,7 @@ func TestRun_WithArgs_DoesNotOpenEditor(t *testing.T) { // Stub editor and detect if called (should not be) called := false oldRun := editor.RunEditor - editor.RunEditor = func(_ string, _ string) error { called = true; return nil } + editor.RunEditor = func(_ context.Context, _ string, _ string) error { called = true; return nil } t.Cleanup(func() { editor.RunEditor = oldRun }) var stdout, stderr bytes.Buffer if err := Run(context.Background(), []string{"ARG"}, bytes.NewBufferString("SEL"), &stdout, &stderr); err != nil { diff --git a/internal/hexaicli/run_editor_behavior_test.go b/internal/hexaicli/run_editor_behavior_test.go index a934473..99a2f2d 100644 --- a/internal/hexaicli/run_editor_behavior_test.go +++ b/internal/hexaicli/run_editor_behavior_test.go @@ -25,7 +25,7 @@ func TestRun_DoesNotOpenEditorWhenStdinPresent(t *testing.T) { // Guard: make editor invocation fatal if called oldRunEd := editor.RunEditor defer func() { editor.RunEditor = oldRunEd }() - editor.RunEditor = func(_ string, _ string) error { + editor.RunEditor = func(_ context.Context, _ string, _ string) error { t.Fatalf("editor should not be invoked when stdin has content") return nil } diff --git a/internal/hexaicli/runner.go b/internal/hexaicli/runner.go index eaae1cd..3929001 100644 --- a/internal/hexaicli/runner.go +++ b/internal/hexaicli/runner.go @@ -18,7 +18,7 @@ import ( type cliConfigLoader func(context.Context, *log.Logger) appconfig.App -type cliEditorOpener func([]byte) (string, error) +type cliEditorOpener func(context.Context, []byte) (string, error) type cliClientFactory func(appconfig.App) (llm.Client, error) @@ -85,7 +85,7 @@ func (r *Runner) Run(ctx context.Context, args []string, stdin io.Reader, stdout } cfgPath = p } - if err := editor.OpenFile(cfgPath); err != nil { + if err := editor.OpenFile(ctx, cfgPath); err != nil { _, _ = fmt.Fprintf(stderr, logging.AnsiBase+"hexai %s: %v"+logging.AnsiReset+"\n", sub, err) return err } @@ -127,7 +127,7 @@ func (r *Runner) Run(ctx context.Context, args []string, stdin io.Reader, stdout input, rerr := readInput(stdin, args) if rerr != nil && len(args) == 0 { - if prompt, eerr := runner.openEditor(nil); eerr == nil && strings.TrimSpace(prompt) != "" { + if prompt, eerr := runner.openEditor(ctx, nil); eerr == nil && strings.TrimSpace(prompt) != "" { args = []string{prompt} input, rerr = readInput(stdin, args) } @@ -182,5 +182,5 @@ func normalizeRunner(r *Runner) Runner { } func loadConfigFromContext(ctx context.Context, logger *log.Logger) appconfig.App { - return appconfig.LoadWithOptions(logger, appconfig.LoadOptions{ConfigPath: configPathFromContext(ctx)}) + return appconfig.LoadWithOptions(ctx, logger, appconfig.LoadOptions{ConfigPath: configPathFromContext(ctx)}) } diff --git a/internal/hexaicli/runner_test.go b/internal/hexaicli/runner_test.go index 009af54..8b52b89 100644 --- a/internal/hexaicli/runner_test.go +++ b/internal/hexaicli/runner_test.go @@ -40,7 +40,7 @@ func TestRunner_UsesInjectedDependencies(t *testing.T) { PromptConfig: appconfig.PromptConfig{PromptCLIDefaultSystem: "SYS"}, } }, - openEditor: func([]byte) (string, error) { return "PROMPT", nil }, + openEditor: func(context.Context, []byte) (string, error) { return "PROMPT", nil }, newClient: func(appconfig.App) (client llm.Client, err error) { return &fakeClient{name: "fake", model: "m", resp: "OUT"}, nil }, @@ -67,7 +67,7 @@ func TestRunner_ConfigSubcommand_OpensConfigFromContext(t *testing.T) { t.Cleanup(func() { editor.RunEditor = old }) t.Setenv("EDITOR", "true") var gotPath string - editor.RunEditor = func(_, path string) error { + editor.RunEditor = func(_ context.Context, _, path string) error { gotPath = path return nil } @@ -89,7 +89,7 @@ func TestRunner_ConfigSubcommand_UsesXDGWhenNoOverride(t *testing.T) { xdg := t.TempDir() t.Setenv("XDG_CONFIG_HOME", xdg) var gotPath string - editor.RunEditor = func(_, path string) error { + editor.RunEditor = func(_ context.Context, _, path string) error { gotPath = path return nil } |
