refactor: remove exact cross-layer css duplicates
This commit is contained in:
@@ -1803,6 +1803,30 @@ test("heart breathing prepares once then contracts on each exhale", async ({ pag
|
||||
await expect(page.locator(".heart-breath-ripple span").first()).toHaveCSS("transition-duration", "4s");
|
||||
});
|
||||
|
||||
test("stylesheet layers do not repeat identical top-level rules", async ({ page }) => {
|
||||
await mockApplication(page, session("admin", true));
|
||||
await page.goto("/index.html");
|
||||
|
||||
const duplicates = await page.evaluate(() => {
|
||||
const occurrences = new Map();
|
||||
for (const sheet of Array.from(document.styleSheets)) {
|
||||
const href = sheet.href ? new URL(sheet.href).pathname : "inline";
|
||||
for (const rule of Array.from(sheet.cssRules || [])) {
|
||||
if (typeof rule.selectorText !== "string" || !rule.style) continue;
|
||||
const key = `${rule.selectorText}\u0000${rule.style.cssText}`;
|
||||
const rows = occurrences.get(key) || [];
|
||||
rows.push(href);
|
||||
occurrences.set(key, rows);
|
||||
}
|
||||
}
|
||||
return Array.from(occurrences.entries())
|
||||
.filter(([, paths]) => new Set(paths).size > 1)
|
||||
.map(([rule, paths]) => ({ rule, paths }));
|
||||
});
|
||||
|
||||
expect(duplicates).toEqual([]);
|
||||
});
|
||||
|
||||
test("mobile shell stays within the viewport", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 375, height: 812 });
|
||||
await mockApplication(page, session("user", true));
|
||||
|
||||
@@ -29,6 +29,34 @@ RETIRED_FRONTEND_SOURCE_RANGES = (
|
||||
)
|
||||
AUDITED_FRONTEND_SOURCE_LINE_COUNT = 9283
|
||||
|
||||
# CR-12 removes only declarations that are repeated verbatim by a later
|
||||
# stylesheet layer under the same top-level cascade context. Keeping the exact
|
||||
# source fragments here makes every other byte of the accepted CSS baseline a
|
||||
# preservation requirement.
|
||||
AUDITED_CSS_RETIREMENTS = {
|
||||
"styles.css": (
|
||||
".workspace-view.active-view {\n display: block;\n}\n\n",
|
||||
"body.sidebar-collapsed {\n grid-template-columns: 64px minmax(0, 1fr);\n}\n\n",
|
||||
".rotation-day:last-child { border-right: 0; }\n\n",
|
||||
(
|
||||
"#screenerView .probability-value strong,\n"
|
||||
"#screenerView .probability-value small {\n"
|
||||
" display: block;\n"
|
||||
"}\n\n"
|
||||
),
|
||||
),
|
||||
"renovation.css": (
|
||||
".overview-strip .sentiment-block { padding-left: 0; }\n",
|
||||
(
|
||||
'.overview-strip[data-overview-expanded="true"] .metric-value '
|
||||
"{ font-size: 18px; }\n\n"
|
||||
),
|
||||
),
|
||||
"redesign-v2.css": (
|
||||
"#dragonView .dragon-operation-table .dragon-col-reason { width: auto; }\n",
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def sha256(path: Path) -> str:
|
||||
return hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
@@ -123,6 +151,17 @@ def assert_moved_asset_matches(
|
||||
frontend_relative: str | None = None,
|
||||
) -> None:
|
||||
target_relative = frontend_relative or original_relative
|
||||
if original_relative in AUDITED_CSS_RETIREMENTS:
|
||||
original = (ORIGINAL_STATIC / original_relative).read_text(encoding="utf-8")
|
||||
for retired in AUDITED_CSS_RETIREMENTS[original_relative]:
|
||||
testcase.assertEqual(original.count(retired), 1, retired)
|
||||
original = original.replace(retired, "", 1)
|
||||
testcase.assertEqual(
|
||||
(FRONTEND_ROOT / target_relative).read_text(encoding="utf-8"),
|
||||
original,
|
||||
original_relative,
|
||||
)
|
||||
return
|
||||
testcase.assertEqual(
|
||||
sha256(FRONTEND_ROOT / target_relative),
|
||||
sha256(ORIGINAL_STATIC / original_relative),
|
||||
|
||||
@@ -44,7 +44,7 @@ class FrontendPreservationSliceTests(unittest.TestCase):
|
||||
(ORIGINAL_STATIC / "index.html").read_text(encoding="utf-8"),
|
||||
)
|
||||
|
||||
def test_complete_stylesheet_stack_is_byte_identical_after_relocation(self) -> None:
|
||||
def test_stylesheet_stack_matches_baseline_after_audited_retirements(self) -> None:
|
||||
for original, migrated in (
|
||||
("shared/tokens.css", "shared/tokens.css"),
|
||||
("styles.css", "styles/styles.css"),
|
||||
|
||||
Reference in New Issue
Block a user