@@ -1272,6 +1272,78 @@ describe("anthropic provider replay hooks", () => {
12721272 }
12731273 } ) ;
12741274
1275+ it ( "preflights non-interactive setup-token input without writing credentials" , async ( ) => {
1276+ const provider = await registerSingleProviderPlugin ( anthropicPlugin ) ;
1277+ const setupTokenAuth = provider . auth . find ( ( entry ) => entry . id === "setup-token" ) ;
1278+ if ( ! setupTokenAuth ?. validateNonInteractive ) {
1279+ throw new Error ( "expected setup-token reset preflight" ) ;
1280+ }
1281+ const runtime = { log : vi . fn ( ) , error : vi . fn ( ) , exit : vi . fn ( ) } ;
1282+
1283+ const valid = await setupTokenAuth . validateNonInteractive ( {
1284+ authChoice : "setup-token" ,
1285+ config : { } ,
1286+ baseConfig : { } ,
1287+ opts : { token : ANTHROPIC_SETUP_TOKEN } ,
1288+ runtime,
1289+ resolveApiKey : vi . fn ( async ( ) => null ) ,
1290+ } ) ;
1291+
1292+ expect ( valid ) . toBe ( true ) ;
1293+ expect ( runtime . error ) . not . toHaveBeenCalled ( ) ;
1294+ } ) ;
1295+
1296+ it ( "rejects setup-token ref storage during non-interactive preflight" , async ( ) => {
1297+ const provider = await registerSingleProviderPlugin ( anthropicPlugin ) ;
1298+ const setupTokenAuth = provider . auth . find ( ( entry ) => entry . id === "setup-token" ) ;
1299+ if ( ! setupTokenAuth ?. validateNonInteractive ) {
1300+ throw new Error ( "expected setup-token reset preflight" ) ;
1301+ }
1302+ const runtime = { log : vi . fn ( ) , error : vi . fn ( ) , exit : vi . fn ( ) } ;
1303+
1304+ const valid = await setupTokenAuth . validateNonInteractive ( {
1305+ authChoice : "setup-token" ,
1306+ config : { } ,
1307+ baseConfig : { } ,
1308+ opts : {
1309+ token : ANTHROPIC_SETUP_TOKEN ,
1310+ secretInputMode : "ref" , // pragma: allowlist secret
1311+ } ,
1312+ runtime,
1313+ resolveApiKey : vi . fn ( async ( ) => null ) ,
1314+ } ) ;
1315+
1316+ expect ( valid ) . toBe ( false ) ;
1317+ expect ( runtime . error ) . toHaveBeenCalledWith (
1318+ "Anthropic setup-token input cannot be stored with --secret-input-mode ref. Use --secret-input-mode plaintext." ,
1319+ ) ;
1320+ expect ( runtime . exit ) . toHaveBeenCalledWith ( 1 ) ;
1321+ } ) ;
1322+
1323+ it ( "rejects invalid setup-token expiry during non-interactive preflight" , async ( ) => {
1324+ const provider = await registerSingleProviderPlugin ( anthropicPlugin ) ;
1325+ const setupTokenAuth = provider . auth . find ( ( entry ) => entry . id === "setup-token" ) ;
1326+ if ( ! setupTokenAuth ?. validateNonInteractive ) {
1327+ throw new Error ( "expected setup-token reset preflight" ) ;
1328+ }
1329+ const runtime = { log : vi . fn ( ) , error : vi . fn ( ) , exit : vi . fn ( ) } ;
1330+
1331+ const valid = await setupTokenAuth . validateNonInteractive ( {
1332+ authChoice : "setup-token" ,
1333+ config : { } ,
1334+ baseConfig : { } ,
1335+ opts : { token : ANTHROPIC_SETUP_TOKEN , tokenExpiresIn : "nope" } ,
1336+ runtime,
1337+ resolveApiKey : vi . fn ( async ( ) => null ) ,
1338+ } ) ;
1339+
1340+ expect ( valid ) . toBe ( false ) ;
1341+ expect ( runtime . error ) . toHaveBeenCalledWith (
1342+ expect . stringContaining ( "Invalid --token-expires-in" ) ,
1343+ ) ;
1344+ expect ( runtime . exit ) . toHaveBeenCalledWith ( 1 ) ;
1345+ } ) ;
1346+
12751347 it ( "omits setup-token expiry when duration overflows the Date range" , async ( ) => {
12761348 vi . useFakeTimers ( ) ;
12771349 vi . setSystemTime ( 8_640_000_000_000_000 ) ;
0 commit comments