Skip to content

test(fork-sync): reflective mock factory for fork-boundary modules (Option 3 — DEFERRED) #2439

@alexey-pelykh

Description

@alexey-pelykh

Status

DEFERRED — see Revisit Conditions below. Tracked for visibility, not actively scheduled.

Problem (when revisited)

Hand-written mocks in tests diverge silently from real module implementations. A factory that imports the real module, asserts each export's shape, then substitutes behavior would fail-fast at test setup when the real module's contract changes incompatibly.

Proposed solution (when revisited)

Replace inline vi.mock("../../agents/agent-scope.js", () => ({...})) with:

import { mockAgentScope } from "../../../test/mock-factories/agent-scope.js";
mockAgentScope({ runtime: "claude" });

Internally the factory imports the real module, asserts each export's shape (e.g., assertCallable(mod.resolveAgentRuntimeOrThrow, { returns: "string" })), then substitutes. When the real module's contract changes (e.g., resolveAgentRuntimeOrThrow becomes : never), the assertion fails at test setup time → all dependent tests fail → CI red.

Why deferred

  • Migration cost — 5+ test files for agent-scope alone, growing per fork-boundary module
  • Benefit largely subsumed by the attestation manifest (other child issue of meta(fork-sync): hardening architecture epic — prevent #2408-class regressions #2433) at lower cost
  • "Shape assertion" is a second source of truth competing with TypeScript types — risks brittleness
  • Requires the mock-allowlist (other deferred child issue) to enforce factory usage on new tests

Revisit when

Effort (estimated when revisited)

3-5 days first module + factory; ongoing per-module (~1 day each).

Dependencies

Tracked under: #2433
Companion: mock-allowlist (other deferred child issue of #2433) — would be required to enforce factory usage

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestneeds-discussionApproach is opinionated or uncertain — needs team alignment before implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions