fix(tree): stop rendering the base directory as a folder row
A workspace with extra folders used to grow one folder row per directory, including its own base directory. For a cloud workspace the base is the locally generated mirror (`wmvl31c7ilkuc`), so the sidebar showed that id as a folder name and hid every session owned by the workspace inside it — one cloud project read as a project nested inside itself. The base directory is now the workspace row itself: `nodes[].sessions` keeps its sessions and only real extras become folder rows. `folderNode` no longer takes `isBase`, so a mirror id can never be labelled as a folder again, and a workspace without extras keeps the exact pre-folders node shape. Adds a regression test covering the mirror case (extra folder only, base sessions on the workspace, no `wmvl31c7ilkuc` label) and documents the change in CHANGELOG. typecheck 0 errors, 290 tests pass.
This commit is contained in:
parent
36b9cb2bc0
commit
571638b836
|
|
@ -34,9 +34,16 @@
|
||||||
- `parseFolderEntry` 允许缺 `folders` 字段(不再连带丢掉 members),`remoteSubpath` 与
|
- `parseFolderEntry` 允许缺 `folders` 字段(不再连带丢掉 members),`remoteSubpath` 与
|
||||||
`joinSubpath` 对绝对/盘符/UNC 输入的判定统一;`joinSubpath` 额外拒绝 `C:foo`。
|
`joinSubpath` 对绝对/盘符/UNC 输入的判定统一;`joinSubpath` 额外拒绝 `C:foo`。
|
||||||
|
|
||||||
|
### 侧栏文件夹行
|
||||||
|
- 工作区自己的目录不再渲染成一条文件夹行。以前只要工作区挂了额外文件夹,它就会多出
|
||||||
|
一条以目录末段命名的行;云端工作区的路径是镜像目录,于是侧栏出现 `wmvl31c7ilkuc`
|
||||||
|
这样的内部 id,并且工作区自身的会话被藏进这条行里,看起来像「一个项目套在它自己里面」。
|
||||||
|
- 现在只有真正额外挂进来的文件夹才有行,工作区自己的会话直接列在标题下方;没有额外
|
||||||
|
文件夹时节点形状与引入文件夹功能之前完全一致。
|
||||||
|
|
||||||
### 测试与工程
|
### 测试与工程
|
||||||
- 新增 `tests/folders-cas.test.ts`、`tests/folders-persist.test.ts`、`tests/remote-paths.test.ts`
|
- 新增 `tests/folders-cas.test.ts`、`tests/folders-persist.test.ts`、`tests/remote-paths.test.ts`
|
||||||
覆盖上述回归点;`tsc -p tsconfig.json` / `tsconfig.client.json` 与 288 个 vitest 用例全部通过。
|
覆盖上述回归点;`tsc -p tsconfig.json` / `tsconfig.client.json` 与 290 个 vitest 用例全部通过。
|
||||||
- `tsdown.config.ts` 关闭客户端 sourcemap,`lib/client.js.map`(内嵌完整源码)已从构建产物移除;
|
- `tsdown.config.ts` 关闭客户端 sourcemap,`lib/client.js.map`(内嵌完整源码)已从构建产物移除;
|
||||||
`.gitignore` 补 `*.map` / `*.tsbuildinfo` / `dist/` / `coverage/` / `tools/_tmp/`,并取消对
|
`.gitignore` 补 `*.map` / `*.tsbuildinfo` / `dist/` / `coverage/` / `tools/_tmp/`,并取消对
|
||||||
`docs/` 的忽略,把 `remote-ssh-integration-plan.md` 纳入版本控制。
|
`docs/` 的忽略,把 `remote-ssh-integration-plan.md` 纳入版本控制。
|
||||||
|
|
|
||||||
|
|
@ -1557,18 +1557,17 @@ window.__ModuleLoader__.load({
|
||||||
if (bucket === void 0) byFolder.set(owner, [node]);
|
if (bucket === void 0) byFolder.set(owner, [node]);
|
||||||
else bucket.push(node);
|
else bucket.push(node);
|
||||||
}
|
}
|
||||||
const folderNode = (path, isBase) => {
|
const folderNode = (path) => {
|
||||||
const owned = isBase ? base : byFolder.get(path) ?? [];
|
|
||||||
return {
|
return {
|
||||||
path,
|
path,
|
||||||
label: labels.get(path) ?? folderLabel(path),
|
label: labels.get(path) ?? folderLabel(path),
|
||||||
isRoot: samePath(path, root),
|
isRoot: samePath(path, root),
|
||||||
expanded: collapsedFolders === void 0 || !collapsedFolders.has(folderKey(workspaceId, path)),
|
expanded: collapsedFolders === void 0 || !collapsedFolders.has(folderKey(workspaceId, path)),
|
||||||
isBase,
|
isBase: false,
|
||||||
sessions: owned
|
sessions: byFolder.get(path) ?? []
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
const folders = [folderNode(workspacePath, true), ...extras.map((path) => folderNode(path, false))];
|
const folders = extras.map((path) => folderNode(path));
|
||||||
const rootIndex = folders.findIndex((folder) => folder.isRoot);
|
const rootIndex = folders.findIndex((folder) => folder.isRoot);
|
||||||
if (rootIndex > 0) {
|
if (rootIndex > 0) {
|
||||||
const [rootFolder] = folders.splice(rootIndex, 1);
|
const [rootFolder] = folders.splice(rootIndex, 1);
|
||||||
|
|
@ -8068,11 +8067,20 @@ window.__ModuleLoader__.load({
|
||||||
onArchive: onSessionArchive
|
onArchive: onSessionArchive
|
||||||
}, session.id))
|
}, session.id))
|
||||||
});
|
});
|
||||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RowGroup, {
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(RowGroup, {
|
||||||
expanded: workspace.expanded,
|
expanded: workspace.expanded,
|
||||||
className: "wgTreeChildren",
|
className: "wgTreeChildren",
|
||||||
animate: animate && folders.length + workspace.sessions.length <= ANIMATION_ROW_CAP,
|
animate: animate && folders.length + workspace.sessions.length <= ANIMATION_ROW_CAP,
|
||||||
children: folders.map((folder) => {
|
children: [workspace.sessions.map((session) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SessionRow, {
|
||||||
|
node: session,
|
||||||
|
currentId: current,
|
||||||
|
now,
|
||||||
|
t,
|
||||||
|
onOpen,
|
||||||
|
onRename: onSessionRename,
|
||||||
|
onFork,
|
||||||
|
onArchive: onSessionArchive
|
||||||
|
}, session.id)), folders.map((folder) => {
|
||||||
const key = folderKey(workspace.workspaceId, folder.path);
|
const key = folderKey(workspace.workspaceId, folder.path);
|
||||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
||||||
role: "group",
|
role: "group",
|
||||||
|
|
@ -8112,7 +8120,7 @@ window.__ModuleLoader__.load({
|
||||||
}, session.id))
|
}, session.id))
|
||||||
})]
|
})]
|
||||||
}, key);
|
}, key);
|
||||||
})
|
})]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/** One category section: header row + expanded workspace folders. */
|
/** One category section: header row + expanded workspace folders. */
|
||||||
|
|
@ -8307,9 +8315,18 @@ window.__ModuleLoader__.load({
|
||||||
onArchive: () => {}
|
onArchive: () => {}
|
||||||
}, session.id))
|
}, session.id))
|
||||||
});
|
});
|
||||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
||||||
role: "group",
|
role: "group",
|
||||||
children: folders.map((folder) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
children: [workspace.sessions.map((session) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SessionRow, {
|
||||||
|
node: session,
|
||||||
|
currentId: current,
|
||||||
|
now,
|
||||||
|
t,
|
||||||
|
onOpen: open,
|
||||||
|
onRename: () => {},
|
||||||
|
onFork: () => {},
|
||||||
|
onArchive: () => {}
|
||||||
|
}, session.id)), folders.map((folder) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
||||||
role: "group",
|
role: "group",
|
||||||
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FolderRow, {
|
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(FolderRow, {
|
||||||
node: folder,
|
node: folder,
|
||||||
|
|
@ -8332,7 +8349,7 @@ window.__ModuleLoader__.load({
|
||||||
onArchive: () => {}
|
onArchive: () => {}
|
||||||
}, session.id))
|
}, session.id))
|
||||||
})]
|
})]
|
||||||
}, folderKey(workspace.workspaceId, folder.path)))
|
}, folderKey(workspace.workspaceId, folder.path)))]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,10 @@ export interface WorkspaceGroupNode {
|
||||||
sessions: readonly SessionNode[];
|
sessions: readonly SessionNode[];
|
||||||
/**
|
/**
|
||||||
* Folder rows, present only when the workspace carries at least one extra
|
* Folder rows, present only when the workspace carries at least one extra
|
||||||
* folder: root first, then stored order, base included. Absent means "this
|
* folder: root first, then stored order. The base directory is never a row —
|
||||||
* workspace has exactly one directory", the plain pre-folders node shape.
|
* it is the workspace row itself, and its sessions live in {@link sessions}.
|
||||||
|
* Absent means "this workspace has exactly one directory", the plain
|
||||||
|
* pre-folders node shape.
|
||||||
*/
|
*/
|
||||||
folders?: readonly FolderNode[];
|
folders?: readonly FolderNode[];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2366,6 +2366,19 @@ function WorkspaceSubtree({ workspace, current, now, t, animate, onOpen, onSessi
|
||||||
className="wgTreeChildren"
|
className="wgTreeChildren"
|
||||||
animate={animate && folders.length + workspace.sessions.length <= ANIMATION_ROW_CAP}
|
animate={animate && folders.length + workspace.sessions.length <= ANIMATION_ROW_CAP}
|
||||||
>
|
>
|
||||||
|
{workspace.sessions.map((session) => (
|
||||||
|
<SessionRow
|
||||||
|
key={session.id}
|
||||||
|
node={session}
|
||||||
|
currentId={current}
|
||||||
|
now={now}
|
||||||
|
t={t}
|
||||||
|
onOpen={onOpen}
|
||||||
|
onRename={onSessionRename}
|
||||||
|
onFork={onFork}
|
||||||
|
onArchive={onSessionArchive}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
{folders.map((folder) => {
|
{folders.map((folder) => {
|
||||||
const key = folderKey(workspace.workspaceId, folder.path)
|
const key = folderKey(workspace.workspaceId, folder.path)
|
||||||
return (
|
return (
|
||||||
|
|
@ -2673,6 +2686,19 @@ function SearchSubtree({ workspace, current, now, open, t }: {
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div role="group">
|
<div role="group">
|
||||||
|
{workspace.sessions.map((session) => (
|
||||||
|
<SessionRow
|
||||||
|
key={session.id}
|
||||||
|
node={session}
|
||||||
|
currentId={current}
|
||||||
|
now={now}
|
||||||
|
t={t}
|
||||||
|
onOpen={open}
|
||||||
|
onRename={() => {}}
|
||||||
|
onFork={() => {}}
|
||||||
|
onArchive={() => {}}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
{folders.map((folder) => (
|
{folders.map((folder) => (
|
||||||
<div key={folderKey(workspace.workspaceId, folder.path)} role="group">
|
<div key={folderKey(workspace.workspaceId, folder.path)} role="group">
|
||||||
<FolderRow
|
<FolderRow
|
||||||
|
|
|
||||||
|
|
@ -121,8 +121,10 @@ export interface WorkspaceGroupNode {
|
||||||
sessions: readonly SessionNode[]
|
sessions: readonly SessionNode[]
|
||||||
/**
|
/**
|
||||||
* Folder rows, present only when the workspace carries at least one extra
|
* Folder rows, present only when the workspace carries at least one extra
|
||||||
* folder: root first, then stored order, base included. Absent means "this
|
* folder: root first, then stored order. The base directory is never a row —
|
||||||
* workspace has exactly one directory", the plain pre-folders node shape.
|
* it is the workspace row itself, and its sessions live in {@link sessions}.
|
||||||
|
* Absent means "this workspace has exactly one directory", the plain
|
||||||
|
* pre-folders node shape.
|
||||||
*/
|
*/
|
||||||
folders?: readonly FolderNode[]
|
folders?: readonly FolderNode[]
|
||||||
}
|
}
|
||||||
|
|
@ -385,25 +387,24 @@ function applyFolders(
|
||||||
if (bucket === undefined) byFolder.set(owner, [node])
|
if (bucket === undefined) byFolder.set(owner, [node])
|
||||||
else bucket.push(node)
|
else bucket.push(node)
|
||||||
}
|
}
|
||||||
const folderNode = (path: string, isBase: boolean): FolderNode => {
|
const folderNode = (path: string): FolderNode => {
|
||||||
const owned = isBase ? base : (byFolder.get(path) ?? [])
|
|
||||||
return {
|
return {
|
||||||
path,
|
path,
|
||||||
label: labels.get(path) ?? folderLabel(path),
|
label: labels.get(path) ?? folderLabel(path),
|
||||||
isRoot: samePath(path, root),
|
isRoot: samePath(path, root),
|
||||||
expanded: collapsedFolders === undefined || !collapsedFolders.has(folderKey(workspaceId, path)),
|
expanded: collapsedFolders === undefined || !collapsedFolders.has(folderKey(workspaceId, path)),
|
||||||
isBase,
|
// The base directory is the workspace row itself, so every row here is an
|
||||||
|
// extra folder: a mirror id must never be dressed up as one, and none of
|
||||||
|
// them can be removed from the workspace.
|
||||||
|
isBase: false,
|
||||||
// Every owned session is kept on the node so the row's count stays honest
|
// Every owned session is kept on the node so the row's count stays honest
|
||||||
// while the folder is collapsed; the RowGroup does the hiding.
|
// while the folder is collapsed; the RowGroup does the hiding.
|
||||||
sessions: owned,
|
sessions: byFolder.get(path) ?? [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const folders: FolderNode[] = [
|
const folders: FolderNode[] = extras.map(path => folderNode(path))
|
||||||
folderNode(workspacePath, true),
|
|
||||||
...extras.map(path => folderNode(path, false)),
|
|
||||||
]
|
|
||||||
// Root first, then stored order: moving the root row to the front keeps the
|
// Root first, then stored order: moving the root row to the front keeps the
|
||||||
// remaining rows (base included) in their stored order.
|
// remaining rows in their stored order.
|
||||||
const rootIndex = folders.findIndex(folder => folder.isRoot)
|
const rootIndex = folders.findIndex(folder => folder.isRoot)
|
||||||
if (rootIndex > 0) {
|
if (rootIndex > 0) {
|
||||||
const [rootFolder] = folders.splice(rootIndex, 1)
|
const [rootFolder] = folders.splice(rootIndex, 1)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import { describe, expect, it } from 'vitest'
|
||||||
import type { SessionListState, SessionSummary } from '@deepseek-ai/dsh-api-session-controller/client'
|
import type { SessionListState, SessionSummary } from '@deepseek-ai/dsh-api-session-controller/client'
|
||||||
import type { WorkspaceView } from '@deepseek-ai/dsh-api-workspace-controller/client'
|
import type { WorkspaceView } from '@deepseek-ai/dsh-api-workspace-controller/client'
|
||||||
import { deriveGroups, deriveSearchGroups, deriveTopLevel } from '../src/client/tree.ts'
|
import { deriveGroups, deriveSearchGroups, deriveTopLevel } from '../src/client/tree.ts'
|
||||||
|
import type { FoldersDocument } from '../src/core/folders.ts'
|
||||||
import type { GroupsConfig, ManualGroups } from '../src/core/types.ts'
|
import type { GroupsConfig, ManualGroups } from '../src/core/types.ts'
|
||||||
|
|
||||||
const CONFIG: GroupsConfig = {
|
const CONFIG: GroupsConfig = {
|
||||||
|
|
@ -215,3 +216,72 @@ describe('deriveTopLevel', () => {
|
||||||
expect(top.map(w => w.workspaceId)).toEqual(['ws-c', 'ws-a', 'ws-b'])
|
expect(top.map(w => w.workspaceId)).toEqual(['ws-c', 'ws-a', 'ws-b'])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regression: a workspace whose base directory is a remote mirror used to grow
|
||||||
|
* a folder row labelled with the mirror's leaf segment (`wmvl31c7ilkuc`) and
|
||||||
|
* then hide all of the workspace's own sessions behind it, so one cloud
|
||||||
|
* project looked like a project nested inside itself.
|
||||||
|
*/
|
||||||
|
describe('folder rows never include the base directory', () => {
|
||||||
|
const MIRROR = 'C:/Users/zcol/.dsh/remote-workspaces/wmvl31c7ilkuc'
|
||||||
|
const LOCAL = 'C:/Users/zcol/云端记忆系统'
|
||||||
|
|
||||||
|
function sessionIn(id: string, cwd: string): SessionSummary {
|
||||||
|
return { ...session(id, `会话-${id}`), cwd } as unknown as SessionSummary
|
||||||
|
}
|
||||||
|
|
||||||
|
function state(byId: Record<string, SessionSummary>): SessionListState {
|
||||||
|
return {
|
||||||
|
ids: Object.keys(byId),
|
||||||
|
byId,
|
||||||
|
current: undefined,
|
||||||
|
phase: 'ready',
|
||||||
|
subagentsByParent: {},
|
||||||
|
} as unknown as SessionListState
|
||||||
|
}
|
||||||
|
|
||||||
|
const workspaces = [
|
||||||
|
workspace('ws-o', MIRROR, '插件项目', ['s-cloud']),
|
||||||
|
workspace('ws-m', LOCAL, '云端记忆系统', ['s-local']),
|
||||||
|
]
|
||||||
|
const folders: FoldersDocument = {
|
||||||
|
version: 1,
|
||||||
|
workspaces: {
|
||||||
|
'ws-o': {
|
||||||
|
folders: [],
|
||||||
|
members: [{ path: LOCAL, workspaceId: 'ws-m', kind: 'local' }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
const list = state({
|
||||||
|
's-cloud': sessionIn('s-cloud', `${MIRROR}/src`),
|
||||||
|
's-local': sessionIn('s-local', `${LOCAL}/docs`),
|
||||||
|
})
|
||||||
|
const noManual: ManualGroups = { categories: [], assignments: {} }
|
||||||
|
// Sessions only materialize on an expanded row, so the owner starts open.
|
||||||
|
const view = { expandedCategories: [], expandedWorkspaces: ['ws-o'] }
|
||||||
|
|
||||||
|
it('renders only the extra folder and keeps base sessions on the workspace row', () => {
|
||||||
|
const groups = deriveGroups(list, workspaces, [], CONFIG, view, noManual, new Map(), folders)
|
||||||
|
const node = groups.flatMap(group => group.workspaces).find(w => w.workspaceId === 'ws-o')
|
||||||
|
expect(node).toBeDefined()
|
||||||
|
expect(node!.folders?.map(f => f.path)).toEqual([LOCAL])
|
||||||
|
expect(node!.folders?.every(f => f.isBase === false)).toBe(true)
|
||||||
|
// The mirror id must never leak into a folder label.
|
||||||
|
expect(node!.folders?.map(f => f.label) ?? []).not.toContain('wmvl31c7ilkuc')
|
||||||
|
// Base-owned sessions stay on the workspace itself.
|
||||||
|
expect(node!.sessions.map(s => s.id)).toEqual(['s-cloud'])
|
||||||
|
expect(node!.folders?.[0]?.sessions.map(s => s.id)).toEqual(['s-local'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('keeps the pre-folders node shape when the workspace has no extras', () => {
|
||||||
|
const groups = deriveGroups(list, workspaces, [], CONFIG, view, noManual, new Map(), {
|
||||||
|
version: 1,
|
||||||
|
workspaces: {},
|
||||||
|
})
|
||||||
|
const node = groups.flatMap(group => group.workspaces).find(w => w.workspaceId === 'ws-o')
|
||||||
|
expect(node?.folders).toBeUndefined()
|
||||||
|
expect(node?.sessions.map(s => s.id)).toEqual(['s-cloud'])
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue