Refactor import statements and enhance error messages in SQL validation tests

- Simplified import statements in web-search-tool.ts and web-search-tool.test.ts for better readability.
- Updated error messages in sql-parser-helpers.test.ts to provide clearer feedback regarding wildcard usage on physical tables.
This commit is contained in:
dal 2025-07-23 21:46:51 -06:00
parent d438943f9b
commit 7cd3aed6fa
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
4 changed files with 24 additions and 26 deletions

View File

@ -17,9 +17,7 @@ describe('webSearch tool', () => {
beforeEach(async () => { beforeEach(async () => {
vi.clearAllMocks(); vi.clearAllMocks();
const { mockFirecrawlService: mock } = vi.mocked( const { mockFirecrawlService: mock } = vi.mocked(await import('@buster/web-tools')) as any;
await import('@buster/web-tools')
) as any;
mockFirecrawlService = mock; mockFirecrawlService = mock;
}); });

View File

@ -1,8 +1,4 @@
import { import { FirecrawlService, type WebSearchOptions, type WebSearchResult } from '@buster/web-tools';
FirecrawlService,
type WebSearchOptions,
type WebSearchResult,
} from '@buster/web-tools';
import type { RuntimeContext } from '@mastra/core/runtime-context'; import type { RuntimeContext } from '@mastra/core/runtime-context';
import { createTool } from '@mastra/core/tools'; import { createTool } from '@mastra/core/tools';
import { wrapTraced } from 'braintrust'; import { wrapTraced } from 'braintrust';

View File

@ -23,7 +23,8 @@ function createWorkflowAwareHealingMessage(toolName: string, context?: WorkflowC
const { currentStep, availableTools } = context; const { currentStep, availableTools } = context;
const nextMode = currentStep === 'think-and-prep' ? 'analyst' : 'think-and-prep'; const nextMode = currentStep === 'think-and-prep' ? 'analyst' : 'think-and-prep';
const transitionDescription = currentStep === 'think-and-prep' const transitionDescription =
currentStep === 'think-and-prep'
? 'after thinking, understanding the data, and submitting your thoughts' ? 'after thinking, understanding the data, and submitting your thoughts'
: 'after completing your analysis'; : 'after completing your analysis';
@ -31,7 +32,8 @@ function createWorkflowAwareHealingMessage(toolName: string, context?: WorkflowC
if (availableTools && availableTools.size > 0) { if (availableTools && availableTools.size > 0) {
const currentToolList = Array.from(availableTools).sort().join(', '); const currentToolList = Array.from(availableTools).sort().join(', ');
const nextModeTools = nextMode === 'analyst' const nextModeTools =
nextMode === 'analyst'
? 'createMetrics, modifyMetrics, createDashboards, modifyDashboards, doneTool' ? 'createMetrics, modifyMetrics, createDashboards, modifyDashboards, doneTool'
: 'sequentialThinking, executeSql, respondWithoutAssetCreation, submitThoughts, messageUserClarifyingQuestion'; : 'sequentialThinking, executeSql, respondWithoutAssetCreation, submitThoughts, messageUserClarifyingQuestion';
@ -43,11 +45,13 @@ ${nextModeTools}`;
} }
// Fallback to static message if tools not provided // Fallback to static message if tools not provided
const currentModeTools = currentStep === 'think-and-prep' const currentModeTools =
currentStep === 'think-and-prep'
? 'sequentialThinking, executeSql, respondWithoutAssetCreation, submitThoughts, messageUserClarifyingQuestion' ? 'sequentialThinking, executeSql, respondWithoutAssetCreation, submitThoughts, messageUserClarifyingQuestion'
: 'createMetrics, modifyMetrics, createDashboards, modifyDashboards, doneTool'; : 'createMetrics, modifyMetrics, createDashboards, modifyDashboards, doneTool';
const nextModeTools = nextMode === 'analyst' const nextModeTools =
nextMode === 'analyst'
? 'createMetrics, modifyMetrics, createDashboards, modifyDashboards, doneTool' ? 'createMetrics, modifyMetrics, createDashboards, modifyDashboards, doneTool'
: 'sequentialThinking, executeSql, respondWithoutAssetCreation, submitThoughts, messageUserClarifyingQuestion'; : 'sequentialThinking, executeSql, respondWithoutAssetCreation, submitThoughts, messageUserClarifyingQuestion';

View File

@ -426,7 +426,7 @@ models:
const sql = 'SELECT * FROM users'; const sql = 'SELECT * FROM users';
const result = validateWildcardUsage(sql); const result = validateWildcardUsage(sql);
expect(result.isValid).toBe(false); expect(result.isValid).toBe(false);
expect(result.error).toContain('Wildcard usage on physical tables is not allowed'); expect(result.error).toContain("You're not allowed to use a wildcard on physical tables");
expect(result.blockedTables).toContain('users'); expect(result.blockedTables).toContain('users');
}); });
@ -434,7 +434,7 @@ models:
const sql = 'SELECT u.* FROM users u'; const sql = 'SELECT u.* FROM users u';
const result = validateWildcardUsage(sql); const result = validateWildcardUsage(sql);
expect(result.isValid).toBe(false); expect(result.isValid).toBe(false);
expect(result.error).toContain('Wildcard usage on physical tables is not allowed'); expect(result.error).toContain("You're not allowed to use a wildcard on physical tables");
expect(result.blockedTables).toContain('u'); expect(result.blockedTables).toContain('u');
}); });
@ -470,7 +470,7 @@ models:
`; `;
const result = validateWildcardUsage(sql); const result = validateWildcardUsage(sql);
expect(result.isValid).toBe(false); expect(result.isValid).toBe(false);
expect(result.error).toContain('Wildcard usage on physical tables is not allowed'); expect(result.error).toContain("You're not allowed to use a wildcard on physical tables");
expect(result.blockedTables).toContain('users'); expect(result.blockedTables).toContain('users');
}); });
@ -514,7 +514,7 @@ models:
const sql = 'SELECT * FROM public.users'; const sql = 'SELECT * FROM public.users';
const result = validateWildcardUsage(sql); const result = validateWildcardUsage(sql);
expect(result.isValid).toBe(false); expect(result.isValid).toBe(false);
expect(result.error).toContain('Wildcard usage on physical tables is not allowed'); expect(result.error).toContain("You're not allowed to use a wildcard on physical tables");
}); });
it('should handle invalid SQL gracefully', () => { it('should handle invalid SQL gracefully', () => {