@stratix/testing 0.1.0
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/LICENSE +21 -0
- package/README.md +36 -0
- package/dist/AgentTester.d.ts +120 -0
- package/dist/AgentTester.d.ts.map +1 -0
- package/dist/AgentTester.js +152 -0
- package/dist/AgentTester.js.map +1 -0
- package/dist/MockLLMProvider.d.ts +80 -0
- package/dist/MockLLMProvider.d.ts.map +1 -0
- package/dist/MockLLMProvider.js +143 -0
- package/dist/MockLLMProvider.js.map +1 -0
- package/dist/TestApplication.d.ts +64 -0
- package/dist/TestApplication.d.ts.map +1 -0
- package/dist/TestApplication.js +90 -0
- package/dist/TestApplication.js.map +1 -0
- package/dist/assertions.d.ts +41 -0
- package/dist/assertions.d.ts.map +1 -0
- package/dist/assertions.js +82 -0
- package/dist/assertions.js.map +1 -0
- package/dist/builders/EntityBuilder.d.ts +47 -0
- package/dist/builders/EntityBuilder.d.ts.map +1 -0
- package/dist/builders/EntityBuilder.js +68 -0
- package/dist/builders/EntityBuilder.js.map +1 -0
- package/dist/factories/DataFactory.d.ts +42 -0
- package/dist/factories/DataFactory.d.ts.map +1 -0
- package/dist/factories/DataFactory.js +66 -0
- package/dist/factories/DataFactory.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/testHelpers.d.ts +51 -0
- package/dist/testHelpers.d.ts.map +1 -0
- package/dist/testHelpers.js +100 -0
- package/dist/testHelpers.js.map +1 -0
- package/dist/utils/assertions.d.ts +43 -0
- package/dist/utils/assertions.d.ts.map +1 -0
- package/dist/utils/assertions.js +62 -0
- package/dist/utils/assertions.js.map +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { ApplicationBuilder } from '@stratix/runtime';
|
|
2
|
+
import { AwilixContainer } from '@stratix/impl-di-awilix';
|
|
3
|
+
import { ConsoleLogger } from '@stratix/impl-logger-console';
|
|
4
|
+
import { LogLevel } from '@stratix/abstractions';
|
|
5
|
+
/**
|
|
6
|
+
* Test Application Builder
|
|
7
|
+
*
|
|
8
|
+
* Provides a simplified way to create test applications with in-memory implementations.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const app = await TestApplication.create()
|
|
13
|
+
* .useInMemoryDefaults()
|
|
14
|
+
* .build();
|
|
15
|
+
*
|
|
16
|
+
* await app.start();
|
|
17
|
+
* // Run tests
|
|
18
|
+
* await app.stop();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class TestApplication {
|
|
22
|
+
builder;
|
|
23
|
+
testContainer;
|
|
24
|
+
testLogger;
|
|
25
|
+
constructor() {
|
|
26
|
+
this.builder = ApplicationBuilder.create();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Create a new test application builder
|
|
30
|
+
*/
|
|
31
|
+
static create() {
|
|
32
|
+
return new TestApplication();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Use in-memory defaults for testing
|
|
36
|
+
*
|
|
37
|
+
* Includes:
|
|
38
|
+
* - Awilix Container
|
|
39
|
+
* - Console Logger (error level only)
|
|
40
|
+
*/
|
|
41
|
+
useInMemoryDefaults() {
|
|
42
|
+
this.testContainer = new AwilixContainer();
|
|
43
|
+
this.testLogger = new ConsoleLogger({ level: LogLevel.ERROR });
|
|
44
|
+
this.builder.useContainer(this.testContainer).useLogger(this.testLogger);
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Set a custom container
|
|
49
|
+
*/
|
|
50
|
+
useContainer(container) {
|
|
51
|
+
this.builder.useContainer(container);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Set a custom logger
|
|
56
|
+
*/
|
|
57
|
+
useLogger(logger) {
|
|
58
|
+
this.builder.useLogger(logger);
|
|
59
|
+
return this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Add a custom plugin
|
|
63
|
+
*/
|
|
64
|
+
usePlugin(plugin, config) {
|
|
65
|
+
this.builder.usePlugin(plugin, config);
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Build the application
|
|
70
|
+
*/
|
|
71
|
+
async build() {
|
|
72
|
+
return await this.builder.build();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Create and start a test application
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const app = await createTestApp();
|
|
81
|
+
* // Run tests
|
|
82
|
+
* await app.stop();
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export async function createTestApp() {
|
|
86
|
+
const app = await TestApplication.create().useInMemoryDefaults().build();
|
|
87
|
+
await app.start();
|
|
88
|
+
return app;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=TestApplication.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TestApplication.js","sourceRoot":"","sources":["../src/TestApplication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,eAAe;IAClB,OAAO,CAAqB;IAC5B,aAAa,CAAa;IAC1B,UAAU,CAAU;IAE5B;QACE,IAAI,CAAC,OAAO,GAAG,kBAAkB,CAAC,MAAM,EAAE,CAAC;IAC7C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,MAAM;QACX,OAAO,IAAI,eAAe,EAAE,CAAC;IAC/B,CAAC;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5
|
+
/**
|
|
6
|
+
* Asserts that the agent result is successful
|
|
7
|
+
*/
|
|
8
|
+
export declare function expectSuccess<T>(result: AgentResult<T>): asserts result is AgentResult<T> & {
|
|
9
|
+
data: T;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Asserts that the agent result is a failure
|
|
13
|
+
*/
|
|
14
|
+
export declare function expectFailure<T>(result: AgentResult<T>): asserts result is AgentResult<T> & {
|
|
15
|
+
error: Error;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Asserts that the result data matches the expected value
|
|
19
|
+
*/
|
|
20
|
+
export declare function expectData<T>(result: AgentResult<T>, expected: T): void;
|
|
21
|
+
/**
|
|
22
|
+
* Asserts that the result data contains the expected subset
|
|
23
|
+
*/
|
|
24
|
+
export declare function expectDataContains<T extends Record<string, unknown>>(result: AgentResult<T>, expected: Partial<T>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Asserts that execution cost is within budget
|
|
27
|
+
*/
|
|
28
|
+
export declare function expectCostWithinBudget<T>(result: AgentResult<T>, budget: number): void;
|
|
29
|
+
/**
|
|
30
|
+
* Asserts that execution duration is within limit
|
|
31
|
+
*/
|
|
32
|
+
export declare function expectDurationWithinLimit<T>(result: AgentResult<T>, maxDuration: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* Asserts that the error message contains the expected text
|
|
35
|
+
*/
|
|
36
|
+
export declare function expectErrorContains<T>(result: AgentResult<T>, expectedText: string): void;
|
|
37
|
+
/**
|
|
38
|
+
* Asserts that the result uses the expected model
|
|
39
|
+
*/
|
|
40
|
+
export declare function expectModel<T>(result: AgentResult<T>, expectedModel: string): void;
|
|
41
|
+
//# sourceMappingURL=assertions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertions.d.ts","sourceRoot":"","sources":["../src/assertions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAEvD;;GAEG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
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assertion helpers for testing agents
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Asserts that the agent result is successful
|
|
6
|
+
*/
|
|
7
|
+
export function expectSuccess(result) {
|
|
8
|
+
if (!result.isSuccess()) {
|
|
9
|
+
throw new Error(`Expected success but got failure: ${result.error?.message}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Asserts that the agent result is a failure
|
|
14
|
+
*/
|
|
15
|
+
export function expectFailure(result) {
|
|
16
|
+
if (!result.isFailure()) {
|
|
17
|
+
throw new Error('Expected failure but got success');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Asserts that the result data matches the expected value
|
|
22
|
+
*/
|
|
23
|
+
export function expectData(result, expected) {
|
|
24
|
+
expectSuccess(result);
|
|
25
|
+
if (JSON.stringify(result.data) !== JSON.stringify(expected)) {
|
|
26
|
+
throw new Error(`Expected data ${JSON.stringify(expected)} but got ${JSON.stringify(result.data)}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Asserts that the result data contains the expected subset
|
|
31
|
+
*/
|
|
32
|
+
export function expectDataContains(result, expected) {
|
|
33
|
+
expectSuccess(result);
|
|
34
|
+
for (const [key, value] of Object.entries(expected)) {
|
|
35
|
+
const actualValue = result.data[key];
|
|
36
|
+
if (JSON.stringify(actualValue) !== JSON.stringify(value)) {
|
|
37
|
+
throw new Error(`Expected ${key} to be ${JSON.stringify(value)} but got ${JSON.stringify(actualValue)}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Asserts that execution cost is within budget
|
|
43
|
+
*/
|
|
44
|
+
export function expectCostWithinBudget(result, budget) {
|
|
45
|
+
const cost = result.metadata.cost || 0;
|
|
46
|
+
if (cost > budget) {
|
|
47
|
+
throw new Error(`Cost $${cost.toFixed(4)} exceeds budget $${budget.toFixed(4)}`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Asserts that execution duration is within limit
|
|
52
|
+
*/
|
|
53
|
+
export function expectDurationWithinLimit(result, maxDuration) {
|
|
54
|
+
const duration = result.metadata.duration;
|
|
55
|
+
if (duration === undefined) {
|
|
56
|
+
throw new Error('Duration metadata is not available');
|
|
57
|
+
}
|
|
58
|
+
if (duration > maxDuration) {
|
|
59
|
+
throw new Error(`Duration ${duration}ms exceeds limit ${maxDuration}ms`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Asserts that the error message contains the expected text
|
|
64
|
+
*/
|
|
65
|
+
export function expectErrorContains(result, expectedText) {
|
|
66
|
+
expectFailure(result);
|
|
67
|
+
const errorMessage = result.error.message.toLowerCase();
|
|
68
|
+
const searchText = expectedText.toLowerCase();
|
|
69
|
+
if (!errorMessage.includes(searchText)) {
|
|
70
|
+
throw new Error(`Expected error message to contain "${expectedText}" but got "${result.error.message}"`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Asserts that the result uses the expected model
|
|
75
|
+
*/
|
|
76
|
+
export function expectModel(result, expectedModel) {
|
|
77
|
+
const actualModel = result.metadata.model;
|
|
78
|
+
if (actualModel !== expectedModel) {
|
|
79
|
+
throw new Error(`Expected model "${expectedModel}" but got "${actualModel}"`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=assertions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assertions.js","sourceRoot":"","sources":["../src/assertions.ts"],"names":[],"mappings":"AAEA;;GAEG;AAEH;;GAEG;AACH,MAAM,UAAU,aAAa,CAC3B,MAAsB;IAEtB,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,C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AAK,aAAa,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,mBAAmB,aAAa,cAAc,WAAW,GAAG,CAAC,CAAC;IAChF,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Entity } from '@stratix/primitives';
|
|
2
|
+
/**
|
|
3
|
+
* Generic Entity Builder for testing
|
|
4
|
+
*
|
|
5
|
+
* Provides a fluent API for building test entities.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const user = new EntityBuilder(User)
|
|
10
|
+
* .withProps({ email: 'test@example.com', name: 'Test' })
|
|
11
|
+
* .build();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare class EntityBuilder<E extends Entity<any>> {
|
|
15
|
+
private readonly EntityClass;
|
|
16
|
+
private props;
|
|
17
|
+
private id?;
|
|
18
|
+
constructor(EntityClass: new (props: any, id: any) => E);
|
|
19
|
+
/**
|
|
20
|
+
* Set entity properties
|
|
21
|
+
*/
|
|
22
|
+
withProps(props: Partial<any>): this;
|
|
23
|
+
/**
|
|
24
|
+
* Set entity ID
|
|
25
|
+
*/
|
|
26
|
+
withId(id: any): this;
|
|
27
|
+
/**
|
|
28
|
+
* Build the entity
|
|
29
|
+
*/
|
|
30
|
+
build(): E;
|
|
31
|
+
/**
|
|
32
|
+
* Build multiple entities
|
|
33
|
+
*/
|
|
34
|
+
buildMany(count: number): E[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create an entity builder
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const user = entityBuilder(User)
|
|
42
|
+
* .withProps({ email: 'test@example.com' })
|
|
43
|
+
* .build();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export declare function entityBuilder<E extends Entity<any>>(EntityClass: new (props: any, id: any) => E): EntityBuilder<E>;
|
|
47
|
+
//# sourceMappingURL=EntityBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityBuilder.d.ts","sourceRoot":"","sources":["../../src/builders/EntityBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,qBAAqB,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,qBAAa,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC;IAIlC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAHxC,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,EAAE,CAAC,CAAM;gBAEY,WAAW,EAAE,KAAK,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC;IAExE;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI;IAKpC;;OAEG;IACH,MAAM,CAAC,EAAE,EAAE,GAAG,GAAG,IAAI;IAKrB;;OAEG;IACH,KAAK,IAAI,CAAC;IAQV;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE;CAS9B;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,GAAG,CAAC,EACjD,WAAW,EAAE,KAAK,KAAK,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,KAAK,CAAC,GAC1C,aAAa,CAAC,CAAC,CAAC,CAElB"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { EntityId } from '@stratix/primitives';
|
|
2
|
+
/**
|
|
3
|
+
* Generic Entity Builder for testing
|
|
4
|
+
*
|
|
5
|
+
* Provides a fluent API for building test entities.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* const user = new EntityBuilder(User)
|
|
10
|
+
* .withProps({ email: 'test@example.com', name: 'Test' })
|
|
11
|
+
* .build();
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export class EntityBuilder {
|
|
15
|
+
EntityClass;
|
|
16
|
+
props = {};
|
|
17
|
+
id;
|
|
18
|
+
constructor(EntityClass) {
|
|
19
|
+
this.EntityClass = EntityClass;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Set entity properties
|
|
23
|
+
*/
|
|
24
|
+
withProps(props) {
|
|
25
|
+
this.props = { ...this.props, ...props };
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Set entity ID
|
|
30
|
+
*/
|
|
31
|
+
withId(id) {
|
|
32
|
+
this.id = id;
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Build the entity
|
|
37
|
+
*/
|
|
38
|
+
build() {
|
|
39
|
+
if (!this.id) {
|
|
40
|
+
this.id = EntityId.create();
|
|
41
|
+
}
|
|
42
|
+
return new this.EntityClass(this.props, this.id);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Build multiple entities
|
|
46
|
+
*/
|
|
47
|
+
buildMany(count) {
|
|
48
|
+
const entities = [];
|
|
49
|
+
for (let i = 0; i < count; i++) {
|
|
50
|
+
entities.push(this.build());
|
|
51
|
+
}
|
|
52
|
+
return entities;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Create an entity builder
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const user = entityBuilder(User)
|
|
61
|
+
* .withProps({ email: 'test@example.com' })
|
|
62
|
+
* .build();
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export function entityBuilder(EntityClass) {
|
|
66
|
+
return new EntityBuilder(EntityClass);
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=EntityBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EntityBuilder.js","sourceRoot":"","sources":["../../src/builders/EntityBuilder.ts"],"names":[],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|
2
|
+
/**
|
|
3
|
+
* Data Factory for generating test data
|
|
4
|
+
*
|
|
5
|
+
* Provides helper methods for creating common test data.
|
|
6
|
+
*/
|
|
7
|
+
export declare class DataFactory {
|
|
8
|
+
private static counter;
|
|
9
|
+
/**
|
|
10
|
+
* Generate a unique email
|
|
11
|
+
*/
|
|
12
|
+
static email(prefix?: string): Email;
|
|
13
|
+
/**
|
|
14
|
+
* Generate a unique string
|
|
15
|
+
*/
|
|
16
|
+
static string(prefix?: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Generate a unique number
|
|
19
|
+
*/
|
|
20
|
+
static number(min?: number, max?: number): number;
|
|
21
|
+
/**
|
|
22
|
+
* Generate a unique entity ID
|
|
23
|
+
*/
|
|
24
|
+
static entityId<T extends string>(): EntityId<T>;
|
|
25
|
+
/**
|
|
26
|
+
* Generate a random boolean
|
|
27
|
+
*/
|
|
28
|
+
static boolean(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Generate a random date
|
|
31
|
+
*/
|
|
32
|
+
static date(daysAgo?: number): Date;
|
|
33
|
+
/**
|
|
34
|
+
* Pick a random element from an array
|
|
35
|
+
*/
|
|
36
|
+
static pick<T>(array: T[]): T;
|
|
37
|
+
/**
|
|
38
|
+
* Reset the counter
|
|
39
|
+
*/
|
|
40
|
+
static reset(): void;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=DataFactory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataFactory.d.ts","sourceRoot":"","sources":["../../src/factories/DataFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;;GAIG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAK;IAE3B;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,SAAS,GAAG,KAAK;IASpC;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM;IAKtC;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,GAAG,SAAI,EAAE,GAAG,SAAO,GAAG,MAAM;IAI1C;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC;IAIhD;;OAEG;IACH,MAAM,CAAC,OAAO,IAAI,OAAO;IAIzB;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,SAAI,GAAG,IAAI;IAM9B;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC;IAI7B;;OAEG;IACH,MAAM,CAAC,KAAK,IAAI,IAAI;CAGrB"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Email, EntityId } from '@stratix/primitives';
|
|
2
|
+
/**
|
|
3
|
+
* Data Factory for generating test data
|
|
4
|
+
*
|
|
5
|
+
* Provides helper methods for creating common test data.
|
|
6
|
+
*/
|
|
7
|
+
export class DataFactory {
|
|
8
|
+
static counter = 0;
|
|
9
|
+
/**
|
|
10
|
+
* Generate a unique email
|
|
11
|
+
*/
|
|
12
|
+
static email(prefix = 'test') {
|
|
13
|
+
this.counter++;
|
|
14
|
+
const result = Email.create(`${prefix}${this.counter}@example.com`);
|
|
15
|
+
if (!result.isSuccess) {
|
|
16
|
+
throw new Error('Failed to create email');
|
|
17
|
+
}
|
|
18
|
+
return result.value;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Generate a unique string
|
|
22
|
+
*/
|
|
23
|
+
static string(prefix = 'test') {
|
|
24
|
+
this.counter++;
|
|
25
|
+
return `${prefix}${this.counter}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Generate a unique number
|
|
29
|
+
*/
|
|
30
|
+
static number(min = 0, max = 1000) {
|
|
31
|
+
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Generate a unique entity ID
|
|
35
|
+
*/
|
|
36
|
+
static entityId() {
|
|
37
|
+
return EntityId.create();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Generate a random boolean
|
|
41
|
+
*/
|
|
42
|
+
static boolean() {
|
|
43
|
+
return Math.random() > 0.5;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Generate a random date
|
|
47
|
+
*/
|
|
48
|
+
static date(daysAgo = 0) {
|
|
49
|
+
const date = new Date();
|
|
50
|
+
date.setDate(date.getDate() - daysAgo);
|
|
51
|
+
return date;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Pick a random element from an array
|
|
55
|
+
*/
|
|
56
|
+
static pick(array) {
|
|
57
|
+
return array[Math.floor(Math.random() * array.length)];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Reset the counter
|
|
61
|
+
*/
|
|
62
|
+
static reset() {
|
|
63
|
+
this.counter = 0;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=DataFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataFactory.js","sourceRoot":"","sources":["../../src/factories/DataFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;;;GAIG;AACH,MAAM,OAAO,WAAW;IACd,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC;IAE3B;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM;QAC1B,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,IAAI,CAAC,OAAO,cAAc,CAAC,CAAC;QACpE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CA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
|
|
2
|
+
export { EntityBuilder, entityBuilder } from './builders/EntityBuilder.js';
|
|
3
|
+
export { DataFactory } from './factories/DataFactory.js';
|
|
4
|
+
export { assertSuccess, assertFailure, unwrapSuccess, unwrapFailure } from './utils/assertions.js';
|
|
5
|
+
export { MockLLMProvider } from './MockLLMProvider.js';
|
|
6
|
+
export type { MockResponse } from './MockLLMProvider.js';
|
|
7
|
+
export { AgentTester } from './AgentTester.js';
|
|
8
|
+
export type { TestOptions, TestResult } from './AgentTester.js';
|
|
9
|
+
export { expectSuccess, expectFailure, expectData, expectDataContains, expectCostWithinBudget, expectDurationWithinLimit, expectErrorContains, expectModel, } from './assertions.js';
|
|
10
|
+
export { createTestContext, createTestAgentId, createDeterministicAgentId, wait, repeatTest, runInParallel, createTimeout, expectToReject, measureTime, } from './testHelpers.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAGnG,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEzD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAGhE,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB,EACzB,mBAAmB,EACnB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,0BAA0B,EAC1B,IAAI,EACJ,UAAU,EACV,aAAa,EACb,aAAa,EACb,cAAc,EACd,WAAW,GACZ,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Legacy testing utilities
|
|
2
|
+
export { TestApplication, createTestApp } from './TestApplication.js';
|
|
3
|
+
export { EntityBuilder, entityBuilder } from './builders/EntityBuilder.js';
|
|
4
|
+
export { DataFactory } from './factories/DataFactory.js';
|
|
5
|
+
export { assertSuccess, assertFailure, unwrapSuccess, unwrapFailure } from './utils/assertions.js';
|
|
6
|
+
// AI Agent testing utilities
|
|
7
|
+
export { MockLLMProvider } from './MockLLMProvider.js';
|
|
8
|
+
export { AgentTester } from './AgentTester.js';
|
|
9
|
+
// Agent-specific assertions
|
|
10
|
+
export { expectSuccess, expectFailure, expectData, expectDataContains, expectCostWithinBudget, expectDurationWithinLimit, expectErrorContains, expectModel, } from './assertions.js';
|
|
11
|
+
// Test helpers
|
|
12
|
+
export { createTestContext, createTestAgentId, createDeterministicAgentId, wait, repeatTest, runInParallel, createTimeout, expectToReject, measureTime, } from './testHelpers.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC3E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEnG,6BAA6B;AAC7B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAG/C,4BAA4B;AAC5B,OAAO,EACL,aAAa,EACb,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB,EACzB,mBAAmB,EACnB,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAEzB,eAAe;AACf,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,0BAA0B,EAC1B,IAAI,EACJ,UAAU,EACV,aAAa,EACb,aAAa,EACb,cAAc,EACd,WAAW,GACZ,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { AgentContext } from '@stratix/primitives';
|
|
2
|
+
import type { AgentId } from '@stratix/primitives';
|
|
3
|
+
/**
|
|
4
|
+
* Helper functions for creating test data
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Creates a test AgentContext with default values
|
|
8
|
+
*/
|
|
9
|
+
export declare function createTestContext(overrides?: Partial<{
|
|
10
|
+
userId: string;
|
|
11
|
+
sessionId: string;
|
|
12
|
+
environment: 'development' | 'staging' | 'production';
|
|
13
|
+
metadata: Record<string, unknown>;
|
|
14
|
+
budget: number;
|
|
15
|
+
}>): AgentContext;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a test AgentId
|
|
18
|
+
*/
|
|
19
|
+
export declare function createTestAgentId(): AgentId;
|
|
20
|
+
/**
|
|
21
|
+
* Waits for a specified duration (for testing delays)
|
|
22
|
+
*/
|
|
23
|
+
export declare function wait(ms: number): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Creates a deterministic AgentId for testing (using a seed)
|
|
26
|
+
*/
|
|
27
|
+
export declare function createDeterministicAgentId(_seed: string): AgentId;
|
|
28
|
+
/**
|
|
29
|
+
* Repeats a test function N times
|
|
30
|
+
*/
|
|
31
|
+
export declare function repeatTest<T>(times: number, testFn: (iteration: number) => Promise<T>): Promise<T[]>;
|
|
32
|
+
/**
|
|
33
|
+
* Runs tests in parallel
|
|
34
|
+
*/
|
|
35
|
+
export declare function runInParallel<T>(testFns: Array<() => Promise<T>>): Promise<T[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Creates a timeout promise for testing
|
|
38
|
+
*/
|
|
39
|
+
export declare function createTimeout(ms: number, message?: string): Promise<never>;
|
|
40
|
+
/**
|
|
41
|
+
* Asserts that a promise rejects with a specific error
|
|
42
|
+
*/
|
|
43
|
+
export declare function expectToReject(promise: Promise<unknown>, expectedError?: string | RegExp): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Measures execution time of an async function
|
|
46
|
+
*/
|
|
47
|
+
export declare function measureTime<T>(fn: () => Promise<T>): Promise<{
|
|
48
|
+
result: T;
|
|
49
|
+
duration: number;
|
|
50
|
+
}>;
|
|
51
|
+
//# sourceMappingURL=testHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testHelpers.d.ts","sourceRoot":"","sources":["../src/testHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAY,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAEnD;;GAEG;AAEH;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,aAAa,GAAG,SAAS,GAAG,YAAY,CAAC;IACtD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC,GACD,YAAY,CAad;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAE3C;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAE9C;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAKjE;AAED;;GAEG;AACH,wBAAsB,UAAU,CAAC,CAAC,EAChC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GACxC,OAAO,CAAC,CAAC,EAAE,CAAC,CAQd;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAErF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,CAM1E;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,EACzB,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,GAC9B,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,CAAC,EACjC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC;IAAE,MAAM,EAAE,CAAC,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAM1C"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { AgentContext, EntityId } from '@stratix/primitives';
|
|
2
|
+
/**
|
|
3
|
+
* Helper functions for creating test data
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Creates a test AgentContext with default values
|
|
7
|
+
*/
|
|
8
|
+
export function createTestContext(overrides) {
|
|
9
|
+
const context = new AgentContext({
|
|
10
|
+
userId: overrides?.userId || 'test-user',
|
|
11
|
+
sessionId: overrides?.sessionId || 'test-session',
|
|
12
|
+
environment: overrides?.environment || 'development',
|
|
13
|
+
metadata: overrides?.metadata,
|
|
14
|
+
});
|
|
15
|
+
if (overrides?.budget !== undefined) {
|
|
16
|
+
context.setBudget(overrides.budget);
|
|
17
|
+
}
|
|
18
|
+
return context;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Creates a test AgentId
|
|
22
|
+
*/
|
|
23
|
+
export function createTestAgentId() {
|
|
24
|
+
return EntityId.create();
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Waits for a specified duration (for testing delays)
|
|
28
|
+
*/
|
|
29
|
+
export function wait(ms) {
|
|
30
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Creates a deterministic AgentId for testing (using a seed)
|
|
34
|
+
*/
|
|
35
|
+
export function createDeterministicAgentId(_seed) {
|
|
36
|
+
// This creates a reproducible ID based on the seed
|
|
37
|
+
// In real tests, you might want actual deterministic UUIDs
|
|
38
|
+
// TODO: Implement actual deterministic UUID generation based on seed
|
|
39
|
+
return EntityId.create();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Repeats a test function N times
|
|
43
|
+
*/
|
|
44
|
+
export async function repeatTest(times, testFn) {
|
|
45
|
+
const results = [];
|
|
46
|
+
for (let i = 0; i < times; i++) {
|
|
47
|
+
results.push(await testFn(i));
|
|
48
|
+
}
|
|
49
|
+
return results;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Runs tests in parallel
|
|
53
|
+
*/
|
|
54
|
+
export async function runInParallel(testFns) {
|
|
55
|
+
return Promise.all(testFns.map((fn) => fn()));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Creates a timeout promise for testing
|
|
59
|
+
*/
|
|
60
|
+
export function createTimeout(ms, message) {
|
|
61
|
+
return new Promise((_, reject) => {
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
reject(new Error(message || `Timeout after ${ms}ms`));
|
|
64
|
+
}, ms);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Asserts that a promise rejects with a specific error
|
|
69
|
+
*/
|
|
70
|
+
export async function expectToReject(promise, expectedError) {
|
|
71
|
+
try {
|
|
72
|
+
await promise;
|
|
73
|
+
throw new Error('Expected promise to reject but it resolved');
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (expectedError) {
|
|
77
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
78
|
+
if (typeof expectedError === 'string') {
|
|
79
|
+
if (!message.includes(expectedError)) {
|
|
80
|
+
throw new Error(`Expected error to include "${expectedError}" but got "${message}"`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
if (!expectedError.test(message)) {
|
|
85
|
+
throw new Error(`Expected error to match ${expectedError} but got "${message}"`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Measures execution time of an async function
|
|
93
|
+
*/
|
|
94
|
+
export async function measureTime(fn) {
|
|
95
|
+
const start = Date.now();
|
|
96
|
+
const result = await fn();
|
|
97
|
+
const duration = Date.now() - start;
|
|
98
|
+
return { result, duration };
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=testHelpers.js.map
|