Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Jan 4, 2025
1 parent f7c5c76 commit 27fab9b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
13 changes: 11 additions & 2 deletions packages/shortest/src/ai/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export class AIClient {
content: Anthropic.Beta.Messages.BetaContentBlockParam,
) => void,
toolOutputCallback?: (name: string, input: any) => void,
): Promise<{ finalResponse: any; tokenUsage: { input: number; output: number }; pendingCache: any }> {
): Promise<{
finalResponse: any;
tokenUsage: { input: number; output: number };
pendingCache: any;
}> {
const maxRetries = 3;
let attempts = 0;

Expand Down Expand Up @@ -70,7 +74,12 @@ export class AIClient {
content: Anthropic.Beta.Messages.BetaContentBlockParam,
) => void,
_toolOutputCallback?: (name: string, input: any) => void,
): Promise<{ messages: any; finalResponse: any; pendingCache: any; tokenUsage: { input: number; output: number } }> {
): Promise<{
messages: any;
finalResponse: any;
pendingCache: any;
tokenUsage: { input: number; output: number };
}> {
const messages: Anthropic.Beta.Messages.BetaMessageParam[] = [];
// temp cache store
const pendingCache: Partial<{ steps?: CacheStep[] }> = {};
Expand Down
18 changes: 11 additions & 7 deletions packages/shortest/src/core/runner/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ export class TestRunner {
test: TestFunction,
context: BrowserContext,
config: { noCache: boolean } = { noCache: false },
): Promise<{ result: "pass" | "fail"; reason: string; tokenUsage: { input: number; output: number } }> {
): Promise<{
result: "pass" | "fail";
reason: string;
tokenUsage: { input: number; output: number };
}> {
// If it's direct execution, skip AI
if (test.directExecution) {
try {
Expand All @@ -149,7 +153,7 @@ export class TestRunner {
return {
result: "pass" as const,
reason: "Direct execution successful",
tokenUsage: { input: 0, output: 0 },
tokenUsage: { input: 0, output: 0 },
};
} catch (error) {
return {
Expand Down Expand Up @@ -240,11 +244,11 @@ export class TestRunner {
: error instanceof Error
? error.message
: String(error),
tokenUsage: { input: 0, output: 0 },
tokenUsage: { input: 0, output: 0 },
};
}
}
return { ...result, tokenUsage: { input: 0, output: 0 } };
return { ...result, tokenUsage: { input: 0, output: 0 } };
} catch {
// delete stale cached test entry
await this.cache.delete(test);
Expand All @@ -266,7 +270,7 @@ export class TestRunner {
return {
result: "fail" as const,
reason: error instanceof Error ? error.message : String(error),
tokenUsage: { input: 0, output: 0 },
tokenUsage: { input: 0, output: 0 },
};
}
}
Expand All @@ -280,7 +284,7 @@ export class TestRunner {

// Parse AI result first
const finalMessage = result.finalResponse.content.find(
(block:any) =>
(block: any) =>
block.type === "text" &&
(block as Anthropic.Beta.Messages.BetaTextBlock).text.includes(
'"result":',
Expand Down Expand Up @@ -468,4 +472,4 @@ export class TestRunner {
process.exit(1);
}
}
}
}
17 changes: 8 additions & 9 deletions packages/shortest/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export class Logger {
private readonly COST_PER_1K_INPUT_TOKENS = 0.015;
private readonly COST_PER_1K_OUTPUT_TOKENS = 0.075;


startFile(file: string) {
this.currentFile = file.split("/").pop() || file;
console.log(pc.blue(`\n📄 ${pc.bold(this.currentFile)}`));
Expand All @@ -34,7 +33,7 @@ export class Logger {
name: string | undefined,
status: "passed" | "failed",
error?: Error,
tokenUsage?: TokenMetrics
tokenUsage?: TokenMetrics,
) {
const testName = name || "Unnamed Test";
const symbol = status === "passed" ? "✓" : "✗";
Expand All @@ -48,8 +47,8 @@ export class Logger {
console.log(
pc.dim(
` ↳ ${totalTokens.toLocaleString()} tokens ` +
`(≈ $${cost.toFixed(2)})`
)
`(≈ $${cost.toFixed(2)})`,
),
);
}

Expand Down Expand Up @@ -111,10 +110,10 @@ export class Logger {
).length;
const passedTests = totalTests - failedTests;

const { totalInputTokens, totalOutputTokens, totalCost } = this.calculateTotalTokenUsage();
const { totalInputTokens, totalOutputTokens, totalCost } =
this.calculateTotalTokenUsage();
const totalTokens = totalInputTokens + totalOutputTokens;


console.log(pc.dim("⎯".repeat(50)));

console.log(
Expand All @@ -131,11 +130,11 @@ export class Logger {
pc.dim(new Date(this.startTime).toLocaleTimeString()),
);
console.log(
pc.bold(" Tokens "),
pc.bold(" Tokens "),
pc.dim(
`${totalTokens.toLocaleString()} tokens ` +
`(≈ $${totalCost.toFixed(2)})`
)
`(≈ $${totalCost.toFixed(2)})`,
),
);
console.log(pc.dim("\n" + "⎯".repeat(50)));
}
Expand Down

0 comments on commit 27fab9b

Please sign in to comment.