@dfosco/storyboard-core 4.2.6 → 4.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/scaffold/AGENTS.md +1 -1
- package/scaffold/skills/ship/SKILL.md +1 -1
- package/scaffold/skills/worktree/SKILL.md +7 -24
- package/src/canvas/terminal-config.js +2 -2
- package/src/cli/branch.js +6 -6
- package/src/cli/code.js +3 -3
- package/src/cli/dev.js +5 -5
- package/src/server/index.js +1 -1
- package/src/worktree/port.js +20 -20
- package/src/worktree/port.test.js +21 -21
package/package.json
CHANGED
package/scaffold/AGENTS.md
CHANGED
|
@@ -66,7 +66,7 @@ The default location is in `.agents/plans`, but the user may ask for a specific
|
|
|
66
66
|
|
|
67
67
|
- **create** (`.agents/skills/create/SKILL.md`) — Walks through creating Storyboard assets: prototype, external prototype, flow, page, canvas, object, or record.
|
|
68
68
|
|
|
69
|
-
- **worktree** (`.agents/skills/worktree/SKILL.md`) — Creates a git worktree in
|
|
69
|
+
- **worktree** (`.agents/skills/worktree/SKILL.md`) — Creates a git worktree in `worktrees/<branch-name>` and switches into it.
|
|
70
70
|
|
|
71
71
|
- **tools** (`.agents/skills/tools/SKILL.md`) — Reference for creating toolbar tools: config schema, handlers, surfaces, and render types.
|
|
72
72
|
|
|
@@ -34,7 +34,7 @@ Invoke the **worktree** skill to create a git worktree for the feature branch.
|
|
|
34
34
|
- If the user provided an explicit branch name, use that instead.
|
|
35
35
|
- Use `ask_user` to confirm the branch name before creating the worktree.
|
|
36
36
|
|
|
37
|
-
After the worktree is created, all subsequent work happens inside
|
|
37
|
+
After the worktree is created, all subsequent work happens inside `worktrees/<branch-name>` **at the repository root** (use `git rev-parse --show-toplevel` to find the root). Never create worktrees nested inside other worktrees.
|
|
38
38
|
|
|
39
39
|
### Step 2: Plan the feature
|
|
40
40
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## What This Does
|
|
6
6
|
|
|
7
|
-
Creates a git worktree for a given branch name inside
|
|
7
|
+
Creates a git worktree for a given branch name inside `worktrees/` and switches into it.
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -12,35 +12,18 @@ Creates a git worktree for a given branch name inside `.worktrees/` and switches
|
|
|
12
12
|
|
|
13
13
|
When the user asks for a worktree named `<branch-name>`:
|
|
14
14
|
|
|
15
|
-
### Step 0: Slugify the branch name
|
|
16
|
-
|
|
17
|
-
Sanitize the branch name to avoid filesystem and subdomain issues:
|
|
18
|
-
|
|
19
|
-
1. Convert to lowercase.
|
|
20
|
-
2. Replace dots (`.`), spaces, underscores, and other non-alphanumeric characters (except `-` and `/`) with hyphens.
|
|
21
|
-
3. Collapse consecutive hyphens into one.
|
|
22
|
-
4. Trim leading/trailing hyphens from each segment.
|
|
23
|
-
|
|
24
|
-
**Examples:**
|
|
25
|
-
- `feature.v2` → `feature-v2`
|
|
26
|
-
- `v3.11.0` → `v3-11-0`
|
|
27
|
-
- `my_cool.feature` → `my-cool-feature`
|
|
28
|
-
- `UPPER.Case` → `upper-case`
|
|
29
|
-
|
|
30
|
-
Use the slugified name for both the **branch name** and **worktree directory** throughout the rest of the workflow.
|
|
31
|
-
|
|
32
15
|
### Step 1: Create the worktree
|
|
33
16
|
|
|
34
17
|
If the branch already exists locally or on the remote:
|
|
35
18
|
|
|
36
19
|
```bash
|
|
37
|
-
git worktree add
|
|
20
|
+
git worktree add worktrees/<branch-name> <branch-name>
|
|
38
21
|
```
|
|
39
22
|
|
|
40
23
|
If the branch does NOT exist yet, create it from the current HEAD:
|
|
41
24
|
|
|
42
25
|
```bash
|
|
43
|
-
git worktree add
|
|
26
|
+
git worktree add worktrees/<branch-name> -b <branch-name>
|
|
44
27
|
```
|
|
45
28
|
|
|
46
29
|
### Step 2: Register a dev-server port
|
|
@@ -59,12 +42,12 @@ Or if the project has `scripts/worktree-port.js`:
|
|
|
59
42
|
node scripts/worktree-port.js <branch-name>
|
|
60
43
|
```
|
|
61
44
|
|
|
62
|
-
This writes to
|
|
45
|
+
This writes to `worktrees/ports.json` (gitignored). The dev server (`npx storyboard-dev`) reads from this file automatically.
|
|
63
46
|
|
|
64
47
|
### Step 3: Change into the worktree directory
|
|
65
48
|
|
|
66
49
|
```bash
|
|
67
|
-
cd
|
|
50
|
+
cd worktrees/<branch-name>
|
|
68
51
|
```
|
|
69
52
|
|
|
70
53
|
All subsequent commands in the session should run from this directory.
|
|
@@ -99,9 +82,9 @@ The dev server automatically uses the port assigned in Step 2.
|
|
|
99
82
|
|
|
100
83
|
## Notes
|
|
101
84
|
|
|
102
|
-
- Worktrees live in
|
|
85
|
+
- Worktrees live in `worktrees/` at the repo root — this directory is already gitignored.
|
|
103
86
|
- The branch name comes from the user's request (e.g., "create worktree comments-redo" → branch is `comments-redo`).
|
|
104
87
|
- **Always slugify** the branch name (Step 0) before creating the worktree. Dots cause issues with subdomain routing and are replaced with hyphens.
|
|
105
88
|
- If the worktree already exists, inform the user and `cd` into it instead of recreating it.
|
|
106
89
|
- Port assignments are stable — once a worktree gets a port, it keeps it across restarts.
|
|
107
|
-
- To see all assigned ports, check
|
|
90
|
+
- To see all assigned ports, check `worktrees/ports.json`.
|
|
@@ -42,9 +42,9 @@ function readDevDomain() {
|
|
|
42
42
|
/** Detect worktree name */
|
|
43
43
|
function getWorktreeName() {
|
|
44
44
|
try {
|
|
45
|
-
// Check if we're in a
|
|
45
|
+
// Check if we're in a worktrees/ directory
|
|
46
46
|
const cwd = rootDir
|
|
47
|
-
const match = cwd.match(
|
|
47
|
+
const match = cwd.match(/worktrees\/([^/]+)/)
|
|
48
48
|
return match ? match[1] : 'main'
|
|
49
49
|
} catch { return 'main' }
|
|
50
50
|
}
|
package/src/cli/branch.js
CHANGED
|
@@ -105,7 +105,7 @@ export async function runBranchGuide(branchArg) {
|
|
|
105
105
|
p.log.success(`Worktree ${bold(targetBranch)} already exists`)
|
|
106
106
|
p.note(
|
|
107
107
|
[
|
|
108
|
-
` ${green('cd')} ${dim(
|
|
108
|
+
` ${green('cd')} ${dim(`worktrees/${targetBranch}`)}`,
|
|
109
109
|
` ${green('npx storyboard dev')} ${dim('to start developing')}`,
|
|
110
110
|
].join('\n'),
|
|
111
111
|
'Ready to go'
|
|
@@ -156,7 +156,7 @@ export async function runBranchGuide(branchArg) {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
// Create the worktree
|
|
159
|
-
const targetDir = resolve(root, '
|
|
159
|
+
const targetDir = resolve(root, 'worktrees', targetBranch)
|
|
160
160
|
const spin = p.spinner()
|
|
161
161
|
|
|
162
162
|
try {
|
|
@@ -164,9 +164,9 @@ export async function runBranchGuide(branchArg) {
|
|
|
164
164
|
? ['worktree', 'add', targetDir, '-b', targetBranch]
|
|
165
165
|
: ['worktree', 'add', targetDir, targetBranch]
|
|
166
166
|
|
|
167
|
-
spin.start(`Creating worktree
|
|
167
|
+
spin.start(`Creating worktree worktrees/${targetBranch}`)
|
|
168
168
|
execFileSync('git', gitArgs, { cwd: root, stdio: 'pipe' })
|
|
169
|
-
spin.stop(`Worktree created:
|
|
169
|
+
spin.stop(`Worktree created: worktrees/${targetBranch}`)
|
|
170
170
|
} catch (err) {
|
|
171
171
|
spin.stop('Failed to create worktree')
|
|
172
172
|
p.log.error(err.message || 'git worktree add failed')
|
|
@@ -211,13 +211,13 @@ export async function runBranchGuide(branchArg) {
|
|
|
211
211
|
|
|
212
212
|
// 7. Summary
|
|
213
213
|
const lines = [
|
|
214
|
-
` Your branch is set up as a worktree in ${green(
|
|
214
|
+
` Your branch is set up as a worktree in ${green(`worktrees/${targetBranch}`)}`,
|
|
215
215
|
]
|
|
216
216
|
if (didStash) {
|
|
217
217
|
lines.push(` Your uncommitted work has been safely moved`)
|
|
218
218
|
}
|
|
219
219
|
lines.push('')
|
|
220
|
-
lines.push(` ${green('cd')} ${dim(
|
|
220
|
+
lines.push(` ${green('cd')} ${dim(`worktrees/${targetBranch}`)}`)
|
|
221
221
|
lines.push(` ${green('npx storyboard dev')} ${dim('to start developing')}`)
|
|
222
222
|
lines.push('')
|
|
223
223
|
lines.push(` ${dim('Tip: ask your AI agent about worktrees — they\'re great!')}`)
|
package/src/cli/code.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Usage:
|
|
5
5
|
* storyboard code # open current worktree or repo root
|
|
6
6
|
* storyboard code main # open repo root
|
|
7
|
-
* storyboard code <branch> # open
|
|
7
|
+
* storyboard code <branch> # open worktrees/<branch>/
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import * as p from '@clack/prompts'
|
|
@@ -33,7 +33,7 @@ if (!branch) {
|
|
|
33
33
|
const name = detectWorktreeName()
|
|
34
34
|
const dir = name === 'main' ? root : worktreeDir(name)
|
|
35
35
|
if (openInCode(dir)) {
|
|
36
|
-
p.outro(`Opened ${name === 'main' ? 'repo root' :
|
|
36
|
+
p.outro(`Opened ${name === 'main' ? 'repo root' : `worktrees/${name}/`}`)
|
|
37
37
|
} else {
|
|
38
38
|
p.log.error('Could not open VS Code. Is the `code` CLI installed?')
|
|
39
39
|
p.log.info('Run `npx storyboard setup` to install it, or open VS Code and run:')
|
|
@@ -59,7 +59,7 @@ if (!branch) {
|
|
|
59
59
|
process.exit(1)
|
|
60
60
|
}
|
|
61
61
|
if (openInCode(dir)) {
|
|
62
|
-
p.outro(`Opened
|
|
62
|
+
p.outro(`Opened worktrees/${branch}/`)
|
|
63
63
|
} else {
|
|
64
64
|
p.log.error('Could not open VS Code.')
|
|
65
65
|
process.exit(1)
|
package/src/cli/dev.js
CHANGED
|
@@ -60,13 +60,13 @@ function remoteBranchExists(name, cwd) {
|
|
|
60
60
|
* @returns {string} path to the new worktree directory
|
|
61
61
|
*/
|
|
62
62
|
function createWorktree(name, root, { newBranch = false } = {}) {
|
|
63
|
-
const targetDir = resolve(root, '
|
|
63
|
+
const targetDir = resolve(root, 'worktrees', name)
|
|
64
64
|
|
|
65
65
|
const gitArgs = newBranch
|
|
66
66
|
? ['worktree', 'add', targetDir, '-b', name]
|
|
67
67
|
: ['worktree', 'add', targetDir, name]
|
|
68
68
|
|
|
69
|
-
p.log.step(`Creating worktree:
|
|
69
|
+
p.log.step(`Creating worktree: worktrees/${name}`)
|
|
70
70
|
execFileSync('git', gitArgs, { cwd: root, stdio: 'inherit' })
|
|
71
71
|
|
|
72
72
|
p.log.step('Installing dependencies…')
|
|
@@ -112,7 +112,7 @@ async function resolveDevTarget(branchArg, { allowCreate = true } = {}) {
|
|
|
112
112
|
// No worktree exists — prompt the user to convert
|
|
113
113
|
p.log.warning(`Root is on branch "${branch}" instead of main.`)
|
|
114
114
|
const shouldConvert = await p.confirm({
|
|
115
|
-
message: `Convert "${branch}" to a worktree? (moves branch to
|
|
115
|
+
message: `Convert "${branch}" to a worktree? (moves branch to worktrees/${branch}/)`,
|
|
116
116
|
initialValue: true,
|
|
117
117
|
})
|
|
118
118
|
|
|
@@ -403,9 +403,9 @@ async function main() {
|
|
|
403
403
|
const { worktreeName, targetCwd, created } = await resolveDevTarget(branchArg, { allowCreate })
|
|
404
404
|
|
|
405
405
|
if (created) {
|
|
406
|
-
p.log.success(`Worktree ready:
|
|
406
|
+
p.log.success(`Worktree ready: worktrees/${worktreeName}`)
|
|
407
407
|
} else if (branchArg) {
|
|
408
|
-
p.log.info(`Using ${worktreeName === 'main' ? 'main repo' :
|
|
408
|
+
p.log.info(`Using ${worktreeName === 'main' ? 'main repo' : `worktrees/${worktreeName}`}`)
|
|
409
409
|
}
|
|
410
410
|
|
|
411
411
|
const domain = readDevDomain(targetCwd)
|
package/src/server/index.js
CHANGED
|
@@ -89,7 +89,7 @@ async function parseBody(req) {
|
|
|
89
89
|
function resolveWorktreeCwd(branch) {
|
|
90
90
|
const root = repoRoot()
|
|
91
91
|
if (branch === 'main') return root
|
|
92
|
-
const wtDir = join(root, '
|
|
92
|
+
const wtDir = join(root, 'worktrees', branch)
|
|
93
93
|
if (existsSync(wtDir)) return wtDir
|
|
94
94
|
return null
|
|
95
95
|
}
|
package/src/worktree/port.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Worktree Port Registry
|
|
3
3
|
*
|
|
4
|
-
* Manages a JSON registry (
|
|
4
|
+
* Manages a JSON registry (worktrees/ports.json) that maps worktree names
|
|
5
5
|
* to unique dev-server ports. Main always gets 1234; worktrees get 1235+.
|
|
6
6
|
*
|
|
7
7
|
* This module is published as part of @dfosco/storyboard-core so client
|
|
@@ -19,10 +19,10 @@ import { findByWorktree } from './serverRegistry.js'
|
|
|
19
19
|
const BASE_PORT = 1234
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* Resolve the path to
|
|
22
|
+
* Resolve the path to worktrees/ports.json.
|
|
23
23
|
*
|
|
24
24
|
* Derives the repo root from directory structure so it works whether
|
|
25
|
-
* running from the repo root or from inside
|
|
25
|
+
* running from the repo root or from inside worktrees/<name>/ — even
|
|
26
26
|
* when ports.json does not exist yet.
|
|
27
27
|
*
|
|
28
28
|
* @param {string} [cwd] — override working directory
|
|
@@ -31,34 +31,34 @@ const BASE_PORT = 1234
|
|
|
31
31
|
export function portsFilePath(cwd = process.cwd()) {
|
|
32
32
|
const realCwd = realpathSync(cwd)
|
|
33
33
|
|
|
34
|
-
// Check if we're inside
|
|
35
|
-
const worktreeMatch = realCwd.match(/^(.+)[/\\]
|
|
34
|
+
// Check if we're inside worktrees/<name>/
|
|
35
|
+
const worktreeMatch = realCwd.match(/^(.+)[/\\]worktrees[/\\][^/\\]+/)
|
|
36
36
|
if (worktreeMatch) {
|
|
37
|
-
return join(worktreeMatch[1], '
|
|
37
|
+
return join(worktreeMatch[1], 'worktrees', 'ports.json')
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// We're at the repo root (or somewhere else) — default location
|
|
41
|
-
return join(realCwd, '
|
|
41
|
+
return join(realCwd, 'worktrees', 'ports.json')
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Detect the worktree name from the current git context.
|
|
46
46
|
*
|
|
47
|
-
* Returns 'main' when not inside a
|
|
47
|
+
* Returns 'main' when not inside a worktrees/<name>/ directory.
|
|
48
48
|
*/
|
|
49
49
|
export function detectWorktreeName() {
|
|
50
50
|
try {
|
|
51
51
|
const topLevel = execSync('git rev-parse --show-toplevel', { encoding: 'utf8' }).trim()
|
|
52
52
|
const realTop = realpathSync(topLevel)
|
|
53
53
|
|
|
54
|
-
// Check if we're inside a
|
|
55
|
-
if (realTop.includes('
|
|
54
|
+
// Check if we're inside a worktrees/<name> directory
|
|
55
|
+
if (realTop.includes('worktrees/') || realTop.includes('worktrees\\')) {
|
|
56
56
|
return basename(realTop)
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// Also check the cwd pattern
|
|
60
60
|
const realCwd = realpathSync(process.cwd())
|
|
61
|
-
const worktreeMatch = realCwd.match(
|
|
61
|
+
const worktreeMatch = realCwd.match(/worktrees[/\\]([^/\\]+)/)
|
|
62
62
|
if (worktreeMatch) return worktreeMatch[1]
|
|
63
63
|
|
|
64
64
|
// Not a worktree — check the current branch name
|
|
@@ -90,7 +90,7 @@ function isPortInUse(port) {
|
|
|
90
90
|
/**
|
|
91
91
|
* Get or assign a port for the given worktree name.
|
|
92
92
|
*
|
|
93
|
-
* Creates
|
|
93
|
+
* Creates worktrees/ports.json if it doesn't exist. Assigns ports
|
|
94
94
|
* starting at BASE_PORT+1 (1235) for non-main worktrees.
|
|
95
95
|
* If the previously assigned port was stolen by another process,
|
|
96
96
|
* reassigns to the next available port.
|
|
@@ -179,7 +179,7 @@ export function resolveRunningPort(worktreeName) {
|
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
/**
|
|
182
|
-
* Resolve the port for a worktree from
|
|
182
|
+
* Resolve the port for a worktree from worktrees/ports.json
|
|
183
183
|
* without assigning a new one if missing.
|
|
184
184
|
*
|
|
185
185
|
* @param {string} worktreeName
|
|
@@ -216,9 +216,9 @@ export function slugify(name) {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
|
-
* Resolve the repo root — the directory that contains
|
|
219
|
+
* Resolve the repo root — the directory that contains `worktrees/`.
|
|
220
220
|
*
|
|
221
|
-
* Works whether cwd is the repo root itself or inside
|
|
221
|
+
* Works whether cwd is the repo root itself or inside `worktrees/<name>/`.
|
|
222
222
|
*
|
|
223
223
|
* @param {string} [cwd]
|
|
224
224
|
* @returns {string} absolute path to repo root
|
|
@@ -226,7 +226,7 @@ export function slugify(name) {
|
|
|
226
226
|
export function repoRoot(cwd = process.cwd()) {
|
|
227
227
|
const realCwd = realpathSync(cwd)
|
|
228
228
|
|
|
229
|
-
const worktreeMatch = realCwd.match(/^(.+)[/\\]
|
|
229
|
+
const worktreeMatch = realCwd.match(/^(.+)[/\\]worktrees[/\\][^/\\]+/)
|
|
230
230
|
if (worktreeMatch) return worktreeMatch[1]
|
|
231
231
|
|
|
232
232
|
return realCwd
|
|
@@ -235,7 +235,7 @@ export function repoRoot(cwd = process.cwd()) {
|
|
|
235
235
|
/**
|
|
236
236
|
* Resolve the full path to a worktree directory.
|
|
237
237
|
*
|
|
238
|
-
* Returns repo root for 'main',
|
|
238
|
+
* Returns repo root for 'main', `worktrees/<name>` otherwise.
|
|
239
239
|
*
|
|
240
240
|
* @param {string} name — worktree name
|
|
241
241
|
* @param {string} [cwd]
|
|
@@ -244,11 +244,11 @@ export function repoRoot(cwd = process.cwd()) {
|
|
|
244
244
|
export function worktreeDir(name, cwd) {
|
|
245
245
|
const root = repoRoot(cwd)
|
|
246
246
|
if (name === 'main') return root
|
|
247
|
-
return join(root, '
|
|
247
|
+
return join(root, 'worktrees', name)
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
/**
|
|
251
|
-
* List existing worktree directory names from
|
|
251
|
+
* List existing worktree directory names from `worktrees/`.
|
|
252
252
|
*
|
|
253
253
|
* Only returns directories that look like real worktrees (contain a `.git` file).
|
|
254
254
|
* Does not include 'main'.
|
|
@@ -258,7 +258,7 @@ export function worktreeDir(name, cwd) {
|
|
|
258
258
|
*/
|
|
259
259
|
export function listWorktrees(cwd) {
|
|
260
260
|
const root = repoRoot(cwd)
|
|
261
|
-
const worktreesDir = join(root, '
|
|
261
|
+
const worktreesDir = join(root, 'worktrees')
|
|
262
262
|
|
|
263
263
|
if (!existsSync(worktreesDir)) return []
|
|
264
264
|
|
|
@@ -43,27 +43,27 @@ describe('portsFilePath', () => {
|
|
|
43
43
|
rmSync(tempRoot, { recursive: true, force: true })
|
|
44
44
|
})
|
|
45
45
|
|
|
46
|
-
it('returns root
|
|
46
|
+
it('returns root worktrees/ports.json from repo root', () => {
|
|
47
47
|
const result = portsFilePath(tempRoot)
|
|
48
|
-
expect(result).toBe(join(tempRoot, '
|
|
48
|
+
expect(result).toBe(join(tempRoot, 'worktrees', 'ports.json'))
|
|
49
49
|
})
|
|
50
50
|
|
|
51
51
|
it('returns shared ports.json from inside a worktree dir', () => {
|
|
52
|
-
// Simulate
|
|
53
|
-
const worktreeDir = join(tempRoot, '
|
|
52
|
+
// Simulate worktrees/my-branch/
|
|
53
|
+
const worktreeDir = join(tempRoot, 'worktrees', 'my-branch')
|
|
54
54
|
mkdirSync(worktreeDir, { recursive: true })
|
|
55
55
|
const result = portsFilePath(worktreeDir)
|
|
56
|
-
expect(result).toBe(join(tempRoot, '
|
|
56
|
+
expect(result).toBe(join(tempRoot, 'worktrees', 'ports.json'))
|
|
57
57
|
})
|
|
58
58
|
|
|
59
59
|
it('returns shared ports.json from worktree even when ports.json does not exist', () => {
|
|
60
60
|
// This is the key bug fix — first run from a worktree with no ports.json
|
|
61
|
-
const worktreeDir = join(tempRoot, '
|
|
61
|
+
const worktreeDir = join(tempRoot, 'worktrees', 'first-run')
|
|
62
62
|
mkdirSync(worktreeDir, { recursive: true })
|
|
63
63
|
const result = portsFilePath(worktreeDir)
|
|
64
|
-
// Must point to root, NOT to
|
|
65
|
-
expect(result).toBe(join(tempRoot, '
|
|
66
|
-
expect(result).not.toContain('first-run
|
|
64
|
+
// Must point to root, NOT to worktrees/first-run/worktrees/ports.json
|
|
65
|
+
expect(result).toBe(join(tempRoot, 'worktrees', 'ports.json'))
|
|
66
|
+
expect(result).not.toContain('first-run/worktrees')
|
|
67
67
|
})
|
|
68
68
|
})
|
|
69
69
|
|
|
@@ -73,7 +73,7 @@ describe('getPort / resolvePort', () => {
|
|
|
73
73
|
|
|
74
74
|
beforeEach(() => {
|
|
75
75
|
tempRoot = realpathSync(mkdtempSync(join(tmpdir(), 'sb-port-test-')))
|
|
76
|
-
mkdirSync(join(tempRoot, '
|
|
76
|
+
mkdirSync(join(tempRoot, 'worktrees'), { recursive: true })
|
|
77
77
|
originalCwd = process.cwd()
|
|
78
78
|
process.chdir(tempRoot)
|
|
79
79
|
})
|
|
@@ -106,7 +106,7 @@ describe('getPort / resolvePort', () => {
|
|
|
106
106
|
|
|
107
107
|
it('persists to ports.json', () => {
|
|
108
108
|
getPort('persisted')
|
|
109
|
-
const portsFile = join(tempRoot, '
|
|
109
|
+
const portsFile = join(tempRoot, 'worktrees', 'ports.json')
|
|
110
110
|
expect(existsSync(portsFile)).toBe(true)
|
|
111
111
|
const data = JSON.parse(readFileSync(portsFile, 'utf8'))
|
|
112
112
|
expect(data.persisted).toBe(1235)
|
|
@@ -123,7 +123,7 @@ describe('getPort / resolvePort', () => {
|
|
|
123
123
|
})
|
|
124
124
|
|
|
125
125
|
it('handles corrupted ports.json gracefully', () => {
|
|
126
|
-
const portsFile = join(tempRoot, '
|
|
126
|
+
const portsFile = join(tempRoot, 'worktrees', 'ports.json')
|
|
127
127
|
writeFileSync(portsFile, 'not valid json')
|
|
128
128
|
// Should not throw — starts fresh
|
|
129
129
|
const port = getPort('recovery')
|
|
@@ -136,7 +136,7 @@ describe('repoRoot', () => {
|
|
|
136
136
|
|
|
137
137
|
beforeEach(() => {
|
|
138
138
|
tempRoot = realpathSync(mkdtempSync(join(tmpdir(), 'sb-root-test-')))
|
|
139
|
-
mkdirSync(join(tempRoot, '
|
|
139
|
+
mkdirSync(join(tempRoot, 'worktrees', 'my-branch'), { recursive: true })
|
|
140
140
|
})
|
|
141
141
|
|
|
142
142
|
afterEach(() => {
|
|
@@ -147,8 +147,8 @@ describe('repoRoot', () => {
|
|
|
147
147
|
expect(repoRoot(tempRoot)).toBe(tempRoot)
|
|
148
148
|
})
|
|
149
149
|
|
|
150
|
-
it('returns parent of
|
|
151
|
-
const wt = join(tempRoot, '
|
|
150
|
+
it('returns parent of worktrees when inside a worktree', () => {
|
|
151
|
+
const wt = join(tempRoot, 'worktrees', 'my-branch')
|
|
152
152
|
expect(repoRoot(wt)).toBe(tempRoot)
|
|
153
153
|
})
|
|
154
154
|
})
|
|
@@ -158,7 +158,7 @@ describe('worktreeDir', () => {
|
|
|
158
158
|
|
|
159
159
|
beforeEach(() => {
|
|
160
160
|
tempRoot = realpathSync(mkdtempSync(join(tmpdir(), 'sb-wtdir-test-')))
|
|
161
|
-
mkdirSync(join(tempRoot, '
|
|
161
|
+
mkdirSync(join(tempRoot, 'worktrees'), { recursive: true })
|
|
162
162
|
})
|
|
163
163
|
|
|
164
164
|
afterEach(() => {
|
|
@@ -169,8 +169,8 @@ describe('worktreeDir', () => {
|
|
|
169
169
|
expect(worktreeDir('main', tempRoot)).toBe(tempRoot)
|
|
170
170
|
})
|
|
171
171
|
|
|
172
|
-
it('returns
|
|
173
|
-
expect(worktreeDir('my-feature', tempRoot)).toBe(join(tempRoot, '
|
|
172
|
+
it('returns worktrees/<name> for branches', () => {
|
|
173
|
+
expect(worktreeDir('my-feature', tempRoot)).toBe(join(tempRoot, 'worktrees', 'my-feature'))
|
|
174
174
|
})
|
|
175
175
|
})
|
|
176
176
|
|
|
@@ -185,12 +185,12 @@ describe('listWorktrees', () => {
|
|
|
185
185
|
rmSync(tempRoot, { recursive: true, force: true })
|
|
186
186
|
})
|
|
187
187
|
|
|
188
|
-
it('returns empty array when
|
|
188
|
+
it('returns empty array when worktrees does not exist', () => {
|
|
189
189
|
expect(listWorktrees(tempRoot)).toEqual([])
|
|
190
190
|
})
|
|
191
191
|
|
|
192
192
|
it('returns only directories with a .git file', () => {
|
|
193
|
-
const wtDir = join(tempRoot, '
|
|
193
|
+
const wtDir = join(tempRoot, 'worktrees')
|
|
194
194
|
mkdirSync(wtDir)
|
|
195
195
|
|
|
196
196
|
// Valid worktree — has .git file
|
|
@@ -208,7 +208,7 @@ describe('listWorktrees', () => {
|
|
|
208
208
|
})
|
|
209
209
|
|
|
210
210
|
it('returns multiple worktrees', () => {
|
|
211
|
-
const wtDir = join(tempRoot, '
|
|
211
|
+
const wtDir = join(tempRoot, 'worktrees')
|
|
212
212
|
mkdirSync(wtDir)
|
|
213
213
|
|
|
214
214
|
for (const name of ['alpha', 'beta', 'gamma']) {
|