Elffuss BraidHub

utopia-ia/elffuss-code public

The Lab is reachable from the IDE and runs what it shows

- View › Elffuss Lab and a palette command open lab.html in a new tab;
  there was no link to it anywhere in the IDE.
- Picking another brain in the Lab drops the loaded provider (its LED says
  "sin cargar"), and Run stays disabled with a hint while a bench that needs
  a model (games, SWE with a model) has no loaded provider for the selected
  brain. A run labelled "onnx" used to execute with whatever was loaded
  before, rules included, and was saved to the ranking with that label. A
  load that finishes after you picked another brain is not used.
- Switching bench repaints that bench's ranking (it kept showing the
  previous one).
- ■ in the middle of a run reports "parado (parcial)" (or "parado" when
  nothing finished), logs the result as PARCIAL, uses a neutral LED instead
  of "listo". It used to say "✔ terminado" and "completado" with partial
  totals.
- "Lanzar el IDE con esta configuración" wrote algo and ctxopts keys that
  the IDE never reads. It is now "Abrir el IDE con este cerebro": it stores
  the brain (the Lab's ids are IDE ids), removes the dead keys, and says
  that algorithm and knobs only apply inside the Lab; the knobs' hint says
  the same.

tests/lab-ux.mjs (stand-in onnx provider served with page.route): the menu
and palette open the Lab, a brain change invalidates the loaded one and Run
waits for the right one, the ranking follows the bench, a stopped run is
partial and marked so, and the launch button only stores the brain. Against
the previous code it fails from the first check. labstop.mjs now expects
"parado" instead of "abortado" for a stopped games run.

b0da3d5 already keeps a stopped run out of the ranking (its partial score
would compete with complete runs even when labelled). That stricter rule
wins: the tiles show PARCIAL and the log says
the partial result does not enter the ranking, "Guardar" refuses it, and
the "PARCIAL (parado)" ranking label is gone. lab-ux.mjs check 4 and the
SWE check in labstop.mjs follow that ("parado (parcial)" for a run with
partial results).
Changesetfa92ebd9325b774ca5d301ab0eb7db17b6c95841f2b3374235a141d7c461f53e
AuthorKikoCis <kikocisneros@gmail.com> · 2026-10-10 16:23 +02:00
CommitterKikoCis <kikocisneros@gmail.com> · 2026-10-11 14:14 +02:00
Parents6da87834a6d9

Browse the files at this changeset

6 files changed

added tests/lab-ux.mjs +108 −0
@@ -0,0 +1,108 @@
1+// Elffuss Lab: que lo que se ve sea lo que corre.
2+//
3+// 1. Desde el IDE se llega al Lab (View › Elffuss Lab y la paleta); antes
4+// solo escribiendo la URL.
5+// 2. Cambiar de cerebro en la lista descarta el cargado: antes una corrida
6+// «con onnx» se ejecutaba con Reglas. «Lanzar» espera a que el cerebro
7+// elegido esté cargado cuando el banco lo necesita.
8+// 3. Cambiar de banco repinta el ranking de ese banco.
9+// 4. ■ a mitad: «parado (parcial)», no «✔ terminado/completado», y no
10+// entra en el ranking.
11+// 5. «Abrir el IDE con este cerebro» hace solo eso (antes prometía aplicar
12+// algoritmo y perillas que el IDE no lee).
13+// El cerebro «onnx» es de mentira (page.route sirve un providers/onnx.js propio).
14+//
15+// BASE=http://127.0.0.1:8898 node tests/lab-ux.mjs
16+import { chromium } from 'playwright';
17+const BASE = process.env.BASE || 'http://localhost:8799';
18+let fails = 0; const ok = (n, c, e = '') => { console.log((c ? '✅' : '❌') + ' ' + n + (e ? ' — ' + e : '')); if (!c) fails++; };
19+
20+const FALSO = `export let name = 'falso'; export async function load() {}
21+export async function chat() { return 'hecho'; }`;
22+
23+const b = await chromium.launch();
24+const ctx = await b.newContext({ locale: 'es-ES' });
25+await ctx.addInitScript(() => { try { localStorage.setItem('elffusscode.model', 'rules'); } catch {} });
26+const errs = [];
27+
28+// 1 · el IDE lleva al Lab
29+const ide = await ctx.newPage({ viewport: { width: 1400, height: 900 } });
30+ide.on('pageerror', e => errs.push(e.message.slice(0, 160)));
31+await ide.goto(BASE + '/?test-opfs', { waitUntil: 'domcontentloaded' });
32+await ide.waitForFunction(() => window.elffussClaw?.conv?.getActive?.(), null, { timeout: 15000 });
33+await ide.evaluate(() => { window.__abiertas = []; window.open = (u) => { window.__abiertas.push(String(u)); return null; }; });
34+await ide.click('#menubar button[data-menu="view"]');
35+const enMenu = await ide.locator('#topmenu .menu-item', { hasText: 'Elffuss Lab' }).count();
36+await ide.locator('#topmenu .menu-item', { hasText: 'Elffuss Lab' }).click().catch(() => {});
37+await ide.keyboard.press(process.platform === 'darwin' ? 'Meta+Shift+P' : 'Control+Shift+P');
38+await ide.fill('#pal-input', '>Lab');
39+await ide.waitForTimeout(150);
40+await ide.press('#pal-input', 'Enter');
41+const abiertas = await ide.evaluate(() => window.__abiertas);
42+ok('1 · View › Elffuss Lab abre el Lab', enMenu === 1 && abiertas[0] === 'lab.html', JSON.stringify(abiertas));
43+ok('1 · …y también la paleta', abiertas[1] === 'lab.html', JSON.stringify(abiertas));
44+await ide.close();
45+
46+const p = await ctx.newPage({ viewport: { width: 1300, height: 900 } });
47+p.on('pageerror', e => errs.push(e.message.slice(0, 160)));
48+await p.route('**/js/providers/onnx.js*', route => route.fulfill({ status: 200, contentType: 'text/javascript', body: FALSO }));
49+await p.goto(BASE + '/lab.html', { waitUntil: 'domcontentloaded' });
50+await p.waitForTimeout(600);
51+const estado = () => p.evaluate(() => ({
52+ led: document.querySelector('#led-model').textContent.trim(), run: document.getElementById('btn-run').disabled,
53+ hint: document.getElementById('run-hint').textContent, prog: document.getElementById('prog-txt').textContent,
54+ rank: document.getElementById('rank-tag').textContent, log: document.getElementById('log').textContent,
55+ ultima: document.getElementById('log').lastElementChild?.textContent || '',
56+}));
57+
58+// 2 · cargar Reglas y cambiar a onnx
59+await p.click('#btn-load'); // Reglas
60+await p.waitForFunction(() => /modelo: rules/.test(document.querySelector('#led-model').textContent), null, { timeout: 5000 });
61+await p.locator('#brains label').nth(1).click(); // onnx
62+let e = await estado();
63+ok('2 · cambiar de cerebro descarta el que estaba cargado', /sin cargar/.test(e.led), e.led);
64+await p.locator('#benches label').nth(2).click(); // juegos: necesita cerebro
65+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));
67+await p.click('#btn-load');
68+await p.waitForFunction(() => /modelo: onnx/.test(document.querySelector('#led-model').textContent), null, { timeout: 5000 });
69+e = await estado();
70+ok('2 · cargado el elegido, «Lanzar» se habilita', !e.run && !e.hint, JSON.stringify(e));
71+
72+// 3 · el ranking sigue al banco
73+await p.locator('#benches label').nth(0).click(); // contexto
74+await p.click('#btn-run');
75+await p.waitForFunction(() => /completado/.test(document.getElementById('prog-txt').textContent), null, { timeout: 15000 });
76+await p.click('#btn-save');
77+e = await estado();
78+ok('3 · el ranking de «contexto» tiene la corrida guardada', /1 corridas · contexto/.test(e.rank), e.rank);
79+await p.locator('#benches label').nth(1).click(); // swe
80+e = await estado();
81+ok('3 · al cambiar a «swe» el ranking es el de swe', /sin corridas de swe/.test(e.rank), e.rank);
82+
83+// 4 · ■ a mitad: parcial
84+await p.locator('#benches label').nth(0).click(); // contexto otra vez
85+await p.evaluate(() => { document.getElementById('btn-run').click(); document.getElementById('btn-stop').click(); });
86+await p.waitForFunction(() => !document.getElementById('btn-stop').disabled === false && /parado/.test(document.getElementById('prog-txt').textContent), null, { timeout: 15000 }).catch(() => {});
87+e = await estado();
88+ok('4 · parado a mitad: dice «parado (parcial)», no «completado»', e.prog === 'parado (parcial)' && /parado: resultado PARCIAL/.test(e.ultima) && !/terminado/.test(e.ultima), e.prog + ' · ' + e.ultima.slice(0, 90));
89+// Parcial no es comparable: «Guardar» no la mete en el ranking (su porcentaje
90+// competiría con el de corridas completas aunque fuera marcada).
91+const filasAntes = await p.evaluate(() => document.querySelectorAll('#rank-body tr').length);
92+await p.click('#btn-save');
93+const r4 = await p.evaluate(() => ({ filas: document.querySelectorAll('#rank-body tr').length, ultima: document.getElementById('log').lastElementChild?.textContent || '' }));
94+ok('4 · la corrida parada no entra en el ranking, y se dice', r4.filas === filasAntes && /no entra en el ranking/.test(r4.ultima), JSON.stringify(r4));
95+
96+// 5 · abrir el IDE con este cerebro
97+await p.evaluate(() => { window.open = () => null; localStorage.setItem('elffusscode.ctxopts', '{"MMR":false}'); });
98+const etiqueta = await p.locator('#btn-launch').textContent();
99+await p.click('#btn-launch');
100+const r5 = await p.evaluate(() => ({ model: localStorage.getItem('elffusscode.model'), ctx: localStorage.getItem('elffusscode.ctxopts'), algo: localStorage.getItem('elffusscode.algo') }));
101+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));
103+
104+console.log('\n errores JS:', errs[0] || 'ninguno');
105+ok('sin errores de página', errs.length === 0, errs.join(' | '));
106+console.log(fails ? `\n❌ ${fails} FALLO(S)` : '\n✅ LAB: LO QUE SE VE ES LO QUE CORRE');
107+await b.close();
108+process.exit(fails ? 1 : 0);
modified tests/labstop.mjs +1 −1
@@ -88,7 +88,7 @@
8888 await p.waitForTimeout(200);
8989 const s = await estado();
9090 ok('SWE: la corrida parada termina, con la primera tarea ya contada', terminoSwe && /"resolved":"\d+\/1"/.test(s.log), '…' + s.log.slice(-160));
91-ok('SWE parado: el progreso dice «parado» y el piloto «parado» (neutro)', s.prog === 'parado' && s.led.cls.trim() === 'led' && s.led.txt === 'parado', `${s.prog} · ${JSON.stringify(s.led)}`);
91+ok('SWE parado: el progreso dice «parado (parcial)» y el piloto «parado» (neutro)', s.prog === 'parado (parcial)' && s.led.cls.trim() === 'led' && s.led.txt === 'parado', `${s.prog} · ${JSON.stringify(s.led)}`);
9292 ok(' …y no se anuncia como «✔ terminado»', !s.log.includes('✔ terminado'), '…' + s.log.slice(-120));
9393 ok(' …y «Guardar» no la mete en el ranking', s.ranking === rankingAntes && /no entra en el ranking/.test(s.log), `${rankingAntes} → ${s.ranking}`);
9494
modified web/js/i18n.js +2 −0
@@ -182,6 +182,7 @@
182182 cfgCant_leader: "Otra pestaña lleva el cerebro: hazlo desde ahí.",
183183 avatarLabel: "Mente de Elffuss",
184184 setTelSend: "Enviar", setTelSending: "Enviando…",
185+ mLab: "Elffuss Lab (banco de pruebas)",
185186 clearModelsConfirm: "Vas a borrar {size} de modelos guardados en este navegador.\n\nNo se pierde nada tuyo: solo los pesos descargados. La próxima vez habrá que bajarlos otra vez.\n\n¿Seguir?",
186187 clearModelsShared: "Ojo: el almacén compartido de Elffuss no se pudo consultar desde aquí; puede quedar algo guardado ahí.",
187188 clearModelsDone: "💾 Liberados {size}.", clearModelsFailed: "No se pudo vaciar: {what}.",
@@ -365,6 +366,7 @@
365366 cfgCant_leader: "Another tab runs the brain: do it from there.",
366367 avatarLabel: "Elffuss Mind",
367368 setTelSend: "Send", setTelSending: "Sending…",
369+ mLab: "Elffuss Lab (test bench)",
368370 clearModelsConfirm: "You are about to delete {size} of models stored in this browser.\n\nNothing of yours is lost: only the downloaded weights. Next time they will be downloaded again.\n\nContinue?",
369371 clearModelsShared: "Note: Elffuss's shared store could not be checked from here; something may remain stored there.",
370372 clearModelsDone: "💾 Freed {size}.", clearModelsFailed: "Couldn't clear: {what}.",
modified web/js/lab.js +52 −13
@@ -24,6 +24,7 @@
2424 ctx: {}, // overrides sobre DEFAULTS
2525 bench: 'contexto',
2626 provider: null,
27+ providerFor: null, // qué cerebro es el que está cargado de verdad
2728 running: false, abort: false,
2829 aborter: null, // la parada de la corrida en curso (botón ■)
2930 run: null, // { bench, casos:[], métricas:{} } — la traza
@@ -187,15 +188,43 @@
187188 mod.configure(id.split(':')[1]);
188189 }
189190 if (mod.load) await mod.load(s => { $('#load-state').textContent = String(s).slice(0, 60); });
190- S.provider = mod;
191- setLed('#led-model', 'on', 'modelo: ' + id);
192191 $('#load-state').textContent = '';
193- log('cerebro listo: ' + id, 'a');
192+ // Mientras cargaba se eligió otro en la lista: este no se usa.
193+ if (S.brain !== id) log('cargado ' + id + ', pero ya está elegido «' + S.brain + '»: pulsa «Cargar cerebro» para ese', 'w');
194+ else {
195+ S.provider = mod;
196+ S.providerFor = id;
197+ setLed('#led-model', 'on', 'modelo: ' + id);
198+ log('cerebro listo: ' + id, 'a');
199+ }
194200 } catch (e) {
195201 setLed('#led-model', 'err', 'fallo al cargar');
196202 log('no se pudo cargar el cerebro: ' + e.message, 'e');
197203 }
198204 $('#btn-load').disabled = false;
205+ pintarRun();
206+}
207+
208+// ¿Hace falta un cerebro CARGADO para este banco? El de contexto mide el
209+// compresor (sin modelo) y el SWE con «Reglas» usa un solucionador de guion.
210+const necesitaCerebro = () => S.bench === 'juegos' || (S.bench === 'swe' && S.brain !== 'rules');
211+// «Lanzar» solo se puede si el cerebro elegido es el que está cargado: antes
212+// cambiar de cerebro en la lista no tocaba el proveedor cargado, y una corrida
213+// «con onnx» se ejecutaba en realidad con Reglas (y se guardaba con esa
214+// etiqueta en el ranking).
215+function pintarRun() {
216+ const falta = necesitaCerebro() && S.providerFor !== S.brain;
217+ $('#btn-run').disabled = S.running || falta;
218+ $('#run-hint').textContent = falta ? 'Carga el cerebro «' + S.brain + '» antes de lanzar este banco.' : '';
219+}
220+function elegirCerebro(id) {
221+ S.brain = id;
222+ $('#brain-tag').textContent = id;
223+ if (S.providerFor !== id) {
224+ S.provider = null; S.providerFor = null;
225+ setLed('#led-model', '', 'modelo: sin cargar (' + id + ')');
226+ }
227+ pintarRun();
199228 }
200229
201230 // ═══════════════ BANCO 1 · contexto (determinista, sin GPU) ═══════════════
@@ -486,13 +515,15 @@
486515 // «listo», y entraba en S.run: «Guardar» la puntuaba con el denominador
487516 // recortado (parar tras k tareas resueltas daba k/k = 100 %). Y la de juegos,
488517 // que para con una excepción, encendía el piloto rojo «con fallo». Lo medido
489- // se enseña como parcial, pero no se puede guardar en el ranking.
518+ // se enseña como PARCIAL, pero no se puede guardar en el ranking: marcarla
519+ // «parcial» en la tabla no basta, su porcentaje seguiría compitiendo con los
520+ // de corridas completas.
490521 const parado = S.abort;
491522 S.ultimaParada = parado;
492523 if (out && parado) {
493- tiles(out.resumen);
524+ tiles({ estado: { v: 'PARCIAL', warn: true }, ...out.resumen });
494525 S.run = null;
495- log('parcial (parado, no entra en el ranking): ' + JSON.stringify(out.resumen), 'w');
526+ log('■ parado: resultado PARCIAL (' + out.filas.length + ' casos, no entra en el ranking) ' + JSON.stringify(out.resumen), 'w');
496527 } else if (out) {
497528 tiles(out.resumen);
498529 S.run = {
@@ -506,8 +537,9 @@
506537 }
507538 if (parado) setLed('#led-run', '', 'parado'); // piloto neutro, como en reposo
508539 else setLed('#led-run', error ? 'err' : 'on', error ? 'con fallo' : 'listo');
509- prog(1, 1, parado ? 'parado' : error ? 'abortado' : 'completado');
510- S.running = false; S.aborter = null; $('#btn-run').disabled = false; $('#btn-stop').disabled = true;
540+ prog(1, 1, parado ? (out ? 'parado (parcial)' : 'parado') : error ? 'abortado' : 'completado');
541+ S.running = false; S.aborter = null; $('#btn-stop').disabled = true;
542+ pintarRun();
511543 }
512544
513545 // ─────────────────── historial y ranking, en local ───────────────────
@@ -577,9 +609,11 @@
577609 }
578610
579611 // ─────────────────────────── arranque ───────────────────────────
580-radio($('#brains'), BRAINS, S.brain, id => { S.brain = id; $('#brain-tag').textContent = id; });
612+radio($('#brains'), BRAINS, S.brain, elegirCerebro);
581613 radio($('#algos'), ALGOS, S.algo, id => { S.algo = id; $('#algo-tag').textContent = id; algoKnobs(); });
582-radio($('#benches'), BENCHES, S.bench, id => { S.bench = id; $('#bench-tag').textContent = id; });
614+// Cambiar de banco repinta el ranking de ESE banco (antes seguía enseñando el
615+// del anterior) y el estado de «Lanzar».
616+radio($('#benches'), BENCHES, S.bench, id => { S.bench = id; $('#bench-tag').textContent = id; pintarRanking(); pintarRun(); });
583617 $('#brain-tag').textContent = S.brain;
584618 $('#bench-tag').textContent = S.bench;
585619 algoKnobs(); ctxUI();
@@ -595,17 +629,22 @@
595629 $('#ctx-all').onclick = () => { CTX_KNOBS.flatMap(([, k]) => k).forEach(([k, t]) => { if (t === 'bool') S.ctx[k] = true; }); ctxUI(); };
596630 $('#ctx-none').onclick = () => { CTX_KNOBS.flatMap(([, k]) => k).forEach(([k, t]) => { if (t === 'bool') S.ctx[k] = false; }); ctxUI(); };
597631 $('#ctx-def').onclick = () => { S.ctx = {}; ctxUI(); };
632+// Hace lo que dice el botón y nada más: abrir el IDE con ESTE cerebro (los ids
633+// del Lab son ids del IDE). Antes se llamaba «Lanzar el IDE con esta
634+// configuración» y guardaba también algoritmo y perillas en claves que el IDE
635+// no lee nunca: la configuración no llegaba y el log decía que sí.
598636 $('#btn-launch').onclick = () => {
599637 localStorage.setItem('elffusscode.model', S.brain);
600- localStorage.setItem('elffusscode.ctxopts', JSON.stringify(S.ctx));
601- localStorage.setItem('elffusscode.algo', JSON.stringify({ algo: S.algo, opts: S.algoOpts }));
602- log('configuración guardada; abriendo el IDE', 'a');
638+ localStorage.removeItem('elffusscode.ctxopts');
639+ localStorage.removeItem('elffusscode.algo');
640+ log('el IDE arrancará con el cerebro «' + S.brain + '»; el algoritmo y las perillas solo se aplican aquí, en el Lab', 'a');
603641 window.open('index.html', '_blank');
604642 };
605643
606644 $('#btn-save').onclick = guardarCorrida;
607645 $('#btn-clear').onclick = borrarHistorial;
608646 pintarRanking();
647+pintarRun();
609648
610649 log('Elffuss Lab listo. Elige algoritmo, enciende o apaga la compresión y lanza un banco.', 'a');
611650 log('El banco de contexto no necesita GPU: mide el compresor y responde al instante.');
modified web/js/main.js +6 −0
@@ -2034,7 +2034,12 @@
20342034 { label: t('pToggleExplorer'), run: () => $('act-files').click() },
20352035 { label: t('pToggleTerm'), hint: 'Ctrl+`', run: () => { closePalette(); toggleTerminal(); } },
20362036 { label: t('pSave', { k: atajo('S') }), run: () => saveActive() },
2037+ { label: t('mLab'), run: () => abrirLab() },
20372038 ];
2039+// El banco de pruebas (lab.html) existía pero no había forma de llegar a él
2040+// desde el IDE: solo escribiendo la URL. Se abre en otra pestaña para no
2041+// dejar a medias lo que tengas aquí.
2042+function abrirLab() { window.open('lab.html', '_blank', 'noopener'); }
20382043
20392044 function openPalette(prefix = '') {
20402045 $('palette').hidden = false;
@@ -2141,6 +2146,7 @@
21412146 { label: t('tCity'), run: () => openView('city') },
21422147 { label: t('mPalette'), hint: atajo('P', true), run: () => openPalette('>') },
21432148 { label: 'Skills', run: () => openSkillsPanel() },
2149+ { label: t('mLab'), hint: '↗', run: () => abrirLab() },
21442150 { label: t('mAbout'), hint: '↗', run: () => window.open('https://github.com/KikoCis/elffuss-code', '_blank', 'noopener') },
21452151 ];
21462152 if (which === 'git') {
modified web/lab.html +5 −3
@@ -14,7 +14,7 @@
1414 <div class="sub">banco de pruebas · algoritmos y compresión de contexto</div>
1515 <div class="spacer"></div>
1616 <div class="led" id="led-model"><i></i><span>modelo: sin cargar</span></div>
17- <div class="led" id="led-run"><i></i><span>en reposo</span></div>
17+ <div class="led" id="led-run" role="status"><i></i><span>en reposo</span></div>
1818 <a class="sub" href="index.html">← volver al IDE</a>
1919 </header>
2020
@@ -55,7 +55,8 @@
5555 <div id="ctx-knobs"></div>
5656 <p class="hint">Cada perilla es la del motor real (<code>acer-core.js</code>).
5757 Lo que marques aquí es lo que se le pasa a <code>packHistoryACER</code>
58- en el banco de contexto y lo que se guarda al lanzar el IDE.</p>
58+ en el banco de contexto. Se queda en el Lab: el IDE usa siempre su
59+ configuración por defecto.</p>
5960 </div>
6061 </div>
6162 </section>
@@ -70,8 +71,9 @@
7071 <button class="btn primary" id="btn-run">▶ Lanzar benchmark</button>
7172 <button class="btn" id="btn-stop" disabled>■ Parar</button>
7273 <button class="btn" id="btn-save">★ Guardar en el ranking</button>
73- <button class="btn ghost" id="btn-launch">Lanzar el IDE con esta configuración</button>
74+ <button class="btn ghost" id="btn-launch" title="Abre el IDE en otra pestaña con el cerebro elegido arriba">Abrir el IDE con este cerebro</button>
7475 </div>
76+ <div class="sub" id="run-hint" role="status" style="margin-top:6px"></div>
7577 <div class="bar" style="margin-top:12px"><i id="prog"></i></div>
7678 <div class="sub" id="prog-txt" style="margin-top:6px">—</div>
7779 </div>