summaryrefslogtreecommitdiff
path: root/internal/hexaiaction
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-09-07 17:58:32 +0300
committerPaul Buetow <paul@buetow.org>2025-09-07 17:58:32 +0300
commit3246ebcc5246ed357f45ac32234d5cd34922b9f3 (patch)
treec594f2fd2ebc01689574c721f4e85e1065a124c4 /internal/hexaiaction
parent77e41a1018715fa5ac4e6156354710b3b224b4fc (diff)
test+docs: add editor tests; document HEXAI_EDITOR/EDITOR and Custom prompt; seam client in CLI for tests
Diffstat (limited to 'internal/hexaiaction')
-rw-r--r--internal/hexaiaction/custom_action_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/internal/hexaiaction/custom_action_test.go b/internal/hexaiaction/custom_action_test.go
new file mode 100644
index 0000000..451a313
--- /dev/null
+++ b/internal/hexaiaction/custom_action_test.go
@@ -0,0 +1,39 @@
+package hexaiaction
+
+import (
+ "bytes"
+ "context"
+ "testing"
+
+ "codeberg.org/snonux/hexai/internal/appconfig"
+ "codeberg.org/snonux/hexai/internal/editor"
+ "codeberg.org/snonux/hexai/internal/llm"
+ "os"
+)
+
+type llmFake2 struct{}
+func (llmFake2) Chat(_ context.Context, _ []llm.Message, _ ...llm.RequestOption) (string, error) { return "DONE", nil }
+func (llmFake2) Name() string { return "fake" }
+func (llmFake2) DefaultModel() string { return "m" }
+
+func TestActionCustom_UsesEditorPrompt(t *testing.T) {
+ // Seam: choose custom, fake client, and fake editor
+ oldChoose := chooseActionFn
+ oldNew := newClientFromApp
+ chooseActionFn = func() (ActionKind, error) { return ActionCustom, nil }
+ newClientFromApp = func(_ appconfig.App) (llm.Client, error) { return llmFake2{}, nil }
+ t.Cleanup(func(){ chooseActionFn = oldChoose; newClientFromApp = oldNew })
+
+ oldRunEd := editor.RunEditor
+ editor.RunEditor = func(_ string, path string) error {
+ return os.WriteFile(path, []byte("make it done"), 0o600)
+ }
+ t.Cleanup(func(){ editor.RunEditor = oldRunEd })
+ t.Setenv("HEXAI_EDITOR", "dummy")
+
+ in := bytes.NewBufferString("some code")
+ var out bytes.Buffer
+ var errb bytes.Buffer
+ if err := Run(context.Background(), in, &out, &errb); err != nil { t.Fatalf("Run: %v", err) }
+ if out.String() == "" { t.Fatalf("expected output") }
+}