fix(reconciliation): 运行时读复用知识库绑定 Key
- 为什么:运行时读另用 WEKNORA_RUNTIME_KEY_FILE(0400 文件、启动读一次),当前部署没有该文件,队列与处理详情恒不可用;换 Key 还要重启,且与绑定页不同步。 - 做什么:RuntimeProvider 改为每次请求经 kbbinding.Resolve(EnvTest) 取地址与 Key,与 reconciliationRemote 共用同一 resolver;删除配置字段/校验、ReadRuntimeKeyFile 与测试、compose/env、启动 WARN。 - 三态:绑定不可用→503 runtime_read_unavailable;上游 401/403→502 runtime_read_forbidden;超时/DNS→502 runtime_read_unreachable;overview 增 weknora_queue_error,页面三句不同文案并保留 WeKnora 跳转链接。 - 同步:openapi progress 契约与 502、需求书 §5/Q7、阶段计划、运维手册、CHANGELOG。 - 验证:make verify 17 项 success;新增换 Key 二次请求头、401/403/不可达分类、Service 透传、overview 原因码、页面三文案用例。
This commit is contained in:
@@ -581,17 +581,38 @@ func TestCreateRunEnqueuesJobWithinJobIDLimit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type progressRuntimeStub struct{ err error }
|
||||
type failingRuntime struct{ err error }
|
||||
|
||||
func (s progressRuntimeStub) DocumentProgress(context.Context, string) (governance.ReconciliationProgress, error) {
|
||||
return governance.ReconciliationProgress{}, s.err
|
||||
func (runtime failingRuntime) DocumentProgress(context.Context, string) (governance.ReconciliationProgress, error) {
|
||||
return governance.ReconciliationProgress{}, runtime.err
|
||||
}
|
||||
|
||||
func TestProgressPassesProviderClassificationInsteadOfRefolding(t *testing.T) {
|
||||
for _, want := range []error{ErrRuntimeForbidden, ErrRuntimeUnreachable, ErrRuntimeUnavailable} {
|
||||
service := &Service{runtime: progressRuntimeStub{err: want}}
|
||||
if _, err := service.Progress(context.Background(), "doc-1"); !errors.Is(err, want) {
|
||||
t.Fatalf("Progress err=%v, want %v", err, want)
|
||||
}
|
||||
// Progress must not re-collapse the provider's classification: the page needs
|
||||
// "no binding", "no permission" and "unreachable" to stay distinct.
|
||||
func TestProgressPreservesClassifiedRuntimeErrors(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
err error
|
||||
want error
|
||||
}{
|
||||
{name: "unavailable", err: ErrRuntimeUnavailable, want: ErrRuntimeUnavailable},
|
||||
{name: "forbidden", err: ErrRuntimeForbidden, want: ErrRuntimeForbidden},
|
||||
{name: "unreachable", err: ErrRuntimeUnreachable, want: ErrRuntimeUnreachable},
|
||||
{name: "not found", err: &weknora.HTTPError{StatusCode: http.StatusNotFound}, want: ErrNotFound},
|
||||
{name: "unclassified", err: errors.New("boom"), want: ErrRuntimeUnavailable},
|
||||
}
|
||||
for _, testCase := range cases {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
service, err := New(Config{
|
||||
Store: &fakeReconciliationStore{}, Remote: &fakeReconciliationRemote{},
|
||||
Runtime: failingRuntime{err: testCase.err},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := service.Progress(context.Background(), "doc-1"); !errors.Is(err, testCase.want) {
|
||||
t.Fatalf("Progress err = %v, want %v", err, testCase.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user