Skip to content

Commit 2e7f4ec

Browse files
waleedlatif1claude
andcommitted
test(copilot): cover auth-deny on a found row skips the messages query
Address PR review: exercise the `if (!authorized) return null` contract — when the chat row exists but authorization fails, the getter returns null and never issues the copilot_messages read. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 370642e commit 2e7f4ec

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

apps/sim/lib/copilot/chat/lifecycle.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,17 @@ describe('lifecycle copilot chat reads (cutover to copilot_messages)', () => {
8989
expect(dbChainMockFns.orderBy).not.toHaveBeenCalled()
9090
})
9191

92+
it('returns null and does NOT query messages when the row is found but authorization fails', async () => {
93+
// Row exists but belongs to a workflow the user cannot read.
94+
dbChainMockFns.limit.mockResolvedValueOnce([{ ...chatRow, workflowId: 'wf-1' }])
95+
mockAuthorizeWorkflow.mockResolvedValueOnce({ allowed: false, workflow: null })
96+
97+
const result = await getAccessibleCopilotChatWithMessages(CHAT_ID, USER_ID)
98+
99+
expect(result).toBeNull()
100+
expect(dbChainMockFns.orderBy).not.toHaveBeenCalled()
101+
})
102+
92103
it('legacy getAccessibleCopilotChat also assembles messages from copilot_messages', async () => {
93104
dbChainMockFns.limit.mockResolvedValueOnce([
94105
{ ...chatRow, model: 'm', planArtifact: null, config: null },

0 commit comments

Comments
 (0)