Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
8 changes: 4 additions & 4 deletions src/main/agent-launch/startup-agent-worktree-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const FULL: RuntimeManagedWorktreeCreateArgs = {
}

describe('createWorktreeWithStartupAgent', () => {
it('starts a terminal agent with the prompt folded by the create, whatever the chat default', async () => {
it('forwards the startup agent and prompt to the create with the chat default on', async () => {
const { runtime, created, create } = harness()
const prompt = 'x'.repeat(3000)
const args = {
Expand All @@ -100,7 +100,7 @@ describe('createWorktreeWithStartupAgent', () => {
expect(runtime.getStructuredAgentSessionCreateSupport).not.toHaveBeenCalled()
})

it('hands a post-start agent its prompt through the create, which sends it once the agent is up', async () => {
it('forwards a post-start agent and prompt to the create', async () => {
const { runtime, create } = harness()
const args = { ...FULL, startupAgent: 'aider' as const, startupPrompt: 'fix the bug' }

Expand All @@ -109,7 +109,7 @@ describe('createWorktreeWithStartupAgent', () => {
expect(runtime.createManagedWorktree).toHaveBeenCalledWith(args)
})

it('treats a blank prompt as none, which the create launches bare either way', async () => {
it('omits a blank startup prompt from the create request', async () => {
for (const startupPrompt of ['', ' \n']) {
const { runtime, create } = harness()

Expand All @@ -119,7 +119,7 @@ describe('createWorktreeWithStartupAgent', () => {
}
})

it('starts a linked draft through `startupDraft`, unsent, with the agent the draft resolves', async () => {
it('forwards a linked draft through `startupDraft` with its resolved agent', async () => {
const { runtime, create } = harness({ draftAgent: 'codex' })
const { createdWithAgent: _requested, ...request } = FULL
const draft = 'https://github.com/o/r/issues/1'
Expand Down
4 changes: 2 additions & 2 deletions src/main/agent-trust-presets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('markCursorWorkspaceTrusted', () => {
const trustFile = join(projectsDir, slugDirs[0], '.workspace-trusted')
expect(existsSync(trustFile)).toBe(true)
const payload = JSON.parse(readFileSync(trustFile, 'utf-8'))
expect(payload.workspacePath).toBeTruthy()
expect(payload.workspacePath).toBe(realpathSync.native(workspace))
expect(typeof payload.trustedAt).toBe('string')
} finally {
rmSync(workspace, { recursive: true, force: true })
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('markCopilotFolderTrusted', () => {
const parsed = JSON.parse(readFileSync(configPath, 'utf-8'))
expect(Array.isArray(parsed.trustedFolders)).toBe(true)
expect(parsed.trustedFolders.length).toBe(1)
expect(typeof parsed.trustedFolders[0]).toBe('string')
expect(parsed.trustedFolders[0]).toBe(realpathSync.native(workspace))
} finally {
rmSync(workspace, { recursive: true, force: true })
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/ai-vault-search/session-search-file-write.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function counts(db: SyncDatabase): Record<string, number> {
}
}

it('writes a whole read in one transaction', () => {
it('publishes all rows from a completed whole read', () => {
replayTranscriptRead({ messages: userMessages('needle text', 300) })

const after = counts(index.db)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ it('moves the generation when a purge reclaims rows nothing can reach', async ()
}
})

it("leaves the generation alone when a replace swaps a session's own rows", async () => {
it('leaves the generation alone when messages attached to live sessions are deleted', async () => {
// Deleting messages attached to live sessions must not fire the orphan-reclamation trigger.
const root = await tempRoot()
const path = join(root, 'index.sqlite')
Expand Down Expand Up @@ -213,7 +213,7 @@ it('keeps the generation across a reopen, because the bump rides its own commit'
}
})

it('fences a reader against a writer it does not share a process with', async () => {
it('fences a reader against another database handle moving the index', async () => {
// A process-local generation would miss another process’s writes and admit stale cursors.
const root = await tempRoot()
const path = join(root, 'index.sqlite')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ it('cuts at punctuation when the window holds no whitespace at all', async () =>
}
})

it('keeps a 9,000-character identifier whole rather than cutting at its underscores', () => {
it('hard-cuts a 9,000-character identifier without treating underscores as boundaries', () => {
// Underscores are token characters, so this oversized identifier requires a hard cut.
const text = 'ab_'.repeat(3000)
expect(text.length).toBe(9000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function entry(overrides: Partial<AutomationHostCatalogEntry> = {}): AutomationH
return {
stableRef: { authority: { kind: 'desktop' }, selector: { kind: 'self' } },
owner: { authority: { kind: 'desktop' }, selector: { kind: 'self' } },
stableKey: 'desktop:self',
stableKey: 'host:desktop:self',
label: 'This computer',
authorityLabel: 'Desktop',
kind: 'self',
Expand All @@ -39,7 +39,7 @@ function sshEntry(targetGeneration: number): AutomationHostCatalogEntry {
authority: { kind: 'desktop' },
selector: { kind: 'ssh', targetId: 'box', targetGeneration }
},
stableKey: 'desktop:ssh:box',
stableKey: 'host:desktop:ssh:box',
kind: 'ssh'
})
}
Expand Down Expand Up @@ -82,13 +82,13 @@ describe('create destination resolution', () => {
it('prefers the explicit selection and only then the active workspace', () => {
const entries = [entry(), sshEntry(3)]
expect(
preselectAutomationCreateHost(entries, 'desktop:ssh:box', 'desktop:self')?.stableKey
).toBe('desktop:ssh:box')
expect(preselectAutomationCreateHost(entries, null, 'desktop:self')?.stableKey).toBe(
'desktop:self'
preselectAutomationCreateHost(entries, 'host:desktop:ssh:box', 'host:desktop:self')?.stableKey
).toBe('host:desktop:ssh:box')
expect(preselectAutomationCreateHost(entries, null, 'host:desktop:self')?.stableKey).toBe(
'host:desktop:self'
)
// An unresolvable workspace host leaves the choice open rather than picking one.
expect(preselectAutomationCreateHost(entries, null, 'desktop:ssh:gone')).toBeNull()
expect(preselectAutomationCreateHost(entries, null, 'host:desktop:ssh:gone')).toBeNull()
expect(preselectAutomationCreateHost(entries, null, null)).toBeNull()
})
})
Expand Down Expand Up @@ -172,14 +172,14 @@ describe('offered create hosts', () => {
it('does not blame the server for hosts another repair or none would fix', () => {
// Unverified since disconnect: the repair is a reconnect, not an update.
const unverified = entry({
stableKey: 'desktop:ssh:cold',
stableKey: 'host:desktop:ssh:cold',
kind: 'ssh',
querySupport: 'legacy-unscoped',
scopeGap: 'target-unverified'
})
// Scoped but not yet hydrated: disabled, and no repair to name.
const unhydrated = entry({
stableKey: 'desktop:ssh:warm',
stableKey: 'host:desktop:ssh:warm',
kind: 'ssh',
owner: null,
catalogState: 'unhydrated'
Expand All @@ -199,19 +199,19 @@ describe('sole create host', () => {
}

it('states the only eligible host and never one of several', () => {
expect(soleAutomationCreateHost([entry()], hydrated)?.stableKey).toBe('desktop:self')
expect(soleAutomationCreateHost([entry()], hydrated)?.stableKey).toBe('host:desktop:self')
expect(soleAutomationCreateHost([entry(), sshEntry(3)], hydrated)).toBeNull()
// An orphan bucket, an unowned host, and a view-only host are not candidates at all.
expect(
soleAutomationCreateHost([entry(), entry({ stableKey: 'orphan', kind: 'orphan' })], hydrated)
?.stableKey
).toBe('desktop:self')
).toBe('host:desktop:self')
expect(
soleAutomationCreateHost(
[entry(), entry({ stableKey: 'legacy', querySupport: 'legacy-unscoped' })],
hydrated
)?.stableKey
).toBe('desktop:self')
).toBe('host:desktop:self')
})

it('states nothing until the catalog has settled', () => {
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('create project mismatch', () => {
addedAt: 1,
worktreeBaseRef: 'main',
...overrides
} as Repo
}
}
const desktopSelf = {
authority: { kind: 'desktop' } as const,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ describe('shouldHandleAutomationDetailTabArrowKey', () => {
expect(shouldHandleAutomationDetailTabArrowKey(makeEvent({ target: editable }))).toBe(false)
})

it('ignores keys when target is inside a modal dialog, menu, or listbox', () => {
it.each(['dialog', 'menu', 'listbox'])('ignores keys inside a %s', (role) => {
const dialog = document.createElement('div')
dialog.setAttribute('role', 'dialog')
dialog.setAttribute('role', role)
const childButton = document.createElement('button')
dialog.appendChild(childButton)
document.body.appendChild(dialog)
Expand Down Expand Up @@ -198,9 +198,9 @@ describe('shouldHandleAutomationDetailEscapeKey', () => {
expect(shouldHandleAutomationDetailEscapeKey(makeEvent({ target: clearsValue }))).toBe(false)
})

it('ignores Escape when target is inside a modal dialog, menu, or listbox', () => {
it.each(['dialog', 'menu', 'listbox'])('ignores Escape inside a %s', (role) => {
const dialog = document.createElement('div')
dialog.setAttribute('role', 'dialog')
dialog.setAttribute('role', role)
const childButton = document.createElement('button')
dialog.appendChild(childButton)
document.body.appendChild(dialog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ beforeEach(async () => {
})

describe('extra agent args capability gate', () => {
it('refuses a create or move to a host without the capability before writing', async () => {
it('refuses a create on a host without the capability before writing', async () => {
const { createAutomationForDestination } = await client()
getRuntimeEnvironmentStatus.mockResolvedValue(LEGACY_HOST)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ afterEach(() => {
})

describe('automation host query controller', () => {
it('advances catalog generations before fetching anything', async () => {
it('syncs catalog generations and fetches the catalog host', async () => {
const listScoped = vi.fn(() => Promise.resolve(emptyList()))
const { controller } = createController(listScoped)
expect(getAuthorityCatalogGeneration(RUNTIME)).toBe(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,15 @@ describe('automation host cache invalidation scope', () => {
expect(cache.freshness(RUNTIME_SELF)).toBe('missing')
})

it('evicts a departed entry and caps the retired pool', () => {
it('evicts departed entries and rejects work captured before retirement', () => {
const cache = createCache({ retiredLimit: 1 })
cache.commit(cache.beginRequest(DESKTOP_SELF), { rows: [row('a')] })
cache.commit(cache.beginRequest(RUNTIME_SELF), { rows: [row('b')] })
const stale = cache.beginRequest(RUNTIME_SELF)
cache.evict(hostStableKey(DESKTOP_SELF))
cache.evict(hostStableKey(RUNTIME_SELF))
expect(cache.keys()).toEqual([])
// The revived entry keeps its advanced generation, so nothing captured before eviction commits.
const stale = cache.beginRequest(RUNTIME_SELF)
cache.invalidate(RUNTIME_SELF)
cache.beginRequest(RUNTIME_SELF)
expect(cache.commit(stale, { rows: [] })).toBe(false)
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { describe, expect, it } from 'vitest'
import type { RuntimeStatus } from '../../../../shared/runtime-types'
import { createCompatibleRuntimeStatusResponse } from '@/runtime/runtime-compatibility-test-fixture'
import { AUTOMATION_LIST_HOST_SCOPE_RUNTIME_CAPABILITY } from '../../../../shared/protocol-version'
import {
buildAutomationHostCatalogSource,
Expand All @@ -8,6 +10,14 @@ import {
type AutomationCatalogSshSource
} from './automation-host-catalog-source'

function status(overrides: Partial<RuntimeStatus> = {}): RuntimeStatus {
const response = createCompatibleRuntimeStatusResponse()
if (!response.ok) {
throw new Error(response.error.message)
}
return { ...response.result, ...overrides }
}

function runtime(
overrides: Partial<AutomationCatalogRuntimeSource> = {}
): AutomationCatalogRuntimeSource {
Expand All @@ -32,22 +42,22 @@ describe('automation host catalog source', () => {
it('treats a never-probed environment as loading, not as down', () => {
expect(runtimeAuthorityHealth(runtime())).toBe('loading')
expect(runtimeAuthorityHealth(runtime({ status: { status: null } }))).toBe('unavailable')
expect(runtimeAuthorityHealth(runtime({ status: { status: {} as never } }))).toBe('fresh')
expect(runtimeAuthorityHealth(runtime({ status: { status: status() } }))).toBe('fresh')
})

it('assumes scoped support until the capability set is actually known', () => {
// The scoped client re-checks the capability and fails closed itself, so
// guessing legacy here would only discard owners on a modern host.
expect(runtimeQuerySupport(runtime())).toBe('scoped')
expect(runtimeQuerySupport(runtime({ status: { status: null } }))).toBe('scoped')
expect(
runtimeQuerySupport(runtime({ status: { status: { capabilities: [] } as never } }))
).toBe('legacy-unscoped')
expect(runtimeQuerySupport(runtime({ status: { status: status({ capabilities: [] }) } }))).toBe(
'legacy-unscoped'
)
expect(
runtimeQuerySupport(
runtime({
status: {
status: { capabilities: [AUTOMATION_LIST_HOST_SCOPE_RUNTIME_CAPABILITY] } as never
status: status({ capabilities: [AUTOMATION_LIST_HOST_SCOPE_RUNTIME_CAPABILITY] })
}
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -605,16 +605,4 @@ describe('automation host diagnostics bookkeeping', () => {
byStableKey: {}
})
})

it('never copies an automation, a prompt, or a name into a counter', () => {
const diagnostics = createAutomationHostDiagnostics()
diagnostics.recordResponse({
authorityKey: 'a',
stableKey: 'k1',
rows: 3,
durationMs: 12,
approxSerializedChars: 900
})
expect(JSON.stringify(diagnostics.snapshot())).not.toMatch(/prompt|automation-|secret/i)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('execution health', () => {
expect(resolveSshExecutionHealth('unhydrated', 'connected', 'disconnected')).toBe('unknown')
})

it('maps every SSH status onto a distinct execution state', () => {
it('maps reported SSH statuses and absent status to execution health', () => {
expect(resolveSshExecutionHealth('authoritative', 'connected', undefined)).toBe('connected')
expect(resolveSshExecutionHealth('authoritative', 'reconnecting', undefined)).toBe('connecting')
expect(resolveSshExecutionHealth('authoritative', 'deploying-relay', undefined)).toBe(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ const SCOPED_AUTHORITIES = AUTHORITY_COUNT / 2
const HOST_COUNT = AUTHORITY_COUNT * ENTRIES_PER_AUTHORITY
const AUTOMATION_COUNT = HOST_COUNT * AUTOMATIONS_PER_HOST
const SSH_TARGET_GENERATION = 3
// Doc 417: a refresh at this size must not block the renderer for a frame budget's worth of work.
const LONG_TASK_BUDGET_MS = 50

function authorityAt(index: number): AutomationAuthorityRef {
return { kind: 'runtime', environmentId: `env-${index}`, pairingRevision: index + 1 }
Expand Down Expand Up @@ -230,31 +228,6 @@ async function roundTrip<T>(environmentId: string, value: () => T): Promise<T> {
}
}

/**
* Longest gap between successive macrotasks: a synchronous block anywhere in the
* refresh delays the next timer by its own duration, which is the only way to
* observe "no long task" rather than to assert it about one function.
*/
function watchLongTasks(): () => number {
let worst = 0
let last = performance.now()
let running = true
const tick = (): void => {
if (!running) {
return
}
const at = performance.now()
worst = Math.max(worst, at - last)
last = at
setTimeout(tick, 0)
}
setTimeout(tick, 0)
return () => {
running = false
return worst
}
}

function harness(): {
cache: AutomationHostCache
refresh: (options?: { force?: boolean }) => Promise<void>
Expand Down Expand Up @@ -378,15 +351,6 @@ describe('one refresh of 50 hosts carrying 1,000 automations', () => {
expect(snap.totals.rows).toBe(AUTOMATION_COUNT)
expect(perHost).toBe(AUTOMATION_COUNT)
})

it('does no synchronous work long enough to drop a frame', async () => {
const { refresh } = harness()
const stop = watchLongTasks()

await refresh()

expect(stop()).toBeLessThan(LONG_TASK_BUDGET_MS)
})
})

describe('relay cost the request pool cannot see', () => {
Expand Down Expand Up @@ -428,7 +392,7 @@ describe('relay cost the request pool cannot see', () => {
})

describe('the commit fence under real concurrency', () => {
it('commits nothing from an authority that re-paired while its answer was in flight', async () => {
it('commits nothing from an authority invalidated while its answer was in flight', async () => {
const { cache, refresh } = harness()
// One modern and one old server, so both the per-entry and the fan-out arm
// are fenced out while the other 40 hosts keep landing around them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,4 @@ describe('automation list empty state', () => {
expect(state.kind).toBe('host-empty')
expect(state.title).toBe('No automations on web-01')
})

it('keeps each empty string exclusive to its own condition', () => {
const titles = [
resolveAutomationListEmptyState(input()).title,
resolveAutomationListEmptyState(input({ resolution: ALL_HOSTS })).title,
resolveAutomationListEmptyState(input({ searchActive: true, hostRowCount: 2 })).title,
resolveAutomationListEmptyState(
input({ resolution: hostResolution({ entry: entry({ authorityHealth: 'stale-error' }) }) })
).title
]
expect(new Set(titles).size).toBe(4)
})
})
Loading
Loading