utopia-ia/elffuss-code public
Changesets · Branches · Tags · Compare
| Changeset | ab2541aae10475f088a4960a57953452abed03621497ddfeab77fc49d21b1276 |
|---|---|
| Author | KikoCis <kikocisneros@gmail.com> · 2026-10-11 15:10 +02:00 |
| Committer | KikoCis <kikocisneros@gmail.com> · 2026-10-11 15:10 +02:00 |
| Parents | 86dfa66543e3 |
3 files changed
modified tests/lab-ux.mjs +12 −2
| @@ -63,7 +63,7 @@ | ||
| 63 | 63 | ok('2 · cambiar de cerebro descarta el que estaba cargado', /sin cargar/.test(e.led), e.led); |
| 64 | 64 | await p.locator('#benches label').nth(2).click(); // juegos: necesita cerebro |
| 65 | 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)); | |
| 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)); | |
| 67 | 67 | await p.click('#btn-load'); |
| 68 | 68 | await p.waitForFunction(() => /modelo: onnx/.test(document.querySelector('#led-model').textContent), null, { timeout: 5000 }); |
| 69 | 69 | e = await estado(); |
| @@ -99,7 +99,17 @@ | ||
| 99 | 99 | await p.click('#btn-launch'); |
| 100 | 100 | const r5 = await p.evaluate(() => ({ model: localStorage.getItem('elffusscode.model'), ctx: localStorage.getItem('elffusscode.ctxopts'), algo: localStorage.getItem('elffusscode.algo') })); |
| 101 | 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)); | |
| 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 | +} | |
| 103 | 113 | |
| 104 | 114 | console.log('\n errores JS:', errs[0] || 'ninguno'); |
| 105 | 115 | ok('sin errores de página', errs.length === 0, errs.join(' | ')); |
modified tests/labstop.mjs +13 −0
| @@ -49,6 +49,15 @@ | ||
| 49 | 49 | await p.click('#btn-run'); |
| 50 | 50 | await p.waitForFunction(() => (window.__labProv?.llamadas || 0) >= 1, null, { timeout: 5000 }).catch(() => {}); |
| 51 | 51 | 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); | |
| 52 | 61 | await p.evaluate(() => { window.__labParado = true; }); |
| 53 | 62 | await p.click('#btn-stop'); |
| 54 | 63 | const termino = await p.waitForFunction(() => !document.getElementById('btn-run').disabled, null, { timeout: 15000 }).then(() => true).catch(() => false); |
| @@ -62,7 +71,11 @@ | ||
| 62 | 71 | ranking: document.getElementById('rank-tag').textContent, |
| 63 | 72 | })); |
| 64 | 73 | 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); | |
| 65 | 75 | 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); | |
| 66 | 79 | ok('■ corta la inferencia en curso (el modelo recibe la parada)', r.st?.abortadas === 1 && r.st?.terminadas === 0, JSON.stringify(r.st)); |
| 67 | 80 | ok(' …y no se lanza ninguna inferencia más', r.st?.trasParar === 0, `${r.st?.trasParar} tras parar`); |
| 68 | 81 | ok('la corrida termina (▶ vuelve a estar disponible)', termino); |
modified web/js/lab.js +23 −5
| @@ -18,7 +18,7 @@ | ||
| 18 | 18 | |
| 19 | 19 | // ─────────────────────────── estado ─────────────────────────── |
| 20 | 20 | const S = { |
| 21 | - brain: localStorage.getItem('elffusscode.model') || 'rules', | |
| 21 | + brain: 'rules', // el del IDE si el Lab lo conoce (ver BRAINS, abajo) | |
| 22 | 22 | algo: 'directo', |
| 23 | 23 | algoOpts: { rounds: 1, chunkTokens: 1800, maxChunks: 24 }, |
| 24 | 24 | ctx: {}, // overrides sobre DEFAULTS |
| @@ -67,13 +67,19 @@ | ||
| 67 | 67 | ['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.'], |
| 68 | 68 | ]; |
| 69 | 69 | |
| 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. | |
| 70 | 73 | const BRAINS = [ |
| 71 | 74 | ['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.'], | |
| 73 | 76 | ['litert:gemma-e2b', 'Gemma-4 E2B (~2 GB)', 'WebGPU.'], |
| 74 | 77 | ['litert:gemma-e4b', 'Gemma-4 E4B (~3 GB)', 'WebGPU. El mejor.'], |
| 75 | 78 | ]; |
| 76 | 79 | |
| 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 | + | |
| 77 | 83 | // ─────────────────────────── consola ─────────────────────────── |
| 78 | 84 | function log(msg, cls = '') { |
| 79 | 85 | const t = new Date().toTimeString().slice(0, 8); |
| @@ -182,7 +188,10 @@ | ||
| 182 | 188 | try { |
| 183 | 189 | let mod; |
| 184 | 190 | 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 | + } | |
| 186 | 195 | else if (id.startsWith('litert:')) { |
| 187 | 196 | mod = await import('./providers/litert.js'); |
| 188 | 197 | mod.configure(id.split(':')[1]); |
| @@ -473,9 +482,18 @@ | ||
| 473 | 482 | } |
| 474 | 483 | |
| 475 | 484 | // ─────────────────────────── 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 | + | |
| 476 | 492 | async function run() { |
| 477 | 493 | if (S.running) return; |
| 478 | 494 | 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); | |
| 479 | 497 | $('#btn-run').disabled = true; $('#btn-stop').disabled = false; |
| 480 | 498 | setLed('#led-run', 'busy', 'ejecutando ' + S.bench); |
| 481 | 499 | tiles({}); prog(0, 1, 'preparando…'); |
| @@ -527,8 +545,7 @@ | ||
| 527 | 545 | } else if (out) { |
| 528 | 546 | tiles(out.resumen); |
| 529 | 547 | 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, | |
| 532 | 549 | duracionSegs: Math.round((Date.now() - t0) / 1000), cuando: new Date().toISOString(), |
| 533 | 550 | }; |
| 534 | 551 | log('✔ terminado: ' + JSON.stringify(out.resumen), 'a'); |
| @@ -539,6 +556,7 @@ | ||
| 539 | 556 | else setLed('#led-run', error ? 'err' : 'on', error ? 'con fallo' : 'listo'); |
| 540 | 557 | prog(1, 1, parado ? (out ? 'parado (parcial)' : 'parado') : error ? 'abortado' : 'completado'); |
| 541 | 558 | S.running = false; S.aborter = null; $('#btn-stop').disabled = true; |
| 559 | + bloqueaEleccion(false); | |
| 542 | 560 | pintarRun(); |
| 543 | 561 | } |
| 544 | 562 |