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

Function TestGetRepoChangesStagedModifiedDeleted

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

Source from the content-addressed store, hash-verified

874}
875
876func TestGetRepoChangesStagedModifiedDeleted(t *testing.T) {
877 t.Parallel()
878
879 repoDir := initTestRepo(t)
880 logger := slogtest.Make(t, nil)
881
882 h := agentgit.NewHandler(logger)
883
884 // Modify the committed file (worktree modified).
885 require.NoError(t, os.WriteFile(filepath.Join(repoDir, "README.md"), []byte("# Modified\n"), 0o600))
886
887 // Stage a new file.
888 require.NoError(t, os.WriteFile(filepath.Join(repoDir, "staged.go"), []byte("package staged\n"), 0o600))
889 gitCmd(t, repoDir, "add", "staged.go")
890
891 // Create an untracked file.
892 require.NoError(t, os.WriteFile(filepath.Join(repoDir, "untracked.txt"), []byte("hello\n"), 0o600))
893
894 h.Subscribe([]string{filepath.Join(repoDir, "README.md")})
895 msg := h.Scan(context.Background())
896 require.NotNil(t, msg)
897 require.Len(t, msg.Repositories, 1)
898
899 diff := msg.Repositories[0].UnifiedDiff
900
901 // README.md was committed then modified in worktree.
902 require.Contains(t, diff, "README.md")
903 require.Contains(t, diff, "--- a/README.md")
904 require.Contains(t, diff, "+++ b/README.md")
905 require.Contains(t, diff, "-# Test")
906 require.Contains(t, diff, "+# Modified")
907
908 // staged.go was added to the staging area.
909 require.Contains(t, diff, "staged.go")
910 require.Contains(t, diff, "+package staged")
911
912 // untracked.txt is untracked (shown via --no-index diff).
913 require.Contains(t, diff, "untracked.txt")
914 require.Contains(t, diff, "+hello")
915}
916
917func TestFallbackPollTriggersScan(t *testing.T) {
918 t.Parallel()

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected