|
2 | 2 | * @vitest-environment node |
3 | 3 | */ |
4 | 4 | import { describe, expect, it } from 'vitest' |
5 | | -import { extractResourcesFromToolResult } from './extraction' |
| 5 | +import { extractDeletedResourcesFromToolResult, extractResourcesFromToolResult } from './extraction' |
6 | 6 |
|
7 | 7 | describe('extractResourcesFromToolResult', () => { |
8 | 8 | it('extracts file resources from create_file results', () => { |
@@ -141,4 +141,66 @@ describe('extractResourcesFromToolResult', () => { |
141 | 141 |
|
142 | 142 | expect(resources).toEqual([]) |
143 | 143 | }) |
| 144 | + |
| 145 | + it('auto-opens a scheduledtask resource from manage_scheduled_task create results', () => { |
| 146 | + const resources = extractResourcesFromToolResult( |
| 147 | + 'manage_scheduled_task', |
| 148 | + { operation: 'create', args: { title: 'Daily Report' } }, |
| 149 | + { jobId: 'sched_123', title: 'Daily Report', message: 'Job created successfully.' } |
| 150 | + ) |
| 151 | + |
| 152 | + expect(resources).toEqual([{ type: 'scheduledtask', id: 'sched_123', title: 'Daily Report' }]) |
| 153 | + }) |
| 154 | + |
| 155 | + it('auto-opens a scheduledtask resource on update, falling back to the args title', () => { |
| 156 | + const resources = extractResourcesFromToolResult( |
| 157 | + 'manage_scheduled_task', |
| 158 | + { operation: 'update', args: { jobId: 'sched_123', title: 'Renamed Task' } }, |
| 159 | + { jobId: 'sched_123', updated: ['title'], message: 'Job updated successfully' } |
| 160 | + ) |
| 161 | + |
| 162 | + expect(resources).toEqual([{ type: 'scheduledtask', id: 'sched_123', title: 'Renamed Task' }]) |
| 163 | + }) |
| 164 | + |
| 165 | + it('does not auto-open for read-only manage_scheduled_task operations', () => { |
| 166 | + expect( |
| 167 | + extractResourcesFromToolResult( |
| 168 | + 'manage_scheduled_task', |
| 169 | + { operation: 'list' }, |
| 170 | + { jobs: [], count: 0 } |
| 171 | + ) |
| 172 | + ).toEqual([]) |
| 173 | + expect( |
| 174 | + extractResourcesFromToolResult( |
| 175 | + 'manage_scheduled_task', |
| 176 | + { operation: 'get', args: { jobId: 'sched_123' } }, |
| 177 | + { id: 'sched_123', title: 'Daily Report' } |
| 178 | + ) |
| 179 | + ).toEqual([]) |
| 180 | + }) |
| 181 | +}) |
| 182 | + |
| 183 | +describe('extractDeletedResourcesFromToolResult', () => { |
| 184 | + it('removes scheduledtask resources on manage_scheduled_task delete', () => { |
| 185 | + const resources = extractDeletedResourcesFromToolResult( |
| 186 | + 'manage_scheduled_task', |
| 187 | + { operation: 'delete', args: { jobIds: ['sched_1', 'sched_2'] } }, |
| 188 | + { deleted: ['sched_1', 'sched_2'], notFound: [] } |
| 189 | + ) |
| 190 | + |
| 191 | + expect(resources).toEqual([ |
| 192 | + { type: 'scheduledtask', id: 'sched_1', title: 'Scheduled Task' }, |
| 193 | + { type: 'scheduledtask', id: 'sched_2', title: 'Scheduled Task' }, |
| 194 | + ]) |
| 195 | + }) |
| 196 | + |
| 197 | + it('does not remove anything for non-delete manage_scheduled_task ops', () => { |
| 198 | + expect( |
| 199 | + extractDeletedResourcesFromToolResult( |
| 200 | + 'manage_scheduled_task', |
| 201 | + { operation: 'update', args: { jobId: 'sched_1' } }, |
| 202 | + { jobId: 'sched_1', updated: ['title'] } |
| 203 | + ) |
| 204 | + ).toEqual([]) |
| 205 | + }) |
144 | 206 | }) |
0 commit comments