Files
windmill/frontend/src/lib/components/sessions/previewReload.test.ts
T
hugocasaandClaude Opus 5.5 8dd46a4d14 feat: build, test and run standalone ai agents from ai sessions (#11954)
* feat: guidance for building standalone ai agents in ai sessions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: agent guidance for resource-only sessions, no flow tools

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: tell the user to deploy a drafted tool script with its agent

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: scope plain agent values, document tool_inputs, list agents in get_instructions

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: test and run ai agents from ai sessions, open agents in their editor

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: full-bleed agent editor tabs, back to the run form for agent tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: describe read-and-run as running agents too, pin agent run links

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: host the agent editor natively in session tabs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: switch the agent editor to tabs below 900px

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: name an agent's session tab after its summary

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: show deployed agents in session tabs, open and run them from the chat

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: deploy agents from the chat, report agent tabs as the active editor

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: pick agents from the tab picker, name their tabs, scope the agent page to its workspace

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: leave open editors alone on agent writes, read the agent page's workspace user

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: refresh an agent's deployed page when the chat deploys or deletes it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: name agent tabs before they load, mark agents in the changes drawer, stay on a deleted agent's tab

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep a cleared agent summary out of its tab name

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep the resource drawer's json option that the resources list still passes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* feat: open an agent in an AI session from its pages, fix review findings on agent tabs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: name the reserved agent tool names in the agent guidance

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: reload an agent's editor on a discard, open a new agent in a session

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: show agents as agents on compare and deploy, name a never-deployed one by its path

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: keep a deployed agent's type in its draft diff

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: link a fork row to the agent editor only on the side that holds the agent

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: guard agent page paths, mark drafted agents in the picker, side-aware agent rows on fork compare

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 10:46:43 +01:00

207 lines
7.8 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { toolReloadEffect, tabsToReload, viewerTabsToReload } from './previewReload'
import type { SessionPreviewTab } from './sessionState.svelte'
import { pageItemUrl } from './previewPaths'
describe('toolReloadEffect', () => {
it('maps a non-item mutation to its own list page only', () => {
expect(toolReloadEffect('write_schedule', { path: 'u/me/s' }).pages).toEqual(['/schedules'])
expect(toolReloadEffect('write_resource', {}).pages).toEqual(['/resources'])
expect(toolReloadEffect('write_variable', {}).pages).toEqual(['/variables'])
expect(toolReloadEffect('create_folder', { name: 'f' }).pages).toEqual(['/folders'])
expect(toolReloadEffect('create_resource_type', { name: 'c_x' }).pages).toEqual(['/resources'])
})
it('maps a trigger write to its kind-specific page', () => {
expect(toolReloadEffect('write_trigger', { kind: 'kafka' }).pages).toEqual(['/kafka_triggers'])
expect(toolReloadEffect('write_trigger', { kind: 'http' }).pages).toEqual(['/routes'])
})
it('maps a generic item tool to the page for its type', () => {
expect(toolReloadEffect('deploy_workspace_item', { type: 'schedule' }).pages).toEqual([
'/schedules'
])
expect(toolReloadEffect('delete_workspace_item', { type: 'resource' }).pages).toEqual([
'/resources'
])
expect(
toolReloadEffect('discard_local_draft', { type: 'trigger', trigger_kind: 'nats' }).pages
).toEqual(['/nats_triggers'])
})
it('reloads no page for item-editor kinds (they self-sync via their live editor)', () => {
for (const type of ['script', 'flow', 'app']) {
expect(toolReloadEffect('deploy_workspace_item', { type }).pages).toEqual([])
}
for (const name of [
'write_script',
'edit_script',
'write_flow',
'init_app',
'write_app_file'
]) {
expect(toolReloadEffect(name, { path: 'u/me/x' }).pages).toEqual([])
}
})
it('reloads nothing for a purely local or unknown tool (the silent-stale guard)', () => {
expect(toolReloadEffect('update_user_instructions', {}).pages).toEqual([])
expect(toolReloadEffect('some_future_tool', { path: 'p' }).pages).toEqual([])
})
it('reloads nothing for a trigger of unknown kind rather than guessing', () => {
expect(toolReloadEffect('write_trigger', { kind: 'not_a_kind' }).pages).toEqual([])
})
})
describe('page item tabs', () => {
const tab = (url: string): SessionPreviewTab => ({ id: url, url, loc: url })
const kafkaA = tab('pageitem:trigger.kafka/u%2Fme%2Fa')
const kafkaB = tab('pageitem:trigger.kafka/u%2Fme%2Fb')
const list = tab('/kafka_triggers')
it('reloads only the trigger a write names, and its list page', () => {
const { pages, items } = toolReloadEffect('write_trigger', {
kind: 'kafka',
config: { path: 'u/me/a' }
})
const named = new Set(items.map((i) => pageItemUrl(i)))
expect(tabsToReload([kafkaA, kafkaB, list], new Set(pages), named)).toEqual([kafkaA, list])
})
it('reloads every tab of the kind when the tool names no item', () => {
expect(tabsToReload([kafkaA, kafkaB], new Set(['/kafka_triggers']))).toEqual([kafkaA, kafkaB])
})
})
describe('tabsToReload', () => {
const scheduleTab: SessionPreviewTab = { id: 's', url: '/schedules', loc: '/schedules' }
const resourceTab: SessionPreviewTab = { id: 'r', url: '/resources', loc: '/resources' }
const scriptTab: SessionPreviewTab = {
id: 'sc',
url: '/scripts/edit/f/foo/bar',
loc: '/scripts/edit/f/foo/bar'
}
const pipelineTab: SessionPreviewTab = { id: 'p', url: '/pipeline/crm', loc: '/pipeline/crm' }
const tabs = [scheduleTab, resourceTab, scriptTab, pipelineTab]
it('returns only the tabs whose page is in the set', () => {
expect(tabsToReload(tabs, new Set(['/schedules']))).toEqual([scheduleTab])
})
it('returns list-page tabs but never item-editor or pipeline tabs', () => {
// toolReloadEffect only ever emits list-page paths, so item/pipeline route
// paths are never in `pages` — those tabs self-sync and stay put.
expect(tabsToReload(tabs, new Set(['/schedules', '/resources']))).toEqual([
scheduleTab,
resourceTab
])
})
it("reloads the resources list on an agent write but not the agent's editor, which a discard does", () => {
const url = pageItemUrl({ kind: 'resource', path: 'u/me/a' })
const agentTab: SessionPreviewTab = { id: 'a', url, loc: url }
const reloaded = (name: string, args: any) => {
const { pages, items, live = [] } = toolReloadEffect(name, args)
return tabsToReload(
[resourceTab, agentTab],
new Set(pages),
new Set(items.map(pageItemUrl)),
new Set(live.map(pageItemUrl))
)
}
expect(reloaded('write_resource', { resource_type: 'ai_agent', path: 'u/me/a' })).toEqual([
resourceTab
])
expect(reloaded('discard_local_draft', { type: 'resource', path: 'u/me/a' })).toEqual([
resourceTab,
agentTab
])
})
it('is empty when no pages were touched', () => {
expect(tabsToReload(tabs, new Set())).toEqual([])
})
it('matches on the observed loc (with query/hash stripped) over the seeded url', () => {
const navigated: SessionPreviewTab = { id: 'n', url: '/runs', loc: '/schedules?workspace=w' }
expect(tabsToReload([navigated], new Set(['/schedules']))).toEqual([navigated])
})
})
describe('viewerTabsToReload', () => {
const viewTab: SessionPreviewTab = {
id: 'v',
url: '/scripts/get/f/foo/bar',
loc: '/scripts/get/f/foo/bar'
}
const editTab: SessionPreviewTab = {
id: 'e',
url: '/flows/edit/f/foo/baz',
loc: '/flows/edit/f/foo/baz'
}
const pageTab: SessionPreviewTab = { id: 'p', url: '/schedules', loc: '/schedules' }
it('returns the view-side tab whose item was deployed', () => {
expect(viewerTabsToReload([viewTab, editTab, pageTab], new Set(['f/foo/bar']))).toEqual([
viewTab
])
})
it("refreshes an agent's deployed page when the chat deletes or deploys it", () => {
const agentTab: SessionPreviewTab = {
id: 'a',
url: '/agents/get/u/me/bot',
loc: '/agents/get/u/me/bot'
}
const { deployed } = toolReloadEffect('delete_workspace_item', {
type: 'resource',
path: 'u/me/bot'
})
expect(viewerTabsToReload([agentTab, viewTab], new Set(deployed))).toEqual([agentTab])
})
// The editor holds what the user is writing; refetching the deployed version over it
// would discard that, and it self-syncs from the store the chat already mutated.
it('never returns the edit side, even for the item that was deployed', () => {
expect(viewerTabsToReload([editTab], new Set(['f/foo/baz']))).toEqual([])
})
it('leaves a view tab on a different item alone', () => {
expect(viewerTabsToReload([viewTab], new Set(['f/other/item']))).toEqual([])
})
it('is empty when no items were deployed', () => {
expect(viewerTabsToReload([viewTab, editTab], new Set())).toEqual([])
})
})
describe('toolReloadEffect deployed', () => {
// A deploy is invisible to a View tab otherwise: it renders the deployed version over
// the API and shares no store with the chat.
it('names the item a deploy or delete changed, for the kinds a tab can view', () => {
for (const type of ['script', 'flow', 'app']) {
expect(toolReloadEffect('deploy_workspace_item', { type, path: 'u/me/x' }).deployed).toEqual([
'u/me/x'
])
expect(toolReloadEffect('delete_workspace_item', { type, path: 'u/me/x' }).deployed).toEqual([
'u/me/x'
])
}
})
it('names no item for a draft-only tool — nothing deployed changed', () => {
expect(toolReloadEffect('write_script', { path: 'u/me/x' }).deployed).toEqual([])
expect(
toolReloadEffect('discard_local_draft', { type: 'script', path: 'u/me/x' }).deployed
).toEqual([])
expect(toolReloadEffect('rebase_draft', { type: 'flow', path: 'u/me/x' }).deployed).toEqual([])
})
it('names no item for types that have a list page instead of a view side', () => {
expect(
toolReloadEffect('deploy_workspace_item', { type: 'schedule', path: 'u/me/s' }).deployed
).toEqual([])
})
})