@@ -114,6 +114,21 @@ const nostrTestPlugin = {
114114
115115const nostrConfigure = createPluginSetupWizardConfigure ( nostrTestPlugin ) ;
116116
117+ function withoutNostrPrivateKey < T > ( run : ( ) => T ) : T {
118+ const hadValue = Object . hasOwn ( process . env , "NOSTR_PRIVATE_KEY" ) ;
119+ const previous = process . env . NOSTR_PRIVATE_KEY ;
120+ delete process . env . NOSTR_PRIVATE_KEY ;
121+ try {
122+ return run ( ) ;
123+ } finally {
124+ if ( hadValue && previous !== undefined ) {
125+ process . env . NOSTR_PRIVATE_KEY = previous ;
126+ } else {
127+ delete process . env . NOSTR_PRIVATE_KEY ;
128+ }
129+ }
130+ }
131+
117132function requireNostrLooksLikeId ( ) {
118133 const looksLikeId = nostrTestPlugin . messaging ?. targetResolver ?. looksLikeId ;
119134 if ( ! looksLikeId ) {
@@ -210,7 +225,7 @@ describe("nostrPlugin", () => {
210225 describe ( "config adapter" , ( ) => {
211226 it ( "listAccountIds returns empty array for unconfigured" , ( ) => {
212227 const cfg = { channels : { } } ;
213- const ids = nostrTestPlugin . config . listAccountIds ( cfg ) ;
228+ const ids = withoutNostrPrivateKey ( ( ) => nostrTestPlugin . config . listAccountIds ( cfg ) ) ;
214229 expect ( ids ) . toStrictEqual ( [ ] ) ;
215230 } ) ;
216231
@@ -447,12 +462,12 @@ describe("nostr account helpers", () => {
447462 describe ( "listNostrAccountIds" , ( ) => {
448463 it ( "returns empty array when not configured" , ( ) => {
449464 const cfg = { channels : { } } ;
450- expect ( listNostrAccountIds ( cfg ) ) . toStrictEqual ( [ ] ) ;
465+ expect ( withoutNostrPrivateKey ( ( ) => listNostrAccountIds ( cfg ) ) ) . toStrictEqual ( [ ] ) ;
451466 } ) ;
452467
453468 it ( "returns empty array when nostr section exists but no privateKey" , ( ) => {
454469 const cfg = { channels : { nostr : { enabled : true } } } ;
455- expect ( listNostrAccountIds ( cfg ) ) . toStrictEqual ( [ ] ) ;
470+ expect ( withoutNostrPrivateKey ( ( ) => listNostrAccountIds ( cfg ) ) ) . toStrictEqual ( [ ] ) ;
456471 } ) ;
457472
458473 it ( "returns default when privateKey is configured" , ( ) => {
@@ -503,7 +518,7 @@ describe("nostr account helpers", () => {
503518
504519 it ( "resolves unconfigured account with defaults" , ( ) => {
505520 const cfg = { channels : { } } ;
506- const account = resolveNostrAccount ( { cfg } ) ;
521+ const account = withoutNostrPrivateKey ( ( ) => resolveNostrAccount ( { cfg } ) ) ;
507522
508523 expect ( account . accountId ) . toBe ( "default" ) ;
509524 expect ( account . enabled ) . toBe ( true ) ;
@@ -602,7 +617,9 @@ describe("nostr account helpers", () => {
602617 throw new Error ( "nostr setup credential inspect missing" ) ;
603618 }
604619
605- expect ( credential . inspect ( { cfg, accountId : "default" } ) ) . toEqual ( {
620+ expect (
621+ withoutNostrPrivateKey ( ( ) => credential . inspect ( { cfg, accountId : "default" } ) ) ,
622+ ) . toEqual ( {
606623 accountConfigured : false ,
607624 hasConfiguredValue : true ,
608625 resolvedValue : undefined ,
0 commit comments