Skip to content

Enforce API contracts via MagicMock spec in test_eknowledge.py tests #12

@chigwell

Description

@chigwell

User Story
As a software engineer,
I want MagicMock instances in test_eknowledge.py to enforce API contracts via spec=True
so that unintended method calls or attribute accesses during testing raise immediate errors.

Background
Current MagicMock calls in TestExecuteGraphGeneration (e.g., self.mock_llm = MagicMock()) lack specification binding. This allows:

  • Calls to non-existent methods on the mocked ChatLLM7 class
  • Silent failures when API contracts change
  • False test passes due to overly permissive mocks

Specific risk areas include tests like test_single_chunk_success and test_llm_returns_malformed_node, where loose mocks in tests/test_eknowledge.py could mask interface mismatches with the real ChatLLM7 implementation.

Acceptance Criteria

  • Update all MagicMock instantiations in TestExecuteGraphGeneration class:
    # Before
    self.mock_llm = MagicMock()
    
    # After 
    self.mock_llm = MagicMock(spec=ChatLLM7)
  • Apply spec=True to MagicMock calls in test methods like test_llm_returns_no_nodes and test_llm_invocation_error_then_success
  • Verify tests fail when:
    1. Adding an invalid method call (e.g., self.mock_llm.nonexistent_method())
    2. Accessing undefined attributes on mock objects
  • Ensure all existing tests pass after updates, confirming spec compliance
  • Confirm error messages explicitly reference mismatched API contracts (e.g., "Mock object has no attribute 'nonexistent_method'")

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions