AgentSkillsCN

build-fixer

系统性地诊断Python构建错误。当pytest失败、ruff报告错误、basedpyright发现类型问题,或uv出现依赖问题时,可使用此技能。

SKILL.md
--- frontmatter
name: build-fixer
description: Systematic Python build error diagnosis. Use when pytest fails, ruff reports errors, basedpyright finds type issues, or uv has dependency problems.

Build Fixer - Python

Systematic workflow for diagnosing and fixing Python build errors.

When to Use

  • Tests are failing (pytest errors)
  • Linting/formatting errors (ruff errors)
  • Type checking errors (basedpyright errors)
  • Dependency resolution issues (uv errors)

Diagnostic Workflow

Step 1: Identify the Tool

Error SourceIndicators
pytestFAILED, AssertionError, test_ in output
ruffError codes like E501, F401, I001
basedpyrighterror:, reportX codes, type annotations
uvResolutionFailure, PackageNotFound, lock file errors

Step 2: Run Diagnostics

bash
# Run all quality checks
uv run pytest -q                    # Tests
ruff check .                        # Linting
ruff format . --check               # Formatting
uv run basedpyright src tests       # Type checking

Step 3: Tool-Specific Diagnosis


pytest Errors

Common Patterns

ErrorCauseFix
AssertionErrorExpected vs actual mismatchCheck test logic or implementation
ImportErrorMissing dependency or wrong pathInstall package or fix import
AttributeErrorMethod/attribute doesn't existCheck API usage
fixture not foundMissing or misspelled fixtureAdd fixture or fix name
exit code 5No tests collectedCheck test file naming (test_*.py)

Diagnosis Steps

  1. Read full error output - Don't skim, read the entire traceback
  2. Identify failing test - Note file:line and test name
  3. Check assertion - Compare expected vs actual values
  4. Trace the problem:
    • Is the test wrong? (Update test)
    • Is the implementation wrong? (Fix implementation)
  5. Re-run to verify: uv run pytest tests/path/to/test.py::test_name -q

Verification

bash
uv run pytest -q                    # All tests pass
uv run pytest -q --tb=short         # With short tracebacks if debugging

ruff Errors

Common Error Codes

CodeMeaningAuto-fix?
E501Line too longNo - refactor needed
F401Unused importYes
F841Unused variableYes
I001Import order wrongYes
UPUse modern Python syntaxUsually yes

Diagnosis Steps

  1. Run with auto-fix first: ruff check . --fix
  2. For remaining errors, read the rule explanation
  3. For line length (E501):
    • Break long strings
    • Use intermediate variables
    • Split long function calls
  4. Re-run to verify: ruff check .

Verification

bash
ruff format .                       # Format code
ruff check . --fix                  # Fix what can be fixed
ruff check .                        # Verify clean (0 errors)

basedpyright Errors

Common Error Types

ErrorCauseFix
reportMissingTypeStubsNo type stubs for libraryAdd stubs or ignore
reportUnknownMemberTypeCan't infer typeAdd type annotation
reportArgumentTypeWrong argument typeFix argument or annotation
reportReturnTypeReturn type mismatchFix return or annotation
reportUnboundVariableVariable used before assignmentInitialize or check logic

Diagnosis Steps

  1. Read error message and file:line
  2. Check if type stub needed: Some libraries lack stubs
  3. Add type annotations where missing:
    python
    def func(arg: str) -> int:  # Add parameter and return types
    
  4. For complex types, use typing module:
    python
    from typing import Any, Optional, Union
    
  5. Re-run to verify: uv run basedpyright src tests

Verification

bash
uv run basedpyright src tests       # 0 errors

uv Errors

Common Error Types

ErrorCauseFix
ResolutionFailureConflicting dependenciesRelax version constraints
PackageNotFoundPackage doesn't existCheck spelling, use correct name
LockfileOutdatedLock file staleRegenerate lock
WheelBuildFailedBinary build failedCheck Python version, system deps

Diagnosis Steps

  1. For resolution failures:

    • Check pyproject.toml version constraints
    • Try uv lock --upgrade to refresh
    • Relax overly strict version pins
  2. For missing packages:

    • Verify package name on PyPI
    • Install: uv pip install package-name
  3. For lock file issues:

    bash
    uv lock --upgrade
    

Verification

bash
uv pip list                         # Check installed packages
uv lock --check                     # Verify lock file is current

Decision Tree

code
Build failed?
├─ pytest error?
│  ├─ AssertionError → Check test vs implementation
│  ├─ ImportError → Check imports and dependencies
│  └─ No tests collected → Check test naming (test_*.py)
│
├─ ruff error?
│  ├─ Auto-fixable? → Run `ruff check . --fix`
│  └─ Manual fix → Read rule, refactor code
│
├─ basedpyright error?
│  ├─ Missing types? → Add type annotations
│  ├─ Wrong types? → Fix implementation or annotation
│  └─ Missing stubs? → Add stubs or suppress
│
└─ uv error?
   ├─ Resolution failed? → Relax constraints, upgrade lock
   └─ Package not found? → Verify name on PyPI

Full Verification Sequence

Run all checks in order:

bash
# 1. Format
ruff format .

# 2. Lint
ruff check . --fix
ruff check .

# 3. Type check
uv run basedpyright src tests

# 4. Test
uv run pytest -q

# All must pass (0 errors, 0 failures)