from __future__ import annotations
import json
from pathlib import Path
ROOT = Path(__file__).resolve().parent
SOURCE = (ROOT / 'auto_service8700_manager.py').read_text(encoding='utf-8')

def _config(name: str) -> dict:
    return json.loads((ROOT / name).read_text(encoding='utf-8'))

def test_version_and_retired_service_removed() -> None:
    assert '"version": "2.3.8.223"' in SOURCE
    assert 'direct_schedule_activation' in SOURCE
    assert 'ws_user_mouse_idle_10s' not in SOURCE
    for cfg_name in ['auto_service8700_manager.default.json', 'auto_service8700_manager.json']:
        cfg = _config(cfg_name)
        assert cfg['version'] == '2.3.8.223'
        names = {str(x.get('name','')).upper() for x in cfg.get('services',[])}
        assert 'HEART8772' not in names
        ws = next(x for x in cfg['services'] if str(x.get('name','')).upper() == 'WS8771')
        forbidden = {'ws8771_heart_client.py','ws8771_ig_auto_click_download.py','ws8771_ig_auto_download.py','ws8771_origin_crosscheck.py'}
        assert not forbidden.intersection(ws.get('watch_files',[]))
        assert 'Heart8772' not in (cfg.get('bat_catalog') or {})
        assert 'Heart8772' not in (cfg.get('shared_watch') or {}).get('restart_services',[])

def test_source_does_not_restore_retired_heart_service() -> None:
    for token in ['"name": "Heart8772"', 'D:\\_St\\Heart8772', 'heart8772_position.py', 'ws8771_heart_client.py', 'ws8771_ig_auto_click_download.py']:
        assert token not in SOURCE
