feat(coding): add model tools and device packages
This commit is contained in:
1 parent
841273b433
commit
664b8823a0
60 files changed
+3847
-2068
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { parseDevicePackageIndex } from '@/lib/device-packages';
|
||||
import { createDevicePackageStore } from '@/stores/device-packages';
|
||||
|
||||
const installed = {
|
||||
schemaVersion: 1 as const,
|
||||
packageId: 'pi-web-search',
|
||||
displayName: 'Pi Web Search',
|
||||
resolvedVersion: '1.2.3',
|
||||
source: { kind: 'npm' as const, requested: 'npm:pi-web-search', resolved: 'npm:pi-web-search@1.2.3' },
|
||||
kind: 'mixed' as const,
|
||||
skillEntries: [{ id: 'pi-web-search', entryPath: 'skills/pi-web-search/SKILL.md' }],
|
||||
extensionEntries: ['extensions/web-search.ts'],
|
||||
enabled: true,
|
||||
confirmedExecutableCode: true,
|
||||
installedAt: '2026-09-02T00:00:00.000Z',
|
||||
};
|
||||
|
||||
describe('device package Renderer boundary', () => {
|
||||
it('parses only the bounded device package projection', () => {
|
||||
expect(parseDevicePackageIndex({
|
||||
schemaVersion: 1, generation: 3, packages: [installed],
|
||||
})).toEqual({ schemaVersion: 1, generation: 3, packages: [installed] });
|
||||
expect(() => parseDevicePackageIndex({
|
||||
schemaVersion: 1, generation: 3, packages: [{ ...installed, packageRoot: 'C:\\private' }],
|
||||
})).toThrow('device package');
|
||||
});
|
||||
|
||||
it('does not let an older refresh overwrite a later device mutation', async () => {
|
||||
let resolveRead!: (value: unknown) => void;
|
||||
const read = vi.fn(() => new Promise<unknown>((resolve) => { resolveRead = resolve; }));
|
||||
const setEnabled = vi.fn().mockResolvedValue({
|
||||
schemaVersion: 1, generation: 4, packages: [{ ...installed, enabled: false }],
|
||||
});
|
||||
const store = createDevicePackageStore({
|
||||
read: async () => parseDevicePackageIndex(await read()),
|
||||
setEnabled: async () => parseDevicePackageIndex(await setEnabled()),
|
||||
uninstall: vi.fn(),
|
||||
});
|
||||
const staleRead = store.getState().load();
|
||||
await store.getState().setEnabled('pi-web-search', false);
|
||||
resolveRead({ schemaVersion: 1, generation: 3, packages: [installed] });
|
||||
await staleRead;
|
||||
|
||||
expect(store.getState().index).toMatchObject({
|
||||
generation: 4, packages: [{ packageId: 'pi-web-search', enabled: false }],
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user