forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclaude-binary-check.test.mjs
More file actions
90 lines (80 loc) · 2.89 KB
/
Copy pathclaude-binary-check.test.mjs
File metadata and controls
90 lines (80 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { tmpdir } from 'node:os'
import { afterEach, describe, expect, it } from 'vitest'
import { checkClaudeBinary, findClaudeBinary } from './claude-binary-check.mjs'
const roots = []
function makeRoot() {
const root = mkdtempSync(join(tmpdir(), 'omi-claude-binary-check-'))
roots.push(root)
return root
}
function writeBinary(dir, bytes) {
mkdirSync(dir, { recursive: true })
writeFileSync(join(dir, 'claude.exe'), Buffer.alloc(bytes, 1))
}
afterEach(() => {
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
})
describe('checkClaudeBinary', () => {
it('skips on non-Windows platforms', () => {
expect(checkClaudeBinary(makeRoot(), 'darwin')).toEqual({ ok: true, skipped: true })
})
it('fails loudly when the optional package is absent (the pnpm-exit-0 case)', () => {
const result = checkClaudeBinary(makeRoot(), 'win32')
expect(result.ok).toBe(false)
expect(result.reason).toContain('optionalDependency')
expect(result.reason).toContain('pnpm install')
})
it('does not mistake an empty residual virtual-store directory for an install', () => {
// A failed optional download can leave the .pnpm dir behind with no
// claude.exe inside — the exact shape seen in the PR #9304 review.
const root = makeRoot()
mkdirSync(
join(
root,
'node_modules',
'.pnpm',
'@anthropic-ai+claude-agent-sdk-win32-x64@0.3.205',
'node_modules',
'@anthropic-ai',
'claude-agent-sdk-win32-x64'
),
{ recursive: true }
)
const result = checkClaudeBinary(root, 'win32')
expect(result.ok).toBe(false)
expect(result.reason).toContain('claude.exe not found')
})
it('fails on a truncated download', () => {
const root = makeRoot()
writeBinary(join(root, 'node_modules', '@anthropic-ai', 'claude-agent-sdk-win32-x64'), 10)
const result = checkClaudeBinary(root, 'win32', 1024)
expect(result.ok).toBe(false)
expect(result.reason).toContain('truncated')
})
it('passes with a plausible binary in the flattened layout', () => {
const root = makeRoot()
writeBinary(join(root, 'node_modules', '@anthropic-ai', 'claude-agent-sdk-win32-x64'), 2048)
const result = checkClaudeBinary(root, 'win32', 1024)
expect(result.ok).toBe(true)
expect(result.size).toBe(2048)
})
it('finds the binary in the pnpm virtual-store layout too', () => {
const root = makeRoot()
writeBinary(
join(
root,
'node_modules',
'.pnpm',
'@anthropic-ai+claude-agent-sdk-win32-x64@0.3.205',
'node_modules',
'@anthropic-ai',
'claude-agent-sdk-win32-x64'
),
2048
)
expect(findClaudeBinary(root)).toContain('.pnpm')
expect(checkClaudeBinary(root, 'win32', 1024).ok).toBe(true)
})
})