memlnaut-nisps/manifold/tests/e2e/training-health.spec.ts

78 lines
3.4 KiB
TypeScript
Raw Permalink Normal View History

feat: curve truth, DriverConfig, real telemetry, engine benchmark Four items from one workflow, committed together because their build and CI wiring genuinely interleaves — nisps/CMakeLists.txt, run-all-tests.sh and ci.yml each carry hunks from two of them, and the stage renumbering (1/5 -> 1/6) touches every line. Splitting would produce commits that do not build, which is worse than a commit that does four things and says so. S26 part 2 — the curve declaration now matches reality. params[].curve stays the mode-wide DEFAULT; a voice_spaces entry may now be {name, curve_overrides} declaring only the slots where THAT voice space deviates. The 6 modes with one voice space are byte-identical. The values were derived MECHANICALLY by a new codegen/curve-audit.ts that models the four idioms a p[N]*p[N] regex misses (alias form, memlcelium's implicit-counter sq() lambda, loop-generated indices, smooth_params_), inlines helpers, and RAISES rather than guessing when it cannot reduce an expression. A drift gate cross-checks 1179 (voice space x param) slots against engine source on every run and was proved to fail loudly on three drift classes. Application stays in the engine: nisps/engines, nisps/pipeline and nisps/core are untouched, generated output is pure insertion (755 insertions, 0 deletions), and the rebuilt nisps.wasm was byte-identical. S4 / 7.2 — firmware reads the active mode's driver config at mode start, and mic/line is real. My brief assumed the engine owns this; the code disagreed and the code was right. sound_analysis_midi's EngineT is NoOpEngine — the mic lives on a separately-composed AnalysisEngine member — so engine-level wiring would have compiled, passed every gate, and left the one mic mode on line input. Hence a mode-level seam defaulting to engine().driver_config(). Separately, DriverConfig's defaults (line_level 0, output_volume 1.0) had drifted from memllib's actual 3/0.8 because nothing had ever read them; wiring them as-is would have made every silent mode louder and its line input maximally insensitive — a behaviour change disguised as plumbing. Now pinned by a test. Also: GetSysClockSpeed() panic()s on unsupported sample rates and runs on the first line of setup(), so sample_rate needed a fallback ahead of clock setup. CI's firmware env list gains soundanalysismidi — it is the only mic variant and nothing else compiles that path. Plan 5e — telemetry is real. A loss_history C-API entry across the full 5-layer chain lets the browser read the per-iteration loss the core already records. The audit named one fabrication site; there were two — wasm-iml.ts's synchronous train() published lossHistory: [loss] as well. A third, ctx.loss, was not merely dead but actively synthetic (fallbacks of prev * 0.82 and a literal 0.5, rendered by nothing) and is deleted. The firmware buffer stays untouched, per the L25 call. EngineApi.lossHistory() reads spine state rather than the MLP handle, because trainAsync() fits on the worker's mirror net and the handle would give a subtly-wrong second answer. Plan 5f — engine throughput is measurable. One source compiled twice (CMake natively, emcc for WASM) so the targets compare directly and no WASM export is added. Sequencers are driven into a working state, and every row prints its own working-state evidence so a number produced by an idle engine is visible rather than plausible. Reports, never asserts: a wall-clock threshold on shared hardware is meaningless or flaky, same call as the firmware size job. ALIGNMENT: the telemetry defect is deleted (built, not deferred); the performance defect is rewritten to what is actually left — these are HOST numbers, and nothing measures the RP2350 at 150 MHz, which is the target the mission's constraint is about. Q4 (memllib ownership) and Q5 (legacy feedback modes) are closed. Corrections to my own earlier claims, both found by agents contradicting the brief: manifold/ONBOARDING.md was NOT "now accurate" — its primitives list still named five deleted primitives and cited a seededGradient() that does not exist. And the parity harness misses the sequencer engines because it runs 128 frames while their sequencers evaluate every 400-500 samples, NOT because all-params-0.5 fails to trigger them (it does trigger: 0.5 maps to ratio 2, firing three times per bar). The fix is a longer window, not different params. Gates: run-all-tests.sh ALL GREEN — 4/4 ctest, parity PASS, lint clean, curve drift 1179 slots ok, 39 e2e (was 33). Firmware: 5 envs built including the mic variant.
2026-07-21 22:02:23 +02:00
/**
* Training-health panel (simplification-plan §6.5e / ALIGNMENT defect 6).
*
* The point of the panel is that "is the network learning?" becomes GENUINELY
* answerable, so the test asserts two things a placeholder could not satisfy:
*
* 1. Before any training it says so plainly no plot, no numbers.
* 2. After a real fit it reports the iteration count and the endpoints of the
* core's own loss curve, and draws a polyline with one vertex per
* iteration.
*
* It also pins the disclosure rule: the panel is advanced surface, so it lives
* at the Learning drawer's `expanded` depth (Manifold's existing DrawerDepth
* mechanism) and must NOT appear in the condensed panel.
*/
import { test, expect } from '@playwright/test';
import { loadProbe } from './helpers';
import { PafSynthSchema } from '../../src/modes/generated';
const N_OUTPUTS = PafSynthSchema.ml.output_size;
const LOW = { input: [0.1, 0.9], output: new Array(N_OUTPUTS).fill(0.1) };
const HIGH = { input: [0.9, 0.1], output: new Array(N_OUTPUTS).fill(0.9) };
/** Open the Learning drawer and expand it to the advanced depth. */
async function openLearningExpanded(page: import('@playwright/test').Page) {
await page.getByTitle('Learning', { exact: true }).click();
await page.getByTitle('Expand', { exact: true }).click();
}
test.beforeEach(async ({ page }) => {
await loadProbe(page);
});
test('training health is advanced surface — absent from the condensed drawer', async ({ page }) => {
await page.getByTitle('Learning', { exact: true }).click();
await expect(page.getByText('Training health')).toHaveCount(0);
});
test('with no training run the panel says so instead of drawing a curve', async ({ page }) => {
await openLearningExpanded(page);
await expect(page.getByText('Training health')).toBeVisible();
await expect(page.getByText(/no training run yet/)).toBeVisible();
await expect(page.locator('svg polyline')).toHaveCount(0);
});
test('after a real fit the panel reports the core loss curve', async ({ page }) => {
const hist = await page.evaluate(
([low, high]) => {
window.__nisps!.addExample(low.input, low.output);
window.__nisps!.addExample(high.input, high.output);
window.__nisps!.train();
return Array.from(window.__nisps!.getLossHistory());
},
[LOW, HIGH],
);
expect(hist.length).toBeGreaterThan(1);
await openLearningExpanded(page);
await expect(page.getByText(/no training run yet/)).toHaveCount(0);
await expect(page.getByText(`${hist.length} iter`)).toBeVisible();
await expect(page.getByText(`start ${hist[0]!.toFixed(4)}`)).toBeVisible();
await expect(page.getByText(`end ${hist[hist.length - 1]!.toFixed(4)}`)).toBeVisible();
// One polyline vertex per recorded iteration — the plot is the data, not decor.
const points = await page.locator('svg polyline').first().getAttribute('points');
expect(points!.trim().split(/\s+/)).toHaveLength(hist.length);
});
test('layer stats show one row per layer with real weight-health numbers', async ({ page }) => {
const layers = await page.evaluate(() => window.__nisps!.describe().numLayers);
await openLearningExpanded(page);
const rows = page.locator('table tbody tr');
await expect(rows).toHaveCount(layers);
// mean|w| of a freshly-drawn net is non-zero — the table is reading the net.
const meanAbs = await rows.first().locator('td').nth(1).innerText();
expect(Number(meanAbs)).toBeGreaterThan(0);
});