mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-29 13:03:42 +01:00
fix tests
This commit is contained in:
@@ -8,6 +8,7 @@ import { DisposableStore, toDisposable } from '../../../../base/common/lifecycle
|
||||
import { URI } from '../../../../base/common/uri.js';
|
||||
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
|
||||
import { NullLogService } from '../../../log/common/log.js';
|
||||
import { FileService } from '../../../files/common/fileService.js';
|
||||
import { AgentSession } from '../../common/agentService.js';
|
||||
import { IActionEnvelope } from '../../common/state/sessionActions.js';
|
||||
import { AgentService } from '../../node/agentService.js';
|
||||
@@ -20,7 +21,7 @@ suite('AgentService (node dispatcher)', () => {
|
||||
let copilotAgent: MockAgent;
|
||||
|
||||
setup(() => {
|
||||
service = disposables.add(new AgentService(new NullLogService()));
|
||||
service = disposables.add(new AgentService(new NullLogService(), disposables.add(new FileService(new NullLogService()))));
|
||||
copilotAgent = new MockAgent('copilot');
|
||||
disposables.add(toDisposable(() => copilotAgent.dispose()));
|
||||
});
|
||||
|
||||
@@ -4,10 +4,14 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { VSBuffer } from '../../../../base/common/buffer.js';
|
||||
import { DisposableStore, toDisposable } from '../../../../base/common/lifecycle.js';
|
||||
import { Schemas } from '../../../../base/common/network.js';
|
||||
import { observableValue } from '../../../../base/common/observable.js';
|
||||
import { URI } from '../../../../base/common/uri.js';
|
||||
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
|
||||
import { FileService } from '../../../files/common/fileService.js';
|
||||
import { InMemoryFileSystemProvider } from '../../../files/common/inMemoryFilesystemProvider.js';
|
||||
import { NullLogService } from '../../../log/common/log.js';
|
||||
import { AgentSession, IAgent } from '../../common/agentService.js';
|
||||
import { IActionEnvelope, ISessionAction } from '../../common/state/sessionActions.js';
|
||||
@@ -15,13 +19,13 @@ import { SessionStatus } from '../../common/state/sessionState.js';
|
||||
import { AgentSideEffects } from '../../node/agentSideEffects.js';
|
||||
import { SessionStateManager } from '../../node/sessionStateManager.js';
|
||||
import { MockAgent } from './mockAgent.js';
|
||||
import { cwd } from '../../../../base/common/process.js';
|
||||
|
||||
// ---- Tests ------------------------------------------------------------------
|
||||
|
||||
suite('AgentSideEffects', () => {
|
||||
|
||||
const disposables = new DisposableStore();
|
||||
let fileService: FileService;
|
||||
let stateManager: SessionStateManager;
|
||||
let agent: MockAgent;
|
||||
let sideEffects: AgentSideEffects;
|
||||
@@ -48,7 +52,16 @@ suite('AgentSideEffects', () => {
|
||||
);
|
||||
}
|
||||
|
||||
setup(() => {
|
||||
setup(async () => {
|
||||
fileService = disposables.add(new FileService(new NullLogService()));
|
||||
const memFs = disposables.add(new InMemoryFileSystemProvider());
|
||||
disposables.add(fileService.registerProvider(Schemas.inMemory, memFs));
|
||||
|
||||
// Seed a file so the handleBrowseDirectory tests can distinguish files from dirs
|
||||
const testDir = URI.from({ scheme: Schemas.inMemory, path: '/testDir' });
|
||||
await fileService.createFolder(testDir);
|
||||
await fileService.writeFile(URI.from({ scheme: Schemas.inMemory, path: '/testDir/file.txt' }), VSBuffer.fromString('hello'));
|
||||
|
||||
agent = new MockAgent();
|
||||
disposables.add(toDisposable(() => agent.dispose()));
|
||||
stateManager = disposables.add(new SessionStateManager(new NullLogService()));
|
||||
@@ -56,10 +69,12 @@ suite('AgentSideEffects', () => {
|
||||
sideEffects = disposables.add(new AgentSideEffects(stateManager, {
|
||||
getAgent: () => agent,
|
||||
agents: agentList,
|
||||
}, new NullLogService()));
|
||||
}, new NullLogService(), fileService));
|
||||
});
|
||||
|
||||
teardown(() => disposables.clear());
|
||||
teardown(() => {
|
||||
disposables.clear();
|
||||
});
|
||||
ensureNoDisposablesAreLeakedInTestSuite();
|
||||
|
||||
// ---- handleAction: session/turnStarted ------------------------------
|
||||
@@ -88,7 +103,7 @@ suite('AgentSideEffects', () => {
|
||||
const noAgentSideEffects = disposables.add(new AgentSideEffects(stateManager, {
|
||||
getAgent: () => undefined,
|
||||
agents: emptyAgents,
|
||||
}, new NullLogService()));
|
||||
}, new NullLogService(), fileService));
|
||||
|
||||
const envelopes: IActionEnvelope[] = [];
|
||||
disposables.add(stateManager.onDidEmitEnvelope(e => envelopes.push(e)));
|
||||
@@ -233,7 +248,7 @@ suite('AgentSideEffects', () => {
|
||||
const noAgentSideEffects = disposables.add(new AgentSideEffects(stateManager, {
|
||||
getAgent: () => undefined,
|
||||
agents: emptyAgents,
|
||||
}, new NullLogService()));
|
||||
}, new NullLogService(), fileService));
|
||||
|
||||
await assert.rejects(
|
||||
() => noAgentSideEffects.handleCreateSession({ session: sessionUri, provider: 'nonexistent' }),
|
||||
@@ -277,14 +292,14 @@ suite('AgentSideEffects', () => {
|
||||
|
||||
test('throws when the directory does not exist', async () => {
|
||||
await assert.rejects(
|
||||
() => sideEffects.handleBrowseDirectory(URI.file('/path/that/does/not/exist')),
|
||||
() => sideEffects.handleBrowseDirectory(URI.from({ scheme: Schemas.inMemory, path: '/nonexistent' })),
|
||||
/Directory not found/,
|
||||
);
|
||||
});
|
||||
|
||||
test('throws when the target is not a directory', async () => {
|
||||
await assert.rejects(
|
||||
() => sideEffects.handleBrowseDirectory(URI.file(cwd() + '/package.json')),
|
||||
() => sideEffects.handleBrowseDirectory(URI.from({ scheme: Schemas.inMemory, path: '/testDir/file.txt' })),
|
||||
/Not a directory/,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -342,7 +342,7 @@ suite('ProtocolServerHandler', () => {
|
||||
const resp = findResponse(transport.sent, 1);
|
||||
assert.ok(resp);
|
||||
const result = (resp as { result: IInitializeResult }).result;
|
||||
assert.strictEqual(URI.revive(result.defaultDirectory!).fsPath, '/home/testuser');
|
||||
assert.strictEqual(URI.revive(result.defaultDirectory!).path, '/home/testuser');
|
||||
});
|
||||
|
||||
test('browseDirectory routes to side effect handler', async () => {
|
||||
@@ -355,7 +355,7 @@ suite('ProtocolServerHandler', () => {
|
||||
const resp = await responsePromise;
|
||||
|
||||
assert.strictEqual(sideEffects.browsedUris.length, 1);
|
||||
assert.strictEqual(sideEffects.browsedUris[0].fsPath, '/home/user/project');
|
||||
assert.strictEqual(sideEffects.browsedUris[0].path, '/home/user/project');
|
||||
|
||||
assert.ok(resp);
|
||||
const result = (resp as { result: { entries: { name: string; uri: unknown; type: string }[] } }).result;
|
||||
|
||||
Reference in New Issue
Block a user