diff --git a/fxcss/cli.py b/fxcss/cli.py index 145a63f..879fa26 100644 --- a/fxcss/cli.py +++ b/fxcss/cli.py @@ -1130,7 +1130,7 @@ def cmd_profiles(args): checkable = any(((r["manifest"] or {}).get("source") or {}).get("kind") in fetch.REMOTE_KINDS for r in rows) if not args.check and checkable: - notes.append("Pass --check to ask GitHub whether anything newer exists.") + notes.append((" ", "Pass --check to ask GitHub whether anything newer exists.")) if notes: print() for mark, note in notes: @@ -3036,8 +3036,11 @@ def build_parser(): prog="fxcss", usage="fxcss [options]", description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) ap.add_argument("--version", action="version", version=f"fxcss {__version__}") + # prog is spelled out: before Python 3.14 argparse derives it from the + # usage line above, and every subcommand would then introduce itself as + # `fxcss [options] new`. sub = ap.add_subparsers(dest="cmd", required=False, metavar="", - parser_class=argparse.ArgumentParser) + prog="fxcss", parser_class=argparse.ArgumentParser) tr = sub.add_parser( "try", help="test-drive a theme from GitHub or a folder in a throwaway profile", diff --git a/fxcss/core.py b/fxcss/core.py index e9bf304..058a6d8 100644 --- a/fxcss/core.py +++ b/fxcss/core.py @@ -548,6 +548,16 @@ def _fixture_pages_loaded(state, expected): for tab, (url, title) in zip(state, expected))) +def startup_attempts(): + """How many times a session launches Firefox before giving up. + + Windows can connect Marionette before its first content process is + ready. Give that process time, then try a fresh launch if it stalls -- + and one launch more there, where a second stall in a row is not rare. + """ + return 3 if sys.platform == "win32" else 2 + + class Session: """A running Firefox with a themed profile and a Marionette connection.""" @@ -569,9 +579,7 @@ def __init__(self, repo: Path, firefox: str, dark=False, native_menus=None, self._window_ready = False def __enter__(self): - # Windows can connect Marionette before its first content process is - # ready. Give that process time, then try a fresh launch if it stalls. - attempts = 3 if sys.platform == "win32" else 2 + attempts = startup_attempts() try: for attempt in range(attempts): self._start_browser() diff --git a/tests/smoke_startup.py b/tests/smoke_startup.py index 5579f2b..cceaf29 100644 --- a/tests/smoke_startup.py +++ b/tests/smoke_startup.py @@ -84,8 +84,12 @@ def _start_browser(self): with delayed_document() as url, BrokenFirstProcess( theme, core.find_firefox(), extra_prefs='user_pref("intl.l10n.pseudo", "bidi");\n') as session: - assert len(session.browser_pids) == 2, session.browser_pids - assert session.browser_pids[0] != session.browser_pids[1], session.browser_pids + # The first launch is broken on purpose, so there is always a second. + # A later one may stall for real, as Windows runners sometimes do, and + # the session is then entitled to every launch it allows itself. + launches = len(session.browser_pids) + assert 2 <= launches <= core.startup_attempts(), session.browser_pids + assert len(set(session.browser_pids)) == launches, session.browser_pids session.urls["docs.html"] = url # Reproduce the operation that failed indefinitely on Windows CI. The # original browser must never be navigated, even if it looks ready. diff --git a/tests/test_units.py b/tests/test_units.py index 16eba20..8a7a911 100644 --- a/tests/test_units.py +++ b/tests/test_units.py @@ -4403,5 +4403,84 @@ def test_no_module_urls_sneak_in(self): self.assertNotIn("importESModule", core._INJECTOR_JS) +class ProfilesListingTests(unittest.TestCase): + """`fxcss profiles` with a theme that came from a repository. + + The closing notes are (mark, text) pairs. The hint about --check went in + as a bare string, so the listing printed and then died unpacking it -- + for exactly the people who had installed something from GitHub. + """ + + def listing(self, argv, source): + import contextlib + import io + from unittest import mock + from fxcss import cli + row = {"name": "default-release", "path": Path("/profiles/abc.default-release"), + "kind": "Release", "default": True, "state": "managed", + "running": False, + "drift": {"modified": [], "missing": [], "extra": [], "checked": 1}, + "manifest": {"theme": "example/theme", "source": source, + "installed": "2026-11-10T09:00:00", + "files": ["chrome/userChrome.css"]}} + out = io.StringIO() + with mock.patch("fxcss.cli.survey_profiles", return_value=[row]), \ + mock.patch("fxcss.fetch.resolve", side_effect=RuntimeError("offline")), \ + contextlib.redirect_stdout(out): + code = cli.cmd_profiles(cli.build_parser().parse_args(argv)) + return code, out.getvalue() + + REMOTE = {"kind": "github", "owner": "example", "name": "theme", + "ref": "v1.0.0", "ref_kind": "release"} + + def test_a_repository_theme_lists_and_offers_the_check(self): + code, text = self.listing(["profiles"], self.REMOTE) + self.assertEqual(code, 0) + self.assertIn("example/theme @ v1.0.0", text) + self.assertIn("Pass --check to ask GitHub", text) + + def test_the_check_is_not_offered_twice(self): + code, text = self.listing(["profiles", "--check"], self.REMOTE) + self.assertEqual(code, 0) + self.assertNotIn("Pass --check", text) + + def test_a_local_theme_has_nothing_to_check(self): + code, text = self.listing(["profiles"], {"kind": "local", "path": "/themes/mine"}) + self.assertEqual(code, 0) + self.assertNotIn("Pass --check", text) + + +class SubcommandUsageTests(unittest.TestCase): + """Every subcommand introduces itself as `fxcss `. + + Before Python 3.14 argparse builds a subparser's name from the parent's + usage line, and the parent's is written by hand, so `fxcss new` called + itself `fxcss [options] new` in its usage and its errors. + """ + + def subparsers(self): + import argparse + from fxcss import cli + (action,) = [a for a in cli.build_parser()._actions + if isinstance(a, argparse._SubParsersAction)] + return action.choices + + def test_each_one_is_named_after_the_program_and_itself(self): + for name, parser in self.subparsers().items(): + with self.subTest(command=name): + self.assertEqual(parser.prog, f"fxcss {name}") + + def test_an_error_says_which_command_it_came_from(self): + import contextlib + import io + from fxcss import cli + err = io.StringIO() + with self.assertRaises(SystemExit), contextlib.redirect_stderr(err): + cli.build_parser().parse_args(["new"]) + self.assertIn("usage: fxcss new ", err.getvalue()) + self.assertIn("fxcss new: error:", err.getvalue()) + self.assertNotIn("", err.getvalue()) + + if __name__ == "__main__": unittest.main()