mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-20 15:06:36 +00:00
fix(openai): accept full heartbeat bootstrap envelopes
This commit is contained in:
1 parent
270eac6973
commit
a0babc93dd
2 files changed
+71
-6
No files matched your search
@@ -166,3 +166,44 @@ func TestNormalizeCodexAutomationBootstrapPreservesOrderAndIsIdempotent(t *testi
|
||||
require.False(t, changedAgain)
|
||||
require.Equal(t, got, again)
|
||||
}
|
||||
|
||||
func TestNormalizeCodexAutomationBootstrapFullHeartbeat(t *testing.T) {
|
||||
const output = `<heartbeat>
|
||||
<automation_id>flutter</automation_id>
|
||||
<current_time_iso>2026-09-09T00:33:34.775Z</current_time_iso>
|
||||
<instructions>
|
||||
Read the reference index and report changes. Preserve A & B and <tags>.
|
||||
</instructions>
|
||||
</heartbeat>`
|
||||
body := codexAutomationBootstrapBody(t, output, "")
|
||||
got, changed := normalizeCodexAutomationBootstrap(body)
|
||||
require.True(t, changed)
|
||||
require.Equal(t, "user", gjson.GetBytes(got, "input.0.role").String())
|
||||
require.Equal(t, output, gjson.GetBytes(got, "input.0.content.0.text").String())
|
||||
again, changedAgain := normalizeCodexAutomationBootstrap(got)
|
||||
require.False(t, changedAgain)
|
||||
require.Equal(t, got, again)
|
||||
|
||||
for _, field := range []string{"automation_id", "current_time_iso", "instructions"} {
|
||||
duplicate := strings.Replace(output, "</heartbeat>", "<"+field+">duplicate</"+field+"></heartbeat>", 1)
|
||||
require.False(t, validCodexAutomationHeartbeat(duplicate), field)
|
||||
}
|
||||
for _, invalid := range []string{
|
||||
strings.Replace(output, "2026-09-09T00:33:34.775Z", "yesterday", 1),
|
||||
strings.Replace(output, "<current_time_iso>2026-09-09T00:33:34.775Z</current_time_iso>", "", 1),
|
||||
strings.Replace(output, "Read the reference index and report changes. Preserve A & B and <tags>.", " ", 1),
|
||||
strings.Replace(output, "<instructions>", `<instructions source="other">`, 1),
|
||||
strings.Replace(output, "<instructions>", "<instructions><nested/>", 1),
|
||||
} {
|
||||
require.False(t, validCodexAutomationHeartbeat(invalid))
|
||||
}
|
||||
for _, guarded := range [][]byte{
|
||||
codexAutomationBootstrapBody(t, output, `,"call_id":"call-1"`),
|
||||
[]byte(strings.Replace(string(body), `"model":"gpt-5"`, `"model":"gpt-5","previous_response_id":"resp-1"`, 1)),
|
||||
[]byte(strings.Replace(string(body), `"namespace":"codex_app"`, `"namespace":"other"`, 1)),
|
||||
} {
|
||||
unchanged, normalized := normalizeCodexAutomationBootstrap(guarded)
|
||||
require.False(t, normalized)
|
||||
require.Equal(t, guarded, unchanged)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user