From c482c81aa4a387e29c33cfe0f3c2d84a2cc70e35 Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 08:09:07 +0000 Subject: [PATCH 1/3] test(debug): observe timed-out adapter exit without requiring watch dial --- desktop/internal/workbench/debug_announced_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/desktop/internal/workbench/debug_announced_test.go b/desktop/internal/workbench/debug_announced_test.go index 8a2d42d8a7..3e4a992cc5 100644 --- a/desktop/internal/workbench/debug_announced_test.go +++ b/desktop/internal/workbench/debug_announced_test.go @@ -291,16 +291,26 @@ func TestDebugAnnouncedRemoteEndpointFailsAndStopsTheProcess(t *testing.T) { func TestDebugAnnouncedAdapterThatNeverAnnouncesTimesOut(t *testing.T) { h := debugPluginHarness(t, "dev.lithe.test.debug-announced", debugAnnouncedManifest, true) - root, _, watch := announcedWorkspace(t, "silent") + root, _, _ := announcedWorkspace(t, "silent") // A race-instrumented child can take over a second to reach its watch. h.app.debugInitializeWindow = 3 * time.Second p := openHostedPanel(t, h, root) h.clickNamed(h.app.text.Debug.Start) + session := p.debug.activeSession() + if session == nil { + t.Fatal("the announced adapter never entered its startup session") + } awaitStateWithin(t, h, 20*time.Second, "the timeout", func() bool { return p.debug.failure != "" }) if p.debug.failure != h.app.text.Debug.TimedOut || p.debug.activeSession() != nil { t.Fatalf("failure = %q, want the timeout message", p.debug.failure) } - watch.ended(t, 20*time.Second) + // The discovery deadline includes process startup, so a loaded CI runner + // can expire the session before the child dials the optional watch. Check + // the host-owned process rather than demanding that the child connected. + awaitDebugSessionDone(t, session) + if session.process.Load() == nil { + t.Fatal("the timeout was reported without starting the adapter process") + } } // announcementRecorder is a reader whose Core answer is a fixed rule: a line From fe9241e0af1031f9188ffcee0d1dc6ccba19a03c Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 08:24:28 +0000 Subject: [PATCH 2/3] docs(matrix): cover announced adapter deadline and process-exit verification --- .../platform-feature-matrix/features/debug-tcp-transport.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/platform-feature-matrix/features/debug-tcp-transport.json b/shared/platform-feature-matrix/features/debug-tcp-transport.json index d8a29a5b83..b92e319a95 100644 --- a/shared/platform-feature-matrix/features/debug-tcp-transport.json +++ b/shared/platform-feature-matrix/features/debug-tcp-transport.json @@ -38,8 +38,8 @@ ] }, "owner": "Debug", - "verification": "macOS:在有已安装调试提供方的源码文件上,从 Debug 更多操作打开连接调试适配器,填写已运行的 DAP 服务地址、launch/attach 与适配器参数。分别验证回环、IPv4/IPv6/DNS 外部地址、非回环默认取消的逐次确认、错误 JSON 与非法端点。确认 IDE 到 DAP 的地址不覆盖适配器到 debuggee 的地址,既有 stdio 与 tcpLanguageServer 回环限制不变。验证端点发现与建连两段独立超时(冷启动发现不缩短也不拉长建连)、被拒绝/不可达端口立即以系统原因结束、连接拒绝或 initialize 超时/未获批准/已有活动会话时对话框保持打开并保留已填内容,初始化完成后才关闭;取消等待只停止本次连接,不能误停后来选中的会话、当前文件无调试提供方时菜单项不可用、单个在途写入、字节/消息预算、写入超时、EOF、解析/建连/已连接时取消和旧回调隔离(含 Core 桥接失败清理后重新登记的连接);停止时断开帧最多排空 1 秒且 attach 的 terminateDebuggee 为 false,超时仍回收;停止后外部服务、共享 LSP、attach 目标与用户隧道仍存活。真实回环测试覆盖 Core initialize/attach 帧;真实适配器和界面全链路仍待验收。Windows 未接入此 TCP 宿主。 Viva:托管 tcpAnnounced 适配器停止时验证 disconnect 后在 Core 退出宽限内自行退出并完成清理;忽略协议退出的子进程在宽限到期后强制回收,重复停止不提前打断。", - "notes": "语言服务器托管适配器(tcpLanguageServer)和自行输出监听端口的适配器进程(tcpAnnounced)的环回 TCP 连接都按 Core 的 debug.transport.handle 生命周期驱动;tcpAnnounced 的端点由 Core 的 debug.adapters.readAnnouncement 从进程输出行读出,发现期限沿用 Core 默认值:帧先入队、同时只有一个写在途,发现/连接/写入期限与排空期限都是 Core 下发的定时器,用户停止时先发 DAP disconnect 再有界排空。直接连接用户指定的远程适配器端点(adapterEndpoint)仍未接入。 已通过协议请求退出的托管进程使用 Core 解析的进程退出宽限,不再立即发送系统终止信号;启动失败仍直接停止,不等待远端协议应答。", + "verification": "macOS:在有已安装调试提供方的源码文件上,从 Debug 更多操作打开连接调试适配器,填写已运行的 DAP 服务地址、launch/attach 与适配器参数。分别验证回环、IPv4/IPv6/DNS 外部地址、非回环默认取消的逐次确认、错误 JSON 与非法端点。确认 IDE 到 DAP 的地址不覆盖适配器到 debuggee 的地址,既有 stdio 与 tcpLanguageServer 回环限制不变。验证端点发现与建连两段独立超时(冷启动发现不缩短也不拉长建连)、被拒绝/不可达端口立即以系统原因结束、连接拒绝或 initialize 超时/未获批准/已有活动会话时对话框保持打开并保留已填内容,初始化完成后才关闭;取消等待只停止本次连接,不能误停后来选中的会话、当前文件无调试提供方时菜单项不可用、单个在途写入、字节/消息预算、写入超时、EOF、解析/建连/已连接时取消和旧回调隔离(含 Core 桥接失败清理后重新登记的连接);停止时断开帧最多排空 1 秒且 attach 的 terminateDebuggee 为 false,超时仍回收;停止后外部服务、共享 LSP、attach 目标与用户隧道仍存活。真实回环测试覆盖 Core initialize/attach 帧;真实适配器和界面全链路仍待验收。Windows 未接入此 TCP 宿主。 Viva:托管 tcpAnnounced 适配器停止时验证 disconnect 后在 Core 退出宽限内自行退出并完成清理;忽略协议退出的子进程在宽限到期后强制回收,重复停止不提前打断。 tcpAnnounced 的无应答初始化超时回归执行 TestDebugAnnouncedAdapterThatNeverAnnouncesTimesOut:适配器在 CI 高负载下可能到超时都未连接可选 watch;断言宿主报告 TimedOut、会话释放,并通过已存在的有界 startupDone/exitObserved 等待实际进程退出,而不是要求 watch 一定先连上。继续保留其他用例检查确实有 TCP 连接后发送 disconnect 的流程;macOS/Windows 原生验收仍待完成。", + "notes": "语言服务器托管适配器(tcpLanguageServer)和自行输出监听端口的适配器进程(tcpAnnounced)的环回 TCP 连接都按 Core 的 debug.transport.handle 生命周期驱动;tcpAnnounced 的端点由 Core 的 debug.adapters.readAnnouncement 从进程输出行读出,发现期限沿用 Core 默认值:帧先入队、同时只有一个写在途,发现/连接/写入期限与排空期限都是 Core 下发的定时器,用户停止时先发 DAP disconnect 再有界排空。直接连接用户指定的远程适配器端点(adapterEndpoint)仍未接入。 已通过协议请求退出的托管进程使用 Core 解析的进程退出宽限,不再立即发送系统终止信号;启动失败仍直接停止,不等待远端协议应答。 #1962:此前超时测试将连接到 watch 当作适配器已运行的必要证据,固定窗口到期可先取消子进程,测试错误地等 20 秒;此处只更换测试的退出观察方式,不改生产调试超时或协议。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": { From 4629cd383377b8d0331a8b2f4417ad464365f8ea Mon Sep 17 00:00:00 2001 From: lick <2188718831@qq.com> Date: Mon, 23 Nov 2026 09:20:10 -0800 Subject: [PATCH 3/3] test(debug): trigger announced initialize timeout deterministically --- desktop/internal/workbench/app.go | 15 ++--- .../workbench/debug_announced_test.go | 56 ++++++++++++++----- desktop/internal/workbench/debug_start.go | 16 +++++- .../features/debug-tcp-transport.json | 4 +- 4 files changed, 66 insertions(+), 25 deletions(-) diff --git a/desktop/internal/workbench/app.go b/desktop/internal/workbench/app.go index 321c4f87bd..914c6d5c14 100644 --- a/desktop/internal/workbench/app.go +++ b/desktop/internal/workbench/app.go @@ -656,13 +656,14 @@ type App struct { // savedBackground is the window background last stored (window_background.go). savedBackground gfx.Color focus focusTarget - // debugHostedPort and debugInitializeWindow replace, in tests, asking the - // language server for a debug port and Core's initialize deadline. Production - // leaves both zero. - debugHostedPort func(ctx context.Context, p *project, adapter debugAdapter) (int, error) - debugInitializeWindow time.Duration - kernel Kernel - store *store.Store + // debugHostedPort, debugInitializeWindow, and debugInitializeTrigger replace, + // in tests, asking the language server for a debug port and Core's initialize + // deadline. Production leaves all three zero. + debugHostedPort func(ctx context.Context, p *project, adapter debugAdapter) (int, error) + debugInitializeWindow time.Duration + debugInitializeTrigger <-chan struct{} + kernel Kernel + store *store.Store // startupPath is the project folder the window opens once it exists (Options.OpenPath). startupPath string startupFile string diff --git a/desktop/internal/workbench/debug_announced_test.go b/desktop/internal/workbench/debug_announced_test.go index 3e4a992cc5..7639fa8772 100644 --- a/desktop/internal/workbench/debug_announced_test.go +++ b/desktop/internal/workbench/debug_announced_test.go @@ -136,6 +136,7 @@ func TestDebugAnnouncedAdapterRunner(t *testing.T) { type announcedWatch struct { listener net.Listener accepted chan net.Conn + conn net.Conn } // announcedWorkspace is the fixture workspace for one mode, and the watch the @@ -150,6 +151,9 @@ func announcedWorkspace(t *testing.T, mode string) (root, source string, watch * watch = &announcedWatch{listener: listener, accepted: make(chan net.Conn, 1)} t.Cleanup(func() { _ = listener.Close() + if watch.conn != nil { + _ = watch.conn.Close() + } select { case conn := <-watch.accepted: if conn != nil { @@ -176,20 +180,33 @@ func announcedWorkspace(t *testing.T, mode string) (root, source string, watch * return root, source, watch } -// ended waits for the fixture process to end and returns what it reported -// before it did. -func (w *announcedWatch) ended(t *testing.T, limit time.Duration) string { +// awaitConnected waits for the fixture process to connect to the watch so tests +// can synchronize deterministically with the running child before triggering +// timeouts. +func (w *announcedWatch) awaitConnected(t *testing.T, limit time.Duration) { t.Helper() - deadline := time.Now().Add(limit) - var conn net.Conn + if w.conn != nil { + return + } select { - case conn = <-w.accepted: + case conn := <-w.accepted: if conn == nil { t.Fatal("the adapter watch listener stopped before accepting the connection") } + w.conn = conn case <-time.After(limit): t.Fatal("the adapter process never connected to the watch") } +} + +// ended waits for the fixture process to end and returns what it reported +// before it did. +func (w *announcedWatch) ended(t *testing.T, limit time.Duration) string { + t.Helper() + deadline := time.Now().Add(limit) + w.awaitConnected(t, limit) + conn := w.conn + w.conn = nil defer conn.Close() if err := conn.SetReadDeadline(deadline); err != nil { t.Fatal(err) @@ -291,25 +308,36 @@ func TestDebugAnnouncedRemoteEndpointFailsAndStopsTheProcess(t *testing.T) { func TestDebugAnnouncedAdapterThatNeverAnnouncesTimesOut(t *testing.T) { h := debugPluginHarness(t, "dev.lithe.test.debug-announced", debugAnnouncedManifest, true) - root, _, _ := announcedWorkspace(t, "silent") - // A race-instrumented child can take over a second to reach its watch. - h.app.debugInitializeWindow = 3 * time.Second + root, _, watch := announcedWorkspace(t, "silent") + // Control the initialize timeout deterministically so child startup never + // races the timeout clock. + trigger := make(chan struct{}) + t.Cleanup(func() { + select { + case <-trigger: + default: + close(trigger) + } + }) + h.app.debugInitializeTrigger = trigger p := openHostedPanel(t, h, root) h.clickNamed(h.app.text.Debug.Start) session := p.debug.activeSession() if session == nil { t.Fatal("the announced adapter never entered its startup session") } + watch.awaitConnected(t, 20*time.Second) + close(trigger) awaitStateWithin(t, h, 20*time.Second, "the timeout", func() bool { return p.debug.failure != "" }) if p.debug.failure != h.app.text.Debug.TimedOut || p.debug.activeSession() != nil { t.Fatalf("failure = %q, want the timeout message", p.debug.failure) } - // The discovery deadline includes process startup, so a loaded CI runner - // can expire the session before the child dials the optional watch. Check - // the host-owned process rather than demanding that the child connected. + watch.ended(t, 20*time.Second) awaitDebugSessionDone(t, session) - if session.process.Load() == nil { - t.Fatal("the timeout was reported without starting the adapter process") + select { + case <-session.cleanupDone: + case <-time.After(debugAdapterExitWait): + t.Fatal("the timed-out debug session did not finish cleanup before the deadline") } } diff --git a/desktop/internal/workbench/debug_start.go b/desktop/internal/workbench/debug_start.go index f55172e1b9..6fe4c9e72f 100644 --- a/desktop/internal/workbench/debug_start.go +++ b/desktop/internal/workbench/debug_start.go @@ -651,7 +651,7 @@ func (a *App) beginDebug(p *project, start debugStart) { // Core owns the length of the window (the transport policy's initialization // deadline); the host only runs the clock. func (a *App) watchDebugInitialize(p *project, session *debugSession, window time.Duration) { - timer := time.AfterFunc(window, func() { + timeout := func() { // The window is the start's deadline: an adapter start that has no result by now // timed out. A start that already ended keeps its result. a.recordDebugStart(session.ctx, session, core.StageTimeout, context.DeadlineExceeded) @@ -666,7 +666,19 @@ func (a *App) watchDebugInitialize(p *project, session *debugSession, window tim a.finishDebugError(p, session, errors.New(a.text.Debug.TimedOut)) } }) - }) + } + if a.debugInitializeTrigger != nil { + trigger := a.debugInitializeTrigger + go func() { + select { + case <-trigger: + timeout() + case <-session.ctx.Done(): + } + }() + return + } + timer := time.AfterFunc(window, timeout) // The timer must not outlive the session: Stop and shutdown cancel its context. context.AfterFunc(session.ctx, func() { timer.Stop() }) } diff --git a/shared/platform-feature-matrix/features/debug-tcp-transport.json b/shared/platform-feature-matrix/features/debug-tcp-transport.json index b92e319a95..91d3992f1c 100644 --- a/shared/platform-feature-matrix/features/debug-tcp-transport.json +++ b/shared/platform-feature-matrix/features/debug-tcp-transport.json @@ -38,8 +38,8 @@ ] }, "owner": "Debug", - "verification": "macOS:在有已安装调试提供方的源码文件上,从 Debug 更多操作打开连接调试适配器,填写已运行的 DAP 服务地址、launch/attach 与适配器参数。分别验证回环、IPv4/IPv6/DNS 外部地址、非回环默认取消的逐次确认、错误 JSON 与非法端点。确认 IDE 到 DAP 的地址不覆盖适配器到 debuggee 的地址,既有 stdio 与 tcpLanguageServer 回环限制不变。验证端点发现与建连两段独立超时(冷启动发现不缩短也不拉长建连)、被拒绝/不可达端口立即以系统原因结束、连接拒绝或 initialize 超时/未获批准/已有活动会话时对话框保持打开并保留已填内容,初始化完成后才关闭;取消等待只停止本次连接,不能误停后来选中的会话、当前文件无调试提供方时菜单项不可用、单个在途写入、字节/消息预算、写入超时、EOF、解析/建连/已连接时取消和旧回调隔离(含 Core 桥接失败清理后重新登记的连接);停止时断开帧最多排空 1 秒且 attach 的 terminateDebuggee 为 false,超时仍回收;停止后外部服务、共享 LSP、attach 目标与用户隧道仍存活。真实回环测试覆盖 Core initialize/attach 帧;真实适配器和界面全链路仍待验收。Windows 未接入此 TCP 宿主。 Viva:托管 tcpAnnounced 适配器停止时验证 disconnect 后在 Core 退出宽限内自行退出并完成清理;忽略协议退出的子进程在宽限到期后强制回收,重复停止不提前打断。 tcpAnnounced 的无应答初始化超时回归执行 TestDebugAnnouncedAdapterThatNeverAnnouncesTimesOut:适配器在 CI 高负载下可能到超时都未连接可选 watch;断言宿主报告 TimedOut、会话释放,并通过已存在的有界 startupDone/exitObserved 等待实际进程退出,而不是要求 watch 一定先连上。继续保留其他用例检查确实有 TCP 连接后发送 disconnect 的流程;macOS/Windows 原生验收仍待完成。", - "notes": "语言服务器托管适配器(tcpLanguageServer)和自行输出监听端口的适配器进程(tcpAnnounced)的环回 TCP 连接都按 Core 的 debug.transport.handle 生命周期驱动;tcpAnnounced 的端点由 Core 的 debug.adapters.readAnnouncement 从进程输出行读出,发现期限沿用 Core 默认值:帧先入队、同时只有一个写在途,发现/连接/写入期限与排空期限都是 Core 下发的定时器,用户停止时先发 DAP disconnect 再有界排空。直接连接用户指定的远程适配器端点(adapterEndpoint)仍未接入。 已通过协议请求退出的托管进程使用 Core 解析的进程退出宽限,不再立即发送系统终止信号;启动失败仍直接停止,不等待远端协议应答。 #1962:此前超时测试将连接到 watch 当作适配器已运行的必要证据,固定窗口到期可先取消子进程,测试错误地等 20 秒;此处只更换测试的退出观察方式,不改生产调试超时或协议。", + "verification": "macOS:在有已安装调试提供方的源码文件上,从 Debug 更多操作打开连接调试适配器,填写已运行的 DAP 服务地址、launch/attach 与适配器参数。分别验证回环、IPv4/IPv6/DNS 外部地址、非回环默认取消的逐次确认、错误 JSON 与非法端点。确认 IDE 到 DAP 的地址不覆盖适配器到 debuggee 的地址,既有 stdio 与 tcpLanguageServer 回环限制不变。验证端点发现与建连两段独立超时(冷启动发现不缩短也不拉长建连)、被拒绝/不可达端口立即以系统原因结束、连接拒绝或 initialize 超时/未获批准/已有活动会话时对话框保持打开并保留已填内容,初始化完成后才关闭;取消等待只停止本次连接,不能误停后来选中的会话、当前文件无调试提供方时菜单项不可用、单个在途写入、字节/消息预算、写入超时、EOF、解析/建连/已连接时取消和旧回调隔离(含 Core 桥接失败清理后重新登记的连接);停止时断开帧最多排空 1 秒且 attach 的 terminateDebuggee 为 false,超时仍回收;停止后外部服务、共享 LSP、attach 目标与用户隧道仍存活。真实回环测试覆盖 Core initialize/attach 帧;真实适配器和界面全链路仍待验收。Windows 未接入此 TCP 宿主。 Viva:托管 tcpAnnounced 适配器停止时验证 disconnect 后在 Core 退出宽限内自行退出并完成清理;忽略协议退出的子进程在宽限到期后强制回收,重复停止不提前打断。 tcpAnnounced 的无应答初始化超时回归执行 TestDebugAnnouncedAdapterThatNeverAnnouncesTimesOut:测试先通过 watch.awaitConnected 确认子进程已启动并建立观察连接,再由 debugInitializeTrigger 确定性触发初始化超时;断言宿主报告 TimedOut、会话释放,并通过 watch.ended、startupDone/exitObserved 与 cleanupDone 确认子进程及清理全部有界完成。继续保留其他用例检查确实有 TCP 连接后发送 disconnect 的流程;macOS/Windows 原生验收仍待完成。", + "notes": "语言服务器托管适配器(tcpLanguageServer)和自行输出监听端口的适配器进程(tcpAnnounced)的环回 TCP 连接都按 Core 的 debug.transport.handle 生命周期驱动;tcpAnnounced 的端点由 Core 的 debug.adapters.readAnnouncement 从进程输出行读出,发现期限沿用 Core 默认值:帧先入队、同时只有一个写在途,发现/连接/写入期限与排空期限都是 Core 下发的定时器,用户停止时先发 DAP disconnect 再有界排空。直接连接用户指定的远程适配器端点(adapterEndpoint)仍未接入。 已通过协议请求退出的托管进程使用 Core 解析的进程退出宽限,不再立即发送系统终止信号;启动失败仍直接停止,不等待远端协议应答。 #1962:此前超时测试使用固定定时器(300ms / 3s)与子进程启动和连接 watch 竞争;改为测试在确认子进程连上 watch 后通过 debugInitializeTrigger 确定性触发 watchDebugInitialize 超时,并验证进程退出与清理完成,不改生产调试超时或协议。", "legacy": { "revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36", "macos": {