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

Function TestCtxPressureTripwire

internal/tui/tui_test.go:761–784  ·  view source on GitHub ↗

TestCtxPressureTripwire: the round_done companion warning fires only when the server-counted prompt reaches 95% of the active window. The char/4 packer undercounts code-heavy history (~1.6x measured on a real run), so the server count is the only signal that the real prompt is about to spill past th

(t *testing.T)

Source from the content-addressed store, hash-verified

759// count is the only signal that the real prompt is about to spill past the
760// window into silent server-side truncation.
761func TestCtxPressureTripwire(t *testing.T) {
762 dir := t.TempDir()
763 OpenDebugLog(dir)
764 t.Cleanup(CloseDebugLog)
765 m := newTestModel(t, func(http.ResponseWriter, *http.Request) {})
766 m.liveContextSize[m.cfg.Active] = 10000
767
768 m.applyDone(llm.Event{PromptTokens: 9499}) // below threshold: silent
769 m.applyDone(llm.Event{}) // server reported nothing: silent
770 m.applyDone(llm.Event{PromptTokens: 9500}) // 95%: fire
771 CloseDebugLog()
772
773 raw, err := os.ReadFile(filepath.Join(dir, "log.txt"))
774 if err != nil {
775 t.Fatal(err)
776 }
777 logStr := string(raw)
778 if got := strings.Count(logStr, "] ctx_pressure"); got != 1 {
779 t.Fatalf("tripwire must fire exactly once (at >=95%% of the window), got %d\n%s", got, logStr)
780 }
781 if !strings.Contains(logStr, "prompt_tokens=9500 at >=95% of ctx=10000") {
782 t.Fatalf("tripwire record must name the offending count and window:\n%s", logStr)
783 }
784}
785
786// TestSlashModelSwitchDropsStickyFallbackState: llm.Client's noReasoningEffort
787// flag ("this server 400'd on tools+reasoning_effort, stop sending it") is

Callers

nothing calls this directly

Calls 4

OpenDebugLogFunction · 0.85
newTestModelFunction · 0.85
CloseDebugLogFunction · 0.85
applyDoneMethod · 0.80

Tested by

no test coverage detected