@lvce-editor/test-worker 14.20.0 → 15.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.d.ts CHANGED
@@ -86,6 +86,34 @@ export interface DroppedFileHandle {
86
86
  readonly id: number;
87
87
  }
88
88
 
89
+ export interface ToolCallItemBase<TArguments, TName extends string> {
90
+ readonly toolCall: {
91
+ readonly arguments: TArguments;
92
+ readonly name: TName;
93
+ };
94
+ }
95
+
96
+ export interface ToolCallItemReadFileArgs {
97
+ readonly uri: string;
98
+ }
99
+
100
+ export interface ToolCallItemWriteFileArgs {
101
+ readonly content: string;
102
+ readonly uri: string;
103
+ }
104
+
105
+ export interface ToolCallItemSearchFilesArgs {
106
+ readonly query: string;
107
+ }
108
+
109
+ export interface ToolCallItemTextSearchArgs {
110
+ readonly query: string;
111
+ }
112
+
113
+ export interface TextItem {
114
+ readonly text: string;
115
+ }
116
+
89
117
  export interface MockErrorResponse {
90
118
  readonly code: string;
91
119
  readonly error: string;
@@ -101,17 +129,6 @@ export interface MockOpenAiResponseOptions {
101
129
  readonly value: any;
102
130
  }
103
131
 
104
- export interface ToolCallItem {
105
- readonly toolCall: {
106
- readonly arguments: any;
107
- readonly name: "list_files";
108
- };
109
- }
110
-
111
- export interface TextItem {
112
- readonly text: string;
113
- }
114
-
115
132
  export interface ChatDebugEvent {
116
133
  readonly [key: string]: unknown;
117
134
  }
@@ -145,6 +162,11 @@ export interface Dirent {
145
162
  readonly type: number;
146
163
  }
147
164
 
165
+ export interface GitInvocation {
166
+ readonly command: readonly string[];
167
+ readonly cwd: string;
168
+ }
169
+
148
170
  export interface LayoutExpectation extends LayoutExpectationObject {
149
171
  readonly activeGroupIndex?: number;
150
172
  readonly direction?: LayoutDirection;
@@ -156,10 +178,26 @@ export interface SelectItem2Options {
156
178
  readonly label: string;
157
179
  }
158
180
 
181
+ export type EmptyObject = Record<string, never>;
182
+
183
+ export type ToolCallItemGetWorkspaceUri = ToolCallItemBase<EmptyObject, "getWorkspaceUri">;
184
+
185
+ export type ToolCallItemReadFile = ToolCallItemBase<ToolCallItemReadFileArgs, "read_file">;
186
+
187
+ export type ToolCallItemWriteFile = ToolCallItemBase<ToolCallItemWriteFileArgs, "write_file">;
188
+
189
+ export type ToolCallItemSearchFiles = ToolCallItemBase<ToolCallItemSearchFilesArgs, "search_files">;
190
+
191
+ export type ToolCallItemTextSearch = ToolCallItemBase<ToolCallItemTextSearchArgs, "text_search">;
192
+
193
+ export type ToolCallItem = ToolCallItemGetWorkspaceUri | ToolCallItemReadFile | ToolCallItemWriteFile | ToolCallItemSearchFiles | ToolCallItemTextSearch;
194
+
159
195
  export type MockRequestInput = ToolCallItem | TextItem;
160
196
 
161
197
  export type ChatDebugInputName = "closeDetails" | "eventCategoryFilter" | "filter" | "showEventStreamFinishedEvents" | "showInputEvents" | "showResponsePartEvents" | "timelineRangePreset" | "useDevtoolsLayout";
162
198
 
199
+ export type ChatDebugCategoryId = "tools" | "network";
200
+
163
201
  export type TokenRow = readonly string[];
164
202
 
165
203
  export type LayoutDirection = "horizontal" | "vertical" | number;
@@ -299,6 +337,7 @@ interface ChatDebug {
299
337
  readonly appendStoredEventForTest: (event: any) => Promise<void>;
300
338
  readonly closeDetails: () => Promise<void>;
301
339
  readonly handleClickRefresh: () => Promise<void>;
340
+ readonly handleEventCategoryFilter: (filter: ChatDebugCategoryId) => Promise<void>;
302
341
  readonly handleHeaderContextMenu: (x: number, y: number) => Promise<void>;
303
342
  readonly handleInput: (name: ChatDebugInputName, value: string, checked: boolean) => Promise<void>;
304
343
  readonly handlePreviewTextPointerDown: (x: number, y: number) => Promise<void>;
@@ -598,6 +637,7 @@ interface FileSystem {
598
637
  readonly readFile: (uri: string) => Promise<string>;
599
638
  readonly remove: (uri: string) => Promise<void>;
600
639
  readonly setFiles: (files: readonly FileItem[]) => Promise<void>;
640
+ readonly shouldHaveFolder: (uri: string) => Promise<void>;
601
641
  readonly writeFile: (uri: string, content: string) => Promise<void>;
602
642
  readonly writeJson: (uri: string, data: any) => Promise<void>;
603
643
  }
@@ -620,6 +660,22 @@ interface FindWidget {
620
660
  readonly toggleUseRegularExpression: () => Promise<void>;
621
661
  }
622
662
 
663
+ interface Git {
664
+ readonly add: (pathSpec: string) => Promise<void>;
665
+ readonly addRemote: (name: string, remoteUrl: string) => Promise<void>;
666
+ readonly branch: (name: string) => Promise<void>;
667
+ readonly checkout: (ref: string) => Promise<void>;
668
+ readonly clone: (repositoryUrl: string, cwd: string) => Promise<void>;
669
+ readonly commit: (message: string) => Promise<void>;
670
+ readonly fetch: (remote: string) => Promise<void>;
671
+ readonly init: () => Promise<void>;
672
+ readonly pull: (remote: string, branch: string) => Promise<void>;
673
+ readonly push: (remote: string, branch: string) => Promise<void>;
674
+ readonly setConfig: (key: string, value: string) => Promise<void>;
675
+ readonly shouldHaveInvocations: (invocations: readonly GitInvocation[]) => Promise<void>;
676
+ readonly status: () => Promise<unknown>;
677
+ }
678
+
623
679
  interface IconTheme {
624
680
  readonly setIconTheme: (id: string) => Promise<void>;
625
681
  }
@@ -929,6 +985,7 @@ export interface TestApi {
929
985
  readonly ExtensionSearch: ExtensionSearch
930
986
  readonly FileSystem: FileSystem
931
987
  readonly FindWidget: FindWidget
988
+ readonly Git: Git
932
989
  readonly IconTheme: IconTheme
933
990
  readonly IframeInspector: IframeInspector
934
991
  readonly KeyBindingsEditor: KeyBindingsEditor
@@ -1091,7 +1091,7 @@ const createMockRpc = ({
1091
1091
  };
1092
1092
 
1093
1093
  const rpcs = Object.create(null);
1094
- const set$5 = (id, rpc) => {
1094
+ const set$7 = (id, rpc) => {
1095
1095
  rpcs[id] = rpc;
1096
1096
  };
1097
1097
  const get$2 = id => {
@@ -1124,7 +1124,7 @@ const create = rpcId => {
1124
1124
  const mockRpc = createMockRpc({
1125
1125
  commandMap
1126
1126
  });
1127
- set$5(rpcId, mockRpc);
1127
+ set$7(rpcId, mockRpc);
1128
1128
  // @ts-ignore
1129
1129
  mockRpc[Symbol.dispose] = () => {
1130
1130
  remove$1(rpcId);
@@ -1133,7 +1133,7 @@ const create = rpcId => {
1133
1133
  return mockRpc;
1134
1134
  },
1135
1135
  set(rpc) {
1136
- set$5(rpcId, rpc);
1136
+ set$7(rpcId, rpc);
1137
1137
  }
1138
1138
  };
1139
1139
  };
@@ -1146,14 +1146,25 @@ const Web = 1;
1146
1146
  const Remote = 3;
1147
1147
 
1148
1148
  const EditorWorker = 99;
1149
+ const ExtensionHostWorker = 44;
1150
+ const ExtensionManagementWorker = 9006;
1149
1151
  const OpenerWorker = 4561;
1150
1152
  const RendererWorker = 1;
1151
1153
  const TestWorker = 9001;
1152
1154
 
1155
+ const {
1156
+ invoke: invoke$3,
1157
+ set: set$6
1158
+ } = create(EditorWorker);
1159
+
1160
+ const {
1161
+ set: set$5
1162
+ } = create(ExtensionHostWorker);
1163
+
1153
1164
  const {
1154
1165
  invoke: invoke$2,
1155
1166
  set: set$4
1156
- } = create(EditorWorker);
1167
+ } = create(ExtensionManagementWorker);
1157
1168
 
1158
1169
  const {
1159
1170
  invoke: invoke$1,
@@ -1176,14 +1187,44 @@ const sendMessagePortToOpenerWorker = async (port, rpcId) => {
1176
1187
  const readFile$1 = async uri => {
1177
1188
  return invoke('FileSystem.readFile', uri);
1178
1189
  };
1190
+ const sendMessagePortToExtensionHostWorker = async (port, rpcId = 0) => {
1191
+ const command = 'HandleMessagePort.handleMessagePort2';
1192
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', port, command, rpcId);
1193
+ };
1194
+ const sendMessagePortToExtensionManagementWorker = async (port, rpcId) => {
1195
+ const command = 'Extensions.handleMessagePort';
1196
+ await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionManagementWorker', port, command, rpcId);
1197
+ };
1179
1198
  const getPreference = async key => {
1180
1199
  return await invoke('Preferences.get', key);
1181
1200
  };
1182
1201
 
1183
- const send$1 = async port => {
1202
+ const send$3 = async port => {
1184
1203
  await sendMessagePortToEditorWorker(port, TestWorker);
1185
1204
  };
1186
1205
  const initializeEditorWorker = async () => {
1206
+ const rpc = await create$3({
1207
+ commandMap: {},
1208
+ send: send$3
1209
+ });
1210
+ set$6(rpc);
1211
+ };
1212
+
1213
+ const send$2 = async port => {
1214
+ await sendMessagePortToExtensionHostWorker(port, TestWorker);
1215
+ };
1216
+ const initializeExtensionHostWorker = async () => {
1217
+ const rpc = await create$3({
1218
+ commandMap: {},
1219
+ send: send$2
1220
+ });
1221
+ set$5(rpc);
1222
+ };
1223
+
1224
+ const send$1 = async port => {
1225
+ await sendMessagePortToExtensionManagementWorker(port, TestWorker);
1226
+ };
1227
+ const initializeExtensionManagementWorker = async () => {
1187
1228
  const rpc = await create$3({
1188
1229
  commandMap: {},
1189
1230
  send: send$1
@@ -2361,6 +2402,9 @@ const appendStoredEventForTest = async event => {
2361
2402
  const handleClickRefresh = async () => {
2362
2403
  await invoke('ChatDebug.handleClickRefresh');
2363
2404
  };
2405
+ const handleEventCategoryFilter = async filter => {
2406
+ await invoke('ChatDebug.handleEventCategoryFilter', filter);
2407
+ };
2364
2408
  const handleTableBodyContextMenu = async (x, y) => {
2365
2409
  await invoke('ChatDebug.handleTableBodyContextMenu', x, y);
2366
2410
  };
@@ -2369,6 +2413,7 @@ const ChatDebug = {
2369
2413
  appendStoredEventForTest,
2370
2414
  closeDetails,
2371
2415
  handleClickRefresh,
2416
+ handleEventCategoryFilter,
2372
2417
  handleHeaderContextMenu,
2373
2418
  handleInput: handleInput$7,
2374
2419
  handlePreviewTextPointerDown,
@@ -2760,7 +2805,7 @@ const areSelectionsEqual = (a, b) => {
2760
2805
  };
2761
2806
 
2762
2807
  const getEditorKey = async () => {
2763
- const keys = await invoke$2('Editor.getKeys');
2808
+ const keys = await invoke$3('Editor.getKeys');
2764
2809
  if (keys.length === 0) {
2765
2810
  throw new Error(`no editor found`);
2766
2811
  }
@@ -3026,11 +3071,11 @@ const growSelection = async () => {
3026
3071
  };
3027
3072
  const getSelections = async () => {
3028
3073
  const key = await getEditorKey();
3029
- return invoke$2('Editor.getSelections', key);
3074
+ return invoke$3('Editor.getSelections', key);
3030
3075
  };
3031
3076
  const shouldHaveText = async expectedText => {
3032
3077
  const key = await getEditorKey();
3033
- const text = await invoke$2('Editor.getText', key);
3078
+ const text = await invoke$3('Editor.getText', key);
3034
3079
  if (text !== expectedText) {
3035
3080
  throw new Error(`Expected editor to have text ${expectedText} but was ${text}`);
3036
3081
  }
@@ -3055,7 +3100,7 @@ const areTokensEqual = (actual, expected) => {
3055
3100
  };
3056
3101
  const shouldHaveTokens = async expectedTokens => {
3057
3102
  const key = await getEditorKey();
3058
- const text = await invoke$2('Editor.getTokens', key);
3103
+ const text = await invoke$3('Editor.getTokens', key);
3059
3104
  if (!areTokensEqual(text, expectedTokens)) {
3060
3105
  const stringifiedActual = JSON.stringify(text);
3061
3106
  const stringifiedExpected = JSON.stringify(expectedTokens);
@@ -3064,20 +3109,20 @@ const shouldHaveTokens = async expectedTokens => {
3064
3109
  };
3065
3110
  const shouldHaveSelections = async expectedSelections => {
3066
3111
  const key = await getEditorKey();
3067
- const selections = await invoke$2('Editor.getSelections', key);
3112
+ const selections = await invoke$3('Editor.getSelections', key);
3068
3113
  if (!areSelectionsEqual(selections, expectedSelections)) {
3069
3114
  throw new Error(`Expected editor to have selections ${expectedSelections} but was ${selections}`);
3070
3115
  }
3071
3116
  };
3072
3117
  const undo = async () => {
3073
- await invoke$2('Editor.undo');
3118
+ await invoke$3('Editor.undo');
3074
3119
  };
3075
3120
  const redo = async () => {
3076
- await invoke$2('Editor.redo');
3121
+ await invoke$3('Editor.redo');
3077
3122
  };
3078
3123
  const shouldHaveDiagnostics = async expectedDiagnostics => {
3079
3124
  const key = await getEditorKey();
3080
- const diagnostics = await invoke$2('Editor.getDiagnostics', key);
3125
+ const diagnostics = await invoke$3('Editor.getDiagnostics', key);
3081
3126
  if (!areDiagnosticsEqual(diagnostics, expectedDiagnostics)) {
3082
3127
  const stringifiedActual = JSON.stringify(diagnostics);
3083
3128
  const stringifiedExpected = JSON.stringify(expectedDiagnostics);
@@ -3430,6 +3475,7 @@ const Explorer = {
3430
3475
  const addWebExtension = async relativePath => {
3431
3476
  // TODO compute absolutePath
3432
3477
  const absolutePath = relativePath;
3478
+ await invoke$2('Extensions.addWebExtension', absolutePath);
3433
3479
  await invoke('ExtensionMeta.addWebExtension', absolutePath);
3434
3480
  };
3435
3481
  const addNodeExtension = async relativePath => {
@@ -3725,13 +3771,44 @@ const setFiles = async files => {
3725
3771
  const readDir = async uri => {
3726
3772
  return invoke('FileSystem.readDirWithFileTypes', uri);
3727
3773
  };
3774
+ const getParentUri = uri => {
3775
+ const url = new URL(uri);
3776
+ const pathSegments = url.pathname.split('/').filter(Boolean);
3777
+ pathSegments.pop();
3778
+ url.pathname = pathSegments.length === 0 ? '/' : `/${pathSegments.join('/')}`;
3779
+ return url.toString();
3780
+ };
3781
+ const getBaseName = uri => {
3782
+ const url = new URL(uri);
3783
+ const pathSegments = url.pathname.split('/').filter(Boolean);
3784
+ return pathSegments.at(-1) || '';
3785
+ };
3786
+ const shouldHaveFolder = async uri => {
3787
+ const parentUri = getParentUri(uri);
3788
+ const folderName = getBaseName(uri);
3789
+ const dirents = await readDir(parentUri);
3790
+ const matchingDirent = dirents.find(dirent => dirent.name === folderName);
3791
+ if (!matchingDirent) {
3792
+ throw new AssertionError(`expected filesystem to have folder "${uri}" but it was not found`);
3793
+ }
3794
+ if (matchingDirent.type !== Directory) {
3795
+ throw new AssertionError(`expected filesystem entry "${uri}" to be a folder but it was type ${matchingDirent.type}`);
3796
+ }
3797
+ };
3728
3798
  const remove = async uri => {
3729
3799
  await invoke('FileSystem.remove', uri);
3730
3800
  };
3801
+ const getTmpDirFileScheme = async () => {
3802
+ const tmpFolder = await invoke('PlatformPaths.getTmpDir');
3803
+ const tmpUri = tmpFolder.startsWith('file://') ? tmpFolder : `file://${tmpFolder}`;
3804
+ return `${tmpUri}/test-${Date.now()}`;
3805
+ };
3731
3806
  const getTmpDir = async ({
3732
3807
  scheme = Memfs
3733
3808
  } = {}) => {
3734
3809
  switch (scheme) {
3810
+ case 'file':
3811
+ return getTmpDirFileScheme();
3735
3812
  case Memfs:
3736
3813
  return 'memfs:///workspace';
3737
3814
  default:
@@ -3797,6 +3874,7 @@ const FileSystem = {
3797
3874
  readFile,
3798
3875
  remove,
3799
3876
  setFiles,
3877
+ shouldHaveFolder,
3800
3878
  writeFile,
3801
3879
  writeJson
3802
3880
  };
@@ -3865,6 +3943,63 @@ const FindWidget = {
3865
3943
  toggleUseRegularExpression: toggleUseRegularExpression$1
3866
3944
  };
3867
3945
 
3946
+ const init = async () => {
3947
+ // await RendererWorker.invoke('ExtensionHostManagement.activateByEvent', 'onSourceControl:')
3948
+ await invoke('ExtensionHost.executeCommand', 'git.init');
3949
+ };
3950
+ const clone = async (repositoryUrl, cwd) => {
3951
+ await invoke('ExtensionHost.executeCommand', 'Git.clone', repositoryUrl, cwd);
3952
+ };
3953
+ const add = async pathSpec => {
3954
+ await invoke('ExtensionHost.executeCommand', 'Git.add', pathSpec);
3955
+ };
3956
+ const commit = async message => {
3957
+ await invoke('ExtensionHost.executeCommand', 'Git.commit', message);
3958
+ };
3959
+ const push$1 = async (remote, branch) => {
3960
+ await invoke('ExtensionHost.executeCommand', 'Git.push', remote, branch);
3961
+ };
3962
+ const pull = async (remote, branch) => {
3963
+ await invoke('ExtensionHost.executeCommand', 'Git.pull', remote, branch);
3964
+ };
3965
+ const fetch$1 = async remote => {
3966
+ await invoke('ExtensionHost.executeCommand', 'Git.fetch', remote);
3967
+ };
3968
+ const checkout = async ref => {
3969
+ await invoke('ExtensionHost.executeCommand', 'Git.checkout', ref);
3970
+ };
3971
+ const branch = async name => {
3972
+ await invoke('ExtensionHost.executeCommand', 'Git.branch', name);
3973
+ };
3974
+ const status = async () => {
3975
+ return invoke('ExtensionHost.executeCommand', 'Git.status');
3976
+ };
3977
+ const addRemote = async (name, remoteUrl) => {
3978
+ await invoke('ExtensionHost.executeCommand', 'Git.addRemote', name, remoteUrl);
3979
+ };
3980
+ const setConfig = async (key, value) => {
3981
+ await invoke('ExtensionHost.executeCommand', 'Git.setConfig', key, value);
3982
+ };
3983
+ const shouldHaveInvocations = async invocations => {
3984
+ // TODO
3985
+ };
3986
+
3987
+ const Git = {
3988
+ add,
3989
+ addRemote,
3990
+ branch,
3991
+ checkout,
3992
+ clone,
3993
+ commit,
3994
+ fetch: fetch$1,
3995
+ init,
3996
+ pull,
3997
+ push: push$1,
3998
+ setConfig,
3999
+ shouldHaveInvocations,
4000
+ status
4001
+ };
4002
+
3868
4003
  const setIconTheme = async id => {
3869
4004
  await invoke('IconTheme.setIconTheme', id);
3870
4005
  };
@@ -4907,6 +5042,7 @@ const createApi = (platform, assetDir) => {
4907
5042
  FindWidget,
4908
5043
  getTmpDir: getTmpDir$1,
4909
5044
  // TODO maybe deprecate this or move to file system
5045
+ Git,
4910
5046
  IconTheme,
4911
5047
  IframeInspector,
4912
5048
  KeyBindingsEditor,
@@ -5581,7 +5717,7 @@ const initializeRendererWorker = async () => {
5581
5717
  };
5582
5718
 
5583
5719
  const listen = async () => {
5584
- await Promise.all([initializeRendererWorker(), initializeEditorWorker(), initializeOpenerWorker()]);
5720
+ await Promise.all([initializeRendererWorker(), initializeEditorWorker(), initializeOpenerWorker(), initializeExtensionManagementWorker(), initializeExtensionHostWorker()]);
5585
5721
  };
5586
5722
 
5587
5723
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/test-worker",
3
- "version": "14.20.0",
3
+ "version": "15.0.0",
4
4
  "description": "Test Worker",
5
5
  "repository": {
6
6
  "type": "git",