Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cmd/wl/cmd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Use 'wl config get <key>' to read a setting.
Use 'wl config set <key> <value>' to change a setting.

Supported keys:
mode Workflow mode: wild-west (default) or pr
mode Workflow mode: pr (default) or wild-west
signing Enable GPG-signed Dolt commits: true or false
provider-type Upstream provider type (read-only, set during 'wl join')
github-repo (deprecated) Upstream GitHub repo for PR shells`,
Expand Down
4 changes: 2 additions & 2 deletions cmd/wl/cmd_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func TestRunConfigGet_ModeDefault(t *testing.T) {
if err != nil {
t.Fatalf("runConfigGet(mode) error: %v", err)
}
if got := strings.TrimSpace(stdout.String()); got != "wild-west" {
t.Errorf("runConfigGet(mode default) = %q, want %q", got, "wild-west")
if got := strings.TrimSpace(stdout.String()); got != "pr" {
t.Errorf("runConfigGet(mode default) = %q, want %q", got, "pr")
}
}

Expand Down
1 change: 1 addition & 0 deletions cmd/wl/cmd_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ func runServeHosted(cmd *cobra.Command, stdout, _ io.Writer) error {
defer pendingCache.Stop()
anonClient := sdk.New(sdk.ClientConfig{
DB: publicDB,
Mode: federation.ModePR,
ListPendingItems: pendingCache.Get,
})
apiServer.SetPublicClient(anonClient)
Expand Down
10 changes: 6 additions & 4 deletions internal/federation/federation.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Config struct {
// JoinedAt is when the rig joined the wasteland.
JoinedAt time.Time `json:"joined_at"`

// Mode is the workflow mode: "" or "wild-west" (default) or "pr".
// Mode is the workflow mode: "" or "pr" (default) or "wild-west".
Mode string `json:"mode,omitempty"`

// Backend is the database backend: "remote" (DoltHub API, default) or "local" (dolt CLI).
Expand All @@ -81,10 +81,10 @@ type Config struct {
GitHubRepo string `json:"github_repo,omitempty"`
}

// ResolveMode returns the effective mode, defaulting to wild-west.
// ResolveMode returns the effective mode, defaulting to PR mode.
func (c *Config) ResolveMode() string {
if c.Mode == "" || c.Mode == ModeWildWest {
return ModeWildWest
if c.Mode == "" || c.Mode == ModePR {
return ModePR
}
return c.Mode
}
Expand Down Expand Up @@ -318,6 +318,7 @@ func (s *Service) Join(upstream, forkOrg, handle, displayName, ownerEmail, versi
ForkDB: upstreamDB,
LocalDir: localDir,
Backend: BackendLocal,
Mode: ModePR,
RigHandle: handle,
HopURI: hopURI,
JoinedAt: time.Now(),
Expand Down Expand Up @@ -412,6 +413,7 @@ func (s *Service) Create(opts CreateOptions) (*CreateResult, error) {
ForkDB: db,
LocalDir: localDir,
Backend: BackendLocal,
Mode: ModePR,
RigHandle: opts.Handle,
HopURI: hopURI,
JoinedAt: time.Now(),
Expand Down
6 changes: 6 additions & 0 deletions internal/federation/federation_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ func TestJoin_Success(t *testing.T) {
if cfg.RigHandle != "alice-rig" {
t.Errorf("RigHandle = %q, want %q", cfg.RigHandle, "alice-rig")
}
if cfg.Mode != ModePR {
t.Errorf("Mode = %q, want %q", cfg.Mode, ModePR)
}

if !provider.Forked["steveyegge/wl-commons->alice-dev"] {
t.Error("expected fork to be created")
Expand Down Expand Up @@ -322,6 +325,9 @@ func TestCreate_Success(t *testing.T) {
if cfg.ProviderType != "fake" {
t.Errorf("ProviderType = %q, want %q", cfg.ProviderType, "fake")
}
if cfg.Mode != ModePR {
t.Errorf("Mode = %q, want %q", cfg.Mode, ModePR)
}

// Verify call ordering: Init → SQLExec → StageAndCommit → RegisterRig → AddRemote → Push
expectedOrder := []string{"Init", "SQLExec", "StageAndCommit", "RegisterRig", "AddRemote", "Push"}
Expand Down
21 changes: 21 additions & 0 deletions internal/federation/federation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,27 @@ func TestResolveProviderType(t *testing.T) {
}
}

func TestResolveMode(t *testing.T) {
tests := []struct {
name string
mode string
want string
}{
{"empty defaults to pr", "", ModePR},
{"explicit pr", ModePR, ModePR},
{"explicit wild-west", ModeWildWest, ModeWildWest},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
cfg := &Config{Mode: tc.mode}
got := cfg.ResolveMode()
if got != tc.want {
t.Errorf("ResolveMode() = %q, want %q", got, tc.want)
}
})
}
}

func TestResolveBackend(t *testing.T) {
tests := []struct {
name string
Expand Down
37 changes: 21 additions & 16 deletions test/integration/offline/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ func joinedEnv(t *testing.T, backend backendKind) *testEnv {
return env
}

func joinedLifecycleEnv(t *testing.T, backend backendKind) *testEnv {
t.Helper()
return joinedEnvInMode(t, backend, "wild-west")
}

// forkCloneDir returns the fork clone dir from the wasteland config.
func forkCloneDir(t *testing.T, env *testEnv) string {
t.Helper()
Expand Down Expand Up @@ -146,7 +151,7 @@ func TestSchemaInit(t *testing.T) {
func TestPostWanted(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

stdout, stderr, err := runWL(t, env, "post",
Expand Down Expand Up @@ -200,7 +205,7 @@ func TestPostWanted(t *testing.T) {
func TestClaimWanted(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

// Post an item first.
Expand Down Expand Up @@ -235,7 +240,7 @@ func TestClaimWanted(t *testing.T) {
func TestClaimAlreadyClaimed(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

// Post and claim.
Expand Down Expand Up @@ -269,7 +274,7 @@ func TestClaimAlreadyClaimed(t *testing.T) {
func TestDoneFullLifecycle(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

// Post.
Expand Down Expand Up @@ -317,7 +322,7 @@ func TestDoneFullLifecycle(t *testing.T) {
func TestDoneWrongClaimer(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

// Post and claim as the default rig (forkOrg handle).
Expand Down Expand Up @@ -354,7 +359,7 @@ func TestDoneWrongClaimer(t *testing.T) {
func TestDoneUnclaimed(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

// Post but don't claim.
Expand Down Expand Up @@ -387,7 +392,7 @@ func TestDoneUnclaimed(t *testing.T) {
func TestPostOutput(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)

stdout, _, err := runWL(t, env, "post", "--title", "Output format test", "--type", "docs", "--no-push")
if err != nil {
Expand All @@ -410,7 +415,7 @@ func TestPostOutput(t *testing.T) {
func TestAcceptFullLifecycle(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

// Post as forkOrg (poster).
Expand Down Expand Up @@ -487,7 +492,7 @@ func TestAcceptFullLifecycle(t *testing.T) {
func TestAcceptSelfReject(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)

// Post → claim → done as forkOrg.
stdout, _, err := runWL(t, env, "post", "--title", "Self accept test", "--type", "bug", "--no-push")
Expand Down Expand Up @@ -518,7 +523,7 @@ func TestAcceptSelfReject(t *testing.T) {
func TestRejectFullLifecycle(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

// Post as forkOrg (poster).
Expand Down Expand Up @@ -602,7 +607,7 @@ func TestRejectFullLifecycle(t *testing.T) {
func TestUpdateWanted(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

// Post.
Expand Down Expand Up @@ -643,7 +648,7 @@ func TestUpdateWanted(t *testing.T) {
func TestUpdateClaimedFails(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)

// Post and claim.
stdout, _, err := runWL(t, env, "post", "--title", "Claimed update test", "--type", "bug", "--no-push")
Expand All @@ -669,7 +674,7 @@ func TestUpdateClaimedFails(t *testing.T) {
func TestUnclaimWanted(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

// Post an item.
Expand Down Expand Up @@ -713,7 +718,7 @@ func TestUnclaimWanted(t *testing.T) {
func TestUnclaimByPoster(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

// Post as forkOrg (poster).
Expand Down Expand Up @@ -761,7 +766,7 @@ func TestUnclaimByPoster(t *testing.T) {
func TestDeleteWanted(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)
dbDir := forkCloneDir(t, env)

// Post.
Expand Down Expand Up @@ -793,7 +798,7 @@ func TestDeleteWanted(t *testing.T) {
func TestDeleteClaimedFails(t *testing.T) {
for _, backend := range backends {
t.Run(string(backend), func(t *testing.T) {
env := joinedEnv(t, backend)
env := joinedLifecycleEnv(t, backend)

// Post and claim.
stdout, _, err := runWL(t, env, "post", "--title", "Claimed delete test", "--type", "feature", "--no-push")
Expand Down
26 changes: 26 additions & 0 deletions test/integration/offline/offline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,14 @@ func (e *testEnv) remoteArgs() []string {
}
}

// joinedEnvInMode creates a joined env and then explicitly sets the workflow mode.
func joinedEnvInMode(t *testing.T, backend backendKind, mode string) *testEnv {
t.Helper()
env := joinedEnv(t, backend)
setMode(t, env, upstream, mode)
return env
}

// joinWasteland runs "wl join" with the appropriate remote provider as the front door.
func (e *testEnv) joinWasteland(t *testing.T, upstream, forkOrg string) {
t.Helper()
Expand Down Expand Up @@ -295,6 +303,24 @@ func runWL(t *testing.T, env *testEnv, args ...string) (string, string, error) {
return stdout.String(), stderr.String(), err
}

// setMode updates the wasteland config to the given mode.
func setMode(t *testing.T, env *testEnv, upstreamPath, mode string) {
t.Helper()
cfg := env.loadConfig(t, upstreamPath)
cfg["mode"] = mode

parts := strings.SplitN(upstreamPath, "/", 2)
configPath := filepath.Join(env.ConfigDir, "wastelands", parts[0], parts[1]+".json")

data, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
t.Fatalf("marshaling config: %v", err)
}
if err := os.WriteFile(configPath, append(data, '\n'), 0o644); err != nil {
t.Fatalf("writing config: %v", err)
}
}

// doltSQL runs a dolt SQL query against a database directory and returns CSV output.
func doltSQL(t *testing.T, dbDir, query string) string {
t.Helper()
Expand Down
Loading