Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/composables/useWorkspaceInset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,21 @@ describe('useWorkspaceInsetRight', () => {
width.value = 960
await nextTick()

expect(readInset()).toBe('420px')
// Teardown clears the var rather than freezing it at its last published
// value - a docked surface unmounted mid-close (its host's `v-if` beats
// its own `docked.value ? width : 0` branch to the flush) must not leave
// every portaled overlay permanently offset.
expect(readInset()).toBe('0px')
})

it('leaves the incoming publisher alone when the outgoing one disposes', () => {
const outgoing = effectScope()
outgoing.run(() => useWorkspaceInsetRight(() => 420))
runInScope(() => 960)

// A mode switch mounts the new docked host before unmounting the old one.
outgoing.stop()

expect(readInset()).toBe('960px')
})
})
18 changes: 17 additions & 1 deletion src/composables/useWorkspaceInset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { watchEffect } from 'vue'
import { onScopeDispose, watchEffect } from 'vue'

/**
* Width consumed by docked surfaces on the right of the workspace.
Expand All @@ -9,11 +9,27 @@ import { watchEffect } from 'vue'
*/
export const WORKSPACE_INSET_RIGHT = '--workspace-inset-right'

let activePublisher: symbol | null = null

export function useWorkspaceInsetRight(widthPx: () => number): void {
const publisher = Symbol('workspace-inset-right')
watchEffect(() => {
activePublisher = publisher
document.documentElement.style.setProperty(
WORKSPACE_INSET_RIGHT,
`${widthPx()}px`
)
})
// A docked surface's own `docked.value ? width : 0` branch never runs once
// its host is unmounted BEFORE that branch flips (e.g. a parent `v-if`
// unmounts the whole component in the same flush as closing it) - clear
// the var directly on teardown so it cannot survive its publisher.
//
// Mode switches mount the incoming publisher before the outgoing one
// disposes (GraphCanvas and LinearView both host the dock), so only the
// surface still owning the variable may clear it.
onScopeDispose(() => {
if (activePublisher !== publisher) return
document.documentElement.style.setProperty(WORKSPACE_INSET_RIGHT, '0px')
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ describe('mint ports against the real layout store delivery', () => {
const linkStore = useLinkStore()
const severed = linkTopology(41, '2')
linkStore.registerLink(scope, severed)
await realDelivery()
minted.length = 0
const consoleError = vi
.spyOn(console, 'error')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
import { defineComponent, nextTick, ref } from 'vue'

import { i18n } from '@/i18n'
import { WORKSPACE_INSET_RIGHT } from '@/composables/useWorkspaceInset'
import { reportError } from '@/platform/telemetry/reportError'
import type { TurnId } from '@/workbench/extensions/agent/schemas/agentApiSchema'
import { useAgentConversationStore } from '@/workbench/extensions/agent/stores/agent/agentConversationStore'
Expand Down Expand Up @@ -65,6 +66,7 @@ function renderPanel() {
describe('DockedAgentPanel', () => {
beforeEach(() => {
localStorage.clear()
document.documentElement.style.removeProperty(WORKSPACE_INSET_RIGHT)
fetchApi.mockReset()
fetchApi.mockResolvedValue(jsonResponse(404, { error: 'not found' }))
vi.mocked(reportError).mockClear()
Expand All @@ -84,6 +86,9 @@ describe('DockedAgentPanel', () => {
timeout: 5000
})
).toBeTruthy()
expect(
document.documentElement.style.getPropertyValue(WORKSPACE_INSET_RIGHT)
).toBe(`${store.width}px`)
})

it('restores the server run mode when the panel initializes', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { computed, defineAsyncComponent, defineComponent, h, ref } from 'vue'
import { useI18n } from 'vue-i18n'

import { reportError } from '@/platform/telemetry/reportError'
import { useWorkspaceInsetRight } from '@/composables/useWorkspaceInset'
import { useAgentPanelStore } from '@/workbench/extensions/agent/stores/agent/agentPanelStore'
import { useAgentRunModeStore } from '@/workbench/extensions/agent/stores/agent/agentRunModeStore'

Expand Down Expand Up @@ -68,6 +69,7 @@ const agentPanelStore = useAgentPanelStore()
const agentRunModeStore = useAgentRunModeStore()
const { isOpen, enabled, width } = storeToRefs(agentPanelStore)
const docked = computed(() => enabled.value && isOpen.value)
useWorkspaceInsetRight(() => (docked.value ? width.value : 0))
Comment thread
christian-byrne marked this conversation as resolved.
Resolved

void agentRunModeStore.load().catch((error: unknown) => {
reportError(error, { errorType: 'agent_run_mode_load_failure' })
Expand Down
76 changes: 53 additions & 23 deletions src/workbench/extensions/agent/crdt/linkMintPort.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'

import { toLinkId } from '@/types/linkId'

import type { GraphOperation } from './graphOperations'
import { attachLinkMintPort } from './linkMintPort'
import type {
Expand All @@ -10,6 +12,9 @@ import type {
import { createMintSession } from './mintSession'
import type { MintSession } from './mintSession'

const { reportError } = vi.hoisted(() => ({ reportError: vi.fn() }))
vi.mock(import('@/platform/telemetry/reportError'), () => ({ reportError }))

const ROOT_SCOPE: LinkScopeView = {
rootGraphId: 'root-uuid',
owningGraphId: 'root-uuid'
Expand All @@ -21,7 +26,7 @@ const SUBGRAPH_SCOPE: LinkScopeView = {

function topology(id: number): LinkTopologyView {
return {
id,
id: toLinkId(id),
originNodeId: 1,
originSlot: 0,
targetNodeId: 2,
Expand Down Expand Up @@ -82,8 +87,9 @@ describe('attachLinkMintPort', () => {
})
})

it('mints a concrete connect for a local link placement', () => {
it('mints a concrete connect for a local link placement', async () => {
place(ROOT_SCOPE, topology(41))
await Promise.resolve()

expect(minted).toEqual([
{
Expand Down Expand Up @@ -121,14 +127,10 @@ describe('attachLinkMintPort', () => {
})

it('surfaces a subgraph-interior placement observably instead of minting', () => {
const consoleError = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined)
place(SUBGRAPH_SCOPE, topology(41))

expect(minted).toEqual([])
expect(consoleError).toHaveBeenCalledOnce()
consoleError.mockRestore()
expect(reportError).toHaveBeenCalledOnce()
})

it('captures a severed link under both endpoints, consumed exactly once', () => {
Expand All @@ -139,40 +141,34 @@ describe('attachLinkMintPort', () => {
})

it('surfaces an unconsumed local disconnect as divergence after the sweep', async () => {
const consoleError = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined)
remove(ROOT_SCOPE, topology(41))
await afterSweep()

expect(consoleError).toHaveBeenCalledOnce()
expect(consoleError.mock.calls[0][1]).toBe(41)
consoleError.mockRestore()
expect(reportError).toHaveBeenCalledOnce()
expect(reportError).toHaveBeenCalledWith(
expect.any(Error),
expect.objectContaining({
errorType: 'agent_crdt_unrepresentable_link_change',
tags: expect.objectContaining({ linkId: 41 })
})
)
})

it('stays silent for a consumed severance (the delete carried it)', async () => {
const consoleError = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined)
remove(ROOT_SCOPE, topology(41))
port.severances.take('1')
await afterSweep()

expect(consoleError).not.toHaveBeenCalled()
consoleError.mockRestore()
expect(reportError).not.toHaveBeenCalled()
})

it('stays silent for teardown severances', async () => {
const consoleError = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined)
session.beginGraphTeardown()
remove(ROOT_SCOPE, topology(41))
session.endGraphTeardown()
await afterSweep()

expect(consoleError).not.toHaveBeenCalled()
consoleError.mockRestore()
expect(reportError).not.toHaveBeenCalled()
})

it('sweeps the capture window: a later take finds nothing', async () => {
Expand All @@ -191,4 +187,38 @@ describe('attachLinkMintPort', () => {

expect(minted).toEqual([])
})

it('cancels a same-task deletion of an unflushed placement without a phantom connect', async () => {
place(ROOT_SCOPE, topology(41))
remove(ROOT_SCOPE, topology(41))
await afterSweep()

// The canceled placement never reaches enqueue and is never reported as
// a `link connect` divergence (it did not ship). The severance sweep
// still runs and correctly reports the unconsumed disconnect - it was a
// real local delete that nothing (e.g. a delete_node mint) consumed.
expect(minted).toEqual([])
expect(reportError).toHaveBeenCalledOnce()
expect(reportError).toHaveBeenCalledWith(
expect.objectContaining({
message: expect.stringContaining('link disconnect')
}),
expect.anything()
)
})

it('flushes and surfaces pending placements on detach instead of discarding them silently', () => {
place(ROOT_SCOPE, topology(41))
port.detach()

expect(minted).toEqual([])
expect(reportError).toHaveBeenCalledOnce()
expect(reportError).toHaveBeenCalledWith(
expect.any(Error),
expect.objectContaining({
errorType: 'agent_crdt_unrepresentable_link_change',
tags: expect.objectContaining({ linkId: 41 })
})
)
})
})
Loading
Loading