pi-odd-worktree 1.1.1 → 2.0.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.
@@ -0,0 +1,161 @@
1
+ 'use strict';
2
+ // S1/S2: no creation path reaches a Herdr binary.
3
+ //
4
+ // The package no longer resolves or builds Herdr argv at all, so this suite pins
5
+ // the claim two ways: a `herdr` sentinel FIRST on PATH records any argv it is
6
+ // given (an empty log is the assertion), and a source scan proves no file
7
+ // outside the git seam builds Herdr argv or resolves the binary. Both creation
8
+ // fronts are exercised because they share one creation helper.
9
+ const { test, describe, before, after } = require('node:test');
10
+ const assert = require('node:assert/strict');
11
+ const fs = require('node:fs');
12
+ const os = require('node:os');
13
+ const path = require('node:path');
14
+ const { spawnSync } = require('node:child_process');
15
+ const { loadExtension, SRC, LIB_DIR } = require('./fixtures/load-extension.js');
16
+
17
+ const savedEnv = { ...process.env };
18
+ const scratch = [];
19
+ const track = (entry) => { scratch.push(entry); return entry; };
20
+ after(() => {
21
+ for (const key of Object.keys(process.env)) if (!(key in savedEnv)) delete process.env[key];
22
+ for (const [key, value] of Object.entries(savedEnv)) process.env[key] = value;
23
+ for (const dir of scratch) { try { fs.rmSync(dir, { recursive: true, force: true }); } catch {} }
24
+ });
25
+
26
+ const BIN = track(fs.mkdtempSync(path.join(os.tmpdir(), 'no-herdr-bin-')));
27
+ const HERDR_LOG = path.join(BIN, 'calls.log');
28
+ fs.writeFileSync(
29
+ path.join(BIN, 'herdr'),
30
+ '#!/bin/sh\nprintf "%s\\n" "$*" >> "$HERDR_LOG"\nexit 1\n',
31
+ { mode: 0o755 },
32
+ );
33
+ fs.writeFileSync(path.join(BIN, 'codegraph'), '#!/bin/sh\nexit 0\n', { mode: 0o755 });
34
+
35
+ function herdrCalls() {
36
+ try {
37
+ return fs.readFileSync(HERDR_LOG, 'utf8').trim();
38
+ } catch {
39
+ return '';
40
+ }
41
+ }
42
+ const resetHerdr = () => fs.writeFileSync(HERDR_LOG, '');
43
+
44
+ function git(cwd, args) {
45
+ const out = spawnSync('git', args, { cwd, encoding: 'utf8' });
46
+ if (out.status !== 0) throw new Error(`git ${args.join(' ')}: ${out.stderr}`);
47
+ return out.stdout.trim();
48
+ }
49
+
50
+ function makeRepo() {
51
+ const dir = track(fs.mkdtempSync(path.join(os.tmpdir(), 'no-herdr-repo-')));
52
+ git(dir, ['init', '-b', 'main']);
53
+ git(dir, ['config', 'user.email', 'no-herdr@example.test']);
54
+ git(dir, ['config', 'user.name', 'No Herdr']);
55
+ fs.writeFileSync(path.join(dir, 'README.md'), '# fixture\n');
56
+ git(dir, ['add', 'README.md']);
57
+ git(dir, ['commit', '-m', 'init']);
58
+ return fs.realpathSync(dir);
59
+ }
60
+
61
+ const resultText = (result) => (result.content || []).map((part) => (part && part.text) || '').join('\n');
62
+
63
+ function ctxFor(repo, notes, ui) {
64
+ return {
65
+ cwd: repo,
66
+ hasUI: true,
67
+ mode: 'tui',
68
+ sessionManager: { getSessionId: () => 'no-herdr-session' },
69
+ ui: { confirm: async () => true, notify: (text, level) => notes.push([level, text]), ...(ui || {}) },
70
+ };
71
+ }
72
+
73
+ // `/warp` create: the selector's create action, the create panel's answer, then
74
+ // the closing selector. Only those answers are scripted.
75
+ function warpCreateUi(panelAnswer) {
76
+ let call = 0;
77
+ return {
78
+ custom: async () => {
79
+ call += 1;
80
+ if (call === 1) return { create: true };
81
+ if (call === 2) return panelAnswer;
82
+ return undefined;
83
+ },
84
+ };
85
+ }
86
+
87
+ let tools;
88
+ let commands;
89
+ before(async () => {
90
+ process.env.PATH = `${BIN}${path.delimiter}${savedEnv.PATH || ''}`;
91
+ process.env.GENTLE_WORKTREE_THREAD = 'no-herdr-session';
92
+ ({ tools, commands } = await loadExtension({}));
93
+ });
94
+
95
+ describe('no creation path invokes Herdr', () => {
96
+ for (const existing of [false, true]) {
97
+ const kind = existing ? 'an existing' : 'a new';
98
+
99
+ test(`worktree_create never invokes Herdr for ${kind} branch`, async () => {
100
+ resetHerdr();
101
+ const repo = makeRepo();
102
+ const branch = existing ? 'feat/adopted' : 'feat/fresh';
103
+ if (existing) git(repo, ['branch', branch]);
104
+ const result = await tools.get('worktree_create').execute(
105
+ 'no-herdr-tool',
106
+ { branch, changes: 'none' },
107
+ undefined,
108
+ undefined,
109
+ ctxFor(repo, []),
110
+ );
111
+ assert.notEqual(result.isError, true, resultText(result));
112
+ assert.equal(result.details.branchCreated, !existing);
113
+ assert.equal(herdrCalls(), '', `Herdr was invoked: ${herdrCalls()}`);
114
+ assert.doesNotMatch(resultText(result), /herdr (workspace|association)/i, 'no Herdr workspace is reported');
115
+ });
116
+
117
+ test(`/warp create never invokes Herdr for ${kind} branch`, async () => {
118
+ resetHerdr();
119
+ const repo = makeRepo();
120
+ const name = existing ? 'adopted' : 'fresh';
121
+ if (existing) git(repo, ['branch', `feat/${name}`]);
122
+ const notes = [];
123
+ await commands.get('warp').handler('', ctxFor(repo, notes, warpCreateUi({ ok: true, type: 'feat', name })));
124
+ const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, `feat-${name}`);
125
+ assert.ok(fs.existsSync(target), `the /warp create made no checkout (notifications: ${JSON.stringify(notes)})`);
126
+ assert.equal(herdrCalls(), '', `Herdr was invoked: ${herdrCalls()}`);
127
+ for (const [, text] of notes) assert.doesNotMatch(text, /herdr (workspace|association)/i, `Herdr reported: ${text}`);
128
+ });
129
+ }
130
+
131
+ test('a refused create writes nothing and never invokes Herdr', async () => {
132
+ resetHerdr();
133
+ const repo = makeRepo();
134
+ const before = git(repo, ['branch', '--format=%(refname:short)']);
135
+ const result = await tools.get('worktree_create').execute(
136
+ 'no-herdr-bad',
137
+ { branch: 'bad..name', changes: 'none' },
138
+ undefined,
139
+ undefined,
140
+ ctxFor(repo, []),
141
+ );
142
+ assert.equal(result.isError, true);
143
+ assert.match(resultText(result), /^invalid branch name/);
144
+ assert.equal(git(repo, ['branch', '--format=%(refname:short)']), before);
145
+ assert.equal(herdrCalls(), '', `Herdr was invoked: ${herdrCalls()}`);
146
+ });
147
+
148
+ // S1 is an AUDIT claim: no source file outside the git seam reaches a Herdr
149
+ // binary. Pinned as text so a reintroduced call cannot hide in a helper.
150
+ test('no source file outside lib/worktree-git.js calls a Herdr binary', () => {
151
+ const files = [
152
+ SRC,
153
+ ...fs.readdirSync(LIB_DIR).filter((name) => name.endsWith('.js')).map((name) => path.join(LIB_DIR, name)),
154
+ ].filter((file) => !file.endsWith(`${path.sep}worktree-git.js`));
155
+ for (const file of files) {
156
+ const source = fs.readFileSync(file, 'utf8');
157
+ assert.doesNotMatch(source, /herdrArgv\s*\(/, `${file} builds Herdr argv`);
158
+ assert.doesNotMatch(source, /resolveHerdrBinary\s*\(/, `${file} resolves the Herdr binary`);
159
+ }
160
+ });
161
+ });
@@ -8,35 +8,14 @@ const os = require('node:os');
8
8
 
9
9
  const prompt = require('../lib/odd-worktrees-prompt.js');
10
10
 
11
- const WITH_CODEGRAPH = [
12
- '## ODD worktrees',
13
- '',
14
- 'Each ODD feature has its own worktree. Before starting implementation, check',
15
- 'whether that ODD already has an assigned worktree: if it does, resume it there;',
16
- 'if it does not, create one before starting.',
17
- '',
18
- '`worktree_create` places the checkout at `<repo-parent>/<repo-name>-worktrees/<name>`',
19
- 'and runs `codegraph init` there, so the new checkout has its own index from the',
20
- 'start. Edits and writes trigger a background `codegraph sync` for that checkout.',
21
- 'Every worktree keeps its own `.codegraph/`; never copy, symlink or reuse another',
22
- "checkout's index.",
23
- '',
24
- 'Keep all work for one ODD in its assigned worktree. Do not create a second one',
25
- 'to continue it.',
26
- ].join('\n');
27
-
28
- const WITHOUT_CODEGRAPH = [
29
- '## ODD worktrees',
30
- '',
31
- 'Each ODD feature has its own worktree. Before starting implementation, check',
32
- 'whether that ODD already has an assigned worktree: if it does, resume it there;',
33
- 'if it does not, create one before starting.',
34
- '',
35
- '`worktree_create` places the checkout at `<repo-parent>/<repo-name>-worktrees/<name>`.',
36
- '',
37
- 'Keep all work for one ODD in its assigned worktree. Do not create a second one',
38
- 'to continue it.',
39
- ].join('\n');
11
+ const fs = require('node:fs');
12
+ const path = require('node:path');
13
+
14
+ const PROMPT_DIR = path.resolve(__dirname, '..', 'lib', 'odd-prompt');
15
+ const WITH_FILE = path.join(PROMPT_DIR, 'odd-worktrees.with-codegraph.md');
16
+ const WITHOUT_FILE = path.join(PROMPT_DIR, 'odd-worktrees.without-codegraph.md');
17
+ const WITH_CODEGRAPH = fs.readFileSync(WITH_FILE, 'utf8').trim();
18
+ const WITHOUT_CODEGRAPH = fs.readFileSync(WITHOUT_FILE, 'utf8').trim();
40
19
 
41
20
  const savedEnv = { ...process.env };
42
21
  after(() => {
@@ -168,3 +147,31 @@ describe('extension wiring (T3)', () => {
168
147
  assert.doesNotThrow(() => handlers[0]({}, {}));
169
148
  });
170
149
  });
150
+
151
+ describe('the section is prose on disk', () => {
152
+ test('both variants live in their own Markdown file and are what gets injected', () => {
153
+ assert.ok(fs.existsSync(WITH_FILE), 'the CodeGraph variant file exists');
154
+ assert.ok(fs.existsSync(WITHOUT_FILE), 'the plain variant file exists');
155
+ assert.equal(prompt.WITH_CODEGRAPH, WITH_CODEGRAPH);
156
+ assert.equal(prompt.WITHOUT_CODEGRAPH, WITHOUT_CODEGRAPH);
157
+ });
158
+
159
+ test('each file opens with the section heading that makes injection idempotent', () => {
160
+ for (const text of [WITH_CODEGRAPH, WITHOUT_CODEGRAPH]) {
161
+ assert.ok(text.startsWith('## ODD worktrees'), text.split('\n')[0]);
162
+ }
163
+ });
164
+
165
+ test('only the CodeGraph variant mentions CodeGraph', () => {
166
+ assert.match(WITH_CODEGRAPH, /codegraph init/);
167
+ assert.match(WITH_CODEGRAPH, /codegraph sync/);
168
+ assert.doesNotMatch(WITHOUT_CODEGRAPH, /codegraph/i);
169
+ });
170
+
171
+ test('neither variant instructs the agent to warp', () => {
172
+ for (const text of [WITH_CODEGRAPH, WITHOUT_CODEGRAPH]) {
173
+ assert.doesNotMatch(text, /worktree_warp/);
174
+ assert.doesNotMatch(text, /move the session/i);
175
+ }
176
+ });
177
+ });
@@ -86,7 +86,7 @@ describe('registration', () => {
86
86
  const { hasCodegraph } = require('../lib/codegraph-session.js');
87
87
  const expected = hasCodegraph(process.env) ? [...base, ...codegraph].sort() : base;
88
88
  assert.deepEqual(registered, expected, 'the command list is the base three plus the codegraph triple exactly when the CLI is present');
89
- assert.deepEqual([...tools.keys()].sort(), ['worktree_close', 'worktree_create', 'worktree_list', 'worktree_warp']);
89
+ assert.deepEqual([...tools.keys()].sort(), ['worktree_create', 'worktree_delete', 'worktree_list', 'worktree_warp']);
90
90
  assert.deepEqual([...messageRenderers.keys()], ['worktree-warp']);
91
91
  });
92
92
 
@@ -98,13 +98,13 @@ describe('registration', () => {
98
98
  };
99
99
  assert.deepEqual(summary('worktree_create'), { name: 'worktree_create', label: 'Worktree Create' });
100
100
  assert.deepEqual(summary('worktree_list'), { name: 'worktree_list', label: 'Worktree List' });
101
- assert.deepEqual(summary('worktree_close'), { name: 'worktree_close', label: 'Worktree Close' });
101
+ assert.deepEqual(summary('worktree_delete'), { name: 'worktree_delete', label: 'Worktree Delete' });
102
102
  assert.deepEqual(summary('worktree_warp'), { name: 'worktree_warp', label: 'Worktree Warp' });
103
103
  });
104
104
 
105
- test('the close help text names the active-session refusal and no Herdr workspace', async () => {
105
+ test('the delete help text names the active-session refusal and no Herdr workspace', async () => {
106
106
  const { tools } = await loadExtension({});
107
- const description = tools.get('worktree_close').description;
107
+ const description = tools.get('worktree_delete').description;
108
108
  assert.match(description, /live Pi session working in that checkout/);
109
109
  assert.match(description, /warp to another checkout first/i);
110
110
  assert.match(description, /git/);
@@ -139,7 +139,10 @@ describe('removed surface', () => {
139
139
  assert.equal(commands.has(gone), false, `no /${gone} command`);
140
140
  }
141
141
  assert.equal(commands.has('issues'), true, '/issues is the migrated command');
142
+ // Modules only: `lib/` also holds the prompt prose (`lib/odd-prompt/*.md`),
143
+ // which no module reads through `require`.
142
144
  for (const file of fs.readdirSync(path.join(ROOT, 'lib'))) {
145
+ if (!fs.statSync(path.join(LIB_DIR, file)).isFile()) continue;
143
146
  const text = fs.readFileSync(path.join(LIB_DIR, file), 'utf8');
144
147
  assert.equal(/require\(['"]\.\/gh-issues\.js['"]\)/.test(text), false, `lib/${file} does not pull the issues reader`);
145
148
  }
@@ -14,7 +14,7 @@
14
14
  // names that session. Nothing else may: no label, no prefix, no saved history.
15
15
  //
16
16
  // These cases are written against the PUBLIC surfaces only — the two exported
17
- // guard functions and the registered `worktree_close` tool — so they keep
17
+ // guard functions and the registered `worktree_delete` tool — so they keep
18
18
  // working if internals move. Every fixture is a throwaway repository and agent
19
19
  // home under the system temp directory; no real worktree, presence store or
20
20
  // session is touched.
@@ -255,7 +255,7 @@ describe('S7 identity join through the registered tool', () => {
255
255
  const sessionHash = publishPresence(AGENT_HOME, { sessionId: 'raw-session-7', label: 'Worker', workspace: target, heartbeat: Date.now(), incarnationIndex: 4 });
256
256
  publishTransport(AGENT_HOME, { sessionId: 'raw-session-7' });
257
257
 
258
- const closed = await tools.get('worktree_close').execute('t5-c2', { name: 'feat-t5-joined' }, undefined, undefined, ctx);
258
+ const closed = await tools.get('worktree_delete').execute('t5-c2', { name: 'feat-t5-joined' }, undefined, undefined, ctx);
259
259
  assert.equal(closed.isError, true);
260
260
  const text = resultText(closed);
261
261
  assert.ok(text.includes('id raw-session-7'), text);
@@ -277,7 +277,7 @@ describe('S7 identity join through the registered tool', () => {
277
277
  const target = path.join(path.dirname(repo), `${path.basename(repo)}-worktrees`, 'feat-t5-unjoined');
278
278
  const sessionHash = publishPresence(AGENT_HOME, { sessionId: 'raw-session-8', label: 'Worker', workspace: target, heartbeat: Date.now(), incarnationIndex: 5 });
279
279
 
280
- const closed = await tools.get('worktree_close').execute('t5-c5', { name: 'feat-t5-unjoined' }, undefined, undefined, ctx);
280
+ const closed = await tools.get('worktree_delete').execute('t5-c5', { name: 'feat-t5-unjoined' }, undefined, undefined, ctx);
281
281
  assert.equal(closed.isError, true);
282
282
  const text = resultText(closed);
283
283
  assert.ok(text.includes(`presence ${sessionHash.slice(0, 12)}`), text);
@@ -295,7 +295,7 @@ describe('S7 identity join through the registered tool', () => {
295
295
  // never be attributed to this checkout, and it must never block.
296
296
  publishPresence(AGENT_HOME, { sessionId: 'legacy-peer', label: 'Legacy', heartbeat: Date.now(), incarnationIndex: 6, discovery: false });
297
297
 
298
- const closed = await tools.get('worktree_close').execute('t5-c7', { name: 'feat-t5-notice' }, undefined, undefined, ctx);
298
+ const closed = await tools.get('worktree_delete').execute('t5-c7', { name: 'feat-t5-notice' }, undefined, undefined, ctx);
299
299
  assert.notEqual(closed.isError, true, resultText(closed));
300
300
  const text = resultText(closed);
301
301
  assert.match(text, /published no workspace/);