Refactor done-tool-execute parameter naming and improve code formatting in modify-reports-tool files

This commit is contained in:
dal 2025-09-17 00:49:09 -06:00
parent 8f9fcb711b
commit a7e0c71acb
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
4 changed files with 39 additions and 8 deletions

View File

@ -15,7 +15,7 @@ async function processDone(
state: DoneToolState,
toolCallId: string,
messageId: string,
context: DoneToolContext
_context: DoneToolContext
): Promise<DoneToolOutput> {
const output: DoneToolOutput = {
success: true,

View File

@ -208,7 +208,10 @@ export function createModifyReportsDelta(context: ModifyReportsContext, state: M
const rawCode = getOptimisticValue<string>(editMap, TOOL_KEYS.code, '');
// Unescape JSON string sequences, then normalize any double-escaped characters
// Note: We preserve the code even if it's empty string, as that might be intentional
const code = rawCode !== undefined ? normalizeEscapedText(unescapeJsonString(rawCode || '')) : undefined;
const code =
rawCode !== undefined
? normalizeEscapedText(unescapeJsonString(rawCode || ''))
: undefined;
if (code !== undefined) {
// Use explicit operation if provided, otherwise infer from code_to_replace

View File

@ -17,10 +17,15 @@ vi.mock('@buster/database', () => ({
batchUpdateReport: vi.fn().mockResolvedValue({ success: true }),
updateMetricsToReports: vi.fn().mockResolvedValue({ created: 0, updated: 0, deleted: 0 }),
db: {
select: () => ({
from: () => ({
where: () => ({
limit: mockDbLimit,
select: vi.fn().mockReturnValue({
from: vi.fn().mockReturnValue({
where: vi.fn().mockReturnValue({
limit: vi.fn().mockResolvedValue([
{
content: '# Original Report\nSome content here.',
versionHistory: null,
},
]),
}),
}),
}),
@ -61,6 +66,16 @@ vi.mock('../../../shared/create-raw-llm-tool-result-entry', () => ({
}),
}));
vi.mock('../helpers/metric-extraction', () => ({
extractAndCacheMetricsWithUserContext: vi.fn().mockResolvedValue(undefined),
extractMetricIds: vi.fn().mockReturnValue([]),
}));
vi.mock('../report-snapshot-cache', () => ({
getCachedSnapshot: vi.fn().mockReturnValue(null),
updateCachedSnapshot: vi.fn().mockResolvedValue(undefined),
}));
import { db, updateMessageEntries } from '@buster/database';
describe('modify-reports-execute', () => {
@ -353,10 +368,20 @@ Updated content with metrics.`;
});
it('should handle report not found in database', async () => {
// Override the database mock for this specific test to return empty array
const mockDbSelect = vi.fn().mockReturnValue({
from: vi.fn().mockReturnValue({
where: vi.fn().mockReturnValue({
limit: vi.fn().mockResolvedValue([]),
}),
}),
});
(db.select as ReturnType<typeof vi.fn>) = mockDbSelect;
// Mock no report found - snapshot will be undefined since report doesn't exist
// This should trigger the fallback to fetch from DB
state.snapshotContent = undefined;
mockDbLimit.mockResolvedValue([]);
const input: ModifyReportsInput = {
id: 'non-existent-report',

View File

@ -79,7 +79,10 @@ const ModifyReportsStateSchema = z.object({
startTime: z.number().optional(),
responseMessageCreated: z.boolean().optional(),
snapshotContent: z.string().optional(),
lastSavedContent: z.string().optional().describe('Track the last content saved to DB to avoid redundant updates'),
lastSavedContent: z
.string()
.optional()
.describe('Track the last content saved to DB to avoid redundant updates'),
reportsModifiedInMessage: z.set(z.string()).optional(),
snapshotVersion: z.number().optional(),
versionHistory: z