|
17 | 17 | import { describe, it, expect, beforeEach } from '@jest/globals'; |
18 | 18 | import * as vscode from 'vscode'; |
19 | 19 | import { ExtensionContext } from 'vscode'; |
20 | | -import { MANAGE_COMPONENTS_PACKS_COMMAND_ID } from '../manifest'; |
| 20 | +import { MANAGE_COMPONENTS_PACKS_COMMAND_ID, MERGE_FILE_FROM_PATH_COMMAND_ID } from '../manifest'; |
21 | 21 | import * as fsUtils from '../utils/fs-utils'; |
22 | 22 | import * as vscodeUtils from '../utils/vscode-utils'; |
23 | 23 | import { solutionManagerFactory, MockSolutionManager } from './solution-manager.factories'; |
@@ -234,4 +234,141 @@ describe('SolutionProblems', () => { |
234 | 234 | expect(command).toBe(`command:${MANAGE_COMPONENTS_PACKS_COMMAND_ID}`); |
235 | 235 | expect(JSON.parse(decodeURIComponent(args))).toEqual([{ type: 'context', value: 'HID.Debug+STM32U585AIIx' }]); |
236 | 236 | }); |
| 237 | + |
| 238 | + it('creates open merge view command link for absolute merge paths', async () => { |
| 239 | + await solutionProblems.activate({ subscriptions: [] } as unknown as ExtensionContext); |
| 240 | + const setSpy = jest.spyOn(vscode.languages.createDiagnosticCollection(), 'set'); |
| 241 | + |
| 242 | + await eventHub.fireConvertCompleted({ |
| 243 | + severity: 'warning', |
| 244 | + detection: false, |
| 245 | + logMessages: { |
| 246 | + success: true, |
| 247 | + errors: [], |
| 248 | + warnings: ["mylayer.clayer.yml - file '/packs/Component/config.c' update required from component 'Arm::Device@2.3.4'"], |
| 249 | + info: [], |
| 250 | + }, |
| 251 | + }); |
| 252 | + await waitTimeout(); |
| 253 | + |
| 254 | + const [, diagnostics] = setSpy.mock.calls[0] as unknown as [vscode.Uri, readonly vscode.Diagnostic[] | undefined]; |
| 255 | + const diagnostic = diagnostics?.[0]; |
| 256 | + const code = diagnostic?.code as { value: string; target: vscode.Uri }; |
| 257 | + const [command, args] = code.target.toString().split('?'); |
| 258 | + |
| 259 | + expect(diagnostic?.message).toBe("update required for config file 'config.c' from component 'Device'."); |
| 260 | + expect(code.value).toBe('Open in Merge View'); |
| 261 | + expect(command).toBe(`command:${MERGE_FILE_FROM_PATH_COMMAND_ID}`); |
| 262 | + expect(JSON.parse(decodeURIComponent(args))).toEqual(['/packs/Component/config.c']); |
| 263 | + }); |
| 264 | + |
| 265 | + it('creates a merge command uri with encoded local path', () => { |
| 266 | + const result = solutionProblems['createMergeCommandUri']('/packs/Component/config.c'); |
| 267 | + const [command, args] = result.toString().split('?'); |
| 268 | + |
| 269 | + expect(command).toBe(`command:${MERGE_FILE_FROM_PATH_COMMAND_ID}`); |
| 270 | + expect(JSON.parse(decodeURIComponent(args))).toEqual(['/packs/Component/config.c']); |
| 271 | + }); |
| 272 | + |
| 273 | + it('creates merge diagnostic action for merge messages with component context', () => { |
| 274 | + const result = solutionProblems['createMergeDiagnosticAction']( |
| 275 | + "file '/packs/Component/config.c' update required from component 'Arm::Device@2.3.4'", |
| 276 | + layerPath, |
| 277 | + ); |
| 278 | + |
| 279 | + expect(result).toEqual({ |
| 280 | + message: "update required for config file 'config.c' from component 'Device'.", |
| 281 | + code: { |
| 282 | + value: 'Open in Merge View', |
| 283 | + target: vscode.Uri.parse(`command:${MERGE_FILE_FROM_PATH_COMMAND_ID}?${encodeURIComponent(JSON.stringify(['/packs/Component/config.c']))}`), |
| 284 | + }, |
| 285 | + }); |
| 286 | + }); |
| 287 | + |
| 288 | + it('returns undefined merge diagnostic action for non-merge messages', () => { |
| 289 | + const result = solutionProblems['createMergeDiagnosticAction']( |
| 290 | + "component 'Arm::Device@2.3.4' is missing", |
| 291 | + layerPath, |
| 292 | + ); |
| 293 | + |
| 294 | + expect(result).toBeUndefined(); |
| 295 | + }); |
| 296 | + |
| 297 | + it('falls back to the diagnostic file path for relative merge paths', async () => { |
| 298 | + await solutionProblems.activate({ subscriptions: [] } as unknown as ExtensionContext); |
| 299 | + const setSpy = jest.spyOn(vscode.languages.createDiagnosticCollection(), 'set'); |
| 300 | + |
| 301 | + await eventHub.fireConvertCompleted({ |
| 302 | + severity: 'warning', |
| 303 | + detection: false, |
| 304 | + logMessages: { |
| 305 | + success: true, |
| 306 | + errors: [], |
| 307 | + warnings: ["mylayer.clayer.yml - file 'relative-config.c' update recommended"], |
| 308 | + info: [], |
| 309 | + }, |
| 310 | + }); |
| 311 | + await waitTimeout(); |
| 312 | + |
| 313 | + const [uri, diagnostics] = setSpy.mock.calls[0] as unknown as [vscode.Uri, readonly vscode.Diagnostic[] | undefined]; |
| 314 | + const diagnostic = diagnostics?.[0]; |
| 315 | + const code = diagnostic?.code as { value: string; target: vscode.Uri }; |
| 316 | + const [command, args] = code.target.toString().split('?'); |
| 317 | + |
| 318 | + expect(uri.fsPath).toContain('mylayer.clayer.yml'); |
| 319 | + expect(diagnostic?.message).toBe("update recommended for config file 'mylayer.clayer.yml' has a new version available for merge."); |
| 320 | + expect(code.value).toBe('Open in Merge View'); |
| 321 | + expect(command).toBe(`command:${MERGE_FILE_FROM_PATH_COMMAND_ID}`); |
| 322 | + expect(JSON.parse(decodeURIComponent(args))).toEqual([layerPath]); |
| 323 | + }); |
| 324 | + |
| 325 | + it.each(['required', 'recommended', 'suggested', 'mandatory'] as const)( |
| 326 | + 'renders merge diagnostics for %s update levels', |
| 327 | + async updateLevel => { |
| 328 | + await solutionProblems.activate({ subscriptions: [] } as unknown as ExtensionContext); |
| 329 | + const setSpy = jest.spyOn(vscode.languages.createDiagnosticCollection(), 'set'); |
| 330 | + |
| 331 | + await eventHub.fireConvertCompleted({ |
| 332 | + severity: 'warning', |
| 333 | + detection: false, |
| 334 | + logMessages: { |
| 335 | + success: true, |
| 336 | + errors: [], |
| 337 | + warnings: [`mylayer.clayer.yml - file '/packs/Component/${updateLevel}.c' update ${updateLevel}`], |
| 338 | + info: [], |
| 339 | + }, |
| 340 | + }); |
| 341 | + await waitTimeout(); |
| 342 | + |
| 343 | + const [, diagnostics] = setSpy.mock.calls[0] as unknown as [vscode.Uri, readonly vscode.Diagnostic[] | undefined]; |
| 344 | + expect(diagnostics?.[0].message).toBe( |
| 345 | + `update ${updateLevel} for config file '${updateLevel}.c' has a new version available for merge.` |
| 346 | + ); |
| 347 | + } |
| 348 | + ); |
| 349 | + |
| 350 | + it('keeps non-merge diagnostics on the generic action path', async () => { |
| 351 | + await solutionProblems.activate({ subscriptions: [] } as unknown as ExtensionContext); |
| 352 | + const setSpy = jest.spyOn(vscode.languages.createDiagnosticCollection(), 'set'); |
| 353 | + |
| 354 | + await eventHub.fireConvertCompleted({ |
| 355 | + severity: 'error', |
| 356 | + detection: false, |
| 357 | + logMessages: { |
| 358 | + success: false, |
| 359 | + errors: ["mylayer.clayer.yml - component 'Arm::Device@2.3.4' is missing"], |
| 360 | + warnings: [], |
| 361 | + info: [], |
| 362 | + }, |
| 363 | + }); |
| 364 | + await waitTimeout(); |
| 365 | + |
| 366 | + const [, diagnostics] = setSpy.mock.calls[0] as unknown as [vscode.Uri, readonly vscode.Diagnostic[] | undefined]; |
| 367 | + const diagnostic = diagnostics?.[0]; |
| 368 | + const code = diagnostic?.code as { value: string; target: vscode.Uri }; |
| 369 | + |
| 370 | + expect(diagnostic?.message).toBe("component 'Arm::Device@2.3.4' is missing"); |
| 371 | + expect(code.value).toBe('Find in Files'); |
| 372 | + expect(code.target.toString()).toContain('command:workbench.action.findInFiles'); |
| 373 | + }); |
237 | 374 | }); |
0 commit comments