@@ -61,26 +61,33 @@ func (streamStatusManagedAuthStub) DetermineCaller(_ *http.Request) (*auth.Reque
6161
6262func (streamStatusManagedAuthStub ) Release (_ * auth.RequestAuth ) {}
6363
64- func TestBuildOpenAICurrentInputContextTranscriptUsesInjectedFileWrapper (t * testing.T ) {
64+ func TestBuildOpenAICurrentInputContextTranscriptUsesNumberedHistorySections (t * testing.T ) {
6565 _ , historyMessages := splitOpenAIHistoryMessages (historySplitTestMessages (), 1 )
6666 transcript := buildOpenAICurrentInputContextTranscript (historyMessages )
6767
6868 if strings .Contains (transcript , "[file content end]" ) || strings .Contains (transcript , "[file content begin]" ) || strings .Contains (transcript , "[file name]:" ) {
69- t .Fatalf ("expected plain transcript without file wrapper tags, got %q" , transcript )
70- }
71- if ! strings .Contains (transcript , "<|begin▁of▁sentence|>" ) {
72- t .Fatalf ("expected serialized conversation markers, got %q" , transcript )
73- }
74- if ! strings .Contains (transcript , "first user turn" ) || ! strings .Contains (transcript , "tool result" ) {
75- t .Fatalf ("expected historical turns preserved, got %q" , transcript )
76- }
77- if ! strings .Contains (transcript , "[reasoning_content]" ) || ! strings .Contains (transcript , "hidden reasoning" ) {
78- t .Fatalf ("expected reasoning block preserved, got %q" , transcript )
79- }
80- if ! strings .Contains (transcript , "<|DSML|tool_calls>" ) {
81- t .Fatalf ("expected tool calls preserved, got %q" , transcript )
69+ t .Fatalf ("expected transcript without file wrapper tags, got %q" , transcript )
70+ }
71+ if ! strings .Contains (transcript , "# HISTORY.txt" ) {
72+ t .Fatalf ("expected history transcript header, got %q" , transcript )
73+ }
74+ if ! strings .Contains (transcript , "Prior conversation history and tool progress." ) {
75+ t .Fatalf ("expected history transcript description, got %q" , transcript )
76+ }
77+ for _ , want := range []string {
78+ "=== 1. USER ===" ,
79+ "=== 2. ASSISTANT ===" ,
80+ "=== 3. TOOL ===" ,
81+ "first user turn" ,
82+ "tool result" ,
83+ "[reasoning_content]" ,
84+ "hidden reasoning" ,
85+ "<|DSML|tool_calls>" ,
86+ } {
87+ if ! strings .Contains (transcript , want ) {
88+ t .Fatalf ("expected transcript to contain %q, got %q" , want , transcript )
89+ }
8290 }
83-
8491}
8592
8693func TestSplitOpenAIHistoryMessagesUsesLatestUserTurn (t * testing.T ) {
@@ -243,7 +250,7 @@ func TestApplyCurrentInputFileDisabledPassThrough(t *testing.T) {
243250 }
244251}
245252
246- func TestApplyCurrentInputFileUploadsFirstTurnWithInjectedWrapper (t * testing.T ) {
253+ func TestApplyCurrentInputFileUploadsFirstTurnWithNumberedHistoryTranscript (t * testing.T ) {
247254 ds := & inlineUploadDSStub {}
248255 h := & openAITestSurface {
249256 Store : mockOpenAIConfig {
@@ -273,15 +280,21 @@ func TestApplyCurrentInputFileUploadsFirstTurnWithInjectedWrapper(t *testing.T)
273280 t .Fatalf ("expected 1 current input upload, got %d" , len (ds .uploadCalls ))
274281 }
275282 upload := ds .uploadCalls [0 ]
276- if upload .Filename != "history .txt" {
283+ if upload .Filename != "HISTORY .txt" {
277284 t .Fatalf ("unexpected upload filename: %q" , upload .Filename )
278285 }
279286 uploadedText := string (upload .Data )
280287 if strings .Contains (uploadedText , "[file content end]" ) || strings .Contains (uploadedText , "[file content begin]" ) || strings .Contains (uploadedText , "[file name]:" ) {
281288 t .Fatalf ("expected uploaded transcript without file wrapper tags, got %q" , uploadedText )
282289 }
283- if ! strings .Contains (uploadedText , "<|begin▁of▁sentence|><|User|>first turn content that is long enough" ) {
284- t .Fatalf ("expected serialized current user turn markers, got %q" , uploadedText )
290+ for _ , want := range []string {
291+ "# HISTORY.txt" ,
292+ "=== 1. USER ===" ,
293+ "first turn content that is long enough" ,
294+ } {
295+ if ! strings .Contains (uploadedText , want ) {
296+ t .Fatalf ("expected uploaded transcript to contain %q, got %q" , want , uploadedText )
297+ }
285298 }
286299 if ! strings .Contains (uploadedText , promptcompat .ThinkingInjectionMarker ) {
287300 t .Fatalf ("expected thinking injection in current input file, got %q" , uploadedText )
@@ -290,7 +303,7 @@ func TestApplyCurrentInputFileUploadsFirstTurnWithInjectedWrapper(t *testing.T)
290303 if strings .Contains (out .FinalPrompt , "first turn content that is long enough" ) {
291304 t .Fatalf ("expected current input text to be replaced in live prompt, got %s" , out .FinalPrompt )
292305 }
293- if strings .Contains (out .FinalPrompt , "CURRENT_USER_INPUT.txt" ) || strings .Contains (out .FinalPrompt , "history.txt" ) || strings .Contains (out .FinalPrompt , "Read that file" ) {
306+ if strings .Contains (out .FinalPrompt , "CURRENT_USER_INPUT.txt" ) || strings .Contains (out .FinalPrompt , "history.txt" ) || strings .Contains (out .FinalPrompt , "HISTORY.txt" ) || strings . Contains ( out . FinalPrompt , " Read that file" ) {
294307 t .Fatalf ("expected live prompt not to instruct file reads, got %s" , out .FinalPrompt )
295308 }
296309 if ! strings .Contains (out .FinalPrompt , "Answer the latest user request directly." ) {
@@ -302,6 +315,9 @@ func TestApplyCurrentInputFileUploadsFirstTurnWithInjectedWrapper(t *testing.T)
302315 if ! strings .Contains (out .PromptTokenText , "first turn content that is long enough" ) {
303316 t .Fatalf ("expected prompt token text to preserve original full context, got %q" , out .PromptTokenText )
304317 }
318+ if ! strings .Contains (out .PromptTokenText , "# HISTORY.txt" ) || ! strings .Contains (out .PromptTokenText , "=== 1. USER ===" ) {
319+ t .Fatalf ("expected prompt token text to include numbered history transcript, got %q" , out .PromptTokenText )
320+ }
305321}
306322
307323func TestApplyCurrentInputFilePreservesFullContextPromptForTokenCounting (t * testing.T ) {
@@ -337,7 +353,10 @@ func TestApplyCurrentInputFilePreservesFullContextPromptForTokenCounting(t *test
337353 t .Fatalf ("expected prompt token text to contain file context with full conversation, got %q" , out .PromptTokenText )
338354 }
339355 if strings .Contains (out .PromptTokenText , "[file content end]" ) || strings .Contains (out .PromptTokenText , "[file name]:" ) {
340- t .Fatalf ("expected prompt token text to use raw transcript without wrapper tags, got %q" , out .PromptTokenText )
356+ t .Fatalf ("expected prompt token text to omit file wrapper tags, got %q" , out .PromptTokenText )
357+ }
358+ if ! strings .Contains (out .PromptTokenText , "# HISTORY.txt" ) || ! strings .Contains (out .PromptTokenText , "=== 1. SYSTEM ===" ) {
359+ t .Fatalf ("expected prompt token text to include numbered history transcript, got %q" , out .PromptTokenText )
341360 }
342361 if ! strings .Contains (out .PromptTokenText , "Answer the latest user request directly." ) {
343362 t .Fatalf ("expected prompt token text to also include neutral live prompt, got %q" , out .PromptTokenText )
@@ -378,16 +397,16 @@ func TestApplyCurrentInputFileUploadsFullContextFile(t *testing.T) {
378397 t .Fatalf ("expected one current input upload, got %d" , len (ds .uploadCalls ))
379398 }
380399 upload := ds .uploadCalls [0 ]
381- if upload .Filename != "history .txt" {
382- t .Fatalf ("expected history .txt upload, got %q" , upload .Filename )
400+ if upload .Filename != "HISTORY .txt" {
401+ t .Fatalf ("expected HISTORY .txt upload, got %q" , upload .Filename )
383402 }
384403 uploadedText := string (upload .Data )
385- for _ , want := range []string {"system instructions" , "first user turn" , "hidden reasoning" , "tool result" , "latest user turn" , promptcompat .ThinkingInjectionMarker } {
404+ for _ , want := range []string {"# HISTORY.txt" , "=== 1. SYSTEM ===" , "=== 2. USER ===" , "=== 3. ASSISTANT ===" , "=== 4. TOOL ===" , "=== 5. USER ===" , " system instructions" , "first user turn" , "hidden reasoning" , "tool result" , "latest user turn" , promptcompat .ThinkingInjectionMarker } {
386405 if ! strings .Contains (uploadedText , want ) {
387406 t .Fatalf ("expected full context file to contain %q, got %q" , want , uploadedText )
388407 }
389408 }
390- if strings .Contains (out .FinalPrompt , "first user turn" ) || strings .Contains (out .FinalPrompt , "latest user turn" ) || strings .Contains (out .FinalPrompt , "CURRENT_USER_INPUT.txt" ) || strings .Contains (out .FinalPrompt , "history.txt" ) || strings .Contains (out .FinalPrompt , "Read that file" ) {
409+ if strings .Contains (out .FinalPrompt , "first user turn" ) || strings .Contains (out .FinalPrompt , "latest user turn" ) || strings .Contains (out .FinalPrompt , "CURRENT_USER_INPUT.txt" ) || strings .Contains (out .FinalPrompt , "history.txt" ) || strings .Contains (out .FinalPrompt , "HISTORY.txt" ) || strings . Contains ( out . FinalPrompt , " Read that file" ) {
391410 t .Fatalf ("expected live prompt to use only a neutral continuation instruction, got %s" , out .FinalPrompt )
392411 }
393412 if ! strings .Contains (out .FinalPrompt , "Answer the latest user request directly." ) {
@@ -423,6 +442,9 @@ func TestApplyCurrentInputFileCarriesHistoryText(t *testing.T) {
423442 if out .HistoryText != string (ds .uploadCalls [0 ].Data ) {
424443 t .Fatalf ("expected current input file flow to preserve uploaded text in history, got %q" , out .HistoryText )
425444 }
445+ if ! strings .Contains (out .HistoryText , "# HISTORY.txt" ) || ! strings .Contains (out .HistoryText , "=== 1. SYSTEM ===" ) {
446+ t .Fatalf ("expected history text to use numbered transcript format, got %q" , out .HistoryText )
447+ }
426448}
427449
428450func TestChatCompletionsCurrentInputFileUploadsContextAndKeepsNeutralPrompt (t * testing.T ) {
@@ -454,15 +476,18 @@ func TestChatCompletionsCurrentInputFileUploadsContextAndKeepsNeutralPrompt(t *t
454476 t .Fatalf ("expected 1 upload call, got %d" , len (ds .uploadCalls ))
455477 }
456478 upload := ds .uploadCalls [0 ]
457- if upload .Filename != "history .txt" {
479+ if upload .Filename != "HISTORY .txt" {
458480 t .Fatalf ("unexpected upload filename: %q" , upload .Filename )
459481 }
460482 if upload .Purpose != "assistants" {
461483 t .Fatalf ("unexpected purpose: %q" , upload .Purpose )
462484 }
463485 historyText := string (upload .Data )
464486 if strings .Contains (historyText , "[file content end]" ) || strings .Contains (historyText , "[file content begin]" ) || strings .Contains (historyText , "[file name]:" ) {
465- t .Fatalf ("expected plain history transcript without wrapper tags, got %s" , historyText )
487+ t .Fatalf ("expected history transcript without file wrapper tags, got %s" , historyText )
488+ }
489+ if ! strings .Contains (historyText , "# HISTORY.txt" ) || ! strings .Contains (historyText , "=== 1. SYSTEM ===" ) {
490+ t .Fatalf ("expected history transcript to use numbered sections, got %s" , historyText )
466491 }
467492 if ! strings .Contains (historyText , "latest user turn" ) {
468493 t .Fatalf ("expected full context to include latest turn, got %s" , historyText )
@@ -523,6 +548,10 @@ func TestResponsesCurrentInputFileUploadsContextAndKeepsNeutralPrompt(t *testing
523548 if len (ds .uploadCalls ) != 1 {
524549 t .Fatalf ("expected 1 upload call, got %d" , len (ds .uploadCalls ))
525550 }
551+ historyText := string (ds .uploadCalls [0 ].Data )
552+ if ! strings .Contains (historyText , "# HISTORY.txt" ) || ! strings .Contains (historyText , "=== 1. SYSTEM ===" ) {
553+ t .Fatalf ("expected uploaded history text to use numbered transcript format, got %s" , historyText )
554+ }
526555 if ds .completionReq == nil {
527556 t .Fatal ("expected completion payload to be captured" )
528557 }
@@ -669,6 +698,10 @@ func TestCurrentInputFileWorksAcrossAutoDeleteModes(t *testing.T) {
669698 if len (ds .uploadCalls ) != 1 {
670699 t .Fatalf ("expected current input upload for mode=%s, got %d" , mode , len (ds .uploadCalls ))
671700 }
701+ historyText := string (ds .uploadCalls [0 ].Data )
702+ if ! strings .Contains (historyText , "# HISTORY.txt" ) || ! strings .Contains (historyText , "=== 1. SYSTEM ===" ) {
703+ t .Fatalf ("expected uploaded history text to use numbered transcript format, got %s" , historyText )
704+ }
672705 if ds .completionReq == nil {
673706 t .Fatalf ("expected completion payload for mode=%s" , mode )
674707 }
0 commit comments