@@ -24,99 +24,6 @@ import (
2424 "github.com/aoagents/agent-orchestrator/backend/internal/storage/sqlite"
2525)
2626
27- // ---- store adapter ----
28- //
29- // MIRROR OF backend/lifecycle_wiring.go's storeAdapter. The integration tests
30- // can't import package main, so the small set of methods that bridge
31- // *sqlite.Store to ports.SessionStore + ports.PRWriter is duplicated here.
32- // Function bodies are line-for-line identical to the production adapter so a
33- // future divergence shows up as a real diff in code review; the obvious
34- // follow-up is to extract the production adapter into a shared internal
35- // package — explicitly out of scope for this PR ("do NOT redesign anything").
36-
37- type storeAdapter struct { * sqlite.Store }
38-
39- var (
40- _ ports.SessionStore = storeAdapter {}
41- _ ports.PRWriter = storeAdapter {}
42- )
43-
44- func (a storeAdapter ) PRFactsForSession (ctx context.Context , id domain.SessionID ) (domain.PRFacts , error ) {
45- rows , err := a .Store .ListPRsBySession (ctx , string (id ))
46- if err != nil {
47- return domain.PRFacts {}, err
48- }
49- if len (rows ) == 0 {
50- return domain.PRFacts {}, nil
51- }
52- pick := rows [0 ]
53- for _ , r := range rows {
54- if r .State == "draft" || r .State == "open" {
55- pick = r
56- break
57- }
58- }
59- facts := domain.PRFacts {
60- URL : pick .URL , Number : int (pick .Number ), Exists : true ,
61- Draft : pick .State == "draft" , Merged : pick .State == "merged" , Closed : pick .State == "closed" ,
62- CI : domain .CIState (pick .CIState ),
63- Review : domain .ReviewDecision (pick .ReviewDecision ),
64- Mergeability : domain .Mergeability (pick .Mergeability ),
65- }
66- comments , err := a .Store .ListPRComments (ctx , pick .URL )
67- if err != nil {
68- return domain.PRFacts {}, err
69- }
70- for _ , c := range comments {
71- if ! c .Resolved {
72- facts .ReviewComments = true
73- break
74- }
75- }
76- return facts , nil
77- }
78-
79- func (a storeAdapter ) WritePR (ctx context.Context , pr ports.PRRow , checks []ports.PRCheckRow , comments []ports.PRComment ) error {
80- row := sqlite.PRRow {
81- URL : pr .URL , SessionID : pr .SessionID , Number : int64 (pr .Number ),
82- State : prState (pr ),
83- ReviewDecision : string (pr .Review ),
84- CIState : string (pr .CI ),
85- Mergeability : string (pr .Mergeability ),
86- UpdatedAt : pr .UpdatedAt ,
87- }
88- checkRows := make ([]sqlite.PRCheckRow , len (checks ))
89- for i , c := range checks {
90- checkRows [i ] = sqlite.PRCheckRow {
91- PRURL : c .PRURL , Name : c .Name , CommitHash : c .CommitHash ,
92- Status : c .Status , URL : c .URL , LogTail : c .LogTail , CreatedAt : c .CreatedAt ,
93- }
94- }
95- commentRows := make ([]sqlite.PRCommentRow , len (comments ))
96- for i , c := range comments {
97- commentRows [i ] = sqlite.PRCommentRow {
98- PRURL : pr .URL , CommentID : c .ID , Author : c .Author , File : c .File ,
99- Line : int64 (c .Line ), Body : c .Body , Resolved : c .Resolved , CreatedAt : c .CreatedAt ,
100- }
101- }
102- return a .Store .WritePRObservation (ctx , row , checkRows , commentRows )
103- }
104-
105- // prState mirrors the production helper of the same name in
106- // backend/lifecycle_wiring.go.
107- func prState (r ports.PRRow ) string {
108- switch {
109- case r .Merged :
110- return "merged"
111- case r .Closed :
112- return "closed"
113- case r .Draft :
114- return "draft"
115- default :
116- return "open"
117- }
118- }
119-
12027// ---- plugin fakes (minimal: only enough to drive SM through real LCM) ----
12128
12229type stubRuntime struct {
@@ -197,7 +104,6 @@ func (n *captureNotifier) drain() []ports.Event {
197104type liveStack struct {
198105 dataDir string
199106 store * sqlite.Store
200- adapter storeAdapter
201107 lcm * lifecycle.Manager
202108 sm * session.Manager
203109 notifier * captureNotifier
@@ -216,24 +122,22 @@ func openLiveStack(t *testing.T, dataDir string) *liveStack {
216122 if err != nil {
217123 t .Fatalf ("open sqlite: %v" , err )
218124 }
219- adapter := storeAdapter {store }
220125 notifier := & captureNotifier {}
221126 messenger := & captureMessenger {}
222- lcm := lifecycle .New (adapter , adapter , notifier , messenger )
127+ lcm := lifecycle .New (store , store , notifier , messenger )
223128
224129 wsRoot := t .TempDir ()
225130 sm := session .New (session.Deps {
226131 Runtime : & stubRuntime {id : "h1" , name : "tmux" },
227132 Agent : stubAgent {},
228133 Workspace : & stubWorkspace {root : wsRoot },
229- Store : adapter ,
134+ Store : store ,
230135 Messenger : messenger ,
231136 Lifecycle : lcm ,
232137 })
233138 st := & liveStack {
234139 dataDir : dataDir ,
235140 store : store ,
236- adapter : adapter ,
237141 lcm : lcm ,
238142 sm : sm ,
239143 notifier : notifier ,
@@ -272,11 +176,10 @@ func seedProject(t *testing.T, store *sqlite.Store, id string) {
272176}
273177
274178func durableLifecycle (store * sqlite.Store , messenger ports.AgentMessenger ) * lifecycle.Manager {
275- adapter := storeAdapter {store }
276179 renderer := notification .NewRenderer (store )
277180 logger := slog .New (slog .NewTextHandler (io .Discard , nil ))
278181 notifier := notification .NewEnqueuer (store , renderer , logger )
279- return lifecycle .New (adapter , adapter , notifier , messenger )
182+ return lifecycle .New (store , store , notifier , messenger )
280183}
281184
282185func durableRecord (project , issue , branch string ) domain.SessionRecord {
@@ -347,7 +250,7 @@ func TestHappyPath_Spawn_PR_Kill(t *testing.T) {
347250 if err := st .lcm .ApplyPRObservation (ctx , sess .ID , ports.PRObservation {
348251 Fetched : true , URL : prURL , Number : 1 ,
349252 CI : domain .CIPassing , Review : domain .ReviewNone , Mergeability : domain .MergeMergeable ,
350- Checks : []ports .PRCheckRow {{
253+ Checks : []domain .PRCheckRow {{
351254 Name : "ci/build" , CommitHash : "abc123" , Status : "passed" , CreatedAt : time .Now (),
352255 }},
353256 }); err != nil {
@@ -357,7 +260,7 @@ func TestHappyPath_Spawn_PR_Kill(t *testing.T) {
357260 if err != nil || ! ok {
358261 t .Fatalf ("get pr: ok=%v err=%v" , ok , err )
359262 }
360- if prRow .SessionID != string (sess .ID ) || prRow .CIState != "passing" || prRow .State != "open" {
263+ if prRow .SessionID != string (sess .ID ) || prRow .CI != domain . CIPassing || prRow .Draft || prRow . Merged || prRow . Closed {
361264 t .Fatalf ("pr row wrong: %+v" , prRow )
362265 }
363266
@@ -491,7 +394,7 @@ func TestCIFailureAndRecovery_NudgeThenClears(t *testing.T) {
491394 if err := st .lcm .ApplyPRObservation (ctx , sess .ID , ports.PRObservation {
492395 Fetched : true , URL : prURL , Number : 2 ,
493396 CI : domain .CIFailing , Mergeability : domain .MergeUnstable ,
494- Checks : []ports .PRCheckRow {{
397+ Checks : []domain .PRCheckRow {{
495398 Name : "ci/build" , CommitHash : "c1" , Status : "failed" , LogTail : "panic: nil map" , CreatedAt : time .Now (),
496399 }},
497400 }); err != nil {
@@ -507,7 +410,7 @@ func TestCIFailureAndRecovery_NudgeThenClears(t *testing.T) {
507410
508411 // Brake confirmation: only one failure so far, RecentCheckStatuses should
509412 // reflect it.
510- history , err := st .adapter .RecentCheckStatuses (ctx , prURL , "ci/build" , 3 )
413+ history , err := st .store .RecentCheckStatuses (ctx , prURL , "ci/build" , 3 )
511414 if err != nil {
512415 t .Fatalf ("recent checks: %v" , err )
513416 }
@@ -521,7 +424,7 @@ func TestCIFailureAndRecovery_NudgeThenClears(t *testing.T) {
521424 if err := st .lcm .ApplyPRObservation (ctx , sess .ID , ports.PRObservation {
522425 Fetched : true , URL : prURL , Number : 2 ,
523426 CI : domain .CIPassing , Mergeability : domain .MergeMergeable ,
524- Checks : []ports .PRCheckRow {{
427+ Checks : []domain .PRCheckRow {{
525428 Name : "ci/build" , CommitHash : "c2" , Status : "passed" , CreatedAt : time .Now (),
526429 }},
527430 }); err != nil {
@@ -537,7 +440,7 @@ func TestCIFailureAndRecovery_NudgeThenClears(t *testing.T) {
537440
538441 // And the pr row reflects the recovery in the canonical fact store.
539442 prRow , ok , _ := st .store .GetPR (ctx , prURL )
540- if ! ok || prRow .CIState != "passing" {
443+ if ! ok || prRow .CI != domain . CIPassing {
541444 t .Fatalf ("pr ci_state should be passing post-recovery: %+v" , prRow )
542445 }
543446}
0 commit comments