Repository navigation
Description
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
Agentand many Junior-owned modules - several integration suites inject a fake
AgentRunneror 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, orMessage - 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:checkbeyond module-mock syntax - reject fake runners, manufactured outcomes, Pi
Agentmocks, 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.tswith 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
Agentwith 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
Agentor Junior'sAgentRunnerbehavior - 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
test(agent): add fixed model output fixture (#1427)
test(slack): use typed Chat SDK fixtures (#1428)
test: enforce integration test boundaries (#1434)
test: run agent dispatch through real loop (#1436)
test: run child agent invocation through real loop (#1438)
test: run child concurrency through real agents (#1443)
test: run dispatch recovery through real agent (#1450)
test: run Slack continuation through real agent (#1452)
test: remove simulated Slack file resume coverage (#1459)
test: run OAuth Slack resume through real agent (#1466)
dcramer commentedon Aug 12, 2026
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:
StreamFnThese 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:The audit found two gaps in the enforcement and timeout proof:
completedAgentRunand two named scripted helpers, but it missed direct returnedawaiting_auth,suspended, andcompletedoutcomes. 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.The hardening follow-up keeps
neverRunAgentRunneras 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:
Recommended order:
test: harden agent integration boundaries (#1472)
test: run MCP tools through real agent loop (#1475)
test: run MCP OAuth callback through real agent (#1479)
dcramer commentedon Aug 14, 2026
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.