Skip to content

Conversation

@deepika1214
Copy link
Contributor

Summary

Replaces string matching with proper JSON parsing in the isRemoteWorkload function to prevent false positives when detecting remote workloads.

Fixes

Closes #2941

Testing

All existing tests pass. New test validates the fix prevents false positives when JSON contains "remote_url" as part of a string value rather than as a field name.

…_2941

Signed-off-by: deepika1214 <deepikav201818@gmail.com>
@github-actions github-actions bot added the size/XS Extra small PR: < 100 lines changed label Dec 9, 2025
@github-actions github-actions bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Dec 9, 2025
@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.12%. Comparing base (c914d42) to head (207c945).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2968   +/-   ##
=======================================
  Coverage   56.11%   56.12%           
=======================================
  Files         328      328           
  Lines       32399    32401    +2     
=======================================
+ Hits        18181    18185    +4     
+ Misses      12670    12669    -1     
+ Partials     1548     1547    -1     

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

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

Signed-off-by: deepika1214 <deepikav201818@gmail.com>
@github-actions github-actions bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Dec 9, 2025
@github-actions github-actions bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Dec 10, 2025
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 fixes a bug in the isRemoteWorkload function where string matching on raw JSON could produce false positives. The fix replaces string matching with proper JSON parsing to accurately detect the presence and value of the remote_url field.

Key Changes

  • Replaced io.ReadAll + strings.Contains with json.NewDecoder for proper JSON parsing in isRemoteWorkload
  • Added whitespace trimming check to ensure empty or whitespace-only URLs are not considered remote
  • Added comprehensive test cases covering edge cases including the false positive scenario

Reviewed changes

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

File Description
pkg/workloads/statuses/file_status.go Refactored isRemoteWorkload to use JSON parsing instead of string matching; removed unnecessary io import
pkg/workloads/statuses/file_status_test.go Added edge case tests for remote workload detection including false positive prevention

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1906 to +1927
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()

// Test the JSON parsing logic directly
var config struct {
RemoteURL string `json:"remote_url"`
}

err := json.Unmarshal([]byte(tt.configJSON), &config)
if err != nil {
t.Fatalf("failed to parse JSON: %v", err)
}

result := strings.TrimSpace(config.RemoteURL) != ""

if result != tt.expected {
t.Errorf("expected %v, got %v for JSON: %s", tt.expected, result, tt.configJSON)
}
})
}
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

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

The test reimplements the JSON parsing logic instead of testing the actual isRemoteWorkload function. This creates a disconnect where the test could pass even if the actual implementation has bugs.

Consider testing the actual isRemoteWorkload method by:

  1. Creating a fileStatusManager with mocked runConfigStore
  2. Setting up the mock to return different JSON configurations
  3. Calling manager.isRemoteWorkload(ctx, "test-workload") and verifying the result

Example pattern used elsewhere in this file (see lines 103-111):

manager, _, mockRunConfigStore := newTestFileStatusManager(t, ctrl)
mockRunConfigStore.EXPECT().Exists(gomock.Any(), "test-workload").Return(true, nil)
mockReader := io.NopCloser(strings.NewReader(tt.configJSON))
mockRunConfigStore.EXPECT().GetReader(gomock.Any(), "test-workload").Return(mockReader, nil)
result, err := manager.isRemoteWorkload(ctx, "test-workload")

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot added size/XS Extra small PR: < 100 lines changed and removed size/XS Extra small PR: < 100 lines changed labels Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace string matching with JSON parsing in isRemoteWorkload

2 participants