Skip to content

Commit 692c0b4

Browse files
committed
fix(types): remove unused import and fix context tests
- Remove unused getSocketBasicsVersion import in spawn.mts - Fix context.test.mts tests for non-project directory detection - Use isolated temp directory outside project tree for test isolation
1 parent 9121cc3 commit 692c0b4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/cli/src/utils/dlx/spawn.mts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import { getDefaultOrgSlug } from '../../commands/ci/fetch-default-org-slug.mjs'
5555
import { getCliVersion } from '../../env/cli-version.mts'
5656
import { getPyCliChecksums } from '../../env/pycli-checksums.mts'
5757
import { getPyCliVersion } from '../../env/pycli-version.mts'
58-
import { getSocketBasicsVersion } from '../../env/socket-basics-version.mts'
5958
import { getPythonBuildTag } from '../../env/python-build-tag.mts'
6059
import { requirePythonChecksum } from '../../env/python-checksums.mts'
6160
import { getPythonVersion } from '../../env/python-version.mts'

packages/cli/test/unit/utils/project/context.test.mts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
import { existsSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'
18+
import os from 'node:os'
1819
import path from 'node:path'
1920

2021
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
@@ -37,8 +38,19 @@ describe('project context utilities', () => {
3738
const packageManagerField = path.join(testRoot, 'pm-field-project')
3839
const noLockProject = path.join(testRoot, 'no-lock-project')
3940
const nestedProject = path.join(testRoot, 'nested', 'deep', 'project')
41+
// Use a temp directory outside any project tree to test non-project detection.
42+
// This ensures no package.json exists in any parent directory.
43+
const emptyDir = path.join(
44+
os.tmpdir(),
45+
`socket-cli-test-empty-${Date.now()}`,
46+
'deeply',
47+
'nested',
48+
'empty',
49+
)
4050

4151
beforeAll(() => {
52+
// Create empty directory (no package.json) for testing non-project detection.
53+
mkdirSync(emptyDir, { recursive: true })
4254
// Create npm project.
4355
mkdirSync(npmProject, { recursive: true })
4456
writeFileSync(
@@ -115,6 +127,11 @@ describe('project context utilities', () => {
115127
if (existsSync(testRoot)) {
116128
rmSync(testRoot, { recursive: true, force: true })
117129
}
130+
// Clean up the temp emptyDir base (the unique timestamped directory).
131+
const emptyDirBase = path.dirname(path.dirname(path.dirname(emptyDir)))
132+
if (existsSync(emptyDirBase)) {
133+
rmSync(emptyDirBase, { recursive: true, force: true })
134+
}
118135
})
119136

120137
describe('detectPackageManager', () => {
@@ -215,7 +232,7 @@ describe('project context utilities', () => {
215232
})
216233

217234
it('returns null when no package.json found', async () => {
218-
const result = await findProjectRoot('/tmp')
235+
const result = await findProjectRoot(emptyDir)
219236

220237
expect(result).toBeNull()
221238
})
@@ -247,7 +264,7 @@ describe('project context utilities', () => {
247264
})
248265

249266
it('returns null for non-project directory', async () => {
250-
const context = await getProjectContext('/tmp')
267+
const context = await getProjectContext(emptyDir)
251268

252269
expect(context).toBeNull()
253270
})

0 commit comments

Comments
 (0)