0hmX/am3352

This code suite comprises TypeScript scripts that analyze, verify, and assemble complex DDR memory interface hardware, focusing on physical routing, via and pad placement, electrical clearance, and physical constraints, often involving precise geometric calculations and consistent provenance tracking.

Version
1.0.5
License
unset
Stars
0

scripts/refresh-ddr-current-metadata.ts

/** Bind reviewed metadata corrections to an unchanged board in a separate artifact. */
import { readFileSync, writeFileSync, cpSync, existsSync } from 'node:fs'
import { resolve, relative } from 'node:path'
import { createHash } from 'node:crypto'
import { objectHash } from './improve-ddr-a9-power-launches'

const [sourceArg, auditArg, outputArg] = process.argv.slice(2)
if (!outputArg) throw Error('Usage: source-board metadata-audit new-output')
const source = resolve(sourceArg), auditDir = resolve(auditArg), out = resolve(outputArg)
if (existsSync(out) || !relative(source, out).startsWith('..')) throw Error('Use a new output outside the source directory')
const read = (p: string) => JSON.parse(readFileSync(p, 'utf8'))
const audit = read(`${auditDir}/report.json`), report = read(`${source}/report.json`)
const candidate = read(`${source}/candidate.circuit.json`), hash = objectHash(candidate)
const assertInputs = () => {
  for (const [p, expected] of Object.entries(audit.inputFileHashes)) {
    if (createHash('sha256').update(readFileSync(p)).digest('hex') !== expected) throw Error(`Audit input changed: ${p}`)
  }
}
assertInputs()
if (audit.currentReportObjectSha256 !== objectHash(report) || audit.candidateCircuitSha256 !== hash || report.candidateCircuitSha256 !== hash) throw Error('Metadata audit is stale')
const contracts = audit.bytes.map((row: any) => {
  const name = row.byte ? 'ram-byte1-exit-contract.json' : 'exit-contract.json'
  const cache = read(`${source}/ram-byte${row.byte}-facing-progress.trace-paths.json`)
  const proposal = read(`${auditDir}/${name}.proposal.json`)
  if (objectHash(cache) !== row.cacheObjectSha256 || objectHash(read(`${source}/${name}`)) !== row.sourceContractObjectSha256 || proposal.candidateCircuitSha256 !== hash || proposal.metadataCorrectionProposal?.sourceContractObjectSha256 !== row.sourceContractObjectSha256 || proposal.metadataCorrectionProposal?.cacheObjectSha256 !== row.cacheObjectSha256) throw Error('Contract/cache binding differs')
  if (!row.zeroEnvelopeGrowth || Object.values(row.copperPaddingGrowthMm).some((v: any) => v > 1e-9)) throw Error('Unexpected envelope growth')
  const { metadataCorrectionProposal, ...contract } = proposal
  return { name, byte: row.byte, cacheHash: objectHash(cache), contract: { ...contract, metadataCorrection: { sourceContractObjectSha256: row.sourceContractObjectSha256, auditObjectSha256: objectHash(audit), copperEnvelope: row.afterE3CopperBounds, copperPaddingGrowthMm: row.copperPaddingGrowthMm } } }
})
if (contracts.length !== 2 || new Set(contracts.map((c: any) => c.byte)).size !== 2) throw Error('Expected both byte contracts')
assertInputs()
cpSync(source, out, { recursive: true })
const write = (name: string, value: any) => writeFileSync(`${out}/${name}`, JSON.stringify(value, null, 2) + '\n')
for (const c of contracts) write(c.name, c.contract)
const currentContracts = Object.fromEntries(contracts.map((c: any) => [c.name, { currentSha256: objectHash(c.contract), cacheSha256: c.cacheHash }]))
const updated = { ...report, priorExitContractProvenance: report.exitContractProvenance, exitContractProvenance: currentContracts, metadataRefresh: { sourceDirectory: source, sourceReportObjectSha256: objectHash(report), auditDirectory: auditDir, auditObjectSha256: objectHash(audit), copperUnchanged: true }, scope: 'Nineteen of fifty signal nets connected; 56 of sixty RAM power launches qualified geometrically. Both current E3 launches adopted with byte0 planar matching retained. Board-specific RAM caches have zero added envelope padding. Current default-adapter E1/E2/clock differences and full electrical/fabrication qualification remain outstanding.' }
if (updated.currentE3Migration && updated.inheritedWebRepair) updated.currentE3Migration = { ...updated.currentE3Migration, planeWebPolicy: { ...updated.currentE3Migration.planeWebPolicy, scope: 'Provisional .127mm copper-web threshold with external .107mm reference-pour clearance; fabrication approval remains outstanding. The two inherited inner3 slivers are repaired in this candidate; see inheritedWebRepair.' } }
write('metadata-refresh-audit.json', audit)
write('metadata-parent-report.json', report)
write('report.json', updated)
if (objectHash(read(`${out}/candidate.circuit.json`)) !== hash || objectHash(read(`${out}/host-bundle.json`)) !== objectHash(read(`${source}/host-bundle.json`))) throw Error('Unexpected copper change')
assertInputs()
console.log(JSON.stringify({ out, candidateCircuitSha256: hash, copperUnchanged: true, currentContracts }))