fix(packages): load bundled Pi runtime for local installs

This commit is contained in:
2026-09-02 22:46:58 +08:00
parent 28e1690038
commit 5a2f0eb678
9 changed files with 356 additions and 19 deletions

View File

@@ -118,12 +118,24 @@ describe('DevicePackageManager', () => {
expect(preview.warnings.join(' ')).toContain('网络');
});
it('runs remote Pi installation with lifecycle scripts disabled and reports declared scripts', async () => {
it('uses the bundled Pi runtime for remote installation when the app Pi graph is unavailable', async () => {
const root = await temporaryRoot('remote');
const runtimeRoot = path.join(root, 'pi-runtime');
const cliPath = path.join(runtimeRoot, 'dist', 'cli.js');
await writeJson(path.join(runtimeRoot, 'package.json'), { type: 'module' });
await mkdir(path.dirname(cliPath), { recursive: true });
await writeFile(path.join(path.dirname(cliPath), 'index.js'), [
"import path from 'node:path';",
'export class SettingsManager { static inMemory() { return {}; } }',
'export class DefaultPackageManager {',
' constructor(options) { this.agentDir = options.agentDir; }',
" getInstalledPath() { return path.join(this.agentDir, 'npm', 'node_modules', 'fixture-installed'); }",
'}',
].join('\n'), 'utf8');
const calls: DevicePackageInstallInput[] = [];
const runInstall = vi.fn(async (input: DevicePackageInstallInput) => {
calls.push(input);
const packageRoot = path.join(input.agentDir, 'npm', 'node_modules', 'pi-web-search');
const packageRoot = path.join(input.agentDir, 'npm', 'node_modules', 'fixture-installed');
await writeJson(path.join(packageRoot, 'package.json'), {
name: 'pi-web-search',
version: '2.4.0',
@@ -135,7 +147,7 @@ describe('DevicePackageManager', () => {
const manager = new DevicePackageManager({
rootDir: path.join(root, 'store'),
executablePath: 'Makelore.exe',
cliPath: 'pi-cli.js',
cliPath,
npmCliPath: 'npm-cli.js',
runInstall,
now: () => NOW,