fix project instruction review findings

This commit is contained in:
Yichen Jiang
2026-07-01 18:51:50 +08:00
parent 0691048e47
commit e23a6902e7
7 changed files with 167 additions and 21 deletions

View File

@@ -5,7 +5,7 @@
*/
import { homedir } from 'node:os'
import { join } from 'node:path'
import { join, resolve } from 'node:path'
/** Directory name for the default DeepSeek Harness home under the OS home. */
export const DSH_HOME_DIR_NAME = '.dsh'
@@ -13,6 +13,9 @@ export const DSH_HOME_DIR_NAME = '.dsh'
/** Stable user-facing display form for the default DeepSeek Harness home. */
export const DEFAULT_DSH_HOME_DISPLAY = `~/${DSH_HOME_DIR_NAME}`
/** Environment variable that overrides the default DeepSeek Harness home. */
export const DSH_HOME_ENV = 'DSH_HOME'
/** Resolve the default DeepSeek Harness home using Node's platform path rules. */
export function defaultDshHome(): string {
return join(homedir(), DSH_HOME_DIR_NAME)
@@ -24,3 +27,9 @@ export function expandHomePath(path: string): string {
if (path.startsWith('~/') || path.startsWith('~\\')) return join(homedir(), path.slice(2))
return path
}
/** Resolve an explicitly configured, env-selected, or default DSH home path. */
export function resolveDshHome(configured?: string, env: Record<string, string | undefined> = process.env): string {
const selected = configured ?? env[DSH_HOME_ENV] ?? defaultDshHome()
return resolve(expandHomePath(selected))
}

View File

@@ -6,6 +6,7 @@ import {
DSH_HOME_DIR_NAME,
defaultDshHome,
expandHomePath,
resolveDshHome,
} from '@deepseek-ai/dsh-paths'
describe('dsh path helpers', () => {
@@ -22,4 +23,12 @@ describe('dsh path helpers', () => {
expect(expandHomePath('/tmp/.dsh')).toBe('/tmp/.dsh')
expect(expandHomePath('~other/.dsh')).toBe('~other/.dsh')
})
it('resolves explicit DSH home before environment and default locations', () => {
const envHome = join(homedir(), 'env-dsh')
expect(resolveDshHome(undefined, { DSH_HOME: '~/env-dsh' })).toBe(envHome)
expect(resolveDshHome('/tmp/explicit-dsh', { DSH_HOME: '~/env-dsh' })).toBe('/tmp/explicit-dsh')
expect(resolveDshHome(undefined, {})).toBe(defaultDshHome())
})
})