fix(diagnostics): BUG-1, BUG-2 - DRY violation - centralize generateId and buildPk in types.ts
This commit is contained in:
parent
890a558c31
commit
4cb8b499af
@ -4,10 +4,11 @@
|
||||
* @module diagnostics
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import * as repo from './repository.js';
|
||||
import {
|
||||
generateId,
|
||||
CreateDebugSessionSchema,
|
||||
UpdateDebugSessionSchema,
|
||||
IngestTracesSchema,
|
||||
@ -21,10 +22,8 @@ import {
|
||||
type IngestLogsInput,
|
||||
} from './types.js';
|
||||
|
||||
// Test helpers
|
||||
function generateId(prefix: string): string {
|
||||
return `${prefix}_${randomUUID().replace(/-/g, '')}`;
|
||||
}
|
||||
// Test helpers - generateId is now imported from types.ts for DRY compliance
|
||||
// function generateId(prefix: string): string { ... } // REMOVED - using shared version
|
||||
|
||||
function createTestSession(productId: string, overrides?: Partial<DebugSessionDoc>): DebugSessionDoc {
|
||||
const now = new Date().toISOString();
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
import type { FastifyInstance } from 'fastify';
|
||||
import { randomUUID } from 'node:crypto';
|
||||
import { generateId, buildPk } from './types.js';
|
||||
import { getRequestProductId } from '../../lib/request-context.js';
|
||||
import { requireRole } from '../../lib/auth.js';
|
||||
import { BadRequestError, NotFoundError } from '../../lib/errors.js';
|
||||
@ -49,15 +49,11 @@ import {
|
||||
// TODO-1: Event bus integration - need to emit events for session lifecycle
|
||||
// Import event bus once available: import { emitEvent } from '../../lib/event-bus.js';
|
||||
|
||||
// Re-export shared helpers from types
|
||||
export { generateId, buildPk } from './types.js';
|
||||
|
||||
// ─── Helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
function generateId(prefix: string): string {
|
||||
return `${prefix}_${randomUUID().replace(/-/g, '')}`;
|
||||
}
|
||||
|
||||
function buildPk(productId: string, sessionId: string): string {
|
||||
return `${productId}:${sessionId}`;
|
||||
}
|
||||
|
||||
// TODO-2: PII Redaction - need to implement PII scanning for log messages
|
||||
// This should be shared with telemetry module
|
||||
|
||||
@ -12,6 +12,24 @@
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { randomUUID } from 'node:crypto';
|
||||
|
||||
/**
|
||||
* Generate a prefixed ID for diagnostics documents.
|
||||
* Exported for use in routes and tests.
|
||||
*/
|
||||
export function generateId(prefix: string): string {
|
||||
return `${prefix}_${randomUUID().replace(/-/g, '')}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build composite partition key for traces/logs.
|
||||
* Exported for use in routes.
|
||||
*/
|
||||
export function buildPk(productId: string, sessionId: string): string {
|
||||
return `${productId}:${sessionId}`;
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
// Enums
|
||||
// ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
Loading…
Reference in New Issue
Block a user