XMC Feature Development
Guides agents through feature development, code refactoring, Bazel test matrix execution, coverage measurement, and pre-commit verification.
Warnings for the author
- "name" should use lowercase letters, digits and single hyphens only
- "name" should match the name of the directory that holds SKILL.md
- Not listed through the skills extension: the directory must be named after the skill.
Feature Development & Refactoring Playbook
This skill provides step-by-step procedures for implementing new features, refactoring existing code, running test matrices, measuring coverage, and preparing changes for PR submission.
[!IMPORTANT] All execution steps in this skill MUST strictly adhere to the policy rules defined in Core Engineering Standards and Skills & Automation Guidelines.
Guidelines for Using CLI Tools
When invoking helper tools under tools/ (e.g., run_affected_tests.py):
- Do not read tool source code: Do not open or read the Python source code of helper tools. Refer to Skills & Automation Guidelines.
- Use
--help: Run tools with--helpto inspect parameters and usage. - Parse Structured Output & Handle Errors: All tools output structured JSON; check the exit code per Helper Tool Exit Codes.
- Shell & Payload Safety: Execute standalone
.pyscript files or pass arguments via script parameters. Avoid double-quoted inline commands (python3 -c "...").
1. Requirements Scoping & Package Identification
- Scope Task & Identify Modified Files:
- Analyze user request and identify target packages/directories (e.g.,
pkg/auth/oauth2,cmd/xid_service). - Identify existing 1-to-1 unit test files (e.g.,
handlers_test.goforhandlers.go). If missing, plan to create a dedicated unit test file. - Search for existing implementations before planning new code:
git grepthe capability (in-repo packages,tools/), then check the standard library and declared dependencies, per the Reuse-First Policy.
- Analyze user request and identify target packages/directories (e.g.,
- Dependency & Target Discovery:
- Inspect the CI-equivalent affected test scope (including reverse dependencies and any UI/Helm suites under
other_suites) without running tests:python3 ./tools/run_affected_tests.py --dry-run - To list affected
go_binarytargets for a specific package when needed:bazel query "kind(go_binary, rdeps(//..., //pkg/auth/oauth2/...))"
- Inspect the CI-equivalent affected test scope (including reverse dependencies and any UI/Helm suites under
2. Code Implementation & Clean Code Design
- Apply SRP & KISS:
- Keep functions focused and under the 20–30 line target cap.
- Use early return guard clauses at the top of functions; eliminate redundant
elseblocks after returns. - Prefer default immutability (
constin TypeScript, value receivers or immutable structs where applicable).
- Decouple Mocks & Baseline Test Fixtures:
- Centralize shared helpers in global/shared packages.
- Define baseline test fixtures and express test cases as concise deltas (e.g., using
prototest.Modify).
- Test Inputs for Parsers & Pollers:
- Parsers and linters: Test against the most complex real-world constructs in the target corpus (e.g., for Markdown: nested or long code fences, redirects, URLs, labels; for any parser: empty, malformed, and multibyte inputs), rather than only minimal synthetic inputs.
- Polling and wait tools: Test every state transition, including the exact deadline boundary.
- Open-Source Code TODOs:
- Ensure inline
TODOcomments in public packages useTODO:or public issue linksTODO(#123), avoiding internal bug IDs.
- Ensure inline
3. Test Execution via Affected Tests Tool
- Run Affected Tests Script:
Execute the automated affected tests runner to resolve all changed files since
origin/main(including uncommitted and untracked files) viaresolve_test_scope.pyand runbazel teston affected targets with CI-equivalent flags:python3 ./tools/run_affected_tests.py- Output & Exit Codes: stdout emits structured JSON (
changed_files,backend_mode,reason,bazel_targets,other_suites,passed_targets); Bazel output streams to stderr. Exits0when tests pass (or dry-run / nothing to run),1on test failures or handled errors (with failed targets and log paths indetails), and2on unexpected errors. - Spanner Emulator: Pre-flights
SPANNER_EMULATOR_HOST(defaultlocalhost:9010) and forwards non-default addresses via--test_env. Pass--skip-emulator-checkwhen affected targets do not use Spanner. - Other Suites: When
other_suiteslists the UI or Helm chart suite, run those suites before opening a PR:bazel test //cmd/ui/...(afternpm ci --legacy-peer-depsincmd/ui) orbazel test //test/helm/....
- Output & Exit Codes: stdout emits structured JSON (
- Targeted Package Iteration (During Editing):
Never run hostbazel test //pkg/auth/oauth2/... bazel query 'tests(//pkg/auth/oauth2/...)' # list target names; never guess themgo build,go vet, orgo test. They fail on the Bazel-generated protobuf packages.
4. Code Coverage Measurement
- Execute Bazel Coverage:
Run coverage evaluation for the target package:
bazel coverage --combined_report=lcov //pkg/auth/oauth2/... - Parse & Verify Coverage:
- Locate the coverage output at
bazel-out/_coverage/_coverage_report.dat. - Verify that 100% of newly added or modified lines of business logic are covered by unit tests.
- Ensure 1-to-1 test file cohesion (each source file must have a dedicated
*_test.goor*_test.pyfile).
- Locate the coverage output at
5. Pre-Commit Verification & Staging
- Stage, Then Run Pre-Commit Hooks:
Before committing code changes, stage them and run the repository pre-commit script, which formats files, auto-restages formatter fixes to fully staged files, runs linters, and executes
run_affected_tests.py --skip-emulator-check:git add <changed_paths> ./.githooks/pre-commit - Verify Linter & Affected Test Status: Ensure all linters and affected unit tests pass without errors or warnings.
- Proceed to PR Creation: Refer to the XMC Create PR Skill to format the commit message and submit a Pull Request.
Files of this skill
This skill has no supporting files.