Files
ycode/scripts/rea/recover-memory-panel.mjs

65 lines
2.7 KiB
JavaScript

// Project the WorkBuddy 5.8.3 MemorySettingsPanel CSS recovered through REA.
// This script only reads an archived REA Evidence record; it never contacts the app.
import assert from 'node:assert/strict'
import { createHash } from 'node:crypto'
import fs from 'node:fs/promises'
import path from 'node:path'
const evidenceId = 'ev_ccbabc0d8507e997eba15aab8b5effa66f7e82d6720c6131bfcd62157b9d6896'
const evidencePath = path.resolve(
process.env.YCODE_MEMORY_EVIDENCE ??
`.tmp/rea-css-evidence/${evidenceId}.json`
)
const outputPath = path.resolve(
'src/renderer/src/components/source-memory-settings-recovered.css'
)
const expectedSourceSha256 = '43e0b0207ff1a91ad6066efc772dad351b2b5e7afe588d38a5ee38537eb01aad'
const expectedSourceBytes = 25213
const evidence = JSON.parse(await fs.readFile(evidencePath, 'utf8'))
assert.equal(evidence.evidence_id, evidenceId, 'REA Evidence identity changed')
assert.equal(evidence.operation, 'inspect_electron_page')
assert.equal(evidence.normalized_result?.styles?.total, 52, 'unexpected WorkBuddy CSS source count')
assert.equal(evidence.normalized_result?.styles?.truncated, false, 'CSS capture was truncated')
assert.equal(evidence.normalized_result?.styles?.source_failures ?? 0, 0, 'CSS source failure')
const matches = evidence.normalized_result.styles.items.filter(item =>
/MemorySettingsPanel-[^/\\]+\.css$/i.test(item.file_path ?? '')
)
assert.equal(matches.length, 1, 'expected exactly one MemorySettingsPanel CSS source')
const source = matches[0].source?.artifact
assert.equal(source?.sha256, expectedSourceSha256, 'MemorySettingsPanel CSS digest changed')
assert.equal(source?.bytes, expectedSourceBytes, 'MemorySettingsPanel CSS byte length changed')
assert.equal(typeof source?.text, 'string', 'MemorySettingsPanel CSS text is unavailable')
const header = [
'/*',
` * REA Evidence ${evidenceId}`,
` * Source ${path.basename(matches[0].file_path)}`,
` * SHA-256 ${expectedSourceSha256}`,
' * The declarations below are the unmodified recovered module source.',
' */',
''
].join('\n')
const output = `${header}${source.text.trim()}\n`
const outputSha256 = createHash('sha256').update(output).digest('hex')
if (process.argv.includes('--check')) {
const current = await fs.readFile(outputPath, 'utf8')
assert.equal(current, output, 'recovered MemorySettingsPanel CSS is stale')
} else {
await fs.mkdir(path.dirname(outputPath), { recursive: true })
await fs.writeFile(outputPath, output)
}
console.log(JSON.stringify({
evidenceId,
sourceFile: path.basename(matches[0].file_path),
sourceSha256: expectedSourceSha256,
sourceBytes: expectedSourceBytes,
output: path.relative(process.cwd(), outputPath).replaceAll('\\', '/'),
outputBytes: Buffer.byteLength(output),
outputSha256
}, null, 2))