MODULE 12 · LESSON 12.5
Test agents, plugins, and lifecycle deterministically
Test the agent boundary without paying for model inference.
Lesson 72 of 86 · FabrCore 2.0
Overview
The testing harness supplies a fake agent host and model so routing, tools, state and lifecycle can be exercised deterministically. It is distinct from the runtime harness that manages todos and delegation. Tests should check observable behavior, not duplicate implementation details.
Fake inference keeps the expectation controlled
FabrCoreTestHarness and its fake Host/model let you specify inputs and expected tool behavior without relying on model wording or paid inference. This testing harness is different from the runtime harness that manages todos. Assert the external contract: which message was returned, which tool was invoked and what state changed.
Use integration tests for real infrastructure
A fake service cannot establish SQL recovery, WebSocket replay or Microsoft tenant consent. Test those boundaries against their real configured implementations in separate runs. Keeping the scopes explicit makes a failure easier to diagnose: a wrong-principal response is a contract bug, while an unreachable database is an infrastructure problem.
Write a deterministic boundary test
- Use FabrCoreTestHarness, FakeChatClient and TestFabrCoreAgentHost for a deterministic request and expected tool result.
- Add assertions for principal/handle routing, Args, system-message behavior, busy arrivals, state migration and trace propagation.
- Add integration tests for real Localhost/SQL providers, WebSocket replay/gaps and blueprint expansion where those boundaries matter. Inject time instead of waiting for wall-clock timers.
[TestClass]
public class MyAgentTests
{
[TestMethod]
public async Task OnMessage_ReturnsExpectedResponse()
{
using var harness = new FabrCoreTestHarness();
// Configure sequential LLM responses
var chatClient = FakeChatClient.WithSequentialResponses(
"""{"effort": "small", "reasoning": "Simple question"}""",
"The answer is 42."
);
var agent = harness.CreateMockAgent<MyAgent>(chatClient);
await harness.InitializeAgent(agent);
var response = await harness.SendMessage(agent, "What is the answer?");
Assert.IsNotNull(response.Message);
Assert.IsTrue(response.Message.Contains("42"));
}
}
Make the test fail for the right reason
- Run the illustrated deterministic test with a known SR-1042 fixture and an expected response/tool result. Confirm it passes without a model credential.
- Change the expected target or the fixture behavior deliberately in the test setup and verify the assertion fails with a useful description of the broken contract.
- Restore the correct behavior and add a denied/invalid-input case. The test should establish that the tool did not perform the forbidden effect, not merely that the agent returned an apologetic sentence.
The result is repeatable feedback on application behavior. It does not substitute for tests of real storage, transport or external provider compatibility.
If the result is different
A fake provider cannot establish database persistence or external tenant compatibility. Keep those in separate integration runs.
Go deeper
Explore the related documentation.