ATC_SIMPLE/.claude/commands/smoke-test-checklist.md

129 lines
5.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description: Sinh smoke test checklist (Happy / Empty / Error / Responsive / Data Edge) từ PR/commit Gitea
argument-hint: <gitea-pr-or-commit-url>
allowed-tools: Bash, Read, Grep, Glob
---
# /smoke-test-checklist
Đầu vào (`$ARGUMENTS`) là **một link Gitea**:
- Pull request: `https://<gitea-host>/<owner>/<repo>/pulls/<index>` (chấp nhận cả `/pull/<index>`).
- Commit: `https://<gitea-host>/<owner>/<repo>/commit/<sha>` (chấp nhận cả `/commits/<sha>`).
Nếu thiếu link, **dừng** và yêu cầu cung cấp.
Gọi API bằng `curl -s -u "andrew.ng@apactech.io:andrew.ng@123" -H "Accept: application/json" --fail-with-body "<url>"`. **Không** in lệnh kèm password ra response. Nếu 401/403, báo lỗi auth, không in credentials.
## Các bước phải làm
### 1. Parse link
- `GITEA_HOST` = scheme + host. `OWNER`, `REPO`.
- `KIND` = `pr` (path chứa `/pulls/` hoặc `/pull/`) | `commit` (path chứa `/commit/` hoặc `/commits/`).
- `REF` = số PR (cho `pr`) hoặc SHA (cho `commit`).
Nếu không khớp pattern → hỏi lại thay vì đoán.
### 2. Lấy diff để hiểu phạm vi thay đổi
Base API: `${GITEA_HOST}/api/v1/repos/${OWNER}/${REPO}`
#### KIND = pr
- `GET /pulls/${REF}``title`, `body`, `base.ref`, `head.ref`, `head.sha`, `state`, `merged`.
- `GET /pulls/${REF}/files` → list file thay đổi.
- Raw diff: `GET ${GITEA_HOST}/${OWNER}/${REPO}/pulls/${REF}.diff` → lưu `/tmp/smoke-${REF}.diff`.
#### KIND = commit
- `GET /git/commits/${REF}``message`, `files`.
- Raw diff: `GET ${GITEA_HOST}/${OWNER}/${REPO}/commit/${REF}.diff` → lưu `/tmp/smoke-${REF}.diff`.
**Ưu tiên git local** nếu `git remote -v` trỏ về cùng `GITEA_HOST/${OWNER}/${REPO}`: dùng `git show <sha>` / `git diff <base>..<head>` thay vì hit Gitea.
### 3. Phân loại thay đổi
Đọc diff + (nếu cần) mở file gốc bằng `Read` để xác định **bề mặt cần test**:
- **UI / FE**: file dưới `FRONTEND/src/` (components, modals, pages, routing, `App.tsx`, terminal).
- **API / BE**: file dưới `BACKEND/app/controllers/`, routes (`start/routes.ts`), models, migrations.
- **Socket event**: handler mới/sửa trong `BACKEND/providers/socket_io_provider.ts` hoặc handler trong `FRONTEND/src/App.tsx`'s big `useEffect` / `SocketContext`.
- **Device interaction**: thay đổi trong `BACKEND/app/services/{line,station,apc,switch}_connection.ts` (gửi command xuống thiết bị, scenario, DPELP, physical test, IOS/license load).
- **Persisted state**: thay đổi `saveState`/`restoreState`, key Redis `socket_state` hoặc `station:{id}:line:{id}:history`, migration MySQL.
Ghi nhớ phân loại để generate checklist phù hợp (vd. không thêm "Mobile / Responsive" cho thay đổi thuần BE).
### 4. Sinh checklist
**5 nhóm bắt buộc** (đúng thứ tự, đúng tên):
#### Happy Path
Kịch bản chính của tính năng vừa thêm/sửa, đi từ A→Z với input hợp lệ. Mỗi mục mô tả **hành động cụ thể + kỳ vọng quan sát được**.
#### Empty State
- Danh sách rỗng, chưa có dữ liệu.
- User chưa chọn line/station nào.
- Modal mở khi không có context (chưa connect, chưa run scenario, v.v.).
- Trang load lần đầu chưa có `localStorage.user`.
#### Error Case
- API trả 4xx/5xx.
- Socket disconnect giữa chừng (mất line/station session → cần auto-reconnect theo `handleLineOperation`).
- TCP session timeout / `setTimeoutConnect` chạm 8h.
- Device không phản hồi command (vd. APC, switch).
- Input invalid (tên rỗng, ký tự đặc biệt, số âm).
- Lỗi từ Lucid model (unique constraint, FK).
#### Data Edge Case
- Chuỗi rất dài (output line, log, scenario name → buffer truncate ở `saveState` 5000 chars).
- Ký tự Unicode / emoji / VN dấu trong tên station, scenario, comment.
- Số rất lớn / âm / 0 cho port number, line number, timeout.
- Concurrent: 2 user thao tác cùng 1 line/station (CLI ownership trong `userConnecting`).
- Race với keep-alive (`keepConnectAPC` 40s / `keepConnectStation` 120s) đúng lúc user gửi command.
- Restart backend → state restore đúng từ Redis (`restoreState`).
### 5. Trả về kết quả
Format markdown (Vietnamese), checkbox GitHub-style `- [ ]`:
```
# Smoke Test Checklist — <KIND> #<REF>
1. Happy Path
- [ ] <bước 1 + kỳ vọng>
- [ ] <bước 2 + kỳ vọng>
...
2. Empty State
- [ ] <case 1>
...
3. Error Case
- [ ] <case 1>
...
4. Data Edge Case
- [ ] <case 1>
...
```
### 6. Nguyên tắc viết checklist
- Mỗi item bắt đầu bằng **động từ hành động** (Mở, Nhấn, Gửi, Disconnect…) + **kỳ vọng quan sát được**, không viết chung chung "test feature X".
- Bám sát diff: chỉ liệt kê case **liên quan trực tiếp** thay đổi này. Không generate checklist generic cho cả app.
- Đặt item theo thứ tự dễ thực hiện (UI flow trước, edge sau).
- Nếu một nhóm không có case nào áp dụng → ghi rõ `N/A — <lý do>`, không tự bịa.
- Tổng số item khuyến nghị: 38 / nhóm. Nếu nhiều hơn, gom case tương đương.
### 7. Không tự ý
- **Không** tự chạy test, không khởi động app (nếu user muốn, họ chạy `/run` hoặc `/verify` riêng).
- **Không** comment lên Gitea / Jira.
- **Không** sửa code.
- **Không** in password.