Skip to content

Commit 4c06b63

Browse files
Merge pull request #17 from KalleBylin/fix/default-workflow
fix: make PR mode the default workflow
2 parents 05ce08a + 9801ebb commit 4c06b63

12 files changed

Lines changed: 128 additions & 74 deletions

File tree

cmd/wl/cmd_config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Use 'wl config get <key>' to read a setting.
1919
Use 'wl config set <key> <value>' to change a setting.
2020
2121
Supported keys:
22-
mode Workflow mode: wild-west (default) or pr
22+
mode Workflow mode: pr (default) or wild-west
2323
signing Enable GPG-signed Dolt commits: true or false
2424
provider-type Upstream provider type (read-only, set during 'wl join')
2525
github-repo (deprecated) Upstream GitHub repo for PR shells`,

cmd/wl/cmd_config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ func TestRunConfigGet_ModeDefault(t *testing.T) {
108108
if err != nil {
109109
t.Fatalf("runConfigGet(mode) error: %v", err)
110110
}
111-
if got := strings.TrimSpace(stdout.String()); got != "wild-west" {
112-
t.Errorf("runConfigGet(mode default) = %q, want %q", got, "wild-west")
111+
if got := strings.TrimSpace(stdout.String()); got != "pr" {
112+
t.Errorf("runConfigGet(mode default) = %q, want %q", got, "pr")
113113
}
114114
}
115115

cmd/wl/cmd_serve.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ func runServeHosted(cmd *cobra.Command, stdout, _ io.Writer) error {
310310
defer pendingCache.Stop()
311311
anonClient := sdk.New(sdk.ClientConfig{
312312
DB: publicDB,
313+
Mode: federation.ModePR,
313314
ListPendingItems: pendingCache.Get,
314315
})
315316
apiServer.SetPublicClient(anonClient)

internal/federation/federation.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type Config struct {
6363
// JoinedAt is when the rig joined the wasteland.
6464
JoinedAt time.Time `json:"joined_at"`
6565

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

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

84-
// ResolveMode returns the effective mode, defaulting to wild-west.
84+
// ResolveMode returns the effective mode, defaulting to PR mode.
8585
func (c *Config) ResolveMode() string {
86-
if c.Mode == "" || c.Mode == ModeWildWest {
87-
return ModeWildWest
86+
if c.Mode == "" || c.Mode == ModePR {
87+
return ModePR
8888
}
8989
return c.Mode
9090
}
@@ -318,6 +318,7 @@ func (s *Service) Join(upstream, forkOrg, handle, displayName, ownerEmail, versi
318318
ForkDB: upstreamDB,
319319
LocalDir: localDir,
320320
Backend: BackendLocal,
321+
Mode: ModePR,
321322
RigHandle: handle,
322323
HopURI: hopURI,
323324
JoinedAt: time.Now(),
@@ -412,6 +413,7 @@ func (s *Service) Create(opts CreateOptions) (*CreateResult, error) {
412413
ForkDB: db,
413414
LocalDir: localDir,
414415
Backend: BackendLocal,
416+
Mode: ModePR,
415417
RigHandle: opts.Handle,
416418
HopURI: hopURI,
417419
JoinedAt: time.Now(),

internal/federation/federation_service_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func TestJoin_Success(t *testing.T) {
3030
if cfg.RigHandle != "alice-rig" {
3131
t.Errorf("RigHandle = %q, want %q", cfg.RigHandle, "alice-rig")
3232
}
33+
if cfg.Mode != ModePR {
34+
t.Errorf("Mode = %q, want %q", cfg.Mode, ModePR)
35+
}
3336

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

326332
// Verify call ordering: Init → SQLExec → StageAndCommit → RegisterRig → AddRemote → Push
327333
expectedOrder := []string{"Init", "SQLExec", "StageAndCommit", "RegisterRig", "AddRemote", "Push"}

internal/federation/federation_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,27 @@ func TestResolveProviderType(t *testing.T) {
312312
}
313313
}
314314

315+
func TestResolveMode(t *testing.T) {
316+
tests := []struct {
317+
name string
318+
mode string
319+
want string
320+
}{
321+
{"empty defaults to pr", "", ModePR},
322+
{"explicit pr", ModePR, ModePR},
323+
{"explicit wild-west", ModeWildWest, ModeWildWest},
324+
}
325+
for _, tc := range tests {
326+
t.Run(tc.name, func(t *testing.T) {
327+
cfg := &Config{Mode: tc.mode}
328+
got := cfg.ResolveMode()
329+
if got != tc.want {
330+
t.Errorf("ResolveMode() = %q, want %q", got, tc.want)
331+
}
332+
})
333+
}
334+
}
335+
315336
func TestResolveBackend(t *testing.T) {
316337
tests := []struct {
317338
name string

test/integration/offline/lifecycle_test.go

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ func joinedEnv(t *testing.T, backend backendKind) *testEnv {
2727
return env
2828
}
2929

30+
func joinedLifecycleEnv(t *testing.T, backend backendKind) *testEnv {
31+
t.Helper()
32+
return joinedEnvInMode(t, backend, "wild-west")
33+
}
34+
3035
// forkCloneDir returns the fork clone dir from the wasteland config.
3136
func forkCloneDir(t *testing.T, env *testEnv) string {
3237
t.Helper()
@@ -146,7 +151,7 @@ func TestSchemaInit(t *testing.T) {
146151
func TestPostWanted(t *testing.T) {
147152
for _, backend := range backends {
148153
t.Run(string(backend), func(t *testing.T) {
149-
env := joinedEnv(t, backend)
154+
env := joinedLifecycleEnv(t, backend)
150155
dbDir := forkCloneDir(t, env)
151156

152157
stdout, stderr, err := runWL(t, env, "post",
@@ -200,7 +205,7 @@ func TestPostWanted(t *testing.T) {
200205
func TestClaimWanted(t *testing.T) {
201206
for _, backend := range backends {
202207
t.Run(string(backend), func(t *testing.T) {
203-
env := joinedEnv(t, backend)
208+
env := joinedLifecycleEnv(t, backend)
204209
dbDir := forkCloneDir(t, env)
205210

206211
// Post an item first.
@@ -235,7 +240,7 @@ func TestClaimWanted(t *testing.T) {
235240
func TestClaimAlreadyClaimed(t *testing.T) {
236241
for _, backend := range backends {
237242
t.Run(string(backend), func(t *testing.T) {
238-
env := joinedEnv(t, backend)
243+
env := joinedLifecycleEnv(t, backend)
239244
dbDir := forkCloneDir(t, env)
240245

241246
// Post and claim.
@@ -269,7 +274,7 @@ func TestClaimAlreadyClaimed(t *testing.T) {
269274
func TestDoneFullLifecycle(t *testing.T) {
270275
for _, backend := range backends {
271276
t.Run(string(backend), func(t *testing.T) {
272-
env := joinedEnv(t, backend)
277+
env := joinedLifecycleEnv(t, backend)
273278
dbDir := forkCloneDir(t, env)
274279

275280
// Post.
@@ -317,7 +322,7 @@ func TestDoneFullLifecycle(t *testing.T) {
317322
func TestDoneWrongClaimer(t *testing.T) {
318323
for _, backend := range backends {
319324
t.Run(string(backend), func(t *testing.T) {
320-
env := joinedEnv(t, backend)
325+
env := joinedLifecycleEnv(t, backend)
321326
dbDir := forkCloneDir(t, env)
322327

323328
// Post and claim as the default rig (forkOrg handle).
@@ -354,7 +359,7 @@ func TestDoneWrongClaimer(t *testing.T) {
354359
func TestDoneUnclaimed(t *testing.T) {
355360
for _, backend := range backends {
356361
t.Run(string(backend), func(t *testing.T) {
357-
env := joinedEnv(t, backend)
362+
env := joinedLifecycleEnv(t, backend)
358363
dbDir := forkCloneDir(t, env)
359364

360365
// Post but don't claim.
@@ -387,7 +392,7 @@ func TestDoneUnclaimed(t *testing.T) {
387392
func TestPostOutput(t *testing.T) {
388393
for _, backend := range backends {
389394
t.Run(string(backend), func(t *testing.T) {
390-
env := joinedEnv(t, backend)
395+
env := joinedLifecycleEnv(t, backend)
391396

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

416421
// Post as forkOrg (poster).
@@ -487,7 +492,7 @@ func TestAcceptFullLifecycle(t *testing.T) {
487492
func TestAcceptSelfReject(t *testing.T) {
488493
for _, backend := range backends {
489494
t.Run(string(backend), func(t *testing.T) {
490-
env := joinedEnv(t, backend)
495+
env := joinedLifecycleEnv(t, backend)
491496

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

524529
// Post as forkOrg (poster).
@@ -602,7 +607,7 @@ func TestRejectFullLifecycle(t *testing.T) {
602607
func TestUpdateWanted(t *testing.T) {
603608
for _, backend := range backends {
604609
t.Run(string(backend), func(t *testing.T) {
605-
env := joinedEnv(t, backend)
610+
env := joinedLifecycleEnv(t, backend)
606611
dbDir := forkCloneDir(t, env)
607612

608613
// Post.
@@ -643,7 +648,7 @@ func TestUpdateWanted(t *testing.T) {
643648
func TestUpdateClaimedFails(t *testing.T) {
644649
for _, backend := range backends {
645650
t.Run(string(backend), func(t *testing.T) {
646-
env := joinedEnv(t, backend)
651+
env := joinedLifecycleEnv(t, backend)
647652

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

675680
// Post an item.
@@ -713,7 +718,7 @@ func TestUnclaimWanted(t *testing.T) {
713718
func TestUnclaimByPoster(t *testing.T) {
714719
for _, backend := range backends {
715720
t.Run(string(backend), func(t *testing.T) {
716-
env := joinedEnv(t, backend)
721+
env := joinedLifecycleEnv(t, backend)
717722
dbDir := forkCloneDir(t, env)
718723

719724
// Post as forkOrg (poster).
@@ -761,7 +766,7 @@ func TestUnclaimByPoster(t *testing.T) {
761766
func TestDeleteWanted(t *testing.T) {
762767
for _, backend := range backends {
763768
t.Run(string(backend), func(t *testing.T) {
764-
env := joinedEnv(t, backend)
769+
env := joinedLifecycleEnv(t, backend)
765770
dbDir := forkCloneDir(t, env)
766771

767772
// Post.
@@ -793,7 +798,7 @@ func TestDeleteWanted(t *testing.T) {
793798
func TestDeleteClaimedFails(t *testing.T) {
794799
for _, backend := range backends {
795800
t.Run(string(backend), func(t *testing.T) {
796-
env := joinedEnv(t, backend)
801+
env := joinedLifecycleEnv(t, backend)
797802

798803
// Post and claim.
799804
stdout, _, err := runWL(t, env, "post", "--title", "Claimed delete test", "--type", "feature", "--no-push")

test/integration/offline/offline_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ func (e *testEnv) remoteArgs() []string {
248248
}
249249
}
250250

251+
// joinedEnvInMode creates a joined env and then explicitly sets the workflow mode.
252+
func joinedEnvInMode(t *testing.T, backend backendKind, mode string) *testEnv {
253+
t.Helper()
254+
env := joinedEnv(t, backend)
255+
setMode(t, env, upstream, mode)
256+
return env
257+
}
258+
251259
// joinWasteland runs "wl join" with the appropriate remote provider as the front door.
252260
func (e *testEnv) joinWasteland(t *testing.T, upstream, forkOrg string) {
253261
t.Helper()
@@ -295,6 +303,24 @@ func runWL(t *testing.T, env *testEnv, args ...string) (string, string, error) {
295303
return stdout.String(), stderr.String(), err
296304
}
297305

306+
// setMode updates the wasteland config to the given mode.
307+
func setMode(t *testing.T, env *testEnv, upstreamPath, mode string) {
308+
t.Helper()
309+
cfg := env.loadConfig(t, upstreamPath)
310+
cfg["mode"] = mode
311+
312+
parts := strings.SplitN(upstreamPath, "/", 2)
313+
configPath := filepath.Join(env.ConfigDir, "wastelands", parts[0], parts[1]+".json")
314+
315+
data, err := json.MarshalIndent(cfg, "", " ")
316+
if err != nil {
317+
t.Fatalf("marshaling config: %v", err)
318+
}
319+
if err := os.WriteFile(configPath, append(data, '\n'), 0o644); err != nil {
320+
t.Fatalf("writing config: %v", err)
321+
}
322+
}
323+
298324
// doltSQL runs a dolt SQL query against a database directory and returns CSV output.
299325
func doltSQL(t *testing.T, dbDir, query string) string {
300326
t.Helper()

0 commit comments

Comments
 (0)