Skip to content

test(processtree): cover reparenting strategy selection and fallbacks - #1045

Merged
matthyx merged 2 commits into
kubescape:mainfrom
DeathGun44:test/reparenting
Oct 23, 2026
Merged

matthyx merged 2 commits into
kubescape:mainfrom
DeathGun44:test/reparenting

Conversation

@DeathGun44

@DeathGun44 DeathGun44 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Overview

pkg/processtree/reparenting had no tests for DefaultStrategy, FallBackStrategy, or the logic that picks between strategies. This PR adds them, plus a one-line fix.

New tests:

  • DefaultStrategy: exiting process missing, PPID 0, parent missing, parent tracked.
  • FallBackStrategy: always applicable, always returns 1.
  • Reparenting logic: no children, the first strategy wins when it applies, then the first match in order, the "no strategy found" error, AddStrategy and GetStrategies.

Fix: DefaultStrategy.Name() returned "fallback", the same as FallBackStrategy. It was "default" in the early #591 work and changed when the strategies were split into separate files. Nothing calls Name() today. Happy to drop this commit if the shared name is intentional.

Coverage of ./pkg/processtree/reparenting/... goes from 20.0% to 90.8% (Go 1.27.3).

How to Test

go test -race -count=3 ./pkg/processtree/reparenting/...

Summary by CodeRabbit

  • Tests
    • Expanded coverage for process reparenting, including cases with missing or untracked parents, processes without children, and selection between reparenting strategies. Added checks for strategy ordering, when a strategy applies, and the parent process selected. These checks help verify consistent behavior across common and edge-case process tree scenarios.

Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
Signed-off-by: DeathGun44 <krishnamewara841@gmail.com>
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 101514fb-f854-42a7-b7d2-e4f6ba4e0391
📥 Commits

Reviewing files that changed from the base of the PR and between c7a77c1 and c0d1ab7.

📒 Files selected for processing: 4
  • pkg/processtree/reparenting/reparenting_strategies_test.go
  • pkg/processtree/reparenting/strategies/default.go
  • pkg/processtree/reparenting/strategies/default_test.go
  • pkg/processtree/reparenting/strategies/fallback_test.go

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The default reparenting strategy is now named "default" instead of "fallback". New tests cover strategy behavior, registration and ordering, strategy selection, and strategy-list copying.

Changes: Reparenting strategies

Layer / File(s) Summary
Strategy names and parent selection
pkg/processtree/reparenting/strategies/default.go, pkg/processtree/reparenting/strategies/default_test.go, pkg/processtree/reparenting/strategies/fallback_test.go
The default strategy name changes to "default". Tests check default and fallback strategy names, applicability, and selected parent PIDs.
Strategy registration and reparenting
pkg/processtree/reparenting/reparenting_strategies_test.go
Tests cover strategy registration and ordering, empty child lists, first-applicable selection, missing applicable strategies, default-strategy parent selection, and strategy-list copying.

Priority: ⬇️ Low

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

Change: Other

Merge Risk: ⚪ Minimal · up to c0d1a

The strategy rename and added tests appear ready to merge after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the added tests for reparenting strategy selection and fallback behavior.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

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

No blocking findings. The new tests cover existing strategy ordering, short-circuiting, parent eligibility, fallback behavior, and returned-slice isolation. The base still gives DefaultStrategy and FallBackStrategy the same name; correcting DefaultStrategy to default is sound and does not change PID selection. Related #591/#604 history provides no objection to this correction; #1027 and #876 address different process-tree paths and do not supersede this coverage.

Validated go test -mod=readonly -race -count=3 ./pkg/processtree/reparenting/... with Go 1.27.0 in an isolated container: both packages passed. Formatting and diff checks also pass. No full-agent build/full-suite run; a separate baseline assertion run did not finish, so no completed before/after result is claimed. Listed CI contains successful DCO, GitGuardian, and CodeRabbit checks, with no build/unit-test result.

Reviewed head c0d1ab7 against main c7a77c1. Immediately rechecked: still open, non-draft, mergeable, unchanged head/base, and no review threads. Independent code and architecture reviews found no blockers.

@matthyx matthyx moved this to Waiting on Author in KS PRs tracking Oct 23, 2026
@matthyx
matthyx merged commit d4bb9db into kubescape:main Oct 23, 2026
70 of 71 checks passed
@DeathGun44

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review!

@matthyx matthyx moved this from Waiting on Author to To Archive in KS PRs tracking Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: To Archive

Development

Successfully merging this pull request may close these issues.

2 participants