@sun-asterisk/sungen 2.3.1 → 2.4.1

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 (105) hide show
  1. package/README.md +10 -11
  2. package/dist/cli/index.js +1 -1
  3. package/dist/generators/gherkin-parser/index.d.ts +8 -0
  4. package/dist/generators/gherkin-parser/index.d.ts.map +1 -1
  5. package/dist/generators/gherkin-parser/index.js +12 -0
  6. package/dist/generators/gherkin-parser/index.js.map +1 -1
  7. package/dist/generators/test-generator/adapters/playwright/templates/steps/actions/table-action-in-row.hbs +1 -1
  8. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-column-exists.hbs +5 -1
  9. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-match-data.hbs +15 -0
  10. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-exists.hbs +7 -1
  11. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-not-exists.hbs +5 -1
  12. package/dist/generators/test-generator/patterns/index.d.ts.map +1 -1
  13. package/dist/generators/test-generator/patterns/index.js +2 -1
  14. package/dist/generators/test-generator/patterns/index.js.map +1 -1
  15. package/dist/generators/test-generator/patterns/table-patterns.d.ts +12 -0
  16. package/dist/generators/test-generator/patterns/table-patterns.d.ts.map +1 -1
  17. package/dist/generators/test-generator/patterns/table-patterns.js +142 -98
  18. package/dist/generators/test-generator/patterns/table-patterns.js.map +1 -1
  19. package/dist/generators/test-generator/patterns/types.d.ts +2 -0
  20. package/dist/generators/test-generator/patterns/types.d.ts.map +1 -1
  21. package/dist/generators/test-generator/step-mapper.d.ts +13 -0
  22. package/dist/generators/test-generator/step-mapper.d.ts.map +1 -1
  23. package/dist/generators/test-generator/step-mapper.js +80 -0
  24. package/dist/generators/test-generator/step-mapper.js.map +1 -1
  25. package/dist/orchestrator/ai-rules-updater.d.ts.map +1 -1
  26. package/dist/orchestrator/ai-rules-updater.js +8 -6
  27. package/dist/orchestrator/ai-rules-updater.js.map +1 -1
  28. package/dist/orchestrator/project-initializer.d.ts.map +1 -1
  29. package/dist/orchestrator/project-initializer.js +33 -2
  30. package/dist/orchestrator/project-initializer.js.map +1 -1
  31. package/dist/orchestrator/screen-manager.js +1 -1
  32. package/dist/orchestrator/screen-manager.js.map +1 -1
  33. package/dist/orchestrator/templates/ai-instructions/claude-cmd-add-screen.md +5 -5
  34. package/{src/orchestrator/templates/ai-instructions/claude-cmd-make-tc.md → dist/orchestrator/templates/ai-instructions/claude-cmd-create-test.md} +7 -7
  35. package/dist/orchestrator/templates/ai-instructions/claude-cmd-review.md +21 -0
  36. package/dist/orchestrator/templates/ai-instructions/claude-cmd-run-test.md +32 -0
  37. package/dist/orchestrator/templates/ai-instructions/claude-config.md +65 -12
  38. package/dist/orchestrator/templates/ai-instructions/claude-skill-error-mapping.md +128 -52
  39. package/dist/orchestrator/templates/ai-instructions/claude-skill-gherkin-syntax.md +15 -39
  40. package/dist/orchestrator/templates/ai-instructions/claude-skill-selector-fix.md +72 -259
  41. package/dist/orchestrator/templates/ai-instructions/claude-skill-tc-generation.md +57 -205
  42. package/dist/orchestrator/templates/ai-instructions/claude-skill-tc-review.md +104 -0
  43. package/dist/orchestrator/templates/ai-instructions/claude-skill-viewpoint.md +188 -0
  44. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-add-screen.md +4 -4
  45. package/dist/orchestrator/templates/ai-instructions/{copilot-cmd-make-tc.md → copilot-cmd-create-test.md} +8 -8
  46. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-review.md +24 -0
  47. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-run-test.md +35 -0
  48. package/dist/orchestrator/templates/ai-instructions/copilot-config.md +66 -13
  49. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-error-mapping.md +128 -52
  50. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-gherkin-syntax.md +15 -39
  51. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-selector-fix.md +72 -234
  52. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-tc-generation.md +57 -205
  53. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-tc-review.md +104 -0
  54. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-viewpoint.md +188 -0
  55. package/dist/orchestrator/templates/readme.md +85 -22
  56. package/package.json +1 -1
  57. package/src/cli/index.ts +1 -1
  58. package/src/generators/gherkin-parser/index.ts +23 -0
  59. package/src/generators/test-generator/adapters/playwright/templates/steps/actions/table-action-in-row.hbs +1 -1
  60. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-column-exists.hbs +5 -1
  61. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-match-data.hbs +15 -0
  62. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-exists.hbs +7 -1
  63. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-not-exists.hbs +5 -1
  64. package/src/generators/test-generator/patterns/index.ts +2 -1
  65. package/src/generators/test-generator/patterns/table-patterns.ts +155 -111
  66. package/src/generators/test-generator/patterns/types.ts +2 -0
  67. package/src/generators/test-generator/step-mapper.ts +87 -1
  68. package/src/orchestrator/ai-rules-updater.ts +8 -6
  69. package/src/orchestrator/project-initializer.ts +38 -2
  70. package/src/orchestrator/screen-manager.ts +1 -1
  71. package/src/orchestrator/templates/ai-instructions/claude-cmd-add-screen.md +5 -5
  72. package/{dist/orchestrator/templates/ai-instructions/claude-cmd-make-tc.md → src/orchestrator/templates/ai-instructions/claude-cmd-create-test.md} +7 -7
  73. package/src/orchestrator/templates/ai-instructions/claude-cmd-review.md +21 -0
  74. package/src/orchestrator/templates/ai-instructions/claude-cmd-run-test.md +32 -0
  75. package/src/orchestrator/templates/ai-instructions/claude-config.md +65 -12
  76. package/src/orchestrator/templates/ai-instructions/claude-skill-error-mapping.md +128 -52
  77. package/src/orchestrator/templates/ai-instructions/claude-skill-gherkin-syntax.md +15 -39
  78. package/src/orchestrator/templates/ai-instructions/claude-skill-selector-fix.md +72 -259
  79. package/src/orchestrator/templates/ai-instructions/claude-skill-tc-generation.md +57 -205
  80. package/src/orchestrator/templates/ai-instructions/claude-skill-tc-review.md +104 -0
  81. package/src/orchestrator/templates/ai-instructions/claude-skill-viewpoint.md +188 -0
  82. package/src/orchestrator/templates/ai-instructions/copilot-cmd-add-screen.md +4 -4
  83. package/src/orchestrator/templates/ai-instructions/{copilot-cmd-make-tc.md → copilot-cmd-create-test.md} +8 -8
  84. package/src/orchestrator/templates/ai-instructions/copilot-cmd-review.md +24 -0
  85. package/src/orchestrator/templates/ai-instructions/copilot-cmd-run-test.md +35 -0
  86. package/src/orchestrator/templates/ai-instructions/copilot-config.md +66 -13
  87. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-error-mapping.md +128 -52
  88. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-gherkin-syntax.md +15 -39
  89. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-selector-fix.md +72 -234
  90. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-tc-generation.md +57 -205
  91. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-tc-review.md +104 -0
  92. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-viewpoint.md +188 -0
  93. package/src/orchestrator/templates/readme.md +85 -22
  94. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-cell-by-filter.hbs +0 -2
  95. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-cell-by-index.hbs +0 -2
  96. package/dist/orchestrator/templates/ai-instructions/claude-cmd-make-test.md +0 -29
  97. package/dist/orchestrator/templates/ai-instructions/claude-skill-gherkin-review.md +0 -228
  98. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-make-test.md +0 -32
  99. package/dist/orchestrator/templates/ai-instructions/github-skill-sungen-gherkin-review.md +0 -228
  100. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-cell-by-filter.hbs +0 -2
  101. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-cell-by-index.hbs +0 -2
  102. package/src/orchestrator/templates/ai-instructions/claude-cmd-make-test.md +0 -29
  103. package/src/orchestrator/templates/ai-instructions/claude-skill-gherkin-review.md +0 -228
  104. package/src/orchestrator/templates/ai-instructions/copilot-cmd-make-test.md +0 -32
  105. package/src/orchestrator/templates/ai-instructions/github-skill-sungen-gherkin-review.md +0 -228
@@ -0,0 +1,32 @@
1
+ ---
2
+ name: run-test
3
+ description: 'Compile and run Playwright tests — auto-fixes selectors on failure'
4
+ argument-hint: [screen-name]
5
+ allowed-tools: Read, Grep, Bash, Glob, Edit, AskUserQuestion
6
+ ---
7
+
8
+ ## Role
9
+
10
+ You are a **Senior Developer**. Use `sungen-selector-fix`, `sungen-selector-keys`, and `sungen-error-mapping` skills.
11
+
12
+ ## Parameters
13
+
14
+ Parse **screen** from `$ARGUMENTS`. If missing, ask the user.
15
+
16
+ ## Phase 1: Compile & Run (no MCP)
17
+
18
+ 1. Verify `qa/screens/<screen>/` has `.feature` + `test-data.yaml`
19
+ 2. Ensure `selectors.yaml` has page selector. If missing, ask user for URL path
20
+ 3. `sungen generate --screen <screen>`
21
+ 4. `npx playwright test specs/generated/<screen>/*.spec.ts --reporter=line`
22
+ 5. If all pass → done
23
+
24
+ ## Phase 2: Targeted Fix (only if failures)
25
+
26
+ 6. Parse failures → group by root cause
27
+ 7. Navigate to page ONCE via MCP → ONE `browser_snapshot`
28
+ 8. Fix broken selectors per `sungen-selector-fix` skill
29
+ 9. Recompile → re-run only failing tests
30
+ 10. Repeat up to 3 attempts
31
+ 11. Final full run for regression check
32
+ 12. Still failing → ask user
@@ -3,8 +3,40 @@
3
3
  You generate 3 files for sungen — a Gherkin compiler that produces Playwright tests.
4
4
  **You do NOT write Playwright code.** You only write `.feature`, `selectors.yaml`, and `test-data.yaml`.
5
5
 
6
- For Gherkin syntax, selector types, and YAML rules, the `sungen-gherkin-syntax` skill is auto-loaded when needed.
7
- For error diagnosis, the `sungen-error-mapping` skill is auto-loaded when needed.
6
+ ## Skills (auto-loaded when needed)
7
+
8
+ | Skill | Purpose |
9
+ |---|---|
10
+ | `sungen-gherkin-syntax` | All 70+ step patterns, selector types, YAML key rules, tags, element types |
11
+ | `sungen-error-mapping` | Playwright & sungen error → fix mapping |
12
+ | `sungen-tc-generation` | Test case generation strategy, output format |
13
+ | `sungen-tc-review` | Review scoring, quality rules, checklist |
14
+ | `sungen-viewpoint` | 7 UI patterns x 4 viewpoints — coverage checklists |
15
+ | `sungen-selector-keys` | YAML key generation from `[Reference]` names, suffixes, lookup priority |
16
+ | `sungen-selector-fix` | Selector generation from live page, auto-fix strategy |
17
+
18
+ ## Workflow (4 AI commands)
19
+
20
+ | Command | What it does |
21
+ |---|---|
22
+ | `/sungen:add-screen <name> <path>` | Scaffold `qa/screens/<name>/` directories |
23
+ | `/sungen:create-test <name>` | Generate `.feature` + `test-data.yaml` (no selectors) |
24
+ | `/sungen:review <name>` | Score syntax, coverage, viewpoint quality (60% threshold) |
25
+ | `/sungen:run-test <name>` | Generate `selectors.yaml` from live page, compile, run, auto-fix |
26
+
27
+ **Order:** add-screen → create-test → review → run-test.
28
+
29
+ ## File Structure
30
+
31
+ ```
32
+ qa/screens/<screen-name>/
33
+ ├── features/<screen>.feature # Gherkin scenarios
34
+ ├── selectors/<screen>.yaml # Element locators (generated during run-test)
35
+ ├── test-data/<screen>.yaml # Test data variables
36
+ └── requirements/
37
+ ├── spec.md # Screen specification (primary source)
38
+ └── ui/ # Screenshots, mockups
39
+ ```
8
40
 
9
41
  ## Complete Example
10
42
 
@@ -15,13 +47,13 @@ Given a login page, here are the 3 files you generate:
15
47
  @no-auth
16
48
  Feature: Login Screen
17
49
 
18
- Scenario: Successful login
50
+ Scenario: VP-LOGIC-001 Successful login
19
51
  Given User is on [login] page
20
52
  When User fill [Email] field with {{email}}
21
53
  And User fill [Password] field with {{password}}
22
54
  And User click [Submit] button
23
55
  Then User see [Welcome] heading with {{welcome_text}}
24
- And User see [Dashboard] link is visible
56
+ And User see [Dashboard] link
25
57
  ```
26
58
 
27
59
  **qa/screens/login/selectors/login.yaml**
@@ -61,6 +93,16 @@ password: 'password123'
61
93
  welcome_text: 'Welcome back'
62
94
  ```
63
95
 
96
+ ## Critical Gherkin Rules (quick reference)
97
+
98
+ 1. **NEVER write `is visible`** — `User see [T] type` already asserts visibility. Only use `is hidden` to assert absence.
99
+ 2. **Use `@no-auth` for pre-login pages** (login, register, forgot-password). Use `@auth:role` for authenticated pages.
100
+ 3. **Scenario names use VP prefix** — `VP-UI-001`, `VP-VAL-001`, `VP-LOGIC-001`, `VP-SEC-001`.
101
+ 4. **Values use `{{snake_case}}`** — never hardcode data in `.feature`. All values go in `test-data.yaml`.
102
+ 5. **Selectors are deferred** — `selectors.yaml` is generated during `/sungen-run-test` from the live page, NOT during `/sungen-create-test`.
103
+ 6. **Every `{{variable}}` must exist in `test-data.yaml`** — missing variables cause compile failures.
104
+ 7. **Assertion type is determined by element type** — input types (`field`, `textarea`, `search`, `dropdown`, `slider`, `date-picker`) → `toHaveValue()`. Everything else → `toHaveText()`. Wrong type = wrong assertion = test failure.
105
+
64
106
  ## Using Playwright MCP to explore pages
65
107
 
66
108
  When exploring a page to generate test files:
@@ -69,23 +111,34 @@ When exploring a page to generate test files:
69
111
  3. Use `browser_snapshot` to see all elements
70
112
  4. Generate the 3 files from the snapshot
71
113
 
72
- **NEVER use `browser_run_code`.** It fails with `require is not defined`.
73
- Only use: `browser_navigate`, `browser_snapshot`, `browser_click`, `browser_fill_form`, `browser_evaluate`.
114
+ ### Allowed MCP tools
115
+
116
+ | Tool | Use for |
117
+ |---|---|
118
+ | `browser_navigate` | Open pages |
119
+ | `browser_snapshot` | Capture all accessible elements |
120
+ | `browser_click` | Interact with elements (open dialogs, dropdowns) |
121
+ | `browser_fill_form` | Fill form fields |
122
+ | `browser_evaluate` | **Read-only DOM queries only** (e.g., detect `data-testid` attributes) |
123
+
124
+ **NEVER use `browser_run_code`** — fails with `require is not defined`.
125
+
126
+ ### Authentication via MCP
74
127
 
75
- To browse authenticated pages via MCP:
76
128
  1. `browser_navigate` to `baseURL`
77
129
  2. If redirected to login, ask the user to log in manually:
78
130
  > "This page requires login. Please log in using the browser. Confirm when you're done."
79
131
  3. Once confirmed, `browser_navigate` to the target page and take `browser_snapshot`
80
132
 
81
133
  **Never use `sungen makeauth`.** Always let the user log in manually via the MCP browser.
82
- **NEVER use `browser_evaluate` to inject cookies or localStorage.** It causes size limit issues and server 500 errors.
134
+ **NEVER use `browser_evaluate` to inject cookies or localStorage** causes size limit issues and server 500 errors. Use `browser_evaluate` ONLY for read-only DOM queries.
83
135
  **Minimize navigations** — take one snapshot per page, do not navigate repeatedly.
84
136
 
85
- ## Commands
137
+ ## CLI Commands
86
138
 
87
139
  ```bash
88
- sungen add --screen <name> --path <url-path> # Create screen
89
- sungen generate --screen <name> # Compile to .spec.ts
90
- sungen generate --all # Compile all
140
+ sungen add --screen <name> --path <url-path> # Scaffold screen directories
141
+ sungen add --screen <name> --path <path> --feature <name> # Scaffold with sub-feature
142
+ sungen generate --screen <name> # Compile .feature → .spec.ts
143
+ sungen generate --all # Compile all screens
91
144
  ```
@@ -1,69 +1,145 @@
1
1
  ---
2
2
  name: sungen-error-mapping
3
- description: 'Playwright and Sungen error to fix mapping. Auto-loaded when running or debugging tests.'
3
+ description: 'Error diagnosis and fix strategy — systematic debugging flow, error patterns, fix priorities. Auto-loaded during run-test.'
4
4
  user-invocable: false
5
5
  ---
6
6
 
7
- ## Playwright Errors Fix
7
+ ## Diagnosis Flow (before fixing anything)
8
8
 
9
- | Error | Fix |
10
- |---|---|
11
- | strict mode violation | add `nth`, `exact: true`, or specific `name` in selectors.yaml |
12
- | Element is not an input | change `type` or `value` in selectors.yaml |
13
- | Timeout waiting for selector | fix `type`/`value`/`name` to match element in selectors.yaml |
14
- | toBeVisible Timeout | verify accessible name or use `testid` in selectors.yaml |
15
- | toHaveText mismatch | fix expected text in `test-data.yaml` — OR if element is an input (field/textarea/search/dropdown), change Gherkin type so compiler uses `toHaveValue` instead |
16
- | toHaveValue mismatch | fix expected value in `test-data.yaml` — this is for input elements (field, textarea, search, dropdown, slider, date-picker) |
17
- | toContainText mismatch | fix expected partial text in `test-data.yaml` |
18
- | Navigation failed | fix page `value` path in selectors.yaml |
19
- | not a select | set `variant: 'custom'` in selectors.yaml |
20
- | Frame not found | fix `frame` value in selectors.yaml |
21
- | dialog was dismissed | alert step is AFTER the trigger — move `click [OK] alert` BEFORE the button click that opens the dialog |
22
- | page.once('dialog') never fired | no browser dialog appeared — check if the action actually triggers a `window.alert/confirm/prompt`, not a CSS modal |
23
-
24
- ### Assertion type mismatch (toHaveText vs toHaveValue)
25
-
26
- Sungen picks the assertion based on element type:
27
- - **Input types** (`field`, `textarea`, `search`, `dropdown`, `slider`, `date-picker`) → `toHaveValue()`
28
- - **Text types** (everything else: `message`, `header`, `label`, `row`, etc.) → `toHaveText()`
29
- - **Partial match** (uses `contains` keyword) → `toContainText()`
30
-
31
- If you see `toHaveText` failing on an input element, the Gherkin step has the wrong target type. Fix: change the target type in the `.feature` file (e.g., `see [Email] message with {{v}}` → `see [Email] field with {{v}}`).
32
-
33
- ## Auth Errors → Fix
9
+ **Step 1: Read the error** — extract: error type, element name, expected vs actual, file:line.
34
10
 
35
- | Symptom | Fix |
36
- |---|---|
37
- | Tests redirect to login page | `specs/.auth/<role>.json` missing or expired. Tell user: `sungen makeauth <role> --url <baseURL>` |
38
- | `storageState` file not found | Run `sungen makeauth <role> --url <baseURL>` to create auth state |
39
- | Most tests timeout on first step | Auth expired — re-run `sungen makeauth <role> --url <baseURL>` |
40
- | Page shows home/login instead of target | SPA routing + expired auth. Re-run `sungen makeauth`, add `wait for` step after navigation |
11
+ **Step 2: Read error context** — check `test-results/` for the snapshot at failure time. This shows the exact page state when the test failed — more reliable than re-navigating with MCP.
12
+
13
+ **Step 3: Compare** match the failing selector against the snapshot. Ask:
14
+ - Does the element exist on the page?
15
+ - Does the accessible name match exactly?
16
+ - Are there multiple matches (strict mode)?
17
+ - Is the element inside an iframe or dialog?
18
+ - Is the page in the expected state (correct URL, loaded)?
19
+
20
+ Then choose the fix from the patterns below.
21
+
22
+ ---
23
+
24
+ ## Fix Priority (try in order)
25
+
26
+ 1. **Auth issue** — page redirected to login? Fix auth first, everything else is noise
27
+ 2. **Element not found** — wrong name/type/value in selectors.yaml. Re-snapshot, copy exact name
28
+ 3. **Multiple matches** — add `nth`, `exact: true`, or `scope` to narrow down
29
+ 4. **Wrong assertion** — `toHaveText` vs `toHaveValue` mismatch, wrong expected data
30
+ 5. **Timing** — SPA not loaded, async content. Add `wait for` step in .feature
31
+
32
+ ---
33
+
34
+ ## Playwright Errors
35
+
36
+ ### Selector errors → fix in `selectors.yaml`
37
+
38
+ | Error | Diagnosis | Fix |
39
+ |---|---|---|
40
+ | strict mode violation | Multiple elements match | Add `nth: 0`, `exact: true`, or more specific `name` |
41
+ | Timeout / not found | Element doesn't exist or name wrong | Re-snapshot → copy exact accessible name. Check iframe/dialog scope |
42
+ | Element is not an input | Wrong element type targeted | Change `type` or `value` to match actual element |
43
+ | not a select | Custom dropdown, not native `<select>` | Set `variant: 'custom'` |
44
+ | Frame not found | iframe selector wrong or doesn't exist | Fix `frame` value, verify iframe in snapshot |
45
+
46
+ ### Assertion errors → fix in `test-data.yaml` or `.feature`
47
+
48
+ | Error | Diagnosis | Fix |
49
+ |---|---|---|
50
+ | toHaveText mismatch | Expected text differs from actual | Fix value in test-data. If element is input type → change Gherkin type to `field`/`textarea` (triggers `toHaveValue` instead) |
51
+ | toHaveValue mismatch | Expected value differs from actual | Fix value in test-data |
52
+ | toContainText mismatch | Partial text not found | Fix expected partial text in test-data |
53
+ | toBeVisible timeout | Element exists but hidden, or name wrong | Check: is element conditionally visible? Wrong name? Inside dialog? |
54
+ | toHaveCount mismatch | Row count differs | Fix expected count in test-data. Verify: is table loaded? Filtered? |
41
55
 
42
- **Never run `sungen makeauth` yourself.** Always tell the user to run it manually.
56
+ ### Assertion type rule
43
57
 
44
- ## Performance Errors Fix (specs/base.ts)
58
+ Sungen picks assertion based on element type:
59
+ - **Input** (`field`, `textarea`, `search`, `dropdown`, `slider`) → `toHaveValue()`
60
+ - **Text** (everything else: `message`, `heading`, `label`, `row`) → `toHaveText()`
61
+ - **Partial** (`contains` keyword) → `toContainText()`
45
62
 
46
- All generated `.spec.ts` files import from `specs/base.ts`. This shared file handles context caching, navigation skip, and overlay cleanup.
63
+ If `toHaveText` fails on an input the Gherkin step has wrong target type. Fix: change type in `.feature`.
47
64
 
48
- | Symptom | Fix in `specs/base.ts` |
65
+ ---
66
+
67
+ ## Table-Specific Errors
68
+
69
+ | Error | Diagnosis | Fix |
70
+ |---|---|---|
71
+ | `tableRow is not defined` | Column assertion without preceding row scope step | Add `User see [Ref] row in [Table] table with {{v}}` before `User see [Col] column with {{v}}` |
72
+ | `toHaveText` on cell fails (with columns) | Wrong column index in `columns` config | Re-count columns in snapshot (0-indexed). Fix `index` in selectors.yaml |
73
+ | `toBeVisible` on cell fails (no columns) | `filter({ hasText })` didn't match | Check exact cell text in snapshot. Fix value in test-data |
74
+ | Row filter matches 0 rows | Filter text doesn't match any row content | Re-snapshot → find actual row text. Fix filter value in test-data |
75
+ | Row filter matches multiple rows | Filter text is too generic (matches multiple rows) | Use more specific filter text (unique identifier like email, ID) |
76
+ | Table not found | Wrong table name or table not rendered | Re-snapshot → copy exact table accessible name |
77
+
78
+ ---
79
+
80
+ ## Auth Errors
81
+
82
+ | Symptom | Fix |
49
83
  |---|---|
50
- | Server returns 429 (rate limited) | Context caching broken check `contextCache` Map reuses sessions per `storageState` |
51
- | Tests slow even with `--workers=1` | Navigation skip not working check `goto` patch compares `currentPath === url` |
52
- | Previous test's modal blocks next test | Overlay cleanup insufficient improve Escape/click dismiss logic |
53
- | All tests fail on first navigation | `page.url()` is `about:blank` check try/catch in goto patch |
54
- | Multiple session invalidation errors | Too many contexts created — ensure `contextCache.get(cacheKey)` returns existing context |
84
+ | Redirect to login page | Auth expired. Ask user to log in manually via MCP browser |
85
+ | `storageState` file not found | Ask user to log in manually via MCP browser, then save storage state |
86
+ | Most tests timeout on first step | Auth expiredask user to re-authenticate via MCP browser |
87
+ | Page shows home instead of target | SPA + expired auth. Re-authenticate + add `wait for` step |
55
88
 
56
- **Rules:**
57
- - `base.ts` changes affect ALL tests — edit carefully
58
- - Small project-specific tweaks are OK (e.g., custom overlay dismiss, timeout tuning, extra wait logic)
59
- - Do NOT move individual selector/data fixes into `base.ts` — those belong in `selectors.yaml` / `test-data.yaml`
60
- - If unsure whether a fix belongs in `base.ts` or selectors, ask the user
89
+ **Never use `sungen makeauth`.** Always let the user log in manually via the MCP browser.
61
90
 
62
- ## Sungen Errors → Fix
91
+ ---
92
+
93
+ ## Sungen Compile Errors
63
94
 
64
95
  | Error | Fix |
65
96
  |---|---|
66
- | Unknown step pattern | rewrite `.feature` step to match supported pattern |
67
- | Missing selector | add key to `selectors.yaml` |
68
- | Missing variable | add key to `test-data.yaml` |
69
- | Invalid selector type | use: role/testid/placeholder/label/text/locator/page/upload/frame |
97
+ | Unknown step pattern | Rewrite step to match `sungen-gherkin-syntax` patterns |
98
+ | Missing selector | Add key to `selectors.yaml` |
99
+ | Missing variable | Add key to `test-data.yaml` |
100
+ | Invalid selector type | Use: role/testid/placeholder/label/text/locator/page/upload/frame |
101
+
102
+ ---
103
+
104
+ ## Performance & Infrastructure Errors → Fix in `specs/base.ts`
105
+
106
+ All generated `.spec.ts` import from `specs/base.ts` — shared context caching, navigation, overlay cleanup. AI **can and should** tune `base.ts` to match the project.
107
+
108
+ | Symptom | Root cause | Fix |
109
+ |---|---|---|
110
+ | Server 429 (rate limited) | Too many browser contexts | Fix `contextCache` to reuse sessions per `storageState` |
111
+ | Tests slow with `--workers=1` | Redundant navigation | Fix goto patch: skip if `currentPath === url` |
112
+ | Previous test's modal blocks next | Overlay not cleaned up | Add/improve Escape + backdrop click in cleanup hook |
113
+ | All tests fail on first navigation | `page.url()` is `about:blank` | Add try/catch in goto patch |
114
+ | Flaky timeouts on SPA pages | Default timeout too short for app | Increase `actionTimeout` / `navigationTimeout` |
115
+ | Tests pass individually but fail in batch | Shared state leaking between tests | Isolate context per test or reset state in `beforeEach` |
116
+
117
+ ### What AI CAN fix in `base.ts`
118
+
119
+ - Timeout tuning (increase for slow APIs, decrease for fast apps)
120
+ - Custom overlay/modal dismiss logic (project has unique close patterns)
121
+ - Navigation wait strategy (`networkidle` vs `domcontentloaded` vs custom)
122
+ - Context caching strategy (per-role, per-session)
123
+ - Cookie/localStorage cleanup between tests
124
+
125
+ ### What AI should NOT move into `base.ts`
126
+
127
+ - Individual selector fixes → belong in `selectors.yaml`
128
+ - Test data values → belong in `test-data.yaml`
129
+ - Single-test workarounds → belong in the `.spec.ts` directly
130
+
131
+ ---
132
+
133
+ ## Smart Fix Strategy
134
+
135
+ ### When multiple tests fail on the same element
136
+ Fix the **root cause once** — don't fix each test individually. Group by selector key, fix selectors.yaml, recompile, re-run batch.
137
+
138
+ ### When you're unsure about the fix
139
+ **Re-snapshot** — `browser_navigate` to the failing page, take `browser_snapshot`, compare the live state against what the test expects. This is faster than guessing.
140
+
141
+ ### When the fix might break other tests
142
+ After fixing selectors.yaml, run ALL tests (not just the failing one) to catch regressions from renamed/changed selectors.
143
+
144
+ ### When nothing works after 3 attempts
145
+ Ask the user. The issue might be: dynamic content, race condition, environment-specific state, or a real application bug.
@@ -33,7 +33,6 @@ AND → inherits from preceding keyword
33
33
  User is on [T] page # navigate to page
34
34
  User is on [T] page with {{v}} # navigate with data (e.g., detail page with ID)
35
35
  User is on [T] dialog # enter dialog scope
36
- User is logged in | is not logged in # auth state
37
36
  ```
38
37
 
39
38
  ### Form
@@ -51,7 +50,7 @@ User check [T] radio # select radio
51
50
  User uncheck [T] checkbox # uncheck
52
51
  User uncheck [T] toggle # toggle off
53
52
  User select [T] dropdown with {{v}} # select option
54
- User upload [T] uploader with {{f}} # file upload
53
+ User fill [T] uploader with {{f}} # file upload
55
54
  ```
56
55
 
57
56
  ### Interaction
@@ -155,29 +154,23 @@ User see [T] page # URL assertion
155
154
  ### Table
156
155
 
157
156
  ```
158
- User see [Col] column in [Table] table # column exists (parent scoping)
159
- User see [Table] table row with {{f}} # row exists
160
- User see [Table] table has no row with {{f}} # row not exists
161
- User see [Table] table with {{count}} rows # row count
162
- User see [Table] table is empty # empty table
163
- User see [Table] table row with {{f}} has [Col] with {{v}} # cell by filter
164
- User see [Table] table row 1 [Col] cell with {{v}} # cell by index
165
- User click [Act] in [Table] table row with {{f}} # action in row
157
+ User see [Col] column in [Table] table # column exists
158
+ User see [Ref] row in [Table] table with {{v}} # row exists (enters row scope)
159
+ User see [Ref] row in [Table] table with {{v}} is hidden # row hidden
160
+ User see [Table] table with {{count}} # row count
161
+ User see [Table] table is empty # empty table
162
+ User see [Col] column with {{v}} # cell value (row scoped)
163
+ User click [Act] button in [Table] table with {{v}} # action in row
164
+ User see [Table] table match data: # exact table match (inline DataTable)
165
+ | Header1 | Header2 |
166
+ | {{value1}} | {{value2}} |
166
167
  ```
167
168
 
168
- ### Parent Scoping (disambiguation)
169
+ **Priority**: Use row scope patterns for single-row verification + actions. Use `table match data` only when verifying multiple rows at once.
169
170
 
170
- ```
171
- User click [Submit] button in [User Info] form # button inside specific form
172
- User fill [Email] field in [Registration] form with {{v}} # field inside specific form
173
- User see [Total] text in [Summary] section with {{v}} # text inside specific section
174
- User click [Delete] button in [Active Users] table # button inside specific table
175
- ```
171
+ Row scope: `see [Ref] row in [Table] table with {{v}}` defines `tableRow`. Subsequent `see [Col] column with {{v}}` checks the cell in that row. With `columns` config → exact `nth(index)`, without → `filter({ hasText })`.
176
172
 
177
- - **Optional**only use when page has 2+ similar UI blocks
178
- - **Valid parent types**: `table`, `list`, `section`, `dialog`, `form`
179
- - **Max 2 levels**: `[Target] in [Parent]`. **NEVER** nest 3 levels: `[A] in [B] in [C]`
180
- - Parent resolves from selectors YAML first, falls back to auto-infer `getByRole(parentType, { name })`
173
+ Table match data: `see [Table] table match data:` followed by a Cucumber DataTable. First row = headers, remaining rows = expected data. Uses **filter-based matching** — verifies rows containing expected values exist, resilient to data changes, extra rows, and row reordering. Use `{{variable}}` for cell values.
181
174
 
182
175
  ### States
183
176
 
@@ -196,24 +189,7 @@ User click [Delete] button in [Active Users] table # button inside specifi
196
189
 
197
190
  ### Auto-infer (no YAML entry needed)
198
191
 
199
- | Gherkin | Playwright locator |
200
- |---|---|
201
- | `[Submit] button` | `getByRole('button', { name: 'Submit' })` |
202
- | `[Home] link` | `getByRole('link', { name: 'Home' })` |
203
- | `[Welcome] heading` / `header` | `getByRole('heading', { name: 'Welcome' })` |
204
- | `[Email] field` | `getByPlaceholder('Email')` |
205
- | `[Success] text` / `message` / `label` | `getByText('Success')` |
206
- | `[Terms] checkbox` | `getByRole('checkbox', { name: 'Terms' })` |
207
- | `[Male] radio` | `getByRole('radio', { name: 'Male' })` |
208
- | `[Global] search` | `getByRole('searchbox', { name: 'Global' })` |
209
- | `[Vietnam] option` | `getByRole('option', { name: 'Vietnam' })` |
210
- | `[Price] slider` | `getByRole('slider', { name: 'Price' })` |
211
- | `[Notification] toggle` | `getByRole('switch', { name: 'Notification' })` |
212
- | `[Profile] tab` | `getByRole('tab', { name: 'Profile' })` |
213
- | `[Orders] table` | `getByRole('table', { name: 'Orders' })` |
214
- | `[Products] list` | `getByRole('list', { name: 'Products' })` |
215
- | `[Name] column` | `getByRole('columnheader', { name: 'Name' })` |
216
- | `[Confirm] dialog` / `modal` / `drawer` | `getByRole('dialog', { name: 'Confirm' })` |
192
+ Most elements auto-infer from `[Label] type` → `getByRole(type, { name: 'Label' })`. Only add YAML when the accessible name differs, needs `nth`, or needs `testid`. Full auto-infer table → see `sungen-selector-keys` skill.
217
193
 
218
194
  ## YAML Keys
219
195