Found by @XEDAB while working on #97 — their branch is the first thing that ever made this assertion do work, and it failed immediately. Details and the measurement are in this thread.
The problem
tests/test_no_chrome.py:50:
def run_cli(urls, retries=1) -> dict:
with tempfile.TemporaryDirectory() as out:
asyncio.run(moon_cli.run(urls, out, 4, 4, retries, "proxies.txt"))
done = len(os.listdir(out))
return {"ok": len(urls) if done == 0 else done, "fail": 0}
If the run writes no files, done == 0 and ok becomes len(urls). assert_browser_counts then asserts:
assert result["ok"] == len(urls)
which is len(urls) == len(urls). The zero-file case — the one worth catching — is reported as a complete success.
It is the case that actually happens
Measured on current main with a temporary probe using the same fixtures and the same URLs as test_cli_mixed_batch_launches_one_shared_browser:
So that assertion has never been able to fail on any run of this suite. The open_browser / playwright / close_browser counts above it are real and do their job; only the ok line is inert.
Three tests share assert_browser_counts and all three inherit this:
test_cli_fuckingfast_only_launches_no_browser
test_cli_mixed_batch_launches_one_shared_browser
test_cli_datanodes_only_launches_one_browser
The decision to make
There is a real choice here and I do not want to prescribe the wrong one again:
- Make the stub write files, so
done is a true count and the assertion means "every URL produced a file". Strongest, but it puts the stubs on the hook for producing believable output and may need the download layer stubbed further down than it currently is.
- Drop the
ok assertion and replace it with something the stub actually guarantees — the browser counts already carry the intent of these tests, and a fourth assertion that cannot fail is worse than three that can.
Option 2 is smaller and honest. Option 1 is more valuable if the stub can support it without becoming a second implementation of the downloader. Whoever takes this should pick one and say why in the PR body; either is acceptable, an assertion that silently cannot fail is not.
Done when
- No assertion in
test_no_chrome.py passes by construction
- If the
ok check survives in any form, it fails when the run produces fewer files than URLs — demonstrate this, e.g. by breaking something locally and showing the test goes red
pytest tests/ -q green
Needs no Windows machine. The stubs replace Chrome and the network, so this runs anywhere.
Found by @XEDAB while working on #97 — their branch is the first thing that ever made this assertion do work, and it failed immediately. Details and the measurement are in this thread.
The problem
tests/test_no_chrome.py:50:If the run writes no files,
done == 0andokbecomeslen(urls).assert_browser_countsthen asserts:which is
len(urls) == len(urls). The zero-file case — the one worth catching — is reported as a complete success.It is the case that actually happens
Measured on current
mainwith a temporary probe using the same fixtures and the same URLs astest_cli_mixed_batch_launches_one_shared_browser:So that assertion has never been able to fail on any run of this suite. The
open_browser/playwright/close_browsercounts above it are real and do their job; only theokline is inert.Three tests share
assert_browser_countsand all three inherit this:test_cli_fuckingfast_only_launches_no_browsertest_cli_mixed_batch_launches_one_shared_browsertest_cli_datanodes_only_launches_one_browserThe decision to make
There is a real choice here and I do not want to prescribe the wrong one again:
doneis a true count and the assertion means "every URL produced a file". Strongest, but it puts the stubs on the hook for producing believable output and may need the download layer stubbed further down than it currently is.okassertion and replace it with something the stub actually guarantees — the browser counts already carry the intent of these tests, and a fourth assertion that cannot fail is worse than three that can.Option 2 is smaller and honest. Option 1 is more valuable if the stub can support it without becoming a second implementation of the downloader. Whoever takes this should pick one and say why in the PR body; either is acceptable, an assertion that silently cannot fail is not.
Done when
test_no_chrome.pypasses by constructionokcheck survives in any form, it fails when the run produces fewer files than URLs — demonstrate this, e.g. by breaking something locally and showing the test goes redpytest tests/ -qgreenNeeds no Windows machine. The stubs replace Chrome and the network, so this runs anywhere.