@sun-asterisk/sungen 2.0.3 → 2.1.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 (86) hide show
  1. package/README.md +2 -2
  2. package/dist/cli/commands/init.d.ts.map +1 -1
  3. package/dist/cli/commands/init.js +3 -2
  4. package/dist/cli/commands/init.js.map +1 -1
  5. package/dist/cli/index.js +1 -1
  6. package/dist/generators/test-generator/adapters/adapter-interface.d.ts +6 -1
  7. package/dist/generators/test-generator/adapters/adapter-interface.d.ts.map +1 -1
  8. package/dist/generators/test-generator/adapters/playwright/templates/scenario.hbs +0 -4
  9. package/dist/generators/test-generator/adapters/playwright/templates/steps/actions/drag-action.hbs +1 -0
  10. package/dist/generators/test-generator/adapters/playwright/templates/steps/actions/expand-action.hbs +11 -0
  11. package/dist/generators/test-generator/adapters/playwright/templates/steps/actions/toggle-action.hbs +1 -0
  12. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/loading-assertion.hbs +2 -0
  13. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/selected-assertion.hbs +2 -0
  14. package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/sorted-assertion.hbs +2 -0
  15. package/dist/generators/test-generator/adapters/playwright/templates/test-file.hbs +25 -0
  16. package/dist/generators/test-generator/code-generator.d.ts.map +1 -1
  17. package/dist/generators/test-generator/code-generator.js +41 -3
  18. package/dist/generators/test-generator/code-generator.js.map +1 -1
  19. package/dist/generators/test-generator/patterns/assertion-patterns.d.ts.map +1 -1
  20. package/dist/generators/test-generator/patterns/assertion-patterns.js +58 -6
  21. package/dist/generators/test-generator/patterns/assertion-patterns.js.map +1 -1
  22. package/dist/generators/test-generator/patterns/form-patterns.js +3 -3
  23. package/dist/generators/test-generator/patterns/form-patterns.js.map +1 -1
  24. package/dist/generators/test-generator/patterns/interaction-patterns.d.ts.map +1 -1
  25. package/dist/generators/test-generator/patterns/interaction-patterns.js +86 -1
  26. package/dist/generators/test-generator/patterns/interaction-patterns.js.map +1 -1
  27. package/dist/generators/test-generator/template-engine.d.ts +6 -0
  28. package/dist/generators/test-generator/template-engine.d.ts.map +1 -1
  29. package/dist/generators/test-generator/template-engine.js +1 -0
  30. package/dist/generators/test-generator/template-engine.js.map +1 -1
  31. package/dist/orchestrator/project-initializer.d.ts +3 -6
  32. package/dist/orchestrator/project-initializer.d.ts.map +1 -1
  33. package/dist/orchestrator/project-initializer.js +62 -58
  34. package/dist/orchestrator/project-initializer.js.map +1 -1
  35. package/dist/orchestrator/templates/ai-instructions/claude-cmd-add-screen.md +42 -0
  36. package/dist/orchestrator/templates/ai-instructions/claude-cmd-make-tc.md +60 -0
  37. package/dist/orchestrator/templates/ai-instructions/claude-cmd-make-test.md +59 -0
  38. package/dist/orchestrator/templates/ai-instructions/claude-config.md +90 -0
  39. package/dist/orchestrator/templates/ai-instructions/claude-skill-error-mapping.md +27 -0
  40. package/dist/orchestrator/templates/ai-instructions/claude-skill-gherkin-syntax.md +127 -0
  41. package/dist/orchestrator/templates/ai-instructions/claude-skill-selector-keys.md +94 -0
  42. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-add-screen.md +41 -0
  43. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-make-tc.md +59 -0
  44. package/dist/orchestrator/templates/ai-instructions/copilot-cmd-make-test.md +58 -0
  45. package/dist/orchestrator/templates/ai-instructions/copilot-config.md +90 -0
  46. package/dist/orchestrator/templates/ai-instructions/copilot-skill-error-mapping.md +27 -0
  47. package/dist/orchestrator/templates/ai-instructions/copilot-skill-gherkin-syntax.md +127 -0
  48. package/dist/orchestrator/templates/ai-instructions/copilot-skill-selector-keys.md +94 -0
  49. package/dist/orchestrator/templates/readme.md +42 -38
  50. package/docs/gherkin standards/gherkin-core-standard.md +141 -90
  51. package/docs/gherkin standards/gherkin-core-standard.vi.md +264 -54
  52. package/package.json +2 -2
  53. package/src/cli/commands/init.ts +3 -2
  54. package/src/cli/index.ts +1 -1
  55. package/src/generators/test-generator/adapters/adapter-interface.ts +7 -1
  56. package/src/generators/test-generator/adapters/playwright/templates/scenario.hbs +0 -4
  57. package/src/generators/test-generator/adapters/playwright/templates/steps/actions/drag-action.hbs +1 -0
  58. package/src/generators/test-generator/adapters/playwright/templates/steps/actions/expand-action.hbs +11 -0
  59. package/src/generators/test-generator/adapters/playwright/templates/steps/actions/toggle-action.hbs +1 -0
  60. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/loading-assertion.hbs +2 -0
  61. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/selected-assertion.hbs +2 -0
  62. package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/sorted-assertion.hbs +2 -0
  63. package/src/generators/test-generator/adapters/playwright/templates/test-file.hbs +25 -0
  64. package/src/generators/test-generator/code-generator.ts +50 -8
  65. package/src/generators/test-generator/patterns/assertion-patterns.ts +62 -6
  66. package/src/generators/test-generator/patterns/form-patterns.ts +3 -3
  67. package/src/generators/test-generator/patterns/interaction-patterns.ts +93 -1
  68. package/src/generators/test-generator/template-engine.ts +4 -0
  69. package/src/orchestrator/project-initializer.ts +74 -58
  70. package/src/orchestrator/templates/ai-instructions/claude-cmd-add-screen.md +42 -0
  71. package/src/orchestrator/templates/ai-instructions/claude-cmd-make-tc.md +60 -0
  72. package/src/orchestrator/templates/ai-instructions/claude-cmd-make-test.md +59 -0
  73. package/src/orchestrator/templates/ai-instructions/claude-config.md +90 -0
  74. package/src/orchestrator/templates/ai-instructions/claude-skill-error-mapping.md +27 -0
  75. package/src/orchestrator/templates/ai-instructions/claude-skill-gherkin-syntax.md +127 -0
  76. package/src/orchestrator/templates/ai-instructions/claude-skill-selector-keys.md +94 -0
  77. package/src/orchestrator/templates/ai-instructions/copilot-cmd-add-screen.md +41 -0
  78. package/src/orchestrator/templates/ai-instructions/copilot-cmd-make-tc.md +59 -0
  79. package/src/orchestrator/templates/ai-instructions/copilot-cmd-make-test.md +58 -0
  80. package/src/orchestrator/templates/ai-instructions/copilot-config.md +90 -0
  81. package/src/orchestrator/templates/ai-instructions/copilot-skill-error-mapping.md +27 -0
  82. package/src/orchestrator/templates/ai-instructions/copilot-skill-gherkin-syntax.md +127 -0
  83. package/src/orchestrator/templates/ai-instructions/copilot-skill-selector-keys.md +94 -0
  84. package/src/orchestrator/templates/readme.md +42 -38
  85. package/dist/orchestrator/templates/ai-rules.md +0 -189
  86. package/src/orchestrator/templates/ai-rules.md +0 -189
@@ -0,0 +1,127 @@
1
+ ---
2
+ description: 'Sungen Gherkin patterns, selector types, and YAML key rules. Referenced by other sungen prompts.'
3
+ mode: 'agent'
4
+ tools: []
5
+ ---
6
+
7
+ ## Step Patterns (65 patterns)
8
+
9
+ ### Setup
10
+
11
+ ```
12
+ User is on [T] page # navigate to page
13
+ User navigate to [T] page with {{v}} # navigate with data
14
+ User is logged in | is not logged in # auth state
15
+ ```
16
+
17
+ ### Form
18
+
19
+ ```
20
+ User fill [T] field with {{v}} # text input
21
+ User clear [T] field # clear input
22
+ User check [T] checkbox # check
23
+ User uncheck [T] checkbox # uncheck
24
+ User select [T] dropdown with {{v}} # select option
25
+ User toggle [T] switch # toggle switch/checkbox
26
+ User upload [T] file with {{f}} # file upload
27
+ ```
28
+
29
+ ### Interaction
30
+
31
+ ```
32
+ User click [T] button # click
33
+ User click [T] button with {{v}} # click with text match
34
+ User double click [T] element # double click
35
+ User hover [T] icon # hover
36
+ User drag [T] to [T2] # drag and drop
37
+ User expand [T] row # expand (aria-expanded)
38
+ User collapse [T] row # collapse (aria-expanded)
39
+ ```
40
+
41
+ ### Keyboard
42
+
43
+ ```
44
+ User press Escape key # global key press
45
+ User press Enter on [T] field # key on element
46
+ ```
47
+
48
+ ### Wait
49
+
50
+ ```
51
+ User wait for N seconds # wait timeout
52
+ User wait for [T] dialog # wait for element
53
+ User wait for [T] dialog is STATE # wait for state
54
+ User wait for [T] dialog with {{v}} # wait for element with text
55
+ User wait for [T] page # wait for navigation
56
+ ```
57
+
58
+ ### Scroll & Frame
59
+
60
+ ```
61
+ User scroll to [T] section # scroll into view
62
+ User switch to [T] frame # enter/exit iframe
63
+ ```
64
+
65
+ ### Assertions
66
+
67
+ ```
68
+ User see [T] page # URL assertion
69
+ User see [T] heading # visibility
70
+ User see [T] heading with {{v}} # visibility + text
71
+ User see [T] text contains {{v}} # partial text match
72
+ User see [T] text has text {{v}} # exact text match
73
+ User see [T] button is STATE # state assertion
74
+ User see [T] dialog with {{v}} is STATE # text + state
75
+ User see {{v}} # see data text
76
+ ```
77
+
78
+ ### Table
79
+
80
+ ```
81
+ User see [Table] table has row with {{f}} # row exists
82
+ User see [Table] table has no row with {{f}} # row not exists
83
+ User see [Table] table has {{count}} rows # row count
84
+ User see [Table] table has [Col] column # column exists
85
+ User see [Table] table is empty # empty table
86
+ User see [Table] table row with {{f}} has [Col] with {{v}} # cell by filter
87
+ User see [Table] table row 1 [Col] cell with {{v}} # cell by index
88
+ User click [Act] in [Table] table row with {{f}} # action in row
89
+ ```
90
+
91
+ ### States
92
+
93
+ `hidden` `visible` `disabled` `enabled` `checked` `unchecked` `focused` `empty` `loading` `selected` `sorted ascending` `sorted descending`
94
+
95
+ ### Element Types
96
+
97
+ `page` `button` `link` `field` `textarea` `heading` `text` `checkbox` `radio` `switch` `dropdown` `dialog` `modal` `menu` `menuitem` `tab` `tabpanel` `table` `row` `cell` `list` `listitem` `icon` `image` `alert` `spinner` `progressbar` `section` `region` `nav` `frame` `uploader` `file` `columnheader` `tooltip` `slider` `treeitem`
98
+
99
+ ## YAML Keys
100
+
101
+ `[Reference]` → **lowercase, spaces→dots**: `[Search Content]` → `search.content:`
102
+
103
+ ## Selectors (priority order)
104
+
105
+ | type | value | name | use |
106
+ |---|---|---|---|
107
+ | `testid` | data-testid | — | when exists |
108
+ | `role` | button/heading/link… | accessible name | interactive elements |
109
+ | `placeholder` | placeholder text | — | inputs |
110
+ | `label` | label text | — | labeled inputs |
111
+ | `text` | — | — | static text |
112
+ | `locator` | CSS selector | — | last resort |
113
+ | `page` | relative URL | — | navigation |
114
+ | `upload` | — | — | file inputs |
115
+ | `frame` | iframe selector | — | iframes |
116
+
117
+ Options: `nth` `exact` `scope` `match` `variant` `frame` `contenteditable` `columns`
118
+
119
+ ## Tags
120
+
121
+ | Tag | Effect |
122
+ |---|---|
123
+ | `@auth:role` | Use auth storage state for role |
124
+ | `@no-auth` | Disable inherited auth |
125
+ | `@steps:name` | Define reusable step block |
126
+ | `@extend:name` | Prepend steps from @steps block |
127
+ | `@manual` | Skip in generation |
@@ -0,0 +1,94 @@
1
+ ---
2
+ description: 'Rules for generating correct YAML selector keys from Gherkin [Reference] names. Referenced by other sungen prompts when creating or fixing selectors.yaml files.'
3
+ mode: 'agent'
4
+ tools: []
5
+ ---
6
+
7
+ ## Key Generation: `[Reference]` → YAML key
8
+
9
+ Transform: Vietnamese/Japanese → ASCII → lowercase → remove special chars → spaces to dots.
10
+
11
+ ```
12
+ [Submit] → submit
13
+ [Search Content] → search.content
14
+ [User's Profile] → users.profile
15
+ [Thời gian] → thoi.gian
16
+ [Địa điểm] → dia.diem
17
+ [ログイン] → roguin
18
+ [パスワード] → pasuwaado
19
+ [Page 2] → page.2
20
+ [Kudos Detail Modal] → kudos.detail.modal
21
+ ```
22
+
23
+ **Rules:**
24
+ 1. Remove Vietnamese diacritics: `ằắẳẵặ` → `a`, `đ` → `d`, etc.
25
+ 2. Convert Japanese Hiragana/Katakana to Romaji
26
+ 3. Lowercase everything
27
+ 4. `'s` → `s` (apostrophe-s becomes just s)
28
+ 5. Remove all special chars except spaces
29
+ 6. Trim, then spaces → dots
30
+ 7. **NEVER use spaces, underscores, or uppercase in YAML keys**
31
+
32
+ ## Type-Suffixed Keys
33
+
34
+ When the same label is used for different element types, add `--type` suffix:
35
+
36
+ ```yaml
37
+ # [Add Campaign] button AND [Add Campaign] text
38
+ add.campaign--button:
39
+ type: 'role'
40
+ value: 'button'
41
+ name: 'Add Campaign'
42
+
43
+ add.campaign--text:
44
+ type: 'text'
45
+ value: 'Add Campaign'
46
+ ```
47
+
48
+ Type aliases (normalized automatically):
49
+ | Gherkin type | Normalized suffix |
50
+ |---|---|
51
+ | title, label, caption, message | `text` |
52
+ | heading, header | `heading` |
53
+ | logo, image, icon | `img` |
54
+ | btn | `button` |
55
+ | input, textbox, textarea, editor | `field` |
56
+ | column | `columnheader` |
57
+ | list-item | `listitem` |
58
+
59
+ ## Nth-Suffixed Keys
60
+
61
+ When targeting a specific occurrence by index, add `--N` suffix:
62
+
63
+ ```yaml
64
+ # [Send Thank You] button 3
65
+ hay.gui.loi.cam.on--3:
66
+ type: 'role'
67
+ value: 'button'
68
+ name: 'Send Thank You'
69
+ ```
70
+
71
+ ## Lookup Priority
72
+
73
+ Resolver searches in this order:
74
+ 1. `key--N` (nth-suffixed)
75
+ 2. `key--type` (type-suffixed, normalized)
76
+ 3. `key` (base key)
77
+ 4. Auto-infer from element type if no YAML entry
78
+ 5. Any `key--*` (first suffixed match)
79
+
80
+ ## Auto-Infer (no YAML entry needed)
81
+
82
+ If no YAML key exists, the resolver infers from the Gherkin element type:
83
+
84
+ | Gherkin | Inferred locator |
85
+ |---|---|
86
+ | `[X] button` | `getByRole('button', { name: 'X' })` |
87
+ | `[X] link` | `getByRole('link', { name: 'X' })` |
88
+ | `[X] heading` | `getByRole('heading', { name: 'X' })` |
89
+ | `[X] checkbox` | `getByRole('checkbox', { name: 'X' })` |
90
+ | `[X] field` | `getByPlaceholder('X')` |
91
+ | `[X] text` | `getByText('X')` |
92
+ | `[X] logo/image/icon` | `getByRole('img', { name: 'X' })` |
93
+
94
+ **Only add a YAML entry when** the auto-inferred locator won't work (wrong name, need testid, need nth, etc.).
@@ -19,8 +19,6 @@ sungen generate → compiles Gherkin + selectors + data → Playwright .spec.ts
19
19
  ├── specs/
20
20
  │ ├── generated/ # Auto-generated Playwright tests
21
21
  │ └── .auth/ # Auth storage states
22
- ├── docs/
23
- │ └── gherkin-dictionary.md # Full grammar & compiler rules
24
22
  ├── .github/
25
23
  │ └── copilot-instructions.md # AI rules for GitHub Copilot
26
24
  └── CLAUDE.md # AI rules for Claude Code
@@ -28,55 +26,62 @@ sungen generate → compiles Gherkin + selectors + data → Playwright .spec.ts
28
26
 
29
27
  ## Workflow
30
28
 
31
- ### 1. Add a screen
32
-
33
- ```bash
34
- sungen add --screen login --path /login
35
- # Add more features to an existing screen:
36
- sungen add --screen login --feature forgot-password
29
+ ```
30
+ Step 1 Step 2 Step 3
31
+ ┌──────────┐ ┌──────────┐ ┌──────────┐
32
+ /add- │────────▶│ /make-tc │────────▶│ /make- │
33
+ screen │ │ │ │ test │
34
+ └──────────┘ └──────────┘ └──────────┘
35
+ Scaffold Design TCs Compile &
36
+ directories & generate run tests
37
+ 3 files
37
38
  ```
38
39
 
39
- ### 2. Set up auth (if needed)
40
+ Use AI commands (Claude Code or GitHub Copilot) to drive the workflow:
40
41
 
41
- ```bash
42
- sungen makeauth admin
43
- # Opens browser → login manually → saves specs/.auth/admin.json
44
- ```
42
+ ### Step 1: Add a screen
45
43
 
46
- ### 3. Generate Gherkin + selectors with AI
44
+ | Claude Code | GitHub Copilot |
45
+ |---|---|
46
+ | `/sungen:add-screen login /login` | `@workspace /sungen-add-screen login /login` |
47
47
 
48
- Use your AI assistant (GitHub Copilot or Claude Code) to:
49
- 1. Navigate to the page URL via MCP Playwright
50
- 2. Take an accessibility snapshot
51
- 3. Generate `.feature` + `selectors.yaml` + `test-data.yaml`
48
+ Scaffolds `qa/screens/<name>/` with empty feature, selectors, and test-data files, then asks if you want to create test cases.
52
49
 
53
- The AI rules in `.github/copilot-instructions.md` and `CLAUDE.md` teach the AI
54
- how to write correct Gherkin syntax and selector YAML for sungen.
50
+ ### Step 2: Create test cases
55
51
 
56
- ### 4. Compile to Playwright tests
52
+ | Claude Code | GitHub Copilot |
53
+ |---|---|
54
+ | `/sungen:make-tc login` | `@workspace /sungen-make-tc login` |
57
55
 
58
- ```bash
59
- sungen generate --screen login
60
- # or for all screens:
61
- sungen generate --all
62
- ```
56
+ AI acts as a **Senior QA Engineer**: explores the live page (via Playwright MCP) or analyzes static designs, gathers test viewpoints (UI/UX, Validation, Logic, Security), and generates the 3 files.
63
57
 
64
- ### 5. Run tests
58
+ ### Step 3: Compile & run tests
59
+
60
+ | Claude Code | GitHub Copilot |
61
+ |---|---|
62
+ | `/sungen:make-test login` | `@workspace /sungen-make-test login` |
63
+
64
+ AI acts as a **Senior Developer**: compiles Gherkin → Playwright `.spec.ts`, runs tests, and auto-fixes selectors/test-data on failure (up to 5 attempts).
65
+
66
+ ### Auth setup (if needed)
67
+
68
+ If any page requires authentication, run manually before Step 2:
65
69
 
66
70
  ```bash
67
- npx playwright test
68
- npx playwright test --ui # interactive mode
71
+ sungen makeauth admin --url <baseURL>
72
+ # Opens browser login manually → saves specs/.auth/admin.json
69
73
  ```
70
74
 
71
- ### 6. Fix failures (AI Verify loop)
72
-
73
- When tests fail, use AI to read the error → fix `selectors.yaml` → recompile → re-run.
75
+ ### Manual CLI commands
74
76
 
75
- | Error | Fix in selectors.yaml |
76
- |---|---|
77
- | strict mode: resolved to N elements | Add `exact: true` or `scope` or `nth` |
78
- | element(s) not found | Fix `name`, `type`, or `value` |
79
- | getByText matched too many | Add `match: 'exact'` or `nth` |
77
+ ```bash
78
+ sungen add --screen <name> --path <path> # Scaffold screen
79
+ sungen add --screen <name> --feature <name> # Add feature to screen
80
+ sungen generate --screen <name> # Compile to .spec.ts
81
+ sungen generate --all # Compile all screens
82
+ npx playwright test # Run all tests
83
+ npx playwright test --ui # Interactive mode
84
+ ```
80
85
 
81
86
  ---
82
87
 
@@ -192,6 +197,5 @@ Locator priority: `data-testid` > `role+name` > `label` > `text` > `CSS`
192
197
 
193
198
  ## Documentation
194
199
 
195
- - [Gherkin Dictionary](docs/gherkin-dictionary.md) — full grammar, all 17 patterns, compiler rules
196
200
  - [Sungen GitHub](https://github.com/sun-asterisk/sungen)
197
201
  - [Playwright Documentation](https://playwright.dev)