diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/hermes/test_plugin.py | 18 | ||||
| -rw-r--r-- | tests/opencode/test-bootstrap-caching.mjs | 22 | ||||
| -rw-r--r-- | tests/opencode/test-session-bootstrap.mjs | 10 | ||||
| -rw-r--r-- | tests/pi/test-pi-extension.mjs | 49 |
4 files changed, 93 insertions, 6 deletions
diff --git a/tests/hermes/test_plugin.py b/tests/hermes/test_plugin.py index 57d619e..7c896a3 100644 --- a/tests/hermes/test_plugin.py +++ b/tests/hermes/test_plugin.py @@ -87,6 +87,24 @@ class TestBootstrapInjection: assert _fire_pre_llm(mock_ctx, is_first_turn=False) is None assert _fire_pre_llm(mock_ctx, is_first_turn=None) is None + def test_subagent_platform_skips_bootstrap_on_first_turn(self, mock_ctx): + plugin = _load_plugin() + plugin.register(mock_ctx) + assert ( + _fire_pre_llm(mock_ctx, is_first_turn=True, platform="subagent") + is None + ) + + def test_non_subagent_platforms_receive_bootstrap(self, mock_ctx): + plugin = _load_plugin() + plugin.register(mock_ctx) + for platform in ("cli", "desktop", "cron", "telegram"): + result = _fire_pre_llm( + mock_ctx, is_first_turn=True, platform=platform + ) + assert isinstance(result, dict) + assert BOOTSTRAP_MARKER in result["context"] + def test_hook_tolerates_future_kwargs(self, mock_ctx): plugin = _load_plugin() plugin.register(mock_ctx) diff --git a/tests/opencode/test-bootstrap-caching.mjs b/tests/opencode/test-bootstrap-caching.mjs index 386b7b1..39e4daa 100644 --- a/tests/opencode/test-bootstrap-caching.mjs +++ b/tests/opencode/test-bootstrap-caching.mjs @@ -76,6 +76,9 @@ const failures = scenario === 'present' if (scenario === 'present') { failures.push(...assertV2Bootstrap(result)); + // #2583: both flavors register bare skill ids and look them up exactly. + failures.push(...assertTeachesBareSkillIds('V1', bootstrapText(firstOutput), 'name')); + failures.push(...assertTeachesBareSkillIds('V2', v2Result.text, 'id')); } failures.push(...mappingFailures); @@ -202,6 +205,25 @@ function assertMappingConstants(mod) { return failures; } +// #2583: skills reference each other as `superpowers:<name>` (the Claude Code +// plugin namespace), but OpenCode V1 and V2 register bare ids (`brainstorming`) +// and their `skill` tools do an exact lookup, so a namespaced call fails with +// "Unable to load skill". When the injected bootstrap contains namespaced +// references, its tool mapping must tell the model to drop the prefix, using +// the flavor's `skill` parameter (V1 `name`, V2 `id`). +function assertTeachesBareSkillIds(flavor, text, param) { + const failures = []; + const refs = [...new Set(text.match(/superpowers:[a-z0-9-]+/g) || [])]; + if (refs.length === 0) return failures; + if (!text.includes('drop the `superpowers:` prefix')) { + failures.push(`expected ${flavor} bootstrap to tell the model to drop the superpowers: prefix (bootstrap references ${refs.join(', ')})`); + } + if (!text.includes(`\`superpowers:brainstorming\` → \`skill\` with \`${param}: "brainstorming"\``)) { + failures.push(`expected ${flavor} bootstrap to show superpowers:brainstorming loading as \`skill\` with \`${param}: "brainstorming"\``); + } + return failures; +} + // Drive setup() with a mock V2 ctx and fire the captured "context" hook on a // top-level (parentID-less) session. Returns the injected-part count and the // injected bootstrap text ('' when nothing was injected). diff --git a/tests/opencode/test-session-bootstrap.mjs b/tests/opencode/test-session-bootstrap.mjs index 31658d5..67b3118 100644 --- a/tests/opencode/test-session-bootstrap.mjs +++ b/tests/opencode/test-session-bootstrap.mjs @@ -139,6 +139,16 @@ for (const flavor of ['v1', 'v2']) { await unknown.invoke(noID); assert.equal(bootstrapCount(noID), 1); assert.deepEqual(unknown.lookups, []); + + // #2197: a prompt that merely mentions the bootstrap's tag is not the bootstrap. + const mentions = await makeHarness(flavor, (id) => reply(flavor, { id })); + const probe = makeEvent(flavor, `${flavor}-mentions-tag`); + (probe.messages[0].parts ?? probe.messages[0].content)[0].text = + "Is there an 'EXTREMELY_IMPORTANT' block in your context?"; + await mentions.invoke(probe); + assert.equal(bootstrapCount(probe), 1, `${flavor}: prompt mentioning the tag still gets bootstrap`); + await mentions.invoke(probe); + assert.equal(bootstrapCount(probe), 1, `${flavor}: prompt mentioning the tag, repeated event`); } function compactedEvent(sessionID) { 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 () => { |
