@jamesaphoenix/tx-test-utils 0.4.2

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 (101) hide show
  1. package/dist/database/index.d.ts +8 -0
  2. package/dist/database/index.d.ts.map +1 -0
  3. package/dist/database/index.js +7 -0
  4. package/dist/database/index.js.map +1 -0
  5. package/dist/database/test-database.d.ts +101 -0
  6. package/dist/database/test-database.d.ts.map +1 -0
  7. package/dist/database/test-database.js +130 -0
  8. package/dist/database/test-database.js.map +1 -0
  9. package/dist/factories/anchor.factory.d.ts +117 -0
  10. package/dist/factories/anchor.factory.d.ts.map +1 -0
  11. package/dist/factories/anchor.factory.js +201 -0
  12. package/dist/factories/anchor.factory.js.map +1 -0
  13. package/dist/factories/candidate.factory.d.ts +151 -0
  14. package/dist/factories/candidate.factory.d.ts.map +1 -0
  15. package/dist/factories/candidate.factory.js +194 -0
  16. package/dist/factories/candidate.factory.js.map +1 -0
  17. package/dist/factories/edge.factory.d.ts +119 -0
  18. package/dist/factories/edge.factory.d.ts.map +1 -0
  19. package/dist/factories/edge.factory.js +191 -0
  20. package/dist/factories/edge.factory.js.map +1 -0
  21. package/dist/factories/factories.test.d.ts +8 -0
  22. package/dist/factories/factories.test.d.ts.map +1 -0
  23. package/dist/factories/factories.test.js +419 -0
  24. package/dist/factories/factories.test.js.map +1 -0
  25. package/dist/factories/index.d.ts +15 -0
  26. package/dist/factories/index.d.ts.map +1 -0
  27. package/dist/factories/index.js +21 -0
  28. package/dist/factories/index.js.map +1 -0
  29. package/dist/factories/learning.factory.d.ts +107 -0
  30. package/dist/factories/learning.factory.d.ts.map +1 -0
  31. package/dist/factories/learning.factory.js +150 -0
  32. package/dist/factories/learning.factory.js.map +1 -0
  33. package/dist/factories/task.factory.d.ts +106 -0
  34. package/dist/factories/task.factory.d.ts.map +1 -0
  35. package/dist/factories/task.factory.js +151 -0
  36. package/dist/factories/task.factory.js.map +1 -0
  37. package/dist/fixtures/index.d.ts +36 -0
  38. package/dist/fixtures/index.d.ts.map +1 -0
  39. package/dist/fixtures/index.js +47 -0
  40. package/dist/fixtures/index.js.map +1 -0
  41. package/dist/helpers/effect.d.ts +186 -0
  42. package/dist/helpers/effect.d.ts.map +1 -0
  43. package/dist/helpers/effect.js +298 -0
  44. package/dist/helpers/effect.js.map +1 -0
  45. package/dist/helpers/effect.test.d.ts +7 -0
  46. package/dist/helpers/effect.test.d.ts.map +1 -0
  47. package/dist/helpers/effect.test.js +271 -0
  48. package/dist/helpers/effect.test.js.map +1 -0
  49. package/dist/helpers/index.d.ts +7 -0
  50. package/dist/helpers/index.d.ts.map +1 -0
  51. package/dist/helpers/index.js +11 -0
  52. package/dist/helpers/index.js.map +1 -0
  53. package/dist/index.d.ts +26 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +52 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/llm-cache/cache.d.ts +152 -0
  58. package/dist/llm-cache/cache.d.ts.map +1 -0
  59. package/dist/llm-cache/cache.js +199 -0
  60. package/dist/llm-cache/cache.js.map +1 -0
  61. package/dist/llm-cache/cache.test.d.ts +7 -0
  62. package/dist/llm-cache/cache.test.d.ts.map +1 -0
  63. package/dist/llm-cache/cache.test.js +310 -0
  64. package/dist/llm-cache/cache.test.js.map +1 -0
  65. package/dist/llm-cache/cli.d.ts +113 -0
  66. package/dist/llm-cache/cli.d.ts.map +1 -0
  67. package/dist/llm-cache/cli.js +248 -0
  68. package/dist/llm-cache/cli.js.map +1 -0
  69. package/dist/llm-cache/index.d.ts +31 -0
  70. package/dist/llm-cache/index.d.ts.map +1 -0
  71. package/dist/llm-cache/index.js +31 -0
  72. package/dist/llm-cache/index.js.map +1 -0
  73. package/dist/mocks/anthropic.mock.d.ts +173 -0
  74. package/dist/mocks/anthropic.mock.d.ts.map +1 -0
  75. package/dist/mocks/anthropic.mock.js +125 -0
  76. package/dist/mocks/anthropic.mock.js.map +1 -0
  77. package/dist/mocks/ast-grep.mock.d.ts +216 -0
  78. package/dist/mocks/ast-grep.mock.d.ts.map +1 -0
  79. package/dist/mocks/ast-grep.mock.js +164 -0
  80. package/dist/mocks/ast-grep.mock.js.map +1 -0
  81. package/dist/mocks/file-system.mock.d.ts +181 -0
  82. package/dist/mocks/file-system.mock.d.ts.map +1 -0
  83. package/dist/mocks/file-system.mock.js +280 -0
  84. package/dist/mocks/file-system.mock.js.map +1 -0
  85. package/dist/mocks/index.d.ts +10 -0
  86. package/dist/mocks/index.d.ts.map +1 -0
  87. package/dist/mocks/index.js +16 -0
  88. package/dist/mocks/index.js.map +1 -0
  89. package/dist/mocks/mocks.test.d.ts +10 -0
  90. package/dist/mocks/mocks.test.d.ts.map +1 -0
  91. package/dist/mocks/mocks.test.js +961 -0
  92. package/dist/mocks/mocks.test.js.map +1 -0
  93. package/dist/mocks/openai.mock.d.ts +205 -0
  94. package/dist/mocks/openai.mock.d.ts.map +1 -0
  95. package/dist/mocks/openai.mock.js +178 -0
  96. package/dist/mocks/openai.mock.js.map +1 -0
  97. package/dist/setup/index.d.ts +7 -0
  98. package/dist/setup/index.d.ts.map +1 -0
  99. package/dist/setup/index.js +9 -0
  100. package/dist/setup/index.js.map +1 -0
  101. package/package.json +80 -0
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Mock AstGrepService for testing.
3
+ *
4
+ * Provides configurable mock AstGrepService with symbol fixtures,
5
+ * import fixtures, pattern match fixtures, and failure injection
6
+ * for testing services that depend on ast-grep code intelligence.
7
+ *
8
+ * Note: Uses inline types until AstGrepService is exported from @tx/core (tx-cf0f3c40).
9
+ *
10
+ * @module @tx/test-utils/mocks/ast-grep
11
+ */
12
+ import { Context, Effect, Layer } from "effect";
13
+ /**
14
+ * Symbol kind - one of the valid code construct types.
15
+ */
16
+ export type MockSymbolKind = "function" | "class" | "interface" | "type" | "const" | "variable" | "method" | "struct" | "enum" | "trait" | "module";
17
+ /**
18
+ * Information about an extracted symbol.
19
+ */
20
+ export interface MockSymbolInfo {
21
+ /** Symbol name (e.g., function name, class name) */
22
+ readonly name: string;
23
+ /** Kind of symbol */
24
+ readonly kind: MockSymbolKind;
25
+ /** Line number where the symbol is defined (1-indexed) */
26
+ readonly line: number;
27
+ /** Whether the symbol is exported */
28
+ readonly exported: boolean;
29
+ /** File path where the symbol is defined (optional, for convenience) */
30
+ readonly filePath?: string;
31
+ }
32
+ /**
33
+ * Import kind - static (import/require) or dynamic (import()).
34
+ */
35
+ export type MockImportKind = "static" | "dynamic";
36
+ /**
37
+ * Information about an import statement.
38
+ */
39
+ export interface MockImportInfo {
40
+ /** Source module path or package name */
41
+ readonly source: string;
42
+ /** Imported specifiers (names) */
43
+ readonly specifiers: readonly string[];
44
+ /** Kind of import */
45
+ readonly kind: MockImportKind;
46
+ }
47
+ /**
48
+ * A match result from ast-grep pattern matching.
49
+ */
50
+ export interface MockMatch {
51
+ /** File path where the match was found */
52
+ readonly file: string;
53
+ /** Line number (1-indexed) */
54
+ readonly line: number;
55
+ /** Column number (1-indexed) */
56
+ readonly column: number;
57
+ /** Matched text */
58
+ readonly text: string;
59
+ /** Named captures from the pattern (e.g., $NAME -> value) */
60
+ readonly captures: Readonly<Record<string, string>>;
61
+ }
62
+ declare const MockAstGrepError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
63
+ readonly _tag: "AstGrepError";
64
+ } & Readonly<A>;
65
+ /**
66
+ * Error type for ast-grep operations.
67
+ */
68
+ export declare class MockAstGrepError extends MockAstGrepError_base<{
69
+ readonly reason: string;
70
+ readonly cause?: unknown;
71
+ }> {
72
+ get message(): string;
73
+ }
74
+ declare const MockAstGrepServiceTag_base: Context.TagClass<MockAstGrepServiceTag, "AstGrepService", {
75
+ readonly findSymbols: (filePath: string) => Effect.Effect<readonly MockSymbolInfo[], MockAstGrepError>;
76
+ readonly getImports: (filePath: string) => Effect.Effect<readonly MockImportInfo[], MockAstGrepError>;
77
+ readonly matchPattern: (pattern: string, path: string) => Effect.Effect<readonly MockMatch[], MockAstGrepError>;
78
+ }>;
79
+ /**
80
+ * Mock AstGrepService tag for dependency injection.
81
+ */
82
+ export declare class MockAstGrepServiceTag extends MockAstGrepServiceTag_base {
83
+ }
84
+ /**
85
+ * Configuration options for the MockAstGrepService.
86
+ */
87
+ export interface MockAstGrepServiceConfig {
88
+ /**
89
+ * Map of file paths to symbols returned by findSymbols.
90
+ * If a file path is not in the map, returns an empty array.
91
+ */
92
+ symbols?: Map<string, readonly MockSymbolInfo[]>;
93
+ /**
94
+ * Default symbols returned for any file not in the symbols map.
95
+ * If not provided, returns an empty array.
96
+ */
97
+ defaultSymbols?: readonly MockSymbolInfo[];
98
+ /**
99
+ * Map of file paths to imports returned by getImports.
100
+ * If a file path is not in the map, returns an empty array.
101
+ */
102
+ imports?: Map<string, readonly MockImportInfo[]>;
103
+ /**
104
+ * Default imports returned for any file not in the imports map.
105
+ * If not provided, returns an empty array.
106
+ */
107
+ defaultImports?: readonly MockImportInfo[];
108
+ /**
109
+ * Map of patterns to matches returned by matchPattern.
110
+ * Key format: `${pattern}::${path}` for specific path matches,
111
+ * or just `${pattern}` for pattern-only matches.
112
+ */
113
+ matches?: Map<string, readonly MockMatch[]>;
114
+ /**
115
+ * Default matches returned for any pattern not in the matches map.
116
+ * If not provided, returns an empty array.
117
+ */
118
+ defaultMatches?: readonly MockMatch[];
119
+ /**
120
+ * When true, all operations will fail with an error.
121
+ */
122
+ shouldFail?: boolean;
123
+ /**
124
+ * Custom error message when shouldFail is true.
125
+ * Defaults to "Mock AstGrep error".
126
+ */
127
+ failureMessage?: string;
128
+ /**
129
+ * Map of specific operations to fail.
130
+ * Keys: "findSymbols", "getImports", "matchPattern"
131
+ * Values: error message for that operation
132
+ */
133
+ failuresByOperation?: Map<string, string>;
134
+ }
135
+ /**
136
+ * Result returned by MockAstGrepService factory.
137
+ */
138
+ export interface MockAstGrepServiceResult {
139
+ /**
140
+ * Effect Layer providing the mock AstGrepService.
141
+ */
142
+ layer: Layer.Layer<MockAstGrepServiceTag>;
143
+ /**
144
+ * Array of all findSymbols calls made.
145
+ */
146
+ findSymbolsCalls: string[];
147
+ /**
148
+ * Array of all getImports calls made.
149
+ */
150
+ getImportsCalls: string[];
151
+ /**
152
+ * Array of all matchPattern calls made.
153
+ */
154
+ matchPatternCalls: Array<{
155
+ pattern: string;
156
+ path: string;
157
+ }>;
158
+ /**
159
+ * Reset all call tracking arrays.
160
+ */
161
+ reset: () => void;
162
+ /**
163
+ * Get total number of all calls made.
164
+ */
165
+ getCallCount: () => number;
166
+ }
167
+ /**
168
+ * Create a mock AstGrepService for testing.
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * // Basic usage - returns empty arrays
173
+ * const mock = MockAstGrepService()
174
+ * const program = Effect.gen(function* () {
175
+ * const astGrep = yield* MockAstGrepServiceTag
176
+ * return yield* astGrep.findSymbols("src/index.ts")
177
+ * })
178
+ * const result = await Effect.runPromise(Effect.provide(program, mock.layer))
179
+ * expect(result).toEqual([])
180
+ * ```
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * // With configured symbols
185
+ * const symbols = new Map([
186
+ * ["src/index.ts", [
187
+ * { name: "main", kind: "function", line: 1, exported: true },
188
+ * { name: "Helper", kind: "class", line: 10, exported: false }
189
+ * ]]
190
+ * ])
191
+ * const mock = MockAstGrepService({ symbols })
192
+ * ```
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * // With failure injection
197
+ * const mock = MockAstGrepService({
198
+ * shouldFail: true,
199
+ * failureMessage: "ast-grep not installed"
200
+ * })
201
+ * ```
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * // With operation-specific failures
206
+ * const mock = MockAstGrepService({
207
+ * failuresByOperation: new Map([
208
+ * ["findSymbols", "Failed to parse file"]
209
+ * ])
210
+ * })
211
+ * // findSymbols will fail, but getImports and matchPattern will work
212
+ * ```
213
+ */
214
+ export declare const MockAstGrepService: (config?: MockAstGrepServiceConfig) => MockAstGrepServiceResult;
215
+ export {};
216
+ //# sourceMappingURL=ast-grep.mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-grep.mock.d.ts","sourceRoot":"","sources":["../../src/mocks/ast-grep.mock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAO/C;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,UAAU,GACV,OAAO,GACP,WAAW,GACX,MAAM,GACN,OAAO,GACP,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,OAAO,GACP,QAAQ,CAAA;AAEZ;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oDAAoD;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,qBAAqB;IACrB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;IAC7B,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,qCAAqC;IACrC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;IAC1B,wEAAwE;IACxE,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,SAAS,CAAA;AAEjD;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,kCAAkC;IAClC,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;IACtC,qBAAqB;IACrB,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;CAC9B;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,8BAA8B;IAC9B,QAAQ,CAAC,IAAI,EAAE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AS,EAAE,CAAC,CAAA;IAC3C;;;OAGG;IACH,cAAc,CAAC,EAAE,SAAS,SAAS,EAAE,CAAA;IACrC;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC1C;AAED;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACzC;;OAEG;IACH,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B;;OAEG;IACH,eAAe,EAAE,MAAM,EAAE,CAAA;IACzB;;OAEG;IACH,iBAAiB,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC3D;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAA;IACjB;;OAEG;IACH,YAAY,EAAE,MAAM,MAAM,CAAA;CAC3B;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAQ,wBAA6B,KAAG,wBA2G1E,CAAA"}
@@ -0,0 +1,164 @@
1
+ /**
2
+ * Mock AstGrepService for testing.
3
+ *
4
+ * Provides configurable mock AstGrepService with symbol fixtures,
5
+ * import fixtures, pattern match fixtures, and failure injection
6
+ * for testing services that depend on ast-grep code intelligence.
7
+ *
8
+ * Note: Uses inline types until AstGrepService is exported from @tx/core (tx-cf0f3c40).
9
+ *
10
+ * @module @tx/test-utils/mocks/ast-grep
11
+ */
12
+ import { Context, Effect, Layer } from "effect";
13
+ import { Data } from "effect";
14
+ /**
15
+ * Error type for ast-grep operations.
16
+ */
17
+ export class MockAstGrepError extends Data.TaggedError("AstGrepError") {
18
+ get message() {
19
+ return `AST grep error: ${this.reason}`;
20
+ }
21
+ }
22
+ // ============================================================================
23
+ // Service Tag (mirrors AstGrepService from @tx/core)
24
+ // ============================================================================
25
+ /**
26
+ * Mock AstGrepService tag for dependency injection.
27
+ */
28
+ export class MockAstGrepServiceTag extends Context.Tag("AstGrepService")() {
29
+ }
30
+ // ============================================================================
31
+ // Factory
32
+ // ============================================================================
33
+ /**
34
+ * Create a mock AstGrepService for testing.
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // Basic usage - returns empty arrays
39
+ * const mock = MockAstGrepService()
40
+ * const program = Effect.gen(function* () {
41
+ * const astGrep = yield* MockAstGrepServiceTag
42
+ * return yield* astGrep.findSymbols("src/index.ts")
43
+ * })
44
+ * const result = await Effect.runPromise(Effect.provide(program, mock.layer))
45
+ * expect(result).toEqual([])
46
+ * ```
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // With configured symbols
51
+ * const symbols = new Map([
52
+ * ["src/index.ts", [
53
+ * { name: "main", kind: "function", line: 1, exported: true },
54
+ * { name: "Helper", kind: "class", line: 10, exported: false }
55
+ * ]]
56
+ * ])
57
+ * const mock = MockAstGrepService({ symbols })
58
+ * ```
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * // With failure injection
63
+ * const mock = MockAstGrepService({
64
+ * shouldFail: true,
65
+ * failureMessage: "ast-grep not installed"
66
+ * })
67
+ * ```
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * // With operation-specific failures
72
+ * const mock = MockAstGrepService({
73
+ * failuresByOperation: new Map([
74
+ * ["findSymbols", "Failed to parse file"]
75
+ * ])
76
+ * })
77
+ * // findSymbols will fail, but getImports and matchPattern will work
78
+ * ```
79
+ */
80
+ export const MockAstGrepService = (config = {}) => {
81
+ const findSymbolsCalls = [];
82
+ const getImportsCalls = [];
83
+ const matchPatternCalls = [];
84
+ const layer = Layer.succeed(MockAstGrepServiceTag, {
85
+ findSymbols: (filePath) => Effect.gen(function* () {
86
+ // Track the call
87
+ findSymbolsCalls.push(filePath);
88
+ // Check for global failure
89
+ if (config.shouldFail) {
90
+ return yield* Effect.fail(new MockAstGrepError({
91
+ reason: config.failureMessage || "Mock AstGrep error"
92
+ }));
93
+ }
94
+ // Check for operation-specific failure
95
+ const opFailure = config.failuresByOperation?.get("findSymbols");
96
+ if (opFailure) {
97
+ return yield* Effect.fail(new MockAstGrepError({ reason: opFailure }));
98
+ }
99
+ // Return configured symbols or default
100
+ if (config.symbols?.has(filePath)) {
101
+ return config.symbols.get(filePath);
102
+ }
103
+ return config.defaultSymbols || [];
104
+ }),
105
+ getImports: (filePath) => Effect.gen(function* () {
106
+ // Track the call
107
+ getImportsCalls.push(filePath);
108
+ // Check for global failure
109
+ if (config.shouldFail) {
110
+ return yield* Effect.fail(new MockAstGrepError({
111
+ reason: config.failureMessage || "Mock AstGrep error"
112
+ }));
113
+ }
114
+ // Check for operation-specific failure
115
+ const opFailure = config.failuresByOperation?.get("getImports");
116
+ if (opFailure) {
117
+ return yield* Effect.fail(new MockAstGrepError({ reason: opFailure }));
118
+ }
119
+ // Return configured imports or default
120
+ if (config.imports?.has(filePath)) {
121
+ return config.imports.get(filePath);
122
+ }
123
+ return config.defaultImports || [];
124
+ }),
125
+ matchPattern: (pattern, path) => Effect.gen(function* () {
126
+ // Track the call
127
+ matchPatternCalls.push({ pattern, path });
128
+ // Check for global failure
129
+ if (config.shouldFail) {
130
+ return yield* Effect.fail(new MockAstGrepError({
131
+ reason: config.failureMessage || "Mock AstGrep error"
132
+ }));
133
+ }
134
+ // Check for operation-specific failure
135
+ const opFailure = config.failuresByOperation?.get("matchPattern");
136
+ if (opFailure) {
137
+ return yield* Effect.fail(new MockAstGrepError({ reason: opFailure }));
138
+ }
139
+ // Try specific pattern+path key first
140
+ const specificKey = `${pattern}::${path}`;
141
+ if (config.matches?.has(specificKey)) {
142
+ return config.matches.get(specificKey);
143
+ }
144
+ // Try pattern-only key
145
+ if (config.matches?.has(pattern)) {
146
+ return config.matches.get(pattern);
147
+ }
148
+ return config.defaultMatches || [];
149
+ })
150
+ });
151
+ return {
152
+ layer,
153
+ findSymbolsCalls,
154
+ getImportsCalls,
155
+ matchPatternCalls,
156
+ reset: () => {
157
+ findSymbolsCalls.length = 0;
158
+ getImportsCalls.length = 0;
159
+ matchPatternCalls.length = 0;
160
+ },
161
+ getCallCount: () => findSymbolsCalls.length + getImportsCalls.length + matchPatternCalls.length
162
+ };
163
+ };
164
+ //# sourceMappingURL=ast-grep.mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-grep.mock.js","sourceRoot":"","sources":["../../src/mocks/ast-grep.mock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAuE7B;;GAEG;AACH,MAAM,OAAO,gBAAiB,SAAQ,IAAI,CAAC,WAAW,CAAC,cAAc,CAGnE;IACA,IAAI,OAAO;QACT,OAAO,mBAAmB,IAAI,CAAC,MAAM,EAAE,CAAA;IACzC,CAAC;CACF;AAED,+EAA+E;AAC/E,qDAAqD;AACrD,+EAA+E;AAE/E;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAOrE;CAAG;AAwFN,+EAA+E;AAC/E,UAAU;AACV,+EAA+E;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,SAAmC,EAAE,EAA4B,EAAE;IACpG,MAAM,gBAAgB,GAAa,EAAE,CAAA;IACrC,MAAM,eAAe,GAAa,EAAE,CAAA;IACpC,MAAM,iBAAiB,GAA6C,EAAE,CAAA;IAEtE,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,qBAAqB,EAAE;QACjD,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A;YACzC,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;gBACrC,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW,CAAE,CAAA;YACzC,CAAC;YAED,uBAAuB;YACvB,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;gBACjC,OAAO,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAE,CAAA;YACrC,CAAC;YAED,OAAO,MAAM,CAAC,cAAc,IAAI,EAAE,CAAA;QACpC,CAAC,CAAC;KACL,CAAC,CAAA;IAEF,OAAO;QACL,KAAK;QACL,gBAAgB;QAChB,eAAe;QACf,iBAAiB;QACjB,KAAK,EAAE,GAAG,EAAE;YACV,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAA;YAC3B,eAAe,CAAC,MAAM,GAAG,CAAC,CAAA;YAC1B,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAA;QAC9B,CAAC;QACD,YAAY,EAAE,GAAG,EAAE,CAAC,gBAAgB,CAAC,MAAM,GAAG,eAAe,CAAC,MAAM,GAAG,iBAAiB,CAAC,MAAM;KAChG,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Mock FileSystemService for testing.
3
+ *
4
+ * Provides configurable mock FileSystemService with in-memory storage,
5
+ * initial file fixtures, and failure injection for testing services
6
+ * that depend on file system operations.
7
+ *
8
+ * Note: Uses inline types until FileSystemService is exported from @tx/core.
9
+ *
10
+ * @module @tx/test-utils/mocks/file-system
11
+ */
12
+ import { Context, Effect, Layer } from "effect";
13
+ declare const MockFileSystemError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
14
+ readonly _tag: "FileSystemError";
15
+ } & Readonly<A>;
16
+ /**
17
+ * Error type for file system operations.
18
+ */
19
+ export declare class MockFileSystemError extends MockFileSystemError_base<{
20
+ readonly reason: string;
21
+ readonly path?: string;
22
+ readonly cause?: unknown;
23
+ }> {
24
+ get message(): string;
25
+ }
26
+ declare const MockFileSystemServiceTag_base: Context.TagClass<MockFileSystemServiceTag, "FileSystemService", {
27
+ readonly readFile: (path: string) => Effect.Effect<string, MockFileSystemError>;
28
+ readonly writeFile: (path: string, content: string) => Effect.Effect<void, MockFileSystemError>;
29
+ readonly exists: (path: string) => Effect.Effect<boolean, MockFileSystemError>;
30
+ readonly mkdir: (path: string) => Effect.Effect<void, MockFileSystemError>;
31
+ readonly readdir: (path: string) => Effect.Effect<readonly string[], MockFileSystemError>;
32
+ }>;
33
+ /**
34
+ * Mock FileSystemService tag for dependency injection.
35
+ */
36
+ export declare class MockFileSystemServiceTag extends MockFileSystemServiceTag_base {
37
+ }
38
+ /**
39
+ * Configuration options for the MockFileSystem.
40
+ */
41
+ export interface MockFileSystemConfig {
42
+ /**
43
+ * Initial files to populate the in-memory file system.
44
+ * Keys are file paths, values are file contents.
45
+ */
46
+ initialFiles?: Map<string, string>;
47
+ /**
48
+ * Initial directories to create.
49
+ * Set of directory paths. If not provided, directories are auto-created
50
+ * based on file paths in initialFiles.
51
+ */
52
+ initialDirectories?: Set<string>;
53
+ /**
54
+ * When true, all operations will fail with an error.
55
+ */
56
+ shouldFail?: boolean;
57
+ /**
58
+ * Custom error message when shouldFail is true.
59
+ * Defaults to "Mock FileSystem error".
60
+ */
61
+ failureMessage?: string;
62
+ /**
63
+ * Map of specific operations to fail.
64
+ * Keys: "readFile", "writeFile", "exists", "mkdir", "readdir"
65
+ * Values: error message for that operation
66
+ */
67
+ failuresByOperation?: Map<string, string>;
68
+ /**
69
+ * Map of specific paths to fail on.
70
+ * Keys: file/directory paths
71
+ * Values: error message when accessing that path
72
+ */
73
+ failuresByPath?: Map<string, string>;
74
+ }
75
+ /**
76
+ * Result returned by MockFileSystem factory.
77
+ */
78
+ export interface MockFileSystemResult {
79
+ /**
80
+ * Effect Layer providing the mock FileSystemService.
81
+ */
82
+ layer: Layer.Layer<MockFileSystemServiceTag>;
83
+ /**
84
+ * Array of all readFile calls made (paths).
85
+ */
86
+ readFileCalls: string[];
87
+ /**
88
+ * Array of all writeFile calls made.
89
+ */
90
+ writeFileCalls: Array<{
91
+ path: string;
92
+ content: string;
93
+ }>;
94
+ /**
95
+ * Array of all exists calls made (paths).
96
+ */
97
+ existsCalls: string[];
98
+ /**
99
+ * Array of all mkdir calls made (paths).
100
+ */
101
+ mkdirCalls: string[];
102
+ /**
103
+ * Array of all readdir calls made (paths).
104
+ */
105
+ readdirCalls: string[];
106
+ /**
107
+ * Get the current in-memory file contents.
108
+ */
109
+ getFiles: () => Map<string, string>;
110
+ /**
111
+ * Get the current in-memory directories.
112
+ */
113
+ getDirectories: () => Set<string>;
114
+ /**
115
+ * Reset all call tracking arrays and restore initial state.
116
+ */
117
+ reset: () => void;
118
+ /**
119
+ * Get total number of all calls made.
120
+ */
121
+ getCallCount: () => number;
122
+ }
123
+ /**
124
+ * Create a mock FileSystemService for testing.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Basic usage - empty file system
129
+ * const mock = MockFileSystem()
130
+ * const program = Effect.gen(function* () {
131
+ * const fs = yield* MockFileSystemServiceTag
132
+ * yield* fs.writeFile("/tmp/test.txt", "hello")
133
+ * return yield* fs.readFile("/tmp/test.txt")
134
+ * })
135
+ * const result = await Effect.runPromise(Effect.provide(program, mock.layer))
136
+ * expect(result).toBe("hello")
137
+ * ```
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * // With initial files
142
+ * const mock = MockFileSystem({
143
+ * initialFiles: new Map([
144
+ * ["/app/config.json", '{"debug": true}'],
145
+ * ["/app/data.txt", "Hello World"]
146
+ * ])
147
+ * })
148
+ * ```
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * // With failure injection
153
+ * const mock = MockFileSystem({
154
+ * shouldFail: true,
155
+ * failureMessage: "Disk full"
156
+ * })
157
+ * ```
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // With path-specific failures
162
+ * const mock = MockFileSystem({
163
+ * failuresByPath: new Map([
164
+ * ["/protected/secret.txt", "Permission denied"]
165
+ * ])
166
+ * })
167
+ * ```
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * // With operation-specific failures
172
+ * const mock = MockFileSystem({
173
+ * failuresByOperation: new Map([
174
+ * ["writeFile", "Read-only file system"]
175
+ * ])
176
+ * })
177
+ * ```
178
+ */
179
+ export declare const MockFileSystem: (config?: MockFileSystemConfig) => MockFileSystemResult;
180
+ export {};
181
+ //# sourceMappingURL=file-system.mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"file-system.mock.d.ts","sourceRoot":"","sources":["../../src/mocks/file-system.mock.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAA;;;;AAO/C;;GAEG;AACH,qBAAa,mBAAoB,SAAQ,yBAAoC;IAC3E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CACzB,CAAC;IACA,IAAI,OAAO,WAIV;CACF;;uBAYsB,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC;wBAC3D,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,mBAAmB,CAAC;qBAC9E,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,mBAAmB,CAAC;oBAC9D,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,mBAAmB,CAAC;sBACx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