refactor: 템플릿에서 기본적으로 제공하고 있는 워크 플로우에 디자인과 라우팅 흡수

This commit is contained in:
donghyeon-ka
2026-09-21 14:21:34 +09:00
parent 85c804b030
commit 42eaf45582
146 changed files with 11050 additions and 2066 deletions
+7
View File
@@ -981,9 +981,16 @@ async function inspectTypeScriptOnlyPolicy(): Promise<TypeScriptOnlyPolicy> {
/\.config\.(?:js|jsx|mjs|cjs)$/u.test(entry.name),
)
.map((entry) => resolve(projectRoot, entry.name));
const nonExecutableEvidenceRoots = [
"tests/fixtures/memento-visual-baseline/legacy/",
] as const;
const candidates = [...files, ...rootConfigFiles]
.filter((file) => forbiddenJavaScriptExtensionPattern.test(file))
.map((file) => reportPath(file, projectRoot, ""))
.filter(
(file) =>
!nonExecutableEvidenceRoots.some((root) => file.startsWith(root)),
)
.sort();
const violations = candidates;
return {
+30
View File
@@ -0,0 +1,30 @@
import { spawnSync } from "node:child_process";
const result = spawnSync(
process.execPath,
["scripts/check-design-system.ts", "--fixture"],
{
cwd: process.cwd(),
encoding: "utf8",
},
);
const output = `${result.stdout ?? ""}
${result.stderr ?? ""}`;
if (result.status === 0) {
process.stderr.write(
"Design-system negative fixture unexpectedly passed; raw product palette regression is not protected.\n",
);
process.exit(1);
}
if (!output.includes("raw product palette value in tests/fixtures/design-system/forbidden/memento-raw-product.css")) {
process.stderr.write(
"Design-system negative fixture failed, but not because the Memento raw palette was rejected.\n",
);
process.stderr.write(output);
process.exit(1);
}
process.stdout.write(
"Design-system fixtures: Memento raw product palette rejected PASS\n",
);
+21 -4
View File
@@ -13,6 +13,11 @@ const tokenFiles = {
semantic: "src/presentation/design-system/tokens/semantic.css",
component: "src/presentation/design-system/tokens/component.css",
};
const productDesignSources = [
"src/presentation/design-system/memento/memento.css",
] as const;
const rawPalettePattern = /(?:#[0-9a-f]{3,8}\b|oklch\(|rgba?\()/i;
const tokenLayers: Array<readonly [string, string, readonly string[]]> = [
["primitive", tokenFiles.primitive, REQUIRED_PRIMITIVE_TOKENS],
["semantic", tokenFiles.semantic, REQUIRED_SEMANTIC_TOKENS],
@@ -29,9 +34,11 @@ for (const [layer, file, tokens] of tokenLayers) {
}
const cssSources = await Promise.all(
[...Object.values(tokenFiles), "src/presentation/styles/theme.css"].map(
async (file) => ({ file, source: await readFile(file, "utf8") }),
),
[
...Object.values(tokenFiles),
"src/presentation/styles/theme.css",
...productDesignSources,
].map(async (file) => ({ file, source: await readFile(file, "utf8") })),
);
const definitions = new Set(
cssSources.flatMap(({ source }) =>
@@ -109,7 +116,7 @@ for (const file of sources) {
}
if (
!file.includes("src/presentation/design-system/tokens/") &&
/(?:#[0-9a-f]{3,8}\b|oklch\(|rgba?\()/i.test(source)
rawPalettePattern.test(source)
) {
failures.push(`raw palette value in ${file}`);
}
@@ -121,6 +128,16 @@ for (const file of sources) {
}
}
const productStyles = fixtureMode
? ["tests/fixtures/design-system/forbidden/memento-raw-product.css"]
: [...productDesignSources];
for (const file of productStyles) {
const source = await readFile(file, "utf8");
if (rawPalettePattern.test(source)) {
failures.push(`raw product palette value in ${file}`);
}
}
const report = designSystemReportArtifactSchema.parse({
schemaVersion: 1,
mode: fixtureMode ? "negative-fixture" : "source",
+322
View File
@@ -0,0 +1,322 @@
import { createHash } from "node:crypto";
import { readdir, readFile, stat } from "node:fs/promises";
import path from "node:path";
const root = process.cwd();
const failures: string[] = [];
async function text(relativePath: string): Promise<string> {
return readFile(path.join(root, relativePath), "utf8");
}
async function exists(relativePath: string): Promise<boolean> {
try {
await stat(path.join(root, relativePath));
return true;
} catch {
return false;
}
}
async function sha256(relativePath: string): Promise<string> {
return createHash("sha256")
.update(await readFile(path.join(root, relativePath)))
.digest("hex");
}
async function walk(relativeDirectory: string): Promise<string[]> {
const absolute = path.join(root, relativeDirectory);
const entries = await readdir(absolute, { withFileTypes: true });
const files: string[] = [];
for (const entry of entries) {
const relative = path.join(relativeDirectory, entry.name);
if (entry.isDirectory()) {
files.push(...(await walk(relative)));
} else if (entry.isFile()) {
files.push(relative);
}
}
return files;
}
function fail(message: string): void {
failures.push(message);
}
const indexHtml = await text("index.html");
for (const [id, pattern] of [
["STATIC_PAGE_MARKUP", /class=["'][^"']*\bpage\b/u],
["STATIC_MODAL_MARKUP", /class=["'][^"']*\bmodal\b/u],
["BETA_SCRIPT", /beta\.js/u],
["BETA_STYLESHEET", /beta\.css/u],
["STATIC_LOGIN", /login-v2\.html/u],
["STATIC_REGISTER", /register-v2\.html/u],
] as const) {
if (pattern.test(indexHtml)) {
fail(`${id}: index.html contains product prototype markup/assets`);
}
}
for (const obsolete of [
"public/beta.js",
"public/beta.css",
"public/login-v2.html",
"public/register-v2.html",
"src/features/memento-web/presentation/memento-runtime-bridge.tsx",
"src/features/memento-web/presentation/memento-prototype-integration.ts",
"src/features/memento-web/adapters/http-memento-gateway.ts",
"src/features/memento-web/adapters/create-memento-gateway.ts",
] as const) {
if (await exists(obsolete)) {
fail(`OBSOLETE_ASSET: ${obsolete} must not return`);
}
}
const presentationRoot = "src/features/memento-web/presentation";
for (const relative of await walk(presentationRoot)) {
if (!/\.(?:ts|tsx)$/u.test(relative)) continue;
const source = await text(relative);
for (const [id, pattern] of [
["DOM_QUERY", /\b(?:document\.)?(?:querySelector|querySelectorAll|getElementById)\s*\(/u],
["GLOBAL_CLICK_HANDLER", /\bdocument\.addEventListener\s*\(\s*["']click["']/u],
["DIRECT_FETCH", /\b(?:globalThis\.)?fetch\s*\(/u],
] as const) {
if (pattern.test(source)) {
fail(`${id}: ${relative}`);
}
}
for (const match of source.matchAll(/from\s+["']([^"']*presentation\/design-system\/[^"']+)["']/gu)) {
const imported = match[1] ?? "";
if (!imported.endsWith("/design-system/index.ts")) {
fail(`DESIGN_SYSTEM_DEEP_IMPORT: ${relative} -> ${imported}`);
}
}
}
const featureRoot = "src/features/memento-web";
for (const relative of await walk(featureRoot)) {
if (!/\.(?:ts|tsx)$/u.test(relative)) continue;
const source = await text(relative);
if (/\b(?:globalThis\.)?fetch\s*\(/u.test(source)) {
fail(`FEATURE_DIRECT_FETCH: ${relative}`);
}
}
for (const relative of (await walk("public")).filter((file) => file.endsWith(".js"))) {
const source = await text(relative);
if (
/\b(?:querySelector|querySelectorAll|getElementById|classList|onclick|addEventListener)\b/u.test(
source,
)
) {
fail(`PUBLIC_IMPERATIVE_UI_JS: ${relative}`);
}
}
const serviceWorkerGenerator = await text("scripts/generate-service-worker-assets.ts");
if (/beta\.(?:js|css)/u.test(serviceWorkerGenerator)) {
fail("SERVICE_WORKER_BETA_ASSET: beta asset remains in service-worker generator");
}
const contractSource = await text(
"src/features/memento-web/contracts/memento-feature-contract.ts",
);
const runtimeSource = await text(
"src/features/memento-web/presentation/memento-feature-runtime.tsx",
);
for (const routeId of [
"APP_HOME",
"MEMENTO_LIBRARY",
"MEMENTO_MEMORIES",
"MEMENTO_MEMORY_DETAIL",
"MEMENTO_ALBUMS",
"MEMENTO_ALBUM_DETAIL",
"MEMENTO_SEARCH",
"MEMENTO_PEOPLE",
"MEMENTO_PERSON_DETAIL",
"MEMENTO_PLACES",
"MEMENTO_PLACE_DETAIL",
"MEMENTO_SETTINGS",
"MEMENTO_LOGIN",
"MEMENTO_REGISTER",
] as const) {
if (!contractSource.includes(`${routeId}: route({`)) {
fail(`ROUTE_CONTRACT_MISSING: ${routeId}`);
}
if (!runtimeSource.includes(`${routeId}: Object.freeze({`)) {
fail(`ROUTE_RUNTIME_MISSING: ${routeId}`);
}
}
const approvedLegacyFixture = Object.freeze({
"tests/fixtures/memento-visual-baseline/legacy/index.html":
"d4ec52fcb9092468f18da4f13b462ac85bc60eef89fcfaabb31a5493387f9cde",
"tests/fixtures/memento-visual-baseline/legacy/beta.css":
"83476b0b188a8c89e64b693f33714f244e0ec30d107fc2485eb4e61ff40de420",
"tests/fixtures/memento-visual-baseline/legacy/beta.js":
"74790fa2dbb07de3c95eaeba709e2477d6710a2a8fbac4f07ca19b078b39a689",
"tests/fixtures/memento-visual-baseline/legacy/login-v2.html":
"891c3b05153a4a3c97f68c5cb19fc954884457a4b24b30e310ec61f073f8bf98",
"tests/fixtures/memento-visual-baseline/legacy/register-v2.html":
"53ce076096589408e9ccda0f856e96b974b82a0a0ab2d1fdde6bf3aea8e739c2",
} as const);
for (const [fixture, expectedHash] of Object.entries(approvedLegacyFixture)) {
if (!(await exists(fixture))) {
fail(`LEGACY_VISUAL_FIXTURE_MISSING: ${fixture}`);
continue;
}
const actualHash = await sha256(fixture);
if (actualHash !== expectedHash) {
fail(
`LEGACY_VISUAL_FIXTURE_CHANGED: ${fixture} expected ${expectedHash} got ${actualHash}`,
);
}
}
for (const evidence of [
"tests/fixtures/memento-visual-baseline/README.md",
"tests/visual/MEMENTO_VISUAL_BASELINE.md",
"tests/visual/memento-legacy-parity.visual.spec.ts",
"playwright.memento-legacy.config.ts",
] as const) {
if (!(await exists(evidence))) {
fail(`LEGACY_VISUAL_EVIDENCE_MISSING: ${evidence}`);
}
}
function splitSelectorList(prelude: string): string[] {
const selectors: string[] = [];
let buffer = "";
let parentheses = 0;
let brackets = 0;
let quote: "'" | '"' | null = null;
for (let index = 0; index < prelude.length; index += 1) {
const character = prelude[index]!;
if (quote) {
buffer += character;
if (character === "\\") {
buffer += prelude[index + 1] ?? "";
index += 1;
} else if (character === quote) {
quote = null;
}
continue;
}
if (character === "'" || character === '"') {
quote = character;
buffer += character;
continue;
}
if (character === "(") parentheses += 1;
else if (character === ")") parentheses -= 1;
else if (character === "[") brackets += 1;
else if (character === "]") brackets -= 1;
if (character === "," && parentheses === 0 && brackets === 0) {
selectors.push(buffer.trim());
buffer = "";
continue;
}
buffer += character;
}
if (buffer.trim()) selectors.push(buffer.trim());
return selectors;
}
function matchingCssBrace(source: string, openIndex: number): number {
let depth = 0;
let quote: "'" | '"' | null = null;
for (let index = openIndex; index < source.length; index += 1) {
const character = source[index]!;
if (quote) {
if (character === "\\") index += 1;
else if (character === quote) quote = null;
continue;
}
if (character === "'" || character === '"') {
quote = character;
continue;
}
if (source.startsWith("/*", index)) {
const end = source.indexOf("*/", index + 2);
if (end < 0) return source.length - 1;
index = end + 1;
continue;
}
if (character === "{") depth += 1;
else if (character === "}") {
depth -= 1;
if (depth === 0) return index;
}
}
throw new Error("Unbalanced Memento CSS");
}
function collectCssSelectors(source: string): string[] {
const selectors: string[] = [];
let index = 0;
while (index < source.length) {
while (index < source.length && /\s/u.test(source[index]!)) index += 1;
if (source.startsWith("/*", index)) {
const end = source.indexOf("*/", index + 2);
index = end < 0 ? source.length : end + 2;
continue;
}
const open = source.indexOf("{", index);
if (open < 0) break;
const prelude = source.slice(index, open).trim();
const close = matchingCssBrace(source, open);
const body = source.slice(open + 1, close);
if (/^@(?:media|supports|layer|container)\b/u.test(prelude)) {
selectors.push(...collectCssSelectors(body));
} else if (!prelude.startsWith("@")) {
selectors.push(...splitSelectorList(prelude));
}
index = close + 1;
}
return selectors;
}
const mementoStylesheet = await text(
"src/presentation/design-system/memento/memento.css",
);
for (const selector of collectCssSelectors(mementoStylesheet)) {
if (
!selector.includes(".memento-app") &&
!selector.includes(".memento-auth-")
) {
fail(`MEMENTO_CSS_UNSCOPED: ${selector}`);
}
}
const visualSpec = "tests/visual/memento-prototype.visual.spec.ts";
if (!(await exists(visualSpec))) {
fail("VISUAL_SPEC_MISSING: Memento visual regression spec is required");
}
const snapshotDirectory =
"tests/visual/__snapshots__/memento-prototype.visual.spec.ts-snapshots";
if (!(await exists(snapshotDirectory))) {
fail("VISUAL_BASELINE_MISSING: Memento snapshot directory is required");
} else {
const snapshots = (await readdir(path.join(root, snapshotDirectory))).filter(
(name) => name.endsWith(".png"),
);
if (snapshots.length < 26) {
fail(
`VISUAL_BASELINE_INCOMPLETE: expected at least 26 snapshots, found ${snapshots.length}`,
);
}
}
if (failures.length > 0) {
console.error("Memento assurance gate: FAIL");
for (const failure of failures) console.error(`- ${failure}`);
process.exitCode = 1;
} else {
console.log(
"Memento assurance gate: PASS (React ownership, route/runtime, HTTP boundary, prototype removal, visual baseline)",
);
}
+4 -6
View File
@@ -38,15 +38,13 @@ const EXCLUDED_FILES: ReadonlySet<string> = new Set([
]);
/**
* Memento's visible Beta shell is intentionally copied byte-for-byte from the
* approved design prototype. These stable URLs are still safe to pre-cache:
* every row is digest-verified during install and lives in a release-specific
* cache. API responses and private originals are never added here.
* Memento's React shell keeps the approved prototype media assets on stable
* product URLs. Those URLs are still safe to pre-cache because every row is
* digest-verified during install and lives in a release-specific cache. API
* responses and private originals are never added here.
*/
const MEMENTO_SHELL_FILES: ReadonlySet<string> = new Set([
"index.html",
"beta.css",
"beta.js",
...Array.from({ length: 11 }, (_, index) => `assets/photo-${index + 1}.jpg`),
]);
+49
View File
@@ -0,0 +1,49 @@
import { createReadStream } from "node:fs";
import { stat } from "node:fs/promises";
import { createServer } from "node:http";
import path from "node:path";
const port = Number(process.argv[2] ?? "4175");
const root = path.resolve("tests/fixtures/memento-visual-baseline/legacy");
const publicRoot = path.resolve("public");
const MIME = Object.freeze({
".css": "text/css; charset=utf-8",
".html": "text/html; charset=utf-8",
".js": "text/javascript; charset=utf-8",
".jpg": "image/jpeg",
".json": "application/json; charset=utf-8",
".png": "image/png",
".svg": "image/svg+xml",
});
function candidatePath(urlPath: string): string {
const clean = decodeURIComponent(urlPath.split("?")[0] ?? "/");
const relative = clean === "/" ? "index.html" : clean.replace(/^\/+/, "");
const base = relative.startsWith("assets/") ? publicRoot : root;
const resolved = path.resolve(base, relative);
if (!resolved.startsWith(base + path.sep) && resolved !== base) {
throw new Error("path traversal");
}
return resolved;
}
const server = createServer(async (request, response) => {
try {
const file = candidatePath(request.url ?? "/");
const metadata = await stat(file);
if (!metadata.isFile()) throw new Error("not a file");
const extension = path.extname(file) as keyof typeof MIME;
response.statusCode = 200;
response.setHeader("Content-Type", MIME[extension] ?? "application/octet-stream");
response.setHeader("Cache-Control", "no-store");
createReadStream(file).pipe(response);
} catch {
response.statusCode = 404;
response.end("Not found");
}
});
server.listen(port, "127.0.0.1", () => {
process.stdout.write(`Memento legacy visual fixture: http://127.0.0.1:${port}\n`);
});