@@ -107,15 +107,127 @@ def __init__(self, *, state_store, github, locks, handlers, workflow, adapters,
107107 self .compat = compat
108108
109109
110+ class _AdapterView :
111+ def __init__ (self , target , allowed : set [str ]):
112+ self ._target = target
113+ self ._allowed = set (allowed )
114+
115+ def __getattr__ (self , name : str ):
116+ if name not in self ._allowed :
117+ raise AttributeError (name )
118+ return getattr (self ._target , name )
119+
120+
110121class FakeRuntimeAdapterServices :
111122 def __init__ (self , runtime : "FakeReviewerBotRuntime" ):
112123 self ._runtime = runtime
113- self .workflow = runtime .workflow
114- self .review = runtime .compat .review
115- self .review_state = runtime .compat .review
116- self .commands = runtime .compat .review
117- self .queue = runtime .compat .review
118- self .automation = runtime .compat .automation
124+ self .github = runtime .github
125+ self .workflow = _AdapterView (
126+ runtime .workflow ,
127+ {
128+ "process_pass_until_expirations" ,
129+ "sync_members_with_queue" ,
130+ "sync_status_labels_for_items" ,
131+ "fetch_members" ,
132+ },
133+ )
134+ self .review_state = _AdapterView (
135+ runtime .compat .review ,
136+ {
137+ "maybe_record_head_observation_repair" ,
138+ "handle_transition_notice" ,
139+ "ensure_review_entry" ,
140+ "set_current_reviewer" ,
141+ "update_reviewer_activity" ,
142+ "mark_review_complete" ,
143+ "is_triage_or_higher" ,
144+ "trigger_mandatory_approver_escalation" ,
145+ "satisfy_mandatory_approver_requirement" ,
146+ "compute_reviewer_response_state" ,
147+ "rebuild_pr_approval_state" ,
148+ },
149+ )
150+ self .commands = _AdapterView (
151+ SimpleNamespace (
152+ handle_pass_command = runtime .compat .review .handle_pass_command ,
153+ handle_pass_until_command = runtime .compat .review .handle_pass_until_command ,
154+ handle_label_command = runtime .compat .review .handle_label_command ,
155+ handle_sync_members_command = runtime .compat .review .handle_sync_members_command ,
156+ handle_queue_command = runtime .compat .review .handle_queue_command ,
157+ handle_commands_command = runtime .compat .review .handle_commands_command ,
158+ handle_claim_command = runtime .compat .review .handle_claim_command ,
159+ handle_release_command = runtime .compat .review .handle_release_command ,
160+ handle_rectify_command = runtime .compat .review .handle_rectify_command ,
161+ handle_assign_command = runtime .compat .review .handle_assign_command ,
162+ handle_assign_from_queue_command = runtime .compat .review .handle_assign_from_queue_command ,
163+ handle_accept_no_fls_changes_command = runtime .compat .automation .handle_accept_no_fls_changes_command ,
164+ get_commands_help = runtime .compat .review .get_commands_help ,
165+ strip_code_blocks = runtime .compat .review .strip_code_blocks ,
166+ parse_command = runtime .compat .review .parse_command ,
167+ ),
168+ {
169+ "handle_pass_command" ,
170+ "handle_pass_until_command" ,
171+ "handle_label_command" ,
172+ "handle_sync_members_command" ,
173+ "handle_queue_command" ,
174+ "handle_commands_command" ,
175+ "handle_claim_command" ,
176+ "handle_release_command" ,
177+ "handle_rectify_command" ,
178+ "handle_assign_command" ,
179+ "handle_assign_from_queue_command" ,
180+ "handle_accept_no_fls_changes_command" ,
181+ "get_commands_help" ,
182+ "strip_code_blocks" ,
183+ "parse_command" ,
184+ },
185+ )
186+ self .queue = _AdapterView (
187+ runtime .compat .review ,
188+ {
189+ "get_next_reviewer" ,
190+ "record_assignment" ,
191+ "reposition_member_as_next" ,
192+ },
193+ )
194+ self .automation = _AdapterView (
195+ runtime .compat .automation ,
196+ {
197+ "run_command" ,
198+ "summarize_output" ,
199+ "list_changed_files" ,
200+ "get_default_branch" ,
201+ "find_open_pr_for_branch_status" ,
202+ "create_pull_request" ,
203+ "fetch_members" ,
204+ "handle_accept_no_fls_changes_command" ,
205+ },
206+ )
207+ self .state_lock = _AdapterView (
208+ runtime .compat .state_lock ,
209+ {
210+ "assert_lock_held" ,
211+ "parse_iso8601_timestamp" ,
212+ "normalize_lock_metadata" ,
213+ "get_state_issue" ,
214+ "clear_lock_metadata" ,
215+ "get_state_issue_snapshot" ,
216+ "conditional_patch_state_issue" ,
217+ "render_state_issue_body" ,
218+ "get_state_issue_html_url" ,
219+ "get_lock_ref_display" ,
220+ "get_lock_ref_snapshot" ,
221+ "build_lock_metadata" ,
222+ "create_lock_commit" ,
223+ "cas_update_lock_ref" ,
224+ "lock_is_currently_valid" ,
225+ "renew_state_issue_lease_lock" ,
226+ "ensure_state_issue_lease_lock_fresh" ,
227+ "acquire_state_issue_lease_lock" ,
228+ "release_state_issue_lease_lock" ,
229+ },
230+ )
119231
120232 def process_pass_until_expirations (self , state : dict ):
121233 return self ._runtime .workflow .process_pass_until_expirations (state )
@@ -278,6 +390,9 @@ def parse_iso8601_timestamp(self, value: Any):
278390 def normalize_lock_metadata (self , lock_meta : dict | None ):
279391 return state_store_module .normalize_lock_metadata (lock_meta )
280392
393+ def assert_lock_held (self , context : str ) -> None :
394+ return state_store_module .assert_lock_held (self ._runtime , context )
395+
281396 def get_state_issue (self ):
282397 return state_store_module .get_state_issue (self ._runtime )
283398
0 commit comments