Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions fxcss/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -3036,8 +3036,11 @@ def build_parser():
prog="fxcss", usage="fxcss <command> [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 <command> [options] new`.
sub = ap.add_subparsers(dest="cmd", required=False, metavar="<command>",
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",
Expand Down
14 changes: 11 additions & 3 deletions fxcss/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand All @@ -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()
Expand Down
8 changes: 6 additions & 2 deletions tests/smoke_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
79 changes: 79 additions & 0 deletions tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name>`.

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 <command> [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("<command>", err.getvalue())


if __name__ == "__main__":
unittest.main()
Loading