| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "encoding/json" |
| 6 | "testing" |
| 7 | |
| 8 | "reasonix/internal/evidence" |
| 9 | "reasonix/internal/runtimepolicy" |
| 10 | ) |
| 11 | |
| 12 | // A closed-loop turn is a delivery-floor turn: the floor alone arms the |
| 13 | // readiness pause, so the scope on its own no longer produces one. |
| 14 | func withClosedLoopContext(ctx context.Context) context.Context { |
| 15 | if ctx == nil { |
| 16 | ctx = context.Background() |
| 17 | } |
| 18 | ctx = runtimepolicy.WithContext(ctx, runtimepolicy.Constraints{}) |
| 19 | return WithDeliveryExecutionScope(ctx, DeliveryExecutionScope{ID: "test-closed-loop", TaskText: "closed-loop test"}) |
| 20 | } |
| 21 | |
| 22 | func withNoClosedLoop(ctx context.Context) context.Context { |
| 23 | if ctx == nil { |
| 24 | return context.Background() |
| 25 | } |
| 26 | return ctx |
| 27 | } |
| 28 | |
| 29 | func TestGoalScopeDoesNotRequireRiskDrivenReview(t *testing.T) { |
| 30 | for _, path := range []string{"internal/auth/session.go", "schema/migration.sql", "README.md"} { |
| 31 | ledger := evidence.NewLedger() |
| 32 | ledger.Record(evidence.ReceiptFromToolCall("edit_file", json.RawMessage(`{"path":"`+path+`"}`), true, false)) |
| 33 | a := &Agent{task: taskRuntime{ledger: ledger}, turn: turnRuntime{deliveryScopeActive: true}} |
| 34 | if result := a.ReadinessResult(); !result.Ready || len(result.Missing) != 0 { |
| 35 | t.Fatalf("%s acquired a review gate: %+v", path, result) |
| 36 | } |
| 37 | if len(ledger.Receipts()) != 1 || !ledger.Receipts()[0].Success { |
| 38 | t.Fatal("completion query changed execution evidence") |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 |