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

Function TestE2E_WriteFileTriggersGitWatch

agent/agentgit/agentgit_test.go:1262–1297  ·  view source on GitHub ↗

--- End-to-end integration tests (PathStore → git watch pipeline) ---

(t *testing.T)

Source from the content-addressed store, hash-verified

1260// --- End-to-end integration tests (PathStore → git watch pipeline) ---
1261
1262func TestE2E_WriteFileTriggersGitWatch(t *testing.T) {
1263 t.Parallel()
1264
1265 ctx := testutil.Context(t, testutil.WaitLong)
1266 repoDir := initTestRepo(t)
1267
1268 // Write a dirty file into the repo.
1269 require.NoError(t, os.WriteFile(filepath.Join(repoDir, "newfile.go"), []byte("package newfile\n"), 0o600))
1270
1271 ps := agentgit.NewPathStore()
1272 chatID := uuid.New()
1273 mClock := quartz.NewMock(t)
1274
1275 // Connect the git watch WebSocket BEFORE adding any paths.
1276 stream := dialGitWatchWithPathStore(t, ps, chatID, agentgit.WithClock(mClock))
1277 ch := stream.Chan()
1278
1279 // Simulate what HandleWriteFile does: add a path to the
1280 // PathStore. This triggers a notification → subscribe → scan.
1281 ps.AddPaths([]uuid.UUID{chatID}, []string{filepath.Join(repoDir, "newfile.go")})
1282
1283 // The WebSocket should receive a changes message showing the
1284 // repo with the dirty file.
1285 msg := recvMsg(ctx, t, ch)
1286 require.Equal(t, codersdk.WorkspaceAgentGitServerMessageTypeChanges, msg.Type)
1287 require.NotEmpty(t, msg.Repositories)
1288
1289 foundRepo := false
1290 for _, r := range msg.Repositories {
1291 if r.RepoRoot == repoDir {
1292 foundRepo = true
1293 require.Contains(t, r.UnifiedDiff, "newfile.go")
1294 }
1295 }
1296 require.True(t, foundRepo, "expected repo %s in changes message", repoDir)
1297}
1298
1299func TestE2E_SubagentAncestorWatch(t *testing.T) {
1300 t.Parallel()

Callers

nothing calls this directly

Calls 13

AddPathsMethod · 0.95
ContextFunction · 0.92
NewPathStoreFunction · 0.92
WithClockFunction · 0.92
initTestRepoFunction · 0.85
recvMsgFunction · 0.85
NotEmptyMethod · 0.80
WriteFileMethod · 0.65
NewMethod · 0.65
ChanMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected