refactor(person): delete personAvatarColor + djb2 from personFormat.ts
Some checks failed
CI / Unit & Component Tests (pull_request) Failing after 4m43s
CI / OCR Service Tests (pull_request) Successful in 29s
CI / Backend Unit Tests (pull_request) Successful in 6m12s
CI / fail2ban Regex (pull_request) Successful in 48s
CI / Semgrep Security Scan (pull_request) Successful in 23s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m7s
SDD Gate / RTM Check (pull_request) Successful in 17s
SDD Gate / Contract Validate (pull_request) Successful in 23s
SDD Gate / Constitution Impact (pull_request) Successful in 19s

Dead code now that all callers use Avatar / avatarFor. Removes the old
5-color id-hashed palette (AVATAR_PALETTE) and its test suite.

Refs #855
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-06-16 19:04:11 +02:00
parent f4d8442760
commit 61116916a8
2 changed files with 1 additions and 38 deletions

View File

@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'; import { describe, it, expect } from 'vitest';
import { getInitials, abbreviateName, formatXsMeta, personAvatarColor } from './personFormat'; import { getInitials, abbreviateName, formatXsMeta } from './personFormat';
import { formatDate } from '$lib/shared/utils/date'; import { formatDate } from '$lib/shared/utils/date';
// ─── getInitials ───────────────────────────────────────────────────────────── // ─── getInitials ─────────────────────────────────────────────────────────────
@@ -97,29 +97,6 @@ describe('formatXsMeta', () => {
}); });
}); });
// ─── personAvatarColor ───────────────────────────────────────────────────────
const PALETTE = ['#012851', '#5A3080', '#007596', '#2A6040', '#803020'];
describe('personAvatarColor', () => {
it('returns a value from the palette', () => {
expect(PALETTE).toContain(personAvatarColor('abc'));
});
it('is deterministic — same id always returns same color', () => {
const id = '550e8400-e29b-41d4-a716-446655440000';
expect(personAvatarColor(id)).toBe(personAvatarColor(id));
});
it('all 5 palette entries are reachable across 1000 random UUIDs', () => {
const seen = new Set<string>();
for (let i = 0; i < 1000; i++) {
seen.add(personAvatarColor(crypto.randomUUID()));
}
expect(seen.size).toBe(5);
});
});
// ─── formatDate ────────────────────────────────────────────────────────────── // ─── formatDate ──────────────────────────────────────────────────────────────
describe('formatDate', () => { describe('formatDate', () => {

View File

@@ -8,16 +8,6 @@ type DocForMeta = {
documentDate?: string | null; documentDate?: string | null;
}; };
const AVATAR_PALETTE = ['#012851', '#5A3080', '#007596', '#2A6040', '#803020'] as const;
function djb2(str: string): number {
let hash = 5381;
for (let i = 0; i < str.length; i++) {
hash = (hash * 33) ^ str.charCodeAt(i);
}
return Math.abs(hash);
}
/** Localized fallback when a person has no name parts. */ /** Localized fallback when a person has no name parts. */
export function unknownPersonName(): string { export function unknownPersonName(): string {
return m.person_unknown(); return m.person_unknown();
@@ -83,7 +73,3 @@ export function formatXsMeta(doc: DocForMeta): string {
return parts.join(' · '); return parts.join(' · ');
} }
export function personAvatarColor(personId: string): string {
return AVATAR_PALETTE[djb2(personId) % AVATAR_PALETTE.length];
}