Files
Aislo/resources/tester/cad/random-uuid-polyfill.test.ts
T
eomsangdonandClaude Opus 5.5 ec41d50d92 fix(A00·B07 CAD): http + IP 주소(Tailscale)에서 CAD 가 죽던 것 — crypto.randomUUID 대체
보안 문맥이 아닌 http + IP 에서는 crypto.randomUUID 가 없어 CAD 개체 만들기에서 멈춤.
앱 본체(A00_Common/main.ts)와 CAD(openwebcad/src/main.tsx) 진입 맨 앞에서
getRandomValues 로 v4 UUID 를 채움 · 이미 있으면 그대로.
crypto.subtle(B03 지문) · serviceWorker(B03) 는 이미 없을 때 건너뜀 · navigator.clipboard 는 안 씀.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K7JS47SacjPxZ718QsZKyr
2026-09-28 15:37:22 +09:00

27 lines
1.1 KiB
TypeScript

/**
* http + IP(보안 문맥 아님)에서 비는 crypto.randomUUID 대체 검증 — CAD · 앱 본체 두 벌.
* 실행: node --experimental-strip-types resources/tester/cad/random-uuid-polyfill.test.ts
*/
import assert from 'node:assert/strict';
const V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
const native = crypto.randomUUID;
for (const path of [
'../../../B07_DesignDetail/openwebcad/src/random-uuid-polyfill.ts',
'../../../A00_Common/random_uuid_polyfill.ts',
]) {
// biome-ignore lint: 시험 — 보안 문맥 아닌 브라우저처럼 비움
(crypto as any).randomUUID = undefined;
await import(`${path}?${Math.random()}`);
const ids = Array.from({ length: 200 }, () => crypto.randomUUID());
assert.ok(ids.every((id) => V4.test(id)), `${path}: v4 모양`);
assert.equal(new Set(ids).size, ids.length, `${path}: 안 겹침`);
}
// 이미 있으면 그대로
crypto.randomUUID = native;
await import(`../../../A00_Common/random_uuid_polyfill.ts?${Math.random()}`);
assert.equal(crypto.randomUUID, native, '원래 것 유지');
console.log('random-uuid 대체 시험 통과');