Files
tech-log-frontend/tests/unit/memory-indexeddb-fidelity.test.ts
T
DongHyeonka c80320dfc7 chore: sync the frontend template from ebea300 to af3d8e6
Carries 359 template commits, tag v0.2.0 plus one documentation commit: the
generator-built feature index with its app, bounded-context and feature
declarations, the src/platform kernel and scale tooling, the 2026-09-24 src
review fixes, and the 2026-09-25 maturity review round with its CHANGELOG
[보안]/[계약] rows. 691 of the 824 template paths are applied, 85 of them
merged with product changes; 127 are not carried.

Product identity is unchanged: name, version 0.1.0, routes, design and the
TechLog domain.

Three decisions worth naming. TechLog stays composed directly, as the last
two syncs recorded; its directory carries a NOT_INSTALLED marker that says so,
and every installed-* composer takes the template's projection with TechLog
added on top. The reference sample is no longer installed: the template now
installs a feature only through feature-module.ts and context-routes.ts,
which load the screens this product deleted, so its three operations, six
schemas and one topic leave the registries, recorded as registry change
evidence. And AppRouter mounts the platform and TechLog routes only; the
template's bounded-context route gateway waits for a generator-installed
feature.

Required fixes: readSubject on the BFF session owner (without it every HTTP
Studio session would close as integration-failed), zod through the facade in
nine TechLog files, noUnusedLocals, and public/config.json written out to
match the local profile. Derived baselines were recomputed after reproducing
both sides' values: CI contract 101 commands / 106 references / 141
artifacts, gate shape c9adcf85; registry approval 2dc6c3a3; the runtime
config schema baseline equals the schema at 8210d48.

Verified here: types, lint, architecture, adapter inventory, CI contract,
i18n, design system, diagnostics, browser security, dev release manifest,
TechLog contract and build pass; 220 component, 155 integration, 15
contract, 418 TechLog, 43 reference-feature, 18 recipe and 46
release-coherence tests pass, and 2381 of 2383 unit tests. Reproduced at
8210d48 first and unchanged: check:registries (byte-identical),
test:runtime-schema, verify:documentation. Brought by the template and
escalated rather than suppressed: check:request-fanout on TechLog's cursor
pagination, check:remediation-ledger (fails upstream too), the shared-chunk
hash test, and the registry-dependent sample removal and second-feature
tests. Playwright suites were not run.

Full record, the five open questions and the follow-ups in
docs/operations/template-sync-2026-09-29.md.

(cherry picked from commit b2170cf265dea45dc9cc05d3c61e627e97f31cdb)
2026-11-12 08:28:54 +09:00

121 lines
4.2 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { MemoryIndexedDbFactory } from "../helpers/memory-indexeddb.ts";
/**
* 05-08. Where the fake used to part from native IndexedDB, each case pins
* the native result, so a test built on the fake cannot pass on a behavior no
* browser has.
*/
function settle<Value>(request: IDBRequest<Value>): Promise<Value> {
return new Promise((resolve, reject) => {
request.onsuccess = () => resolve(request.result);
request.onerror = () => reject(request.error);
});
}
function outcome(transaction: IDBTransaction): Promise<string> {
return new Promise((resolve) => {
transaction.oncomplete = () => resolve("complete");
transaction.onabort = () =>
resolve(`abort:${transaction.error?.name ?? "none"}`);
});
}
async function openWithStore(
memory: MemoryIndexedDbFactory,
name: string,
): Promise<IDBDatabase> {
const request = memory.factory.open(name, 1);
request.onupgradeneeded = () => {
request.result.createObjectStore("s", { keyPath: "k" });
};
return await settle(request);
}
describe("05-08 memory IndexedDB matches native semantics the adapters rely on", () => {
it("(a) runs overlapping readwrite transactions one after another", async () => {
const memory = new MemoryIndexedDbFactory();
const database = await openWithStore(memory, "a");
memory.seed("s", { k: "counter", n: 0 });
const first = database.transaction(["s"], "readwrite");
const second = database.transaction(["s"], "readwrite");
const settled = [outcome(first), outcome(second)];
for (const transaction of [first, second]) {
const read = transaction.objectStore("s").get("counter");
read.onsuccess = () => {
const { n } = read.result as { n: number };
transaction.objectStore("s").put({ k: "counter", n: n + 1 });
};
}
expect(await Promise.all(settled)).toEqual(["complete", "complete"]);
expect(memory.readRaw("s", "counter")).toEqual({ k: "counter", n: 2 });
});
it("(b) rejects a request placed after the transaction's task ended", async () => {
const memory = new MemoryIndexedDbFactory();
const database = await openWithStore(memory, "b");
const transaction = database.transaction(["s"], "readwrite");
const settled = outcome(transaction);
await new Promise((resolve) => setTimeout(resolve, 5));
expect(() =>
transaction.objectStore("s").put({ k: "late" }),
).toThrow(expect.objectContaining({ name: "TransactionInactiveError" }));
// A transaction with no request left commits on its own.
expect(await settled).toBe("complete");
expect(memory.readRaw("s", "late")).toBeUndefined();
});
it("(b) keeps a transaction active for requests placed in a success callback's microtasks", async () => {
const memory = new MemoryIndexedDbFactory();
const database = await openWithStore(memory, "b2");
const transaction = database.transaction(["s"], "readwrite");
const settled = outcome(transaction);
const read = transaction.objectStore("s").get("absent");
read.onsuccess = () => {
void Promise.resolve().then(() => {
transaction.objectStore("s").put({ k: "chained" });
});
};
expect(await settled).toBe("complete");
expect(memory.readRaw("s", "chained")).toEqual({ k: "chained" });
});
it("(d) keeps databases of different names apart", async () => {
const memory = new MemoryIndexedDbFactory();
const userA = await openWithStore(memory, "user-A");
await settle(
userA.transaction(["s"], "readwrite").objectStore("s").put({
k: "secret-of-A",
}),
);
let upgraded = false;
const request = memory.factory.open("user-B", 1);
request.onupgradeneeded = () => {
upgraded = true;
request.result.createObjectStore("s", { keyPath: "k" });
};
const userB = await settle(request);
expect(upgraded).toBe(true);
expect(
await settle(
userB.transaction(["s"], "readonly").objectStore("s").get(
"secret-of-A",
),
),
).toBeUndefined();
expect(
await settle(
userA.transaction(["s"], "readonly").objectStore("s").get(
"secret-of-A",
),
),
).toEqual({ k: "secret-of-A" });
});
});