workon 0.26.1

Development workspace launcher with Zellij, Claude CLI, and branchdiff
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
//! The built `workon`, run piped in a cleared environment whose PATH is a stub directory
//! (`support::World`). The pseudo-terminal tests are in `tui/`, compiled into this crate so
//! they share the harness.

mod support;
mod tui;

use std::path::Path;

use predicates::prelude::*;
use support::World;

/// End-to-end shell-completion check: with HOME pointed at a tempdir holding one
/// worktree, the dynamic completer must surface that workspace's id when
/// completing `workon attach <TAB>`. Guards the `add = ArgValueCandidates`
/// wiring and the CompleteEnv shim, not just the candidate function.
#[test]
fn dynamic_completion_offers_workspace_ids() {
    let world = World::new();
    let proj = world.path().join("proj");
    std::fs::create_dir(&proj).unwrap();
    world.git(&proj, &["init", "-q"]);
    world.git(&proj, &["commit", "-q", "--allow-empty", "-m", "init"]);

    std::fs::create_dir_all(world.worktrees()).unwrap();
    let wt = world.worktrees().join("proj-ws-abc123");
    world.git(&proj, &["worktree", "add", "-q", "--detach", wt.to_str().unwrap(), "HEAD"]);

    // clap_complete's request protocol: `workon -- workon attach <cursor>` with
    // the cursor word index in _CLAP_COMPLETE_INDEX.
    world
        .workon(&world.path())
        .env("COMPLETE", "zsh")
        .env("_CLAP_COMPLETE_INDEX", "2")
        .args(["--", "workon", "attach", ""])
        .assert()
        .success()
        .stdout(predicate::str::contains("ws-abc123"));
}

/// `workon` with `args`, from an empty directory in a fresh world.
fn workon(args: &[&str]) -> assert_cmd::assert::Assert {
    let world = World::new();
    world.workon(&world.path()).args(args).assert()
}

#[test]
fn version_flag() {
    workon(&["--version"]).success().stdout(predicate::str::contains("workon 0."));
}

#[test]
fn help_flag() {
    workon(&["--help"]).success().stdout(predicate::str::contains("Development workspace launcher"));
}

#[test]
fn skip_copy_ignored_requires_workspace() {
    workon(&["--skip-copy-ignored"]).failure().stderr(predicate::str::contains("--skip-copy-ignored"));
}

#[test]
fn help_lists_config_flag() {
    workon(&["--help"]).success().stdout(predicate::str::contains("--config"));
}

#[test]
fn help_lists_subcommands() {
    workon(&["--help"])
        .success()
        .stdout(predicate::str::contains("create"))
        .stdout(predicate::str::contains("attach"))
        .stdout(predicate::str::contains("destroy"))
        .stdout(predicate::str::contains("list"))
        .stdout(predicate::str::contains("path"));
}

#[test]
fn create_help_lists_its_flags() {
    workon(&["create", "--help"])
        .success()
        .stdout(predicate::str::contains("--name"))
        .stdout(predicate::str::contains("--skip-copy-ignored"))
        .stdout(predicate::str::contains("--base"))
        .stdout(predicate::str::contains("--json"));
}

#[test]
fn path_unknown_reference_fails_cleanly() {
    workon(&["path", "definitely-no-such-ws"])
        .failure()
        .stderr(predicate::str::contains("no workspace matches 'definitely-no-such-ws'"));
}

#[test]
fn destroy_help_lists_no_save() {
    workon(&["destroy", "--help"]).success().stdout(predicate::str::contains("--no-save"));
}

/// A bare token (no slash) is a ws_id/nickname; with no matching workspace it
/// should fail cleanly rather than be misread as a flag or path. Proves the
/// subcommand + positional parse and reaches lookup.
#[test]
fn destroy_unknown_reference_fails_cleanly() {
    workon(&["destroy", "definitely-no-such-ws"]).failure().stderr(predicate::str::contains("definitely-no-such-ws"));
}

/// `--resume` is workspace-only. Guards the `requires = "workspace"` constraint
/// across the change of `-w` from an optional-value arg to a plain bool flag.
#[test]
fn resume_requires_workspace() {
    workon(&["--resume", "some-session-id"]).failure().stderr(predicate::str::contains("--resume"));
}

#[test]
fn help_lists_name_flag() {
    workon(&["--help"]).success().stdout(predicate::str::contains("--name"));
}

#[test]
fn help_lists_new_session_long_flag() {
    workon(&["--help"]).success().stdout(predicate::str::contains("--new-session"));
}

/// `-n` used to force a new session; it's now an inert no-op. It must still
/// *parse* (no "unexpected argument") — proven by reaching the config error
/// rather than a clap parse error.
#[test]
fn reserved_n_short_flag_is_accepted_as_noop() {
    workon(&["-n", "--config", "no-such-config"]).failure().stderr(predicate::str::contains("no-such-config"));
}

/// `-w` is now a pure boolean flag — it must not swallow the following
/// `--config` token as a value. If it did, config resolution wouldn't run and
/// we'd never see the "no-such-config" error.
#[test]
fn workspace_flag_takes_no_value() {
    workon(&["-w", "--config", "no-such-config"]).failure().stderr(predicate::str::contains("no-such-config"));
}

#[test]
fn missing_named_config_errors_cleanly() {
    workon(&["--config", "no-such-config"])
        .failure()
        .stderr(predicate::str::contains("no-such-config"))
        .stderr(predicate::str::contains("#creating-a-config"));
}

#[test]
fn invalid_config_name_with_path_traversal_is_rejected() {
    workon(&["--config", "../etc/hosts"]).failure().stderr(predicate::str::contains("invalid config name"));
}

/// `workon create --name <name> --json` in `proj`. Returns the JSON report.
fn create_json(world: &World, proj: &Path, name: &str) -> serde_json::Value {
    let out =
        world.workon(proj).args(["create", "--name", name, "--json"]).assert().success().get_output().stdout.clone();
    serde_json::from_slice(&out).expect("create --json prints JSON")
}

/// `--name` becomes the ws_id's label, and `--name ""` means no name: a bare
/// `ws-xxxxxx` rather than one ending in an empty `-` label.
#[test]
fn create_name_labels_the_ws_id_and_empty_name_is_no_name() {
    let world = World::new();
    let proj = world.project(&[]);
    let labelled = create_json(&world, &proj, "Fix Bug");
    assert_eq!(labelled["failed_steps"], serde_json::json!([]), "nothing failed: {labelled}");
    let labelled = labelled["ws_id"].as_str().unwrap().to_string();
    assert!(labelled.starts_with("ws-") && labelled.ends_with("-fix-bug"), "{labelled}");
    assert_eq!(labelled.len(), "ws-abcdef-fix-bug".len(), "{labelled}");

    let unnamed = create_json(&world, &proj, "")["ws_id"].as_str().unwrap().to_string();
    assert_eq!(unnamed.len(), "ws-abcdef".len(), "{unnamed}");
    assert!(unnamed.starts_with("ws-") && !unnamed.ends_with('-'), "{unnamed}");
}

/// Creating a workspace pre-accepts Claude Code's trust dialog for it, in the
/// `~/.claude.json` under `$HOME`.
#[test]
fn create_trusts_the_worktree_in_claude_json() {
    let world = World::new();
    let proj = world.project(&[]);
    let report = create_json(&world, &proj, "");
    let path = report["path"].as_str().unwrap();

    let claude: serde_json::Value =
        serde_json::from_str(&std::fs::read_to_string(world.home().join(".claude.json")).unwrap()).unwrap();
    assert_eq!(claude["projects"][path]["hasTrustDialogAccepted"], serde_json::Value::Bool(true), "{claude}");
}

/// `workon create` copies the project's gitignored files into the worktree and
/// says what it did on stderr: the up-front notice (no time estimate for a
/// handful of files), a warning per file or nested repo it could not copy, and
/// a summary counting what was cloned whole and what was copied one by one.
/// Files under a tracked directory (`config/`) can't be cloned as a top-level
/// entry, so they are the ones copied individually.
#[test]
fn create_reports_the_gitignored_files_it_copies() {
    use std::os::unix::fs::PermissionsExt;

    let world = World::new();
    let proj = world
        .project(&[(".gitignore", ".env\nconfig/*.key\nconfig/gem/\nconfig/bad/\n"), ("config/app.yml", "tracked\n")]);

    std::fs::write(proj.join(".env"), "SECRET=1\n").unwrap();
    std::fs::write(proj.join("config/master.key"), "key\n").unwrap();
    // Nested repos (a bundler git checkout) are listed as directories.
    for nested in ["config/gem", "config/bad"] {
        std::fs::create_dir_all(proj.join(nested)).unwrap();
        world.git(&proj.join(nested), &["init", "-q"]);
        std::fs::write(proj.join(nested).join("file"), "x\n").unwrap();
    }
    let unreadable = [proj.join("config/locked.key"), proj.join("config/bad/file")];
    for path in &unreadable {
        std::fs::write(path, "x\n").unwrap();
        std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o000)).unwrap();
    }
    // Root reads anything, so it would see no failures to warn about.
    let can_fail = std::fs::File::open(&unreadable[0]).is_err();

    let output = world.workon(&proj).args(["create", "--json"]).output().unwrap();
    for path in &unreadable {
        std::fs::set_permissions(path, std::fs::Permissions::from_mode(0o644)).unwrap();
    }
    assert!(output.status.success(), "{output:?}");
    let stderr = String::from_utf8_lossy(&output.stderr);

    assert!(stderr.contains("Cloning 5 gitignored files (skip with --skip-copy-ignored)..."), "{stderr}");
    if can_fail {
        assert!(stderr.contains("Warning: could not copy config/locked.key"), "{stderr}");
        assert!(stderr.contains("Warning: could not clone dir config/bad"), "{stderr}");
        assert!(stderr.contains("Cloned 5 gitignored files (1 dirs cloned, 2 copied individually)"), "{stderr}");
    }
}

/// A project with a mise config, created by a user whose mise shims directory
/// exists but is not on PATH and who has no `mise activate`, gets the warning that
/// non-interactive shells will miss the pinned tool versions. The shims directory
/// is looked up under `$HOME`; the stub `mise` answers `--version`, so `mise trust`
/// runs and the shims check after it.
#[test]
fn create_warns_when_mise_shims_are_off_path() {
    let world = World::new();
    let proj = world.project(&[("mise.toml", "[tools]\n")]);
    std::fs::create_dir_all(world.home().join(".local/share/mise/shims")).unwrap();

    let output = world.workon(&proj).args(["create", "--json"]).output().unwrap();
    assert!(output.status.success(), "{output:?}");

    let stderr = String::from_utf8_lossy(&output.stderr);
    assert!(stderr.contains("Warning: mise shims directory is not on your PATH"), "{stderr}");
    let trusted = Path::new(&world.stubs.call("mise", "trust").args[1]).to_path_buf();
    assert!(trusted.starts_with(world.worktrees()) && trusted.ends_with("mise.toml"), "{trusted:?}");
}

const RAILS: (&str, &str) = ("config/database.yml", "test:\n  adapter: postgresql\n");

/// Runs `workon create` with `args` in a project holding `files`, where `stubs` replace the
/// default stand-ins; asserts exit 3 (not ready) and returns stdout and stderr.
fn create_not_ready(files: &[(&str, &str)], stubs: &[(&str, &str)], args: &[&str]) -> (World, String, String) {
    let world = World::new();
    let proj = world.project(files);
    for (name, body) in stubs {
        world.stubs.set(name, body);
    }
    let out = world.workon(&proj).arg("create").args(args).assert().code(3).get_output().clone();
    let (stdout, stderr) =
        (String::from_utf8_lossy(&out.stdout).into_owned(), String::from_utf8_lossy(&out.stderr).into_owned());
    (world, stdout, stderr)
}

fn last_lines(text: &str, n: usize) -> Vec<&str> {
    let lines: Vec<&str> = text.lines().collect();
    lines[lines.len().saturating_sub(n)..].to_vec()
}

/// Issue #2: a Rails schema load that fails is reported by `create`, in its JSON and in its last
/// lines, which name the command that opens the workspace anyway. It exits 3 and keeps the
/// workspace, so a script can tell it from a create that made nothing.
#[test]
fn create_reports_a_failed_schema_load() {
    let failing = [("bundle", "echo 'bundler: cannot load' >&2; exit 1")];
    let (_world, stdout, stderr) = create_not_ready(&[RAILS], &failing, &["--json"]);

    let report: serde_json::Value = serde_json::from_str(&stdout).unwrap();
    assert_eq!(report["failed_steps"], serde_json::json!(["rails db:schema:load"]), "{report}");
    let ws_id = report["ws_id"].as_str().unwrap();
    assert!(Path::new(report["path"].as_str().unwrap()).is_dir(), "the workspace is kept: {report}");
    assert!(stderr.contains("bundler: cannot load"), "the step's own error is shown: {stderr}");
    assert_eq!(
        last_lines(&stderr, 2),
        [
            "Warning: the workspace is not ready; failed (output above): rails db:schema:load".to_string(),
            format!("Open it anyway with: workon attach {ws_id}"),
        ],
        "{stderr}"
    );
}

/// Without --json the path still goes to stdout, and the same two lines end stderr.
#[test]
fn create_without_json_ends_with_the_same_lines() {
    let failing = [("bundle", "exit 1")];
    let (_world, stdout, stderr) = create_not_ready(&[RAILS], &failing, &[]);

    let path = stdout.trim();
    assert!(Path::new(path).is_dir(), "{stdout}");
    let ws_id = path.rsplit_once("proj-").map(|(_, id)| id).unwrap();
    assert_eq!(
        last_lines(&stderr, 2),
        [
            "Warning: the workspace is not ready; failed (output above): rails db:schema:load".to_string(),
            format!("Open it anyway with: workon attach {ws_id}"),
        ],
        "{stderr}"
    );
}

/// A test database that cannot be created (the server is down) is a failed step too: the
/// workspace would otherwise run its tests against the shared database.
#[test]
fn create_reports_a_test_database_it_could_not_create() {
    let failing = [("createdb", "echo 'createdb: error: connection refused' >&2; exit 1")];
    let (_world, stdout, stderr) = create_not_ready(&[RAILS], &failing, &["--json"]);

    let report: serde_json::Value = serde_json::from_str(&stdout).unwrap();
    let steps = report["failed_steps"].as_array().unwrap();
    assert_eq!(steps.len(), 1, "{report}");
    assert!(steps[0].as_str().unwrap().starts_with("create test database proj_ws_"), "{report}");
    assert_eq!(report["dbs"], serde_json::json!([]), "nothing to drop: {report}");
    assert!(stderr.contains("is the Postgres server running?"), "the reason is shown: {stderr}");
}

/// Issue #4: git-sourced gems live in a per-checkout bundler path the gitignored-file clone
/// does not cover, so a workspace with a Gemfile gets `bundle check || bundle install` before
/// the schema load. A passing check means the gems are already there: no install runs.
#[test]
fn create_checks_gems_before_loading_the_schema() {
    let world = World::new();
    let proj = world.project(&[RAILS, ("Gemfile", "source \"https://rubygems.org\"\n")]);

    let out = world.workon(&proj).args(["create", "--json"]).output().unwrap();
    assert!(out.status.success(), "{out:?}");

    let report: serde_json::Value = serde_json::from_slice(&out.stdout).unwrap();
    let ws = Path::new(report["path"].as_str().unwrap());
    let calls = world.stubs.calls("bundle");
    assert_eq!(calls.len(), 2, "{calls:?}");
    assert_eq!(calls[0].args, ["check"], "the gems are checked first: {calls:?}");
    assert_eq!(&calls[0].cwd, ws, "in the new workspace: {calls:?}");
    assert_eq!(calls[1].args, ["exec", "rails", "db:schema:load"], "the schema load follows: {calls:?}");
}

/// A failing check (the git-sourced gem is not yet checked out) runs the install,
/// then the schema load.
#[test]
fn create_installs_gems_when_the_check_fails() {
    let world = World::new();
    let proj = world.project(&[RAILS, ("Gemfile", "source \"https://rubygems.org\"\n")]);
    world.stubs.set("bundle", "if [ \"$1\" = check ]; then exit 1; fi\nexit 0");

    let out = world.workon(&proj).args(["create", "--json"]).output().unwrap();
    assert!(out.status.success(), "{out:?}");

    let calls = world.stubs.calls("bundle");
    let args: Vec<Vec<&str>> = calls.iter().map(|c| c.args.iter().map(String::as_str).collect()).collect();
    assert_eq!(args, [vec!["check"], vec!["install"], vec!["exec", "rails", "db:schema:load"]], "{calls:?}");
}

/// A failed install is a failed step, and the schema load it would have left half-run
/// does not run.
#[test]
fn create_reports_a_failed_bundle_install() {
    let failing = [(
        "bundle",
        "if [ \"$1\" = check ]; then exit 1; fi\n\
         if [ \"$1\" = install ]; then echo 'bundler: not yet checked out' >&2; exit 1; fi\nexit 0",
    )];
    let (world, stdout, stderr) =
        create_not_ready(&[RAILS, ("Gemfile", "source \"https://rubygems.org\"\n")], &failing, &["--json"]);

    let report: serde_json::Value = serde_json::from_str(&stdout).unwrap();
    assert_eq!(report["failed_steps"], serde_json::json!(["bundle install"]), "{report}");
    assert!(stderr.contains("bundler: not yet checked out"), "the step's own error is shown: {stderr}");
    let calls = world.stubs.calls("bundle");
    assert!(calls.iter().all(|c| c.args.first().is_some_and(|a| a != "exec")), "no schema load: {calls:?}");
}

/// Without a Gemfile there is nothing to check or install: the schema load is the only
/// bundle call.
#[test]
fn create_without_a_gemfile_skips_the_gem_check() {
    let world = World::new();
    let proj = world.project(&[RAILS]);

    world.workon(&proj).args(["create", "--json"]).assert().success();

    let calls = world.stubs.calls("bundle");
    let args: Vec<Vec<&str>> = calls.iter().map(|c| c.args.iter().map(String::as_str).collect()).collect();
    assert_eq!(args, [vec!["exec", "rails", "db:schema:load"]], "{calls:?}");
}

/// Every provisioner with a setup step carries its failure through to `failed_steps`.
#[test]
fn each_provisioner_reports_its_failed_steps() {
    let csproj = "<Project><ItemGroup><PackageReference Include=\"Npgsql.EntityFrameworkCore.PostgreSQL\" Version=\"9.0.0\" /></ItemGroup></Project>\n";
    // The project's files, the stand-in that fails, the steps it should report, and the variable
    // its Setup still records, and the env file the framework reads it from.
    type Case<'a> = (&'a [(&'a str, &'a str)], (&'a str, &'a str), &'a [&'a str], &'a str, Option<&'a str>);
    let cases: [Case<'_>; 4] = [
        (
            &[("artisan", "#!/usr/bin/env php\n"), ("phpunit.xml", "<env name=\"DB_CONNECTION\" value=\"pgsql\"/>\n")],
            ("php", "exit 1"),
            &["php artisan migrate"],
            "DB_URL",
            Some(".env.testing"),
        ),
        (
            &[("prisma/schema.prisma", "datasource db {\n  provider = \"postgresql\"\n}\n")],
            ("npx", "exit 1"),
            &["prisma schema apply", "prisma generate"],
            "DATABASE_URL",
            Some(".env.test.local"),
        ),
        (
            &[("App/App.csproj", csproj)],
            ("dotnet", "exit 1"),
            &["dotnet tool restore", "dotnet ef database update"],
            "ConnectionStrings__",
            Some(".env.test.local"),
        ),
        (
            &[("mix.exs", "def project do [app: :shop, deps: [{:ecto_sql, \"~> 3.10\"}]] end\n")],
            ("mix", "case \"$1\" in ecto.create) exit 0 ;; *) exit 1 ;; esac"),
            &["mix ecto.migrate"],
            "MIX_TEST_PARTITION",
            None,
        ),
    ];
    for (files, stub, expected, var, env_file) in cases {
        let (_world, stdout, _stderr) = create_not_ready(files, &[stub], &["--json"]);
        let report: serde_json::Value = serde_json::from_str(&stdout).unwrap();
        assert_eq!(report["failed_steps"], serde_json::json!(expected), "{} failing: {report}", stub.0);
        assert_eq!(report["dbs"].as_array().map(Vec::len), Some(1), "the database is kept for teardown: {report}");
        let meta = std::fs::read_to_string(Path::new(report["path"].as_str().unwrap()).join(".workon.json")).unwrap();
        assert!(meta.contains(var), "{} keeps {var} for the session: {meta}", stub.0);
        if let Some(file) = env_file {
            let written =
                std::fs::read_to_string(Path::new(report["path"].as_str().unwrap()).join(file)).unwrap_or_default();
            assert!(written.contains(var), "{} writes {var} to {file}: {written:?}", stub.0);
        }
    }
}

/// A running session for this project whose process tree lacks the layout's focused command
/// (`claude`) was started with another layout: plain `workon` refuses to attach to it rather
/// than silently giving the user the running layout.
#[test]
fn workon_refuses_to_attach_to_a_session_running_another_layout() {
    let world = World::new();
    let proj = world.project(&[]);
    world.stubs.set(
        "zellij",
        "case \"$1\" in --version) echo 'zellij 0.43.1' ;; list-sessions) echo 'proj [Created 1m ago]' ;; esac",
    );
    world.stubs.set("pgrep", "echo 4242");
    world.stubs.set("ps", "printf '4243 4242 /bin/zsh\\n4244 4243 /opt/homebrew/bin/opencode\\n'");

    let out = world.workon(&proj).assert().failure().get_output().clone();

    let stderr = String::from_utf8_lossy(&out.stderr);
    assert!(
        stderr.contains("zellij session 'proj' is already running in the main worktree with a different layout"),
        "{stderr}"
    );
    assert!(world.stubs.calls("zellij").iter().all(|c| c.args.first().is_none_or(|a| a != "attach")), "never attached");
}

/// With no reference, `path` finds the workspace the cwd is inside, from any depth, and
/// refuses outside one.
#[test]
fn path_without_a_reference_finds_the_enclosing_workspace() {
    let world = World::new();
    let proj = world.project(&[]);
    let created = create_json(&world, &proj, "deep");
    let ws = Path::new(created["path"].as_str().unwrap()).to_path_buf();
    let deep = ws.join("a/b");
    std::fs::create_dir_all(&deep).unwrap();

    for dir in [&ws, &deep] {
        let out = world.workon(dir).arg("path").assert().success().get_output().stdout.clone();
        assert_eq!(String::from_utf8_lossy(&out).trim(), ws.to_str().unwrap(), "from {}", dir.display());
    }
    world.workon(&proj).arg("path").assert().failure().stderr(predicate::str::contains("not inside a workspace"));
}

/// `create --base` is parsed and handed to the backend before any workspace is made: with no
/// jj on PATH the git backend refuses it and nothing is created.
#[test]
fn create_base_is_refused_before_anything_is_made_without_jj() {
    let world = World::new();
    let proj = world.project(&[]);
    world
        .workon(&proj)
        .args(["create", "--base", "main"])
        .assert()
        .failure()
        .stderr(predicate::str::contains("--base needs jj installed"));
    assert!(!world.worktrees().exists() || std::fs::read_dir(world.worktrees()).unwrap().next().is_none());
}