From 72b19363709c0834a8e60a037d06bb7cc07f314f Mon Sep 17 00:00:00 2001 From: ivanharvard <144486839+ivanharvard@users.noreply.github.com> Date: Tue, 5 Aug 2025 17:14:40 -0400 Subject: [PATCH 1/4] added support for --https and --ssh --- check50/__main__.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/check50/__main__.py b/check50/__main__.py index a675d6e..1b14160 100644 --- a/check50/__main__.py +++ b/check50/__main__.py @@ -259,6 +259,20 @@ def process_args(args): if args.ansi_log and "ansi" not in seen_output: LOGGER.warning(_("--ansi-log has no effect when ansi is not among the output formats")) + if args.https or args.ssh: + if args.offline: + LOGGER.warning(_("Using either --https and --ssh will have no effect when running offline")) + args.auth_method = None + elif args.https and args.ssh: + LOGGER.warning(_("--https and --ssh have no effect when used together")) + args.auth_method = None + elif args.https: + args.auth_method = "https" + else: + args.auth_method = "ssh" + else: + args.auth_method = None + class LoggerWriter: def __init__(self, logger, level): @@ -334,6 +348,18 @@ def main(): parser.add_argument("--no-install-dependencies", action="store_true", help=_("do not install dependencies (only works with --local)")) + parser.add_argument("--assertion-rewrite", + action="store", + nargs="?", + const="enabled", + choices=["true", "enabled", "1", "on", "false", "disabled", "0", "off"], + help=_("enable or disable assertion rewriting; overrides ENABLE_CHECK50_ASSERT flag in the checks file")) + parser.add_argument("--https", + action="store_true", + help=_("force authentication via HTTPS")) + parser.add_argument("--ssh", + action="store_true", + help=_("force authentication via SSH")) parser.add_argument("-V", "--version", action="version", version=f"%(prog)s {__version__}") @@ -355,7 +381,7 @@ def main(): # If remote, push files to GitHub and await results if not args.local: - commit_hash = lib50.push("check50", internal.slug, internal.CONFIG_LOADER, data={"check50": True})[1] + commit_hash = lib50.push("check50", internal.slug, internal.CONFIG_LOADER, data={"check50": True}, auth_method=args.auth_method)[1] with lib50.ProgressBar("Waiting for results") if "ansi" in args.output else nullcontext(): tag_hash, results = await_results(commit_hash, internal.slug) @@ -392,7 +418,13 @@ def main(): original_checks_file = (internal.check_dir / config["checks"]).resolve() # If the user has enabled the rewrite feature - if assertions.rewrite_enabled(str(original_checks_file)): + assertion_rewrite_enabled = False + if args.assertion_rewrite is not None: + assertion_rewrite_enabled = args.assertion_rewrite.lower() in ("true", "1", "enabled", "on") + else: + assertion_rewrite_enabled = assertions.rewrite_enabled(str(original_checks_file)) + + if assertion_rewrite_enabled: # Create a temporary copy of the checks file with tempfile.NamedTemporaryFile(suffix=".py", delete=False) as tmp: checks_file = Path(tmp.name) From f698cf5bb4423088af5ac079888e1bf0f008ebac Mon Sep 17 00:00:00 2001 From: ivanharvard <144486839+ivanharvard@users.noreply.github.com> Date: Wed, 6 Aug 2025 16:42:13 -0400 Subject: [PATCH 2/4] added debug messages --- check50/__main__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/check50/__main__.py b/check50/__main__.py index 1b14160..d0bdf4b 100644 --- a/check50/__main__.py +++ b/check50/__main__.py @@ -14,6 +14,7 @@ import sys import tempfile import time +import traceback import attr import lib50 @@ -381,7 +382,14 @@ def main(): # If remote, push files to GitHub and await results if not args.local: - commit_hash = lib50.push("check50", internal.slug, internal.CONFIG_LOADER, data={"check50": True}, auth_method=args.auth_method)[1] + try: + commit_hash = lib50.push("check50", internal.slug, internal.CONFIG_LOADER, data={"check50": True}, auth_method=args.auth_method)[1] + except lib50.ConnectionError: + LOGGER.debug(traceback.format_exc()) # log the traceback + raise _exceptions.Error(_( + "check50 failed to authenticate your Github account. Try running check50 again with --https or --ssh, " + "or try restarting your codespace. If the problem persists, please email us at sysadmins@cs50.harvard.edu." + )) with lib50.ProgressBar("Waiting for results") if "ansi" in args.output else nullcontext(): tag_hash, results = await_results(commit_hash, internal.slug) From 39da322d9698bbe7cd61a27d51cd7f584defd46f Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Wed, 6 Aug 2025 23:45:34 -0400 Subject: [PATCH 3/4] improve error handling during authentication failure --- check50/__main__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/check50/__main__.py b/check50/__main__.py index d0bdf4b..7adc73d 100644 --- a/check50/__main__.py +++ b/check50/__main__.py @@ -385,11 +385,16 @@ def main(): try: commit_hash = lib50.push("check50", internal.slug, internal.CONFIG_LOADER, data={"check50": True}, auth_method=args.auth_method)[1] except lib50.ConnectionError: - LOGGER.debug(traceback.format_exc()) # log the traceback - raise _exceptions.Error(_( - "check50 failed to authenticate your Github account. Try running check50 again with --https or --ssh, " - "or try restarting your codespace. If the problem persists, please email us at sysadmins@cs50.harvard.edu." - )) + LOGGER.debug(traceback.format_exc() + if not os.environ.get("CODESPACES"): + raise _exceptions.Error(_( + "check50 failed to authenticate your Github account. Please make sure you are connected to the internet and try again." + )) + except Exception as e: + LOGGER.debug(traceback.format_exc()) + raise _exceptions.Error(_("Sorry, something's wrong, please try again.\n" + "If the problem persists, please visit our status page https://cs50.statuspage.io for more information.")) from e + with lib50.ProgressBar("Waiting for results") if "ansi" in args.output else nullcontext(): tag_hash, results = await_results(commit_hash, internal.slug) From 3c50d812480e7b4532fcba31c8458168b67fc11c Mon Sep 17 00:00:00 2001 From: Rongxin Liu Date: Wed, 6 Aug 2025 23:56:30 -0400 Subject: [PATCH 4/4] fix syntax error --- check50/__main__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check50/__main__.py b/check50/__main__.py index 7adc73d..75a2ef7 100644 --- a/check50/__main__.py +++ b/check50/__main__.py @@ -385,8 +385,8 @@ def main(): try: commit_hash = lib50.push("check50", internal.slug, internal.CONFIG_LOADER, data={"check50": True}, auth_method=args.auth_method)[1] except lib50.ConnectionError: - LOGGER.debug(traceback.format_exc() - if not os.environ.get("CODESPACES"): + LOGGER.debug(traceback.format_exc()) + if not os.environ.get("CODESPACES"): raise _exceptions.Error(_( "check50 failed to authenticate your Github account. Please make sure you are connected to the internet and try again." ))