From 3db9ab59569103ba5ff9506641c2f862bd14027b Mon Sep 17 00:00:00 2001 From: 07xh <3267597860@qq.com> Date: Mon, 23 Nov 2026 18:00:46 +0800 Subject: [PATCH 1/3] fix(ucampus): reject nonfinite server pass values as completion --- src/studyflow/platforms/ucampus/course_progress.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/studyflow/platforms/ucampus/course_progress.py b/src/studyflow/platforms/ucampus/course_progress.py index 347eb3a8..d759105e 100644 --- a/src/studyflow/platforms/ucampus/course_progress.py +++ b/src/studyflow/platforms/ucampus/course_progress.py @@ -9,6 +9,7 @@ import base64 import json +import math import re from typing import Any, TYPE_CHECKING from urllib.parse import quote @@ -137,7 +138,8 @@ def parse_tasks(rt: dict[str, Any], unit_id: str) -> list[dict[str, Any]]: state = leaf.get("state") required = strategies.get("required") if isinstance(strategies, dict) else None passed = state.get("pass") if isinstance(state, dict) else None - if passed is True or passed == 1 or isinstance(passed, (int, float)) and passed > 1: + if (passed is True or + type(passed) in (int, float) and math.isfinite(passed) and passed >= 1): completed = True elif passed in (0, "0") and passed is not None: completed = False From 66ac5763b03f6cee71b9cda48c4a65aacf77c7aa Mon Sep 17 00:00:00 2001 From: 07xh <3267597860@qq.com> Date: Mon, 23 Nov 2026 18:01:01 +0800 Subject: [PATCH 2/3] fix(ucampus): handle arbitrary integer counters without float conversion --- src/studyflow/platforms/ucampus/course_progress.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/studyflow/platforms/ucampus/course_progress.py b/src/studyflow/platforms/ucampus/course_progress.py index d759105e..112e776a 100644 --- a/src/studyflow/platforms/ucampus/course_progress.py +++ b/src/studyflow/platforms/ucampus/course_progress.py @@ -139,7 +139,8 @@ def parse_tasks(rt: dict[str, Any], unit_id: str) -> list[dict[str, Any]]: required = strategies.get("required") if isinstance(strategies, dict) else None passed = state.get("pass") if isinstance(state, dict) else None if (passed is True or - type(passed) in (int, float) and math.isfinite(passed) and passed >= 1): + (type(passed) is int or type(passed) is float and math.isfinite(passed)) + and passed >= 1): completed = True elif passed in (0, "0") and passed is not None: completed = False From 5df00a1207d84e5699d6dfcb4c4585b33592d7ef Mon Sep 17 00:00:00 2001 From: 07xh <3267597860@qq.com> Date: Mon, 23 Nov 2026 18:01:20 +0800 Subject: [PATCH 3/3] test(ucampus): nonfinite progress flags remain unverified --- tests/test_ucampus_progress.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_ucampus_progress.py b/tests/test_ucampus_progress.py index 691d9061..18441166 100644 --- a/tests/test_ucampus_progress.py +++ b/tests/test_ucampus_progress.py @@ -201,3 +201,27 @@ class Response: lambda *a, **kw: Response()) with pytest.raises(UCampusProgressError, match=expected): UCampusProgressReader(credentials_loader=lambda: cfg).list_units("course-v2:real") + + +@pytest.mark.parametrize("invalid", [float("nan"), float("inf"), float("-inf")]) +def test_nonfinite_server_pass_is_unknown_not_completed(invalid): + tasks = parse_tasks({"leafs": { + "video1": {"tab_type": "video", "state": {"pass": invalid}}, + }}, "unit1") + assert len(tasks) == 1 + assert tasks[0]["completed"] is None + + +def test_numeric_server_pass_keeps_previous_valid_behavior(): + for value, expected in ((True, True), (1, True), (2, True), (1.0, True), + (0, False), (False, False), (-1, None)): + tasks = parse_tasks({"leafs": { + "video1": {"tab_type": "video", "state": {"pass": value}}, + }}, "unit1") + assert tasks[0]["completed"] is expected + # Large integer counters should not pass through float(), which may raise + # OverflowError for a JSON integer with more digits than a float can hold. + huge = parse_tasks({"leafs": { + "video1": {"tab_type": "video", "state": {"pass": 10 ** 400}}, + }}, "unit1") + assert huge[0]["completed"] is True