@@ -32,14 +32,26 @@ def _isolated_session_context_cache(tmp_path: Path, monkeypatch: pytest.MonkeyPa
3232
3333
3434@pytest .fixture (autouse = True )
35- def _no_local_skills ( monkeypatch : pytest .MonkeyPatch ) -> None :
36- """Keep the skills sweep away from the developer's real ~/.claude/skills .
35+ def _isolated_home ( tmp_path : Path , monkeypatch : pytest .MonkeyPatch ) -> Path :
36+ """Point every home-relative lookup at a scratch directory .
3737
38- Unlike the MCP collectors, which these tests stub per IDE, the skills sweep walks the
39- filesystem directly - so without this every assertion would depend on whoever ran it.
40- A test that cares about skills overrides ``collect_all_skills`` itself.
38+ The skills sweep walks the filesystem rather than going through a collector these tests
39+ stub, so without this it would read the real ~/.claude/skills of whoever ran it.
4140 """
42- monkeypatch .setattr (_session_start_mod , 'collect_all_skills' , list )
41+ home = tmp_path / 'home'
42+ home .mkdir ()
43+ monkeypatch .setattr (Path , 'home' , lambda : home )
44+
45+ return home
46+
47+
48+ def _write_claude_skill (home : Path , name : str , content : str ) -> Path :
49+ """Create a user-scope Claude Code skill under the isolated home and return its path."""
50+ skill_file = home / '.claude' / 'skills' / name / 'SKILL.md'
51+ skill_file .parent .mkdir (parents = True , exist_ok = True )
52+ skill_file .write_text (content , encoding = 'utf-8' )
53+
54+ return skill_file
4355
4456
4557# Auth tests
@@ -620,16 +632,16 @@ def test_reports_skill_files(
620632 mock_collect : MagicMock ,
621633 mock_load_config : MagicMock ,
622634 mock_ctx : MagicMock ,
623- monkeypatch : pytest . MonkeyPatch ,
635+ _isolated_home : Path ,
624636) -> None :
625637 """User-scope skills ride alongside the MCP inventory in the same report."""
626638 mock_get_auth .return_value = MagicMock (tenant_id = 'tenant-1' )
627639 mock_ai_client = MagicMock ()
628640 mock_get_client .return_value = mock_ai_client
629641 mock_collect .return_value = ({}, {})
630- skill_path = '/home/u/.claude/skills/ dummy-skill/SKILL.md '
631- skills = [{ 'path' : skill_path , 'content' : '--- \n name: dummy-skill\n --- \n Body. \n ' }]
632- monkeypatch . setattr ( _session_start_mod , 'collect_all_skills' , lambda : skills )
642+ content = '--- \n name: dummy-skill\n --- \n Body. \n '
643+ skill_file = _write_claude_skill ( _isolated_home , 'dummy-skill' , content )
644+ skills = [{ 'path' : str ( skill_file ), 'content' : content }]
633645
634646 payload = {'session_id' : 'session-123' }
635647
@@ -659,17 +671,16 @@ def test_editing_a_skill_re_reports(
659671 mock_collect : MagicMock ,
660672 mock_load_config : MagicMock ,
661673 mock_ctx : MagicMock ,
662- monkeypatch : pytest . MonkeyPatch ,
674+ _isolated_home : Path ,
663675) -> None :
664676 """Skill bodies are part of the dedup digest, so an edit sends a fresh report."""
665677 mock_get_auth .return_value = MagicMock (tenant_id = 'tenant-1' )
666678 mock_ai_client = MagicMock ()
667679 mock_get_client .return_value = mock_ai_client
668680 mock_collect .return_value = ({}, {})
669- path = '/home/u/.claude/skills/dummy-skill/SKILL.md'
670681 payload = json .dumps ({'session_id' : 'session-123' })
671682
672- monkeypatch . setattr ( _session_start_mod , 'collect_all_skills ' , lambda : [{ 'path' : path , 'content' : ' first'}] )
683+ _write_claude_skill ( _isolated_home , 'dummy-skill ' , ' first' )
673684 with patch ('sys.stdin' , new = StringIO (payload )):
674685 session_start_command (mock_ctx , ide = 'claude-code' )
675686
@@ -678,7 +689,7 @@ def test_editing_a_skill_re_reports(
678689 session_start_command (mock_ctx , ide = 'claude-code' )
679690 assert mock_ai_client .report_session_context .call_count == 1
680691
681- monkeypatch . setattr ( _session_start_mod , 'collect_all_skills ' , lambda : [{ 'path' : path , 'content' : ' edited'}] )
692+ _write_claude_skill ( _isolated_home , 'dummy-skill ' , ' edited' )
682693 with patch ('sys.stdin' , new = StringIO (payload )):
683694 session_start_command (mock_ctx , ide = 'claude-code' )
684695 assert mock_ai_client .report_session_context .call_count == 2
0 commit comments