fix(pi): load installed device extensions

This commit is contained in:
2026-09-03 10:32:00 +08:00
parent 34e59bfaf2
commit 17664c5fff
2 changed files with 32 additions and 3 deletions

View File

@@ -196,6 +196,22 @@ describe('Pi Agent Server real process', () => {
writeFile(languagePromptPath, MAKELORE_DEFAULT_LANGUAGE_PROMPT),
]);
const extensionPath = await materializeMakelorePiExtension(extensionDir);
const firstDeviceExtensionPath = path.join(extensionDir, 'first-device-extension.mjs');
const secondDeviceExtensionPath = path.join(extensionDir, 'second-device-extension.mjs');
await Promise.all([
writeFile(firstDeviceExtensionPath, [
'export default function (pi) {',
" pi.registerCommand('first-device-ping', { description: 'First device ping', handler: async () => {} });",
'}',
'',
].join('\n')),
writeFile(secondDeviceExtensionPath, [
'export default function (pi) {',
" pi.registerCommand('second-device-ping', { description: 'Second device ping', handler: async () => {} });",
'}',
'',
].join('\n')),
]);
const runtimeRoot = path.resolve('node_modules/@earendil-works/pi-coding-agent');
const server = new PiAgentServerProcess({
executablePath: process.execPath,
@@ -221,6 +237,8 @@ describe('Pi Agent Server real process', () => {
'--system-prompt', promptPath,
'--append-system-prompt', languagePromptPath,
'--extension', extensionPath,
'--extension', firstDeviceExtensionPath,
'--extension', secondDeviceExtensionPath,
'--session-id', `session-${conversationId}`,
],
env: {
@@ -261,6 +279,15 @@ describe('Pi Agent Server real process', () => {
.resolves.toMatchObject({
data: { models: expect.arrayContaining([expect.objectContaining({ id: 'test-model' })]) },
});
await expect(left.request<{ commands: Array<{ name: string; source: string }> }>({ type: 'get_commands' }))
.resolves.toMatchObject({
data: {
commands: expect.arrayContaining([
expect.objectContaining({ name: 'first-device-ping', source: 'extension' }),
expect.objectContaining({ name: 'second-device-ping', source: 'extension' }),
]),
},
});
const settled = (worker: typeof left) => new Promise<void>((resolve) => {
const unsubscribe = worker.subscribe((event) => {