Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,39 @@ describe('AddContentToDocTool', () => {
expect(parsed.block_ids).toBeNull();
});

it('should ignore null entries inside block_ids in successful response', async () => {
const getDocByIdResponse = {
docs: [{ id: 'doc_123', name: 'Test Doc', url: 'https://example.com/doc' }],
};

const addContentResponse = {
add_content_to_doc_from_markdown: {
success: true,
block_ids: [null, 'block_1'],
error: null,
},
};

jest.spyOn(mocks, 'mockRequest').mockImplementation((query: string) => {
if (query.includes('query getDocById')) {
return Promise.resolve(getDocByIdResponse);
}
if (query.includes('mutation addContentToDocFromMarkdown')) {
return Promise.resolve(addContentResponse);
}
return Promise.resolve({});
});

const result = await callToolByNameRawAsync('add_content_to_doc', {
doc_id: 'doc_123',
markdown: 'Content',
});

const parsed = JSON.parse(result.content[0].text);
expect(parsed.message).toContain('1 block created');
expect(parsed.block_ids).toEqual(['block_1']);
});

it('should return doc_name and doc_url in success response', async () => {
const getDocByIdResponse = {
docs: [{ id: 'doc_123', name: 'My Important Doc', url: 'https://example.com/my-doc' }],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ USAGE EXAMPLES:
return { content: `Error adding content to document: ${error || 'Unknown error'}` };
}

const blockCount = block_ids?.length ?? 0;
const filteredBlockIds = block_ids?.filter((blockId): blockId is NonNullable<typeof blockId> => blockId != null) ?? [];
const blockCount = filteredBlockIds.length;
return {
content: {
message: `Successfully added content to document ${doc.id}. ${blockCount} block${blockCount === 1 ? '' : 's'} created.`,
doc_id: doc.id,
block_ids: block_ids,
block_ids: filteredBlockIds.length > 0 ? filteredBlockIds : null,
doc_name: doc.name,
doc_url: doc.url,
},
Expand Down