Repository navigation
test(nodes): keep the real depends and engLib in sys.modules for the whole test run (#3097) - #3098
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
🤖 Internal: Discord sync markerAuto-managed by the Discord notification workflow. Stores the linked Discord message ID and forum thread ID. Do not edit or delete. |
…whole test run (#3097) - `tool_git/test_tools.py` puts its `depends` and `engLib` stand-ins in `sys.modules` only while `tool_git` loads - the `sys.modules` guard pins `depends` and `engLib` the way it pins numpy - a module loaded by `BuiltinImporter` (such as `engLib`) counts as real, not as a stub - guard tests for both modules
d8dbb66 to
9475fe7
Compare
dk-rocketride
left a comment
There was a problem hiding this comment.
Approved. The stubs now live only for the tool_git import, inside the patch.dict that already covered it, and pinning depends and engLib makes the next leak fail in teardown instead of silently turning depends() into a no-op. Outside the engine _import_pinned skips modules that don't import, so plain-python runs are unaffected. The BuiltinImporter check has its own test. CI is green on all three platforms.
Brings in the first ten develop PRs since base 7e009b1. Every PR's intent was checked on the merged tree; the two files that conflicted were resolved by re-expressing develop's behaviour in this branch's shape, not by taking a side. PRs and how each intent survives: - #3062 feat(appdev,shell): point failed builds to their build log - preserved (TS only, no overlap). - #3081 test(client-typescript): more time for slow-runner startup tests - preserved (tests only). - #3055 fix(nodes): store_milvus writes and reads a real Milvus with pymilvus 3 - preserved: develop's rewrite merged cleanly onto the converted driver (self.config shape untouched by the PR); store_milvus suite + mock + shapes tests pass. - #3069 feat(client): invite() returning the invited member in both SDKs - preserved; client-python tests/test_account.py 3 passed; docs merged. - #2965 fix(ai): generated SQL on a read-only, time-limited connection - preserved; packages/ai/tests/ai/common/database 392 passed (live DSN tests skipped). - #3061 docs(cli): per-CLI command tables + CI drift check - preserved; tests/test_validate_cli_docs.py 24 passed. - #3096 fix(appdev,shell): review follow-up on build-log change - preserved (TS only). - #3091 fix(mcp): credential fields opt out of automatic wiring - RE-EXPRESSED. develop added a catalog-file option `auto_wire: false`; this branch has no catalog file (credentials.json and nodes/scripts/gen-credentials.mjs are deleted, the catalog is derived from each node's resolved service definition). The same rule now lives in the definition walk: a credential found inside an array item (a list-row field the node reads per row) is described but `auto_wire=False` and `required=False`, and `evaluate()` only wires `auto_wire` fields. develop's six-case test is kept as test_array_row_credential_is_described_but_never_required_or_wired against catalog_from_definitions. gen-credentials.mjs stays deleted (superseded). - #3098 test(nodes): keep real depends and engLib in sys.modules - preserved; test_sys_modules_guard.py + tool_git tests pass. - #3076 docs(vscode): connection modes - preserved (docs only). Verification on the merged tree: ruff format/check clean on the touched .py; grep gate for getNodeConfig/getMultiProviderConfig/overlay_top_level/ _warnMisnamedKeys/preconfig over packages/ai/src, rocketlib-python, nodes/src = 0; old-format services*.json = tool_pipedrive enum label only; nodes/test/test_import_gate.py + store_milvus + guard + tool_git = 328 passed; mcp credentials/integrations + database + device budget = 392 passed; ./builder nodes:sync ok. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Summary
nodes/test,depends()installed nothing during the tests.tool_git/test_tools.pyput a stubdependsand aMagicMockengLibinsys.moduleswhen pytest imported it, and left them there for the rest of the session. pytest imports every test module before the first test runs, so:depends()/load_depends()call did nothing. On an engine without torch,test_embedding_image.pyfailed withNo module named 'torch', also with the command its docstring gives (builder nodes:test-full --pytest="-m skip_node -k embedding_image"), which collects all ofnodes/testtoo. Run on its own, the test installs torch first;engLiblater in the run (ai.common.ssl,ai.node,depends.py) got theMagicMock.tool_git/test_tools.pynow puts both stand-ins insys.modulesonly whiletool_gitloads, inside thepatch.dictblock that already covers that import.git_repo.pycallsdepends()only at import, so nothing in these tests needs them afterwards.sys.modulesguard (nodes/test/_sys_modules_guard.py) pinsdependsandengLib, as it pins numpy since test(nodes): keep the real numpy in sys.modules for the whole test run (#3019, #3025) #3068: it checks them at collection time and after every test, a test that leaves either replaced or removed fails, and the real module is put back.engLibis compiled into the engine, so it has no__file__, and the guard's stub check (_is_stub_module) took it for a stub; it could not have been pinned. A module loaded byBuiltinImporternow counts as real. A hand-built module with the same name is still a stub.pytest.importorskip('torch')intest_embedding_image.py: on an engine without torch the test would be skipped forever instead of installing torch and running, and every other first-use install in the run would stay a silent no-op.Type
fix (tests only)
Testing
./builder testpassesLocal runs with
./dist/server/engine.exe -m pytest ...on a fresh light dist (no torch at the start):nodes/test -m skip_node -k embedding_image(the docstring's command, run directly)No module named 'torch'depends()installedtorch 2.10.0+cu128andtransformers 4.53.3first (4 min 17 s)sys.modules['depends']after collectingtest_embedding_image.pyandtool_git/test_tools.pyin one session__file__.../rocketlib-python/lib/depends.pynodes/testin one process (-m "not skip_node", no*_full, asbuilder nodes:test)depends, before thetool_gitfixtool_git/test_tools.pyleft['depends']; no other module or testdependsandengLibpinned,tool_gitfixed)tool_gitfix reverted, the guard namestool_git/test_tools.pyfordependsand, in a separate run, forengLibskip_nodeand*_fullincludedtool_git, every suite that stubsdependsorengLib) with-n 3, and in reversed ordertool_gitleavesdepends/engLibfor the session; built-in modules count as stubs;depends,engLibor both not pinnedWith the real
depends()active during the tests, the whole-nodes/testrun resolved the requirements ofrerank_cohere,store_chromaandstore_weaviate, which their tests load while they run, and installed 7 packages (authlib, cohere, fastavro, filelock, grpcio-health-checking, tokenizers, types-requests). On develop those calls did nothing. The run was not slower (2 min 42 s against 3 min 23 s on develop).ruff checkandruff format --check(0.16.5) pass on the changed files.Self-review checklist items checked: 3 (every path to a stub
depends/engLib: module level,setdefault, per test,patch.dict, attributes of the real module), 4 (the guard tests call the real hooks; the docstring's command run end to end), 7 and 11 (path table for_is_stub_module, a test per changed row), 13 (each changed file run with the wholenodes/testin one process), 21 and 26c (mutations show no test passes for the wrong reason), 29 (every guard test putssys.modulesback on every path), 30 and 34 (docstring and nesting tools).Known limit: the per-test check runs only for tests that run; the
*_fullandskip_nodetests were collected, not run, here (they need GPUs, models or databases).Checklist
Linked Issue
Fixes #3097
Summary by CodeRabbit