@torus-engineering/tas-kit 1.8.0 → 1.10.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.
@@ -0,0 +1,173 @@
1
+ # /tas-apitest-plan $ARGUMENTS
2
+
3
+ Vai trò: SE - Software Engineer
4
+ Generate API Test Specification (Markdown) từ API Spec (OpenAPI 3.0, Markdown, YAML) hoặc phân tích code API.
5
+
6
+ ## Always / Ask / Never
7
+
8
+ | | Hành động |
9
+ |---|---|
10
+ | **Always** | Đọc toàn bộ spec hoặc phân tích code trước khi tạo test spec |
11
+ | **Always** | Tổ chức test cases theo API version — mỗi version một section riêng |
12
+ | **Always** | Append-only: không sửa sections trong version cũ đã tồn tại |
13
+ | **Always** | Coverage matrix: mỗi endpoint cần ≥1 happy path + ≥1 error path |
14
+ | **Always** | Đọc `.claude/rules/csharp/api-testing.md` để nắm convention |
15
+ | **Ask** | Khi spec không rõ expected response schema hoặc business rule |
16
+ | **Never** | Sử dụng version folder/syntax trong test spec file (dùng section headers thay vì) |
17
+ | **Never** | Bỏ qua error path — mỗi endpoint cần cover validation errors |
18
+
19
+ ## Hành động
20
+
21
+ ### Bước 1 — Locate Inputs
22
+
23
+ `$ARGUMENTS` là path đến:
24
+ - API Spec file (OpenAPI 3.0 JSON/YAML, Markdown)
25
+ - Hoặc Story ID — glob tìm `docs/epics/**/Story-{ID}*.md`
26
+ - Hoặc path tới project code API cần phân tích
27
+
28
+ Nếu không có → hỏi user:
29
+ ```
30
+ Nhập input cho /tas-apitest-plan:
31
+ 1. Path đến API Spec file (OpenAPI/Markdown/YAML)
32
+ 2. Story ID (để tìm link spec trong Story)
33
+ 3. Path đến code API cần phân tích tự động
34
+ ```
35
+
36
+ ### Bước 2 — Detect Existing Test Spec
37
+
38
+ Glob tìm `docs/tests/API-Test-Spec-*.md`.
39
+
40
+ - **Tìm thấy**: Đọc file, detect versions đã có (tìm section headers `## v{N}`)
41
+ - **Không tìm thấy**: Tạo mới với version v1
42
+
43
+ ### Bước 3 — Parse Input
44
+
45
+ **Nếu là API Spec file:**
46
+ - Đọc và parse OpenAPI/Markdown/YAML
47
+ - Thu thập cho mỗi endpoint:
48
+ - HTTP method + path, path/query params, request body schema
49
+ - Response schemas theo từng status code
50
+ - Auth requirement, description/summary
51
+ - Tags để nhóm endpoints
52
+
53
+ **Nếu là Story:**
54
+ - Đọc Story để tìm link spec trong `## Technical Plan` hoặc `## Acceptance Criteria`
55
+ - Parse spec như trên
56
+ - Thêm AC mapping vào test spec
57
+
58
+ **Nếu là code path:**
59
+ - Glob tìm controller/handler files (`.cs`, `.ts`, `.py` tùy stack)
60
+ - Phân tích attributes/routes để phát hiện endpoints
61
+ - Extract DTO classes để biết request/response schema
62
+ - Hỏi user confirm nếu detect không rõ
63
+
64
+ ### Bước 4 — Detect API Version
65
+
66
+ Ưu tiên theo thứ tự:
67
+ 1. `info.version` trong OpenAPI
68
+ 2. Prefix trong URL path (v1/, v2/)
69
+ 3. Hỏi user
70
+
71
+ Version format: `v1`, `v2` (không có dot).
72
+
73
+ ### Bước 5 — Determine Output Path
74
+
75
+ Output: `docs/tests/API-Test-Spec-{slug}.md`
76
+
77
+ **Slug generation:**
78
+ - Từ `api_name` trong spec → lowercase, replace spaces với dashes
79
+ - Hoặc hỏi user nhập slug ngắn gọn (ví dụ: `users`, `orders`, `products`)
80
+
81
+ ### Bước 6 — Determine Update Mode
82
+
83
+ Nếu spec file đã tồn tại và version đã có:
84
+ - **Append mode** (default): thêm test cases mới vào cuối section version hiện tại
85
+ - Hỏi user nếu muốn tạo version mới (v2, v3...):
86
+
87
+ ```
88
+ Spec file đã có với version {current}. Bạn muốn:
89
+ 1. Append test cases vào version {current} (default)
90
+ 2. Tạo version mới (v{next}) cho test cases
91
+ ```
92
+
93
+ ### Bước 7 — Generate Test Spec
94
+
95
+ Đọc template `.tas/templates/API-Test-Spec.md` để nắm cấu trúc.
96
+
97
+ **Phân tích endpoints để tạo coverage matrix:**
98
+
99
+ Với mỗi endpoint, generate test cases cho:
100
+ 1. **Happy path** (2xx) — luôn có
101
+ 2. **Unauthorized** (401) — nếu endpoint yêu cầu auth
102
+ 3. **Forbidden** (403) — nếu có RBAC/ownership check
103
+ 4. **Not found** (404) — nếu có path param
104
+ 5. **Validation error** (400/422) — nếu có required fields hoặc business rules
105
+ 6. **Business rules** — từ Story ACs hoặc spec descriptions
106
+
107
+ **Coverage matrix format:**
108
+ ```
109
+ | Endpoint | Happy Path | 401 Unauthorized | 403 Forbidden | 404 Not Found | 400/422 Validation | Business Rule |
110
+ |----------|:---------:|:----------------:|:-------------:|:-------------:|:------------------:|:-------------:|
111
+ | GET /api/users | ✓ | ✓ | | | | |
112
+ | POST /api/users | ✓ | ✓ | | | ✓ | |
113
+ ```
114
+
115
+ **Test case detail format:**
116
+ ```
117
+ #### TC-XXX: {Title} — {Modifier}
118
+ - **Endpoint**: `{METHOD} {path}`
119
+ - **Auth**: Required/Not Required
120
+ - **Preconditions**:
121
+ - {List preconditions}
122
+ - **Request Query/Path/Body**:
123
+ - {Request details}
124
+ - **Expected Response**:
125
+ - Status: {code}
126
+ - Body: {schema}
127
+ - **Assertions**:
128
+ - {List assertions}
129
+ - **AC Reference**: AC-{N} (nếu có)
130
+ - **Test Method Name**: `{Method}_{Resource}_Returns{Status}_When{Condition}`
131
+ ```
132
+
133
+ ### Bước 8 — Write Test Spec File
134
+
135
+ **File chưa tồn tại:** Tạo mới từ template.
136
+
137
+ **File đã tồn tại (append mode):**
138
+ - Đọc file hiện tại
139
+ - Find section `## v{N}` mà đang làm việc
140
+ - Append test cases mới vào cuối section trước `## Version History` hoặc `## Changelog`
141
+ - Preserve toàn bộ content cũ
142
+
143
+ ### Bước 9 — Summary
144
+
145
+ Hiển thị:
146
+ 1. Output file path
147
+ 2. Number of endpoints detected
148
+ 3. Number of test cases generated
149
+ 4. Coverage matrix
150
+ 5. Next steps:
151
+ - Review test spec file
152
+ - Run `/tas-apitest docs/tests/API-Test-Spec-{slug}.md` để generate code
153
+
154
+ ```
155
+ ## API Test Spec Generated
156
+
157
+ **Output**: `docs/tests/API-Test-Spec-{slug}.md`
158
+ **Version**: v{N}
159
+ **Endpoints**: {N}
160
+ **Test Cases**: {N}
161
+
162
+ ### Coverage Matrix
163
+ [Print coverage matrix]
164
+
165
+ ### Next Steps
166
+ 1. Review test spec: `docs/tests/API-Test-Spec-{slug}.md`
167
+ 2. Generate test code: `/tas-apitest docs/tests/API-Test-Spec-{slug}.md`
168
+ 3. Run tests: `dotnet test tests/ApiTests/`
169
+ ```
170
+
171
+ ## Bước cuối — Token Log
172
+
173
+ Invoke skill `token-logger`: ghi AI Usage Log vào test spec file.
@@ -0,0 +1,143 @@
1
+ # /tas-apitest $ARGUMENTS
2
+
3
+ Vai trò: SE - Software Engineer
4
+ Generate .NET xUnit automation test project cho REST API từ API Test Spec file (Markdown).
5
+
6
+ ## Always / Ask / Never
7
+
8
+ | | Hành động |
9
+ |---|---|
10
+ | **Always** | Đọc toàn bộ API Test Spec file trước khi generate bất kỳ test nào |
11
+ | **Always** | Tổ chức tests theo API version — mỗi version một folder riêng |
12
+ | **Always** | Append-only: không sửa files trong version folder cũ đã tồn tại |
13
+ | **Always** | URL và credentials ra `appsettings.json` — không hardcode trong code |
14
+ | **Always** | XML doc comment trên mỗi test method |
15
+ | **Ask** | Khi test spec không rõ expected response schema |
16
+ | **Never** | Sửa hoặc xóa test files của version cũ hơn |
17
+ | **Never** | Hardcode base URL, API key, credentials trong test code |
18
+ | **Never** | Bỏ qua error path — mỗi endpoint cần ≥1 happy path + ≥1 error path |
19
+
20
+ ## Hành động
21
+
22
+ ### Bước 1 — Locate Input
23
+
24
+ `$ARGUMENTS` là path đến API Test Spec file: `docs/tests/API-Test-Spec-{slug}.md`.
25
+
26
+ Nếu không có → hỏi user:
27
+ ```
28
+ Nhập path đến API Test Spec file (vd: docs/tests/API-Test-Spec-users.md)
29
+ ```
30
+
31
+ ### Bước 2 — Parse API Test Spec
32
+
33
+ Đọc `.claude/rules/csharp/api-testing.md` để nắm convention trước khi generate.
34
+
35
+ Từ API Test Spec file, thu thập:
36
+ - API version
37
+ - Endpoints với method, path, params
38
+ - Test cases theo từng endpoint (TC-XXX)
39
+ - Request/response schemas
40
+ - Auth requirements
41
+ - Test data requirements
42
+ - Setup/teardown notes
43
+
44
+ ### Bước 3 — Detect Existing Test Project
45
+
46
+ Glob tìm `**/ApiTests/*.csproj`, `**/Api.Tests/*.csproj`, `**/IntegrationTests/*.csproj`.
47
+
48
+ - **Tìm thấy**: Đọc framework đang dùng (xUnit/NUnit/MSTest), glob `v*/` folders để biết versions đã có.
49
+ - **Không tìm thấy**: Tạo mới tại `tests/ApiTests/` với xUnit + FluentAssertions (per `csharp/testing.md`).
50
+
51
+ ### Bước 4 — Get API Version from Spec
52
+
53
+ Đọc version từ API Test Spec file (tìm frontmatter `api_version` hoặc section headers `## v{N}`).
54
+
55
+ Version folder: lowercase, không có dot — `v1`, `v2` (không phải `v1.0`).
56
+
57
+ ### Bước 5 — Generate Infrastructure (chỉ khi tạo project mới)
58
+
59
+ Đọc `.claude/rules/csharp/api-testing.md` section **Project Structure** và **Config Pattern** để generate:
60
+ - `ApiTests.csproj` với packages chuẩn
61
+ - `appsettings.json` (base) + `appsettings.Test.json` + `appsettings.Staging.json` với values từ spec
62
+ - `Shared/TestBase.cs` — load config, HttpClient, helper methods
63
+ - `Shared/ApiTestSettings.cs` — strongly typed settings
64
+ - `.gitignore` cho `appsettings.*.local.json`
65
+
66
+ ### Bước 6 — Generate Test Classes từ Spec
67
+
68
+ Nhóm endpoints theo resource. Mỗi nhóm → `tests/ApiTests/{version}/{Resource}ApiTests.cs`.
69
+
70
+ Với mỗi test case (TC-XXX) trong spec:
71
+ 1. Đọc test case details
72
+ 2. Map sang test method với naming: `{HttpMethod}_{Resource}_Returns{Status}_When{Condition}`
73
+ 3. Generate XML doc từ test case title
74
+ 4. Generate assertions từ expected response
75
+ 5. Add AC reference comment nếu có
76
+
77
+ Test class header comment:
78
+ ```csharp
79
+ // ============================================================
80
+ // {Resource} API Tests — v{N}
81
+ // Spec: docs/tests/API-Test-Spec-{slug}.md
82
+ // Generated: {YYYY-MM-DD}
83
+ // Story: {ID} (if applicable)
84
+ // APPEND-ONLY: không sửa methods đã tồn tại.
85
+ // ============================================================
86
+ ```
87
+
88
+ ### Bước 7 — Append-Only Guard
89
+
90
+ Trước khi ghi file: kiểm tra file đã tồn tại chưa.
91
+ - **File chưa có** → tạo mới bình thường.
92
+ - **File đã có** trong version folder → check từng test method:
93
+ - Method đã tồn tại (cùng tên) → **SKIP**, không ghi đè
94
+ - Method chưa có → append vào cuối class
95
+
96
+ ### Bước 8 — Generate Test Data Files (nếu spec yêu cầu)
97
+
98
+ Nếu spec có `test-data.{env}.json` references:
99
+ - Tạo `tests/ApiTests/data/test-data.Test.json` với sample data từ spec
100
+ - Hướng dẫn user tạo `test-data.Staging.json` và `test-data.local.json`
101
+
102
+ ### Bước 9 — Post-Generate Review
103
+
104
+ Launch `csharp-reviewer` agent:
105
+ > Review `tests/ApiTests/{version}/`. Đọc `.claude/rules/csharp/testing.md` + `.claude/rules/csharp/api-testing.md`.
106
+ > Tập trung: async/await, HttpClient disposal, assertion completeness, XML doc coverage.
107
+ > Format: Critical / High / Medium / Low với file:line.
108
+
109
+ Gate: Critical/High → fix ngay. Medium/Low → list gợi ý.
110
+
111
+ ### Bước 10 — Summary
112
+
113
+ Hiển thị:
114
+ 1. Test project path
115
+ 2. Number of test classes generated
116
+ 3. Number of test methods generated
117
+ 4. Coverage matrix (so với spec)
118
+ 5. Next steps để chạy tests
119
+
120
+ ```
121
+ ## API Tests Generated
122
+
123
+ **Project**: `tests/ApiTests/`
124
+ **Version**: v{N}
125
+ **Test Classes**: {N}
126
+ **Test Methods**: {N}
127
+
128
+ ### Generated Files
129
+ - tests/ApiTests/{version}/{Resource}ApiTests.cs
130
+ - tests/ApiTests/Shared/TestBase.cs (if new project)
131
+
132
+ ### Coverage (vs Spec)
133
+ [Print coverage table: spec test cases vs generated methods]
134
+
135
+ ### Next Steps
136
+ 1. Configure test environment: edit tests/ApiTests/appsettings.Test.json
137
+ 2. Add test data: tests/ApiTests/data/test-data.Test.json
138
+ 3. Run tests: `dotnet test tests/ApiTests/`
139
+ ```
140
+
141
+ ## Bước cuối — Token Log
142
+
143
+ Invoke skill `token-logger`: ghi AI Usage Log vào API Test Spec file.
@@ -8,7 +8,13 @@ Kiểm tra bảo mật codebase, lưu báo cáo vào docs/security-report.md.
8
8
  ## Hành động
9
9
 
10
10
  ### Bước 1 — Xác định scope
11
- `$ARGUMENTS` có thể là: file path, directory, hoặc để trống (scan toàn bộ codebase).
11
+ `$ARGUMENTS` có thể là:
12
+ - File path hoặc directory → scan scope chỉ định
13
+ - Để trống → scan toàn bộ codebase
14
+ - `--staged` → chỉ scan các file đang staged (giống pre-commit hook), nhanh + dùng để self-test trước khi commit
15
+
16
+ Với `--staged`: lấy danh sách từ `git diff --cached --name-only --diff-filter=ACM` và chỉ review các file đó. Dùng chung regex patterns với `.tas/hooks/security-scan.js` rồi bổ sung deep review bằng agents bên dưới.
17
+
12
18
  Đọc `.tas/checklists/security.md` để lấy checklist.
13
19
 
14
20
  ### Bước 2 — Parallel Security Scan