跳到主要内容
知仓学习社ZHICANG

tdd-workflows-tdd-green

Implement the minimal code needed to make failing tests pass in the TDD green phase.

不碰外部(只输出文字)无严重或高危命中rmyndharis/antigravity-skills

它会碰到什么

扫了多少2 个文本文件,25 KB
它会碰到什么不碰外部(只输出文字)
命中总数0 处
命中统计严重 0 · 高 0 · 中 0 · 低 0

这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。

技能内容

Green Phase: Simple function

def product_list(request):

products = Product.objects.all()

return JsonResponse({'products': list(products.values())})

Refactor: Class-based view

class ProductListView(View):

def get(self, request):

products = Product.objects.all()

return JsonResponse({'products': list(products.values())})

Refactor: Generic view

class ProductListView(ListView):

model = Product

context_object_name = 'products'


### Express Patterns

**Inline → Middleware → Service Layer:**

// Green Phase: Inline logic

app.post('/api/users', (req, res) => {

const user = { id: Date.now(), ...req.body };

users.push(user);

res.json(user);

});

// Refactor: Extract middleware

app.post('/api/users', validateUser, (req, res) => {

const user = userService.create(req.body);

res.json(user);

});

// Refactor: Full layering

app.post('/api/users',

validateUser,

asyncHandler(userController.create)

);


## Use this skill when

- Moving from red to green in a TDD cycle
- Implementing minimal behavior to satisfy tests
- You want to keep implementation intentionally simple

## Do not use this skill when

- You are refactoring for design or performance
- Tests are already passing and you need new requirements
- You need a full architectural redesign

## Instructions

1. Review failing tests and identify the smallest fix.
2. Implement the minimal change to pass the next test.
3. Run tests after each change to confirm progress.
4. Record shortcuts or debt for the refactor phase.

## Safety

- Avoid bypassing tests to make them pass.
- Keep changes scoped to the failing behavior only.

## Resources

- `resources/implementation-playbook.md` for detailed patterns and examples.

想直接用这个技能?

本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。