Add external file open to plugin SDK

This commit is contained in:
2026-06-27 13:31:59 +08:00
parent cdc0b373d8
commit 3ff01460ac
14 changed files with 37 additions and 7 deletions
+6 -1
View File
@@ -23,6 +23,8 @@ describe('VerstakPluginAPI contract', () => {
expect(typeof api.files.createFolder).toBe('function');
expect(typeof api.files.move).toBe('function');
expect(typeof api.files.trash).toBe('function');
expect(typeof api.files.openExternal).toBe('function');
expect(typeof api.files.showInFolder).toBe('function');
expect(typeof api.workbench.openResource).toBe('function');
expect(typeof api.workbench.editResource).toBe('function');
expect(typeof api.sync.status).toBe('function');
@@ -36,6 +38,7 @@ describe('VerstakPluginAPI contract', () => {
expect(permissionEnum).toContain('files.read');
expect(permissionEnum).toContain('files.write');
expect(permissionEnum).toContain('files.delete');
expect(permissionEnum).toContain('files.openExternal');
expect(permissionEnum).toContain('workbench.open');
});
@@ -196,7 +199,7 @@ describe('VerstakPluginAPI contract', () => {
expect(received).toEqual(['first']);
});
test('files mock supports text write, read, list, move, and trash', async () => {
test('files mock supports text write, read, list, move, trash, and external open', async () => {
const api = createMockPluginAPI('files.plugin');
await api.files.createFolder('PlatformTest');
@@ -205,6 +208,8 @@ describe('VerstakPluginAPI contract', () => {
await expect(api.files.list('PlatformTest')).resolves.toEqual([
expect.objectContaining({ relativePath: 'PlatformTest/one.txt', type: 'file' }),
]);
await expect(api.files.openExternal('PlatformTest/one.txt')).resolves.toBeUndefined();
await expect(api.files.showInFolder('PlatformTest/one.txt')).resolves.toBeUndefined();
await api.files.move('PlatformTest/one.txt', 'PlatformTest/two.txt');
const trash = await api.files.trash('PlatformTest/two.txt');
+2
View File
@@ -111,6 +111,8 @@ export interface VerstakPluginAPI {
createFolder(relativePath: string): Promise<void>;
move(fromRelativePath: string, toRelativePath: string, options?: MovePathOptions): Promise<void>;
trash(relativePath: string): Promise<TrashResult>;
openExternal(relativePath: string): Promise<void>;
showInFolder(relativePath: string): Promise<void>;
};
workbench: {
+8
View File
@@ -203,6 +203,14 @@ export function createMockPluginAPI(pluginId = 'test.plugin'): VerstakPluginAPI
deletedAt: new Date().toISOString(),
};
}),
openExternal: vi.fn(async (relativePath: string) => {
const path = normalizePath(relativePath);
if (!files.has(path)) throw new Error(`not-found: ${path}`);
}),
showInFolder: vi.fn(async (relativePath: string) => {
const path = normalizePath(relativePath);
if (!files.has(path)) throw new Error(`not-found: ${path}`);
}),
},
workbench: {
openResource: vi.fn(async (request) => ({
+1
View File
@@ -69,6 +69,7 @@ export type Permission =
| 'files.read'
| 'files.write'
| 'files.delete'
| 'files.openExternal'
| 'workbench.open'
| 'storage.namespace'
| 'storage.migrations'