Skip to content

Commit 4a37301

Browse files
committed
CR and test fixes
1 parent 908ab75 commit 4a37301

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

plugins/qualifire/globals.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,20 @@ const convertToolCalls = (toolCalls: any) => {
9090
return undefined;
9191
}
9292

93-
return toolCalls.map((toolCall: any) => ({
94-
id: toolCall.id,
95-
name: toolCall.function.name,
96-
arguments: JSON.parse(toolCall.function?.arguments ?? '{}'),
97-
}));
93+
return toolCalls.map((toolCall: any) => {
94+
const rawArgs = toolCall.function?.arguments ?? '{}';
95+
let parsedArgs: any = rawArgs;
96+
try {
97+
parsedArgs = typeof rawArgs === 'string' ? JSON.parse(rawArgs) : rawArgs;
98+
} catch {
99+
// leave as-is
100+
}
101+
return {
102+
id: toolCall.id,
103+
name: toolCall.function.name,
104+
arguments: parsedArgs,
105+
};
106+
});
98107
};
99108

100109
export const convertToMessages = (

plugins/qualifire/manifest.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
"description": [
184184
{
185185
"type": "subHeading",
186-
"text": "Checks that the model returnd a valid json object. If provided, also validated agains given json schema."
186+
"text": "Checks that the model returned a valid json object. If provided, also validates agains the given json schema."
187187
}
188188
],
189189
"parameters": {
@@ -266,7 +266,7 @@
266266
"description": [
267267
{
268268
"type": "subHeading",
269-
"text": "Checks that the model returnd a valid sql code."
269+
"text": "Checks that the model returnd valid sql code."
270270
}
271271
],
272272
"parameters": {}
@@ -279,7 +279,7 @@
279279
"description": [
280280
{
281281
"type": "subHeading",
282-
"text": "Checks that the model returnd a valid javascript code."
282+
"text": "Checks that the model returnd valid javascript code."
283283
}
284284
],
285285
"parameters": {}

plugins/qualifire/qualifire.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,18 +2737,18 @@ describe('policy handler', () => {
27372737
});
27382738
});
27392739

2740-
describe('toolSelectionQuality handler', () => {
2741-
// Mock the globals module before importing toolSelectionQuality
2740+
describe('toolUseQuality handler', () => {
2741+
// Mock the globals module before importing toolUseQuality
27422742
jest.mock('./globals', () => ({
27432743
postQualifire: jest.fn(),
27442744
convertToMessages: jest.fn(),
27452745
parseAvailableTools: jest.fn(),
27462746
}));
27472747

2748-
let toolSelectionQualityHandler: any;
2748+
let toolUseQualityHandler: any;
27492749

27502750
beforeAll(() => {
2751-
toolSelectionQualityHandler = require('./toolSelectionQuality').handler;
2751+
toolUseQualityHandler = require('./toolUseQuality').handler;
27522752
});
27532753

27542754
const mockContext = {
@@ -2848,7 +2848,7 @@ describe('toolSelectionQuality handler', () => {
28482848
},
28492849
]);
28502850

2851-
const result = await toolSelectionQualityHandler(
2851+
const result = await toolUseQualityHandler(
28522852
mockContext,
28532853
mockParameters,
28542854
'afterRequestHook' as HookEventType
@@ -2928,7 +2928,7 @@ describe('toolSelectionQuality handler', () => {
29282928
},
29292929
]);
29302930

2931-
const result = await toolSelectionQualityHandler(
2931+
const result = await toolUseQualityHandler(
29322932
mockContext,
29332933
mockParameters,
29342934
'afterRequestHook' as HookEventType
@@ -2940,7 +2940,7 @@ describe('toolSelectionQuality handler', () => {
29402940

29412941
describe('when called with unsupported event types', () => {
29422942
it('should return error for beforeRequestHook', async () => {
2943-
const result = await toolSelectionQualityHandler(
2943+
const result = await toolUseQualityHandler(
29442944
mockContext,
29452945
mockParameters,
29462946
'beforeRequestHook' as HookEventType
@@ -2949,15 +2949,15 @@ describe('toolSelectionQuality handler', () => {
29492949
expect(result).toEqual({
29502950
error: {
29512951
message:
2952-
'Qualifire Tool Selection Quality guardrail only supports after_request_hooks.',
2952+
'Qualifire Tool Use Quality guardrail only supports after_request_hooks.',
29532953
},
29542954
verdict: true,
29552955
data: null,
29562956
});
29572957
});
29582958

29592959
it('should return error for other event types', async () => {
2960-
const result = await toolSelectionQualityHandler(
2960+
const result = await toolUseQualityHandler(
29612961
mockContext,
29622962
mockParameters,
29632963
'onErrorHook' as HookEventType
@@ -2966,7 +2966,7 @@ describe('toolSelectionQuality handler', () => {
29662966
expect(result).toEqual({
29672967
error: {
29682968
message:
2969-
'Qualifire Tool Selection Quality guardrail only supports after_request_hooks.',
2969+
'Qualifire Tool Use Quality guardrail only supports after_request_hooks.',
29702970
},
29712971
verdict: true,
29722972
data: null,
@@ -2989,7 +2989,7 @@ describe('toolSelectionQuality handler', () => {
29892989
(convertToMessages as jest.Mock).mockReturnValue([]);
29902990
(parseAvailableTools as jest.Mock).mockReturnValue([]);
29912991

2992-
const result = await toolSelectionQualityHandler(
2992+
const result = await toolUseQualityHandler(
29932993
mockContext,
29942994
mockParameters,
29952995
'afterRequestHook' as HookEventType

0 commit comments

Comments
 (0)