--- name: fix-linter-test description: Debug and fix a failing MegaLinter linter test. Use when a linter test fails in CI or locally. allowed-tools: Read Grep Glob Bash Edit argument-hint: "[linter-name-or-test-output]" model: sonnet metadata: internal: true --- Debug the failing test for `$ARGUMENTS`. Steps: 1. Find the test file in `megalinter/tests/test_megalinter/linters/` 2. Check if it's auto-generated (has `@generated by .automation/build.py` header) — if so, fix the descriptor YAML or fixtures, NOT the test file itself 3. Read the descriptor YAML in `megalinter/descriptors/` to understand expected behavior (`cli_lint_mode`, `supported_cli_lint_modes`, `config_file_name`, `cli_lint_errors_regex`, `file_extensions`) 4. Check test fixtures in `.automation/test//`: - Good files must pass the linter cleanly - Bad files must trigger errors matching `cli_lint_errors_regex` - File extensions must match `file_extensions` or `file_names_regex` in the descriptor 5. If a custom linter class exists in `megalinter/linters/`, review it for issues 6. Common failure causes: - Fixture file extensions don't match descriptor's `file_extensions` - `cli_lint_errors_regex` doesn't match actual linter output format - Missing config file referenced in `config_file_name` - `cli_lint_mode` mismatch (file vs list_of_files vs project) - `supported_cli_lint_modes` lists a mode the tool can't run — the per-mode tests (`test_success__lint_mode` / `test_failure__lint_mode`) run for every declared mode; if a failure is confined to one mode, remove it from `supported_cli_lint_modes` (unsupported modes are auto-skipped) - Version pin broken or tool not installable in Dockerfile - Linter behavior differs between host OS and Docker container (Linux) - `test_success_project_lint_mode` fails on a file under `.wireit/`: that is a **poison fixture** guarding excluded-directories forwarding (see `.claude/rules/testing.md`). The forwarding is broken, not the fixture — check the command in the log for the forwarded exclusion arguments and the `[Excluded directories]` trace line, then review the descriptor's `cli_lint_mode_project_exclude_*` properties or the class `manage_excluded_directories_config()` / `build_lint_command` override (a custom `build_lint_command` that does not call `super()` bypasses forwarding). Do NOT delete the poison fixture to make the test pass - **Native test failure** (workflow `Test native mode`, `.github/workflows/test-native.yml`, jobs named ` #`): the same test classes run against linters installed by `native_install`, on Linux, macOS and Windows. Fix the native side, never the Docker `install` block, and keep fixtures valid for Docker (they are shared). Causes already met: - Windows output encoding: Python tools print in cp1252 on pipes (`PYTHONUTF8` is set by `megalinter/native/toolchain.py`) - Windows paths: `\` separators in regexes built by linter classes (match `[/\\]`), executables reporting `tool.exe 1.2.3` (`version_extract_regex`) - Windows line endings: a linter enforcing LF or CRLF depending on the OS; a native default config in `TEMPLATES/native/` overrides `TEMPLATES/` in native mode - A variable stripped by the environment allowlist (`ALLOWED_ENV_NAMES` in `toolchain.py`): add system variables there, secrets never - Lock not covering the platform (gem platforms, assets): regenerated by the `Native locks` workflow, never by hand - A parse-error-only fixture reporting a different error count per OS: prefer fixtures with real lint findings - Host-provided tools (`runtime_provided`) run the runner's version and their tests are non-blocking - Add the `native-full-matrix` label to a PR to run all 5 platforms (pull requests run Linux x86-64 only); never install linters natively on your machine to reproduce, CI does it 7. Reproduce in Docker (required — linters are not installed locally): ```bash LINTER="_" docker buildx build --platform linux/amd64 --file linters/$LINTER/Dockerfile --tag $LINTER . docker run --rm --env TEST_CASE_RUN=true --env OUTPUT_DETAIL=detailed \ --env TEST_KEYWORDS="${LINTER}_test" --env MEGALINTER_VOLUME_ROOT="." \ --volume "$(pwd):/tmp/lint" $LINTER ``` To run only specific test methods, use a `-k`-style substring (matches all modes): ```bash # all failure-mode tests (test_failure_file_lint_mode, _list_of_files_, _project_) --env TEST_KEYWORDS="${LINTER}_test and test_failure" # narrow to a single mode --env TEST_KEYWORDS="${LINTER}_test and test_failure_project_lint_mode" ``` 8. In CI, filter tests via commit message body: `TEST_KEYWORDS=_test` 9. **Update `CHANGELOG.md`** only if the fix changes user-visible linter behavior (wrong error count, missed files, broken output). Add one line under **Fixes** in the beta section: ```text - Fix : ``` Do NOT add an entry for test-infrastructure-only fixes (fixture paths, test class regeneration, etc.). Style: `.claude/rules/changelog.md` (written for end users, no internal details).