@@ -12,6 +12,8 @@ import type { Project, ProjectEvent } from "../../../../handlers/project/types";
1212import { ProjectSpecSchema } from "../../../../projectSchemas/project" ;
1313import type { CoreOptions } from "../../../types" ;
1414import { EnvLocalFile } from "../../envLocal" ;
15+ import { v0Fixture } from "../../legacy/fixtures-test-support" ;
16+ import { translateV0Spec } from "../../legacy/translate" ;
1517import {
1618 createCredentialProvisioner ,
1719 createCredentialRemover ,
@@ -80,6 +82,15 @@ async function project(credentials: unknown[], envLocal?: string): Promise<Proje
8082 } ;
8183}
8284
85+ /** The same project loaded from a v0 `agentcore.json`. */
86+ async function legacyProject ( credentials : unknown [ ] , envLocal ?: string ) : Promise < Project > {
87+ const v0Spec = v0Fixture ( "baseline.json" ) ;
88+ return {
89+ ...( await project ( credentials , envLocal ) ) ,
90+ legacy : { format : "v0" , v0Spec, extras : translateV0Spec ( v0Spec ) . extras } ,
91+ } ;
92+ }
93+
8394type ProviderKind = "apikey" | "oauth" | "payment" ;
8495
8596/**
@@ -986,3 +997,99 @@ describe("createCredentialRemover", () => {
986997 expect ( subject . contents ( ) ) . toEqual ( { [ OPENAI_PROVIDER ] : existing } ) ;
987998 } ) ;
988999} ) ;
1000+
1001+ describe ( "v0 projects" , ( ) => {
1002+ // The v0 CLI named every provider by the bare credential name, and the agent code it
1003+ // deployed looks providers up by that name, so a v0 project keeps it.
1004+ const COINBASE_ENV =
1005+ "AGENTCORE_CREDENTIAL_WALLET_API_KEY_ID='key-1'\n" +
1006+ "AGENTCORE_CREDENTIAL_WALLET_API_KEY_SECRET='secret-1'\n" +
1007+ "AGENTCORE_CREDENTIAL_WALLET_WALLET_SECRET='wallet-1'\n" ;
1008+
1009+ test ( "creates providers under the bare credential name, recorded under the spec name" , async ( ) => {
1010+ const subject = account ( ) ;
1011+ const input = await legacyProject (
1012+ [ API_KEY , COINBASE ] ,
1013+ "AGENTCORE_CREDENTIAL_OPENAI_KEY='sk-live'\n" + COINBASE_ENV ,
1014+ ) ;
1015+
1016+ const { events, result } = await run ( subject . provision , input ) ;
1017+
1018+ expect ( stepMessages ( events ) ) . toEqual ( [
1019+ "Preparing credential provider 'openai-key'" ,
1020+ "Preparing credential provider 'wallet'" ,
1021+ ] ) ;
1022+ expect ( Object . keys ( subject . contents ( ) ) ) . toEqual ( [ "openai-key" , "wallet" ] ) ;
1023+ expect ( subject . configFor ( "openai-key" ) ) . toEqual ( { name : "openai-key" , apiKey : "sk-live" } ) ;
1024+ expect ( result ) . toEqual ( {
1025+ "openai-key" : recordedAs ( "ApiKeyCredentialProvider" , {
1026+ credentialProviderArn : "arn:apikey:openai-key" ,
1027+ clientSecretArn : "arn:secret:openai-key" ,
1028+ } ) ,
1029+ wallet : recordedAs ( "PaymentCredentialProvider" , {
1030+ credentialProviderArn : "arn:payment:wallet" ,
1031+ } ) ,
1032+ } ) ;
1033+ } ) ;
1034+
1035+ test ( "updates the provider v0 created rather than creating a scoped one" , async ( ) => {
1036+ const subject = account ( { "my-oauth" : { credentialProviderArn : "arn:oauth:my-oauth" } } ) ;
1037+ const input = await legacyProject (
1038+ [ OAUTH ] ,
1039+ "AGENTCORE_CREDENTIAL_MY_OAUTH_CLIENT_SECRET='rotated'\n" ,
1040+ ) ;
1041+
1042+ const { result } = await run ( subject . provision , input ) ;
1043+
1044+ expect ( Object . keys ( subject . contents ( ) ) ) . toEqual ( [ "my-oauth" ] ) ;
1045+ expect ( subject . contents ( ) [ "my-oauth" ] ?. operation ) . toBe ( "updated" ) ;
1046+ expect ( result [ "my-oauth" ] ?. credentialProviderArn ) . toBe ( "arn:oauth:my-oauth" ) ;
1047+ } ) ;
1048+
1049+ test ( "reuses the provider v0 created when no secret is available locally" , async ( ) => {
1050+ const existing = { credentialProviderArn : "arn:apikey:openai-key" } ;
1051+ const subject = account ( { "openai-key" : existing } ) ;
1052+
1053+ const { result } = await run ( subject . provision , await legacyProject ( [ API_KEY ] ) ) ;
1054+
1055+ expect ( subject . contents ( ) ) . toEqual ( { "openai-key" : existing } ) ;
1056+ expect ( result ) . toEqual ( { "openai-key" : recordedAs ( "ApiKeyCredentialProvider" , existing ) } ) ;
1057+ } ) ;
1058+
1059+ test ( "rolls back a provider it created under the bare name" , async ( ) => {
1060+ const subject = account ( { } , { createFailsFor : "wallet" } ) ;
1061+ const input = await legacyProject (
1062+ [ API_KEY , COINBASE ] ,
1063+ "AGENTCORE_CREDENTIAL_OPENAI_KEY='sk-live'\n" + COINBASE_ENV ,
1064+ ) ;
1065+
1066+ await runFailing ( subject . provision , input ) ;
1067+
1068+ expect ( subject . deleted ) . toEqual ( [ { kind : "apikey" , name : "openai-key" } ] ) ;
1069+ } ) ;
1070+
1071+ test ( "never deletes API key or OAuth providers, which v0 projects may share" , async ( ) => {
1072+ const subject = account ( {
1073+ "openai-key" : { credentialProviderArn : "arn:apikey:openai-key" } ,
1074+ "my-oauth" : { credentialProviderArn : "arn:oauth:my-oauth" } ,
1075+ wallet : { credentialProviderArn : "arn:payment:wallet" } ,
1076+ } ) ;
1077+ const input = await legacyProject ( [ ] ) ;
1078+
1079+ const { events } = await collect (
1080+ createCredentialRemover ( subject . client ) ( input , {
1081+ ...INPUT ,
1082+ providers : [ API_KEY , OAUTH , COINBASE ] ,
1083+ } ) ,
1084+ ) ;
1085+
1086+ // Payment providers are removed as v0's teardown removed them, by the bare name.
1087+ expect ( subject . deleted ) . toEqual ( [ { kind : "payment" , name : "wallet" } ] ) ;
1088+ expect ( Object . keys ( subject . contents ( ) ) ) . toEqual ( [ "openai-key" , "my-oauth" ] ) ;
1089+ expect ( stepMessages ( events ) ) . toEqual ( [
1090+ "Leaving credential provider 'openai-key' in place: v0 projects can share it" ,
1091+ "Leaving credential provider 'my-oauth' in place: v0 projects can share it" ,
1092+ "Removing credential provider 'wallet'" ,
1093+ ] ) ;
1094+ } ) ;
1095+ } ) ;
0 commit comments