diff --git a/core/data/log.test.ts b/core/data/log.test.ts index e2471b6bd..5e9bcce5f 100644 --- a/core/data/log.test.ts +++ b/core/data/log.test.ts @@ -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", () => {