fix: improve error handling and refactor test mocks for SQL execution

- Added a check to ensure the DataSource is available before executing SQL statements, throwing an error if not.
- Refactored test mocks to use `vi.mocked` for better clarity and consistency in handling DataSource connection errors.
- Removed unnecessary whitespace for cleaner code.

These changes enhance the robustness of SQL execution and improve the reliability of related tests.
This commit is contained in:
dal 2025-08-08 09:36:26 -06:00
parent fb65ac42ea
commit 7f1bfc3bc5
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
3 changed files with 8 additions and 22 deletions

View File

@ -276,9 +276,9 @@ export function createSuperExecuteSqlExecute(
}
const dataSourceId = context.dataSourceId;
let dataSource: DataSource | null = null;
try {
// Get a new DataSource instance
dataSource = await getDataSource(dataSourceId);
@ -288,6 +288,10 @@ export function createSuperExecuteSqlExecute(
withRateLimit(
'sql-execution',
async () => {
if (!dataSource) {
throw new Error('DataSource is not available');
}
const result = await executeSingleStatement(sqlStatement, dataSource);
return { sql: sqlStatement, result };
},

View File

@ -254,7 +254,7 @@ describe('super-execute-sql', () => {
it('should handle data source connection errors', async () => {
const executeHandler = createSuperExecuteSqlExecute(mockState, mockContext);
vi.spyOn(managerInstance, 'getDataSource').mockRejectedValue(new Error('Connection failed'));
vi.mocked(getDataSource).mockRejectedValue(new Error('Connection failed'));
const result = await executeHandler({
statements: ['SELECT 1'],
@ -272,7 +272,7 @@ describe('super-execute-sql', () => {
const executeHandler = createSuperExecuteSqlExecute(mockState, mockContext);
// Reset the mock to resolve properly for this test
vi.spyOn(managerInstance, 'getDataSource').mockResolvedValue(mockDataSource);
vi.mocked(getDataSource).mockResolvedValue(mockDataSource);
mockExecute.mockResolvedValue({
success: true,

View File

@ -10,24 +10,6 @@ import {
runThinkAndPrepAgentStep,
} from '../../steps';
// concurrently run the following steps:
// 1. create todos
// 2. extract values
// 3. chat title
// Each of those output their single result
// Think and prep step
// should output the messages up to the submit thoughts
// if finishing tool is called, then we don't continue
// Analyst step
// should output the messages up to the done tool
// Return Jacob output
// Temporary empty export to mark this file as a module until implementation is added
const AnalystWorkflowInputSchema = z.object({
messages: z.array(z.custom<ModelMessage>()),
messageId: z.string().uuid(),