diff --git a/cmd/audita/main_integration_test.go b/cmd/audita/main_integration_test.go index d87b81e..bd54871 100644 --- a/cmd/audita/main_integration_test.go +++ b/cmd/audita/main_integration_test.go @@ -7,6 +7,7 @@ import ( "encoding/json" "errors" "fmt" + "gitea.maximumdirect.net/eric/audita/v4/internal/testsupport/promptfixture" "io" "io/fs" "net/http" @@ -277,7 +278,7 @@ func newProcessFixture(t *testing.T, mode, modules string) processFixture { if err != nil { t.Fatal(err) } - data = append(data, []byte(" repair_attempts: 0\n")...) + data = promptfixture.WithRepairAttempts(t, data, 0) if err := os.WriteFile(filepath.Join(promptDir, filepath.Base(meta.EmbeddedPath)), data, 0600); err != nil { t.Fatal(err) } diff --git a/docs/roadmap/remediation.md b/docs/roadmap/remediation.md index 19eadcd..79af2a6 100644 --- a/docs/roadmap/remediation.md +++ b/docs/roadmap/remediation.md @@ -1,7 +1,7 @@ # Library Adoption Remediation **Status:** Findings from the implementation, integration, and algorithm -reviews; remediation has not begun. +reviews; remediation is in progress. **Reviewed source:** `338e93a7ebda9a86593069d63f9d5a7fe23ccaf5` (`Complete library adoption validation and cleanup`). @@ -21,6 +21,9 @@ ordering defect. R1–R3 remain outstanding. ## R1: Remove the Test Fixtures' Implicit YAML Layout Requirement +**Complete.** Shared structural YAML fixture editing replaces all three text +injections; focused layout/contract regressions and affected package tests pass. + **Priority:** P2 — test maintainability and unintended constraint. **Affected code:** diff --git a/internal/framework/llm/adapter_test.go b/internal/framework/llm/adapter_test.go index 9b32b87..4fc4707 100644 --- a/internal/framework/llm/adapter_test.go +++ b/internal/framework/llm/adapter_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "gitea.maximumdirect.net/eric/audita/v4/internal/testsupport/promptfixture" "io" "io/fs" "net/http" @@ -99,7 +100,7 @@ func adapterFixtureWithPrompt(t *testing.T, replies []reply, retries, repairs in if err != nil { t.Fatal(err) } - data = append(data, []byte(fmt.Sprintf(" repair_attempts: %d\n", repairs))...) + data = promptfixture.WithRepairAttempts(t, data, repairs) if err := os.WriteFile(filepath.Join(promptDir, filepath.Base(meta.EmbeddedPath)), data, 0600); err != nil { t.Fatal(err) } diff --git a/internal/framework/llm/native_adapter_test.go b/internal/framework/llm/native_adapter_test.go index 3f32384..ac2ecfd 100644 --- a/internal/framework/llm/native_adapter_test.go +++ b/internal/framework/llm/native_adapter_test.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "gitea.maximumdirect.net/eric/audita/v4/internal/testsupport/promptfixture" "io" "io/fs" "net/http" @@ -95,7 +96,7 @@ func TestRoleClientExecutionBudgetsAndFailureClasses(t *testing.T) { if err != nil { t.Fatal(err) } - prompt = append(prompt, []byte(fmt.Sprintf(" repair_attempts: %d\n", tc.repair))...) + prompt = promptfixture.WithRepairAttempts(t, prompt, tc.repair) promptDir := filepath.Join(dir, "prompts") if err := os.MkdirAll(promptDir, 0700); err != nil { t.Fatal(err) diff --git a/internal/testsupport/promptfixture/budget.go b/internal/testsupport/promptfixture/budget.go new file mode 100644 index 0000000..669e14b --- /dev/null +++ b/internal/testsupport/promptfixture/budget.go @@ -0,0 +1,35 @@ +// Package promptfixture adapts complete prompt documents for controlled tests. +package promptfixture + +import ( + "go.yaml.in/yaml/v4" + "testing" +) + +// WithRepairAttempts changes prompt-owned budgets without depending on YAML layout. +func WithRepairAttempts(t testing.TB, data []byte, attempts int) []byte { + t.Helper() + var document map[string]any + if err := yaml.Unmarshal(data, &document); err != nil { + t.Fatal(err) + } + var update func(map[string]any) + update = func(scope map[string]any) { + records, _ := scope["prompts"].([]any) + for _, record := range records { + prompt := record.(map[string]any) + output := prompt["output"].(map[string]any) + output["repair_attempts"] = attempts + } + collections, _ := scope["collections"].(map[string]any) + for _, collection := range collections { + update(collection.(map[string]any)) + } + } + update(document) + result, err := yaml.Marshal(document) + if err != nil { + t.Fatal(err) + } + return result +} diff --git a/internal/testsupport/promptfixture/budget_test.go b/internal/testsupport/promptfixture/budget_test.go new file mode 100644 index 0000000..45aa1b6 --- /dev/null +++ b/internal/testsupport/promptfixture/budget_test.go @@ -0,0 +1,42 @@ +package promptfixture + +import ( + "go.yaml.in/yaml/v4" + "testing" +) + +func TestBudgetIgnoresLayoutAndPreservesContract(t *testing.T) { + for _, input := range []string{ + `prompts: [{output: {format: json, repair_attempts: 9}, id: test, messages: [{role: user, content: hello}]}]`, + "collections:\n test:\n prompts:\n - output:\n format: json\n messages: [{role: user, content: hello}]\n id: test\n", + } { + result := WithRepairAttempts(t, []byte(input), 2) + var doc struct { + Prompts []struct { + Output struct { + Format string + RepairAttempts int `yaml:"repair_attempts"` + } + Messages []struct{ Content string } + } + Collections map[string]struct { + Prompts []struct { + Output struct { + RepairAttempts int `yaml:"repair_attempts"` + } + } + } + } + if err := yaml.Unmarshal(result, &doc); err != nil { + t.Fatal(err) + } + if len(doc.Prompts) > 0 { + p := doc.Prompts[0] + if p.Output.RepairAttempts != 2 || p.Output.Format != "json" || p.Messages[0].Content != "hello" { + t.Fatalf("lost contract: %s", result) + } + } else if doc.Collections["test"].Prompts[0].Output.RepairAttempts != 2 { + t.Fatalf("budget: %s", result) + } + } +}