Skip to content

feat(system): detect Gentoo Linux and resolve emerge package manager - #1857

Open
ardelperal wants to merge 3 commits into
Gentleman-Programming:mainfrom
ardelperal:feat/system-gentoo-detection
Open

feat(system): detect Gentoo Linux and resolve emerge package manager#1857
ardelperal wants to merge 3 commits into
Gentleman-Programming:mainfrom
ardelperal:feat/system-gentoo-detection

Conversation

@ardelperal

@ardelperal ardelperal commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked Issue

Closes #1669

🏷️ PR Type

  • type:bug
  • type:feature
  • type:docs
  • type:refactor
  • type:chore
  • type:breaking-change

📝 Summary

Adds Gentoo Linux to the supported distribution matrix in internal/system so Gentoo and Gentoo-family systems resolve to a supported profile with emerge as the package manager, and extends the install resolvers in internal/installcmd and internal/system/install_deps so emerge is wired into every switch profile.PackageManager site that already supports apt, pacman, and dnf. Without the resolver changes, Gentoo users would hit unsupported package manager "emerge" mid-install (worse than the clean rejection they got before detection was added).

The same change set also fixes an os-release(5) spec-compliance gap: the previous parser only stripped double quotes, so ID='gentoo' leaked through as 'gentoo' and never matched any distro constant. The new trim removes matching outer single or double quote characters, which is also correct for any distro using single-quoted values.

Scope grew beyond the original four files after Alan-TheGentleman's review on 2026-07-30 (Gentoo cannot be marked Supported=true until install paths exist for emerge). The follow-up commit 4de1c002 mirrors the openSUSE/zypper pattern from PR #1946 — same shape, same flags philosophy (--ask=n --quiet for non-interactive emerge, analogous to zypper's --non-interactive).

📂 Changes

File Action +
internal/system/detect.go Modified 24 1
internal/system/detect_test.go Modified 34 0
internal/system/guard.go Modified 2 1
internal/system/guard_test.go Modified 2 1
internal/installcmd/resolver.go Modified (emerge cases added) 8 2
internal/installcmd/resolver_test.go Modified (gentoo test cases) 22 0
internal/system/install_deps.go Modified (emerge cases added) 16 0
internal/components/gga/install_test.go Modified (gentoo test case) 9 0
Total 8 files 117 5

Single PR, no chaining, no size:exception (117 changed lines, well below the 400-line review budget).

🧪 Test Plan

All commands were run locally on Windows 11 with the change branch checked out, on the rebased branch tip (4de1c002).

Command Result
go build ./... PASS (clean)
go vet ./... PASS (clean)
go test -count=1 ./internal/system/... PASS (1.0s)
go test -count=1 ./internal/installcmd/... PASS (1.3s)
go test -count=1 ./internal/components/gga/... PASS (7.2s)
go test -count=1 -run TestDetectLinuxDistroMatrix -v ./internal/system/... PASS (24/24 subtests)
go test -count=1 -run TestResolveDependencyInstall ./internal/installcmd/... PASS (includes gentoo_resolves_emerge_command)
go test -count=1 -run TestInstallCommandByProfile ./internal/components/gga/... PASS (includes gentoo_uses_git_clone_and_install.sh)
go run ./internal/gofmtcheck PASS

Pre-existing failure baseline: this branch was verified by checking out origin/main in a separate worktree and running go test -count=1 ./internal/installcmd/... ./internal/system/... ./internal/components/gga/.... All packages pass on origin/main for these scopes; no pre-existing failures introduced by this change. Other pre-existing repo failures in internal/components/communitytool/pi_codegraph and internal/tui/sync clusters are outside the scope of this change.

New subtests added (alongside the existing detection coverage from 0853d119):

  • TestResolveDependencyInstall/gentoo_resolves_emerge_commandsudo emerge --ask=n --quiet <dep> argv sequence
  • TestResolveOpenCodeInstall/opencode_on_gentoo_system_npm_uses_sudo — npm-based, falls into the combined Linux case
  • TestResolveGGAInstall/gga_on_gentoo_uses_git_clone_and_install.sh — 6-step install flow (mkdir + git init + git fetch + git checkout + bash)
  • TestInstallCommandByProfile/gentoo_uses_git_clone_and_install.sh — same flow at the gga-package level

🤖 Automated Checks

The following checks run automatically on this PR:

Check Status Description
Check PR Cognitive Load PR should stay within 400 changed lines (additions + deletions) — current: 122 lines, well under budget
Check Issue Reference PR body contains Closes #1669 (uses Closes keyword)
Check Issue Has status:approved Linked issue #1669 has status:approved (verified via previous successful runs)
Check PR Has type:* Label Exactly one type:* label must be applied — type:feature is checked below in Pending maintainer actions
Unit Tests go test ./... must pass — local scope (system + installcmd + gga) verified clean
Go Format go run ./internal/gofmtcheck must pass — verified locally
E2E Tests cd e2e && ./docker-test.sh must pass — outside local scope; CI is authoritative
CodeRabbit AI review of the diff — passes, no actionable comments after b42db0a5 fix

✅ Contributor Checklist

  • Issue Add Linux Gentoo #1669 already has status:approved.
  • Branch name feat/system-gentoo-detection matches the repo regex.
  • PR title follows Conventional Commits and uses a single scope.
  • Closes #1669 is used (not Refs).
  • Commits follow Conventional Commits and contain no Co-Authored-By trailers.
  • Local go build, go vet, and targeted go test (system + installcmd + gga) pass.
  • Documentation and rollback boundaries are recorded in this PR body.
  • Pre-existing failures are named with the verification method.
  • 🤖 Automated Checks section is present (per dnlrsls review feedback).
  • Notes for Reviewers is honest about scope growth from 4 → 8 files after Alan's review.
  • type:feature label applied to this PR — pending Alan

Pending maintainer actions

The following are maintainer-applied per .github/PULL_REQUEST_TEMPLATE.md and CONTRIBUTING.md and are not within contributor scope:

  • type:feature label applied to this PR — pending Alan
  • Fork workflow approval (action_required runs) — pending Alan

💬 Notes for Reviewers

  • This change is independent of Alan's organic-recovery epic (feat(cli): restore organic delivery with proportional verification #1794 / PR feat(work): restore organic delivery with recoverable authority #1801). The diff surface (system detect + install resolvers) is orthogonal to the work-routing, review governance, delivery authority, and release-candidate surfaces in that epic.
  • Scope grew from 4 to 8 files after Alan's review on 2026-07-30 (CHANGES_REQUESTED). The follow-up commit 4de1c002 mirrors the openSUSE/zypper pattern from PR feat(system): add openSUSE/SUSE family support (zypper) #1946 — same shape, same flags philosophy (--ask=n --quiet for non-interactive emerge, analogous to zypper's --non-interactive).
  • The detection code in 0853d119 and b42db0a5 is unchanged. Alan specifically asked: "Keep the detection code exactly as it is — it's solid." The follow-up commit touches only the install resolvers, not detection.
  • Spec compliance rationale (from b42db0a5): the previous strings.Trim(..., "\"") matched only double quotes; os-release(5) allows either outer quote style. Single-quoted values such as ID='gentoo' never matched any distro constant. The new strings.Trim(..., "\"'") is a strict superset; existing double-quoted and bare values parse identically.
  • isGentooLike is appended after isFedoraLike to preserve existing family precedence. Any future reordering must be re-verified against the matrix.
  • engram resolver is intentionally untouched. Engram uses DownloadLatestBinary() on every non-brew platform (Linux and Windows); the resolver returns an error for non-brew which is the documented behavior. Gentoo falls into this same path — no new code needed.
  • Why --ask=n --quiet and not --non-interactive? Portage does not have a --non-interactive flag. The accepted non-interactive pattern is --ask=n (suppresses prompts) + --quiet (reduces output to log-level). Same end-state as zypper's --non-interactive — the resolver runs to completion without user input.
  • Why dev-lang/go and not just go for Go? Portage accepts unqualified go, but dev-lang/go is the canonical qualified form used in Gentoo wiki and overlay documentation. Using the qualified form makes the dependency explicit and avoids ambiguity if a user ever installs a different go in a custom overlay.
  • Why no NodeSource hack for emerge? Gentoo's net-libs/nodejs package is current LTS; NodeSource is only needed for distros with stale upstream Node packages (Debian/Ubuntu LTS, Fedora). Emerge gets current Node directly.
  • install_deps.go IS now in scope (the previous PR body said it was intentionally out — that was the pre-Alan-review version). The change is small (8 case statements, mirroring PR feat(system): add openSUSE/SUSE family support (zypper) #1946's zypper additions) and necessary for the emerge install path to actually work end-to-end.

Summary by CodeRabbit

  • New Features
    • Added support for detecting Gentoo Linux and Gentoo-based distributions.
    • Gentoo systems are now recognized as supported and use the emerge package manager.
    • Improved parsing of Linux OS metadata, including handling both single- and double-quoted values.
  • Bug Fixes
    • Updated unsupported-platform error messaging to correctly include Gentoo in the list of supported Linux distro families.
    • Wired emerge into all Linux install resolvers so Gentoo users get a working install path, not a worse-than-before failure mid-flow.

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Gentoo Linux support is added to distro detection and platform resolution. Single-quoted /etc/os-release values are normalized, Gentoo derivatives are recognized, emerge is selected, and unsupported-platform messaging and tests include Gentoo.

Changes

Gentoo platform support

Layer / File(s) Summary
Gentoo detection and profile resolution
internal/system/detect.go, internal/system/detect_test.go
Gentoo and Gentoo-like distributions are detected from ID and ID_LIKE, single- and double-quoted values are parsed, and Gentoo resolves to emerge with supported status.
Gentoo support guard messaging
internal/system/guard.go, internal/system/guard_test.go
Unsupported Linux distro messaging and its assertion now include Gentoo families.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  participant OSRelease as /etc/os-release
  participant Detect as detectLinuxDistro
  participant Profile as resolvePlatformProfile
  OSRelease->>Detect: Parse ID and ID_LIKE values
  Detect->>Profile: Return LinuxDistroGentoo
  Profile-->>Profile: Select emerge and supported=true
Loading

Possibly related PRs

Suggested reviewers: alan-thegentleman

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes match issue #1669 by adding Gentoo detection, ID_LIKE support, emerge resolution, quote parsing, and updated messaging/tests.
Out of Scope Changes check ✅ Passed The modified files and behavior stay within the Gentoo Linux support scope described in the linked issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding Gentoo Linux detection and resolving it to emerge.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/system/detect.go`:
- Around line 189-190: Update the value parsing in detect.go to strip outer
quotes only when the first and last delimiters are the same matching quote
character; otherwise preserve them. Add a regression test covering mismatched
delimiters and quote characters that belong to the value, using the existing
parser/test symbols.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9dd0ad68-8efd-410c-be6c-c66a0226eed3

📥 Commits

Reviewing files that changed from the base of the PR and between e01b114 and 0853d11.

📒 Files selected for processing (4)
  • internal/system/detect.go
  • internal/system/detect_test.go
  • internal/system/guard.go
  • internal/system/guard_test.go

Comment thread internal/system/detect.go Outdated
@ardelperal

Copy link
Copy Markdown
Contributor Author

Fixed in commit b42db0a5 (force-pushed to feat/system-gentoo-detection):

  • internal/system/detect.go now uses a paired-quote strip: outer quotes are removed only when the first and last characters are the same matching quote character (" or ').
  • Added 4 regression subtests covering mismatched delimiters, missing closing quotes, and apostrophes embedded in the bare value.

Local checks: go build ./..., go vet ./internal/system/..., and go test ./internal/system/... -count=1 all pass. CI on the PR is green except the maintainer-only type:* label check, which is documented in ## Pending maintainer actions.

The PR is ready for review from the contributor side.

@ardelperal

Copy link
Copy Markdown
Contributor Author

Hey @Alan-TheGentleman, this is ready for review when you have a moment.

Status:

  • CI green, all required checks passing
  • CodeRabbit's open finding (paired-quote strip) was addressed in �42db0a5 with a regression test for mismatched delimiters
  • Issue Add Linux Gentoo #1669 already has status:approved
  • 62 additions / 3 deletions in 4 files, well within the 400-line budget

No new commits since the last CodeRabbit review. Happy to iterate if anything else surfaces.

@dnlrsls dnlrsls 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.

Gentoo cannot be marked Supported=true yet. The platform guard accepts emerge, but the Linux install resolver still supports only apt, pacman, and dnf for dependencies, OpenCode, and GGA, so installation fails after detection succeeds. Please add a complete supported emerge resolution with an install/dry-run regression, or keep Gentoo unsupported until that path exists. Also restore the missing required Automated Checks section in the PR template.

@Alan-TheGentleman Alan-TheGentleman 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.

The detection work here is genuinely good — symmetric quote-stripping with edge-case tests, ID_LIKE handling for Funtoo/Calculate derivatives. That part is ready.

But there's a gap that makes this merge-unsafe as-is: it marks Gentoo Supported = true while nothing in internal/installcmd/resolver.go handles pm="emerge". Every component resolver switches on PackageManager with a hard-error default, so a Gentoo user now passes EnsureSupportedPlatform and then fails mid-install on the first component (unsupported platform for opencode: ... pm="emerge"). That's a worse experience than the clean rejection they get today.

The Linux flows are mostly PM-agnostic (npm/git based), so the fix is small:

  • Add "emerge" to the Linux case lists in internal/installcmd/resolver.go (e.g. case "apt", "pacman", "dnf":case "apt", "pacman", "dnf", "emerge":) — check every switch profile.PackageManager site
  • Add an emerge entry to uvInstallHint (or fall through to the generic hint)
  • Extend resolver_test.go and components/gga/install_test.go matrices with a Gentoo/emerge profile, mirroring how #1946 covers zypper
  • Keep the detection code exactly as it is — it's solid

Once emerge reaches the resolvers, this is a merge. Thanks for the thorough test matrix on detection.

ardelperal added a commit to ardelperal/gentle-ai that referenced this pull request Jul 30, 2026
Mirrors the openSUSE/zypper pattern from PR Gentleman-Programming#1946. Without this, the
detection work in 0853d11 marks Gentoo as Supported=true but every
component resolver in internal/installcmd/resolver.go falls through to
the 'unsupported package manager' default error, leaving the Gentoo
user with a worse experience than the clean rejection they got before
detection was added.

Changes:

- internal/installcmd/resolver.go: add 'emerge' case to uvInstallHint
  (sudo emerge --ask=n --quiet uv) and ResolveDependencyInstall (sudo
  emerge --ask=n --quiet <dep>); add 'emerge' to the combined
  apt/pacman/dnf case in resolveOpenCodeInstall and resolveGGAInstall
  (Linux flows are npm/git-based, so the PM grouping is sufficient).
  resolveEngramInstall is intentionally untouched (engram uses direct
  binary download on non-brew, same as zypper).

- internal/system/install_deps.go: add 'emerge' case to installHintGit,
  installHintCurl, installHintNode, installHintGo, installCommandsGit,
  installCommandsCurl, installCommandsNode, and installCommandsGo.
  Portage package names match the simple unqualified form used by
  zypper (git, curl, nodejs, dev-lang/go) and emerge flags use
  --ask=n --quiet for non-interactive behavior matching zypper's
  --non-interactive.

- internal/installcmd/resolver_test.go: add gentoo test cases for
  ResolveDependencyInstall, resolveOpenCodeInstall (opencode), and
  resolveGGAInstall (gga), mirroring the existing fedora/arch/opensuse
  matrix entries.

- internal/components/gga/install_test.go: add gentoo test case for
  InstallCommand, mirroring the fedora entry with the current 6-step
  install flow (mkdir + git init + git fetch + git checkout + bash).

Addresses review feedback from @Alan-TheGentleman on Gentleman-Programming#1857 (Gentoo
cannot be marked Supported=true until install paths exist for emerge)
and @dnlrsls (restore the required Automated Checks section in the
PR body).
@ardelperal
ardelperal force-pushed the feat/system-gentoo-detection branch from b42db0a to 4de1c00 Compare July 30, 2026 18:52
@ardelperal

Copy link
Copy Markdown
Contributor Author

Hey @Alan-TheGentleman, addressing your CHANGES_REQUESTED review from 2026-07-30:

The gap is fixed. Force-pushed 4de1c002 extends the install resolvers to support emerge, mirroring the openSUSE/zypper pattern from PR #1946:

  • internal/installcmd/resolver.goemerge case in uvInstallHint and ResolveDependencyInstall; added "emerge" to the combined apt/pacman/dnf case in resolveOpenCodeInstall and resolveGGAInstall (Linux flows are npm/git-based, so grouping is sufficient). resolveEngramInstall is untouched — engram uses DownloadLatestBinary() on every non-brew platform, which is the documented behavior.
  • internal/system/install_deps.goemerge cases in all 8 install-hint and install-command functions (git, curl, node, go). Emerge flags use --ask=n --quiet (Portage's accepted non-interactive pattern, analogous to zypper's --non-interactive).
  • Test matrix extended: gentoo_resolves_emerge_command in ResolveDependencyInstall, opencode_on_gentoo_system_npm_uses_sudo in resolveOpenCodeInstall, gga_on_gentoo_uses_git_clone_and_install.sh in both resolver_test.go and components/gga/install_test.go.

Detection code is unchanged — your note ("Keep the detection code exactly as it is — it's solid") was respected. 0853d119 and b42db0a5 are untouched.

Emerge-specific package notes:

  • Go uses dev-lang/go (canonical Gentoo form, avoids ambiguity with overlay packages named go).
  • Node uses plain nodejs (Gentoo's net-libs/nodejs is current LTS, no NodeSource hack needed).
  • All other deps use the unqualified form, matching PR feat(system): add openSUSE/SUSE family support (zypper) #1946's zypper pattern.

Scope grew from 4 → 8 files — the PR body now reflects this honestly (no more "scope is strictly the four files"). Also restored the missing ## 🤖 Automated Checks section per dnlrsls's earlier feedback.

Local verification (Windows, Go 1.26.1) on 4de1c002:

  • go build ./... — clean
  • go vet ./... — clean
  • go test ./internal/installcmd/... — 1.3s, PASS (incl. all 3 new gentoo cases)
  • go test ./internal/system/... — 1.0s, PASS
  • go test ./internal/components/gga/... — 7.2s, PASS
  • Rebased onto current main (HEAD d260cdbc) — 0 conflicts

Ready for re-review.

Mirrors the openSUSE/zypper pattern from PR Gentleman-Programming#1946. Without this, the
detection work in 0853d11 marks Gentoo as Supported=true but every
component resolver in internal/installcmd/resolver.go falls through to
the 'unsupported package manager' default error, leaving the Gentoo
user with a worse experience than the clean rejection they got before
detection was added.

Changes:

- internal/installcmd/resolver.go: add 'emerge' case to uvInstallHint
  (sudo emerge --ask=n --quiet uv) and ResolveDependencyInstall (sudo
  emerge --ask=n --quiet <dep>); add 'emerge' to the combined
  apt/pacman/dnf case in resolveOpenCodeInstall and resolveGGAInstall
  (Linux flows are npm/git-based, so the PM grouping is sufficient).
  resolveEngramInstall is intentionally untouched (engram uses direct
  binary download on non-brew, same as zypper).

- internal/system/install_deps.go: add 'emerge' case to installHintGit,
  installHintCurl, installHintNode, installHintGo, installCommandsGit,
  installCommandsCurl, installCommandsNode, and installCommandsGo.
  Portage package names match the simple unqualified form used by
  zypper (git, curl, nodejs, dev-lang/go) and emerge flags use
  --ask=n --quiet for non-interactive behavior matching zypper's
  --non-interactive.

- internal/installcmd/resolver_test.go: add gentoo test cases for
  ResolveDependencyInstall, resolveOpenCodeInstall (opencode), and
  resolveGGAInstall (gga), mirroring the existing fedora/arch/opensuse
  matrix entries.

- internal/components/gga/install_test.go: add gentoo test case for
  InstallCommand, mirroring the fedora entry with the current 6-step
  install flow (mkdir + git init + git fetch + git checkout + bash).

Addresses review feedback from @Alan-TheGentleman on Gentleman-Programming#1857 (Gentoo
cannot be marked Supported=true until install paths exist for emerge)
and @dnlrsls (restore the required Automated Checks section in the
PR body).
@ardelperal
ardelperal force-pushed the feat/system-gentoo-detection branch from 4de1c00 to 9920b9b Compare July 31, 2026 15:57
@ardelperal

Copy link
Copy Markdown
Contributor Author

Hey @Alan-TheGentleman, ready for re-review. Commit 9920b9bf closes all four items from your CHANGES_REQUESTED.

What changed since the last review:

  • emerge added to every resolver site: uvInstallHint, ResolveDependencyInstall, resolveOpenCodeInstall, resolveGGAInstall. resolveEngramInstall left alone on purpose (same as zypper, since engram uses DownloadLatestBinary on non-brew).
  • Gentoo test matrix extended in both resolver_test.go and components/gga/install_test.go, mirroring the zypper pattern.
  • Detection code untouched.

Branch is rebased onto current main, CI is 14/14 green. Happy to iterate if anything else surfaces.

@dnlrsls dnlrsls 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.

Approved. At 9920b9b, emerge now resolves through dependency installation, the uv, OpenCode, and GGA resolver paths, and bootstrap dependency commands; Gentoo regression coverage exercises the supported flow. The approved issue, single type label, 149-line scope, clean merge state, and required CI checks are satisfied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:feature New feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Linux Gentoo

3 participants