Add Prettier and ESLint tooling (Refs #77)
This commit is contained in:
@@ -6,18 +6,40 @@ import { vi } from 'vitest';
|
||||
export async function mockAgentFiles() {
|
||||
const backend = await import('../../src/lib/server/backends/native.js');
|
||||
const { serverDir } = await import('../../src/lib/server/config.js');
|
||||
return vi.spyOn(backend, 'nativeRequest').mockImplementation(async (instance, kind, payload = {}) => {
|
||||
const path = join(serverDir(instance.server), String(payload.path ?? '.'));
|
||||
let result: unknown;
|
||||
if (kind === 'files.read') {
|
||||
const content = await fs.readFile(path).catch((error: NodeJS.ErrnoException) => { if (error.code === 'ENOENT') return null; throw error; });
|
||||
result = { contentBase64: content?.toString('base64') ?? null };
|
||||
} else if (kind === 'files.stat') {
|
||||
const stat = await fs.stat(path).catch((error: NodeJS.ErrnoException) => { if (error.code === 'ENOENT') return null; throw error; });
|
||||
result = stat ? { exists: true, size: stat.size, mtime: stat.mtime.toISOString(), isDirectory: stat.isDirectory(), isFile: stat.isFile() } : null;
|
||||
} else if (kind === 'files.list') {
|
||||
result = { entries: (await fs.readdir(path, { withFileTypes: true })).map(entry => ({ name: entry.name, isDirectory: entry.isDirectory(), isFile: entry.isFile() })) };
|
||||
} else throw new Error(`Unexpected agent command: ${kind}`);
|
||||
return result as never;
|
||||
});
|
||||
return vi
|
||||
.spyOn(backend, 'nativeRequest')
|
||||
.mockImplementation(async (instance, kind, payload = {}) => {
|
||||
const path = join(serverDir(instance.server), String(payload.path ?? '.'));
|
||||
let result: unknown;
|
||||
if (kind === 'files.read') {
|
||||
const content = await fs.readFile(path).catch((error: NodeJS.ErrnoException) => {
|
||||
if (error.code === 'ENOENT') return null;
|
||||
throw error;
|
||||
});
|
||||
result = { contentBase64: content?.toString('base64') ?? null };
|
||||
} else if (kind === 'files.stat') {
|
||||
const stat = await fs.stat(path).catch((error: NodeJS.ErrnoException) => {
|
||||
if (error.code === 'ENOENT') return null;
|
||||
throw error;
|
||||
});
|
||||
result = stat
|
||||
? {
|
||||
exists: true,
|
||||
size: stat.size,
|
||||
mtime: stat.mtime.toISOString(),
|
||||
isDirectory: stat.isDirectory(),
|
||||
isFile: stat.isFile()
|
||||
}
|
||||
: null;
|
||||
} else if (kind === 'files.list') {
|
||||
result = {
|
||||
entries: (await fs.readdir(path, { withFileTypes: true })).map((entry) => ({
|
||||
name: entry.name,
|
||||
isDirectory: entry.isDirectory(),
|
||||
isFile: entry.isFile()
|
||||
}))
|
||||
};
|
||||
} else throw new Error(`Unexpected agent command: ${kind}`);
|
||||
return result as never;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user