@@ -110,3 +110,41 @@ func TestRepository_UseArtifactMarksSingleUse(t *testing.T) {
110110 t .Fatalf ("artifact state = %q, want %q" , artifact .State , core .ArtifactStateUsed )
111111 }
112112}
113+
114+ func TestRepository_ListGrantsBySessionIsBounded (t * testing.T ) {
115+ t .Parallel ()
116+
117+ mock , err := pgxmock .NewPool ()
118+ if err != nil {
119+ t .Fatalf ("pgxmock.NewPool() error = %v" , err )
120+ }
121+ defer mock .Close ()
122+
123+ repo := postgres .NewRepository (mock )
124+ createdAt := time .Date (2026 , 4 , 15 , 18 , 0 , 0 , 0 , time .UTC )
125+ expiresAt := createdAt .Add (30 * time .Minute )
126+
127+ mock .ExpectQuery ("SELECT id, tenant_id, session_id, tool, capability, resource_ref, delivery_mode, connector_kind, approval_id, artifact_ref, state, requested_ttl_seconds, effective_ttl_seconds, expires_at, created_at, reason\\ s+FROM grants\\ s+WHERE session_id = \\ $1\\ s+ORDER BY created_at ASC, id ASC\\ s+LIMIT \\ $2" ).
128+ WithArgs ("sess_abc" , pgxmock .AnyArg ()).
129+ WillReturnRows (pgxmock .NewRows ([]string {
130+ "id" , "tenant_id" , "session_id" , "tool" , "capability" , "resource_ref" , "delivery_mode" , "connector_kind" , "approval_id" , "artifact_ref" , "state" , "requested_ttl_seconds" , "effective_ttl_seconds" , "expires_at" , "created_at" , "reason" ,
131+ }).AddRow (
132+ "gr_123" , "t_acme" , "sess_abc" , "github" , "repo.read" , "repo:evalops/asb" , "direct" , "github" , nil , nil ,
133+ string (core .GrantStateIssued ), int32 (300 ), int32 (300 ), expiresAt , createdAt , "cleanup" ,
134+ ))
135+
136+ grants , err := repo .ListGrantsBySession (context .Background (), "sess_abc" )
137+ if err != nil {
138+ t .Fatalf ("ListGrantsBySession() error = %v" , err )
139+ }
140+ if len (grants ) != 1 {
141+ t .Fatalf ("len(grants) = %d, want 1" , len (grants ))
142+ }
143+ if grants [0 ].ID != "gr_123" {
144+ t .Fatalf ("grant id = %q, want %q" , grants [0 ].ID , "gr_123" )
145+ }
146+
147+ if err := mock .ExpectationsWereMet (); err != nil {
148+ t .Fatalf ("ExpectationsWereMet() error = %v" , err )
149+ }
150+ }
0 commit comments