createHarness creates a unique temporary directory for each harness instance using tmpdir() + timestamp + random suffix, providing test isolation for file-system operations.[1] When persistSession is false (the default), createHarness uses SessionManager.inMemory(); when true, it creates a file-backed SessionManager rooted at a temporary directory under sessions/.[1] The default system prompt used when creating an Agent in createHarness is "You are a test assistant.", overridable via HarnessOptions.systemPrompt.[1] FauxProviderRegistration is a test-only stand-in for a real AI model provider that supplies scripted responses instead of making live network calls, keeping tests fast, deterministic, and offline-capable.
HarnessOptions supports rlmDepth and rlmMaxDepth fields that are passed directly to AgentSession, enabling tests to configure subagent recursion depth limits.[1] The Agent constructed in createHarness wires three lifecycle hooks — onPayload (before provider request), onResponse (after provider response), and transformContext (message context transformation) — all delegated through the ExtensionRunner if handlers are registered.[1]
The Harness interface exposes setResponses, appendResponses, and getPendingResponseCount methods, all delegated directly to the underlying FauxProviderRegistration, for controlling faux model responses in tests.[1] The Harness interface exposes eventsOfType<T>(type), a type-narrowed helper that returns only events of the specified AgentSessionEvent discriminant type from the session's event log.[1]
The getMessageText helper in packages/coding-agent/test/suite/harness.ts handles both string content and structured content arrays, joining all type: "text" parts with newlines.[1] getUserTexts(harness) and getAssistantTexts(harness) are test utility functions in packages/coding-agent/test/suite/harness.ts that filter harness.session.messages by role and extract plain text from each message via getMessageText.[1]
Sources