diff --git a/bun.lock b/bun.lock index ed8b1892..1d06ec5f 100644 --- a/bun.lock +++ b/bun.lock @@ -188,6 +188,7 @@ "name": "@shumai/e2e", "version": "0.1.9", "dependencies": { + "@earendil-works/pi-agent-core": "0.78.0", "@shumai/agent": "workspace:*", "@shumai/core": "workspace:*", "@shumai/db": "workspace:*", diff --git a/packages/e2e/package.json b/packages/e2e/package.json index 733d0c70..104b50c6 100644 --- a/packages/e2e/package.json +++ b/packages/e2e/package.json @@ -9,6 +9,7 @@ "@shumai/workflow-core": "workspace:*", "@shumai/agent": "workspace:*", "@shumai/transcode": "workspace:*", - "@shumai/dtos": "workspace:*" + "@shumai/dtos": "workspace:*", + "@earendil-works/pi-agent-core": "0.78.0" } } diff --git a/packages/e2e/workflow/agent-autofill.test.ts b/packages/e2e/workflow/agent-autofill.test.ts index 056fbe5a..0d6d55cf 100644 --- a/packages/e2e/workflow/agent-autofill.test.ts +++ b/packages/e2e/workflow/agent-autofill.test.ts @@ -1,10 +1,11 @@ -import { describe, it, expect, beforeAll, afterAll } from 'vitest' +import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest' import { prisma } from '@shumai/db' import { setupTestDbHooks } from '@shumai/db/test' import { workflowService, TaskQueueAgent, TaskQueueTranscode } from '@shumai/workflow-core' import { initAgentWorkflows } from '@shumai/agent' import { initTranscodeWorkflows } from '@shumai/transcode' import { s3Service } from '@shumai/core/src/s3/s3' +import { AgentHarness, type AgentTool } from '@earendil-works/pi-agent-core' import { fileURLToPath } from 'url' import * as path from 'path' @@ -12,8 +13,6 @@ const currentDir = path.dirname(fileURLToPath(import.meta.url)) const agentWorkflowsPath = path.resolve(currentDir, '../../../apps/agent/src/workflows.ts') const transcodeWorkflowsPath = path.resolve(currentDir, '../../../apps/transcode/src/workflows.ts') -// No module mocks needed because we override activities directly in the global registry below - describe('Workflow E2E - agentAutofillMedia', () => { setupTestDbHooks() @@ -28,18 +27,28 @@ describe('Workflow E2E - agentAutofillMedia', () => { initAgentWorkflows() initTranscodeWorkflows() - // Override the AI activity with a mock implementation in the global registry - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const localActs = (globalThis as any).__localActivities - if (localActs) { - localActs.autofillAiActivity = async () => { - return { - text: JSON.stringify({ title: 'E2E Title Extracted' }), - usage: { inputTokens: 10, outputTokens: 20, model: 'gemini' }, - sessionId: 'mock-session-123', - } + // Spy on the harness prompt method to intercept the LLM call while running real activities & tools + vi.spyOn(AgentHarness.prototype, 'prompt').mockImplementation(async function ( + this: AgentHarness, + ) { + // Find the real autofill_metadata tool configured on the harness + const tools = this.getTools() + const autofillTool = tools.find((t: AgentTool) => t.name === 'autofill_metadata') + + if (autofillTool) { + // Execute the real tool callback to perform the actual DB updates + await autofillTool.execute('call-123', { title: 'E2E Title Extracted' }) } - } + + // Return a successful assistant response mock + /* eslint-disable @typescript-eslint/no-explicit-any -- Mock assistant response structure */ + return { + content: [{ type: 'text', text: 'Success' }], + usage: { input: 10, output: 20 }, + stopReason: 'stop', + } as any + /* eslint-enable @typescript-eslint/no-explicit-any */ + }) const type = process.env.WORKFLOW_EXECUTOR || 'local' if (type === 'temporal') { @@ -69,6 +78,9 @@ describe('Workflow E2E - agentAutofillMedia', () => { workflowService.close() + // Restore spied methods + vi.restoreAllMocks() + // Clean up E2E files in local filesystem storage try { console.log('Cleaning up local E2E storage files...')