From 15ef22e4fa0ddb94adf544a7b7a4d32313c578e0 Mon Sep 17 00:00:00 2001 From: fullsend-code <278716306+fullsend-ai-coder[bot]@users.noreply.github.com> Date: Tue, 17 Nov 2026 01:13:38 +0000 Subject: [PATCH] fix(#9571): converge only the glob repos the install preflights checked repos install runs its configuration preflights (adoption, install defaults, proposed safety, effective infrastructure) through one read cache, so each glob org is listed once for all of them (#8501). Converge then expanded the same globs again through the uncached clients, so a repository created in a glob org between the two listings was converged without passing any preflight. Add ConvergeConfig.GlobClients: when set, Converge expands glob entries through that factory instead of its converge clients. repos install passes the preflight read cache, so convergence reuses the org listings the preflights checked. Every other forge read and write still goes through the uncached clients. Explicit entries, globless manifests and repo filters behave as before; the filter is the same one the preflights expanded with. Tests: a Converge unit test for GlobClients set and unset, and a repos install test where a repository appears in the org listing after the preflights list it and is not converged (fails without the fix). Note: pre-commit could not fetch its hook repositories in the sandbox (TLS failure), so the applicable hooks were run directly: gofmt, go vet ./..., whitespace/end-of-file checks, broken-symlink lint and the secret scan passed. The semgrep hook skipped itself because its pinned ruleset could not be downloaded. Six internal/cli tests (TestStartFetchService_*, TestPostScriptEnv_NoSchema*) fail in this sandbox on main as well and are unrelated. Closes #9571 Co-Authored-By: Claude Opus 5.5 --- internal/cli/repos.go | 7 ++- .../cli/repos_install_glob_listing_test.go | 53 +++++++++++++++++++ internal/repos/converge.go | 15 +++++- internal/repos/converge_glob_clients_test.go | 45 ++++++++++++++++ internal/repos/preflight_read_cache.go | 12 +++-- 5 files changed, 125 insertions(+), 7 deletions(-) create mode 100644 internal/cli/repos_install_glob_listing_test.go create mode 100644 internal/repos/converge_glob_clients_test.go diff --git a/internal/cli/repos.go b/internal/cli/repos.go index 87cd607bff..39d5124494 100644 --- a/internal/cli/repos.go +++ b/internal/cli/repos.go @@ -743,8 +743,10 @@ func runReposInstall(ctx context.Context, opts *reposInstallConfig) error { // The configuration preflights below only read the forge, and the // manifest is written only after all of them, so they share one read // cache: equivalent layer, component and glob reads are made once - // (#8501). It is discarded before the manifest write; convergence - // reads current state through clients. + // (#8501). No repository state is read through it after the manifest + // write: convergence reads current state through clients, and only + // expands globs through this cache so it converges the repositories + // the preflights checked (#9571). preflightClients := repos.NewPreflightReadCache(clients) // Preflight the existing configuration layers of manifest-tracked repos @@ -959,6 +961,7 @@ func runReposInstall(ctx context.Context, opts *reposInstallConfig) error { RepoFilter: opts.repoFilter, ExcludeRepos: append(containFailedKeys(containFailedRepos), adoptionSkip...), MaxConcurrency: opts.concurrency, + GlobClients: preflightClients, UpstreamRef: upstreamRef, UpstreamTag: upstreamTag, Direct: opts.direct, diff --git a/internal/cli/repos_install_glob_listing_test.go b/internal/cli/repos_install_glob_listing_test.go new file mode 100644 index 0000000000..d395a76a46 --- /dev/null +++ b/internal/cli/repos_install_glob_listing_test.go @@ -0,0 +1,53 @@ +package cli + +import ( + "context" + "sync" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/fullsend-ai/fullsend/internal/forge" +) + +// lateRepoClient adds a repository to the fake organization listing on the +// first file read, which the configuration preflights make right after +// expanding the manifest's globs. Every later listing names the new +// repository, as when it is created in the org while install runs. +type lateRepoClient struct { + *forge.FakeClient + late forge.Repository + once sync.Once +} + +func (c *lateRepoClient) GetFileContent(ctx context.Context, owner, repo, path string) ([]byte, error) { + c.once.Do(func() { c.Repos = append(c.Repos, c.late) }) + return c.FakeClient.GetFileContent(ctx, owner, repo, path) +} + +// Convergence acts on the glob expansion the preflights checked: a +// repository that appears in a glob org after the preflights listed it is +// not converged (#9571). +func TestRunReposInstall_GlobRepoCreatedAfterPreflightsIsNotConverged(t *testing.T) { + manifestPath := writeTestManifest(t, globInferenceAuthManifestYAML) + fc := newInstallFakeClient("acme/api", "acme/web") + var late forge.Repository + for i, r := range fc.Repos { + if r.FullName == "acme/web" { + late = r + fc.Repos = append(fc.Repos[:i:i], fc.Repos[i+1:]...) + break + } + } + require.Equal(t, "acme/web", late.FullName) + client := &lateRepoClient{FakeClient: fc, late: late} + + opts := useOpenAIInputs(githubManagedInstallOpts(manifestPath, fc)) + opts.testClient = client + require.NoError(t, runReposInstall(context.Background(), opts)) + + assert.True(t, fc.Secrets["acme/api/FULLSEND_OPENAI_API_KEY"], "the preflighted repository is converged") + assert.False(t, fc.Secrets["acme/web/FULLSEND_OPENAI_API_KEY"], "a repository the preflights never checked is not converged") + assert.Len(t, client.Repos, 2, "the late repository is in later listings") +} diff --git a/internal/repos/converge.go b/internal/repos/converge.go index f6029c38e7..1090823c84 100644 --- a/internal/repos/converge.go +++ b/internal/repos/converge.go @@ -32,6 +32,15 @@ type ConvergeConfig struct { ExcludeRepos []string MaxConcurrency int + // GlobClients, when set, is the factory Converge expands glob entries + // through instead of the clients it converges with. `repos install` + // passes the read cache its preflights expanded the same globs through + // (NewPreflightReadCache), so convergence acts on exactly the + // repositories the preflights checked: a repository created in a glob + // org after the preflights listed it is not converged (#9571). Every + // other forge read and write still goes through the converge clients. + GlobClients ForgeClientFactory + // UpstreamRef is the git ref (SHA) used to pin scaffold workflow refs. UpstreamRef string // UpstreamTag is the version tag corresponding to UpstreamRef. @@ -795,7 +804,11 @@ func Converge(ctx context.Context, cfg ConvergeConfig, return nil, fmt.Errorf("invalid manifest: %w", err) } - repos, err := manifest.ExpandGlobsFor(ctx, clients, cfg.RepoFilter) + globClients := clients + if cfg.GlobClients != nil { + globClients = cfg.GlobClients + } + repos, err := manifest.ExpandGlobsFor(ctx, globClients, cfg.RepoFilter) if err != nil { return nil, fmt.Errorf("expanding globs: %w", err) } diff --git a/internal/repos/converge_glob_clients_test.go b/internal/repos/converge_glob_clients_test.go new file mode 100644 index 0000000000..46918c538c --- /dev/null +++ b/internal/repos/converge_glob_clients_test.go @@ -0,0 +1,45 @@ +package repos + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/fullsend-ai/fullsend/internal/forge" +) + +// Converge expands glob entries through GlobClients when it is set, so a +// repository that the converge clients list but GlobClients does not (one +// created after the install preflights listed the org) is not converged +// (#9571). Without GlobClients the converge clients expand the globs. +func TestConverge_GlobClientsExpandGlobs(t *testing.T) { + fc := newFakeClientForBatch("acme/api", "acme/web") + preflightListing := forge.NewFakeClient() + preflightListing.Repos = []forge.Repository{{FullName: "acme/api", Name: "api", DefaultBranch: "main"}} + + cases := []struct { + name string + globClients ForgeClientFactory + want []string + }{ + {name: "GlobClients set", globClients: newTestClientFactory(preflightListing), want: []string{"acme/api"}}, + {name: "GlobClients unset", want: []string{"acme/api", "acme/web"}}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + cfg := convergeCfgWithDefaults(newConvergeManifest("acme/*")) + cfg.DryRun = true + cfg.GlobClients = tc.globClients + + result, err := Converge(context.Background(), cfg, newTestClientFactory(fc), (&fakeScaffoldCommit{}).fn(), noopProgress) + require.NoError(t, err) + var got []string + for _, r := range result.Results { + got = append(got, r.Owner+"/"+r.Repo) + } + assert.ElementsMatch(t, tc.want, got) + }) + } +} diff --git a/internal/repos/preflight_read_cache.go b/internal/repos/preflight_read_cache.go index 320782fde0..58c35f4ec5 100644 --- a/internal/repos/preflight_read_cache.go +++ b/internal/repos/preflight_read_cache.go @@ -17,10 +17,14 @@ import ( // The cache never observes a write it did not make, so it is only correct // for a window in which nothing writes to the forge. `repos install` uses // one for its read-only configuration preflights (ownership, install -// defaults, proposed safety, effective infrastructure) and discards it -// before the manifest is written; convergence keeps reading current state -// through the original clients. Successful reads and not-found answers are -// cached; any other error is returned uncached. +// defaults, proposed safety, effective infrastructure) and reads no +// repository state through it once the manifest is written; convergence +// reads current state through the original clients. Convergence only +// expands glob entries through it (ConvergeConfig.GlobClients), so it acts +// on the org listings the preflights checked rather than on a later +// listing that may name an unchecked repository (#9571); convergence never +// writes org listings, so reusing them is safe. Successful reads and +// not-found answers are cached; any other error is returned uncached. func NewPreflightReadCache(clients ForgeClientFactory) ForgeClientFactory { return &preflightReadCache{clients: clients, byForge: make(map[string]*cachingReadClient)} }