(t *testing.T)
| 779 | } |
| 780 | |
| 781 | func TestWebSocketIncrementalSubscribe(t *testing.T) { |
| 782 | t.Parallel() |
| 783 | |
| 784 | ctx := testutil.Context(t, testutil.WaitLong) |
| 785 | repoA := initTestRepo(t) |
| 786 | repoB := initTestRepo(t) |
| 787 | require.NoError(t, os.WriteFile(filepath.Join(repoA, "a.go"), []byte("package a\n"), 0o600)) |
| 788 | require.NoError(t, os.WriteFile(filepath.Join(repoB, "b.go"), []byte("package b\n"), 0o600)) |
| 789 | |
| 790 | ps := agentgit.NewPathStore() |
| 791 | chatID := uuid.New() |
| 792 | mClock := quartz.NewMock(t) |
| 793 | |
| 794 | // Seed repo A before connecting. |
| 795 | ps.AddPaths([]uuid.UUID{chatID}, []string{filepath.Join(repoA, "a.go")}) |
| 796 | |
| 797 | stream := dialGitWatchWithPathStore(t, ps, chatID, agentgit.WithClock(mClock)) |
| 798 | ch := stream.Chan() |
| 799 | |
| 800 | msg1 := recvMsg(ctx, t, ch) |
| 801 | require.Equal(t, codersdk.WorkspaceAgentGitServerMessageTypeChanges, msg1.Type) |
| 802 | require.Len(t, msg1.Repositories, 1) |
| 803 | require.Equal(t, repoA, msg1.Repositories[0].RepoRoot) |
| 804 | |
| 805 | // Advance past the scan cooldown so the next scan fires |
| 806 | // immediately. |
| 807 | mClock.Advance(2 * time.Second).MustWait(context.Background()) |
| 808 | |
| 809 | // Now add repo B via the PathStore (incremental). |
| 810 | ps.AddPaths([]uuid.UUID{chatID}, []string{filepath.Join(repoB, "b.go")}) |
| 811 | |
| 812 | msg2 := recvMsg(ctx, t, ch) |
| 813 | require.Equal(t, codersdk.WorkspaceAgentGitServerMessageTypeChanges, msg2.Type) |
| 814 | // The second message should include repo B. It may or may not |
| 815 | // include repo A depending on delta logic (no change in A since |
| 816 | // last emit), but repo B must be present. |
| 817 | foundB := false |
| 818 | for _, r := range msg2.Repositories { |
| 819 | if r.RepoRoot == repoB { |
| 820 | foundB = true |
| 821 | } |
| 822 | } |
| 823 | require.True(t, foundB, "incremental subscribe should include repo B") |
| 824 | } |
| 825 | |
| 826 | func TestWebSocketRefreshTriggersChanges(t *testing.T) { |
| 827 | t.Parallel() |
nothing calls this directly
no test coverage detected