Full bug fix cycle automation (issue creation โ branch โ fix โ PR)
Overview#
This workflow automates the entire bug issue fix cycle:
- Bug report creation (optional)
- Branch creation
- Bug fix work
- Unit test writing (frontend + backend)
- Test execution and verification
- PR creation and merge
Usage#
# ๊ธฐ์กด ๋ฒ๊ทธ ์ด์๋ก ์์
/dev:bugfix {issue_number}
# ์ ๋ฒ๊ทธ ๋ฆฌํฌํธ๋ถํฐ ์์
/dev:bugfix --new [์ด๋ฏธ์ง_๊ฒฝ๋ก] " ๋ฒ๊ทธ ์ค๋ช
"
Parameters#
| Parameter | Required | Description |
|---|---|---|
issue_number | โ * | Existing bug issue number |
--new | โ * | New bug report creation mode |
--no-merge | โ | PR creation only (no merge) |
--skip-tests | โ | Skip tests (for urgent hotfixes) |
--base | โ | Base branch (default: development) |
*Either issue_number or --new is required
Option Examples#
# PR only (no merge)
/dev:bugfix 123 --no-merge
# Skip tests (urgent)
/dev:bugfix 123 --skip-tests
# Change base branch
/dev:bugfix 123 --base main
# New bug + image analysis
/dev:bugfix --new /tmp/screenshot.png " App crash "
Execution Flow#
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ /dev:bugfix โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ Step 0: Blast Radius Analysis (before fix) โ
โ โโโ Identify all callers/dependents of affected code (Grep) โ
โ โโโ Map test coverage of affected areas โ
โ โโโ Flag untested areas that could regress โ
โ โโโ Risk assessment: โ
โ LOW (โค5 files) โ proceed โ
โ MED (5-15 files or multi-layer) โ confirm with user โ
โ HIGH ( > 15 files or core module) โ suggest /plan โ /build โ
โ โ
โ Step 1: Bug Report Creation (with --new option) โ
โ โโโ Call /bug-report (image analysis) โ
โ โโโ Create ZenHub issue โ
โ โโโ Result: obtain issue_number โ
โ โ
โ Step 2: Query Issue Info โ
โ โโโ mcp__zenhub__searchLatestIssues โ
โ โโโ Extract issue type, title, body โ
โ โโโ Analyze bug cause โ
โ โ
โ Step 3: Branch Creation โ
โ โโโ fix/{number}-{slug} format โ
โ โโโ issue-state-agent โ " In Progress " โ
โ โโโ Based on development branch โ
โ โ
โ Step 4: Bug Fix Work โ
โ โโโ Analyze issue body โ identify cause โ
โ โโโ Search related code โ
โ โโโ Fix code โ
โ โโโ Create incremental commits โ
โ โ
โ Step 4.5: Existing Test Verification (Baseline) โ
โ โโโ Run existing tests for related packages โ
โ โโโ On failure โ fix code or existing tests first โ
โ โโโ Record baseline pass rate โ
โ โ
โ Step 5: Test Writing (required, delegated to cc-flutter-dev) โ
โ โโโ Frontend tests โ
โ โ โโโ unit-test-agent โ UseCase parameter passing tests โ
โ โ โโโ bloc-test-agent โ BLoC state transition verification โ
โ โ โโโ widget-test-agent โ State copyWith rendering tests โ
โ โโโ Backend tests โ
โ โ โโโ Endpoint auth/permission tests โ
โ โ โโโ Filter parameter passing integration tests โ
โ โ โโโ Service logic unit tests (if applicable) โ
โ โโโ Create test commits โ
โ โ
โ Step 6: Test Execution and Regression Verification โ
โ โโโ Run all tests (existing + new) โ
โ โโโ Attempt auto-fix on failure (up to 3 times) โ
โ โโโ Verify baseline pass rate maintained โ
โ โ
โ Step 7: PR Creation โ
โ โโโ gh pr create โ
โ โโโ issue-state-agent โ " Review " โ
โ โโโ Auto-link issue (Closes #{number}) โ
โ โ
โ Step 8: Merge (unless --no-merge) โ
โ โโโ Wait for review โ
โ โโโ Squash merge โ
โ โโโ Issue auto-Close via GitHub " Closes # " keyword โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Detailed Implementation#
Step 0: Blast Radius Analysis#
Run before creating a branch to assess fix complexity and risk:
// 1. Identify affected code area from issue description
const affectedFiles = await Grep({ pattern: bugPattern, output_mode: " files_with_matches " });
// 2. Find all callers/dependents
const dependents = [];
for (const file of affectedFiles) {
const exports = extractExports(file); // classes, functions, mixins
for (const symbol of exports) {
const callers = await Grep({ pattern: symbol, output_mode: " files_with_matches " });
dependents.push(...callers);
}
}
const uniqueDependents = [...new Set(dependents)];
// 3. Map test coverage
const testFiles = await Glob({ pattern: " test/**/*_test.dart " });
const coveredFiles = matchSourceToTest(uniqueDependents, testFiles);
const uncoveredFiles = uniqueDependents.filter(f = > !coveredFiles.includes(f));
// 4. Risk assessment
const fileCount = uniqueDependents.length;
const layerCount = countLayers(uniqueDependents); // presentation, domain, data, backend
let riskLevel;
if (fileCount < = 5 & & layerCount < = 1) {
riskLevel = " LOW " ; // โ proceed directly
} else if (fileCount < = 15 || layerCount < = 2) {
riskLevel = " MEDIUM " ; // โ confirm with user
} else {
riskLevel = " HIGH " ; // โ suggest /plan โ /build workflow
}
Output:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Blast Radius Analysis โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ
โ Affected files: {fileCount} โ
โ Layers touched: {layers} โ
โ Test coverage: {coveredCount}/{totalCount} files covered โ
โ Uncovered areas: โ
โ - {uncoveredFile1} โ
โ - {uncoveredFile2} โ
โ Risk Level: {LOW|MEDIUM|HIGH} โ
โ โ
โ {recommendation} โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- LOW: ์๋ ์งํ
- MEDIUM: ์ฌ์ฉ์์๊ฒ ํ์ธ ์์ฒญ ("Proceed with bugfix?" / "Switch to /plan โ /build?")
- HIGH:
/plan โ /build์ํฌํ๋ก์ฐ ๊ถ์ฅ (๊ตฌ์กฐ์ ๋ณ๊ฒฝ์ด ํ์ํ ๊ฐ๋ฅ์ฑ ๋์)
Step 1: Bug Report Creation (Optional)#
When --new option is provided:
// /bug-report ์คํฌ ํธ์ถ
const bugReport = await Skill({
skill: " bug-report " ,
args: `${imagePath} " ${description} " `
});
// Extract created issue number
const issueNumber = bugReport.issue_number;
Step 2: Query Issue Info#
// Query issue info
const issueResult = await mcp__zenhub__searchLatestIssues({
query: issue_number.toString()
});
const issue = issueResult.find(i = > i.number === issue_number);
// Extract bug info
const bugInfo = {
id: issue.id,
number: issue.number,
title: issue.title,
body: issue.body, // Includes reproduction steps, expected/actual results
severity: extractSeverity(issue.labels),
area: extractArea(issue.labels),
};
Step 3: Branch Creation#
// Generate branch name: fix/{number}-{slug}
const slug = createSlug(bugInfo.title);
const branchName = `fix/${bugInfo.number}-${slug}`;
// Create branch
await Bash(`git checkout -b ${branchName} origin/development`);
// Pipeline move: In Progress
await mcp__zenhub__moveIssueToPipeline({
issueId: bugInfo.id,
pipelineId: inProgressPipelineId
});
Step 4: Bug Fix Work#
// Bug cause analysis
// 1. Identify reproduction steps from issue body
// 2. Search related code (Grep, Glob)
// 3. Infer cause
// Code fix
// - Modify related files
// - Create incremental commits
await Bash(`git commit -m " fix(${scope}): ๐ ${bugInfo.title} " `);
Step 5: Unit Test Writing (Required)#
Frontend + backend unit tests must be written before PR creation.
5-1. Frontend Tests
Write the following tests depending on the changed code area:
// State tests: copyWith, nullable field clearing, Equatable, etc.
// File: test/presentation/bloc/{feature}_state_test.dart
// - Verify initial state default values
// - Verify copyWith updates
// - Verify nullable field clearing (clearXxx flags)
// - Verify value preservation (existing values maintained on copyWith() call)
// BLoC tests: event handlers โ state transitions
// File: test/presentation/bloc/{feature}_bloc_test.dart
// - Verify per-event state transitions with blocTest()
// - Mock Repository setUp
// - Set initial state with seed()
// - Verify sequential state changes with expect()
// UseCase tests: parameter passing and error handling
// File: test/domain/usecase/{usecase}_test.dart
// - Verify correct parameter passing on Repository calls (verify)
// - Separate success/failure cases
// - Verify Params Equatable
5-2. Backend Tests
// Integration tests: using withServerpod()
// File: backend/kobic_server/test/integration/{feature}_test.dart
// - Auth test: reject unauthenticated access to requireLogin endpoints
// - Filter parameter passing test: verify correct calls per filter
// - Combined filter test: apply all filters simultaneously
// - Pagination test: pass limit/offset parameters
// Service unit tests (on business logic changes)
// File: backend/kobic_server/test/unit/{feature}/{service}_test.dart
5-3. Test Fixture Writing Rules
// Serverpod generated DTO classes have many required fields
// โ Create test fixtures via helper functions
// e.g.: _createTestBook(), _createCategory()
// Mock generation: @GenerateNiceMocks + build_runner
// โ Must regenerate mocks after writing test files
await Bash(`melos exec --scope=${package} -- dart run build_runner build -d`);
5-4. Test Commit
await Bash(`git commit -m " test(${scope}): โ
${bugInfo.title} ํ
์คํธ ์ถ๊ฐ " `);
Step 6: Test Execution and Verification#
// Run all tests
await Bash(`melos exec --scope=${package} -- flutter test`);
// Attempt auto-fix on failure
if (testFailed) {
// Fix fixtures (generated class signature mismatches, etc.)
// Build transitive dependencies (missing .g.dart, .module.dart)
// Regenerate mocks
// Re-run
}
// Verify all tests pass (required)
// Do not proceed with PR creation if tests fail
Step 7: PR Creation#
// Create PR
const prTitle = `fix(${scope}): ๐ ${bugInfo.title}`;
const prBody = `
## Summary
- ${bugInfo.title} bug fix
## Changes
- ${changesSummary}
## Test Plan
- [ ] Reproduction steps verified
- [ ] Tests passed
Closes #${bugInfo.number}
๐ค Generated with [Claude Code](https://claude.com/claude-code)
`;
await Bash(`gh pr create --title " ${prTitle} " --body " ${prBody} " `);
// Pipeline move: Review
await mcp__zenhub__moveIssueToPipeline({
issueId: bugInfo.id,
pipelineId: reviewPipelineId
});
Step 8: Merge#
// Squash merge โ issue auto-Close via GitHub " Closes # " keyword
// No Done pipeline move needed (merge = complete)
await Bash(`gh pr merge --squash --delete-branch`);
Output Format#
On Success#
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Bug Cycle Complete: #123 โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ
โ โ
โ ๐ Bug: [Bug] ๋ก๊ทธ์ธ: ์์
๋ก๊ทธ์ธ ๋ฒํผ ๋ฏธ๋์ โ
โ ๐ฟ Branch: fix/123-social-login-button โ
โ โ
โ ๐ Commits: โ
โ 1. fix(auth): ๐ ์์
๋ก๊ทธ์ธ ๋ฒํผ ํด๋ฆญ ํธ๋ค๋ฌ ์์ โ
โ 2. test(auth): โ
์์
๋ก๊ทธ์ธ ๋ฒํผ ํ
์คํธ ์ถ๊ฐ โ
โ โ
โ โ
Tests: โ
โ - FE State: 16/16 passed โ
โ - FE BLoC: 10/10 passed โ
โ - FE UseCase: 10/10 passed โ
โ - BE Integration: 10/10 passed โ
โ โ
โ ๐ PR: #456 โ
โ - URL: https://github.com/coco-de/kobic/pull/456 โ
โ - Status: Merged โ
โ
โ โ
โ ๐ Duration: 8m 15s โ
โ ๐ Final State: CLOSED (by merge) โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
On Failure#
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Bug Cycle Failed: #123 โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฃ
โ โ
โ โ Failed at: Step 4 (Bug fix work) โ
โ โ
โ Error Details: โ
โ - Cause identification failed: additional info needed โ
โ - Related code not found โ
โ โ
โ Current State: โ
โ - Branch: fix/123-social-login (exists) โ
โ - Commits: 0 โ
โ - Pipeline: In Progress โ
โ - PR: Not created โ
โ โ
โ Recovery Options: โ
โ 1. Request additional info on the issue โ
โ 2. Manually analyze cause then retry โ
โ 3. /dev:bugfix 123 --skip-tests โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
TodoWrite Integration#
Progress Tracking#
TodoWrite([
{ content: " Bug report creation " , status: " completed " , activeForm: " Bug report creation complete " },
{ content: " Issue info query " , status: " in_progress " , activeForm: " Querying issue info " },
{ content: " Branch creation " , status: " pending " , activeForm: " Branch creation pending " },
{ content: " Bug fix work " , status: " pending " , activeForm: " Bug fix pending " },
{ content: " Unit test writing (FE+BE) " , status: " pending " , activeForm: " Test writing pending " },
{ content: " Test execution and verification " , status: " pending " , activeForm: " Test execution pending " },
{ content: " PR creation " , status: " pending " , activeForm: " PR creation pending " },
{ content: " Merge and close " , status: " pending " , activeForm: " Merge pending " },
]);
Error Handling#
Step-by-Step Recovery Strategy#
| Failed Step | State | Recovery Method |
|---|---|---|
| Blast radius | No changes | Retry or switch to /plan โ /build |
| Bug report | No changes | Retry /bug-report |
| Branch creation | Issue exists | Retry |
| Bug fix | Branch exists | Manual fix then retry |
| Test writing | Code modified | Fix fixtures, regenerate mocks, build transitive deps |
| Test execution | Tests written | Manual test fix or --skip-tests |
| PR creation | Tests passed | Run gh pr create manually |
| Merge | PR exists | Wait for CI pass then retry |
Key Rules#
- Verify Bug Issue Type: Only process Bug type issues
- Branch Naming: Follow
fix/{number}-{slug}format - Commit Message:
fix({scope}): ๐ {description}format - Tests Required (before PR): Frontend (State/BLoC/UseCase) + Backend (integration/unit) tests must be written and passed before PR creation
- Separate Test Commits: Separate fix commits from test commits for easier review
- Issue Link: Include
Closes #{number}in PR - State Tracking: Update Pipeline state at every step
Related Commands#
/bug-report: Bug report creation/dev:issue: General issue cycle/zenhub:manage: ZenHub pipeline management
Related Agents#
issue-state-agent: Issue state managementimplementation-agent: Code implementationtest-runner-agent: Test executionpr-lifecycle-agent: PR management