fix: запуск занятия по HTTP в локальной сети без crypto.randomUUID

This commit is contained in:
gglamer 2026-09-29 11:06:19 +00:00
commit 92b4684871
4 changed files with 34 additions and 5 deletions

View file

@ -5,7 +5,7 @@ import { transform } from "esbuild";
const source = await readFile(new URL("../src/shared/api/ws.ts", import.meta.url), "utf8");
const { code } = await transform(source, { loader: "ts", format: "esm" });
const moduleUrl = `data:text/javascript;base64,${Buffer.from(code).toString("base64")}`;
const { callChannel, stationChannel } = await import(moduleUrl);
const { callChannel, randomUuid, stationChannel } = await import(moduleUrl);
const mergeSource = await readFile(new URL("../src/features/kio-card/merge.ts", import.meta.url), "utf8");
const { code: mergeCode } = await transform(mergeSource, { loader: "ts", format: "esm" });
const { applyPatch, applyState, edit, empty } = await import(
@ -119,4 +119,19 @@ socket.receive({ type: "station.state", snapshot: { card_id: "card-1", reply_tex
socket = reconnect(socket);
assert.deepEqual(socket.sent, [], "matching persisted station snapshot clears the reply");
// Стенд по http://<IP> — не защищённый контекст: randomUUID у браузера нет.
const nativeRandomUuid = Object.getOwnPropertyDescriptor(globalThis.crypto, "randomUUID");
Object.defineProperty(globalThis.crypto, "randomUUID", { value: undefined, configurable: true });
try {
const ids = Array.from({ length: 200 }, () => randomUuid());
for (const id of ids) {
assert.match(id, /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, "UUID v4 without randomUUID");
}
assert.equal(new Set(ids).size, ids.length, "UUIDs without randomUUID do not repeat");
} finally {
if (nativeRandomUuid) Object.defineProperty(globalThis.crypto, "randomUUID", nativeRandomUuid);
else delete globalThis.crypto.randomUUID;
}
assert.match(randomUuid(), /^[0-9a-f-]{36}$/, "native randomUUID is used when present");
console.log("WebSocket durable outbox replay/ack tests passed");