- 变基到 CYWL-38 的 reconciliationMessages 之后:沿用 runtime_key_forbidden / runtime_unreachable 公共码,不再另造一套。 - HTTP 仍按本任务裁定用 502 区分上游拒绝/失败与绑定不可用 503。 - 页面文案统一由 reconciliationMessages 输出;按新 Key 来源改写「平台只读 Key」措辞。 - 同步 monitoring 原因码与相关测试;make verify 17 项全绿。
This commit is contained in:
@@ -46,8 +46,8 @@ func TestRuntimeQueueProjectionStatesWhyQueueIsAbsent(t *testing.T) {
|
|||||||
code string
|
code string
|
||||||
}{
|
}{
|
||||||
{name: "binding unavailable", err: reconciliation.ErrRuntimeUnavailable, code: "runtime_read_unavailable"},
|
{name: "binding unavailable", err: reconciliation.ErrRuntimeUnavailable, code: "runtime_read_unavailable"},
|
||||||
{name: "key forbidden", err: reconciliation.ErrRuntimeForbidden, code: "runtime_read_forbidden"},
|
{name: "key forbidden", err: reconciliation.ErrRuntimeForbidden, code: "runtime_key_forbidden"},
|
||||||
{name: "unreachable", err: reconciliation.ErrRuntimeUnreachable, code: "runtime_read_unreachable"},
|
{name: "unreachable", err: reconciliation.ErrRuntimeUnreachable, code: "runtime_unreachable"},
|
||||||
{name: "unclassified", err: errors.New("boom"), code: ""},
|
{name: "unclassified", err: errors.New("boom"), code: ""},
|
||||||
}
|
}
|
||||||
for _, testCase := range cases {
|
for _, testCase := range cases {
|
||||||
|
|||||||
@@ -98,52 +98,6 @@ func TestRuntimeProviderResolvesKeyOnEveryRequest(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRuntimeProviderClassifiesUpstreamFailures(t *testing.T) {
|
|
||||||
cases := []struct {
|
|
||||||
name string
|
|
||||||
status int
|
|
||||||
want error
|
|
||||||
}{
|
|
||||||
{name: "unauthorized", status: http.StatusUnauthorized, want: ErrRuntimeForbidden},
|
|
||||||
{name: "forbidden", status: http.StatusForbidden, want: ErrRuntimeForbidden},
|
|
||||||
{name: "server error still unavailable", status: http.StatusInternalServerError, want: ErrRuntimeUnavailable},
|
|
||||||
}
|
|
||||||
for _, testCase := range cases {
|
|
||||||
t.Run(testCase.name, func(t *testing.T) {
|
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
|
||||||
w.WriteHeader(testCase.status)
|
|
||||||
}))
|
|
||||||
defer server.Close()
|
|
||||||
provider := NewRuntimeProvider(RuntimeConfig{
|
|
||||||
Resolve: staticConnection(server.URL, "runtime-key"),
|
|
||||||
Timeout: 5 * time.Second,
|
|
||||||
})
|
|
||||||
if _, err := provider.Queues(context.Background()); !errors.Is(err, testCase.want) {
|
|
||||||
t.Fatalf("queues err = %v, want %v", err, testCase.want)
|
|
||||||
}
|
|
||||||
if _, err := provider.DocumentProgress(context.Background(), "doc-1"); !errors.Is(err, testCase.want) {
|
|
||||||
t.Fatalf("progress err = %v, want %v", err, testCase.want)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRuntimeProviderClassifiesUnreachable(t *testing.T) {
|
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {}))
|
|
||||||
url := server.URL
|
|
||||||
server.Close()
|
|
||||||
provider := NewRuntimeProvider(RuntimeConfig{
|
|
||||||
Resolve: staticConnection(url, "runtime-key"),
|
|
||||||
Timeout: time.Second,
|
|
||||||
})
|
|
||||||
if _, err := provider.Queues(context.Background()); !errors.Is(err, ErrRuntimeUnreachable) {
|
|
||||||
t.Fatalf("queues err = %v, want %v", err, ErrRuntimeUnreachable)
|
|
||||||
}
|
|
||||||
if _, err := provider.DocumentProgress(context.Background(), "doc-1"); !errors.Is(err, ErrRuntimeUnreachable) {
|
|
||||||
t.Fatalf("progress err = %v, want %v", err, ErrRuntimeUnreachable)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRuntimeProviderUnavailableAndNotFound(t *testing.T) {
|
func TestRuntimeProviderUnavailableAndNotFound(t *testing.T) {
|
||||||
unavailable := NewRuntimeProvider(RuntimeConfig{
|
unavailable := NewRuntimeProvider(RuntimeConfig{
|
||||||
Resolve: func(context.Context) (string, string, error) { return "", "", nil },
|
Resolve: func(context.Context) (string, string, error) { return "", "", nil },
|
||||||
@@ -173,8 +127,8 @@ func TestRuntimeProviderUnavailableAndNotFound(t *testing.T) {
|
|||||||
func TestRuntimeErrorCodeDistinguishesStates(t *testing.T) {
|
func TestRuntimeErrorCodeDistinguishesStates(t *testing.T) {
|
||||||
cases := map[string]error{
|
cases := map[string]error{
|
||||||
"runtime_read_unavailable": ErrRuntimeUnavailable,
|
"runtime_read_unavailable": ErrRuntimeUnavailable,
|
||||||
"runtime_read_forbidden": ErrRuntimeForbidden,
|
"runtime_key_forbidden": ErrRuntimeForbidden,
|
||||||
"runtime_read_unreachable": ErrRuntimeUnreachable,
|
"runtime_unreachable": ErrRuntimeUnreachable,
|
||||||
"": errors.New("unclassified"),
|
"": errors.New("unclassified"),
|
||||||
}
|
}
|
||||||
for want, err := range cases {
|
for want, err := range cases {
|
||||||
@@ -243,8 +197,8 @@ func TestRuntimeProviderClassifiesForbiddenAndUnreachable(t *testing.T) {
|
|||||||
}))
|
}))
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
provider := NewRuntimeProvider(RuntimeConfig{
|
provider := NewRuntimeProvider(RuntimeConfig{
|
||||||
BaseURL: func(context.Context) string { return server.URL },
|
Resolve: staticConnection(server.URL, "runtime-key"),
|
||||||
APIKey: "runtime-key", Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
})
|
})
|
||||||
if _, err := provider.DocumentProgress(context.Background(), "doc-1"); !errors.Is(err, tc.want) {
|
if _, err := provider.DocumentProgress(context.Background(), "doc-1"); !errors.Is(err, tc.want) {
|
||||||
t.Fatalf("status %d err=%v, want %v", tc.status, err, tc.want)
|
t.Fatalf("status %d err=%v, want %v", tc.status, err, tc.want)
|
||||||
@@ -260,8 +214,7 @@ func TestRuntimeProviderClassifiesClosedListenerAsUnreachable(t *testing.T) {
|
|||||||
url := server.URL
|
url := server.URL
|
||||||
server.Close()
|
server.Close()
|
||||||
provider := NewRuntimeProvider(RuntimeConfig{
|
provider := NewRuntimeProvider(RuntimeConfig{
|
||||||
BaseURL: func(context.Context) string { return url },
|
Resolve: staticConnection(url, "runtime-key"), Timeout: 2 * time.Second,
|
||||||
APIKey: "runtime-key", Timeout: 2 * time.Second,
|
|
||||||
})
|
})
|
||||||
if _, err := provider.DocumentProgress(context.Background(), "doc-1"); !errors.Is(err, ErrRuntimeUnreachable) {
|
if _, err := provider.DocumentProgress(context.Background(), "doc-1"); !errors.Is(err, ErrRuntimeUnreachable) {
|
||||||
t.Fatalf("closed listener err=%v, want %v", err, ErrRuntimeUnreachable)
|
t.Fatalf("closed listener err=%v, want %v", err, ErrRuntimeUnreachable)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ var (
|
|||||||
ErrActionNotAllowed = errors.New("reconciliation action not allowed")
|
ErrActionNotAllowed = errors.New("reconciliation action not allowed")
|
||||||
ErrRemoteFailed = errors.New("reconciliation remote call failed")
|
ErrRemoteFailed = errors.New("reconciliation remote call failed")
|
||||||
ErrRuntimeUnavailable = errors.New("weknora runtime read unavailable")
|
ErrRuntimeUnavailable = errors.New("weknora runtime read unavailable")
|
||||||
// ErrRuntimeForbidden / ErrRuntimeUnreachable 把「Key 无权限」与「连不上」
|
// ErrRuntimeForbidden / ErrRuntimeUnreachable 把「Key 无权限」与「连不上」
|
||||||
// 从 ErrRuntimeUnavailable 里拆出来:页面要给两种不同的中文,不能再折叠。
|
// 从 ErrRuntimeUnavailable 里拆出来:页面要给两种不同的中文,不能再折叠。
|
||||||
ErrRuntimeForbidden = errors.New("weknora runtime key forbidden")
|
ErrRuntimeForbidden = errors.New("weknora runtime key forbidden")
|
||||||
ErrRuntimeUnreachable = errors.New("weknora runtime read unreachable")
|
ErrRuntimeUnreachable = errors.New("weknora runtime read unreachable")
|
||||||
|
|||||||
@@ -142,14 +142,14 @@ describe('ServiceStrip queue availability', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('tells the operator to authorize the missing permission', () => {
|
it('tells the operator to authorize the missing permission', () => {
|
||||||
const html = renderToStaticMarkup(<ServiceStrip overview={overview(null, 'runtime_read_forbidden')} />)
|
const html = renderToStaticMarkup(<ServiceStrip overview={overview(null, 'runtime_key_forbidden')} />)
|
||||||
expect(html).toContain('当前 Key 缺少平台运行时读权限')
|
expect(html).toContain('当前 Key 缺少平台运行时读权限')
|
||||||
expect(html).not.toContain('连不上 WeKnora')
|
expect(html).not.toContain('连不上 WeKnora')
|
||||||
expect(html).not.toContain('runtime_read_forbidden')
|
expect(html).not.toContain('runtime_key_forbidden')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('reports an unreachable instance instead of a missing key', () => {
|
it('reports an unreachable instance instead of a missing key', () => {
|
||||||
const html = renderToStaticMarkup(<ServiceStrip overview={overview(null, 'runtime_read_unreachable')} />)
|
const html = renderToStaticMarkup(<ServiceStrip overview={overview(null, 'runtime_unreachable')} />)
|
||||||
expect(html).toContain('连不上 WeKnora')
|
expect(html).toContain('连不上 WeKnora')
|
||||||
expect(html).not.toContain('缺少平台运行时读权限')
|
expect(html).not.toContain('缺少平台运行时读权限')
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ describe('WeKnora progress drawer block', () => {
|
|||||||
)
|
)
|
||||||
await act(async () => root.render(<WeKnoraProgress documentID="doc-1" />))
|
await act(async () => root.render(<WeKnoraProgress documentID="doc-1" />))
|
||||||
await act(async () => await Promise.resolve())
|
await act(async () => await Promise.resolve())
|
||||||
expect(container.textContent).toContain('未配置知识库绑定或绑定不可用')
|
expect(container.textContent).toContain('未配置知识库绑定或绑定不可用')
|
||||||
})
|
})
|
||||||
it('names the missing permission when the key is rejected', async () => {
|
it('names the missing permission when the key is rejected', async () => {
|
||||||
vi.stubGlobal(
|
vi.stubGlobal(
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ describe('platform task drawer', () => {
|
|||||||
)
|
)
|
||||||
await act(async () => root.render(<TaskDetail item={item} onClose={vi.fn()} />))
|
await act(async () => root.render(<TaskDetail item={item} onClose={vi.fn()} />))
|
||||||
await act(async () => await Promise.resolve())
|
await act(async () => await Promise.resolve())
|
||||||
expect(container.textContent).toContain('未配置知识库绑定或绑定不可用')
|
expect(container.textContent).toContain('未配置知识库绑定或绑定不可用')
|
||||||
expect(container.querySelector('a[href="https://weknora.test/platform/knowledge-bases/kb-1"]')).not.toBeNull()
|
expect(container.querySelector('a[href="https://weknora.test/platform/knowledge-bases/kb-1"]')).not.toBeNull()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user