Skip to content

Commit f8ea72d

Browse files
committed
fix(scripts): match example uuids case-insensitively in the spec audit
The pattern only recognised lowercase hex, so an uppercase id in a published spec was never examined and the audit reported success without having looked at it. Matching case-insensitively is not enough on its own: hex is case-insensitive, so a mixed-case id counts `A` and `a` as two digits and reports twenty distinct ones rather than sixteen. That inflated count clears the threshold the texture test uses to recognise a hand-authored placeholder, so a real id could have passed for one. The allowlist is an exact-string lookup and would likewise have missed an uppercase spelling of an entry. Both checks and the lookup now take a normalised id, while the finding still reports the spelling as it appears in the file.
1 parent 6102106 commit f8ea72d

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

scripts/check-spec-example-ids.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import path from 'node:path'
1616

1717
const ROOT = path.resolve(import.meta.dir, '..')
1818
const SPEC_DIR = path.join(ROOT, 'apps/docs')
19-
const UUID_PATTERN = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/g
19+
const UUID_PATTERN = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi
2020

2121
/** Ids that are obviously synthetic to a reader but do not match the pandigital texture. */
2222
const ALLOWED: Record<string, string> = {
@@ -25,12 +25,21 @@ const ALLOWED: Record<string, string> = {
2525
'pre-existing hand-authored block id shared with the v2 workflow operations tests',
2626
}
2727

28-
/** All-zero and all-f sentinels read as synthetic on sight. */
28+
/**
29+
* All-zero and all-f sentinels read as synthetic on sight.
30+
*
31+
* Takes an already-lowercased id: hex is case-insensitive, so counting `A` and `a` as two
32+
* digits would inflate the distinct count and misjudge the texture.
33+
*/
2934
function isSentinel(uuid: string): boolean {
3035
return new Set(uuid.replace(/-/g, '')).size <= 2
3136
}
3237

33-
/** Hand-authored placeholders in this repo use every hex digit, none more than three times. */
38+
/**
39+
* Hand-authored placeholders in this repo use every hex digit, none more than three times.
40+
*
41+
* Takes an already-lowercased id, for the reason given on {@link isSentinel}.
42+
*/
3443
function isHouseStyle(uuid: string): boolean {
3544
const hex = uuid.replace(/-/g, '')
3645
const digits = new Set(hex)
@@ -48,7 +57,8 @@ for (const file of specFiles) {
4857
const contents = await Bun.file(path.join(SPEC_DIR, file)).text()
4958
const seen = new Set(contents.match(UUID_PATTERN) ?? [])
5059
for (const uuid of [...seen].sort()) {
51-
if (uuid in ALLOWED || isSentinel(uuid) || isHouseStyle(uuid)) continue
60+
const normalized = uuid.toLowerCase()
61+
if (normalized in ALLOWED || isSentinel(normalized) || isHouseStyle(normalized)) continue
5262
findings.push(` - ${file}: ${uuid}`)
5363
}
5464
}

0 commit comments

Comments
 (0)