Repository navigation
clean remaining mock session #44973
Description
The file-by-file list is below, scoped to SQLAlchemy session, engine, query and result doubles in
api/tests/unit_tests/on checkout1f500e52cc. This is not a count of everyMockor ORM-model stand-in: those would include unrelated external-service tests.I separated persistence scenarios from deliberate failure/no-DB tests so contributors do not remove useful coverage just to eliminate mocks.
Persistence scenarios to convert first
All paths below are relative to
api/tests/unit_tests/.
File Remaining double / change to make tasks/test_remove_app_and_related_data_task.py_FakeSessionFactoryqueues fabricated SQL results. Seed offload/upload records and assert deletion against SQLite; preserve the storage-outside-transaction check. [1]services/agent/test_home_snapshot_service.py_apply_with_client_erroruses a mocked session and aSimpleNamespacelookup result. Seed the lookup record before exercising the backend error. [2]services/agent/test_workflow_publish_service.pyPublished-binding copy uses mocked scalar/scalarsresults and inspectssession.add. Persist the agent and bindings, then query the copied binding. [3]services/agent/test_knowledge_gateway.py_ScalarsSessionreturns preloaded snapshots without executing the query. Replace it with persisted snapshots. [4]services/test_agent_service.py_ScriptedSessionreturns conversation/message/account results in call order and ignores SQL. Seed the real ownership chain. [5]services/knowledge_fs/test_query_images.py_Sessionand_install_filesbypass file lookup and commit behavior. Persist upload/tool-file records instead. [6]services/knowledge_fs/test_service_query_image_upload.py_Sessionmanually interprets compiled query parameters and records adds/commits. Exercise token lookup and upload persistence through SQLite. [7]services/knowledge_fs/test_revocation_commands.pyScriptedSessionexplicitly ignores statements and replays queued results. Seed authorization/revocation records. [8]services/test_skill_management_service.pyRuntime skill listing fabricates the joined rows returned by session.execute. Seed binding, skill, version and tool-file rows. [9]services/tools/test_mcp_tools_manage_service.pyThe shared sessionfixture is aMock; lookup tests inspect SQL strings. Use persisted providers and decoy tenants/identifiers to verify actual lookup behavior. [10]services/test_app_package_service.pyIcon import captures add_allarguments from a mocked session. Query the persisted destination-owned upload instead. [11]core/app/task_pipeline/test_easy_ui_based_generate_task_pipeline.pyLocal _Session/_Resultclasses return message/upload rows by call order. Replace these with persisted file associations. [12]core/rag/retrieval/test_dataset_retrieval.pyThe foreign-dataset rejection test still supplies a fabricated session.scalarresult. Persist both allowed and foreign datasets. Keep deadlock injection as a separate concern. [13] [14]core/workflow/nodes/agent/test_message_transformer.pyTool-file lookup uses mocked Sessioncontexts and fabricated metadata. Seed existing/missing tool-file cases. [15]controllers/console/app/test_workflow.pyPublish/delete tests replace sessions and transaction contexts. Use real app/workflow rows and real transactions where testing persistence. [16] controllers/console/datasets/rag_pipeline/test_rag_pipeline_workflow.pyNode-execution response construction uses a mocked session returning None. Build the response with a real session. [17]controllers/common/test_access_response.pyMCP request cases script session.scalarresponses. Seed MCP server/app records for lookup-backed cases. [18]Additional files with DB doubles, but not blanket persistence migrations
These need a narrower decision at the individual test level:
File Treatment services/test_app_dsl_service.pyMocked session verifies validation exits before mutation. Consider unbound_session, retaining the early-exit assertion. [19]services/test_app_generate_service.pyA session mock is passed through to a mocked workflow lookup. Replace the placeholder with a real/unbound session rather than adding unnecessary persistence. [20] services/test_snippet_service.pyRepository-delegation test installs mocked session/factory placeholders. Replace these without changing the repository-boundary scope. [21] services/test_workflow_event_snapshot_service.pyMock represents a legacy message with created_at=None. Preserve that compatibility case; do not force it into normal-schema persistence without checking whether that row is representable. [22]services/enterprise/test_rbac_service.py_RecordingSessionverifies remote/commit/close ordering. A real session plus lifecycle observation could replace it, but preserve ordering coverage. [23]services/tools/test_tools_transform_service.pyPatches db.sessionwhile mocking the provider controller. This is boundary wiring, not SQL-result fabrication. Use a real session and model if cleaning up this slice. [24]services/rag_pipeline/test_rag_pipeline_task_proxy.pyUses a fake engine / mocked dbwhileFileServiceis mocked. Replace the engine placeholder, or expand coverage to real upload persistence as a separate change. [25] [26]services/knowledge/segments/test_adapters.pyAutospecced session verifies an ownership mismatch does not commit. Candidate for unbound_session, not a full persistence migration. [27]core/app/apps/agent_app/test_app_runner.pyMocked session injects a database failure and verifies rollback. Preserve failure injection. [28] core/workflow/nodes/agent_v2/test_validators.pyMocked session verifies legacy agent nodes trigger no query. Candidate for unbound_session. [29]controllers/openapi/test_app_run.pyMocked session verifies streaming does not commit. Preserve that lifecycle invariant when replacing the mock. [30] controllers/openapi/auth/test_router.py_OneRowSessiondeliberately handles an aware-timestamp expiry case that the file documents as incompatible with SQLite timestamp round-tripping. Not a mechanical SQLite conversion. [31]repositories/data_source/test_credential_repository.pyAutospecced session supports MySQL/PostgreSQL/SQLite SQL-compilation assertions. Keep dialect coverage separate from persistence tests. [32] Use
sqlite_session/sqlite_session_factoryfor real persistence, andunbound_sessionfor paths that must not touch the database. Both are already provided centrally. [33]This is the complete verified list from this static pass, not proof that arbitrary aliases or ORM-only stand-ins elsewhere are absent. I have not run the tests.
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
Activity
GYJ99 commentedon Oct 28, 2026
Hi maintainers, I'd like to take one independent, test-only slice of #44973:
api/tests/unit_tests/services/agent/test_home_snapshot_service.py, specifically the_apply_with_client_errorhelper and its 502/413 error-path tests. Would you be comfortable assigning/confirming this slice for @GYJ99?I checked the current test and production
AgentHomeSnapshotService.create_for_build_applypaths. The helper currently uses a mocked session whosescalar()returns a fabricated agent; this file already has_persist_build_binding()and sharedsqlite_sessionfixtures for real Agent/Workspace/Binding records. I propose seeding those records, exercising the actual agent lookup while preserving backend-error injection and existing error mapping assertions, and adding a tenant/agent mismatch negative case if it covers a meaningful lookup regression.I found #44978 (knowledge-gateway snapshots) and #44980 (query-image fixtures), but neither touches this file. I would keep the change confined to this module, run its focused pytest suite plus Ruff/type checks before a PR, and document any test environment limitation. This is a code-level plan, not a claim of completed local tests. AI assistance (ChatGPT) was used for issue/code triage.
hjeesum commentedon Oct 28, 2026
Hey, I’d like to take three small, independent files from #44973, and I’ll open a separate PR for each:
core/workflow/nodes/agent_v2/test_validators.py (second table): swap the mocked session for the shared unbound_session fixture, keeping the “no query is made” assertion.
controllers/console/datasets/rag_pipeline/test_rag_pipeline_workflow.py: replace the mocked session that returns None with a real session when building the node-execution response.
core/workflow/nodes/agent/test_message_transformer.py: seed real tool-file rows for the existing and missing cases instead of mocked Session contexts.
Each change will stay within its own file. I’ll run the file’s tests plus ruff check and ruff format --check before every PR and link back here. Could a maintainer assign these to @hjeesum, or tell me if I should leave any of them?
hjeesum commentedon Oct 28, 2026
Opened PRs for the three files I claimed:
agent_v2/test_validators.py: test: use unbound_session for legacy agent node validator test #44996rag_pipeline/test_rag_pipeline_workflow.py: test: use sqlite_session in node execution list test #44998agent/test_message_transformer.py: test: use sqlite_session for tool file lookups in message transformer tests #45000test(knowledge-fs): run revocation producer queries on SQLite rows
tech00exploere commentedon Oct 29, 2026
Hi maintainers, I've opened PR #45081 for the
api/tests/unit_tests/services/agent/test_workflow_publish_service.pyslice of #44973.It migrates
test_publish_copy_uses_current_roster_snapshotfrom mocked sessions to SQLite-backed persistence (sqlite_session), with all 13 tests in the module passing locally and Ruff checks verified.lj1166 commentedon Oct 30, 2026
Hi maintainers, I would like to take one independent, test-only slice of #44973:
api/tests/unit_tests/services/test_app_generate_service.py, specifically the case described in the inventory where a mocked session is passed through to a mocked workflow lookup.I will keep the scope limited to replacing the placeholder session/factory with the existing
unbound_sessionfixture where the path must not access the database, without broadening this into a persistence migration or changing production code. Before opening a PR, I will run the focused test file and the required lint/format checks, then report the actual results.AI assistance is being used for code navigation and test work; I will review and verify the submitted change.
test(api): seed real SQLite rows for message-end file payloads
lj1166 commentedon Oct 30, 2026
The
test_app_generate_service.pyslice I claimed is already covered by merged PR #45130, which now uses the sharedunbound_sessionfixture. I am withdrawing this slice to avoid duplicate work.jdabid commentedon Oct 30, 2026
Hi maintainers, I'd like to take the
api/tests/unit_tests/services/knowledge/segments/test_adapters.pyslice of #44973 (test_legacy_segment_mutation_rejects_mismatched_rows_before_dispatch), replacing the autospeccedSessionmock with the sharedunbound_sessionfixture while preserving themutations.update_segment.assert_not_called()and transaction-state checks.test(knowledge): use unbound_session in segment adapter ownership test (