Subtest isolation

From bearcove/dodeca · View interactive version

Subtest isolation is an AI agent skill from the GitHub repository bearcove/dodeca. Create minimal subtests to isolate and fix complex bugs. Use when a test fails and the issue is buried in complexity.

How to use this skill

Skill file

Subtest Isolation Methodology

When a test fails with complex output or multiple issues, create a minimal subtest to isolate and fix ONE specific problem at a time.

When to Use This Approach

Use subtest isolation when:

Don't use for:

The Process

1. Identify the Specific Problem

Look at the failing test output and pinpoint EXACTLY what's wrong:

Example from test45:

Problem identified: Bottom box has all text overlapping incorrectly.
"center" text appearing at the very top instead of middle.

2. Create Minimal Reproduction

Create a new test file (e.g., test45b.pikchr) with ONLY the problematic element:

# test45b.pikchr - isolate the bottom box issue
box "rjust" rjust above "center" center "ljust" ljust above \
    "rjust" rjust below "ljust" ljust below big big

Key principles:

3. Verify It Fails the Same Way

Run the subtest and confirm it shows the SAME bug:

cargo run --example simple -- vendor/pikchr-c/tests/test45b.pikchr
# OR
mcp__pikru-test__run_pikru_test test45b

Check that:

4. Add Debug Output

Add targeted debug output to understand what's happening:

eprintln!("[SLOT HEIGHT] text='{}' slot={:?} font_scale={} charht={} h={}",
    text.value, slot, text.font_scale(), charht, h);

eprintln!("[Y OFFSET] text='{}' slot={:?} calc=[{}] y_offset={} final_y={}",
    positioned_text.value, slot, offset_calc, y_offset, center.y + svg_y_offset);

Debug output best practices:

5. Run and Analyze

Run the subtest and analyze the debug output:

cargo run --example simple -- vendor/pikchr-c/tests/test45b.pikchr 2>&1 | grep '\[SLOT'

Look for:

Example output that revealed the bug:

[SLOT HEIGHT] text='center' slot=Above2 font_scale=1 charht=0.14 h=0.14

→ BUG FOUND: "center" text assigned to Above2 instead of Center!

6. Compare with C Implementation

Run the C implementation on the same subtest:

vendor/pikchr-c/pikchr --svg-only vendor/pikchr-c/tests/test45b.pikchr | grep '<text'

Compare:

Example comparison:

C output:    <text y="38.16" ...>center</text>
Rust output: <text y="12.24" ...>center</text>

→ Confirms the bug: Rust placing center text way too high

7. Fix the Bug

Based on debug output and comparison:

  1. Identify the root cause
  2. Make the minimal fix needed
  3. Don't over-engineer - fix THIS bug only

Example fix:

// BUG: wasn't checking t.center
else if t.center {
    Some(TextVSlot::Center)  // ← FIX: explicitly assign Center slot
}

8. Verify Subtest Passes

Run the subtest again - it should now MATCH:

mcp__pikru-test__run_pikru_test test45b

Expect:

{"test_name":"test45b","status":"match","comparison":{"ssim":1.0, ...}}

9. Remove Debug Output

Clean up the debug statements you added:

// Remove all the eprintln! statements
// Keep the code clean for production

10. Verify Original Test Passes

Run the original test to confirm the fix works in context:

mcp__pikru-test__run_pikru_test test45

If it still fails:

If it passes:

11. Keep or Remove Subtest

Keep the subtest if:

Remove the subtest if:

Example: test45 → test45b

Original problem:

Subtest creation:

# test45b.pikchr - just the problematic box
box "rjust" rjust above "center" center "ljust" ljust above \
    "rjust" rjust below "ljust" ljust below big big

Debug output revealed:

[SLOT HEIGHT] text='center' slot=Above2 ...  ← WRONG! Should be Center

Root cause found:

Fix applied:

// Added center field to PositionedText
// Handle TextAttr::Center in parsing
// Check t.center when assigning initial slots

Result:

Tips and Tricks

Effective Debug Output

Show the calculation:

eprintln!("calc=[Above: 0.5*{} + 0.5*{} = {}]", hc, ha1, offset);

Track state transitions:

eprintln!("[BEFORE] slot={:?} y_offset={}", slot, y_offset);
// ... calculation ...
eprintln!("[AFTER] y_offset={} final_y={}", y_offset, final_y);

Use structured prefixes:

[SLOT HEIGHT]   // For slot height calculations
[Y OFFSET]      // For y-coordinate calculations
[ASSIGNMENT]    // For slot assignments
[FINAL]         // For final values

Iterative Refinement

If the first subtest doesn't reproduce the bug:

  1. Add back one element at a time
  2. Check what's needed to trigger the issue
  3. Keep the minimal set that shows the problem

Multiple Bugs

If you find multiple bugs:

  1. Fix them ONE at a time
  2. Create separate subtests for each
  3. Name them test45b, test45c, etc.
  4. Verify each fix independently

When It's Still Not Clear

If debug output doesn't reveal the issue:

  1. Add even MORE detailed logging
  2. Compare execution flow with C (use C debug output if available)
  3. Check if the bug is earlier in the pipeline (parsing vs rendering)
  4. Verify your assumptions about how the code should work

Checklist

Remember

The goal is laser focus:

Not:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.