Skip to content

Commit 900eb15

Browse files
author
CrewCoder
committed
feat: update package-lock.json and enhance tests with realpathSync for improved path handling
1 parent 4dc70cd commit 900eb15

7 files changed

Lines changed: 48 additions & 21 deletions

‎package-lock.json‎

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/main/brain-authorization-policy.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mkdirSync, mkdtempSync, statSync } from 'fs'
1+
import { mkdirSync, mkdtempSync, realpathSync, statSync } from 'fs'
22
import { join } from 'path'
33
import { tmpdir } from 'os'
44
import { describe, expect, it } from 'vitest'
@@ -7,12 +7,13 @@ import { BrainAuthorizationPolicy, brainAuthorizationPolicyPath } from './brain-
77
describe('Brain authorization policy', () => {
88
it('persists canonical roots, scopes, and local audit across restart', () => {
99
const dataDir = mkdtempSync(join(tmpdir(), 'brain-policy-')); const root = join(dataDir, 'workspace'); mkdirSync(root)
10+
const canonicalRoot = realpathSync(root)
1011
let now = 100; const path = brainAuthorizationPolicyPath(dataDir)
1112
const policy = new BrainAuthorizationPolicy(path, [root], ['workspace:read'], () => now)
1213
now = 200
1314
const updated = policy.update({ roots: [root], scopes: ['agent', 'workspace:read'], userId: 'owner' })
14-
expect(updated).toMatchObject({ scopes: ['agent', 'workspace:read'], roots: [root], audit: [{ userId: 'owner', at: 200 }] })
15-
expect(statSync(path).mode & 0o777).toBe(0o600)
15+
expect(updated).toMatchObject({ scopes: ['agent', 'workspace:read'], roots: [canonicalRoot], audit: [{ userId: 'owner', at: 200 }] })
16+
if (process.platform !== 'win32') expect(statSync(path).mode & 0o777).toBe(0o600)
1617
expect(new BrainAuthorizationPolicy(path, [], [], () => 300).current()).toEqual(updated)
1718
})
1819
it('rejects invalid policy', () => {

‎src/main/hub-local-brain.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { EventEmitter } from 'events'
22
import { mkdtempSync, rmSync } from 'fs'
33
import { tmpdir } from 'os'
4-
import { join } from 'path'
4+
import { dirname, join } from 'path'
55
import { afterEach, describe, expect, it } from 'vitest'
66
import type { ChildProcess } from 'child_process'
77
import {
@@ -51,13 +51,14 @@ describe('local Brain Hub origin matching', () => {
5151

5252
describe('local Brain spawn plan', () => {
5353
it('spawns sibling brain.js from a compiled Hub entry', () => {
54+
const scriptPath = '/opt/crewcode/out/main/hub.js'
5455
expect(localBrainSpawnPlan({
5556
execPath: '/usr/bin/node',
56-
scriptPath: '/opt/crewcode/out/main/hub.js',
57+
scriptPath,
5758
brainArgv: ['--data-dir', '/brain'],
5859
})).toEqual({
5960
execPath: '/usr/bin/node',
60-
args: ['/opt/crewcode/out/main/brain.js', '--data-dir', '/brain'],
61+
args: [join(dirname(scriptPath), 'brain.js'), '--data-dir', '/brain'],
6162
})
6263
})
6364

@@ -193,7 +194,7 @@ describe('local Brain supervisor', () => {
193194
warn: () => undefined,
194195
})
195196
await ready
196-
expect(spawned[0]?.[0]).toBe('/opt/crewcode/out/main/brain.js')
197+
expect(spawned[0]?.[0]).toBe(join(dirname('/opt/crewcode/out/main/hub.js'), 'brain.js'))
197198
await supervisor.stop()
198199
expect(child.killed).toBe(true)
199200
})

‎src/main/hub-machine-enrollment.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { generateKeyPairSync } from 'crypto'
22
import { mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from 'fs'
33
import { tmpdir } from 'os'
4-
import { join } from 'path'
4+
import { join, resolve } from 'path'
55
import { afterEach, describe, expect, it, vi } from 'vitest'
66
import {
77
HubDeviceEnrollmentIssuer,
@@ -64,7 +64,7 @@ describe('Hub machine client security', () => {
6464
expect(() => parseBrainOptions([], 'enroll')).toThrow('requires --hub')
6565
expect(parseBrainOptions([], 'brain')).toMatchObject({ name: expect.any(String), allowedScopes: [], allowedWorkspaceRoots: [] })
6666
expect(parseBrainOptions(['--workspace-root', '.', '--allow-scope', 'workspace:read', '--allow-scope', 'agent'], 'brain', '/tmp')).toMatchObject({
67-
allowedWorkspaceRoots: ['/tmp'], allowedScopes: ['workspace:read', 'agent'],
67+
allowedWorkspaceRoots: [resolve('/tmp', '.')], allowedScopes: ['workspace:read', 'agent'],
6868
})
6969
expect(() => parseBrainOptions(['--allow-scope', 'everything'], 'brain')).toThrow('invalid Brain scope')
7070
})

‎src/main/hub-relay.test.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
hkdfSync,
99
verify,
1010
} from 'crypto'
11-
import { mkdtempSync, readFileSync, rmSync } from 'fs'
11+
import { mkdtempSync, readFileSync, realpathSync, rmSync } from 'fs'
1212
import { createServer } from 'http'
1313
import { tmpdir } from 'os'
1414
import { join } from 'path'
@@ -26,8 +26,10 @@ const cleanups: Array<() => void | Promise<void>> = []
2626
afterEach(async () => { while (cleanups.length) await cleanups.pop()?.() })
2727

2828
function directory(): string {
29-
const value = mkdtempSync(join(tmpdir(), 'crewcode-hub-relay-'))
30-
cleanups.push(() => rmSync(value, { recursive: true, force: true }))
29+
const value = realpathSync(mkdtempSync(join(tmpdir(), 'crewcode-hub-relay-')))
30+
cleanups.push(() => {
31+
try { rmSync(value, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 }) } catch { /* Windows may keep SQLite/PTY handles briefly */ }
32+
})
3133
return value
3234
}
3335

‎src/main/pty-service.yuheard.test.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { mkdtempSync } from 'fs'
2+
import { tmpdir } from 'os'
3+
import { join } from 'path'
14
import { beforeEach, describe, expect, it, vi } from 'vitest'
25

36
const mocks = vi.hoisted(() => ({
@@ -46,11 +49,14 @@ function fakeProc() {
4649
}
4750

4851
describe('PtyService YuHeard bundle boundary', () => {
52+
let cwd: string
53+
4954
beforeEach(() => {
5055
vi.clearAllMocks()
5156
mocks.spawn.mockReturnValue(fakeProc())
5257
mocks.installWrapper.mockReturnValue('/tmp/crewcode-yuheard-wrap/pane-1')
5358
mocks.fishArgv.mockReturnValue(['-C', 'yuheard-init'])
59+
cwd = mkdtempSync(join(tmpdir(), 'pty-yuheard-'))
5460
})
5561

5662
it('uses injected server access and statically imported wrappers for a Fish shell', () => {
@@ -68,15 +74,15 @@ describe('PtyService YuHeard bundle boundary', () => {
6874

6975
const result = service.create({
7076
paneId: 'pane-1',
71-
cwd: '/tmp',
77+
cwd,
7278
shell: 'fish',
7379
yuheard: true,
7480
autoWrap: true,
7581
wrapAgentIds: ['codex', 'claude'],
7682
})
7783

7884
expect(result.ok).toBe(true)
79-
expect(notePaneSpawned).toHaveBeenCalledWith('pane-1', '/tmp')
85+
expect(notePaneSpawned).toHaveBeenCalledWith('pane-1', cwd)
8086
expect(mocks.installWrapper).toHaveBeenCalledWith(
8187
'pane-1',
8288
['codex', 'claude'],
@@ -121,7 +127,7 @@ describe('PtyService YuHeard bundle boundary', () => {
121127
const service = new PtyService(() => server)
122128
service.create({
123129
paneId: 'pane-1',
124-
cwd: '/tmp',
130+
cwd,
125131
shell: 'fish',
126132
yuheard: true,
127133
autoWrap: true,
@@ -158,7 +164,7 @@ describe('PtyService YuHeard bundle boundary', () => {
158164
const service = new PtyService(() => server)
159165
service.create({
160166
paneId: 'pane-1',
161-
cwd: '/tmp',
167+
cwd,
162168
shell: 'fish',
163169
yuheard: true,
164170
autoWrap: true,

‎src/main/yuheard-wrapper.test.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
66
import { mkdtempSync, readFileSync, existsSync, statSync, rmSync, utimesSync, readdirSync } from 'fs'
77
import { tmpdir } from 'os'
8-
import { join } from 'path'
8+
import { delimiter, join } from 'path'
99
import {
1010
installYuHeardWrapper,
1111
installYuHeardHook,
@@ -36,8 +36,10 @@ describe('installYuHeardWrapper', () => {
3636
expect(dir).toBe(join(baseDir, 'pn-1'))
3737
expect(existsSync(join(dir, 'claude'))).toBe(true)
3838
expect(existsSync(join(dir, 'codex'))).toBe(true)
39-
const st = statSync(join(dir, 'claude'))
40-
expect((st.mode & 0o100) !== 0).toBe(true)
39+
if (process.platform !== 'win32') {
40+
const st = statSync(join(dir, 'claude'))
41+
expect((st.mode & 0o100) !== 0).toBe(true)
42+
}
4143
})
4244

4345
it('embeds the socket path in the hook and does not call yuheard on PATH', () => {
@@ -188,7 +190,8 @@ describe('pruneYuHeardWrappers', () => {
188190

189191
describe('prependWrapperToPath', () => {
190192
it('prepends the wrapper dir to an existing PATH', () => {
191-
expect(prependWrapperToPath('/wrappers/pn-1', '/usr/bin:/bin')).toBe('/wrappers/pn-1:/usr/bin:/bin')
193+
const current = ['/usr/bin', '/bin'].join(delimiter)
194+
expect(prependWrapperToPath('/wrappers/pn-1', current)).toBe(['/wrappers/pn-1', '/usr/bin', '/bin'].join(delimiter))
192195
})
193196

194197
it('handles an empty PATH gracefully', () => {

0 commit comments

Comments
 (0)