@@ -2,7 +2,6 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
22import type { SessionEntry } from "../config/sessions.js" ;
33
44const streamSimpleMock = vi . fn ( ) ;
5- const appendCustomEntryMock = vi . fn ( ) ;
65const buildSessionContextMock = vi . fn ( ) ;
76const getLeafEntryMock = vi . fn ( ) ;
87const branchMock = vi . fn ( ) ;
@@ -13,11 +12,8 @@ const discoverModelsMock = vi.fn();
1312const resolveModelWithRegistryMock = vi . fn ( ) ;
1413const getApiKeyForModelMock = vi . fn ( ) ;
1514const requireApiKeyMock = vi . fn ( ) ;
16- const acquireSessionWriteLockMock = vi . fn ( ) ;
1715const resolveSessionAuthProfileOverrideMock = vi . fn ( ) ;
1816const getActiveEmbeddedRunSnapshotMock = vi . fn ( ) ;
19- const waitForEmbeddedPiRunEndMock = vi . fn ( ) ;
20- const diagWarnMock = vi . fn ( ) ;
2117const diagDebugMock = vi . fn ( ) ;
2218
2319vi . mock ( "@mariozechner/pi-ai" , ( ) => ( {
@@ -31,7 +27,6 @@ vi.mock("@mariozechner/pi-coding-agent", () => ({
3127 branch : branchMock ,
3228 resetLeaf : resetLeafMock ,
3329 buildSessionContext : buildSessionContextMock ,
34- appendCustomEntry : appendCustomEntryMock ,
3530 } ) ,
3631 } ,
3732} ) ) ;
@@ -54,13 +49,8 @@ vi.mock("./model-auth.js", () => ({
5449 requireApiKey : ( ...args : unknown [ ] ) => requireApiKeyMock ( ...args ) ,
5550} ) ) ;
5651
57- vi . mock ( "./session-write-lock.js" , ( ) => ( {
58- acquireSessionWriteLock : ( ...args : unknown [ ] ) => acquireSessionWriteLockMock ( ...args ) ,
59- } ) ) ;
60-
6152vi . mock ( "./pi-embedded-runner/runs.js" , ( ) => ( {
6253 getActiveEmbeddedRunSnapshot : ( ...args : unknown [ ] ) => getActiveEmbeddedRunSnapshotMock ( ...args ) ,
63- waitForEmbeddedPiRunEnd : ( ...args : unknown [ ] ) => waitForEmbeddedPiRunEndMock ( ...args ) ,
6454} ) ) ;
6555
6656vi . mock ( "./auth-profiles/session-override.js" , ( ) => ( {
@@ -70,12 +60,11 @@ vi.mock("./auth-profiles/session-override.js", () => ({
7060
7161vi . mock ( "../logging/diagnostic.js" , ( ) => ( {
7262 diagnosticLogger : {
73- warn : ( ...args : unknown [ ] ) => diagWarnMock ( ...args ) ,
7463 debug : ( ...args : unknown [ ] ) => diagDebugMock ( ...args ) ,
7564 } ,
7665} ) ) ;
7766
78- const { BTW_CUSTOM_TYPE , runBtwSideQuestion } = await import ( "./btw.js" ) ;
67+ const { runBtwSideQuestion } = await import ( "./btw.js" ) ;
7968
8069function makeAsyncEvents ( events : unknown [ ] ) {
8170 return {
@@ -99,7 +88,6 @@ function createSessionEntry(overrides: Partial<SessionEntry> = {}): SessionEntry
9988describe ( "runBtwSideQuestion" , ( ) => {
10089 beforeEach ( ( ) => {
10190 streamSimpleMock . mockReset ( ) ;
102- appendCustomEntryMock . mockReset ( ) ;
10391 buildSessionContextMock . mockReset ( ) ;
10492 getLeafEntryMock . mockReset ( ) ;
10593 branchMock . mockReset ( ) ;
@@ -110,11 +98,8 @@ describe("runBtwSideQuestion", () => {
11098 resolveModelWithRegistryMock . mockReset ( ) ;
11199 getApiKeyForModelMock . mockReset ( ) ;
112100 requireApiKeyMock . mockReset ( ) ;
113- acquireSessionWriteLockMock . mockReset ( ) ;
114101 resolveSessionAuthProfileOverrideMock . mockReset ( ) ;
115102 getActiveEmbeddedRunSnapshotMock . mockReset ( ) ;
116- waitForEmbeddedPiRunEndMock . mockReset ( ) ;
117- diagWarnMock . mockReset ( ) ;
118103 diagDebugMock . mockReset ( ) ;
119104
120105 buildSessionContextMock . mockReturnValue ( {
@@ -128,15 +113,11 @@ describe("runBtwSideQuestion", () => {
128113 } ) ;
129114 getApiKeyForModelMock . mockResolvedValue ( { apiKey : "secret" , mode : "api-key" , source : "test" } ) ;
130115 requireApiKeyMock . mockReturnValue ( "secret" ) ;
131- acquireSessionWriteLockMock . mockResolvedValue ( {
132- release : vi . fn ( ) . mockResolvedValue ( undefined ) ,
133- } ) ;
134116 resolveSessionAuthProfileOverrideMock . mockResolvedValue ( "profile-1" ) ;
135117 getActiveEmbeddedRunSnapshotMock . mockReturnValue ( undefined ) ;
136- waitForEmbeddedPiRunEndMock . mockResolvedValue ( true ) ;
137118 } ) ;
138119
139- it ( "streams blocks and persists a non-context custom entry " , async ( ) => {
120+ it ( "streams blocks without persisting BTW data to disk " , async ( ) => {
140121 const onBlockReply = vi . fn ( ) . mockResolvedValue ( undefined ) ;
141122 streamSimpleMock . mockReturnValue (
142123 makeAsyncEvents ( [
@@ -212,17 +193,6 @@ describe("runBtwSideQuestion", () => {
212193 text : "Side answer." ,
213194 btw : { question : "What changed?" } ,
214195 } ) ;
215- await vi . waitFor ( ( ) => {
216- expect ( appendCustomEntryMock ) . toHaveBeenCalledWith (
217- BTW_CUSTOM_TYPE ,
218- expect . objectContaining ( {
219- question : "What changed?" ,
220- answer : "Side answer." ,
221- provider : "anthropic" ,
222- model : "claude-sonnet-4-5" ,
223- } ) ,
224- ) ;
225- } ) ;
226196 } ) ;
227197
228198 it ( "returns a final payload when block streaming is unavailable" , async ( ) => {
@@ -641,14 +611,7 @@ describe("runBtwSideQuestion", () => {
641611 ) ;
642612 } ) ;
643613
644- it ( "returns the BTW answer and retries transcript persistence after a session lock" , async ( ) => {
645- acquireSessionWriteLockMock
646- . mockRejectedValueOnce (
647- new Error ( "session file locked (timeout 250ms): pid=123 /tmp/session.lock" ) ,
648- )
649- . mockResolvedValueOnce ( {
650- release : vi . fn ( ) . mockResolvedValue ( undefined ) ,
651- } ) ;
614+ it ( "returns the BTW answer without appending transcript custom entries" , async ( ) => {
652615 streamSimpleMock . mockReturnValue (
653616 makeAsyncEvents ( [
654617 {
@@ -688,26 +651,10 @@ describe("runBtwSideQuestion", () => {
688651 } ) ;
689652
690653 expect ( result ) . toEqual ( { text : "323" } ) ;
691- await vi . waitFor ( ( ) => {
692- expect ( waitForEmbeddedPiRunEndMock ) . toHaveBeenCalledWith ( "session-1" , 30000 ) ;
693- expect ( appendCustomEntryMock ) . toHaveBeenCalledWith (
694- BTW_CUSTOM_TYPE ,
695- expect . objectContaining ( {
696- question : "What is 17 * 19?" ,
697- answer : "323" ,
698- } ) ,
699- ) ;
700- } ) ;
654+ expect ( buildSessionContextMock ) . toHaveBeenCalled ( ) ;
701655 } ) ;
702656
703- it ( "logs deferred persistence failures through the diagnostic logger" , async ( ) => {
704- acquireSessionWriteLockMock
705- . mockRejectedValueOnce (
706- new Error ( "session file locked (timeout 250ms): pid=123 /tmp/session.lock" ) ,
707- )
708- . mockRejectedValueOnce (
709- new Error ( "session file locked (timeout 10000ms): pid=123 /tmp/session.lock" ) ,
710- ) ;
657+ it ( "does not log transcript persistence warnings because BTW no longer writes to disk" , async ( ) => {
711658 streamSimpleMock . mockReturnValue (
712659 makeAsyncEvents ( [
713660 {
@@ -747,11 +694,9 @@ describe("runBtwSideQuestion", () => {
747694 } ) ;
748695
749696 expect ( result ) . toEqual ( { text : "323" } ) ;
750- await vi . waitFor ( ( ) => {
751- expect ( diagWarnMock ) . toHaveBeenCalledWith (
752- expect . stringContaining ( "btw transcript persistence skipped: sessionId=session-1" ) ,
753- ) ;
754- } ) ;
697+ expect ( diagDebugMock ) . not . toHaveBeenCalledWith (
698+ expect . stringContaining ( "btw transcript persistence skipped" ) ,
699+ ) ;
755700 } ) ;
756701
757702 it ( "excludes tool results from BTW context to avoid replaying raw tool output" , async ( ) => {
0 commit comments