@able-autonomy/able 0.0.20 → 0.2.0
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/able.ts +9 -2
- package/config.ts +11 -0
- package/package.json +1 -1
- package/src/bloat/apply.test.ts +81 -0
- package/src/bloat/apply.ts +49 -0
- package/src/{agents → bloat}/blocks.ts +2 -2
- package/src/{agents → bloat}/checks.ts +2 -2
- package/src/bloat/compare.ts +63 -0
- package/src/{agents → bloat}/findings.ts +11 -7
- package/src/{agents → bloat}/grid.ts +4 -4
- package/src/bloat/index.ts +258 -0
- package/src/{agents → bloat}/load.ts +2 -2
- package/src/{agents → bloat}/picker.ts +3 -3
- package/src/bloat/report.ts +286 -0
- package/src/{agents → bloat}/scan.ts +2 -2
- package/src/bloat/show.ts +79 -0
- package/src/bloat/steps.ts +32 -0
- package/src/{agents → bloat}/types.ts +48 -3
- package/src/commit.ts +2 -1
- package/src/git.ts +43 -2
- package/src/push.ts +2 -1
- package/src/ui.ts +3 -0
- package/src/workspaces/agent.ts +8 -2
- package/src/workspaces/fixture.ts +49 -0
- package/src/workspaces/index.ts +3 -1
- package/src/workspaces/ls.ts +56 -11
- package/src/workspaces/merge.ts +29 -13
- package/src/workspaces/new.ts +17 -15
- package/src/workspaces/overlap.test.ts +53 -0
- package/src/workspaces/overlap.ts +86 -0
- package/src/workspaces/preview.test.ts +81 -0
- package/src/workspaces/preview.ts +162 -0
- package/src/workspaces/refresh.ts +26 -24
- package/src/workspaces/rm.ts +6 -1
- package/src/workspaces/services.ts +2 -2
- package/src/workspaces/state.ts +56 -9
- package/src/workspaces/trunk.test.ts +88 -0
- package/sync.ts +5 -2
- package/src/agents/index.ts +0 -198
- package/src/agents/report.ts +0 -211
- package/src/agents/show.ts +0 -73
- package/src/agents/steps.ts +0 -32
- /package/src/{agents → bloat}/kinds.ts +0 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// A scratch host for the workspace tests: a bare `origin`, a main checkout cloned from it with an `able.config.ts`,
|
|
2
|
+
// and a way to run `able` inside any checkout of it. Everything lives in one temporary folder.
|
|
3
|
+
|
|
4
|
+
import { mkdtempSync, mkdirSync, realpathSync, writeFileSync } from 'node:fs'
|
|
5
|
+
import { tmpdir } from 'node:os'
|
|
6
|
+
import { dirname, join } from 'node:path'
|
|
7
|
+
|
|
8
|
+
const able = join(import.meta.dir, '../../able.ts')
|
|
9
|
+
|
|
10
|
+
export const sh = (cwd: string, ...cmd: string[]) => {
|
|
11
|
+
const r = Bun.spawnSync(cmd, { cwd, stdout: 'pipe', stderr: 'pipe', env: { ...process.env, GIT_AUTHOR_NAME: 't', GIT_AUTHOR_EMAIL: 't@t', GIT_COMMITTER_NAME: 't', GIT_COMMITTER_EMAIL: 't@t' } })
|
|
12
|
+
return { code: r.exitCode, out: `${r.stdout}${r.stderr}`.replace(/\x1b\[[0-9;]*m|\x1b\][^\x1b]*\x1b\\/g, '') }
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const git = (cwd: string, ...args: string[]) => {
|
|
16
|
+
const r = sh(cwd, 'git', ...args)
|
|
17
|
+
if (r.code !== 0) throw new Error(`git ${args.join(' ')}: ${r.out}`)
|
|
18
|
+
return r.out.trim()
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const run = (cwd: string, ...args: string[]) => sh(cwd, process.execPath, able, ...args)
|
|
22
|
+
|
|
23
|
+
export function write(root: string, path: string, text: string) {
|
|
24
|
+
mkdirSync(dirname(join(root, path)), { recursive: true })
|
|
25
|
+
writeFileSync(join(root, path), text)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const commit = (root: string, path: string, text: string, message = `change ${path}`) => {
|
|
29
|
+
write(root, path, text)
|
|
30
|
+
git(root, 'add', '--', path)
|
|
31
|
+
git(root, 'commit', '--quiet', '-m', message)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A fresh host: `origin` (bare), `main` (its clone, on `main`, pushed), workspaces in `ws/`. */
|
|
35
|
+
export function host() {
|
|
36
|
+
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'able-ws-')))
|
|
37
|
+
const origin = join(dir, 'origin.git')
|
|
38
|
+
const main = join(dir, 'main')
|
|
39
|
+
git(dir, 'init', '--quiet', '--bare', '--initial-branch=main', origin)
|
|
40
|
+
git(dir, 'clone', '--quiet', origin, main)
|
|
41
|
+
git(main, 'checkout', '--quiet', '-B', 'main')
|
|
42
|
+
write(main, 'able.config.ts', `export default { trunk: 'main', journal: 'journal', workspaces: { dir: '../ws', ports: { step: 100, max: 9 } } }\n`)
|
|
43
|
+
write(main, '.gitignore', '.able/\n')
|
|
44
|
+
write(main, 'README.md', 'one\ntwo\nthree\n')
|
|
45
|
+
git(main, 'add', '-A')
|
|
46
|
+
git(main, 'commit', '--quiet', '-m', 'start')
|
|
47
|
+
git(main, 'push', '--quiet', '-u', 'origin', 'main')
|
|
48
|
+
return { dir, origin, main, ws: (slug: string) => join(dir, 'ws', slug) }
|
|
49
|
+
}
|
package/src/workspaces/index.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
// able ws: the Workspaces module (knowledge/product/modules/workspaces.md).
|
|
2
2
|
//
|
|
3
3
|
// able ws new <slug> [--no-fetch] a worktree on feat/<slug> from the trunk, with the host's copy and onCreate
|
|
4
|
-
// able ws ls [--json] every checkout: offset, services, tree, resources held
|
|
4
|
+
// able ws ls [--json] every checkout: offset, services, tree, resources held; overlap between workspaces
|
|
5
5
|
// able ws current [--json] the checkout this runs in: slug, branch, path, port offset, main checkout
|
|
6
6
|
// able ws refresh merges the trunk into this workspace
|
|
7
7
|
// able ws merge ["message"] [--yes] [--keep-open] merges this workspace into the trunk as `Merge feat/<slug>`
|
|
8
8
|
// able ws rm <slug> [--force] stops and removes a workspace, deleting its branch once merged
|
|
9
|
+
// able ws preview [<slug>…] rebuilds `all`: origin's trunk plus the open workspaces' committed work
|
|
9
10
|
// able ws start | stop [<service>…] the workspace's services, in dependency order
|
|
10
11
|
// able ws status the services running in this checkout
|
|
11
12
|
// able ws take <resource> moves a shared resource to this checkout
|
|
@@ -21,6 +22,7 @@ const commands: Record<string, () => Promise<unknown>> = {
|
|
|
21
22
|
rm: () => import('./rm.ts'),
|
|
22
23
|
refresh: () => import('./refresh.ts'),
|
|
23
24
|
merge: () => import('./merge.ts'),
|
|
25
|
+
preview: () => import('./preview.ts'),
|
|
24
26
|
take: () => import('./take.ts'),
|
|
25
27
|
current: async () => console.log(JSON.stringify(await (await import('./state.ts')).current(), null, args.includes('--json') ? undefined : 2)),
|
|
26
28
|
start: async () => (await import('./services.ts')).start(names),
|
package/src/workspaces/ls.ts
CHANGED
|
@@ -1,25 +1,48 @@
|
|
|
1
1
|
// able ws ls: the main checkout and every workspace, read live: offset, services, tree, shared resources held.
|
|
2
2
|
// A service counts as running when Able started it or its `ready` check answers; a resource's holders come from its
|
|
3
3
|
// `holder` command when the host gives one, otherwise from Able's record.
|
|
4
|
-
//
|
|
4
|
+
// Under the table, the overlap between open workspaces' committed tips (overlap.ts), against `origin/<trunk>` as last
|
|
5
|
+
// fetched; `ls` itself doesn't fetch. With --json, only the workspaces and the preview, oldest first and the preview
|
|
6
|
+
// last, for a host's own tools (84): slug, branch, path, portOffset, createdAt, `dirty`, `unpushed`, `url` (from
|
|
7
|
+
// `workspaces.url`), `overlap` (each `{ with, conflicts, shared }`) and the preview's `build`. `--no-overlap` leaves
|
|
8
|
+
// the overlap out, for a caller that needs only which checkouts there are: it is most of the git work. Where it can't
|
|
9
|
+
// be worked out (git older than 2.38, no `origin/<trunk>`) the list still prints, the overlap said to be not shown.
|
|
5
10
|
|
|
6
11
|
import { existsSync } from 'node:fs'
|
|
7
12
|
import { resolve } from 'node:path'
|
|
8
|
-
import { loadConfig } from '../../config.ts'
|
|
9
|
-
import { dirtyCount, mainRoot, unpushedCount } from '../git.ts'
|
|
13
|
+
import { loadConfig, urlOf } from '../../config.ts'
|
|
14
|
+
import { dirtyCount, lastFetched, mainRoot, unpushedCount } from '../git.ts'
|
|
10
15
|
import { shellFor, type Place } from '../run.ts'
|
|
11
|
-
import { bold, dim, red, yellow } from '../ui.ts'
|
|
16
|
+
import { bold, dim, red, when, yellow } from '../ui.ts'
|
|
17
|
+
import { overlapUnavailable, overlaps } from './overlap.ts'
|
|
12
18
|
import { answers } from './services.ts'
|
|
13
|
-
import {
|
|
19
|
+
import { byAge, holderOf, openOf, PREVIEW, readState, running, workspaces } from './state.ts'
|
|
14
20
|
|
|
15
21
|
const main = mainRoot()
|
|
16
22
|
const state = await readState(main)
|
|
23
|
+
const config = await loadConfig(main)
|
|
24
|
+
const all = (await workspaces(main, state)).sort(byAge)
|
|
25
|
+
const open = openOf(all)
|
|
26
|
+
const base = `origin/${config.trunk}`
|
|
27
|
+
const skip = process.argv.includes('--no-overlap') || !open.length
|
|
28
|
+
const noOverlap = skip ? undefined : overlapUnavailable(main, config.trunk)
|
|
29
|
+
const overlap =
|
|
30
|
+
skip || noOverlap
|
|
31
|
+
? {}
|
|
32
|
+
: overlaps(
|
|
33
|
+
main,
|
|
34
|
+
config.trunk,
|
|
35
|
+
open.map((w) => ({ slug: w.slug, tip: w.branch })),
|
|
36
|
+
)
|
|
17
37
|
if (process.argv.includes('--json')) {
|
|
18
|
-
|
|
38
|
+
const facts = (w: (typeof all)[number]) => (existsSync(w.path) ? { dirty: dirtyCount(w.path), unpushed: w.branch ? unpushedCount(w.path) : 0 } : {})
|
|
39
|
+
const url = (w: (typeof all)[number]) => (config.workspaces?.url ? { url: urlOf(config.workspaces.url, w.slug, w.portOffset) } : {})
|
|
40
|
+
const build = (w: (typeof all)[number]) => (w.kind ? { build: state.workspaces[PREVIEW]?.build } : {})
|
|
41
|
+
console.log(JSON.stringify(all.map((w) => ({ ...w, ...facts(w), ...url(w), ...build(w), overlap: overlap[w.slug] ?? [] }))))
|
|
19
42
|
process.exit(0)
|
|
20
43
|
}
|
|
21
|
-
const rows =
|
|
22
|
-
const { services = {}, resources = {} } =
|
|
44
|
+
const rows: Place[] = [{ slug: 'main', path: main, portOffset: 0, main }, ...all.map((w) => ({ slug: w.slug, path: w.path, portOffset: w.portOffset, main }))]
|
|
45
|
+
const { services = {}, resources = {} } = config.workspaces ?? {}
|
|
23
46
|
const home = rows[0]
|
|
24
47
|
|
|
25
48
|
const asked = (c: NonNullable<(typeof resources)[string]['holder']>, at: Place) => {
|
|
@@ -49,22 +72,44 @@ const upCount = async (w: Place) => {
|
|
|
49
72
|
}
|
|
50
73
|
const ups = await Promise.all(rows.map(upCount))
|
|
51
74
|
|
|
52
|
-
|
|
75
|
+
const width = Math.max(16, ...rows.map((w) => w.slug.length))
|
|
76
|
+
console.log(`\n${bold(` ${'CHECKOUT'.padEnd(width)} OFFSET SERVICES TREE`)}`)
|
|
53
77
|
rows.forEach((w, i) => {
|
|
54
78
|
const up = ups[i] ?? 0
|
|
55
79
|
let tree = yellow('directory missing')
|
|
56
80
|
if (existsSync(w.path)) {
|
|
57
81
|
const dirty = dirtyCount(w.path)
|
|
58
82
|
const ahead = unpushedCount(w.path)
|
|
59
|
-
|
|
83
|
+
const built = w.slug === PREVIEW ? state.workspaces[PREVIEW]?.build : undefined
|
|
84
|
+
tree = [
|
|
85
|
+
dirty ? yellow(`${dirty} dirty`) : dim('clean'),
|
|
86
|
+
built ? dim(`preview of ${built.included.map((i) => i.slug).join(', ') || `${base} alone`}, built ${when(built.at)}`) : ahead ? yellow(`${ahead} unpushed`) : dim('0 unpushed'),
|
|
87
|
+
].join(dim(' · '))
|
|
60
88
|
}
|
|
61
89
|
const holds = Object.entries(holders)
|
|
62
90
|
.filter(([, slugs]) => slugs.includes(w.slug))
|
|
63
91
|
.map(([name, slugs]) => (slugs.length > 1 ? red(name) : name))
|
|
64
92
|
const column = up ? `${up} running`.padEnd(10) : dim('stopped'.padEnd(10))
|
|
65
|
-
console.log(` ${w.slug.padEnd(
|
|
93
|
+
console.log(` ${w.slug.padEnd(width)} ${String(w.portOffset).padEnd(7)} ${column} ${tree}${holds.length ? bold(` holds ${holds.join(' + ')}`) : ''}`)
|
|
66
94
|
})
|
|
67
95
|
for (const [name, slugs] of Object.entries(holders))
|
|
68
96
|
if (slugs.length > 1) console.log(red(`\n ${name} is held by ${slugs.join(' and ')} at once: able ws take ${name} in the one that should hold it`))
|
|
69
97
|
if (rows.length === 1) console.log(dim('\n no workspaces: able ws new <slug>'))
|
|
98
|
+
|
|
99
|
+
// Each workspace against the trunk, and each pair once: under the older of the two.
|
|
100
|
+
const rank = (slug: string) => open.findIndex((w) => w.slug === slug)
|
|
101
|
+
const found = open.flatMap((w) => (overlap[w.slug] ?? []).filter((o) => o.with === base || rank(o.with) > rank(w.slug)).map((o) => ({ slug: w.slug, ...o })))
|
|
102
|
+
if (noOverlap) console.log(`\n${bold(' OVERLAP')} ${dim(`not shown: ${noOverlap}`)}`)
|
|
103
|
+
else if (!skip) {
|
|
104
|
+
console.log(`\n${bold(' OVERLAP')} ${dim(`committed tips, against ${base} as of ${lastFetched(main, config.trunk)}`)}`)
|
|
105
|
+
if (!found.length) console.log(dim(' none'))
|
|
106
|
+
const pairWidth = Math.max(...found.map((o) => `${o.slug} × ${o.with}`.length), 0)
|
|
107
|
+
const list = (files: string[]) => files.slice(0, 4).join(', ') + (files.length > 4 ? dim(` +${files.length - 4}`) : '')
|
|
108
|
+
for (const o of found) {
|
|
109
|
+
const pair = `${o.slug} × ${o.with}`.padEnd(pairWidth)
|
|
110
|
+
if (o.conflicts.length) console.log(` ${pair} ${red(`${o.conflicts.length} conflict${o.conflicts.length > 1 ? 's' : ''}`)} ${list(o.conflicts)}`)
|
|
111
|
+
const quiet = o.shared.filter((f) => !o.conflicts.includes(f))
|
|
112
|
+
if (quiet.length) console.log(` ${o.conflicts.length ? ''.padEnd(pairWidth) : pair} ${yellow(`${quiet.length} shared`)} ${list(quiet)}`)
|
|
113
|
+
}
|
|
114
|
+
}
|
|
70
115
|
console.log()
|
package/src/workspaces/merge.ts
CHANGED
|
@@ -8,13 +8,16 @@
|
|
|
8
8
|
// `Merge feat/<slug>`, which is how `able sync` finds it. A message commits what is still dirty first. The main checkout takes no part; afterwards it is
|
|
9
9
|
// fast-forwarded when it is on the trunk and nothing of its own is in the way.
|
|
10
10
|
//
|
|
11
|
+
// It never carries commits that are only on the main checkout's `local <trunk>`: a branch holding any (merged in before
|
|
12
|
+
// `able ws refresh` took `origin/<trunk>` only) is refused, with them named, until they are pushed on their own.
|
|
13
|
+
//
|
|
11
14
|
// A conflict stops it with the files named: resolve them here, commit, and run it again. A push refused because the
|
|
12
15
|
// trunk moved meanwhile is the same: run it again, and it merges the newer trunk in.
|
|
13
16
|
|
|
14
17
|
import { existsSync, readFileSync } from 'node:fs'
|
|
15
18
|
import { join, relative } from 'node:path'
|
|
16
19
|
import { runChecks, runMergeChecks } from '../checks.ts'
|
|
17
|
-
import { count, dirtyCount, fetchTrunk, git, gitLoud, gitQuiet, lines, mergeOrFail } from '../git.ts'
|
|
20
|
+
import { carriedFromLocal, count, dirtyCount, fetchTrunk, git, gitLoud, gitQuiet, lines, mergeOrFail, needOrigin, unpushedOnTrunk } from '../git.ts'
|
|
18
21
|
import { status, working } from '../status.ts'
|
|
19
22
|
import { bold, cancel, confirm, dim, fail, green, yellow } from '../ui.ts'
|
|
20
23
|
import { inWorkspace } from './state.ts'
|
|
@@ -22,7 +25,7 @@ import { inWorkspace } from './state.ts'
|
|
|
22
25
|
const args = process.argv.slice(4)
|
|
23
26
|
const msg = args.find((a) => !a.startsWith('-') && a !== '')
|
|
24
27
|
|
|
25
|
-
const { ws, config } = await inWorkspace()
|
|
28
|
+
const { ws, config } = await inWorkspace('able ws merge')
|
|
26
29
|
const { trunk } = config
|
|
27
30
|
const dirty = dirtyCount(ws.path)
|
|
28
31
|
if (dirty && !msg) fail(`${dirty} uncommitted file(s); commit them (able commit), or pass a message to commit them all at once`)
|
|
@@ -34,24 +37,31 @@ if (!keepOpen && existsSync(brief) && !readFileSync(brief, 'utf8').includes('\n#
|
|
|
34
37
|
fail(`${relative(ws.path, brief)} has no ## Ledger; close the workspace first (the able-close-ws skill), then merge, or land what is done with --keep-open`)
|
|
35
38
|
|
|
36
39
|
const step = working(`merge ${ws.slug}`)
|
|
37
|
-
step(`fetching
|
|
38
|
-
fetchTrunk(ws.path, trunk)
|
|
40
|
+
step(`fetching origin/${trunk}`)
|
|
41
|
+
needOrigin(fetchTrunk(ws.path, trunk), trunk)
|
|
42
|
+
const carried = carriedFromLocal(ws.path, trunk)
|
|
43
|
+
if (carried.length)
|
|
44
|
+
fail(
|
|
45
|
+
`${ws.branch} holds ${carried.length} commit(s) from local ${trunk} that origin/${trunk} doesn't have; they would leave inside this merge:\n${carried
|
|
46
|
+
.map((c) => ` ${c}`)
|
|
47
|
+
.join('\n')}\n ${dim(`push them from the main checkout first (able push), then merge again`)}`,
|
|
48
|
+
)
|
|
39
49
|
const ahead = count(ws.path, `origin/${trunk}..HEAD`)
|
|
40
50
|
const behind = count(ws.path, `HEAD..origin/${trunk}`)
|
|
41
51
|
|
|
42
|
-
console.log(`\n ${bold(`Merge ${ws.branch} into
|
|
43
|
-
console.log(` ${ahead} commit(s) to merge${dirty ? `, +${dirty} uncommitted → "${msg}"` : ''};
|
|
52
|
+
console.log(`\n ${bold(`Merge ${ws.branch} into origin/${trunk}`)}`)
|
|
53
|
+
console.log(` ${ahead} commit(s) to merge${dirty ? `, +${dirty} uncommitted → "${msg}"` : ''}; origin/${trunk} is ${behind} commit(s) ahead${behind ? ', merged in first' : ''}`)
|
|
44
54
|
if (!ahead && !dirty) {
|
|
45
55
|
console.log(dim(' nothing to merge\n'))
|
|
46
56
|
status({ state: 'done', msg: `merge ${ws.slug}: nothing to merge` })
|
|
47
57
|
process.exit(0)
|
|
48
58
|
}
|
|
49
|
-
if (!args.includes('--yes') && !confirm(`Merge
|
|
59
|
+
if (!args.includes('--yes') && !confirm(`Merge origin/${trunk} in, run the checks, and push to origin/${trunk}?`)) cancel('aborted; nothing pushed')
|
|
50
60
|
|
|
51
61
|
const commitAll = (message: string) => gitLoud(ws.path, 'add', '-A') && gitLoud(ws.path, 'commit', '--quiet', '-m', message)
|
|
52
62
|
if (dirty && msg && !commitAll(msg)) fail('commit failed')
|
|
53
63
|
if (behind) {
|
|
54
|
-
step(`merging
|
|
64
|
+
step(`merging origin/${trunk} in`)
|
|
55
65
|
mergeOrFail(ws.path, `origin/${trunk}`, ws.branch, 'resolve them here, commit the merge, then run able ws merge again')
|
|
56
66
|
}
|
|
57
67
|
|
|
@@ -65,14 +75,14 @@ step(`pushing ${ws.branch}`)
|
|
|
65
75
|
if (!gitLoud(ws.path, 'push', '--quiet', '-u', 'origin', ws.branch)) fail(`push of ${ws.branch} failed`)
|
|
66
76
|
|
|
67
77
|
// The branch already holds the trunk, so this merge cannot conflict.
|
|
68
|
-
step(`pushing the merge to
|
|
78
|
+
step(`pushing the merge to origin/${trunk}`)
|
|
69
79
|
if (!gitLoud(ws.path, 'checkout', '--quiet', '--detach', `origin/${trunk}`) || !gitLoud(ws.path, 'merge', '--quiet', '--no-ff', '-m', `Merge ${ws.branch}`, ws.branch))
|
|
70
80
|
fail('could not build the merge commit')
|
|
71
81
|
const merged = git(ws.path, 'rev-parse', 'HEAD')
|
|
72
82
|
const pushed = gitLoud(ws.path, 'push', '--quiet', 'origin', `HEAD:${trunk}`)
|
|
73
83
|
gitLoud(ws.path, 'checkout', '--quiet', ws.branch)
|
|
74
|
-
if (!pushed) fail(
|
|
75
|
-
console.log(`\n ${green('✓')} ${bold(ws.branch)} is on
|
|
84
|
+
if (!pushed) fail(`origin/${trunk} moved meanwhile; run it again to merge it in`)
|
|
85
|
+
console.log(`\n ${green('✓')} ${bold(ws.branch)} is on origin/${trunk}`)
|
|
76
86
|
|
|
77
87
|
// `--ff-only` either moves the main checkout to the merge or refuses without touching it.
|
|
78
88
|
const onTrunk = git(ws.main, 'rev-parse', '--abbrev-ref', 'HEAD') === trunk
|
|
@@ -80,9 +90,15 @@ const synced = onTrunk && gitQuiet(ws.main, 'merge', '--quiet', '--ff-only', mer
|
|
|
80
90
|
console.log(
|
|
81
91
|
synced
|
|
82
92
|
? ` ${green('✓')} main checkout fast-forwarded`
|
|
83
|
-
: yellow(
|
|
93
|
+
: yellow(
|
|
94
|
+
!onTrunk
|
|
95
|
+
? ` main checkout not updated: it is not on ${trunk}; pull it there: git pull --ff-only`
|
|
96
|
+
: unpushedOnTrunk(ws.main, trunk).length
|
|
97
|
+
? ` main checkout not updated: local ${trunk} has commits origin/${trunk} doesn't; put them on top of it there: git pull --rebase`
|
|
98
|
+
: ` main checkout not updated: its own changes are in the way; pull it there: git pull --ff-only`,
|
|
99
|
+
),
|
|
84
100
|
)
|
|
85
101
|
console.log(
|
|
86
102
|
keepOpen ? `\n ${dim('the workspace stays open: keep working here, and close it (able-close-ws) before its last merge')}\n` : `\n ${dim('next, from the main checkout:')} able ws rm ${ws.slug}\n`,
|
|
87
103
|
)
|
|
88
|
-
status({ state: 'done', msg: `merge: ${ws.branch} is on
|
|
104
|
+
status({ state: 'done', msg: `merge: ${ws.branch} is on origin/${trunk}` })
|
package/src/workspaces/new.ts
CHANGED
|
@@ -7,21 +7,25 @@
|
|
|
7
7
|
// the cut carries it. Already on origin as it is here: nothing to publish. Nowhere: refused, unless `--no-brief`.
|
|
8
8
|
// Running it again after a failure picks up where it stopped: a brief committed but not pushed is pushed, since the
|
|
9
9
|
// only unpushed changes it allows are the brief's own. `--brief`, the old way to ask for this, is still accepted.
|
|
10
|
+
//
|
|
11
|
+
// Other unpushed commits on `local <trunk>` are not in the new workspace, which is cut from `origin/<trunk>`: a warning
|
|
12
|
+
// names them. Only when publishing the brief would push them along is that a refusal.
|
|
10
13
|
|
|
11
|
-
import {
|
|
14
|
+
import { existsSync, mkdirSync } from 'node:fs'
|
|
12
15
|
import { dirname, join, relative, resolve } from 'node:path'
|
|
13
16
|
import { loadConfig, trailerArgs } from '../../config.ts'
|
|
14
17
|
import { runChecks } from '../checks.ts'
|
|
15
|
-
import { count, failOnMerge, fetchTrunk, git, gitLoud, gitQuiet, lines, mainRoot } from '../git.ts'
|
|
18
|
+
import { count, failOnMerge, fetchTrunk, git, gitLoud, gitQuiet, lines, mainRoot, needOrigin, unpushedOnTrunk, warnLeftOut } from '../git.ts'
|
|
16
19
|
import { runCommand } from '../run.ts'
|
|
17
20
|
import { status, working } from '../status.ts'
|
|
18
21
|
import { bold, dim, fail, green, yellow } from '../ui.ts'
|
|
19
|
-
import { branchOf, readState, workspaces, writeState } from './state.ts'
|
|
22
|
+
import { branchOf, copyFiles, freeOffset, PREVIEW, readState, workspaces, writeState } from './state.ts'
|
|
20
23
|
|
|
21
24
|
const args = process.argv.slice(4)
|
|
22
25
|
const slug = args.find((a) => !a.startsWith('-'))
|
|
23
26
|
if (!slug) fail('usage: able ws new <slug> [--no-brief] [--no-fetch]')
|
|
24
27
|
if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) fail(`invalid name '${slug}': lowercase letters, digits and dashes only`)
|
|
28
|
+
if (slug === PREVIEW || slug === 'main') fail(`'${slug}' is reserved: ${slug === PREVIEW ? 'it is the combined preview (able ws preview)' : 'it is the main checkout'}`)
|
|
25
29
|
|
|
26
30
|
const main = mainRoot()
|
|
27
31
|
const config = await loadConfig(main)
|
|
@@ -35,14 +39,13 @@ if (existsSync(path)) fail(`${path} already exists; remove it first`)
|
|
|
35
39
|
if (git(main, 'rev-parse', '--verify', '--quiet', branch)) fail(`branch '${branch}' already exists`)
|
|
36
40
|
|
|
37
41
|
// Without `ports` every workspace sits at offset 0 and only one runs services at a time (88, 94).
|
|
38
|
-
const
|
|
39
|
-
const { ports } = ws
|
|
40
|
-
const portOffset = ports ? (Array.from({ length: ports.max }, (_, i) => (i + 1) * ports.step).find((o) => !taken.has(o)) ?? fail('no free port offset; remove a workspace first')) : 0
|
|
42
|
+
const portOffset = freeOffset(state, ws.ports)
|
|
41
43
|
|
|
42
44
|
const step = working(`new ${slug}`)
|
|
45
|
+
let fetched = true
|
|
43
46
|
if (!args.includes('--no-fetch')) {
|
|
44
|
-
step(`fetching
|
|
45
|
-
fetchTrunk(main, config.trunk)
|
|
47
|
+
step(`fetching origin/${config.trunk}`)
|
|
48
|
+
fetched = fetchTrunk(main, config.trunk)
|
|
46
49
|
}
|
|
47
50
|
|
|
48
51
|
const { trunk, journal } = config
|
|
@@ -60,7 +63,8 @@ if (differs) {
|
|
|
60
63
|
// Unpushed work other than the brief would leave with it. The brief's own commit (a run that stopped before its
|
|
61
64
|
// push) is fine: this run pushes it.
|
|
62
65
|
const others = lines(main, 'diff', '--name-only', `origin/${trunk}...${trunk}`).filter((f) => f !== file)
|
|
63
|
-
if (others.length) fail(
|
|
66
|
+
if (others.length) fail(`local ${trunk} has unpushed changes that would leave with the brief:\n${git(main, 'log', '--oneline', `origin/${trunk}..${trunk}`)}`)
|
|
67
|
+
needOrigin(fetched, trunk)
|
|
64
68
|
if (git(main, 'status', '--porcelain', '--', file)) {
|
|
65
69
|
const at = { slug: 'main', path: main, portOffset: 0, main }
|
|
66
70
|
if (!runChecks(config, [file], at)) fail('a check failed; nothing committed')
|
|
@@ -69,7 +73,8 @@ if (differs) {
|
|
|
69
73
|
if (count(main, `origin/${trunk}..${trunk}`) && !gitLoud(main, 'push', '--quiet', 'origin', trunk)) fail(`push of ${trunk} failed`)
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
// Cut from origin's trunk: the main checkout's own branch may lag, and is the operator's to move.
|
|
76
|
+
// Cut from origin's trunk: the main checkout's own branch may lag or lead, and is the operator's to move.
|
|
77
|
+
const left = differs ? [] : unpushedOnTrunk(main, trunk)
|
|
73
78
|
const start = git(main, 'rev-parse', '--verify', '--quiet', `origin/${config.trunk}`) ? `origin/${config.trunk}` : config.trunk
|
|
74
79
|
|
|
75
80
|
const started = Date.now()
|
|
@@ -81,11 +86,7 @@ if (added.exitCode !== 0) fail(`worktree add failed: ${added.stderr.toString().t
|
|
|
81
86
|
state.workspaces[slug] = { portOffset, createdAt: new Date().toISOString() }
|
|
82
87
|
await writeState(main, state)
|
|
83
88
|
|
|
84
|
-
|
|
85
|
-
if (!existsSync(join(main, rel))) continue
|
|
86
|
-
mkdirSync(dirname(join(path, rel)), { recursive: true })
|
|
87
|
-
copyFileSync(join(main, rel), join(path, rel))
|
|
88
|
-
}
|
|
89
|
+
copyFiles(main, path, ws.copy)
|
|
89
90
|
|
|
90
91
|
if (ws.onCreate?.length) step('onCreate commands')
|
|
91
92
|
const failed = (ws.onCreate ?? []).filter((c) => !runCommand(c, { slug, path, portOffset, main }))
|
|
@@ -95,6 +96,7 @@ console.log(`\n${green('✓')} ${bold(slug)} ${dim(path)} ${dim(`in ${((Date.now
|
|
|
95
96
|
console.log(` ${'branch'.padEnd(12)} ${branch} ${dim(`from ${start}`)}`)
|
|
96
97
|
console.log(` ${'port offset'.padEnd(12)} ${portOffset}`)
|
|
97
98
|
console.log(` ${'brief'.padEnd(12)} ${brief || yellow(`none: ${config.trunk} has no ${config.journal}/workspaces/${slug}.md`)}`)
|
|
99
|
+
warnLeftOut(left, `on local ${trunk} not in the new workspace: it is cut from origin/${trunk}, which doesn't have them`, 'push them (able push), then able ws refresh inside it, to include them')
|
|
98
100
|
if (failed.length) console.log(yellow(`\n ${failed.length} onCreate command(s) failed; run them inside the workspace`))
|
|
99
101
|
console.log(`\n ${dim(`cd ${relative(process.cwd(), path)}`)}\n`)
|
|
100
102
|
status({ state: 'done', msg: `new: ${slug} is ready${failed.length ? `, ${failed.length} onCreate command(s) failed` : ''}` })
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { expect, test } from 'bun:test'
|
|
2
|
+
import { commit, git, host, run } from './fixture.ts'
|
|
3
|
+
|
|
4
|
+
test('ws ls reports conflicts and shared files between open workspaces, writing nothing to the repository', () => {
|
|
5
|
+
const h = host()
|
|
6
|
+
for (const slug of ['one', 'two', 'three']) expect(run(h.main, 'ws', 'new', slug, '--no-brief').code).toBe(0)
|
|
7
|
+
commit(h.ws('one'), 'README.md', 'one\nTWO by one\nthree\n')
|
|
8
|
+
commit(h.ws('two'), 'README.md', 'one\nTWO by two\nthree\n')
|
|
9
|
+
commit(h.ws('one'), 'shared.txt', 'a\n')
|
|
10
|
+
commit(h.ws('three'), 'shared.txt', 'a\n')
|
|
11
|
+
commit(h.ws('three'), 'alone.txt', 'x\n')
|
|
12
|
+
// An uncommitted edit is not a committed tip, so it never counts.
|
|
13
|
+
commit(h.ws('two'), 'loose.txt', 'x\n')
|
|
14
|
+
Bun.write(`${h.ws('three')}/loose.txt`, 'y\n')
|
|
15
|
+
|
|
16
|
+
const before = git(h.main, 'count-objects', '-v')
|
|
17
|
+
const refs = git(h.main, 'for-each-ref')
|
|
18
|
+
const json = JSON.parse(run(h.main, 'ws', 'ls', '--json').out) as { slug: string; dirty: number; overlap: { with: string; conflicts: string[]; shared: string[] }[] }[]
|
|
19
|
+
expect(git(h.main, 'count-objects', '-v')).toBe(before)
|
|
20
|
+
expect(git(h.main, 'for-each-ref')).toBe(refs)
|
|
21
|
+
|
|
22
|
+
const of = (slug: string) => json.find((w) => w.slug === slug)?.overlap ?? []
|
|
23
|
+
expect(of('one')).toEqual([
|
|
24
|
+
{ with: 'two', conflicts: ['README.md'], shared: ['README.md'] },
|
|
25
|
+
{ with: 'three', conflicts: [], shared: ['shared.txt'] },
|
|
26
|
+
])
|
|
27
|
+
expect(of('two')).toEqual([{ with: 'one', conflicts: ['README.md'], shared: ['README.md'] }])
|
|
28
|
+
expect(json.find((w) => w.slug === 'three')?.dirty).toBe(1)
|
|
29
|
+
|
|
30
|
+
// Against origin/main: a change origin/main makes to the same line conflicts with both.
|
|
31
|
+
commit(h.main, 'README.md', 'one\nTWO by main\nthree\n')
|
|
32
|
+
git(h.main, 'push', '--quiet', 'origin', 'main')
|
|
33
|
+
const after = JSON.parse(run(h.main, 'ws', 'ls', '--json').out) as typeof json
|
|
34
|
+
expect(after.find((w) => w.slug === 'one')?.overlap[0]).toEqual({ with: 'origin/main', conflicts: ['README.md'], shared: [] })
|
|
35
|
+
|
|
36
|
+
const table = run(h.main, 'ws', 'ls').out
|
|
37
|
+
expect(table).toContain('OVERLAP')
|
|
38
|
+
expect(table).toMatch(/one × two\s+1 conflict\s+README\.md/)
|
|
39
|
+
expect(table).toMatch(/one × three\s+1 shared\s+shared\.txt/)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('ws ls still lists the workspaces when there is no origin/main to compare against', () => {
|
|
43
|
+
const h = host()
|
|
44
|
+
expect(run(h.main, 'ws', 'new', 'one', '--no-brief').code).toBe(0)
|
|
45
|
+
git(h.main, 'update-ref', '-d', 'refs/remotes/origin/main')
|
|
46
|
+
const table = run(h.main, 'ws', 'ls')
|
|
47
|
+
expect(table.code).toBe(0)
|
|
48
|
+
expect(table.out).toContain('one')
|
|
49
|
+
expect(table.out).toContain('not shown: no origin/main to compare against')
|
|
50
|
+
const json = run(h.main, 'ws', 'ls', '--json')
|
|
51
|
+
expect(json.code).toBe(0)
|
|
52
|
+
expect(JSON.parse(json.out)[0].overlap).toEqual([])
|
|
53
|
+
})
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// Overlap between open workspaces (principle 4: shown, never resolved for the operator). Committed tips only: each
|
|
2
|
+
// workspace's tip against `origin/<trunk>`, and every pair against each other.
|
|
3
|
+
//
|
|
4
|
+
// conflicts `git merge-tree --write-tree`: the files a merge of the two would stop on
|
|
5
|
+
// shared files the files both change, from `git diff --name-only origin/<trunk>...<tip>` of each
|
|
6
|
+
//
|
|
7
|
+
// Nothing is written to the repository: merge-tree's trees and blobs go to a throwaway object directory, with the
|
|
8
|
+
// repository's own as an alternate, and no ref, index or worktree is touched.
|
|
9
|
+
|
|
10
|
+
import { mkdtempSync, rmSync } from 'node:fs'
|
|
11
|
+
import { tmpdir } from 'node:os'
|
|
12
|
+
import { join, resolve } from 'node:path'
|
|
13
|
+
import { git, lines } from '../git.ts'
|
|
14
|
+
import { fail } from '../ui.ts'
|
|
15
|
+
|
|
16
|
+
/** What one workspace overlaps with: `with` is another workspace's slug, or `origin/<trunk>`. */
|
|
17
|
+
export type Overlap = { with: string; conflicts: string[]; shared: string[] }
|
|
18
|
+
|
|
19
|
+
/** Why git can't run `git merge-tree --write-tree` (it needs 2.38), or nothing when it can. */
|
|
20
|
+
function mergeTreeTooOld() {
|
|
21
|
+
const [major = 0, minor = 0] = (git('.', '--version').match(/(\d+)\.(\d+)/) ?? []).slice(1).map(Number)
|
|
22
|
+
if (major < 2 || (major === 2 && minor < 38)) return `git ${major}.${minor} is too old: overlap and the preview need git 2.38 or newer (git merge-tree --write-tree)`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function requireMergeTree() {
|
|
26
|
+
const old = mergeTreeTooOld()
|
|
27
|
+
if (old) fail(old)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Why overlap can't be worked out here (git too old, no `origin/<trunk>`), or nothing when it can. `able ws ls`
|
|
31
|
+
* skips it then, with the reason, and lists the checkouts anyway. */
|
|
32
|
+
export function overlapUnavailable(main: string, trunk: string) {
|
|
33
|
+
return mergeTreeTooOld() ?? (git(main, 'rev-parse', '--verify', '--quiet', `origin/${trunk}^{commit}`) ? undefined : `no origin/${trunk} to compare against`)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Where merge-tree writes when nothing may reach the repository: a scratch object directory, removed by `done`. */
|
|
37
|
+
export type Scratch = { env: Record<string, string>; done: () => void }
|
|
38
|
+
|
|
39
|
+
/** A scratch object directory with the repository's own objects as an alternate, so merge-tree can read them all. */
|
|
40
|
+
export function scratchObjects(main: string): Scratch {
|
|
41
|
+
const dir = mkdtempSync(join(tmpdir(), 'able-merge-tree-'))
|
|
42
|
+
const objects = resolve(main, git(main, 'rev-parse', '--git-path', 'objects'))
|
|
43
|
+
return { env: { GIT_OBJECT_DIRECTORY: dir, GIT_ALTERNATE_OBJECT_DIRECTORIES: objects }, done: () => rmSync(dir, { recursive: true, force: true }) }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** `git merge-tree --write-tree a b`: the merged tree, and the files it conflicts on (none: a clean merge). Its
|
|
47
|
+
* objects go to `scratch` when given, else into the repository (the preview checks its tree out). */
|
|
48
|
+
export function mergeTree(main: string, a: string, b: string, scratch?: Scratch) {
|
|
49
|
+
const r = Bun.spawnSync(['git', '-C', main, 'merge-tree', '--write-tree', '--name-only', '--no-messages', a, b], {
|
|
50
|
+
stdout: 'pipe',
|
|
51
|
+
stderr: 'pipe',
|
|
52
|
+
env: { ...process.env, ...scratch?.env },
|
|
53
|
+
})
|
|
54
|
+
// 0: clean, 1: conflicts (the tree's id, then one line per conflicted file); anything else is an error.
|
|
55
|
+
if (r.exitCode !== 0 && r.exitCode !== 1) fail(`git merge-tree ${a} ${b}: ${r.stderr.toString().trim()}`)
|
|
56
|
+
const [tree = '', ...files] = r.stdout.toString().split('\n').filter(Boolean)
|
|
57
|
+
return { tree, conflicts: r.exitCode === 0 ? [] : [...new Set(files)] }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Every open workspace's overlap, by slug: against `origin/<trunk>` first, then against each other workspace.
|
|
61
|
+
* A tip is any ref: the workspace's branch. */
|
|
62
|
+
export function overlaps(main: string, trunk: string, tips: { slug: string; tip: string }[]): Record<string, Overlap[]> {
|
|
63
|
+
const base = `origin/${trunk}`
|
|
64
|
+
const scratch = scratchObjects(main)
|
|
65
|
+
const conflicts = (a: string, b: string) => mergeTree(main, a, b, scratch).conflicts
|
|
66
|
+
try {
|
|
67
|
+
const changed = Object.fromEntries(tips.map((t) => [t.slug, new Set(lines(main, 'diff', '--name-only', `${base}...${t.tip}`))]))
|
|
68
|
+
const out: Record<string, Overlap[]> = Object.fromEntries(tips.map((t) => [t.slug, []]))
|
|
69
|
+
for (const t of tips) {
|
|
70
|
+
const c = conflicts(base, t.tip)
|
|
71
|
+
if (c.length) out[t.slug]?.push({ with: base, conflicts: c, shared: [] })
|
|
72
|
+
}
|
|
73
|
+
tips.forEach((a, i) => {
|
|
74
|
+
for (const b of tips.slice(i + 1)) {
|
|
75
|
+
const shared = [...(changed[a.slug] ?? [])].filter((f) => changed[b.slug]?.has(f)).sort()
|
|
76
|
+
const c = conflicts(a.tip, b.tip)
|
|
77
|
+
if (!shared.length && !c.length) continue
|
|
78
|
+
out[a.slug]?.push({ with: b.slug, conflicts: c, shared })
|
|
79
|
+
out[b.slug]?.push({ with: a.slug, conflicts: c, shared })
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
return out
|
|
83
|
+
} finally {
|
|
84
|
+
scratch.done()
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// The preview slot: `all`, rebuilt from origin/main and the open workspaces' committed tips, never answering as main.
|
|
2
|
+
|
|
3
|
+
import { expect, test } from 'bun:test'
|
|
4
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
5
|
+
import { join } from 'node:path'
|
|
6
|
+
import { commit, git, host, run, write } from './fixture.ts'
|
|
7
|
+
|
|
8
|
+
test('ws preview combines the open workspaces, leaves out and names a conflicting one, and is a checkout of its own', () => {
|
|
9
|
+
const h = host()
|
|
10
|
+
for (const slug of ['one', 'two', 'three']) expect(run(h.main, 'ws', 'new', slug, '--no-brief').code).toBe(0)
|
|
11
|
+
commit(h.ws('one'), 'one.txt', 'from one\n')
|
|
12
|
+
commit(h.ws('two'), 'two.txt', 'from two\n')
|
|
13
|
+
commit(h.ws('one'), 'README.md', 'one\nTWO by one\nthree\n')
|
|
14
|
+
commit(h.ws('three'), 'README.md', 'one\nTWO by three\nthree\n')
|
|
15
|
+
write(h.ws('two'), 'uncommitted.txt', 'never in the preview\n')
|
|
16
|
+
|
|
17
|
+
const r = run(h.main, 'ws', 'preview')
|
|
18
|
+
expect(r.code).toBe(0)
|
|
19
|
+
expect(r.out).toMatch(/\+ one/)
|
|
20
|
+
expect(r.out).toMatch(/\+ two/)
|
|
21
|
+
expect(r.out).toMatch(/− three .* left out: conflicts with one/)
|
|
22
|
+
const all = h.ws('all')
|
|
23
|
+
expect(readFileSync(join(all, 'one.txt'), 'utf8')).toBe('from one\n')
|
|
24
|
+
expect(readFileSync(join(all, 'two.txt'), 'utf8')).toBe('from two\n')
|
|
25
|
+
expect(existsSync(join(all, 'uncommitted.txt'))).toBe(false)
|
|
26
|
+
// Detached, and no branch or ref of its own.
|
|
27
|
+
expect(git(all, 'rev-parse', '--abbrev-ref', 'HEAD')).toBe('HEAD')
|
|
28
|
+
expect(git(h.main, 'for-each-ref', '--format=%(refname)')).not.toContain('all')
|
|
29
|
+
|
|
30
|
+
// Its own checkout: slug, offset, and never main.
|
|
31
|
+
const at = JSON.parse(run(all, 'ws', 'current', '--json').out)
|
|
32
|
+
expect(at.slug).toBe('all')
|
|
33
|
+
expect(at.portOffset).toBeGreaterThan(0)
|
|
34
|
+
const offsets = (JSON.parse(run(h.main, 'ws', 'ls', '--json').out) as { slug: string; portOffset: number; kind?: string }[]).map((w) => w.portOffset)
|
|
35
|
+
expect(new Set(offsets).size).toBe(offsets.length)
|
|
36
|
+
|
|
37
|
+
// Read-only.
|
|
38
|
+
for (const cmd of [['commit', 'x', '--yes'], ['push'], ['ws', 'merge', '--yes'], ['ws', 'refresh']]) {
|
|
39
|
+
const refused = run(all, ...cmd)
|
|
40
|
+
expect(refused.code).not.toBe(0)
|
|
41
|
+
expect(refused.out).toContain('read-only')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Named only, and a rebuild picks up new commits.
|
|
45
|
+
commit(h.ws('two'), 'two.txt', 'two, again\n')
|
|
46
|
+
expect(run(h.main, 'ws', 'preview', 'two').code).toBe(0)
|
|
47
|
+
expect(readFileSync(join(all, 'two.txt'), 'utf8')).toBe('two, again\n')
|
|
48
|
+
expect(existsSync(join(all, 'one.txt'))).toBe(false)
|
|
49
|
+
|
|
50
|
+
// Edits in the preview stop the rebuild, each named with its workspace.
|
|
51
|
+
write(all, 'two.txt', 'edited in the preview\n')
|
|
52
|
+
write(all, 'stray.txt', 'x\n')
|
|
53
|
+
const stopped = run(h.main, 'ws', 'preview')
|
|
54
|
+
expect(stopped.code).not.toBe(0)
|
|
55
|
+
expect(stopped.out).toMatch(/two\.txt\s+two/)
|
|
56
|
+
expect(stopped.out).toMatch(/stray\.txt\s+no workspace/)
|
|
57
|
+
|
|
58
|
+
// Reserved, and removable like any checkout.
|
|
59
|
+
expect(run(h.main, 'ws', 'new', 'all', '--no-brief').out).toContain('reserved')
|
|
60
|
+
expect(run(h.main, 'ws', 'rm', 'all', '--force').code).toBe(0)
|
|
61
|
+
expect(existsSync(all)).toBe(false)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
test("a hook that rewrites a tracked file doesn't stop the next rebuild, and a preview whose folder is gone can be removed", () => {
|
|
65
|
+
const h = host()
|
|
66
|
+
expect(run(h.main, 'ws', 'new', 'one', '--no-brief').code).toBe(0)
|
|
67
|
+
commit(h.ws('one'), 'one.txt', 'from one\n')
|
|
68
|
+
// As an install rewrites a lockfile the combined tree disagrees with.
|
|
69
|
+
write(h.main, 'able.config.ts', `export default { trunk: 'main', journal: 'journal', workspaces: { dir: '../ws', ports: { step: 100, max: 9 }, onPreview: ['echo rewritten >> README.md'] } }\n`)
|
|
70
|
+
|
|
71
|
+
const first = run(h.main, 'ws', 'preview')
|
|
72
|
+
expect(first.code).toBe(0)
|
|
73
|
+
expect(first.out).toContain('put back what the hooks changed in tracked files: README.md')
|
|
74
|
+
expect(git(h.ws('all'), 'status', '--porcelain')).toBe('')
|
|
75
|
+
expect(run(h.main, 'ws', 'preview').code).toBe(0)
|
|
76
|
+
|
|
77
|
+
// Deleted by hand: `ws rm all` still clears its entry and frees its offset.
|
|
78
|
+
git(h.main, 'worktree', 'remove', '--force', h.ws('all'))
|
|
79
|
+
expect(run(h.main, 'ws', 'rm', 'all').code).toBe(0)
|
|
80
|
+
expect((JSON.parse(run(h.main, 'ws', 'ls', '--json').out) as { slug: string }[]).map((w) => w.slug)).toEqual(['one'])
|
|
81
|
+
})
|