All files / src/types signal.ts

100% Statements 21/21
100% Branches 10/10
100% Functions 1/1
100% Lines 21/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 651x                                                                                       1x 65x 65x 65x 65x 65x 65x 65x 65x 65x 65x 65x 65x 65x 65x 65x 65x 65x 65x 65x  
/**
 * Signal type — compatible with OpenSIP's signal format.
 * Used by the check framework internally. Converted to Finding for output.
 */
 
export type SignalSeverity = 'critical' | 'high' | 'medium' | 'low'
export type SignalCategory = 'security' | 'quality' | 'architecture' | 'testing' | 'resilience' | 'documentation' | 'warning' | 'performance' | 'error'
 
export interface Signal {
  readonly id: string
  readonly source: string
  readonly provider: string
  readonly severity: SignalSeverity
  readonly category: SignalCategory | string
  readonly ruleId: string
  readonly message: string
  readonly suggestion?: string
  readonly filePath: string
  readonly line?: number
  readonly column?: number
  readonly code?: { file?: string; line?: number; column?: number }
  readonly fixAction?: string
  readonly fixConfidence?: number
  readonly metadata: Record<string, unknown>
  readonly strength?: number
  readonly fingerprint?: string
  readonly createdAt: string
}
 
export interface CreateSignalInput {
  source: string
  provider?: string
  severity: SignalSeverity
  category?: SignalCategory | string
  ruleId: string
  message: string
  suggestion?: string
  code?: { file?: string; line?: number; column?: number }
  fix?: { action?: string; confidence?: number }
  metadata?: Record<string, unknown>
}
 
import { randomUUID } from 'node:crypto'
 
export function createSignal(input: CreateSignalInput): Signal {
  return {
    id: `sig_${randomUUID().slice(0, 12)}`,
    source: input.source,
    provider: input.provider ?? 'opensip-tools',
    severity: input.severity,
    category: input.category ?? 'quality',
    ruleId: input.ruleId,
    message: input.message,
    suggestion: input.suggestion,
    filePath: input.code?.file ?? '',
    line: input.code?.line,
    column: input.code?.column,
    code: input.code,
    fixAction: input.fix?.action,
    fixConfidence: input.fix?.confidence,
    metadata: input.metadata ?? {},
    createdAt: new Date().toISOString(),
  }
}