# Headless proof for [#20825](https://github.com/pingdotgg/t3code/pull/20825)

Head: `1b3b634297c4f12ead8d0325e6ba1e14c5e9b852`. Linux / Node 24.

This executes the production mobile checkout helper against the real GitVcsDriver service, with JSON round-trip and VcsListRefsResult schema decoding. It uses disposable local Git repositories, bare remotes and linked worktrees. It does not mount React/native UI, send WebSocket requests, submit drafts or start an agent. Older-server behavior is simulated by dropping the optional isAtRepositoryRoot field after schema decoding.

The mismatched-upstream scenario is a separate static fixture phase with a new service runtime, avoiding dependence on expiry of the existing refresh-coalescing cache. Reused/rejected selections never switch the original checkout; its main branch and contents are asserted unchanged. The mismatched remote and freed historical branch use production switchRef, with null worktree overrides. A stale historical path never survives a successful checkout. The held worktree retains its contents, including after it moves to another branch to free the historical branch.

Native iOS/Android, macOS/Windows and Electron remain unverified. No layout change is claimed.

Run: `node --experimental-transform-types --import /tmp/worktree-git-11b/register-loader.mjs /tmp/worktree-git-11b/headless-proof.mjs`. The loader only resolves extensionless relative TypeScript imports for Node; production modules execute directly. This proof script and both loader files live outside the checkout.

## Production service and helper output

```json
{
  "head": "1b3b634297c4f12ead8d0325e6ba1e14c5e9b852",
  "transport": "in-process real GitVcsDriver -> JSON and VcsListRefsResult schema -> production mobile helper",
  "uiVerified": false,
  "scenarios": [
    {
      "scenario": "root project, historical branch",
      "outcome": "selected",
      "branch": "feature/a",
      "worktreePath": "/tmp/20825-headless-eNRI0d/held"
    },
    {
      "scenario": "root project, direct picker",
      "outcome": "selected",
      "branch": "feature/a",
      "worktreePath": "/tmp/20825-headless-eNRI0d/held"
    },
    {
      "scenario": "matching slash-containing remote",
      "outcome": "selected",
      "branch": "feature/a",
      "worktreePath": "/tmp/20825-headless-eNRI0d/held"
    },
    {
      "scenario": "symlinked root project, direct picker",
      "outcome": "selected",
      "branch": "feature/a",
      "worktreePath": "/tmp/20825-headless-eNRI0d/held"
    },
    {
      "scenario": "nested project, historical",
      "outcome": "rejected",
      "message": "Error: This project is a repository subdirectory. Choose another branch or add the repository root as a project to reuse this worktree."
    },
    {
      "scenario": "nested project, picker",
      "outcome": "rejected",
      "message": "Error: This project is a repository subdirectory. Choose another branch or add the repository root as a project to reuse this worktree."
    },
    {
      "scenario": "older server missing root metadata",
      "outcome": "rejected",
      "message": "Error: The server did not report whether this project is at the repository root, so this worktree cannot be reused safely. Update the server or choose another branch."
    },
    {
      "scenario": "nested project, already-current historical branch",
      "outcome": "selected",
      "branch": "main",
      "worktreePath": null
    },
    {
      "scenario": "different upstream uses actual server switchRef",
      "outcome": "selected",
      "branch": "upstream/feature/a",
      "worktreePath": null
    },
    {
      "scenario": "free historical branch clears its previous worktree path",
      "outcome": "selected",
      "branch": "feature/a",
      "worktreePath": null
    }
  ],
  "assertions": "all passed; reused/rejected paths never switched original checkout; mismatched-remote and free-branch fallbacks used real switchRef; held worktree contents unchanged"
}
```


## Nested/old-server before fix: 4 expected failures, 9 passed

```text
note: You are running `vp test` as a Vite+ built-in command. If you meant to run the test npm script, use `vpr test` instead.

 RUN  v5.0.1 /home/ubuntu/wt/worktree-git-11b

 ❯ apps/mobile/src/features/threads/checkout-new-task-branch.test.ts (13 tests | 4 failed) 2363ms
   ❯ new-task branch checkout (13)
     × rejects historical worktree reuse when project root is unsafe (nested: true) 99ms
     × rejects picker worktree reuse when project root is unsafe (nested: true) 77ms
     × rejects historical worktree reuse when project root is unsafe (nested: false) 87ms
     × rejects picker worktree reuse when project root is unsafe (nested: false) 77ms

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 4 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  apps/mobile/src/features/threads/checkout-new-task-branch.test.ts > new-task branch checkout > rejects historical worktree reuse when project root is unsafe (nested: true)
 FAIL  apps/mobile/src/features/threads/checkout-new-task-branch.test.ts > new-task branch checkout > rejects picker worktree reuse when project root is unsafe (nested: true)
 FAIL  apps/mobile/src/features/threads/checkout-new-task-branch.test.ts > new-task branch checkout > rejects historical worktree reuse when project root is unsafe (nested: false)
 FAIL  apps/mobile/src/features/threads/checkout-new-task-branch.test.ts > new-task branch checkout > rejects picker worktree reuse when project root is unsafe (nested: false)
AssertionError: expected 'Success' to be 'Failure' // Object.is equality

Expected: "Failure"
Received: "Success"

 ❯ apps/mobile/src/features/threads/checkout-new-task-branch.test.ts:351:27
    349|         "feature\n",
    350|       );
    351|       expect(result._tag).toBe("Failure");
       |                           ^
    352|       if (result._tag !== "Failure") throw new Error("Expected unsafe …
    353|       if (nested) {

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/4]⎯


 Test Files  1 failed (1)
      Tests  4 failed | 9 passed (13)
   Start at  22:44:19
   Duration  5.19s (tests 47%, transform 33%, import 18%, setup 2%)


```


## Symlink-root regression before server identity fix: 1 expected failure

```text
note: You are running `vp test` as a Vite+ built-in command. If you meant to run the test npm script, use `vpr test` instead.

 RUN  v5.0.1 /home/ubuntu/wt/worktree-git-11b

 ❯ apps/mobile/src/features/threads/checkout-new-task-branch.test.ts (14 tests | 1 failed | 13 skipped) 166ms
   ❯ new-task branch checkout (14)
     × reuses an occupied picker worktree when the project root is a symlink 163ms

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  apps/mobile/src/features/threads/checkout-new-task-branch.test.ts > new-task branch checkout > reuses an occupied picker worktree when the project root is a symlink
AssertionError: Error: This project is a repository subdirectory. Choose another branch or add the repository root as a project to reuse this worktree.: expected 'Failure' to be 'Success' // Object.is equality

Expected: "Success"
Received: "Failure"

 ❯ apps/mobile/src/features/threads/checkout-new-task-branch.test.ts:242:7
    240|       result._tag,
    241|       result._tag === "Failure" ? String(squashAtomCommandFailure(resu…
    242|     ).toBe("Success");
       |       ^
    243|     if (result._tag !== "Success") throw new Error("Symlink-root workt…
    244|     expect(result.value.worktreePath).toBe(worktreePath);

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯


 Test Files  1 failed (1)
      Tests  1 failed | 13 skipped (14)
   Start at  22:52:25
   Duration  2.41s (transform 55%, import 34%, tests 7%, setup 4%)


```


## Stale historical worktree path before fix: 1 expected failure

```text
note: You are running `vp test` as a Vite+ built-in command. If you meant to run the test npm script, use `vpr test` instead.

 RUN  v5.0.1 /home/ubuntu/wt/worktree-git-11b

 ❯ apps/mobile/src/features/threads/checkout-new-task-branch.test.ts (14 tests | 1 failed | 13 skipped) 139ms
   ❯ new-task branch checkout (14)
     × switches to a free branch and clears its historical worktree path 137ms

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  apps/mobile/src/features/threads/checkout-new-task-branch.test.ts > new-task branch checkout > switches to a free branch and clears its historical worktree path
AssertionError: expected '/tmp/t3-branch-selection-wmhYAZ/previ…' to be null

- Expected:
null

+ Received:
"/tmp/t3-branch-selection-wmhYAZ/previous-worktree"

 ❯ apps/mobile/src/features/threads/checkout-new-task-branch.test.ts:153:39
    151|     expect(result.value.name).toBe("feature/a");
    152|     expect(result.value.current).toBe(true);
    153|     expect(result.value.worktreePath).toBeNull();
       |                                       ^
    154|     expect((await git("branch", "--show-current")).stdout.trim()).toBe…
    155|     expect(await NodeFSP.readFile(NodePath.join(cwd, "file.txt"), "utf…

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯


 Test Files  1 failed (1)
      Tests  1 failed | 13 skipped (14)
   Start at  23:09:42
   Duration  2.48s (transform 57%, import 32%, tests 6%, setup 5%)
```

## Mobile after all fixes plus neighbors: 41 passed

```text
note: You are running `vp test` as a Vite+ built-in command. If you meant to run the test npm script, use `vpr test` instead.

 RUN  v5.0.1 /home/ubuntu/wt/worktree-git-11b


 Test Files  3 passed (3)
      Tests  41 passed (41)
   Start at  23:09:53
   Duration  3.85s (transform 42%, tests 27%, import 27%, setup 4%)

  Transform  transforming modules took 2.74s · 42% of tracked time, re-done on every run
             persist transforms across runs with fsModuleCache: true
             learn more: https://vitest.dev/guide/improving-performance#caching-between-reruns
```


## Server before boolean metadata: 1 expected failure, 7 passed

```text
note: You are running `vp test` as a Vite+ built-in command. If you meant to run the test npm script, use `vpr test` instead.

 RUN  v5.0.1 /home/ubuntu/wt/worktree-git-11b

stdout | apps/server/src/vcs/GitVcsDriverCore.test.ts > GitVcsDriver core integration > refName operations > lists root and upstream metadata and optionally includes matching remote refs
[22:53:07.316] ERROR (#21): Error [AssertionError]: expected [ { …(6) }, { …(6) } ] to deeply equal [ { …(7) }, { …(7) } ]
    at /home/ubuntu/wt/worktree-git-11b/apps/server/src/vcs/GitVcsDriverCore.test.ts:3281:16 {
  actual: [
    {
      rootPath: '/tmp/git-vcs-driver-worktree-QJrBhM',
      refs: [Array],
      isRepo: true,
      hasPrimaryRemote: true,
      nextCursor: null,
      totalCount: 5
    },
    {
      rootPath: '/tmp/git-vcs-driver-worktree-QJrBhM',
      refs: [Array],
      isRepo: true,
      hasPrimaryRemote: true,
      nextCursor: null,
      totalCount: 4
    }
  ],
  expected: [
    {
      rootPath: '/tmp/git-vcs-driver-worktree-QJrBhM',
      refs: [Array],
      isRepo: true,
      hasPrimaryRemote: true,
      nextCursor: null,
      totalCount: 5,
      isAtRepositoryRoot: false
    },
    {
      rootPath: '/tmp/git-vcs-driver-worktree-QJrBhM',
      refs: [Array],
      isRepo: true,
      hasPrimaryRemote: true,
      nextCursor: null,
      totalCount: 4,
      isAtRepositoryRoot: true
    }
  ],
  showDiff: true,
  operator: 'deepStrictEqual',
  [cause]: undefined
}

 ❯ apps/server/src/vcs/GitVcsDriverCore.test.ts (176 tests | 1 failed | 168 skipped) 2708ms
   ❯ GitVcsDriver core integration (133)
     ❯ refName operations (8)
       × lists root and upstream metadata and optionally includes matching remote refs 969ms

⎯⎯⎯⎯⎯⎯⎯ Failed Tests 1 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  apps/server/src/vcs/GitVcsDriverCore.test.ts > GitVcsDriver core integration > refName operations > lists root and upstream metadata and optionally includes matching remote refs
AssertionError: expected [ { …(6) }, { …(6) } ] to deeply equal [ { …(7) }, { …(7) } ]

- Expected
+ Received

@@ -1,9 +1,8 @@
  [
    {
      "hasPrimaryRemote": true,
-     "isAtRepositoryRoot": false,
      "isRepo": true,
      "nextCursor": null,
      "refs": [
        {
          "current": true,
@@ -48,11 +47,10 @@
      "rootPath": "/tmp/git-vcs-driver-worktree-QJrBhM",
      "totalCount": 5,
    },
    {
      "hasPrimaryRemote": true,
-     "isAtRepositoryRoot": true,
      "isRepo": true,
      "nextCursor": null,
      "refs": [
        {
          "current": true,

 ❯ apps/server/src/vcs/GitVcsDriverCore.test.ts:3281:16
    3279|           { ...aliased, isAtRepositoryRoot: true },
    3280|         ];
    3281|         assert.deepEqual([complete, aliased], expected);
       |                ^
    3282|         assert.deepEqual(
    3283|           [decodeVcsListRefsResult(complete), decodeVcsListRefsResult(…
 ❯ IteratorImpl.~effect/Effect/successCont node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:1422:28
 ❯ ExitPrimitive.~effect/Effect/evaluate node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/core.ts:585:30
 ❯ FiberImpl.runLoop node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:654:41
 ❯ FiberImpl.evaluate node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:595:23
 ❯ FiberImpl.evaluate node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:589:27
 ❯ Array.<anonymous> node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:1159:17
 ❯ FiberImpl.evaluate node_modules/.pnpm/effect@4.0.5/node_modules/effect/src/internal/effect.ts:618:21

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯


 Test Files  1 failed (1)
      Tests  1 failed | 7 passed | 168 skipped (176)
   Start at  22:53:02
   Duration  6.70s (tests 42%, transform 40%, import 16%, setup 2%)

  Transform  transforming modules took 2.58s · 40% of tracked time, re-done on every run
             persist transforms across runs with fsModuleCache: true
             learn more: https://vitest.dev/guide/improving-performance#caching-between-reruns


```


## Server after all fixes and junction fixture: 8 passed

```text
note: You are running `vp test` as a Vite+ built-in command. If you meant to run the test npm script, use `vpr test` instead.

 RUN  v5.0.1 /home/ubuntu/wt/worktree-git-11b


 Test Files  1 passed (1)
      Tests  8 passed | 168 skipped (176)
   Start at  22:56:20
   Duration  5.15s (tests 47%, transform 33%, import 17%, setup 2%)
```


## Other verification

25 shared VCS/action tests passed. Mobile, contracts, client-runtime and server typechecks passed. Scoped lint and formatting passed; four pre-existing lint warnings remain. Original mobile suite: 11 cases; rebuilt suite: 14 cases, including 4 nested/old-server rows and one symlink-root case. The existing checkout case also verifies a stale historical worktree path is cleared after successful checkout. Existing server test extended in place; no server case added. No full repository suite was run. Independent review records are tracked separately.
