Skip to content

Commit 6448fd0

Browse files
authored
Merge pull request #491 from objectstack-ai/copilot/update-action-step-logic
2 parents 1e9c916 + f99abfd commit 6448fd0

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

packages/core/src/plugin-loader.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ export interface ServiceRegistration {
3232
}
3333

3434
/**
35-
* Plugin Configuration Validator
35+
* Plugin Configuration Validator Interface
3636
* Uses Zod for runtime validation of plugin configurations
37+
* @deprecated Use the PluginConfigValidator class from security module instead
3738
*/
38-
export interface PluginConfigValidator {
39+
export interface IPluginConfigValidator {
3940
schema: z.ZodSchema;
4041
validate(config: any): any;
4142
}

packages/core/src/security/plugin-config-validator.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { describe, it, expect, beforeEach } from 'vitest';
22
import { z } from 'zod';
3-
import { PluginConfigValidator } from '../plugin-config-validator.js';
4-
import { createLogger } from '../../logger.js';
5-
import type { PluginMetadata } from '../../plugin-loader.js';
3+
import { PluginConfigValidator } from './plugin-config-validator.js';
4+
import { createLogger } from '../logger.js';
5+
import type { PluginMetadata } from '../plugin-loader.js';
66

77
describe('PluginConfigValidator', () => {
88
let validator: PluginConfigValidator;
99
let logger: ReturnType<typeof createLogger>;
1010

1111
beforeEach(() => {
12-
logger = createLogger({ level: 'silent' });
12+
logger = createLogger({ level: 'error' });
1313
validator = new PluginConfigValidator(logger);
1414
});
1515

packages/core/src/security/plugin-config-validator.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class PluginConfigValidator {
6262
...formattedErrors.map(e => ` - ${e.path}: ${e.message}`),
6363
].join('\n');
6464

65-
this.logger.error(errorMessage, {
65+
this.logger.error(errorMessage, undefined, {
6666
plugin: plugin.name,
6767
errors: formattedErrors,
6868
});
@@ -89,7 +89,8 @@ export class PluginConfigValidator {
8989

9090
try {
9191
// Use Zod's partial() method for partial validation
92-
const partialSchema = plugin.configSchema.partial();
92+
// Cast to ZodObject to access partial() method
93+
const partialSchema = (plugin.configSchema as any).partial();
9394
const validatedConfig = partialSchema.parse(partialConfig);
9495

9596
this.logger.debug(`✅ Partial config validated: ${plugin.name}`);
@@ -171,8 +172,8 @@ export class PluginConfigValidator {
171172

172173
// Private methods
173174

174-
private formatZodErrors(error: z.ZodError): Array<{path: string; message: string}> {
175-
return error.errors.map(e => ({
175+
private formatZodErrors(error: z.ZodError<any>): Array<{path: string; message: string}> {
176+
return error.issues.map((e: z.ZodIssue) => ({
176177
path: e.path.join('.') || 'root',
177178
message: e.message,
178179
}));

packages/core/src/security/plugin-permission-enforcer.test.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import { describe, it, expect, beforeEach } from 'vitest';
2-
import { PluginPermissionEnforcer, SecurePluginContext } from '../plugin-permission-enforcer.js';
3-
import { createLogger } from '../../logger.js';
2+
import { PluginPermissionEnforcer, SecurePluginContext } from './plugin-permission-enforcer.js';
3+
import { createLogger } from '../logger.js';
44
import type { PluginCapability } from '@objectstack/spec/system';
5-
import type { PluginContext } from '../../types.js';
5+
import type { PluginContext } from '../types.js';
66

77
describe('PluginPermissionEnforcer', () => {
88
let enforcer: PluginPermissionEnforcer;
99
let logger: ReturnType<typeof createLogger>;
1010

1111
beforeEach(() => {
12-
logger = createLogger({ level: 'silent' });
12+
logger = createLogger({ level: 'error' });
1313
enforcer = new PluginPermissionEnforcer(logger);
1414
});
1515

@@ -23,6 +23,7 @@ describe('PluginPermissionEnforcer', () => {
2323
version: { major: 1, minor: 0, patch: 0 },
2424
},
2525
conformance: 'full',
26+
certified: false,
2627
},
2728
];
2829

@@ -43,6 +44,7 @@ describe('PluginPermissionEnforcer', () => {
4344
version: { major: 1, minor: 0, patch: 0 },
4445
},
4546
conformance: 'full',
47+
certified: false,
4648
},
4749
];
4850

@@ -63,6 +65,7 @@ describe('PluginPermissionEnforcer', () => {
6365
version: { major: 1, minor: 0, patch: 0 },
6466
},
6567
conformance: 'full',
68+
certified: false,
6669
},
6770
];
6871

@@ -82,6 +85,7 @@ describe('PluginPermissionEnforcer', () => {
8285
version: { major: 1, minor: 0, patch: 0 },
8386
},
8487
conformance: 'full',
88+
certified: false,
8589
},
8690
];
8791

@@ -106,6 +110,7 @@ describe('PluginPermissionEnforcer', () => {
106110
version: { major: 1, minor: 0, patch: 0 },
107111
},
108112
conformance: 'full',
113+
certified: false,
109114
},
110115
];
111116

@@ -125,6 +130,7 @@ describe('PluginPermissionEnforcer', () => {
125130
version: { major: 1, minor: 0, patch: 0 },
126131
},
127132
conformance: 'full',
133+
certified: false,
128134
},
129135
];
130136

@@ -146,6 +152,7 @@ describe('PluginPermissionEnforcer', () => {
146152
version: { major: 1, minor: 0, patch: 0 },
147153
},
148154
conformance: 'full',
155+
certified: false,
149156
},
150157
];
151158

@@ -165,12 +172,12 @@ describe('SecurePluginContext', () => {
165172
let mockBaseContext: PluginContext;
166173

167174
beforeEach(() => {
168-
logger = createLogger({ level: 'silent' });
175+
logger = createLogger({ level: 'error' });
169176
enforcer = new PluginPermissionEnforcer(logger);
170177

171178
mockBaseContext = {
172179
registerService: () => {},
173-
getService: (name: string) => ({ name }),
180+
getService: <T>(name: string): T => ({ name } as any),
174181
getServices: () => new Map(),
175182
hook: () => {},
176183
trigger: async () => {},
@@ -189,6 +196,7 @@ describe('SecurePluginContext', () => {
189196
version: { major: 1, minor: 0, patch: 0 },
190197
},
191198
conformance: 'full',
199+
certified: false,
192200
},
193201
];
194202

@@ -221,6 +229,7 @@ describe('SecurePluginContext', () => {
221229
version: { major: 1, minor: 0, patch: 0 },
222230
},
223231
conformance: 'full',
232+
certified: false,
224233
},
225234
];
226235

packages/core/src/security/plugin-signature-verifier.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { PluginMetadata } from '../plugin-loader.js';
33

44
// Conditionally import crypto for Node.js environments
55
let cryptoModule: typeof import('crypto') | null = null;
6-
if (typeof window === 'undefined') {
6+
if (typeof (globalThis as any).window === 'undefined') {
77
try {
88
// Dynamic import for Node.js crypto module
99
// eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -132,7 +132,7 @@ export class PluginSignatureVerifier {
132132

133133
if (!isValid) {
134134
const error = `Signature verification failed for plugin: ${plugin.name}`;
135-
this.logger.error(error, { plugin: plugin.name, publisherId });
135+
this.logger.error(error, undefined, { plugin: plugin.name, publisherId });
136136
throw new Error(error);
137137
}
138138

@@ -190,7 +190,7 @@ export class PluginSignatureVerifier {
190190
private handleUnsignedPlugin(plugin: PluginMetadata): SignatureVerificationResult {
191191
if (this.config.strictMode) {
192192
const error = `Plugin missing signature (strict mode): ${plugin.name}`;
193-
this.logger.error(error, { plugin: plugin.name });
193+
this.logger.error(error, undefined, { plugin: plugin.name });
194194
throw new Error(error);
195195
}
196196

@@ -220,7 +220,7 @@ export class PluginSignatureVerifier {
220220

221221
private computePluginHash(plugin: PluginMetadata): string {
222222
// In browser environment, use SubtleCrypto
223-
if (typeof window !== 'undefined') {
223+
if (typeof (globalThis as any).window !== 'undefined') {
224224
return this.computePluginHashBrowser(plugin);
225225
}
226226

@@ -287,7 +287,7 @@ export class PluginSignatureVerifier {
287287
publicKey: string
288288
): Promise<boolean> {
289289
// In browser environment, use SubtleCrypto
290-
if (typeof window !== 'undefined') {
290+
if (typeof (globalThis as any).window !== 'undefined') {
291291
return this.verifyCryptoSignatureBrowser(data, signature, publicKey);
292292
}
293293

0 commit comments

Comments
 (0)