Skip to content

Mark unmarked live-network tests as network (#397) - #509

Merged
neuromechanist merged 5 commits into
developfrom
fix/issue-397-network-marks
Sep 25, 2026
Merged

neuromechanist merged 5 commits into
developfrom
fix/issue-397-network-marks

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Summary

Closes #397.

tests/test_knowledge/test_papers_sync.py::TestPapersSync made real OpenAlex calls through opencite with no network marker, so the standard local filter (-m "not llm and not integration and not network and not slow") selected it, and a slow or unreachable OpenAlex could hang the local suite indefinitely (observed: 12+ minutes on one test, socket in CLOSE_WAIT).

This PR marks that class and every other unmarked live-network test found by measurement (running the offline selection with outbound network forced to fail fast via HTTPS_PROXY=http://127.0.0.1:9, plus --durations to catch slow ones proxy-blocking might miss), and gives the OpenAlex sync calls an explicit, bounded timeout.

Tests marked network

  • tests/test_knowledge/test_papers_sync.py
    • TestPapersSync (class): test_sync_openalex_papers_basic, test_sync_respects_max_results
    • TestLivePaperSearch (class): test_live_search_returns_recent
  • tests/test_tools/test_tool_integration.py (issue explicitly names this file's retrieve-docs tests)
    • TestRetrieveDocsTool::test_retrieve_preloaded_doc_success
    • TestRetrieveDocsTool::test_retrieve_ondemand_doc_success
    • TestRetrieveDocsToolCitations::test_returns_search_result_block_on_success
    • TestDocumentFetcher (class): test_fetcher_returns_content_for_known_doc, test_fetcher_handles_invalid_doc, test_fetcher_caches_results
    • TestErrorHandling::test_retrieve_tool_handles_network_error_gracefully
  • tests/test_tools/test_fetcher.py (TestDocumentFetcher class, 5 of its methods that hit a real URL; the module docstring overclaimed "every test needs network," corrected it)
    • test_fetch_real_document, test_fetch_caches_result, test_fetch_invalid_url, test_fetch_many, test_preload
  • tests/test_knowledge/test_github_sync.py (additional finding from the sweep, same anti-pattern as test_papers_sync.py: real GitHub API calls, no marker)
    • TestGitHubSync::test_sync_repo_issues_basic_flow, test_sync_repo_full_flow, test_sync_with_token

Left unmarked (verified they never touch the network): unknown-URL lookups that short-circuit in the doc registry before any fetch, the respx-mocked chrome-only-page tests, test_fetch_uses_cache (pre-populates the cache, never fetches), and all the TestDocumentFetcher/TestGetFetcher cache-only tests in test_fetcher.py.

Timeout

sync_openalex_papers() had no way to bound its opencite request. Added an optional timeout parameter (forwarded to opencite's own Config.timeout, mirroring the pattern search_papers_live already used) so the two TestPapersSync tests can pass timeout=15 and fail fast instead of relying on opencite's internal defaults. The other three files already had an explicit, bounded client-side timeout (DocumentFetcher.timeout_seconds / _github_request's timeout param), so no source changes were needed there. pytest-timeout is not used anywhere in this repo (checked pyproject.toml and all workflows), so it was not added.

CI: unchanged in effect

  • .github/workflows/tests.yml (test job, runs on every push/PR to develop/main) selects -m "not network": it already excluded nothing extra for these tests before this change beyond what "not network" always meant; after this change these tests are properly excluded, matching the local filter.
  • .github/workflows/test.yml's integration-tests job has a "Run network tests" step (pytest tests/ -v -m "network" --tb=short, continue-on-error: true) with no path restriction, gated to push-to-main/workflow_dispatch. It already covers tests/ broadly, so it picks up every test marked here with no workflow edit needed, exactly as it already does for the HED validation tests marked in Mark the live HED validation tests as network #486.
  • No workflow files were changed in this PR.

Measurement

Offline selection with network forced to fail immediately:

HTTPS_PROXY=http://127.0.0.1:9 HTTP_PROXY=http://127.0.0.1:9 ALL_PROXY=http://127.0.0.1:9 NO_PROXY=localhost,127.0.0.1 \
  uv run pytest tests/ -q -m "not llm and not integration and not network and not slow" -p no:cacheprovider --durations=30
  • Before this change: 7 failed (6 from live-network assertions failing fast against the blocked proxy, 1 pre-existing and unrelated), 2950 passed, 15 skipped, 85 deselected, 43.5s. The --durations output also showed the three now-marked test_papers_sync.py tests as the three slowest in the run (~7s each, consistent with retry/backoff against the blocked proxy).
  • After this change: 1 failed (tests/test_cli/test_main.py::TestVersionCommand::test_version_shows_version, an ANSI-color-code assertion unrelated to network, present before and after this change, not touched here), 2940 passed, 13 skipped, 103 deselected (+18, matching every test marked above), 22.1s.
  • test_github_sync.py's tests were found separately: they tolerate a failed request (assert count >= 0) so they don't fail under the blocked proxy, but code inspection plus a live run confirmed they reach api.github.com for real; included for the same reason test_papers_sync.py was.

Live run of every newly marked test against the real services (-m network): 17 passed, 1 skipped (test_sync_with_token, no GITHUB_TOKEN set locally, same as before this change).

Test plan

  • uv run pytest tests/ -q -m "not llm and not integration and not network and not slow" -p no:cacheprovider with network blocked: 2940 passed, 1 pre-existing unrelated failure, 13 skipped, 103 deselected, 22.1s (no hang)
  • uv run pytest tests/test_knowledge/test_papers_sync.py tests/test_tools/test_tool_integration.py tests/test_tools/test_fetcher.py tests/test_knowledge/test_github_sync.py -m network against the live services: all pass (1 skip for missing GITHUB_TOKEN)
  • uv run ruff check .
  • uv run ruff format --check src tests
  • Confirmed test.yml's network job (-m "network", no path filter) still covers every test marked in this PR; no workflow files changed

tests/test_knowledge/test_papers_sync.py's TestPapersSync makes real
OpenAlex calls through opencite but carried no marker, so the standard
local filter (-m "not llm and not integration and not network and not
slow") selected it; a slow or unreachable OpenAlex hung the suite
indefinitely. TestLivePaperSearch was the same, just already carrying
its own timeout kwarg.

sync_openalex_papers() had no way to bound the opencite request, so
give it an explicit timeout that forwards to opencite's own Config
(mirrors search_papers_live's existing timeout parameter). The two
TestPapersSync tests now pass timeout=15.

Tested: -m "not llm and not integration and not network and not slow"
deselects all 3; -m network runs all 3 against the live OpenAlex API
in under 1s each. ruff check and format clean.
tests/test_tools/test_tool_integration.py fetches real documentation
URLs (no respx mock) in several tests without a network marker: the
preloaded/on-demand retrieve_docs tests, the citations success path,
the whole TestDocumentFetcher class, and the "handles network error
gracefully" test (which still does a real fetch). None hang -- the
underlying DocumentFetcher already bounds each request to 30s -- but
they still spend the local suite's time on a live request and depend
on external hosts being reachable.

Left unmarked: tests that never reach the network (unknown-URL lookups
short-circuit in the doc registry before any fetch) and the
respx-mocked chrome-only-page tests, which exercise the same code path
against a fake response.

Tested: -m "not llm and not integration and not network and not slow"
deselects all 7; -m network runs all 7 against the live docs, passing.
ruff check and format clean.
tests/test_tools/test_fetcher.py's module docstring claimed every test
needs network access, but only 5 of its TestDocumentFetcher methods
actually call fetcher.fetch() against a real URL (GitHub raw content,
or a nonexistent repo to check the 404 path); the rest exercise the
cache layer with synthetic data. Mark just the five live ones and
correct the docstring.

Tested: -m "not llm and not integration and not network and not slow"
deselects all 5; -m network runs all 5 against GitHub, passing.
ruff check and format clean.
Found during the #397 sweep: tests/test_knowledge/test_github_sync.py
carries the same "real API tests, not mocks" note as test_papers_sync.py
but had no network marker on the tests that hit the real GitHub API
(sync_repo_issues/sync_repo against hed-standard/hed-specification, and
the GITHUB_TOKEN-gated variant). They tolerate a failed request and
return 0 rather than hanging or raising, so they weren't caught by
re-running the offline suite with the network blocked, but they still
reach api.github.com from what is supposed to be an offline run.

Tested: -m "not llm and not integration and not network and not slow"
deselects the 3 marked tests; -m network runs them against the live
GitHub API (2 pass, 1 skips for missing GITHUB_TOKEN as before). ruff
check and format clean.
sync_repos(['nonexistent/repo']) makes real unauthenticated GitHub
requests, so it belongs with the other live tests (#397 review).

Tested: test_github_sync.py -m 'not network' passes with it
deselected; ruff check and format clean.
@neuromechanist
neuromechanist merged commit c64a562 into develop Sep 25, 2026
10 of 12 checks passed
@neuromechanist
neuromechanist deleted the fix/issue-397-network-marks branch September 25, 2026 01:14
neuromechanist added a commit that referenced this pull request Sep 25, 2026
Brings in #505 and #509; CHANGELOG keeps both Added entries.

Tested: build-runtime-bundle --check (current); test-widget-tools passed;
tests/test_frontend_job_parity.py passed.
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