AgentSkillsCN

red-frontend-api

按照TDD(红灯阶段)编写一项Vitest逻辑测试。为纯前端逻辑(.logic.ts)创建测试。在用户想要创建前端逻辑测试,或提及“/red-frontend”命令时使用此功能。

SKILL.md
--- frontmatter
name: red-frontend-api
description: Write ONE Vitest + MSW API client test following TDD (red phase). Creates test for frontend API client using MSW for HTTP mocking. Use when user wants to create frontend API tests or mentions /red-frontend-api command.

/red-frontend-api - Write Frontend API Client Test (Red Phase)

Orchestrates red-agent for frontend-api layer.

Usage

code
/red-frontend-api "Story name" "Scenario name"
/red-frontend-api 2 "Registration API call"
/red-frontend-api                                      # Interactive selection

CRITICAL TDD RULE

Test MUST be run WITHOUT .skip first to verify failure. Only after confirming failure is correct, add .skip marker.

Workflow

  1. Parse user input (story, scenario)
  2. Load agent instructions from .claude/agents/red-agent.md
  3. Load layer template from .claude/templates/frontend/api-test.md
  4. Execute the following steps:
    • Identify API endpoints from ProductSpecification/ and backend controllers
    • Predict expected failure (document before writing test)
    • Write ONE test with MSW handler WITHOUT .skip initially
    • Run test using Skill tool: skill="test-frontend", args="{test-file-pattern}"
    • Verify failure matches prediction
    • Add .skip to the test
    • Verify test is now SKIPPED
  5. Return result summary with predicted vs actual failure

Key Rules

  • ONE test per invocation
  • MUST verify failure before adding .skip
  • Use MSW (Mock Service Worker) for HTTP mocking (analogous to WireMock on backend)
  • MSW handlers define expected request/response pairs
  • Use Skill tool for test execution (not npx directly)

Expected Failure Patterns

Current ImplementationExpected Test Failure
No API client moduleCannot find module
throw new Error('Not implemented')Error: Not implemented
Function returns undefinedAssertion failure
Wrong URL or methodMSW unhandled request warning + failure
Missing error handlingAssertion on error response fails

Story Mapping

#Story
01Login/Logout
02Registration
03Password Reset
04Connect Calendar
05Create Task
06Edit Task
07Delete Task
08Archive/Restore Task
09Task Detail View
10Activity Log
11Dashboard
12Billing & Subscription

Next Step

After red phase: /green-frontend-api "Story name" "Scenario name"