Skip to content

Code-generate the backend mock to eliminate manual sync #517

@ako

Description

@ako

Problem

Adding a new backend method requires four coordinated edits: interface definition, MPR implementation, mock stub, and compile-time interface check. The mock (mdl/backend/mock/) is hand-written and the most error-prone step — an agent or contributor can miss it, causing compilation failures in unrelated tests.

The mock currently has 17 files for 26 sub-interfaces in FullBackend, indicating it is already drifting from the interface definitions.

Proposed solution

Replace the hand-written mock with one generated by mockgen (or moq) from the backend interfaces. The generated mock is always correct by construction — it can never drift.

Implementation steps

  1. Add mockgen or moq as a Go tool dependency (go install in tools.go)
  2. Add //go:generate mockgen ... directives to each interface file in mdl/backend/
  3. Add make mocks target that runs go generate ./mdl/backend/...
  4. Add generated mock files to .gitignore (same rationale as the generated parser: derived from source)
  5. Add make mocks step to CI before make test
  6. Delete hand-written mock files in mdl/backend/mock/

Expected outcome

Adding a new backend method requires only two edits: the interface and the MPR implementation. The mock is regenerated automatically. Interface drift is impossible.

See proposal: docs/11-proposals/PROPOSAL_agentic_architecture_improvements.md (Change 4)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions