fix: detect AppData directory paths without trailing separators

This commit is contained in:
YeonGyu-Kim 2026-02-17 01:45:14 +09:00
parent 5ae45c8c8e
commit 24789334e4
2 changed files with 26 additions and 2 deletions

View File

@ -15,6 +15,17 @@ describe("session-directory-resolver", () => {
expect(result).toBe(true)
})
test("returns true when path ends with AppData directory segment", () => {
//#given
const directory = "C:/Users/test/AppData/Local"
//#when
const result = isWindowsAppDataDirectory(directory)
//#then
expect(result).toBe(true)
})
test("returns false when path is outside AppData", () => {
//#given
const directory = "D:/projects/oh-my-opencode"
@ -25,6 +36,17 @@ describe("session-directory-resolver", () => {
//#then
expect(result).toBe(false)
})
test("returns false for lookalike non-AppData segment", () => {
//#given
const directory = "D:/projects/appdata/local-tools"
//#when
const result = isWindowsAppDataDirectory(directory)
//#then
expect(result).toBe(false)
})
})
describe("resolveSessionDirectory", () => {

View File

@ -1,4 +1,4 @@
const WINDOWS_APPDATA_SEGMENTS = ["\\appdata\\local\\", "\\appdata\\roaming\\", "\\appdata\\locallow\\"]
const WINDOWS_APPDATA_SEGMENTS = ["\\appdata\\local", "\\appdata\\roaming", "\\appdata\\locallow"]
function normalizeWindowsPath(directory: string): string {
return directory.replaceAll("/", "\\").toLowerCase()
@ -6,7 +6,9 @@ function normalizeWindowsPath(directory: string): string {
export function isWindowsAppDataDirectory(directory: string): boolean {
const normalizedDirectory = normalizeWindowsPath(directory)
return WINDOWS_APPDATA_SEGMENTS.some((segment) => normalizedDirectory.includes(segment))
return WINDOWS_APPDATA_SEGMENTS.some((segment) => {
return normalizedDirectory.endsWith(segment) || normalizedDirectory.includes(`${segment}\\`)
})
}
export function resolveSessionDirectory(options: {