MCPcopy Create free account
hub / github.com/codehamr/codehamr / TestRepeatedFailureNudgeSuccessResetsStreak

Function TestRepeatedFailureNudgeSuccessResetsStreak

internal/tui/tui_test.go:1862–1886  ·  view source on GitHub ↗

TestRepeatedFailureNudgeSuccessResetsStreak: a single success in the middle of a run of failures resets the streak, so the nudge never fires.

(t *testing.T)

Source from the content-addressed store, hash-verified

1860 }
1861 if !strings.Contains(last.Content, fmt.Sprintf("last %d tool calls", maxToolFailStreak)) {
1862 t.Fatalf("nudge should name the streak count: %q", last.Content)
1863 }
1864 // Streak resets after firing so it can't double-fire on the next failure.
1865 if final.failStreak != 0 || final.failKey != "" {
1866 t.Fatalf("nudge must reset failKey/failStreak, got key=%q streak=%d", final.failKey, final.failStreak)
1867 }
1868}
1869
1870// recordAndNudge replays Update's toolResultMsg "queue drained" branch: record
1871// the outcome, then consider the failure nudge. Lets the streak tests exercise
1872// the real recordToolOutcome + maybeFailureNudge without a live SSE turn.
1873func (m Model) recordAndNudge(result chmctx.Message) (tea.Model, tea.Cmd) {
1874 m.history = append(m.history, result)
1875 m.recordToolOutcome(result.ToolName, result.Content)
1876 m.maybeFailureNudge()
1877 return m, nil
1878}
1879
1880// TestRepeatedFailureNudgeSuccessResetsStreak: a single success in the middle
1881// of a run of failures resets the streak, so the nudge never fires.
1882func TestRepeatedFailureNudgeSuccessResetsStreak(t *testing.T) {
1883 m := newTestModel(t, func(http.ResponseWriter, *http.Request) {})
1884 m.lastToolKey = tools.BashName + "|make build"
1885 fail := chmctx.Message{Role: chmctx.RoleTool, ToolName: tools.BashName, Content: "x\n(exit: exit status 1)"}
1886 ok := chmctx.Message{Role: chmctx.RoleTool, ToolName: tools.BashName, Content: "all green"}
1887
1888 var mm tea.Model = m
1889 // 4 failures, then one success, then 4 more failures, never 5 in a row.

Callers

nothing calls this directly

Calls 2

newTestModelFunction · 0.85
recordAndNudgeMethod · 0.80

Tested by

no test coverage detected