Skip to content

test(DATAGO-129265): Migrate repository unit tests to real DB integration tests #2#1274

Open
dylanwalsh-solace wants to merge 3 commits intomainfrom
dylanwalsh-solace/DATAGO-129265/internal-mocking-2
Open

test(DATAGO-129265): Migrate repository unit tests to real DB integration tests #2#1274
dylanwalsh-solace wants to merge 3 commits intomainfrom
dylanwalsh-solace/DATAGO-129265/internal-mocking-2

Conversation

@dylanwalsh-solace
Copy link
Copy Markdown
Contributor

@dylanwalsh-solace dylanwalsh-solace commented Mar 26, 2026

What is the purpose of this change?

DATAGO-129265 - Change included as part of a larger audit to improve testing across the community repo.

This PR addresses internal mocking issues identified in the test infrastructure audit. It migrates tests that were mocking internal repository/database operations to use real database integration tests, and improves assertion quality by verifying actual outcomes instead of mock interactions.

How was this change implemented?

Migrated to Integration Tests (New Files):

  1. test_task_repository_active_children.py - Replaces unit tests that mocked SQLAlchemy query chains. Now tests find_active_children() against real SQLite/PostgreSQL databases, properly verifying SQL NULL handling for active child tasks.
  2. test_session_service_integration.py - Replaces unit tests that mocked DB operations. Now tests move_session_to_project() with real database, verifying session.project_id updates persist correctly.
  3. test_task_logger_service_integration.py - Companion integration tests for TaskLoggerService's _save_chat_messages_for_background_task() method. Verifies task events are correctly reconstructed and saved to chat_tasks table.
  4. test_sse_buffer_integration.py - Companion integration tests for PersistentSSEEventBuffer. Verifies event buffering, flushing, and cleanup operations against real database (both normal and hybrid modes).

Assertion Improvements (Modified Files):

  • test_share_service_behaviours.py - Replaced repository.update_user_snapshot_time.assert_called_once() with actual verification that the returned timestamp is valid and repository was called with correct parameters.
  • test_share_access_control.py - Improved assertions to verify actual state changes rather than just mock interactions.

Deleted Files:

  • tests/unit/gateway/http_sse/repository/test_task_repository.py - Fully replaced by integration tests
  • tests/unit/services/test_session_service_move_to_project.py - Fully replaced by integration tests

All new integration tests use the existing DatabaseProvider infrastructure with SQLite and PostgreSQL test containers (via pytest parametrization).

Key Design Decisions (optional - delete if not applicable)

Why did you choose this approach over alternatives?

How was this change tested?

  • Manual testing: [describe scenarios]
  • Unit tests: [new/modified tests]
  • Integration tests: [if applicable]
  • Known limitations: [what wasn't tested]

Is there anything the reviewers should focus on/be aware of?

Special attention areas, potential risks, or open questions

@dylanwalsh-solace dylanwalsh-solace changed the base branch from main to dylanwalsh-solace/DATAGO-129265/internal-mocking March 26, 2026 16:18
@dylanwalsh-solace dylanwalsh-solace changed the title Dylanwalsh solace/datago 129265/internal mocking 2 test(DATAGO-129265): Migrate repository unit tests to real DB integration tests #2 Mar 26, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 26, 2026

✅ FOSSA Guard: Licensing (SolaceLabs_solace-agent-mesh) • PASSED

Compared against main (3a1867c128d18a5d63a16c81dd46f0edb63032ae) • 0 new, 6 total (6 in base)

Scan Report | View Details in FOSSA

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 26, 2026

✅ FOSSA Guard: Vulnerability (SolaceLabs_solace-agent-mesh) • PASSED

Compared against main (3a1867c128d18a5d63a16c81dd46f0edb63032ae) • 0 new, 4 total (4 in base)

Scan Report | View Details in FOSSA

@dylanwalsh-solace dylanwalsh-solace force-pushed the dylanwalsh-solace/DATAGO-129265/internal-mocking branch from 60f3218 to bd6f3e5 Compare March 26, 2026 19:28
@dylanwalsh-solace dylanwalsh-solace force-pushed the dylanwalsh-solace/DATAGO-129265/internal-mocking-2 branch from 05d1d39 to 95bf350 Compare March 26, 2026 20:01
@dylanwalsh-solace dylanwalsh-solace marked this pull request as ready for review March 26, 2026 20:50
Base automatically changed from dylanwalsh-solace/DATAGO-129265/internal-mocking to main March 30, 2026 18:29
@dylanwalsh-solace dylanwalsh-solace force-pushed the dylanwalsh-solace/DATAGO-129265/internal-mocking-2 branch from 95bf350 to ed44965 Compare March 31, 2026 11:57
@dylanwalsh-solace dylanwalsh-solace force-pushed the dylanwalsh-solace/DATAGO-129265/internal-mocking-2 branch from 35602c2 to 7e3ba06 Compare April 1, 2026 12:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the test-infrastructure migration away from fragile internal DB/repository mocking toward real database-backed integration tests, while also tightening some unit-test assertions to check outcomes/parameters rather than only mock interactions.

Changes:

  • Replaced mocked repository/unit tests with new integration tests that exercise real SQLite/PostgreSQL persistence for task repository, session move, task logger, and SSE buffer behavior.
  • Improved share-service/share-access unit test assertions to validate returned values and key call parameters rather than only “called once” checks.
  • Updated embed template-resolution unit tests to use sam_test_infrastructure’s in-memory artifact service.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
tests/unit/services/test_session_service_move_to_project.py Deleted mocked unit tests in favor of DB integration coverage.
tests/unit/gateway/http_sse/test_share_service_behaviours.py Assertion refactors around snapshot updates and formatting changes.
tests/unit/gateway/http_sse/test_share_access_control.py Assertion refactors for access control behaviors and router-level status mapping.
tests/unit/gateway/http_sse/repository/test_task_repository.py Deleted mocked SQLAlchemy-chain unit tests replaced by DB integration tests.
tests/unit/common/utils/embeds/test_automatic_template_resolution.py Switched to sam_test_infrastructure artifact service import and formatting tweaks.
tests/integration/apis/persistence/tasks/test_task_repository_active_children.py New DB integration coverage for TaskRepository.find_active_children() (NULL status + recursion).
tests/integration/apis/persistence/tasks/test_task_logger_service_integration.py New DB integration coverage for _save_chat_messages_for_background_task() persistence.
tests/integration/apis/persistence/sse_buffer/test_sse_buffer_integration.py New DB integration coverage for persistent SSE buffering (normal + hybrid).
tests/integration/apis/persistence/sessions/test_session_service_integration.py New DB integration coverage for move_session_to_project() persistence.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/unit/gateway/http_sse/test_share_access_control.py Outdated
Comment thread tests/integration/apis/persistence/sessions/test_session_service_integration.py Outdated
Comment thread tests/integration/apis/persistence/sessions/test_session_service_integration.py Outdated
Comment thread tests/unit/gateway/http_sse/test_share_service_behaviours.py
@sonarqube-solacecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants