mirror of
https://github.com/stablyai/orca.git
synced 2026-09-29 16:02:50 +00:00
#14397 split `shared/types.ts` into 46 per-domain modules but kept the path as a re-export barrel so the import sites did not have to change. This removes the barrel: every consumer now imports from the module that actually declares the type, and `src/shared/types.ts` is deleted. Barrels hide where a type lives, make every consumer look like it depends on the whole domain, and let an unrelated edit invalidate a module that ~2,000 files transitively import. 2,323 import declarations across 2,321 files. Rewritten mechanically: each specifier was resolved to an absolute path via the TypeScript AST and recomputed, rather than string-substituted, so alias forms (`@/../../shared/ types`) and per-specifier `type` modifiers survive. Four cases the mechanical pass had to handle, each found by a gate rather than by reading the diff: - Modules inside `src/shared` import the barrel as `./types`, not `shared/types`. A pre-filter on the latter string skipped 176 of them and left imports dangling at a deleted file, which surfaced as confusing `Property 'x' is optional in type 'Repo' but required in Pick<Repo, ...>` errors rather than "module not found". - The barrel RENAMED one type on the way through (`WorkspaceSource as WorkspaceCreateTelemetrySource`), so the original name in the owning module has to be re-aliased at each consumer. - Three test files put `;(globalThis as ...)` on the line after the import. TypeScript parses that `;` as the import statement's terminator, so replacing through `statement.getEnd()` deletes it and breaks ASI. The rewrite now stops at the module specifier. - A file that already imported directly from a module got a SECOND import from it, because the barrel re-exported those same names — which trips `import/no-duplicates` under `--deny-warnings`. A post-pass merges declarations sharing a specifier and type-only-ness; the `import type` plus `import` pair from one module is left alone, since that form is allowed. Splitting one barrel import into several genuinely adds lines, which pushed `terminal-layout-pty-ownership.ts` to 301 counted lines: its 107-character import must wrap, and neither local type collapses onto one line (101 and 116 characters). Rather than contort a type declaration to fit a line budget, `collectLeafIds` and `pruneLeaves` move to `terminal-pane-layout-tree.ts` — they are pure structural operations on the layout tree and independent of PTY ownership. `visible-worktrees.ts` similarly loses its own mini-barrel re-export of `isDefaultBranchWorkspace`, with the four real consumers repointed at the declaring module. No `max-lines` bypass added. Verified: cold `tsc --noEmit` green on node, cli, and web (buildinfo deleted first — these projects are `composite: true` and reuse stale caches); the full `pnpm lint` green, not just bare oxlint — the narrower local check is what let the duplicate imports reach CI; max-lines ratchet OK at 344.
162 lines
6.3 KiB
TypeScript
162 lines
6.3 KiB
TypeScript
import { randomUUID } from 'node:crypto'
|
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
import os from 'node:os'
|
|
import path from 'node:path'
|
|
import type { Page } from '@stablyai/playwright-test'
|
|
import { test, expect } from './helpers/orca-app'
|
|
import { ensureTerminalVisible, waitForActiveWorktree, waitForSessionReady } from './helpers/store'
|
|
import { waitForActivePaneHookDescriptor, waitForActiveTerminalManager } from './helpers/terminal'
|
|
import type { GlobalSettings } from '../../src/shared/global-settings-types'
|
|
|
|
const QUESTION = 'Tabs or spaces?'
|
|
|
|
async function enableNativeChatSetting(page: Page): Promise<void> {
|
|
await page.evaluate(async () => {
|
|
const nextSettings = await window.api.settings.set({ experimentalNativeChat: true })
|
|
window.__store?.setState({ settings: nextSettings as GlobalSettings })
|
|
})
|
|
}
|
|
|
|
// Why (#11761): reproduces the paired-headless topology from the client's side —
|
|
// live status arrives carrying agent identity and a working state, but with no
|
|
// `interactivePrompt`/`toolName`, which is exactly what the host projection
|
|
// dropped. The pending ask exists only in the transcript.
|
|
async function seedStatusWithoutAskPayload(
|
|
page: Page,
|
|
args: { paneKey: string; worktreeId: string; sessionId: string; transcriptPath: string }
|
|
): Promise<void> {
|
|
await page.evaluate(({ paneKey, worktreeId, sessionId, transcriptPath }) => {
|
|
window.__store
|
|
?.getState()
|
|
.setAgentStatus(
|
|
paneKey,
|
|
{ state: 'working', prompt: 'AskUserQuestion card proof', agentType: 'claude' },
|
|
'Claude',
|
|
undefined,
|
|
{ worktreeId },
|
|
{ providerSession: { key: 'session_id', id: sessionId, transcriptPath } }
|
|
)
|
|
}, args)
|
|
}
|
|
|
|
async function toggleTerminalTabToChatView(
|
|
page: Page,
|
|
args: { tabId: string; worktreeId: string }
|
|
): Promise<void> {
|
|
await page.evaluate(({ tabId, worktreeId }) => {
|
|
const store = window.__store
|
|
if (!store) {
|
|
throw new Error('Store unavailable')
|
|
}
|
|
const state = store.getState()
|
|
const unifiedTab = (state.unifiedTabsByWorktree[worktreeId] ?? []).find(
|
|
(tab) => tab.contentType === 'terminal' && tab.entityId === tabId
|
|
)
|
|
if (!unifiedTab) {
|
|
throw new Error('Unified terminal tab not found for chat toggle')
|
|
}
|
|
state.toggleTabViewMode(unifiedTab.id)
|
|
}, args)
|
|
}
|
|
|
|
/** A transcript whose last assistant turn leaves an AskUserQuestion unanswered. */
|
|
function pendingAskTranscript(args: { sessionId: string; userText: string }): string {
|
|
const userTime = new Date()
|
|
const assistantTime = new Date(userTime.getTime() + 2_000)
|
|
const lines = [
|
|
{
|
|
sessionId: args.sessionId,
|
|
uuid: `${args.sessionId}-user`,
|
|
timestamp: userTime.toISOString(),
|
|
type: 'user',
|
|
message: { role: 'user', content: [{ type: 'text', text: args.userText }] }
|
|
},
|
|
{
|
|
sessionId: args.sessionId,
|
|
uuid: `${args.sessionId}-assistant`,
|
|
timestamp: assistantTime.toISOString(),
|
|
type: 'assistant',
|
|
message: {
|
|
model: 'claude-opus-4',
|
|
content: [
|
|
{ type: 'text', text: 'Before I reformat the file I need one decision from you.' },
|
|
{
|
|
type: 'tool_use',
|
|
name: 'AskUserQuestion',
|
|
input: {
|
|
questions: [
|
|
{
|
|
question: QUESTION,
|
|
header: 'Style',
|
|
multiSelect: false,
|
|
options: [{ label: 'Tabs' }, { label: 'Spaces' }]
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
return `${lines.map((line) => JSON.stringify(line)).join('\n')}\n`
|
|
}
|
|
|
|
test.describe('Desktop chat AskUserQuestion card (#11761)', () => {
|
|
test('renders the answerable question card from the transcript when live status carries no ask', async ({
|
|
orcaPage
|
|
}) => {
|
|
await waitForSessionReady(orcaPage)
|
|
await waitForActiveWorktree(orcaPage)
|
|
await ensureTerminalVisible(orcaPage)
|
|
await waitForActiveTerminalManager(orcaPage, 30_000)
|
|
|
|
const descriptor = await waitForActivePaneHookDescriptor(orcaPage)
|
|
const [tabId] = descriptor.paneKey.split(':')
|
|
const sessionId = `e2e-ask-card-${randomUUID()}`
|
|
|
|
const scratchDir = mkdtempSync(path.join(os.tmpdir(), 'orca-e2e-ask-card-'))
|
|
const transcriptPath = path.join(scratchDir, `${sessionId}.jsonl`)
|
|
const screenshotDir = path.join(process.cwd(), 'validation-screenshots', 'ask-user-question')
|
|
mkdirSync(screenshotDir, { recursive: true })
|
|
|
|
try {
|
|
const userText = 'Reformat the config file for me'
|
|
writeFileSync(transcriptPath, pendingAskTranscript({ sessionId, userText }))
|
|
|
|
await enableNativeChatSetting(orcaPage)
|
|
await seedStatusWithoutAskPayload(orcaPage, {
|
|
paneKey: descriptor.paneKey,
|
|
worktreeId: descriptor.worktreeId,
|
|
sessionId,
|
|
transcriptPath
|
|
})
|
|
await toggleTerminalTabToChatView(orcaPage, { tabId, worktreeId: descriptor.worktreeId })
|
|
|
|
await expect(orcaPage.locator('[data-native-chat-root="true"]')).toBeVisible({
|
|
timeout: 15_000
|
|
})
|
|
await expect(orcaPage.getByText(userText)).toBeVisible({ timeout: 30_000 })
|
|
|
|
// The pre-fix build leaves the composer mounted here and never renders a
|
|
// card, so this assertion is what actually gates the regression.
|
|
await expect(orcaPage.getByText(QUESTION)).toBeVisible({ timeout: 10_000 })
|
|
await expect(orcaPage.getByRole('button', { name: /Spaces/ })).toBeVisible()
|
|
await orcaPage.screenshot({ path: path.join(screenshotDir, '01-question-card.png') })
|
|
|
|
// The submit button reads "Skip" until an option is chosen; picking one is
|
|
// what proves the card is answerable rather than merely rendered.
|
|
await orcaPage.getByRole('button', { name: /Spaces/ }).click()
|
|
await expect(orcaPage.getByRole('button', { name: 'Submit' })).toBeVisible()
|
|
await orcaPage.screenshot({ path: path.join(screenshotDir, '02-option-selected.png') })
|
|
|
|
await orcaPage.getByRole('button', { name: 'Submit' }).click()
|
|
// The card owns the composer slot, so its disappearance is the visible
|
|
// signal that the answer was accepted and chat input came back.
|
|
await expect(orcaPage.getByText(QUESTION)).toHaveCount(0, { timeout: 20_000 })
|
|
await orcaPage.screenshot({ path: path.join(screenshotDir, '03-answered.png') })
|
|
} finally {
|
|
rmSync(scratchDir, { recursive: true, force: true })
|
|
}
|
|
})
|
|
})
|