Elffuss BraidHub

utopia-ia/elffuss-code public

Lab: what defines a run is locked while it runs, and the light brain uses the IDE's id

- The brain, algorithm and bench radios, the knobs and "Cargar cerebro" stayed
  live during a run. Picking another brain mid-run switched the remaining cases
  (with "Reglas" the scripted solver solves them) and the run was saved under
  the brain picked last. They are disabled while a run is going, and the saved
  run carries the configuration taken when it started.
- The Lab's light brain was 'onnx', an id the IDE no longer offers (b7d7db0):
  "Abrir el IDE con este cerebro" stored it, and the IDE dropped it at start
  and came up with no model. It is now 'onnx:qwen3.5-0.8b', which loadBrain()
  configures, and the Lab starts with the IDE's saved model only when it is one
  of its brains (a saved 'onnx:...' id used to leave no radio selected and fail
  to load).

tests/labstop.mjs checks that the choices are disabled mid-run, that clicking
another brain mid-run changes nothing, and that they are free again at the end.
tests/lab-ux.mjs expects the new id and checks that the IDE offers it.
Changesetab2541aae10475f088a4960a57953452abed03621497ddfeab77fc49d21b1276
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-11 15:10 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 15:10 +02:00
Parents86dfa66543e3

Browse the files at this changeset

3 files changed

modified tests/lab-ux.mjs +12 −2
@@ -63,7 +63,7 @@
6363 ok('2 · cambiar de cerebro descarta el que estaba cargado', /sin cargar/.test(e.led), e.led);
6464 await p.locator('#benches label').nth(2).click(); // juegos: necesita cerebro
6565 e = await estado();
66-ok('2 · con un banco que necesita cerebro, «Lanzar» espera a que se cargue', e.run && /Carga el cerebro «onnx»/.test(e.hint), JSON.stringify(e));
66+ok('2 · con un banco que necesita cerebro, «Lanzar» espera a que se cargue', e.run && /Carga el cerebro «onnx:qwen3\.5-0\.8b»/.test(e.hint), JSON.stringify(e));
6767 await p.click('#btn-load');
6868 await p.waitForFunction(() => /modelo: onnx/.test(document.querySelector('#led-model').textContent), null, { timeout: 5000 });
6969 e = await estado();
@@ -99,7 +99,17 @@
9999 await p.click('#btn-launch');
100100 const r5 = await p.evaluate(() => ({ model: localStorage.getItem('elffusscode.model'), ctx: localStorage.getItem('elffusscode.ctxopts'), algo: localStorage.getItem('elffusscode.algo') }));
101101 ok('5 · el botón dice lo que hace', /Abrir el IDE con este cerebro/.test(etiqueta), etiqueta);
102-ok('5 · guarda el cerebro y no deja claves que el IDE no lee', r5.model === 'onnx' && r5.ctx === null && r5.algo === null, JSON.stringify(r5));
102+ok('5 · guarda el cerebro y no deja claves que el IDE no lee', r5.model === 'onnx:qwen3.5-0.8b' && r5.ctx === null && r5.algo === null, JSON.stringify(r5));
103+// …y ese id es uno que el IDE ofrece: el ligero era 'onnx' a secas, que el IDE
104+// ya no tiene, así que lo descartaba al arrancar (y se quedaba sin modelo).
105+{
106+ const ide2 = await ctx.newPage({ viewport: { width: 1400, height: 900 } });
107+ await ide2.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
108+ await ide2.waitForFunction(() => document.querySelectorAll('#model-select option').length > 0, null, { timeout: 15000 });
109+ const ids = await ide2.$$eval('#model-select option', os => os.map(o => o.value));
110+ ok('5 · el IDE ofrece ese mismo cerebro', ids.includes(r5.model), JSON.stringify({ lab: r5.model, ide: ids }));
111+ await ide2.close();
112+}
103113
104114 console.log('\n errores JS:', errs[0] || 'ninguno');
105115 ok('sin errores de página', errs.length === 0, errs.join(' | '));
modified tests/labstop.mjs +13 −0
@@ -49,6 +49,15 @@
4949 await p.click('#btn-run');
5050 await p.waitForFunction(() => (window.__labProv?.llamadas || 0) >= 1, null, { timeout: 5000 }).catch(() => {});
5151 await p.waitForTimeout(300); // generando el juego
52+// Mientras corre, cerebro, algoritmo, banco y perillas no se pueden cambiar:
53+// antes un clic en otro cerebro a mitad cambiaba los casos que quedaban y la
54+// corrida se guardaba con la etiqueta del último elegido.
55+const enMarcha = await p.evaluate(() => ({
56+ bloqueados: [...document.querySelectorAll('#brains input, #algos input, #benches input, #ctx-knobs input')].map(i => i.disabled),
57+ cargar: document.getElementById('btn-load').disabled,
58+}));
59+await p.locator('#brains label').nth(0).click({ force: true, timeout: 2000 }).catch(() => {}); // «Reglas», a mitad
60+const cerebroAMitad = await p.evaluate(() => document.getElementById('brain-tag').textContent);
5261 await p.evaluate(() => { window.__labParado = true; });
5362 await p.click('#btn-stop');
5463 const termino = await p.waitForFunction(() => !document.getElementById('btn-run').disabled, null, { timeout: 15000 }).then(() => true).catch(() => false);
@@ -62,7 +71,11 @@
6271 ranking: document.getElementById('rank-tag').textContent,
6372 }));
6473 const r = await estado();
74+const libres = await p.evaluate(() => [...document.querySelectorAll('#brains input, #benches input')].every(i => !i.disabled) && !document.getElementById('btn-load').disabled);
6575 ok('la corrida estaba generando con el cerebro de prueba', r.st?.llamadas >= 1, `${r.st?.llamadas} llamadas`);
76+ok('mientras corre, cerebro, algoritmo, banco y perillas están bloqueados', enMarcha.bloqueados.length > 4 && enMarcha.bloqueados.every(Boolean) && enMarcha.cargar, JSON.stringify(enMarcha));
77+ok(' …y un clic en otro cerebro a mitad no lo cambia', cerebroAMitad === 'onnx:qwen3.5-0.8b', cerebroAMitad);
78+ok(' …y al terminar se pueden volver a elegir', libres);
6679 ok('■ corta la inferencia en curso (el modelo recibe la parada)', r.st?.abortadas === 1 && r.st?.terminadas === 0, JSON.stringify(r.st));
6780 ok(' …y no se lanza ninguna inferencia más', r.st?.trasParar === 0, `${r.st?.trasParar} tras parar`);
6881 ok('la corrida termina (▶ vuelve a estar disponible)', termino);
modified web/js/lab.js +23 −5
@@ -18,7 +18,7 @@
1818
1919 // ─────────────────────────── estado ───────────────────────────
2020 const S = {
21- brain: localStorage.getItem('elffusscode.model') || 'rules',
21+ brain: 'rules', // el del IDE si el Lab lo conoce (ver BRAINS, abajo)
2222 algo: 'directo',
2323 algoOpts: { rounds: 1, chunkTokens: 1800, maxChunks: 24 },
2424 ctx: {}, // overrides sobre DEFAULTS
@@ -67,13 +67,19 @@
6767 ['juegos', 'Juegos (generar y jugar)', 'Genera un juego con el algoritmo elegido, lo ejecuta y lo puntúa: carga sin errores, arranca, se mueve y aguanta jugando.'],
6868 ];
6969
70+// Los ids son ids del IDE («Abrir el IDE con este cerebro» los guarda tal
71+// cual). El ligero era 'onnx' a secas, un id que el IDE ya no ofrece: el IDE lo
72+// descartaba al arrancar y se quedaba sin modelo.
7073 const BRAINS = [
7174 ['rules', 'Reglas (sin GPU)', 'Determinista. Valida el arnés sin bajar pesos.'],
72- ['onnx', 'Qwen3.5-0.8B (CPU/wasm)', 'El ligero, por transformers.js.'],
75+ ['onnx:qwen3.5-0.8b', 'Qwen3.5-0.8B (CPU/wasm)', 'El ligero, por transformers.js.'],
7376 ['litert:gemma-e2b', 'Gemma-4 E2B (~2 GB)', 'WebGPU.'],
7477 ['litert:gemma-e4b', 'Gemma-4 E4B (~3 GB)', 'WebGPU. El mejor.'],
7578 ];
7679
80+// Arranca con el cerebro que tenga el IDE, si es uno de los del Lab.
81+{ const delIde = localStorage.getItem('elffusscode.model'); if (BRAINS.some(([id]) => id === delIde)) S.brain = delIde; }
82+
7783 // ─────────────────────────── consola ───────────────────────────
7884 function log(msg, cls = '') {
7985 const t = new Date().toTimeString().slice(0, 8);
@@ -182,7 +188,10 @@
182188 try {
183189 let mod;
184190 if (id === 'rules') mod = await import('./providers/rules.js');
185- else if (id === 'onnx') mod = await import('./providers/onnx.js');
191+ else if (id.startsWith('onnx:')) {
192+ mod = await import('./providers/onnx.js');
193+ mod.configure?.(id.slice(5));
194+ }
186195 else if (id.startsWith('litert:')) {
187196 mod = await import('./providers/litert.js');
188197 mod.configure(id.split(':')[1]);
@@ -473,9 +482,18 @@
473482 }
474483
475484 // ─────────────────────────── orquestación ───────────────────────────
485+// Mientras corre, lo que define la corrida no se puede tocar. Antes cerebros y
486+// bancos seguían activos: elegir otro cerebro a mitad cambiaba los casos que
487+// quedaban (con «Reglas» resuelve el guion) y la corrida se guardaba con la
488+// etiqueta del último elegido. Y lo que se guarda es lo que había AL EMPEZAR.
489+const ELECCION = '#brains input, #algos input, #benches input, #algo-knobs input, #ctx-knobs input, #ctx-all, #ctx-none, #ctx-def, #btn-load';
490+function bloqueaEleccion(si) { for (const n of document.querySelectorAll(ELECCION)) n.disabled = si; }
491+
476492 async function run() {
477493 if (S.running) return;
478494 S.running = true; S.abort = false; S.aborter = new AbortController();
495+ const cfg = { bench: S.bench, algo: S.algo, algoOpts: { ...S.algoOpts }, brain: S.brain, ctx: { ...DEFAULTS, ...S.ctx } };
496+ bloqueaEleccion(true);
479497 $('#btn-run').disabled = true; $('#btn-stop').disabled = false;
480498 setLed('#led-run', 'busy', 'ejecutando ' + S.bench);
481499 tiles({}); prog(0, 1, 'preparando…');
@@ -527,8 +545,7 @@
527545 } else if (out) {
528546 tiles(out.resumen);
529547 S.run = {
530- bench: S.bench, algo: S.algo, algoOpts: { ...S.algoOpts }, brain: S.brain,
531- ctx: { ...DEFAULTS, ...S.ctx }, resumen: out.resumen, casos: out.filas,
548+ ...cfg, resumen: out.resumen, casos: out.filas,
532549 duracionSegs: Math.round((Date.now() - t0) / 1000), cuando: new Date().toISOString(),
533550 };
534551 log('✔ terminado: ' + JSON.stringify(out.resumen), 'a');
@@ -539,6 +556,7 @@
539556 else setLed('#led-run', error ? 'err' : 'on', error ? 'con fallo' : 'listo');
540557 prog(1, 1, parado ? (out ? 'parado (parcial)' : 'parado') : error ? 'abortado' : 'completado');
541558 S.running = false; S.aborter = null; $('#btn-stop').disabled = true;
559+ bloqueaEleccion(false);
542560 pintarRun();
543561 }
544562