@@ -748,6 +748,30 @@ test("incognito webchat rejects a vanished non-default-agent session before disp
748748 }
749749} ) ;
750750
751+ test ( "createGatewaySession rejects explicit and key-derived unconfigured creation owners" , async ( ) => {
752+ const { createGatewaySession } = await import ( "./session-create-service.js" ) ;
753+ const cfg = { agents : { entries : { ops : { default : true } } } } ;
754+ const prepareLifecycle = vi . fn ( ) ;
755+
756+ for ( const { owner, message } of [
757+ { owner : { agentId : "main" } , message : 'Unknown agent id "main"' } ,
758+ {
759+ owner : { key : "agent:main:dashboard:unconfigured-owner" } ,
760+ message : 'Unknown agent id "main"' ,
761+ } ,
762+ { owner : { agentId : " " } , message : 'Unknown agent id " "' } ,
763+ ] ) {
764+ await expect (
765+ createGatewaySession ( { cfg, ...owner , commandSource : "test" , prepareLifecycle } ) ,
766+ ) . resolves . toMatchObject ( {
767+ ok : false ,
768+ error : { code : "INVALID_REQUEST" , message } ,
769+ } ) ;
770+ }
771+
772+ expect ( prepareLifecycle ) . not . toHaveBeenCalled ( ) ;
773+ } ) ;
774+
751775test ( "createGatewaySession rechecks admin scope after incognito inheritance resolves" , async ( ) => {
752776 await createSessionStoreDir ( ) ;
753777 try {
@@ -2879,6 +2903,7 @@ test("sessions.create rejects worktrees for agent workspaces without a commit",
28792903
28802904test ( "sessions.create stores dashboard model, thinking, and parent linkage, and creates a transcript" , async ( ) => {
28812905 const { storePath } = await createSessionStoreDir ( ) ;
2906+ testState . agentsConfig = { list : [ { id : "main" , default : true } , { id : "ops" } ] } ;
28822907 agentDiscoveryMock . enabled = true ;
28832908 agentDiscoveryMock . models = [ { id : "gpt-test-a" , name : "A" , provider : "openai" } ] ;
28842909 await writeSessionStore ( {
@@ -3737,6 +3762,7 @@ test("sessions.create resolves the current default instead of inherited runtime
37373762
37383763test ( "sessions.create accepts an explicit key for persistent dashboard sessions" , async ( ) => {
37393764 await createSessionStoreDir ( ) ;
3765+ testState . agentsConfig = { list : [ { id : "main" , default : true } , { id : "ops-agent" } ] } ;
37403766
37413767 const key = "agent:ops-agent:dashboard:direct:subagent-orchestrator" ;
37423768 const created = await directSessionReq < {
@@ -4120,6 +4146,8 @@ test("sessions.create adopting an existing key does not restamp node provenance"
41204146
41214147test ( "sessions.create scopes the main alias to the requested agent" , async ( ) => {
41224148 const { storePath } = await createSessionStoreDir ( ) ;
4149+ testState . agentsConfig = { list : [ { id : "main" , default : true } , { id : "longmemeval" } ] } ;
4150+ testState . agentConfig = { sessionStore : { agentId : "longmemeval" } } ;
41234151
41244152 const created = await directSessionReq < {
41254153 key ?: string ;
@@ -4132,7 +4160,7 @@ test("sessions.create scopes the main alias to the requested agent", async () =>
41324160 agentId : "longmemeval" ,
41334161 } ) ;
41344162
4135- expect ( created . ok ) . toBe ( true ) ;
4163+ expect ( created . ok , JSON . stringify ( created . error ) ) . toBe ( true ) ;
41364164 expect ( created . payload ?. key ) . toBe ( "agent:longmemeval:main" ) ;
41374165 expect ( created . payload ?. entry ) . not . toHaveProperty ( "sessionFile" ) ;
41384166
@@ -4197,6 +4225,8 @@ test("sessions.create replaces a dead main entry with a fresh session id", async
41974225
41984226test ( "sessions.create preserves global and unknown sentinel keys" , async ( ) => {
41994227 const { storePath } = await createSessionStoreDir ( ) ;
4228+ testState . agentsConfig = { list : [ { id : "main" , default : true } , { id : "longmemeval" } ] } ;
4229+ testState . agentConfig = { sessionStore : { agentId : "longmemeval" } } ;
42004230
42014231 const globalCreated = await directSessionReq < {
42024232 key ?: string ;
@@ -4209,7 +4239,7 @@ test("sessions.create preserves global and unknown sentinel keys", async () => {
42094239 agentId : "longmemeval" ,
42104240 } ) ;
42114241
4212- expect ( globalCreated . ok ) . toBe ( true ) ;
4242+ expect ( globalCreated . ok , JSON . stringify ( globalCreated . error ) ) . toBe ( true ) ;
42134243 expect ( globalCreated . payload ?. key ) . toBe ( "global" ) ;
42144244 expect ( globalCreated . payload ?. entry ) . not . toHaveProperty ( "sessionFile" ) ;
42154245
@@ -4646,6 +4676,7 @@ test("sessions.create allows plugin runtimes to link their own parent session",
46464676
46474677test ( "sessions.create rejects unknown parentSessionKey" , async ( ) => {
46484678 await createSessionStoreDir ( ) ;
4679+ testState . agentsConfig = { list : [ { id : "main" , default : true } , { id : "ops" } ] } ;
46494680
46504681 const created = await directSessionReq ( "sessions.create" , {
46514682 agentId : "ops" ,
0 commit comments