@pikku/inspector 0.12.75 → 0.12.82

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 (223) hide show
  1. package/CHANGELOG.md +357 -0
  2. package/dist/add/add-analytics.d.ts +9 -0
  3. package/dist/add/add-analytics.js +178 -0
  4. package/dist/add/add-auth.js +0 -54
  5. package/dist/add/add-feature-flag.d.ts +2 -0
  6. package/dist/add/add-feature-flag.js +162 -0
  7. package/dist/add/add-middleware.js +66 -42
  8. package/dist/add/add-wire-addon.js +7 -4
  9. package/dist/add/add-wire-remote-addon.js +1 -0
  10. package/dist/error-codes.d.ts +1 -0
  11. package/dist/error-codes.js +1 -0
  12. package/dist/index.d.ts +3 -1
  13. package/dist/index.js +3 -1
  14. package/dist/inspector.js +5 -0
  15. package/dist/surface/collect-surface.d.ts +58 -0
  16. package/dist/surface/collect-surface.js +613 -0
  17. package/dist/types.d.ts +36 -12
  18. package/dist/utils/filter-inspector-state.js +14 -0
  19. package/dist/utils/load-addon-functions-meta.js +24 -11
  20. package/dist/utils/post-process.js +15 -0
  21. package/dist/utils/read-module-specifiers.d.ts +8 -0
  22. package/dist/utils/read-module-specifiers.js +23 -0
  23. package/dist/utils/read-tsconfig-out-dir.d.ts +5 -0
  24. package/dist/utils/read-tsconfig-out-dir.js +12 -0
  25. package/dist/utils/resolve-deploy-target.d.ts +7 -0
  26. package/dist/utils/resolve-deploy-target.js +15 -7
  27. package/dist/utils/serialize-inspector-state.d.ts +6 -0
  28. package/dist/utils/serialize-inspector-state.js +10 -0
  29. package/dist/visit.js +4 -0
  30. package/package.json +16 -6
  31. package/run-tests.sh +21 -6
  32. package/src/add/add-addon-bans.ts +0 -85
  33. package/src/add/add-agent-scorer.test.ts +0 -197
  34. package/src/add/add-agent-scorer.ts +0 -83
  35. package/src/add/add-agent.test.ts +0 -87
  36. package/src/add/add-agent.ts +0 -638
  37. package/src/add/add-approval-description.ts +0 -76
  38. package/src/add/add-auth.test.ts +0 -791
  39. package/src/add/add-auth.ts +0 -424
  40. package/src/add/add-channel.ts +0 -778
  41. package/src/add/add-cli-renderers.test.ts +0 -74
  42. package/src/add/add-cli.ts +0 -1006
  43. package/src/add/add-credential.ts +0 -186
  44. package/src/add/add-feature.test.ts +0 -306
  45. package/src/add/add-feature.ts +0 -253
  46. package/src/add/add-file-extends-core-type.ts +0 -66
  47. package/src/add/add-file-with-config.ts +0 -45
  48. package/src/add/add-file-with-factory.test.ts +0 -134
  49. package/src/add/add-file-with-factory.ts +0 -288
  50. package/src/add/add-functions.test.ts +0 -743
  51. package/src/add/add-functions.ts +0 -1548
  52. package/src/add/add-gateway.ts +0 -143
  53. package/src/add/add-http-route-ref.test.ts +0 -149
  54. package/src/add/add-http-route.ts +0 -530
  55. package/src/add/add-http-routes.ts +0 -471
  56. package/src/add/add-keyed-wiring.ts +0 -180
  57. package/src/add/add-mcp-prompt.ts +0 -157
  58. package/src/add/add-mcp-resource.ts +0 -175
  59. package/src/add/add-middleware.test.ts +0 -196
  60. package/src/add/add-middleware.ts +0 -879
  61. package/src/add/add-permission-auth.test.ts +0 -59
  62. package/src/add/add-permission.ts +0 -311
  63. package/src/add/add-personas.test.ts +0 -406
  64. package/src/add/add-personas.ts +0 -287
  65. package/src/add/add-queue-worker.ts +0 -117
  66. package/src/add/add-rpc-invocations.test.ts +0 -287
  67. package/src/add/add-rpc-invocations.ts +0 -221
  68. package/src/add/add-scenario-step.test.ts +0 -509
  69. package/src/add/add-schedule.ts +0 -120
  70. package/src/add/add-scope.test.ts +0 -419
  71. package/src/add/add-scope.ts +0 -221
  72. package/src/add/add-secret.ts +0 -10
  73. package/src/add/add-subject-scenario-steps.test.ts +0 -161
  74. package/src/add/add-system-role.test.ts +0 -297
  75. package/src/add/add-system-role.ts +0 -162
  76. package/src/add/add-trigger.ts +0 -165
  77. package/src/add/add-variable.ts +0 -10
  78. package/src/add/add-wire-addon.test.ts +0 -185
  79. package/src/add/add-wire-addon.ts +0 -146
  80. package/src/add/add-wire-remote-addon.ts +0 -80
  81. package/src/add/add-workflow-edge-cases.test.ts +0 -201
  82. package/src/add/add-workflow-fanout.test.ts +0 -166
  83. package/src/add/add-workflow-graph-foreach.test.ts +0 -174
  84. package/src/add/add-workflow-graph-input.test.ts +0 -94
  85. package/src/add/add-workflow-graph-notes.test.ts +0 -74
  86. package/src/add/add-workflow-graph.ts +0 -644
  87. package/src/add/add-workflow-on-error.test.ts +0 -118
  88. package/src/add/add-workflow-return-switch.test.ts +0 -121
  89. package/src/add/add-workflow-silent-drops.test.ts +0 -261
  90. package/src/add/add-workflow-sleep-expression.test.ts +0 -96
  91. package/src/add/add-workflow.test.ts +0 -155
  92. package/src/add/add-workflow.ts +0 -482
  93. package/src/add/addon-bans.test.ts +0 -121
  94. package/src/add/addon-contracts.test.ts +0 -221
  95. package/src/add/allow-escape-hatches.test.ts +0 -144
  96. package/src/add/audit-meta.test.ts +0 -75
  97. package/src/add/classified-sink-check.test.ts +0 -347
  98. package/src/add/config-value-metadata.test.ts +0 -263
  99. package/src/add/dynamic-import-check.test.ts +0 -119
  100. package/src/add/expect-eventually-scenario-only.test.ts +0 -108
  101. package/src/add/function-body-span.test.ts +0 -96
  102. package/src/add/inline-wiring-function.test.ts +0 -104
  103. package/src/add/pii-check.test.ts +0 -258
  104. package/src/add/rpc-type-cast.test.ts +0 -123
  105. package/src/add/scenario-instrumentation.test.ts +0 -89
  106. package/src/add/scenario-instrumentation.ts +0 -42
  107. package/src/add/scenario-marker.test.ts +0 -89
  108. package/src/add/scenario-not-extractable.test.ts +0 -159
  109. package/src/add/scenario-services.test.ts +0 -103
  110. package/src/add/scenario-skip.test.ts +0 -83
  111. package/src/add/validate-workflow-graph-addons.test.ts +0 -102
  112. package/src/add/wire-name-literal.test.ts +0 -117
  113. package/src/error-codes-emitted.test.ts +0 -76
  114. package/src/error-codes.ts +0 -145
  115. package/src/index.ts +0 -66
  116. package/src/inspector.ts +0 -575
  117. package/src/schema-generator.ts +0 -1
  118. package/src/source-file-cache.ts +0 -73
  119. package/src/tsconfig-paths.test.ts +0 -90
  120. package/src/types-map.ts +0 -141
  121. package/src/types.ts +0 -775
  122. package/src/utils/annotate-http-route-auth.test.ts +0 -161
  123. package/src/utils/annotate-http-route-auth.ts +0 -53
  124. package/src/utils/check-classified-sinks.ts +0 -215
  125. package/src/utils/check-pii-output.ts +0 -120
  126. package/src/utils/compute-diagnostics.test.ts +0 -106
  127. package/src/utils/compute-required-schemas.ts +0 -48
  128. package/src/utils/contract-hashes.test.ts +0 -553
  129. package/src/utils/contract-hashes.ts +0 -387
  130. package/src/utils/custom-types-generator.test.ts +0 -124
  131. package/src/utils/custom-types-generator.ts +0 -150
  132. package/src/utils/detect-schema-vendor.test.ts +0 -123
  133. package/src/utils/detect-schema-vendor.ts +0 -120
  134. package/src/utils/does-type-extend-core-type.ts +0 -53
  135. package/src/utils/ensure-function-metadata.ts +0 -385
  136. package/src/utils/extract-function-name.ts +0 -612
  137. package/src/utils/extract-function-node.ts +0 -70
  138. package/src/utils/extract-node-value.test.ts +0 -117
  139. package/src/utils/extract-node-value.ts +0 -172
  140. package/src/utils/extract-secret-usage.test.ts +0 -81
  141. package/src/utils/extract-secret-usage.ts +0 -73
  142. package/src/utils/extract-services.ts +0 -70
  143. package/src/utils/extract-surface-usage.test.ts +0 -147
  144. package/src/utils/extract-surface-usage.ts +0 -121
  145. package/src/utils/filter-inspector-state.test.ts +0 -2232
  146. package/src/utils/filter-inspector-state.ts +0 -1298
  147. package/src/utils/filter-utils.test.ts +0 -843
  148. package/src/utils/filter-utils.ts +0 -161
  149. package/src/utils/find-root-dir.ts +0 -68
  150. package/src/utils/find-zod-transform.test.ts +0 -70
  151. package/src/utils/find-zod-transform.ts +0 -103
  152. package/src/utils/get-exported-variable-name.ts +0 -48
  153. package/src/utils/get-files-and-methods.ts +0 -157
  154. package/src/utils/get-property-value.test.ts +0 -141
  155. package/src/utils/get-property-value.ts +0 -331
  156. package/src/utils/hash.ts +0 -26
  157. package/src/utils/literal-properties.ts +0 -97
  158. package/src/utils/load-addon-functions-meta.test.ts +0 -157
  159. package/src/utils/load-addon-functions-meta.ts +0 -508
  160. package/src/utils/load-addon-scopes.test.ts +0 -138
  161. package/src/utils/middleware.test.ts +0 -204
  162. package/src/utils/middleware.ts +0 -303
  163. package/src/utils/nested-project-filter.test.ts +0 -53
  164. package/src/utils/nested-project-filter.ts +0 -28
  165. package/src/utils/permissions-shorthand.test.ts +0 -79
  166. package/src/utils/permissions.test.ts +0 -125
  167. package/src/utils/permissions.ts +0 -129
  168. package/src/utils/post-process.test.ts +0 -1094
  169. package/src/utils/post-process.ts +0 -1604
  170. package/src/utils/resolve-addon-package.ts +0 -106
  171. package/src/utils/resolve-core-type.test.ts +0 -142
  172. package/src/utils/resolve-core-type.ts +0 -35
  173. package/src/utils/resolve-deploy-target.test.ts +0 -135
  174. package/src/utils/resolve-deploy-target.ts +0 -65
  175. package/src/utils/resolve-function-meta.ts +0 -25
  176. package/src/utils/resolve-function-types.ts +0 -42
  177. package/src/utils/resolve-identifier.ts +0 -46
  178. package/src/utils/resolve-ref-contract.ts +0 -71
  179. package/src/utils/resolve-versions.test.ts +0 -499
  180. package/src/utils/resolve-versions.ts +0 -228
  181. package/src/utils/schema-cache.test.ts +0 -124
  182. package/src/utils/schema-generator.test.ts +0 -272
  183. package/src/utils/schema-generator.ts +0 -780
  184. package/src/utils/secret-alias-services.test.ts +0 -146
  185. package/src/utils/secret-alias-services.ts +0 -58
  186. package/src/utils/serialize-inspector-state.ts +0 -742
  187. package/src/utils/serialize-mcp-json.ts +0 -150
  188. package/src/utils/serialize-middleware-groups-meta.ts +0 -36
  189. package/src/utils/serialize-openapi-json.ts +0 -277
  190. package/src/utils/serialize-permissions-groups-meta.ts +0 -7
  191. package/src/utils/single-declaration.ts +0 -57
  192. package/src/utils/type-utils.ts +0 -145
  193. package/src/utils/validate-auth-sessionless.ts +0 -30
  194. package/src/utils/validate-exposed-functions-gated.test.ts +0 -230
  195. package/src/utils/validate-exposed-functions-gated.ts +0 -103
  196. package/src/utils/validate-tags-resolve-to-middleware.test.ts +0 -108
  197. package/src/utils/validate-tags-resolve-to-middleware.ts +0 -48
  198. package/src/utils/workflow/derive-workflow-plan.test.ts +0 -178
  199. package/src/utils/workflow/derive-workflow-plan.ts +0 -117
  200. package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +0 -1465
  201. package/src/utils/workflow/dsl/deserialize-fanout-body.test.ts +0 -71
  202. package/src/utils/workflow/dsl/deserialize-fanout-fidelity.test.ts +0 -99
  203. package/src/utils/workflow/dsl/deserialize-graph-next.test.ts +0 -161
  204. package/src/utils/workflow/dsl/deserialize-roundtrip-bindings.test.ts +0 -121
  205. package/src/utils/workflow/dsl/deserialize-roundtrip-values.test.ts +0 -116
  206. package/src/utils/workflow/dsl/deserialize-roundtrip.test.ts +0 -145
  207. package/src/utils/workflow/dsl/extract-approval-policy.test.ts +0 -71
  208. package/src/utils/workflow/dsl/extract-dsl-workflow.ts +0 -2254
  209. package/src/utils/workflow/dsl/index.ts +0 -11
  210. package/src/utils/workflow/dsl/patterns.ts +0 -440
  211. package/src/utils/workflow/dsl/validation.ts +0 -203
  212. package/src/utils/workflow/graph/convert-dsl-to-graph-skip.test.ts +0 -35
  213. package/src/utils/workflow/graph/convert-dsl-to-graph.ts +0 -543
  214. package/src/utils/workflow/graph/fanout-node-identity.test.ts +0 -105
  215. package/src/utils/workflow/graph/finalize-workflow-wires.ts +0 -310
  216. package/src/utils/workflow/graph/finalize-workflows.test.ts +0 -50
  217. package/src/utils/workflow/graph/finalize-workflows.ts +0 -130
  218. package/src/utils/workflow/graph/index.ts +0 -28
  219. package/src/utils/workflow/graph/serialize-workflow-graph.ts +0 -240
  220. package/src/utils/workflow/graph/workflow-graph.types.ts +0 -281
  221. package/src/visit.ts +0 -181
  222. package/tsconfig.json +0 -19
  223. package/tsconfig.tsbuildinfo +0 -1
@@ -1,843 +0,0 @@
1
- import { test, describe } from 'node:test'
2
- import { strict as assert } from 'node:assert'
3
- import type { InspectorFilters } from '../types'
4
- import { matchesFilters, matchesWildcard } from './filter-utils'
5
-
6
- describe('matchesFilters', () => {
7
- // Mock logger for testing
8
- const mockLogger = {
9
- info: () => {},
10
- error: () => {},
11
- warn: () => {},
12
- debug: () => {},
13
- diagnostic: () => {},
14
- critical: () => {},
15
- hasCriticalErrors: () => false,
16
- }
17
-
18
- describe('Empty filters', () => {
19
- test('should return true when no filters are provided', () => {
20
- const filters: InspectorFilters = {}
21
-
22
- const result = matchesFilters(
23
- filters,
24
- { tags: ['test'] },
25
- { type: 'http', name: 'test-route' },
26
- mockLogger
27
- )
28
-
29
- assert.equal(result, true)
30
- })
31
-
32
- test('should return true when all filter arrays are empty', () => {
33
- const filters: InspectorFilters = {
34
- tags: [],
35
- wires: [],
36
- directories: [],
37
- }
38
-
39
- const result = matchesFilters(
40
- filters,
41
- { tags: ['test'] },
42
- { type: 'http', name: 'test-route' },
43
- mockLogger
44
- )
45
-
46
- assert.equal(result, true)
47
- })
48
- })
49
-
50
- describe('Tag filtering', () => {
51
- test('should return true when tags match', () => {
52
- const filters: InspectorFilters = {
53
- tags: ['api', 'public'],
54
- }
55
-
56
- const result = matchesFilters(
57
- filters,
58
- { tags: ['api', 'internal'] },
59
- { type: 'http', name: 'test-route' },
60
- mockLogger
61
- )
62
-
63
- assert.equal(result, true)
64
- })
65
-
66
- test('should return false when tags do not match', () => {
67
- const filters: InspectorFilters = {
68
- tags: ['api', 'public'],
69
- }
70
-
71
- const result = matchesFilters(
72
- filters,
73
- { tags: ['internal', 'private'] },
74
- { type: 'http', name: 'test-route' },
75
- mockLogger
76
- )
77
-
78
- assert.equal(result, false)
79
- })
80
-
81
- test('should return false when function has no tags but filter requires tags', () => {
82
- const filters: InspectorFilters = {
83
- tags: ['api'],
84
- }
85
-
86
- const result = matchesFilters(
87
- filters,
88
- { tags: undefined },
89
- { type: 'http', name: 'test-route' },
90
- mockLogger
91
- )
92
-
93
- assert.equal(result, false)
94
- })
95
-
96
- test('should return false when function has empty tags but filter requires tags', () => {
97
- const filters: InspectorFilters = {
98
- tags: ['api'],
99
- }
100
-
101
- const result = matchesFilters(
102
- filters,
103
- { tags: [] },
104
- { type: 'http', name: 'test-route' },
105
- mockLogger
106
- )
107
-
108
- assert.equal(result, false)
109
- })
110
- })
111
-
112
- describe('Wire filtering', () => {
113
- test('should return true when wire matches', () => {
114
- const filters: InspectorFilters = {
115
- wires: ['http', 'channel'],
116
- }
117
-
118
- const result = matchesFilters(
119
- filters,
120
- { tags: ['test'] },
121
- { type: 'http', name: 'test-route' },
122
- mockLogger
123
- )
124
-
125
- assert.equal(result, true)
126
- })
127
-
128
- test('should return false when wire does not match', () => {
129
- const filters: InspectorFilters = {
130
- wires: ['channel', 'queue'],
131
- }
132
-
133
- const result = matchesFilters(
134
- filters,
135
- { tags: ['test'] },
136
- { type: 'http', name: 'test-route' },
137
- mockLogger
138
- )
139
-
140
- assert.equal(result, false)
141
- })
142
-
143
- test('should handle all PikkuWiringTypes correctly', () => {
144
- const eventTypes = ['http', 'channel', 'queue', 'scheduler', 'rpc', 'mcp']
145
-
146
- eventTypes.forEach((eventType) => {
147
- const filters: InspectorFilters = {
148
- wires: [eventType],
149
- }
150
-
151
- const result = matchesFilters(
152
- filters,
153
- { tags: ['test'] },
154
- { type: eventType, name: 'test-route' },
155
- mockLogger
156
- )
157
-
158
- assert.equal(result, true, `Should match for wire: ${eventType}`)
159
- })
160
- })
161
-
162
- test('should exclude matching wires', () => {
163
- const filters: InspectorFilters = {
164
- excludeWires: ['queue', 'scheduler'],
165
- }
166
-
167
- const result = matchesFilters(
168
- filters,
169
- { tags: ['test'] },
170
- { type: 'queue', name: 'email-worker' },
171
- mockLogger
172
- )
173
-
174
- assert.equal(result, false)
175
- })
176
- })
177
-
178
- describe('Directory filtering', () => {
179
- test('should return true when directory matches', () => {
180
- const filters: InspectorFilters = {
181
- directories: ['src/api', 'src/internal'],
182
- }
183
-
184
- const result = matchesFilters(
185
- filters,
186
- { tags: ['test'] },
187
- {
188
- type: 'http',
189
- name: 'test-route',
190
- filePath: '/project/src/api/routes.ts',
191
- },
192
- mockLogger
193
- )
194
-
195
- assert.equal(result, true)
196
- })
197
-
198
- test('should return false when directory does not match', () => {
199
- const filters: InspectorFilters = {
200
- directories: ['src/api', 'src/internal'],
201
- }
202
-
203
- const result = matchesFilters(
204
- filters,
205
- { tags: ['test'] },
206
- {
207
- type: 'http',
208
- name: 'test-route',
209
- filePath: '/project/src/public/routes.ts',
210
- },
211
- mockLogger
212
- )
213
-
214
- assert.equal(result, false)
215
- })
216
-
217
- test('should handle Windows paths correctly', () => {
218
- const filters: InspectorFilters = {
219
- directories: ['src\\api'],
220
- }
221
-
222
- const result = matchesFilters(
223
- filters,
224
- { tags: ['test'] },
225
- {
226
- type: 'http',
227
- name: 'test-route',
228
- filePath: 'C:\\project\\src\\api\\routes.ts',
229
- },
230
- mockLogger
231
- )
232
-
233
- assert.equal(result, true)
234
- })
235
-
236
- test('should handle mixed path separators', () => {
237
- const filters: InspectorFilters = {
238
- directories: ['src/api'],
239
- }
240
-
241
- const result = matchesFilters(
242
- filters,
243
- { tags: ['test'] },
244
- {
245
- type: 'http',
246
- name: 'test-route',
247
- filePath: 'C:\\project\\src\\api\\routes.ts',
248
- },
249
- mockLogger
250
- )
251
-
252
- assert.equal(result, true)
253
- })
254
-
255
- test('should return false when filePath is not provided but directory filter exists', () => {
256
- const filters: InspectorFilters = {
257
- directories: ['src/api'],
258
- }
259
-
260
- const result = matchesFilters(
261
- filters,
262
- { tags: ['test'] },
263
- { type: 'http', name: 'test-route' }, // no filePath
264
- mockLogger
265
- )
266
-
267
- assert.equal(result, false)
268
- })
269
-
270
- test('should handle partial path matches', () => {
271
- const filters: InspectorFilters = {
272
- directories: ['api'],
273
- }
274
-
275
- const result = matchesFilters(
276
- filters,
277
- { tags: ['test'] },
278
- {
279
- type: 'http',
280
- name: 'test-route',
281
- filePath: '/project/src/api/v1/routes.ts',
282
- },
283
- mockLogger
284
- )
285
-
286
- assert.equal(result, true)
287
- })
288
- })
289
-
290
- describe('Combined filtering', () => {
291
- test('should return true when all filters pass', () => {
292
- const filters: InspectorFilters = {
293
- tags: ['api'],
294
- wires: ['http'],
295
- directories: ['src/api'],
296
- }
297
-
298
- const result = matchesFilters(
299
- filters,
300
- { tags: ['api', 'public'] },
301
- {
302
- type: 'http',
303
- name: 'test-route',
304
- filePath: '/project/src/api/routes.ts',
305
- },
306
- mockLogger
307
- )
308
-
309
- assert.equal(result, true)
310
- })
311
-
312
- test('should return false when type filter fails (even if others pass)', () => {
313
- const filters: InspectorFilters = {
314
- tags: ['api'],
315
- wires: ['channel'],
316
- directories: ['src/api'],
317
- }
318
-
319
- const result = matchesFilters(
320
- filters,
321
- { tags: ['api', 'public'] },
322
- {
323
- type: 'http',
324
- name: 'test-route',
325
- filePath: '/project/src/api/routes.ts',
326
- },
327
- mockLogger
328
- )
329
-
330
- assert.equal(result, false)
331
- })
332
-
333
- test('should return false when directory filter fails (even if others pass)', () => {
334
- const filters: InspectorFilters = {
335
- tags: ['api'],
336
- wires: ['http'],
337
- directories: ['src/internal'],
338
- }
339
-
340
- const result = matchesFilters(
341
- filters,
342
- { tags: ['api', 'public'] },
343
- {
344
- type: 'http',
345
- name: 'test-route',
346
- filePath: '/project/src/api/routes.ts',
347
- },
348
- mockLogger
349
- )
350
-
351
- assert.equal(result, false)
352
- })
353
-
354
- test('should return false when tag filter fails (even if others pass)', () => {
355
- const filters: InspectorFilters = {
356
- tags: ['internal'],
357
- wires: ['http'],
358
- directories: ['src/api'],
359
- }
360
-
361
- const result = matchesFilters(
362
- filters,
363
- { tags: ['api', 'public'] },
364
- {
365
- type: 'http',
366
- name: 'test-route',
367
- filePath: '/project/src/api/routes.ts',
368
- },
369
- mockLogger
370
- )
371
-
372
- assert.equal(result, false)
373
- })
374
- })
375
-
376
- describe('Edge cases', () => {
377
- test('should handle undefined params', () => {
378
- const filters: InspectorFilters = {
379
- tags: ['api'],
380
- }
381
-
382
- const result = matchesFilters(
383
- filters,
384
- { tags: undefined },
385
- { type: 'http', name: 'test-route' },
386
- mockLogger
387
- )
388
-
389
- assert.equal(result, false)
390
- })
391
-
392
- test('should handle empty meta name', () => {
393
- const filters: InspectorFilters = {
394
- wires: ['channel'],
395
- }
396
-
397
- const result = matchesFilters(
398
- filters,
399
- { tags: ['test'] },
400
- { type: 'http', name: '' },
401
- mockLogger
402
- )
403
-
404
- assert.equal(result, false)
405
- })
406
-
407
- test('should handle special characters in paths', () => {
408
- const filters: InspectorFilters = {
409
- directories: ['src/api-v2'],
410
- }
411
-
412
- const result = matchesFilters(
413
- filters,
414
- { tags: ['test'] },
415
- {
416
- type: 'http',
417
- name: 'test-route',
418
- filePath: '/project/src/api-v2/routes.ts',
419
- },
420
- mockLogger
421
- )
422
-
423
- assert.equal(result, true)
424
- })
425
-
426
- test('should handle case sensitivity in directory paths', () => {
427
- const filters: InspectorFilters = {
428
- directories: ['src/API'],
429
- }
430
-
431
- const result = matchesFilters(
432
- filters,
433
- { tags: ['test'] },
434
- {
435
- type: 'http',
436
- name: 'test-route',
437
- filePath: '/project/src/api/routes.ts',
438
- },
439
- mockLogger
440
- )
441
-
442
- assert.equal(result, false)
443
- })
444
-
445
- test('should handle multiple matching tags', () => {
446
- const filters: InspectorFilters = {
447
- tags: ['api', 'v1'],
448
- }
449
-
450
- const result = matchesFilters(
451
- filters,
452
- { tags: ['api', 'public', 'v1'] },
453
- { type: 'http', name: 'test-route' },
454
- mockLogger
455
- )
456
-
457
- assert.equal(result, true)
458
- })
459
-
460
- test('should handle multiple matching types', () => {
461
- const filters: InspectorFilters = {
462
- wires: ['http', 'channel'],
463
- }
464
-
465
- const result = matchesFilters(
466
- filters,
467
- { tags: ['test'] },
468
- { type: 'channel', name: 'test-channel' },
469
- mockLogger
470
- )
471
-
472
- assert.equal(result, true)
473
- })
474
-
475
- test('should handle multiple matching directories', () => {
476
- const filters: InspectorFilters = {
477
- directories: ['src/api', 'src/internal'],
478
- }
479
-
480
- const result = matchesFilters(
481
- filters,
482
- { tags: ['test'] },
483
- {
484
- type: 'http',
485
- name: 'test-route',
486
- filePath: '/project/src/internal/routes.ts',
487
- },
488
- mockLogger
489
- )
490
-
491
- assert.equal(result, true)
492
- })
493
- })
494
-
495
- describe('Name filtering', () => {
496
- test('should return true when name matches exactly', () => {
497
- const filters: InspectorFilters = {
498
- names: ['email-worker', 'notification-worker'],
499
- }
500
-
501
- const result = matchesFilters(
502
- filters,
503
- { name: 'email-worker' },
504
- { type: 'queue', name: 'email-queue' },
505
- mockLogger
506
- )
507
-
508
- assert.equal(result, true)
509
- })
510
-
511
- test('should return true when name matches with wildcard', () => {
512
- const filters: InspectorFilters = {
513
- names: ['email-*'],
514
- }
515
-
516
- const result = matchesFilters(
517
- filters,
518
- { name: 'email-worker' },
519
- { type: 'queue', name: 'email-queue' },
520
- mockLogger
521
- )
522
-
523
- assert.equal(result, true)
524
- })
525
-
526
- test('should return false when name does not match wildcard', () => {
527
- const filters: InspectorFilters = {
528
- names: ['email-*'],
529
- }
530
-
531
- const result = matchesFilters(
532
- filters,
533
- { name: 'notification-worker' },
534
- { type: 'queue', name: 'notification-queue' },
535
- mockLogger
536
- )
537
-
538
- assert.equal(result, false)
539
- })
540
-
541
- test('should use meta.name when params.name is not provided', () => {
542
- const filters: InspectorFilters = {
543
- names: ['test-*'],
544
- }
545
-
546
- const result = matchesFilters(
547
- filters,
548
- {},
549
- { type: 'http', name: 'test-route' },
550
- mockLogger
551
- )
552
-
553
- assert.equal(result, true)
554
- })
555
-
556
- test('should prefer params.name over meta.name', () => {
557
- const filters: InspectorFilters = {
558
- names: ['email-*'],
559
- }
560
-
561
- const result = matchesFilters(
562
- filters,
563
- { name: 'email-worker' },
564
- { type: 'queue', name: 'other-name' },
565
- mockLogger
566
- )
567
-
568
- assert.equal(result, true)
569
- })
570
- })
571
-
572
- describe('HTTP route filtering', () => {
573
- test('should return true when httpRoute matches exactly', () => {
574
- const filters: InspectorFilters = {
575
- httpRoutes: ['/api/users', '/api/posts'],
576
- }
577
-
578
- const result = matchesFilters(
579
- filters,
580
- {},
581
- {
582
- type: 'http',
583
- name: 'users-route',
584
- httpRoute: '/api/users',
585
- },
586
- mockLogger
587
- )
588
-
589
- assert.equal(result, true)
590
- })
591
-
592
- test('should return true when httpRoute matches with wildcard', () => {
593
- const filters: InspectorFilters = {
594
- httpRoutes: ['/api/*'],
595
- }
596
-
597
- const result = matchesFilters(
598
- filters,
599
- {},
600
- {
601
- type: 'http',
602
- name: 'users-route',
603
- httpRoute: '/api/users',
604
- },
605
- mockLogger
606
- )
607
-
608
- assert.equal(result, true)
609
- })
610
-
611
- test('should return false when httpRoute does not match wildcard', () => {
612
- const filters: InspectorFilters = {
613
- httpRoutes: ['/api/*'],
614
- }
615
-
616
- const result = matchesFilters(
617
- filters,
618
- {},
619
- {
620
- type: 'http',
621
- name: 'webhook-route',
622
- httpRoute: '/webhooks/stripe',
623
- },
624
- mockLogger
625
- )
626
-
627
- assert.equal(result, false)
628
- })
629
-
630
- test('should not filter when httpRoute is not provided in meta', () => {
631
- const filters: InspectorFilters = {
632
- httpRoutes: ['/api/*'],
633
- }
634
-
635
- const result = matchesFilters(
636
- filters,
637
- {},
638
- { type: 'queue', name: 'worker' },
639
- mockLogger
640
- )
641
-
642
- assert.equal(result, true) // Does not apply to non-HTTP
643
- })
644
-
645
- test('should match multiple route patterns', () => {
646
- const filters: InspectorFilters = {
647
- httpRoutes: ['/api/*', '/webhooks/*'],
648
- }
649
-
650
- const result = matchesFilters(
651
- filters,
652
- {},
653
- {
654
- type: 'http',
655
- name: 'webhook-route',
656
- httpRoute: '/webhooks/stripe',
657
- },
658
- mockLogger
659
- )
660
-
661
- assert.equal(result, true)
662
- })
663
- })
664
-
665
- describe('HTTP method filtering', () => {
666
- test('should return true when httpMethod matches', () => {
667
- const filters: InspectorFilters = {
668
- httpMethods: ['GET', 'POST'],
669
- }
670
-
671
- const result = matchesFilters(
672
- filters,
673
- {},
674
- {
675
- type: 'http',
676
- name: 'users-route',
677
- httpMethod: 'GET',
678
- },
679
- mockLogger
680
- )
681
-
682
- assert.equal(result, true)
683
- })
684
-
685
- test('should return false when httpMethod does not match', () => {
686
- const filters: InspectorFilters = {
687
- httpMethods: ['GET', 'POST'],
688
- }
689
-
690
- const result = matchesFilters(
691
- filters,
692
- {},
693
- {
694
- type: 'http',
695
- name: 'users-route',
696
- httpMethod: 'DELETE',
697
- },
698
- mockLogger
699
- )
700
-
701
- assert.equal(result, false)
702
- })
703
-
704
- test('should handle case-insensitive method matching', () => {
705
- const filters: InspectorFilters = {
706
- httpMethods: ['GET', 'POST'],
707
- }
708
-
709
- const result = matchesFilters(
710
- filters,
711
- {},
712
- {
713
- type: 'http',
714
- name: 'users-route',
715
- httpMethod: 'get',
716
- },
717
- mockLogger
718
- )
719
-
720
- assert.equal(result, true)
721
- })
722
-
723
- test('should not filter when httpMethod is not provided in meta', () => {
724
- const filters: InspectorFilters = {
725
- httpMethods: ['GET'],
726
- }
727
-
728
- const result = matchesFilters(
729
- filters,
730
- {},
731
- { type: 'queue', name: 'worker' },
732
- mockLogger
733
- )
734
-
735
- assert.equal(result, true) // Does not apply to non-HTTP
736
- })
737
- })
738
-
739
- describe('Combined filtering with new filters', () => {
740
- test('should return true when all filters including new ones pass', () => {
741
- const filters: InspectorFilters = {
742
- tags: ['api'],
743
- wires: ['http'],
744
- httpRoutes: ['/api/*'],
745
- httpMethods: ['GET'],
746
- }
747
-
748
- const result = matchesFilters(
749
- filters,
750
- { tags: ['api'] },
751
- {
752
- type: 'http',
753
- name: 'users-route',
754
- httpRoute: '/api/users',
755
- httpMethod: 'GET',
756
- },
757
- mockLogger
758
- )
759
-
760
- assert.equal(result, true)
761
- })
762
-
763
- test('should return false when httpRoute filter fails', () => {
764
- const filters: InspectorFilters = {
765
- tags: ['api'],
766
- httpRoutes: ['/admin/*'],
767
- }
768
-
769
- const result = matchesFilters(
770
- filters,
771
- { tags: ['api'] },
772
- {
773
- type: 'http',
774
- name: 'users-route',
775
- httpRoute: '/api/users',
776
- },
777
- mockLogger
778
- )
779
-
780
- assert.equal(result, false)
781
- })
782
-
783
- test('should return false when httpMethod filter fails', () => {
784
- const filters: InspectorFilters = {
785
- httpRoutes: ['/api/*'],
786
- httpMethods: ['POST'],
787
- }
788
-
789
- const result = matchesFilters(
790
- filters,
791
- {},
792
- {
793
- type: 'http',
794
- name: 'users-route',
795
- httpRoute: '/api/users',
796
- httpMethod: 'GET',
797
- },
798
- mockLogger
799
- )
800
-
801
- assert.equal(result, false)
802
- })
803
- })
804
- })
805
-
806
- describe('matchesWildcard', () => {
807
- test('should match exact strings', () => {
808
- assert.equal(matchesWildcard('email-worker', 'email-worker'), true)
809
- assert.equal(matchesWildcard('test', 'test'), true)
810
- })
811
-
812
- test('should not match different strings', () => {
813
- assert.equal(matchesWildcard('email-worker', 'notification-worker'), false)
814
- assert.equal(matchesWildcard('test', 'other'), false)
815
- })
816
-
817
- test('should match wildcard prefix', () => {
818
- assert.equal(matchesWildcard('email-worker', 'email-*'), true)
819
- assert.equal(matchesWildcard('email-sender', 'email-*'), true)
820
- assert.equal(matchesWildcard('email', 'email-*'), false) // Needs prefix before *
821
- })
822
-
823
- test('should match wildcard for routes', () => {
824
- assert.equal(matchesWildcard('/api/users', '/api/*'), true)
825
- assert.equal(matchesWildcard('/api/posts', '/api/*'), true)
826
- assert.equal(matchesWildcard('/webhooks/stripe', '/api/*'), false)
827
- })
828
-
829
- test('should handle empty prefix with wildcard', () => {
830
- assert.equal(matchesWildcard('anything', '*'), true)
831
- assert.equal(matchesWildcard('', '*'), true)
832
- })
833
-
834
- test('should handle exact match when no wildcard', () => {
835
- assert.equal(matchesWildcard('test', 'test'), true)
836
- assert.equal(matchesWildcard('test', 'test*'), false) // Has suffix after exact match
837
- })
838
-
839
- test('should handle special characters in prefix', () => {
840
- assert.equal(matchesWildcard('api-v2-users', 'api-v2-*'), true)
841
- assert.equal(matchesWildcard('api.v2.users', 'api.v2.*'), true)
842
- })
843
- })