Skip to content

Commit

Permalink
Merge pull request elizaOS#522 from ai16z-demirix/resolve-conflicts
Browse files Browse the repository at this point in the history
fix: fixing failing goals, cache and token tests
  • Loading branch information
lalalune authored Nov 25, 2024
2 parents 0ffa45c + 72dc145 commit c6a3bf9
Show file tree
Hide file tree
Showing 7 changed files with 368 additions and 231 deletions.
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"eslint": "9.13.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-vitest": "0.5.4",
"jest": "29.7.0",
"lint-staged": "15.2.10",
"nodemon": "3.1.7",
Expand Down
29 changes: 13 additions & 16 deletions packages/core/src/tests/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,41 @@
import { CacheManager, MemoryCacheAdapter } from "../cache.ts"; // Adjust the import based on your project structure
import { CacheManager, MemoryCacheAdapter } from "../cache.ts";
import { describe, it, expect, beforeEach, afterEach, vi } from "vitest";

// Now, let’s fix the test suite.

describe.only("CacheManager", () => {
describe("CacheManager", () => {
let cache: CacheManager<MemoryCacheAdapter>;

jest.useFakeTimers();

beforeEach(() => {
vi.useFakeTimers();
cache = new CacheManager(new MemoryCacheAdapter());
jest.setSystemTime(Date.now());
vi.setSystemTime(Date.now());
});

afterEach(() => {
vi.useRealTimers();
});

it("should set/get/delete cache", async () => {
await cache.set("foo", "bar");

expect(await cache.get("foo")).toEqual("bar");

expect(cache.adapter.data.get("foo")).toEqual(
JSON.stringify({ value: "bar", expires: 0 })
);

await cache.delete("foo");

expect(await cache.get("foo")).toEqual(undefined);
expect(cache.adapter.data.get("foo")).toEqual(undefined);
});

it("should set/get/delete cache with expiration", async () => {
const expires = Date.now() + 5 * 1000;
it("should handle expiring cache", async () => {
const expires = Date.now() + 1000;

await cache.set("foo", "bar", { expires: expires });
await cache.set("foo", "bar", { expires });

expect(await cache.get("foo")).toEqual("bar");

expect(cache.adapter.data.get("foo")).toEqual(
JSON.stringify({ value: "bar", expires: expires })
);

jest.setSystemTime(expires + 1000);
vi.setSystemTime(expires + 1000);

expect(await cache.get("foo")).toEqual(undefined);
expect(cache.adapter.data.get("foo")).toEqual(undefined);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tests/defaultCharacters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe("defaultCharacter", () => {
});

it("should have the correct modelProvider", () => {
expect(defaultCharacter.modelProvider).toBe(ModelProviderName.OPENAI);
expect(defaultCharacter.modelProvider).toBe(ModelProviderName.OLLAMA);
});

it("should have the correct voice model", () => {
Expand Down
Loading

0 comments on commit c6a3bf9

Please sign in to comment.