gitoria

notes

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit52ffac9f52ffac9f|||PR Keyboard and reload checks for the notes gate (HL-STANDARD F21, F5)Atlas52ffac9f/plugins/mpackdb/tools/check-index-keys.mjs

5.7 KB

  1. #!/usr/bin/env node
  2. // Usage: node check-index-keys.mjs <directory>
  3. //
  4. // READ ONLY. For every <name>.mpack in the directory (not below it) this lists the live
  5. // records whose indexed text field holds a comma, a newline, a carriage return or starts with
  6. // a double quote, and says which of them are MISSING from that field's index file
  7. // <name>.<field>.txt (mission 486: the engine before the fix dropped such entries from the
  8. // index when it was reopened). The indexed fields are the <name>.<field>.txt files beside
  9. // the .mpack; nothing is written, locked or created. Exit status 1 when any entry is missing.
  10. //
  11. // A missing entry is repaired by opening the table with the fixed hl:mpackdb: an index whose
  12. // idxstate carries no "idxFmt":2 mark is rebuilt from the data once, the data itself holds
  13. // every record.
  14. import { readFileSync, readdirSync, existsSync } from 'node:fs'
  15. import { join } from 'node:path'
  16. const dir = process.argv[2]
  17. if (!dir) {
  18. console.error('usage: node check-index-keys.mjs <directory>')
  19. process.exit(2)
  20. }
  21. // --- a small MessagePack reader (the subset the engine writes: maps, arrays, strings, numbers)
  22. function decode(buf, start) {
  23. let p = start
  24. const val = () => {
  25. const b = buf[p++]
  26. if (b <= 0x7f) return b
  27. if (b >= 0xe0) return b - 256
  28. if ((b & 0xe0) === 0xa0) return str(b & 0x1f)
  29. if ((b & 0xf0) === 0x80) return map(b & 0x0f)
  30. if ((b & 0xf0) === 0x90) return arr(b & 0x0f)
  31. switch (b) {
  32. case 0xc0: return null
  33. case 0xc2: return false
  34. case 0xc3: return true
  35. case 0xc4: return bin(buf[p++])
  36. case 0xc5: { const n = buf.readUInt16BE(p); p += 2; return bin(n) }
  37. case 0xc6: { const n = buf.readUInt32BE(p); p += 4; return bin(n) }
  38. case 0xca: { const v = buf.readFloatBE(p); p += 4; return v }
  39. case 0xcb: { const v = buf.readDoubleBE(p); p += 8; return v }
  40. case 0xcc: return buf[p++]
  41. case 0xcd: { const v = buf.readUInt16BE(p); p += 2; return v }
  42. case 0xce: { const v = buf.readUInt32BE(p); p += 4; return v }
  43. case 0xcf: { const v = Number(buf.readBigUInt64BE(p)); p += 8; return v }
  44. case 0xd0: return buf.readInt8(p++)
  45. case 0xd1: { const v = buf.readInt16BE(p); p += 2; return v }
  46. case 0xd2: { const v = buf.readInt32BE(p); p += 4; return v }
  47. case 0xd3: { const v = Number(buf.readBigInt64BE(p)); p += 8; return v }
  48. case 0xd9: return str(buf[p++])
  49. case 0xda: { const n = buf.readUInt16BE(p); p += 2; return str(n) }
  50. case 0xdb: { const n = buf.readUInt32BE(p); p += 4; return str(n) }
  51. case 0xdc: { const n = buf.readUInt16BE(p); p += 2; return arr(n) }
  52. case 0xdd: { const n = buf.readUInt32BE(p); p += 4; return arr(n) }
  53. case 0xde: { const n = buf.readUInt16BE(p); p += 2; return map(n) }
  54. case 0xdf: { const n = buf.readUInt32BE(p); p += 4; return map(n) }
  55. default: throw new Error('unsupported msgpack byte 0x' + b.toString(16))
  56. }
  57. }
  58. const str = (n) => { const s = buf.toString('utf8', p, p + n); p += n; return s }
  59. const bin = (n) => { p += n; return null }
  60. const arr = (n) => { const a = []; for (let i = 0; i < n; i++) a.push(val()); return a }
  61. const map = (n) => { const o = {}; for (let i = 0; i < n; i++) { const k = val(); o[k] = val() } return o }
  62. return val()
  63. }
  64. // --- an index file: the offsets it names (a quoted key is a JSON string, else split from the right)
  65. function indexOffsets(text) {
  66. const offsets = new Set()
  67. for (const line of text.split('\n')) {
  68. if (!line) continue
  69. if (line[0] === '"') {
  70. let rest = null
  71. for (let i = 1; i < line.length; i++) {
  72. if (line[i] === '\\') { i++; continue }
  73. if (line[i] === '"') { rest = line.slice(i + 1); break }
  74. }
  75. if (rest !== null && /^,\d+,\d+$/.test(rest)) { offsets.add(Number(rest.split(',')[1])); continue }
  76. }
  77. const c2 = line.lastIndexOf(',')
  78. const c1 = c2 > 0 ? line.lastIndexOf(',', c2 - 1) : -1
  79. if (c1 < 0) continue
  80. const off = Number(line.slice(c1 + 1, c2))
  81. if (Number.isInteger(off)) offsets.add(off)
  82. }
  83. return offsets
  84. }
  85. const risky = (v) => typeof v === 'string' && (/[,\n\r]/.test(v) || v[0] === '"')
  86. let missingTotal = 0
  87. const all = readdirSync(dir)
  88. const names = all.filter((f) => f.endsWith('.mpack')).map((f) => f.slice(0, -'.mpack'.length)).sort()
  89. for (const name of names) {
  90. const data = readFileSync(join(dir, name + '.mpack'))
  91. let deleted = new Set()
  92. const metaPath = join(dir, name + '.meta.json')
  93. if (existsSync(metaPath)) {
  94. try { deleted = new Set(JSON.parse(readFileSync(metaPath, 'utf8')).deleted || []) } catch { /* no usable meta */ }
  95. }
  96. const fields = all
  97. .filter((f) => f.startsWith(name + '.') && f.endsWith('.txt'))
  98. .map((f) => f.slice(name.length + 1, -4))
  99. .filter((f) => f && !f.includes('.'))
  100. const indexes = new Map(fields.map((f) => [f, indexOffsets(readFileSync(join(dir, name + '.' + f + '.txt'), 'utf8'))]))
  101. let live = 0, riskyCount = 0, missing = 0
  102. for (let pos = 0; pos + 4 <= data.length;) {
  103. const size = data.readUInt32LE(pos)
  104. if (size < 5 || pos + size > data.length) { console.log(`${name}.mpack: record frame at ${pos} is damaged or cut short; stopped there`); break }
  105. if (!deleted.has(pos)) {
  106. live++
  107. let rec = null
  108. try { rec = decode(data, pos + 4) } catch (e) { console.log(`${name}.mpack: record at ${pos} cannot be read: ${e.message}`) }
  109. if (rec && typeof rec === 'object') {
  110. for (const [field, offsets] of indexes) {
  111. if (!risky(rec[field])) continue
  112. riskyCount++
  113. const lost = !offsets.has(pos)
  114. if (lost) { missing++; missingTotal++ }
  115. console.log(`${name}.${field}: record at offset ${pos} key ${JSON.stringify(rec[field])} ${lost ? 'MISSING from the index file' : 'present'}`)
  116. }
  117. }
  118. }
  119. pos += size
  120. }
  121. console.log(`${name}: ${live} live records, indexed fields [${fields.join(', ')}], ${riskyCount} with a comma/newline/CR/leading quote, ${missing} missing from their index`)
  122. }
  123. if (!names.length) console.log('no .mpack files in ' + dir)
  124. process.exit(missingTotal ? 1 : 0)

Branches

Latest commits

  • 52ffac9f|||PR Keyboard and reload checks for the notes gate (HL-STANDARD F21, F5)Atlas
  • 617ee8c0Merge branch 'hl-standard' into mainAtlas
  • 452458ee|||PR Type the function parameters of notes' own .hl files (HL-STANDARD L10)Atlas
  • 23758cd6Re-vendor complete Hybriel plugins and runtime to day44mre
  • 5d7cc700Backup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 3e07b1cfVendor complete Hybriel day39 plugin sources and librariesmre
  • d7366702Check session cookie flags after login and assert anonymous GET stays cookielessmre
  • 16bc8fd8Re-vendor Hybriel day38b with the mpackdb store-open race fixmre
  • d860dc2dnotes#12: the markup names its own rules instead of hand-written class strings: the selected row is `aria-current="page"` (the list-first theme rule styles it, no class), the delete question is `Style.pAsk` and follows its own `open` attribute (bound to `asking`), the error line is `Style.pMessage` (body once in lib/looks.hl, rule in notes.hl, main.hl and loginfailed.hl). The CSS declarations are the same, only selectors changed (.ask -> p.ask, .ask.open -> p.ask[open], .message -> p.message); the pages look the same (AE 0 at 4 sizes). main.hl's selectorClass in/out stays (login.js reads it).mre
  • 2e7f8664notes#13: the list and back links pass the note key from the loop (emit pick(e, r.key)) instead of writing data-note into the View and reading it back with getAttribute; the two window.history.replaceState calls and the identcode e.target.value read stay (hl:web has no replace-navigation, a bound hidden input is not adopted on a script's change event), see NO13 reportmre
  • 4dc98282notes#15: a deleted note made in this tab leaves the list at once (the delete now removes this tab's edit under every key the row has: local id, server id); gate: browser.mjs notes#15 section, red on the old codemre
  • e4e7402fnotes#11: plain declarations instead of let for variables never reassigned (components/notes.hl 3, lib/jsoncheck.hl 5, lib/util.hl 2, tools/migrate-short-ids.hl 8)mre
  • 27b6a09enotes#8: Style blocks in the nested form (note-list, note-editor, .ask with their children nested, :empty as a nested pseudo-class); the same CSS rules, the pages look the samemre
  • 71a9538bnotes: B27W report, log linemre
  • 78ba0073notes: an ident access key (Authorization: Bearer idt_…) reads and writes its identity's notes through /api/me and /api/notes; gate tests/ident-access-notes.mjs (ident#27)mre
  • 3de46dacnotes: the sign-in callback keeps the session it finds and signs it in (same cookie, nothing signed out; ident#28); security gate 73+5 failing → 78 passedmre
  • 5909d458notes: MdEditor from components 59704ce (text on the clipboard always pastes, a file manager copy still attaches; pipe rows without a delimiter row; tickets#49, notes#5)mre
  • 98bd6a98N5b: pipe rows without a delimiter row are a table (MdEditor ad4e929, plain copy); gate tests/dashboard-table.mjs; reportmre
  • dbf93319N5 report: components gate rerun 613 passed, 0 failedmre
  • 3a8bc0d2N5: empty Table-button table is written as a real pipe table (MdEditor 4bd1112, plain copy); gate tests/table-button.mjs; reportmre