wuying-agentbay-sdk 0.1.0 → 0.3.3
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/README.md +124 -61
- package/dist/index.cjs +7848 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +3174 -0
- package/dist/index.d.ts +3174 -0
- package/dist/index.mjs +7864 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +86 -48
- package/dist/src/adb/adb.d.ts +0 -20
- package/dist/src/adb/adb.js +0 -57
- package/dist/src/adb/index.d.ts +0 -1
- package/dist/src/adb/index.js +0 -17
- package/dist/src/agent-bay.d.ts +0 -68
- package/dist/src/agent-bay.js +0 -213
- package/dist/src/api/client.d.ts +0 -191
- package/dist/src/api/client.js +0 -629
- package/dist/src/api/index.d.ts +0 -4
- package/dist/src/api/index.js +0 -26
- package/dist/src/api/models/CallMcpToolRequest.d.ts +0 -21
- package/dist/src/api/models/CallMcpToolRequest.js +0 -71
- package/dist/src/api/models/CallMcpToolResponse.d.ts +0 -19
- package/dist/src/api/models/CallMcpToolResponse.js +0 -68
- package/dist/src/api/models/CallMcpToolResponseBody.d.ts +0 -19
- package/dist/src/api/models/CallMcpToolResponseBody.js +0 -67
- package/dist/src/api/models/CreateMcpSessionRequest.d.ts +0 -19
- package/dist/src/api/models/CreateMcpSessionRequest.js +0 -67
- package/dist/src/api/models/CreateMcpSessionResponse.d.ts +0 -19
- package/dist/src/api/models/CreateMcpSessionResponse.js +0 -68
- package/dist/src/api/models/CreateMcpSessionResponseBody.d.ts +0 -20
- package/dist/src/api/models/CreateMcpSessionResponseBody.js +0 -71
- package/dist/src/api/models/CreateMcpSessionResponseBodyData.d.ts +0 -19
- package/dist/src/api/models/CreateMcpSessionResponseBodyData.js +0 -67
- package/dist/src/api/models/DeleteContextRequest.d.ts +0 -15
- package/dist/src/api/models/DeleteContextRequest.js +0 -59
- package/dist/src/api/models/DeleteContextResponse.d.ts +0 -19
- package/dist/src/api/models/DeleteContextResponse.js +0 -68
- package/dist/src/api/models/DeleteContextResponseBody.d.ts +0 -18
- package/dist/src/api/models/DeleteContextResponseBody.js +0 -65
- package/dist/src/api/models/GetContextRequest.d.ts +0 -16
- package/dist/src/api/models/GetContextRequest.js +0 -61
- package/dist/src/api/models/GetContextResponse.d.ts +0 -19
- package/dist/src/api/models/GetContextResponse.js +0 -68
- package/dist/src/api/models/GetContextResponseBody.d.ts +0 -20
- package/dist/src/api/models/GetContextResponseBody.js +0 -71
- package/dist/src/api/models/GetContextResponseBodyData.d.ts +0 -19
- package/dist/src/api/models/GetContextResponseBodyData.js +0 -67
- package/dist/src/api/models/GetLabelRequest.d.ts +0 -17
- package/dist/src/api/models/GetLabelRequest.js +0 -63
- package/dist/src/api/models/GetLabelResponse.d.ts +0 -19
- package/dist/src/api/models/GetLabelResponse.js +0 -68
- package/dist/src/api/models/GetLabelResponseBody.d.ts +0 -23
- package/dist/src/api/models/GetLabelResponseBody.js +0 -77
- package/dist/src/api/models/GetLabelResponseBodyData.d.ts +0 -14
- package/dist/src/api/models/GetLabelResponseBodyData.js +0 -57
- package/dist/src/api/models/GetLinkRequest.d.ts +0 -15
- package/dist/src/api/models/GetLinkRequest.js +0 -59
- package/dist/src/api/models/GetLinkResponse.d.ts +0 -19
- package/dist/src/api/models/GetLinkResponse.js +0 -68
- package/dist/src/api/models/GetLinkResponseBody.d.ts +0 -19
- package/dist/src/api/models/GetLinkResponseBody.js +0 -67
- package/dist/src/api/models/GetMcpResourceRequest.d.ts +0 -15
- package/dist/src/api/models/GetMcpResourceRequest.js +0 -59
- package/dist/src/api/models/GetMcpResourceResponse.d.ts +0 -19
- package/dist/src/api/models/GetMcpResourceResponse.js +0 -68
- package/dist/src/api/models/GetMcpResourceResponseBody.d.ts +0 -20
- package/dist/src/api/models/GetMcpResourceResponseBody.js +0 -71
- package/dist/src/api/models/GetMcpResourceResponseBodyData.d.ts +0 -17
- package/dist/src/api/models/GetMcpResourceResponseBodyData.js +0 -65
- package/dist/src/api/models/GetMcpResourceResponseBodyDataDesktopInfo.d.ts +0 -18
- package/dist/src/api/models/GetMcpResourceResponseBodyDataDesktopInfo.js +0 -65
- package/dist/src/api/models/ListContextsRequest.d.ts +0 -16
- package/dist/src/api/models/ListContextsRequest.js +0 -61
- package/dist/src/api/models/ListContextsResponse.d.ts +0 -19
- package/dist/src/api/models/ListContextsResponse.js +0 -68
- package/dist/src/api/models/ListContextsResponseBody.d.ts +0 -23
- package/dist/src/api/models/ListContextsResponseBody.js +0 -77
- package/dist/src/api/models/ListContextsResponseBodyData.d.ts +0 -19
- package/dist/src/api/models/ListContextsResponseBodyData.js +0 -67
- package/dist/src/api/models/ListSessionRequest.d.ts +0 -17
- package/dist/src/api/models/ListSessionRequest.js +0 -63
- package/dist/src/api/models/ListSessionResponse.d.ts +0 -19
- package/dist/src/api/models/ListSessionResponse.js +0 -68
- package/dist/src/api/models/ListSessionResponseBody.d.ts +0 -23
- package/dist/src/api/models/ListSessionResponseBody.js +0 -77
- package/dist/src/api/models/ListSessionResponseBodyData.d.ts +0 -14
- package/dist/src/api/models/ListSessionResponseBodyData.js +0 -57
- package/dist/src/api/models/ModifyContextRequest.d.ts +0 -16
- package/dist/src/api/models/ModifyContextRequest.js +0 -61
- package/dist/src/api/models/ModifyContextResponse.d.ts +0 -19
- package/dist/src/api/models/ModifyContextResponse.js +0 -68
- package/dist/src/api/models/ModifyContextResponseBody.d.ts +0 -18
- package/dist/src/api/models/ModifyContextResponseBody.js +0 -65
- package/dist/src/api/models/ReleaseMcpSessionRequest.d.ts +0 -15
- package/dist/src/api/models/ReleaseMcpSessionRequest.js +0 -59
- package/dist/src/api/models/ReleaseMcpSessionResponse.d.ts +0 -19
- package/dist/src/api/models/ReleaseMcpSessionResponse.js +0 -68
- package/dist/src/api/models/ReleaseMcpSessionResponseBody.d.ts +0 -18
- package/dist/src/api/models/ReleaseMcpSessionResponseBody.js +0 -65
- package/dist/src/api/models/SetLabelRequest.d.ts +0 -16
- package/dist/src/api/models/SetLabelRequest.js +0 -61
- package/dist/src/api/models/SetLabelResponse.d.ts +0 -19
- package/dist/src/api/models/SetLabelResponse.js +0 -68
- package/dist/src/api/models/SetLabelResponseBody.d.ts +0 -18
- package/dist/src/api/models/SetLabelResponseBody.js +0 -65
- package/dist/src/api/models/model.d.ts +0 -43
- package/dist/src/api/models/model.js +0 -89
- package/dist/src/application/application.d.ts +0 -88
- package/dist/src/application/application.js +0 -172
- package/dist/src/application/index.d.ts +0 -1
- package/dist/src/application/index.js +0 -17
- package/dist/src/command/command.d.ts +0 -43
- package/dist/src/command/command.js +0 -120
- package/dist/src/command/index.d.ts +0 -1
- package/dist/src/command/index.js +0 -17
- package/dist/src/config.d.ts +0 -15
- package/dist/src/config.js +0 -114
- package/dist/src/context.d.ts +0 -87
- package/dist/src/context.js +0 -208
- package/dist/src/exceptions.d.ts +0 -30
- package/dist/src/exceptions.js +0 -58
- package/dist/src/filesystem/filesystem.d.ts +0 -109
- package/dist/src/filesystem/filesystem.js +0 -245
- package/dist/src/filesystem/index.d.ts +0 -1
- package/dist/src/filesystem/index.js +0 -17
- package/dist/src/index.d.ts +0 -10
- package/dist/src/index.js +0 -32
- package/dist/src/oss/index.d.ts +0 -1
- package/dist/src/oss/index.js +0 -5
- package/dist/src/oss/oss.d.ts +0 -80
- package/dist/src/oss/oss.js +0 -233
- package/dist/src/session.d.ts +0 -99
- package/dist/src/session.js +0 -226
- package/dist/src/ui/index.d.ts +0 -1
- package/dist/src/ui/index.js +0 -17
- package/dist/src/ui/ui.d.ts +0 -95
- package/dist/src/ui/ui.js +0 -206
- package/dist/src/utils/logger.d.ts +0 -15
- package/dist/src/utils/logger.js +0 -48
- package/dist/src/window/index.d.ts +0 -1
- package/dist/src/window/index.js +0 -17
- package/dist/src/window/window.d.ts +0 -109
- package/dist/src/window/window.js +0 -220
- package/dist/tests/agent-bay.test.d.ts +0 -1
- package/dist/tests/agent-bay.test.js +0 -366
- package/dist/tests/integration/context-persistence.test.d.ts +0 -1
- package/dist/tests/integration/context-persistence.test.js +0 -226
- package/dist/tests/integration/context-session.test.d.ts +0 -1
- package/dist/tests/integration/context-session.test.js +0 -223
- package/dist/tests/integration/window-operations.test.d.ts +0 -1
- package/dist/tests/integration/window-operations.test.js +0 -228
- package/dist/tests/unit/adb.test.d.ts +0 -1
- package/dist/tests/unit/adb.test.js +0 -60
- package/dist/tests/unit/agent-bay.test.d.ts +0 -1
- package/dist/tests/unit/agent-bay.test.js +0 -182
- package/dist/tests/unit/application.test.d.ts +0 -1
- package/dist/tests/unit/application.test.js +0 -260
- package/dist/tests/unit/command.test.d.ts +0 -1
- package/dist/tests/unit/command.test.js +0 -252
- package/dist/tests/unit/context.test.d.ts +0 -1
- package/dist/tests/unit/context.test.js +0 -199
- package/dist/tests/unit/filesystem.test.d.ts +0 -1
- package/dist/tests/unit/filesystem.test.js +0 -493
- package/dist/tests/unit/oss.test.d.ts +0 -1
- package/dist/tests/unit/oss.test.js +0 -243
- package/dist/tests/unit/session-labels.test.d.ts +0 -1
- package/dist/tests/unit/session-labels.test.js +0 -138
- package/dist/tests/unit/session-params.test.d.ts +0 -1
- package/dist/tests/unit/session-params.test.js +0 -78
- package/dist/tests/unit/session.test.d.ts +0 -1
- package/dist/tests/unit/session.test.js +0 -204
- package/dist/tests/unit/ui.test.d.ts +0 -1
- package/dist/tests/unit/ui.test.js +0 -158
- package/dist/tests/unit/window.test.d.ts +0 -1
- package/dist/tests/unit/window.test.js +0 -331
- package/dist/tests/utils/test-helpers.d.ts +0 -35
- package/dist/tests/utils/test-helpers.js +0 -79
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const src_1 = require("../../src");
|
|
4
|
-
const test_helpers_1 = require("../utils/test-helpers");
|
|
5
|
-
const logger_1 = require("../../src/utils/logger");
|
|
6
|
-
// Define test path prefix based on platform
|
|
7
|
-
const TestPathPrefix = '/tmp';
|
|
8
|
-
// Helper function to extract file data from content array
|
|
9
|
-
function extractFileContent(content) {
|
|
10
|
-
if (!Array.isArray(content) || content.length === 0) {
|
|
11
|
-
return '';
|
|
12
|
-
}
|
|
13
|
-
// Concatenate all text fields from content items
|
|
14
|
-
let fullText = '';
|
|
15
|
-
for (const item of content) {
|
|
16
|
-
if (item && typeof item === 'object' && typeof item.text === 'string') {
|
|
17
|
-
fullText += item.text;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
return fullText;
|
|
21
|
-
}
|
|
22
|
-
// Helper function to parse directory entries from content array
|
|
23
|
-
function parseDirectoryContent(content) {
|
|
24
|
-
if (!Array.isArray(content) || content.length === 0) {
|
|
25
|
-
return [];
|
|
26
|
-
}
|
|
27
|
-
// Try to extract and parse text from the first content item
|
|
28
|
-
const item = content[0];
|
|
29
|
-
if (item && typeof item === 'object' && item.text && typeof item.text === 'string') {
|
|
30
|
-
try {
|
|
31
|
-
return JSON.parse(item.text);
|
|
32
|
-
}
|
|
33
|
-
catch (e) {
|
|
34
|
-
(0, logger_1.log)(`Warning: Failed to parse content text as JSON: ${e}`);
|
|
35
|
-
// Try to parse directory entries from text format
|
|
36
|
-
const entries = [];
|
|
37
|
-
const lines = item.text.split('\n');
|
|
38
|
-
for (const line of lines) {
|
|
39
|
-
const trimmedLine = line.trim();
|
|
40
|
-
if (trimmedLine === '')
|
|
41
|
-
continue;
|
|
42
|
-
const entry = {};
|
|
43
|
-
if (trimmedLine.startsWith('[DIR]')) {
|
|
44
|
-
entry.isDirectory = true;
|
|
45
|
-
entry.name = trimmedLine.substring('[DIR]'.length).trim();
|
|
46
|
-
}
|
|
47
|
-
else if (trimmedLine.startsWith('[FILE]')) {
|
|
48
|
-
entry.isDirectory = false;
|
|
49
|
-
entry.name = trimmedLine.substring('[FILE]'.length).trim();
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
entries.push(entry);
|
|
55
|
-
}
|
|
56
|
-
return entries;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return [];
|
|
60
|
-
}
|
|
61
|
-
// Helper function to check if content has error
|
|
62
|
-
function hasErrorInContent(content) {
|
|
63
|
-
if (!Array.isArray(content)) {
|
|
64
|
-
return true;
|
|
65
|
-
}
|
|
66
|
-
if (content.length === 0) {
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
// Check if first content item has error text
|
|
70
|
-
return content.some(item => item && typeof item === 'object' &&
|
|
71
|
-
item.text && typeof item.text === 'string' &&
|
|
72
|
-
(item.text.includes('error') || item.text.includes('Error')));
|
|
73
|
-
}
|
|
74
|
-
// Helper function to parse file info from content
|
|
75
|
-
function parseFileInfo(content) {
|
|
76
|
-
if (!Array.isArray(content) || content.length === 0) {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
// Try to extract and parse text from the first content item
|
|
80
|
-
const item = content[0];
|
|
81
|
-
if (item && typeof item === 'object' && item.text && typeof item.text === 'string') {
|
|
82
|
-
try {
|
|
83
|
-
return JSON.parse(item.text);
|
|
84
|
-
}
|
|
85
|
-
catch (e) {
|
|
86
|
-
(0, logger_1.log)(`Warning: Failed to parse file info text as JSON: ${e}`);
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
describe('FileSystem', () => {
|
|
93
|
-
let agentBay;
|
|
94
|
-
let session;
|
|
95
|
-
beforeEach(async () => {
|
|
96
|
-
const apiKey = (0, test_helpers_1.getTestApiKey)();
|
|
97
|
-
agentBay = new src_1.AgentBay({ apiKey });
|
|
98
|
-
// Create a session with linux_latest image
|
|
99
|
-
(0, logger_1.log)('Creating a new session for filesystem testing...');
|
|
100
|
-
const sessionParams = { imageId: 'linux_latest' };
|
|
101
|
-
session = await agentBay.create(sessionParams);
|
|
102
|
-
(0, logger_1.log)(`Session created with ID: ${session.sessionId}`);
|
|
103
|
-
});
|
|
104
|
-
afterEach(async () => {
|
|
105
|
-
// Clean up the session
|
|
106
|
-
(0, logger_1.log)('Cleaning up: Deleting the session...');
|
|
107
|
-
try {
|
|
108
|
-
if (session)
|
|
109
|
-
await agentBay.delete(session);
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
(0, logger_1.log)(`Warning: Error deleting session: ${error}`);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
describe('readFile', () => {
|
|
116
|
-
it.only('should read a file', async () => {
|
|
117
|
-
if (session.filesystem) {
|
|
118
|
-
(0, logger_1.log)('Reading file...');
|
|
119
|
-
try {
|
|
120
|
-
// Use a file that should exist on most systems
|
|
121
|
-
const filePath = '/etc/hosts';
|
|
122
|
-
const content = await session.filesystem.readFile(filePath);
|
|
123
|
-
(0, logger_1.log)(`ReadFile result: content='${content.substring(0, 100)}...'`);
|
|
124
|
-
// Check if response contains "tool not found"
|
|
125
|
-
expect((0, test_helpers_1.containsToolNotFound)(content)).toBe(false);
|
|
126
|
-
// Verify the content is not empty
|
|
127
|
-
expect(content.length).toBeGreaterThan(0);
|
|
128
|
-
(0, logger_1.log)('File read successful');
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
(0, logger_1.log)(`Note: File operation failed: ${error}`);
|
|
132
|
-
// Don't fail the test if filesystem operations are not supported
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
(0, logger_1.log)('Note: FileSystem interface is nil, skipping file test');
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
it.only('should handle file not found errors', async () => {
|
|
140
|
-
if (session.filesystem) {
|
|
141
|
-
(0, logger_1.log)('Reading non-existent file...');
|
|
142
|
-
try {
|
|
143
|
-
const nonExistentFile = '/path/to/non/existent/file';
|
|
144
|
-
const content = await session.filesystem.readFile(nonExistentFile);
|
|
145
|
-
(0, logger_1.log)(`ReadFile result for non-existent file: content='${content}'`);
|
|
146
|
-
// If we get here, the API might return an empty string or error message for non-existent files
|
|
147
|
-
// We're just checking that the promise resolves
|
|
148
|
-
expect(content).toBeDefined();
|
|
149
|
-
}
|
|
150
|
-
catch (error) {
|
|
151
|
-
// If the API rejects the promise, that's also an acceptable behavior for a non-existent file
|
|
152
|
-
(0, logger_1.log)(`Non-existent file read failed as expected: ${error}`);
|
|
153
|
-
expect(error).toBeDefined();
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
(0, logger_1.log)('Note: FileSystem interface is nil, skipping file not found test');
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
describe('writeFile', () => {
|
|
162
|
-
it.only('should write to a file', async () => {
|
|
163
|
-
// Check if filesystem exists and has a writeFile method
|
|
164
|
-
// Note: This is a conditional test as writeFile might not be implemented in all versions
|
|
165
|
-
if (session.filesystem && typeof session.filesystem.writeFile === 'function') {
|
|
166
|
-
(0, logger_1.log)('Writing to file...');
|
|
167
|
-
try {
|
|
168
|
-
// Use a temporary file path
|
|
169
|
-
const tempFile = `${TestPathPrefix}/agentbay-test-${Date.now()}.txt`;
|
|
170
|
-
const content = `Test content generated at ${new Date().toISOString()}`;
|
|
171
|
-
await session.filesystem.writeFile(tempFile, content);
|
|
172
|
-
(0, logger_1.log)(`WriteFile successful: ${tempFile}`);
|
|
173
|
-
// Verify by reading the file back
|
|
174
|
-
const readContent = await session.filesystem.readFile(tempFile);
|
|
175
|
-
(0, logger_1.log)(`ReadFile after write: content='${readContent}'`);
|
|
176
|
-
// Check if the content matches
|
|
177
|
-
expect(readContent).toBe(content);
|
|
178
|
-
(0, logger_1.log)('File write verified successfully');
|
|
179
|
-
// Clean up the temporary file
|
|
180
|
-
if (session.command) {
|
|
181
|
-
await session.command.executeCommand(`rm ${tempFile}`);
|
|
182
|
-
(0, logger_1.log)(`Temporary file deleted: ${tempFile}`);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
catch (error) {
|
|
186
|
-
(0, logger_1.log)(`Note: File write operation failed: ${error}`);
|
|
187
|
-
// Don't fail the test if filesystem operations are not supported
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
(0, logger_1.log)('Note: FileSystem writeFile method is not available, skipping file write test');
|
|
192
|
-
}
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
describe('createDirectory', () => {
|
|
196
|
-
it.only('should create a directory', async () => {
|
|
197
|
-
if (session.filesystem && typeof session.filesystem.createDirectory === 'function') {
|
|
198
|
-
(0, logger_1.log)('Creating directory...');
|
|
199
|
-
try {
|
|
200
|
-
const testDirPath = `${TestPathPrefix}/test_directory_${(0, test_helpers_1.randomString)()}`;
|
|
201
|
-
await session.filesystem.createDirectory(testDirPath);
|
|
202
|
-
(0, logger_1.log)(`CreateDirectory successful: ${testDirPath}`);
|
|
203
|
-
// Verify the directory was created by listing its parent directory
|
|
204
|
-
if (typeof session.filesystem.listDirectory === 'function') {
|
|
205
|
-
const entries = await session.filesystem.listDirectory(`${TestPathPrefix}/`);
|
|
206
|
-
(0, logger_1.log)(`ListDirectory result: entries count=${entries.length}`);
|
|
207
|
-
// Extract the directory name from the path
|
|
208
|
-
const dirName = testDirPath.split('/').pop();
|
|
209
|
-
// Check if the directory exists in the listing
|
|
210
|
-
let directoryFound = false;
|
|
211
|
-
for (const entry of entries) {
|
|
212
|
-
if (entry.name === dirName && entry.isDirectory) {
|
|
213
|
-
directoryFound = true;
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
expect(directoryFound).toBe(true);
|
|
218
|
-
(0, logger_1.log)('Directory verified in listing');
|
|
219
|
-
// Clean up the test directory
|
|
220
|
-
if (session.command) {
|
|
221
|
-
await session.command.executeCommand(`rmdir ${testDirPath}`);
|
|
222
|
-
(0, logger_1.log)(`Test directory deleted: ${testDirPath}`);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
(0, logger_1.log)('Note: ListDirectory method is not available, skipping directory verification');
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
catch (error) {
|
|
230
|
-
(0, logger_1.log)(`Note: Directory creation failed: ${error}`);
|
|
231
|
-
// Don't fail the test if filesystem operations are not supported
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
else {
|
|
235
|
-
(0, logger_1.log)('Note: FileSystem createDirectory method is not available, skipping directory test');
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
describe('editFile', () => {
|
|
240
|
-
it.only('should edit a file by replacing text', async () => {
|
|
241
|
-
if (session.filesystem && typeof session.filesystem.editFile === 'function') {
|
|
242
|
-
(0, logger_1.log)('Editing file...');
|
|
243
|
-
try {
|
|
244
|
-
// First create a file to edit
|
|
245
|
-
const testFilePath = `${TestPathPrefix}/test_edit_${(0, test_helpers_1.randomString)()}.txt`;
|
|
246
|
-
const initialContent = "This is the original content.\nLine to be replaced.\nThis is the final line.";
|
|
247
|
-
await session.filesystem.writeFile(testFilePath, initialContent);
|
|
248
|
-
(0, logger_1.log)(`Created file for editing: ${testFilePath}`);
|
|
249
|
-
// Now edit the file
|
|
250
|
-
const edits = [
|
|
251
|
-
{
|
|
252
|
-
oldText: "Line to be replaced.",
|
|
253
|
-
newText: "This line has been edited."
|
|
254
|
-
}
|
|
255
|
-
];
|
|
256
|
-
await session.filesystem.editFile(testFilePath, edits);
|
|
257
|
-
(0, logger_1.log)(`EditFile successful: ${testFilePath}`);
|
|
258
|
-
// Verify the file was edited correctly by reading it back
|
|
259
|
-
const content = await session.filesystem.readFile(testFilePath);
|
|
260
|
-
(0, logger_1.log)(`ReadFile after edit: content='${content}'`);
|
|
261
|
-
const expectedContent = "This is the original content.\nThis line has been edited.\nThis is the final line.";
|
|
262
|
-
expect(content).toBe(expectedContent);
|
|
263
|
-
(0, logger_1.log)('File edit verified successfully');
|
|
264
|
-
// Clean up the test file
|
|
265
|
-
if (session.command) {
|
|
266
|
-
await session.command.executeCommand(`rm ${testFilePath}`);
|
|
267
|
-
(0, logger_1.log)(`Test file deleted: ${testFilePath}`);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
catch (error) {
|
|
271
|
-
(0, logger_1.log)(`Note: File edit operation failed: ${error}`);
|
|
272
|
-
// Don't fail the test if filesystem operations are not supported
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
else {
|
|
276
|
-
(0, logger_1.log)('Note: FileSystem editFile method is not available, skipping file edit test');
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
describe('getFileInfo', () => {
|
|
281
|
-
it.only('should get file information', async () => {
|
|
282
|
-
if (session.filesystem && typeof session.filesystem.getFileInfo === 'function') {
|
|
283
|
-
(0, logger_1.log)('Getting file info...');
|
|
284
|
-
try {
|
|
285
|
-
// First create a file to get info for
|
|
286
|
-
const testFilePath = `${TestPathPrefix}/test_info_${(0, test_helpers_1.randomString)()}.txt`;
|
|
287
|
-
const testContent = "This is a test file for GetFileInfo.";
|
|
288
|
-
await session.filesystem.writeFile(testFilePath, testContent);
|
|
289
|
-
(0, logger_1.log)(`Created file for info test: ${testFilePath}`);
|
|
290
|
-
// Get file info
|
|
291
|
-
const infoContent = await session.filesystem.getFileInfo(testFilePath);
|
|
292
|
-
(0, logger_1.log)(`GetFileInfo result: infoContent=${JSON.stringify(infoContent)}`);
|
|
293
|
-
// Verify the file info contains expected fields
|
|
294
|
-
expect(infoContent.name).toBe(testFilePath.split('/').pop());
|
|
295
|
-
expect(typeof infoContent.size).toBe('number');
|
|
296
|
-
expect(infoContent.isDirectory).toBe(false);
|
|
297
|
-
expect(infoContent.isFile).toBe(true);
|
|
298
|
-
(0, logger_1.log)('File info verified successfully');
|
|
299
|
-
// Clean up the test file
|
|
300
|
-
if (session.command) {
|
|
301
|
-
await session.command.executeCommand(`rm ${testFilePath}`);
|
|
302
|
-
(0, logger_1.log)(`Test file deleted: ${testFilePath}`);
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
catch (error) {
|
|
306
|
-
(0, logger_1.log)(`Note: Get file info operation failed: ${error}`);
|
|
307
|
-
// Don't fail the test if filesystem operations are not supported
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
else {
|
|
311
|
-
(0, logger_1.log)('Note: FileSystem getFileInfo method is not available, skipping file info test');
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
});
|
|
315
|
-
describe('listDirectory', () => {
|
|
316
|
-
it.only('should list directory contents', async () => {
|
|
317
|
-
if (session.filesystem && typeof session.filesystem.listDirectory === 'function') {
|
|
318
|
-
(0, logger_1.log)('Listing directory...');
|
|
319
|
-
try {
|
|
320
|
-
const entries = await session.filesystem.listDirectory(`${TestPathPrefix}/`);
|
|
321
|
-
(0, logger_1.log)(`ListDirectory result: entries count=${entries.length}`);
|
|
322
|
-
// Verify the entries contain expected fields
|
|
323
|
-
if (entries.length > 0) {
|
|
324
|
-
const firstEntry = entries[0];
|
|
325
|
-
expect(typeof firstEntry.name).toBe('string');
|
|
326
|
-
expect(typeof firstEntry.isDirectory).toBe('boolean');
|
|
327
|
-
(0, logger_1.log)('Directory listing verified successfully');
|
|
328
|
-
}
|
|
329
|
-
else {
|
|
330
|
-
(0, logger_1.log)('Directory is empty, skipping entry verification');
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
catch (error) {
|
|
334
|
-
(0, logger_1.log)(`Note: List directory operation failed: ${error}`);
|
|
335
|
-
// Don't fail the test if filesystem operations are not supported
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
else {
|
|
339
|
-
(0, logger_1.log)('Note: FileSystem listDirectory method is not available, skipping directory listing test');
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
});
|
|
343
|
-
describe('moveFile', () => {
|
|
344
|
-
it.only('should move a file from source to destination', async () => {
|
|
345
|
-
if (session.filesystem && typeof session.filesystem.moveFile === 'function') {
|
|
346
|
-
(0, logger_1.log)('Moving file...');
|
|
347
|
-
try {
|
|
348
|
-
// First create a file to move
|
|
349
|
-
const sourceFilePath = `${TestPathPrefix}/test_source_${(0, test_helpers_1.randomString)()}.txt`;
|
|
350
|
-
const destFilePath = `${TestPathPrefix}/test_destination_${(0, test_helpers_1.randomString)()}.txt`;
|
|
351
|
-
const testContent = "This is a test file for MoveFile.";
|
|
352
|
-
await session.filesystem.writeFile(sourceFilePath, testContent);
|
|
353
|
-
(0, logger_1.log)(`Created file for move test: ${sourceFilePath}`);
|
|
354
|
-
// Move the file
|
|
355
|
-
await session.filesystem.moveFile(sourceFilePath, destFilePath);
|
|
356
|
-
(0, logger_1.log)(`MoveFile successful: ${sourceFilePath} -> ${destFilePath}`);
|
|
357
|
-
// Verify the file was moved correctly by reading it back
|
|
358
|
-
const content = await session.filesystem.readFile(destFilePath);
|
|
359
|
-
(0, logger_1.log)(`ReadFile after move: content='${content}'`);
|
|
360
|
-
expect(content).toBe(testContent);
|
|
361
|
-
(0, logger_1.log)('File move verified successfully');
|
|
362
|
-
// Verify the source file no longer exists
|
|
363
|
-
try {
|
|
364
|
-
await session.filesystem.getFileInfo(sourceFilePath);
|
|
365
|
-
// If we get here, the file still exists
|
|
366
|
-
(0, logger_1.log)('Source file still exists after move');
|
|
367
|
-
expect(false).toBe(true); // This should fail the test
|
|
368
|
-
}
|
|
369
|
-
catch (error) {
|
|
370
|
-
// The file should not exist, so any error here is acceptable
|
|
371
|
-
(0, logger_1.log)('Source file correctly no longer exists');
|
|
372
|
-
}
|
|
373
|
-
// Clean up the destination file
|
|
374
|
-
if (session.command) {
|
|
375
|
-
await session.command.executeCommand(`rm ${destFilePath}`);
|
|
376
|
-
(0, logger_1.log)(`Destination file deleted: ${destFilePath}`);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
catch (error) {
|
|
380
|
-
(0, logger_1.log)(`Note: File move operation failed: ${error}`);
|
|
381
|
-
// Don't fail the test if filesystem operations are not supported
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
else {
|
|
385
|
-
(0, logger_1.log)('Note: FileSystem moveFile method is not available, skipping file move test');
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
describe('readMultipleFiles', () => {
|
|
390
|
-
it.only('should read multiple files at once', async () => {
|
|
391
|
-
if (session.filesystem && typeof session.filesystem.readMultipleFiles === 'function') {
|
|
392
|
-
(0, logger_1.log)('Reading multiple files...');
|
|
393
|
-
try {
|
|
394
|
-
// First create some test files
|
|
395
|
-
const file1Content = "This is test file 1 content.";
|
|
396
|
-
const file2Content = "This is test file 2 content.";
|
|
397
|
-
const testFile1Path = `${TestPathPrefix}/test_file1_${(0, test_helpers_1.randomString)()}.txt`;
|
|
398
|
-
const testFile2Path = `${TestPathPrefix}/test_file2_${(0, test_helpers_1.randomString)()}.txt`;
|
|
399
|
-
await session.filesystem.writeFile(testFile1Path, file1Content);
|
|
400
|
-
(0, logger_1.log)(`Created test file 1: ${testFile1Path}`);
|
|
401
|
-
await session.filesystem.writeFile(testFile2Path, file2Content);
|
|
402
|
-
(0, logger_1.log)(`Created test file 2: ${testFile2Path}`);
|
|
403
|
-
// Read multiple files
|
|
404
|
-
const paths = [testFile1Path, testFile2Path];
|
|
405
|
-
const contents = await session.filesystem.readMultipleFiles(paths);
|
|
406
|
-
(0, logger_1.log)(`ReadMultipleFiles result: contents count=${Object.keys(contents).length}`);
|
|
407
|
-
// Verify the contents of each file
|
|
408
|
-
expect(contents[testFile1Path]).toBe(file1Content);
|
|
409
|
-
expect(contents[testFile2Path]).toBe(file2Content);
|
|
410
|
-
(0, logger_1.log)('Multiple files read verified successfully');
|
|
411
|
-
// Clean up the test files
|
|
412
|
-
if (session.command) {
|
|
413
|
-
await session.command.executeCommand(`rm ${testFile1Path} ${testFile2Path}`);
|
|
414
|
-
(0, logger_1.log)(`Test files deleted: ${testFile1Path}, ${testFile2Path}`);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
catch (error) {
|
|
418
|
-
(0, logger_1.log)(`Note: Read multiple files operation failed: ${error}`);
|
|
419
|
-
// Don't fail the test if filesystem operations are not supported
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
else {
|
|
423
|
-
(0, logger_1.log)('Note: FileSystem readMultipleFiles method is not available, skipping read multiple files test');
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
describe('searchFiles', () => {
|
|
428
|
-
it.only('should search for files matching a pattern', async () => {
|
|
429
|
-
if (session.filesystem && typeof session.filesystem.searchFiles === 'function') {
|
|
430
|
-
(0, logger_1.log)('Searching files...');
|
|
431
|
-
try {
|
|
432
|
-
// First create a subdirectory for testing
|
|
433
|
-
const testSubdirPath = `${TestPathPrefix}/search_test_dir_${(0, test_helpers_1.randomString)()}`;
|
|
434
|
-
await session.filesystem.createDirectory(testSubdirPath);
|
|
435
|
-
(0, logger_1.log)(`Created test subdirectory: ${testSubdirPath}`);
|
|
436
|
-
// Create test files with specific naming patterns
|
|
437
|
-
const file1Content = "This is test file 1 content.";
|
|
438
|
-
const file2Content = "This is test file 2 content.";
|
|
439
|
-
const file3Content = "This is test file 3 content.";
|
|
440
|
-
const searchPattern = "SEARCHABLE_PATTERN";
|
|
441
|
-
const searchFile1Path = `${testSubdirPath}/SEARCHABLE_PATTERN_file1.txt`;
|
|
442
|
-
const searchFile2Path = `${testSubdirPath}/regular_file2.txt`;
|
|
443
|
-
const searchFile3Path = `${testSubdirPath}/SEARCHABLE_PATTERN_file3.txt`;
|
|
444
|
-
await session.filesystem.writeFile(searchFile1Path, file1Content);
|
|
445
|
-
(0, logger_1.log)(`Created search test file 1: ${searchFile1Path}`);
|
|
446
|
-
await session.filesystem.writeFile(searchFile2Path, file2Content);
|
|
447
|
-
(0, logger_1.log)(`Created search test file 2: ${searchFile2Path}`);
|
|
448
|
-
await session.filesystem.writeFile(searchFile3Path, file3Content);
|
|
449
|
-
(0, logger_1.log)(`Created search test file 3: ${searchFile3Path}`);
|
|
450
|
-
// Search for files with names containing the pattern
|
|
451
|
-
const excludePatterns = ["ignored_pattern"];
|
|
452
|
-
const results = await session.filesystem.searchFiles(testSubdirPath, searchPattern, excludePatterns);
|
|
453
|
-
(0, logger_1.log)(`SearchFiles result: results count=${results.length}`);
|
|
454
|
-
// Verify we found the expected number of results (should be 2 files)
|
|
455
|
-
expect(results.length).toBe(2);
|
|
456
|
-
(0, logger_1.log)('Search found the expected number of results');
|
|
457
|
-
// Verify the search results contain the expected files
|
|
458
|
-
let foundFile1 = false;
|
|
459
|
-
let foundFile3 = false;
|
|
460
|
-
for (const result of results) {
|
|
461
|
-
const path = result.path;
|
|
462
|
-
if (!path)
|
|
463
|
-
continue;
|
|
464
|
-
// Normalize paths for comparison
|
|
465
|
-
const normalizedPath = path.replace(/\\/g, '/');
|
|
466
|
-
(0, logger_1.log)(`Comparing result path: ${normalizedPath} with expected paths: ${searchFile1Path} and ${searchFile3Path}`);
|
|
467
|
-
if (normalizedPath === searchFile1Path) {
|
|
468
|
-
foundFile1 = true;
|
|
469
|
-
}
|
|
470
|
-
else if (normalizedPath === searchFile3Path) {
|
|
471
|
-
foundFile3 = true;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
expect(foundFile1).toBe(true);
|
|
475
|
-
expect(foundFile3).toBe(true);
|
|
476
|
-
(0, logger_1.log)('Search results contain the expected files');
|
|
477
|
-
// Clean up the test files and directory
|
|
478
|
-
if (session.command) {
|
|
479
|
-
await session.command.executeCommand(`rm -rf ${testSubdirPath}`);
|
|
480
|
-
(0, logger_1.log)(`Test subdirectory and files deleted: ${testSubdirPath}`);
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
catch (error) {
|
|
484
|
-
(0, logger_1.log)(`Note: Search files operation failed: ${error}`);
|
|
485
|
-
// Don't fail the test if filesystem operations are not supported
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
(0, logger_1.log)('Note: FileSystem searchFiles method is not available, skipping search files test');
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
});
|
|
493
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|