@aigne/test-utils 0.5.55 → 0.5.56-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.5.56-beta.1](https://github.com/AIGNE-io/aigne-framework/compare/test-utils-v0.5.56-beta...test-utils-v0.5.56-beta.1) (2025-10-22)
4
+
5
+
6
+ ### Dependencies
7
+
8
+ * The following workspace dependencies were updated
9
+ * dependencies
10
+ * @aigne/core bumped to 1.64.0-beta.1
11
+
12
+ ## [0.5.56-beta](https://github.com/AIGNE-io/aigne-framework/compare/test-utils-v0.5.55...test-utils-v0.5.56-beta) (2025-10-21)
13
+
14
+
15
+ ### Dependencies
16
+
17
+ * The following workspace dependencies were updated
18
+ * dependencies
19
+ * @aigne/core bumped to 1.64.0-beta
20
+
3
21
  ## [0.5.55](https://github.com/AIGNE-io/aigne-framework/compare/test-utils-v0.5.55-beta.12...test-utils-v0.5.55) (2025-10-19)
4
22
 
5
23
 
@@ -0,0 +1,7 @@
1
+ export interface TestConfig {
2
+ initialCall?: string;
3
+ scriptPath?: string;
4
+ }
5
+ export declare function runExampleTest(config?: TestConfig): Promise<{
6
+ status: number | null;
7
+ }>;
@@ -0,0 +1,12 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { join } from "node:path";
3
+ export async function runExampleTest(config) {
4
+ const scriptPath = config?.scriptPath ?? join(process.cwd(), "index.ts");
5
+ return spawnSync("bun", [scriptPath], {
6
+ stdio: ["inherit", "inherit", "inherit"],
7
+ env: {
8
+ ...process.env,
9
+ INITIAL_CALL: config?.initialCall ?? process.env.INITIAL_CALL,
10
+ },
11
+ });
12
+ }
@@ -0,0 +1,7 @@
1
+ import { type AgentResponseChunk, type AgentResponseStream, type Message } from "@aigne/core";
2
+ export declare function agentResponseStreamToArraySnapshot<T extends Message>(stream: AgentResponseStream<T>, options?: {
3
+ catchError?: false;
4
+ }): Promise<AgentResponseChunk<T>[]>;
5
+ export declare function agentResponseStreamToArraySnapshot<T extends Message>(stream: AgentResponseStream<T>, options?: {
6
+ catchError?: boolean;
7
+ }): Promise<(AgentResponseChunk<T> | Error)[]>;
@@ -0,0 +1,14 @@
1
+ import { isAgentResponseProgress, } from "@aigne/core";
2
+ import { readableStreamToArray } from "@aigne/core/utils/stream-utils.js";
3
+ export async function agentResponseStreamToArraySnapshot(stream, options) {
4
+ return (await readableStreamToArray(stream, options)).map((i) => !(i instanceof Error) && isAgentResponseProgress(i)
5
+ ? {
6
+ progress: {
7
+ ...i.progress,
8
+ contextId: "TEST_CONTEXT_ID",
9
+ parentContextId: "TEST_PARENT_CONTEXT_ID",
10
+ timestamp: 123456,
11
+ },
12
+ }
13
+ : i);
14
+ }
@@ -0,0 +1,5 @@
1
+ export declare function createMockEventStream<T>(data: {
2
+ path: string;
3
+ } | {
4
+ raw: string;
5
+ }): T;
@@ -0,0 +1,13 @@
1
+ import { readFile } from "node:fs/promises";
2
+ export function createMockEventStream(data) {
3
+ return new ReadableStream({
4
+ async start(controller) {
5
+ const file = "path" in data ? await readFile(data.path) : data.raw;
6
+ for (const line of file.toString().split("\n")) {
7
+ if (line)
8
+ controller.enqueue(JSON.parse(line.replace("data:", "")));
9
+ }
10
+ controller.close();
11
+ },
12
+ });
13
+ }
@@ -0,0 +1,7 @@
1
+ import { type ChatModelInputResponseFormat, type ChatModelInputTool, type ChatModelOutputToolCall, type Message } from "@aigne/core";
2
+ export declare const COMMON_TOOLS: ChatModelInputTool[];
3
+ export declare const COMMON_RESPONSE_FORMAT: ChatModelInputResponseFormat;
4
+ export declare const createWeatherToolMessages: () => Promise<import("@aigne/core").ChatModelInputMessage[]>;
5
+ export declare const createWeatherToolExpected: () => any;
6
+ export declare const createWeatherToolCallMessages: () => Promise<import("@aigne/core").ChatModelInputMessage[]>;
7
+ export declare function createToolCallResponse(functionName: string, args: Message): ChatModelOutputToolCall;
@@ -0,0 +1,76 @@
1
+ import { expect } from "bun:test";
2
+ import { AgentMessageTemplate, ChatMessagesTemplate, SystemMessageTemplate, ToolMessageTemplate, UserMessageTemplate, } from "@aigne/core";
3
+ export const COMMON_TOOLS = [
4
+ {
5
+ type: "function",
6
+ function: {
7
+ name: "get_weather",
8
+ parameters: {
9
+ type: "object",
10
+ properties: {
11
+ city: {
12
+ type: "string",
13
+ },
14
+ },
15
+ required: ["city"],
16
+ },
17
+ },
18
+ },
19
+ ];
20
+ export const COMMON_RESPONSE_FORMAT = {
21
+ type: "json_schema",
22
+ jsonSchema: {
23
+ name: "output",
24
+ schema: {
25
+ type: "object",
26
+ properties: {
27
+ text: {
28
+ type: "string",
29
+ },
30
+ },
31
+ required: ["text"],
32
+ additionalProperties: false,
33
+ },
34
+ strict: true,
35
+ },
36
+ };
37
+ const createBaseMessages = () => [
38
+ SystemMessageTemplate.from("You are a chatbot"),
39
+ UserMessageTemplate.from([{ type: "text", text: "What is the weather in New York?" }]),
40
+ ];
41
+ export const createWeatherToolMessages = () => ChatMessagesTemplate.from(createBaseMessages()).format();
42
+ export const createWeatherToolExpected = () => expect.objectContaining({
43
+ toolCalls: [
44
+ {
45
+ function: {
46
+ arguments: {
47
+ city: "New York",
48
+ },
49
+ name: "get_weather",
50
+ },
51
+ id: expect.any(String),
52
+ type: "function",
53
+ },
54
+ ],
55
+ });
56
+ export const createWeatherToolCallMessages = () => ChatMessagesTemplate.from([
57
+ ...createBaseMessages(),
58
+ AgentMessageTemplate.from(undefined, [
59
+ {
60
+ id: "get_weather",
61
+ type: "function",
62
+ function: { name: "get_weather", arguments: { city: "New York" } },
63
+ },
64
+ ]),
65
+ ToolMessageTemplate.from({ temperature: 20 }, "get_weather"),
66
+ ]).format();
67
+ export function createToolCallResponse(functionName, args) {
68
+ return {
69
+ id: functionName,
70
+ type: "function",
71
+ function: {
72
+ name: functionName,
73
+ arguments: args,
74
+ },
75
+ };
76
+ }
@@ -0,0 +1,3 @@
1
+ export declare function withEnv(env: Record<string, string>): {
2
+ [Symbol.dispose]: () => void;
3
+ };
@@ -0,0 +1,9 @@
1
+ export function withEnv(env) {
2
+ const originalEnv = { ...process.env };
3
+ process.env = { ...process.env, ...env };
4
+ return {
5
+ [Symbol.dispose]: () => {
6
+ process.env = originalEnv;
7
+ },
8
+ };
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/test-utils",
3
- "version": "0.5.55",
3
+ "version": "0.5.56-beta.1",
4
4
  "description": "Test utils for AIGNE framework",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -27,7 +27,7 @@
27
27
  }
28
28
  },
29
29
  "dependencies": {
30
- "@aigne/core": "^1.63.0"
30
+ "@aigne/core": "^1.64.0-beta.1"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/bun": "^1.2.22",