11import { triggersMock } from '@sim/testing/mocks/triggers.mock'
22import { describe, expect, it, vi } from 'vitest'
3- import type { BlockConfig } from '@/blocks/types'
3+ import type { BlockToolParamsContext } from '@/blocks/types'
44
55vi.mock('@/triggers', () => triggersMock)
66
77import { GoogleDriveBlock } from '@/blocks/blocks/google_drive'
88
9- /** The block's `tools.config.params` mapper, which every block under test defines. */
10- function requireParamsMapper(block: BlockConfig) {
11- const mapper = block.tools.config?.params
12- if (!mapper) throw new Error(`${block.type} has no params mapper`)
13- return mapper
14- }
9+ /** The block's `tools.config.params` mapper; `context` is set on a tool call, absent on the canvas. */
10+ const buildParams = (
11+ inputs: Record<string, unknown>,
12+ context?: BlockToolParamsContext
13+ ): Record<string, unknown> => GoogleDriveBlock.tools.config?.params?.(inputs, context) ?? {}
1514
1615const paginationCases = [
1716 { operation: 'list', subBlockId: 'pageToken' },
@@ -22,26 +21,22 @@ const paginationCases = [
2221] as const
2322
2423describe('GoogleDriveBlock pagination', () => {
25- const buildParams = requireParamsMapper(GoogleDriveBlock)
26-
2724 describe.each(paginationCases)('$operation', ({ operation, subBlockId }) => {
2825 /**
2926 * `pageToken` is the canonical tool param, so the `list` case would forward
3027 * through `...rest` even without the mapper. The per-operation ids are the
3128 * ones the mapper has to translate, and none of them may survive as-is.
3229 */
3330 it('forwards the page token to the tool under its own id', () => {
34- const params = buildParams({ operation, [subBlockId]: 'token-abc' }, undefined as never )
31+ const params = buildParams({ operation, [subBlockId]: 'token-abc' })
3532
3633 expect(params).toMatchObject({ pageToken: 'token-abc' })
3734 if (subBlockId !== 'pageToken') expect(params[subBlockId]).toBeUndefined()
3835 })
3936 })
4037
4138 it('does not leak a page token into operations that do not paginate', () => {
42- expect(
43- buildParams({ operation: 'get_file', pageToken: 'token-abc' }, undefined as never).pageToken
44- ).toBeUndefined()
39+ expect(buildParams({ operation: 'get_file', pageToken: 'token-abc' }).pageToken).toBeUndefined()
4540 })
4641
4742 /**
@@ -54,7 +49,7 @@ describe('GoogleDriveBlock pagination', () => {
5449 '$subBlockId left over from a previous operation',
5550 ({ subBlockId }) => {
5651 it.each(['upload', 'get_file', 'list'])('is dropped under %s', (operation) => {
57- const params = buildParams({ operation, [subBlockId]: 'stale' }, undefined as never )
52+ const params = buildParams({ operation, [subBlockId]: 'stale' })
5853
5954 expect(params.pageToken).toBeUndefined()
6055 expect(params[subBlockId]).toBeUndefined()
@@ -63,15 +58,12 @@ describe('GoogleDriveBlock pagination', () => {
6358 )
6459
6560 it('prefers the operation-owned token when a stale sibling is also present', () => {
66- const params = buildParams(
67- {
68- operation: 'search',
69- searchPageToken: 'search-token',
70- commentsPageToken: 'stale',
71- pageToken: 'stale-canonical',
72- },
73- undefined as never
74- )
61+ const params = buildParams({
62+ operation: 'search',
63+ searchPageToken: 'search-token',
64+ commentsPageToken: 'stale',
65+ pageToken: 'stale-canonical',
66+ })
7567
7668 expect(params.pageToken).toBe('search-token')
7769 expect(params.commentsPageToken).toBeUndefined()
@@ -84,7 +76,6 @@ describe('GoogleDriveBlock pagination', () => {
8476 * the per-operation fields (`permissionsPageSize`, `searchPageToken`, `searchQuery`) are never rendered.
8577 */
8678describe('GoogleDriveBlock agent tool calls', () => {
87- const buildParams = requireParamsMapper(GoogleDriveBlock)
8879 const agentCall = (operation: string, args: Record<string, unknown>): Record<string, unknown> => {
8980 const inputs = { ...args, operation }
9081 return { ...inputs, ...buildParams(inputs, { operation }) }
@@ -107,16 +98,9 @@ describe('GoogleDriveBlock agent tool calls', () => {
10798 expect(buildParams({ operation: 'search', pageToken: 'stale' }).pageToken).toBeUndefined()
10899 })
109100
110- it('drops a list page token left over on the canvas under a non-paginating operation', () => {
111- expect(buildParams({ operation: 'get_file', pageToken: 'stale' }).pageToken).toBeUndefined()
112- })
113-
114101 /** A stored agent tool keeps its operation on the tool, not in the args the mapper receives. */
115- it.each(['list', 'search', 'list_permissions', 'list_revisions', 'list_comments'])(
116- 'keeps the model pageToken on %s when the args carry no operation',
117- (operation) => {
118- const args = { fileId: 'f-1', pageToken: 'next' }
119- expect({ ...args, ...buildParams(args, { operation }) }.pageToken).toBe('next')
120- }
121- )
102+ it('keeps the model pageToken when the args carry no operation', () => {
103+ const args = { fileId: 'f-1', pageToken: 'next' }
104+ expect({ ...args, ...buildParams(args, { operation: 'list_comments' }) }.pageToken).toBe('next')
105+ })
122106})
0 commit comments