fix: use --restore-last-session instead of unsigned Preferences restore_on_startup
All checks were successful
技能自动化发布 / release (push) Successful in 5s
All checks were successful
技能自动化发布 / release (push) Successful in 5s
This commit is contained in:
@@ -18,6 +18,37 @@ class TestPlaywrightLaunchHelpers:
|
||||
assert "--start-maximized" in args
|
||||
|
||||
|
||||
class TestEnsureSessionRestoreDoesNotTouchProtectedPref:
|
||||
def test_leaves_restore_on_startup_unchanged(self, tmp_path, fake_env):
|
||||
from pathlib import Path
|
||||
|
||||
from service.chrome_profile_prefs import ensure_session_restore, preferences_path
|
||||
from util.logging_config import setup_skill_logging
|
||||
|
||||
setup_skill_logging("account-manager", "openclaw.skill.account_manager_test")
|
||||
|
||||
profile = tmp_path / "prof"
|
||||
prefs = Path(preferences_path(str(profile)))
|
||||
prefs.parent.mkdir(parents=True, exist_ok=True)
|
||||
prefs.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"session": {"restore_on_startup": 5},
|
||||
"profile": {"exit_type": "Crashed", "exited_cleanly": False},
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
result = ensure_session_restore(str(profile))
|
||||
assert result["ok"] is True
|
||||
assert result["prefs_restore_on_startup_touched"] is False
|
||||
data = json.loads(prefs.read_text(encoding="utf-8"))
|
||||
assert data["session"]["restore_on_startup"] == 5
|
||||
assert data["profile"]["exit_type"] == "Normal"
|
||||
assert data["profile"]["exited_cleanly"] is True
|
||||
|
||||
|
||||
class TestProfileHasRestorableSession:
|
||||
def test_empty_profile_false(self, tmp_path):
|
||||
from service.chrome_profile_prefs import profile_has_restorable_session
|
||||
@@ -130,7 +161,7 @@ class TestCmdOpenDirectBrowser:
|
||||
def test_cmd_open_skips_url_when_modern_sessions_exist(
|
||||
self, clean_db, tmp_path, capsys, monkeypatch
|
||||
):
|
||||
"""Modern Chrome Sessions/ must restore without forcing homepage URL."""
|
||||
"""Modern Chrome Sessions/ must restore via --restore-last-session, no homepage URL."""
|
||||
from service import browser_service
|
||||
|
||||
profile = tmp_path / "prof"
|
||||
@@ -145,8 +176,11 @@ class TestCmdOpenDirectBrowser:
|
||||
payload = json.loads(out.splitlines()[-1])
|
||||
|
||||
assert payload["success"] is True
|
||||
assert payload["data"]["has_session"] is True
|
||||
assert payload["data"]["restore_last_session"] is True
|
||||
assert "https://example.com" not in spawned["cmd"]
|
||||
assert spawned["cmd"][-1].startswith("--")
|
||||
assert "--restore-last-session" in spawned["cmd"]
|
||||
assert spawned["cmd"][-1] == "--restore-last-session" or spawned["cmd"][-1].startswith("--")
|
||||
|
||||
|
||||
class TestHumanChromeLaunchArgs:
|
||||
@@ -158,9 +192,17 @@ class TestHumanChromeLaunchArgs:
|
||||
assert args[0].startswith("--user-data-dir=")
|
||||
for flag in HUMAN_CHROME_FLAGS:
|
||||
assert flag in args
|
||||
assert "--restore-last-session" not in args
|
||||
assert args[-1] == "https://chat.deepseek.com"
|
||||
assert "--enable-automation" not in args
|
||||
|
||||
def test_restore_session_flag_without_url(self, tmp_path):
|
||||
from service.browser_service import human_chrome_launch_args
|
||||
|
||||
args = human_chrome_launch_args(str(tmp_path / "prof"), None, restore_session=True)
|
||||
assert "--restore-last-session" in args
|
||||
assert not any(a.startswith("http") for a in args)
|
||||
|
||||
def test_shortcut_arguments_quote_profile_and_include_url(self, tmp_path):
|
||||
from service.browser_service import human_chrome_shortcut_arguments
|
||||
|
||||
@@ -170,8 +212,16 @@ class TestHumanChromeLaunchArgs:
|
||||
assert '--user-data-dir="' in text
|
||||
assert "--start-maximized" in text
|
||||
assert "--no-first-run" in text
|
||||
assert "--restore-last-session" not in text
|
||||
assert text.endswith("https://example.com")
|
||||
|
||||
def test_shortcut_restore_session(self, tmp_path):
|
||||
from service.browser_service import human_chrome_shortcut_arguments
|
||||
|
||||
text = human_chrome_shortcut_arguments(str(tmp_path / "p"), None, restore_session=True)
|
||||
assert "--restore-last-session" in text
|
||||
assert "http" not in text
|
||||
|
||||
|
||||
class TestResolveChromiumChannel:
|
||||
"""resolve_chromium_channel returns a channel string when browsers exist."""
|
||||
|
||||
Reference in New Issue
Block a user