@ontrails/testing 1.0.0-beta.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.
Files changed (80) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/.turbo/turbo-lint.log +3 -0
  3. package/.turbo/turbo-typecheck.log +1 -0
  4. package/CHANGELOG.md +23 -0
  5. package/README.md +221 -0
  6. package/dist/all.d.ts +30 -0
  7. package/dist/all.d.ts.map +1 -0
  8. package/dist/all.js +47 -0
  9. package/dist/all.js.map +1 -0
  10. package/dist/assertions.d.ts +49 -0
  11. package/dist/assertions.d.ts.map +1 -0
  12. package/dist/assertions.js +84 -0
  13. package/dist/assertions.js.map +1 -0
  14. package/dist/context.d.ts +19 -0
  15. package/dist/context.d.ts.map +1 -0
  16. package/dist/context.js +33 -0
  17. package/dist/context.js.map +1 -0
  18. package/dist/contracts.d.ts +16 -0
  19. package/dist/contracts.d.ts.map +1 -0
  20. package/dist/contracts.js +56 -0
  21. package/dist/contracts.js.map +1 -0
  22. package/dist/detours.d.ts +12 -0
  23. package/dist/detours.d.ts.map +1 -0
  24. package/dist/detours.js +30 -0
  25. package/dist/detours.js.map +1 -0
  26. package/dist/examples.d.ts +22 -0
  27. package/dist/examples.d.ts.map +1 -0
  28. package/dist/examples.js +187 -0
  29. package/dist/examples.js.map +1 -0
  30. package/dist/harness-cli.d.ts +21 -0
  31. package/dist/harness-cli.d.ts.map +1 -0
  32. package/dist/harness-cli.js +213 -0
  33. package/dist/harness-cli.js.map +1 -0
  34. package/dist/harness-mcp.d.ts +21 -0
  35. package/dist/harness-mcp.d.ts.map +1 -0
  36. package/dist/harness-mcp.js +50 -0
  37. package/dist/harness-mcp.js.map +1 -0
  38. package/dist/hike.d.ts +32 -0
  39. package/dist/hike.d.ts.map +1 -0
  40. package/dist/hike.js +169 -0
  41. package/dist/hike.js.map +1 -0
  42. package/dist/index.d.ts +14 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +16 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/logger.d.ts +15 -0
  47. package/dist/logger.d.ts.map +1 -0
  48. package/dist/logger.js +87 -0
  49. package/dist/logger.js.map +1 -0
  50. package/dist/trail.d.ts +20 -0
  51. package/dist/trail.d.ts.map +1 -0
  52. package/dist/trail.js +80 -0
  53. package/dist/trail.js.map +1 -0
  54. package/dist/types.d.ts +80 -0
  55. package/dist/types.d.ts.map +1 -0
  56. package/dist/types.js +5 -0
  57. package/dist/types.js.map +1 -0
  58. package/package.json +23 -0
  59. package/src/__tests__/context.test.ts +60 -0
  60. package/src/__tests__/contracts.test.ts +68 -0
  61. package/src/__tests__/detours.test.ts +55 -0
  62. package/src/__tests__/examples.test.ts +176 -0
  63. package/src/__tests__/hike.test.ts +164 -0
  64. package/src/__tests__/logger.test.ts +136 -0
  65. package/src/__tests__/trail.test.ts +99 -0
  66. package/src/all.ts +55 -0
  67. package/src/assertions.ts +108 -0
  68. package/src/context.ts +42 -0
  69. package/src/contracts.ts +85 -0
  70. package/src/detours.ts +44 -0
  71. package/src/examples.ts +314 -0
  72. package/src/harness-cli.ts +310 -0
  73. package/src/harness-mcp.ts +65 -0
  74. package/src/hike.ts +283 -0
  75. package/src/index.ts +40 -0
  76. package/src/logger.ts +125 -0
  77. package/src/trail.ts +116 -0
  78. package/src/types.ts +117 -0
  79. package/tsconfig.json +9 -0
  80. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,30 @@
1
+ /**
2
+ * testDetours — verify that all detour targets exist in the topo.
3
+ *
4
+ * Pure structural validation. No implementation execution needed.
5
+ */
6
+ import { describe, expect, test } from 'bun:test';
7
+ // ---------------------------------------------------------------------------
8
+ // testDetours
9
+ // ---------------------------------------------------------------------------
10
+ /**
11
+ * Verify that every trail's detour targets reference trails that
12
+ * actually exist in the app's topo.
13
+ */
14
+ export const testDetours = (app) => {
15
+ const trailEntries = [...app.trails];
16
+ describe('detours', () => {
17
+ describe.each(trailEntries)('%s', (_id, trailDef) => {
18
+ const t = trailDef;
19
+ if (t.detours === undefined) {
20
+ return;
21
+ }
22
+ const { detours } = t;
23
+ const testCases = Object.entries(detours).flatMap(([detourName, targets]) => targets.map((targetId) => ({ detourName, targetId })));
24
+ test.each(testCases)('detour "$detourName" -> "$targetId" exists', ({ targetId }) => {
25
+ expect(app.has(targetId)).toBe(true);
26
+ });
27
+ });
28
+ });
29
+ };
30
+ //# sourceMappingURL=detours.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detours.js","sourceRoot":"","sources":["../src/detours.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAIlD,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAS,EAAQ,EAAE;IAC7C,MAAM,YAAY,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IAErC,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;QACvB,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;YAClD,MAAM,CAAC,GAAG,QAAmC,CAAC;YAE9C,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;gBAC5B,OAAO;YACT,CAAC;YAED,MAAM,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC;YACtB,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAC/C,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,EAAE,CACxB,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,CAAC,CACxD,CAAC;YAEF,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAClB,4CAA4C,EAC5C,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACvC,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * testExamples — the headline one-liner.
3
+ *
4
+ * Iterates every trail in the app's topo. For each trail with examples,
5
+ * generates describe/test blocks using bun:test. Progressive assertion
6
+ * determines which check to run per example. For hikes with `follows`
7
+ * declarations, checks that every declared follow was called at least once.
8
+ */
9
+ import type { Topo, TrailContext } from '@ontrails/core';
10
+ /**
11
+ * Generate describe/test blocks for every trail example in the app.
12
+ *
13
+ * For hikes with `follows` declarations and examples, also verifies that
14
+ * every declared follow ID was called at least once across all examples.
15
+ *
16
+ * One line in your test file:
17
+ * ```ts
18
+ * testExamples(app);
19
+ * ```
20
+ */
21
+ export declare const testExamples: (app: Topo, ctxOrFactory?: Partial<TrailContext> | (() => Partial<TrailContext>)) => void;
22
+ //# sourceMappingURL=examples.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"examples.d.ts","sourceRoot":"","sources":["../src/examples.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAGV,IAAI,EAGJ,YAAY,EACb,MAAM,gBAAgB,CAAC;AAkQxB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GACvB,KAAK,IAAI,EACT,eAAe,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC,KACnE,IAuBF,CAAC"}
@@ -0,0 +1,187 @@
1
+ /**
2
+ * testExamples — the headline one-liner.
3
+ *
4
+ * Iterates every trail in the app's topo. For each trail with examples,
5
+ * generates describe/test blocks using bun:test. Progressive assertion
6
+ * determines which check to run per example. For hikes with `follows`
7
+ * declarations, checks that every declared follow was called at least once.
8
+ */
9
+ import { describe, expect, test } from 'bun:test';
10
+ import { AlreadyExistsError, AmbiguousError, AssertionError, AuthError, CancelledError, ConflictError, InternalError, NetworkError, NotFoundError, PermissionError, RateLimitError, Result, TimeoutError, TrailsError, ValidationError, validateInput, } from '@ontrails/core';
11
+ import { assertErrorMatch, assertFullMatch, assertSchemaMatch, expectOk, } from './assertions.js';
12
+ import { mergeTestContext } from './context.js';
13
+ // ---------------------------------------------------------------------------
14
+ // Error class name -> constructor map
15
+ // ---------------------------------------------------------------------------
16
+ const ERROR_MAP = {
17
+ AlreadyExistsError: AlreadyExistsError,
18
+ AmbiguousError: AmbiguousError,
19
+ AssertionError: AssertionError,
20
+ AuthError: AuthError,
21
+ CancelledError: CancelledError,
22
+ ConflictError: ConflictError,
23
+ InternalError: InternalError,
24
+ NetworkError: NetworkError,
25
+ NotFoundError: NotFoundError,
26
+ PermissionError: PermissionError,
27
+ RateLimitError: RateLimitError,
28
+ TimeoutError: TimeoutError,
29
+ TrailsError: TrailsError,
30
+ ValidationError: ValidationError,
31
+ };
32
+ /**
33
+ * Resolve an error class name string to the actual constructor.
34
+ * Falls back to generic Error if the name is not in the core taxonomy.
35
+ */
36
+ const resolveErrorClass = (name) => ERROR_MAP[name] ?? Error;
37
+ // ---------------------------------------------------------------------------
38
+ // Helpers
39
+ // ---------------------------------------------------------------------------
40
+ const assertProgressiveMatch = (result, example, output) => {
41
+ if (example.expected !== undefined) {
42
+ assertFullMatch(result, example.expected);
43
+ return;
44
+ }
45
+ if (example.error !== undefined) {
46
+ const errorClass = resolveErrorClass(example.error);
47
+ assertErrorMatch(result, errorClass);
48
+ return;
49
+ }
50
+ assertSchemaMatch(result, output);
51
+ };
52
+ /**
53
+ * Handle input validation failure for an example.
54
+ * Returns true if the validation error was expected (and assertions passed).
55
+ * Throws if the validation error was unexpected.
56
+ */
57
+ const handleValidationError = (validated, example) => {
58
+ if (!validated.isErr()) {
59
+ return false;
60
+ }
61
+ if (example.error !== undefined) {
62
+ const errorClass = resolveErrorClass(example.error);
63
+ expect(validated.error).toBeInstanceOf(errorClass);
64
+ return true;
65
+ }
66
+ throw new Error(`Example "${example.name}" has invalid input: ${validated.error.message}`);
67
+ };
68
+ /**
69
+ * Run a single example against a trail.
70
+ * Handles validation, execution, and assertions.
71
+ */
72
+ const runExample = async (t, example, output, testCtx) => {
73
+ const validated = validateInput(t.input, example.input);
74
+ if (handleValidationError(validated, example)) {
75
+ return;
76
+ }
77
+ const validatedInput = expectOk(validated);
78
+ const result = await t.implementation(validatedInput, testCtx);
79
+ assertProgressiveMatch(result, example, output);
80
+ };
81
+ // ---------------------------------------------------------------------------
82
+ // Follows coverage for hikes
83
+ // ---------------------------------------------------------------------------
84
+ /**
85
+ * Build a recording follow function that tracks which trail IDs are called.
86
+ *
87
+ * Delegates to `baseFollow` when available, otherwise looks up the trail
88
+ * in the topo and executes it with validated input. Falls back to
89
+ * `Result.ok()` when neither is available.
90
+ */
91
+ const createCoverageFollow = (called, baseFollow, topo, ctx) => {
92
+ const follow = (id, input) => {
93
+ called.add(id);
94
+ if (baseFollow !== undefined) {
95
+ return baseFollow(id, input);
96
+ }
97
+ const trailDef = topo.get(id);
98
+ if (trailDef !== undefined) {
99
+ const validated = validateInput(trailDef.input, input);
100
+ if (validated.isErr()) {
101
+ return Promise.resolve(validated);
102
+ }
103
+ return Promise.resolve(trailDef.implementation(validated.value, ctx));
104
+ }
105
+ return Promise.resolve(Result.ok());
106
+ };
107
+ return follow;
108
+ };
109
+ /**
110
+ * Run a single example against a hike, recording follow calls.
111
+ */
112
+ const runHikeExample = async (hikeDef, example, output, baseCtx, called, topo) => {
113
+ const validated = validateInput(hikeDef.input, example.input);
114
+ if (handleValidationError(validated, example)) {
115
+ return;
116
+ }
117
+ const validatedInput = expectOk(validated);
118
+ const follow = createCoverageFollow(called, baseCtx.follow, topo, baseCtx);
119
+ const testCtx = { ...baseCtx, follow };
120
+ const result = await hikeDef.implementation(validatedInput, testCtx);
121
+ assertProgressiveMatch(result, example, output);
122
+ };
123
+ const collectHikesWithExamples = (app) => [...app.hikes]
124
+ .filter(([, h]) => h.examples !== undefined && h.examples.length > 0)
125
+ .map(([hikeId, hikeDef]) => ({
126
+ examples: hikeDef.examples,
127
+ hikeDef,
128
+ hikeId,
129
+ }));
130
+ // ---------------------------------------------------------------------------
131
+ // Hike example describe blocks
132
+ // ---------------------------------------------------------------------------
133
+ /**
134
+ * Generate describe/test blocks for hikes with follows coverage.
135
+ *
136
+ * Always uses a recording follow so that follows coverage can be checked.
137
+ * Hikes without `follows` still run their examples but skip the coverage test.
138
+ */
139
+ const describeHikeExamples = (hikesWithExamples, resolveCtx, topo) => {
140
+ if (hikesWithExamples.length === 0) {
141
+ return;
142
+ }
143
+ describe.each([...hikesWithExamples])('$hikeId', ({ hikeDef, examples }) => {
144
+ const called = new Set();
145
+ test.each([...examples])('example: $name', async (example) => {
146
+ const baseCtx = mergeTestContext(resolveCtx());
147
+ await runHikeExample(hikeDef, example, hikeDef.output, baseCtx, called, topo);
148
+ });
149
+ if (hikeDef.follows.length > 0) {
150
+ test('follows coverage', () => {
151
+ const uncovered = hikeDef.follows.filter((id) => !called.has(id));
152
+ expect(uncovered).toEqual([]);
153
+ });
154
+ }
155
+ });
156
+ };
157
+ // ---------------------------------------------------------------------------
158
+ // testExamples
159
+ // ---------------------------------------------------------------------------
160
+ /**
161
+ * Generate describe/test blocks for every trail example in the app.
162
+ *
163
+ * For hikes with `follows` declarations and examples, also verifies that
164
+ * every declared follow ID was called at least once across all examples.
165
+ *
166
+ * One line in your test file:
167
+ * ```ts
168
+ * testExamples(app);
169
+ * ```
170
+ */
171
+ export const testExamples = (app, ctxOrFactory) => {
172
+ const resolveCtx = typeof ctxOrFactory === 'function' ? ctxOrFactory : () => ctxOrFactory;
173
+ const trailEntries = [...app.trails];
174
+ describe.each(trailEntries)('%s', (_id, trailDef) => {
175
+ const t = trailDef;
176
+ if (t.examples === undefined || t.examples.length === 0) {
177
+ return;
178
+ }
179
+ const { examples, output } = t;
180
+ test.each([...examples])('example: $name', async (example) => {
181
+ const testCtx = mergeTestContext(resolveCtx());
182
+ await runExample(t, example, output, testCtx);
183
+ });
184
+ });
185
+ describeHikeExamples(collectHikesWithExamples(app), resolveCtx, app);
186
+ };
187
+ //# sourceMappingURL=examples.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"examples.js","sourceRoot":"","sources":["../src/examples.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAWlD,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,cAAc,EACd,SAAS,EACT,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,aAAa,EACb,eAAe,EACf,cAAc,EACd,MAAM,EACN,YAAY,EACZ,WAAW,EACX,eAAe,EACf,aAAa,GACd,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,QAAQ,GACT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,8EAA8E;AAC9E,sCAAsC;AACtC,8EAA8E;AAE9E,MAAM,SAAS,GAAoD;IACjE,kBAAkB,EAAE,kBAAqD;IACzE,cAAc,EAAE,cAAiD;IACjE,cAAc,EAAE,cAAiD;IACjE,SAAS,EAAE,SAA4C;IACvD,cAAc,EAAE,cAAiD;IACjE,aAAa,EAAE,aAAgD;IAC/D,aAAa,EAAE,aAAgD;IAC/D,YAAY,EAAE,YAA+C;IAC7D,aAAa,EAAE,aAAgD;IAC/D,eAAe,EAAE,eAAkD;IACnE,cAAc,EAAE,cAAiD;IACjE,YAAY,EAAE,YAA+C;IAC7D,WAAW,EAAE,WAAyD;IACtE,eAAe,EAAE,eAAkD;CACpE,CAAC;AAEF;;;GAGG;AACH,MAAM,iB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AoE,EAC9D,EAAE;IACR,MAAM,UAAU,GACd,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC;IACzE,MAAM,YAAY,GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC;IAErC,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE;QAClD,MAAM,CAAC,GAAG,QAAmC,CAAC;QAC9C,IAAI,CAAC,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACxD,OAAO;QACT,CAAC;QAED,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;QAE/B,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CACtB,gBAAgB,EAChB,KAAK,EAAE,OAAuC,EAAE,EAAE;YAChD,MAAM,OAAO,GAAG,gBAAgB,CAAC,UAAU,EAAE,CAAC,CAAC;YAC/C,MAAM,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAChD,CAAC,CACF,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,oBAAoB,CAAC,wBAAwB,CAAC,GAAG,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,CAAC;AACvE,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * CLI integration test harness.
3
+ *
4
+ * Builds CLI commands from an App, executes them in-process,
5
+ * and captures stdout/stderr.
6
+ */
7
+ import type { CliHarness, CliHarnessOptions } from './types.js';
8
+ /**
9
+ * Create a CLI harness for integration testing.
10
+ *
11
+ * Builds commands from the app's topo and provides a `run()` method
12
+ * that parses command strings and executes them in-process.
13
+ *
14
+ * ```ts
15
+ * const harness = createCliHarness({ app });
16
+ * const result = await harness.run("entity show --name Alpha --output json");
17
+ * expect(result.exitCode).toBe(0);
18
+ * ```
19
+ */
20
+ export declare const createCliHarness: (options: CliHarnessOptions) => CliHarness;
21
+ //# sourceMappingURL=harness-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness-cli.d.ts","sourceRoot":"","sources":["../src/harness-cli.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAoRpB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,iBAAiB,KAAG,UAM7D,CAAC"}
@@ -0,0 +1,213 @@
1
+ /**
2
+ * CLI integration test harness.
3
+ *
4
+ * Builds CLI commands from an App, executes them in-process,
5
+ * and captures stdout/stderr.
6
+ */
7
+ import { buildCliCommands } from '@ontrails/cli';
8
+ import { createTestContext } from './context.js';
9
+ // ---------------------------------------------------------------------------
10
+ // Tokenizer
11
+ // ---------------------------------------------------------------------------
12
+ /** Parse a command string into tokens (simple split, no quoting support). */
13
+ const parseCommandString = (input) => input
14
+ .trim()
15
+ .split(/\s+/)
16
+ .filter((s) => s.length > 0);
17
+ // ---------------------------------------------------------------------------
18
+ // Command resolution
19
+ // ---------------------------------------------------------------------------
20
+ /** Try to match group + name from tokens. */
21
+ const tryGroupMatch = (commands, firstToken, secondToken, tokens) => {
22
+ if (secondToken === undefined || secondToken.startsWith('-')) {
23
+ return undefined;
24
+ }
25
+ const match = commands.find((c) => c.group === firstToken && c.name === secondToken);
26
+ if (match === undefined) {
27
+ return undefined;
28
+ }
29
+ return { command: match, flagTokens: tokens.slice(2) };
30
+ };
31
+ /** Try to match a direct name from the first token. */
32
+ const tryDirectMatch = (commands, firstToken, tokens) => {
33
+ const match = commands.find((c) => c.name === firstToken && c.group === undefined);
34
+ if (match === undefined) {
35
+ return undefined;
36
+ }
37
+ return { command: match, flagTokens: tokens.slice(1) };
38
+ };
39
+ /** Resolve a command from tokens, handling group.name patterns. */
40
+ const resolveCommand = (commands, tokens) => {
41
+ const [firstToken, secondToken] = tokens;
42
+ if (firstToken === undefined) {
43
+ return undefined;
44
+ }
45
+ return (tryGroupMatch(commands, firstToken, secondToken, tokens) ??
46
+ tryDirectMatch(commands, firstToken, tokens));
47
+ };
48
+ // ---------------------------------------------------------------------------
49
+ // Flag parsing
50
+ // ---------------------------------------------------------------------------
51
+ /** Parse a value flag (--key value) and return new index. */
52
+ const parseValueFlag = (key, next, flags) => {
53
+ const num = Number(next);
54
+ flags[key] = Number.isNaN(num) ? next : num;
55
+ };
56
+ /** Parse a single flag token and advance the index. */
57
+ const parseSingleFlag = (tokens, i, flags) => {
58
+ const token = tokens[i];
59
+ if (token === undefined || !token.startsWith('--')) {
60
+ return i + 1;
61
+ }
62
+ const key = token.slice(2);
63
+ const next = tokens[i + 1];
64
+ if (next !== undefined && !next.startsWith('-')) {
65
+ parseValueFlag(key, next, flags);
66
+ return i + 2;
67
+ }
68
+ flags[key] = true;
69
+ return i + 1;
70
+ };
71
+ /** Parse flag tokens into a record. */
72
+ const parseFlagTokens = (tokens) => {
73
+ const flags = {};
74
+ let i = 0;
75
+ while (i < tokens.length) {
76
+ i = parseSingleFlag(tokens, i, flags);
77
+ }
78
+ return flags;
79
+ };
80
+ /** Create interceptors for stdout/stderr capture. */
81
+ const captureStreams = () => {
82
+ let stdout = '';
83
+ let stderr = '';
84
+ const origStdoutWrite = process.stdout.write;
85
+ const origStderrWrite = process.stderr.write;
86
+ process.stdout.write = ((chunk) => {
87
+ stdout +=
88
+ typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk);
89
+ return true;
90
+ });
91
+ process.stderr.write = ((chunk) => {
92
+ stderr +=
93
+ typeof chunk === 'string' ? chunk : new TextDecoder().decode(chunk);
94
+ return true;
95
+ });
96
+ return {
97
+ getStderr: () => stderr,
98
+ getStdout: () => stdout,
99
+ restore: () => {
100
+ process.stdout.write = origStdoutWrite;
101
+ process.stderr.write = origStderrWrite;
102
+ },
103
+ writeStdout: (text) => {
104
+ stdout += text;
105
+ },
106
+ };
107
+ };
108
+ // ---------------------------------------------------------------------------
109
+ // Output formatting
110
+ // ---------------------------------------------------------------------------
111
+ /** Try to parse a string as JSON, returning undefined on failure. */
112
+ const tryParseJson = (text) => {
113
+ try {
114
+ return JSON.parse(text);
115
+ }
116
+ catch {
117
+ return undefined;
118
+ }
119
+ };
120
+ /** Format result value into stdout and build the CLI result. */
121
+ const formatSuccessResult = (value, flags, streams) => {
122
+ const outputMode = flags['output'] ?? (flags['json'] === true ? 'json' : 'text');
123
+ if (outputMode === 'json') {
124
+ const jsonStr = `${JSON.stringify(value, null, 2)}\n`;
125
+ streams.writeStdout(jsonStr);
126
+ return {
127
+ exitCode: 0,
128
+ json: tryParseJson(jsonStr),
129
+ stderr: streams.getStderr(),
130
+ stdout: streams.getStdout(),
131
+ };
132
+ }
133
+ const formatted = typeof value === 'string'
134
+ ? `${value}\n`
135
+ : `${JSON.stringify(value, null, 2)}\n`;
136
+ streams.writeStdout(formatted);
137
+ return {
138
+ exitCode: 0,
139
+ json: tryParseJson(streams.getStdout().trim()),
140
+ stderr: streams.getStderr(),
141
+ stdout: streams.getStdout(),
142
+ };
143
+ };
144
+ // ---------------------------------------------------------------------------
145
+ // Execute command
146
+ // ---------------------------------------------------------------------------
147
+ /** Build an error result from a caught exception. */
148
+ const buildErrorResult = (error, streams) => {
149
+ streams.restore();
150
+ const message = error instanceof Error ? error.message : String(error);
151
+ return {
152
+ exitCode: 1,
153
+ stderr: streams.getStderr() || message,
154
+ stdout: streams.getStdout(),
155
+ };
156
+ };
157
+ /** Execute a resolved command and return the result. */
158
+ const executeCommand = async (command, flags, streams) => {
159
+ const ctx = createTestContext();
160
+ const result = await command.execute({}, flags, ctx);
161
+ streams.restore();
162
+ if (result.isErr()) {
163
+ return {
164
+ exitCode: 1,
165
+ stderr: streams.getStderr() || result.error.message,
166
+ stdout: streams.getStdout(),
167
+ };
168
+ }
169
+ return formatSuccessResult(result.value, flags, streams);
170
+ };
171
+ /** Run the full command pipeline: resolve, parse, execute. */
172
+ const runCommand = async (commands, commandString) => {
173
+ const parts = parseCommandString(commandString);
174
+ const resolved = resolveCommand(commands, parts);
175
+ if (resolved === undefined) {
176
+ return {
177
+ exitCode: 1,
178
+ stderr: `Unknown command: ${commandString}`,
179
+ stdout: '',
180
+ };
181
+ }
182
+ const { command, flagTokens } = resolved;
183
+ const flags = parseFlagTokens(flagTokens);
184
+ const streams = captureStreams();
185
+ try {
186
+ return await executeCommand(command, flags, streams);
187
+ }
188
+ catch (error) {
189
+ return buildErrorResult(error, streams);
190
+ }
191
+ };
192
+ // ---------------------------------------------------------------------------
193
+ // createCliHarness
194
+ // ---------------------------------------------------------------------------
195
+ /**
196
+ * Create a CLI harness for integration testing.
197
+ *
198
+ * Builds commands from the app's topo and provides a `run()` method
199
+ * that parses command strings and executes them in-process.
200
+ *
201
+ * ```ts
202
+ * const harness = createCliHarness({ app });
203
+ * const result = await harness.run("entity show --name Alpha --output json");
204
+ * expect(result.exitCode).toBe(0);
205
+ * ```
206
+ */
207
+ export const createCliHarness = (options) => {
208
+ const commands = buildCliCommands(options.app);
209
+ return {
210
+ run: (commandString) => runCommand(commands, commandString),
211
+ };
212
+ };
213
+ //# sourceMappingURL=harness-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness-cli.js","sourceRoot":"","sources":["../src/harness-cli.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAGjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAOjD,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAE9E,6EAA6E;AAC7E,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAY,EAAE,CACrD,KAAK;KACF,IAAI,EAAE;KACN,KAAK,CAAC,KAAK,CAAC;KACZ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,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qB,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,aAAa,CAAC;KACpE,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * MCP integration test harness.
3
+ *
4
+ * Builds MCP tools from an App, invokes them directly (no transport),
5
+ * and returns the MCP tool response.
6
+ */
7
+ import type { McpHarness, McpHarnessOptions } from './types.js';
8
+ /**
9
+ * Create an MCP harness for integration testing.
10
+ *
11
+ * Builds MCP tools from the app's topo and provides a `callTool()` method
12
+ * that invokes tools directly without any transport layer.
13
+ *
14
+ * ```ts
15
+ * const harness = createMcpHarness({ app });
16
+ * const result = await harness.callTool("myapp_entity_show", { name: "Alpha" });
17
+ * expect(result.isError).toBe(false);
18
+ * ```
19
+ */
20
+ export declare const createMcpHarness: (options: McpHarnessOptions) => McpHarness;
21
+ //# sourceMappingURL=harness-mcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness-mcp.d.ts","sourceRoot":"","sources":["../src/harness-mcp.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EACV,UAAU,EACV,iBAAiB,EAElB,MAAM,YAAY,CAAC;AAMpB;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,gBAAgB,GAAI,SAAS,iBAAiB,KAAG,UAgC7D,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * MCP integration test harness.
3
+ *
4
+ * Builds MCP tools from an App, invokes them directly (no transport),
5
+ * and returns the MCP tool response.
6
+ */
7
+ import { buildMcpTools } from '@ontrails/mcp';
8
+ // ---------------------------------------------------------------------------
9
+ // createMcpHarness
10
+ // ---------------------------------------------------------------------------
11
+ /**
12
+ * Create an MCP harness for integration testing.
13
+ *
14
+ * Builds MCP tools from the app's topo and provides a `callTool()` method
15
+ * that invokes tools directly without any transport layer.
16
+ *
17
+ * ```ts
18
+ * const harness = createMcpHarness({ app });
19
+ * const result = await harness.callTool("myapp_entity_show", { name: "Alpha" });
20
+ * expect(result.isError).toBe(false);
21
+ * ```
22
+ */
23
+ export const createMcpHarness = (options) => {
24
+ const tools = buildMcpTools(options.app);
25
+ const toolMap = new Map();
26
+ for (const tool of tools) {
27
+ toolMap.set(tool.name, tool);
28
+ }
29
+ return {
30
+ async callTool(name, args) {
31
+ const tool = toolMap.get(name);
32
+ if (tool === undefined) {
33
+ return {
34
+ content: [{ text: `Unknown tool: ${name}`, type: 'text' }],
35
+ isError: true,
36
+ };
37
+ }
38
+ const result = await tool.handler(args, {
39
+ progressToken: undefined,
40
+ sendProgress: undefined,
41
+ signal: undefined,
42
+ });
43
+ return {
44
+ content: result.content,
45
+ isError: result.isError ?? false,
46
+ };
47
+ },
48
+ };
49
+ };
50
+ //# sourceMappingURL=harness-mcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness-mcp.js","sourceRoot":"","sources":["../src/harness-mcp.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAS9C,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,OAA0B,EAAc,EAAE;IACzE,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,OAAO,GAAG,IAAI,GAAG,EAA6B,CAAC;IACrD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,OAAO;QACL,KAAK,CAAC,QAAQ,CACZ,IAAY,EACZ,IAA6B;YAE7B,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC/B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACvB,OAAO;oBACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;oBAC1D,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE;gBACtC,aAAa,EAAE,SAAS;gBACxB,YAAY,EAAE,SAAS;gBACvB,MAAM,EAAE,SAAS;aAClB,CAAC,CAAC;YAEH,OAAO;gBACL,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,OAAO,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK;aACjC,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
package/dist/hike.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * testHike — composition-aware scenario testing for hikes.
3
+ *
4
+ * Tests the composition graph: which trails were followed, in what order,
5
+ * and supports failure injection from followed trail examples.
6
+ */
7
+ import type { AnyHike, AnyTrail, TrailContext } from '@ontrails/core';
8
+ import type { HikeScenario } from './types.js';
9
+ /** Options for testHike that provide trail definitions for injection. */
10
+ export interface TestHikeOptions {
11
+ /** Partial context overrides. */
12
+ readonly ctx?: Partial<TrailContext> | undefined;
13
+ /** Map of trail ID to trail definition, used for injectFromExample. */
14
+ readonly trails?: ReadonlyMap<string, AnyTrail> | undefined;
15
+ }
16
+ /**
17
+ * Generate a describe block for a hike with one test per scenario.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * testHike(onboardHike, [
22
+ * {
23
+ * description: "follows add then relate",
24
+ * input: { name: "Alpha" },
25
+ * expectOk: true,
26
+ * expectFollowed: ["entity.add", "entity.relate"],
27
+ * },
28
+ * ]);
29
+ * ```
30
+ */
31
+ export declare const testHike: (hikeDef: AnyHike, scenarios: readonly HikeScenario[], options?: TestHikeOptions) => void;
32
+ //# sourceMappingURL=hike.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hike.d.ts","sourceRoot":"","sources":["../src/hike.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAY,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAehF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA8N/C,yEAAyE;AACzE,MAAM,WAAW,eAAe;IAC9B,iCAAiC;IACjC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IACjD,uEAAuE;IACvE,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAC,GAAG,SAAS,CAAC;CAC7D;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,GACnB,SAAS,OAAO,EAChB,WAAW,SAAS,YAAY,EAAE,EAClC,UAAU,eAAe,KACxB,IASF,CAAC"}