|
| 1 | +import { toCustomerFacingError } from './pentest-run-error.util'; |
| 2 | + |
| 3 | +describe('toCustomerFacingError', () => { |
| 4 | + const infraMessagePrefix = |
| 5 | + 'The scan was interrupted by a temporary infrastructure issue'; |
| 6 | + |
| 7 | + describe('infra / transient failures', () => { |
| 8 | + const infraErrors = [ |
| 9 | + 'Sandbox container deleted by Daytona infrastructure (age 35m). Desired-state=started but container gone — likely Daytona backup/restore race condition.', |
| 10 | + 'Run timed out — sandbox became unresponsive', |
| 11 | + 'Timed out with no sandbox after 9m', |
| 12 | + 'Hard timeout: 4m (cap 120m); Daytona unreachable', |
| 13 | + ]; |
| 14 | + |
| 15 | + it.each(infraErrors)( |
| 16 | + 'maps infra error to the transient message: %s', |
| 17 | + (raw) => { |
| 18 | + expect(toCustomerFacingError(raw)).toContain(infraMessagePrefix); |
| 19 | + }, |
| 20 | + ); |
| 21 | + |
| 22 | + it('never echoes the raw provider text', () => { |
| 23 | + const raw = |
| 24 | + 'Sandbox container deleted by Daytona infrastructure (age 35m). backup/restore race condition.'; |
| 25 | + const message = toCustomerFacingError(raw); |
| 26 | + expect(message.toLowerCase()).not.toContain('daytona'); |
| 27 | + expect(message.toLowerCase()).not.toContain('sandbox'); |
| 28 | + expect(message.toLowerCase()).not.toContain('container'); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('genuine runtime cap', () => { |
| 33 | + it('humanizes a 720m cap as 12 hours', () => { |
| 34 | + const message = toCustomerFacingError( |
| 35 | + 'Hard timeout: workflow ran 722m (cap 720m)', |
| 36 | + ); |
| 37 | + expect(message).toContain('maximum runtime of 12 hours'); |
| 38 | + expect(message).toContain("won't be charged"); |
| 39 | + }); |
| 40 | + |
| 41 | + it('humanizes a 120m cap as 2 hours', () => { |
| 42 | + const message = toCustomerFacingError( |
| 43 | + 'Hard timeout: workflow ran 130m (cap 120m)', |
| 44 | + ); |
| 45 | + expect(message).toContain('maximum runtime of 2 hours'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('renders a single-hour cap without pluralizing', () => { |
| 49 | + const message = toCustomerFacingError( |
| 50 | + 'Hard timeout: workflow ran 61m (cap 60m)', |
| 51 | + ); |
| 52 | + expect(message).toContain('maximum runtime of 1 hour'); |
| 53 | + expect(message).not.toContain('1 hours'); |
| 54 | + }); |
| 55 | + |
| 56 | + it('falls back to minutes for a non-hour cap', () => { |
| 57 | + const message = toCustomerFacingError( |
| 58 | + 'Hard timeout: workflow ran 95m (cap 90m)', |
| 59 | + ); |
| 60 | + expect(message).toContain('maximum runtime of 90 minutes'); |
| 61 | + }); |
| 62 | + |
| 63 | + it('renders a single-minute cap without pluralizing', () => { |
| 64 | + const message = toCustomerFacingError( |
| 65 | + 'Hard timeout: workflow ran 2m (cap 1m)', |
| 66 | + ); |
| 67 | + expect(message).toContain('maximum runtime of 1 minute'); |
| 68 | + expect(message).not.toContain('1 minutes'); |
| 69 | + }); |
| 70 | + |
| 71 | + it('classifies the "; Daytona unreachable" variant as infra, not runtime cap', () => { |
| 72 | + const message = toCustomerFacingError( |
| 73 | + 'Hard timeout: 4m (cap 120m); Daytona unreachable', |
| 74 | + ); |
| 75 | + expect(message).toContain(infraMessagePrefix); |
| 76 | + expect(message).not.toContain('maximum runtime'); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + describe('unknown / empty', () => { |
| 81 | + const genericPrefix = "The scan couldn't be completed"; |
| 82 | + |
| 83 | + it('returns the generic message for an unrecognized error', () => { |
| 84 | + expect( |
| 85 | + toCustomerFacingError('some brand new error we have not seen'), |
| 86 | + ).toContain(genericPrefix); |
| 87 | + }); |
| 88 | + |
| 89 | + it('returns the generic message for null / undefined / empty', () => { |
| 90 | + expect(toCustomerFacingError(null)).toContain(genericPrefix); |
| 91 | + expect(toCustomerFacingError(undefined)).toContain(genericPrefix); |
| 92 | + expect(toCustomerFacingError('')).toContain(genericPrefix); |
| 93 | + }); |
| 94 | + }); |
| 95 | +}); |
0 commit comments