Skip to content

fix(ctp): drop invalid ref fields#1159

Open
crenshaw-dev wants to merge 13 commits intoargoproj-labs:mainfrom
crenshaw-dev:ref-runtime-validation
Open

fix(ctp): drop invalid ref fields#1159
crenshaw-dev wants to merge 13 commits intoargoproj-labs:mainfrom
crenshaw-dev:ref-runtime-validation

Conversation

@crenshaw-dev
Copy link
Contributor

If an invalid repoURL or commit sha is in the hydrator.metadata references, it'll fail the status validation and brick reconciliation.

This change drops any invalid values and logs a warning. The user impact is that the data will simply be missing from the UI, which isn't a terrible failure mode for data that's just informative, not functional.

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
@codecov-commenter
Copy link

Bundle Report

Bundle size has no change ✅

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents ChangeTransferPolicy reconciliation from getting “bricked” when hydrator.metadata contains invalid (non-CRD-validating) reference fields by sanitizing invalid reference values before they are written into status.

Changes:

  • Add runtime sanitization for hydrator.metadata references[].commit.{sha,repoURL} in git.GetShaMetadataFromFile.
  • Add unit test coverage for reference sanitization in internal/git/git_test.go.
  • Extend controller test helpers and add an integration-style controller test covering the invalid-reference scenario.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
internal/git/git.go Adds reference sanitization logic to avoid CRD validation failures on status patch.
internal/git/git_test.go Adds tests asserting invalid reference fields are cleared while preserving the reference item.
internal/controller/suite_test.go Refactors hydration test helper to allow injecting valid/invalid references into hydrator.metadata.
internal/controller/changetransferpolicy_controller_test.go Adds a controller test ensuring reconciliation succeeds when invalid reference fields exist.

Comment on lines +190 to +200
if c.RepoURL != "" {
validURL := repoURLValidPattern.MatchString(c.RepoURL)
if validURL {
if u, err := url.Parse(c.RepoURL); err != nil || (u.Scheme != "http" && u.Scheme != "https") {
validURL = false
}
}
if !validURL {
logger.Info("Discarding invalid RepoURL in hydrator.metadata references", "index", i, "repoURL", c.RepoURL)
c.RepoURL = ""
}
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

sanitizeReferences claims to match CommitMetadata CRD validation, but for RepoURL the CRD also has XValidation self == '' || isURL(self) in addition to the regex pattern. The current check (regex + url.Parse + scheme check) is likely less strict than isURL and may allow values that the API will still reject, which would keep the original "status patch fails validation" failure mode. Consider tightening validation to more closely mirror the CRD (e.g., require an absolute URL with non-empty host, and reject URLs that parse but are not considered valid URLs).

Copilot uses AI. Check for mistakes.
@codecov-commenter
Copy link

codecov-commenter commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.08%. Comparing base (00b067f) to head (236a74d).

Files with missing lines Patch % Lines
internal/git/git.go 71.42% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1159      +/-   ##
==========================================
- Coverage   53.42%   51.08%   -2.34%     
==========================================
  Files          54       54              
  Lines        6168     6195      +27     
==========================================
- Hits         3295     3165     -130     
- Misses       2513     2675     +162     
+ Partials      360      355       -5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

crenshaw-dev and others added 2 commits March 9, 2026 09:46
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

crenshaw-dev and others added 3 commits March 9, 2026 10:07
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
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