Communitygithub.com

cdcoonce/Portfolio_Website

测试驱动开发,遵循红-绿-重构循环。当用户希望使用 TDD 构建功能、修复 Bug、提到“红-绿-重构”、需要集成测试或要求测试优先开发时使用。

Portfolio_Website 是什么?

该技能实现了严格的测试驱动开发(TDD)流程,基于“红-绿-重构”循环,专为需要以测试为先的方法构建功能或修复 Bug 的开发者设计。它的核心哲学是:测试应通过公共接口验证行为,而非实现细节。好测试是集成式的,像规范一样描述“系统做什么”;坏测试则耦合于实现,在重构时会无故失败。技能明确反对“水平分片”反模式(即先批量写所有测试,再批量写所有实现),主张采用“垂直分片”的曳光弹方法——一次只写一个测试,然后编写刚好能通过的代码,如此迭代。工作流包括规划阶段(与用户确认接口变更和优先行为)、曳光弹阶段(编写第一个端到端测试)、增量循环阶段(一次一个测试,最小代码通过),以及重构阶段(仅在全部测试通过后进行)。每个循环都配有检查清单,确保测试仅关注公共接口且能抵御重构。该技能适用于任何支持 TDD 的编程语言和框架,并附带对测试示例、模拟指南、深层模块设计、接口可测试性及重构的深入参考。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/cdcoonce/Portfolio_Website/tree/HEAD/.claude/skills/tdd

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

测试驱动开发

核心理念

核心原则:测试应通过公共接口验证行为,而非实现细节。代码可以完全改变,测试不应改变。

好测试是集成式的:它们通过公共 API 执行真实的代码路径。它们描述系统做什么,而不是如何做。一个好的测试读起来像一份规范——“用户可以使用有效购物车结账”准确告诉你存在什么能力。这些测试在重构后依然有效,因为它们不关心内部结构。

坏测试与实现耦合。它们模拟内部协作对象、测试私有方法,或通过外部手段验证(例如直接查询数据库而非使用接口)。警示信号:当你重构时测试失败,但行为并未改变。如果你重命名了一个内部函数而测试失败,那些测试是在测试实现,而不是行为。

参见 tests.md 获取示例,mocking.md 获取模拟指南。

反模式:水平分片

不要先写所有测试,然后写所有实现。这是“水平分片”——把 RED 阶段当作“编写所有测试”,把 GREEN 阶段当作“编写所有代码”。

这会产生垃圾测试:

  • 批量编写的测试测试的是想象的行为,而非实际的行为
  • 你最终测试的是事物的形状(数据结构、函数签名),而不是面向用户的行为
  • 测试对真实变化不敏感——行为破坏时测试通过,行为正常时测试失败
  • 你超出了自己的视野,在理解实现之前就确定了测试结构

正确方法:通过曳光弹实现垂直分片。一个测试 → 一个实现 → 重复。每个测试回应你在上一个周期中学到的东西。因为你刚刚编写了代码,所以确切知道什么行为重要以及如何验证它。

错误(水平):
  RED:   test1, test2, test3, test4, test5
  GREEN: impl1, impl2, impl3, impl4, impl5

正确(垂直):
  RED→GREEN: test1→impl1
  RED→GREEN: test2→impl2
  RED→GREEN: test3→impl3
  ...

工作流

1. 规划

在编写任何代码之前:

  • 与用户确认需要哪些接口变更
  • 与用户确认要测试哪些行为(确定优先级)
  • 识别可以应用深层模块的机会(小接口,深实现)
  • 为可测试性设计接口
  • 列出要测试的行为(不是实现步骤)
  • 获取用户对计划的批准

询问:“公共接口应该是什么样的?哪些行为最重要需要测试?”

你不可能测试所有东西。 与用户确认确切哪些行为最重要。将测试工作集中在关键路径和复杂逻辑上,而不是每一个可能的边界情况。

2. 曳光弹

编写一个测试,确认系统的一个方面:

RED:   编写第一个行为的测试 → 测试失败
GREEN: 编写最小代码通过 → 测试通过

这是你的曳光弹——证明路径端到端可用。

3. 增量循环

对于每个剩余行为:

RED:   编写下一个测试 → 失败
GREEN: 最小代码通过 → 通过

规则:

  • 一次一个测试
  • 只编写足以通过当前测试的代码
  • 不要预见未来的测试
  • 保持测试关注可观察的行为

4. 重构

在所有测试通过后,寻找重构候选:

  • 提取重复代码
  • 深化模块(将复杂度隐藏在简单接口背后)
  • 在自然的地方应用 SOLID 原则
  • 考虑新代码揭示了现有代码的什么信息
  • 每个重构步骤后运行测试

永远不要在 RED 状态下重构。 先回到 GREEN。

每个周期的检查清单

[ ] 测试描述的是行为,而不是实现
[ ] 测试只使用公共接口
[ ] 测试在内部重构后仍然有效
[ ] 代码对于此测试是最小的
[ ] 没有添加投机性的功能

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

cdcoonce/Portfolio_Website

Git commit workflow with enforced conventional commit style. Use when Claude needs to stage and commit changes, craft commit messages, or the user asks to commit, make a commit, or save their work. Ensures consistent commit message format, proper scoping, and atomic commits across the project.

cdcoonce/Portfolio_Website

AI-powered code quality analysis for Python, Markdown, and Mermaid diagrams. Use this skill when: (1) reviewing code for quality issues, (2) checking Python files for PEP8 violations, unused code, missing type hints, docstring problems, complexity issues, or potential runtime errors, (3) validating Markdown documentation for broken links, heading structure, or formatting issues, (4) validating Mermaid diagram syntax, (5) the user asks for a "code review" or "quality check", (6) analyzing code snippets pasted in conversation, or (7) suggesting and applying fixes for code quality issues.

cdcoonce/Portfolio_Website

Deploy the portfolio chat agent Lambda function to AWS. Use when the user asks to deploy, redeploy, push to Lambda, update the chat agent, or after updating context files or lambda_function.py. Rebuilds the knowledge base, packages dependencies, and deploys to AWS Lambda.

cdcoonce/Portfolio_Website

Generate multiple radically different interface designs for a module using parallel sub-agents. Use when user wants to design an API, explore interface options, compare module shapes, or mentions "design it twice".

cdcoonce/Portfolio_Website

Orchestrate the full GitHub-issues-driven development lifecycle. 7-phase pipeline from brainstorm through PR with state tracking and cross-conversation resume. Use when user says "dev cycle", "development workflow", "full development pipeline", or invokes /dev-cycle.

cdcoonce/Portfolio_Website

Production Python coding standards with automatic version detection (3.10-3.13). Use when writing, reviewing, or refactoring Python to ensure adherence to modern type syntax, LBYL exception handling, pathlib operations, ABC-based interfaces, and production-tested patterns. Not Dagster-specific - applies to any Python project.

cdcoonce/Portfolio_Website

Set up Claude Code hooks to block dangerous git commands (push, reset --hard, clean, branch -D, etc.) before they execute. Use when user wants to prevent destructive git operations, add git safety hooks, or block git push/reset in Claude Code.

cdcoonce/Portfolio_Website

GitHub CLI (gh) integration for managing issues, pull requests, branches,

cdcoonce/Portfolio_Website

Interview the user relentlessly about a plan or design until reaching shared understanding, resolving each branch of the decision tree. Use when user wants to stress-test a plan, get grilled on their design, or mentions "grill me".

cdcoonce/Portfolio_Website

Explore a codebase to find opportunities for architectural improvement, focusing on making the codebase more testable by deepening shallow modules. Use when user wants to improve architecture, find refactoring opportunities, consolidate tightly-coupled modules, or make a codebase more AI-navigable.

cdcoonce/Portfolio_Website

CEO/founder-mode plan review. Rethink the problem, find the 10-star product, challenge premises, expand scope when it creates a better product. Three modes: SCOPE EXPANSION (dream big), HOLD SCOPE (maximum rigor), SCOPE REDUCTION (strip to essentials). Use when the user asks for a plan review, CEO review, mega review, or wants a plan challenged/stress-tested before implementation.

cdcoonce/Portfolio_Website

Break a PRD into independently-grabbable GitHub issues using tracer-bullet vertical slices. Use when user wants to convert a PRD to issues, create implementation tickets, or break down a PRD into work items.

cdcoonce/Portfolio_Website

Turn a PRD into a multi-phase implementation plan using tracer-bullet vertical slices, saved as a local Markdown file in docs/plans/. Use when user wants to break down a PRD, create an implementation plan, plan phases from a PRD, or mentions "tracer bullets".

cdcoonce/Portfolio_Website

Generate or update the `.claude/docs/project.md` file that gives Claude project-specific context. Use this skill when the user asks to create, update, regenerate, or refresh project context, or says things like "update project.md", "generate project context", "this repo needs a project.md", or "Claude doesn't know about this project". Also trigger when onboarding Claude to a new repository for the first time.

cdcoonce/Portfolio_Website

Generate comprehensive, high-quality README.md files for code repositories. Use this skill whenever the user asks to create, write, generate, update, or improve a README for any project or repository. Also trigger when the user says things like "document this project", "write docs for this repo", "this repo needs a README", "help me onboard developers to this codebase", or asks for project documentation in markdown. Even if the user just says "README" or "readme" in the context of a codebase, use this skill.

cdcoonce/Portfolio_Website

Create a detailed refactor plan with tiny commits via user interview, then file it as a GitHub issue. Use when user wants to plan a refactor, create a refactoring RFC, or break a refactor into safe incremental steps.

cdcoonce/Portfolio_Website

Set up pre-commit hooks for the current repo. Use when user wants to add pre-commit hooks, configure commit-time linting, formatting, type checking, or testing. Triggers on "pre-commit", "git hooks", "linting hooks", or /setup-pre-commit.

cdcoonce/Portfolio_Website

Triage a bug or issue by exploring the codebase to find root cause, then create a GitHub issue with a TDD-based fix plan. Use when user reports a bug, wants to file an issue, mentions "triage", or wants to investigate and plan a fix for a problem.

cdcoonce/Portfolio_Website

Rewrites the prose sections of wiki pages in-place. Reads source files to understand current context, then updates only the content inside <!-- claude:prose --> ... <!-- claude:prose:end --> markers. Never touches <!-- generated:start --> ... <!-- generated:end --> blocks. Supports targeting a single page with /update-wiki {PageName}.

cdcoonce/Portfolio_Website

Create a PRD through user interview, codebase exploration, and module design, then submit as a GitHub issue. Use when user wants to write a PRD, create a product requirements document, or plan a new feature.

相关技能