(params: {
metadata: WorkspaceMetadata;
executeBashImpl: (
workspaceId: string,
script: string,
options?: {
timeout_secs?: number | null;
cwdMode?: "default" | "repo-root" | null;
repoRootProjectPath?: string | null;
}
) => Promise<Result<BashToolResult>>;
})
| 5309 | } |
| 5310 | |
| 5311 | function createServiceHarness(params: { |
| 5312 | metadata: WorkspaceMetadata; |
| 5313 | executeBashImpl: ( |
| 5314 | workspaceId: string, |
| 5315 | script: string, |
| 5316 | options?: { |
| 5317 | timeout_secs?: number | null; |
| 5318 | cwdMode?: "default" | "repo-root" | null; |
| 5319 | repoRootProjectPath?: string | null; |
| 5320 | } |
| 5321 | ) => Promise<Result<BashToolResult>>; |
| 5322 | }): { |
| 5323 | workspaceService: WorkspaceService; |
| 5324 | executeBashMock: ReturnType<typeof mock>; |
| 5325 | getWorkspaceMetadataMock: ReturnType<typeof mock>; |
| 5326 | } { |
| 5327 | const getWorkspaceMetadataMock = mock(() => Promise.resolve(Ok(params.metadata))); |
| 5328 | const aiService: AIService = { |
| 5329 | isStreaming: mock(() => false), |
| 5330 | getWorkspaceMetadata: getWorkspaceMetadataMock, |
| 5331 | on(_eventName: string | symbol, _listener: (...args: unknown[]) => void) { |
| 5332 | return this; |
| 5333 | }, |
| 5334 | off(_eventName: string | symbol, _listener: (...args: unknown[]) => void) { |
| 5335 | return this; |
| 5336 | }, |
| 5337 | } as unknown as AIService; |
| 5338 | |
| 5339 | const mockConfig: Partial<Config> = { |
| 5340 | srcDir: "/tmp/test", |
| 5341 | getSessionDir: mock(() => "/tmp/test/sessions"), |
| 5342 | generateStableId: mock(() => "test-id"), |
| 5343 | findWorkspace: mock(() => null), |
| 5344 | }; |
| 5345 | const mockInitStateManager: Partial<InitStateManager> = { |
| 5346 | on: mock(() => undefined as unknown as InitStateManager), |
| 5347 | getInitState: mock(() => undefined), |
| 5348 | }; |
| 5349 | const workspaceService = createWorkspaceServiceForTest({ |
| 5350 | config: mockConfig, |
| 5351 | historyService, |
| 5352 | aiService, |
| 5353 | initStateManager: mockInitStateManager as InitStateManager, |
| 5354 | }); |
| 5355 | |
| 5356 | const executeBashMock = mock(params.executeBashImpl); |
| 5357 | |
| 5358 | interface WorkspaceServiceTestAccess { |
| 5359 | executeBash: typeof executeBashMock; |
| 5360 | } |
| 5361 | |
| 5362 | const svc = workspaceService as unknown as WorkspaceServiceTestAccess; |
| 5363 | svc.executeBash = executeBashMock; |
| 5364 | |
| 5365 | return { workspaceService, executeBashMock, getWorkspaceMetadataMock }; |
| 5366 | } |
| 5367 | |
| 5368 | test("returns a single entry for single-project workspaces", async () => { |
no test coverage detected