Skip to content

Commit c93510c

Browse files
committed
test running
1 parent d778e60 commit c93510c

32 files changed

+1862
-117
lines changed

packages/core/.env.test

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
TEST_DATABASE_CLIENT=sqlite
22
NODE_ENV=test
3+
MAIN_WALLET_ADDRESS=testwalletaddressfM3U31goWWrCpF59CHWNhnCJ9Vyh
4+
OPENAI_API_KEY=OPENAI_TEST_KEY
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"data":[],"expiry":1731784276120}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"data":{"ownerBalance":"100","creatorBalance":"50","ownerPercentage":10,"creatorPercentage":5,"top10HolderBalance":"200","top10HolderPercent":20},"expiry":1731784617753}

packages/core/jest.config.js

-29
This file was deleted.

packages/core/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
"watch": "tsc --watch",
1212
"dev": "tsup --format esm --dts --watch",
1313
"build:docs": "cd docs && pnpm run build",
14-
"test": "vitest run",
15-
"test:watch": "vitest"
14+
"test": "NODE_ENV=test vitest run",
15+
"test:watch": "NODE_ENV=test vitest"
1616
},
1717
"author": "",
1818
"license": "MIT",

packages/core/src/embedding.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { models } from "./models.ts";
55
import { IAgentRuntime, ModelProviderName, ModelClass } from "./types.ts";
66
import fs from "fs";
77
import { trimTokens } from "./generation.ts";
8-
import settings from "./settings.ts";
8+
import { settings } from "./settings.ts";
99

1010
function getRootPath() {
1111
const __filename = fileURLToPath(import.meta.url);

packages/core/src/generation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
parseJSONObjectFromText,
2323
parseShouldRespondFromText,
2424
} from "./parsing.ts";
25-
import settings from "./settings.ts";
25+
import { settings } from "./settings.ts";
2626
import {
2727
Content,
2828
IAgentRuntime,

packages/core/src/models.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import settings from "./settings.ts";
1+
import { settings } from "./settings.ts";
22
import { Models, ModelProviderName, ModelClass } from "./types.ts";
33

44
export const models: Models = {

packages/core/src/runtime.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { formatActors, formatMessages, getActorDetails } from "./messages.ts";
2020
import { parseJsonArrayFromText } from "./parsing.ts";
2121
import { formatPosts } from "./posts.ts";
2222
import { getProviders } from "./providers.ts";
23-
import settings from "./settings.ts";
23+
import { settings } from "./settings.ts";
2424
import {
2525
Character,
2626
Goal,

packages/core/src/settings.ts

+58-18
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,94 @@ import { config } from "dotenv";
22
import fs from "fs";
33
import path from "path";
44

5+
export interface Settings {
6+
MAIN_WALLET_ADDRESS: string;
7+
OPENAI_API_KEY: string;
8+
USE_OPENAI_EMBEDDING: string;
9+
SYSTEM_PROMPT: string;
10+
OPENROUTER_MODEL: string;
11+
SMALL_OPENROUTER_MODEL: string;
12+
MEDIUM_OPENROUTER_MODEL: string;
13+
LARGE_OPENROUTER_MODEL: string;
14+
OLLAMA_MODEL: string;
15+
LARGE_OLLAMA_MODEL: string;
16+
MEDIUM_OLLAMA_MODEL: string;
17+
SMALL_OLLAMA_MODEL: string;
18+
OLLAMA_SERVER_URL: string;
19+
OLLAMA_EMBEDDING_MODEL: string;
20+
RPC_URL: string;
21+
BASE_MINT: string;
22+
BACKEND_URL: string;
23+
BACKEND_TOKEN: string;
24+
BIRDEYE_API_KEY: string;
25+
HELIUS_API_KEY: string;
26+
SERVER_PORT: string;
27+
CAPSOLVER_API_KEY: string;
28+
CUDA_PATH: string;
29+
}
30+
531
/**
632
* Recursively searches for a .env file starting from the current directory
733
* and moving up through parent directories
8-
* @param {string} [startDir=process.cwd()] - Starting directory for the search
9-
* @returns {string|null} Path to the nearest .env file or null if not found
1034
*/
1135
export function findNearestEnvFile(startDir = process.cwd()) {
36+
console.error('DEBUG - Starting env file search');
37+
console.error('DEBUG - Current working directory:', process.cwd());
38+
39+
// In test environment, use the known working path
40+
if (process.env.NODE_ENV === 'test' || process.env.VITEST) {
41+
const testPath = path.join(process.cwd(), '.env.test');
42+
console.error('DEBUG - Checking test path:', testPath);
43+
if (fs.existsSync(testPath)) {
44+
console.error('DEBUG - Found test env file at:', testPath);
45+
return testPath;
46+
}
47+
}
48+
49+
// Look for regular .env
1250
let currentDir = startDir;
51+
const envFile = process.env.NODE_ENV === 'test' ? '.env.test' : '.env';
1352

14-
// Continue searching until we reach the root directory
1553
while (currentDir !== path.parse(currentDir).root) {
16-
const envPath = path.join(currentDir, ".env");
17-
54+
const envPath = path.join(currentDir, envFile);
55+
console.error('DEBUG - Checking path:', envPath);
1856
if (fs.existsSync(envPath)) {
57+
console.error('DEBUG - Found env file at:', envPath);
1958
return envPath;
2059
}
21-
22-
// Move up to parent directory
2360
currentDir = path.dirname(currentDir);
2461
}
2562

26-
// Check root directory as well
27-
const rootEnvPath = path.join(path.parse(currentDir).root, ".env");
28-
return fs.existsSync(rootEnvPath) ? rootEnvPath : null;
63+
console.error('DEBUG - No env file found after checking all paths');
64+
console.error('DEBUG - Final cwd:', process.cwd());
65+
console.error('DEBUG - Final NODE_ENV:', process.env.NODE_ENV);
66+
return null;
2967
}
3068

3169
/**
3270
* Loads environment variables from the nearest .env file
33-
* @returns {Object} Environment variables object
34-
* @throws {Error} If no .env file is found
3571
*/
3672
export function loadEnvConfig() {
73+
console.error('DEBUG - loadEnvConfig called');
74+
console.error('DEBUG - Current working directory:', process.cwd());
75+
console.error('DEBUG - NODE_ENV:', process.env.NODE_ENV);
76+
3777
const envPath = findNearestEnvFile();
3878

3979
if (!envPath) {
4080
throw new Error("No .env file found in current or parent directories.");
4181
}
4282

43-
// Load the .env file
83+
console.error('DEBUG - Loading env file from:', envPath);
4484
const result = config({ path: envPath });
45-
4685
if (result.error) {
4786
throw new Error(`Error loading .env file: ${result.error}`);
4887
}
4988

50-
console.log(`Loaded .env file from: ${envPath}`);
51-
return process.env;
89+
console.error('DEBUG - Successfully loaded env file');
90+
91+
// Populate the settings object with the environment variables
92+
Object.assign(settings, process.env);
5293
}
5394

54-
export const settings = loadEnvConfig();
55-
export default settings;
95+
export const settings: Settings = {} as Settings;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
describe("Basic Test Suite", () => {
4+
it("should run a basic test", () => {
5+
expect(true).toBe(true);
6+
});
7+
8+
it("should have access to environment variables", () => {
9+
expect(process.env.NODE_ENV).toBe("test");
10+
expect(process.env.TEST_DATABASE_CLIENT).toBe("sqlite");
11+
});
12+
});
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// getCachedEmbeddings
2+
// check cache.json for embedding where the key is a stringified version of the memory and the value is a number array
3+
import fs from "fs";
4+
export const getCachedEmbeddings = async (text: string) => {
5+
if (!fs.existsSync("./embedding-cache.json")) {
6+
fs.writeFileSync("./embedding-cache.json", "{}");
7+
}
8+
// read cache.json
9+
const cache = JSON.parse(
10+
fs.readFileSync("./embedding-cache.json", "utf8") as string
11+
);
12+
// stringify the memory
13+
const key = JSON.stringify(text);
14+
// return the value of the memory
15+
return cache[key];
16+
};
17+
18+
export const writeCachedEmbedding = async (
19+
text: string,
20+
embedding: number[]
21+
) => {
22+
// check if ./embedding-cache.json exists, if it doesn't, write {} to it
23+
if (!fs.existsSync("./embedding-cache.json")) {
24+
fs.writeFileSync("./embedding-cache.json", "{}");
25+
}
26+
// read cache.json
27+
const cache = JSON.parse(
28+
fs.readFileSync("./embedding-cache.json", "utf8") as string
29+
);
30+
// stringify the memory
31+
const key = JSON.stringify(text);
32+
// write the value of the memory
33+
cache[key] = embedding;
34+
// write the cache to cache.json
35+
fs.writeFileSync("./embedding-cache.json", JSON.stringify(cache));
36+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { type UUID } from "@ai16z/eliza/src/types.ts";
2+
3+
export const SERVER_URL = "http://localhost:7998";
4+
export const SUPABASE_URL = "https://pronvzrzfwsptkojvudd.supabase.co";
5+
export const SUPABASE_ANON_KEY =
6+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InByb252enJ6ZndzcHRrb2p2dWRkIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDY4NTYwNDcsImV4cCI6MjAyMjQzMjA0N30.I6_-XrqssUb2SWYg5DjsUqSodNS3_RPoET3-aPdqywM";
7+
export const TEST_EMAIL = "testuser123@gmail.com";
8+
export const TEST_PASSWORD = "testuser123@gmail.com";
9+
export const TEST_EMAIL_2 = "testuser234@gmail.com";
10+
export const TEST_PASSWORD_2 = "testuser234@gmail.com";
11+
12+
export const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID;

0 commit comments

Comments
 (0)