Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions internal/cli/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
53 changes: 53 additions & 0 deletions internal/cli/repos_install_glob_listing_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
15 changes: 14 additions & 1 deletion internal/repos/converge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down
45 changes: 45 additions & 0 deletions internal/repos/converge_glob_clients_test.go
Original file line number Diff line number Diff line change
@@ -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)
})
}
}
12 changes: 8 additions & 4 deletions internal/repos/preflight_read_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
}
Expand Down
Loading