(t *testing.T)
| 2311 | } |
| 2312 | |
| 2313 | func testTui_ai(t *testing.T) { |
| 2314 | // Setup |
| 2315 | defer testutils.BackupAndRestore(t)() |
| 2316 | defer testutils.BackupAndRestoreEnv("OPENAI_API_KEY")() |
| 2317 | os.Setenv("OPENAI_API_KEY", "") |
| 2318 | tester, _, _ := setupTestTui(t, Online) |
| 2319 | req, err := json.Marshal( |
| 2320 | ai.TestOnlyOverrideAiSuggestionRequest{Query: "myQuery", Suggestions: []string{"result 1", "result 2", "longer result 3"}}, |
| 2321 | ) |
| 2322 | require.NoError(t, err) |
| 2323 | _, err = lib.ApiPost(hctx.MakeContext(), "/api/v1/ai-suggest-override", "application/json", req) |
| 2324 | require.NoError(t, err) |
| 2325 | |
| 2326 | // Test running an AI query |
| 2327 | require.Equal(t, "true", strings.TrimSpace(tester.RunInteractiveShell(t, `hishtory config-get ai-completion`))) |
| 2328 | out := captureTerminalOutputWithComplexCommands(t, tester, []TmuxCommand{ |
| 2329 | {Keys: "hishtory SPACE tquery ENTER"}, |
| 2330 | // ExtraDelay since AI queries are debounced and thus slower |
| 2331 | {Keys: "'?myQuery'", ExtraDelay: 1.0}, |
| 2332 | }) |
| 2333 | out = stripTuiCommandPrefix(t, out) |
| 2334 | testutils.CompareGoldens(t, out, "TestTui-AiQuery") |
| 2335 | |
| 2336 | // Test that when it is disabled, no AI queries are run |
| 2337 | tester.RunInteractiveShell(t, `hishtory config-set ai-completion false`) |
| 2338 | out = captureTerminalOutput(t, tester, []string{ |
| 2339 | "hishtory SPACE tquery ENTER", |
| 2340 | "'?myQuery'", |
| 2341 | }) |
| 2342 | out = stripTuiCommandPrefix(t, out) |
| 2343 | testutils.CompareGoldens(t, out, "TestTui-AiQuery-Disabled") |
| 2344 | } |
| 2345 | |
| 2346 | func testControlR(t *testing.T, tester shellTester, shellName string, onlineStatus OnlineStatus) { |
| 2347 | // Setup |
nothing calls this directly
no test coverage detected