Skip to content

Commit bf48b66

Browse files
tess
1 parent 8ae0136 commit bf48b66

File tree

4 files changed

+622
-8
lines changed

4 files changed

+622
-8
lines changed

packages/core/package.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
"dev": "tsup --format esm --dts --watch",
1717
"build:docs": "cd docs && pnpm run build",
1818
"postinstall": "npx playwright install-deps && npx playwright install",
19-
"test": "jest --runInBand",
20-
"test:watch": "jest --runInBand --watch"
19+
"test": "vitest",
20+
"test:watch": "vitest --watch"
2121
},
2222
"author": "",
2323
"license": "MIT",
@@ -43,9 +43,9 @@
4343
"eslint-plugin-prettier": "5.2.1",
4444
"jest": "29.7.0",
4545
"lint-staged": "15.2.10",
46-
"prettier": "3.3.3",
4746
"nodemon": "3.1.7",
4847
"pm2": "5.4.2",
48+
"prettier": "3.3.3",
4949
"rimraf": "6.0.1",
5050
"rollup": "2.79.2",
5151
"ts-jest": "29.2.5",
@@ -73,6 +73,7 @@
7373
"tinyld": "1.3.4",
7474
"together-ai": "^0.7.0",
7575
"unique-names-generator": "4.7.1",
76-
"uuid": "11.0.2"
76+
"uuid": "11.0.2",
77+
"vitest": "^2.1.4"
7778
}
7879
}
+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { describe, it, expect } from "vitest";
2+
import {
3+
composeActionExamples,
4+
formatActionNames,
5+
formatActions,
6+
} from "../actions";
7+
import { Action } from "../types";
8+
9+
describe("actions", () => {
10+
const mockActions: Action[] = [
11+
{
12+
name: "Action1",
13+
description: "First action description",
14+
similes: ["greeting", "welcoming"],
15+
examples: [
16+
[
17+
{
18+
user: "user",
19+
content: {
20+
text: "Hello {{user1}}!",
21+
action: "greet",
22+
},
23+
},
24+
],
25+
],
26+
handler: async () => {},
27+
validate: async () => true,
28+
},
29+
{
30+
name: "Action2",
31+
description: "Second action description",
32+
similes: ["talking", "conversing"],
33+
examples: [
34+
[
35+
{
36+
user: "user",
37+
content: {
38+
text: "{{user1}} talks to {{user2}}",
39+
action: null,
40+
},
41+
},
42+
],
43+
],
44+
handler: async () => {},
45+
validate: async () => true,
46+
},
47+
];
48+
49+
describe("composeActionExamples", () => {
50+
it("should generate formatted examples with replaced usernames", () => {
51+
const result = composeActionExamples(mockActions, 2);
52+
53+
expect(result).toBeTypeOf("string");
54+
expect(result).toContain("user:");
55+
expect(result).not.toContain("{{user1}}");
56+
expect(result).not.toContain("{{user2}}");
57+
});
58+
59+
it("should respect the count parameter", () => {
60+
const result = composeActionExamples(mockActions, 1);
61+
const examples = result
62+
.split("\n")
63+
.filter((line) => line.length > 0);
64+
expect(examples).toHaveLength(1);
65+
});
66+
});
67+
68+
describe("formatActionNames", () => {
69+
it("should return comma-separated action names", () => {
70+
const result = formatActionNames(mockActions);
71+
72+
expect(result).toBeTypeOf("string");
73+
expect(result).toContain("Action1");
74+
expect(result).toContain("Action2");
75+
expect(result).toContain(", ");
76+
});
77+
});
78+
79+
describe("formatActions", () => {
80+
it("should return formatted actions with descriptions", () => {
81+
const result = formatActions(mockActions);
82+
83+
expect(result).toBeTypeOf("string");
84+
expect(result).toContain("Action1: First action description");
85+
expect(result).toContain("Action2: Second action description");
86+
expect(result).toContain(",\n");
87+
});
88+
});
89+
});

packages/core/src/settings.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import path from "path";
88
* @param {string} [startDir=process.cwd()] - Starting directory for the search
99
* @returns {string|null} Path to the nearest .env file or null if not found
1010
*/
11-
function findNearestEnvFile(startDir = process.cwd()) {
11+
export function findNearestEnvFile(startDir = process.cwd()) {
1212
let currentDir = startDir;
1313

1414
// Continue searching until we reach the root directory
@@ -33,7 +33,7 @@ function findNearestEnvFile(startDir = process.cwd()) {
3333
* @returns {Object} Environment variables object
3434
* @throws {Error} If no .env file is found
3535
*/
36-
function loadEnvConfig() {
36+
export function loadEnvConfig() {
3737
const envPath = findNearestEnvFile();
3838

3939
if (!envPath) {

0 commit comments

Comments
 (0)