You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

22 lines
1.1 KiB

import { describe, expect, it } from 'vitest'
import { diagnoseFailure } from '@template/core'
describe('safe internal diagnostics', () => {
it('keeps a correlation ID, known codes and cause classes without secret messages or paths', () => {
const cause = Object.assign(new Error('credential=super-secret'), { code: 'SQLITE_BUSY' })
const error = new TypeError('private file C:/private/secret.txt', { cause })
const diagnostic = diagnoseFailure(error)
expect(diagnostic.incidentId).toMatch(/^[0-9a-f-]{36}$/)
expect(diagnostic.causes).toEqual([
{ name: 'TypeError' },
{ name: 'Error', code: 'SQLITE_BUSY' }
])
expect(JSON.stringify(diagnostic)).not.toMatch(/super-secret|private|secret\.txt/)
})
it('bounds circular causes and rejects arbitrary names and codes', () => {
const error = Object.assign(new Error('secret'), { name: 'my-token', code: 'my-token' })
error.cause = error
expect(diagnoseFailure(error).causes).toEqual([{ name: 'Error' }])
expect(diagnoseFailure({ secret: 'token' }).causes).toEqual([{ name: 'NonError' }])
})
})