Skip to content

medium verifier: exact and ordered_list reject bool-as-int (fixes #47) - #106

Open
bluzername wants to merge 1 commit into
TIGER-AI-Lab:mainfrom
bluzername:fix/exact-comparators-reject-bool-as-int
Open

bluzername wants to merge 1 commit into
TIGER-AI-Lab:mainfrom
bluzername:fix/exact-comparators-reject-bool-as-int

Conversation

@bluzername

Copy link
Copy Markdown

What is wrong

In tasks/medium/tests/websitebench/harbor/judge.py, exact only check type(actual) is type(expected) at the top level, then fall back to plain ==. Python say True == 1 and False == 0, even for a value sitting inside a dict or a list, so this type check at the top never catch it:

compare_values({"paid": True}, {"paid": 1}, {"type": "exact"})       # passed, should not
compare_values([True, 0], [1, False], {"type": "ordered_list"})     # passed, should not

json_contract's own equal() already has the right rule (bool and int/float are never the same type, but int and float can still match each other for serialization drift like 2500 vs 2500.0). A candidate API that return 1 where the reference return true would pass every exact check on the 9 api_json observations in medium, which is exactly the hole issue #47 describe.

The fix

Added a small standalone _type_strict_equal() (same recursion/number rule as json_contract's equal(), just without its field-rule matching, since exact/ordered_list do not declare fields) and use it for both exact and ordered_list instead of a bare ==.

Scoped to medium only, same as the issue - the other 69 tasks each keep their own copy of judge.py, not touched here.

Test

New tests/test_medium_judge_comparators.py, loading judge.py the same dynamic way tests/test_check_tasks.py already load scripts/check_tasks.py. 6 cases: bool-vs-int at top level and inside a dict/list for both comparators (2 of them are RED on the old == code, GREEN after), plus 3 confirming a true match and the int/float drift case still pass.

I was not able to execute the suite in my sandbox (no pytest/unittest access on a freshly cloned repo here), so I hand traced _type_strict_equal against every new case and against the existing exact/ordered_list/json_contract call sites in compare_values line by line. python3 -m py_compile on both changed files is clean. Sorry for the extra load on review, happy to adjust if CI see something I miss.

…ixes TIGER-AI-Lab#47)

Python's == treat True as 1 and False as 0 even inside a dict or a list.
exact only check type() at the top level, then fall back to ==, so a
dict that differ only by bool-vs-int somewhere inside it still compare
equal. ordered_list have the same problem for a list. json_contract's
own equal() already guard this one rule - now exact and ordered_list
use a small standalone _type_strict_equal that keep the same rule
(recurse through dict/list, number drift between int and float still
OK, bool is never a number).

Scoped to medium only, same as issue TIGER-AI-Lab#47 - the other 69 tasks keep
their own copy of judge.py untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant