pi-odd-worktree 3.9.0 → 3.9.1

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.
@@ -270,6 +270,37 @@ test('a live flip repaints the message and turns it off again, with no re-regist
270
270
  assert.ok(wire.bridge.resolutions >= 4, 'the follow was read on every pass');
271
271
  });
272
272
 
273
+ /**
274
+ * One MOUNTED message component: the rows the bridge answers for this message, read again on
275
+ * every paint. Mounted once, like the component Pi builds for a custom message — nothing here
276
+ * is rebuilt between the flips below, which is exactly the claim (S5).
277
+ */
278
+ function mountMessage(state, customType, lines, width = 70) {
279
+ const hostRows = [...lines];
280
+ return {
281
+ render() {
282
+ return renderMessage(state, customType, hostRows, width);
283
+ },
284
+ };
285
+ }
286
+
287
+ test('a mounted message card repaints when Card activity flips, in both directions', () => {
288
+ // S5: the message designs are FOLLOWED per pass by the bridge, so a mounted message
289
+ // (Pi builds one per message and never asks its renderer again) repaints when the line
290
+ // moves — the one claim this card has to make good on, and the reason it owns no switch.
291
+ const wire = registered({ toolLine: ACTIVITY });
292
+ const input = plainBody(EXPLORATION, STARTED);
293
+ const mounted = mountMessage(wire.bridge, EXPLORATION, input);
294
+ const on = mounted.render();
295
+ assert.equal(unpaint(on[0]), headOf(EXPLORATION_HEADING, 70), 'the card is drawn while the line says activity');
296
+ wire.bridge.toolLine = 'native';
297
+ assert.deepEqual(mounted.render(), input, 'flipped off, the very same component draws Pi\'s own rows, byte for byte');
298
+ wire.bridge.toolLine = ACTIVITY;
299
+ assert.deepEqual(mounted.render(), on, 'flipped back on, the card is drawn again, unchanged');
300
+ assert.equal(wire.bridge.calls.length, 1, 'no re-registration: one design, asked again on every pass');
301
+ assert.equal(wire.bridge.resolutions, 3, 'the follow was read on each of the three passes');
302
+ });
303
+
273
304
  test('registration needs no store, so no seed is written for a switch that already exists', () => {
274
305
  // The fake publishes no `createStore`: a module that seeded anything would have to throw here.
275
306
  const outcome = registered();
@@ -3,12 +3,29 @@
3
3
  // switches. The switches are read ONCE, when the extension registers, from the bridge's
4
4
  // store, and a missing document keeps everything on — so every other suite in this package
5
5
  // loads the whole thing.
6
- const { test, describe, afterEach } = require('node:test');
6
+ const { test, describe, after, afterEach } = require('node:test');
7
7
  const assert = require('node:assert/strict');
8
8
  const os = require('node:os');
9
9
 
10
10
  const { BRIDGE_SLOT, defaultBridge, loadExtension } = require('./fixtures/load-extension.js');
11
11
 
12
+ // The prompt assertions below read the extension's own `before_agent_start`, which honors these
13
+ // two switches from the ambient environment: a suite that ran inside a subagent child (or under
14
+ // `ODD_WORKTREE_PROMPT=0`) would otherwise assert against a prompt the extension was told to keep
15
+ // empty. They are cleared once here, so the cases are the same in every environment.
16
+ const savedPromptEnv = {
17
+ child: process.env.GENTLE_PI_AGENTS_CHILD,
18
+ prompt: process.env.ODD_WORKTREE_PROMPT,
19
+ };
20
+ delete process.env.GENTLE_PI_AGENTS_CHILD;
21
+ delete process.env.ODD_WORKTREE_PROMPT;
22
+ after(() => {
23
+ for (const [key, value] of [['GENTLE_PI_AGENTS_CHILD', savedPromptEnv.child], ['ODD_WORKTREE_PROMPT', savedPromptEnv.prompt]]) {
24
+ if (value === undefined) delete process.env[key];
25
+ else process.env[key] = value;
26
+ }
27
+ });
28
+
12
29
  const saved = globalThis[BRIDGE_SLOT];
13
30
  afterEach(() => {
14
31
  if (saved === undefined) delete globalThis[BRIDGE_SLOT];
@@ -108,21 +125,45 @@ describe('Codegraph+', () => {
108
125
  });
109
126
 
110
127
  describe('the CodeGraph card', () => {
111
- const cardResolvers = async (modules, selection) => {
128
+ // The card claims `codegraph` on EVERY answer, because Pi resolves a tool's renderers once,
129
+ // when it mounts the card, and never asks again: the `Card activity` line is read inside the
130
+ // component, on every paint, and a flipped line repaints the card already on screen. What this
131
+ // file can observe is the ROWS — with any answer but `activity`, and with no reader at all, the
132
+ // chain's own renderer keeps them untouched — and that the card is still the one answering,
133
+ // which is what a flip depends on. (This load injects no text seam, so the card itself degrades
134
+ // to the host's drawing here; tools/codegraph-card.test.js proves the card's own rows.)
135
+ const CHAIN = {
136
+ renderShell: 'self',
137
+ renderCall: () => ({ render: () => ['the chain drew this'], invalidate() {} }),
138
+ renderResult: () => ({ render: () => ['the chain drew this too'], invalidate() {} }),
139
+ };
140
+
141
+ /** The CodeGraph card's own answer on this load, as the call rows it draws — or [] when none claims. */
142
+ const cardRows = async (modules, selection) => {
112
143
  const resolvers = [];
113
144
  await load(modules, { selection, host: { registerToolRenderer: (resolver) => resolvers.push(resolver) } });
114
- return resolvers.filter((resolver) => resolver('codegraph', () => undefined) !== undefined).length;
145
+ return resolvers
146
+ .map((resolver) => resolver('codegraph', () => CHAIN))
147
+ .filter((slot) => slot !== CHAIN && slot?.renderShell === 'self' && typeof slot.renderCall === 'function')
148
+ .map((slot) => slot.renderCall({ operation: 'status' }, undefined, { isPartial: false }).render(24));
115
149
  };
116
150
 
117
- test('is a design of the `Card activity` line: activity on paints it, and Codegraph+ off keeps it', async () => {
118
- assert.equal(await cardResolvers(undefined, ACTIVITY), 1, 'activity on, both modules on');
119
- assert.equal(await cardResolvers({ codegraph: false }, ACTIVITY), 1, 'Codegraph+ off does not take the card away');
151
+ test('is a design of the `Card activity` line: activity on answers it, and Codegraph+ off keeps it', async () => {
152
+ for (const modules of [undefined, { codegraph: false }]) {
153
+ assert.deepEqual(await cardRows(modules, ACTIVITY), [['the chain drew this']], `the card answers whatever the line says (${JSON.stringify(modules)})`);
154
+ }
120
155
  });
121
156
 
122
- test('is not a module surface: native leaves every row to the chain', async () => {
123
- assert.equal(await cardResolvers(undefined, () => ({ kind: 'native' })), 0);
124
- assert.equal(await cardResolvers({ codegraph: false }, () => ({ kind: 'native' })), 0);
125
- assert.equal(await cardResolvers(undefined, undefined), 0, 'no reader, no switch, no card');
157
+ test('is not a module surface: native, another answer and no reader hand every row back to the chain', async () => {
158
+ for (const [name, selection] of [
159
+ ['native', () => ({ kind: 'native' })],
160
+ ['another plugin\'s design', () => ({ kind: 'design', design: { id: 'acme.tools' } })],
161
+ ['no reader at all', undefined],
162
+ ]) {
163
+ for (const modules of [undefined, { codegraph: false }]) {
164
+ assert.deepEqual(await cardRows(modules, selection), [['the chain drew this']], `${name} (${JSON.stringify(modules)}): the rows are the chain's`);
165
+ }
166
+ }
126
167
  });
127
168
  });
128
169