diff --git a/frontend/src/lib/components/copilot/chat/global/core.test.ts b/frontend/src/lib/components/copilot/chat/global/core.test.ts index ec44a4f65e..6b5d159931 100644 --- a/frontend/src/lib/components/copilot/chat/global/core.test.ts +++ b/frontend/src/lib/components/copilot/chat/global/core.test.ts @@ -733,6 +733,67 @@ describe('global AI tools', () => { expect(raw).not.toContain('deployed_step') }) + it('reads draft-only DB script anchors as drafts when no local draft exists', async () => { + vi.mocked(ScriptService.getScriptByPathWithDraft).mockResolvedValueOnce({ + path: 'f/scripts/draft-only', + hash: 'draft-anchor-hash', + summary: 'draft-only summary', + description: 'draft-only description', + content: 'draft-only content', + language: 'bun', + kind: 'script', + draft_only: true + } as any) + + const raw = await callGlobalTool('read_workspace_item', { + type: 'script', + path: 'f/scripts/draft-only' + }) + const item = JSON.parse(raw) + + expect(item).toEqual({ + type: 'script', + path: 'f/scripts/draft-only', + summary: 'draft-only summary', + language: 'bun', + value: 'draft-only content', + isDraft: true + }) + }) + + it('reads draft-only DB flow anchors as drafts when no local draft exists', async () => { + vi.mocked(FlowService.getFlowByPathWithDraft).mockResolvedValueOnce({ + path: 'f/flows/draft-only', + summary: 'draft-only flow summary', + value: { + modules: [{ id: 'draft_only_step', value: { type: 'identity' } }] + }, + schema: { type: 'object', properties: { draftOnly: { type: 'boolean' } } }, + edited_by: 'admin', + edited_at: '2026-05-22T10:00:00Z', + archived: false, + extra_perms: {}, + draft_only: true + } as any) + + const raw = await callGlobalTool('read_workspace_item', { + type: 'flow', + path: 'f/flows/draft-only' + }) + const item = JSON.parse(raw) + + expect(item).toMatchObject({ + type: 'flow', + path: 'f/flows/draft-only', + summary: 'draft-only flow summary', + isDraft: true, + value: { + modules: [{ id: 'draft_only_step', value: { type: 'identity' } }], + schema: { type: 'object', properties: { draftOnly: { type: 'boolean' } } } + } + }) + }) + it('applies path_prefix to local drafts before enforcing the result limit', async () => { await callGlobalTool('write_script', { path: 'f/other/outside', diff --git a/frontend/src/lib/components/copilot/chat/global/core.ts b/frontend/src/lib/components/copilot/chat/global/core.ts index a7c9779e2f..bf6c5c5889 100644 --- a/frontend/src/lib/components/copilot/chat/global/core.ts +++ b/frontend/src/lib/components/copilot/chat/global/core.ts @@ -1186,9 +1186,9 @@ async function readWorkspaceItem( ): Promise { switch (type) { case 'script': - return scriptToItem(await loadScriptWithDbDraft(path, workspace), true, false) + return scriptToItem(await loadScriptWithDbDraft(path, workspace), true) case 'flow': - return flowToItem(await loadFlowWithDbDraft(path, workspace), true, false) + return flowToItem(await loadFlowWithDbDraft(path, workspace), true) case 'schedule': return scheduleToItem(await ScheduleService.getSchedule({ workspace, path }), true) case 'trigger':