summaryrefslogtreecommitdiff
path: root/tests/pi
diff options
context:
space:
mode:
authorDrew Ritter <drew@primeradiant.com>2026-11-02 13:31:53 -0800
committerDrew Ritter <drew@primeradiant.com>2026-11-02 13:31:53 -0800
commit38fd8323e43f4b13e8bdc9d62b85ca1ed524a3f8 (patch)
tree335eecee026317ef5699bf6f0a0da7104cffed7b /tests/pi
parent80b085cfb36c0dfe5f6740a3a4764d16429a8228 (diff)
parent587f04636d67a32d2edf65550085cdf2d70260a4 (diff)
Merge dev into the OpenCode compaction bootstrap fixfix/2391-opencode-compaction-bootstrap
Drew requested resolution of the merge conflict in obra/superpowers PR #2601. Merge current dev into the existing PR branch without rewriting its history. Resolve the V2 bootstrap hunk by keeping #2601's shared handler registered on context, compaction, and generate, and incorporating #2600's exact BOOTSTRAP_MARKER prefix guard. This preserves injection for prompts that merely mention EXTREMELY_IMPORTANT while preventing duplicate bootstrap parts. All other dev changes merge without manual edits. Validation: bash tests/opencode/run-tests.sh passed all five suites, including hook registration, tag-mention regression coverage, child-session suppression, caching, and skill registration. git diff --cached --check passed and the index contains no unresolved paths. Live OpenCode integration sessions were not rerun for this conflict-only repair. Tracking: PRI-3674
Diffstat (limited to 'tests/pi')
-rw-r--r--tests/pi/test-pi-extension.mjs49
1 files changed, 43 insertions, 6 deletions
diff --git a/tests/pi/test-pi-extension.mjs b/tests/pi/test-pi-extension.mjs
index c79f710..65d65e0 100644
--- a/tests/pi/test-pi-extension.mjs
+++ b/tests/pi/test-pi-extension.mjs
@@ -34,6 +34,14 @@ function firstHandler(handlers, event) {
return eventHandlers[0];
}
+// Fire an event the way pi does: every registered handler runs, and an event
+// the extension does not subscribe to is a no-op.
+async function emit(handlers, event, payload) {
+ for (const handler of handlers.get(event) ?? []) {
+ await handler({ type: event, ...payload }, {});
+ }
+}
+
function textOf(message) {
if (typeof message.content === 'string') return message.content;
return message.content
@@ -55,17 +63,16 @@ test('extension leaves package skill discovery to Pi and registers lifecycle hoo
const { handlers } = await loadExtension();
assert.equal((handlers.get('resources_discover') ?? []).length, 0, 'extension must not bypass package skill filters');
- for (const event of ['session_start', 'session_compact', 'context', 'agent_end']) {
+ for (const event of ['session_start', 'session_compact', 'context']) {
assert.equal((handlers.get(event) ?? []).length, 1, `missing ${event} handler`);
}
assert.equal((handlers.get('session_before_compact') ?? []).length, 0);
});
-test('startup context injects the bootstrap as one user message until agent_end', async () => {
+test('startup context injects the bootstrap as one user message', async () => {
const { handlers } = await loadExtension();
const sessionStart = firstHandler(handlers, 'session_start');
const context = firstHandler(handlers, 'context');
- const agentEnd = firstHandler(handlers, 'agent_end');
await sessionStart({ type: 'session_start', reason: 'startup' }, {});
@@ -86,10 +93,40 @@ test('startup context injects the bootstrap as one user message until agent_end'
const alreadyInjected = await context({ type: 'context', messages: result.messages }, {});
assert.equal(alreadyInjected, undefined, 'bootstrap should not duplicate when already present');
+});
+
+// pi emits agent_start/agent_end around every user prompt, not once per
+// session, and the messages a context handler returns are never written back
+// to session history. So every provider request of every prompt needs the
+// bootstrap injected again (#2083).
+test('every provider request of every prompt in a session carries the bootstrap', async () => {
+ const { handlers } = await loadExtension();
+ const context = firstHandler(handlers, 'context');
+
+ await emit(handlers, 'session_start', { reason: 'startup' });
- await agentEnd({ type: 'agent_end', messages: [] }, {});
- const afterEnd = await context({ type: 'context', messages: originalMessages }, {});
- assert.equal(afterEnd, undefined, 'startup bootstrap should clear after agent_end');
+ const history = [];
+ const prompts = [
+ { text: 'first prompt', providerRequests: 1 },
+ { text: 'second prompt with a tool call', providerRequests: 2 },
+ { text: 'third prompt', providerRequests: 1 },
+ ];
+ for (const [promptIndex, prompt] of prompts.entries()) {
+ history.push({ role: 'user', content: [{ type: 'text', text: prompt.text }], timestamp: promptIndex });
+ await emit(handlers, 'agent_start', {});
+ for (let request = 1; request <= prompt.providerRequests; request += 1) {
+ await emit(handlers, 'turn_start', {});
+ const result = await context({ type: 'context', messages: structuredClone(history) }, {});
+ const label = `prompt ${promptIndex + 1}, provider request ${request}`;
+ assert.ok(result, `${label}: bootstrap missing`);
+ assert.equal(result.messages.length, history.length + 1, `${label}: expected exactly one bootstrap message`);
+ assert.match(textOf(result.messages[0]), /You have superpowers/, `${label}: bootstrap not first`);
+ history.push({ role: 'assistant', content: [{ type: 'text', text: 'ok' }], timestamp: promptIndex });
+ await emit(handlers, 'turn_end', {});
+ }
+ await emit(handlers, 'agent_end', { messages: [] });
+ await emit(handlers, 'agent_settled', {});
+ }
});
test('session_compact injects bootstrap after compaction summaries, not before compaction', async () => {