Skip to content

Conversation

@Joibel
Copy link
Owner

@Joibel Joibel commented Dec 3, 2025

Duplicate of argoproj#15092 for CodeRabbit review.


In argoproj#14996 the singular version of each of semaphore, mutex and schedule would not get moved over to the plural in the presence of both fields.

This is not really correct as if you have both sets in 3.7 you will get the behaviour of the appended list+singular. So this PR makes convert append instead of only replace.

Summary by CodeRabbit

  • Bug Fixes

    • Improved legacy configuration conversion so synchronisation references and schedule entries are reliably consolidated without altering existing public behaviour.
  • Tests

    • Added thorough unit tests covering legacy-to-current configuration conversions, including nil/empty states, singular vs plural fields, ordering and immutability checks to ensure data integrity across scenarios.

✏️ Tip: You can customize this high-level summary in your review settings.

@Joibel
Copy link
Owner Author

Joibel commented Dec 3, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 3, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link

coderabbitai bot commented Dec 3, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Legacy conversion logic modified to build plural slices by copying existing plural fields and conditionally appending singular legacy fields. Changes applied to LegacySynchronization.ToCurrent and LegacyCronWorkflowSpec.ToCurrent. Comprehensive unit tests added covering nil, empty, singular and plural cases and aliasing behaviour.

Changes

Cohort / File(s) Summary
Legacy Type Conversion Logic
workflow/convert/legacy_types.go
LegacySynchronization.ToCurrent now initialises empty plural slices, performs alias-safe copies of Semaphores and Mutexes, and conditionally appends singular Semaphore/Mutex fields. LegacyCronWorkflowSpec.ToCurrent now builds a local schedules slice by copying existing schedules and appending a singular Schedule if present, removing post-construction migration logic. No exported signatures changed.
Conversion Tests
workflow/convert/legacy_types_test.go
New unit tests: TestLegacySynchronization_ToCurrent and TestLegacyCronWorkflowSpec_ToCurrent. Tests cover nil receivers, empty/partial legacy states, singular vs plural combinations, aliasing avoidance when combining slices, ordering and immutability of source slices. Uses Argo v3 types and k8s core selectors for assertions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Pay attention to slice aliasing/copying logic in legacy_types.go.
  • Verify tests correctly assert lengths, ordering and that original slices are unmodified.
  • Confirm nil handling and initialisation semantics are consistent across conversions.

Poem

🐰
I hopped through slices, crisp and spry,
Pulled lone fields close, gave plural a try.
No aliases tangled, no items astray—
Tests clap their paws, and I nibble away. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description does not follow the required template structure. While it provides context about the issue and changes, it is missing key sections like Motivation, Modifications, Verification, and Documentation in the prescribed format. Restructure the description to include all template sections: Motivation (explain why), Modifications (what changed), Verification (how tested), and Documentation. Reference issue argoproj#14996 or argoproj#15092 in the Fixes section.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: fixing conversion of singular fields to plural fields, which aligns with the core objective of the PR.

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6a7caf0 and da8005f.

📒 Files selected for processing (2)
  • workflow/convert/legacy_types.go (2 hunks)
  • workflow/convert/legacy_types_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
workflow/convert/legacy_types_test.go (1)
workflow/convert/legacy_types.go (2)
  • LegacySynchronization (14-23)
  • LegacyCronWorkflowSpec (102-115)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Lint
  • GitHub Check: Build Binaries (cli)
  • GitHub Check: Windows Unit Tests
  • GitHub Check: Build Binaries (controller)
  • GitHub Check: Unit Tests
  • GitHub Check: argo-images (argocli)
  • GitHub Check: argo-images (argoexec)

Comment on lines 51 to 127
func TestLegacyCronWorkflowSpec_ToCurrent(t *testing.T) {
t.Run("appends singular to plural", func(t *testing.T) {
lcs := &LegacyCronWorkflowSpec{
Schedule: "0 0 * * *",
Schedules: []string{"0 * * * *", "30 * * * *"},
}
result := lcs.ToCurrent()

assert.Len(t, result.Schedules, 3)
assert.Equal(t, "0 * * * *", result.Schedules[0])
assert.Equal(t, "30 * * * *", result.Schedules[1])
assert.Equal(t, "0 0 * * *", result.Schedules[2])

// Verify no aliasing - original slice unchanged
assert.Len(t, lcs.Schedules, 2)
})
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Add test cases for edge cases.

Similar to the synchronisation tests, this test lacks coverage for:

  • Only plural schedules present (singular empty string)
  • Only singular schedule present (plural nil/empty)
  • Neither present (empty struct)

Add the following test cases:

t.Run("only plural schedules", func(t *testing.T) {
	lcs := &LegacyCronWorkflowSpec{
		Schedules: []string{"0 * * * *", "30 * * * *"},
	}
	result := lcs.ToCurrent()

	assert.Len(t, result.Schedules, 2)
	assert.Equal(t, "0 * * * *", result.Schedules[0])
	assert.Equal(t, "30 * * * *", result.Schedules[1])
})

t.Run("only singular schedule", func(t *testing.T) {
	lcs := &LegacyCronWorkflowSpec{
		Schedule: "0 0 * * *",
	}
	result := lcs.ToCurrent()

	assert.Len(t, result.Schedules, 1)
	assert.Equal(t, "0 0 * * *", result.Schedules[0])
})

t.Run("empty schedules", func(t *testing.T) {
	lcs := &LegacyCronWorkflowSpec{}
	result := lcs.ToCurrent()

	assert.Nil(t, result.Schedules)
})
🤖 Prompt for AI Agents
In workflow/convert/legacy_types_test.go around lines 51 to 67, the
TestLegacyCronWorkflowSpec_ToCurrent test covers only the case where both
Schedule and Schedules are set; add three additional subtests to cover edge
cases: (1) "only plural schedules" where Schedule is empty and Schedules
contains two entries — assert result.Schedules has length 2 and entries
preserved, (2) "only singular schedule" where Schedules is nil/empty and
Schedule is set — assert result.Schedules has length 1 with the singular value,
and (3) "empty schedules" where both fields are empty — assert result.Schedules
is nil; implement these t.Run subtests in the same style as existing assertions
to ensure full coverage and no aliasing.

@Joibel
Copy link
Owner Author

Joibel commented Dec 3, 2025

@coderabbitai generate docstrings

@coderabbitai
Copy link

coderabbitai bot commented Dec 3, 2025

✅ Actions performed

Initiated docstring generation; will generate only if new commits exist.

@coderabbitai
Copy link

coderabbitai bot commented Dec 3, 2025

Caution

Docstrings generation - FAILED

No docstrings were generated.

@Joibel
Copy link
Owner Author

Joibel commented Dec 3, 2025

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Dec 3, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
workflow/convert/legacy_types_test.go (1)

92-127: Good coverage, consider adding nil receiver test for consistency.

The tests cover all the key scenarios for schedule conversion. For consistency with TestLegacySynchronization_ToCurrent, consider adding a nil receiver test case.

 func TestLegacyCronWorkflowSpec_ToCurrent(t *testing.T) {
+	t.Run("nil receiver", func(t *testing.T) {
+		var lcs *LegacyCronWorkflowSpec
+		// Note: This would panic - if nil handling is needed, 
+		// add a nil check to LegacyCronWorkflowSpec.ToCurrent()
+	})
+
 	t.Run("neither", func(t *testing.T) {

Note: If LegacyCronWorkflowSpec.ToCurrent() should support nil receivers (like LegacySynchronization.ToCurrent() does), the method would need a nil check added. Otherwise, this is a nitpick for test symmetry.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da8005f and e3fcce7.

📒 Files selected for processing (2)
  • workflow/convert/legacy_types.go (2 hunks)
  • workflow/convert/legacy_types_test.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
workflow/convert/legacy_types_test.go (1)
workflow/convert/legacy_types.go (2)
  • LegacySynchronization (14-23)
  • LegacyCronWorkflowSpec (100-113)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: argo-images (argocli)
  • GitHub Check: argo-images (argoexec)
🔇 Additional comments (4)
workflow/convert/legacy_types.go (2)

31-45: LGTM! Correctly preserves plural fields and appends singular.

The implementation now properly handles all cases by always copying the plural slice first, then conditionally appending the singular field. This addresses the data loss bug from the previous implementation where plural fields were discarded when singular fields were absent.


117-126: LGTM! Schedule conversion follows the same correct pattern.

The schedules conversion mirrors the synchronisation logic correctly: copy the plural slice first, then append the singular schedule if non-empty. This ensures plural-only schedules are preserved.

workflow/convert/legacy_types_test.go (2)

1-10: Good test structure with appropriate imports.

The test file correctly imports the required testing framework (testify/assert) and Argo Workflows types needed for comprehensive testing.


12-90: Excellent test coverage for LegacySynchronization.ToCurrent().

The tests comprehensively cover all edge cases previously flagged in reviews:

  • Nil receiver handling
  • Empty struct (neither singular nor plural)
  • Only singular fields
  • Only plural fields
  • Combined fields with aliasing verification

The aliasing test at lines 86-88 correctly verifies that the original slices are not mutated after conversion.

@Joibel Joibel closed this Dec 8, 2025
@Joibel Joibel deleted the convert-fix branch December 8, 2025 13:06
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.

2 participants