memlnaut-nisps/manifold/tests/e2e/geo-dislike.spec.ts
monkey-w1n5t0n 6c499e6826 feat(manifold): P5.2/P5.3 — derive MF_MODES from schema truth + per-mode engine dims
Schema-backed modes in console/model.ts are now DERIVED from the codegen
schemas in src/modes/generated/ (source of truth): real param names/groups/
count, plus each mode's ml net shape (MFMode.ml) and schema engine_id. A thin
manifold OVERLAY supplies only label/glyph/ModeClass/input/ordering. New
browser-viable modes xiasri + slp_workshop get derived entries; schema-less
visualizer + c15 stay hand-written on DEFAULT_MODE_ML. Schema min/max/default/
label/curve surface as engine-unit metadata (schemaMin/... on MFParam) without
touching the 0..1 routing semantics.

Switching instrument mode reshapes the runtime-shaped WASM net to the mode's
schema ml config (ConsoleApp effect keyed on [engine, modeId]; no confirm
modal). Boot lands paf_synth dims (4->[10,10,14]->33) once WASM is ready. The
P2.3 axis-count reshape offer still reads the engine's live inputSize and does
not spuriously prompt on a mode switch.

Adds schema-modes.spec.ts (P5 gate): drives switches via a new window.__mf
debug seam and asserts describe() dims, getWeights count, output length/bounds,
and UI param count FROM the imported schemas; spot-checks trainAsync after a
switch. Updates reshape/probe-api/geo-dislike specs to assert from the boot
mode schema instead of the retired fixed 32/126 shape.

All gates green: typecheck, unit (9), build, e2e (33).
2026-07-18 12:45:06 +02:00

73 lines
3.2 KiB
TypeScript

/**
* Geometric dislike (feedback Mode 1) — the SHARED C++/WASM core primitive
* (one-core-engine P3; rl-feedback-design §2.1). Drives the probe's read-only
* count accessors + the dislikeGeometric driver.
*
* The core reads the MLP's CURRENT input and the passed HEARD (post-pipeline)
* output vector. With NO positives it runs the cold-start fallback and returns
* FeedbackAction 15 (GeometricColdStart); with positives it computes the k-NN
* centroid push-away target and returns 14 (GeometricPush).
*/
import { test, expect } from '@playwright/test';
import { loadProbe, settleInputs, countChanged, allWithin } from './helpers';
import { PafSynthSchema } from '../../src/modes/generated';
// The boot mode is paf_synth; the heard vector must match its output arity.
const N_OUTPUTS = PafSynthSchema.ml.output_size; // 33
// A heard vector deliberately distinct from any plausible net output.
const HEARD = new Array(N_OUTPUTS).fill(0.9);
test.describe('geometric dislike (Mode 1) — core-backed', () => {
test.beforeEach(async ({ page }) => {
await loadProbe(page);
});
test('dislike before any likes returns cold-start (15) and stores a negative', async ({ page }) => {
const r = await page.evaluate((heard) => {
const p = window.__nisps!;
p.setFeedbackMode('avoid'); // geometric dislike proto mode maps to core Avoid
p.setAvoidStyle(0); // Geometric (default)
p.setInputs(0.5, 0.5);
const action = p.dislikeGeometric(heard);
return { action, counts: p.feedbackCounts() };
}, HEARD);
expect(r.action).toBe(15); // GeometricColdStart
expect(r.counts.positive).toBe(0);
expect(r.counts.negative).toBe(1);
});
test('two likes then a dislike pushes (14), changes the disliked output, stays bounded', async ({ page }) => {
await page.evaluate(() => {
window.__nisps!.setFeedbackMode('avoid');
window.__nisps!.setAvoidStyle(0);
});
// Like at two distinct inputs — the core's thumbsUp auto-stores a positive
// into the k-NN centroid while in Avoid+Geometric mode (ADR §2.1).
await settleInputs(page, 0.2, 0.3);
await page.evaluate(() => window.__nisps!.thumbsUp());
await settleInputs(page, 0.8, 0.7);
await page.evaluate(() => window.__nisps!.thumbsUp());
// Settle at a third input and capture the heard-≠-output baseline there.
const before = await settleInputs(page, 0.5, 0.5);
// Sanity: the heard vector we will pass genuinely differs from the outputs.
expect(countChanged(before, HEARD, 1e-3)).toBeGreaterThan(0);
// Dislike at the settled input with an explicit lr for a visibly-audible push.
const res = await page.evaluate((heard) => {
const p = window.__nisps!;
const action = p.dislikeGeometric(heard, 1.0);
return { action, counts: p.feedbackCounts() };
}, HEARD);
// Re-settle at the same input; the weights moved, so the output must too.
const after = await settleInputs(page, 0.5, 0.5);
expect(res.action).toBe(14); // GeometricPush (positives exist → not cold-start)
expect(res.counts.positive).toBeGreaterThanOrEqual(2);
expect(res.counts.negative).toBe(1);
expect(countChanged(before, after, 1e-4)).toBeGreaterThan(0);
expect(allWithin(after, 0, 1)).toBe(true);
});
});