MCPcopy Index your code
hub / github.com/codehamr/codehamr / newTestModel

Function newTestModel

internal/tui/tui_test.go:30–50  ·  view source on GitHub ↗

newTestModel wires a model against a mock OpenAI SSE server so we can exercise submit → stream → done without the real stack. The server is torn down via t.Cleanup.

(t *testing.T, handler http.HandlerFunc)

Source from the content-addressed store, hash-verified

28// exercise submit → stream → done without the real stack. The server is
29// torn down via t.Cleanup.
30func newTestModel(t *testing.T, handler http.HandlerFunc) Model {
31 t.Helper()
32 srv := httptest.NewServer(handler)
33 t.Cleanup(srv.Close)
34
35 cfg, _, err := config.Bootstrap(t.TempDir())
36 if err != nil {
37 t.Fatal(err)
38 }
39 cfg.ActiveProfile().URL = srv.URL
40 // Persist so the reload-on-slash path reads the mock URL back, not the
41 // seeded localhost default.
42 if err := cfg.Save(); err != nil {
43 t.Fatal(err)
44 }
45 client := llm.New(srv.URL, cfg.ActiveProfile().LLM, "")
46 m := New(cfg, client, t.TempDir(), "test")
47 // give it a size so view() doesn't panic
48 sized, _ := m.Update(tea.WindowSizeMsg{Width: 100, Height: 30})
49 return sized.(Model)
50}
51
52// TestSystemPromptIncludesWorkingDirAndInvestigateRule: the system prompt must
53// (a) tell the model to investigate files itself rather than ask the user to

Calls 6

BootstrapFunction · 0.92
NewFunction · 0.92
ActiveProfileMethod · 0.80
SaveMethod · 0.80
NewFunction · 0.70
UpdateMethod · 0.45

Tested by

no test coverage detected