Skip to content

Commit 77334d4

Browse files
Refactor redteam module to improve plugin configuration resolution and enhance test coverage.
1 parent fa9e329 commit 77334d4

File tree

2 files changed

+57
-900
lines changed

2 files changed

+57
-900
lines changed

src/redteam/index.ts

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ async function addIntentToTestCase(
431431
...testCase,
432432
metadata: {
433433
...testCase.metadata,
434-
goal: extractedIntent,
434+
intent: extractedIntent,
435435
},
436436
};
437437
}
@@ -790,38 +790,8 @@ export async function synthesize({
790790
}
791791
});
792792

793-
// TODO: This is a hack to extract intent for test cases. We should find a better way to do this.
794-
logger.debug(`Extracting intent for ${testCases.length} test cases in batches of 20...`);
795-
const batchSize = 20;
796-
const testCasesWithIntent: TestCaseWithPlugin[] = [];
797-
798-
for (let i = 0; i < testCases.length; i += batchSize) {
799-
const batch = testCases.slice(i, i + batchSize);
800-
const batchResults = await Promise.allSettled(
801-
batch.map(async (testCase, batchIndex) => {
802-
try {
803-
return await addIntentToTestCase(testCase, purpose);
804-
} catch (error) {
805-
logger.warn(
806-
`Intent extraction failed for test case ${i + batchIndex}: ${error}. Using original test case.`,
807-
);
808-
return testCase;
809-
}
810-
}),
811-
);
812-
813-
batchResults.forEach((result) => {
814-
if (result.status === 'fulfilled') {
815-
testCasesWithIntent.push(result.value);
816-
} else {
817-
logger.warn(`Intent extraction rejected: ${result.reason}. Using original test case.`);
818-
testCasesWithIntent.push(batch[batchResults.indexOf(result)]);
819-
}
820-
});
821-
}
822-
823793
// After generating plugin test cases but before applying strategies:
824-
const pluginTestCases = testCasesWithIntent;
794+
const pluginTestCases = testCases;
825795

826796
// Initialize strategy results
827797
const strategyResults: Record<string, { requested: number; generated: number }> = {};
@@ -876,5 +846,21 @@ export async function synthesize({
876846

877847
logger.info(generateReport(pluginResults, strategyResults));
878848

879-
return { purpose, entities, testCases: finalTestCases, injectVar };
849+
const testCasesWithIntent = await Promise.all(
850+
finalTestCases.map((testCase) => addIntentToTestCase(testCase, purpose)),
851+
);
852+
853+
return { purpose, entities, testCases: testCasesWithIntent, injectVar };
880854
}
855+
856+
export {
857+
getPluginSeverity,
858+
getStatus,
859+
generateReport,
860+
categories,
861+
formatTestCount,
862+
pluginMatchesStrategyTargets,
863+
applyStrategies,
864+
isStrategyCollection,
865+
addIntentToTestCase,
866+
};

0 commit comments

Comments
 (0)