Files
89acf1e1fa fix(plugins): release diagnostic logs after successful uninstall (#21185)
* fix(plugins): retire log owners after successful uninstall

* fix: address memory PR review regressions and withdraw false positives

* fix(plugins): fence stale activation after uninstall

* chore: allow durable plugin uninstall audit evidence

---------

Co-authored-by: m4air <m4air@Mac.localdomain>
Co-authored-by: Neil <neil@stably.ai>
2026-09-19 14:53:28 -07:00

59 lines
2.5 KiB
JavaScript

const assert = require('node:assert/strict')
const { readFileSync, existsSync } = require('node:fs')
const { createHash } = require('node:crypto')
const path = require('node:path')
const { parsePatch, applyPatch, reversePatch } = require('diff')
const root = path.resolve(__dirname, '../../..')
const canonicalLf = (text) => text.replaceAll('\r\n', '\n')
const readText = (name) => canonicalLf(readFileSync(name, 'utf8'))
const sha256 = (text) => createHash('sha256').update(text).digest('hex')
function loadSources({
variant = process.env.ORCA_PLUGIN_LOG_VARIANT ?? 'fixed',
read = readText,
exists = existsSync
} = {}) {
assert.ok(['before', 'fixed'].includes(variant))
const versions = JSON.parse(read(path.join(__dirname, 'source-versions.json')))
const patches = (name) =>
new Map(
parsePatch(canonicalLf(read(path.join(__dirname, name))))
.filter((patch) => patch.newFileName)
.map((patch) => [patch.newFileName.slice(2), patch])
)
const fixes = patches('fix.patch')
const contexts = patches('dependency-context.patch')
const sources = new Map()
const hashes = {}
for (const [relative, entry] of Object.entries(versions.sources)) {
const filename = path.join(root, relative)
let source = exists(filename) ? canonicalLf(read(filename)) : null
let hash = source === null ? null : sha256(source)
if (hash !== entry.fixed && hash === entry.main && contexts.has(relative)) {
source = applyPatch(source ?? '', contexts.get(relative))
assert.notEqual(source, false, `Dependency context failed: ${relative}`)
hash = sha256(source)
}
assert.equal(hash, entry.fixed, `Source drift: ${relative}`)
if (variant === 'before' && fixes.has(relative)) {
source = applyPatch(source, reversePatch(fixes.get(relative)))
assert.notEqual(source, false, `Reverse fix failed: ${relative}`)
}
if (variant === 'before' && entry.before === null) {
assert.equal(source, '')
continue
}
assert.equal(sha256(source), variant === 'before' ? entry.before : entry.fixed)
sources.set(path.join(root, relative), source)
hashes[relative] = sha256(source)
}
for (const [relative, expected] of Object.entries(versions.dependencies)) {
assert.equal(
sha256(canonicalLf(read(path.join(root, relative)))),
expected,
`Dependency drift: ${relative}`
)
}
return { root, sources, hashes, variant, versions }
}
module.exports = { loadSources, canonicalLf, readText, sha256 }