merge: integrate remote and local main histories
# Conflicts: # .project-docs/20-architecture/module-map.md # .project-docs/30-worklog/current-state.md # .project-docs/50-evidence/evidence-index.md # src/pages/MyPlugins/index.tsx # tests/unit/pi-agent-server-process-real.test.ts # tests/unit/pi-managed-worker-opener.test.ts # tests/unit/plugin-marketplace-pages.test.tsx
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// @vitest-environment node
|
||||
|
||||
import { mkdtemp, readFile, rm } from 'node:fs/promises';
|
||||
import { mkdtemp, mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
||||
import { tmpdir } from 'node:os';
|
||||
import path from 'node:path';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
@@ -31,6 +31,9 @@ import { PiWorkerPool } from '../../electron/coding-runtime/pi/worker-pool';
|
||||
import type { CodingCapabilityRegistry } from '../../electron/coding-plugins/registry';
|
||||
import type { EffectivePluginSnapshot } from '../../electron/coding-plugins/effective-resolver';
|
||||
import { DATA_SERVICE_PLUGIN_DEFINITION } from '../../shared/coding-plugins';
|
||||
import type { ModelToolRegistryPort } from '../../electron/coding-runtime/pi/model-tools/model-tool-registry';
|
||||
import type { DevicePackageManager } from '../../electron/coding-packages/device-package-manager';
|
||||
import { DEVICE_PACKAGE_TOOL_DEFINITIONS } from '../../electron/coding-packages/device-package-tools';
|
||||
|
||||
const roots: string[] = [];
|
||||
const NOW = '2026-08-22T16:00:00.000Z';
|
||||
@@ -131,12 +134,51 @@ describe('managed Pi worker opener', () => {
|
||||
isDefault: true,
|
||||
createdAt: NOW,
|
||||
updatedAt: NOW,
|
||||
metadata: {
|
||||
worksSquareModelCapabilities: {
|
||||
'model-a': {
|
||||
reasoningEfforts: ['high'],
|
||||
reasoningCanDisable: false,
|
||||
webSearch: {
|
||||
schemaVersion: 1,
|
||||
adapter: 'bailian-chat-completions',
|
||||
supportsForcedSearch: true,
|
||||
sourceMode: 'inline-or-structured',
|
||||
billingAuthority: 'model-request',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const processOptions: PiWorkerProcessOptions[] = [];
|
||||
const processes: OpenerFakeProcess[] = [];
|
||||
const telemetry: PiRuntimeTelemetryEvent[] = [];
|
||||
const registry = new PiSessionRegistry({ projectStore });
|
||||
const extensionHost = new PiManagedExtensionHost();
|
||||
const devicePackageRoot = path.join(root, 'device-package');
|
||||
const deviceSkillPath = path.join(devicePackageRoot, 'skills', 'device-skill', 'SKILL.md');
|
||||
const deviceExtensionPath = path.join(devicePackageRoot, 'extensions', 'device-tools.ts');
|
||||
await mkdir(path.dirname(deviceSkillPath), { recursive: true });
|
||||
await mkdir(path.dirname(deviceExtensionPath), { recursive: true });
|
||||
await writeFile(deviceSkillPath, '---\nname: device-skill\n---\n', 'utf8');
|
||||
await writeFile(deviceExtensionPath, 'export default function () {}\n', 'utf8');
|
||||
const releaseDeviceWorkers: Array<ReturnType<typeof vi.fn>> = [];
|
||||
const devicePackageManager = {
|
||||
resolveEnabledResources: vi.fn(async () => ({
|
||||
generation: 7,
|
||||
packageIds: ['device-tools'],
|
||||
packageRefs: [{ packageId: 'device-tools', resolvedVersion: '1.2.3' }],
|
||||
skillEntries: [{
|
||||
id: 'device-skill', entryPath: 'skills/device-skill/SKILL.md', packageRoot: devicePackageRoot,
|
||||
}],
|
||||
extensionPaths: [deviceExtensionPath],
|
||||
})),
|
||||
registerActiveWorker: vi.fn(() => {
|
||||
const release = vi.fn(async () => undefined);
|
||||
releaseDeviceWorkers.push(release);
|
||||
return release;
|
||||
}),
|
||||
} as unknown as DevicePackageManager;
|
||||
const effectiveSnapshot: EffectivePluginSnapshot = Object.freeze({
|
||||
accountSessionId: 'account-a\u00001',
|
||||
projectId: 'project-a',
|
||||
@@ -157,6 +199,23 @@ describe('managed Pi worker opener', () => {
|
||||
effectiveSnapshot,
|
||||
})),
|
||||
} as unknown as CodingCapabilityRegistry;
|
||||
const modelToolDisposals: Array<ReturnType<typeof vi.fn>> = [];
|
||||
const modelToolRegistry = {
|
||||
registerWorker: vi.fn(() => {
|
||||
const dispose = vi.fn();
|
||||
modelToolDisposals.push(dispose);
|
||||
return {
|
||||
tools: [{
|
||||
name: 'web_search', label: 'Web search', description: 'Search with current model',
|
||||
capabilityId: 'model.web-search', operation: 'search', roles: ['parent'] as const,
|
||||
mutation: 'read' as const, projectWriteLease: false, permissions: [],
|
||||
inputSchema: { type: 'object' },
|
||||
}],
|
||||
dispose,
|
||||
};
|
||||
}),
|
||||
invoke: vi.fn(),
|
||||
} as unknown as ModelToolRegistryPort;
|
||||
const firstReleaseCleanup = deferred<void>();
|
||||
const releaseCleanups: Array<ReturnType<typeof vi.fn>> = [];
|
||||
const registerActivePluginReleases = vi.fn((_releaseIds: readonly string[]) => {
|
||||
@@ -178,6 +237,9 @@ describe('managed Pi worker opener', () => {
|
||||
bundledSkillsDir: path.resolve('resources/coding-skills'),
|
||||
extensionHost,
|
||||
capabilityRegistry,
|
||||
modelToolRegistry,
|
||||
devicePackageManager,
|
||||
devicePackageTools: DEVICE_PACKAGE_TOOL_DEFINITIONS,
|
||||
registerActivePluginReleases,
|
||||
loadProviderInput: async () => ({ accounts: [account], modelSummaries: [] }),
|
||||
resolveCredential: async () => 'provider-secret-value',
|
||||
@@ -228,7 +290,10 @@ describe('managed Pi worker opener', () => {
|
||||
expect(argv).toContain('--session-id');
|
||||
expect(argv).toContain('--extension');
|
||||
expect(argv).toContain('makelore-runtime-v5.mjs');
|
||||
expect(options.additionalArgs?.filter((argument) => argument === '--extension')).toHaveLength(1);
|
||||
expect(options.additionalArgs?.filter((argument) => argument === '--extension')).toHaveLength(2);
|
||||
expect(options.additionalArgs).toEqual(expect.arrayContaining([
|
||||
'--skill', deviceSkillPath, '--extension', deviceExtensionPath,
|
||||
]));
|
||||
expect(argv).not.toContain('PRIVATE MANAGED PROMPT');
|
||||
expect(argv).not.toContain('provider-secret-value');
|
||||
expect(Object.values(options.env ?? {})).toContain('provider-secret-value');
|
||||
@@ -237,13 +302,25 @@ describe('managed Pi worker opener', () => {
|
||||
expect(options.env?.MAKELORE_PI_CONTEXT_FILE).toContain('worker-');
|
||||
expect(options.tools?.filter((name) => name.startsWith('data_service_')))
|
||||
.toEqual(effectiveSnapshot.toolDefinitions.map(({ name }) => name));
|
||||
expect(options.tools).toContain('web_search');
|
||||
expect(options.tools).toEqual(expect.arrayContaining(
|
||||
DEVICE_PACKAGE_TOOL_DEFINITIONS.map(({ name }) => name),
|
||||
));
|
||||
const workerContext = JSON.parse(await readFile(
|
||||
options.env?.MAKELORE_PI_CONTEXT_FILE as string,
|
||||
'utf8',
|
||||
)) as Record<string, unknown>;
|
||||
expect(workerContext.effectivePluginSnapshot).toEqual(effectiveSnapshot);
|
||||
expect(workerContext.allowedToolNames)
|
||||
.toEqual(effectiveSnapshot.toolDefinitions.map(({ name }) => name));
|
||||
.toEqual([
|
||||
...effectiveSnapshot.toolDefinitions.map(({ name }) => name),
|
||||
'web_search',
|
||||
...DEVICE_PACKAGE_TOOL_DEFINITIONS.map(({ name }) => name),
|
||||
]);
|
||||
expect(workerContext).toMatchObject({
|
||||
devicePackageGeneration: 7,
|
||||
devicePackageIds: ['device-tools'],
|
||||
});
|
||||
}
|
||||
const modelsFile = path.join(userDataDir, 'coding-runtime', 'pi', 'config', 'models.json');
|
||||
expect(await readFile(modelsFile, 'utf8')).not.toContain('provider-secret-value');
|
||||
@@ -275,6 +352,10 @@ describe('managed Pi worker opener', () => {
|
||||
await restarted.worker.stop('test_injection');
|
||||
expect(releaseCleanups).toHaveLength(3);
|
||||
expect(releaseCleanups.every((cleanup) => cleanup.mock.calls.length === 1)).toBe(true);
|
||||
expect(modelToolDisposals).toHaveLength(3);
|
||||
expect(modelToolDisposals.every((dispose) => dispose.mock.calls.length === 1)).toBe(true);
|
||||
expect(releaseDeviceWorkers).toHaveLength(3);
|
||||
expect(releaseDeviceWorkers.every((release) => release.mock.calls.length === 1)).toBe(true);
|
||||
await extensionHost.close();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user