DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(dsh-tauri): 桌面载体鉴权两道闸门各自独立接管(0.1.7 失效)
hairyf0318f3bd68cf
diff --git a/packages/dsh-tauri/src/host/service/gate.test.ts b/packages/dsh-tauri/src/host/service/gate.test.tsindex 20250dff..d9186721 100644--- a/packages/dsh-tauri/src/host/service/gate.test.ts+++ b/packages/dsh-tauri/src/host/service/gate.test.ts@@ -1,7 +1,7 @@import type { IncomingMessage, ServerResponse } from 'node:http'import type { ConnectionHost } from '../types'import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'-import { clearHostRuntime, setCurrentHostInstance } from '../config/runtime'+import { clearHostRuntime, getCurrentHostInstance, setCurrentHostInstance } from '../config/runtime'import { gate } from './gate'const request = {} as IncomingMessage@@ -76,6 +76,21 @@ describe('gate.attach with the carrier marker', () => {detach()})+ /** 0.1.7 起 `requestRejection` 移到 peer 上,`connection` 只剩 `authorizeIndex`。 */+ it('still bypasses the index gate when the core dropped requestRejection', () => {+ const warn = vi.fn()+ const authorizeIndex = () => false+ setCurrentHostInstance({ connection: { authorizeIndex }, logger: { warn } } as never)++ const detach = gate.attach()++ expect(warn).not.toHaveBeenCalled()+ const { connection } = getCurrentHostInstance() as ConnectionHost+ expect(connection.authorizeIndex(request, response)).toBe(true)+ detach()+ expect(connection.authorizeIndex).toBe(authorizeIndex)+ })+it('restores both gates on detach', () => {const { connection } = makeHost(401)const rejection = connection.requestRejectiondiff --git a/packages/dsh-tauri/src/host/service/gate.ts b/packages/dsh-tauri/src/host/service/gate.tsindex 2057bc16..430ebb4a 100644--- a/packages/dsh-tauri/src/host/service/gate.ts+++ b/packages/dsh-tauri/src/host/service/gate.ts@@ -18,6 +18,11 @@ const EMBEDDED_ENV = 'DSH_TAURI_EMBEDDED'* browser-session Cookie 不会被携带,根路径 token 交换也就无法完成。这里在* `connection` 服务实例上覆写两道闸门:`requestRejection` 保留 Host/Origin fence* 的 403、只把 401 降级为放行;`authorizeIndex` 直接放行 index。+ *+ * 两道闸门必须**各自独立**接管:0.1.6 及更早两处都在 `connection` 上;0.1.7 起+ * `requestRejection` 移到了 peer 上,`connection` 只剩 `authorizeIndex`(且该方法+ * 会自行写出 401/303,返回 true 才是「调用方可以发 index.html」)。此前把两者绑成+ * 一个整体,缺一道就整个适配 noop —— 表现为嵌入 WebView 与健康探测都恒拿 401。*/export const gate = defineService({attach(): () => void {@@ -26,22 +31,41 @@ export const gate = defineService({}const { connection } = getCurrentHostInstance()+ if (connection === undefined || connection === null) {+ warn('宿主实例缺少 connection 服务,桌面载体鉴权适配未生效')+ return noop+ }++ const restores: Array<() => void> = []+const rejection = connection.requestRejection+ if (typeof rejection === 'function') {+ connection.requestRejection = (request: IncomingMessage) => {+ const rejected = rejection.call(connection, request)+ return rejected === 401 ? undefined : rejected+ }+ restores.push(() => {+ connection.requestRejection = rejection+ })+ }+const authorize = connection.authorizeIndex- if (typeof rejection !== 'function' || typeof authorize !== 'function') {- warn('connection 服务缺少 requestRejection/authorizeIndex,桌面载体鉴权适配未生效')- return noop+ if (typeof authorize === 'function') {+ connection.authorizeIndex = () => true+ restores.push(() => {+ connection.authorizeIndex = authorize+ })}- connection.requestRejection = (request: IncomingMessage) => {- const rejected = rejection.call(connection, request)- return rejected === 401 ? undefined : rejected+ if (restores.length === 0) {+ warn('connection 服务缺少 requestRejection/authorizeIndex,桌面载体鉴权适配未生效')+ return noop}- connection.authorizeIndex = () => truereturn () => {- connection.requestRejection = rejection- connection.authorizeIndex = authorize+ for (const restore of restores) {+ restore()+ }}},})