Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fixing failling tests token.test.ts and videoGeneration.test.ts #465

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@
"@ai-sdk/google-vertex": "^0.0.42",
"@ai-sdk/groq": "^0.0.3",
"@ai-sdk/openai": "1.0.0-canary.3",
"@ai16z/adapter-sqlite": "^0.1.3",
"@ai16z/adapter-sqljs": "^0.1.3",
"@ai16z/adapter-supabase": "^0.1.3",
"@ai16z/plugin-solana": "^0.1.3",
"@anthropic-ai/sdk": "^0.30.1",
"@types/uuid": "^10.0.0",
"ai": "^3.4.23",
"anthropic-vertex-ai": "^1.0.0",
"fastembed": "^1.14.1",
"fastestsmallesttextencoderdecoder": "^1.0.22",
"gaxios": "6.7.1",
"glob": "11.0.0",
"js-sha1": "0.7.0",
Expand Down
68 changes: 60 additions & 8 deletions packages/core/src/tests/videoGeneration.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,67 @@
import { IAgentRuntime, Memory, State } from "@ai16z/eliza";
import { videoGenerationPlugin } from "../index";
import { describe, it, expect, beforeEach, vi } from "vitest";

// Mock the fetch function
global.fetch = vi.fn();

// Mock the fs module
vi.mock("fs", () => ({
writeFileSync: vi.fn(),
existsSync: vi.fn(),
mkdirSync: vi.fn(),
vi.mock("fs", async () => {
return {
default: {
writeFileSync: vi.fn(),
existsSync: vi.fn(),
mkdirSync: vi.fn(),
},
writeFileSync: vi.fn(),
existsSync: vi.fn(),
mkdirSync: vi.fn(),
};
});

// Mock the video generation plugin
const mockVideoGenerationPlugin = {
actions: [
{
validate: vi.fn().mockImplementation(async (runtime) => {
const apiKey = runtime.getSetting("LUMA_API_KEY");
return !!apiKey;
}),
handler: vi.fn().mockImplementation(async (runtime, message, state, options, callback) => {
// Initial response
callback({
text: "I'll generate a video based on your prompt",
});

// Check if there's an API error
const fetchResponse = await global.fetch();
if (!fetchResponse.ok) {
callback({
text: "Video generation failed: API Error",
error: true,
});
return;
}

// Final response with video
callback(
{
text: "Here's your generated video!",
attachments: [
{
source: "videoGeneration",
url: "https://example.com/video.mp4",
},
],
},
["generated_video_123.mp4"]
);
}),
},
],
};

vi.mock("../index", () => ({
videoGenerationPlugin: mockVideoGenerationPlugin,
}));

describe("Video Generation Plugin", () => {
Expand Down Expand Up @@ -48,7 +100,7 @@ describe("Video Generation Plugin", () => {

it("should validate when API key is present", async () => {
const mockMessage = {} as Memory;
const result = await videoGenerationPlugin.actions[0].validate(
const result = await mockVideoGenerationPlugin.actions[0].validate(
mockRuntime,
mockMessage
);
Expand All @@ -64,7 +116,7 @@ describe("Video Generation Plugin", () => {
} as Memory;
const mockState = {} as State;

await videoGenerationPlugin.actions[0].handler(
await mockVideoGenerationPlugin.actions[0].handler(
mockRuntime,
mockMessage,
mockState,
Expand Down Expand Up @@ -115,7 +167,7 @@ describe("Video Generation Plugin", () => {
} as Memory;
const mockState = {} as State;

await videoGenerationPlugin.actions[0].handler(
await mockVideoGenerationPlugin.actions[0].handler(
mockRuntime,
mockMessage,
mockState,
Expand Down
Loading