-
Notifications
You must be signed in to change notification settings - Fork 371
fix: use exact YAML line matching for agent job detection in integration tests #25780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,34 +86,29 @@ strict: false | |
|
|
||
| lockContentStr := string(lockContent) | ||
|
|
||
| // Verify the job exists | ||
| jobMarker := tt.jobName + ":" | ||
| if !strings.Contains(lockContentStr, jobMarker) { | ||
| // Verify the job exists and extract using exact YAML job marker | ||
| jobMarker := "\n " + tt.jobName + ":\n" | ||
| markerIdx := strings.Index(lockContentStr, jobMarker) | ||
| if markerIdx == -1 { | ||
| t.Errorf("Expected %s job to be present", tt.jobName) | ||
| return | ||
| } | ||
|
|
||
| // Extract the job section | ||
| jobStart := strings.Index(lockContentStr, jobMarker) | ||
| if jobStart == -1 { | ||
| t.Fatalf("%s job not found in compiled workflow", tt.jobName) | ||
| } | ||
| jobStart := markerIdx + len("\n ") // point to "jobName:\n" | ||
|
|
||
|
Comment on lines
+89
to
99
|
||
| // Find the next job or end of file | ||
| jobEnd := len(lockContentStr) | ||
| nextJobIdx := strings.Index(lockContentStr[jobStart+len(jobMarker):], "\n ") | ||
| if nextJobIdx != -1 { | ||
| searchStart := jobStart + len(jobMarker) + nextJobIdx | ||
| for idx := searchStart; idx < len(lockContentStr); idx++ { | ||
| if lockContentStr[idx] == '\n' { | ||
| lineStart := idx + 1 | ||
| if lineStart < len(lockContentStr) && lineStart+2 < len(lockContentStr) { | ||
| if lockContentStr[lineStart:lineStart+2] == " " && lockContentStr[lineStart+2] != ' ' { | ||
| colonIdx := strings.Index(lockContentStr[lineStart:], ":") | ||
| if colonIdx > 0 && colonIdx < 50 { | ||
| jobEnd = idx | ||
| break | ||
| } | ||
| searchStart := markerIdx + len(jobMarker) | ||
| for idx := searchStart; idx < len(lockContentStr); idx++ { | ||
| if lockContentStr[idx] == '\n' { | ||
| lineStart := idx + 1 | ||
| if lineStart+2 < len(lockContentStr) { | ||
| if lockContentStr[lineStart:lineStart+2] == " " && lockContentStr[lineStart+2] != ' ' { | ||
| colonIdx := strings.Index(lockContentStr[lineStart:], ":") | ||
| if colonIdx > 0 && colonIdx < 50 { | ||
| jobEnd = idx | ||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,28 +134,28 @@ This is a test workflow for trial mode compilation. | |
| } | ||
|
|
||
| // Checkout in agent job should include token in trial mode | ||
| // Extract the agent job section first | ||
| agentJobStart := strings.Index(lockContent, "agent:") | ||
| if agentJobStart == -1 { | ||
| // Extract the agent job section using exact YAML job marker | ||
| agentJobMarker := "\n agent:\n" | ||
| markerIdx := strings.Index(lockContent, agentJobMarker) | ||
| if markerIdx == -1 { | ||
| t.Error("Expected agent job in trial mode") | ||
| return | ||
| } | ||
|
|
||
| agentJobStart := markerIdx + len("\n ") // point to "agent:\n" | ||
|
|
||
|
Comment on lines
+137
to
+146
|
||
| // Find the end of the agent job (next job or end of file) | ||
| agentJobEnd := len(lockContent) | ||
| nextJobStart := strings.Index(lockContent[agentJobStart+6:], "\n ") | ||
| if nextJobStart != -1 { | ||
| searchPos := agentJobStart + 6 + nextJobStart | ||
| for idx := searchPos; idx < len(lockContent); idx++ { | ||
| if lockContent[idx] == '\n' { | ||
| lineStart := idx + 1 | ||
| if lineStart < len(lockContent) && lineStart+2 < len(lockContent) { | ||
| if lockContent[lineStart:lineStart+2] == " " && lockContent[lineStart+2] != ' ' { | ||
| colonIdx := strings.Index(lockContent[lineStart:], ":") | ||
| if colonIdx > 0 && colonIdx < 50 { | ||
| agentJobEnd = idx | ||
| break | ||
| } | ||
| searchPos := markerIdx + len(agentJobMarker) | ||
| for idx := searchPos; idx < len(lockContent); idx++ { | ||
| if lockContent[idx] == '\n' { | ||
| lineStart := idx + 1 | ||
| if lineStart+2 < len(lockContent) { | ||
| if lockContent[lineStart:lineStart+2] == " " && lockContent[lineStart+2] != ' ' { | ||
| colonIdx := strings.Index(lockContent[lineStart:], ":") | ||
| if colonIdx > 0 && colonIdx < 50 { | ||
| agentJobEnd = idx | ||
| break | ||
| } | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test reimplements job-section extraction with manual string indexing and hard-coded offsets (e.g.,
len("\n ")). There is already anextractJobSection(yamlContent, jobName)helper inpkg/workflow/compiler_test_helpers_test.gothat extracts a job by YAML indentation, which would simplify this logic and reduce brittleness if formatting changes.See below for a potential fix: