@@ -3019,5 +3019,119 @@ This is a test agent that handles various tasks.
30193019 }
30203020 } )
30213021 } )
3022+
3023+ describe ( "force parameter" , ( ) => {
3024+ it ( "should skip version compatibility check when force is true" , ( ) => {
3025+ const { writeFileSync, unlinkSync, existsSync : fsExistsSync } = require ( "node:fs" )
3026+ const tempPath = join ( import . meta. dirname , "temp-force-version.md" )
3027+ try {
3028+ const content = `---
3029+ version: 1.0
3030+ requires: ">=99.0.0"
3031+ ---
3032+ # Test Agent
3033+
3034+ This is a test agent that handles various tasks.
3035+ ` . padEnd ( MIN_CONTENT_LENGTH + 50 , " " )
3036+ writeFileSync ( tempPath , content )
3037+
3038+ // Without force, this should fail
3039+ const resultWithoutForce = validateAgentFile ( tempPath , "1.0.0" , false )
3040+ expect ( resultWithoutForce . valid ) . toBe ( false )
3041+ expect ( resultWithoutForce . error ) . toContain ( "Incompatible OpenCode version" )
3042+
3043+ // With force, this should succeed and indicate version check was skipped
3044+ const resultWithForce = validateAgentFile ( tempPath , "1.0.0" , true )
3045+ expect ( resultWithForce . valid ) . toBe ( true )
3046+ expect ( resultWithForce . skippedVersionCheck ) . toBe ( true )
3047+ } finally {
3048+ if ( fsExistsSync ( tempPath ) ) {
3049+ unlinkSync ( tempPath )
3050+ }
3051+ }
3052+ } )
3053+
3054+ it ( "should not set skippedVersionCheck when version is compatible" , ( ) => {
3055+ const { writeFileSync, unlinkSync, existsSync : fsExistsSync } = require ( "node:fs" )
3056+ const tempPath = join ( import . meta. dirname , "temp-force-compatible.md" )
3057+ try {
3058+ const content = `---
3059+ version: 1.0
3060+ requires: ">=1.0.0"
3061+ ---
3062+ # Test Agent
3063+
3064+ This is a test agent that handles various tasks.
3065+ ` . padEnd ( MIN_CONTENT_LENGTH + 50 , " " )
3066+ writeFileSync ( tempPath , content )
3067+
3068+ // Version is compatible, so skippedVersionCheck should not be set
3069+ const result = validateAgentFile ( tempPath , "1.0.0" , true )
3070+ expect ( result . valid ) . toBe ( true )
3071+ expect ( result . skippedVersionCheck ) . toBeUndefined ( )
3072+ } finally {
3073+ if ( fsExistsSync ( tempPath ) ) {
3074+ unlinkSync ( tempPath )
3075+ }
3076+ }
3077+ } )
3078+
3079+ it ( "should still validate content structure when force is true" , ( ) => {
3080+ const { writeFileSync, unlinkSync, existsSync : fsExistsSync } = require ( "node:fs" )
3081+ const tempPath = join ( import . meta. dirname , "temp-force-invalid-content.md" )
3082+ try {
3083+ // Content without frontmatter should still fail even with force
3084+ writeFileSync (
3085+ tempPath ,
3086+ "# No Frontmatter\n\nThis agent has no frontmatter but mentions agent and task." . padEnd (
3087+ MIN_CONTENT_LENGTH + 10 ,
3088+ " " ,
3089+ ) ,
3090+ )
3091+ const result = validateAgentFile ( tempPath , "1.0.0" , true )
3092+ expect ( result . valid ) . toBe ( false )
3093+ expect ( result . error ) . toContain ( "frontmatter" )
3094+ } finally {
3095+ if ( fsExistsSync ( tempPath ) ) {
3096+ unlinkSync ( tempPath )
3097+ }
3098+ }
3099+ } )
3100+
3101+ it ( "should default force to false when not provided" , ( ) => {
3102+ const { writeFileSync, unlinkSync, existsSync : fsExistsSync } = require ( "node:fs" )
3103+ const tempPath = join ( import . meta. dirname , "temp-force-default.md" )
3104+ try {
3105+ const content = `---
3106+ version: 1.0
3107+ requires: ">=99.0.0"
3108+ ---
3109+ # Test Agent
3110+
3111+ This is a test agent that handles various tasks.
3112+ ` . padEnd ( MIN_CONTENT_LENGTH + 50 , " " )
3113+ writeFileSync ( tempPath , content )
3114+
3115+ // Without explicit force parameter, should fail on incompatible version
3116+ const result = validateAgentFile ( tempPath , "1.0.0" )
3117+ expect ( result . valid ) . toBe ( false )
3118+ expect ( result . error ) . toContain ( "Incompatible OpenCode version" )
3119+ } finally {
3120+ if ( fsExistsSync ( tempPath ) ) {
3121+ unlinkSync ( tempPath )
3122+ }
3123+ }
3124+ } )
3125+
3126+ it ( "should work with actual agent files when force is true" , ( ) => {
3127+ const agentsDir = join ( import . meta. dirname , ".." , "agents" )
3128+ for ( const name of AGENT_NAMES ) {
3129+ const filePath = join ( agentsDir , `${ name } .md` )
3130+ const result = validateAgentFile ( filePath , "0.0.1" , true )
3131+ // With force=true, even incompatible versions should pass
3132+ expect ( result . valid ) . toBe ( true )
3133+ }
3134+ } )
3135+ } )
30223136 } )
30233137} )
0 commit comments