@ontrails/testing 1.0.0-beta.2 → 1.0.0-beta.21
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 +396 -5
- package/README.md +86 -22
- package/package.json +34 -5
- package/src/all-established.ts +168 -0
- package/src/all.ts +51 -12
- package/src/assertions.ts +253 -0
- package/src/cli.ts +6 -0
- package/src/composes.ts +433 -0
- package/src/context.ts +200 -14
- package/src/contracts.ts +45 -21
- package/src/detours.ts +155 -18
- package/src/effective-examples.ts +414 -0
- package/src/errors.ts +47 -0
- package/src/examples.ts +302 -177
- package/src/harness-cli.ts +83 -58
- package/src/harness-http.ts +341 -0
- package/src/harness-mcp.ts +46 -16
- package/src/http.ts +10 -0
- package/src/index.ts +22 -14
- package/src/logger.ts +3 -1
- package/src/mcp.ts +6 -0
- package/src/scenario.ts +375 -0
- package/src/signals.ts +221 -0
- package/src/surface-parity.ts +389 -0
- package/src/trail.ts +1 -1
- package/src/types.ts +24 -52
- package/.turbo/turbo-build.log +0 -1
- package/.turbo/turbo-lint.log +0 -3
- package/.turbo/turbo-typecheck.log +0 -1
- package/dist/all.d.ts +0 -30
- package/dist/all.d.ts.map +0 -1
- package/dist/all.js +0 -47
- package/dist/all.js.map +0 -1
- package/dist/assertions.d.ts +0 -49
- package/dist/assertions.d.ts.map +0 -1
- package/dist/assertions.js +0 -84
- package/dist/assertions.js.map +0 -1
- package/dist/context.d.ts +0 -19
- package/dist/context.d.ts.map +0 -1
- package/dist/context.js +0 -33
- package/dist/context.js.map +0 -1
- package/dist/contracts.d.ts +0 -16
- package/dist/contracts.d.ts.map +0 -1
- package/dist/contracts.js +0 -56
- package/dist/contracts.js.map +0 -1
- package/dist/detours.d.ts +0 -12
- package/dist/detours.d.ts.map +0 -1
- package/dist/detours.js +0 -30
- package/dist/detours.js.map +0 -1
- package/dist/examples.d.ts +0 -22
- package/dist/examples.d.ts.map +0 -1
- package/dist/examples.js +0 -187
- package/dist/examples.js.map +0 -1
- package/dist/harness-cli.d.ts +0 -21
- package/dist/harness-cli.d.ts.map +0 -1
- package/dist/harness-cli.js +0 -213
- package/dist/harness-cli.js.map +0 -1
- package/dist/harness-mcp.d.ts +0 -21
- package/dist/harness-mcp.d.ts.map +0 -1
- package/dist/harness-mcp.js +0 -50
- package/dist/harness-mcp.js.map +0 -1
- package/dist/hike.d.ts +0 -32
- package/dist/hike.d.ts.map +0 -1
- package/dist/hike.js +0 -169
- package/dist/hike.js.map +0 -1
- package/dist/index.d.ts +0 -14
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -16
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -15
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -87
- package/dist/logger.js.map +0 -1
- package/dist/trail.d.ts +0 -20
- package/dist/trail.d.ts.map +0 -1
- package/dist/trail.js +0 -80
- package/dist/trail.js.map +0 -1
- package/dist/types.d.ts +0 -80
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/src/__tests__/context.test.ts +0 -60
- package/src/__tests__/contracts.test.ts +0 -68
- package/src/__tests__/detours.test.ts +0 -55
- package/src/__tests__/examples.test.ts +0 -176
- package/src/__tests__/hike.test.ts +0 -164
- package/src/__tests__/logger.test.ts +0 -136
- package/src/__tests__/trail.test.ts +0 -99
- package/src/hike.ts +0 -283
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
package/dist/logger.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test logger that captures log records for assertion.
|
|
3
|
-
*/
|
|
4
|
-
// ---------------------------------------------------------------------------
|
|
5
|
-
// Level ordering for filtering
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
7
|
-
const LEVEL_ORDER = {
|
|
8
|
-
debug: 1,
|
|
9
|
-
error: 4,
|
|
10
|
-
fatal: 5,
|
|
11
|
-
info: 2,
|
|
12
|
-
silent: 6,
|
|
13
|
-
trace: 0,
|
|
14
|
-
warn: 3,
|
|
15
|
-
};
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
// Internal factory (shared between root and child loggers)
|
|
18
|
-
// ---------------------------------------------------------------------------
|
|
19
|
-
const createTestLoggerInternal = (name, minLevel, sharedEntries, baseMetadata) => {
|
|
20
|
-
const minOrder = LEVEL_ORDER[minLevel] ?? 0;
|
|
21
|
-
const shouldLog = (level) => (LEVEL_ORDER[level] ?? 0) >= minOrder;
|
|
22
|
-
const log = (level, message, metadata) => {
|
|
23
|
-
if (!shouldLog(level)) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const record = {
|
|
27
|
-
category: name,
|
|
28
|
-
level,
|
|
29
|
-
message,
|
|
30
|
-
metadata: { ...baseMetadata, ...metadata },
|
|
31
|
-
timestamp: new Date(),
|
|
32
|
-
};
|
|
33
|
-
sharedEntries.push(record);
|
|
34
|
-
};
|
|
35
|
-
return {
|
|
36
|
-
assertLogged(level, messageSubstring) {
|
|
37
|
-
const match = sharedEntries.find((r) => r.level === level && r.message.includes(messageSubstring));
|
|
38
|
-
if (match === undefined) {
|
|
39
|
-
throw new Error(`Expected a log entry with level="${level}" containing "${messageSubstring}", but none was found. ` +
|
|
40
|
-
`Entries: ${JSON.stringify(sharedEntries.map((r) => ({ level: r.level, message: r.message })))}`);
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
child(metadata) {
|
|
44
|
-
const merged = { ...baseMetadata, ...metadata };
|
|
45
|
-
return createTestLoggerInternal(name, minLevel, sharedEntries, merged);
|
|
46
|
-
},
|
|
47
|
-
clear() {
|
|
48
|
-
sharedEntries.length = 0;
|
|
49
|
-
},
|
|
50
|
-
debug(message, metadata) {
|
|
51
|
-
log('debug', message, metadata);
|
|
52
|
-
},
|
|
53
|
-
get entries() {
|
|
54
|
-
return sharedEntries;
|
|
55
|
-
},
|
|
56
|
-
error(message, metadata) {
|
|
57
|
-
log('error', message, metadata);
|
|
58
|
-
},
|
|
59
|
-
fatal(message, metadata) {
|
|
60
|
-
log('fatal', message, metadata);
|
|
61
|
-
},
|
|
62
|
-
find(predicate) {
|
|
63
|
-
return sharedEntries.filter(predicate);
|
|
64
|
-
},
|
|
65
|
-
info(message, metadata) {
|
|
66
|
-
log('info', message, metadata);
|
|
67
|
-
},
|
|
68
|
-
name,
|
|
69
|
-
trace(message, metadata) {
|
|
70
|
-
log('trace', message, metadata);
|
|
71
|
-
},
|
|
72
|
-
warn(message, metadata) {
|
|
73
|
-
log('warn', message, metadata);
|
|
74
|
-
},
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
// ---------------------------------------------------------------------------
|
|
78
|
-
// createTestLogger
|
|
79
|
-
// ---------------------------------------------------------------------------
|
|
80
|
-
/**
|
|
81
|
-
* Create a test logger that captures all log records in an array.
|
|
82
|
-
*
|
|
83
|
-
* Records are not printed. Use `entries`, `find()`, and `assertLogged()`
|
|
84
|
-
* to inspect what was logged during a test.
|
|
85
|
-
*/
|
|
86
|
-
export const createTestLogger = (options) => createTestLoggerInternal('test', options?.level ?? 'trace', [], {});
|
|
87
|
-
//# sourceMappingURL=logger.js.map
|
package/dist/logger.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,8EAA8E;AAC9E,+BAA+B;AAC/B,8EAA8E;AAE9E,MAAM,WAAW,GAA2B;IAC1C,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;CACR,CAAC;AAEF,8EAA8E;AAC9E,2DAA2D;AAC3D,8EAA8E;AAE9E,MAAM,wBAAwB,GAAG,CAC/B,IAAY,EACZ,QAAkB,EAClB,aAA0B,EAC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AI,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC"}
|
package/dist/trail.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* testTrail — custom scenario testing for individual trails.
|
|
3
|
-
*
|
|
4
|
-
* Use this for edge cases, boundary values, and regression tests
|
|
5
|
-
* that don't belong in `examples` (which are agent-facing documentation).
|
|
6
|
-
*/
|
|
7
|
-
import type { AnyTrail, TrailContext } from '@ontrails/core';
|
|
8
|
-
import type { TestScenario } from './types.js';
|
|
9
|
-
/**
|
|
10
|
-
* Generate a describe block for a trail with one test per scenario.
|
|
11
|
-
*
|
|
12
|
-
* ```ts
|
|
13
|
-
* testTrail(myTrail, [
|
|
14
|
-
* { description: "valid input", input: { name: "Alpha" }, expectOk: true },
|
|
15
|
-
* { description: "missing name", input: {}, expectErr: ValidationError },
|
|
16
|
-
* ]);
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export declare const testTrail: (trailDef: AnyTrail, scenarios: readonly TestScenario[], ctx?: Partial<TrailContext>) => void;
|
|
20
|
-
//# sourceMappingURL=trail.d.ts.map
|
package/dist/trail.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trail.d.ts","sourceRoot":"","sources":["../src/trail.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,QAAQ,EAAU,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAUrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAyE/C;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,GACpB,UAAU,QAAQ,EAClB,WAAW,SAAS,YAAY,EAAE,EAClC,MAAM,OAAO,CAAC,YAAY,CAAC,KAC1B,IASF,CAAC"}
|
package/dist/trail.js
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* testTrail — custom scenario testing for individual trails.
|
|
3
|
-
*
|
|
4
|
-
* Use this for edge cases, boundary values, and regression tests
|
|
5
|
-
* that don't belong in `examples` (which are agent-facing documentation).
|
|
6
|
-
*/
|
|
7
|
-
import { describe, expect, test } from 'bun:test';
|
|
8
|
-
import { ValidationError, validateInput } from '@ontrails/core';
|
|
9
|
-
import { assertErrorMatch, assertFullMatch, assertSchemaMatch, expectOk, } from './assertions.js';
|
|
10
|
-
import { mergeTestContext } from './context.js';
|
|
11
|
-
// ---------------------------------------------------------------------------
|
|
12
|
-
// Helpers
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
const assertScenarioResult = (result, scenario, trailDef) => {
|
|
15
|
-
if (scenario.expectValue !== undefined) {
|
|
16
|
-
assertFullMatch(result, scenario.expectValue);
|
|
17
|
-
}
|
|
18
|
-
else if (scenario.expectErr !== undefined) {
|
|
19
|
-
assertErrorMatch(result, scenario.expectErr, scenario.expectErrMessage);
|
|
20
|
-
}
|
|
21
|
-
else if (scenario.expectErrMessage !== undefined) {
|
|
22
|
-
expect(result.isErr()).toBe(true);
|
|
23
|
-
if (result.isErr()) {
|
|
24
|
-
expect(result.error.message).toContain(scenario.expectErrMessage);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else if (scenario.expectOk === true) {
|
|
28
|
-
expect(result.isOk()).toBe(true);
|
|
29
|
-
assertSchemaMatch(result, trailDef.output);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Handle input validation failure for a scenario.
|
|
34
|
-
* Returns true if the error was expected and handled.
|
|
35
|
-
* Throws if the error was unexpected.
|
|
36
|
-
*/
|
|
37
|
-
const handleValidationError = (validated, scenario) => {
|
|
38
|
-
if (!validated.isErr()) {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
if (scenario.expectErr === ValidationError) {
|
|
42
|
-
expect(validated.error).toBeInstanceOf(ValidationError);
|
|
43
|
-
if (scenario.expectErrMessage !== undefined) {
|
|
44
|
-
expect(validated.error.message).toContain(scenario.expectErrMessage);
|
|
45
|
-
}
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
throw new Error(`Input validation failed unexpectedly: ${validated.error.message}`);
|
|
49
|
-
};
|
|
50
|
-
const runScenario = async (trailDef, scenario, ctx) => {
|
|
51
|
-
const testCtx = mergeTestContext(ctx);
|
|
52
|
-
const validated = validateInput(trailDef.input, scenario.input);
|
|
53
|
-
if (handleValidationError(validated, scenario)) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const validatedInput = expectOk(validated);
|
|
57
|
-
const result = await trailDef.implementation(validatedInput, testCtx);
|
|
58
|
-
assertScenarioResult(result, scenario, trailDef);
|
|
59
|
-
};
|
|
60
|
-
// ---------------------------------------------------------------------------
|
|
61
|
-
// testTrail
|
|
62
|
-
// ---------------------------------------------------------------------------
|
|
63
|
-
/**
|
|
64
|
-
* Generate a describe block for a trail with one test per scenario.
|
|
65
|
-
*
|
|
66
|
-
* ```ts
|
|
67
|
-
* testTrail(myTrail, [
|
|
68
|
-
* { description: "valid input", input: { name: "Alpha" }, expectOk: true },
|
|
69
|
-
* { description: "missing name", input: {}, expectErr: ValidationError },
|
|
70
|
-
* ]);
|
|
71
|
-
* ```
|
|
72
|
-
*/
|
|
73
|
-
export const testTrail = (trailDef, scenarios, ctx) => {
|
|
74
|
-
describe(trailDef.id, () => {
|
|
75
|
-
test.each([...scenarios])('$description', async (scenario) => {
|
|
76
|
-
await runScenario(trailDef, scenario, ctx);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
//# sourceMappingURL=trail.js.map
|
package/dist/trail.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"trail.js","sourceRoot":"","sources":["../src/trail.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGlD,OAAO,EAAE,eAAe,EAAE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C,QAAQ,CAAC,EAAE,EAAE,GAAG,EAAE;QACzB,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CACvB,cAAc,EACd,KAAK,EAAE,QAAsB,EAAE,EAAE;YAC/B,MAAM,WAAW,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;QAC7C,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
|
package/dist/types.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared types for @ontrails/testing.
|
|
3
|
-
*/
|
|
4
|
-
import type { Logger, Topo } from '@ontrails/core';
|
|
5
|
-
import type { LogLevel, LogRecord } from '@ontrails/logging';
|
|
6
|
-
/** A custom test scenario for a single trail. */
|
|
7
|
-
export interface TestScenario {
|
|
8
|
-
/** Description shown in test output. */
|
|
9
|
-
readonly description?: string | undefined;
|
|
10
|
-
/** Assert the result error has this message (substring match). */
|
|
11
|
-
readonly expectErrMessage?: string | undefined;
|
|
12
|
-
/** Assert the result is an error of this type. */
|
|
13
|
-
readonly expectErr?: (new (...args: never[]) => Error) | undefined;
|
|
14
|
-
/** Assert the result is ok. */
|
|
15
|
-
readonly expectOk?: boolean | undefined;
|
|
16
|
-
/** Assert the result value equals this. */
|
|
17
|
-
readonly expectValue?: unknown | undefined;
|
|
18
|
-
/** Input to pass to the implementation. */
|
|
19
|
-
readonly input: unknown;
|
|
20
|
-
}
|
|
21
|
-
/** A test scenario for a hike's composition graph. */
|
|
22
|
-
export interface HikeScenario extends TestScenario {
|
|
23
|
-
/** Assert these trail IDs were followed, in order. */
|
|
24
|
-
readonly expectFollowed?: readonly string[] | undefined;
|
|
25
|
-
/** Assert follow counts per trail ID. */
|
|
26
|
-
readonly expectFollowedCount?: Readonly<Record<string, number>> | undefined;
|
|
27
|
-
/** Inject failure from a followed trail's example by description. */
|
|
28
|
-
readonly injectFromExample?: Readonly<Record<string, string>> | undefined;
|
|
29
|
-
}
|
|
30
|
-
/** A logger that captures entries for assertion in tests. */
|
|
31
|
-
export interface TestLogger extends Logger {
|
|
32
|
-
/** All log records captured during the test. */
|
|
33
|
-
readonly entries: readonly LogRecord[];
|
|
34
|
-
/** Clear captured entries. */
|
|
35
|
-
clear(): void;
|
|
36
|
-
/** Find entries matching a predicate. */
|
|
37
|
-
find(predicate: (record: LogRecord) => boolean): readonly LogRecord[];
|
|
38
|
-
/** Assert that at least one entry matches. */
|
|
39
|
-
assertLogged(level: LogLevel, messageSubstring: string): void;
|
|
40
|
-
}
|
|
41
|
-
/** Options for creating a test trail context. */
|
|
42
|
-
export interface TestTrailContextOptions {
|
|
43
|
-
readonly cwd?: string | undefined;
|
|
44
|
-
readonly env?: Record<string, string> | undefined;
|
|
45
|
-
readonly logger?: Logger | undefined;
|
|
46
|
-
readonly requestId?: string | undefined;
|
|
47
|
-
readonly signal?: AbortSignal | undefined;
|
|
48
|
-
}
|
|
49
|
-
/** Options for creating a CLI harness. */
|
|
50
|
-
export interface CliHarnessOptions {
|
|
51
|
-
readonly app: Topo;
|
|
52
|
-
}
|
|
53
|
-
/** A test harness for CLI commands. */
|
|
54
|
-
export interface CliHarness {
|
|
55
|
-
/** Execute a CLI command string and capture output. */
|
|
56
|
-
run(command: string): Promise<CliHarnessResult>;
|
|
57
|
-
}
|
|
58
|
-
/** The result of a CLI harness command execution. */
|
|
59
|
-
export interface CliHarnessResult {
|
|
60
|
-
readonly exitCode: number;
|
|
61
|
-
/** Parsed JSON output if --output json was used. */
|
|
62
|
-
readonly json?: unknown | undefined;
|
|
63
|
-
readonly stderr: string;
|
|
64
|
-
readonly stdout: string;
|
|
65
|
-
}
|
|
66
|
-
/** Options for creating an MCP harness. */
|
|
67
|
-
export interface McpHarnessOptions {
|
|
68
|
-
readonly app: Topo;
|
|
69
|
-
}
|
|
70
|
-
/** A test harness for MCP tools. */
|
|
71
|
-
export interface McpHarness {
|
|
72
|
-
/** Call an MCP tool by name with arguments. */
|
|
73
|
-
callTool(name: string, args: Record<string, unknown>): Promise<McpHarnessResult>;
|
|
74
|
-
}
|
|
75
|
-
/** The result of an MCP harness tool invocation. */
|
|
76
|
-
export interface McpHarnessResult {
|
|
77
|
-
readonly content: unknown;
|
|
78
|
-
readonly isError: boolean;
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAM7D,iDAAiD;AACjD,MAAM,WAAW,YAAY;IAC3B,wCAAwC;IACxC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C,kEAAkE;IAClE,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/C,kDAAkD;IAClD,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,KAAK,CAAC,GAAG,SAAS,CAAC;IACnE,+BAA+B;IAC/B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC,2CAA2C;IAC3C,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3C,2CAA2C;IAC3C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB;AAMD,sDAAsD;AACtD,MAAM,WAAW,YAAa,SAAQ,YAAY;IAChD,sDAAsD;IACtD,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC;IACxD,yCAAyC;IACzC,QAAQ,CAAC,mB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AACrD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,oDAAoD;IACpD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAMD,2CAA2C;AAC3C,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,EAAE,IAAI,CAAC;CACpB;AAED,oCAAoC;AACpC,MAAM,WAAW,UAAU;IACzB,+CAA+C;IAC/C,QAAQ,CACN,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC5B,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAC9B;AAED,oDAAoD;AACpD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B"}
|
package/dist/types.js
DELETED
package/dist/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import { createTestContext } from '../context.js';
|
|
4
|
-
import type { TestLogger } from '../types.js';
|
|
5
|
-
|
|
6
|
-
// ---------------------------------------------------------------------------
|
|
7
|
-
// Tests
|
|
8
|
-
// ---------------------------------------------------------------------------
|
|
9
|
-
|
|
10
|
-
describe('createTestContext', () => {
|
|
11
|
-
test('produces a valid TrailContext with no args', () => {
|
|
12
|
-
const ctx = createTestContext();
|
|
13
|
-
expect(ctx.requestId).toBe('test-request-001');
|
|
14
|
-
expect(ctx.signal).toBeDefined();
|
|
15
|
-
expect(ctx.signal.aborted).toBe(false);
|
|
16
|
-
expect(ctx.logger).toBeDefined();
|
|
17
|
-
expect(ctx.workspaceRoot).toBeDefined();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('default logger is a TestLogger', () => {
|
|
21
|
-
const ctx = createTestContext();
|
|
22
|
-
const logger = ctx.logger as TestLogger;
|
|
23
|
-
expect(typeof logger.info).toBe('function');
|
|
24
|
-
expect(typeof logger.clear).toBe('function');
|
|
25
|
-
expect(typeof logger.find).toBe('function');
|
|
26
|
-
expect(typeof logger.assertLogged).toBe('function');
|
|
27
|
-
expect(logger.entries).toBeDefined();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('default env is set to test', () => {
|
|
31
|
-
const ctx = createTestContext();
|
|
32
|
-
const env = ctx['env'] as Record<string, string>;
|
|
33
|
-
expect(env).toEqual({ TRAILS_ENV: 'test' });
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('overrides requestId', () => {
|
|
37
|
-
const ctx = createTestContext({ requestId: 'custom-id' });
|
|
38
|
-
expect(ctx.requestId).toBe('custom-id');
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('overrides signal', () => {
|
|
42
|
-
const controller = new AbortController();
|
|
43
|
-
controller.abort();
|
|
44
|
-
const ctx = createTestContext({ signal: controller.signal });
|
|
45
|
-
expect(ctx.signal.aborted).toBe(true);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('overrides cwd', () => {
|
|
49
|
-
const ctx = createTestContext({ cwd: '/tmp/test' });
|
|
50
|
-
expect(ctx.workspaceRoot).toBe('/tmp/test');
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('overrides env', () => {
|
|
54
|
-
const ctx = createTestContext({
|
|
55
|
-
env: { CUSTOM: '1', NODE_ENV: 'test' },
|
|
56
|
-
});
|
|
57
|
-
const env = ctx['env'] as Record<string, string>;
|
|
58
|
-
expect(env).toEqual({ CUSTOM: '1', NODE_ENV: 'test' });
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { describe, test } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import { Result, trail, topo } from '@ontrails/core';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
|
|
6
|
-
import { testContracts } from '../contracts.js';
|
|
7
|
-
|
|
8
|
-
// ---------------------------------------------------------------------------
|
|
9
|
-
// Test trails
|
|
10
|
-
// ---------------------------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
/** Trail whose implementation matches the output schema. */
|
|
13
|
-
const validTrail = trail('valid', {
|
|
14
|
-
examples: [
|
|
15
|
-
{
|
|
16
|
-
expected: { id: 1, name: 'Alpha' },
|
|
17
|
-
input: { name: 'Alpha' },
|
|
18
|
-
name: 'Valid output',
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
implementation: (input: { name: string }) =>
|
|
22
|
-
Result.ok({ id: 1, name: input.name }),
|
|
23
|
-
input: z.object({ name: z.string() }),
|
|
24
|
-
output: z.object({ id: z.number(), name: z.string() }),
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
/** Trail without output schema -- should be skipped. */
|
|
28
|
-
const noSchemaTrail = trail('noschema', {
|
|
29
|
-
examples: [{ expected: 10, input: { x: 5 }, name: 'No schema' }],
|
|
30
|
-
implementation: (input: { x: number }) => Result.ok(input.x * 2),
|
|
31
|
-
input: z.object({ x: z.number() }),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
/** Trail without examples -- should be skipped. */
|
|
35
|
-
const noExamplesTrail = trail('noexamples', {
|
|
36
|
-
implementation: (input: { x: number }) => Result.ok({ value: input.x }),
|
|
37
|
-
input: z.object({ x: z.number() }),
|
|
38
|
-
output: z.object({ value: z.number() }),
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// ---------------------------------------------------------------------------
|
|
42
|
-
// Tests
|
|
43
|
-
// ---------------------------------------------------------------------------
|
|
44
|
-
|
|
45
|
-
describe('testContracts: valid output matches schema', () => {
|
|
46
|
-
// eslint-disable-next-line jest/require-hook
|
|
47
|
-
testContracts(topo('test-app', { validTrail } as Record<string, unknown>));
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('testContracts: skips trails without output schemas', () => {
|
|
51
|
-
// eslint-disable-next-line jest/require-hook
|
|
52
|
-
testContracts(topo('test-app', { noSchemaTrail } as Record<string, unknown>));
|
|
53
|
-
|
|
54
|
-
test('no-op marker', () => {
|
|
55
|
-
// Trail without output schema is skipped -- no contract tests generated
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('testContracts: skips trails without examples', () => {
|
|
60
|
-
// eslint-disable-next-line jest/require-hook
|
|
61
|
-
testContracts(
|
|
62
|
-
topo('test-app', { noExamplesTrail } as Record<string, unknown>)
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
test('no-op marker', () => {
|
|
66
|
-
// Trail without examples is skipped -- no contract tests generated
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { describe, test } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import { Result, trail, topo } from '@ontrails/core';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
|
|
6
|
-
import { testDetours } from '../detours.js';
|
|
7
|
-
|
|
8
|
-
// ---------------------------------------------------------------------------
|
|
9
|
-
// Test trails
|
|
10
|
-
// ---------------------------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
const showTrail = trail('entity.show', {
|
|
13
|
-
detours: {
|
|
14
|
-
related: ['entity.list'],
|
|
15
|
-
},
|
|
16
|
-
implementation: (input: { id: string }) => Result.ok({ id: input.id }),
|
|
17
|
-
input: z.object({ id: z.string() }),
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const listTrail = trail('entity.list', {
|
|
21
|
-
implementation: () => Result.ok([]),
|
|
22
|
-
input: z.object({}),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const noDetoursTrail = trail('entity.plain', {
|
|
26
|
-
implementation: () => Result.ok('ok'),
|
|
27
|
-
input: z.object({}),
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// ---------------------------------------------------------------------------
|
|
31
|
-
// Tests
|
|
32
|
-
// ---------------------------------------------------------------------------
|
|
33
|
-
|
|
34
|
-
describe('testDetours: all targets exist', () => {
|
|
35
|
-
// eslint-disable-next-line jest/require-hook
|
|
36
|
-
testDetours(
|
|
37
|
-
topo('test-app', {
|
|
38
|
-
listTrail,
|
|
39
|
-
showTrail,
|
|
40
|
-
} as Record<string, unknown>)
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('testDetours: skips trails without detours', () => {
|
|
45
|
-
// eslint-disable-next-line jest/require-hook
|
|
46
|
-
testDetours(
|
|
47
|
-
topo('test-app', {
|
|
48
|
-
noDetoursTrail,
|
|
49
|
-
} as Record<string, unknown>)
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
test('no-op marker', () => {
|
|
53
|
-
// Trail without detours is skipped -- no detour tests generated
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { describe, test } from 'bun:test';
|
|
2
|
-
|
|
3
|
-
import { NotFoundError, Result, hike, trail, topo } from '@ontrails/core';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
|
|
6
|
-
import { testExamples } from '../examples.js';
|
|
7
|
-
|
|
8
|
-
// ---------------------------------------------------------------------------
|
|
9
|
-
// Test trails
|
|
10
|
-
// ---------------------------------------------------------------------------
|
|
11
|
-
|
|
12
|
-
const greetTrail = trail('greet', {
|
|
13
|
-
description: 'Greet someone',
|
|
14
|
-
examples: [
|
|
15
|
-
{
|
|
16
|
-
expected: { greeting: 'Hello, Alice' },
|
|
17
|
-
input: { name: 'Alice' },
|
|
18
|
-
name: 'Greet Alice',
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
implementation: (input: { name: string }) =>
|
|
22
|
-
Result.ok({ greeting: `Hello, ${input.name}` }),
|
|
23
|
-
input: z.object({ name: z.string() }),
|
|
24
|
-
output: z.object({ greeting: z.string() }),
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const searchTrail = trail('search', {
|
|
28
|
-
description: 'Search for things',
|
|
29
|
-
examples: [
|
|
30
|
-
{
|
|
31
|
-
input: { query: 'test' },
|
|
32
|
-
name: 'Schema-only search',
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
implementation: (input: { query: string }) =>
|
|
36
|
-
Result.ok({ results: [`result for ${input.query}`] }),
|
|
37
|
-
input: z.object({ query: z.string() }),
|
|
38
|
-
output: z.object({ results: z.array(z.string()) }),
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const entityTrail = trail('entity.show', {
|
|
42
|
-
description: 'Show entity',
|
|
43
|
-
examples: [
|
|
44
|
-
{
|
|
45
|
-
expected: { id: 1, name: 'Alpha' },
|
|
46
|
-
input: { name: 'Alpha' },
|
|
47
|
-
name: 'Show entity by name',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
error: 'NotFoundError',
|
|
51
|
-
input: { name: 'missing' },
|
|
52
|
-
name: 'Entity not found returns NotFoundError',
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
implementation: (input: { name: string }) => {
|
|
56
|
-
if (input.name === 'missing') {
|
|
57
|
-
return Result.err(new NotFoundError('Entity not found'));
|
|
58
|
-
}
|
|
59
|
-
return Result.ok({ id: 1, name: input.name });
|
|
60
|
-
},
|
|
61
|
-
input: z.object({ name: z.string() }),
|
|
62
|
-
output: z.object({ id: z.number(), name: z.string() }),
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const noExamplesTrail = trail('noexamples', {
|
|
66
|
-
implementation: (input: { x: number }) => Result.ok(input.x * 2),
|
|
67
|
-
input: z.object({ x: z.number() }),
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// ---------------------------------------------------------------------------
|
|
71
|
-
// Test hikes (for follows coverage)
|
|
72
|
-
// ---------------------------------------------------------------------------
|
|
73
|
-
|
|
74
|
-
const addTrail = trail('entity.add', {
|
|
75
|
-
description: 'Add an entity',
|
|
76
|
-
implementation: (input: { name: string }) =>
|
|
77
|
-
Result.ok({ id: '1', name: input.name }),
|
|
78
|
-
input: z.object({ name: z.string() }),
|
|
79
|
-
output: z.object({ id: z.string(), name: z.string() }),
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const relateTrail = trail('entity.relate', {
|
|
83
|
-
description: 'Relate entities',
|
|
84
|
-
implementation: (input: { from: string; to: string }) =>
|
|
85
|
-
Result.ok({ from: input.from, to: input.to }),
|
|
86
|
-
input: z.object({ from: z.string(), to: z.string() }),
|
|
87
|
-
output: z.object({ from: z.string(), to: z.string() }),
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
const onboardHike = hike('entity.onboard', {
|
|
91
|
-
description: 'Onboard a new entity',
|
|
92
|
-
examples: [
|
|
93
|
-
{
|
|
94
|
-
expected: { id: '1', name: 'Alpha' },
|
|
95
|
-
input: { name: 'Alpha' },
|
|
96
|
-
name: 'Onboard Alpha',
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
follows: ['entity.add', 'entity.relate'],
|
|
100
|
-
implementation: async (input: { name: string }, ctx) => {
|
|
101
|
-
if (!ctx.follow) {
|
|
102
|
-
return Result.err(new Error('follow not available'));
|
|
103
|
-
}
|
|
104
|
-
const addResult = await ctx.follow('entity.add', input);
|
|
105
|
-
if (addResult.isErr()) {
|
|
106
|
-
return addResult;
|
|
107
|
-
}
|
|
108
|
-
const relateResult = await ctx.follow('entity.relate', {
|
|
109
|
-
from: 'root',
|
|
110
|
-
to: (addResult.value as { id: string }).id,
|
|
111
|
-
});
|
|
112
|
-
if (relateResult.isErr()) {
|
|
113
|
-
return relateResult;
|
|
114
|
-
}
|
|
115
|
-
return Result.ok({ id: '1', name: input.name });
|
|
116
|
-
},
|
|
117
|
-
input: z.object({ name: z.string() }),
|
|
118
|
-
output: z.object({ id: z.string(), name: z.string() }),
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// ---------------------------------------------------------------------------
|
|
122
|
-
// Tests
|
|
123
|
-
// ---------------------------------------------------------------------------
|
|
124
|
-
|
|
125
|
-
describe('testExamples', () => {
|
|
126
|
-
// eslint-disable-next-line jest/require-hook
|
|
127
|
-
testExamples(
|
|
128
|
-
topo('test-app', {
|
|
129
|
-
entityTrail,
|
|
130
|
-
greetTrail,
|
|
131
|
-
noExamplesTrail,
|
|
132
|
-
searchTrail,
|
|
133
|
-
} as Record<string, unknown>)
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
// Also test with custom context (static form)
|
|
137
|
-
describe('with custom context', () => {
|
|
138
|
-
// eslint-disable-next-line jest/require-hook
|
|
139
|
-
testExamples(topo('ctx-app', { greetTrail } as Record<string, unknown>), {
|
|
140
|
-
requestId: 'custom-request',
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// Test with factory form (each test gets a fresh context)
|
|
145
|
-
describe('with context factory', () => {
|
|
146
|
-
// eslint-disable-next-line jest/require-hook
|
|
147
|
-
testExamples(
|
|
148
|
-
topo('factory-app', { greetTrail } as Record<string, unknown>),
|
|
149
|
-
() => ({ requestId: `factory-${crypto.randomUUID()}` })
|
|
150
|
-
);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
describe('testExamples skips trails with no examples', () => {
|
|
155
|
-
// eslint-disable-next-line jest/require-hook
|
|
156
|
-
testExamples(
|
|
157
|
-
topo('skip-app', {
|
|
158
|
-
noExamplesTrail,
|
|
159
|
-
} as Record<string, unknown>)
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
test('no-op marker', () => {
|
|
163
|
-
// This test exists so the describe block is not empty
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe('testExamples follows coverage for hikes', () => {
|
|
168
|
-
// eslint-disable-next-line jest/require-hook
|
|
169
|
-
testExamples(
|
|
170
|
-
topo('hike-app', {
|
|
171
|
-
addTrail,
|
|
172
|
-
onboardHike,
|
|
173
|
-
relateTrail,
|
|
174
|
-
} as Record<string, unknown>)
|
|
175
|
-
);
|
|
176
|
-
});
|