pi-odd-worktree 3.7.1 → 3.8.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.
@@ -50,10 +50,6 @@ function setup(overrides = {}) {
50
50
  },
51
51
  }),
52
52
  warmUpDaemon: async () => true,
53
- createCodegraphCardResolver: (options) => {
54
- calls.card.push(options);
55
- return { registered: true };
56
- },
57
53
  ...(overrides.impl || {}),
58
54
  };
59
55
  const result = registerCodegraph(pi, {
@@ -86,34 +82,6 @@ test('without the CodeGraph CLI nothing is registered at all', () => {
86
82
  assert.equal(pi.handlers.size, 0);
87
83
  });
88
84
 
89
- test('the CodeGraph card is registered once through the host hook, with the extension\'s own text metrics', () => {
90
- const registered = [];
91
- const { calls, pi } = setup();
92
- assert.equal(calls.card.length, 1);
93
- assert.deepEqual(calls.card[0].metrics(), { metrics: true });
94
- assert.equal(typeof calls.card[0].registerToolRenderer, 'function');
95
- pi.registerToolRenderer = (resolver) => registered.push(resolver);
96
- calls.card[0].registerToolRenderer('resolver');
97
- assert.deepEqual(registered, ['resolver'], 'the hook is looked up when it is used');
98
- });
99
-
100
- test('S6: the CodeGraph card gets the session cwd through a live seam', async () => {
101
- const { calls, run } = setup();
102
- assert.equal(typeof calls.card[0].cwd, 'function', 'the card factory is handed a cwd seam');
103
- assert.equal(calls.card[0].cwd(), undefined, 'unknown until the session says');
104
- await run('session_start', { reason: 'startup' });
105
- assert.equal(calls.card[0].cwd(), '/work/repo', 'the seam answers with the session checkout');
106
- });
107
-
108
- test('a host without the renderer hook is given no registration to call', () => {
109
- const { calls } = setup();
110
- assert.equal(calls.card[0].registerToolRenderer('x'), undefined, 'a missing hook is a no-op, never a throw');
111
- });
112
-
113
- test('without the CLI the card is not registered either', () => {
114
- const { calls } = setup({ hasBinary: () => false });
115
- assert.equal(calls.card.length, 0);
116
- });
117
85
 
118
86
  test('a primary session start ensures the MCP entry once, prepares the index and reports the change', async () => {
119
87
  const { calls, run } = setup();
@@ -99,10 +99,9 @@ describe('the Card diff line (S2)', () => {
99
99
  assert.equal(typeof design.preview, 'function');
100
100
  });
101
101
 
102
- test('the preview is ONE row, titled after the value', () => {
102
+ test('the preview is ONE row, titled after the LINE so both options read as one line', () => {
103
103
  const preview = diffColorDesign(seamFor().seam).preview();
104
- assert.equal(preview.title, `Cards · ${DIFF_DESIGN_LABEL}`);
105
- assert.equal(preview.title, 'Cards · color');
104
+ assert.equal(preview.title, 'Cards · Card diff', 'the same title the `default` value shows');
106
105
  assert.equal(preview.sample.split('\n').length, 1, 'one row, like every Cards value');
107
106
  assert.deepEqual(preview, DIFF_DESIGN_PREVIEW);
108
107
  });
@@ -756,3 +755,152 @@ describe('the shape of the contract (S5)', () => {
756
755
  assert.doesNotThrow(() => diffColorDesign(seamFor().seam).apply(rows, callCtx({ render: { args } })));
757
756
  });
758
757
  });
758
+
759
+ describe('a diff line the host wrapped is ONE row ending in an ellipsis, as the write pane draws it (S15)', () => {
760
+ const ctx = () => ({ tool: 'edit', part: 'call', width: WIDTH, theme, render: { args: { path: 'lib/app.js' } } });
761
+ // The host's `Text` breaks a long diff line at the width: the first row states the number, every
762
+ // other row is the rest of the SAME line, at the row's own left column with no number.
763
+ const INNER = WIDTH - 4;
764
+ const hostWrap = (marker, number, code) => {
765
+ // Word wrap; a word longer than the row is broken through, which fills the row.
766
+ const rows = [];
767
+ let current = '';
768
+ for (let word of `${marker}${number} ${code}`.split(' ')) {
769
+ if (current !== '' && textLength(`${current} ${word}`) > INNER) {
770
+ rows.push(current);
771
+ current = '';
772
+ }
773
+ while (textLength(word) > INNER) {
774
+ if (current !== '') rows.push(current);
775
+ rows.push(word.slice(0, INNER));
776
+ current = '';
777
+ word = word.slice(INNER);
778
+ }
779
+ current = current === '' ? word : `${current} ${word}`;
780
+ }
781
+ rows.push(current);
782
+ return rows.map((row) => `│ ${row.padEnd(INNER)} │`);
783
+ };
784
+ const textLength = (text) => Array.from(text).length;
785
+ const LONG = 'const mentions = source.split(newline).filter((line) => !/oddModules/.test(line) && /codegraph/i.test(line))';
786
+
787
+ test('an added line: the rest rows are dropped and the one row keeps its width, divider and role', () => {
788
+ const wrapped = hostWrap('+', '233', LONG);
789
+ assert.ok(wrapped.length >= 2, 'the host did wrap this line');
790
+ const rows = diffColorDesign(seamFor().seam).apply(wrapped, ctx());
791
+ assert.equal(rows.length, 1, `the wrapped remainder is not drawn as stray rows: ${rows.map(unpaint).join('\n')}`);
792
+ assert.equal(cols(rows[0]), WIDTH, 'the row keeps the width the host gave it');
793
+ const plain = unpaint(rows[0]);
794
+ assert.match(plain, /^│ \+233 │ const mentions = .*…\s*│$/u, plain);
795
+ assert.match(rows[0], /<toolDiffAdded>\+233 │ .*…<\/toolDiffAdded>/u, 'the whole row still wears the role');
796
+ assert.equal((plain.match(/│/gu) ?? []).length, 3, `two frame cells and ONE divider: ${plain}`);
797
+ });
798
+
799
+ test('a removed and a context line behave the same, and the rows around them are untouched', () => {
800
+ const rows = diffColorDesign(seamFor().seam).apply([
801
+ `│ ${'@@ -230,3 +230,3 @@'.padEnd(INNER)} │`,
802
+ ...hostWrap('-', '232', LONG),
803
+ ...hostWrap(' ', '234', LONG),
804
+ `│ ${'+235 const next = 1;'.padEnd(INNER)} │`,
805
+ ], ctx());
806
+ const plain = rows.map(unpaint);
807
+ assert.equal(plain.length, 4, plain.join('\n'));
808
+ assert.match(plain[1], /^│ -232 │ const mentions = .*…\s*│$/u);
809
+ assert.match(plain[2], /^│ +234 │ const mentions = .*…\s*│$/u);
810
+ assert.match(plain[3], /^│ \+235 │ const next = 1;\s*│$/u, 'a line that fit is not marked');
811
+ for (const row of rows) assert.equal(cols(row), WIDTH);
812
+ });
813
+
814
+ test('a word longer than the width is cut the same way, and nothing wraps past the frame', () => {
815
+ const rows = diffColorDesign(seamFor().seam).apply(hostWrap('+', '9', 'x'.repeat(130)), ctx());
816
+ assert.equal(rows.length, 1);
817
+ assert.equal(cols(rows[0]), WIDTH);
818
+ assert.match(unpaint(rows[0]), /^│ \+9 │ x+…\s*│$/u);
819
+ });
820
+
821
+ test('painted twice is the same rows', () => {
822
+ const design = diffColorDesign(seamFor().seam);
823
+ const once = design.apply(hostWrap('+', '233', LONG), ctx());
824
+ assert.deepEqual(design.apply(once, ctx()), once);
825
+ });
826
+
827
+ test('only the rest of a line is dropped: a skip marker, the closing rule and a hint stay', () => {
828
+ const rows = [
829
+ ...hostWrap('+', '233', LONG),
830
+ '│ ... │',
831
+ '╰──────────────────────────────────────────────────────────╯',
832
+ 'ctrl+o to expand',
833
+ ];
834
+ const plain = diffColorDesign(seamFor().seam).apply(rows, ctx()).map(unpaint);
835
+ assert.equal(plain.length, 4, plain.join('\n'));
836
+ assert.equal(plain[1], rows[hostWrap('+', '233', LONG).length]);
837
+ assert.equal(plain[2], rows.at(-2));
838
+ assert.equal(plain[3], 'ctrl+o to expand');
839
+ });
840
+ });
841
+
842
+ describe('the edit heading states what the call changed, as the write heading states its lines (S16)', () => {
843
+ const heading = '╭─ ✎ edit lib/app.js ─────────────────────────────────────╮';
844
+ const withHint = '╭─ ✎ edit lib/app.js ──────────────── ctrl+o to collapse ─╮';
845
+ const run = (rows, edits, extra = {}) => diffColorDesign(seamFor().seam).apply(rows, {
846
+ tool: 'edit',
847
+ part: 'call',
848
+ width: WIDTH,
849
+ theme,
850
+ render: { args: { path: 'lib/app.js', edits }, ...extra },
851
+ });
852
+ const edit = (oldText, newText) => ({ oldText, newText });
853
+
854
+ test('added and removed lines follow the path, muted, and the row keeps its width', () => {
855
+ const [row] = run([withHint], [edit('a\nb', 'a\nc\nd')]);
856
+ assert.equal(cols(row), cols(withHint), 'the rule gave the columns, the frame did not move');
857
+ assert.match(row, /edit lib\/app\.js <muted>\(\+2 · -1\)<\/muted> ─+ ctrl\+o to collapse ─╮$/u, row);
858
+ });
859
+
860
+ test('a count of zero is not written, and nothing changed writes nothing', () => {
861
+ assert.match(run([heading], [edit('a', 'a\nb\nc')])[0], /<muted>\(\+2\)<\/muted>/u);
862
+ assert.match(run([heading], [edit('a\nb', 'a')])[0], /<muted>\(-1\)<\/muted>/u);
863
+ assert.equal(run([heading], [edit('same', 'same')])[0], heading);
864
+ });
865
+
866
+ test('every edit of the call counts, and the legacy single oldText/newText call too', () => {
867
+ assert.match(run([heading], [edit('a', 'b'), edit('x\ny', 'x')])[0], /\(\+1 · -2\)/u);
868
+ const legacy = diffColorDesign(seamFor().seam).apply([heading], {
869
+ tool: 'edit', part: 'call', width: WIDTH, theme, render: { args: { path: 'lib/app.js', oldText: 'a', newText: 'b\nc' } },
870
+ });
871
+ assert.match(legacy[0], /\(\+2 · -1\)/u);
872
+ });
873
+
874
+ test('a line only counts when the call really changes it', () => {
875
+ const [row] = run([heading], [edit('keep\nold\nkeep too', 'keep\nnew\nkeep too')]);
876
+ assert.match(row, /\(\+1 · -1\)/u, row);
877
+ });
878
+
879
+ test('float and unframed headings carry the count too', () => {
880
+ const float = ' ▎ ✎ edit lib/app.js ctrl+o to expand ';
881
+ assert.match(run([float], [edit('a', 'b')])[0], /edit lib\/app\.js <muted>\(\+1 · -1\)<\/muted> +ctrl\+o to expand/u);
882
+ assert.equal(cols(run([float], [edit('a', 'b')])[0]), cols(float));
883
+ const bare = `edit lib/app.js${' '.repeat(40)}`;
884
+ assert.match(run([bare], [edit('a', 'b')])[0], /^edit lib\/app\.js <muted>\(\+1 · -1\)<\/muted> +$/u);
885
+ });
886
+
887
+ test('no room, no args, a failed call or the body rows: the host\'s rows come back', () => {
888
+ const tight = '╭─ ✎ edit lib/app.js ─╮';
889
+ assert.deepEqual(run([tight], [edit('a', 'b')]), [tight]);
890
+ assert.deepEqual(run([heading], undefined), [heading]);
891
+ assert.deepEqual(run([heading], [edit('a', 'b')], { isError: true }), [heading]);
892
+ const body = ['│ -1 edit lib/app.js ────────────────────────────────────── │'];
893
+ assert.equal(unpaint(run(body, [edit('a', 'b')])[0]).includes('(+1 · -1)'), false);
894
+ });
895
+
896
+ test('painted twice is the same row', () => {
897
+ const once = run([withHint], [edit('a', 'b')]);
898
+ assert.deepEqual(run(once, [edit('a', 'b')]), once);
899
+ });
900
+
901
+ test('the colour the heading was drawn in is picked up again after the count', () => {
902
+ const painted = `\u001b[34m${withHint}\u001b[39m`;
903
+ const [row] = run([painted], [edit('a', 'b')]);
904
+ assert.ok(row.includes('</muted>\u001b[34m'), row);
905
+ });
906
+ });
@@ -25,7 +25,7 @@ const {
25
25
  fileResultRows,
26
26
  } = require('../lib/file-card.js');
27
27
  const { createFileCardResolver, registerFileCard } = require('../lib/file-card-resolver.js');
28
- // The design this package registers on the bridge's `Card tags` line: the card's one
28
+ // The design this package registers on the bridge's `Card activity` line: the card's one
29
29
  // switch is that line's answer for the tool being drawn, so the card is only painted
30
30
  // for a tool the line actually covers.
31
31
  const { toolsActivityDesign } = require('../lib/bash-design.js');
@@ -564,7 +564,7 @@ test('a foreign, hostile or unreadable bridge never hides the card', () => {
564
564
  assert.match(draw(), /📑 odd/u, 'an unknown kind keeps the card');
565
565
  });
566
566
 
567
- test('S1: a write is covered by the Card tags line, so its file card paints and `default` restores the host row', () => {
567
+ test('S1: a write is covered by the Card activity line, so its file card paints and `default` restores the host row', () => {
568
568
  // A bridge answers from the design's own `tools` list, exactly as it resolves
569
569
  // coverage: a tool the line does not name is `not-covered`, which is the host's own
570
570
  // card. `write` is declared on that line so the file card can be asked about it.
@@ -573,7 +573,7 @@ test('S1: a write is covered by the Card tags line, so its file card paints and
573
573
  publishBridge((tool) => (design.tools.includes(tool) ? { kind: 'design', design } : { kind: 'not-covered' }), asked);
574
574
  const resolver = fileResolver();
575
575
  for (const tool of ['read', 'write']) {
576
- assert.equal(design.tools.includes(tool), true, `${tool} is covered by the Card tags line`);
576
+ assert.equal(design.tools.includes(tool), true, `${tool} is covered by the Card activity line`);
577
577
  const row = callRow(resolver, tool, { path: ODD, content: '# x\n' }, plainTheme);
578
578
  assert.match(unpaint(row), /📑 odd/u, `${tool}: the file card paints its heading`);
579
579
  assert.match(unpaint(row), new RegExp(`${tool} cards-skill-odd\\.md`, 'u'), `${tool}: and names the call`);
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
  // The jobs card: `bash_background`, `monitor`, `job_stop` and `job_list` are registered by
3
3
  // Gentle Shell with no renderer of their own, so Pi draws its plain default box and the
4
- // conversation's card style never reaches them. While the bridge's `Card tags` line answers
4
+ // conversation's card style never reaches them. While the bridge's `Card activity` line answers
5
5
  // `activity` for the tool being drawn, this package draws them on its own card substrate
6
6
  // (`lib/shell-card.js`), in whichever style the shell has chosen. Any other answer — and the
7
7
  // absence of an answer — leaves Pi's own drawing exactly as it was.
@@ -117,7 +117,7 @@ function assertFramed(rows, width) {
117
117
 
118
118
  // ---- the one switch ----
119
119
 
120
- test('the card is drawn only while the Card tags line answers activity; every other answer leaves Pi\'s own drawing', () => {
120
+ test('the card is drawn only while the Card activity line answers activity; every other answer leaves Pi\'s own drawing', () => {
121
121
  const answers = [
122
122
  ['no bridge published', undefined],
123
123
  ['the bridge\'s native answer', { kind: 'native' }],
@@ -295,7 +295,7 @@ test('registerJobsCard hands one resolver to the host hook and reports a host th
295
295
  assert.deepEqual(registerJobsCard({}, { metrics }), { registered: false, resolver: undefined });
296
296
  });
297
297
 
298
- test('the Card tags line covers the four job tools, so the bridge can answer for them', () => {
298
+ test('the Card activity line covers the four job tools, so the bridge can answer for them', () => {
299
299
  for (const scopes of [true, false]) {
300
300
  const design = toolsActivityDesign({ scopes });
301
301
  for (const tool of JOB_TOOLS) assert.ok(design.tools.includes(tool), `${tool} (scopes: ${scopes})`);
@@ -5,7 +5,7 @@
5
5
  // paints them on its own card substrate (`lib/shell-card.js`) through gentle-shell-bridge's
6
6
  // message-design surface, in whichever style the host has chosen and always in full.
7
7
  //
8
- // Both designs FOLLOW the `Card tags` line this package's tool design is selected on, so the
8
+ // Both designs FOLLOW the `Card activity` line this package's tool design is selected on, so the
9
9
  // human picks `activity` once and these paint with it — live, per pass, with no switch of their
10
10
  // own. Every case below goes through the public surface: `registerMessageCards` (the wire), the
11
11
  // designs it registers, and the rows `apply` answers for a width. The text seam and the themes
@@ -85,7 +85,7 @@ const validFollow = (follow) => follow !== null
85
85
  * The published bridge object (gentle-shell-bridge@0.12.0's shape, and the older one it replaced).
86
86
  * `validatesFollows` is the 0.12.0 discipline — a registration whose `follows` is malformed is
87
87
  * refused whole; without it, the object is a pre-0.12.0 bridge that ignores the unknown field.
88
- * `toolLine` is the `Card tags` line's live value: `undefined` means the line does not exist.
88
+ * `toolLine` is the `Card activity` line's live value: `undefined` means the line does not exist.
89
89
  */
90
90
  function publishBridge(options = {}) {
91
91
  const settings = options !== null && typeof options === 'object' ? options : {};
@@ -227,7 +227,7 @@ test('each design FOLLOWS the line and the design id this package already regist
227
227
  assert.notEqual(outcome.bridge.designs[0].follows, outcome.bridge.designs[1].follows, 'one follow object per design');
228
228
  });
229
229
 
230
- test('while Card tags answers activity the message is the card', () => {
230
+ test('while Card activity answers activity the message is the card', () => {
231
231
  const wire = registered({ toolLine: ACTIVITY });
232
232
  const rows = renderMessage(wire.bridge, EXPLORATION, plainBody(EXPLORATION, STARTED));
233
233
  assert.equal(unpaint(rows[0]), headOf(EXPLORATION_HEADING, 70));
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+ // S1/S2 (modular-tools): what the extension registers for each setting of the two module
3
+ // switches. The switches are read ONCE, when the extension registers, from the bridge's
4
+ // store, and a missing document keeps everything on — so every other suite in this package
5
+ // loads the whole thing.
6
+ const { test, describe, afterEach } = require('node:test');
7
+ const assert = require('node:assert/strict');
8
+ const os = require('node:os');
9
+
10
+ const { BRIDGE_SLOT, defaultBridge, loadExtension } = require('./fixtures/load-extension.js');
11
+
12
+ const saved = globalThis[BRIDGE_SLOT];
13
+ afterEach(() => {
14
+ if (saved === undefined) delete globalThis[BRIDGE_SLOT];
15
+ else globalThis[BRIDGE_SLOT] = saved;
16
+ });
17
+
18
+ // A bridge whose own-store `modules` document is the one handed in; everything else the
19
+ // default bridge does stays as it is.
20
+ async function load(modules, { selection, host } = {}) {
21
+ const bridge = defaultBridge();
22
+ const document = modules === undefined ? undefined : { ...modules };
23
+ bridge.api.createStore = () => ({
24
+ get: (key, fallback) => (key === 'modules' && document !== undefined ? document : fallback),
25
+ set: () => {},
26
+ delete: () => {},
27
+ });
28
+ // S11: the `Card activity` reader the CodeGraph card follows, when a case needs one.
29
+ if (typeof selection === 'function') bridge.api.resolveToolDesignSelection = selection;
30
+ globalThis[BRIDGE_SLOT] = bridge.api;
31
+ const loaded = await loadExtension(host || {});
32
+ return { ...loaded, bridge };
33
+ }
34
+
35
+ /** The activity design, as the bridge answers it while `Card activity` is on `activity`. */
36
+ const ACTIVITY = () => ({ kind: 'design', design: { id: 'odd-worktree.bash-activity' } });
37
+
38
+ const toolCallHandlers = (loaded) => loaded.hooks.filter(([name]) => name === 'tool_call').length;
39
+
40
+ async function promptOf(loaded, selectedTools) {
41
+ const options = { selectedTools };
42
+ for (const [name, handler] of loaded.hooks) {
43
+ if (name === 'before_agent_start') await handler({ systemPromptOptions: options }, { cwd: os.tmpdir() });
44
+ }
45
+ return options.appendSystemPrompt ?? '';
46
+ }
47
+
48
+ describe('the Tools page', () => {
49
+ test('the extension registers one provider on the `Tools` page, whatever the switches say', async () => {
50
+ for (const modules of [undefined, { codegraph: false }, { worktrees: false }, { codegraph: false, worktrees: false }]) {
51
+ const { bridge } = await load(modules);
52
+ const tools = bridge.rows.filter((provider) => provider.category === 'Tools');
53
+ assert.equal(tools.length, 1, JSON.stringify(modules));
54
+ assert.deepEqual(
55
+ tools[0].rows({}).map((row) => `${row.choice.setting} ${row.choice.value}`),
56
+ ['Codegraph+ Off', 'Codegraph+ On', 'Worktrees+ Off', 'Worktrees+ On'],
57
+ );
58
+ }
59
+ });
60
+ });
61
+
62
+ describe('Worktrees+', () => {
63
+ test('on (the default): the two tools, /warp, its card and every worktree guard and text', async () => {
64
+ const loaded = await load(undefined);
65
+ assert.deepEqual([...loaded.tools.keys()].filter((name) => name.startsWith('worktree_')).sort(), ['worktree_create', 'worktree_list']);
66
+ assert.ok(loaded.commands.has('warp'));
67
+ assert.ok(loaded.messageRenderers.has('worktree-warp'));
68
+ assert.match(await promptOf(loaded, []), /## ODD worktrees/);
69
+ });
70
+
71
+ test('off: no tools, no /warp, no warp card, no worktree text and fewer guards, while everything else stays', async () => {
72
+ const on = await load(undefined);
73
+ const off = await load({ worktrees: false });
74
+ assert.equal([...off.tools.keys()].some((name) => name.startsWith('worktree_')), false);
75
+ assert.equal(off.commands.has('warp'), false);
76
+ assert.equal(off.messageRenderers.has('worktree-warp'), false);
77
+ assert.doesNotMatch(await promptOf(off, []), /## ODD worktrees/);
78
+ // the naming handler, the bash guard and the write guard go; the skill-read guard stays
79
+ assert.equal(toolCallHandlers(on) - toolCallHandlers(off), 3);
80
+ assert.ok(toolCallHandlers(off) >= 1, 'the skill-read guard is transversal');
81
+ for (const name of ['odd', 'files']) assert.ok(off.commands.has(name), `${name} stays`);
82
+ assert.equal(off.hooks.some(([hook]) => hook === 'agent_settled'), false, 'the warp settle tick goes');
83
+ });
84
+
85
+ test('off keeps the CodeGraph text and the issues surface', async () => {
86
+ const off = await load({ worktrees: false });
87
+ assert.match(await promptOf(off, ['codegraph']), /## CodeGraph/);
88
+ assert.ok(off.commands.has('issues'));
89
+ });
90
+ });
91
+
92
+ describe('Codegraph+', () => {
93
+ test('on (the default): the role text rides the prompt of a session holding a CodeGraph tool', async () => {
94
+ assert.match(await promptOf(await load(undefined), ['codegraph']), /## CodeGraph/);
95
+ });
96
+
97
+ test('off: no CodeGraph text, and the worktrees half is untouched', async () => {
98
+ const off = await load({ codegraph: false });
99
+ const prompt = await promptOf(off, ['codegraph']);
100
+ assert.doesNotMatch(prompt, /## CodeGraph/);
101
+ assert.match(prompt, /## ODD worktrees/);
102
+ assert.ok(off.tools.has('worktree_create'));
103
+ assert.ok(off.commands.has('warp'));
104
+ });
105
+ });
106
+
107
+ describe('the CodeGraph card', () => {
108
+ const cardResolvers = async (modules, selection) => {
109
+ const resolvers = [];
110
+ await load(modules, { selection, host: { registerToolRenderer: (resolver) => resolvers.push(resolver) } });
111
+ return resolvers.filter((resolver) => resolver('codegraph', () => undefined) !== undefined).length;
112
+ };
113
+
114
+ test('is a design of the `Card activity` line: activity on paints it, and Codegraph+ off keeps it', async () => {
115
+ assert.equal(await cardResolvers(undefined, ACTIVITY), 1, 'activity on, both modules on');
116
+ assert.equal(await cardResolvers({ codegraph: false }, ACTIVITY), 1, 'Codegraph+ off does not take the card away');
117
+ });
118
+
119
+ test('is not a module surface: native leaves every row to the chain', async () => {
120
+ assert.equal(await cardResolvers(undefined, () => ({ kind: 'native' })), 0);
121
+ assert.equal(await cardResolvers({ codegraph: false }, () => ({ kind: 'native' })), 0);
122
+ assert.equal(await cardResolvers(undefined, undefined), 0, 'no reader, no switch, no card');
123
+ });
124
+ });
125
+
126
+ describe('both off', () => {
127
+ test('the package keeps its transversal surface and adds neither half', async () => {
128
+ const off = await load({ codegraph: false, worktrees: false });
129
+ assert.equal(await promptOf(off, ['codegraph']), '');
130
+ assert.equal(off.tools.size, 0);
131
+ for (const name of ['odd', 'files', 'issues']) assert.ok(off.commands.has(name), `${name} stays`);
132
+ });
133
+ });
@@ -0,0 +1,124 @@
1
+ 'use strict';
2
+ // S1/S3 (modular-tools): the two module switches, `Codegraph+` and `Worktrees+`. The
3
+ // module reads and writes one persisted document through the bridge's store, builds the
4
+ // `Tools` page's rows and says one short thing after a change. It is pure over the
5
+ // injected bridge, so nothing here loads the extension.
6
+ const { test, describe } = require('node:test');
7
+ const assert = require('node:assert/strict');
8
+
9
+ const modules = require('../lib/modules.js');
10
+
11
+ // A bridge whose `createStore` keeps one in-memory file per plugin id, like the real one.
12
+ function fakeBridge(initial = {}) {
13
+ const files = new Map(Object.entries(initial));
14
+ const writes = [];
15
+ const createStore = (id) => ({
16
+ get: (key, fallback) => (files.get(id)?.[key] !== undefined ? files.get(id)[key] : fallback),
17
+ set: (key, value) => {
18
+ files.set(id, { ...(files.get(id) ?? {}), [key]: value });
19
+ writes.push([id, key, value]);
20
+ },
21
+ });
22
+ return { api: { createStore }, files, writes };
23
+ }
24
+
25
+ describe('reading the switches', () => {
26
+ test('both modules are on when nothing is stored, and for every malformed document', () => {
27
+ assert.deepEqual(modules.readModules(fakeBridge().api), { codegraph: true, worktrees: true });
28
+ for (const bad of [null, 42, 'off', [], { codegraph: 'no' }, { worktrees: null }]) {
29
+ const { api } = fakeBridge({ 'odd-worktree': { modules: bad } });
30
+ const read = modules.readModules(api);
31
+ assert.equal(read.codegraph, true, JSON.stringify(bad));
32
+ assert.equal(read.worktrees, true, JSON.stringify(bad));
33
+ }
34
+ });
35
+
36
+ test('a stored false switches exactly that module off', () => {
37
+ const { api } = fakeBridge({ 'odd-worktree': { modules: { codegraph: false } } });
38
+ assert.deepEqual(modules.readModules(api), { codegraph: false, worktrees: true });
39
+ });
40
+
41
+ test('no bridge, no createStore and a throwing store all read as on and never throw', () => {
42
+ for (const api of [null, undefined, {}, { createStore: () => { throw new Error('disk'); } }]) {
43
+ assert.deepEqual(modules.readModules(api), { codegraph: true, worktrees: true });
44
+ }
45
+ });
46
+ });
47
+
48
+ describe('writing a switch', () => {
49
+ test('writes one key and keeps the other module and every other key of the document', () => {
50
+ const bridge = fakeBridge({ 'odd-worktree': { modules: { worktrees: false }, other: 1 } });
51
+ assert.equal(modules.writeModule(bridge.api, 'codegraph', false), true);
52
+ assert.deepEqual(bridge.files.get('odd-worktree'), { modules: { worktrees: false, codegraph: false }, other: 1 });
53
+ });
54
+
55
+ test('a failing store or an unknown module writes nothing and reports false', () => {
56
+ assert.equal(modules.writeModule({ createStore: () => { throw new Error('disk'); } }, 'codegraph', false), false);
57
+ const bridge = fakeBridge();
58
+ assert.equal(modules.writeModule(bridge.api, 'nope', false), false);
59
+ assert.deepEqual(bridge.writes, []);
60
+ });
61
+ });
62
+
63
+ describe('the Tools page rows', () => {
64
+ const rowsOf = (bridge, notices = []) => modules.moduleRowsProvider({ api: bridge.api, notify: (text) => notices.push(text) }).rows({});
65
+
66
+ test('one provider on the `Tools` page, two Off/On toggles named exactly like the switches', () => {
67
+ const provider = modules.moduleRowsProvider({ api: fakeBridge().api, notify: () => {} });
68
+ assert.equal(provider.category, 'Tools');
69
+ assert.equal(typeof provider.id, 'string');
70
+ const rows = provider.rows({});
71
+ assert.deepEqual(rows.map((row) => [row.choice.setting, row.choice.value]), [
72
+ ['Codegraph+', 'Off'], ['Codegraph+', 'On'], ['Worktrees+', 'Off'], ['Worktrees+', 'On'],
73
+ ]);
74
+ for (const row of rows) {
75
+ assert.equal(row.category, 'Tools');
76
+ assert.match(row.choice.setting, /^[A-Za-z]+\+?$/, 'a row name the bridge accepts');
77
+ assert.equal(typeof row.action, 'function');
78
+ }
79
+ });
80
+
81
+ test('current() follows the stored value, On by default', () => {
82
+ const bridge = fakeBridge({ 'odd-worktree': { modules: { worktrees: false } } });
83
+ const rows = rowsOf(bridge);
84
+ assert.deepEqual(rows.map((row) => row.choice.current()), [false, true, true, false]);
85
+ });
86
+
87
+ test('Enter persists first, then says one short thing about the restart', async () => {
88
+ const bridge = fakeBridge();
89
+ const notices = [];
90
+ const rows = rowsOf(bridge, notices);
91
+ await rows[0].action();
92
+ assert.deepEqual(bridge.files.get('odd-worktree').modules, { codegraph: false });
93
+ assert.equal(notices.length, 1);
94
+ assert.match(notices[0], /^Codegraph\+ Off/);
95
+ assert.match(notices[0], /\/reload/);
96
+ assert.match(notices[0], /new session/);
97
+ assert.ok(notices[0].length < 100, `short: ${notices[0]}`);
98
+ assert.equal(rows[0].choice.current(), true, 'the same page reads the new value');
99
+ });
100
+
101
+ test('choosing the value it already has changes nothing and says nothing', async () => {
102
+ const bridge = fakeBridge();
103
+ const notices = [];
104
+ const rows = rowsOf(bridge, notices);
105
+ await rows[3].action();
106
+ assert.deepEqual(bridge.writes, []);
107
+ assert.deepEqual(notices, []);
108
+ });
109
+
110
+ test('a store that cannot write says nothing and never throws', async () => {
111
+ const api = { createStore: () => ({ get: (_k, fallback) => fallback, set: () => { throw new Error('disk'); } }) };
112
+ const notices = [];
113
+ const rows = modules.moduleRowsProvider({ api, notify: (text) => notices.push(text) }).rows({});
114
+ await assert.doesNotReject(async () => rows[0].action());
115
+ assert.deepEqual(notices, []);
116
+ });
117
+
118
+ test('a throwing notify never fails the action', async () => {
119
+ const bridge = fakeBridge();
120
+ const rows = modules.moduleRowsProvider({ api: bridge.api, notify: () => { throw new Error('ui gone'); } }).rows({});
121
+ await assert.doesNotReject(async () => rows[0].action());
122
+ assert.deepEqual(bridge.files.get('odd-worktree').modules, { codegraph: false });
123
+ });
124
+ });