
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
simulacra-test
Advanced tools
A TypeScript framework for simulating and testing agent-based conversations in Jest. This framework allows you to create, run, and test conversational agents with both deterministic and LLM-powered behavior for testing purposes.
npm install simulacrasimulationTest in a file with a agent.test.ts extensionnpx jest agent.test.ts.Look at the examples for an example of a project setup to use the framework.
The framework provides two main ways to generate conversations:
DeterministicConversationGenerator for deterministic testsLLMConversationGenerator for testing with real language modelsHere's an example testing a customer support scenario:
simulationTest(
'should handle refund requests appropriately',
{
role: 'frustrated customer who recently purchased a faulty laptop',
task: 'You bought a laptop last week that keeps crashing. You have tried troubleshooting with tech support but nothing works. Now you want to request a refund.',
conversationGenerator: new LLMConversationGenerator(),
getAgentResponse: (simulationAgentState) => {
// Your agent logic here
return handleCustomerRequest(simulationAgentState.lastResponse?.content);
},
},
async ({ agent }) => {
// Test that refund handler was called
simulationExpect(agent.events, async () => {
expect(mockHandleRefund).toHaveBeenCalled();
}).eventually();
}
);
You can also use DeterministicConversationGenerator for to test a conversational agent with a specific set of messages:
simulationTest(
'should handle a specific conversation flow',
{
role: 'customer seeking technical support',
task: 'You need help with your printer that keeps jamming',
conversationGenerator: new DeterministicConversationGenerator([
{
role: "assistant",
content: "I understand you're having issues with a printer jam. Have you tried removing all paper and checking for debris?"
},
{
role: "assistant",
content: "Let's try resetting the printer. Please turn it off, wait 30 seconds, then turn it back on."
},
{
role: "assistant",
content: "Great! The printer should now be working correctly. Is there anything else you need help with?"
}
]),
getAgentResponse: (simulationAgentState) => handleTechSupport(simulationAgentState.lastResponse?.content)
},
async ({ agent }) => {
simulationExpect(agent.events, async () => {
expect(mockPrinterReset).toHaveBeenCalled();
}).eventually();
}
);
The framework provides powerful assertion capabilities through simulationExpect:
eventually(): Asserts a condition is true by the end of the simulation// Assert something happens by the end of a simulation
simulationExpect(simulationAgent.events, async (simulationAgent) => {
expect(simulationAgent.lastReceivedMessage?.content).toMatchSnapshot();
}).eventually();
always(): Asserts a condition remains true throughout the entire simulation// Assert something remains true throughout a simulation
simulationExpect(simulationAgent.events, async (simulationAgent) => {
expect(mockDeleteUserData.notToBeCalled()).toBe(true);
}).always();
when(condition): Asserts a condition when a specific state is met// Assert something when a condition is met during a simulation
simulationExpect(simulationAgent.events, async (simulationAgent) => {
expect(mockDeleteUserData).toBeCalled();
}).when(state => state.lastSimulationAgentResponse?.content === 'Please delete my data.');
MIT
FAQs
A framework for simulating and testing agent conversations
We found that simulacra-test demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.