MCPcopy Index your code
hub / github.com/coder/coder / TestScanBinaryFileModifiedDiff

Function TestScanBinaryFileModifiedDiff

agent/agentgit/agentgit_test.go:1147–1184  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1145}
1146
1147func 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
1186func TestScanFileDiffTooLargeForWire(t *testing.T) {
1187 t.Parallel()

Callers

nothing calls this directly

Calls 8

SubscribeMethod · 0.95
ScanMethod · 0.95
NewHandlerFunction · 0.92
gitCmdFunction · 0.85
TempDirMethod · 0.65
WriteFileMethod · 0.65
LenMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected