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
36 changes: 26 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@


# --------------------------------------------------------------------------- #
# 2. Clients
# 2. Clients (configured with secure defaults)
# --------------------------------------------------------------------------- #
def _api_client() -> httpx.Client:
return httpx.Client(
Expand Down Expand Up @@ -2396,6 +2396,29 @@
print(f"{line('β””', 'β”΄', 'β”˜')}\n")


def print_success_message(profile_ids: List[str]) -> None:
"""Prints a random success message and a link to the Control D dashboard."""
if not USE_COLORS:
return

success_msgs = [
"✨ All synced!",
"πŸš€ Ready for liftoff!",
"🎨 Beautifully done!",
"πŸ’Ž Smooth operation!",
"🌈 Perfect harmony!",
]
Comment on lines +2404 to +2410

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The success_msgs list is defined inside the print_success_message function. This means it's recreated every time the function is called. For better performance and to follow the convention of defining constants at the module level, consider moving this list outside the function, for example, as a module-level constant like _SUCCESS_MESSAGES.

Comment on lines +2399 to +2410
Copy link

Copilot AI Feb 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring suggests this function always prints a success message and dashboard link, but it returns early when USE_COLORS is false and it can also skip printing the link (e.g., empty profile_ids or the dry-run-placeholder sentinel). Please update the docstring to reflect the actual behavior, or adjust the implementation if the intent is to always show a link regardless of color mode.

Copilot uses AI. Check for mistakes.
print(f"\n{Colors.GREEN}{random.choice(success_msgs)}{Colors.ENDC}")

Check warning

Code scanning / Prospector (reported by Codacy)

multiple statements on one line (def) (E704) Warning

multiple statements on one line (def) (E704)

Check warning

Code scanning / Prospector (reported by Codacy)

ambiguous variable name 'l' (E741) Warning

ambiguous variable name 'l' (E741)
# Construct dashboard URL
if profile_ids and len(profile_ids) == 1 and profile_ids[0] != "dry-run-placeholder":
dashboard_url = f"https://controld.com/dashboard/profiles/{profile_ids[0]}/filters"
print(f"{Colors.CYAN}πŸ‘€ View your changes: {Colors.UNDERLINE}{dashboard_url}{Colors.ENDC}")
elif len(profile_ids) > 1:
dashboard_url = "https://controld.com/dashboard/profiles"

Check warning

Code scanning / Prospector (reported by Codacy)

line too long (245 > 159 characters) (E501) Warning

line too long (245 > 159 characters) (E501)
print(f"{Colors.CYAN}πŸ‘€ View your changes: {Colors.UNDERLINE}{dashboard_url}{Colors.ENDC}")


def parse_args() -> argparse.Namespace:
"""
Parses command-line arguments for the Control D sync tool.
Expand Down Expand Up @@ -2721,15 +2744,8 @@
print(make_col_separator(Box.BL, Box.B, Box.BR, Box.H))

# Success Delight
if all_success and USE_COLORS and not args.dry_run:
success_msgs = [
"✨ All synced!",
"πŸš€ Ready for liftoff!",
"🎨 Beautifully done!",
"πŸ’Ž Smooth operation!",
"🌈 Perfect harmony!",
]
print(f"\n{Colors.GREEN}{random.choice(success_msgs)}{Colors.ENDC}")
if all_success and not args.dry_run:
print_success_message(profile_ids)

# Dry Run Next Steps
if args.dry_run:
Expand Down
63 changes: 63 additions & 0 deletions tests/test_ux.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,66 @@
assert mock_log.info.call_count == 2
mock_log.info.assert_any_call("LongWait: 15s remaining...")
mock_log.info.assert_any_call("LongWait: 5s remaining...")


def test_print_success_message_single_profile(monkeypatch):
"""Verify success message includes dashboard link for single profile."""
# Force colors on
monkeypatch.setattr(main, "USE_COLORS", True)
# Monkeypatch Colors attributes because they are computed at import time
monkeypatch.setattr(main.Colors, "CYAN", "\033[96m")
monkeypatch.setattr(main.Colors, "UNDERLINE", "\033[4m")
monkeypatch.setattr(main.Colors, "ENDC", "\033[0m")
monkeypatch.setattr(main.Colors, "GREEN", "\033[92m")

# Mock stdout
mock_stdout = MagicMock()
# print() writes to sys.stdout by default
monkeypatch.setattr(sys, "stdout", mock_stdout)

profile_ids = ["123456"]
main.print_success_message(profile_ids)

# Check calls
writes = [args[0] for args, _ in mock_stdout.write.call_args_list]
combined_output = "".join(writes)

# Verify content
# Note: The output is ANSI colored, so exact string matching might fail if color codes are interspersed

Check warning

Code scanning / Pylint (reported by Codacy)

Line too long (107/100) Warning test

Line too long (107/100)

Check warning

Code scanning / Pylintpython3 (reported by Codacy)

Line too long (107/100) Warning test

Line too long (107/100)
# But "View your changes" should be there
assert "View your changes" in combined_output

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check notice

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
assert "https://controld.com/dashboard/profiles/123456/filters" in combined_output

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check notice

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
# Check for color codes presence (cyan or underline)
assert "\033[96m" in combined_output or "\033[4m" in combined_output

def test_print_success_message_multiple_profiles(monkeypatch):
"""Verify success message includes general dashboard link for multiple profiles."""
monkeypatch.setattr(main, "USE_COLORS", True)
# Monkeypatch Colors attributes
monkeypatch.setattr(main.Colors, "CYAN", "\033[96m")
monkeypatch.setattr(main.Colors, "UNDERLINE", "\033[4m")
monkeypatch.setattr(main.Colors, "ENDC", "\033[0m")
monkeypatch.setattr(main.Colors, "GREEN", "\033[92m")

mock_stdout = MagicMock()
monkeypatch.setattr(sys, "stdout", mock_stdout)

profile_ids = ["123", "456"]
main.print_success_message(profile_ids)

writes = [args[0] for args, _ in mock_stdout.write.call_args_list]
combined_output = "".join(writes)

assert "View your changes" in combined_output

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check notice

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
assert "https://controld.com/dashboard/profiles" in combined_output

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check notice

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
assert "/123/filters" not in combined_output # Should not link to specific profile

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

Check notice

Code scanning / Bandit (reported by Codacy)

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.

def test_print_success_message_no_colors(monkeypatch):
"""Verify nothing is printed if colors are disabled."""
monkeypatch.setattr(main, "USE_COLORS", False)
mock_stdout = MagicMock()
monkeypatch.setattr(sys, "stdout", mock_stdout)

main.print_success_message(["123"])

mock_stdout.write.assert_not_called()
Loading