diff --git a/tests/test1.mjs b/tests/test1.mjs index 11ebbe37aa..516c9b1a10 100644 --- a/tests/test1.mjs +++ b/tests/test1.mjs @@ -1,33 +1,22 @@ -import { $, chalk } from 'zx'; import assert from 'assert'; import { - startAgent, - stopAgent, send } from "./testLibrary.mjs"; -import { stringToUuid } from '../packages/core/dist/index.js' - -export const DEFAULT_CHARACTER = "trump" -export const DEFAULT_AGENT_ID = stringToUuid(DEFAULT_CHARACTER ?? uuidv4()); async function test1() { - const proc = await startAgent(); - try { + const reply = await send("Hi"); + assert(reply.length > 10); +} - const reply = await send("Hi"); - assert(reply.length > 10); - console.log(chalk.green('✓ Test 1 passed')); - } catch (error) { - console.error(chalk.red(`✗ Test 1 failed: ${error.message}`)); - process.exit(1); - } finally { - await stopAgent(proc); - } +async function test2() { + // TODO } try { - await test1(); + const allTests = [test1, test2]; + allTests.forEach(runIntegrationTest); } catch (error) { - console.error(chalk.red(`Error: ${error.message}`)); + console.error(`Error: ${error.message}`); + console.log(error); process.exit(1); -} \ No newline at end of file +} diff --git a/tests/testLibrary.mjs b/tests/testLibrary.mjs index 5a5881c5db..8e5426af64 100644 --- a/tests/testLibrary.mjs +++ b/tests/testLibrary.mjs @@ -1,7 +1,8 @@ -import { $, fs, path, chalk } from 'zx'; -import { DEFAULT_AGENT_ID, DEFAULT_CHARACTER } from './test1.mjs'; import { spawn } from 'node:child_process'; -$.verbose = false; // Suppress command output unless there's an error +import { stringToUuid } from '../packages/core/dist/index.js'; + +export const DEFAULT_CHARACTER = "trump" +export const DEFAULT_AGENT_ID = stringToUuid(DEFAULT_CHARACTER ?? uuidv4()); function projectRoot() { return path.join(import.meta.dirname, ".."); @@ -9,7 +10,8 @@ function projectRoot() { async function runProcess(command, args = [], directory = projectRoot()) { try { - const result = await $`cd ${directory} && ${command} ${args}`; + throw new Exception("Not implemented yet"); // TODO + // const result = await $`cd ${directory} && ${command} ${args}`; return result.stdout.trim(); } catch (error) { throw new Error(`Command failed: ${error.message}`); @@ -17,12 +19,12 @@ async function runProcess(command, args = [], directory = projectRoot()) { } async function installProjectDependencies() { - console.log(chalk.blue('Installing dependencies...')); + console.log('Installing dependencies...'); return await runProcess('pnpm', ['install', '-r']); } async function buildProject() { - console.log(chalk.blue('Building project...')); + console.log('Building project...'); return await runProcess('pnpm', ['build']); } @@ -34,18 +36,21 @@ async function writeEnvFile(entries) { } async function startAgent(character = DEFAULT_CHARACTER) { - console.log(chalk.blue(`Starting agent for character: ${character}`)); + console.log(`Starting agent for character: ${character}`); const proc = spawn('pnpm', ['start', `--character=characters/${character}.character.json`, '--non-interactive'], { shell: true, "stdio": "inherit" }); log(`proc=${JSON.stringify(proc)}`); - // Wait for server to be ready - await new Promise(resolve => setTimeout(resolve, 60000)); + sleep(60000); // Wait for server to be ready return proc; } async function stopAgent(proc) { - console.log(chalk.blue('Stopping agent...')); - proc.kill('SIGTERM') + console.log('Stopping agent...'); + proc.kill('SIGTERM'); +} + +async function sleep(ms) { + await new Promise(resolve => setTimeout(resolve, ms)); } async function send(message) { @@ -76,8 +81,18 @@ async function send(message) { } } -function log(message) { - console.log(message); +async function runIntegrationTest(fn) { + const proc = await startAgent(); + try { + fn(); + console.log('✓ Test passed'); + } catch (error) { + console.error(`✗ Test failed: ${error.message}`); + console.log(error); + process.exit(1); + } finally { + await stopAgent(proc); + } } export { @@ -89,5 +104,6 @@ export { startAgent, stopAgent, send, + runIntegrationTest, log -} \ No newline at end of file +}