Communitygithub.com

cdcoonce/Portfolio_Website

基於測試驅動開發的紅-綠-重構循環。當使用者想要使用 TDD 建立功能、修正錯誤、提到「紅-綠-重構」、需要整合測試,或要求測試先行開發時使用。

Portfolio_Website 是什麼?

此技能實現了嚴格的測試驅動開發 (TDD) 工作流程,遵守「紅色-綠色-重構」循環。其核心理念是測試應透過公開介面驗證行為,而非實作細節:優秀的測試在重構時仍然有效,而糟糕的測試則因緊耦合於實作而容易在重構時失敗。技能明確反對「水平切片」的反模式(先寫所有測試再寫所有實作),並提倡「垂直切片」的曳光彈方法:一次一個測試、一次一個實作,逐步遞增。工作流程包含規劃階段(與使用者確認介面變更與行為優先順序)、曳光彈階段(第一個測試與最小實作建立端到端路徑)、增量循環(逐一測試/實作),以及重構階段(提取重複、深化模組、套用 SOLID 原則)。每個循環都附有檢查清單,確保測試聚焦於行為而非實作,僅使用公開介面,且不增加推測性功能。技能支援在 Claude Code、Cursor、Codex 等 AI 代理環境中使用。

相容平台~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.

相關技能