| 1145 | } |
| 1146 | |
| 1147 | func TestScanBinaryFileModifiedDiff(t *testing.T) { |
| 1148 | t.Parallel() |
| 1149 | |
| 1150 | dir := t.TempDir() |
| 1151 | |
| 1152 | gitCmd(t, dir, "init") |
| 1153 | gitCmd(t, dir, "config", "user.name", "Test") |
| 1154 | gitCmd(t, dir, "config", "user.email", "test@test.com") |
| 1155 | |
| 1156 | // Commit a binary file. |
| 1157 | binPath := filepath.Join(dir, "data.bin") |
| 1158 | require.NoError(t, os.WriteFile(binPath, []byte("v1\x00\x01\x02"), 0o600)) |
| 1159 | |
| 1160 | gitCmd(t, dir, "add", "data.bin") |
| 1161 | gitCmd(t, dir, "commit", "-m", "add binary") |
| 1162 | |
| 1163 | // Modify the binary file in the worktree. |
| 1164 | require.NoError(t, os.WriteFile(binPath, []byte("v2\x00\x03\x04\x05"), 0o600)) |
| 1165 | |
| 1166 | logger := slogtest.Make(t, nil) |
| 1167 | h := agentgit.NewHandler(logger) |
| 1168 | h.Subscribe([]string{binPath}) |
| 1169 | |
| 1170 | ctx := context.Background() |
| 1171 | msg := h.Scan(ctx) |
| 1172 | require.NotNil(t, msg) |
| 1173 | require.Len(t, msg.Repositories, 1) |
| 1174 | |
| 1175 | repoChanges := msg.Repositories[0] |
| 1176 | |
| 1177 | // The binary file should appear in the unified diff. |
| 1178 | require.Contains(t, repoChanges.UnifiedDiff, "data.bin") |
| 1179 | |
| 1180 | // Diff should show binary marker for modification too. |
| 1181 | require.Contains(t, repoChanges.UnifiedDiff, "Binary") |
| 1182 | require.NotContains(t, repoChanges.UnifiedDiff, "\x00", |
| 1183 | "raw binary content should not appear in diff") |
| 1184 | } |
| 1185 | |
| 1186 | func TestScanFileDiffTooLargeForWire(t *testing.T) { |
| 1187 | t.Parallel() |