Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ponderingdemocritus committed Nov 20, 2024
1 parent 9908001 commit 18c9fad
Show file tree
Hide file tree
Showing 19 changed files with 192 additions and 170 deletions.
2 changes: 1 addition & 1 deletion README_IT.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ pnpm install --include=optional sharp

## Cronologia Stelle

[![Grafico Cronologia Stelle](https://api.star-history.com/svg?repos=ai16z/eliza&type=Date)](https://star-history.com/#ai16z/eliza&Date)
[![Grafico Cronologia Stelle](https://api.star-history.com/svg?repos=ai16z/eliza&type=Date)](https://star-history.com/#ai16z/eliza&Date)
2 changes: 1 addition & 1 deletion agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function loadCharacters(
} catch (e) {
console.error(`Error loading character from ${path}: ${e}`);
// don't continue to load if a specified file is not found
process.exit(1)
process.exit(1);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions docs/docs/core/agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ await memoryManager.createMemory({
roomId,
});
```

---

## Further Reading
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/core/evaluators.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sidebar_position: 5

## Overview

Evaluators enable agents to:
Evaluators enable agents to:

- Build long-term memory
- Track goal progress
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import {
type Memory,
} from "./types.ts";
import { stringToUuid } from "./uuid.ts";
import { v4 as uuidv4 } from 'uuid';
import { v4 as uuidv4 } from "uuid";

/**
* Represents the runtime environment for an agent, handling message processing,
Expand Down
12 changes: 5 additions & 7 deletions packages/core/src/test_resources/createRuntime.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { SqliteDatabaseAdapter, loadVecExtensions } from "@ai16z/adapter-sqlite";
import {
SqliteDatabaseAdapter,
loadVecExtensions,
} from "@ai16z/adapter-sqlite";
import { SqlJsDatabaseAdapter } from "@ai16z/adapter-sqljs";
import { SupabaseDatabaseAdapter } from "@ai16z/adapter-supabase";
import { DatabaseAdapter } from "../database.ts";
import { AgentRuntime } from "../runtime.ts";
import {
Action,
Evaluator,
ModelProviderName,
Provider,
} from "../types.ts";
import { Action, Evaluator, ModelProviderName, Provider } from "../types.ts";
import {
SUPABASE_ANON_KEY,
SUPABASE_URL,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/test_resources/testSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import path from "path";

// Load test environment variables
const envPath = path.resolve(__dirname, "../../.env.test");
console.log('Current directory:', __dirname);
console.log('Trying to load env from:', envPath);
console.log("Current directory:", __dirname);
console.log("Trying to load env from:", envPath);
const result = dotenv.config({ path: envPath });
if (result.error) {
console.error('Error loading .env.test:', result.error);
console.error("Error loading .env.test:", result.error);
}
30 changes: 15 additions & 15 deletions packages/core/src/tests/env.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { describe, it, expect } from 'vitest';
import fs from 'fs';
import path from 'path';
import { describe, it, expect } from "vitest";
import fs from "fs";
import path from "path";

describe('Environment Setup', () => {
it('should verify .env.test file exists', () => {
describe("Environment Setup", () => {
it("should verify .env.test file exists", () => {
const possiblePaths = [
path.join(process.cwd(), '.env.test'),
path.join(process.cwd(), 'packages/core/.env.test'),
path.join(__dirname, '../../.env.test'),
path.join(__dirname, '../.env.test'),
path.join(__dirname, '.env.test'),
path.join(process.cwd(), ".env.test"),
path.join(process.cwd(), "packages/core/.env.test"),
path.join(__dirname, "../../.env.test"),
path.join(__dirname, "../.env.test"),
path.join(__dirname, ".env.test"),
];

console.log('Current working directory:', process.cwd());
console.log('__dirname:', __dirname);
const existingPaths = possiblePaths.filter(p => {
console.log("Current working directory:", process.cwd());
console.log("__dirname:", __dirname);

const existingPaths = possiblePaths.filter((p) => {
const exists = fs.existsSync(p);
console.log(`Path ${p} exists: ${exists}`);
return exists;
});

expect(existingPaths.length).toBeGreaterThan(0);
});
});
});
20 changes: 7 additions & 13 deletions packages/core/src/tests/goals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
State,
} from "../types";

import { describe, test, expect, beforeEach, vi } from 'vitest';
import { describe, test, expect, beforeEach, vi } from "vitest";

// Mock the database adapter
export const mockDatabaseAdapter = {
Expand Down Expand Up @@ -180,9 +180,7 @@ const sampleGoal: Goal = {

describe("getGoals", () => {
it("retrieves goals successfully", async () => {
(mockDatabaseAdapter.getGoals).mockResolvedValue([
sampleGoal,
]);
mockDatabaseAdapter.getGoals.mockResolvedValue([sampleGoal]);

const result = await getGoals({
runtime: mockRuntime,
Expand All @@ -199,7 +197,7 @@ describe("getGoals", () => {
});

it("handles failure to retrieve goals", async () => {
(mockDatabaseAdapter.getGoals).mockRejectedValue(
mockDatabaseAdapter.getGoals.mockRejectedValue(
new Error("Failed to retrieve goals")
);

Expand All @@ -225,9 +223,7 @@ describe("formatGoalsAsString", () => {

describe("updateGoal", () => {
it("updates a goal successfully", async () => {
(mockDatabaseAdapter.updateGoal).mockResolvedValue(
undefined
);
mockDatabaseAdapter.updateGoal.mockResolvedValue(undefined);

await expect(
updateGoal({ runtime: mockRuntime, goal: sampleGoal })
Expand All @@ -236,7 +232,7 @@ describe("updateGoal", () => {
});

it("handles failure to update a goal", async () => {
(mockDatabaseAdapter.updateGoal).mockRejectedValue(
mockDatabaseAdapter.updateGoal.mockRejectedValue(
new Error("Failed to update goal")
);

Expand All @@ -248,9 +244,7 @@ describe("updateGoal", () => {

describe("createGoal", () => {
it("creates a goal successfully", async () => {
(mockDatabaseAdapter.createGoal).mockResolvedValue(
undefined
);
mockDatabaseAdapter.createGoal.mockResolvedValue(undefined);

await expect(
createGoal({ runtime: mockRuntime, goal: sampleGoal })
Expand All @@ -259,7 +253,7 @@ describe("createGoal", () => {
});

it("handles failure to create a goal", async () => {
(mockDatabaseAdapter.createGoal).mockRejectedValue(
mockDatabaseAdapter.createGoal.mockRejectedValue(
new Error("Failed to create goal")
);

Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/tests/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
formatTimestamp,
} from "../messages.ts";
import { IAgentRuntime, Actor, Content, Memory, UUID } from "../types.ts";
import { describe, test, expect, vi, beforeAll } from 'vitest';
import { describe, test, expect, vi, beforeAll } from "vitest";

describe("Messages Library", () => {
let runtime: IAgentRuntime;
Expand Down Expand Up @@ -42,7 +42,9 @@ describe("Messages Library", () => {
const roomId: UUID = "room1234-1234-1234-1234-123456789abc" as UUID;

// Using vi.mocked() type assertion instead of jest.Mock casting
vi.mocked(runtime.databaseAdapter.getParticipantsForRoom).mockResolvedValue([userId]);
vi.mocked(
runtime.databaseAdapter.getParticipantsForRoom
).mockResolvedValue([userId]);
vi.mocked(runtime.databaseAdapter.getAccountById).mockResolvedValue({
id: userId,
name: "Test User",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tests/models.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getModel, getEndpoint } from "../models.ts";
import { ModelProviderName, ModelClass } from "../types.ts";
import { describe, test, expect, vi } from 'vitest';
import { describe, test, expect, vi } from "vitest";

vi.mock("../settings", () => {
return {
Expand All @@ -12,7 +12,7 @@ vi.mock("../settings", () => {
OPENROUTER_API_KEY: "mock-openrouter-key",
},
loadEnv: vi.fn(),
}
};
});

describe("Model Provider Tests", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/tests/relationships.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
formatRelationships,
} from "../relationships";
import { IAgentRuntime, type Relationship, type UUID } from "../types";
import { describe, expect, vi } from 'vitest';
import { describe, expect, vi } from "vitest";

// Mock runtime and databaseAdapter
const mockDatabaseAdapter = {
Expand Down
49 changes: 25 additions & 24 deletions packages/core/src/tests/token.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { createRuntime } from "../test_resources/createRuntime";
import { TokenProvider, WalletProvider } from "@ai16z/plugin-solana";
import { Connection, PublicKey } from "@solana/web3.js";
import { describe, test, expect, beforeEach, vi } from 'vitest';
import NodeCache from 'node-cache';
import { describe, test, expect, beforeEach, vi } from "vitest";
import NodeCache from "node-cache";

describe("TokenProvider Tests", async () => {
let tokenProvider: TokenProvider;
Expand All @@ -13,14 +13,14 @@ describe("TokenProvider Tests", async () => {
vi.clearAllMocks();

const { runtime } = await createRuntime({
env: process.env,
conversationLength: 10,
env: process.env,
conversationLength: 10,
});

const walletProvider = new WalletProvider(
new Connection(runtime.getSetting("RPC_URL")),
new PublicKey(runtime.getSetting("WALLET_PUBLIC_KEY"))
);
new Connection(runtime.getSetting("RPC_URL")),
new PublicKey(runtime.getSetting("WALLET_PUBLIC_KEY"))
);
// Create new instance of TokenProvider
tokenProvider = new TokenProvider(
"2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh",
Expand All @@ -31,31 +31,30 @@ describe("TokenProvider Tests", async () => {
(tokenProvider as any).cache.flushAll();
(tokenProvider as any).cache.close();
(tokenProvider as any).cache = new NodeCache();

// Mock the getCachedData method instead
vi.spyOn(tokenProvider as any, 'getCachedData').mockReturnValue(null);
vi.spyOn(tokenProvider as any, "getCachedData").mockReturnValue(null);
});

test("should fetch token security data", async () => {

// Mock the response for the fetchTokenSecurity call
const mockFetchResponse = {
success: true,
data: {
ownerBalance: "100",
creatorBalance: "50",
ownerPercentage: 10,
creatorPercentage: 5,
top10HolderBalance: "200",
top10HolderPercent: 20,
},
success: true,
data: {
ownerBalance: "100",
creatorBalance: "50",
ownerPercentage: 10,
creatorPercentage: 5,
top10HolderBalance: "200",
top10HolderPercent: 20,
},
};

// Mock fetchWithRetry function
const fetchSpy = vi
.spyOn(tokenProvider as any, "fetchWithRetry")
.mockResolvedValue(mockFetchResponse);
.spyOn(tokenProvider as any, "fetchWithRetry")
.mockResolvedValue(mockFetchResponse);

// Run the fetchTokenSecurity method
const securityData = await tokenProvider.fetchTokenSecurity();
// Check if the data returned is correct
Expand All @@ -70,7 +69,9 @@ describe("TokenProvider Tests", async () => {

// Ensure the mock was called with correct URL
expect(fetchSpy).toHaveBeenCalledWith(
expect.stringContaining("https://public-api.birdeye.so/defi/token_security?address=2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh"),
expect.stringContaining(
"https://public-api.birdeye.so/defi/token_security?address=2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh"
)
);
});
});
Loading

0 comments on commit 18c9fad

Please sign in to comment.