Skip to content

Commit 1666c01

Browse files
sametbasbugclaude
andcommitted
Lock the scales so they cannot drift back
The scales only hold if the next component uses them. This scans every stylesheet for a font-size, weight, tracking, leading, margin, padding or gap carrying a raw length, and fails with the offending line. Values that genuinely sit outside a scale are listed with a reason instead of being left to look like oversights: fluid clamp()s, the safe-area inset, the monogram watermark's graphic dimensions, the line-height: 0 icon reset, the screen-reader clip pattern, and the avatar ring whose 2px follows its border rather than the layout rhythm. Two of the assertions I first wrote were wrong, and mutation-testing them is what showed it: Asserting every declared step is used treats an unused rung as dead code. It isn't -- a type scale is generated by its ratio and a spacing scale by its index law, not by today's usage. The tests now lock those two relationships instead, which is the actual design decision. Checking that a line contains any scale token let `margin: 0.9rem var(--space-8)` through on the strength of its second value. Tokens are stripped first now, then the remainder is checked for raw lengths. Verified by mutation: a raw size, a raw spacing, both mixed shorthands, a broken ratio and a broken index law each fail; a clean tree passes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 9b49c30 commit 1666c01

2 files changed

Lines changed: 127 additions & 1 deletion

File tree

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"staging:slice5:images-cpu": "tsx scripts/orbit-slice5-images-cpu-staging-e2e.ts",
3939
"orbit:import:verify": "tsx scripts/orbit-slice3-manifest.ts",
4040
"orbit:import:local": "tsx scripts/orbit-slice3-import.ts --local --database=orbit-v6-local --config=wrangler.test.jsonc",
41-
"test:d1": "tsx --test --test-concurrency=5 scripts/orbit-agent-identity-tests.ts scripts/orbit-api-contract-tests.ts scripts/orbit-d1-tests.ts scripts/orbit-mcp-authorization-tests.ts scripts/orbit-public-page-tests.ts scripts/orbit-public-repository-tests.ts scripts/orbit-single-renderer-tests.ts scripts/orbit-slice1-tests.ts scripts/orbit-slice1-worker-tests.ts scripts/orbit-slice3-tests.ts scripts/orbit-slice4-tests.ts scripts/orbit-slice5-tests.ts",
41+
"test:d1": "tsx --test --test-concurrency=5 scripts/orbit-agent-identity-tests.ts scripts/orbit-api-contract-tests.ts scripts/orbit-d1-tests.ts scripts/orbit-mcp-authorization-tests.ts scripts/orbit-public-page-tests.ts scripts/orbit-public-repository-tests.ts scripts/orbit-single-renderer-tests.ts scripts/orbit-style-scale-tests.ts scripts/orbit-slice1-tests.ts scripts/orbit-slice1-worker-tests.ts scripts/orbit-slice3-tests.ts scripts/orbit-slice4-tests.ts scripts/orbit-slice5-tests.ts",
4242
"test:d1:core": "tsx --test --test-concurrency=5 scripts/orbit-agent-identity-tests.ts scripts/orbit-api-contract-tests.ts scripts/orbit-d1-tests.ts scripts/orbit-public-page-tests.ts scripts/orbit-public-repository-tests.ts scripts/orbit-slice1-tests.ts scripts/orbit-slice1-worker-tests.ts scripts/orbit-slice3-tests.ts",
4343
"test:d1:publication": "tsx --test scripts/orbit-slice4-tests.ts",
4444
"test:d1:platform": "tsx --test scripts/orbit-slice5-tests.ts",

‎scripts/orbit-style-scale-tests.ts‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/**
2+
* Skala kilidi.
3+
*
4+
* Tip ve boşluk değerleri bir dönem bileşen bileşen elle yazılıyordu: 52 ayrı
5+
* punto, 70 ayrı boşluk, hiçbiri diğerine göre seçilmemiş. Skalaya indirildi;
6+
* bu testler geri dağılmasını engelliyor. Yeni bir bileşen ham rem yazarsa
7+
* burada durur.
8+
*
9+
* Bir değer gerçekten skalanın dışındaysa (akışkan clamp'ler, hizalama
10+
* sabitleri, grafik boyutları) EXEMPT listesine gerekçesiyle eklenir —
11+
* sessizce ham değer bırakılmaz.
12+
*/
13+
import assert from 'node:assert/strict';
14+
import { readFileSync, readdirSync } from 'node:fs';
15+
import { test } from 'node:test';
16+
17+
const STYLE_DIR = new URL('../src/styles/', import.meta.url);
18+
19+
/** tokens.css skalanın tanımlandığı yer; ham değer orada olmalı. */
20+
const SCANNED = readdirSync(STYLE_DIR)
21+
.filter((name) => name.endsWith('.css') && name !== 'tokens.css')
22+
.sort();
23+
24+
/**
25+
* Skalanın dışında kalmasına karar verilen satırlar. Her biri kasıtlı:
26+
* viewport ile sürekli interpolasyon yapanlar kademe seçemez, hizalama ve
27+
* grafik ölçüleri ise ritimden değil kendi geometrisinden gelir.
28+
*/
29+
const EXEMPT: readonly RegExp[] = [
30+
/clamp\(/u, // akışkan hero başlıkları ve kabuk boşlukları
31+
/env\(safe-area-inset/u, // cihaz çentiği, tasarım kararı değil
32+
/font-size:\s*(?:10|16)rem/u, // dev monogram filigranı: tip değil grafik
33+
/letter-spacing:\s*-0\.1em/u, // aynı filigranın sıkışması
34+
/line-height:\s*0;/u, // ikon kutusunu çökerten yerleşim sıfırlaması
35+
/gap:\s*0\.02rem/u, // 0.32px: boşluk değil, kıl payı itme
36+
/margin:\s*-1px !important/u, // ekran okuyucu gizleme kalıbı, yerleşim değil
37+
/padding:\s*2px;/u, // avatar halkası: kalınlığı kenarlığa bağlı, ritme değil
38+
];
39+
40+
type Axis = { readonly property: RegExp; readonly token: string };
41+
42+
const AXES: readonly Axis[] = [
43+
{ property: /^\s*font-size:/u, token: '--text-' },
44+
{ property: /^\s*font-weight:/u, token: '--weight-' },
45+
{ property: /^\s*letter-spacing:/u, token: '--tracking-' },
46+
{ property: /^\s*line-height:/u, token: '--leading-' },
47+
{ property: /^\s*(?:margin|padding)(?:-(?:top|bottom|left|right))?:/u, token: '--space-' },
48+
{ property: /^\s*(?:row-|column-)?gap:/u, token: '--space-' },
49+
];
50+
51+
/** Sayısal bir uzunluk mu taşıyor? `margin: 0` ya da `inherit` sayılmaz. */
52+
function carriesLength(line: string): boolean {
53+
return /[\d.]+(?:rem|em|px)/u.test(line);
54+
}
55+
56+
/**
57+
* Token ifadeleri çıkarıldıktan sonra geriye ham uzunluk kalıyor mu?
58+
*
59+
* Satırda tek bir var() aramak yetmiyordu: `margin: 0.9rem var(--space-8)`
60+
* gibi karışık bir kısa yazım, içindeki tek token yüzünden testten geçiyordu.
61+
*/
62+
function hasRawLength(line: string): boolean {
63+
return carriesLength(line.replaceAll(/var\(--[\w-]+\)/gu, ''));
64+
}
65+
66+
for (const file of SCANNED) {
67+
test(`${file} tip ve boşluk değerlerini skaladan alıyor`, () => {
68+
const source = readFileSync(new URL(file, STYLE_DIR), 'utf8');
69+
const offenders: string[] = [];
70+
71+
for (const raw of source.split('\n')) {
72+
const line = raw.trim();
73+
if (!carriesLength(line)) continue;
74+
if (EXEMPT.some((pattern) => pattern.test(line))) continue;
75+
const axis = AXES.find(({ property }) => property.test(raw));
76+
if (!axis) continue;
77+
if (!line.includes(`var(${axis.token}`) || hasRawLength(line)) offenders.push(line);
78+
}
79+
80+
assert.deepEqual(offenders, [], `${file} içinde skala dışı değer:\n ${offenders.join('\n ')}`);
81+
});
82+
}
83+
84+
test('skalanın kendisi tokens.css dışında tanımlanmıyor', () => {
85+
for (const file of SCANNED) {
86+
const source = readFileSync(new URL(file, STYLE_DIR), 'utf8');
87+
assert.doesNotMatch(
88+
source,
89+
/^\s*--(?:text|weight|tracking|leading|space)-[\w-]+:/mu,
90+
`${file} skalayı yeniden tanımlıyor; kademe eklenecekse yeri tokens.css.`,
91+
);
92+
}
93+
});
94+
95+
/** tokens.css'ten bir eksenin kademelerini tanım sırasıyla oku. */
96+
function rungs(prefix: string): { name: string; value: number }[] {
97+
const tokens = readFileSync(new URL('tokens.css', STYLE_DIR), 'utf8');
98+
return [...tokens.matchAll(new RegExp(`^\\s*(--${prefix}-[\\w-]+):\\s*([\\d.]+)rem;`, 'gmu'))]
99+
.map((match) => ({ name: match[1]!, value: Number(match[2]) }));
100+
}
101+
102+
/**
103+
* Skalanın kullanılmayan kademesi ölü token değil: tip skalası kullanımdan
104+
* değil orandan doğuyor, boşluk skalası da indeks yasasından. Kilitlenmesi
105+
* gereken şey kademelerin kullanılıyor olması değil, aralarındaki ilişki.
106+
*/
107+
test('tip skalası 1.125 oranını koruyor', () => {
108+
const steps = rungs('text');
109+
assert.equal(steps.length, 14, 'Tip skalasının kademe sayısı değişmiş.');
110+
for (let index = 1; index < steps.length; index += 1) {
111+
const ratio = steps[index]!.value / steps[index - 1]!.value;
112+
assert.ok(
113+
Math.abs(ratio - 1.125) < 0.005,
114+
`${steps[index - 1]!.name} -> ${steps[index]!.name} oranı ${ratio.toFixed(4)}, 1.125 olmalı.`,
115+
);
116+
}
117+
});
118+
119+
test('boşluk skalasında sayı piksel/2 demek', () => {
120+
const steps = rungs('space');
121+
assert.ok(steps.length >= 18, `Boşluk skalası beklenenden küçük: ${steps.length}.`);
122+
for (const { name, value } of steps) {
123+
const index = Number(name.replace('--space-', ''));
124+
assert.equal(value * 16, index * 2, `${name} indeksiyle uyumsuz: ${value}rem = ${value * 16}px.`);
125+
}
126+
});

0 commit comments

Comments
 (0)