utg
npx machina-cli add skill recrsn/agent-skills/utg --openclawCheck the diff against origin/main, and generate unit tests for the changed code
in this branch. Run git fetch origin to make sure git context is up-to-date.
Here is the list of files changed in this branch:
!git diff --stat origin/main
Focus on generating tests for the changed code:
- Identify the functions/methods/classes that were added or modified
- Check if the changed code already has sufficient test coverage by looking at existing tests and coverage reports
- If coverage is low for the changed code, prioritize generating tests for those areas
- Only generate tests for logic changes, not data structure changes or formatting changes
- Generate unit tests that cover the new or changed functionality
- Ensure tests cover edge cases and error handling for the changed code
- Use the project's existing test framework and conventions
- Run the test suite with coverage after generating tests, and add more tests if coverage for changed code is low
Testing guidelines:
- Tests should be isolated and not depend on external systems
- Use mocks/stubs for dependencies as needed
- Do not mock logging or telemetry calls
- Only test from the public API of modules/classes, do not test private/internal methods directly
- Follow existing test style and conventions in the codebase
Overview
UTG analyzes the branch diff against origin/main to identify added or modified code. It then generates unit tests targeting the changed logic, prioritizing gaps in coverage and following the project’s testing conventions to validate edge cases and error handling.
How This Skill Works
UTG fetches origin, compares with origin/main, and catalogs changed functions, methods, and classes. It generates unit tests for the altered logic (excluding formatting or data-structure-only changes), uses mocks for dependencies, and runs the suite with coverage to confirm improvements, iterating when coverage remains low.
When to Use It
- When opening a PR that modifies code, to ensure tests cover the changed logic
- When coverage reports show low coverage for recently changed areas
- When new or updated functions/classes are added in the branch
- When edge cases or error handling were introduced or altered
- When you want to validate tests don’t mock logging or telemetry and follow public API testing only
Quick Start
- Step 1: Run or invoke UTG to compare the branch against origin/main (git fetch origin and diff)
- Step 2: UTG identifies changed logic and generates unit tests following existing conventions
- Step 3: Run the test suite with coverage and iterate to raise coverage for changed code
Best Practices
- Test focus on public APIs; do not target private/internal methods
- Isolate tests with mocks/stubs for dependencies; do not mock logging or telemetry
- Prioritize tests for logic changes; skip formatting or data-structure-only changes
- Follow the project’s existing test style and framework conventions
- Run the test suite with coverage and add tests if coverage for changed code is low
Example Use Cases
- Changed authentication flow: generate tests for login, logout, and token refresh paths
- Updated a calculation utility: create tests for typical inputs, edge cases, and error handling
- Modified an API boundary: add tests for valid/invalid inputs and exception cases
- Refactored a function’s internal structure but kept its public behavior; generate tests for public outcomes only
- If coverage tooling reports gaps in changed modules, generate targeted tests to boost coverage