Tests Kit
Test case guardian and insertion tool for the Synnovator platform's business scenarios defined in specs/testcases/.
Mode 1: Guard — Verify Existing Test Cases
Run this workflow before committing any change to synnovator skill scripts, data model docs, or spec files.
Guard Workflow
Run validation script to check structural integrity:
uv run python .claude/skills/tests-kit/scripts/check_testcases.py
This checks: TC ID format, uniqueness across files, file structure, and format conventions.
Identify affected test cases based on the change:
- Read references/testcase-index.md to find TC IDs related to the changed module
- Read references/testcase-format.md for test layering strategy
- Map changes to affected TC prefixes:
content.py / endpoint scripts → TC-USER, TC-CAT, TC-RULE, TC-GRP, TC-POST, TC-RES, TC-IACT
relations.py → TC-REL-*
cascade.py → TC-DEL-*
cache.py → TC-IACT-003, TC-IACT-013, TC-IACT-021 (counter tests)
rules.py → TC-RULE-100+, TC-ENGINE-*, TC-ENTRY-*, TC-CLOSE-*
docs/data-types.md → All content type TCs
docs/relationships.md → TC-REL-*, TC-FRIEND-*, TC-STAGE-*, TC-TRACK-*, TC-PREREQ-*
docs/crud-operations.md → TC-PERM-*, all CRUD TCs
docs/rule-engine.md → TC-ENGINE-*, TC-ENTRY-*, TC-CLOSE-*
- frontend/lib/api-client.ts →
TC-FEINT-090 (CRUD 完整性)
- frontend/app//create/page.tsx** →
TC-FEINT-001~091 (前端集成)
- frontend/app//edit/page.tsx** →
TC-FEINT-040~041 (编辑集成)
- specs/seed-data-requirements.md → 种子数据映射的测试用例 (需检查覆盖度)
- scripts/seed_dev_data.py → 种子数据脚本变更需验证前置条件覆盖
- Map E2E implementation files to TC prefixes:
- e2e/test_journey_anonymous.py →
TC-JOUR-002, TC-BROWSE-*
- e2e/test_journey_team_join.py →
TC-JOUR-005, TC-GRP-004~007
- e2e/test_journey_team_registration.py →
TC-JOUR-007, TC-REL-CG-*
- e2e/test_journey_post_creation.py →
TC-JOUR-009, TC-POST-*, TC-CREATE-*
- e2e/test_journey_certificate.py →
TC-JOUR-010, TC-CLOSE-030~032
- e2e/test_journey_post_edit.py →
TC-JOUR-011-*, TC-REL-PP-*
- e2e/test_journey_post_delete.py →
TC-JOUR-012, TC-DEL-012
- e2e/test_journey_community.py →
TC-JOUR-013, TC-IACT-*, TC-SOCIAL-*
Read the affected test case files in specs/testcases/ and verify each scenario still holds given the proposed change.
Report conflicts — If any test case would be broken:
- List each broken TC ID with explanation
- Propose how to resolve (fix implementation to preserve TC, or update TC with user approval)
Mode 2: Insert — Add New Test Cases
Run this workflow when the user wants to add new test scenarios.
Insert Workflow
Understand the scenario the user wants to test. Ask for:
- What business behavior should be covered?
- Which content types / relations / rules are involved?
Check existing coverage — Read references/testcase-index.md and search for overlapping or similar TCs. If the scenario is already covered, inform the user.
Try to fit within existing specs — Before proposing any spec changes:
- Read relevant files in
docs/ and specs/ to understand current data model and constraints
- Attempt to express the test using existing content types, relations, and rule engine features
- Consider: Can the test be decomposed into multiple steps using existing primitives?
- Consider: Can an existing data type (e.g.,
interaction, post:post relation) serve as an indirect wrapper?
- If the scenario can be expressed without spec changes, proceed to step 5
If spec changes are needed — Present to the user:
- Which spec file(s) need modification
- What the minimum change would be
- Impact analysis: which existing TCs might be affected
- Wait for user approval before proceeding
Determine placement — Read references/testcase-format.md for conventions:
- First, choose the correct layer based on test scope:
- 基础层 (01-10): 单个实体 CRUD/约束测试
- 桥接层 (11): 完整业务流程(多步骤、跨实体)
- 高级层 (12-17): 规则引擎、转移等高级功能
- 场景层 (18-33): 细粒度端到端场景
- Avoid duplication between layer 11 and 18-33:
- 11 覆盖完整流程(1-2 个 TC 验证整条链路)
- 18-33 覆盖场景变体(多个 TC 验证正向/负向/边界)
- Identify the correct file (by module) or decide if a new file is needed
- Pick the next available TC ID number within the appropriate range
- Place positive cases in 001-099 (or 100-199 for feature-specific), negative in 900-999
Write the test case following format conventions:
- Chinese language
**TC-PREFIX-NNN:Title** format
- Scenario + expected result only, no test method
- Single paragraph unless multi-effect cascade
Run validation after insertion:
uv run python .claude/skills/tests-kit/scripts/check_testcases.py
Running E2E Tests
# 运行所有用户旅程 E2E 测试
uv run pytest e2e/ -v -k "journey"
# 运行特定测试
uv run pytest e2e/test_journey_post_creation.py -v
调试 E2E 测试失败
当 E2E 测试失败时,使用 Playwright Trace 进行可视化调试:
# 启用 trace(失败时自动保存)
uv run pytest e2e/ -v --e2e-trace
# 所有测试都保存 trace(用于分析通过的测试)
uv run pytest e2e/ -v --e2e-trace-all
# 查看 trace 文件(可视化界面)
npx playwright show-trace /tmp/e2e_traces/<test_name>.zip
Trace Viewer 提供:
- 📸 时间线视图:每个操作的截图
- 🌐 网络面板:HTTP 请求/响应
- 📝 控制台日志:console.log/error
- 🔍 DOM 快照:可检查页面元素
在测试中使用 traced_page fixture:
def test_something(traced_page):
traced_page.goto("http://localhost:3000/explore")
# 访问捕获的日志
print(traced_page.console_errors) # JS 错误
print(traced_page.network_errors) # 网络错误
# 辅助函数
from conftest import print_console_logs
print_console_logs(traced_page)
Resources
scripts/
check_testcases.py — Validate all test case files for format consistency, TC ID uniqueness, and structural correctness. Run with uv run python .claude/skills/tests-kit/scripts/check_testcases.py.
references/
- testcase-index.md — Complete catalog of all 267 test cases with TC IDs, descriptions, and file locations. Read this to find related test cases or check coverage.
- testcase-format.md — File naming, TC ID conventions, number ranges, writing rules, and structural template. Read this before writing new test cases.
1---2name: tests-kit-23description: Test case management for Synnovator platform. Two modes: (1) Guard mode — before any synnovator skill or implementation change, verify existing test cases in specs/testcases/ are not broken. Use when modifying synnovator skill code, endpoint scripts, engine logic, or data model specs. (2) Insert mode — add new test cases to specs/testcases/. Use when user requests adding business scenarios, new feature test coverage, or regression tests. Triggers: 'run tests', 'check testcases', 'add test case', 'verify tests', 'test coverage', or any synnovator implementation change.4---56# Tests Kit78Test case guardian and insertion tool for the Synnovator platform's business scenarios defined in `specs/testcases/`.910## Mode 1: Guard — Verify Existing Test Cases1112Run this workflow **before committing any change** to synnovator skill scripts, data model docs, or spec files.1314### Guard Workflow15161. **Run validation script** to check structural integrity:17 ```bash18 uv run python .claude/skills/tests-kit/scripts/check_testcases.py19 ```20 This checks: TC ID format, uniqueness across files, file structure, and format conventions.21222. **Identify affected test cases** based on the change:23 - Read [references/testcase-index.md](references/testcase-index.md) to find TC IDs related to the changed module24 - Read [references/testcase-format.md](references/testcase-format.md) for test layering strategy25 - Map changes to affected TC prefixes:26 - `content.py` / endpoint scripts → `TC-USER`, `TC-CAT`, `TC-RULE`, `TC-GRP`, `TC-POST`, `TC-RES`, `TC-IACT`27 - `relations.py` → `TC-REL-*`28 - `cascade.py` → `TC-DEL-*`29 - `cache.py` → `TC-IACT-003`, `TC-IACT-013`, `TC-IACT-021` (counter tests)30 - `rules.py` → `TC-RULE-100+`, `TC-ENGINE-*`, `TC-ENTRY-*`, `TC-CLOSE-*`31 - `docs/data-types.md` → All content type TCs32 - `docs/relationships.md` → `TC-REL-*`, `TC-FRIEND-*`, `TC-STAGE-*`, `TC-TRACK-*`, `TC-PREREQ-*`33 - `docs/crud-operations.md` → `TC-PERM-*`, all CRUD TCs34 - `docs/rule-engine.md` → `TC-ENGINE-*`, `TC-ENTRY-*`, `TC-CLOSE-*`35 - **frontend/lib/api-client.ts** → `TC-FEINT-090` (CRUD 完整性)36 - **frontend/app/**/create/page.tsx** → `TC-FEINT-001~091` (前端集成)37 - **frontend/app/**/edit/page.tsx** → `TC-FEINT-040~041` (编辑集成)38 - **specs/seed-data-requirements.md** → 种子数据映射的测试用例 (需检查覆盖度)39 - **scripts/seed_dev_data.py** → 种子数据脚本变更需验证前置条件覆盖40 - Map E2E implementation files to TC prefixes:41 - **e2e/test_journey_anonymous.py** → `TC-JOUR-002`, `TC-BROWSE-*`42 - **e2e/test_journey_team_join.py** → `TC-JOUR-005`, `TC-GRP-004~007`43 - **e2e/test_journey_team_registration.py** → `TC-JOUR-007`, `TC-REL-CG-*`44 - **e2e/test_journey_post_creation.py** → `TC-JOUR-009`, `TC-POST-*`, `TC-CREATE-*`45 - **e2e/test_journey_certificate.py** → `TC-JOUR-010`, `TC-CLOSE-030~032`46 - **e2e/test_journey_post_edit.py** → `TC-JOUR-011-*`, `TC-REL-PP-*`47 - **e2e/test_journey_post_delete.py** → `TC-JOUR-012`, `TC-DEL-012`48 - **e2e/test_journey_community.py** → `TC-JOUR-013`, `TC-IACT-*`, `TC-SOCIAL-*`49503. **Read the affected test case files** in `specs/testcases/` and verify each scenario still holds given the proposed change.51524. **Report conflicts** — If any test case would be broken:53 - List each broken TC ID with explanation54 - Propose how to resolve (fix implementation to preserve TC, or update TC with user approval)5556## Mode 2: Insert — Add New Test Cases5758Run this workflow when the user wants to add new test scenarios.5960### Insert Workflow61621. **Understand the scenario** the user wants to test. Ask for:63 - What business behavior should be covered?64 - Which content types / relations / rules are involved?65662. **Check existing coverage** — Read [references/testcase-index.md](references/testcase-index.md) and search for overlapping or similar TCs. If the scenario is already covered, inform the user.67683. **Try to fit within existing specs** — Before proposing any spec changes:69 - Read relevant files in `docs/` and `specs/` to understand current data model and constraints70 - Attempt to express the test using **existing** content types, relations, and rule engine features71 - Consider: Can the test be decomposed into multiple steps using existing primitives?72 - Consider: Can an existing data type (e.g., `interaction`, `post:post` relation) serve as an indirect wrapper?73 - If the scenario can be expressed without spec changes, proceed to step 574754. **If spec changes are needed** — Present to the user:76 - Which spec file(s) need modification77 - What the minimum change would be78 - Impact analysis: which existing TCs might be affected79 - Wait for user approval before proceeding80815. **Determine placement** — Read [references/testcase-format.md](references/testcase-format.md) for conventions:82 - **First, choose the correct layer** based on test scope:83 - 基础层 (01-10): 单个实体 CRUD/约束测试84 - 桥接层 (11): 完整业务流程(多步骤、跨实体)85 - 高级层 (12-17): 规则引擎、转移等高级功能86 - 场景层 (18-33): 细粒度端到端场景87 - **Avoid duplication** between layer 11 and 18-33:88 - 11 覆盖**完整流程**(1-2 个 TC 验证整条链路)89 - 18-33 覆盖**场景变体**(多个 TC 验证正向/负向/边界)90 - Identify the correct file (by module) or decide if a new file is needed91 - Pick the next available TC ID number within the appropriate range92 - Place positive cases in 001-099 (or 100-199 for feature-specific), negative in 900-99993946. **Write the test case** following format conventions:95 - Chinese language96 - `**TC-PREFIX-NNN:Title**` format97 - Scenario + expected result only, no test method98 - Single paragraph unless multi-effect cascade991007. **Run validation** after insertion:101 ```bash102 uv run python .claude/skills/tests-kit/scripts/check_testcases.py103 ```104105## Running E2E Tests106107```bash108# 运行所有用户旅程 E2E 测试109uv run pytest e2e/ -v -k "journey"110111# 运行特定测试112uv run pytest e2e/test_journey_post_creation.py -v113```114115## 调试 E2E 测试失败116117当 E2E 测试失败时,使用 **Playwright Trace** 进行可视化调试:118119```bash120# 启用 trace(失败时自动保存)121uv run pytest e2e/ -v --e2e-trace122123# 所有测试都保存 trace(用于分析通过的测试)124uv run pytest e2e/ -v --e2e-trace-all125126# 查看 trace 文件(可视化界面)127npx playwright show-trace /tmp/e2e_traces/<test_name>.zip128```129130**Trace Viewer 提供:**131- 📸 时间线视图:每个操作的截图132- 🌐 网络面板:HTTP 请求/响应133- 📝 控制台日志:console.log/error134- 🔍 DOM 快照:可检查页面元素135136**在测试中使用 traced_page fixture:**137138```python139def test_something(traced_page):140 traced_page.goto("http://localhost:3000/explore")141142 # 访问捕获的日志143 print(traced_page.console_errors) # JS 错误144 print(traced_page.network_errors) # 网络错误145146 # 辅助函数147 from conftest import print_console_logs148 print_console_logs(traced_page)149```150151## Resources152153### scripts/154155- `check_testcases.py` — Validate all test case files for format consistency, TC ID uniqueness, and structural correctness. Run with `uv run python .claude/skills/tests-kit/scripts/check_testcases.py`.156157### references/158159- [testcase-index.md](references/testcase-index.md) — Complete catalog of all 267 test cases with TC IDs, descriptions, and file locations. Read this to find related test cases or check coverage.160- [testcase-format.md](references/testcase-format.md) — File naming, TC ID conventions, number ranges, writing rules, and structural template. Read this before writing new test cases.