@@ -605,7 +605,7 @@ describe("Crabbox gate publisher mutation boundary", () => {
605605} ) ;
606606
607607describe ( "Crabbox broker authentication" , ( ) => {
608- it ( "requires and sends coordinator plus Cloudflare Access credentials" , async ( ) => {
608+ it ( "sends bearer and complete Cloudflare Access credentials" , async ( ) => {
609609 const fetchImpl = vi . fn < typeof fetch > ( async ( _input , init ) => {
610610 expect ( init ?. headers ) . toEqual ( {
611611 Authorization : "Bearer coordinator-token" ,
@@ -627,15 +627,52 @@ describe("Crabbox broker authentication", () => {
627627 await expect ( api . request ( "/v1/runs/run_abc123" ) ) . resolves . toEqual ( {
628628 run : { id : "run_abc123" } ,
629629 } ) ;
630- expect ( ( ) =>
631- createJsonApi ( {
632- accessClientId : "" ,
633- accessClientSecret : "access-secret" ,
634- baseUrl : "https://broker.example/" ,
635- fetchImpl,
636- token : "coordinator-token" ,
637- } ) ,
638- ) . toThrow ( / A c c e s s c l i e n t i d / u) ;
630+ } ) ;
631+
632+ it ( "sends bearer-only authentication when Cloudflare Access is absent" , async ( ) => {
633+ const fetchImpl = vi . fn < typeof fetch > ( async ( _input , init ) => {
634+ expect ( init ?. headers ) . toEqual ( {
635+ Authorization : "Bearer coordinator-token" ,
636+ } ) ;
637+ return new Response ( '{"run":{"id":"run_abc123"}}' , {
638+ headers : { "Content-Type" : "application/json" } ,
639+ status : 200 ,
640+ } ) ;
641+ } ) ;
642+ const api = createJsonApi ( {
643+ accessClientId : "" ,
644+ accessClientSecret : "" ,
645+ baseUrl : "https://broker.example/" ,
646+ fetchImpl,
647+ token : "coordinator-token" ,
648+ } ) ;
649+ await expect ( api . request ( "/v1/runs/run_abc123" ) ) . resolves . toEqual ( {
650+ run : { id : "run_abc123" } ,
651+ } ) ;
652+ } ) ;
653+
654+ it . each ( [
655+ [ "client secret" , "access-id" , "" ] ,
656+ [ "client id" , "" , "access-secret" ] ,
657+ ] ) (
658+ "rejects a Cloudflare Access half-pair missing %s" ,
659+ ( _label , accessClientId , accessClientSecret ) => {
660+ expect ( ( ) =>
661+ createJsonApi ( {
662+ accessClientId,
663+ accessClientSecret,
664+ baseUrl : "https://broker.example/" ,
665+ token : "coordinator-token" ,
666+ } ) ,
667+ ) . toThrow ( / m u s t b e p r o v i d e d t o g e t h e r / u) ;
668+ } ,
669+ ) ;
670+
671+ it . each ( [
672+ [ "coordinator URL" , { baseUrl : "" , token : "coordinator-token" } ] ,
673+ [ "coordinator token" , { baseUrl : "https://broker.example/" , token : "" } ] ,
674+ ] ) ( "requires the %s" , ( _label , values ) => {
675+ expect ( ( ) => createJsonApi ( values ) ) . toThrow ( / r e q u i r e d / u) ;
639676 } ) ;
640677} ) ;
641678
@@ -645,7 +682,11 @@ describe("Crabbox gate workflow", () => {
645682 readFileSync ( ".github/workflows/pr-crabbox-gate-publisher.yml" , "utf8" ) ,
646683 ) as {
647684 jobs : {
648- publish : { permissions : Record < string , string > ; steps : Array < Record < string , unknown > > } ;
685+ publish : {
686+ environment : string ;
687+ permissions : Record < string , string > ;
688+ steps : Array < Record < string , unknown > > ;
689+ } ;
649690 } ;
650691 on : { workflow_dispatch : { inputs : Record < string , unknown > } } ;
651692 permissions : Record < string , string > ;
@@ -659,6 +700,7 @@ describe("Crabbox gate workflow", () => {
659700 "pr_number" ,
660701 ] ) ;
661702 expect ( workflow . permissions ) . toEqual ( { } ) ;
703+ expect ( workflow . jobs . publish . environment ) . toBe ( "qa-live-shared" ) ;
662704 expect ( workflow . jobs . publish . permissions ) . toEqual ( {
663705 checks : "write" ,
664706 contents : "read" ,
@@ -675,8 +717,10 @@ describe("Crabbox gate workflow", () => {
675717 env : {
676718 CRABBOX_ACCESS_CLIENT_ID : "${{ secrets.CRABBOX_ACCESS_CLIENT_ID }}" ,
677719 CRABBOX_ACCESS_CLIENT_SECRET : "${{ secrets.CRABBOX_ACCESS_CLIENT_SECRET }}" ,
678- CRABBOX_COORDINATOR : "${{ secrets.CRABBOX_COORDINATOR }}" ,
679- CRABBOX_COORDINATOR_TOKEN : "${{ secrets.CRABBOX_COORDINATOR_TOKEN }}" ,
720+ CRABBOX_COORDINATOR :
721+ "${{ secrets.CRABBOX_COORDINATOR || secrets.OPENCLAW_QA_MANTIS_CRABBOX_COORDINATOR }}" ,
722+ CRABBOX_COORDINATOR_TOKEN :
723+ "${{ secrets.CRABBOX_COORDINATOR_TOKEN || secrets.OPENCLAW_QA_MANTIS_CRABBOX_COORDINATOR_TOKEN }}" ,
680724 GH_APP_TOKEN :
681725 "${{ steps.app-token.outputs.token || steps.app-token-fallback.outputs.token }}" ,
682726 GH_TOKEN : "${{ github.token }}" ,
0 commit comments