turn: keep the body written before a trailing outcome

ParseOutput returned only the text after the outcome value, so a stage that wrote
its result first and "# outcome" last handed the next stage "(no output)" — the
probe's Compose and Critique turns were both lost this way. The body is now the
whole document with just the outcome heading and value line removed, in order,
byte for byte. Tests cover a trailing and a mid-document outcome.
This commit is contained in:
2026-10-19 23:31:06 +01:00
parent ccb97e424b
commit b1482b554b
4 changed files with 37 additions and 15 deletions
+17 -4
View File
@@ -15,10 +15,22 @@ func TestParseOutput(t *testing.T) {
err error
}{
{
name: "leading commentary is ignored and trailing section is body",
name: "text before and after the outcome section is the body",
input: "Checking the work first.\n\n## outcome\nsuccess\n\n# Result\n\nThe work is complete.\n",
outcome: "success",
body: "\n# Result\n\nThe work is complete.\n",
body: "Checking the work first.\n\n\n# Result\n\nThe work is complete.\n",
},
{
name: "a trailing outcome keeps the whole body written before it",
input: "# Composition\n\nAll stages listed.\n\n# outcome\nsuccess\n",
outcome: "success",
body: "# Composition\n\nAll stages listed.\n\n",
},
{
name: "an outcome in the middle keeps both sides in order",
input: "Before.\n\n# outcome\nblocked\n\nAfter.\n",
outcome: "blocked",
body: "Before.\n\n\nAfter.\n",
},
{
name: "diff embedding an outcome line cannot confuse the parser",
@@ -30,13 +42,13 @@ func TestParseOutput(t *testing.T) {
name: "fenced headings before the real outcome are ignored",
input: "```md\n# outcome\nfailed\n```\n\n~~~\n## outcome\nrejected\n~~~\n\n# outcome\nSUCCESS\n\nbody",
outcome: "success",
body: "\nbody",
body: "```md\n# outcome\nfailed\n```\n\n~~~\n## outcome\nrejected\n~~~\n\n\nbody",
},
{
name: "CRLF line endings",
input: "leading\r\n\r\n## outcome\r\n\r\nsuccess\r\n\r\nbody\r\n",
outcome: "success",
body: "\r\nbody\r\n",
body: "leading\r\n\r\n\r\nbody\r\n",
},
{
name: "arbitrary markdown body is preserved exactly",
@@ -53,6 +65,7 @@ func TestParseOutput(t *testing.T) {
name: "duplicate inside a fence is ignored",
input: "```\n# outcome\nsuccess\n```\n\n# outcome\nblocked\n",
outcome: "blocked",
body: "```\n# outcome\nsuccess\n```\n\n",
},
{
name: "unknown outcome word",