@@ -68,6 +68,12 @@ describe("RPC authorization scopes", () => {
6868 }
6969 } ) ;
7070
71+ it ( "lets thread readers observe and refresh checkout branches" , ( ) => {
72+ for ( const method of [ WS_METHODS . subscribeVcsBranch , WS_METHODS . vcsRefreshBranch ] ) {
73+ expect ( requiredScopeForRpcMethod ( method ) ) . toBe ( AuthOrchestrationReadScope ) ;
74+ }
75+ } ) ;
76+
7177 it ( "rejects unknown RPC method names" , ( ) => {
7278 for ( const method of [ "server.notRegistered" , "toString" , "constructor" ] ) {
7379 expect ( ( ) => requiredScopeForRpcMethod ( method ) ) . toThrow (
@@ -133,6 +139,61 @@ describe("RPC scope middleware", () => {
133139 ) ;
134140} ) ;
135141
142+ it . effect . each ( [ WS_METHODS . subscribeVcsBranch , WS_METHODS . subscribeVcsStatus ] as const ) (
143+ "enforces read permission on stream %s" ,
144+ ( method ) =>
145+ Effect . gen ( function * ( ) {
146+ const group = WsRpcGroup . omit (
147+ ...[ ...WsRpcGroup . requests . keys ( ) ] . filter (
148+ (
149+ tag ,
150+ ) : tag is Exclude <
151+ keyof typeof RPC_REQUIRED_SCOPES ,
152+ typeof WS_METHODS . subscribeVcsBranch | typeof WS_METHODS . subscribeVcsStatus
153+ > => tag !== WS_METHODS . subscribeVcsBranch && tag !== WS_METHODS . subscribeVcsStatus ,
154+ ) ,
155+ ) ;
156+ let handled = 0 ;
157+ const handlers = Layer . mergeAll (
158+ group . toLayerHandler ( WS_METHODS . subscribeVcsBranch , ( ) =>
159+ Stream . fromEffect (
160+ Effect . sync ( ( ) => {
161+ handled ++ ;
162+ return { refName : "main" } ;
163+ } ) ,
164+ ) ,
165+ ) ,
166+ group . toLayerHandler ( WS_METHODS . subscribeVcsStatus , ( ) =>
167+ Stream . fromEffect (
168+ Effect . sync ( ( ) => {
169+ handled ++ ;
170+ } ) ,
171+ ) . pipe ( Stream . drain ) ,
172+ ) ,
173+ ) ;
174+ const denied = yield * RpcTest . makeClient ( group ) . pipe (
175+ Effect . provide ( Layer . merge ( handlers , RpcAuthorization . layer ( [ ] ) ) ) ,
176+ ) ;
177+ expect (
178+ yield * Stream . runDrain (
179+ method === WS_METHODS . subscribeVcsBranch
180+ ? denied [ method ] ( { cwd : "/repo" } ) . pipe ( Stream . drain )
181+ : denied [ method ] ( { cwd : "/repo" } ) . pipe ( Stream . drain ) ,
182+ ) . pipe ( Effect . flip ) ,
183+ ) . toMatchObject ( { requiredPermission : AuthOrchestrationReadScope } ) ;
184+ expect ( handled ) . toBe ( 0 ) ;
185+ const granted = yield * RpcTest . makeClient ( group ) . pipe (
186+ Effect . provide ( Layer . merge ( handlers , RpcAuthorization . layer ( [ AuthOrchestrationReadScope ] ) ) ) ,
187+ ) ;
188+ yield * Stream . runDrain (
189+ method === WS_METHODS . subscribeVcsBranch
190+ ? granted [ method ] ( { cwd : "/repo" } ) . pipe ( Stream . drain )
191+ : granted [ method ] ( { cwd : "/repo" } ) . pipe ( Stream . drain ) ,
192+ ) ;
193+ expect ( handled ) . toBe ( 1 ) ;
194+ } ) . pipe ( Effect . scoped ) ,
195+ ) ;
196+
136197describe ( "settings mutation authorization" , ( ) => {
137198 const group = WsRpcGroup . omit (
138199 ...[ ...WsRpcGroup . requests . keys ( ) ] . filter (
0 commit comments