Skip to content

Commit d7be0f9

Browse files
committed
Merge remote-tracking branch 'origin/staging' into feat/embeddings-multi-provider
2 parents 9302f84 + 5157a59 commit d7be0f9

3 files changed

Lines changed: 100 additions & 2 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
5+
import { memory } from '@sim/db/schema'
6+
import {
7+
createMockRequest,
8+
hybridAuthMockFns,
9+
queueTableRows,
10+
resetDbChainMock,
11+
} from '@sim/testing'
12+
import { beforeEach, describe, expect, it, vi } from 'vitest'
13+
import { AuthType } from '@/lib/auth/hybrid'
14+
import {
15+
PRIVATE_TOOL_METADATA_REQUEST_HEADER,
16+
PRIVATE_TOOL_METADATA_RESPONSE_HEADER,
17+
RESOLVED_SECRET_PROVENANCE_FIELD,
18+
RESOLVED_SECRET_PROVENANCE_METADATA_V1,
19+
} from '@/lib/execution/private-tool-metadata'
20+
21+
const { mockCheckWorkspaceAccess } = vi.hoisted(() => ({
22+
mockCheckWorkspaceAccess: vi.fn(),
23+
}))
24+
25+
vi.mock('@/lib/workspaces/permissions/utils', () => ({
26+
checkWorkspaceAccess: mockCheckWorkspaceAccess,
27+
}))
28+
29+
import { GET } from '@/app/api/memory/[id]/route'
30+
31+
const WORKSPACE_ID = '11111111-1111-4111-8111-111111111111'
32+
const CONTEXT = { params: Promise.resolve({ id: 'missing-conversation' }) }
33+
34+
describe('GET /api/memory/[id]', () => {
35+
beforeEach(() => {
36+
vi.clearAllMocks()
37+
resetDbChainMock()
38+
hybridAuthMockFns.mockCheckInternalAuth.mockResolvedValue({
39+
success: true,
40+
userId: 'user-1',
41+
authType: AuthType.INTERNAL_JWT,
42+
})
43+
mockCheckWorkspaceAccess.mockResolvedValue({ exists: true, hasAccess: true })
44+
queueTableRows(memory, [])
45+
})
46+
47+
it('returns verified exact-empty metadata when a tool lookup has no matching memory', async () => {
48+
const response = await GET(
49+
createMockRequest(
50+
'GET',
51+
undefined,
52+
{
53+
[PRIVATE_TOOL_METADATA_REQUEST_HEADER]: RESOLVED_SECRET_PROVENANCE_METADATA_V1,
54+
},
55+
`http://localhost:3000/api/memory/missing-conversation?workspaceId=${WORKSPACE_ID}`
56+
),
57+
CONTEXT
58+
)
59+
60+
expect(response.status).toBe(200)
61+
expect(response.headers.get(PRIVATE_TOOL_METADATA_RESPONSE_HEADER)).toBe(
62+
RESOLVED_SECRET_PROVENANCE_METADATA_V1
63+
)
64+
expect(await response.json()).toEqual({
65+
success: true,
66+
data: null,
67+
[RESOLVED_SECRET_PROVENANCE_FIELD]: {
68+
version: 1,
69+
complete: true,
70+
entries: [],
71+
scope: { userId: 'user-1', workspaceId: WORKSPACE_ID },
72+
},
73+
})
74+
})
75+
76+
it('preserves the existing headerless empty response for ordinary API callers', async () => {
77+
const response = await GET(
78+
createMockRequest(
79+
'GET',
80+
undefined,
81+
{},
82+
`http://localhost:3000/api/memory/missing-conversation?workspaceId=${WORKSPACE_ID}`
83+
),
84+
CONTEXT
85+
)
86+
87+
expect(response.status).toBe(200)
88+
expect(response.headers.get(PRIVATE_TOOL_METADATA_RESPONSE_HEADER)).toBeNull()
89+
expect(await response.json()).toEqual({ success: true, data: null })
90+
})
91+
})

apps/sim/app/api/memory/[id]/route.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,14 @@ export const GET = withRouteHandler(async (request: NextRequest, context: Memory
9191
.limit(1)
9292

9393
if (memories.length === 0) {
94-
return NextResponse.json({ success: true, data: null }, { status: 200 })
94+
return createMemoryResponse({
95+
request,
96+
authType: accessCheck.authType,
97+
userId: accessCheck.userId,
98+
workspaceId: validatedWorkspaceId,
99+
body: { success: true, data: null },
100+
memories: [],
101+
})
95102
}
96103

97104
const mem = memories[0]

apps/sim/lib/api/contracts/memory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export const getMemoryByIdContract = defineRouteContract({
116116
query: memoryWorkspaceQuerySchema,
117117
response: {
118118
mode: 'json',
119-
schema: memorySuccessResponseSchema(memoryRecordSchema),
119+
schema: memorySuccessResponseSchema(memoryRecordSchema.nullable()),
120120
},
121121
})
122122

0 commit comments

Comments
 (0)