test(agentcompat): preserve existing CRLF workflow data

Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
naiba
2026-07-20 17:32:49 +00:00
co-authored by naiba/CloudCode
parent 926f2ca632
commit 8b352484d8
@@ -30,7 +30,7 @@ func TestPolicy_RejectsInvalidRequiredAggregator(t *testing.T) {
data []byte data []byte
}{ }{
{name: "LF", data: workflowData}, {name: "LF", data: workflowData},
{name: "CRLF", data: []byte(strings.ReplaceAll(string(workflowData), "\n", "\r\n"))}, {name: "CRLF", data: []byte(workflowWithCRLF(string(workflowData)))},
} }
tests := []struct { tests := []struct {
name string name string
@@ -108,6 +108,23 @@ func TestPolicy_RejectsInvalidRequiredAggregator(t *testing.T) {
} }
} }
func TestWorkflowWithCRLF_PreservesExistingCRLF(t *testing.T) {
// Given
workflow := "first\r\nsecond\r\n"
// When
converted := workflowWithCRLF(workflow)
// Then
require.Equal(t, workflow, converted)
}
func workflowWithCRLF(workflow string) string {
// Normalize first so Windows checkouts are not expanded from CRLF to CRCRLF.
workflow = strings.ReplaceAll(workflow, "\r\n", "\n")
return strings.ReplaceAll(workflow, "\n", "\r\n")
}
func mutateWorkflow(t *testing.T, data []byte, currentText, invalidText string) string { func mutateWorkflow(t *testing.T, data []byte, currentText, invalidText string) string {
t.Helper() t.Helper()
workflow := string(data) workflow := string(data)