@@ -463,27 +463,40 @@ describe("TangledSourceControlProvider.make", () => {
463463 } ) . pipe ( serve ( tg ) ) ;
464464 } ) ;
465465
466- it . effect ( "creates a repository and returns its clone URLs" , ( ) => {
467- const tg = fakeTg ( {
468- "repo create repo" : {
469- stdout : encodeJson ( { name : "repo" , author : "alice.example" , knot : "knot1.tangled.sh" } ) ,
470- } ,
471- } ) ;
472- return Effect . gen ( function * ( ) {
473- const provider = yield * TangledSourceControlProvider . make ;
474- const urls = yield * provider . createRepository ( {
475- cwd : "/repo" ,
476- repository : "alice.example/repo" ,
477- visibility : "public" ,
478- } ) ;
479- assert . deepStrictEqual ( urls , {
480- nameWithOwner : "alice.example/repo" ,
481- url : "https://tangled.org/alice.example/repo" ,
482- sshUrl :
"[email protected] :alice.example/repo" , 466+ it . effect . each ( [ "alice.example" , "did:plc:alice" ] ) (
467+ "creates a repository for the confirmed owner %s" ,
468+ ( owner ) => {
469+ const tg = fakeTg ( {
470+ "auth status" : {
471+ stdout : encodeJson ( {
472+ authenticated : true ,
473+ handle : "alice.example" ,
474+ did : "did:plc:alice" ,
475+ } ) ,
476+ } ,
477+ "repo create repo" : {
478+ stdout : encodeJson ( { name : "repo" , author : "alice.example" , knot : "knot1.tangled.sh" } ) ,
479+ } ,
483480 } ) ;
484- assert . deepStrictEqual ( tg . calls , [ [ "repo" , "create" , "repo" ] ] ) ;
485- } ) . pipe ( serve ( tg ) ) ;
486- } ) ;
481+ return Effect . gen ( function * ( ) {
482+ const provider = yield * TangledSourceControlProvider . make ;
483+ const urls = yield * provider . createRepository ( {
484+ cwd : "/repo" ,
485+ repository : `${ owner } /repo` ,
486+ visibility : "public" ,
487+ } ) ;
488+ assert . deepStrictEqual ( urls , {
489+ nameWithOwner : `${ owner } /repo` ,
490+ url : `https://tangled.org/${ owner } /repo` ,
491+ sshUrl :
`[email protected] :${ owner } /repo` , 492+ } ) ;
493+ assert . deepStrictEqual ( tg . calls , [
494+ [ "auth" , "status" ] ,
495+ [ "repo" , "create" , "repo" ] ,
496+ ] ) ;
497+ } ) . pipe ( serve ( tg ) ) ;
498+ } ,
499+ ) ;
487500
488501 it . effect ( "rejects malformed repository paths before invoking tg" , ( ) => {
489502 const tg = fakeTg ( { } ) ;
@@ -508,8 +521,9 @@ describe("TangledSourceControlProvider.make", () => {
508521 } ) . pipe ( serve ( tg ) ) ;
509522 } ) ;
510523
511- it . effect ( "says so when tg created the repository under a different account " , ( ) => {
524+ it . effect ( "rejects a different signed-in handle before creating a repository " , ( ) => {
512525 const tg = fakeTg ( {
526+ "auth status" : { stdout : encodeJson ( { authenticated : true , handle : "alice.example" } ) } ,
513527 "repo create repo" : {
514528 stdout : encodeJson ( { name : "repo" , author : "alice.example" , knot : "knot1.tangled.sh" } ) ,
515529 } ,
@@ -519,12 +533,14 @@ describe("TangledSourceControlProvider.make", () => {
519533 const error = yield * provider
520534 . createRepository ( { cwd : "/repo" , repository : "someone-else/repo" , visibility : "public" } )
521535 . pipe ( Effect . flip ) ;
522- assert . match ( error . detail , / n o t s o m e o n e - e l s e / u) ;
536+ assert . match ( error . detail , / s o m e o n e - e l s e / u) ;
537+ assert . deepStrictEqual ( tg . calls , [ [ "auth" , "status" ] ] ) ;
523538 } ) . pipe ( serve ( tg ) ) ;
524539 } ) ;
525540
526- it . effect ( "rejects clone URLs when tg created the repository under a different DID " , ( ) => {
541+ it . effect ( "rejects a different signed-in DID before creating a repository " , ( ) => {
527542 const tg = fakeTg ( {
543+ "auth status" : { stdout : encodeJson ( { authenticated : true , did : "did:plc:bob" } ) } ,
528544 "repo create repo" : {
529545 stdout : encodeJson ( { name : "repo" , author : "did:plc:bob" , knot : "knot1.tangled.sh" } ) ,
530546 } ,
@@ -540,6 +556,28 @@ describe("TangledSourceControlProvider.make", () => {
540556 . pipe ( Effect . flip ) ;
541557 assert . match ( error . detail , / d i d : p l c : b o b / u) ;
542558 assert . match ( error . detail , / d i d : p l c : a l i c e / u) ;
559+ assert . deepStrictEqual ( tg . calls , [ [ "auth" , "status" ] ] ) ;
560+ } ) . pipe ( serve ( tg ) ) ;
561+ } ) ;
562+
563+ it . effect . each ( [
564+ { authenticated : false , handle : "alice.example" } ,
565+ { authenticated : true } ,
566+ { authenticated : true , status : "expired" , handle : "alice.example" } ,
567+ { authenticated : true , status : "unknown" , handle : "alice.example" } ,
568+ ] ) ( "does not create when the signed-in owner cannot be confirmed: %j" , ( account ) => {
569+ const tg = fakeTg ( { "auth status" : { stdout : encodeJson ( account ) } } ) ;
570+ return Effect . gen ( function * ( ) {
571+ const provider = yield * TangledSourceControlProvider . make ;
572+ const error = yield * provider
573+ . createRepository ( {
574+ cwd : "/repo" ,
575+ repository : "alice.example/repo" ,
576+ visibility : "public" ,
577+ } )
578+ . pipe ( Effect . flip ) ;
579+ assert . match ( error . detail , / C a n n o t c o n f i r m / u) ;
580+ assert . deepStrictEqual ( tg . calls , [ [ "auth" , "status" ] ] ) ;
543581 } ) . pipe ( serve ( tg ) ) ;
544582 } ) ;
545583
0 commit comments