Skip to content

OCPBUGS-99898: Add unit test for aggregateMachineMessages truncation logic - #9128

Open
hypershift-jira-solve-ci[bot] wants to merge 1 commit into
openshift:mainfrom
hypershift-community:fix-OCPBUGS-99898
Open

OCPBUGS-99898: Add unit test for aggregateMachineMessages truncation logic#9128
hypershift-jira-solve-ci[bot] wants to merge 1 commit into
openshift:mainfrom
hypershift-community:fix-OCPBUGS-99898

Conversation

@hypershift-jira-solve-ci

@hypershift-jira-solve-ci hypershift-jira-solve-ci Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

Adds table-driven unit tests for the aggregateMachineMessages function, which previously had zero test coverage despite containing truncation boundary logic prone to off-by-one errors.

The test covers the following cases:

  • Empty input
  • Single message
  • Multiple messages under the limit
  • Exact boundary at 1000 chars
  • Overflow with truncation suffix
  • Single oversized message

Which issue(s) this PR fixes:

Fixes https://redhat.atlassian.net/browse/OCPBUGS-99898

Special notes for your reviewer:

Pure test addition — no production code changes.

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Always review AI generated responses prior to use.
Generated with Claude Code via openshift-developer plugin


Note: This PR was auto-generated by the jira-agent periodic CI job in response to OCPBUGS-99898. See the full report for token usage, cost breakdown, and detailed phase output.

Summary by CodeRabbit

  • Tests
    • Added a new unit test for machine message aggregation behavior.
    • Validates correct handling of nil/empty inputs.
    • Ensures multiple messages concatenate when within the maximum length.
    • Confirms exact boundary inclusion without truncation.
    • Verifies overflow truncation using an end-of-message marker, including the case of a single oversized message.

@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Jul 27, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@hypershift-jira-solve-ci[bot]: This pull request references Jira Issue OCPBUGS-99898, which is invalid:

  • expected the bug to target the "5.0.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

What this PR does / why we need it:

Adds table-driven unit tests for the aggregateMachineMessages function, which previously had zero test coverage despite containing truncation boundary logic prone to off-by-one errors.

The test covers the following cases:

  • Empty input
  • Single message
  • Multiple messages under the limit
  • Exact boundary at 1000 chars
  • Overflow with truncation suffix
  • Single oversized message

Which issue(s) this PR fixes:

Fixes https://redhat.atlassian.net/browse/OCPBUGS-99898

Special notes for your reviewer:

Pure test addition — no production code changes.

Checklist:

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Always review AI generated responses prior to use.
Generated with Claude Code via openshift-developer plugin

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Central YAML (inherited)

Review profile: CHILL

Plan: Enterprise

Run ID: da5e5136-76a8-4948-8ad9-844386f49ff3

📥 Commits

Reviewing files that changed from the base of the PR and between 001cc30 and b70bf93.

📒 Files selected for processing (1)
  • hypershift-operator/controllers/nodepool/nodepool_controller_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • hypershift-operator/controllers/nodepool/nodepool_controller_test.go

📝 Walkthrough

Walkthrough

Adds TestAggregateMachineMessages, a table-driven unit test for aggregateMachineMessages. The test verifies newline-terminated message concatenation, behavior at the 1000-character limit, truncation using endOfMessage when messages exceed the limit, and the result when a single message is larger than the limit.

🚥 Pre-merge checks | ✅ 11
✅ Passed checks (11 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: a new unit test for aggregateMachineMessages truncation 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.
Stable And Deterministic Test Names ✅ Passed The added test only uses static, descriptive subtest names; no dynamic values like IDs, timestamps, or generated names appear.
Test Structure And Quality ✅ Passed The new table-driven unit test covers one behavior per subtest, uses no cluster resources or waits, and matches surrounding test patterns in the file.
Topology-Aware Scheduling Compatibility ✅ Passed Changed files add tests and image env/args only; no nodeSelector, affinity, spread, replica, or PDB scheduling logic was introduced.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed Pure Go unit test (t.Run) for string aggregation; no Ginkgo e2e, IP parsing, IPv4-only literals, or external connectivity found.
No-Weak-Crypto ✅ Passed Only a test file changed, and the added test uses plain string aggregation with no crypto, custom crypto, or secret comparisons.
Container-Privileges ✅ Passed The PR only adds a Go unit test; the diff contains no Kubernetes/container manifests or privilege settings.
No-Sensitive-Data-In-Logs ✅ Passed The PR only adds unit tests and no new logging calls or sensitive-data strings were introduced in the changed lines.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@openshift-ci
openshift-ci Bot requested review from Nirshal and jparrill July 27, 2026 14:52
@openshift-ci openshift-ci Bot added area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release and removed do-not-merge/needs-area labels Jul 27, 2026
@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 44.56%. Comparing base (02c0659) to head (b70bf93).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9128      +/-   ##
==========================================
+ Coverage   44.51%   44.56%   +0.04%     
==========================================
  Files         774      774              
  Lines       97003    97003              
==========================================
+ Hits        43185    43228      +43     
+ Misses      50830    50783      -47     
- Partials     2988     2992       +4     

see 4 files with indirect coverage changes

Flag Coverage Δ
cmd-support 38.39% <ø> (ø)
cpo-hostedcontrolplane 47.22% <ø> (ø)
cpo-other 45.25% <ø> (ø)
hypershift-operator 54.46% <ø> (ø)
other 33.07% <ø> (+0.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Two suggestions — one correctness fix, one missing boundary case.

}

func TestAggregateMachineMessages(t *testing.T) {
g := NewWithT(t)

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.

g is bound to the outer t, not the subtest's t inside t.Run. If a subtest fails, g.Expect().To() calls Fatalf on the parent test, killing the entire function and skipping all remaining subtests.

TestTruncateReasons and TestAggregateMachineReasonsAndMessages nearby have the same issue, but that's not a reason to perpetuate it — the file itself uses the correct pattern in many other places (lines 88, 127, 176, 291, 386, 522, 673, etc.).

Move g := NewWithT(t) inside the t.Run closure so each subtest gets its own gomega instance. The full test function should look like this:

func TestAggregateMachineMessages(t *testing.T) {
	shortMsg := "machine is unhealthy\n"
	padLen := maxMessageLength - len(shortMsg)
	paddedMsg := strings.Repeat("x", padLen-1) + "\n"

	for _, tc := range []struct {
		name   string
		msgs   []string
		expect string
	}{
		// ... test cases unchanged ...
	} {
		t.Run(tc.name, func(t *testing.T) {
			g := NewWithT(t)
			result := aggregateMachineMessages(tc.msgs)
			g.Expect(result).To(Equal(tc.expect))
		})
	}
}

Concretely: remove the g := NewWithT(t) on this line, and add g := NewWithT(t) as the first line inside the t.Run callback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Moved g := NewWithT(t) inside the t.Run closure so each subtest gets its own gomega instance.


AI-assisted response via Claude Code

{
name: "When a single message exceeds the limit it should return only the truncation suffix",
msgs: []string{strings.Repeat("a", maxMessageLength+1)},
expect: endOfMessage,

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 boundary between "fits" and "truncated" for a single message is not covered. The existing "exact boundary" case uses two messages summing to 1000, and this "single oversized" case uses 1001. But a single message of exactly 1000 chars is missing — this is the tightest boundary test for the > condition on the first loop iteration (0 + 1000 = 1000, NOT > 1000, so it should pass through).

Add this test case to the table (e.g. before this one):

{
	name:   "When a single message is exactly maxMessageLength it should be included",
	msgs:   []string{strings.Repeat("z", maxMessageLength)},
	expect: strings.Repeat("z", maxMessageLength),
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Added test case for a single message of exactly maxMessageLength chars to cover the tight boundary of the > condition.


AI-assisted response via Claude Code

@Nirshal

Nirshal commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

/test address-review-comments

@hypershift-jira-solve-ci

Copy link
Copy Markdown
Contributor Author

Review agent triggered. View job

@Nirshal

Nirshal commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Jul 28, 2026
@openshift-merge-bot

Copy link
Copy Markdown
Contributor

Scheduling tests matching the pipeline_run_if_changed or not excluded by pipeline_skip_if_only_changed parameters:
/test e2e-aks-4-22
/test e2e-aws-4-22
/test unit
/test verify

@jparrill

Copy link
Copy Markdown
Contributor

/label acknowledge-critical-fixes-only

@openshift-ci openshift-ci Bot added the acknowledge-critical-fixes-only Indicates if the issuer of the label is OK with the policy. label Jul 28, 2026

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

Dropped a comment. Thanks!

expect string
}{
{
name: "When input is empty it should return empty string",

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.

nit: Consider adding a nil input case alongside the empty slice. Go distinguishes nil from []string{} and aggregateMachineMessages handles both, but documenting that contract explicitly makes the test more robust as a spec.

{
    name:   "When input is nil it should return empty string",
    msgs:   nil,
    expect: "",
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Added a nil input test case before the empty slice case.


AI-assisted response via Claude Code

@jparrill

Copy link
Copy Markdown
Contributor

/test address-review-comments

@hypershift-jira-solve-ci

Copy link
Copy Markdown
Contributor Author

Review agent triggered. View job

The aggregateMachineMessages function had zero test coverage despite
having truncation boundary logic prone to off-by-one errors. This adds
a table-driven TestAggregateMachineMessages covering empty input, single
message, multiple messages under the limit, exact boundary at 1000
chars, overflow with truncation suffix, and a single oversized message.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jparrill

jparrill commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

The test images is failing legitimately, we have a fix in this PR to fix #9138

@openshift-ci openshift-ci Bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 28, 2026
@openshift-ci

openshift-ci Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

@jparrill

Copy link
Copy Markdown
Contributor

/verified by unit tests

No justification needed, just adding unit tests

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Jul 28, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@jparrill: This PR has been marked as verified by unit tests.

Details

In response to this:

/verified by unit tests

No justification needed, just adding unit tests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@jparrill

Copy link
Copy Markdown
Contributor

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Jul 28, 2026
@openshift-ci-robot

Copy link
Copy Markdown

@jparrill: This pull request references Jira Issue OCPBUGS-99898, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

/jira refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository.

@jparrill

Copy link
Copy Markdown
Contributor

/approve

@openshift-ci

openshift-ci Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hypershift-jira-solve-ci[bot], jparrill

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 28, 2026
@openshift-ci

openshift-ci Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

@hypershift-jira-solve-ci[bot]: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/images b70bf93 link true /test images
ci/prow/e2e-aws-4-22 001cc30 link true /test e2e-aws-4-22
ci/prow/e2e-aks-4-22 001cc30 link true /test e2e-aks-4-22

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

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

Labels

acknowledge-critical-fixes-only Indicates if the issuer of the label is OK with the policy. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/hypershift-operator Indicates the PR includes changes for the hypershift operator and API - outside an OCP release jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants