diff --git a/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/.openspec.yaml b/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/.openspec.yaml new file mode 100644 index 0000000000..462e04dae3 --- /dev/null +++ b/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-25 diff --git a/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/design.md b/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/design.md new file mode 100644 index 0000000000..dcac51d650 --- /dev/null +++ b/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/design.md @@ -0,0 +1,10 @@ +# Design + +## Decisions +- Pass `--output.sarif.path=stdout` as a single token and `--default=none` before `--enable ` args in `GolangciLintScanner.build_command`. +- Represent `CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG` in v2 YAML (`version: "2"`, `linters.default: none`, `linters.settings.govet.enable: [lostcancel]`) without `linters.enable`, matching `build_command`'s explicit CLI linter selection and verified via `golangci-lint config verify`. +- Strip `REFUSED_STAND_IN_DIRNAME` from `PATH` when invoking the `@pytest.mark.live("golangci-lint")` `config verify` test inside pytest so `refused_program_stand_ins` (`tests/conftest.py`) does not shadow `/usr/local/bin/golangci-lint` with the `exit 127` stand-in, while preserving `_missing_live_binary` skipping on hosts without `golangci-lint`. + +## Rejected alternatives +- Keep `linters.enable` in `CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG`: mixes CLI and config linter selection when `build_command` dynamically passes `--enable`. +- Add `go` to `RUNNER_TOOLS` or run a live Go scan here: the `devtools:1.1.12` runner image lacks a `go` toolchain; deferred to `#7091`. diff --git a/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/proposal.md b/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/proposal.md new file mode 100644 index 0000000000..0d8de60a12 --- /dev/null +++ b/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/proposal.md @@ -0,0 +1,21 @@ +# Proposal: #5072 + +## Why +`ghcr.io/dan-petty/devtools:1.1.12` (the devcontainer and runner base image) ships `golangci-lint` 2.15.0, which refuses the v1 CLI flags (`--out-format sarif`, `--disable-all`) in `GolangciLintScanner.build_command` and the v1 config keys (`disable-all`, `linters-settings`) in `CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG`. + +## What Changes +- Update `GolangciLintScanner.build_command` in `src/devops_cli/security/golangci_lint.py` to pass `--output.sarif.path=stdout` and `--default=none` (before `--enable ` flags) instead of `--out-format sarif` and `--disable-all`. +- Update `CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG` in `src/devops_cli/config/constants.py` to v2 YAML (`version: "2"`, `linters.default: none`, `linters.settings.govet.enable: [lostcancel]`) without `disable-all`, `linters-settings`, or `linters.enable`. +- Update `tests/security/test_golangci_lint_scanner.py` to assert v2 flags, v2 config shape, v2.15.0 SARIF parsing, and live `golangci-lint config verify -c` verification. + +## Capabilities +- `review-golangci-lint`: configure and run `golangci-lint` v2 cleanly with the devtools binary. + +## Impact +`GolangciLintScanner` emits valid `golangci-lint` v2 commands and configuration accepted by `golangci-lint` 2.15.0. Live Go scanning waits on `#7091` where `go` is present. + +## Feasibility +Confirmed against `golangci-lint --version` (`2.15.0`), `golangci-lint migrate`, `golangci-lint run --help`, `golangci-lint config verify`, `src/devops_cli/security/golangci_lint.py:216-238`, and `src/devops_cli/config/constants.py:691-702`. + +## Existing Tool Considered +Uses the existing `golangci/golangci-lint` 2.15.0 binary (`devtools:1.1.12`) directly with `migrate` and `config verify`; adds no new tool or library code. diff --git a/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/specs/review-golangci-lint/spec.md b/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/specs/review-golangci-lint/spec.md new file mode 100644 index 0000000000..15a4129323 --- /dev/null +++ b/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/specs/review-golangci-lint/spec.md @@ -0,0 +1,15 @@ +## ADDED Requirements + +### Requirement: Scan command uses v2 flags +`GolangciLintScanner.build_command` SHALL pass `--output.sarif.path=stdout` for every scan and `--default=none` before the `--enable` of each named linter, and MUST NOT pass `--out-format` or `--disable-all`. + +#### Scenario: Default scan command +- **WHEN** `test_golangci_lint_build_command` calls `GolangciLintScanner().build_command(Path("."))` +- **THEN** the command holds `run`, `--output.sarif.path=stdout`, `--default=none`, and one `--enable` for each of `errcheck`, `govet`, and `staticcheck`, with neither `--out-format` nor `--disable-all` + +### Requirement: Review config is v2 and accepted by golangci-lint +`CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG` SHALL set `version: "2"`, `linters.default: none`, and `linters.settings.govet.enable: [lostcancel]`, with no `linters-settings`, `disable-all`, or `linters.enable` keys, and SHALL pass `golangci-lint config verify`. + +#### Scenario: Review config passes schema and live verification +- **WHEN** `CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG` is parsed as YAML and passed to `golangci-lint config verify -c` +- **THEN** YAML checks confirm v2 keys without v1 keys, `golangci-lint config verify` exits 0 with no output, and v2.15.0 SARIF parsing returns `Finding` objects diff --git a/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/tasks.md b/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/tasks.md new file mode 100644 index 0000000000..7b157943f3 --- /dev/null +++ b/openspec/changes/archive/2026-11-25-5072-golangci-lint-v2/tasks.md @@ -0,0 +1,13 @@ +# Tasks + +## 1. Behavior + +- [x] 1.1 Update `tests/security/test_golangci_lint_scanner.py` with failing tests for v2 flags, v2 config keys, v2.15.0 SARIF parsing, and live `golangci-lint config verify` + - Verification: `$ uv run pytest -n 0 tests/security/test_golangci_lint_scanner.py` +- [x] 1.2 Update `CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG` (`src/devops_cli/config/constants.py`) and `GolangciLintScanner.build_command` (`src/devops_cli/security/golangci_lint.py`) for v2 + - Verification: `$ uv run pytest -n 0 tests/security/test_golangci_lint_scanner.py tests/security/test_review_pipeline_go.py` + +## 2. Verification + +- [x] 2.1 Run `devops ci --check --skip test --force` and `devops ci fail-to-pass --base origin/main`, and archive OpenSpec + - Verification: `$ uv run devops ci --check --skip test --force && uv run devops ci fail-to-pass --base origin/main` diff --git a/openspec/specs/review-golangci-lint/spec.md b/openspec/specs/review-golangci-lint/spec.md new file mode 100644 index 0000000000..cfa78b7268 --- /dev/null +++ b/openspec/specs/review-golangci-lint/spec.md @@ -0,0 +1,21 @@ +# review-golangci-lint Specification + +## Purpose + +Configure and run `golangci-lint` v2 flags and YAML configuration for Go static analysis in reviews. + +## Requirements + +### Requirement: Scan command uses v2 flags +`GolangciLintScanner.build_command` SHALL pass `--output.sarif.path=stdout` for every scan and `--default=none` before the `--enable` of each named linter, and MUST NOT pass `--out-format` or `--disable-all`. + +#### Scenario: Default scan command +- **WHEN** `test_golangci_lint_build_command` calls `GolangciLintScanner().build_command(Path("."))` +- **THEN** the command holds `run`, `--output.sarif.path=stdout`, `--default=none`, and one `--enable` for each of `errcheck`, `govet`, and `staticcheck`, with neither `--out-format` nor `--disable-all` + +### Requirement: Review config is v2 and accepted by golangci-lint +`CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG` SHALL set `version: "2"`, `linters.default: none`, and `linters.settings.govet.enable: [lostcancel]`, with no `linters-settings`, `disable-all`, or `linters.enable` keys, and SHALL pass `golangci-lint config verify`. + +#### Scenario: Review config passes schema and live verification +- **WHEN** `CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG` is parsed as YAML and passed to `golangci-lint config verify -c` +- **THEN** YAML checks confirm v2 keys without v1 keys, `golangci-lint config verify` exits 0 with no output, and v2.15.0 SARIF parsing returns `Finding` objects diff --git a/src/devops_cli/config/constants.py b/src/devops_cli/config/constants.py index 486b39bd7c..8317238ea4 100644 --- a/src/devops_cli/config/constants.py +++ b/src/devops_cli/config/constants.py @@ -689,16 +689,13 @@ # The prefix of the empty directory that a Popeye scan starts in (#2132). CONST_POPEYE_SCAN_DIR_PREFIX: Final[str] = "devops-scan-popeye-" CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG: Final[str] = ( + 'version: "2"\n' "linters:\n" - " disable-all: true\n" - " enable:\n" - " - errcheck\n" - " - govet\n" - " - staticcheck\n" - "linters-settings:\n" - " govet:\n" - " enable:\n" - " - lostcancel\n" + " default: none\n" + " settings:\n" + " govet:\n" + " enable:\n" + " - lostcancel\n" ) # Bandit's project file. This repository's names the targets `devops ci security` and an # unisolated `devops scan report` of the tree both scan; a review hands Bandit an empty one in diff --git a/src/devops_cli/security/golangci_lint.py b/src/devops_cli/security/golangci_lint.py index e6e05fdaaa..6c22322d8a 100644 --- a/src/devops_cli/security/golangci_lint.py +++ b/src/devops_cli/security/golangci_lint.py @@ -223,7 +223,7 @@ def build_command( **kwargs: Any, ) -> list[str]: """Build argument command list for invoking golangci-lint.""" - cmd = [self.binary_name, "run", "--out-format", "sarif"] + cmd = [self.binary_name, "run", "--output.sarif.path=stdout"] if config_file is not None and Path(config_file).exists(): cmd.extend(["--config", str(config_file)]) active_linters = list(linters) if linters is not None else list(self.linters) @@ -231,7 +231,7 @@ def build_command( if "contextcheck" not in active_linters: active_linters.append("contextcheck") if active_linters: - cmd.append("--disable-all") + cmd.append("--default=none") for linter in active_linters: cmd.extend(["--enable", linter]) return cmd diff --git a/tests/security/test_golangci_lint_scanner.py b/tests/security/test_golangci_lint_scanner.py index 62348b3ec3..ec248022d8 100644 --- a/tests/security/test_golangci_lint_scanner.py +++ b/tests/security/test_golangci_lint_scanner.py @@ -10,12 +10,16 @@ import json import os +import shutil +import subprocess from pathlib import Path import pytest +import yaml from devops_cli.ai.review_schema import Finding from devops_cli.config.commands import BIN_GOLANGCI_LINT +from devops_cli.config.constants import CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG from devops_cli.security.base import ScanOutcome from devops_cli.security.golangci_lint import ( DEFAULT_LINTERS, @@ -27,6 +31,7 @@ from tests.support.fakes.process import ProcessAnswer, ProcessCall, ProcessFake from tests.support.fakes.scanners import ScannerFake from tests.support.fakes.tool_executor import ToolAnswer, ToolExecutorFake +from tests.support.refused_programs import REFUSED_STAND_IN_DIRNAME # What golangci-lint 1.64.6 writes when go/packages cannot load the packages: its own text, # measured on 2026-10-29, then the standard error of the `go` command. @@ -102,16 +107,55 @@ def test_golangci_lint_contextcheck_optional() -> None: def test_golangci_lint_build_command() -> None: - """build_command constructs the argument list with SARIF output and enabled linters.""" + """build_command passes v2 SARIF stdout output, --default=none, and enabled linters (#5072).""" scanner = GolangciLintScanner() cmd = scanner.build_command(Path(".")) - assert cmd[:3] == ["golangci-lint", "run", "--out-format"] - assert cmd[3] == "sarif" - assert "--disable-all" in cmd + assert cmd[:3] == ["golangci-lint", "run", "--output.sarif.path=stdout"] + assert "--default=none" in cmd + assert "--out-format" not in cmd + assert "--disable-all" not in cmd enable_indices = [i for i, arg in enumerate(cmd) if arg == "--enable"] enabled = [cmd[i + 1] for i in enable_indices] assert enabled == ["errcheck", "govet", "staticcheck"] + assert cmd.index("--default=none") < enable_indices[0] + + +def test_golangci_lint_review_config_is_v2() -> None: + """CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG uses v2 keys with no v1 legacy fields (#5072).""" + parsed = yaml.safe_load(CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG) + assert isinstance(parsed, dict) + assert parsed["version"] == "2" + assert "linters-settings" not in parsed + linters = parsed["linters"] + assert linters["default"] == "none" + assert "enable" not in linters + assert "disable-all" not in linters + assert isinstance(linters["settings"], dict) + assert linters["settings"]["govet"] == {"enable": ["lostcancel"]} + + +@pytest.mark.live("golangci-lint") +def test_golangci_lint_config_verify_accepts_review_config(tmp_path: Path) -> None: + """The devtools golangci-lint v2 binary accepts CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG (#5072).""" + config_file = tmp_path / ".golangci.yml" + config_file.write_text(CONST_REVIEW_SCAN_GOLANGCI_LINT_CONFIG, encoding="utf-8") + clean_path = os.pathsep.join( + part + for part in os.environ.get("PATH", "").split(os.pathsep) + if REFUSED_STAND_IN_DIRNAME not in part + ) + binary = shutil.which(BIN_GOLANGCI_LINT, path=clean_path) + assert binary is not None + + done = subprocess.run( + [binary, "config", "verify", "-c", str(config_file)], + capture_output=True, + text=True, + check=False, + ) + assert done.returncode == 0, done.stdout + done.stderr + assert (done.stdout + done.stderr).strip() == "" def test_golangci_lint_build_command_with_contextcheck() -> None: @@ -133,7 +177,7 @@ def test_golangci_lint_sarif_output_conversion() -> None: "tool": { "driver": { "name": "golangci-lint", - "version": "1.64.6", + "version": "2.15.0", "rules": [ { "id": "govet",