import test from "node:test"; import assert from "node:assert/strict"; import {buildPlanChatContext,partialReply} from "../server/plan-chat.js"; import {blankPlan} from "../shared/fields.js"; import {buildPlanCurve} from "../shared/curve.js"; import {computeLedger} from "../shared/ledger.js"; test("Bean Bro sees the displayed 392°F first crack even with blank raw temperatures",()=>{ const p=blankPlan();Object.assign(p.fields,{"1.4":"8:45","3.2":"-0:30","4.3":"1:38","4.1":"light"}); const ctx=buildPlanChatContext(p); const fc=ctx.displayedMilestones.find(p=>p.event==="fc"); assert.equal(fc.tempF,392);assert.equal(fc.time,"8:45");assert.equal(fc.temperatureSource,"illustrative"); assert.equal(ctx.computedLedger.timingBreakdown.development.processAdjustmentS,-30); assert.equal(ctx.computedLedger.developmentS,75); for(const point of buildPlanCurve(p,computeLedger(p))) { const item=ctx.displayedMilestones.find(i=>i.event===point.key); assert.equal(item.tempC,point.tempC);assert.equal(item.timeS,point.timeS); } }); test("Bean Bro distinguishes entered targets, preheat and actual measurements without machine scaling",()=>{ const p=blankPlan();p.fields["1.4"]="8:45";p.fields["4.4"]="1:20"; p.temps.fc.tempC="195";p.preheat.tempC="175";p.planActual.fc.actualBt="171.111111";p.planActual.fc.actualTime="7:05"; const ctx=buildPlanChatContext(p); assert.equal(ctx.displayedMilestones.find(p=>p.event==="fc").tempF,383); assert.equal(ctx.displayedMilestones.find(p=>p.event==="fc").temperatureSource,"entered"); assert.equal(ctx.preheatSetpointF,347);assert.equal(ctx.recordedMilestones.find(p=>p.event==="fc").actualBtF,340); assert.equal(buildPlanChatContext(blankPlan()).displayedMilestones.some(p=>p.event==="fc"),false); }); test("streaming JSON decoder exposes only reply text and handles split escapes",()=>{ const text='The "FC" is 392°F.\nUse actual crack.'; const raw=JSON.stringify({reply:text,suggestions:[{fields:{"4.4":"1:20"}}]}); for(let i=0;i<=raw.length;i++) assert.ok(text.startsWith(partialReply(raw.slice(0,i)))); assert.equal(partialReply(raw),text); assert.equal(partialReply('{"reply":"392\\u00'),"392"); assert.equal(partialReply('{"reply":"392\\u00b0F"}'),"392°F"); });