@allbluecn/web-app 0.27.19 → 0.27.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allbluecn/web-app",
3
- "version": "0.27.19",
3
+ "version": "0.27.20",
4
4
  "license": "AGPL-3.0-or-later",
5
5
  "type": "module",
6
6
  "files": [
@@ -10,8 +10,14 @@ vi.mock('@/lib/auth/auth-client', () => ({
10
10
  useSession: vi.fn(),
11
11
  }))
12
12
 
13
+ // 桌面运行时判定(Bug#2:桌面未登录 session=null 时 Pro 功能需 fail-closed)
14
+ vi.mock('@/lib/desktop-env', () => ({
15
+ isDesktopClient: vi.fn(() => false),
16
+ }))
17
+
13
18
  import { useSubscription } from '../subscription-provider'
14
19
  import { useSession } from '@/lib/auth/auth-client'
20
+ import { isDesktopClient } from '@/lib/desktop-env'
15
21
 
16
22
  const mockUseSubscription = useSubscription as ReturnType<typeof vi.fn>
17
23
  const mockUseSession = useSession as ReturnType<typeof vi.fn>
@@ -97,4 +103,40 @@ describe('useFeature', () => {
97
103
  const { result } = renderHook(() => useFeature('hostedAi'))
98
104
  expect(result.current.enabled).toBe(false)
99
105
  })
106
+
107
+ // Bug#2:桌面真机未登录(session=null)时 Pro 功能泄漏——沙箱档等 Pro 入口
108
+ // 因 OSS_BASE_FEATURES 白名单被判 enabled。桌面未登录与 guest 同为本机匿名态,
109
+ // 必须 fail-closed 返回 requiresLogin。
110
+ it('桌面未登录(session=null)→ requiresLogin(Pro 功能 fail-closed)', () => {
111
+ vi.mocked(isDesktopClient).mockReturnValue(true)
112
+ mockUseSession.mockReturnValue({ data: null })
113
+ mockUseSubscription.mockReturnValue({
114
+ planName: 'open-source',
115
+ // sandboxExecution 在 OSS_BASE_FEATURES 内 → features 为 true,
116
+ // 若不在桌面未登录分支拦截就会泄漏为 enabled
117
+ features: { sandboxExecution: true },
118
+ unavailable: [],
119
+ loading: false,
120
+ })
121
+
122
+ const { result } = renderHook(() => useFeature('sandboxExecution'))
123
+ expect(result.current.enabled).toBe(false)
124
+ expect(result.current.requiresLogin).toBe(true)
125
+ })
126
+
127
+ // 云/web 未登录不收敛(营销态可展示 Pro 入口引导注册),仅桌面壳内 fail-closed
128
+ it('云/web 未登录(session=null,非桌面)→ 不受桌面分支影响', () => {
129
+ vi.mocked(isDesktopClient).mockReturnValue(false)
130
+ mockUseSession.mockReturnValue({ data: null })
131
+ mockUseSubscription.mockReturnValue({
132
+ planName: 'open-source',
133
+ features: { sandboxExecution: true },
134
+ unavailable: [],
135
+ loading: false,
136
+ })
137
+
138
+ const { result } = renderHook(() => useFeature('sandboxExecution'))
139
+ expect(result.current.enabled).toBe(true)
140
+ expect(result.current.requiresLogin).toBeUndefined()
141
+ })
100
142
  })
@@ -1,5 +1,6 @@
1
1
  import { useSubscription } from './subscription-provider'
2
2
  import { useSession } from '@/lib/auth/auth-client'
3
+ import { isDesktopClient } from '@/lib/desktop-env'
3
4
  import { type FeatureKey } from '@allbluecn/kernel'
4
5
 
5
6
  // 桌面访客会话固定 userId(服务端唯一来源 src/server/desktop-guest.ts 的
@@ -27,6 +28,14 @@ export function useFeature(feature: FeatureKey): FeatureState {
27
28
  return { enabled: false, loading: false, requiresLogin: true }
28
29
  }
29
30
 
31
+ // 桌面未登录(session 仍为 null,尚未回落 guest):与 guest 同为「本机匿名」态,
32
+ // Pro 功能必须 fail-closed,否则 OSS_BASE_FEATURES 白名单会让沙箱档等 Pro 入口
33
+ // 在登录前泄漏(真机验收 Bug#2)。桌面 guest 一旦回落,走上面 isGuest 分支同口径。
34
+ // 云/web 未登录不在此列(营销态可展示 Pro 入口引导注册),仅桌面壳内收敛。
35
+ if (!session && isDesktopClient()) {
36
+ return { enabled: false, loading: false, requiresLogin: true }
37
+ }
38
+
30
39
  return {
31
40
  enabled: features[feature] === true,
32
41
  loading,
@@ -112,7 +112,7 @@ export const SDK_GROUPS: SdkGroup[] = [
112
112
  "items": [
113
113
  {
114
114
  "name": "@allbluecn/web-app",
115
- "version": "v0.27.19",
115
+ "version": "v0.27.20",
116
116
  "lastUpdate": "Nov 9, 2026",
117
117
  "source": "apps/web/package.json",
118
118
  "docsUrl": "https://github.com/allbluecn/allblue"
@@ -40,44 +40,58 @@ async function handleHarnessRequest(request: Request): Promise<Response> {
40
40
  if (!isHarnessHostEnabled()) return notFound()
41
41
 
42
42
  // server-only 薄适配层经 server.handlers 剥离,客户端不会加载;动态 import 使
43
- // 门控关闭路径完全不触达 harness 装配(避免无谓构造)。
44
- const [{ getHarnessHost }, { allblueHarness }, { createHarnessHandler }, { getCurrentSession }, { checkAiRateLimit, RateLimitExceededError }] = await Promise.all([
45
- import('@/server/harness/host.server'),
46
- import('@/server/harness/define.server'),
47
- import('@tanstack/ai-harness/server'),
48
- import('@/lib/session'),
49
- import('@/server/lib/rate-limit'),
50
- ])
43
+ // 门控关闭路径完全不触达 harness 装配(避免无谓构造)。整段包顶层 try/catch:
44
+ // 官方 createHarnessHandler 内部虽把 handler 异常转 400,但**动态 import 与 host
45
+ // 首次构造(getHarnessHost → createPrismaPersistence → @allbluecn/database 顶层
46
+ // await createPrismaClient)发生在该内部 try/catch 之前**——桌面真机未登录验收发现
47
+ // 这段抛错(PGlite 未就绪 / 迁移未跑 / env 缺失等)会以裸框架 500 逃逸,客户端
48
+ // describe/snapshot/transcript 三个 GET 全部 `Harness * failed (500)` 且 SSE 重连
49
+ // 退避耗尽 → 「重试次数已达上限」。收敛为结构化 503,不再让装配期故障裸奔。
50
+ try {
51
+ const [{ getHarnessHost }, { allblueHarness }, { createHarnessHandler }, { getCurrentSession }, { checkAiRateLimit, RateLimitExceededError }] = await Promise.all([
52
+ import('@/server/harness/host.server'),
53
+ import('@/server/harness/define.server'),
54
+ import('@tanstack/ai-harness/server'),
55
+ import('@/lib/session'),
56
+ import('@/server/lib/rate-limit'),
57
+ ])
51
58
 
52
- const url = new URL(request.url)
53
- const isControl = url.pathname.endsWith('/control')
54
- if (request.method === 'POST' && isControl) {
55
- const op = await readControlOp(request)
56
- if (op && RATE_LIMITED_OPS.has(op)) {
57
- // 限流身份取 access 层同源会话(client context 不可信,P0-2)
58
- const session = await getCurrentSession(request)
59
- const userId = session?.user?.id
60
- if (userId) {
61
- try {
62
- await checkAiRateLimit(userId, 'chat')
63
- } catch (err) {
64
- if (err instanceof RateLimitExceededError) {
65
- return new Response(
66
- JSON.stringify({ error: 'rate_limited', retryAfterMs: err.retryAfterMs }),
67
- { status: 429, headers: { 'content-type': 'application/json', 'retry-after': String(Math.ceil(err.retryAfterMs / 1000)) } },
68
- )
59
+ const url = new URL(request.url)
60
+ const isControl = url.pathname.endsWith('/control')
61
+ if (request.method === 'POST' && isControl) {
62
+ const op = await readControlOp(request)
63
+ if (op && RATE_LIMITED_OPS.has(op)) {
64
+ // 限流身份取 access 层同源会话(client context 不可信,P0-2)
65
+ const session = await getCurrentSession(request)
66
+ const userId = session?.user?.id
67
+ if (userId) {
68
+ try {
69
+ await checkAiRateLimit(userId, 'chat')
70
+ } catch (err) {
71
+ if (err instanceof RateLimitExceededError) {
72
+ return new Response(
73
+ JSON.stringify({ error: 'rate_limited', retryAfterMs: err.retryAfterMs }),
74
+ { status: 429, headers: { 'content-type': 'application/json', 'retry-after': String(Math.ceil(err.retryAfterMs / 1000)) } },
75
+ )
76
+ }
77
+ throw err
69
78
  }
70
- throw err
71
79
  }
72
80
  }
73
81
  }
74
- }
75
82
 
76
- // host 带 access(getCurrentSession 映射 + owner-only + 抢建防护 + acceptInput
77
- // 可信上下文覆写)。access/acceptInput 已在 getHarnessHost 单例内装配。
78
- const host = getHarnessHost()
79
- const handler = createHarnessHandler({ host, harness: allblueHarness })
80
- return handler(request)
83
+ // host 带 access(getCurrentSession 映射 + owner-only + 抢建防护 + acceptInput
84
+ // 可信上下文覆写)。access/acceptInput 已在 getHarnessHost 单例内装配。
85
+ const host = getHarnessHost()
86
+ const handler = createHarnessHandler({ host, harness: allblueHarness })
87
+ return await handler(request)
88
+ } catch (error) {
89
+ console.error('[harness] 请求处理失败(host 装配或 handler 异常):', error)
90
+ return new Response(
91
+ JSON.stringify({ error: 'harness_unavailable', message: error instanceof Error ? error.message : String(error) }),
92
+ { status: 503, headers: { 'content-type': 'application/json' } },
93
+ )
94
+ }
81
95
  }
82
96
 
83
97
  export const Route = createFileRoute('/api/harness/$')({