[repo] Workspace: Review Phase 0 and record gaps, lessons and handover
Adversarial review with per-package counts and 13 reintroduced bugs, all caught. Fixes from the review: the trace geocell is capped at 6 characters (~1 km; 16 allowed centimetres), one forbidden-word hit per place, and an e2e guard that meta charset stays within the first 1024 bytes. CLAUDE.md §6.2 no longer contradicts itself about care acts; §2 and §3 say what Phase 0 actually built.
This commit is contained in:
@@ -46,7 +46,8 @@ export const FORBIDDEN: readonly ForbiddenTerm[] = [
|
||||
]),
|
||||
...terms('tolkien', TOLKIEN, [
|
||||
'Tolkien', 'Gandalf', 'Mithrandir', 'Frodo', 'Bilbo', 'Samwise', 'Aragorn', 'Galadriel', 'Sauron',
|
||||
'Mordor', 'Rivendell', 'Middle-earth', 'Middle earth', 'hobbit', 'hobbits', 'Lothlórien', 'Lothlorien'
|
||||
// 'Middle-earth' also matches 'Middle earth': spaces and hyphens are interchangeable in a term.
|
||||
'Mordor', 'Rivendell', 'Middle-earth', 'hobbit', 'hobbits', 'Lothlórien', 'Lothlorien'
|
||||
])
|
||||
];
|
||||
|
||||
@@ -68,14 +69,18 @@ const PATTERNS = FORBIDDEN.map((entry) => ({
|
||||
regex: new RegExp(`(?<![\\p{L}\\p{N}])${escape(entry.term)}(?![\\p{L}\\p{N}])`, 'giu')
|
||||
}));
|
||||
|
||||
/** Every forbidden term in `text`, in order of appearance. */
|
||||
/**
|
||||
* Every forbidden term in `text`, in order of appearance, once per place.
|
||||
* `Middle-earth` and `Middle earth` both match either spelling, so a second hit
|
||||
* at the same index is the same word and is dropped.
|
||||
*/
|
||||
export function findForbidden(text: string): ForbiddenHit[] {
|
||||
const hits: ForbiddenHit[] = [];
|
||||
const byIndex = new Map<number, ForbiddenHit>();
|
||||
for (const { entry, regex } of PATTERNS) {
|
||||
regex.lastIndex = 0;
|
||||
for (let m = regex.exec(text); m !== null; m = regex.exec(text)) {
|
||||
hits.push({ ...entry, index: m.index });
|
||||
if (!byIndex.has(m.index)) byIndex.set(m.index, { ...entry, index: m.index });
|
||||
}
|
||||
}
|
||||
return hits.sort((a, b) => a.index - b.index);
|
||||
return [...byIndex.values()].sort((a, b) => a.index - b.index);
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@ describe('forbidden words — what is caught', () => {
|
||||
it('reports hits in reading order', () => {
|
||||
expect(terms('cure first, then therapy')).toEqual(['cure', 'therapy']);
|
||||
});
|
||||
|
||||
it('reports one word once, though two spellings of it match', () => {
|
||||
expect(terms('Middle earth')).toHaveLength(1);
|
||||
expect(terms('Middle-earth and Middle earth')).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('forbidden words — what is NOT caught', () => {
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
"properties": {
|
||||
"traceId": { "description": "Random and rotating.", "type": "string", "pattern": "^[A-Za-z0-9_-]{16,64}$" },
|
||||
"geocell": {
|
||||
"description": "A coarse cell id. The cell system and its density-adaptive size are decided in the Phase 4 feature doc.",
|
||||
"description": "A coarse cell id, at most ~1 km (CLAUDE.md §4). Capped at 6 characters: a 6-character geohash is ~1.2 x 0.6 km, and every character more is ~5x finer, down to centimetres. The cell system and its density-adaptive size are decided in the Phase 4 feature doc.",
|
||||
"type": "string",
|
||||
"pattern": "^[a-z0-9]{4,16}$"
|
||||
"pattern": "^[a-z0-9]{3,6}$"
|
||||
},
|
||||
"dayBucket": { "type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$" },
|
||||
"gesture": { "type": "string", "enum": ["petal", "light"] },
|
||||
|
||||
@@ -109,4 +109,10 @@ describe('trace', () => {
|
||||
it('rejects a precise coordinate in place of a cell', () => {
|
||||
expect(validateTrace({ ...trace, geocell: '50.0755,14.4378' }).ok).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects a cell finer than ~1 km: a long geohash is a house, not a district', () => {
|
||||
expect(validateTrace({ ...trace, geocell: 'u2fkbn' }).ok, '6 chars, ~1.2 km').toBe(true);
|
||||
expect(validateTrace({ ...trace, geocell: 'u2fkbnx' }).ok, '7 chars, ~150 m').toBe(false);
|
||||
expect(validateTrace({ ...trace, geocell: 'u2fkbnxq9vk2' }).ok, '12 chars, ~4 cm').toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user