mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 22:05:50 +00:00
feat: 整合功能恢复与技能学习闭环(含 ECC v2.1 parity + Opus 4.7 接入 + prompt 工程优化)
主要变更: - Skill Learning 闭环系统 (9/9 AC) - Opus 4.7 模型层接入 + adaptive thinking - Prompt 工程优化 (64 审计测试) - Agent Teams 简化门控 (默认启用) - Windows Terminal 后端修复 (EncodedCommand/WT_SESSION) - TF-IDF 技能搜索精准化 (字段加权/CJK 优化) - Autonomy 系统 (/autonomy 命令) - ACP 协议完整实现 - mock.module 泄漏修复 (CI 全绿) - 152+ lint/type 修复
This commit is contained in:
112
packages/modifiers-napi/src/__tests__/index.test.ts
Normal file
112
packages/modifiers-napi/src/__tests__/index.test.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test'
|
||||
|
||||
let ffiShouldThrow = false
|
||||
let nativeFlags = 0
|
||||
let dlopenCalls = 0
|
||||
|
||||
mock.module('bun:ffi', () => ({
|
||||
FFIType: {
|
||||
i32: 0,
|
||||
u64: 0,
|
||||
},
|
||||
dlopen: () => {
|
||||
dlopenCalls++
|
||||
if (ffiShouldThrow) {
|
||||
throw new Error('ffi load failed')
|
||||
}
|
||||
return {
|
||||
symbols: {
|
||||
CGEventSourceFlagsState: () => nativeFlags,
|
||||
},
|
||||
}
|
||||
},
|
||||
}))
|
||||
|
||||
const originalPlatform = process.platform
|
||||
|
||||
async function loadModule() {
|
||||
return import(`../index.ts?case=${Math.random()}`)
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
ffiShouldThrow = false
|
||||
nativeFlags = 0
|
||||
dlopenCalls = 0
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
configurable: true,
|
||||
})
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: originalPlatform,
|
||||
configurable: true,
|
||||
})
|
||||
})
|
||||
|
||||
describe('modifiers-napi', () => {
|
||||
test('returns false for non-darwin platforms', async () => {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: 'win32',
|
||||
configurable: true,
|
||||
})
|
||||
const mod = await loadModule()
|
||||
|
||||
await mod.prewarm()
|
||||
expect(dlopenCalls).toBe(0)
|
||||
expect(mod.isModifierPressed('shift')).toBe(false)
|
||||
expect(mod.isModifierPressed('command')).toBe(false)
|
||||
})
|
||||
|
||||
test('prewarm is idempotent on darwin', async () => {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: 'darwin',
|
||||
configurable: true,
|
||||
})
|
||||
const mod = await loadModule()
|
||||
|
||||
await mod.prewarm()
|
||||
await mod.prewarm()
|
||||
|
||||
expect(dlopenCalls).toBe(1)
|
||||
})
|
||||
|
||||
test('returns false when ffi loading fails on darwin', async () => {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: 'darwin',
|
||||
configurable: true,
|
||||
})
|
||||
ffiShouldThrow = true
|
||||
const mod = await loadModule()
|
||||
|
||||
await mod.prewarm()
|
||||
expect(mod.isModifierPressed('shift')).toBe(false)
|
||||
})
|
||||
|
||||
test('returns false for unknown modifier names on darwin', async () => {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: 'darwin',
|
||||
configurable: true,
|
||||
})
|
||||
nativeFlags = 0x20000
|
||||
const mod = await loadModule()
|
||||
|
||||
await mod.prewarm()
|
||||
expect(mod.isModifierPressed('unknown')).toBe(false)
|
||||
})
|
||||
|
||||
test('uses native flag bits for known modifiers on darwin', async () => {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
value: 'darwin',
|
||||
configurable: true,
|
||||
})
|
||||
nativeFlags = 0x20000 | 0x40000
|
||||
const mod = await loadModule()
|
||||
|
||||
await mod.prewarm()
|
||||
expect(mod.isModifierPressed('shift')).toBe(true)
|
||||
expect(mod.isModifierPressed('control')).toBe(true)
|
||||
expect(mod.isModifierPressed('option')).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -14,14 +14,16 @@ const modifierFlags: Record<string, number> = {
|
||||
const kCGEventSourceStateCombinedSessionState = 0;
|
||||
|
||||
let cgEventSourceFlagsState: ((stateID: number) => number) | null = null;
|
||||
let ffiLoadAttempted = false;
|
||||
|
||||
function loadFFI(): void {
|
||||
if (cgEventSourceFlagsState !== null || process.platform !== "darwin") {
|
||||
async function loadFFI(): Promise<void> {
|
||||
if (ffiLoadAttempted || process.platform !== "darwin") {
|
||||
return;
|
||||
}
|
||||
ffiLoadAttempted = true;
|
||||
|
||||
try {
|
||||
const ffi = require("bun:ffi") as typeof import("bun:ffi");
|
||||
const ffi = await import("bun:ffi");
|
||||
const lib = ffi.dlopen(
|
||||
`/System/Library/Frameworks/Carbon.framework/Carbon`,
|
||||
{
|
||||
@@ -35,13 +37,12 @@ function loadFFI(): void {
|
||||
return Number(lib.symbols.CGEventSourceFlagsState(stateID));
|
||||
};
|
||||
} catch {
|
||||
// If loading fails, keep the function null so isModifierPressed returns false
|
||||
cgEventSourceFlagsState = null;
|
||||
}
|
||||
}
|
||||
|
||||
export function prewarm(): void {
|
||||
loadFFI();
|
||||
export async function prewarm(): Promise<void> {
|
||||
await loadFFI();
|
||||
}
|
||||
|
||||
export function isModifierPressed(modifier: string): boolean {
|
||||
@@ -49,8 +50,6 @@ export function isModifierPressed(modifier: string): boolean {
|
||||
return false;
|
||||
}
|
||||
|
||||
loadFFI();
|
||||
|
||||
if (cgEventSourceFlagsState === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user