merge #929: fix(tree): 改名/删除的调解覆盖后台会话的页签 + 标题只在派生自文件名时跟随(#915 后续)

This commit is contained in:
Menghuan1918 committed 2026-10-26 15:00:55 +08:00
commit 22eb6ebddf
7 files changed
+223 -48

No files matched your search

+5
View File
@@ -85,6 +85,11 @@
- **幽灵输入改为精确清扫**:冷恢复(`sidechat.prompt` → `agents.resume`)此前没有 create 路径那道 `inbox.clear()` 围栏。现在改为 `dropInheritedGhosts`——只折**继承前缀**得到幽灵 id 集合,再逐个 `agent.inbox.remove(id)`,精确且幂等,不会误杀「用户在线程里排队、宿主重启后尚未领取」的合法输入。同时确认幽灵的来源比原先记录的更宽:父会话 mid-turn 且工具有未返回调用时,种子被截断在 `turn/start` **之前**,而 inbox 的领取 splice 发生在 `turn/start` **之后**,所以父会话本轮开头已领取的输入在种子折叠里仍是 pending。
- 🧪 测试:新增 `tests/sidechat-push.spec.ts`、`tests/use-sidechat-push.spec.ts`、`tests/sidechat-transcript.spec.ts`;`tests/sidechat-core.spec.ts` / `tests/sidechat-routes.spec.ts` / `tests/sidechat-view.spec.tsx` 大幅增补(含真实 `Session.create` + 真实 `SessionProjectionRegistry` 的种子验证);挂载 lane 的 sidechat 宿主路由烟测同步。
- 🏷 **改名只在标题本来就来自文件名时才跟着改**([#915](https://github.com/omdsh-dev/DSH-better-sidebar/issues/915) 后续):页签调解此前**无条件**把标题写成新的基名,于是**作者自设的标题**会被一次改名悄悄替换掉——宿主的 agent-opens 推送就带着模型自己给的名字(`use-host-feeds` → `openFile(scope, path, title)`),消费插件也可以自己标名字。现在只有标题**等于该页签路径的基名**(也就是打开时由文件名派生的那种)才跟着新名字走;目录改名本来就不动后代(后代基名没变),两处口径因此一致。原生承载面的 `SidebarSurface.pathTabs()` 随之交出每个记录的 `title`(`NativePathTab` 新增字段)。
- 🧪 测试:`tests/editor-unsaved-guard.spec.tsx` 新增 1 例(同一个文件的两个页签:派生标题跟着走、自设标题原样保留,底部工作台那一路一并断言);`tests/native-surface.spec.ts` 的枚举断言带上 `title`。判别性实测:把判定换回无条件改写 → 该用例红。
- 🧷 **改名 / 删除的页签调解覆盖后台会话的底部工作台**([#915](https://github.com/omdsh-dev/DSH-better-sidebar/issues/915) 后续):上一批(#912)让调解同时走**原生右侧栏**的记录,但底部工作台那一路仍只读**当前会话**的快照(`pathTabsOf` 吃 `store.getSnapshot()`),而底部工作台是**按会话**存的——后台会话里开着的文件页(`target: 'bottom'` 的打开、或在原生承载面之前持久化下来的布局)既不跟着改名、也不随删除关闭,切回去的下一次保存照样把改名掉的文件 / 删掉的文件重建出来。现在枚举走 `store.getSessionStates()`(**每个已缓存会话**都在内),每行都带上**自己的会话**;写入也不再落到「碰巧在屏」的那个会话上——`updateTab` / `closeTab` 遇到**不在屏的会话**改走定向通道(`store.reduceFor`,与定向 `openTab(seed, scope)` 同一条路:写进那个会话的自己的布局,不发布、不通知),当前会话继续走发布通道、界面照常重渲染。删除仍先问未保存的草稿,且问题问在**内容会话**里(草稿注册表的键是 `sessionId::tabId`)。
- 🧪 测试:`tests/editor-unsaved-guard.spec.tsx` 新增 2 例(后台会话的底部页面在改名后跟着走、且当前会话既没被写也没被重新发布;删除时按**它自己的**草稿先问、关在它自己的布局里)。判别性实测:把枚举收回「只看当前会话」→ 2 条红;把定向写入换回发布通道 → 2 条红;把草稿确认的会话换成当前会话 → 删除那条红。
- 🛡 **三处静默数据问题**([#898](https://github.com/omdsh-dev/DSH-better-sidebar/issues/898) / [#899](https://github.com/omdsh-dev/DSH-better-sidebar/issues/899) / [#900](https://github.com/omdsh-dev/DSH-better-sidebar/issues/900)):① 编辑器草稿守卫的记账键从**裸 tab id** 改成 **`会话::tab id`**——原生右栏每个会话的 id 都从 `tab1` 重新计数、底部工作台对同一路径在各会话复用 `editor:<path>`,两套身份原先挤在同一个键上,**另一个会话打开编辑器就会把本会话的草稿记录一并删掉**(刷新时静默丢失);② 面包屑折叠行(`a/b/c` 压成一行)的重命名此前提交的是**链头**目录、与预填名不一致——不改字直接回车等于把父目录改名,现在落到链尾;③ 无 BOM 的 16 位小端数据(低幅采样表 / 未压缩音频数据段这类)不再被判成 UTF-16 文本打开、保存后整份改写(奇数长度还会丢尾字节):新的文本闸门要求 ≥90% 的单元是合法文本单元。同批还带了 dev 新增代码的一轮去重(内部导出 `runGitRaw` / `bottomTerminalKey` / `formatModelRoute` / `dirtyCountForSession` 收敛,仓内调用点同批改完)。(贡献者 PR [#901](https://github.com/omdsh-dev/DSH-better-sidebar/pull/901) @UNscientific-9)
- 🧪 测试:`tests/editor-unsaved-guard.spec.tsx`(跨会话草稿:第二个会话挂同一个原生 id,既不能清掉、也不能确认掉第一个会话的草稿)、`tests/file-tree-compact-fold.spec.tsx`(折叠行重命名断言落到链尾:`/tmp/a/b/c` → `renamed`)、`tests/text-encoding.spec.ts`(uint16LE 采样表 / WAV `data` 段 / 奇数长度判二进制,真 UTF-16LE/BE 仍是文本)。
+12 -2
View File
@@ -779,7 +779,10 @@ interface BetterSidebarService {
*/
openTab(seed: OpenTabSeed, scope?: SessionScope): void
/** 关闭一个 tab(未知 id 严格 no-op,无状态搅动);scope(v0.12.0+)
* 随回调传递(含可选 cwd),缺省为 { sessionId: 当前 } */
* 随回调传递(含可选 cwd),缺省为 { sessionId: 当前 }。
* scope 指的是**不在屏**的会话时(v0.26.0+),那一行在**它自己的**布局里关闭
* ——走定向通道(不发布、不通知),与定向 `openTab(seed, scope)` 同一条路;
* 这正是文件树删除调解能覆盖后台会话页面的机制。不传 scope 行为不变。 */
closeTab(tabId: string, scope?: SessionScope): void
/** 订阅注册表变化(register/dispose 时触发) */
subscribe(listener: () => void): () => void
@@ -811,7 +814,14 @@ interface BetterSidebarService {
* 下一次渲染当渲染垃圾抹掉,宿主**真正**发起的新导航(新修订)仍按地址
* 改写记录。文件树的重命名 / 删除调解会一并处理原生承载面上的页签(跟着
* 改址 / 按既有的未保存确认关闭;枚举由承载面内部交回服务,不是公开方法),
* 消费插件不需要改任何代码。 */
* 消费插件不需要改任何代码。
* **指到不在屏的会话时写进它自己的布局**(v0.26.0+):这类写入走定向通道
* (不发布、不通知),所以文件树的重命名调解同样覆盖**后台会话**底部工作台里的
* 页面,而当前会话继续走发布通道、界面照常重渲染。
* **标题只在它本来就来自文件名时才跟着改名走**(v0.26.0+):页签调解把**派生
* 自基名**的标题换成新基名,而 `openFile(scope, path, title)` 或 `openTab` 里
* **作者自设的标题**(宿主的 agent-opens 推送就带一个)原样保留——名字是你标
* 的,就不该被一次文件改名换掉。 */
updateTab(tabId: string, patch: { title?: string; path?: string; meta?: unknown }, sessionId?: string): void
/** 激活一个已打开的 tab(tab 栏点击路径;触发 descriptor.onActivate;
* 未知 id 严格 no-op);scope(v0.12.0+)随回调传递,同 closeTab */
+4
View File
@@ -361,6 +361,10 @@ export function createNativeTabRecords(): NativeTabRecords {
cwd: entry.scope.cwd,
id: entry.tab.id,
path,
// The chip's title travels with the row: the rename
// reconciliation retitles a page only when that title was
// derived from the file name (see tree-mutations).
title: entry.tab.title,
})
}
}
+48 -4
View File
@@ -561,6 +561,11 @@ export interface NativePathTab {
/** The path the tab is bound to — a file path, or a browser tab's address
* (a url seed is stored on the same field). */
path: string
/** The chip's current title. The rename reconciliation reads it to tell a
* title the tree DERIVED from the file name (the basename it wrote on open)
* from one its author chose — a model-driven open names its own title, and
* that is not the tree's to rewrite. */
title: string
}
/**
@@ -704,6 +709,11 @@ export interface BetterSidebarService {
* strict no-op (no state churn, no callbacks). `scope` (v0.12.0+) rides
* to the callback (its optional cwd included); absent, the callback gets
* `{ sessionId }` of the active session.
*
* v0.26.0+: a scope naming a session that is **not the one on screen** closes
* the row in THAT session's layout through the targeted channel (no publish,
* no notify), which is how the file tree's delete reconciliation reaches a
* background conversation's pages. Without a scope nothing changes.
*/
closeTab(tabId: string, scope?: SessionScope): void
/** Subscribe to registry changes (register/dispose). */
@@ -735,6 +745,13 @@ export interface BetterSidebarService {
* carried (#826) is dropped with it, because that line belongs to the
* navigation that delivered the file — an in-place switch or a rename that
* kept it would send the next file to the previous file's line.
*
* v0.26.0+: a `sessionId` that is **not the session on screen** patches that
* session's own layout through the targeted channel (no publish, no notify —
* the same route a targeted `openTab(seed, scope)` takes), so the file tree's
* rename reconciliation reaches a background conversation's pages instead of
* resolving them against the active session. The active session keeps the
* publishing path, and an omitted `sessionId` behaves exactly as before.
*/
updateTab(tabId: string, patch: { title?: string; path?: string; meta?: unknown }, sessionId?: string): void
/**
@@ -1290,6 +1307,23 @@ export function createBetterSidebarService(store: SidebarStore): BetterSidebarSe
else if (activated !== undefined) safeCall(() => descriptor.onActivate?.(activated!, callbackScope))
}
/**
* Apply a store mutation in the session it names.
*
* A session that is not on screen takes the TARGETED channel (`reduceFor`),
* the same one a targeted `openTab(seed, scope)` uses: it writes that
* session's own state and persists it without touching the published
* snapshot. The publishing channel cannot stand in for it — the row is not in
* the ACTIVE session's tree, so the reduce is a silent no-op at best, and
* patching a same-numbered row of the active session is the other possible
* outcome. The active session keeps the publishing path so the shell
* re-renders with the new title/path.
*/
const reduceInSession = (sessionId: string, reducer: (state: SidebarState) => SidebarState): void => {
if (sessionId === store.getSnapshot().sessionId) store.reduce(reducer)
else store.reduceFor(sessionId, reducer)
}
const closeTab = (tabId: string, scope?: SessionScope): void => {
const sessionId = scope?.sessionId ?? store.getSnapshot().sessionId
if (surface !== undefined && sessionId !== undefined) {
@@ -1311,7 +1345,7 @@ export function createBetterSidebarService(store: SidebarStore): BetterSidebarSe
}
}
let closed: SidebarTab | undefined
store.reduce((state) => {
const closeOne = (state: SidebarState): SidebarState => {
// Unknown tab ids are a strict no-op: no state churn, no notify, no
// pointless localStorage rewrite (mirrors updateTab's short-circuit).
if (!tabOpenIn(state, tabId)) return state
@@ -1319,7 +1353,11 @@ export function createBetterSidebarService(store: SidebarStore): BetterSidebarSe
const leaf = leafWithTab(state.bottomSplits, tabId)
closed = leaf?.tabs.find(tab => tab.id === tabId)
return closeTabReducer(state, paneId, tabId)
})
}
// The row lives in ITS session's tree: an explicit scope that is not on
// screen has to close it there (see `reduceInSession`).
if (sessionId === undefined) store.reduce(closeOne)
else reduceInSession(sessionId, closeOne)
if (closed !== undefined) {
const sessionId = scope?.sessionId ?? store.getSnapshot().sessionId
if (sessionId !== undefined) {
@@ -1343,11 +1381,17 @@ export function createBetterSidebarService(store: SidebarStore): BetterSidebarSe
sessionId?: string,
): void => {
if (surface?.update(tabId, patch, sessionId) === true) return
store.reduce((state) => patchTab(state, tabId, {
const patchOne = (state: SidebarState): SidebarState => patchTab(state, tabId, {
...(patch.title !== undefined ? { title: patch.title } : {}),
...(patch.path !== undefined ? { path: patch.path } : {}),
...(patch.meta !== undefined ? { meta: patch.meta } : {}),
}))
})
// A named session that is not on screen is patched in ITS own state (a
// background conversation's file page under a rename — see
// `reduceInSession`); without one the current session keeps the publishing
// path it always had.
if (sessionId === undefined) store.reduce(patchOne)
else reduceInSession(sessionId, patchOne)
}
/** Activate an open tab (the tab-bar activation path; fires onActivate). */
+67 -36
View File
@@ -15,12 +15,18 @@
* a delete must close every tab at or under the removed path. Both ride the
* SERVICE paths (`updateTab`/`closeTab`) rather than direct state reducers so
* the registered lifecycle callbacks fire like any other tab mutation.
*
* The walk covers EVERY session the store has cached, not just the one on
* screen: the bottom workbench is per session, and a background conversation's
* file page has the same next-save hazard. Each row therefore names its own
* session, and the writes go to that session (`updateTab`/`closeTab` take the
* targeted channel for a session that is not on screen).
*/
import type { Context } from '../context-types.ts'
import type { NativePathTab } from './service.ts'
import { baseName, isWithinWorkspace, relativeTo, resolveSidebarPath } from './paths.ts'
import { confirmDiscardDraft } from './editor-dirty.ts'
import { allLeaves, type SidebarSnapshot, type SidebarStore } from './state.ts'
import { allLeaves, type SidebarStore } from './state.ts'
/** One open tab that carries a file path, and the space it lives in. */
interface PathTab {
@@ -36,13 +42,18 @@ interface PathTab {
absolute: string
/** The session this tab's EDITOR reads and writes in — the `scope.sessionId`
* its host registers the unsaved draft under, so it is the one the close
* guard has to name. Absent only for a bottom-workbench tab whose store has
* no session yet (the guard then reads conservatively rather than missing
* the record and closing a live draft without asking). */
* guard has to name. Absent only for a native tab whose address named no
* session (the guard then reads conservatively rather than missing the
* record and closing a live draft without asking). */
scopeSessionId: string | undefined
/** The native tab's seat session; absent for a bottom-workbench tab, whose
* updates resolve against the store's current session. */
sessionId?: string
/** The tab's current title — the rename reconciliation retitles a page only
* when this is the file name the tree itself wrote there. */
title: string
/** The session the tab is WRITTEN through: the native record's seat, or the
* bottom-workbench row's own session — every row names its session now, so a
* background conversation's pages are patched in place instead of resolving
* against whatever session happens to be on screen. */
sessionId: string
}
/**
@@ -110,28 +121,33 @@ export function clearRetargetedPath(key: string): void {
retargetedPaths.delete(key)
}
/** Every open tab that carries a file path, from BOTH tab spaces. */
function pathTabsOf(snapshot: SidebarSnapshot, native: readonly NativePathTab[]): PathTab[] {
/** Every open tab that carries a file path, from BOTH tab spaces — the bottom
* workbench of EVERY cached session, and the native records. */
function pathTabsOf(store: SidebarStore, native: readonly NativePathTab[]): PathTab[] {
const tabs: PathTab[] = []
const state = snapshot.state
if (state !== undefined) {
// A bottom-workbench row resolves its scope against the store's session, so
// that same session is the one its editor registered its draft under — the
// key's `?? ''` is only the marker's spelling for "no session".
const session = snapshot.sessionId ?? ''
// Every session the store has cached, not just the one on screen: a
// conversation the reader is not looking at can hold file pages of its own
// (a `target: 'bottom'` open, a layout persisted back when files landed in
// the workbench), and a rename/delete has to reach them too — the first save
// after switching back would otherwise recreate the renamed-away file, which
// is the very data problem this module exists to prevent. Each row therefore
// carries its OWN session: it is both the identity half of the rename marker
// and the channel its write goes through.
for (const [sessionId, state] of store.getSessionStates()) {
for (const leaf of allLeaves(state.bottomSplits)) {
for (const tab of leaf.tabs) {
// A bottom-workbench row carries an absolute path already, and it is the
// same string the tree hands this module — one spelling, both fields.
if (tab.path !== undefined) {
tabs.push({
key: pathTabKey(session, tab.id),
id: tab.id,
path: tab.path,
absolute: tab.path,
scopeSessionId: snapshot.sessionId,
})
}
if (tab.path === undefined) continue
tabs.push({
key: pathTabKey(sessionId, tab.id),
id: tab.id,
path: tab.path,
title: tab.title,
absolute: tab.path,
scopeSessionId: sessionId,
sessionId,
})
}
}
}
@@ -140,6 +156,7 @@ function pathTabsOf(snapshot: SidebarSnapshot, native: readonly NativePathTab[])
key: pathTabKey(tab.scopeSessionId, tab.id),
id: tab.id,
path: tab.path,
title: tab.title,
// A chat link opens its tab with the ADDRESS's path, and `fileAddressFor`
// spells that workspace-relative whenever it knows the cwd. Comparing it
// raw against the tree's absolute paths skipped exactly those tabs, so the
@@ -170,25 +187,37 @@ function movedPath(path: string, oldPath: string, newPath: string): string | und
return tail === '.' ? newPath : `${newPath}/${tail}`
}
/** Retarget tabs after `oldPath` became `newPath` (title follows the new
* base name, matching how openFile titles editor tabs).
/** Retarget tabs after `oldPath` became `newPath`.
*
* Files and anything under a renamed DIRECTORY are retargeted — the same
* subtree rule the delete path uses. The move is announced through
* {@link markRetargetedPath} so the editor keeps its document (and an unsaved
* draft) instead of reloading the new name. */
* subtree rule the delete path uses — in EVERY session the store has cached.
* The move is announced through {@link markRetargetedPath} so the editor keeps
* its document (and an unsaved draft) instead of reloading the new name.
*
* The TITLE follows only when it was DERIVED from the file name — an editor
* page opened the way the plugin opens one is titled with the basename, so a
* rename has to carry it along; a title its author chose is not the tree's to
* rewrite. The host's agent-opens push is the live case: the model asks for a
* file with a title of its own (`use-host-feeds` → `openFile(scope, path,
* title)`), and a consumer plugin may label a page itself. A directory rename
* never retitles a descendant anyway (their basenames do not change), so this
* is the same rule seen from the file side. */
export function retargetPathTabs(ctx: Context, store: SidebarStore, oldPath: string, newPath: string): void {
const service = ctx.get('betterSidebar')
if (service === undefined) return
// The tabs live in the snapshot's session: native ids restart per session.
const snapshot = store.getSnapshot()
for (const tab of pathTabsOf(snapshot, service.nativePathTabs())) {
for (const tab of pathTabsOf(store, service.nativePathTabs())) {
const moved = movedPath(tab.absolute, oldPath, newPath)
if (moved === undefined) continue
// The announcement has to match what the editor will see: it compares the
// path it holds (the tab's own spelling) with the one written here.
markRetargetedPath(tab.key, tab.path, moved)
service.updateTab(tab.id, { path: moved, title: baseName(moved) }, tab.sessionId)
service.updateTab(tab.id, {
path: moved,
// Only a DERIVED title follows the new name: `baseName(tab.path)` is the
// spelling the opener would have written, so a title that differs is one
// somebody chose.
...(tab.title === baseName(tab.path) ? { title: baseName(moved) } : {}),
}, tab.sessionId)
}
}
@@ -200,17 +229,19 @@ export function retargetPathTabs(ctx: Context, store: SidebarStore, oldPath: str
*
* The question is asked in the tab's OWN session: the draft registry is keyed
* by `sessionId::tabId`, so a bare id read would look up a same-numbered tab in
* some other session (or nothing at all) and close a live draft unprompted. */
* some other session (or nothing at all) and close a live draft unprompted.
* Every session the store has cached is walked (a background conversation's
* page would otherwise come back with its next save). */
export function closePathTabs(ctx: Context, store: SidebarStore, target: string, unsavedMessage: string): void {
const service = ctx.get('betterSidebar')
if (service === undefined) return
for (const tab of pathTabsOf(store.getSnapshot(), service.nativePathTabs())) {
for (const tab of pathTabsOf(store, service.nativePathTabs())) {
// `isWithinWorkspace` is true for the target itself too, so one test covers
// both "this exact file" and "anything under this directory".
if (!isWithinWorkspace(target, tab.absolute)) continue
if (!confirmDiscardDraft(tab.id, unsavedMessage, tab.scopeSessionId)) continue
// The tab is going away: a move announced for it can never be claimed.
clearRetargetedPath(tab.key)
service.closeTab(tab.id, tab.sessionId === undefined ? undefined : { sessionId: tab.sessionId })
service.closeTab(tab.id, { sessionId: tab.sessionId })
}
}
+82 -3
View File
@@ -298,19 +298,20 @@ describe('tree rename/delete reconciliation', () => {
return { store, service, records, close, context }
}
/** One editor record bound to a file, as a native open would mint it. */
/** One editor record bound to a file, as a native open would mint it. The
* title defaults to the file name, i.e. what an open derives on its own. */
const openNativeFile = (
records: ReturnType<typeof createNativeTabRecords>,
id: string,
path: string,
seat: { sessionId?: string; cwd?: string } = {},
seat: { sessionId?: string; cwd?: string; title?: string } = {},
): void => {
const sessionId = seat.sessionId ?? 'native-scope'
records.ensure({
sessionId,
id,
kind: 'editor',
title: 'a.ts',
title: seat.title ?? path.slice(path.lastIndexOf('/') + 1),
params: { path },
scope: seat.cwd === undefined ? { sessionId } : { sessionId, cwd: seat.cwd },
})
@@ -347,6 +348,28 @@ describe('tree rename/delete reconciliation', () => {
expect(consumeRetargetedPath(key, '/ws/dir/a.ts', '/ws/elsewhere.ts')).toBe(false)
})
it('follows the new name in the title only when the title CAME from the name', () => {
// The host's agent-opens push carries a title of its own (the model asked
// for that file by a label it chose: `use-host-feeds` → `openFile(scope,
// path, title)`), and a consumer plugin may label a page itself. A rename
// carries along the title the opener DERIVED from the file name — the
// basename — and leaves a chosen one as it is. Both tab spaces obey it.
const { store, service, records, context } = mountNativeSession()
openNativeFile(records, 'tab1', '/ws/a.ts')
openNativeFile(records, 'tab2', '/ws/a.ts', { title: 'Plan draft' })
service.openTab({ type: 'editor', title: 'Plan draft', path: '/ws/a.ts', target: 'bottom' })
retargetPathTabs(context, store, '/ws/a.ts', '/ws/b.ts')
// Derived: the chip follows the file…
expect(records.get('native-scope', 'tab1')?.tab).toMatchObject({ path: '/ws/b.ts', title: 'b.ts' })
// …authored: the path moves, the label stays.
expect(records.get('native-scope', 'tab2')?.tab).toMatchObject({ path: '/ws/b.ts', title: 'Plan draft' })
const bottom = allLeaves(store.getSnapshot().state!.bottomSplits)
.flatMap(leaf => leaf.tabs).find(tab => tab.path !== undefined)
expect(bottom).toMatchObject({ path: '/ws/b.ts', title: 'Plan draft' })
})
it('retargets a tab opened from a CHAT LINK (its address stores a workspace-relative path)', () => {
// `fileAddressFor` spells a path inside the workspace relatively, so a tab
// opened from chat holds `src/a.ts` while the tree renames by absolute path.
@@ -464,6 +487,62 @@ describe('tree rename/delete reconciliation', () => {
expect(records.has('native-scope', 'tab4')).toBe(false)
expect(records.has('native-scope', 'tab5')).toBe(true)
})
/** The file paths one session's bottom workbench has open (tree order). */
const bottomPaths = (store: SidebarStore, sessionId: string): string[] => {
const state = store.getSessionStates().get(sessionId)
if (state === undefined) return []
return allLeaves(state.bottomSplits)
.flatMap(leaf => leaf.tabs)
.flatMap(tab => (tab.path === undefined ? [] : [tab.path]))
}
it('retargets a BACKGROUND session\'s bottom-workbench page (every cached session is walked)', () => {
// The bottom workbench is per session, and a file can live there on purpose
// (`target: 'bottom'`) or in a layout persisted back when files landed in
// the workbench. The reconciliation used to read the ACTIVE session's state
// alone, so a background conversation's page kept the old path and its next
// save recreated the renamed-away file — the same data problem, one
// conversation over.
const { store, service, context } = mountNativeSession()
service.openTab(
{ type: 'editor', title: 'a.ts', path: '/ws/a.ts', target: 'bottom' },
{ sessionId: 'other-scope' },
)
expect(bottomPaths(store, 'other-scope')).toEqual(['/ws/a.ts'])
expect(store.getSnapshot().sessionId).toBe('native-scope')
retargetPathTabs(context, store, '/ws/a.ts', '/ws/b.ts')
// The page follows the file in ITS session…
expect(bottomPaths(store, 'other-scope')).toEqual(['/ws/b.ts'])
// …while the session on screen is neither written to nor re-published: a
// targeted write never touches the snapshot the shell renders from.
expect(store.getSnapshot().sessionId).toBe('native-scope')
expect(bottomPaths(store, 'native-scope')).toEqual([])
})
it('closes a BACKGROUND session\'s page on delete, asking about ITS draft', () => {
const confirmSpy = vi.fn().mockReturnValue(true)
vi.stubGlobal('confirm', confirmSpy)
const { store, service, context } = mountNativeSession()
service.openTab(
{ type: 'editor', title: 'a.ts', path: '/ws/a.ts', target: 'bottom' },
{ sessionId: 'other-scope' },
)
const row = allLeaves(store.getSessionStates().get('other-scope')!.bottomSplits)
.flatMap(leaf => leaf.tabs).find(tab => tab.path === '/ws/a.ts')!
// The editor behind that page registered its draft in ITS session, so the
// question has to be asked there — read against the active session the
// record would not be found and the tab would close unprompted.
setEditorDirty(row.id, true, 'other-scope', '/ws/a.ts')
closePathTabs(context, store, '/ws/a.ts', 'discard?')
expect(confirmSpy).toHaveBeenCalledWith('discard?')
expect(bottomPaths(store, 'other-scope')).toEqual([])
expect(store.getSnapshot().sessionId).toBe('native-scope')
})
})
describe('EditorHost dirty registration', () => {
+5 -3
View File
@@ -1408,10 +1408,12 @@ describe('native records: path enumeration and the navigation gate', () => {
records.ensure({ sessionId: 's3', id: 'tab9', kind: 'browser', title: 'site', params: { url: 'https://example.test/x' }, scope: { sessionId: 's3' } })
expect(records.pathTabs().sort((left, right) => left.id.localeCompare(right.id))).toEqual([
{ sessionId: 's1', scopeSessionId: 's1', cwd: undefined, id: 'tab1', path: '/w/a.ts' },
{ sessionId: 's2', scopeSessionId: 's2', cwd: '/w', id: 'tab1', path: 'b.ts' },
// The chip's title rides along: the rename reconciliation retitles a
// page only when that title is the file name it wrote itself.
{ sessionId: 's1', scopeSessionId: 's1', cwd: undefined, id: 'tab1', path: '/w/a.ts', title: 'a.ts' },
{ sessionId: 's2', scopeSessionId: 's2', cwd: '/w', id: 'tab1', path: 'b.ts', title: 'b.ts' },
// A browser seed lands on `path` too (the address bar reads it there).
{ sessionId: 's3', scopeSessionId: 's3', cwd: undefined, id: 'tab9', path: 'https://example.test/x' },
{ sessionId: 's3', scopeSessionId: 's3', cwd: undefined, id: 'tab9', path: 'https://example.test/x', title: 'site' },
])
})