Skip to content

docs: tighten tdd workflow red-green validation - #896

Merged
affaan-m merged 6 commits into
affaan-m:mainfrom
ToniDonDoni:codex/tdd-workflow-red-green-guards
Mar 29, 2026
Merged

affaan-m merged 6 commits into
affaan-m:mainfrom
ToniDonDoni:codex/tdd-workflow-red-green-guards

Conversation

@ToniDonDoni

@ToniDonDoni ToniDonDoni commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

Why

In practice, the current tdd-workflow wording still leaves room for ambiguous behavior:

  • moving into implementation before RED is actually validated
  • treating unrelated build/setup failures as valid RED
  • not making it clear that compile-time RED can be legitimate when a new test first instantiates buggy code

What Changed

  • require a validated RED before modifying production code
  • clarify that RED must come from the intended bug, not unrelated setup/regression issues
  • explicitly allow compile-time RED when a new test first exposes the buggy code path
  • document a compact Git checkpoint flow: test + RED, fix + GREEN, optional refactor

Summary by cubic

Refines the TDD workflow docs to require a validated RED before any production changes, with clear runtime vs compile-time criteria and guards against unrelated failures. Adds a Git checkpoint flow with commit-after-RED and defer-fix-until-GREEN rules, scoped to commits on the current active branch and reachable from HEAD, no squashing until complete, plus compact message templates that capture evidence; separate evidence-only commits aren’t needed when RED/GREEN is shown.

Written for commit 9cc5d08. Summary will update on new commits.

Summary by CodeRabbit

  • Documentation
    • Added a “Git Checkpoints” requirement: create immutable checkpoint commits after each TDD stage (RED, implement/GREEN, refactor) and avoid squashing/rebasing until the workflow completes.
    • Tightened evidence rules: checkpoint commits must be reachable from current HEAD on the active branch; other branches/history excluded.
    • Clarified RED/GREEN rules: RED must be demonstrated by executed runtime or deliberate compile-time failures (not unrelated errors); do not edit production code before RED. Re-run the same test target to verify GREEN before refactor.

@coderabbitai

coderabbitai Bot commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2e1322ee-b566-4623-bc3a-6143c4a10094

📥 Commits

Reviewing files that changed from the base of the PR and between fee93f2 and 9cc5d08.

📒 Files selected for processing (1)
  • skills/tdd-workflow/SKILL.md
✅ Files skipped from review due to trivial changes (1)
  • skills/tdd-workflow/SKILL.md

📝 Walkthrough

Walkthrough

Adds a "Git Checkpoints" section to the TDD workflow requiring checkpoint commits after RED (mandatory for production changes), after GREEN (confirming the same test target), and after REFACTOR; tightens RED/GREEN validation rules, forbids editing production code before RED confirmation, and recommends checkpoint commit messages.

Changes

Cohort / File(s) Summary
TDD Workflow Documentation
skills/tdd-workflow/SKILL.md
Introduce "Git Checkpoints": require checkpoint commits after RED, after GREEN, and after REFACTOR; clarify valid RED (runtime vs compile-time) and exclude unrelated failures; forbid production edits before RED; require rerunning the same test target for GREEN; recommend checkpoint commit message formats and when evidence-only commits are unnecessary.

Sequence Diagram(s)

sequenceDiagram
  participant Dev as Developer
  participant Test as Test Runner
  participant Git as Git Repo
  participant Prod as Production Code

  Dev->>Test: Add failing test that exercises buggy path
  Test->>Dev: Fails (runtime RED) or fails to compile as intended (compile-time RED)
  Dev->>Git: Create RED checkpoint commit (`test: add reproducer...`)
  Dev->>Prod: Implement minimal change (no prod edits before RED)
  Dev->>Test: Rerun the same relevant test target
  Test->>Dev: Previously failing test passes (GREEN)
  Dev->>Git: Create GREEN checkpoint commit (`fix: ...`)
  Dev->>Prod: Refactor while tests remain green
  Dev->>Test: Run tests to confirm green
  Test->>Dev: Tests remain green
  Dev->>Git: Create REFACTOR checkpoint commit (`refactor: ...`)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nudged a test until it said "RED",
Held paws from code until the failure was read.
Fixed with care, watched the green light glow,
Tidied the burrow while all tests flow.
Checkpoints hop by hop—my trail in a row.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly summarizes the main change: tightening TDD workflow validation rules for red-green stages, which matches the core focus of adding stricter RED validation requirements and Git checkpoint flow.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps

greptile-apps Bot commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR tightens the tdd-workflow skill by adding an explicit RED gate, clarifying compile-time vs runtime RED, and introducing a compact Git checkpoint flow (RED commit → GREEN commit → optional refactor commit) across Steps 3–6.

  • RED gate (Step 3): Production code must not be modified until a valid RED is confirmed — either runtime (test executes and fails) or compile-time (new test exposes the buggy path). Unrelated failures (broken setup, missing deps, unrelated regressions) are explicitly excluded.
  • Git Checkpoints (new Core Principle §4): Immutable checkpoint commits after each TDD stage; no squash/rewrite until the cycle is complete. Compact three-commit flow: test: for RED, fix:/feat: for GREEN, refactor: for cleanup.
  • Step 4 deferred commit: Implementation is staged but the commit is deferred until GREEN is confirmed in Step 5, preventing broken state from landing in history.
  • Step 5 GREEN template and Step 6 refactor template both now accommodate <feature or bug> placeholders.
  • Minor issue: The GREEN checkpoint template (fix: <feature or bug>) uses fix: as the commit type for both bug fixes and new features, which conflicts with the project's conventional commit types (feat: for new features, fix: for patches). Consider splitting the template into two variants.

Confidence Score: 4/5

  • Safe to merge after correcting the GREEN checkpoint commit-type template to distinguish feat: (new features) from fix: (bug patches).
  • The PR directly addresses the most significant prior concerns (premature Step-4 commit, bug-scoped commit template placeholders, missing GREEN template). The remaining issue is a single P2 nit: the GREEN checkpoint template conflates fix: with feat:, which contradicts the project's own AGENTS.md commit-type conventions. One targeted fix brings this to merge-ready.
  • skills/tdd-workflow/SKILL.md — line 150: GREEN checkpoint commit-type template

Important Files Changed

Filename Overview
skills/tdd-workflow/SKILL.md Tightens the TDD workflow with a mandatory RED gate, compile-time/runtime RED distinction, and Git checkpoint commit flow across Steps 3–6. The changes are well-structured and address prior concerns; one minor issue remains: the GREEN checkpoint template uses fix: for both bug fixes and new features, which conflicts with the project's conventional commit types.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A([Start TDD Cycle]) --> B[Step 1-2: Write User Journeys\nand Generate Test Cases]
    B --> C[Step 3: Run Tests]
    C --> D{Valid RED?}
    D -->|Unrelated failure\ne.g. broken setup| C
    D -->|Runtime RED\ntest executes and fails| E
    D -->|Compile-time RED\nnew test exposes buggy path| E
    E[🔴 RED Validated] --> F["Git Checkpoint\n`test: add reproducer for <feature or bug>`"]
    F --> G[Step 4: Implement Minimal Fix\nStage changes — defer commit]
    G --> H[Step 5: Run Tests Again]
    H --> I{GREEN?}
    I -->|Still failing| G
    I -->|All pass| J[✅ GREEN Validated]
    J --> K["Git Checkpoint\n`feat: implement <feature>` or `fix: resolve <bug>`"]
    K --> L[Step 6: Refactor\nKeep tests green]
    L --> M[Step 7: Verify Coverage\n80%+ required]
    M --> N{"Coverage\n≥ 80%?"}
    N -->|No| L
    N -->|Yes| O["Optional Git Checkpoint\n`refactor: clean up after <feature or bug> implementation`"]
    O --> P([TDD Cycle Complete])
Loading

Reviews (6): Last reviewed commit: "adjust: scope tdd checkpoints to active ..." | Re-trigger Greptile

Comment thread skills/tdd-workflow/SKILL.md Resolved
Comment thread skills/tdd-workflow/SKILL.md Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
skills/tdd-workflow/SKILL.md (1)

100-118: Strong RED-gate validation that addresses all PR objectives.

This enhancement provides comprehensive guidance that prevents common TDD pitfalls:

  • Distinguishes intended failures from unrelated issues (lines 106-108)
  • Explicitly allows compile-time RED when exposing the bug (line 107)
  • Prevents premature production changes (line 112)
  • Requires actual test execution (line 110)

The Git checkpoint guidance (lines 114-118) with recommended commit format is clear and actionable.

✨ Minor style refinement

Line 102 could be slightly more concise:

-Before modifying business logic or other production code, you must verify all of the following:
+Before modifying business logic or other production code, you must verify the following:

This addresses the static analysis style hint, though the current wording is perfectly clear.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@skills/tdd-workflow/SKILL.md` around lines 100 - 118, The paragraph starting
"This step is mandatory and is the RED gate for all production changes." is a
bit wordy; please tighten that sentence for style by combining redundant phrases
and using a more concise construction (e.g., "This step is the mandatory RED
gate for production changes.")—edit the SKILL.md content around that sentence to
use the shorter phrasing while keeping all existing validation bullets and the
Git checkpoint guidance unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@skills/tdd-workflow/SKILL.md`:
- Around line 100-118: The paragraph starting "This step is mandatory and is the
RED gate for all production changes." is a bit wordy; please tighten that
sentence for style by combining redundant phrases and using a more concise
construction (e.g., "This step is the mandatory RED gate for production
changes.")—edit the SKILL.md content around that sentence to use the shorter
phrasing while keeping all existing validation bullets and the Git checkpoint
guidance unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 18caaee5-d57b-4673-b4dd-f1401b2f8913

📥 Commits

Reviewing files that changed from the base of the PR and between 2166d80 and 39a34e4.

📒 Files selected for processing (1)
  • skills/tdd-workflow/SKILL.md

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="skills/tdd-workflow/SKILL.md">

<violation number="1" location="skills/tdd-workflow/SKILL.md:103">
P2: Step 3 defines contradictory RED criteria by requiring successful compilation while also allowing compile-time RED failures.</violation>
</file>

Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread skills/tdd-workflow/SKILL.md Resolved
ToniDonDoni and others added 2 commits March 25, 2026 02:07
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
skills/tdd-workflow/SKILL.md (2)

103-103: Consider consolidating redundant compile-time RED explanations.

Lines 103 and 107 both explain when compile-time RED is valid. The guidance would be clearer with a single, consolidated explanation.

♻️ Proposed consolidation

Merge the concepts into line 103 and remove line 107:

-Before modifying business logic or other production code, you must verify all of the following:
-- The relevant test target compiles successfully, or the compile failure is itself the RED signal (i.e., the new test instantiates the buggy code path and a compile-time RED is the intended failure)
+Before modifying business logic or other production code, you must verify all the following:
+- The relevant test target compiles successfully, or the compile failure is itself the RED signal when the new test newly instantiates, references, or exercises the buggy code path and exposes the intended defect
 - The new or changed test is actually executed
 - The result is RED
 - The failure is caused by the intended business-logic bug, undefined behavior, or missing implementation
-- A compile-time RED is valid if the new test newly instantiates, references, or exercises the buggy code path and exposes the intended defect
 - The failure is not caused only by unrelated syntax errors, broken test setup, missing dependencies, or unrelated regressions

This also addresses the LanguageTool suggestion to use "all the following" for conciseness.

Also applies to: 107-107

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@skills/tdd-workflow/SKILL.md` at line 103, Consolidate the two redundant
explanations about compile-time RED into a single sentence by merging the
content of the line starting "The relevant test target compiles successfully, or
the compile failure is itself the RED signal..." and removing the later
duplicate around line 107; rephrase to the concise form "All the following must
hold: the relevant test target compiles successfully, or a compile-time failure
is the intended RED (e.g., the new test instantiates the buggy code path)" so
the guidance is clear, non-redundant, and uses "all the following" as suggested
by LanguageTool.

108-108: Clarify "not caused only by" to avoid ambiguity.

The phrase "not caused only by" could be misinterpreted as allowing failures that are partially caused by unrelated issues. Consider rephrasing for clarity.

♻️ Proposed clarification
-- The failure is not caused only by unrelated syntax errors, broken test setup, missing dependencies, or unrelated regressions
+- The failure is not caused by unrelated syntax errors, broken test setup, missing dependencies, or unrelated regressions

Alternative if you want to be more explicit:

-- The failure is not caused only by unrelated syntax errors, broken test setup, missing dependencies, or unrelated regressions
+- The failure stems from the intended defect, not from unrelated syntax errors, broken test setup, missing dependencies, or unrelated regressions
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@skills/tdd-workflow/SKILL.md` at line 108, Reword the ambiguous phrase "not
caused only by" to a clearer statement that the failing test must be
attributable to the student's change rather than solely to unrelated issues;
replace the line with something like "The failure must be caused by the
student's change and not solely by unrelated syntax errors, broken test setup,
missing dependencies, or external regressions" so readers understand the failure
must primarily stem from the submitted change (reference the existing sentence
containing "not caused only by" in SKILL.md).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@skills/tdd-workflow/SKILL.md`:
- Line 103: Consolidate the two redundant explanations about compile-time RED
into a single sentence by merging the content of the line starting "The relevant
test target compiles successfully, or the compile failure is itself the RED
signal..." and removing the later duplicate around line 107; rephrase to the
concise form "All the following must hold: the relevant test target compiles
successfully, or a compile-time failure is the intended RED (e.g., the new test
instantiates the buggy code path)" so the guidance is clear, non-redundant, and
uses "all the following" as suggested by LanguageTool.
- Line 108: Reword the ambiguous phrase "not caused only by" to a clearer
statement that the failing test must be attributable to the student's change
rather than solely to unrelated issues; replace the line with something like
"The failure must be caused by the student's change and not solely by unrelated
syntax errors, broken test setup, missing dependencies, or external regressions"
so readers understand the failure must primarily stem from the submitted change
(reference the existing sentence containing "not caused only by" in SKILL.md).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 72755ac3-be8b-44ff-96ff-e8b5627b2705

📥 Commits

Reviewing files that changed from the base of the PR and between 39a34e4 and 46f6e36.

📒 Files selected for processing (1)
  • skills/tdd-workflow/SKILL.md

Comment thread skills/tdd-workflow/SKILL.md Resolved
Comment thread skills/tdd-workflow/SKILL.md Resolved
Comment thread skills/tdd-workflow/SKILL.md Resolved
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@affaan-m

Copy link
Copy Markdown
Owner

thanks for the pr. triaged and queued for maintainer review.

@ToniDonDoni

ToniDonDoni commented Mar 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Tested manually:
https://github.com/userver-framework/userver
commit 52f21daa3c90ac0cbe7ceb14af62688712106186 (origin/develop, origin/HEAD, develop

opencode run --model opencode/mimo-v2-pro-free "Use the tdd-workflow skill. Fix undefined behavior in LazySharedPtr."

Two commits added

root@7d179421adf5:/workspace/userver# git log | head -15                                
commit 518f6093abe552f077b2addc18f6252c871cd134
Author: Developer <dev@userver.dev>
Date:   Wed Mar 25 11:08:55 2026 +0000

    fix: leave moved-from LazySharedPtr empty after move and return *this from move assignment

commit d7fd33214d337ac6947da62ce14c91a3631ff706
Author: Developer <dev@userver.dev>
Date:   Wed Mar 25 11:06:24 2026 +0000

    test: add reproducer for LazySharedPtr move semantics UB

commit 52f21daa3c90ac0cbe7ceb14af62688712106186
Author: romankoshelev <romankoshelev@yandex-team.com>
Date:   Tue Mar 24 16:45:24 2026 +0300
root@7d179421adf5:/workspace/userver# 

Fix is in the 2nd commit

root@7d179421adf5:/workspace/userver# git diff HEAD~1
diff --git a/core/include/userver/utils/lazy_shared_ptr.hpp b/core/include/userver/utils/lazy_shared_ptr.hpp
index ba55fce0e..556d24320 100644
--- a/core/include/userver/utils/lazy_shared_ptr.hpp
+++ b/core/include/userver/utils/lazy_shared_ptr.hpp
@@ -56,7 +56,11 @@ public:
         : value_(other.value_.load()),
           shared_filled_(other.shared_filled_.load()),
           shared_(std::move(other.shared_)),
-          get_data_(std::move(other.get_data_)) {}
+          get_data_(std::move(other.get_data_))
+    {
+        other.value_.store(nullptr, std::memory_order_relaxed);
+        other.shared_filled_.store(true, std::memory_order_relaxed);
+    }
 
     /// @brief The copy assignment operator.
     /// @note Like copy-constructor, it does not generate pointers if `other` do
@@ -72,6 +76,9 @@ public:
         shared_filled_.store(other.shared_filled_.load(), std::memory_order_relaxed);
         shared_ = std::move(other.shared_);
         get_data_ = std::move(other.get_data_);
+        other.value_.store(nullptr, std::memory_order_relaxed);
+        other.shared_filled_.store(true, std::memory_order_relaxed);
+        return *this;
     }
 
     /// @brief Get a pointer to the data (may be null). Fetches the data on the
root@7d179421adf5:/workspace/userver# 

Tests are in the 1st commit

root@7d179421adf5:/workspace/userver# git diff d7fd33214d337ac6947da62ce14c91a3631ff706 52f21daa3c90ac0cbe7ceb14af62688712106186
diff --git a/core/src/utils/lazy_shared_ptr_test.cpp b/core/src/utils/lazy_shared_ptr_test.cpp
index 41d85d75c..8523f87a8 100644
--- a/core/src/utils/lazy_shared_ptr_test.cpp
+++ b/core/src/utils/lazy_shared_ptr_test.cpp
@@ -94,36 +94,4 @@ UTEST(LazySharedPtr, AssignmentLazy) {
     ASSERT_EQ(&*cache_move, &*ptr);
 }
 
-UTEST(LazySharedPtr, MoveAssignmentReturnsThis) {
-    auto ptr = std::make_shared<std::vector<int>>(std::vector<int>{1, 2, 3});
-    utils::LazySharedPtr<std::vector<int>> a(ptr);
-    utils::LazySharedPtr<std::vector<int>> b;
-    utils::LazySharedPtr<std::vector<int>> c;
-
-    // Chained move assignment must work (requires operator= to return *this)
-    c = (b = std::move(a));
-    ASSERT_EQ(*b, std::vector<int>({1, 2, 3}));
-    ASSERT_EQ(&*c, &*b);
-}
-
-UTEST(LazySharedPtr, MovedFromNonLazyIsEmpty) {
-    auto ptr = std::make_shared<std::vector<int>>(std::vector<int>{1, 2, 3});
-    utils::LazySharedPtr<std::vector<int>> original(ptr);
-    utils::LazySharedPtr<std::vector<int>> target(std::move(original));
-
-    // Moved-from object must be safely empty, not holding a dangling pointer
-    ASSERT_FALSE(static_cast<bool>(original));
-    ASSERT_EQ(original.Get(), nullptr);
-}
-
-UTEST(LazySharedPtr, MovedFromLazyIsEmpty) {
-    Cache cache({1, 2, 3});
-    auto original(utils::MakeLazyCachePtr(cache));
-    utils::LazySharedPtr<std::vector<int>> target(std::move(original));
-
-    // Moved-from object must be safely empty
-    ASSERT_FALSE(static_cast<bool>(original));
-    ASSERT_EQ(original.Get(), nullptr);
-}
-
 USERVER_NAMESPACE_END
root@7d179421adf5:/workspace/userver# 

@affaan-m
affaan-m merged commit b3a43f3 into affaan-m:main Mar 29, 2026
3 checks passed
FrancescoRosciano pushed a commit to FRosciano-Mambo/everything-claude-code that referenced this pull request Jun 1, 2026
…ed-green-guards

docs: tighten tdd workflow red-green validation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants