@@ -4,8 +4,6 @@ import { tmpdir } from 'node:os';
44import { join } from 'node:path' ;
55import { inflateRawSync } from 'node:zlib' ;
66
7- import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest' ;
8-
97import {
108 Error2 ,
119 ErrorCodes ,
@@ -29,13 +27,14 @@ import {
2927 type ServiceIdentifier ,
3028 type ScopeSeed ,
3129} from '@moonshot-ai/agent-core-v2' ;
30+ import { encodeWorkDirKey } from '@moonshot-ai/agent-core-v2/_base/utils/workdir-slug' ;
3231import { TurnStarted } from '@moonshot-ai/agent-core-v2/agent/loop/turnEvents' ;
3332import { sessionWarningsResponseSchema } from '@moonshot-ai/agent-core-v2/app/sessionLegacy/sessionProtocol' ;
34- import { encodeWorkDirKey } from '@moonshot-ai/agent-core-v2/_base/utils/workdir-slug ' ;
33+ import { afterEach , beforeEach , describe , expect , it , vi } from 'vitest ' ;
3534
3635import { type RunningServer , startServer } from '../src/start' ;
37- import { TEST_HOST_IDENTITY } from './helpers/hostIdentity' ;
3836import { authHeaders } from './helpers/auth' ;
37+ import { TEST_HOST_IDENTITY } from './helpers/hostIdentity' ;
3938
4039interface Envelope < T > {
4140 code : number ;
@@ -70,11 +69,7 @@ interface PageWire {
7069 has_more : boolean ;
7170}
7271
73- function agentRpc (
74- service : ServiceIdentifier < unknown > ,
75- method : string ,
76- sessionId : string ,
77- ) : string {
72+ function agentRpc ( service : ServiceIdentifier < unknown > , method : string , sessionId : string ) : string {
7873 return `/api/v1/debug/session/${ sessionId } /agent/main/${ String ( service ) } /${ method } ` ;
7974}
8075
@@ -468,11 +463,9 @@ describe('server-v2 /api/v1/sessions', () => {
468463 expect ( page3 . body . data . items . map ( ( s ) => s . id ) ) . toEqual ( [ ids [ 0 ] ] ) ;
469464 expect ( page3 . body . data . has_more ) . toBe ( false ) ;
470465
471- const seen = [
472- ...page1 . body . data . items ,
473- ...page2 . body . data . items ,
474- ...page3 . body . data . items ,
475- ] . map ( ( s ) => s . id ) ;
466+ const seen = [ ...page1 . body . data . items , ...page2 . body . data . items , ...page3 . body . data . items ] . map (
467+ ( s ) => s . id ,
468+ ) ;
476469 expect ( new Set ( seen ) . size ) . toBe ( 7 ) ;
477470 expect ( new Set ( seen ) ) . toEqual ( new Set ( ids ) ) ;
478471
@@ -629,22 +622,18 @@ describe('server-v2 /api/v1/sessions', () => {
629622 } ) ;
630623 const id = created . body . data . id ;
631624 for ( const text of [ 'first REST prompt' , 'second REST prompt' , 'third REST prompt' ] ) {
632- const submitted = await postJson < { prompt_id : string } > (
633- `/api/v1/sessions/${ id } /prompts` ,
634- { content : [ { type : 'text' , text } ] } ,
635- ) ;
625+ const submitted = await postJson < { prompt_id : string } > ( `/api/v1/sessions/${ id } /prompts` , {
626+ content : [ { type : 'text' , text } ] ,
627+ } ) ;
636628 expect ( submitted . body . code ) . toBe ( 0 ) ;
637629 }
638630
639- const generated = await postJson < { title : string } > (
640- `/api/v1/sessions/${ id } /title/generate` ,
641- ) ;
631+ const generated = await postJson < { title : string } > ( `/api/v1/sessions/${ id } /title/generate` ) ;
642632 expect ( generated . body ) . toMatchObject ( { code : 0 , data : { title : 'generated from REST' } } ) ;
643633 expect ( toolsRequest ) . toEqual ( {
644634 method : 'chat_title' ,
645635 params : {
646- chat_content :
647- 'user: first REST prompt\nuser: second REST prompt\nuser: third REST prompt' ,
636+ chat_content : 'user: first REST prompt\nuser: second REST prompt\nuser: third REST prompt' ,
648637 } ,
649638 } ) ;
650639
@@ -679,9 +668,7 @@ describe('server-v2 /api/v1/sessions', () => {
679668 } ) ;
680669
681670 it ( 'returns session-not-found when generating a title for a missing session' , async ( ) => {
682- const generated = await postJson < null > (
683- '/api/v1/sessions/sess_missing_title/title/generate' ,
684- ) ;
671+ const generated = await postJson < null > ( '/api/v1/sessions/sess_missing_title/title/generate' ) ;
685672
686673 expect ( generated . body . code ) . toBe ( 40401 ) ;
687674 } ) ;
@@ -816,9 +803,7 @@ describe('server-v2 /api/v1/sessions', () => {
816803 agent_config : { goal_control : 'resume' } ,
817804 } ) ;
818805
819- const refreshed = await getJson < { status : string } | null > (
820- `/api/v1/sessions/${ rig . id } /goal` ,
821- ) ;
806+ const refreshed = await getJson < { status : string } | null > ( `/api/v1/sessions/${ rig . id } /goal` ) ;
822807
823808 expect ( refreshed . body . data ?. status ) . toBe ( 'active' ) ;
824809 } finally {
@@ -851,9 +836,9 @@ describe('server-v2 /api/v1/sessions', () => {
851836 . delete ( encodeWorkDirKey ( cwd ) ) ;
852837 await rm ( cwd , { recursive : true , force : true } ) ;
853838
854- await expect (
855- resumeSessionById ( ( server as RunningServer ) . core . accessor , id ) ,
856- ) . rejects . toThrow ( / d o e s n o t e x i s t / ) ;
839+ await expect ( resumeSessionById ( ( server as RunningServer ) . core . accessor , id ) ) . rejects . toThrow (
840+ / d o e s n o t e x i s t / ,
841+ ) ;
857842
858843 const archived = await postJson < { archived : boolean } > ( `/api/v1/sessions/${ id } :archive` ) ;
859844 expect ( archived . body . code ) . toBe ( 0 ) ;
@@ -911,7 +896,10 @@ describe('server-v2 /api/v1/sessions', () => {
911896 const created = await postJson < SessionWire > ( '/api/v1/sessions' , {
912897 metadata : { cwd : home as string } ,
913898 } ) ;
914- const session = getLiveSessionById ( ( server as RunningServer ) . core . accessor , created . body . data . id ) ;
899+ const session = getLiveSessionById (
900+ ( server as RunningServer ) . core . accessor ,
901+ created . body . data . id ,
902+ ) ;
915903 if ( session === undefined ) throw new Error ( 'expected live session' ) ;
916904 const agent = await session . accessor
917905 . get ( IAgentLifecycleService )
@@ -921,10 +909,9 @@ describe('server-v2 /api/v1/sessions', () => {
921909 . mockRejectedValue ( new Error2 ( ErrorCodes . SESSION_BUSY , 'session is busy' ) ) ;
922910
923911 try {
924- const response = await postJson < null > (
925- `/api/v1/sessions/${ created . body . data . id } :undo` ,
926- { count : 1 } ,
927- ) ;
912+ const response = await postJson < null > ( `/api/v1/sessions/${ created . body . data . id } :undo` , {
913+ count : 1 ,
914+ } ) ;
928915
929916 expect ( response . body . code ) . toBe ( 40901 ) ;
930917 } finally {
@@ -1135,14 +1122,10 @@ describe('server-v2 /api/v1/sessions', () => {
11351122 it ( 'paginates archived_only without returning empty filtered pages' , async ( ) => {
11361123 const cwd = home as string ;
11371124 const archivedOlder = await postJson < SessionWire > ( '/api/v1/sessions' , { metadata : { cwd } } ) ;
1138- await postJson < { archived : boolean } > (
1139- `/api/v1/sessions/${ archivedOlder . body . data . id } :archive` ,
1140- ) ;
1125+ await postJson < { archived : boolean } > ( `/api/v1/sessions/${ archivedOlder . body . data . id } :archive` ) ;
11411126
11421127 const archivedNewer = await postJson < SessionWire > ( '/api/v1/sessions' , { metadata : { cwd } } ) ;
1143- await postJson < { archived : boolean } > (
1144- `/api/v1/sessions/${ archivedNewer . body . data . id } :archive` ,
1145- ) ;
1128+ await postJson < { archived : boolean } > ( `/api/v1/sessions/${ archivedNewer . body . data . id } :archive` ) ;
11461129
11471130 await postJson < SessionWire > ( '/api/v1/sessions' , { metadata : { cwd } } ) ;
11481131 await postJson < SessionWire > ( '/api/v1/sessions' , { metadata : { cwd } } ) ;
@@ -1480,11 +1463,24 @@ describe('server-v2 /api/v1/sessions', () => {
14801463
14811464 it ( 'derives the session title from the first prompt submitted via /api/v1' , async ( ) => {
14821465 const cwd = home as string ;
1483- await writeFile ( join ( cwd , 'config.toml' ) , [
1484- 'default_model = "stub"' , '' , '[providers.stub]' , 'type = "openai"' ,
1485- 'base_url = "http://127.0.0.1:9999"' , 'api_key = "stub"' , '' ,
1486- '[models.stub]' , 'provider = "stub"' , 'model = "stub"' , 'max_context_size = 1000' , '' ,
1487- ] . join ( '\n' ) , 'utf-8' ) ;
1466+ await writeFile (
1467+ join ( cwd , 'config.toml' ) ,
1468+ [
1469+ 'default_model = "stub"' ,
1470+ '' ,
1471+ '[providers.stub]' ,
1472+ 'type = "openai"' ,
1473+ 'base_url = "http://127.0.0.1:9999"' ,
1474+ 'api_key = "stub"' ,
1475+ '' ,
1476+ '[models.stub]' ,
1477+ 'provider = "stub"' ,
1478+ 'model = "stub"' ,
1479+ 'max_context_size = 1000' ,
1480+ '' ,
1481+ ] . join ( '\n' ) ,
1482+ 'utf-8' ,
1483+ ) ;
14881484 const created = await postJson < SessionWire > ( '/api/v1/sessions' , { metadata : { cwd } } ) ;
14891485 const id = created . body . data . id ;
14901486 expect ( created . body . data . title ) . toBe ( '' ) ;
0 commit comments