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

Function TestHeadTailBufferKeepsExactHeadAndTail

internal/tools/bash_test.go:86–104  ·  view source on GitHub ↗

TestHeadTailBufferKeepsExactHeadAndTail: once the middle is dropped, the reassembly must carry exactly the first head-cap bytes and the last tail-cap bytes in order, across chunked writes that wrap the ring several times.

(t *testing.T)

Source from the content-addressed store, hash-verified

84// reassembly must carry exactly the first head-cap bytes and the last tail-cap
85// bytes in order, across chunked writes that wrap the ring several times.
86func TestHeadTailBufferKeepsExactHeadAndTail(t *testing.T) {
87 var b headTailBuffer
88 total := bashOutputHead + 5*bashOutputTail
89 // Deterministic byte stream in awkward chunk sizes to exercise ring wraps.
90 buf := make([]byte, 0, total)
91 for i := 0; len(buf) < total; i++ {
92 buf = append(buf, byte('a'+i%26))
93 }
94 for i := 0; i < total; i += 3333 {
95 b.Write(buf[i:min(i+3333, total)])
96 }
97 got := b.String()
98 if !strings.HasPrefix(got, string(buf[:bashOutputHead])) {
99 t.Fatal("head bytes wrong")
100 }
101 if !strings.HasSuffix(got, string(buf[total-bashOutputTail:])) {
102 t.Fatal("tail bytes wrong after ring wraps")
103 }
104}
105
106// TestBashHonorsAlreadyCancelledParent: a pre-cancelled parent (Ctrl+C raced
107// the dispatch) must report "(cancelled)", not "(empty command)" or, worse,

Callers

nothing calls this directly

Calls 2

WriteMethod · 0.95
StringMethod · 0.95

Tested by

no test coverage detected