Skip to content

CLI-973 Add dependency risks global hook - #759

Merged
tomshafir-sonarsource merged 8 commits into
masterfrom
gb/cli-973-dep-risks-runtime-resolution
Sep 15, 2026
Merged

tomshafir-sonarsource merged 8 commits into
masterfrom
gb/cli-973-dep-risks-runtime-resolution

Conversation

@georgii-borovinskikh-sonarsource

@georgii-borovinskikh-sonarsource georgii-borovinskikh-sonarsource commented Sep 2, 2026

Copy link
Copy Markdown
Member

Summary by Gitar

  • Dependency Risks Hook:
    • Enabled global support for dependency risks git hooks with graceful project resolution
    • Updated pre-commit hook to skip gracefully instead of hard-failing when project key is missing

This will update automatically on new commits.

@netlify

netlify Bot commented Sep 2, 2026

Copy link
Copy Markdown

Deploy Preview for sonarqube-cli canceled.

Name Link
🔨 Latest commit e76eacf
🔍 Latest deploy log https://app.netlify.com/projects/sonarqube-cli/deploys/6aa907ff26cd2e00082094e3

@hashicorp-vault-sonar-prod

hashicorp-vault-sonar-prod Bot commented Sep 2, 2026

Copy link
Copy Markdown

CLI-973

Comment thread src/commands/integrate/git/tools/shared.ts
Comment thread src/commands/hook/git-pre-commit.ts Outdated
Comment thread src/commands/hook/git-pre-commit.ts Outdated

@tomshafir-sonarsource tomshafir-sonarsource left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Left a few small comments.

Comment thread src/commands/integrate/git/tools/git-integration-subfeatures.ts
Comment thread CLAUDE.md Outdated
@georgii-borovinskikh-sonarsource
georgii-borovinskikh-sonarsource force-pushed the gb/cli-973-dep-risks-runtime-resolution branch 3 times, most recently from 5531c07 to 873998b Compare September 7, 2026 13:30
vnaskos-sonar and others added 6 commits September 14, 2026 16:01
Building on #715's (CLI-970) dynamic project-key resolution, drop the
InvalidOptionError thrown when --dependency-risks resolves no project key.
The existing "only run the SCA stage when a key resolved" gate already did
the right thing once the throw is gone — the secrets stage and the commit
itself are unaffected by a dependency-risks resolution miss, consistent
with this hook's other fallback paths. Adds a user-facing skip notice
matching the style of the sibling sca-scanner-missing message.
Defer the "no project key resolved" warning until after the
manifest-changed/binary-installed check, so it only fires when a
dependency-risks scan would actually have run. Fix a stale comment
still describing --dependency-risks as opt-in, and correct the
CLAUDE.md paragraph that contradicted itself on prompt behavior. Add
coverage for declining the dependency-risks prompt and for the
reordered warning.
A test added on this branch predates the master-side migration to
ctx.console and was left referencing the removed getMockUiCalls()
global mock when rebased onto it. Switch it to the FakeConsole
instance the rest of the file already uses.
@tomshafir-sonarsource
tomshafir-sonarsource force-pushed the gb/cli-973-dep-risks-runtime-resolution branch from 873998b to aa59f23 Compare September 14, 2026 14:18
Comment thread src/commands/command-tree.ts
@gitar-bot

gitar-bot Bot commented Sep 15, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 6 resolved / 6 findings

Enables global dependency risks git hook with graceful project resolution and prompts for opt-in during setup. Resolved issues include contradictory documentation on opt-out behavior, untested decline path and success path for lazy project discovery, generated docs still advertising removed command, and test ambient state leakage. No issues remain open.

✅ 6 resolved
Quality: CLAUDE.md paragraph contradicts itself on dep-risks opt-out

📄 CLAUDE.md:69
The rewritten sentence opens with "installs a pre-commit dependency-risks (SCA) scan ... whenever SCA is available for the connection — there is no opt-in flag; a future --skip-dep-risks flag is the planned way to opt out non-interactively", but the same paragraph later states that interactive sessions get an Install pre-commit dependency-risks scan? prompt "so the choice can be declined on the spot instead of only via a later --skip-dep-risks flag". A reader (or agent) acting on the opening clause will believe the subfeature is always installed when SCA is available. Qualify the opening clause, e.g. "installs ... by default (auto-installed non-interactively, prompted with default Yes interactively)".

Quality: Decline path for the new dep-risks prompt is untested

📄 tests/unit/commands/integrate/git/git-integration-subfeatures.test.ts:96-110 📄 tests/integration/specs/integrate/git.test.ts:715-724
The prompt introduces a brand-new outcome — the user answering No — which makes selectActiveSubfeatures drop pre-commit-dependency-risks, so the hook must render without --dependency-risks and sca-scanner-cli must not be installed. No test exercises it: the interactive integration test only accepts the prompt, and the unit tests now assert only that shouldInstall returns {action:'ask'} (the previous non-interactive install assertion was replaced by another ask assertion). Add an interactive integration case that declines Install pre-commit dependency-risks scan? and asserts the generated hook contains no --dependency-risks and the state has no sca-scanner-cli dependency.

Quality: Generated docs still advertise removed integrate git --dependency-risks

📄 src/commands/command-tree.ts:403 📄 docs/index.html:649
This PR removes the --dependency-risks option from sonar integrate git (command-tree.ts) and updates the hand-maintained snippet in docs/index.html, but the other committed generator outputs were not regenerated: docs/llms.txt still shows Usage: sonar integrate git [...] [--dependency-risks] [-p <value>] and describes -p as "required with --dependency-risks", and docs/data/commands.json:558/565 still carry the removed option plus its old description. A user (or an LLM consuming llms.txt) following that usage line runs sonar integrate git --dependency-risks and gets an unknown-option error, since there is no CI check that diffs the generated docs against the tree. Re-run bun run gen:docs and commit the refreshed docs/llms.txt and docs/data/commands.json (and docs/commands.html if it changes).

Quality: Lazy project discovery success path is untested

📄 tests/unit/commands/hook/git-pre-commit-dependency-risks.mocked.test.ts:190-193 📄 tests/unit/commands/hook/git-pre-commit-dependency-risks.mocked.test.ts:318-332 📄 src/commands/hook/git-pre-commit-dependency-risks.ts:75-85
The commit's whole point is resolving the project key via discoverProject when no -p was baked, but the added spy only ever resolves {projectRoot, configSources} (no projectKey), so every test either passes project: 'demo' explicitly or exercises the skip branch at line 103. Nothing asserts that a discovered key is what reaches ScaScanOrchestrator.run and the remediation hint, so a regression in resolveProjectKey (e.g. returning projectRoot instead of projectKey, or discovering before the manifest check) would pass CI. Add a test that makes discoverProject resolve a projectKey and assert the orchestrator is called with it.

Quality: Dep-risks hook test now leaks noted-project ambient state

📄 tests/unit/commands/hook/git-pre-commit-dependency-risks.mocked.test.ts:188-202 📄 src/commands/hook/git-pre-commit-dependency-risks.ts:111
runDepRisksStage now calls noteProject(options.auth, project), so the tests that pass project: 'demo' set the module-global notedProject in src/core/telemetry/project-uuid.ts. That state outlives the test (bun shares the module registry across files), and src/core/telemetry/CLAUDE.md:40 states tests must call resetProjectUuidContextForTests() in beforeEach precisely so a leaked project cannot make a later project_uuid assertion pass for the wrong reason or trigger a resolve against FAKE_AUTH.serverUrl. Add the reset call to this file's beforeEach.

...and 1 more resolved from earlier reviews

Review coverage

Functional validation No results

Rules No rules evaluated

Auto-approval Not enabled · Set up

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Counting what did not apply, without listing it.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@sonarqubecloud

Copy link
Copy Markdown

@tomshafir-sonarsource
tomshafir-sonarsource merged commit 6236cbd into master Sep 15, 2026
20 checks passed
@tomshafir-sonarsource
tomshafir-sonarsource deleted the gb/cli-973-dep-risks-runtime-resolution branch September 15, 2026 10:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants