Skip to content

Make core agent tests integration-first #1425

Closed

Description

@dcramer

Objective

Make integration tests the primary owner for Junior's core agent behavior.

The core test path should run the real Junior runtime, Pi agent loop, tools, persistence, task execution, and recovery. Tests may fake Slack. Deterministic tests may also fake model output at the model stream boundary. They must not replace Junior-owned runtime behavior to simulate a product workflow.

This applies first to:

  • task execution and durable turns
  • the core agent loop
  • MCP discovery, activation, calls, and authorization
  • generic and MCP OAuth

Why

The repository policy already prefers this design, and packages/junior/tests/integration/durable-queue.test.ts is a strong reference. It drives signed Slack ingress through the mailbox, queue callback, lease, worker, real agent loop, persistence, and Slack delivery. It fakes only the model stream and Slack HTTP for most cases.

Other core coverage does not meet the same standard:

  • several component suites replace Pi's Agent and many Junior-owned modules
  • several integration suites inject a fake AgentRunner or manufacture a completed run
  • the current MCP dynamic-tools integration test rebuilds the bridge tools in the test instead of running Junior's MCP wiring
  • OAuth behavior is split across heavily mocked unit tests, callback tests with fake runners, and live-model evals
  • shared Slack fixtures use unsafe casts instead of a strongly typed boundary
  • the architecture check only rejects vi.mock("@/...") in integration files, so it reports success while broader runtime replacement remains possible
  • strict and behavioral eval workflows do not run automatically for most changes under packages/junior/src/**

The result is too much coverage of simulated implementations and too little coverage of the system we ship.

Test model

Deterministic core integration tests

Use these for the large, mandatory suite of fixed product contracts.

  • use the real Junior composition and agent loop
  • fake Slack through shared typed inbound fixtures, MSW, and an outbound outbox
  • fake model output only through Pi's StreamFn
  • run real Junior tools, hooks, prompt construction, history conversion, delivery, and terminalization
  • use real SQL storage and the production state or queue port implementation required by the contract
  • run external MCP and OAuth dependencies as local protocol fixtures or MSW servers
  • assert visible replies, external requests, durable history, checkpoints, and terminal state

The scripted model fixture must support plain replies, tool calls, multiple model turns, provider errors, hangs, aborts, and empty or invalid frames. It must not manufacture an AgentRunOutcome.

Curated live-model integration evals

Keep a smaller set of critical normal-loop journeys with a pinned real model.

These cases should cover behavior that depends on model reading or choice, such as:

  • choosing and calling the correct tool
  • MCP discovery and use
  • starting and continuing authorization
  • conversation continuity
  • durable continuation after yield or timeout
  • delegated agent work

Use direct assertions for fixed tool, persistence, authorization, and delivery effects. Use rubric judges only for nondeterministic visible text. These cases are hard pass/fail.

Behavioral evals

Keep the broader real-model suite for bounded quality measurement and aggregate gating. Do not use it as the only owner of fixed runtime behavior.

Unit and component tests

Keep these for distinct local contracts such as parsing, normalization, retry math, schemas, and small state transitions.

A narrow component test may fake an AgentRunner when the runner itself is the external boundary under test. It must not be the primary proof of a product journey. Each product contract should have one primary owning layer.

Hard constraints

For primary core integration tests:

  • do not mock Junior-owned modules
  • do not replace Pi's Agent
  • do not inject a fake AgentRunner
  • do not manufacture completed agent outcomes
  • control model behavior only through StreamFn
  • use shared strongly typed Slack fixtures; do not cast partial objects to SlackAdapter, Thread, or Message
  • keep Junior-owned task execution, recovery, authorization, MCP, tools, and persistence real
  • fake external services at their protocol boundary, not by replacing Junior-owned clients or orchestration
  • assert product outcomes before callbacks, logs, spans, or implementation steps

Add enforcement with a temporary explicit debt list. New violations fail immediately. The debt list may only shrink.

High-level plan

1. Build the shared integration fixture

  • extract the proven model-stream pattern from durable-queue.test.ts
  • provide scripted model sequences through StreamFn
  • use the real Junior Slack adapter with signed webhook builders and MSW
  • provide typed Slack identifiers, events, messages, responses, and an outbound outbox
  • compose the real runtime, worker, agent, SQL store, state, and queue ports
  • provide local MCP and OAuth protocol fixtures

2. Enforce the boundary

  • extend test-architecture:check beyond module-mock syntax
  • reject fake runners, manufactured outcomes, Pi Agent mocks, and unsafe Slack casts in core integration tests
  • add a reviewed debt manifest for existing files
  • document the allowed fake edges in the test README

3. Make durable execution the first vertical slice

  • finish aligning durable-queue.test.ts with the constraint
  • move narrow runner-boundary cases to component coverage when needed
  • migrate representative dispatch and agent invocation journeys to the real agent loop
  • preserve only distinct low-level store and lock tests

4. Replace simulated core agent suites

  • migrate retry, continuation, handoff, compaction, timeout, abort, steering, and tool lifecycle behavior to the real Pi Agent with scripted model streams
  • delete custom test implementations of Pi's agent lifecycle
  • delete duplicate lower-fidelity cases after equal or higher-fidelity coverage exists

5. Rebuild MCP coverage through Junior

  • replace the handcrafted dynamic-tools integration test with the real Junior plugin and MCP path
  • exercise discovery, activation, search, call, result conversion, tool annotations, history, and cleanup
  • cover authorization and session behavior with a local MCP server
  • keep unit tests only for fixed local transforms and validation

6. Consolidate OAuth journeys

Add deterministic full journeys for:

  • generic OAuth pause, private link, callback, token storage, queue wake, same-turn continuation, tool retry, and final reply
  • the equivalent MCP OAuth flow
  • token refresh during a normal turn
  • replayed, expired, mismatched, consumed, and wrong-actor callbacks with no unauthorized state change
  • Slack and local continuation where their contracts differ

Retain unit coverage for state parsing, signatures, PKCE, and fixed response normalization.

7. Curate and trigger live-model coverage

  • define the small set of critical strict integration evals
  • run relevant strict evals automatically for changes to core runtime, MCP, OAuth, task execution, tools, prompts, and harness code
  • keep broader behavioral evals aggregate-gated
  • make ownership and failure triage clear for every curated case

Acceptance criteria

  • primary contracts for task execution, the agent loop, MCP, and OAuth have full integration owners
  • deterministic integration tests fake no more than Slack and the model stream
  • no primary integration test replaces Pi's Agent or Junior's AgentRunner behavior
  • Slack fixtures are strongly typed and shared
  • MCP integration tests run Junior's real MCP implementation
  • OAuth integration tests prove pause and continuation through the same durable turn
  • core source changes automatically select the relevant strict evals
  • the architecture check prevents new low-fidelity core tests
  • lower-fidelity duplicate tests are removed as each area migrates
  • test runtime and reliability remain practical for required pull request checks

Non-goals

  • do not ban all unit or component tests
  • do not require a real model for fixed runtime contracts
  • do not call the real Slack API in tests
  • do not change production architecture only to expose test-only dependency injection
  • do not rewrite every suite in one pull request
  • do not duplicate one behavior at every test layer

Activity

  1. dcramer commented on Aug 12, 2026

    @dcramer
    MemberAuthor

    Audit checkpoint — 2026-08-12

    We paused after #1466 and reviewed the integration-test work as one program.

    What is now complete

    The merged work in #1427, #1428, #1434, #1436, #1438, #1441, #1443, #1450, #1452, #1459, and #1466 added or improved:

    • fixed model output through Pi's StreamFn
    • shared typed Slack fixtures
    • test architecture enforcement and an exact debt list
    • real agent execution for dispatch, child invocation, concurrency, recovery, Slack continuation, and OAuth Slack resume
    • real tool execution across durable pause and resume
    • removal or relocation of lower-confidence tests whose primary contract belongs elsewhere

    These changes are a real accuracy gain. The migrated tests now cover Junior's prompt assembly, Pi events, tool calls, history, persistence, replay, and delivery. They do not only replace one fake with another. The work also found an impossible source and destination fixture and a missing runtime event assertion.

    The seven main migrated integration files currently pass together: 48 tests in about 17 seconds.

    Policy review

    The migrated slices follow policies/testing.md:

    • product behavior runs through real Junior wiring
    • Slack stays at the shared fake edge
    • fixed model behavior enters through the model stream
    • narrow fixed runtime contracts moved to component tests when full product wiring did not add proof
    • duplicate or misleading lower-confidence coverage was removed

    The audit found two gaps in the enforcement and timeout proof:

    1. The architecture check counted completedAgentRun and two named scripted helpers, but it missed direct returned awaiting_auth, suspended, and completed outcomes. Main recorded 102 references. The audit found 10 more direct returned outcomes. The corrected current baseline is 112 references: 98 manufactured-outcome references and 14 scripted-runner references. This is a corrected count, not new test debt.
    2. The OAuth Slack resume timeout test proved the visible failure reply but did not prove that the real agent stopped. The current hardening follow-up passes an abort signal into the run, aborts it on timeout, waits for settlement, and checks that settlement happens before failure handling.

    The hardening follow-up keeps neverRunAgentRunner as an allowed guard because it fails if a path reaches agent execution. It does not manufacture an outcome.

    Remaining work

    The issue is not ready to close. The main gaps are:

    • full generic OAuth pause, callback, token storage, wake, same-turn tool retry, and final reply
    • the same full journey for MCP OAuth
    • real Junior MCP discovery, activation, call, result, history, and cleanup coverage
    • remaining fake-runner debt, mainly in local-agent and Slack event suites
    • curated live-model integration evals and automatic selection for core changes

    Recommended order:

    1. Merge the enforcement and timeout hardening follow-up.
    2. Add the full MCP and OAuth pause-and-resume integration owner.
    3. Continue with the remaining Slack and local-agent debt in bounded groups.
    4. Add the curated live-model cases after the fixed runtime journeys have clear owners.
  2. dcramer commented on Aug 14, 2026

    @dcramer
    MemberAuthor

    Closing this work as complete. Core integration tests now run the real Junior runtime and Pi agent loop, with fixed model output supplied at the model stream boundary. Slack fixtures are typed, MCP and OAuth flows use real Junior wiring, durable execution has full integration owners, the architecture check blocks the old low-confidence patterns, and the temporary debt file is gone.

    The remaining large-file splits and isolated internal-service test cleanup are normal maintenance. They do not block this objective.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions