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
tests/ddr-a9-power-launches.test.ts
import {test,expect} from 'bun:test'
import {readFileSync,existsSync} from 'node:fs'
import {objectHash,validateDeclaredDdrReplacements} from '../scripts/improve-ddr-a9-power-launches'
const fixture=()=>{
const parent=[{type:'pcb_trace',pcb_trace_id:'t',route:[{x:0,y:0},{x:2,y:0}]},{type:'pcb_smtpad',pcb_smtpad_id:'p',x:0,y:0}]
const child=structuredClone(parent);child[0]!.route![1]!.x=1
const manifest={parentCircuitSha256:objectHash(parent),candidateCircuitSha256:objectHash(child),replacements:[{id:'pcb_trace:t',before:parent[0],after:child[0],beforeSha256:objectHash(parent[0]),afterSha256:objectHash(child[0])}]}
return {parent,child,manifest}
}
test('explicit replacement witnesses validate exact before and after geometry',()=>{const f=fixture();expect(validateDeclaredDdrReplacements(f.parent,f.child,f.manifest).allOtherElementsExact).toBe(true)})
test('undeclared support pad modification is rejected even with updated whole-circuit hash',()=>{const f=fixture();f.child[1]!.x=1;f.manifest.candidateCircuitSha256=objectHash(f.child);expect(()=>validateDeclaredDdrReplacements(f.parent,f.child,f.manifest)).toThrow('Undeclared support change')})
test('stale before witness and duplicate declarations fail closed',()=>{const f=fixture();f.manifest.replacements[0]!.beforeSha256='stale';expect(()=>validateDeclaredDdrReplacements(f.parent,f.child,f.manifest)).toThrow();const g=fixture();g.manifest.replacements.push(g.manifest.replacements[0]!);expect(()=>validateDeclaredDdrReplacements(g.parent,g.child,g.manifest)).toThrow()})
test.skipIf(!existsSync('dist/ddr-integrated-nine-power52/ram-power-launch-audit.json'))('isolated A9 artifact has 52 actual launches, preserves nine hosts and support, and changes exactly six traces/two planes',()=>{
const read=(p:string)=>JSON.parse(readFileSync(p,'utf8')),base='dist/ddr-integrated-nine',dir=base+'-power52',parent=read(base+'/candidate.circuit.json'),child=read(dir+'/candidate.circuit.json'),m=read(dir+'/original-copper-replacements.json'),report=read(dir+'/report.json'),audit=read(dir+'/ram-power-launch-audit.json')
expect(validateDeclaredDdrReplacements(parent,child,m).declaredReplacementCount).toBe(8)
expect(readFileSync(dir+'/host-bundle.json').equals(readFileSync(base+'/host-bundle.json'))).toBe(true)
expect(m.replacements.filter((r:any)=>r.before.type==='pcb_trace')).toHaveLength(6)
const ground=m.replacements.filter((r:any)=>r.reason.startsWith('Retain pad'));expect(ground).toHaveLength(4)
for(const r of ground)expect(r.after.route).toEqual(r.before.route.slice(0,3))
expect(audit.total).toBe(60);expect(audit.launchQualified).toBe(52);expect(audit.planeConnected).toBe(52)
const a9=audit.rows.filter((r:any)=>r.terminal==='VDD_A9');expect(a9).toHaveLength(2)
for(const a of a9){expect(a.actualPadToContactViaMm).toBeCloseTo(.55,9);expect(a.connectionVia.annulusSamplesInPlane).toBe(32);expect(audit.rows.filter((r:any)=>r.connectionVia&&Math.hypot(r.connectionVia.x-a.connectionVia.x,r.connectionVia.y-a.connectionVia.y)<1e-7)).toHaveLength(1)}
expect(report.physical.errors).toHaveLength(0);expect(report.physical.violations).toHaveLength(0);expect(report.physical.angles.valid).toBe(true);expect(report.physical.joinedBends).toHaveLength(0);expect(report.physical.connectivity.filter((c:any)=>c.connected)).toHaveLength(9);expect(report.externalAliasesUsed).toBe(false)
})
test.skipIf(!existsSync('dist/ddr-integrated-ten-power52/ram-power-launch-audit.json'))('ten-host combined candidate preserves DQ12 transition and independently proves 52 launches',()=>{
const read=(p:string)=>JSON.parse(readFileSync(p,'utf8')),base='dist/ddr-integrated-ten',dir=base+'-power52',parent=read(base+'/candidate.circuit.json'),child=read(dir+'/candidate.circuit.json'),m=read(dir+'/original-copper-replacements.json'),r=read(dir+'/report.json')
expect(validateDeclaredDdrReplacements(parent,child,m).valid).toBe(true)
expect(readFileSync(dir+'/host-bundle.json').equals(readFileSync(base+'/host-bundle.json'))).toBe(true)
expect(r.preservedHostCount).toBe(10);expect(r.physical.connectivity.filter((c:any)=>c.connected)).toHaveLength(10)
expect(r.physical.errors).toHaveLength(0);expect(r.physical.violations).toHaveLength(0);expect(r.physical.angles.valid).toBe(true);expect(r.physical.joinedBends).toHaveLength(0)
expect(read(dir+'/ram-power-launch-audit.json').launchQualified).toBe(52)
expect(r.planeAudit.every((p:any)=>p.viaContacts.every((c:any)=>c.annulusSamplesInPlane===32))).toBe(true)
})