trae: the two Windows roots of the client's storage.json are one when they name the same folder (#273, moxuanchen)
clientStoragePaths compares its two Windows roots (APPDATA and the home's
AppData\Roaming) ignoring separator, trailing separator and case, so the same
storage.json isn't read twice; the path test compares with this system's
separator, so it passes on Windows.
Run at the reviewed head 08b52ad, merged with #257 and #260 on main 68170b3:
bun test in packages/trae 173 pass 0 fail; check.mjs trae ok. Not run on
Windows here. A case/separator test that fails on main follows on main.
This commit is contained in:
+10
-1
@@ -821,7 +821,16 @@ function clientStoragePaths(platform, home, env) {
|
||||
const file = (root, name) => join(root, name, "User", "globalStorage", "storage.json")
|
||||
if (platform === "darwin") return [file(join(home, "Library", "Application Support"), "Trae CN")]
|
||||
if (platform === "win32") {
|
||||
const roots = [env.APPDATA, join(home, "AppData", "Roaming")].filter((r, i, all) => r && all.indexOf(r) === i)
|
||||
// the two roots are often the same folder: APPDATA and the home's own
|
||||
// AppData\Roaming. They are compared as one system spells them, so a
|
||||
// difference of separator or case alone doesn't read the same file twice
|
||||
const spell = (r) => String(r ?? "").replace(/[\\/]+/g, "\\").replace(/\\+$/, "").toLowerCase()
|
||||
const roots = []
|
||||
for (const r of [env.APPDATA, join(home, "AppData", "Roaming")]) {
|
||||
if (!r) continue
|
||||
if (roots.some((was) => spell(was) === spell(r))) continue
|
||||
roots.push(r)
|
||||
}
|
||||
return roots.flatMap((r) => ["Trae CN", "trae-cn"].map((n) => file(r, n)))
|
||||
}
|
||||
if (platform === "linux") return ["trae-cn", "Trae CN"].map((n) => file(env.XDG_CONFIG_HOME || join(home, ".config"), n))
|
||||
|
||||
@@ -6,7 +6,7 @@ import { afterEach, beforeEach, expect, test } from "bun:test"
|
||||
import { createCipheriv, createHash, randomBytes } from "node:crypto"
|
||||
import { mkdtempSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { join, sep } from "node:path"
|
||||
import { TraeCNAuthPlugin, _internal } from "./index.mjs"
|
||||
import { fakeTrae, json, signedIn } from "./fake.mjs"
|
||||
|
||||
@@ -142,16 +142,35 @@ test("the client's codec decodes what it encodes, and refuses another header", (
|
||||
|
||||
test("where each OS keeps the client's storage.json", () => {
|
||||
const p = _internal.clientStoragePaths
|
||||
expect(p("darwin", "/Users/a", {})).toEqual(["/Users/a/Library/Application Support/Trae CN/User/globalStorage/storage.json"])
|
||||
const w = p("win32", "/h", { APPDATA: "/h/Roam" })
|
||||
expect(w).toEqual([
|
||||
// the paths are joined with this system's separator: the composition is
|
||||
// what is checked, so they are read as one system spells them
|
||||
const same = (ps) => ps.map((x) => x.replaceAll(sep, "/"))
|
||||
expect(same(p("darwin", "/Users/a", {}))).toEqual(["/Users/a/Library/Application Support/Trae CN/User/globalStorage/storage.json"])
|
||||
expect(same(p("win32", "/h", { APPDATA: "/h/Roam" }))).toEqual([
|
||||
"/h/Roam/Trae CN/User/globalStorage/storage.json",
|
||||
"/h/Roam/trae-cn/User/globalStorage/storage.json",
|
||||
"/h/AppData/Roaming/Trae CN/User/globalStorage/storage.json",
|
||||
"/h/AppData/Roaming/trae-cn/User/globalStorage/storage.json",
|
||||
])
|
||||
expect(p("linux", "/home/a", {})[0]).toBe("/home/a/.config/trae-cn/User/globalStorage/storage.json")
|
||||
expect(p("linux", "/home/a", { XDG_CONFIG_HOME: "/x" })[0]).toBe("/x/trae-cn/User/globalStorage/storage.json")
|
||||
expect(same(p("linux", "/home/a", {}))[0]).toBe("/home/a/.config/trae-cn/User/globalStorage/storage.json")
|
||||
expect(same(p("linux", "/home/a", { XDG_CONFIG_HOME: "/x" }))[0]).toBe("/x/trae-cn/User/globalStorage/storage.json")
|
||||
// a root named twice is asked once: APPDATA the same as the home's own
|
||||
expect(same(p("win32", "/h", { APPDATA: "/h/AppData/Roaming" }))).toEqual([
|
||||
"/h/AppData/Roaming/Trae CN/User/globalStorage/storage.json",
|
||||
"/h/AppData/Roaming/trae-cn/User/globalStorage/storage.json",
|
||||
])
|
||||
// and a different APPDATA is a root of its own, beside the home's
|
||||
expect(same(p("win32", "/h", { APPDATA: "/other/Roam" }))).toEqual([
|
||||
"/other/Roam/Trae CN/User/globalStorage/storage.json",
|
||||
"/other/Roam/trae-cn/User/globalStorage/storage.json",
|
||||
"/h/AppData/Roaming/Trae CN/User/globalStorage/storage.json",
|
||||
"/h/AppData/Roaming/trae-cn/User/globalStorage/storage.json",
|
||||
])
|
||||
// no APPDATA at all: the home's own alone
|
||||
expect(same(p("win32", "/h", {}))).toEqual([
|
||||
"/h/AppData/Roaming/Trae CN/User/globalStorage/storage.json",
|
||||
"/h/AppData/Roaming/trae-cn/User/globalStorage/storage.json",
|
||||
])
|
||||
})
|
||||
|
||||
test("this machine's OS as the client names it", () => {
|
||||
|
||||
Reference in New Issue
Block a user