- 生产页保存对内/对外库时,在同一事务内把还没上传、原本瞄准旧生产库的待入库项改指向新库,并在保存提示里回报迁移条数;执行已开始的项目标保持冻结。 - 重排改为「上一次生效目标 → 新目标」成对过滤:测试与生产共用 test_publications,测试侧保存不再带走瞄准生产库的待入库(验收附带发现)。 - 用例补生产重排、测试侧保存不误搬生产作业、生产保存不动测试作业三组断言。
This commit is contained in:
@@ -30,11 +30,17 @@ func fakeCandidate(t *testing.T) *httptest.Server {
|
||||
}
|
||||
switch {
|
||||
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}]}`))
|
||||
_, _ = w.Write([]byte(`{"success":true,"total":5,"data":[{"id":"kb-in","name":"内部技术资料","knowledge_count":3},{"id":"kb-out","name":"客户使用手册","knowledge_count":4},{"id":"p-internal","name":"生产内部资料","knowledge_count":5},{"id":"p-external","name":"生产客户手册","knowledge_count":6},{"id":"p-new-internal","name":"生产内部资料新版","knowledge_count":0}]}`))
|
||||
case r.URL.Path == "/api/v1/knowledge-bases/kb-in":
|
||||
_, _ = 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":"客户使用手册","tenant_id":10000}}`))
|
||||
case r.URL.Path == "/api/v1/knowledge-bases/p-internal":
|
||||
_, _ = w.Write([]byte(`{"success":true,"data":{"id":"p-internal","name":"生产内部资料","tenant_id":10000}}`))
|
||||
case r.URL.Path == "/api/v1/knowledge-bases/p-external":
|
||||
_, _ = w.Write([]byte(`{"success":true,"data":{"id":"p-external","name":"生产客户手册","tenant_id":10000}}`))
|
||||
case r.URL.Path == "/api/v1/knowledge-bases/p-new-internal":
|
||||
_, _ = w.Write([]byte(`{"success":true,"data":{"id":"p-new-internal","name":"生产内部资料新版","tenant_id":10000}}`))
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
@@ -69,11 +75,14 @@ func TestSaveReadsBackResolvesTheKeyAndReplansPendingInOneTransaction(t *testing
|
||||
if _, err := pool.Exec(ctx, `
|
||||
INSERT INTO source_connections(id,source_type,name,enabled) VALUES('conn-kbb','manual','KBB',true);
|
||||
INSERT INTO source_items(id,source_connection_id,stable_external_id,canonical_uri_hash,normalized_path,title,item_type,revision,visibility,visibility_origin) VALUES
|
||||
('item-kbb','conn-kbb','n-kbb',repeat('c',64),'docs/kbb.docx','kbb.docx','document','locator:r1','internal','configured_scope');
|
||||
('item-kbb','conn-kbb','n-kbb',repeat('c',64),'docs/kbb.docx','kbb.docx','document','locator:r1','internal','configured_scope'),
|
||||
('item-prod-kbb','conn-kbb','n-prod-kbb',repeat('d',64),'docs/prod-kbb.docx','prod-kbb.docx','document','locator:r2','internal','configured_scope');
|
||||
INSERT INTO source_item_versions(id,source_item_id,revision,content_object_id,content_state) VALUES
|
||||
('version-kbb','item-kbb','locator:r1',NULL,'unknown');
|
||||
('version-kbb','item-kbb','locator:r1',NULL,'unknown'),
|
||||
('version-prod-kbb','item-prod-kbb','locator:r2',NULL,'unknown');
|
||||
INSERT INTO test_publications(id,source_item_version_id,test_kb_id,processing_state,ingest_state,target_scope) VALUES
|
||||
('pub-kbb','version-kbb','kb-old','planned','pending','internal');
|
||||
('pub-kbb','version-kbb','kb-legacy-in','planned','pending','internal'),
|
||||
('pub-prod-kbb','version-prod-kbb','p-internal','planned','pending','internal');
|
||||
`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -139,6 +148,15 @@ INSERT INTO test_publications(id,source_item_version_id,test_kb_id,processing_st
|
||||
if pendingKB != "kb-in" {
|
||||
t.Fatalf("pending publication target = %s, want kb-in", pendingKB)
|
||||
}
|
||||
// A save on the test card must not carry off pending work that already aims
|
||||
// at the production binding: the two environments share test_publications.
|
||||
var productionPending string
|
||||
if err := pool.QueryRow(ctx, `SELECT test_kb_id FROM test_publications WHERE id='pub-prod-kbb'`).Scan(&productionPending); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if productionPending != "p-internal" {
|
||||
t.Fatalf("test-side save moved a production pending item to %s", productionPending)
|
||||
}
|
||||
|
||||
// A stale revision must not overwrite the saved connection or re-point work.
|
||||
_, err = store.Save(ctx, kbbinding.EnvTest, kbbinding.SaveInput{
|
||||
@@ -184,20 +202,46 @@ INSERT INTO test_publications(id,source_item_version_id,test_kb_id,processing_st
|
||||
|
||||
prodView, err := store.Save(ctx, kbbinding.EnvProduction, kbbinding.SaveInput{
|
||||
BaseRevision: 0, BaseURL: server.URL, KeyAction: "replace", APIKey: testSecret(),
|
||||
InternalKBID: "kb-in", ExternalKBID: "kb-out",
|
||||
InternalKBID: "p-internal", ExternalKBID: "p-external",
|
||||
}, "admin", now)
|
||||
if err != nil {
|
||||
t.Fatalf("production Save() error = %v", err)
|
||||
}
|
||||
if prodView.Environment != kbbinding.EnvProduction || prodView.Revision != 1 {
|
||||
if prodView.Environment != kbbinding.EnvProduction || prodView.Revision != 1 || prodView.Replanned != 0 {
|
||||
t.Fatalf("production view = %#v", prodView)
|
||||
}
|
||||
// Changing the production internal base must re-point pending 待入库 items
|
||||
// that were waiting for p-internal (the C-006 failure), and must leave the
|
||||
// test-lane publication on its own target.
|
||||
prodMoved, err := store.Save(ctx, kbbinding.EnvProduction, kbbinding.SaveInput{
|
||||
BaseRevision: prodView.Revision, BaseURL: server.URL, KeyAction: "replace", APIKey: testSecret(),
|
||||
InternalKBID: "p-new-internal", ExternalKBID: "p-external",
|
||||
}, "admin", now.Add(time.Minute))
|
||||
if err != nil {
|
||||
t.Fatalf("production retarget Save() error = %v", err)
|
||||
}
|
||||
if prodMoved.Replanned != 1 || prodMoved.RetiredDuplicates != 0 {
|
||||
t.Fatalf("production replan = %d/%d, want 1 moved / 0 retired", prodMoved.Replanned, prodMoved.RetiredDuplicates)
|
||||
}
|
||||
var movedProduction, stillTest string
|
||||
if err := pool.QueryRow(ctx, `SELECT test_kb_id FROM test_publications WHERE id='pub-prod-kbb'`).Scan(&movedProduction); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if movedProduction != "p-new-internal" {
|
||||
t.Fatalf("production pending target = %s, want p-new-internal", movedProduction)
|
||||
}
|
||||
if err := pool.QueryRow(ctx, `SELECT test_kb_id FROM test_publications WHERE id='pub-kbb'`).Scan(&stillTest); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if stillTest != "kb-in" {
|
||||
t.Fatalf("test publication moved by a production save: %s", stillTest)
|
||||
}
|
||||
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" || productionURL != server.URL || productionTenant != 10000 {
|
||||
if productionInternal != "p-new-internal" || productionURL != server.URL || productionTenant != 10000 {
|
||||
t.Fatalf("production binding = %s / %s / %d", productionInternal, productionURL, productionTenant)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user