calendar
All repositories: gitoria
5.7 KB
#!/usr/bin/env node// Usage: node check-index-keys.mjs <directory>//// READ ONLY. For every <name>.mpack in the directory (not below it) this lists the live// records whose indexed text field holds a comma, a newline, a carriage return or starts with// a double quote, and says which of them are MISSING from that field's index file// <name>.<field>.txt (mission 486: the engine before the fix dropped such entries from the// index when it was reopened). The indexed fields are the <name>.<field>.txt files beside// the .mpack; nothing is written, locked or created. Exit status 1 when any entry is missing.//// A missing entry is repaired by opening the table with the fixed hl:mpackdb: an index whose// idxstate carries no "idxFmt":2 mark is rebuilt from the data once, the data itself holds// every record.import { readFileSync, readdirSync, existsSync } from 'node:fs'import { join } from 'node:path'const dir = process.argv[2]if (!dir) {console.error('usage: node check-index-keys.mjs <directory>')process.exit(2)}// --- a small MessagePack reader (the subset the engine writes: maps, arrays, strings, numbers)function decode(buf, start) {let p = startconst val = () => {const b = buf[p++]if (b <= 0x7f) return bif (b >= 0xe0) return b - 256if ((b & 0xe0) === 0xa0) return str(b & 0x1f)if ((b & 0xf0) === 0x80) return map(b & 0x0f)if ((b & 0xf0) === 0x90) return arr(b & 0x0f)switch (b) {case 0xc0: return nullcase 0xc2: return falsecase 0xc3: return truecase 0xc4: return bin(buf[p++])case 0xc5: { const n = buf.readUInt16BE(p); p += 2; return bin(n) }case 0xc6: { const n = buf.readUInt32BE(p); p += 4; return bin(n) }case 0xca: { const v = buf.readFloatBE(p); p += 4; return v }case 0xcb: { const v = buf.readDoubleBE(p); p += 8; return v }case 0xcc: return buf[p++]case 0xcd: { const v = buf.readUInt16BE(p); p += 2; return v }case 0xce: { const v = buf.readUInt32BE(p); p += 4; return v }case 0xcf: { const v = Number(buf.readBigUInt64BE(p)); p += 8; return v }case 0xd0: return buf.readInt8(p++)case 0xd1: { const v = buf.readInt16BE(p); p += 2; return v }case 0xd2: { const v = buf.readInt32BE(p); p += 4; return v }case 0xd3: { const v = Number(buf.readBigInt64BE(p)); p += 8; return v }case 0xd9: return str(buf[p++])case 0xda: { const n = buf.readUInt16BE(p); p += 2; return str(n) }case 0xdb: { const n = buf.readUInt32BE(p); p += 4; return str(n) }case 0xdc: { const n = buf.readUInt16BE(p); p += 2; return arr(n) }case 0xdd: { const n = buf.readUInt32BE(p); p += 4; return arr(n) }case 0xde: { const n = buf.readUInt16BE(p); p += 2; return map(n) }case 0xdf: { const n = buf.readUInt32BE(p); p += 4; return map(n) }default: throw new Error('unsupported msgpack byte 0x' + b.toString(16))}}const str = (n) => { const s = buf.toString('utf8', p, p + n); p += n; return s }const bin = (n) => { p += n; return null }const arr = (n) => { const a = []; for (let i = 0; i < n; i++) a.push(val()); return a }const map = (n) => { const o = {}; for (let i = 0; i < n; i++) { const k = val(); o[k] = val() } return o }return val()}// --- an index file: the offsets it names (a quoted key is a JSON string, else split from the right)function indexOffsets(text) {const offsets = new Set()for (const line of text.split('\n')) {if (!line) continueif (line[0] === '"') {let rest = nullfor (let i = 1; i < line.length; i++) {if (line[i] === '\\') { i++; continue }if (line[i] === '"') { rest = line.slice(i + 1); break }}if (rest !== null && /^,\d+,\d+$/.test(rest)) { offsets.add(Number(rest.split(',')[1])); continue }}const c2 = line.lastIndexOf(',')const c1 = c2 > 0 ? line.lastIndexOf(',', c2 - 1) : -1if (c1 < 0) continueconst off = Number(line.slice(c1 + 1, c2))if (Number.isInteger(off)) offsets.add(off)}return offsets}const risky = (v) => typeof v === 'string' && (/[,\n\r]/.test(v) || v[0] === '"')let missingTotal = 0const all = readdirSync(dir)const names = all.filter((f) => f.endsWith('.mpack')).map((f) => f.slice(0, -'.mpack'.length)).sort()for (const name of names) {const data = readFileSync(join(dir, name + '.mpack'))let deleted = new Set()const metaPath = join(dir, name + '.meta.json')if (existsSync(metaPath)) {try { deleted = new Set(JSON.parse(readFileSync(metaPath, 'utf8')).deleted || []) } catch { /* no usable meta */ }}const fields = all.filter((f) => f.startsWith(name + '.') && f.endsWith('.txt')).map((f) => f.slice(name.length + 1, -4)).filter((f) => f && !f.includes('.'))const indexes = new Map(fields.map((f) => [f, indexOffsets(readFileSync(join(dir, name + '.' + f + '.txt'), 'utf8'))]))let live = 0, riskyCount = 0, missing = 0for (let pos = 0; pos + 4 <= data.length;) {const size = data.readUInt32LE(pos)if (size < 5 || pos + size > data.length) { console.log(`${name}.mpack: record frame at ${pos} is damaged or cut short; stopped there`); break }if (!deleted.has(pos)) {live++let rec = nulltry { rec = decode(data, pos + 4) } catch (e) { console.log(`${name}.mpack: record at ${pos} cannot be read: ${e.message}`) }if (rec && typeof rec === 'object') {for (const [field, offsets] of indexes) {if (!risky(rec[field])) continueriskyCount++const lost = !offsets.has(pos)if (lost) { missing++; missingTotal++ }console.log(`${name}.${field}: record at offset ${pos} key ${JSON.stringify(rec[field])} ${lost ? 'MISSING from the index file' : 'present'}`)}}}pos += size}console.log(`${name}: ${live} live records, indexed fields [${fields.join(', ')}], ${riskyCount} with a comma/newline/CR/leading quote, ${missing} missing from their index`)}if (!names.length) console.log('no .mpack files in ' + dir)process.exit(missingTotal ? 1 : 0)
Branches
Latest commits
- e9fec7bb|||PR HL-STANDARD clean-up: typed parameters, plain locals, by-reference cacheAtlas
- eff166a4Re-vendor complete Hybriel plugins and runtime to day44mre
- cef81394Wait for the DST fixture page instead of an unused socketmre
- 42434f47Check lazy-session cookies after login with a stored anonymous fixturemre
- 728e84e3Re-vendor complete Hybriel day41 plugin directoriesmre
- cbd7ff43Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
- 59d1da0acalendar: plain declarations instead of needless let in 9 files (calendar#17): 49 declarations that are never reassigned; reassigned ones and the timer closure's p stay letmre
- f5415cf9calendar: the Style blocks in the language's nested form (calendar#16): rules named after the View's own elements with their children nested, pseudo-classes and @media nested, merged duplicate select rule; same CSS, shots identical in Chrome at 4 sizesmre
- edb7c947calendar: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 56+4 failing → 60 passedmre
- bf8cc0fcStyles move into their components: the shell's styles into main.hl, the events and the editors into the month view's Style block; styles.hl keeps only the theme inherit, the accent and the message line; .gitignore ignores a bin symlink too; tests/styles-shots.mjs for the before/after pixel comparemre
- 5d8579d7README: login.js stays by caramboleyo's explicit rulemre
- cc759328Merge sb3-standby: calendar deploys through its standbymre
- f2fcdc6dcalendar: a standby container (port 45015, profile standby, reminder clock off) and a /health page; deploy hands over through standby-swap.sh without a gapmre
- 229643f7Merge branch 'cal-14'mre
- 1110b26fcalendar#14: the month name no longer breaks into two lines on a phone (Reminder settings drops to its own row when the header is too narrow), gate checks for one-line title and all header controls on screenmre
- 490c658aident#31: the selector's sign-in returns to the page the user started on (return attribute = the login callback with next), gate checkmre
- 18095868calendar: Reminder settings button opens its dialog again (the dialog's open handler still closed the removed user menu and stopped); old e2e and gate scripts use the new headermre
- 6eee4b5acalendar header: the selector alone top right plus Log out as before the theme missions; Reminder settings back on the month page (WIP: the settings test still fails)mre
- 0b909decident selector back in the header (creator 2026-10-24): selector top right signed in and out on phone and desktop, no second Log in button, new gate checks (WIP: gates not re-run after the last edits)mre
- 0c8f9364Merge branch 'sy-sync'mre