velxio/test/test_circuit/README.md

55 lines
2.0 KiB
Markdown
Raw Normal View History

feat: electrical simulation via ngspice-WASM (eecircuit-engine) Adds full SPICE-accurate electrical simulation to Velxio, behind a lazy- loaded ⚡ toolbar toggle. Arduino / ESP32 / RP2040 sketches now co-simulate with real analog behaviour: correct voltages on wires, real I–V curves on LEDs, working potentiometers, NTC thermistors read by analogRead(), PWM driving RC filters, transistors, op-amps, diodes, MOSFETs, etc. Engine: eecircuit-engine (ngspice compiled to WebAssembly). Main bundle stays at 2.4 MB; the 20 MB SPICE chunk only loads when the user activates electrical mode. Disabled at build time via VITE_ELECTRICAL_SIM=false. Frontend additions: - simulation/spice/: SpiceEngine wrapper + lazy entry, NetlistBuilder with UnionFind over wires, componentToSpice mapping (24 metadataIds incl. real part numbers: 2N2222, 2N3055, BC547, IRF540, 2N7000, 1N4148, 1N4007, 1N4733, LEDs, NTC, op-amp ideal), CircuitScheduler with debounced coalescing, AVRSpiceBridge for quasi-static co-simulation. - store/useElectricalStore: Zustand slice, feature-flag aware. - components/analog-ui/: ⚡ toolbar toggle + SVG voltage overlay. - components/components-instruments/: Voltmeter, Ammeter probes. - 62 tests (spice-*, netlist-builder, component-to-spice, instruments). Sandbox (test/test_circuit/): 47-test validation sandbox that proved the approach (hand-rolled MNA baseline + ngspice pipeline) before porting to the app. Kept as reference. Docs: docs/wiki/circuit-emulation-*.md (13 engineering pages covering architecture, solvers, components, AVR bridge, gotchas, performance, integration plan, API reference, appendix) + electrical-simulation- user-guide.md (end-user facing). Reference plan: test/test_circuit/plan/phase_8_velxio_implementation.md Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:11:54 +07:00
# test_circuit — sandbox de emulación de circuitos
Sandbox para validar la emulación de circuitos analógicos + digitales + Arduino en JS puro antes de tocar Velxio.
## Estructura
```
test_circuit/
├── plan/ # Documentos de planificación (fases 07)
├── src/
│ ├── solver/ # MNA hand-rolled (legacy, baseline)
│ ├── components/ # Modelos JS (legacy, baseline)
│ ├── avr/ # AVRHarness (avr8js estilo Velxio)
│ └── spice/ # SpiceEngine (ngspice-WASM) + AVRSpiceBridge
├── test/ # Vitest tests
│ ├── passive.test.js # baseline JS
│ ├── transient_rc.test.js # baseline JS
│ ├── diodes.test.js # baseline JS
│ ├── avr_blink.test.js # avr8js con blink.hex
│ ├── e2e_pot_pwm_led.test.js # baseline JS + avr8js
│ ├── e2e_thermistor.test.js # baseline JS + avr8js
│ ├── ngspice_smoke.test.js # ngspice boot
│ ├── spice_passive.test.js # ngspice DC
│ ├── spice_transient.test.js # ngspice .tran
│ ├── spice_ac.test.js # ngspice .ac Bode
│ ├── spice_active.test.js # diodo, BJT, MOSFET, op-amp
│ ├── spice_digital.test.js # lógica behavioral
│ ├── spice_555_astable.test.js # oscilador relajación
│ └── spice_avr_mixed.test.js # co-simulación avr8js ↔ ngspice
├── fixtures/ # .hex pre-compilados / ensamblados a mano
├── autosearch/ # Hallazgos, métricas, propuestas
└── package.json
```
## Correr las pruebas
```bash
cd test/test_circuit
npm install
npm test
```
Por fase:
```bash
npm run test:phase3 # pasivos
npm run test:phase4 # activos (diodos)
npm run test:avr # integración avr8js
npm run test:e2e # end-to-end Arduino + circuito
```
## Alcance
Ver [plan/phase_0_scope.md](plan/phase_0_scope.md).