opencode: retry one settling session export
A stage's final session write can land just after the step settles. Retry the read-only native export once after 200 ms when its envelope is invalid or names another session, so the stage records session.html instead of dropping evidence.
This commit is contained in:
@@ -73,6 +73,30 @@ func TestExportSessionDecodesRolesPartsAndUnknownTypes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestExportSessionRetriesOneSettlingReadback(t *testing.T) {
|
||||
id := "ses_settle"
|
||||
dir := t.TempDir()
|
||||
count := filepath.Join(dir, "count")
|
||||
valid := `{"info":{"id":"ses_settle"},"messages":[{"info":{"id":"m1","role":"assistant"},"parts":[{"type":"text","text":"ok"}]}]}`
|
||||
script := "#!/bin/sh\n" +
|
||||
"[ \"$1\" = export ] && shift || { [ \"$1\" = session ] && [ \"$2\" = export ] && shift 2 || exit 8; }\n" +
|
||||
"[ \"$1\" = " + id + " ] || exit 9\n" +
|
||||
"if [ ! -f " + count + " ]; then\n" +
|
||||
" echo 1 > " + count + "\n" +
|
||||
" echo '{\"info\":{\"id\":\"wrong\"}}'\n" +
|
||||
" exit 0\n" +
|
||||
"fi\n" +
|
||||
"cat <<'EOF'\n" + valid + "\nEOF\n"
|
||||
bin := writeFixture(t, script)
|
||||
session, err := ExportSession(context.Background(), bin, dir, "v2", id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(session.Messages) != 1 || session.Messages[0].Parts[0].Text != "ok" {
|
||||
t.Fatalf("retried session = %+v", session)
|
||||
}
|
||||
}
|
||||
|
||||
func TestExportSessionRejectsMismatchedOrInvalidID(t *testing.T) {
|
||||
bin := exportFixture(t, "ses_other", `{"info":{"id":"ses_other"},"messages":[{"info":{"role":"assistant"}}]}`)
|
||||
if _, err := ExportSession(context.Background(), bin, t.TempDir(), "v2", "ses_want"); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user