// The meaning check's rules in code (demo epic D2, item 3), on D0's own // cases. import { test } from "node:test"; import assert from "node:assert/strict"; import { decideMeaning, hasBothHalves, meaningPrompt, readMeaning, type MeaningAnswer } from "./meaning"; const A = (o: Partial): MeaningAnswer => ({ speaker: "host", stance: "asserts", sentence: "supported", fix: null, ...o }); // D0 a-qwen3-8b k01, reversed on both models: he reads a hostile business // review aloud and says at once "this is a lie this is liable this is slanderous". const REVIEW = { sentence: "Jeremy Hambly was banned by Wizards of the Coast from sanctioned events due to constant sexual harassment.", quote: "was banned by Wizards of the Coast from attending sanctioned events due to constant sexual harassment", before: "let's look at the reviews of the coffee company one star it says Jeremy Hambly", after: "this is a lie this is liable this is slanderous", }; test("not his words / he rebuts it: rewritten only when the fix says what he reads AND what he says of it", () => { const fix = "He reads a business review that says Wizards banned him for constant sexual harassment; he calls it a lie and slander."; const d = decideMeaning(A({ speaker: "someone he reads or plays", stance: "rebuts it", sentence: "reversed", fix }), REVIEW); assert.equal(d.action, "drop", "reversed comes first: the drafted sentence is gone either way"); const r = decideMeaning(A({ speaker: "someone he reads or plays", stance: "rebuts it", sentence: "overstated", fix }), REVIEW); assert.deepEqual([r.action, r.action !== "drop" && r.sentence], ["rewrite", fix]); const half = decideMeaning(A({ speaker: "someone he reads or plays", stance: "reads it out", sentence: "overstated", fix: "Jeremy reads a review saying he was banned for harassment." }), REVIEW); assert.equal(half.action, "drop"); assert.match(half.action === "drop" ? half.why : "", /^not his words, and no sentence says both/); // Sarcasm is the same rule. assert.equal(decideMeaning(A({ stance: "sarcastic", fix: null }), REVIEW).action, "drop"); // A drafted sentence that already carries both halves stands. const both = "He reads a tweet that says the show is a hit; he says nobody watched it."; const k = decideMeaning(A({ speaker: "someone he reads or plays", stance: "rebuts it", sentence: "supported", fix: null }), { sentence: both, quote: "the show is a hit", before: "a tweet", after: "nobody watched this garbage" }); assert.deepEqual([k.action, k.action !== "drop" && k.sentence], ["rewrite", both]); // What he says of it must be in the transcript around the quote, not a // restatement of what he reads (D2 run i123-d-q25, the power-scaling tweet). const shad = { sentence: "Jeremy says episode 5 does not understand power scaling.", quote: "the acolyte episode 5 doesn't understand power scaling at all which is crucial if you want consistency", before: "Shad adversity", after: "and investment in a fight great point", }; const restated = decideMeaning(A({ speaker: "someone he reads or plays", sentence: "overstated", fix: "He reads a tweet that says episode 5 misses power scaling; he calls it crucial for consistency." }), shad); assert.equal(restated.action, "drop"); assert.match(restated.action === "drop" ? restated.why : "", /not in the transcript around the quote/); const grounded = decideMeaning(A({ speaker: "someone he reads or plays", sentence: "overstated", fix: "The host reads a tweet that says episode 5 misses power scaling; he calls it a great point." }), shad); assert.deepEqual([grounded.action, grounded.action !== "drop" && grounded.sentence], ["rewrite", "He reads a tweet that says episode 5 misses power scaling; he calls it a great point."]); // "reads it out" is reading: the same rule, even when the model says "host". assert.equal(decideMeaning(A({ stance: "reads it out", sentence: "supported" }), shad).action, "drop"); }); test("reversed: dropped (D0 a k09: 'his coffee company dropped a sponsorship' — Trade Coffee dropped its sponsorship of him)", () => { const d = decideMeaning(A({ sentence: "reversed", fix: "He says Trade Coffee dropped its sponsorship of him." }), { sentence: "Jeremy states that his coffee company dropped a sponsorship worth thousands of dollars.", quote: "trade coffees dropped a sponsorship", }); assert.equal(d.action, "drop"); }); test("overstated: the fix replaces the sentence when the lint passes, else dropped", () => { const o = { sentence: "Jeremy says the show will be cancelled.", quote: "I think the show is going to get cancelled" }; const good = decideMeaning(A({ sentence: "overstated", fix: "He says he thinks the show is going to get cancelled." }), o); assert.deepEqual([good.action, good.action !== "drop" && good.sentence], ["rewrite", "He says he thinks the show is going to get cancelled."]); // A fix that drops the hedge fails the lint. const bad = decideMeaning(A({ sentence: "overstated", fix: "He says the show is going to get cancelled maybe." }), { ...o, quote: "I think the show might get cancelled" }); assert.equal(bad.action, "drop"); assert.equal(decideMeaning(A({ sentence: "overstated", fix: null }), o).action, "drop"); assert.equal(decideMeaning(A({ sentence: "overstated", fix: "word ".repeat(31).trim() }), o).action, "drop"); }); test("unclear: kept, marked check by ear; supported and his own: kept as drafted", () => { const o = { sentence: "Jeremy says the show is tanking.", quote: "the show is tanking in the ratings" }; assert.deepEqual(decideMeaning(A({ speaker: "unclear" }), o), { action: "mark", sentence: o.sentence, why: "speaker unclear: check by ear" }); assert.equal(decideMeaning(A({ stance: "unclear" }), o).action, "mark"); assert.deepEqual(decideMeaning(A({}), o), { action: "keep", sentence: o.sentence, why: "supported, his own words" }); }); test("readMeaning: strict — an unknown value is unclear / overstated; an empty or 'null' fix is null", () => { assert.deepEqual(readMeaning({ speaker: "Jeremy", stance: "maybe", sentence: "fine", fix: "null" }), { speaker: "unclear", stance: "unclear", sentence: "overstated", fix: null }); assert.deepEqual(readMeaning(null), { speaker: "unclear", stance: "unclear", sentence: "overstated", fix: null }); assert.equal(readMeaning({ speaker: "host", stance: "asserts", sentence: "supported", fix: ' He says "no". ' }).fix, "He says 'no'."); }); test("hasBothHalves and the prompt", () => { assert.ok(hasBothHalves("He plays a clip of Disney's CEO that says ratings are up; he says they are lying.")); assert.ok(!hasBothHalves("He reads a review that says it is bad.")); assert.ok(!hasBothHalves("He says it is bad; he calls it bad.")); const p = meaningPrompt({ question: "Q?", host: "Jeremy", before: "it says", quote: "the quote", after: "this is a lie", sentence: "S." }); assert.equal(p, "Question: Q?\n\nThe host: Jeremy\n\nBefore the quote: …it says\n\nQUOTE: the quote\n\nAfter the quote: this is a lie…\n\nDrafted sentence: S."); });