memlnaut-nisps/manifold/tests/e2e/geo-dislike.spec.ts

108 lines
4.9 KiB
TypeScript
Raw Normal View History

feat(manifold): geometric dislike + jolt/OU via shared core (one-core-engine P3) TS half of P3.1/P3.2/P3.3: wire the new WASM exports and delete the TS approximations now that geometric-dislike, jolt, OU, and the seeded RNG live in the C++/WASM core. - types.ts/wasm-iml.ts: bind + wrap dislike_geometric, store_positive, positive/negative_count, set_avoid_style, jolt_press/step/release/active/ lr_scale/tick_lr_ramp, explore_intensity/get/apply. Weight-mutating wrappers republish weights (version bump); explore_apply reuses feedbackBuf. - engine-api: extend .feedback (dislikeGeometric/storePositive/counts/ setAvoidStyle) + new .explore facade. thumbsDown now passes the HEARD (routed) vector, not the raw MLP output (raw == net output => inert cold-start). - feedback/controller.ts: delete dislikes[] + applyDislikeBias + both C++ GAP blocks + the SeededRng field; dislike() -> core dislikeGeometric (returns action, 15 => cold-start prompt); like() feeds the centroid via the core thumbsUp; getState() exposes positive/negative counts. Delete feedback/rng.ts. - engine/exploration.ts: execute the P3 SWAP POINT -> drive engine.explore.*; delete engine/jolt.ts + ou-explore.ts. UI surface unchanged. - ConsoleApp: one-time cold-start banner (British spelling), routed heard vector at the dislike call site. - App.tsx/spine.ts: under ?debug=1 pin a fixed seed + fixed per-tick dt so the probe/e2e are deterministic (production keeps time-seeded, real-time dt). - tests: new geo-dislike.spec.ts; probe gains dislikeGeometric/storePositive/ feedbackCounts/setAvoidStyle; the thumbsDown probe test now drives a real distinct-heard-vector dislike (bare thumbsDown on the net's own output is correctly inert under the geometric core). 27 e2e + 9 unit green. Docs: manifold/ONBOARDING.md engine+feedback sections synced.
2026-07-14 04:54:27 +02:00
/**
* 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';
feat(manifold): geometric dislike + jolt/OU via shared core (one-core-engine P3) TS half of P3.1/P3.2/P3.3: wire the new WASM exports and delete the TS approximations now that geometric-dislike, jolt, OU, and the seeded RNG live in the C++/WASM core. - types.ts/wasm-iml.ts: bind + wrap dislike_geometric, store_positive, positive/negative_count, set_avoid_style, jolt_press/step/release/active/ lr_scale/tick_lr_ramp, explore_intensity/get/apply. Weight-mutating wrappers republish weights (version bump); explore_apply reuses feedbackBuf. - engine-api: extend .feedback (dislikeGeometric/storePositive/counts/ setAvoidStyle) + new .explore facade. thumbsDown now passes the HEARD (routed) vector, not the raw MLP output (raw == net output => inert cold-start). - feedback/controller.ts: delete dislikes[] + applyDislikeBias + both C++ GAP blocks + the SeededRng field; dislike() -> core dislikeGeometric (returns action, 15 => cold-start prompt); like() feeds the centroid via the core thumbsUp; getState() exposes positive/negative counts. Delete feedback/rng.ts. - engine/exploration.ts: execute the P3 SWAP POINT -> drive engine.explore.*; delete engine/jolt.ts + ou-explore.ts. UI surface unchanged. - ConsoleApp: one-time cold-start banner (British spelling), routed heard vector at the dislike call site. - App.tsx/spine.ts: under ?debug=1 pin a fixed seed + fixed per-tick dt so the probe/e2e are deterministic (production keeps time-seeded, real-time dt). - tests: new geo-dislike.spec.ts; probe gains dislikeGeometric/storePositive/ feedbackCounts/setAvoidStyle; the thumbsDown probe test now drives a real distinct-heard-vector dislike (bare thumbsDown on the net's own output is correctly inert under the geometric core). 27 e2e + 9 unit green. Docs: manifold/ONBOARDING.md engine+feedback sections synced.
2026-07-14 04:54:27 +02:00
// The boot mode is paf_synth; the heard vector must match its output arity.
const N_OUTPUTS = PafSynthSchema.ml.output_size; // 33
feat(manifold): geometric dislike + jolt/OU via shared core (one-core-engine P3) TS half of P3.1/P3.2/P3.3: wire the new WASM exports and delete the TS approximations now that geometric-dislike, jolt, OU, and the seeded RNG live in the C++/WASM core. - types.ts/wasm-iml.ts: bind + wrap dislike_geometric, store_positive, positive/negative_count, set_avoid_style, jolt_press/step/release/active/ lr_scale/tick_lr_ramp, explore_intensity/get/apply. Weight-mutating wrappers republish weights (version bump); explore_apply reuses feedbackBuf. - engine-api: extend .feedback (dislikeGeometric/storePositive/counts/ setAvoidStyle) + new .explore facade. thumbsDown now passes the HEARD (routed) vector, not the raw MLP output (raw == net output => inert cold-start). - feedback/controller.ts: delete dislikes[] + applyDislikeBias + both C++ GAP blocks + the SeededRng field; dislike() -> core dislikeGeometric (returns action, 15 => cold-start prompt); like() feeds the centroid via the core thumbsUp; getState() exposes positive/negative counts. Delete feedback/rng.ts. - engine/exploration.ts: execute the P3 SWAP POINT -> drive engine.explore.*; delete engine/jolt.ts + ou-explore.ts. UI surface unchanged. - ConsoleApp: one-time cold-start banner (British spelling), routed heard vector at the dislike call site. - App.tsx/spine.ts: under ?debug=1 pin a fixed seed + fixed per-tick dt so the probe/e2e are deterministic (production keeps time-seeded, real-time dt). - tests: new geo-dislike.spec.ts; probe gains dislikeGeometric/storePositive/ feedbackCounts/setAvoidStyle; the thumbsDown probe test now drives a real distinct-heard-vector dislike (bare thumbsDown on the net's own output is correctly inert under the geometric core). 27 e2e + 9 unit green. Docs: manifold/ONBOARDING.md engine+feedback sections synced.
2026-07-14 04:54:27 +02:00
// 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);
});
test('parameterised replay applies configured dose then expires by wall time', async ({ page }) => {
const result = await page.evaluate((heard) => {
const p = window.__nisps!;
p.setFeedbackMode('avoid');
p.setAvoidStyle(0);
p.setGeometricConfig(0.001, 20, 100);
p.setInputs(0.4, 0.6);
p.dislikeGeometric(heard);
const first = p.advanceGeometric(0.05);
const live = p.feedbackCounts().negative;
const second = p.advanceGeometric(0.05);
const expired = p.feedbackCounts().negative;
return { first, live, second, expired };
}, HEARD);
expect(result).toEqual({ first: 1, live: 1, second: 1, expired: 0 });
});
test('expanded Learning panel starts calibrated and can restore upstream defaults', async ({ page }) => {
await page.getByTitle('Learning', { exact: true }).click();
await page.getByTitle('Expand', { exact: true }).click();
await expect(page.getByText('push · learning rate', { exact: true })).toBeVisible();
await expect(page.getByText('push · updates / second', { exact: true })).toBeVisible();
await expect(page.getByText('push · lifetime', { exact: true })).toBeVisible();
await expect(page.getByText('0.0030', { exact: true })).toBeVisible();
await expect(page.getByText('200 Hz', { exact: true })).toBeVisible();
await expect(page.getByText('2.5 s', { exact: true })).toBeVisible();
await expect(page.getByText('≈ 500 replay updates + the press')).toBeVisible();
await page.getByRole('button', { name: 'Upstream defaults' }).click();
await expect(page.getByText('0.0010', { exact: true })).toBeVisible();
});
feat(manifold): geometric dislike + jolt/OU via shared core (one-core-engine P3) TS half of P3.1/P3.2/P3.3: wire the new WASM exports and delete the TS approximations now that geometric-dislike, jolt, OU, and the seeded RNG live in the C++/WASM core. - types.ts/wasm-iml.ts: bind + wrap dislike_geometric, store_positive, positive/negative_count, set_avoid_style, jolt_press/step/release/active/ lr_scale/tick_lr_ramp, explore_intensity/get/apply. Weight-mutating wrappers republish weights (version bump); explore_apply reuses feedbackBuf. - engine-api: extend .feedback (dislikeGeometric/storePositive/counts/ setAvoidStyle) + new .explore facade. thumbsDown now passes the HEARD (routed) vector, not the raw MLP output (raw == net output => inert cold-start). - feedback/controller.ts: delete dislikes[] + applyDislikeBias + both C++ GAP blocks + the SeededRng field; dislike() -> core dislikeGeometric (returns action, 15 => cold-start prompt); like() feeds the centroid via the core thumbsUp; getState() exposes positive/negative counts. Delete feedback/rng.ts. - engine/exploration.ts: execute the P3 SWAP POINT -> drive engine.explore.*; delete engine/jolt.ts + ou-explore.ts. UI surface unchanged. - ConsoleApp: one-time cold-start banner (British spelling), routed heard vector at the dislike call site. - App.tsx/spine.ts: under ?debug=1 pin a fixed seed + fixed per-tick dt so the probe/e2e are deterministic (production keeps time-seeded, real-time dt). - tests: new geo-dislike.spec.ts; probe gains dislikeGeometric/storePositive/ feedbackCounts/setAvoidStyle; the thumbsDown probe test now drives a real distinct-heard-vector dislike (bare thumbsDown on the net's own output is correctly inert under the geometric core). 27 e2e + 9 unit green. Docs: manifold/ONBOARDING.md engine+feedback sections synced.
2026-07-14 04:54:27 +02:00
});