mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 03:15:01 +00:00
test: remove low-value extension settings and config samples (#42495)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -62,12 +62,10 @@
|
||||
"config/scripts/ci/workflow-contracts/cloud-security-history-workflow.test.mjs": 357,
|
||||
"config/scripts/runtime-verification/codex-account/codex-primary-home-tripwire.test.ts": 378,
|
||||
"config/scripts/orcad-distribution/template/compact-packaged-orcad-ripgrep.test.mjs": 1153,
|
||||
"config/scripts/daemon-protocol/schema-facts/daemon-protocol-facts.test.mjs": 59,
|
||||
"config/scripts/desktop-build/output-contracts/dark-build-switches.test.mjs": 52,
|
||||
"config/scripts/dependency-security/audit-tools/dependency-security-audit.test.mjs": 187,
|
||||
"config/scripts/dependency-security/audit-tools/dependency-security-patches.test.mjs": 50,
|
||||
"config/scripts/dependency-security/audit-tools/dependency-security-release.test.mjs": 311,
|
||||
"config/scripts/release/versioning/dev-channel-base-version.test.mjs": 61,
|
||||
"config/scripts/desktop-distribution/channel-policy/dev-channel-windows-staging.test.mjs": 211,
|
||||
"config/scripts/development/electron-bundle-cache/dev-electron-bundle-identity.test.ts": 53,
|
||||
"config/scripts/development/profile-seeding/dev-profile-seed.test.mjs": 294,
|
||||
@@ -91,7 +89,6 @@
|
||||
"config/scripts/diagnostics/lag-capture/lag-probe-failures.test.mjs": 55,
|
||||
"config/scripts/dependency-security/runtime-resolution/linear-sdk-runtime.test.mjs": 773,
|
||||
"config/scripts/preflight/changed-checks/lint-staged-worktree-backup.test.mjs": 278,
|
||||
"config/scripts/locale-catalog/locale-repair-catalog-missing-leaves.test.mjs": 159,
|
||||
"config/scripts/localization/source-extraction/localization-extraction-call-syntax.test.mjs": 317,
|
||||
"config/scripts/localization/extraction-policy/localization-extraction-change-scope.test.mjs": 732,
|
||||
"config/scripts/performance/macos-computer-owner/macos-computer-helper-owner-loss-processes.test.mjs": 52,
|
||||
@@ -121,7 +118,6 @@
|
||||
"config/scripts/mobile-web-app/routing/mobile-web-app-push-subsystem-closure.test.mjs": 57,
|
||||
"config/scripts/mobile-web-app/shell/mobile-web-app-render.test.mjs": 254,
|
||||
"config/scripts/mobile-web-app/session/mobile-web-app-rich-markdown-render.test.mjs": 356,
|
||||
"config/scripts/mobile-web-app/mobile-web-app-route-manifest.test.mjs": 174,
|
||||
"config/scripts/mobile-web-app/shell/mobile-web-app-safe-area-render.test.mjs": 314,
|
||||
"config/scripts/mobile-web-app/session/mobile-web-app-screencast-lane-grant.test.mjs": 70,
|
||||
"config/scripts/mobile-web-app/session/mobile-web-app-session-dictation-capture.test.mjs": 123,
|
||||
@@ -315,7 +311,6 @@
|
||||
"src/cli/handlers/orchestration/worker-start-implicit-coordinator.test.ts": 522,
|
||||
"src/cli/handlers/plugin-dev-watch.test.ts": 942,
|
||||
"src/cli/handlers/plugin-shot-chrome.test.ts": 378,
|
||||
"src/cli/handlers/plugin-shot-default-dir.test.ts": 60,
|
||||
"src/cli/handlers/plugin-shot-editor.test.ts": 440,
|
||||
"src/cli/handlers/plugin-shot-scenario.test.ts": 630,
|
||||
"src/cli/handlers/plugin-view.test.ts": 474,
|
||||
@@ -361,7 +356,6 @@
|
||||
"src/cli/plugin-dev-watch/plugin-dev-watch-loop.test.ts": 543,
|
||||
"src/cli/plugin-dev-watch/plugin-dev-watch-process.test.ts": 69,
|
||||
"src/cli/plugin-dev-watch/plugin-dev-watch-shot.test.ts": 529,
|
||||
"src/cli/plugin-dev-watch/plugin-frame-log-dedupe.test.ts": 339,
|
||||
"src/cli/runtime-client-deferral.test.ts": 1276,
|
||||
"src/cli/runtime-client.test.ts": 633,
|
||||
"src/cli/runtime/client-execution-host.test.ts": 432,
|
||||
@@ -393,7 +387,6 @@
|
||||
"src/cli/runtime/types.test.ts": 62,
|
||||
"src/cli/runtime/websocket-transport.test.ts": 707,
|
||||
"src/cli/serve-electron-flag-parity.test.ts": 79,
|
||||
"src/cli/skills-cli-agent-aliases.test.ts": 70,
|
||||
"src/cli/skills-install.test.ts": 1765,
|
||||
"src/cli/skills-reference-selector.test.ts": 528,
|
||||
"src/cli/skills.test.ts": 386,
|
||||
@@ -886,11 +879,9 @@
|
||||
"src/main/browser/extensions/api/notifications.test.ts": 231,
|
||||
"src/main/browser/extensions/api/tabs-capture.test.ts": 330,
|
||||
"src/main/browser/extensions/api/web-navigation.test.ts": 113,
|
||||
"src/main/browser/extensions/actions/browser-extension-action-icon.test.ts": 62,
|
||||
"src/main/browser/extensions/api-runtime/browser-extension-api-host.test.ts": 894,
|
||||
"src/main/browser/extensions/api/browser-extension-api-namespaces.test.ts": 832,
|
||||
"src/main/browser/extensions/context-menus/browser-extension-context-menu-host.test.ts": 68,
|
||||
"src/main/browser/extensions/context-menus/browser-extension-context-menu-model.test.ts": 57,
|
||||
"src/main/browser/extensions/installation/browser-extension-crx.test.ts": 214,
|
||||
"src/main/browser/extensions/profile-storage/browser-extension-data-removal.test.ts": 427,
|
||||
"src/main/browser/extensions/tabs-and-windows/browser-extension-discarded-tabs.test.ts": 379,
|
||||
@@ -898,7 +889,6 @@
|
||||
"src/main/browser/extensions/declarative-net-request/session/browser-extension-dnr-matched-rules.test.ts": 45,
|
||||
"src/main/browser/extensions/declarative-net-request/session/browser-extension-dnr-requests.test.ts": 655,
|
||||
"src/main/browser/extensions/permissions/browser-extension-install-prompt.test.ts": 233,
|
||||
"src/main/browser/extensions/installation/browser-extension-install-store.test.ts": 276,
|
||||
"src/main/browser/extensions/installation/browser-extension-load-directory.test.ts": 315,
|
||||
"src/main/browser/extensions/permissions/browser-extension-match-pattern.test.ts": 40,
|
||||
"src/main/browser/extensions/native-messaging/browser-extension-native-host-framing.test.ts": 49,
|
||||
@@ -909,7 +899,6 @@
|
||||
"src/main/browser/extensions/native-messaging/browser-extension-native-ports.test.ts": 395,
|
||||
"src/main/browser/extensions/permissions/browser-extension-permission-grants.test.ts": 43,
|
||||
"src/main/browser/extensions/permissions/browser-extension-permission-summary.test.ts": 44,
|
||||
"src/main/browser/extensions/profile-sessions/browser-extension-profile-reload.test.ts": 51,
|
||||
"src/main/browser/extensions/profile-storage/browser-extension-profile-state-store.test.ts": 119,
|
||||
"src/main/browser/extensions/permissions/browser-extension-request-host-access.test.ts": 87,
|
||||
"src/main/browser/extensions/profile-sessions/browser-extension-session-loader.test.ts": 560,
|
||||
@@ -917,11 +906,9 @@
|
||||
"src/main/browser/extensions/permissions/browser-extension-settings-prompt-lifetime.test.ts": 661,
|
||||
"src/main/browser/extensions/profile-storage/browser-extension-sync-storage-store.test.ts": 264,
|
||||
"src/main/browser/extensions/tabs-and-windows/browser-extension-tab-model.test.ts": 324,
|
||||
"src/main/browser/extensions/tabs-and-windows/browser-extension-tab-query.test.ts": 48,
|
||||
"src/main/browser/extensions/tabs-and-windows/browser-extension-tab-resolution.test.ts": 320,
|
||||
"src/main/browser/extensions/web-store/browser-extension-webstore-bridge-host.test.ts": 258,
|
||||
"src/main/browser/extensions/web-store/browser-extension-webstore-download.test.ts": 64,
|
||||
"src/main/browser/extensions/web-store/browser-extension-webstore-install-flow.test.ts": 290,
|
||||
"src/main/browser/extensions/installation/browser-extension-webstore-install.test.ts": 717,
|
||||
"src/main/browser/extensions/web-store/browser-extension-webstore-redirects.test.ts": 101,
|
||||
"src/main/browser/extensions/web-store/browser-extension-webstore-updater.test.ts": 239,
|
||||
@@ -929,7 +916,6 @@
|
||||
"src/main/browser/extensions/api-runtime/browser-extension-worker-api-host.test.ts": 237,
|
||||
"src/main/browser/extensions/declarative-net-request/engine-stages.test.ts": 112,
|
||||
"src/main/browser/extensions/declarative-net-request/engine.test.ts": 145,
|
||||
"src/main/browser/extensions/declarative-net-request/redirect-actions/redirect-url.test.ts": 66,
|
||||
"src/main/browser/extensions/declarative-net-request/regex/regex-filter.test.ts": 116,
|
||||
"src/main/browser/element-grab/grab-guest-overlay-follow.test.ts": 332,
|
||||
"src/main/browser/element-grab/grab-guest-script.test.ts": 107,
|
||||
@@ -4750,7 +4736,6 @@
|
||||
"src/renderer/src/components/settings/virtual-machines/recipes/EphemeralVmsPane.test.tsx": 1025,
|
||||
"src/renderer/src/components/settings/accounts/sign-in/HostAccountSignInPrompt.test.tsx": 309,
|
||||
"src/renderer/src/components/settings/agents/launch/HostAgentLaunchSettings.test.tsx": 7498,
|
||||
"src/renderer/src/components/settings/developer-permissions/LocalNetworkConnectionTest.test.tsx": 592,
|
||||
"src/renderer/src/components/machine-identity/MachineNameField.test.tsx": 557,
|
||||
"src/renderer/src/components/settings/mobile/pairing/MobilePairingQrSection.test.tsx": 397,
|
||||
"src/renderer/src/components/settings/mobile/MobilePane.test.tsx": 1581,
|
||||
@@ -4791,7 +4776,6 @@
|
||||
"src/renderer/src/components/settings/form-controls/use-debounced-settings-text-draft.test.ts": 308,
|
||||
"src/renderer/src/components/settings/repository/hooks/use-repository-hook-settings-draft.test.tsx": 586,
|
||||
"src/renderer/src/components/settings/repository/hooks/use-repository-issue-command-wsl-stopped.test.ts": 523,
|
||||
"src/renderer/src/components/settings/runtime-environments/catalog/use-runtime-environment-catalog.test.tsx": 2252,
|
||||
"src/renderer/src/components/session-search/use-session-search-status.test.tsx": 477,
|
||||
"src/renderer/src/components/settings/accounts/usage/use-zcode-plan-credentials.test.tsx": 880,
|
||||
"src/renderer/src/components/shared/kill-all-terminal-surfaces.test.ts": 1925,
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parseDaemonProtocolFacts } from './daemon-protocol-facts.mjs'
|
||||
|
||||
const facts = (protocolVersion, previousProtocolVersions) => ({
|
||||
protocolVersion,
|
||||
previousProtocolVersions
|
||||
})
|
||||
|
||||
describe('parseDaemonProtocolFacts', () => {
|
||||
it('parses multi-line lists and type annotations', () => {
|
||||
const text = [
|
||||
'// PROTOCOL_VERSION = 99 in a comment is ignored',
|
||||
'export const PROTOCOL_VERSION: number = 4',
|
||||
'export const PREVIOUS_DAEMON_PROTOCOL_VERSIONS: readonly number[] = [',
|
||||
' 1, 2,',
|
||||
' 3,',
|
||||
']'
|
||||
].join('\n')
|
||||
expect(parseDaemonProtocolFacts(text)).toEqual(facts(4, [1, 2, 3]))
|
||||
})
|
||||
|
||||
it('rejects a non-literal protocol declaration with its source label', () => {
|
||||
const text =
|
||||
'export const PROTOCOL_VERSION = NEXT_VERSION\nexport const PREVIOUS_DAEMON_PROTOCOL_VERSIONS = [1] as const'
|
||||
expect(() => parseDaemonProtocolFacts(text, 'fixture.ts')).toThrow(/fixture\.ts/)
|
||||
})
|
||||
})
|
||||
@@ -1,21 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { repairCatalog } from './locale-translation-policy.mjs'
|
||||
|
||||
// English keys can precede locale bootstrapping; missing leaves must not crash the entire repair.
|
||||
describe('repairCatalog with un-bootstrapped keys', () => {
|
||||
const enCatalog = {
|
||||
auto: {
|
||||
lib: { agent: { catalog: { '760bc6883d': 'Codex' } } },
|
||||
components: { untranslated: 'Continue', nested: { alsoMissing: 'Refresh' } }
|
||||
}
|
||||
}
|
||||
|
||||
const translatedOnly = () => ({ auto: { lib: { agent: { catalog: { '760bc6883d': '사본' } } } } })
|
||||
|
||||
it('skips leaves the locale catalog is missing instead of throwing', () => {
|
||||
const localeCatalog = translatedOnly()
|
||||
expect(() => repairCatalog(enCatalog, localeCatalog, 'ko')).not.toThrow()
|
||||
expect(localeCatalog.auto.components).toBeUndefined()
|
||||
})
|
||||
})
|
||||
@@ -1,35 +0,0 @@
|
||||
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
MOBILE_WEB_APP_ROUTE_ROOT,
|
||||
collectMobileWebAppRoutes
|
||||
} from './mobile-web-app-route-manifest.mjs'
|
||||
|
||||
async function withScratch(run) {
|
||||
const scratch = await mkdtemp(join(tmpdir(), 'orca-mobile-web-app-routes-test-'))
|
||||
try {
|
||||
return await run(scratch)
|
||||
} finally {
|
||||
await rm(scratch, { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
|
||||
describe('route manifest', () => {
|
||||
it('imports a .web.tsx sibling under the native route key', async () => {
|
||||
await withScratch(async (scratch) => {
|
||||
const directory = join(scratch, MOBILE_WEB_APP_ROUTE_ROOT)
|
||||
await mkdir(directory, { recursive: true })
|
||||
await writeFile(join(directory, 'index.tsx'), 'export default function Route() {}\n')
|
||||
expect(await collectMobileWebAppRoutes(scratch)).toEqual([
|
||||
{ key: './h/index.tsx', module: join(directory, 'index.tsx') }
|
||||
])
|
||||
await writeFile(join(directory, 'index.web.tsx'), 'export default function Route() {}\n')
|
||||
// Preserve native key so web override changes implementation without changing URL.
|
||||
expect(await collectMobileWebAppRoutes(scratch)).toEqual([
|
||||
{ key: './h/index.tsx', module: join(directory, 'index.web.tsx') }
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,15 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { resolveDevChannelBaseVersion } from './dev-channel-base-version.mjs'
|
||||
|
||||
describe('dev channel base version', () => {
|
||||
// Deleted v1.4.202 release once reset hourlies below installed 1.4.203; channel tags retain the floor.
|
||||
it('does not drop below an already-published channel version', () => {
|
||||
expect(
|
||||
resolveDevChannelBaseVersion('1.4.197', [
|
||||
'v1.4.201',
|
||||
'v1.4.202-hourly.202609141912',
|
||||
'v1.4.203-hourly.202609140417'
|
||||
])
|
||||
).toBe('1.4.203')
|
||||
})
|
||||
})
|
||||
@@ -1,22 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { PluginFrameLogDedupe } from './plugin-frame-log-dedupe'
|
||||
|
||||
const line = (ts: number, text: string, level = 'warn') => ({ ts, level, line: text })
|
||||
const KEY_WARNING = '[frame] Each child in a list should have a unique "key"'
|
||||
|
||||
describe('PluginFrameLogDedupe', () => {
|
||||
it('prints a repeated panel line once per reload with its count, then the later copies', () => {
|
||||
const dedupe = new PluginFrameLogDedupe()
|
||||
expect(
|
||||
dedupe.take([line(1, KEY_WARNING), line(2, 'worker tick', 'info'), line(3, KEY_WARNING)])
|
||||
).toEqual([{ ...line(1, KEY_WARNING), count: 2 }, line(2, 'worker tick', 'info')])
|
||||
// Worker lines are never folded; the panel line already printed this reload is only counted.
|
||||
expect(
|
||||
dedupe.take([line(4, KEY_WARNING), line(5, 'worker tick', 'info'), line(6, KEY_WARNING)])
|
||||
).toEqual([line(5, 'worker tick', 'info')])
|
||||
expect(dedupe.flush()).toEqual([{ ...line(6, KEY_WARNING), count: 2, repeat: true }])
|
||||
// A new reload prints it again.
|
||||
expect(dedupe.take([line(7, KEY_WARNING)])).toEqual([line(7, KEY_WARNING)])
|
||||
expect(dedupe.flush()).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -1,21 +0,0 @@
|
||||
import { join } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { defaultPluginShotsDir, enclosingPluginFolder } from './plugin-shot-default-dir'
|
||||
|
||||
const ROOT = join('/', 'work', 'repo')
|
||||
|
||||
function filesystem(...paths: string[]): (path: string) => boolean {
|
||||
const present = new Set(paths)
|
||||
return (path) => present.has(path)
|
||||
}
|
||||
|
||||
describe('plugin shot default folder', () => {
|
||||
it('keeps <cwd>/.orca/shots elsewhere, and never looks above the repository root', () => {
|
||||
const exists = filesystem(join('/', 'work', 'orca-plugin.json'), join(ROOT, '.git'))
|
||||
expect(enclosingPluginFolder(join(ROOT, 'docs'), exists)).toBeNull()
|
||||
expect(defaultPluginShotsDir(join(ROOT, 'docs'), exists)).toBe(
|
||||
join(ROOT, 'docs', '.orca', 'shots')
|
||||
)
|
||||
expect(enclosingPluginFolder(join('/', 'tmp'), filesystem())).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -1,27 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { SKILLS_CLI_AGENT_KEY_BY_TUI_AGENT } from '../../shared/skills-cli-agent-keys'
|
||||
import { skillsCliAgentAliases } from './skills-cli-agent-aliases'
|
||||
|
||||
describe('skills CLI agent aliases', () => {
|
||||
it('resolves shipped collisions canonically regardless of table order', () => {
|
||||
for (const entries of [
|
||||
Object.entries(SKILLS_CLI_AGENT_KEY_BY_TUI_AGENT),
|
||||
Object.entries(SKILLS_CLI_AGENT_KEY_BY_TUI_AGENT).toReversed()
|
||||
]) {
|
||||
const aliases = skillsCliAgentAliases(Object.fromEntries(entries))
|
||||
|
||||
expect(aliases.get('claude-code')).toBe('claude')
|
||||
expect(aliases.get('opencode')).toBe('opencode')
|
||||
expect(aliases.get('gemini-cli')).toBe('gemini')
|
||||
}
|
||||
})
|
||||
|
||||
it.each(['new-key', 'codex'])(
|
||||
'rejects a new collision for %s without a canonical choice',
|
||||
(key) => {
|
||||
expect(() => skillsCliAgentAliases({ claude: key, codex: key })).toThrow(
|
||||
`Skills CLI agent key "${key}" needs an explicit canonical provider.`
|
||||
)
|
||||
}
|
||||
)
|
||||
})
|
||||
@@ -1,68 +0,0 @@
|
||||
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { inflateSync } from 'node:zlib'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import {
|
||||
encodeRgbaPng,
|
||||
iconFromImageData,
|
||||
resolveActionIconDataUrl
|
||||
} from './browser-extension-action-icon'
|
||||
|
||||
/** Reads back the RGBA rows of a PNG made by encodeRgbaPng (one IDAT, filter 0 rows). */
|
||||
function decodePng(png: Buffer): { width: number; height: number; rgba: number[] } {
|
||||
expect(png.subarray(0, 8)).toEqual(Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))
|
||||
const width = png.readUInt32BE(16)
|
||||
const height = png.readUInt32BE(20)
|
||||
const idatStart = png.indexOf('IDAT') + 4
|
||||
const idatLength = png.readUInt32BE(idatStart - 8)
|
||||
const raw = inflateSync(png.subarray(idatStart, idatStart + idatLength))
|
||||
const rgba: number[] = []
|
||||
for (let y = 0; y < height; y++) {
|
||||
const row = raw.subarray(y * (width * 4 + 1), (y + 1) * (width * 4 + 1))
|
||||
expect(row[0]).toBe(0)
|
||||
rgba.push(...row.subarray(1))
|
||||
}
|
||||
return { width, height, rgba }
|
||||
}
|
||||
|
||||
describe('action icons', () => {
|
||||
it('encodes ImageData pixels as a PNG without changing them', () => {
|
||||
const rgba = [255, 0, 0, 255, 0, 255, 0, 128, 0, 0, 255, 0, 10, 20, 30, 40]
|
||||
expect(decodePng(encodeRgbaPng(2, 2, rgba))).toEqual({ width: 2, height: 2, rgba })
|
||||
})
|
||||
|
||||
it('keeps the smallest ImageData that still covers the toolbar at 2x', () => {
|
||||
const image = (side: number): { width: number; height: number; data: number[] } => ({
|
||||
width: side,
|
||||
height: side,
|
||||
data: Array.from({ length: side * side * 4 }, () => side)
|
||||
})
|
||||
const icon = iconFromImageData({ 16: image(16), 32: image(32), 64: image(64) })
|
||||
expect(icon?.kind).toBe('data')
|
||||
const dataUrl = icon?.kind === 'data' ? icon.dataUrl : ''
|
||||
const decoded = decodePng(Buffer.from(dataUrl.replace('data:image/png;base64,', ''), 'base64'))
|
||||
expect(decoded.width).toBe(32)
|
||||
expect(iconFromImageData({ width: 2, height: 2, data: [1, 2, 3] })).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('resolveActionIconDataUrl', () => {
|
||||
let root: string
|
||||
beforeEach(() => {
|
||||
root = mkdtempSync(join(tmpdir(), 'orca-action-icon-'))
|
||||
})
|
||||
afterEach(() => {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
it('serves the extension file as a data URL and never reads outside the extension', async () => {
|
||||
writeFileSync(join(root, 'icon32.png'), Buffer.from([1, 2, 3]))
|
||||
await expect(
|
||||
resolveActionIconDataUrl(root, { kind: 'path', paths: { 16: 'x.png', 32: '/icon32.png' } })
|
||||
).resolves.toBe('data:image/png;base64,AQID')
|
||||
await expect(
|
||||
resolveActionIconDataUrl(root, { kind: 'path', paths: { 32: '../outside.png' } })
|
||||
).resolves.toBeNull()
|
||||
})
|
||||
})
|
||||
-139
@@ -1,139 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
applyContextMenuClick,
|
||||
createContextMenuItem,
|
||||
removeContextMenuItem,
|
||||
updateContextMenuItem
|
||||
} from './browser-extension-context-menu-model'
|
||||
import {
|
||||
contextMenuTargetFromParams,
|
||||
visibleContextMenuTree
|
||||
} from './browser-extension-context-menu-target'
|
||||
import type { StoredContextMenuItem } from '../profile-storage/browser-extension-profile-state-store'
|
||||
|
||||
function build(...items: Parameters<typeof createContextMenuItem>[1][]): StoredContextMenuItem[] {
|
||||
return items.reduce<StoredContextMenuItem[]>(createContextMenuItem, [])
|
||||
}
|
||||
|
||||
const pageClick = contextMenuTargetFromParams({}, 'https://site.test/', false)
|
||||
|
||||
describe('menu item bookkeeping', () => {
|
||||
it('rejects duplicate ids, unknown parents and descendant cycles like Chrome', () => {
|
||||
const items = build(
|
||||
{ id: 'root', title: 'Root' },
|
||||
{ id: 'child', title: 'Child', parentId: 'root' }
|
||||
)
|
||||
expect(() => createContextMenuItem(items, { id: 'root', title: 'Again' })).toThrow(
|
||||
'Cannot create item with duplicate id root'
|
||||
)
|
||||
expect(() => createContextMenuItem(items, { id: 'x', title: 'X', parentId: 'nope' })).toThrow(
|
||||
'Cannot find menu item with id nope'
|
||||
)
|
||||
expect(() => updateContextMenuItem(items, 'root', { parentId: 'child' })).toThrow(
|
||||
'Cannot set an item to be a descendant of itself'
|
||||
)
|
||||
expect(() => removeContextMenuItem(items, 7)).toThrow('Cannot find menu item with id 7')
|
||||
})
|
||||
|
||||
it('removes descendants with their parent and keeps number and string ids apart', () => {
|
||||
const items = build(
|
||||
{ id: 1, title: 'One' },
|
||||
{ id: '1', title: 'String one' },
|
||||
{ id: 'leaf', title: 'Leaf', parentId: 1 }
|
||||
)
|
||||
expect(removeContextMenuItem(items, 1).map((item) => item.id)).toEqual(['1'])
|
||||
})
|
||||
|
||||
it('keeps exactly one checked radio per adjacent run', () => {
|
||||
const items = build(
|
||||
{ id: 'a', title: 'A', type: 'radio' },
|
||||
{ id: 'b', title: 'B', type: 'radio', checked: true },
|
||||
{ id: 'sep', type: 'separator' },
|
||||
{ id: 'c', title: 'C', type: 'radio' }
|
||||
)
|
||||
expect(items.map((item) => [item.id, item.checked])).toEqual([
|
||||
['a', false],
|
||||
['b', true],
|
||||
['sep', undefined],
|
||||
['c', true]
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('what a right-click shows', () => {
|
||||
const items = build(
|
||||
{ id: 'page', title: 'On page' },
|
||||
{ id: 'edit', title: 'Fill "%s"', contexts: ['editable', 'selection'] },
|
||||
{ id: 'img', title: 'Image', contexts: ['image'], targetUrlPatterns: ['https://cdn.test/*'] },
|
||||
{
|
||||
id: 'docs',
|
||||
title: 'Docs only',
|
||||
contexts: ['all'],
|
||||
documentUrlPatterns: ['https://docs.test/*']
|
||||
},
|
||||
{ id: 'hidden', title: 'Hidden', visible: false },
|
||||
{ id: 'toolbar', title: 'Toolbar', contexts: ['action'] }
|
||||
)
|
||||
|
||||
it('applies contexts, document and target patterns, and visibility', () => {
|
||||
expect(visibleContextMenuTree(items, pageClick).map((item) => item.key)).toEqual(['"page"'])
|
||||
const editable = contextMenuTargetFromParams(
|
||||
{ isEditable: true, selectionText: 'hunter2 is the password I use everywhere online today' },
|
||||
'https://site.test/',
|
||||
false
|
||||
)
|
||||
expect(visibleContextMenuTree(items, editable)).toEqual([
|
||||
expect.objectContaining({
|
||||
key: '"edit"',
|
||||
title: 'Fill "hunter2 is the password I use everywhere online to…"'
|
||||
})
|
||||
])
|
||||
const image = (src: string) =>
|
||||
contextMenuTargetFromParams({ mediaType: 'image', srcURL: src }, 'https://docs.test/a', false)
|
||||
expect(
|
||||
visibleContextMenuTree(items, image('https://cdn.test/x.png')).map((i) => i.key)
|
||||
).toEqual(['"img"', '"docs"'])
|
||||
expect(
|
||||
visibleContextMenuTree(items, image('https://other.test/x.png')).map((i) => i.key)
|
||||
).toEqual(['"docs"'])
|
||||
})
|
||||
|
||||
it('matches a frame click against the frame URL and adds the frame context', () => {
|
||||
const target = contextMenuTargetFromParams(
|
||||
{ frameURL: 'https://docs.test/embed' },
|
||||
'https://site.test/',
|
||||
true
|
||||
)
|
||||
expect([...target.contexts]).toEqual(['page', 'frame'])
|
||||
expect(visibleContextMenuTree(items, target).map((item) => item.key)).toEqual([
|
||||
'"page"',
|
||||
'"docs"'
|
||||
])
|
||||
})
|
||||
|
||||
it('drops a parent whose children are all filtered out', () => {
|
||||
const nested = build(
|
||||
{ id: 'parent', title: 'Parent', contexts: ['all'] },
|
||||
{ id: 'kid', title: 'Kid', parentId: 'parent', contexts: ['link'] }
|
||||
)
|
||||
expect(visibleContextMenuTree(nested, pageClick)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('clicking an item', () => {
|
||||
it('flips a checkbox and moves the radio selection before onClicked', () => {
|
||||
const items = build(
|
||||
{ id: 'box', title: 'Box', type: 'checkbox' },
|
||||
{ id: 'r1', title: 'R1', type: 'radio' },
|
||||
{ id: 'r2', title: 'R2', type: 'radio' }
|
||||
)
|
||||
const box = applyContextMenuClick(items, items[0])
|
||||
expect([box.wasChecked, box.checked]).toEqual([false, true])
|
||||
const radio = applyContextMenuClick(items, items[2])
|
||||
expect(radio.items.map((item) => [item.id, item.checked])).toEqual([
|
||||
['box', undefined],
|
||||
['r1', false],
|
||||
['r2', true]
|
||||
])
|
||||
})
|
||||
})
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parseDnrRedirect, transformDnrUrl } from './redirect-url'
|
||||
import { isDnrRuleProblem } from '../rule-compilation/parse-errors'
|
||||
import type { DnrUrlTransform } from '../rule-compilation/rule-types'
|
||||
|
||||
function transform(url: string, spec: DnrUrlTransform): string | null {
|
||||
const parsed = parseDnrRedirect({ transform: spec }, 1, 'ext')
|
||||
if (isDnrRuleProblem(parsed) || parsed.kind !== 'transform') {
|
||||
throw new Error('bad transform')
|
||||
}
|
||||
return transformDnrUrl(url, parsed.transform)
|
||||
}
|
||||
|
||||
describe('transformDnrUrl', () => {
|
||||
// GetModifiedQuery: removals and replacements keep the original order; additions go last.
|
||||
it.each<[string, DnrUrlTransform['queryTransform'], string]>([
|
||||
[
|
||||
'http://a.com/?a=1&utm_source=x&b=2',
|
||||
{ removeParams: ['utm_source'] },
|
||||
'http://a.com/?a=1&b=2'
|
||||
],
|
||||
['http://a.com/?utm_source=x', { removeParams: ['utm_source'] }, 'http://a.com/'],
|
||||
[
|
||||
'http://a.com/?a=1&a=2',
|
||||
{ addOrReplaceParams: [{ key: 'a', value: 'z' }] },
|
||||
'http://a.com/?a=z&a=2'
|
||||
],
|
||||
[
|
||||
'http://a.com/?a=1',
|
||||
{ addOrReplaceParams: [{ key: 'b', value: 'c d' }] },
|
||||
'http://a.com/?a=1&b=c+d'
|
||||
],
|
||||
[
|
||||
'http://a.com/?a=1',
|
||||
{ addOrReplaceParams: [{ key: 'b', value: '1', replaceOnly: true }] },
|
||||
'http://a.com/?a=1'
|
||||
],
|
||||
// Chromium writes every surviving pair back as key=value.
|
||||
['http://a.com/?flag&x=1', { removeParams: ['x'] }, 'http://a.com/?flag='],
|
||||
['http://a.com/?a=1&&b=2', { removeParams: ['b'] }, 'http://a.com/?a=1&='],
|
||||
['http://a.com/?a=1', { removeParams: ['zzz'] }, 'http://a.com/?a=1']
|
||||
])('%s with %j → %s', (url, queryTransform, expected) => {
|
||||
expect(transform(url, { queryTransform })).toBe(expected)
|
||||
})
|
||||
})
|
||||
@@ -1,87 +0,0 @@
|
||||
import { existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { InstalledBrowserExtension } from '../../../../shared/browser/extensions/browser-extension-types'
|
||||
|
||||
vi.mock('electron', () => ({ app: { getPath: () => tmpdir() } }))
|
||||
|
||||
const { BrowserExtensionInstallStore } = await import('./browser-extension-install-store')
|
||||
const { readBrowserExtensionIconDataUrl } = await import('./browser-extension-manifest')
|
||||
|
||||
const STORE_ID = 'a'.repeat(32)
|
||||
const UNPACKED_ID = 'b'.repeat(32)
|
||||
let root: string
|
||||
|
||||
function record(overrides: Partial<InstalledBrowserExtension>): InstalledBrowserExtension {
|
||||
return {
|
||||
id: STORE_ID,
|
||||
name: 'Vault',
|
||||
version: '1.2.3',
|
||||
path: '',
|
||||
source: 'webstore',
|
||||
iconPath: null,
|
||||
permissions: [],
|
||||
hostPermissions: [],
|
||||
optionsPage: null,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
root = mkdtempSync(join(tmpdir(), 'orca-browser-extensions-'))
|
||||
})
|
||||
afterEach(() => {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
})
|
||||
|
||||
describe('BrowserExtensionInstallStore', () => {
|
||||
it('deletes the folder of a store install but never an unpacked folder', async () => {
|
||||
const store = new BrowserExtensionInstallStore(join(root, 'browser-extensions'))
|
||||
const storeDir = store.installDirectory(STORE_ID, '1.2.3')
|
||||
const unpackedDir = join(root, 'my-extension')
|
||||
mkdirSync(storeDir, { recursive: true })
|
||||
mkdirSync(unpackedDir, { recursive: true })
|
||||
store.save(record({ path: storeDir }))
|
||||
store.save(record({ id: UNPACKED_ID, path: unpackedDir, source: 'unpacked' }))
|
||||
|
||||
await store.remove(STORE_ID)
|
||||
await store.remove(UNPACKED_ID)
|
||||
|
||||
expect(existsSync(join(root, 'browser-extensions', STORE_ID))).toBe(false)
|
||||
expect(existsSync(unpackedDir)).toBe(true)
|
||||
expect(store.list()).toEqual([])
|
||||
})
|
||||
|
||||
it('persists monotonic install precedence, including legacy records and explicit same-version updates', async () => {
|
||||
writeFileSync(
|
||||
join(root, 'installed.json'),
|
||||
JSON.stringify([record({ id: STORE_ID }), record({ id: UNPACKED_ID })])
|
||||
)
|
||||
const store = new BrowserExtensionInstallStore(root)
|
||||
const older = store.get(STORE_ID)?.installTime
|
||||
const newer = store.get(UNPACKED_ID)?.installTime
|
||||
expect(older).toBeLessThan(newer ?? 0)
|
||||
expect(new BrowserExtensionInstallStore(root).get(STORE_ID)?.installTime).toBe(older)
|
||||
store.save(record({ id: STORE_ID }))
|
||||
expect(store.get(STORE_ID)?.installTime).toBe(older)
|
||||
store.save(record({ id: STORE_ID }), true)
|
||||
expect(store.get(STORE_ID)?.installTime).toBeGreaterThan(newer ?? 0)
|
||||
const updated = store.get(STORE_ID)?.installTime
|
||||
await store.remove(STORE_ID)
|
||||
store.save(record({ id: STORE_ID }))
|
||||
expect(store.get(STORE_ID)?.installTime).toBeGreaterThanOrEqual(updated ?? 0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('readBrowserExtensionManifest', () => {
|
||||
it('reads icons only from inside the extension folder', async () => {
|
||||
writeFileSync(join(root, 'icon.png'), Buffer.from([1, 2, 3]))
|
||||
await expect(readBrowserExtensionIconDataUrl(root, 'icon.png')).resolves.toBe(
|
||||
'data:image/png;base64,AQID'
|
||||
)
|
||||
await expect(
|
||||
readBrowserExtensionIconDataUrl(join(root, 'sub'), '../icon.png')
|
||||
).resolves.toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -1,59 +0,0 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { InstalledBrowserExtension } from '../../../../shared/browser/extensions/browser-extension-types'
|
||||
|
||||
const ID = 'nngceckbapebfimnlniiiahkandclblb'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
enabled: new Map<string, string[]>(),
|
||||
prepare: vi.fn(async () => {}),
|
||||
load: vi.fn(async (_profileId: string): Promise<unknown> => ({}))
|
||||
}))
|
||||
|
||||
vi.mock('../../sessions/profiles/browser-session-registry', () => ({
|
||||
browserSessionRegistry: {
|
||||
listProfiles: () => [...mocks.enabled.keys()].map((id) => ({ id })),
|
||||
getEnabledExtensionIds: (profileId: string) => mocks.enabled.get(profileId) ?? []
|
||||
}
|
||||
}))
|
||||
vi.mock('../installation/browser-extension-load-directory', () => ({
|
||||
prepareBrowserExtensionDirectory: mocks.prepare
|
||||
}))
|
||||
vi.mock('./browser-extension-session-loader', () => ({
|
||||
getBrowserExtensionSessionForProfile: () => ({}),
|
||||
loadBrowserExtensionIntoProfile: mocks.load,
|
||||
unloadBrowserExtensionFromProfile: vi.fn()
|
||||
}))
|
||||
|
||||
const { reloadBrowserExtensionWhereEnabled } = await import('./browser-extension-profile-reload')
|
||||
|
||||
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: reload reads only the id and passes the record through.
|
||||
const extension = { id: ID } as InstalledBrowserExtension
|
||||
|
||||
function disable(profileId: string): void {
|
||||
mocks.enabled.set(profileId, [])
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.enabled = new Map([
|
||||
['default', [ID]],
|
||||
['work', [ID]]
|
||||
])
|
||||
})
|
||||
|
||||
describe('reloadBrowserExtensionWhereEnabled', () => {
|
||||
it('does not start the extension in a profile that turned it off during the copy', async () => {
|
||||
mocks.prepare.mockImplementationOnce(async () => disable('default'))
|
||||
await reloadBrowserExtensionWhereEnabled(extension, { refresh: true })
|
||||
expect(mocks.load.mock.calls.map(([profileId]) => profileId)).toEqual(['work'])
|
||||
})
|
||||
|
||||
it("still reloads other profiles when turning it off cancels one profile's load", async () => {
|
||||
mocks.load.mockImplementationOnce(async () => {
|
||||
disable('default')
|
||||
throw new Error('The extension was turned off before it finished loading')
|
||||
})
|
||||
await expect(reloadBrowserExtensionWhereEnabled(extension)).resolves.toBeUndefined()
|
||||
expect(mocks.load.mock.calls.map(([profileId]) => profileId)).toEqual(['default', 'work'])
|
||||
})
|
||||
})
|
||||
@@ -1,77 +0,0 @@
|
||||
/// <reference types="chrome" />
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
matchesDiscardedTabNativeQuery,
|
||||
matchesOrcaTabQuery,
|
||||
type OrcaTabQuery
|
||||
} from './browser-extension-tab-query'
|
||||
|
||||
const MAIN = 1
|
||||
const POPOUT = 7
|
||||
|
||||
function tab(overrides: Partial<chrome.tabs.Tab>): chrome.tabs.Tab {
|
||||
return {
|
||||
id: 10,
|
||||
index: 0,
|
||||
windowId: MAIN,
|
||||
active: false,
|
||||
highlighted: false,
|
||||
selected: false,
|
||||
pinned: false,
|
||||
discarded: false,
|
||||
autoDiscardable: true,
|
||||
incognito: false,
|
||||
groupId: -1,
|
||||
status: 'complete',
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
const tabs = [
|
||||
tab({ id: 10, index: 0 }),
|
||||
tab({ id: 11, index: 1, active: true, highlighted: true, status: 'loading' }),
|
||||
tab({ id: 20, index: 0, windowId: POPOUT, active: true, highlighted: true }),
|
||||
tab({ id: 30, index: 2, discarded: true, status: 'unloaded' })
|
||||
]
|
||||
|
||||
function query(q: OrcaTabQuery, callerWindowId: number | null = MAIN): (number | undefined)[] {
|
||||
const context = {
|
||||
callerWindowId,
|
||||
lastFocusedWindowId: MAIN,
|
||||
windowTypeById: new Map([
|
||||
[MAIN, 'normal'],
|
||||
[POPOUT, 'popup']
|
||||
])
|
||||
}
|
||||
return tabs.filter((t) => matchesOrcaTabQuery(t, q, context)).map((t) => t.id)
|
||||
}
|
||||
|
||||
describe('matchesOrcaTabQuery', () => {
|
||||
it('answers the common "active tab in my window" query per caller window', () => {
|
||||
expect(query({ active: true, currentWindow: true })).toEqual([11])
|
||||
expect(query({ active: true, currentWindow: true }, POPOUT)).toEqual([20])
|
||||
expect(query({ active: true, lastFocusedWindow: true }, POPOUT)).toEqual([11])
|
||||
})
|
||||
})
|
||||
|
||||
describe('matchesDiscardedTabNativeQuery', () => {
|
||||
const cold = tab({ id: 30, discarded: true, url: 'https://docs.test/a', title: 'Docs: A' })
|
||||
|
||||
it("applies Electron's url and title patterns to the tab's saved address", () => {
|
||||
expect(matchesDiscardedTabNativeQuery(cold, { url: '*://docs.test/*' })).toBe(true)
|
||||
expect(matchesDiscardedTabNativeQuery(cold, { url: ['https://x.test/*', '<all_urls>'] })).toBe(
|
||||
true
|
||||
)
|
||||
expect(matchesDiscardedTabNativeQuery(cold, { url: 'https://x.test/*' })).toBe(false)
|
||||
expect(matchesDiscardedTabNativeQuery(cold, { title: 'Docs: *' })).toBe(true)
|
||||
expect(matchesDiscardedTabNativeQuery(cold, { title: 'docs*' })).toBe(false)
|
||||
})
|
||||
|
||||
it('never matches a hidden url, sound or a mute', () => {
|
||||
const hidden = tab({ id: 31, discarded: true })
|
||||
expect(matchesDiscardedTabNativeQuery(hidden, { url: '<all_urls>' })).toBe(false)
|
||||
expect(matchesDiscardedTabNativeQuery(cold, { audible: true })).toBe(false)
|
||||
expect(matchesDiscardedTabNativeQuery(cold, { muted: true })).toBe(false)
|
||||
expect(matchesDiscardedTabNativeQuery(cold, { audible: false, muted: false })).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -1,94 +0,0 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { InstalledBrowserExtension } from '../../../../shared/browser/extensions/browser-extension-types'
|
||||
import {
|
||||
ChromeWebStoreInstallFlow,
|
||||
type ChromeWebStoreFrame,
|
||||
type ChromeWebStoreInstallFlowDeps
|
||||
} from './browser-extension-webstore-install-flow'
|
||||
|
||||
const ID = 'nngceckbapebfimnlniiiahkandclblb'
|
||||
const MANIFEST = JSON.stringify({
|
||||
name: '__MSG_extName__',
|
||||
version: '2026.1.0',
|
||||
manifest_version: 3,
|
||||
permissions: ['tabs', 'storage'],
|
||||
host_permissions: ['https://*/*']
|
||||
})
|
||||
|
||||
function installed(): InstalledBrowserExtension {
|
||||
return {
|
||||
id: ID,
|
||||
name: 'Bitwarden',
|
||||
version: '2026.1.0',
|
||||
path: '/x',
|
||||
source: 'webstore',
|
||||
iconPath: null,
|
||||
permissions: [],
|
||||
hostPermissions: [],
|
||||
optionsPage: null
|
||||
}
|
||||
}
|
||||
|
||||
function setup(overrides: Partial<ChromeWebStoreInstallFlowDeps> = {}) {
|
||||
let now = 1_000
|
||||
let answer = true
|
||||
const deps: ChromeWebStoreInstallFlowDeps = {
|
||||
now: () => now,
|
||||
isEnabledInProfile: () => false,
|
||||
isBusy: () => false,
|
||||
profileLabel: () => 'Work',
|
||||
loadIcon: vi.fn(async () => 'data:image/png;base64,AA=='),
|
||||
confirm: vi.fn(async () => answer),
|
||||
install: vi.fn(async () => installed()),
|
||||
describeInstalled: vi.fn(async () => ({ name: 'Bitwarden', iconDataUrl: null })),
|
||||
uninstall: vi.fn(async () => {}),
|
||||
notifyInstalled: vi.fn(),
|
||||
notifyUninstalled: vi.fn(),
|
||||
...overrides
|
||||
}
|
||||
const valid = { current: true }
|
||||
const frame: ChromeWebStoreFrame = {
|
||||
webContentsId: 7,
|
||||
frameTreeNodeId: 3,
|
||||
profileId: 'work',
|
||||
isStillValid: () => valid.current
|
||||
}
|
||||
return {
|
||||
deps,
|
||||
frame,
|
||||
valid,
|
||||
flow: new ChromeWebStoreInstallFlow(deps),
|
||||
advance: (ms: number) => {
|
||||
now += ms
|
||||
},
|
||||
decline: () => {
|
||||
answer = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const details = {
|
||||
id: ID,
|
||||
manifest: MANIFEST,
|
||||
localizedName: 'Bitwarden',
|
||||
iconUrl: 'https://lh3.googleusercontent.com/x'
|
||||
}
|
||||
|
||||
describe('ChromeWebStoreInstallFlow.complete', () => {
|
||||
it('consumes the approval once', async () => {
|
||||
const { flow, frame } = setup()
|
||||
await flow.begin(frame, details)
|
||||
await flow.complete(frame, ID)
|
||||
await expect(flow.complete(frame, ID)).resolves.toHaveProperty('error')
|
||||
})
|
||||
|
||||
it('refuses an approval granted to another frame or tab', async () => {
|
||||
const { flow, frame, deps } = setup()
|
||||
await flow.begin(frame, details)
|
||||
await expect(flow.complete({ ...frame, frameTreeNodeId: 4 }, ID)).resolves.toHaveProperty(
|
||||
'error'
|
||||
)
|
||||
await expect(flow.complete({ ...frame, webContentsId: 8 }, ID)).resolves.toHaveProperty('error')
|
||||
expect(deps.install).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
// @vitest-environment happy-dom
|
||||
import { act } from 'react'
|
||||
import { createRoot, type Root } from 'react-dom/client'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import { LocalNetworkConnectionTest } from './LocalNetworkConnectionTest'
|
||||
|
||||
let container: HTMLDivElement
|
||||
let root: Root
|
||||
const testConnectionMock = vi.fn()
|
||||
|
||||
beforeEach(() => {
|
||||
localStorage.clear()
|
||||
testConnectionMock.mockReset()
|
||||
Object.assign(window, {
|
||||
api: {
|
||||
developerPermissions: {
|
||||
testLocalNetworkConnection: testConnectionMock
|
||||
}
|
||||
}
|
||||
})
|
||||
container = document.createElement('div')
|
||||
document.body.appendChild(container)
|
||||
root = createRoot(container)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
await act(async () => root.unmount())
|
||||
container.remove()
|
||||
localStorage.clear()
|
||||
Reflect.deleteProperty(window, 'api')
|
||||
})
|
||||
|
||||
function inputValue(input: HTMLInputElement, value: string): void {
|
||||
const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')?.set
|
||||
setter?.call(input, value)
|
||||
input.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
}
|
||||
|
||||
async function expandConnectionTest(): Promise<void> {
|
||||
await act(async () =>
|
||||
container.querySelector<HTMLButtonElement>('[data-slot="collapsible-trigger"]')?.click()
|
||||
)
|
||||
}
|
||||
|
||||
it('saves and displays the last successful target-specific test', async () => {
|
||||
testConnectionMock.mockResolvedValue({
|
||||
ok: true,
|
||||
host: '192.168.1.20',
|
||||
port: 3000,
|
||||
testedAt: new Date('2026-08-06T07:00:00Z').getTime()
|
||||
})
|
||||
await act(async () => root.render(<LocalNetworkConnectionTest />))
|
||||
await expandConnectionTest()
|
||||
|
||||
const host = container.querySelector<HTMLInputElement>('#local-network-test-host')!
|
||||
const port = container.querySelector<HTMLInputElement>('#local-network-test-port')!
|
||||
await act(async () => {
|
||||
inputValue(host, '192.168.1.20')
|
||||
inputValue(port, '3000')
|
||||
})
|
||||
await act(async () =>
|
||||
container.querySelector<HTMLButtonElement>('button[type="submit"]')?.click()
|
||||
)
|
||||
|
||||
expect(testConnectionMock).toHaveBeenCalledWith({ host: '192.168.1.20', port: 3000 })
|
||||
expect(container.textContent).toContain('Last verified')
|
||||
expect(container.textContent).toContain('192.168.1.20:3000')
|
||||
|
||||
await act(async () => root.render(null))
|
||||
await act(async () => root.render(<LocalNetworkConnectionTest />))
|
||||
await expandConnectionTest()
|
||||
expect(container.textContent).toContain('192.168.1.20:3000')
|
||||
})
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
// @vitest-environment happy-dom
|
||||
import { act, cleanup, renderHook, waitFor } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||||
import type { PublicKnownRuntimeEnvironment } from '../../../../../../shared/remote-runtime/host-catalog/runtime-environments'
|
||||
import { useAppStore } from '@/store/index'
|
||||
import { useRuntimeEnvironmentCatalog } from './use-runtime-environment-catalog'
|
||||
|
||||
const initialState = useAppStore.getInitialState()
|
||||
const list = vi.fn<() => Promise<PublicKnownRuntimeEnvironment[]>>()
|
||||
const getStatus = vi.fn(async () => {
|
||||
throw new Error('host is unreachable')
|
||||
})
|
||||
const previousApi = Object.getOwnPropertyDescriptor(window, 'api')
|
||||
const environment: PublicKnownRuntimeEnvironment = {
|
||||
id: 'env-a',
|
||||
name: 'Managed host',
|
||||
createdAt: 1,
|
||||
updatedAt: 1,
|
||||
pairingRevision: 1,
|
||||
lastUsedAt: null,
|
||||
runtimeId: null,
|
||||
endpoints: [
|
||||
{ id: 'ws-a', kind: 'websocket', label: 'WebSocket', endpoint: 'ws://localhost:6768' }
|
||||
],
|
||||
preferredEndpointId: 'ws-a'
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
useAppStore.setState(initialState, true)
|
||||
list.mockReset().mockResolvedValue([])
|
||||
getStatus.mockClear()
|
||||
Object.defineProperty(window, 'api', {
|
||||
configurable: true,
|
||||
value: {
|
||||
runtimeEnvironments: { list, getStatus, getStatusSnapshots: async () => [] }
|
||||
}
|
||||
})
|
||||
})
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
useAppStore.setState(initialState, true)
|
||||
if (previousApi) {
|
||||
Object.defineProperty(window, 'api', previousApi)
|
||||
} else {
|
||||
Reflect.deleteProperty(window, 'api')
|
||||
}
|
||||
})
|
||||
|
||||
it('shows a managed host published after Settings finished its initial list request', async () => {
|
||||
const { result } = renderHook(useRuntimeEnvironmentCatalog)
|
||||
await waitFor(() => expect(result.current.isLoading).toBe(false))
|
||||
expect(list).toHaveBeenCalledTimes(1)
|
||||
act(() => useAppStore.setState({ runtimeEnvironments: [environment] }))
|
||||
expect(result.current.environments).toEqual([environment])
|
||||
expect(list).toHaveBeenCalledTimes(1)
|
||||
expect(getStatus).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('follows saved host changes while contact with the host is unavailable', async () => {
|
||||
list.mockResolvedValue([environment])
|
||||
const { result } = renderHook(useRuntimeEnvironmentCatalog)
|
||||
await waitFor(() => expect(result.current.isLoading).toBe(false))
|
||||
const renamed = { ...environment, name: 'Renamed host', updatedAt: 2 }
|
||||
act(() => useAppStore.setState({ runtimeEnvironments: [renamed] }))
|
||||
expect(result.current.environments).toEqual([renamed])
|
||||
act(() => useAppStore.setState({ runtimeEnvironments: [] }))
|
||||
expect(result.current.environments).toEqual([])
|
||||
expect(list).toHaveBeenCalledTimes(1)
|
||||
expect(getStatus).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
@@ -1,52 +0,0 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
|
||||
import { afterEach, expect, it, vi } from 'vitest'
|
||||
import { useAppStore } from '@/store/index'
|
||||
import { TooltipProvider } from '@/components/ui/tooltip'
|
||||
import { ShortcutsPane } from './ShortcutsPane'
|
||||
|
||||
vi.hoisted(() => vi.stubGlobal('navigator', { userAgent: 'Macintosh' }))
|
||||
const fixtures = vi.hoisted(() => ({ empty: [] }))
|
||||
vi.mock('@/store/plugins/catalog/plugin-contribution-catalog', () => ({
|
||||
useEditablePluginCommands: () => fixtures.empty
|
||||
}))
|
||||
vi.mock('./use-mac-captured-digit-chords', () => ({
|
||||
useMacCapturedDigitChords: () => fixtures.empty
|
||||
}))
|
||||
vi.mock('./KeybindingsFileActions', () => ({ KeybindingsFileActions: () => null }))
|
||||
vi.mock('./ShortcutTerminalPolicyControl', () => ({ ShortcutTerminalPolicyControl: () => null }))
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
it('keeps recording when the current default conflicts with an explicit shortcut in a legacy profile', async () => {
|
||||
vi.stubGlobal('api', { ui: { setShortcutRecorderFocused: vi.fn() } })
|
||||
useAppStore.setState({
|
||||
keybindings: { 'worktree.palette': ['Mod+J'], 'terminal.clear': ['Mod+K'] },
|
||||
keybindingSnapshot: {
|
||||
path: '/tmp/keybindings.json',
|
||||
exists: true,
|
||||
platform: 'darwin',
|
||||
overrides: { 'worktree.palette': ['Mod+J'], 'terminal.clear': ['Mod+K'] },
|
||||
defaultOverrides: { 'worktree.palette': ['Mod+J'], 'terminal.clear': ['Mod+K'] },
|
||||
commonOverrides: {},
|
||||
platformOverrides: { darwin: { 'terminal.clear': ['Mod+K'] } },
|
||||
diagnostics: []
|
||||
},
|
||||
resetKeybindingOverride: vi.fn().mockResolvedValue(undefined),
|
||||
setKeybindingOverride: vi.fn().mockResolvedValue(undefined)
|
||||
})
|
||||
render(
|
||||
<TooltipProvider>
|
||||
<ShortcutsPane />
|
||||
</TooltipProvider>
|
||||
)
|
||||
const recorder = screen.getByRole('button', { name: 'Change shortcut for Switch worktree' })
|
||||
fireEvent.click(recorder)
|
||||
await act(async () => {
|
||||
fireEvent.keyDown(recorder, { key: 'k', code: 'KeyK', metaKey: true })
|
||||
})
|
||||
expect(recorder.getAttribute('aria-pressed')).toBe('true')
|
||||
})
|
||||
Reference in New Issue
Block a user