fix(release): 以实例身份阻断绑定与发布跨实例
网页可能在实例 A 上列库并保存生产绑定,而文档发布执行器实际连实例 B。 克隆实例可以有相同知识库 ID、名称甚至租户,单靠 ID 无法证明写的是同一个 目标。现在绑定保存会冻结候选实例地址/租户,发布计划把身份冻结到每个项, 执行器在 Contract/Prepare/Activate/Restore/Compensate 前核对;不一致以 release_contract_mismatch 非重试失败关闭,不写目标。整库发布目标不变。 测试入库对象在上传前记录实际实例地址/租户;轮询、验收、移除先核对当前 连接,改绑实例或租户后旧对象不会被克隆实例接管。旧行没有身份时失败关闭。 「知识库绑定」保存要求对内/对外各选一个库,不再把显式未绑定回落到部署 默认 ID,避免换绑实例后带过去旧对象的默认库。 验证:隔离 PostgreSQL 覆盖绑定身份落库与发布计划冻结;v071 用同 ID/同租户 的 A/B 实例做正反例;四个测试 handler 的实例错配负例;前端 607 项通过。
This commit is contained in:
@@ -32,9 +32,9 @@ func fakeCandidate(t *testing.T) *httptest.Server {
|
||||
case r.URL.Path == "/api/v1/knowledge-bases":
|
||||
_, _ = w.Write([]byte(`{"success":true,"total":2,"data":[{"id":"kb-in","name":"内部技术资料","knowledge_count":3},{"id":"kb-out","name":"客户使用手册","knowledge_count":4}]}`))
|
||||
case r.URL.Path == "/api/v1/knowledge-bases/kb-in":
|
||||
_, _ = w.Write([]byte(`{"success":true,"data":{"id":"kb-in","name":"内部技术资料"}}`))
|
||||
_, _ = w.Write([]byte(`{"success":true,"data":{"id":"kb-in","name":"内部技术资料","tenant_id":10000}}`))
|
||||
case r.URL.Path == "/api/v1/knowledge-bases/kb-out":
|
||||
_, _ = w.Write([]byte(`{"success":true,"data":{"id":"kb-out","name":"客户使用手册"}}`))
|
||||
_, _ = w.Write([]byte(`{"success":true,"data":{"id":"kb-out","name":"客户使用手册","tenant_id":10000}}`))
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
@@ -82,9 +82,14 @@ INSERT INTO test_publications(id,source_item_version_id,test_kb_id,processing_st
|
||||
MasterKeyFile: masterKey(t),
|
||||
Timeout: 2 * time.Second,
|
||||
AllowDockerHTTP: map[string]bool{kbbinding.EnvTest: true, kbbinding.EnvProduction: true},
|
||||
RoutingDefaults: func() (string, string) { return "env-in", "env-out" },
|
||||
})
|
||||
now := time.Date(2026, 11, 19, 8, 0, 0, 0, time.UTC)
|
||||
if _, err := store.Save(ctx, kbbinding.EnvTest, kbbinding.SaveInput{
|
||||
BaseRevision: 0, BaseURL: server.URL, KeyAction: "replace", APIKey: testSecret(),
|
||||
InternalKBID: "kb-in",
|
||||
}, "admin", now); !errors.Is(err, kbbinding.ErrInvalid) {
|
||||
t.Fatalf("save with an unbound side = %v, want ErrInvalid", err)
|
||||
}
|
||||
view, err := store.Save(ctx, kbbinding.EnvTest, kbbinding.SaveInput{
|
||||
BaseRevision: 0, BaseURL: server.URL, KeyAction: "replace", APIKey: testSecret(),
|
||||
InternalKBID: "kb-in", ExternalKBID: "kb-out",
|
||||
@@ -169,11 +174,12 @@ INSERT INTO test_publications(id,source_item_version_id,test_kb_id,processing_st
|
||||
if prodView.Environment != kbbinding.EnvProduction || prodView.Revision != 1 {
|
||||
t.Fatalf("production view = %#v", prodView)
|
||||
}
|
||||
var productionInternal string
|
||||
if err := pool.QueryRow(ctx, `SELECT internal_kb_id FROM production_kb_bindings WHERE id='active'`).Scan(&productionInternal); err != nil {
|
||||
var productionInternal, productionURL string
|
||||
var productionTenant uint64
|
||||
if err := pool.QueryRow(ctx, `SELECT internal_kb_id, internal_instance_url, internal_tenant_id FROM production_kb_bindings WHERE id='active'`).Scan(&productionInternal, &productionURL, &productionTenant); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if productionInternal != "kb-in" {
|
||||
t.Fatalf("production binding = %s", productionInternal)
|
||||
if productionInternal != "kb-in" || productionURL != server.URL || productionTenant != 10000 {
|
||||
t.Fatalf("production binding = %s / %s / %d", productionInternal, productionURL, productionTenant)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user