@esimplicitylabs/katalyst-xspec 0.6.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 (29) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +69 -0
  3. package/bin/katalyst-xspec.cjs +54 -0
  4. package/cli/init.cjs +679 -0
  5. package/cli/stubs.cjs +365 -0
  6. package/cli/upgrade.cjs +1014 -0
  7. package/dist/chunk-ACAXOGKZ.js +1611 -0
  8. package/dist/index.d.ts +881 -0
  9. package/dist/index.js +1091 -0
  10. package/dist/steps/index.d.ts +151 -0
  11. package/dist/steps/index.js +50 -0
  12. package/package.json +80 -0
  13. package/scripts/postinstall.cjs +85 -0
  14. package/skills/katalyst-bdd-architecture/SKILL.md +517 -0
  15. package/skills/katalyst-bdd-architecture/references/adapters.md +310 -0
  16. package/skills/katalyst-bdd-architecture/references/custom-steps.md +360 -0
  17. package/skills/katalyst-bdd-architecture/references/ports.md +256 -0
  18. package/skills/katalyst-bdd-create-test/SKILL.md +366 -0
  19. package/skills/katalyst-bdd-create-test/references/api-patterns.md +371 -0
  20. package/skills/katalyst-bdd-create-test/references/hybrid-patterns.md +420 -0
  21. package/skills/katalyst-bdd-create-test/references/tui-patterns.md +458 -0
  22. package/skills/katalyst-bdd-create-test/references/ui-patterns.md +415 -0
  23. package/skills/katalyst-bdd-quickstart/SKILL.md +292 -0
  24. package/skills/katalyst-bdd-step-reference/SKILL.md +147 -0
  25. package/skills/katalyst-bdd-step-reference/references/api-steps.md +247 -0
  26. package/skills/katalyst-bdd-step-reference/references/shared-steps.md +340 -0
  27. package/skills/katalyst-bdd-step-reference/references/tui-steps.md +483 -0
  28. package/skills/katalyst-bdd-step-reference/references/ui-steps.md +521 -0
  29. package/skills/katalyst-bdd-troubleshooting/SKILL.md +449 -0
@@ -0,0 +1,449 @@
1
+ ---
2
+ name: katalyst-bdd-troubleshooting
3
+ description: Debug and troubleshoot Katalyst BDD tests. Use when tests fail, steps are not recognized, authentication doesn't work, cleanup isn't running, elements can't be found, or you need debugging techniques like screenshots, pausing, and logging. Triggers on test errors, "no tests found", "step not defined", "debug", "test failing".
4
+ ---
5
+
6
+ # Katalyst BDD Troubleshooting Guide
7
+
8
+ This skill helps diagnose and fix common issues with the Katalyst BDD testing framework.
9
+
10
+ ## Quick Diagnosis
11
+
12
+ | Symptom | Likely Cause | Solution |
13
+ |---------|--------------|----------|
14
+ | "No tests found" | Forgot to generate | Run `npm run gen` |
15
+ | Step is undefined | Wrong tag or typo | Check tag matches step availability |
16
+ | Auth fails (401/403) | Bad credentials | Check `.env` variables |
17
+ | Element not found | Selector wrong or timing | Add waits or use debugging |
18
+ | Cleanup not running | Not registered | Add `Given I register cleanup DELETE...` |
19
+ | Variable undefined | Typo or not set | Check variable names match exactly |
20
+
21
+ ## Issue 1: "No Tests Found"
22
+
23
+ **Error:**
24
+ ```
25
+ Error: No tests found
26
+ ```
27
+
28
+ **Cause:** Feature files haven't been converted to Playwright tests.
29
+
30
+ **Solution:**
31
+ ```bash
32
+ # ALWAYS run this after creating/modifying feature files
33
+ npm run gen
34
+
35
+ # Then run tests
36
+ npm test
37
+ ```
38
+
39
+ **Prevention:** Add to your workflow - always run `npm run gen` before `npm test`.
40
+
41
+ ## Issue 2: Step Not Defined
42
+
43
+ **Error:**
44
+ ```
45
+ Step "When I click the button Submit" is not defined
46
+ ```
47
+
48
+ **Possible Causes:**
49
+
50
+ ### 1. Wrong Tag
51
+ Steps are only available with the correct tag:
52
+
53
+ | Step Type | Required Tag |
54
+ |-----------|--------------|
55
+ | API steps | `@api` or `@hybrid` |
56
+ | UI steps | `@ui` or `@hybrid` |
57
+ | TUI steps | `@tui` |
58
+ | Shared steps | Any tag |
59
+
60
+ **Fix:** Add the correct tag to your feature or scenario:
61
+ ```gherkin
62
+ @ui # <-- Required for UI steps
63
+ Feature: Login Page
64
+
65
+ Scenario: Click button
66
+ When I click the button "Submit"
67
+ ```
68
+
69
+ ### 2. Typo in Step
70
+ Steps must match exactly. Check:
71
+ - Quotation marks around strings
72
+ - Exact wording
73
+ - Correct parameter format
74
+
75
+ **Common mistakes:**
76
+ ```gherkin
77
+ # Wrong - missing quotes
78
+ When I click the button Submit
79
+
80
+ # Right
81
+ When I click the button "Submit"
82
+
83
+ # Wrong - wrong step wording
84
+ When I click on button "Submit"
85
+
86
+ # Right
87
+ When I click the button "Submit"
88
+ ```
89
+
90
+ ### 3. Steps Not Registered
91
+ Ensure your `steps.ts` registers the needed steps:
92
+
93
+ ```typescript
94
+ import { test } from './fixtures';
95
+ import { registerAllSteps } from '@esimplicitylabs/katalyst-xspec/steps';
96
+
97
+ registerAllSteps(test); // Registers all step types
98
+
99
+ export { test };
100
+ ```
101
+
102
+ ## Issue 3: Authentication Failures
103
+
104
+ ### API Auth Fails (401)
105
+
106
+ **Check `.env` variables (all required -- no hardcoded defaults):**
107
+ ```bash
108
+ # Required for admin auth
109
+ DEFAULT_ADMIN_USERNAME=admin@example.com
110
+ DEFAULT_ADMIN_PASSWORD=admin123
111
+
112
+ # Required for user auth
113
+ DEFAULT_USER_USERNAME=user@example.com
114
+ DEFAULT_USER_PASSWORD=user123
115
+
116
+ # Auth endpoint path
117
+ API_AUTH_LOGIN_PATH=/auth/login
118
+ ```
119
+
120
+ > **Important:** If these env vars are not set, auth methods will skip silently with a `console.warn`. Check your test output for messages like `apiLoginAsAdmin skipped: DEFAULT_ADMIN_USERNAME and DEFAULT_ADMIN_PASSWORD are not set`.
121
+
122
+ **Debug:** Add logging to see what's being sent:
123
+ ```gherkin
124
+ # Check your variables are loaded
125
+ Given I set variable "debug" to "true"
126
+ Then I log all feature flags
127
+ ```
128
+
129
+ ### UI Auth Fails
130
+
131
+ For `Given I am authenticated in UI as "admin"`:
132
+ - This uses fetch intercept, not actual login
133
+ - Ensure your app accepts the intercepted auth headers
134
+ - Check the auth adapter configuration
135
+
136
+ ### Token Issues
137
+
138
+ ```gherkin
139
+ # Store and reuse token
140
+ When I POST "/auth/login" with JSON body:
141
+ """
142
+ { "email": "user@example.com", "password": "secret" }
143
+ """
144
+ Then the response status should be 200
145
+ And I store the value at "token" as "authToken"
146
+
147
+ # Debug: Print the token
148
+ Then the variable "authToken" should equal "expected-format"
149
+
150
+ # Use the token
151
+ Given I set bearer token from variable "authToken"
152
+ ```
153
+
154
+ ## Issue 4: Element Not Found
155
+
156
+ **Error:**
157
+ ```
158
+ Error: Timed out waiting for element
159
+ ```
160
+
161
+ ### Solution 1: Add Explicit Wait
162
+ ```gherkin
163
+ Given I navigate to "/page"
164
+ Then I wait "2" seconds # Wait for dynamic content
165
+ Then I should see text "Expected"
166
+ ```
167
+
168
+ ### Solution 2: Wait for Page Load
169
+ ```gherkin
170
+ Given I navigate to "/page"
171
+ Then I wait for the page to load
172
+ Then I should see text "Expected"
173
+ ```
174
+
175
+ ### Solution 3: Use Debugging
176
+ ```gherkin
177
+ Given I navigate to "/page"
178
+ When I pause for debugging # Opens Playwright Inspector
179
+ # Now you can inspect the page manually
180
+ ```
181
+
182
+ ### Solution 4: Take Screenshot
183
+ ```gherkin
184
+ Given I navigate to "/page"
185
+ When I save a screenshot as "debug-page"
186
+ # Check the screenshot to see what's visible
187
+ ```
188
+
189
+ ### Solution 5: Print Page Content
190
+ ```gherkin
191
+ Given I navigate to "/page"
192
+ Then I print visible text # See all text on page
193
+ Then I log the current URL # Verify correct page
194
+ ```
195
+
196
+ ### Solution 6: Check Selector
197
+ For CSS selectors:
198
+ ```gherkin
199
+ # Try different selectors
200
+ When I click the element "#submit-btn"
201
+ When I click the element ".submit-button"
202
+ When I click the element "[data-testid='submit']"
203
+ ```
204
+
205
+ For text-based:
206
+ ```gherkin
207
+ # Exact text match
208
+ When I click the button "Submit"
209
+
210
+ # Contains text
211
+ When I "click" the "button" element that contains "Submit"
212
+ ```
213
+
214
+ ## Issue 5: Variable Not Interpolated
215
+
216
+ **Symptom:** `{varName}` appears literally instead of being replaced.
217
+
218
+ ### Check 1: Variable Was Set
219
+ ```gherkin
220
+ # Make sure you set it first
221
+ Given I set variable "userId" to "123"
222
+
223
+ # Or store from response
224
+ And I store the value at "id" as "userId"
225
+
226
+ # Then use it
227
+ When I GET "/users/{userId}"
228
+ ```
229
+
230
+ ### Check 2: Correct Syntax
231
+ ```gherkin
232
+ # Right - curly braces
233
+ When I GET "/users/{userId}"
234
+
235
+ # Wrong - other syntax
236
+ When I GET "/users/$userId"
237
+ When I GET "/users/{{userId}}"
238
+ When I GET "/users/[userId]"
239
+ ```
240
+
241
+ ### Check 3: Variable Name Matches
242
+ Variables are case-sensitive:
243
+ ```gherkin
244
+ Given I set variable "userId" to "123"
245
+
246
+ # Right
247
+ When I GET "/users/{userId}"
248
+
249
+ # Wrong - case mismatch
250
+ When I GET "/users/{UserId}"
251
+ When I GET "/users/{USERID}"
252
+ ```
253
+
254
+ ## Issue 6: Cleanup Not Running
255
+
256
+ ### Check 1: Registration Syntax
257
+ ```gherkin
258
+ # After creating a resource
259
+ When I POST "/users" with JSON body:
260
+ """
261
+ { "email": "test@test.com" }
262
+ """
263
+ Then the response status should be 201
264
+ And I store the value at "id" as "userId"
265
+
266
+ # MUST register cleanup with the ID
267
+ Given I register cleanup DELETE "/users/{userId}"
268
+ ```
269
+
270
+ ### Check 2: Cleanup Not Disabled
271
+ ```gherkin
272
+ # This disables all cleanup for the scenario
273
+ Given I disable cleanup
274
+
275
+ # Remove this line if you want cleanup to run
276
+ ```
277
+
278
+ ### Check 3: API Base URL Set
279
+ Cleanup uses the API base URL:
280
+ ```bash
281
+ # In .env
282
+ API_BASE_URL=http://localhost:3000
283
+ ```
284
+
285
+ ## Issue 7: JSON Body Errors
286
+
287
+ ### Invalid JSON
288
+ ```gherkin
289
+ # Wrong - trailing comma
290
+ When I POST "/users" with JSON body:
291
+ """
292
+ {
293
+ "name": "Test", # <-- trailing comma not allowed
294
+ }
295
+ """
296
+
297
+ # Right
298
+ When I POST "/users" with JSON body:
299
+ """
300
+ {
301
+ "name": "Test"
302
+ }
303
+ """
304
+ ```
305
+
306
+ ### Variable in JSON
307
+ ```gherkin
308
+ # Variables work inside JSON
309
+ Given I generate a UUID and store as "runId"
310
+ When I POST "/users" with JSON body:
311
+ """
312
+ {
313
+ "email": "test-{runId}@example.com"
314
+ }
315
+ """
316
+ ```
317
+
318
+ ## Issue 8: TUI Tests Failing
319
+
320
+ ### tmux Not Installed
321
+ ```bash
322
+ # Install tmux (macOS)
323
+ brew install tmux
324
+
325
+ # Install tmux (Ubuntu)
326
+ sudo apt-get install tmux
327
+ ```
328
+
329
+ ### TUI Not Configured
330
+ In `fixtures.ts`:
331
+ ```typescript
332
+ import { TuiTesterAdapter } from '@esimplicitylabs/katalyst-xspec';
333
+
334
+ export const test = createBddTest({
335
+ createTui: () => new TuiTesterAdapter({
336
+ command: ['node', 'dist/cli.js'], // Your CLI command
337
+ size: { cols: 100, rows: 30 },
338
+ }),
339
+ });
340
+ ```
341
+
342
+ ### Application Not Starting
343
+ ```gherkin
344
+ # Add wait for ready state
345
+ Given I start the TUI application
346
+ When I wait for "Ready" for 10 seconds # Increase timeout
347
+ Then I should see "Menu"
348
+ ```
349
+
350
+ ## Debugging Techniques
351
+
352
+ ### 1. Pause and Inspect
353
+ ```gherkin
354
+ When I pause for debugging
355
+ # Opens Playwright Inspector - click around, inspect elements
356
+ ```
357
+
358
+ ### 2. Screenshots
359
+ ```gherkin
360
+ When I save a screenshot as "before-click"
361
+ When I click the button "Submit"
362
+ When I save a screenshot as "after-click"
363
+ ```
364
+
365
+ ### 3. Full Page Screenshot
366
+ ```gherkin
367
+ When I save a full page screenshot as "entire-page"
368
+ ```
369
+
370
+ ### 4. Console Logging
371
+ ```gherkin
372
+ Then I log the current URL
373
+ Then I log the page title
374
+ Then I print visible text
375
+ Then I log all cookies
376
+ Then I log localStorage
377
+ ```
378
+
379
+ ### 5. Browser Console
380
+ ```gherkin
381
+ Then I print browser console messages
382
+ ```
383
+
384
+ ### 6. Highlight Element
385
+ ```gherkin
386
+ When I highlight element "#my-button"
387
+ When I save a screenshot as "highlighted"
388
+ ```
389
+
390
+ ### 7. Capture HTML
391
+ ```gherkin
392
+ When I capture the page HTML as "pageContent"
393
+ # pageContent variable now has full HTML
394
+ ```
395
+
396
+ ## Running Tests in Debug Mode
397
+
398
+ ```bash
399
+ # Open Playwright Inspector
400
+ npx playwright test --debug
401
+
402
+ # Run with browser visible
403
+ npx playwright test --headed
404
+
405
+ # Slow down execution
406
+ npx playwright test --headed --slow-mo=1000
407
+
408
+ # Interactive UI mode
409
+ npx playwright test --ui
410
+ ```
411
+
412
+ ## Environment Variable Checklist
413
+
414
+ ```bash
415
+ # API Testing
416
+ API_BASE_URL=http://localhost:3000
417
+
418
+ # UI Testing
419
+ FRONTEND_URL=http://localhost:3000
420
+ BASE_URL=http://localhost:3000
421
+ HEADLESS=true
422
+
423
+ # Authentication (required -- no hardcoded defaults)
424
+ DEFAULT_ADMIN_USERNAME=admin@example.com
425
+ DEFAULT_ADMIN_PASSWORD=admin123
426
+ DEFAULT_USER_USERNAME=user@example.com
427
+ DEFAULT_USER_PASSWORD=user123
428
+ API_AUTH_LOGIN_PATH=/auth/login
429
+
430
+ # UI Login Customization (optional)
431
+ # UI_LOGIN_PATH=/login
432
+ # UI_USERNAME_FIELD=Username
433
+ # UI_PASSWORD_FIELD=Password
434
+ # UI_LOGIN_BUTTON=Login
435
+
436
+ # Cleanup Auth (optional -- alternative to login-based auth)
437
+ # CLEANUP_AUTH_TOKEN=your-admin-token
438
+
439
+ # Cleanup Rules (required -- no built-in rules)
440
+ CLEANUP_RULES='[{"varMatch":"user","path":"/api/users/{id}"}]'
441
+ DEBUG=false
442
+ ```
443
+
444
+ ## Getting More Help
445
+
446
+ 1. **Check the docs** - `docs/` folder in the repository
447
+ 2. **Review examples** - `examples/` folder has working tests
448
+ 3. **Enable verbose logging** - Set `DEBUG=true` in `.env`
449
+ 4. **Use Playwright's trace** - `npx playwright test --trace on`