cp-toolkit 3.0.1 ā 3.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.
- package/bin/cp-toolkit.js +1 -0
- package/package.json +1 -1
- package/src/commands/init.js +81 -1
- package/templates/agents/backend-specialist.agent.md +0 -2
- package/templates/agents/code-archaeologist.agent.md +0 -2
- package/templates/agents/database-architect.agent.md +0 -2
- package/templates/agents/debugger.agent.md +0 -2
- package/templates/agents/devops-engineer.agent.md +0 -2
- package/templates/agents/documentation-writer.agent.md +0 -2
- package/templates/agents/explorer-agent.agent.md +0 -2
- package/templates/agents/frontend-specialist.agent.md +0 -2
- package/templates/agents/game-developer.agent.md +0 -2
- package/templates/agents/mobile-developer.agent.md +0 -2
- package/templates/agents/orchestrator.agent.md +0 -2
- package/templates/agents/penetration-tester.agent.md +0 -2
- package/templates/agents/performance-optimizer.agent.md +0 -2
- package/templates/agents/product-manager.agent.md +0 -2
- package/templates/agents/product-owner.agent.md +0 -2
- package/templates/agents/project-planner.agent.md +0 -2
- package/templates/agents/qa-automation-engineer.agent.md +0 -2
- package/templates/agents/security-auditor.agent.md +0 -2
- package/templates/agents/seo-specialist.agent.md +0 -2
- package/templates/agents/test-engineer.agent.md +0 -2
- package/templates/instructions/testing-development.instructions.md +41 -34
package/bin/cp-toolkit.js
CHANGED
|
@@ -46,6 +46,7 @@ program
|
|
|
46
46
|
.description('Initialize cp-kit in a directory (creates .github/ structure)')
|
|
47
47
|
.option('-y, --yes', 'Skip prompts and use defaults')
|
|
48
48
|
.option('-f, --force', 'Overwrite existing configuration')
|
|
49
|
+
.option('-g, --global', 'Install instructions globally to VS Code User Prompts directory')
|
|
49
50
|
.action(initCommand);
|
|
50
51
|
|
|
51
52
|
// cp-kit add <type> <name>
|
package/package.json
CHANGED
package/src/commands/init.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import fs from 'fs-extra';
|
|
13
13
|
import path from 'path';
|
|
14
|
+
import os from 'os';
|
|
14
15
|
import chalk from 'chalk';
|
|
15
16
|
import ora from 'ora';
|
|
16
17
|
import prompts from 'prompts';
|
|
@@ -20,10 +21,89 @@ import { fileURLToPath } from 'url';
|
|
|
20
21
|
const __filename = fileURLToPath(import.meta.url);
|
|
21
22
|
const __dirname = path.dirname(__filename);
|
|
22
23
|
|
|
24
|
+
function getGlobalPromptsDir() {
|
|
25
|
+
const platform = os.platform();
|
|
26
|
+
const homeDir = os.homedir();
|
|
27
|
+
|
|
28
|
+
if (platform === 'win32') {
|
|
29
|
+
return path.join(process.env.APPDATA, 'Code', 'User', 'prompts');
|
|
30
|
+
} else if (platform === 'darwin') {
|
|
31
|
+
return path.join(homeDir, 'Library', 'Application Support', 'Code', 'User', 'prompts');
|
|
32
|
+
} else {
|
|
33
|
+
// Linux and others
|
|
34
|
+
return path.join(homeDir, '.config', 'Code', 'User', 'prompts');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function initGlobal(options, templatesDir) {
|
|
39
|
+
const targetDir = getGlobalPromptsDir();
|
|
40
|
+
console.log(chalk.bold.cyan('\nš cp-toolkit - Installing Global Instructions\n'));
|
|
41
|
+
console.log(chalk.dim(`Target directory: ${targetDir}`));
|
|
42
|
+
|
|
43
|
+
if (!options.yes) {
|
|
44
|
+
const { confirm } = await prompts({
|
|
45
|
+
type: 'confirm',
|
|
46
|
+
name: 'confirm',
|
|
47
|
+
message: `Install instructions globally to VS Code User Data?`,
|
|
48
|
+
initial: true
|
|
49
|
+
});
|
|
50
|
+
if (!confirm) return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const spinner = ora('Installing global instructions...').start();
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
// Check if Code/User exists (VS Code installed?)
|
|
57
|
+
if (!fs.existsSync(path.dirname(targetDir))) {
|
|
58
|
+
spinner.warn(chalk.yellow('VS Code User directory not found. Is VS Code installed?'));
|
|
59
|
+
const { create } = await prompts({
|
|
60
|
+
type: 'confirm',
|
|
61
|
+
name: 'create',
|
|
62
|
+
message: 'Create directory anyway?',
|
|
63
|
+
initial: true
|
|
64
|
+
});
|
|
65
|
+
if (!create) return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await fs.ensureDir(targetDir);
|
|
69
|
+
|
|
70
|
+
// Copy instructions
|
|
71
|
+
// We flatten them: templates/instructions/*.md -> targetDir/*.md
|
|
72
|
+
const instructionsSourceDir = path.join(templatesDir, 'instructions');
|
|
73
|
+
const files = await fs.readdir(instructionsSourceDir);
|
|
74
|
+
|
|
75
|
+
let count = 0;
|
|
76
|
+
for (const file of files) {
|
|
77
|
+
if (file.endsWith('.md')) {
|
|
78
|
+
await fs.copy(
|
|
79
|
+
path.join(instructionsSourceDir, file),
|
|
80
|
+
path.join(targetDir, file),
|
|
81
|
+
{ overwrite: options.force }
|
|
82
|
+
);
|
|
83
|
+
count++;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
spinner.succeed(chalk.green(`⨠Installed ${count} global instruction files!`));
|
|
88
|
+
console.log(chalk.bold('\nš Next Steps:'));
|
|
89
|
+
console.log(` 1. Instructions are now available in ${chalk.cyan('ALL')} your projects.`);
|
|
90
|
+
console.log(` 2. Use ${chalk.yellow('Settings Sync')} in VS Code to sync them across machines.`);
|
|
91
|
+
|
|
92
|
+
} catch (error) {
|
|
93
|
+
spinner.fail(chalk.red('ā Failed to install global instructions'));
|
|
94
|
+
console.error(error);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
23
98
|
export async function initCommand(directory, options) {
|
|
99
|
+
const templatesDir = path.join(__dirname, '../../templates');
|
|
100
|
+
|
|
101
|
+
if (options.global) {
|
|
102
|
+
return initGlobal(options, templatesDir);
|
|
103
|
+
}
|
|
104
|
+
|
|
24
105
|
const targetDir = directory ? path.resolve(directory) : process.cwd();
|
|
25
106
|
const dirName = path.basename(targetDir);
|
|
26
|
-
const templatesDir = path.join(__dirname, '../../templates');
|
|
27
107
|
|
|
28
108
|
console.log(chalk.bold.cyan('\nš cp-toolkit - GitHub Copilot Agent Toolkit\n'));
|
|
29
109
|
|
|
@@ -3,8 +3,6 @@ name: backend-specialist
|
|
|
3
3
|
description: Expert backend architect for Node.js, Python, and modern serverless/edge systems. Use for API development, server-side logic, database integration, and security. Triggers on backend, server, api, endpoint, database, auth.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, nodejs-best-practices, python-patterns, api-patterns, database-design, mcp-builder, lint-and-validate, powershell-windows, bash-linux
|
|
7
|
-
applyTo: ["**/api/**", "**/*.server.*", "**/controllers/**", "**/*.service.ts"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Backend Development Architect
|
|
@@ -3,8 +3,6 @@ name: code-archaeologist
|
|
|
3
3
|
description: Expert in legacy code, refactoring, and understanding undocumented systems. Use for reading messy code, reverse engineering, and modernization planning. Triggers on legacy, refactor, spaghetti code, analyze repo, explain codebase.
|
|
4
4
|
tools: Read, Grep, Glob, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, refactoring-patterns, code-review-checklist
|
|
7
|
-
applyTo: ["**/*legacy*/**", "**/*.old.*", "**/deprecated/**"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Code Archaeologist
|
|
@@ -3,8 +3,6 @@ name: database-architect
|
|
|
3
3
|
description: Expert database architect for schema design, query optimization, migrations, and modern serverless databases. Use for database operations, schema changes, indexing, and data modeling. Triggers on database, sql, schema, migration, query, postgres, index, table.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, database-design
|
|
7
|
-
applyTo: ["**/prisma/**", "**/*.sql", "**/migrations/**", "**/db/**"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Database Architect
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: debugger
|
|
3
3
|
description: Expert in systematic debugging, root cause analysis, and crash investigation. Use for complex bugs, production issues, performance problems, and error analysis. Triggers on bug, error, crash, not working, broken, investigate, fix.
|
|
4
|
-
capabilities: clean-code, systematic-debugging
|
|
5
|
-
applyTo: ["**/*.log", "**/*.error.log", "**/debug/**", "**/*.dump"]
|
|
6
4
|
---
|
|
7
5
|
|
|
8
6
|
# Debugger - Root Cause Analysis Expert
|
|
@@ -3,8 +3,6 @@ name: devops-engineer
|
|
|
3
3
|
description: Expert in deployment, server management, CI/CD, and production operations. CRITICAL - Use for deployment, server access, rollback, and production changes. HIGH RISK operations. Triggers on deploy, production, server, pm2, ssh, release, rollback, ci/cd.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, deployment-procedures, server-management, powershell-windows, bash-linux
|
|
7
|
-
applyTo: ["**/Dockerfile", "**/*.yaml", "**/terraform/**", "**/.env*"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# DevOps Engineer
|
|
@@ -3,8 +3,6 @@ name: documentation-writer
|
|
|
3
3
|
description: Expert in technical documentation. Use ONLY when user explicitly requests documentation (README, API docs, changelog). DO NOT auto-invoke during normal development.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, documentation-templates
|
|
7
|
-
applyTo: ["**/README.md", "**/CHANGELOG.md", "**/docs/**", "**/*.doc.md"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Documentation Writer
|
|
@@ -3,8 +3,6 @@ name: explorer-agent
|
|
|
3
3
|
description: Advanced codebase discovery, deep architectural analysis, and proactive research agent. The eyes and ears of the framework. Use for initial audits, refactoring plans, and deep investigative tasks.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, ViewCodeItem, FindByName
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, architecture, plan-writing, brainstorming, systematic-debugging
|
|
7
|
-
applyTo: ["**/package.json", "**/CODEBASE.md", "**/.gitignore", "**/.gitmodules"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Explorer Agent - Advanced Discovery & Research
|
|
@@ -3,8 +3,6 @@ name: frontend-specialist
|
|
|
3
3
|
description: Senior Frontend Architect who builds maintainable React/Next.js systems with performance-first mindset. Use when working on UI components, styling, state management, responsive design, or frontend architecture. Triggers on keywords like component, react, vue, ui, ux, css, tailwind, responsive.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, nextjs-react-expert, web-design-guidelines, tailwind-patterns, frontend-design, lint-and-validate
|
|
7
|
-
applyTo: ["**/components/**", "**/*.tsx", "**/*.css", "**/hooks/**"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Senior Frontend Architect
|
|
@@ -3,8 +3,6 @@ name: game-developer
|
|
|
3
3
|
description: Game development across all platforms (PC, Web, Mobile, VR/AR). Use when building games with Unity, Godot, Unreal, Phaser, Three.js, or any game engine. Covers game mechanics, multiplayer, optimization, 2D/3D graphics, and game design patterns.
|
|
4
4
|
tools: Read, Write, Edit, Bash, Grep, Glob
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, game-development, game-development/pc-games, game-development/web-games, game-development/mobile-games, game-development/game-design, game-development/multiplayer, game-development/vr-ar, game-development/2d-games, game-development/3d-games, game-development/game-art, game-development/game-audio
|
|
7
|
-
applyTo: ["**/*.unity", "**/*.gd", "**/*.uproject", "**/*.shader"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Game Developer Agent
|
|
@@ -3,8 +3,6 @@ name: mobile-developer
|
|
|
3
3
|
description: Expert in React Native and Flutter mobile development. Use for cross-platform mobile apps, native features, and mobile-specific patterns. Triggers on mobile, react native, flutter, ios, android, app store, expo.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, mobile-design
|
|
7
|
-
applyTo: ["**/android/**", "**/ios/**", "**/*.dart", "**/*.kt", "**/*.swift"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Mobile Developer
|
|
@@ -3,8 +3,6 @@ name: orchestrator
|
|
|
3
3
|
description: Multi-agent coordination and task orchestration. Use when a task requires multiple perspectives, parallel analysis, or coordinated execution across different domains. Invoke this agent for complex tasks that benefit from security, backend, frontend, testing, and DevOps expertise combined.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Write, Edit, Agent
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, parallel-agents, behavioral-modes, plan-writing, brainstorming, architecture, lint-and-validate, powershell-windows, bash-linux
|
|
7
|
-
applyTo: ["**/PLAN.md", "**/.github/workflows/**", "**/ARCHITECTURE.md"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Orchestrator - Native Multi-Agent Coordination
|
|
@@ -3,8 +3,6 @@ name: penetration-tester
|
|
|
3
3
|
description: Expert in offensive security, penetration testing, red team operations, and vulnerability exploitation. Use for security assessments, attack simulations, and finding exploitable vulnerabilities. Triggers on pentest, exploit, attack, hack, breach, pwn, redteam, offensive.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, vulnerability-scanner, red-team-tactics, api-patterns
|
|
7
|
-
applyTo: ["**/security-audit/*.md", "**/*.pcap", "**/*.burp", "**/exploit.py"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Penetration Tester
|
|
@@ -3,8 +3,6 @@ name: performance-optimizer
|
|
|
3
3
|
description: Expert in performance optimization, profiling, Core Web Vitals, and bundle optimization. Use for improving speed, reducing bundle size, and optimizing runtime performance. Triggers on performance, optimize, speed, slow, memory, cpu, benchmark, lighthouse.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, performance-profiling
|
|
7
|
-
applyTo: ["**/*.profile.json", "**/lighthouse-report.json", "**/webpack-bundle-analyzer/**"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Performance Optimizer
|
|
@@ -3,8 +3,6 @@ name: product-manager
|
|
|
3
3
|
description: Expert in product requirements, user stories, and acceptance criteria. Use for defining features, clarifying ambiguity, and prioritizing work. Triggers on requirements, user story, acceptance criteria, product specs.
|
|
4
4
|
tools: Read, Grep, Glob, Bash
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: plan-writing, brainstorming, clean-code
|
|
7
|
-
applyTo: ["**/PRD.md", "**/*.prd.md", "**/requirements.md", "**/user-stories.md"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Product Manager
|
|
@@ -3,8 +3,6 @@ name: product-owner
|
|
|
3
3
|
description: Strategic facilitator bridging business needs and technical execution. Expert in requirements elicitation, roadmap management, and backlog prioritization. Triggers on requirements, user story, backlog, MVP, PRD, stakeholder.
|
|
4
4
|
tools: Read, Grep, Glob, Bash
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: plan-writing, brainstorming, clean-code
|
|
7
|
-
applyTo: ["**/BACKLOG.md", "**/*.backlog.md", "**/priorities.md", "**/roadmap.md"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Product Owner
|
|
@@ -3,8 +3,6 @@ name: project-planner
|
|
|
3
3
|
description: Smart project planning agent. Breaks down user requests into tasks, plans file structure, determines which agent does what, creates dependency graph. Use when starting new projects or planning major features.
|
|
4
4
|
tools: Read, Grep, Glob, Bash
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, app-builder, plan-writing, brainstorming
|
|
7
|
-
applyTo: ["**/PLAN.md", "**/*.plan.md", "**/roadmap.md", "**/*.todo.md"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Project Planner - Smart Project Planning
|
|
@@ -3,8 +3,6 @@ name: qa-automation-engineer
|
|
|
3
3
|
description: Specialist in test automation infrastructure and E2E testing. Focuses on Playwright, Cypress, CI pipelines, and breaking the system. Triggers on e2e, automated test, pipeline, playwright, cypress, regression.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: webapp-testing, testing-patterns, web-design-guidelines, clean-code, lint-and-validate
|
|
7
|
-
applyTo: ["**/cypress/**", "**/*.spec.ts", "**/*.cy.ts", "**/playwright.config.ts"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# QA Automation Engineer
|
|
@@ -3,8 +3,6 @@ name: security-auditor
|
|
|
3
3
|
description: Elite cybersecurity expert. Think like an attacker, defend like an expert. OWASP 2025, supply chain security, zero trust architecture. Triggers on security, vulnerability, owasp, xss, injection, auth, encrypt, supply chain, pentest.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, vulnerability-scanner, red-team-tactics, api-patterns
|
|
7
|
-
applyTo: ["**/auth/**", "**/middleware/**", "**/*.config.*"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Security Auditor
|
|
@@ -3,8 +3,6 @@ name: seo-specialist
|
|
|
3
3
|
description: SEO and GEO (Generative Engine Optimization) expert. Handles SEO audits, Core Web Vitals, E-E-A-T optimization, AI search visibility. Use for SEO improvements, content optimization, or AI citation strategies.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, seo-fundamentals, geo-fundamentals
|
|
7
|
-
applyTo: ["**/robots.txt", "**/sitemap.xml", "**/*.meta.json", "**/seo-audit.md"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# SEO Specialist
|
|
@@ -3,8 +3,6 @@ name: test-engineer
|
|
|
3
3
|
description: Expert in testing, TDD, and test automation. Use for writing tests, improving coverage, debugging test failures. Triggers on test, spec, coverage, jest, pytest, playwright, e2e, unit test.
|
|
4
4
|
tools: Read, Grep, Glob, Bash, Edit, Write
|
|
5
5
|
model: inherit
|
|
6
|
-
capabilities: clean-code, testing-patterns, tdd-workflow, webapp-testing, code-review-checklist, lint-and-validate
|
|
7
|
-
applyTo: ["**/*.test.ts", "**/*.test.js", "**/__tests__/**", "**/jest.config.js"]
|
|
8
6
|
---
|
|
9
7
|
|
|
10
8
|
# Test Engineer
|
|
@@ -1,42 +1,49 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: testing-development
|
|
3
3
|
description: Guidelines for test structure, frameworks, and code coverage best practices.
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0
|
|
5
5
|
applyTo: "**/*.test.*,**/*.spec.*,**/tests/**,**/__tests__/**"
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
# Testing Development Guidelines
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
|
|
42
|
-
|
|
10
|
+
You are an expert in Software Quality Assurance and Test Automation.
|
|
11
|
+
When writing or analyzing tests in this repository, you MUST follow these directives:
|
|
12
|
+
|
|
13
|
+
## 1. Test Structure & Strategy
|
|
14
|
+
- **Unit Tests**: Isolate individual functions/methods. Mock ALL external dependencies (DB, API, File System).
|
|
15
|
+
- **Integration Tests**: Verify interaction between modules (e.g., API + DB). Use containerized services if possible.
|
|
16
|
+
- **E2E Tests**: Simulate user journeys. Use Playwright/Cypress standards.
|
|
17
|
+
|
|
18
|
+
## 2. The AAA Pattern (Strict Enforcement)
|
|
19
|
+
Every test case MUST follow the **Arrange-Act-Assert** pattern structure explicitly.
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
// ā
CORRECT
|
|
23
|
+
it('should calculate total validation', () => {
|
|
24
|
+
// Arrange
|
|
25
|
+
const input = 10;
|
|
26
|
+
const expected = 20;
|
|
27
|
+
|
|
28
|
+
// Act
|
|
29
|
+
const result = calculate(input);
|
|
30
|
+
|
|
31
|
+
// Assert
|
|
32
|
+
expect(result).toBe(expected);
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 3. Naming Conventions
|
|
37
|
+
- **Files**: `*.test.ts` (Unit), `*.spec.ts` (E2E/Integration).
|
|
38
|
+
- **Descriptions**: Use "should [expected behavior] when [condition]".
|
|
39
|
+
- ā `test('login', ...)`
|
|
40
|
+
- ā
`test('should return 401 when token is expired', ...)`
|
|
41
|
+
|
|
42
|
+
## 4. Mocking & Isolation
|
|
43
|
+
- **No side effects**: Tests must be atomic and order-independent.
|
|
44
|
+
- **State reset**: Use `beforeEach`/`afterEach` to clean up state.
|
|
45
|
+
- **External calls**: NEVER rely on real 3rd party APIs in unit tests.
|
|
46
|
+
|
|
47
|
+
## 5. Agent Behavior
|
|
48
|
+
- If the user asks to "fix a bug", **ALWAYS** ask to write a reproduction test case first.
|
|
49
|
+
- If code coverage is low, proactively suggest adding missing test cases for edge conditions.
|