File size: 8,157 Bytes
e445b51
 
 
 
 
 
 
e4e0afe
e445b51
 
 
 
97869a1
e4e0afe
 
e445b51
 
 
 
e4e0afe
e445b51
97869a1
e4e0afe
 
e445b51
 
 
 
 
 
 
97869a1
e4e0afe
e445b51
e4e0afe
e445b51
 
 
 
 
 
97869a1
96bdf6c
 
 
 
 
 
e4e0afe
 
96bdf6c
 
 
 
 
 
 
 
 
 
4ee260c
 
 
 
 
 
e4e0afe
 
4ee260c
 
 
 
97869a1
 
 
 
 
e4e0afe
 
97869a1
 
 
 
 
 
 
 
 
e4e0afe
 
97869a1
 
 
 
 
 
 
 
 
e4e0afe
 
97869a1
 
 
 
 
e4e0afe
4ee260c
e4e0afe
 
97869a1
 
6c12d18
 
 
 
 
 
 
e4e0afe
 
6c12d18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e4e0afe
6c12d18
 
 
 
 
 
e4e0afe
6c12d18
 
 
 
 
 
 
 
e4e0afe
 
6c12d18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4ee260c
 
 
 
96bdf6c
4ee260c
 
 
96bdf6c
 
6c12d18
e445b51
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import { WorkbenchStatusStrip } from './workbench-status-strip';
import { I18nProvider } from '@/lib/i18n';
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
import { renderToStaticMarkup } from 'react-dom/server';

describe('WorkbenchStatusStrip', () => {
    it('shows model, request route, streaming mode, requested image count, and runtime state before generation', () => {
        const html = renderToStaticMarkup(
            <I18nProvider>
                <WorkbenchStatusStrip
                    model='gpt-image-2'
                    routeLabel='images-sse'
                    streamStatus='自动'
                    requestSummaryLabel='请求 1 张图片'
                />
            </I18nProvider>
        );

        assert.match(html, /当前请求路径已就绪/);
        assert.match(html, /gpt-image-2/);
        assert.match(html, /images-sse/);
        assert.match(html, /自动/);
        assert.match(html, /请求 1 张图片/);
    });

    it('shows explicit parallel batch state when the user enabled it for the current request', () => {
        const html = renderToStaticMarkup(
            <I18nProvider>
                <WorkbenchStatusStrip
                    model='gpt-image-2'
                    routeLabel='默认线路'
                    streamStatus='自动'
                    parallelBatchEnabled
                    requestSummaryLabel='请求 2 张图片'
                />
            </I18nProvider>
        );

        assert.match(html, /并发已启用/);
    });

    it('reserves the request mode slot before runtime details arrive', () => {
        const html = renderToStaticMarkup(
            <I18nProvider>
                <WorkbenchStatusStrip
                    model='gpt-image-2'
                    routeLabel='默认线路'
                    streamStatus='非流式'
                    requestSummaryLabel='请求 1 张图片'
                />
            </I18nProvider>
        );

        assert.match(html, /data-request-mode-placeholder="true"/);
        assert.match(html, /aria-hidden="true"/);
        assert.match(html, /请求方式/);
        assert.doesNotMatch(html, /invisible/);
    });

    it('renders checking, disconnected, route-limited, and custom override runtime states explicitly', () => {
        const checkingHtml = renderToStaticMarkup(
            <I18nProvider>
                <WorkbenchStatusStrip
                    model='gpt-image-2'
                    routeLabel='服务器默认'
                    streamStatus='非流式'
                    requestSummaryLabel='请求 1 张图片'
                    runtimeHealthStatus='checking'
                />
            </I18nProvider>
        );
        const disconnectedHtml = renderToStaticMarkup(
            <I18nProvider>
                <WorkbenchStatusStrip
                    model='gpt-image-2'
                    routeLabel='服务器默认'
                    streamStatus='非流式'
                    requestSummaryLabel='请求 1 张图片'
                    runtimeHealthStatus='disconnected'
                />
            </I18nProvider>
        );
        const routeLimitedHtml = renderToStaticMarkup(
            <I18nProvider>
                <WorkbenchStatusStrip
                    model='gpt-image-2'
                    routeLabel='服务器默认'
                    streamStatus='自动'
                    requestSummaryLabel='请求 1 张图片'
                    runtimeHealthStatus='route-limited'
                />
            </I18nProvider>
        );
        const customOverrideHtml = renderToStaticMarkup(
            <I18nProvider>
                <WorkbenchStatusStrip
                    model='gpt-image-2'
                    routeLabel='使用自定义上游'
                    streamStatus='非流式'
                    requestSummaryLabel='请求 1 张图片'
                    runtimeHealthStatus='custom-override'
                />
            </I18nProvider>
        );

        assert.match(checkingHtml, /正在读取运行时状态/);
        assert.match(checkingHtml, /animate-spin/);
        assert.match(disconnectedHtml, /未取得运行时状态/);
        assert.match(routeLimitedHtml, /当前路由受限/);
        assert.match(customOverrideHtml, /使用自定义上游/);
    });

    it('shows request mode health details and suggested channel env in the status strip', () => {
        const html = renderToStaticMarkup(
            <I18nProvider>
                <WorkbenchStatusStrip
                    model='gpt-image-2'
                    routeLabel='服务器默认'
                    streamStatus='自动'
                    requestSummaryLabel='请求 1 张图片'
                    channelRouting={{
                        effectiveRequestModes: ['images-non-stream', 'images-sse'],
                        requestModeHealth: [
                            {
                                mode: 'images-non-stream',
                                configuredCredentialCount: 2,
                                healthyCredentialCount: 1,
                                configuredChannelCount: 2,
                                healthyChannelCount: 1
                            },
                            {
                                mode: 'responses-sse',
                                configuredCredentialCount: 1,
                                healthyCredentialCount: 0,
                                configuredChannelCount: 1,
                                healthyChannelCount: 0
                            }
                        ]
                    }}
                    runtimeLastFailure={{
                        scope: 'channel',
                        status: 403,
                        code: 'image_generation_disabled',
                        requestMode: 'responses-sse'
                    }}
                />
            </I18nProvider>
        );

        assert.match(html, /请求方式/);
        assert.match(html, /images-non-stream/);
        assert.match(html, /可用于请求/);
        assert.match(html, /responses-sse/);
        assert.match(html, /冷却中或待探测/);
        assert.match(html, /最近渠道失败/);
        assert.match(html, /HTTP 403/);
        assert.match(html, /responses-sse/);
        assert.match(html, /OPENAI_CHANNEL_N_REQUEST_MODES=images-non-stream/);
        assert.match(html, /建议的环境变量/);
    });

    it('keeps request mode details constrained on narrow screens', () => {
        const html = renderToStaticMarkup(
            <I18nProvider>
                <WorkbenchStatusStrip
                    model='gpt-image-2'
                    routeLabel='服务器默认'
                    streamStatus='自动'
                    requestSummaryLabel='请求 1 张图片'
                    channelRouting={{
                        effectiveRequestModes: ['images-non-stream'],
                        requestModeHealth: [
                            {
                                mode: 'images-non-stream',
                                configuredCredentialCount: 1,
                                healthyCredentialCount: 1,
                                configuredChannelCount: 1,
                                healthyChannelCount: 1
                            }
                        ]
                    }}
                />
            </I18nProvider>
        );

        assert.match(html, /group static max-w-full shrink-0 sm:relative sm:basis-auto/);
        assert.match(html, /min-h-11 min-w-11 cursor-pointer/);
        assert.match(html, /sr-only sm:not-sr-only/);
        assert.match(html, /relative flex w-full min-w-0 flex-wrap/);
        assert.match(html, /sm:w-auto/);
        assert.match(html, /hidden h-3 w-px shrink-0 sm:block/);
        assert.match(html, /hidden truncate sm:inline/);
        assert.match(html, /absolute inset-x-0 top-full/);
        assert.match(html, /sm:right-auto sm:left-0 sm:w-\[min\(88vw,28rem\)\]/);
        assert.match(html, /xl:right-0 xl:left-auto/);
    });
});