| 1 | package runner |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "fmt" |
| 6 | "strings" |
| 7 | "testing" |
| 8 | |
| 9 | "amadan.net/oficina/equipo/internal/equipo/team" |
| 10 | "amadan.net/oficina/equipo/internal/runnerproto" |
| 11 | ) |
| 12 | |
| 13 | func TestTurnPromptOmitsThousandTestBaseline(t *testing.T) { |
| 14 | claim := RunClaim{} |
| 15 | claim.Assignment.StepKey = "review" |
| 16 | claim.Brief.Instructions = "fix the total" |
| 17 | claim.Brief.StandingInstructions = "preserve the contract" |
| 18 | var definition runnerproto.CheckDefinition |
| 19 | for i := 0; i < 1000; i++ { |
| 20 | definition.Baseline.Names = append(definition.Baseline.Names, team.TestIdentity{Package: "amadan.net/long/repository/package", Name: fmt.Sprintf("TestBaseline%04d", i)}) |
| 21 | } |
| 22 | claim.Brief.CheckDefinition = marshal(definition) |
| 23 | repro := runnerproto.Reproduction{ExpectedSymptom: "wrong total", Files: []runnerproto.CheckFile{{Path: "total_test.go", Bytes: []byte("package total\nfunc TestRegression() {}")}}, TestNames: []team.TestIdentity{{Package: "total", Name: "TestRegression"}}} |
| 24 | arts := []team.Artifact{{Role: team.RoleReproduction, Payload: marshal(repro)}, {Role: team.RoleCandidate, Payload: marshal(team.GitCandidate{Commit: strings.Repeat("a", 40)})}} |
| 25 | prompt, err := buildTurnPrompt(claim, arts) |
| 26 | wfMust(t, err) |
| 27 | if strings.Contains(prompt, "TestBaseline") || strings.Contains(prompt, "CheckDefinition") || !strings.Contains(prompt, "package total") || !strings.Contains(prompt, "TestRegression") || !strings.Contains(prompt, strings.Repeat("a", 40)) { |
| 28 | t.Fatal("prompt omitted task inputs or embedded baseline", prompt) |
| 29 | } |
| 30 | raw, err := turnIntentPayload("claude", "sonnet", prompt) |
| 31 | wfMust(t, err) |
| 32 | var payload struct { |
| 33 | Hash string `json:"prompt_sha256"` |
| 34 | Bytes int `json:"prompt_bytes"` |
| 35 | } |
| 36 | wfMust(t, json.Unmarshal(raw, &payload)) |
| 37 | if payload.Hash != team.ContentDigest([]byte(prompt)) || payload.Bytes != len(prompt) || len(raw) > 512 { |
| 38 | t.Fatal("intent embeds prompt or lost hash", string(raw)) |
| 39 | } |
| 40 | claim.Brief.Instructions = strings.Repeat("x", 65536) |
| 41 | if _, err = buildTurnPrompt(claim, arts); err != ErrPromptTooLarge { |
| 42 | t.Fatal("oversized plan prompt returned a different error", err) |
| 43 | } |
| 44 | _, err = turnIntentPayload("claude", "sonnet", strings.Repeat("x", 65536)) |
| 45 | if err != ErrPromptTooLarge { |
| 46 | t.Fatal("oversized prompt reached intent", err) |
| 47 | } |
| 48 | } |
| 49 | |