mirror of
https://github.com/stablyai/orca.git
synced 2026-09-23 08:02:31 +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.
228 lines
7.1 KiB
TypeScript
228 lines
7.1 KiB
TypeScript
import { randomUUID } from 'node:crypto'
|
|
import type { ElectronApplication, Page } from '@stablyai/playwright-test'
|
|
import { test, expect } from './helpers/orca-app'
|
|
import { waitForSessionReady } from './helpers/store'
|
|
import type { GlobalSettings } from '../../src/shared/global-settings-types'
|
|
import { readHookEndpoint } from './helpers/agent-hook-endpoint'
|
|
|
|
type AwakeProbeSnapshot = {
|
|
starts: { type: string; id: number }[]
|
|
stops: { id: number }[]
|
|
activeIds: number[]
|
|
}
|
|
|
|
async function getSettings(page: Page): Promise<GlobalSettings> {
|
|
return page.evaluate(() => window.api.settings.get())
|
|
}
|
|
|
|
async function setKeepAwake(page: Page, enabled: boolean): Promise<void> {
|
|
await page.evaluate(async (enabled) => {
|
|
const nextSettings = await window.api.settings.set({
|
|
keepComputerAwakeWhileAgentsRun: enabled
|
|
})
|
|
window.__store?.setState({ settings: nextSettings as GlobalSettings })
|
|
}, enabled)
|
|
}
|
|
|
|
async function openSettings(page: Page): Promise<void> {
|
|
await page.evaluate(() => {
|
|
window.__store!.getState().openSettingsPage()
|
|
})
|
|
await expect(page.getByPlaceholder('Search settings')).toBeVisible({ timeout: 10_000 })
|
|
}
|
|
|
|
async function dismissTransientAnnouncement(page: Page): Promise<void> {
|
|
// Why: first-run announcements are independent of this setting and can cover
|
|
// the settings pane on fresh CI profiles before the search input is used.
|
|
const maybeLaterButton = page.getByRole('button', { name: 'Maybe Later' })
|
|
const visible = await maybeLaterButton
|
|
.isVisible({
|
|
timeout: 1_000
|
|
})
|
|
.catch(() => false)
|
|
if (visible) {
|
|
await maybeLaterButton.click()
|
|
}
|
|
}
|
|
|
|
async function installPowerSaveBlockerProbe(electronApp: ElectronApplication): Promise<void> {
|
|
await electronApp.evaluate(({ powerSaveBlocker }) => {
|
|
const root = globalThis as typeof globalThis & {
|
|
__orcaAwakePowerProbe?: {
|
|
starts: { type: string; id: number }[]
|
|
stops: { id: number }[]
|
|
originalStart: typeof powerSaveBlocker.start
|
|
originalStop: typeof powerSaveBlocker.stop
|
|
}
|
|
}
|
|
if (root.__orcaAwakePowerProbe) {
|
|
root.__orcaAwakePowerProbe.starts = []
|
|
root.__orcaAwakePowerProbe.stops = []
|
|
return
|
|
}
|
|
|
|
const originalStart = powerSaveBlocker.start.bind(powerSaveBlocker)
|
|
const originalStop = powerSaveBlocker.stop.bind(powerSaveBlocker)
|
|
root.__orcaAwakePowerProbe = {
|
|
starts: [],
|
|
stops: [],
|
|
originalStart,
|
|
originalStop
|
|
}
|
|
|
|
powerSaveBlocker.start = ((type) => {
|
|
const id = originalStart(type)
|
|
root.__orcaAwakePowerProbe?.starts.push({ type, id })
|
|
return id
|
|
}) as typeof powerSaveBlocker.start
|
|
|
|
powerSaveBlocker.stop = ((id) => {
|
|
root.__orcaAwakePowerProbe?.stops.push({ id })
|
|
originalStop(id)
|
|
}) as typeof powerSaveBlocker.stop
|
|
})
|
|
}
|
|
|
|
async function readPowerSaveBlockerProbe(
|
|
electronApp: ElectronApplication
|
|
): Promise<AwakeProbeSnapshot> {
|
|
return electronApp.evaluate(({ powerSaveBlocker }) => {
|
|
const probe = (
|
|
globalThis as typeof globalThis & {
|
|
__orcaAwakePowerProbe?: {
|
|
starts: { type: string; id: number }[]
|
|
stops: { id: number }[]
|
|
}
|
|
}
|
|
).__orcaAwakePowerProbe
|
|
const starts = probe?.starts ?? []
|
|
return {
|
|
starts: starts.map((start) => ({ ...start })),
|
|
stops: (probe?.stops ?? []).map((stop) => ({ ...stop })),
|
|
activeIds: starts.map((start) => start.id).filter((id) => powerSaveBlocker.isStarted(id))
|
|
}
|
|
})
|
|
}
|
|
|
|
async function postCodexHookEvent(
|
|
electronApp: ElectronApplication,
|
|
options: {
|
|
paneKey: string
|
|
tabId: string
|
|
eventName: 'UserPromptSubmit' | 'Stop'
|
|
}
|
|
): Promise<void> {
|
|
const endpoint = await readHookEndpoint(electronApp)
|
|
const response = await fetch(`http://127.0.0.1:${endpoint.port}/hook/codex`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'X-Orca-Agent-Hook-Token': endpoint.token
|
|
},
|
|
body: JSON.stringify({
|
|
paneKey: options.paneKey,
|
|
tabId: options.tabId,
|
|
worktreeId: 'e2e-awake-worktree',
|
|
env: endpoint.env,
|
|
version: endpoint.version,
|
|
payload: {
|
|
hook_event_name: options.eventName,
|
|
prompt: 'e2e keep-awake prompt'
|
|
}
|
|
})
|
|
})
|
|
expect(response.status).toBe(204)
|
|
}
|
|
|
|
test.describe('Agent awake setting', () => {
|
|
test.beforeEach(async ({ orcaPage }) => {
|
|
await waitForSessionReady(orcaPage)
|
|
})
|
|
|
|
test('can be changed from Agents settings and persists through IPC', async ({ orcaPage }) => {
|
|
await openSettings(orcaPage)
|
|
await dismissTransientAnnouncement(orcaPage)
|
|
await orcaPage.getByPlaceholder('Search settings').fill('awake')
|
|
|
|
await expect(orcaPage.getByText('Keep computer awake').first()).toBeVisible()
|
|
|
|
const keepAwakeModes = orcaPage.getByRole('radiogroup', {
|
|
name: 'Keep computer awake'
|
|
})
|
|
const offMode = keepAwakeModes.getByRole('radio', { name: 'Off' })
|
|
const agentMode = keepAwakeModes.getByRole('radio', { name: 'Agent' })
|
|
|
|
await expect(offMode).toHaveAttribute('aria-checked', 'true')
|
|
await agentMode.click()
|
|
await expect(agentMode).toHaveAttribute('aria-checked', 'true')
|
|
await expect
|
|
.poll(async () => (await getSettings(orcaPage)).computerAwakeMode, {
|
|
timeout: 5_000,
|
|
message: 'keep-awake mode did not persist after selecting Agent'
|
|
})
|
|
.toBe('auto')
|
|
|
|
await offMode.click()
|
|
await expect(offMode).toHaveAttribute('aria-checked', 'true')
|
|
await expect
|
|
.poll(async () => (await getSettings(orcaPage)).computerAwakeMode, {
|
|
timeout: 5_000,
|
|
message: 'keep-awake mode did not persist after selecting Off'
|
|
})
|
|
.toBe('off')
|
|
})
|
|
|
|
test('keeps the OS awake only while a hook-reported agent is working', async ({
|
|
electronApp,
|
|
orcaPage
|
|
}) => {
|
|
await installPowerSaveBlockerProbe(electronApp)
|
|
await setKeepAwake(orcaPage, true)
|
|
|
|
const tabId = 'e2e-awake-tab'
|
|
const paneKey = `${tabId}:${randomUUID()}`
|
|
await postCodexHookEvent(electronApp, {
|
|
paneKey,
|
|
tabId,
|
|
eventName: 'UserPromptSubmit'
|
|
})
|
|
|
|
await expect
|
|
.poll(async () => await readPowerSaveBlockerProbe(electronApp), {
|
|
timeout: 5_000,
|
|
message: 'powerSaveBlocker did not start for the working agent'
|
|
})
|
|
.toEqual(
|
|
expect.objectContaining({
|
|
activeIds: expect.arrayContaining([expect.any(Number)]),
|
|
starts: expect.arrayContaining([
|
|
expect.objectContaining({ type: 'prevent-display-sleep' })
|
|
])
|
|
})
|
|
)
|
|
|
|
const startedIds = (await readPowerSaveBlockerProbe(electronApp)).starts.map(
|
|
(start) => start.id
|
|
)
|
|
expect(startedIds.length).toBeGreaterThan(0)
|
|
|
|
await postCodexHookEvent(electronApp, {
|
|
paneKey,
|
|
tabId,
|
|
eventName: 'Stop'
|
|
})
|
|
|
|
await expect
|
|
.poll(async () => await readPowerSaveBlockerProbe(electronApp), {
|
|
timeout: 5_000,
|
|
message: 'powerSaveBlocker stayed active after the agent stopped'
|
|
})
|
|
.toEqual(
|
|
expect.objectContaining({
|
|
activeIds: [],
|
|
stops: expect.arrayContaining(startedIds.map((id) => expect.objectContaining({ id })))
|
|
})
|
|
)
|
|
})
|
|
})
|