-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from normand1/dn/token-provider-tests
feat: [Issue-185] Token Provider Tests
- Loading branch information
Showing
20 changed files
with
380 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v23.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
TEST_DATABASE_CLIENT=sqlite | ||
NODE_ENV=test | ||
MAIN_WALLET_ADDRESS=TEST_MAIN_WALLET_ADDRESS_VALUE | ||
OPENAI_API_KEY=TEST_OPENAI_API_KEY_VALUE | ||
RPC_URL=https://api.mainnet-beta.solana.com | ||
WALLET_PUBLIC_KEY=2weMjPLLybRMMva1fM3U31goWWrCpF59CHWNhnCJ9Vyh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules | ||
dist | ||
elizaConfig.yaml | ||
custom_actions/ | ||
custom_actions/ | ||
cache/ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { type UUID } from "@ai16z/eliza/src/types.ts"; | ||
|
||
export const SERVER_URL = "http://localhost:7998"; | ||
export const SUPABASE_URL = "https://pronvzrzfwsptkojvudd.supabase.co"; | ||
export const SUPABASE_ANON_KEY = | ||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InByb252enJ6ZndzcHRrb2p2dWRkIiwicm9sZSI6ImFub24iLCJpYXQiOjE3MDY4NTYwNDcsImV4cCI6MjAyMjQzMjA0N30.I6_-XrqssUb2SWYg5DjsUqSodNS3_RPoET3-aPdqywM"; | ||
export const TEST_EMAIL = "testuser123@gmail.com"; | ||
export const TEST_PASSWORD = "testuser123@gmail.com"; | ||
export const TEST_EMAIL_2 = "testuser234@gmail.com"; | ||
export const TEST_PASSWORD_2 = "testuser234@gmail.com"; | ||
|
||
export const zeroUuid = "00000000-0000-0000-0000-000000000000" as UUID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
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 { | ||
SUPABASE_ANON_KEY, | ||
SUPABASE_URL, | ||
TEST_EMAIL, | ||
TEST_PASSWORD, | ||
zeroUuid, | ||
} from "./constants.ts"; | ||
import { User } from "./types.ts"; | ||
import { getEndpoint } from "../models.ts"; | ||
|
||
export async function createRuntime({ | ||
env, | ||
conversationLength, | ||
evaluators = [], | ||
actions = [], | ||
providers = [], | ||
}: { | ||
env?: Record<string, string> | NodeJS.ProcessEnv; | ||
conversationLength?: number; | ||
evaluators?: Evaluator[]; | ||
actions?: Action[]; | ||
providers?: Provider[]; | ||
}) { | ||
let adapter: DatabaseAdapter; | ||
let user: User; | ||
let session: { | ||
user: User; | ||
}; | ||
|
||
switch (env?.TEST_DATABASE_CLIENT as string) { | ||
case "sqljs": | ||
{ | ||
const module = await import("sql.js"); | ||
|
||
const initSqlJs = module.default; | ||
|
||
// SQLite adapter | ||
const SQL = await initSqlJs({}); | ||
const db = new SQL.Database(); | ||
|
||
adapter = new SqlJsDatabaseAdapter(db); | ||
|
||
// Load sqlite-vss | ||
loadVecExtensions((adapter as SqlJsDatabaseAdapter).db); | ||
// Create a test user and session | ||
session = { | ||
user: { | ||
id: zeroUuid, | ||
email: "test@example.com", | ||
}, | ||
}; | ||
} | ||
break; | ||
case "supabase": { | ||
const module = await import("@supabase/supabase-js"); | ||
|
||
const { createClient } = module; | ||
|
||
const supabase = createClient( | ||
env?.SUPABASE_URL ?? SUPABASE_URL, | ||
env?.SUPABASE_SERVICE_API_KEY ?? SUPABASE_ANON_KEY | ||
); | ||
|
||
const { data } = await supabase.auth.signInWithPassword({ | ||
email: TEST_EMAIL!, | ||
password: TEST_PASSWORD!, | ||
}); | ||
|
||
user = data.user as User; | ||
session = data.session as unknown as { user: User }; | ||
|
||
if (!session) { | ||
const response = await supabase.auth.signUp({ | ||
email: TEST_EMAIL!, | ||
password: TEST_PASSWORD!, | ||
}); | ||
|
||
// Change the name of the user | ||
const { error } = await supabase | ||
.from("accounts") | ||
.update({ name: "Test User" }) | ||
.eq("id", response.data.user?.id); | ||
|
||
if (error) { | ||
throw new Error( | ||
"Create runtime error: " + JSON.stringify(error) | ||
); | ||
} | ||
|
||
user = response.data.user as User; | ||
session = response.data.session as unknown as { user: User }; | ||
} | ||
|
||
adapter = new SupabaseDatabaseAdapter( | ||
env?.SUPABASE_URL ?? SUPABASE_URL, | ||
env?.SUPABASE_SERVICE_API_KEY ?? SUPABASE_ANON_KEY | ||
); | ||
} | ||
case "sqlite": | ||
default: | ||
{ | ||
const module = await import("better-sqlite3"); | ||
|
||
const Database = module.default; | ||
|
||
// SQLite adapter | ||
adapter = new SqliteDatabaseAdapter(new Database(":memory:")); | ||
|
||
// Load sqlite-vss | ||
await loadVecExtensions((adapter as SqliteDatabaseAdapter).db); | ||
// Create a test user and session | ||
session = { | ||
user: { | ||
id: zeroUuid, | ||
email: "test@example.com", | ||
}, | ||
}; | ||
} | ||
break; | ||
} | ||
|
||
const runtime = new AgentRuntime({ | ||
serverUrl: getEndpoint(ModelProviderName.OPENAI), | ||
conversationLength, | ||
token: env!.OPENAI_API_KEY!, | ||
modelProvider: ModelProviderName.OPENAI, | ||
actions: actions ?? [], | ||
evaluators: evaluators ?? [], | ||
providers: providers ?? [], | ||
databaseAdapter: adapter, | ||
}); | ||
|
||
return { user, session, runtime }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import dotenv from "dotenv"; | ||
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); | ||
const result = dotenv.config({ path: envPath }); | ||
if (result.error) { | ||
console.error('Error loading .env.test:', result.error); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export interface User { | ||
id: string; | ||
email?: string; | ||
phone?: string; | ||
role?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
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'), | ||
]; | ||
|
||
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.