mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 13:55:50 +00:00
- 新增 workflowRuns、remoteTriggerAudit、pipeStatus 等工具 - 增强 permissionSetup: auto mode 和 bypass permissions 始终可用 - 新增多组测试覆盖 (modifiers, teamDiscovery, deepLink 等) - 修复 parseInt 缺少 radix 参数 - 移除多余 biome-ignore 注释 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
97 lines
2.5 KiB
TypeScript
97 lines
2.5 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test'
|
|
|
|
let nativePrewarmCalls = 0
|
|
let nativeReturnValue = false
|
|
let nativeShouldThrow = false
|
|
|
|
const nativeIsModifierPressed = mock((modifier: string) => {
|
|
if (nativeShouldThrow) {
|
|
throw new Error('native modifier failure')
|
|
}
|
|
return nativeReturnValue
|
|
})
|
|
|
|
mock.module('modifiers-napi', () => ({
|
|
prewarm: async () => {
|
|
nativePrewarmCalls++
|
|
},
|
|
isModifierPressed: nativeIsModifierPressed,
|
|
}))
|
|
|
|
const originalPlatform = process.platform
|
|
|
|
async function loadModule() {
|
|
return import(`../modifiers.ts?case=${Math.random()}`)
|
|
}
|
|
|
|
beforeEach(() => {
|
|
nativePrewarmCalls = 0
|
|
nativeReturnValue = false
|
|
nativeShouldThrow = false
|
|
nativeIsModifierPressed.mockClear()
|
|
Object.defineProperty(process, 'platform', {
|
|
value: originalPlatform,
|
|
configurable: true,
|
|
})
|
|
})
|
|
|
|
afterEach(() => {
|
|
Object.defineProperty(process, 'platform', {
|
|
value: originalPlatform,
|
|
configurable: true,
|
|
})
|
|
})
|
|
|
|
describe('src/utils/modifiers', () => {
|
|
test('does not touch the native module on non-darwin', async () => {
|
|
Object.defineProperty(process, 'platform', {
|
|
value: 'win32',
|
|
configurable: true,
|
|
})
|
|
const mod = await loadModule()
|
|
|
|
mod.prewarmModifiers()
|
|
expect(nativePrewarmCalls).toBe(0)
|
|
expect(mod.isModifierPressed('shift')).toBe(false)
|
|
expect(nativeIsModifierPressed).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('caches native prewarm after the first darwin call', async () => {
|
|
Object.defineProperty(process, 'platform', {
|
|
value: 'darwin',
|
|
configurable: true,
|
|
})
|
|
const mod = await loadModule()
|
|
|
|
mod.prewarmModifiers()
|
|
mod.prewarmModifiers()
|
|
|
|
// prewarm is fire-and-forget async — flush microtasks
|
|
await new Promise(resolve => setTimeout(resolve, 0))
|
|
expect(nativePrewarmCalls).toBe(1)
|
|
})
|
|
|
|
test('forwards modifier checks to the native module on darwin', async () => {
|
|
Object.defineProperty(process, 'platform', {
|
|
value: 'darwin',
|
|
configurable: true,
|
|
})
|
|
nativeReturnValue = true
|
|
const mod = await loadModule()
|
|
|
|
expect(mod.isModifierPressed('shift')).toBe(true)
|
|
expect(nativeIsModifierPressed).toHaveBeenCalledWith('shift')
|
|
})
|
|
|
|
test('returns false when native modifier checks throw on darwin', async () => {
|
|
Object.defineProperty(process, 'platform', {
|
|
value: 'darwin',
|
|
configurable: true,
|
|
})
|
|
nativeShouldThrow = true
|
|
const mod = await loadModule()
|
|
|
|
expect(mod.isModifierPressed('shift')).toBe(false)
|
|
})
|
|
})
|