// THE TUNE's NUMBERS ON THE BENCH (lane character-tuning, review 2; tuneAsk.mjs): the baseline a press starts from, // what it asks as the line's own, what a Keep keeps, and the thread Tune's piece. Each test names the review finding // it holds, and what the rule before the fix did (S3's: the last read's numbers, every one off the defaults, sent as the // line's own). import assert from "node:assert/strict"; import { test } from "node:test"; import { asksSampler, characterTuneOf, defaultsAskOf, keepAskOf, lineOwnOf, madeOwnOf, plainPressAskOf, sameBaseline, threadTuneMadeOf, tuneAskOf, tuneStartOf, unknownBaselineAskOf } from "./tuneAsk.mjs"; const LIVELY = { temperature: 0.75, top_p: 0.92, repeat_penalty: 1.25 }; const STEADY = { temperature: 0.4, top_p: 0.8 }; const MADE_LIVELY = { temperature: 0.75, top_p: 0.92, top_k: 50, min_p: 0, repeat_penalty: 1.25, takes: 3 }; const asCharacter = (tuning, madeOwn = false) => ({ character: { name: "The Teller", tuning }, madeOwn }); test("review 2 #1: a plain press after a read under the character's Lively asks NONE of the sampler as the line's own", () => { // The last read was the character's ("preset"): the Tune starts from the character's tuning NOW. const made = { tuning: MADE_LIVELY, tuningAsked: "preset" }; const b = asCharacter(LIVELY, madeOwnOf(made.tuning, made.tuningAsked)); const draft = tuneStartOf({ madeWith: made.tuning, baseline: b }); assert.equal(tuneAskOf(draft, b), null, "nothing of its own (lane reads-find): the sampler is the character's, and the takes the line did not own are resolved now, never the last read's"); // The rule before the fix: the last read's numbers, as the line's own. // (Its takes not owned by the line: not in the start since lane reads-find.) assert.deepEqual(defaultsAskOf(tuneStartOf({ madeWith: made.tuning })), { temperature: 0.75, top_p: 0.92, repeat_penalty: 1.25 }); // The character is Steady now: the Tune starts there, and a plain press still asks none of the sampler. const now = asCharacter(STEADY, false); const d2 = tuneStartOf({ madeWith: made.tuning, baseline: now }); assert.deepEqual([d2.temperature, d2.top_p, d2.repeat_penalty], ["0.4", "0.8", "1.2"]); assert.equal(tuneAskOf(d2, now), null, "still nothing of its own: the takes are the character's or the settings', resolved now"); // The line's own last read stays its own: its numbers are the baseline, all of the sampler asked -- and its takes, // which it owned (an older take asked true owns every recorded value: lineOwnOf). const own = asCharacter(STEADY, madeOwnOf({ ...MADE_LIVELY, temperature: 0.9 }, true)); const d3 = tuneStartOf({ madeWith: { ...MADE_LIVELY, temperature: 0.9 }, baseline: own, own: lineOwnOf({ tuning: { ...MADE_LIVELY, temperature: 0.9 }, tuningAsked: true }) }); assert.deepEqual(tuneAskOf(d3, own), { temperature: 0.9, top_p: 0.92, top_k: 50, min_p: 0, repeat_penalty: 1.25, takes: 3 }); // Made before `tuningAsked` was recorded: a sampler value off the defaults was the line's own; the defaults were not. assert.equal(madeOwnOf({ temperature: 0.7 }, undefined), true); assert.equal(madeOwnOf({ temperature: 0.55, takes: 4 }, undefined), false); assert.equal(madeOwnOf({ temperature: 0.7 }, "preset"), false); }); test("review 2 #3: Defaults on a Lively character's line asks the three defaults as the line's own", () => { const b = asCharacter(LIVELY, false); const defaults = { temperature: "0.55", top_p: "0.85", top_k: "50", min_p: "0", repeat_penalty: "1.2", takes: "" }; assert.deepEqual(tuneAskOf(defaults, b), { temperature: 0.55, top_p: 0.85, repeat_penalty: 1.2 }); // The rule before the fix asked nothing (and the character's Lively was read). assert.equal(defaultsAskOf(defaults), null); // One number changed: only it is the line's own (the rest laid under it are the character's). assert.deepEqual(tuneAskOf({ ...tuneStartOf({ baseline: b }), temperature: "0.9" }, b), { temperature: 0.9 }); // No character: S3's rule, exactly. const none = { character: null, madeOwn: false }; assert.deepEqual(tuneAskOf({ ...defaults, temperature: "0.7" }, none), defaultsAskOf({ ...defaults, temperature: "0.7" })); assert.equal(tuneAskOf(defaults, none), null); }); test("review 2 #4: a thread read's Tune starts from his piece, never another piece's first tuned part", () => { const parts = [ { role: "parent:0", voice: "leo", tuning: STEADY, tuningAsked: "preset" }, { role: "post", voice: "tara", tuning: LIVELY, tuningAsked: "preset" }, { role: "post", voice: "tara", tuning: LIVELY, tuningAsked: "preset" }, ]; assert.deepEqual(threadTuneMadeOf(parts), { tuning: LIVELY, tuningAsked: "preset" }); // The rule before the fix: the first part with a tuning (the parent's Steady). assert.deepEqual(parts.find((p) => p.tuning)?.tuning, STEADY); // His line from a take (--post-take) is no synthesized piece: nothing to start from. assert.equal(threadTuneMadeOf([{ role: "post", take: "take-1.recorded", voice: "operator" }]), null); }); test("review 2 #5: a Keep pins the character's takes only when the takes field was typed", () => { const draft = { temperature: "0.9", top_p: "0.92", top_k: "50", min_p: "0", repeat_penalty: "1.25", takes: "4" }; assert.deepEqual(keepAskOf(draft), { temperature: 0.9, top_p: 0.92, repeat_penalty: 1.25 }, "the recorded takes (the editor's setting) are not pinned"); assert.deepEqual(keepAskOf(draft, { takesTyped: true }), { temperature: 0.9, top_p: 0.92, repeat_penalty: 1.25, takes: 4 }); // Top k and min p go only when not their defaults (a character does not keep them: the route says so). assert.deepEqual(keepAskOf({ ...draft, top_k: "40" }).top_k, 40); }); test("review 3 #1: a draft edited against Lively while the character became Steady is NOT sent; pressed again, what is shown is read", () => { // Loaded as Lively; the operator changes only top_p. const was = asCharacter(LIVELY, false); const draft = { ...tuneStartOf({ madeWith: MADE_LIVELY, baseline: was }), top_p: "0.9" }; const a = tuneAskOf(draft, was); assert.deepEqual(a, { top_p: 0.9 }, "the changed value only: the takes the line did not own are not sent"); assert.equal(asksSampler(a), true, "it names a sampler value of its own: the baseline is read again before it is sent"); // Read again: Steady now. It changed under the draft -- nothing is sent (the press is refused, the new baseline said). const now = asCharacter(STEADY, false); assert.equal(sameBaseline(now, was), false); assert.equal(sameBaseline(asCharacter({ ...LIVELY }, false), was), true); // Sent as it was, it would have read {temperature 0.4 (Steady's), top_p 0.9} while the Tune showed 0.75. // Pressed again against Steady, the draft as shown is the line's own: every number that differs from Steady's. assert.deepEqual(tuneAskOf(draft, now), { temperature: 0.75, top_p: 0.9, repeat_penalty: 1.25 }); // An untouched press names no sampler value: sent at once (the character's is asked as it is then). assert.equal(asksSampler({ takes: 3 }), false); }); test("review 3 #2: the baseline unknown -- an untouched press asks nothing of its own, an edited one waits", () => { const draft = tuneStartOf({ madeWith: MADE_LIVELY, baseline: null }); assert.deepEqual(unknownBaselineAskOf(draft, { madeOwn: false }), { waits: false, ask: null }, "an untouched press asks nothing of its own: the takes it did not own are resolved now (lane reads-find)"); assert.deepEqual(unknownBaselineAskOf(draft, { madeOwn: false, dirty: true }), { waits: true, ask: null }); // A line whose last read was its own: its numbers again (S3's rule), still its own. const ownMade = { ...MADE_LIVELY, temperature: 0.9 }; assert.deepEqual(unknownBaselineAskOf(tuneStartOf({ madeWith: ownMade, baseline: null, own: lineOwnOf({ tuning: ownMade, tuningAsked: true }) }), { madeOwn: true }).ask, { temperature: 0.9, top_p: 0.92, repeat_penalty: 1.25, takes: 3 }); }); test("review 3 #3: Use 's -- a line whose last read was its own goes back to its character: nothing of its own asked", () => { const b = asCharacter(STEADY, true); const own = { ...MADE_LIVELY, temperature: 0.9 }; assert.ok(asksSampler(tuneAskOf(tuneStartOf({ madeWith: own, baseline: b }), b)), "before: its own numbers, asked as its own"); const back = characterTuneOf(own, b); assert.deepEqual([back.draft.temperature, back.draft.top_p, back.draft.repeat_penalty], ["0.4", "0.8", "1.2"], "the draft at the character's"); assert.equal(tuneAskOf(back.draft, back.baseline), null, "the next press asks nothing of its own -- the takes too are the character's or the settings' now -- and records \"preset\""); }); test("review 3 #4: no character now, the last read the character's since removed -- the Tune starts from the last read's numbers (S3)", () => { const none = { character: null, madeOwn: false }; const d = tuneStartOf({ madeWith: MADE_LIVELY, baseline: none }); assert.deepEqual([d.temperature, d.top_p, d.repeat_penalty, d.takes], ["0.75", "0.92", "1.25", ""], "the sampler the last read's (S3); the takes it did not own empty: the editor's setting"); assert.deepEqual(tuneStartOf({ madeWith: MADE_LIVELY, baseline: none }), tuneStartOf({ madeWith: MADE_LIVELY }), "S3's start, exactly"); }); // --------------------------------------------------------------------------- // LINE-OWNED VALUES ONLY (lane reads-find, the orchestrator's ruling 2): a plain press passes back only what the line // owned (`tuningOwn`, else an older take's every recorded value when it asked true); the character's or the settings' // -- takes included -- are resolved now. // --------------------------------------------------------------------------- test("lineOwnOf: tuningOwn when recorded; an older take asked true owns every recorded value; else none", () => { assert.deepEqual(lineOwnOf({ tuning: MADE_LIVELY, tuningAsked: "preset", tuningOwn: { takes: 5 } }), { takes: 5 }); assert.deepEqual(lineOwnOf({ tuning: MADE_LIVELY, tuningAsked: true }), MADE_LIVELY); assert.equal(lineOwnOf({ tuning: MADE_LIVELY, tuningAsked: "preset" }), null, "an old take that owned only its takes reads as owning none (the known limit)"); assert.equal(lineOwnOf({ tuning: MADE_LIVELY }), null); assert.equal(lineOwnOf(null), null); }); test("a plain press: the character's takes changed -- the old recorded takes are not sent; a line-owned takes survives", () => { // Made under the character's tuning with the editor's 3 takes; the character names 4 takes now. const now = { character: { name: "The Teller", tuning: { ...LIVELY, takes: 4 } }, madeOwn: false }; assert.equal(plainPressAskOf({ madeWith: MADE_LIVELY, baseline: now, own: lineOwnOf({ tuning: MADE_LIVELY, tuningAsked: "preset" }) }), null, "the character's 4 is asked as it is now"); // The line asked its own 5 takes (tuningOwn): they survive, the sampler is still the character's. assert.deepEqual(plainPressAskOf({ madeWith: { ...MADE_LIVELY, takes: 5 }, baseline: now, own: { takes: 5 } }), { takes: 5 }); // Its own takes equal to the character's now are still its own. assert.deepEqual(plainPressAskOf({ madeWith: { ...MADE_LIVELY, takes: 4 }, baseline: now, own: { takes: 4 } }), { takes: 4 }); // No character: S3's rule for the sampler; the takes only when owned. assert.equal(plainPressAskOf({ madeWith: { temperature: 0.55, takes: 3 }, baseline: { character: null, madeOwn: false } }), null); assert.deepEqual(plainPressAskOf({ madeWith: { temperature: 0.7, takes: 3 }, baseline: null, own: { temperature: 0.7, takes: 3 } }), { temperature: 0.7, takes: 3 }); // The untouched bench press is this same ask (ReadAgain: tuneAskOf of the start, the baseline with ownTakes). const b = { ...now, ownTakes: 5 }; assert.deepEqual(tuneAskOf(tuneStartOf({ madeWith: { ...MADE_LIVELY, takes: 5 }, baseline: b, own: { takes: 5 } }), b), plainPressAskOf({ madeWith: { ...MADE_LIVELY, takes: 5 }, baseline: now, own: { takes: 5 } })); });