@@ -108,6 +108,31 @@ def _make_fixture(base: str) -> str:
108108 return ws_path
109109
110110
111+ def _add_invalid_workspace_and_mrc_rows (ws_path : str ) -> None :
112+ """Add an invalid workspace entry and MRC rows for two composers (alias-path trigger)."""
113+ invalid_dir = os .path .join (ws_path , "invalid-ws" )
114+ os .makedirs (invalid_dir , exist_ok = True )
115+ wj = os .path .join (invalid_dir , "workspace.json" )
116+ with open (wj , "w" , encoding = "utf-8" ) as f :
117+ json .dump ({}, f )
118+
119+ global_db = os .path .join (os .path .dirname (ws_path ), "globalStorage" , "state.vscdb" )
120+ conn = sqlite3 .connect (global_db )
121+ for cid , ctx_id in (
122+ (COMPOSER_ID , "ctx-summary" ),
123+ (OTHER_COMPOSER_ID , "ctx-other" ),
124+ ):
125+ conn .execute (
126+ "INSERT INTO cursorDiskKV ([key], value) VALUES (?, ?)" ,
127+ (
128+ f"messageRequestContext:{ cid } :{ ctx_id } " ,
129+ json .dumps ({"projectLayouts" : [f"/roots/{ cid } " ]}),
130+ ),
131+ )
132+ conn .commit ()
133+ conn .close ()
134+
135+
111136def _collect_queries (ws_path , fn ):
112137 """Call fn(ws_path) while recording every SQL query; return (result, queries)."""
113138 import services .workspace_tabs as _ws_tabs_mod
@@ -203,6 +228,25 @@ def test_scoped_bubble_query_only(self):
203228 msg = f"assemble_single_tab ran a non-scoped bubble scan:\n { global_bubble_scans } " ,
204229 )
205230
231+ def test_scoped_mrc_load_with_invalid_workspaces (self ):
232+ """With invalid workspace folders, alias scan runs but MRC stays per-composer."""
233+ _add_invalid_workspace_and_mrc_rows (self .ws_path )
234+ (_ , _ ), queries = _collect_queries (
235+ self .ws_path ,
236+ lambda p : assemble_single_tab ("global" , COMPOSER_ID , p , rules = []),
237+ )
238+ self .assertTrue (queries , msg = "expected SQL queries to be recorded" )
239+ mrc_scans = [
240+ q for q in queries
241+ if "messageRequestContext:%" in q
242+ and f"messageRequestContext:{ COMPOSER_ID } :%" not in q
243+ ]
244+ self .assertEqual (
245+ mrc_scans ,
246+ [],
247+ msg = f"assemble_single_tab ran a global MRC scan:\n { mrc_scans } " ,
248+ )
249+
206250 def test_scoped_mrc_load_no_invalid_workspaces (self ):
207251 """Without invalid workspace folders, per-tab load must not full-scan MRC or composers."""
208252 (_ , _ ), queries = _collect_queries (
0 commit comments