22import { existsSync , readFileSync } from 'node:fs' ;
33import { homedir } from 'node:os' ;
44import { resolve } from 'node:path' ;
5+ import Ajv from 'ajv' ;
56
67type Baseline = {
78 dependencies : Record < string , string > ;
@@ -15,6 +16,7 @@ function main() {
1516 const cwd = process . cwd ( ) ;
1617 const baselinePath = resolve ( cwd , 'deps-baseline.json' ) ;
1718 const packagePath = resolve ( cwd , 'package.json' ) ;
19+ const contextSchemaPath = resolve ( cwd , 'schemas' , 'wallet-context.v1.schema.json' ) ;
1820
1921 if ( ! existsSync ( baselinePath ) ) {
2022 console . error ( `[deps:check] missing deps-baseline.json at ${ baselinePath } ` ) ;
@@ -48,15 +50,23 @@ function main() {
4850 const contextPath =
4951 process . env . PORTKEY_SKILL_WALLET_CONTEXT_PATH ||
5052 resolve ( homedir ( ) , '.portkey' , 'skill-wallet' , 'context.v1.json' ) ;
51- if ( existsSync ( contextPath ) ) {
53+ if ( ! existsSync ( contextSchemaPath ) ) {
54+ failures . push ( `missing wallet-context schema: ${ contextSchemaPath } ` ) ;
55+ } else if ( existsSync ( contextPath ) ) {
5256 try {
57+ const schema = readJson < Record < string , unknown > > ( contextSchemaPath ) ;
5358 const contextRaw = readJson < Record < string , unknown > > ( contextPath ) ;
54- if ( contextRaw . version !== 1 ) {
55- failures . push ( `wallet-context version expected 1, got ${ String ( contextRaw . version ) } ` ) ;
59+ const ajv = new Ajv ( { allErrors : true , strict : false } ) ;
60+ const validate = ajv . compile ( schema ) ;
61+ if ( ! validate ( contextRaw ) ) {
62+ const details = ( validate . errors || [ ] )
63+ . map ( ( err ) => `${ err . instancePath || '/' } ${ err . message || 'invalid' } ` )
64+ . join ( '; ' ) ;
65+ failures . push ( `wallet-context schema validation failed (${ contextPath } ): ${ details } ` ) ;
5666 }
5767 } catch ( error ) {
5868 const message = error instanceof Error ? error . message : String ( error ) ;
59- failures . push ( `wallet-context parse failed: ${ message } ` ) ;
69+ failures . push ( `wallet-context parse/validation failed: ${ message } ` ) ;
6070 }
6171 }
6272
0 commit comments