added tests

This commit is contained in:
uinstinct 2025-05-23 11:40:09 +05:30
parent 971c4de33e
commit f09ada8d89

View file

@ -18,6 +18,18 @@ const TEST_EVENT: DevDataLogEvent = {
provider: "openai",
},
};
const TEST_AGENT_INTERACTION_EVENT: DevDataLogEvent = {
name: 'agentInteraction',
data: {
prompt: "Hello, world!",
completion: "Hello, world!",
modelProvider: "openai",
modelTitle: "gpt-4",
sessionId: "1234",
},
}
const SCHEMA = "0.2.0";
describe("DataLogger", () => {
@ -157,6 +169,21 @@ describe("DataLogger", () => {
expect(fileContent).toContain('"model":"gpt-4"');
expect(fileContent).toContain('"eventName":"tokensGenerated"');
});
it('should write agent interaction data to local file', async () => {
// Call the method to log data locally
await dataLogger.logLocalData(TEST_AGENT_INTERACTION_EVENT);
// Verify the file was created
const filepath = getDevDataFilePath(TEST_AGENT_INTERACTION_EVENT.name, SCHEMA);
expect(fs.existsSync(filepath)).toBe(true);
// Read file contents and verify
const fileContent = fs.readFileSync(filepath, "utf8");
expect(fileContent).toContain('"eventName":"agentInteraction"');
expect(fileContent).toContain('"prompt":"Hello, world!"');
expect(fileContent).toContain('"completion":"Hello, world!"');
})
});
describe("logDevData", () => {