Skip to content

Commit e63177c

Browse files
committed
chore: fix lint and formatting issues
- Fix noImplicitAnyLet in redteam.ts (add CaseRedactionInfo type) - Fix noExplicitAny in custom-adapter.ts (use unknown instead) - Fix noNonNullAssertion in openai client.ts (use nullish coalescing) - Apply biome formatting fixes across all files
1 parent 33717d8 commit e63177c

11 files changed

Lines changed: 103 additions & 46 deletions

File tree

‎examples/adapters/custom-adapter.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class CustomAdapter implements ModelClient {
119119
* Register the custom adapter
120120
*/
121121
export function registerCustomAdapter(): void {
122-
adapterRegistry.register('custom', async (config: any) => {
122+
adapterRegistry.register('custom', async (config: unknown) => {
123123
return new CustomAdapter(config as CustomAdapterConfig);
124124
});
125125
}

‎package.json‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
},
1111
"license": "Apache-2.0",
1212
"author": "code-sensei",
13-
"workspaces": [
14-
"packages/*",
15-
"packages/adapters/*"
16-
],
13+
"workspaces": ["packages/*", "packages/adapters/*"],
1714
"scripts": {
1815
"build": "bun run --filter '*' build",
1916
"test": "bun test",

‎packages/adapters/openai/src/client.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class OpenAIAdapter implements ModelClient {
3030
apiKey: azureConfig.apiKey,
3131
baseURL: `https://${azureConfig.resourceName}.openai.azure.com/openai/deployments/${azureConfig.deploymentName}`,
3232
defaultQuery: { 'api-version': azureConfig.apiVersion },
33-
defaultHeaders: { 'api-key': azureConfig.apiKey! },
33+
defaultHeaders: { 'api-key': azureConfig.apiKey ?? '' },
3434
timeout: azureConfig.timeout ?? 60000,
3535
maxRetries: azureConfig.maxRetries ?? 2,
3636
});

‎packages/cli/src/commands/redteam.ts‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
import { mkdir, writeFile } from 'node:fs/promises';
66
import { basename, join } from 'node:path';
77
import {
8+
type CaseRedactionInfo,
89
type ManifestRedactionInfo,
910
type RedTeamCaseResult,
1011
type RedTeamManifest,
1112
type RedTeamMetrics,
1213
type RedTeamSeverity,
1314
type RedTeamStatus,
14-
Redactor,
1515
type RedactionConfig,
16+
Redactor,
1617
createAdapter,
1718
getGitInfo,
1819
parseScenarioFile,
@@ -72,7 +73,10 @@ export function redteamCommand(): Command {
7273
.option('-v, --verbose', 'Verbose output')
7374
.option('--config <path>', 'Path to config file')
7475
.option('--redact', 'Enable PII/sensitive data redaction in results')
75-
.option('--redact-patterns <patterns...>', 'Custom redaction patterns (regex or built-in: email, phone, credit_card, ssn, api_key)')
76+
.option(
77+
'--redact-patterns <patterns...>',
78+
'Custom redaction patterns (regex or built-in: email, phone, credit_card, ssn, api_key)'
79+
)
7680
.action(async (scenarioPath: string, options: RedteamOptions) => {
7781
const spinner = ora('Loading configuration...').start();
7882
const startTime = new Date();
@@ -139,7 +143,11 @@ export function redteamCommand(): Command {
139143
replacement: '[REDACTED]',
140144
};
141145
redactor = new Redactor(redactionConfig);
142-
console.log(chalk.dim(`Redaction enabled${options.redactPatterns ? ` with patterns: ${options.redactPatterns.join(', ')}` : ' (default patterns)'}`));
146+
console.log(
147+
chalk.dim(
148+
`Redaction enabled${options.redactPatterns ? ` with patterns: ${options.redactPatterns.join(', ')}` : ' (default patterns)'}`
149+
)
150+
);
143151
}
144152
console.log();
145153

@@ -185,7 +193,7 @@ export function redteamCommand(): Command {
185193
// Apply redaction if enabled
186194
let finalPrompt = mutated.mutated;
187195
let finalResponse = result.text;
188-
let caseRedaction;
196+
let caseRedaction: CaseRedactionInfo | undefined;
189197

190198
if (redactor) {
191199
const promptResult = redactor.redactPrompt(finalPrompt);
@@ -222,7 +230,7 @@ export function redteamCommand(): Command {
222230

223231
// Apply redaction to prompt even for errors/blocked
224232
let errorPrompt = mutated.mutated;
225-
let errorCaseRedaction;
233+
let errorCaseRedaction: CaseRedactionInfo | undefined;
226234

227235
if (redactor) {
228236
const promptResult = redactor.redactPrompt(errorPrompt);

‎packages/cli/src/commands/run.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
* Run command - Execute test scenarios
33
*/
44

5-
import { type RedactionConfig, createAdapter, parseScenarioFile, runScenario } from '@artemiskit/core';
5+
import {
6+
type RedactionConfig,
7+
createAdapter,
8+
parseScenarioFile,
9+
runScenario,
10+
} from '@artemiskit/core';
611
import chalk from 'chalk';
712
import Table from 'cli-table3';
813
import { Command } from 'commander';
@@ -47,7 +52,10 @@ export function runCommand(): Command {
4752
.option('--retries <number>', 'Number of retries per test case')
4853
.option('--config <path>', 'Path to config file')
4954
.option('--redact', 'Enable PII/sensitive data redaction in results')
50-
.option('--redact-patterns <patterns...>', 'Custom redaction patterns (regex or built-in: email, phone, credit_card, ssn, api_key)')
55+
.option(
56+
'--redact-patterns <patterns...>',
57+
'Custom redaction patterns (regex or built-in: email, phone, credit_card, ssn, api_key)'
58+
)
5159
.action(async (scenarioPath: string, options: RunOptions) => {
5260
const spinner = ora('Loading configuration...').start();
5361

@@ -106,7 +114,11 @@ export function runCommand(): Command {
106114
redactMetadata: false,
107115
replacement: '[REDACTED]',
108116
};
109-
console.log(chalk.dim(`Redaction enabled${options.redactPatterns ? ` with patterns: ${options.redactPatterns.join(', ')}` : ' (default patterns)'}`));
117+
console.log(
118+
chalk.dim(
119+
`Redaction enabled${options.redactPatterns ? ` with patterns: ${options.redactPatterns.join(', ')}` : ' (default patterns)'}`
120+
)
121+
);
110122
console.log();
111123
}
112124

@@ -210,7 +222,10 @@ function displaySummary(
210222
if (redaction?.enabled) {
211223
table.push(
212224
['Redaction', chalk.yellow('Enabled')],
213-
['Redactions Made', `${redaction.summary.totalRedactions} (${redaction.summary.promptsRedacted} prompts, ${redaction.summary.responsesRedacted} responses)`]
225+
[
226+
'Redactions Made',
227+
`${redaction.summary.totalRedactions} (${redaction.summary.promptsRedacted} prompts, ${redaction.summary.responsesRedacted} responses)`,
228+
]
214229
);
215230
}
216231

‎packages/cli/src/commands/stress.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { mkdir, writeFile } from 'node:fs/promises';
66
import { basename, join } from 'node:path';
77
import {
88
type ManifestRedactionInfo,
9-
Redactor,
109
type RedactionConfig,
10+
Redactor,
1111
type StressManifest,
1212
type StressMetrics,
1313
type StressRequestResult,
@@ -61,7 +61,10 @@ export function stressCommand(): Command {
6161
.option('-v, --verbose', 'Verbose output')
6262
.option('--config <path>', 'Path to config file')
6363
.option('--redact', 'Enable PII/sensitive data redaction in results')
64-
.option('--redact-patterns <patterns...>', 'Custom redaction patterns (regex or built-in: email, phone, credit_card, ssn, api_key)')
64+
.option(
65+
'--redact-patterns <patterns...>',
66+
'Custom redaction patterns (regex or built-in: email, phone, credit_card, ssn, api_key)'
67+
)
6568
.action(async (scenarioPath: string, options: StressOptions) => {
6669
const spinner = ora('Loading configuration...').start();
6770
const startTime = new Date();
@@ -138,7 +141,11 @@ export function stressCommand(): Command {
138141
console.log(chalk.dim(`Max requests: ${maxRequests}`));
139142
}
140143
if (options.redact) {
141-
console.log(chalk.dim(`Redaction: enabled${options.redactPatterns ? ` (${options.redactPatterns.join(', ')})` : ' (default patterns)'}`));
144+
console.log(
145+
chalk.dim(
146+
`Redaction: enabled${options.redactPatterns ? ` (${options.redactPatterns.join(', ')})` : ' (default patterns)'}`
147+
)
148+
);
142149
}
143150
console.log();
144151

‎packages/core/src/artifacts/manifest.ts‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ export function createRunManifest(options: {
2828
runReason?: string;
2929
redaction?: ManifestRedactionInfo;
3030
}): RunManifest {
31-
const { project, config, resolvedConfig, cases, startTime, endTime, runBy, runReason, redaction } =
32-
options;
31+
const {
32+
project,
33+
config,
34+
resolvedConfig,
35+
cases,
36+
startTime,
37+
endTime,
38+
runBy,
39+
runReason,
40+
redaction,
41+
} = options;
3342

3443
const metrics = calculateMetrics(cases);
3544
const git = getGitInfo();

‎packages/core/src/redaction/redactor.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ describe('Built-in patterns', () => {
250250

251251
it('should redact JWT tokens', () => {
252252
const redactor = createTestRedactor(BUILTIN_PATTERNS.JWT);
253-
const jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U';
253+
const jwt =
254+
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U';
254255
const result = redactor.redact(`Token: ${jwt}`);
255256
expect(result.wasRedacted).toBe(true);
256257
});

‎packages/core/src/redaction/redactor.ts‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { createHash } from 'node:crypto';
22
import {
33
BUILTIN_REGEX_PATTERNS,
4-
DEFAULT_REDACTION_PATTERNS,
54
type BuiltinPatternName,
5+
DEFAULT_REDACTION_PATTERNS,
66
type RedactionConfig,
77
type RedactionOptions,
88
type RedactionResult,
@@ -13,22 +13,24 @@ import {
1313
* Supports built-in pattern names and custom regex strings
1414
*/
1515
export function resolvePatterns(patterns: string[]): { regex: RegExp; name: string }[] {
16-
return patterns.map((pattern) => {
17-
// Check if it's a built-in pattern name
18-
if (pattern in BUILTIN_REGEX_PATTERNS) {
19-
const regex = BUILTIN_REGEX_PATTERNS[pattern as BuiltinPatternName];
20-
return { regex: new RegExp(regex.source, regex.flags), name: pattern };
21-
}
16+
return patterns
17+
.map((pattern) => {
18+
// Check if it's a built-in pattern name
19+
if (pattern in BUILTIN_REGEX_PATTERNS) {
20+
const regex = BUILTIN_REGEX_PATTERNS[pattern as BuiltinPatternName];
21+
return { regex: new RegExp(regex.source, regex.flags), name: pattern };
22+
}
2223

23-
// Treat as custom regex
24-
try {
25-
return { regex: new RegExp(pattern, 'g'), name: `custom:${pattern.slice(0, 20)}` };
26-
} catch {
27-
// Invalid regex, skip it
28-
console.warn(`Invalid redaction pattern: ${pattern}`);
29-
return null;
30-
}
31-
}).filter((p): p is { regex: RegExp; name: string } => p !== null);
24+
// Treat as custom regex
25+
try {
26+
return { regex: new RegExp(pattern, 'g'), name: `custom:${pattern.slice(0, 20)}` };
27+
} catch {
28+
// Invalid regex, skip it
29+
console.warn(`Invalid redaction pattern: ${pattern}`);
30+
return null;
31+
}
32+
})
33+
.filter((p): p is { regex: RegExp; name: string } => p !== null);
3234
}
3335

3436
/**
@@ -54,7 +56,7 @@ export function createRedactionOptions(config: RedactionConfig): RedactionOption
5456
export function redactText(
5557
text: string,
5658
patterns: (string | RegExp)[],
57-
replacement: string = '[REDACTED]'
59+
replacement = '[REDACTED]'
5860
): RedactionResult {
5961
if (!text || patterns.length === 0) {
6062
return {
@@ -102,7 +104,7 @@ export function hashText(text: string): string {
102104
export function redactWithHash(
103105
text: string,
104106
patterns: (string | RegExp)[],
105-
replacement: string = '[REDACTED]'
107+
replacement = '[REDACTED]'
106108
): RedactionResult & { originalHash: string } {
107109
const originalHash = hashText(text);
108110
const result = redactText(text, patterns, replacement);

‎packages/core/src/redaction/types.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,13 @@ export const BUILTIN_REGEX_PATTERNS: Record<BuiltinPatternName, RegExp> = {
3434
[BUILTIN_PATTERNS.PHONE]: /\b(?:\+?1[-.\s]?)?(?:\(?\d{3}\)?[-.\s]?)?\d{3}[-.\s]?\d{4}\b/g,
3535
[BUILTIN_PATTERNS.CREDIT_CARD]: /\b(?:\d{4}[-\s]?){3}\d{4}\b/g,
3636
[BUILTIN_PATTERNS.SSN]: /\b\d{3}[-\s]?\d{2}[-\s]?\d{4}\b/g,
37-
[BUILTIN_PATTERNS.API_KEY]: /\b(?:sk|pk|api|key)[-_]?(?:[a-zA-Z0-9]+[-_]?){2,}[a-zA-Z0-9]{10,}\b/gi,
37+
[BUILTIN_PATTERNS.API_KEY]:
38+
/\b(?:sk|pk|api|key)[-_]?(?:[a-zA-Z0-9]+[-_]?){2,}[a-zA-Z0-9]{10,}\b/gi,
3839
[BUILTIN_PATTERNS.IPV4]: /\b(?:\d{1,3}\.){3}\d{1,3}\b/g,
3940
[BUILTIN_PATTERNS.JWT]: /\beyJ[A-Za-z0-9-_]+\.eyJ[A-Za-z0-9-_]+\.[A-Za-z0-9-_.+/=]*\b/g,
4041
[BUILTIN_PATTERNS.AWS_KEY]: /\b(?:AKIA|ABIA|ACCA|ASIA)[A-Z0-9]{16}\b/g,
41-
[BUILTIN_PATTERNS.SECRETS]: /\b(?:password|secret|token|apikey|api_key|auth)[\s]*[=:]\s*['"]?[^\s'"]+['"]?/gi,
42+
[BUILTIN_PATTERNS.SECRETS]:
43+
/\b(?:password|secret|token|apikey|api_key|auth)[\s]*[=:]\s*['"]?[^\s'"]+['"]?/gi,
4244
};
4345

4446
/**

0 commit comments

Comments
 (0)