@@ -175,16 +175,19 @@ assert.match(sandboxAgentCode, /'model' => \$configured_model/)
175175const docsAgentDirectory = process . env . DOCS_AGENT_DIR
176176const publicPackageBytes = docsAgentDirectory
177177 ? await readFile ( join ( docsAgentDirectory , "bundles" , "technical-docs-agent" , "native" , "technical-docs-maintenance-agent.agent.json" ) )
178- : await readFile ( new URL ( "./fixtures/external-native-package/flat -agent.agent.json" , import . meta. url ) )
178+ : await readFile ( new URL ( "./fixtures/external-native-package/technical-bootstrap -agent.agent.json" , import . meta. url ) )
179179const publicAgentSlug = canonicalExternalNativeAgentIdentity ( publicPackageBytes ) . slug
180+ const skillsPackageBytes = await readFile ( new URL ( "./fixtures/external-native-package/skills-agent.agent.json" , import . meta. url ) )
181+ assert . deepEqual ( canonicalExternalNativeAgentIdentity ( skillsPackageBytes ) , { slug : "skills-agent" } )
182+ assert . deepEqual ( canonicalExternalNativeAgentIdentity ( publicPackageBytes ) , { slug : docsAgentDirectory ? "technical-docs-maintenance-agent" : "technical-bootstrap-agent" } )
180183const publicPackageDigest = `sha256-bytes-v1:${ await import ( "node:crypto" ) . then ( ( { createHash } ) => createHash ( "sha256" ) . update ( publicPackageBytes ) . digest ( "hex" ) ) } `
181184const bootstrapCode = await resolveSandboxTaskCode ( {
182185 task : "Say hello" ,
183186 agent : "wp-codebox-sandbox" ,
184187 runtimeTask : {
185188 ability : "wp-codebox/run-runtime-package" ,
186189 input : {
187- package : { slug : "caller-controlled-agent" , source : "public-external-package" , bootstrap : { encoding : "base64" , bytes : publicPackageBytes . toString ( "base64" ) , digest : publicPackageDigest } } ,
190+ package : { slug : publicAgentSlug , source : "public-external-package" , bootstrap : { encoding : "base64" , bytes : publicPackageBytes . toString ( "base64" ) , digest : publicPackageDigest } } ,
188191 } ,
189192 } ,
190193 sandboxToolPolicy : { schema : "wp-codebox/sandbox-tool-policy/v1" , version : 1 , tools : [ ] } ,
@@ -211,6 +214,30 @@ assert.match(bootstrapCode, /wp_codebox_import_external_runtime_agent_package/)
211214assert . ok ( bootstrapCode . indexOf ( "wp_codebox_import_external_runtime_agent_package" ) < bootstrapCode . indexOf ( "wp_codebox_resolve_runtime_task_ability" ) )
212215assert . match ( bootstrapCode , / b a s e 6 4 _ d e c o d e \( \$ b o o t s t r a p \[ ' b y t e s ' \] , t r u e \) / )
213216
217+ const spoofedBootstrapCode = await resolveSandboxTaskCode ( {
218+ task : "Say hello" ,
219+ agent : "wp-codebox-sandbox" ,
220+ runtimeTask : {
221+ ability : "wp-codebox/run-runtime-package" ,
222+ input : {
223+ package : { slug : publicAgentSlug , source : "public-external-package" , bootstrap : { encoding : "base64" , bytes : publicPackageBytes . toString ( "base64" ) , digest : publicPackageDigest } } ,
224+ input : { agent : "caller-controlled-agent" } ,
225+ } ,
226+ } ,
227+ sandboxToolPolicy : { schema : "wp-codebox/sandbox-tool-policy/v1" , version : 1 , tools : [ ] } ,
228+ } )
229+ const spoofedBootstrapOutput = execFileSync ( "php" , [ "-r" , `${ phpPreamble }
230+ function wp_agent_import_runtime_bundles($bundles, $options) {
231+ $package = json_decode((string) file_get_contents((string) ($bundles[0]['source'] ?? '')), true);
232+ $slug = $package['agent']['agent_slug'] ?? '';
233+ WP_Agents_Registry::get_instance()->register($slug, array('source' => 'canonical-importer'));
234+ return array(array('success' => true, 'agent_slug' => $slug));
235+ }
236+ ${ spoofedBootstrapCode } `] , { encoding : "utf8" } )
237+ const spoofedBootstrap = JSON . parse ( spoofedBootstrapOutput ) as { agent_runtime ?: { success ?: boolean , error ?: { code ?: string } } }
238+ assert . equal ( spoofedBootstrap . agent_runtime ?. success , false )
239+ assert . equal ( spoofedBootstrap . agent_runtime ?. error ?. code , "wp_codebox_external_runtime_package_identity_mismatch" )
240+
214241const failedImportOutput = execFileSync ( "php" , [ "-r" , `${ phpPreamble }
215242function wp_agent_import_runtime_bundles($bundles, $options) { $GLOBALS['external_source'] = $bundles[0]['source']; return array(array('success' => false)); }
216243${ bootstrapCode } `] , {
0 commit comments