合入今晚直改的回归测试与通道缺口修复(R5-Z36)
This commit is contained in:
commit
cd4c4079c7
@ -2431,12 +2431,17 @@ test('main and grouped assistants crop a candidate into another output of the sa
|
||||
const closeup={id:'closeup',fieldId:'M01',documentId:'M01',width:800,height:800};
|
||||
host.productionGoal.requestedOutputs=[detail,main];
|
||||
host.canvas.workflowRead=async()=>({available:true,canvasFirst:true,...detail,productVariantId:'oak',
|
||||
template:{contentHash:'studio'},totalSlots:1,slots:[medium]});
|
||||
template:{contentHash:'studio'},totalSlots:2,slots:[medium,{id:'outside',fieldId:'D02',documentId:'S02',width:800,height:800}]});
|
||||
host.canvas.detailHistory=async({targetOutput,projectImages})=>projectImages
|
||||
?[{candidateId:'medium',adoptionRecorded:true}]
|
||||
:{...main,template:{contentHash:'main-studio'},productVariantId:'oak',slots:[closeup]};
|
||||
const metrics={cropSourcePixels:[1024,960],targetFrame:[800,800],resolutionRatio:1.2,resolutionSufficient:true};
|
||||
const requests=[];
|
||||
const reads=[];
|
||||
host.canvas.detailImages=async id=>{
|
||||
reads.push(id);
|
||||
return {images:[{type:'image',mimeType:'image/png',data:'fixture'}],referenceCount:0};
|
||||
};
|
||||
host.canvas.imageRequest=async(action,args,_signal,scope)=>{
|
||||
if(action==='pending')return [];
|
||||
assert.equal(action,'transform');
|
||||
@ -2455,7 +2460,8 @@ test('main and grouped assistants crop a candidate into another output of the sa
|
||||
const plan=await call('plan_production',{});
|
||||
assert.deepEqual(plan.projectSlots,[
|
||||
{...detail,slots:[{id:'hero',fieldId:'D01',screen:'S01',framePixels:[2048,1536],
|
||||
templateHasProduct:null,candidates:['medium'],adoptionRecorded:['medium']}]},
|
||||
templateHasProduct:null,candidates:['medium'],adoptionRecorded:['medium']},
|
||||
{id:'outside',fieldId:'D02',screen:'S02',framePixels:[800,800],templateHasProduct:null}]},
|
||||
{...main,slots:[{id:'closeup',fieldId:'M01',screen:'M01',framePixels:[800,800],templateHasProduct:null}]},
|
||||
]);
|
||||
assert.equal(requests.length,0);
|
||||
@ -2467,6 +2473,12 @@ test('main and grouped assistants crop a candidate into another output of the sa
|
||||
try{
|
||||
assert.deepEqual(JSON.parse(prompt).groupTargets,[{...detail,slotId:'hero'},{...main,slotId:'closeup'}]);
|
||||
const tool=tools.find(tool=>tool.name==='transform_slot_image');
|
||||
const read=tools.find(tool=>tool.name==='read_slot_images');
|
||||
await read.execute('',{slotId:'outside'});
|
||||
assert.deepEqual(reads,['outside']);
|
||||
await assert.rejects(tool.execute('',{slotId:'outside',sourceCandidateId:'medium',crop}),/不在本次委托/);
|
||||
const adopt=tools.find(tool=>tool.name==='adopt_production_image');
|
||||
await assert.rejects(adopt.execute('',{slotId:'outside',candidateId:'medium'}),/不在本次委托/);
|
||||
const source=await tool.execute('',{referenceIndex:0});
|
||||
assert.equal(source.details.candidateId,'worker-medium');
|
||||
const result=await tool.execute('',{outputId:main.outputId,slotId:'closeup',sourceCandidateId:source.details.candidateId,crop});
|
||||
|
||||
@ -944,6 +944,10 @@ impl Backend {
|
||||
json!({"model":saved["model"].as_str().unwrap_or(""),"imageModel":saved["imageModel"].as_str().unwrap_or(""),"copyModel":crate::jiansun_models::copy_selection(saved).as_str().unwrap_or(""),"copyModels":self.copy_models,"copyReady":ready(crate::jiansun_models::copy_selection(saved),&self.copy_models),"copyCatalogError":self.copy_error,"modelReady":ready(&saved["model"],&self.models),"imageReady":ready(&saved["imageModel"],&self.image_models),"keySaved":key_saved,"availableModels":available,"models":self.models,"imageModels":self.image_models,"imageCatalogError":self.image_error,"thinkingByModel":saved["thinkingByModel"]})
|
||||
}
|
||||
fn state(&mut self) -> R<Value> {
|
||||
self.state_with_catalog(Self::public_model_catalog)
|
||||
}
|
||||
|
||||
fn state_with_catalog(&mut self, load_catalog: impl FnOnce(&Self) -> R<Value>) -> R<Value> {
|
||||
let mut message = String::new();
|
||||
let mut available = None;
|
||||
let mut library_status = "sign_in_required";
|
||||
@ -981,7 +985,7 @@ impl Backend {
|
||||
}
|
||||
}
|
||||
}
|
||||
match self.public_model_catalog() {
|
||||
match load_catalog(self) {
|
||||
Ok(catalog) => {
|
||||
if has_key.is_none() || available.is_some() {
|
||||
self.refresh_image_models(&catalog, &saved, available.as_deref());
|
||||
@ -2522,16 +2526,23 @@ mod tests {
|
||||
.build()
|
||||
.unwrap().into();
|
||||
let scope = backend.scope();
|
||||
let (events, _received) = mpsc::channel();
|
||||
let catalog = json!({"data":{"sections":[{"models":[{"id":"fixture-text","modality":"text",
|
||||
"status":"available","available":true,"invocation":{"method":"POST","path":"/v1/chat/completions",
|
||||
"content_type":"application/json","authentication":{"type":"bearer","header":"Authorization"},
|
||||
"input_schema":{"properties":{"model":{},"messages":{},"stream":{},"tools":{}}}}}]}]}});
|
||||
for (status, expected) in [(401, "sign_in_required"), (403, "forbidden"), (503, "unavailable"),
|
||||
(502, "unavailable"), (403, "disabled")] {
|
||||
let state = backend.action("connection-check", &json!({}), &events, &egui::Context::default()).unwrap();
|
||||
let state = backend.state_with_catalog(|_| Ok(catalog.clone())).unwrap();
|
||||
assert_eq!(state["libraryHttpStatus"], status);
|
||||
assert_eq!(state["libraryStatus"], expected);
|
||||
assert_eq!(state["account"]["id"], "retained-local-owner");
|
||||
assert_eq!(backend.scope(), scope, "failed authorization must not move local drafts into another scope");
|
||||
assert_eq!(backend.auth["access_token"], "local-test-only");
|
||||
assert!(state["models"].as_array().unwrap().is_empty());
|
||||
let models = state["models"].as_array().unwrap();
|
||||
assert_eq!(models.len(), usize::from(expected == "unavailable"));
|
||||
if expected == "unavailable" {
|
||||
assert_eq!(models[0]["id"], "fixture-text");
|
||||
}
|
||||
assert_ne!(state["modelReady"], true);
|
||||
if expected == "forbidden" {
|
||||
assert!(state["message"].as_str().unwrap().contains("访问权限"));
|
||||
@ -2543,6 +2554,9 @@ mod tests {
|
||||
}
|
||||
}
|
||||
server.join().unwrap();
|
||||
let state = backend.state_with_catalog(|_| Ok(catalog)).unwrap();
|
||||
assert_eq!(state["libraryStatus"], "unavailable");
|
||||
assert_eq!(state["models"][0]["id"], "fixture-text");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@ -679,6 +679,15 @@ fn variants(dir: &Path, brief: &Value, previous: Option<&Value>) -> R<Vec<Value>
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
fn skeleton_component<'a>(state: &'a Value, input: &'a Value) -> R<&'a str> {
|
||||
let enterprise = &state["template"]["enterprise"];
|
||||
if input["brief"].is_object() && !state["productTemplates"].is_object() && enterprise.is_object() {
|
||||
enterprise["component"].as_str().ok_or_else(|| "固定模板组件缺失".into())
|
||||
} else {
|
||||
Ok(input["outputId"].as_str().unwrap_or("detail"))
|
||||
}
|
||||
}
|
||||
|
||||
fn canvas_template(previous: Option<&Value>, selected: &Value, brand: &str, category: &str, fetch: impl FnOnce() -> R<Value>) -> R<Value> {
|
||||
// An existing project owns its immutable pack. A newer catalogue entry is
|
||||
// relevant only when explicitly creating another project/version.
|
||||
@ -2082,6 +2091,17 @@ impl Backend {
|
||||
|| state["activeVariantId"].as_str() != Some(variant_id.as_str()) {
|
||||
return Err("当前模板、输出或花色已变化".into());
|
||||
}
|
||||
let candidate_id = target["candidateId"].as_str();
|
||||
let candidate_record = candidate_id.map(|id| read_candidate(&dir, id)).transpose()?;
|
||||
if let Some((candidate, record)) = candidate_id.zip(candidate_record.as_ref()) {
|
||||
if record["binding"]["variantId"] != variant_id {
|
||||
return Err("候选图属于其他花色,不能放进本图位".into());
|
||||
}
|
||||
if !candidate_available(record) {
|
||||
return Ok(json!({"candidateId":candidate,"candidateReady":false,"phase":record["phase"],
|
||||
"retired":!record["retirement"].is_null(),"candidateSlotId":record["binding"]["slotId"]}));
|
||||
}
|
||||
}
|
||||
let references = generation_references(&dir, &state, &variant_id)?;
|
||||
let mut images = Vec::new();
|
||||
let reference_limit = if state["productTemplates"].is_object() { 8 } else { 3 };
|
||||
@ -2123,8 +2143,6 @@ impl Backend {
|
||||
}
|
||||
}
|
||||
let reference_count = images.len();
|
||||
let candidate_id = target["candidateId"].as_str();
|
||||
let candidate_record = candidate_id.map(|id| read_candidate(&dir, id)).transpose()?;
|
||||
let candidate_prompt = candidate_record.as_ref().map(|record| record["prompt"].clone());
|
||||
let is_production_review = state["productTemplates"].is_object() && candidate_record.is_some();
|
||||
let template_base = candidate_record.as_ref().is_some_and(|record| record["templateBase"] == true);
|
||||
@ -2173,14 +2191,6 @@ impl Backend {
|
||||
let mut candidate_original = None;
|
||||
let mut candidate_file = None;
|
||||
if let Some((candidate, record)) = candidate_id.zip(candidate_record) {
|
||||
// 候选还没出完或已退役时如实回报状态;同花色其他图位的候选可放进本图位查看,便于复用和裁切。
|
||||
if !candidate_available(&record) {
|
||||
return Ok(json!({"candidateId":candidate,"candidateReady":false,"phase":record["phase"],
|
||||
"retired":!record["retirement"].is_null(),"candidateSlotId":record["binding"]["slotId"]}));
|
||||
}
|
||||
if record["binding"]["variantId"] != variant_id {
|
||||
return Err("候选图属于其他花色,不能放进本图位".into());
|
||||
}
|
||||
let inspect_ground = is_production_review && target["groundContactDetail"] == true;
|
||||
let inspect_edges = is_production_review && target["sceneEdgeDetails"] == true;
|
||||
let action_region: Option<[u8; 4]> = if is_production_review && !target["actionReviewRegion"].is_null() {
|
||||
@ -4381,11 +4391,7 @@ impl Backend {
|
||||
prepared["baseRevision"] = input["baseRevision"].clone();
|
||||
return Ok(prepared);
|
||||
}
|
||||
let component = input["outputId"].as_str().unwrap_or("detail");
|
||||
let component = if input["brief"].is_object() && state["template"]["enterprise"]["adapterVersion"] == 4
|
||||
&& !state["productTemplates"].is_object() {
|
||||
state["template"]["enterprise"]["component"].as_str().ok_or("固定模板组件缺失")?
|
||||
} else { component }.to_owned();
|
||||
let component = skeleton_component(&state, input)?.to_owned();
|
||||
let component = component.as_str();
|
||||
if let Some(reason) = state["productTemplateIssues"][component].as_str() {
|
||||
return Err(reason.to_owned());
|
||||
@ -5766,6 +5772,21 @@ mod tests {
|
||||
assert_eq!(read_json(&file).unwrap()["phase"], "prepared");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_component_skeleton_uses_the_component_declared_by_either_channel() {
|
||||
let input = json!({"brief":{}});
|
||||
for enterprise in [
|
||||
json!({"sourceKind":"xiaoyi-release","component":"main_images"}),
|
||||
json!({"sourceKind":"resource-map","adapterVersion":4,"component":"main_images"}),
|
||||
] {
|
||||
let mut state = json!({"template":{"enterprise":enterprise}});
|
||||
assert_eq!(skeleton_component(&state, &input).unwrap(), "main_images");
|
||||
state["productTemplates"] = json!({});
|
||||
assert_eq!(skeleton_component(&state, &input).unwrap(), "detail");
|
||||
assert_eq!(skeleton_component(&state, &json!({"outputId":"sku_images"})).unwrap(), "sku_images");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn product_start_reports_runnable_outputs_without_opening_a_canvas() {
|
||||
let fixture = fixture();
|
||||
@ -6404,7 +6425,32 @@ mod tests {
|
||||
write_json(&source_job.join("task.json"), &task).unwrap();
|
||||
fs::write(source_job.join("generated.png"), &pixels).unwrap();
|
||||
source["artifact"] = template_slots::artifact(dir, &source_id, &task).unwrap();
|
||||
reserve(dir, state, &source).unwrap();
|
||||
reserve(dir, state.clone(), &source).unwrap();
|
||||
|
||||
let mut view = json!({"outputId":"detail","variantId":variant,"slotId":slot,
|
||||
"templateHash":state["template"]["contentHash"],"candidateId":source_id,
|
||||
"candidatePixels":true,"includeTemplateReference":false,"includeProductReferences":false});
|
||||
let preview = backend.read_detail_review_images(doc, &view, None).unwrap();
|
||||
assert_eq!(preview["candidateFile"]["width"], 1800);
|
||||
assert_eq!(preview["images"].as_array().unwrap().len(), 1);
|
||||
let mut pending = candidate(dir, "running");
|
||||
let pending_file = candidate_path(dir, pending["id"].as_str().unwrap()).unwrap();
|
||||
write_json(&pending_file, &pending).unwrap();
|
||||
view["candidateId"] = pending["id"].clone();
|
||||
let outcome = backend.read_detail_review_images(doc, &view, None).unwrap();
|
||||
assert_eq!(outcome["candidateReady"], false);
|
||||
assert_eq!(outcome["phase"], "running");
|
||||
assert_eq!(outcome["candidateSlotId"], pending["binding"]["slotId"]);
|
||||
pending["phase"] = json!("complete");
|
||||
pending["retirement"] = json!({"reason":"fixture"});
|
||||
write_json(&pending_file, &pending).unwrap();
|
||||
let retired = backend.read_detail_review_images(doc, &view, None).unwrap();
|
||||
assert_eq!(retired["candidateReady"], false);
|
||||
assert_eq!(retired["retired"], true);
|
||||
pending["binding"]["variantId"] = json!(Uuid::new_v4().to_string());
|
||||
write_json(&pending_file, &pending).unwrap();
|
||||
assert_eq!(backend.read_detail_review_images(doc, &view, None).unwrap_err(), "候选图属于其他花色,不能放进本图位");
|
||||
fs::remove_file(pending_file).unwrap();
|
||||
|
||||
let mut action = json!({"action":"transform","scope":scope,"revision":1,
|
||||
"request":{"slotId":slot,"sourceCandidateId":source_id,"transform":{"crop":[250,200,750,800]}}});
|
||||
|
||||
@ -188,6 +188,11 @@ pub fn select(catalog: &Value, model: &str) -> Result<Value, String> {
|
||||
}
|
||||
|
||||
pub fn select_model(m: &Value) -> Result<Value, String> {
|
||||
let pinned = std::env::var("PHOTOCRAFT_IMAGE_ROUTE_OPTION").ok();
|
||||
select_model_route(m, pinned.as_deref())
|
||||
}
|
||||
|
||||
fn select_model_route(m: &Value, pinned: Option<&str>) -> Result<Value, String> {
|
||||
let model = m["id"].as_str().ok_or("98k模型编号无效")?;
|
||||
if m["available"] == false || m["status"].as_str().is_some_and(|s| s != "available") || m["modality"] != "image" {
|
||||
return Err("所选生图模型当前不可用".into());
|
||||
@ -205,7 +210,7 @@ pub fn select_model(m: &Value) -> Result<Value, String> {
|
||||
}
|
||||
let id = route["id"].as_str().unwrap_or("");
|
||||
// 运维可用环境变量指定本次使用的生图线路,例如低价线路上游欠费时。
|
||||
if std::env::var("PHOTOCRAFT_IMAGE_ROUTE_OPTION").is_ok_and(|pinned| pinned != id) {
|
||||
if pinned.is_some_and(|pinned| pinned != id) {
|
||||
continue;
|
||||
}
|
||||
if !token(id)
|
||||
@ -345,6 +350,26 @@ mod tests {
|
||||
fn catalog() -> Value {
|
||||
json!({"data":{"sections":[{"models":[{"id":"test-image","modality":"image","available":true,"status":"available","default_service_scope_id":"scope-a","default_route_option_id":"route-a","service_offers":[{"service_scope":{"id":"scope-a"},"route_options":[{"id":"route-a","available":true,"invocation":{"method":"POST","path":"/v1/images/generations","content_type":"application/json","headers":{"X-Relay-Route-Option":"route-a"},"input_schema":{"type":"object","additionalProperties":true,"properties":{"model":{"type":"string"},"prompt":{"type":"string"},"n":{"type":"integer"},"response_format":{"type":"string"}}}}}]}]}]}]}})
|
||||
}
|
||||
#[test]
|
||||
fn a_pinned_route_never_falls_back_to_the_cheaper_route() {
|
||||
let mut catalog = catalog();
|
||||
let model = &mut catalog["data"]["sections"][0]["models"][0];
|
||||
let routes = model["service_offers"][0]["route_options"].as_array_mut().unwrap();
|
||||
routes[0]["pricing"]["effective_price"] = json!(1);
|
||||
let mut alternate = routes[0].clone();
|
||||
alternate["id"] = json!("route-b");
|
||||
alternate["pricing"]["effective_price"] = json!(2);
|
||||
alternate["invocation"]["headers"]["X-Relay-Route-Option"] = json!("route-b");
|
||||
alternate["invocation"]["input_schema"]["properties"]["image"] =
|
||||
json!({"type":"array","items":{"type":"string"}});
|
||||
routes.push(alternate);
|
||||
assert_eq!(select_model_route(model, None).unwrap()["route"], "route-a");
|
||||
assert_eq!(select_model_route(model, Some("route-b")).unwrap()["route"], "route-b");
|
||||
assert!(select_model_route(model, Some("missing")).is_err());
|
||||
model["service_offers"][0]["route_options"][1]["available"] = json!(false);
|
||||
assert!(select_model_route(model, Some("route-b")).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn offered_portrait_sizes_keep_local_scene_edits_aligned() {
|
||||
let mut contract = json!({
|
||||
|
||||
@ -839,12 +839,12 @@ impl Backend {
|
||||
if response.status().is_server_error() {
|
||||
return self.check_dispatch();
|
||||
}
|
||||
let (code, value) = body(response, MAX_JSON)?;
|
||||
if code == 401 {
|
||||
if response.status().as_u16() == 401 {
|
||||
self.revoke_access("auth_revoked");
|
||||
let _ = self.renew_portal_session();
|
||||
return Err(AUTH_REVOKED.into());
|
||||
}
|
||||
let (code, value) = body(response, MAX_JSON)?;
|
||||
if code == 200 && value["account"]["id"] != self.auth["account"]["id"] {
|
||||
self.revoke_access("scope_changed");
|
||||
return Err(ACCOUNT_CHANGED.into());
|
||||
@ -1453,6 +1453,39 @@ impl Backend {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn library_outages_preserve_access_but_revocations_and_account_changes_block() {
|
||||
use std::net::TcpListener;
|
||||
for (status, body, expected) in [
|
||||
(502, "<html>Bad Gateway</html>", None),
|
||||
(0, "", None),
|
||||
(401, "<html>Unauthorized</html>", Some(AUTH_REVOKED)),
|
||||
(200, r#"{"account":{"id":"different-account"}}"#, Some(ACCOUNT_CHANGED)),
|
||||
] {
|
||||
for deadline in [None, Some(Instant::now() + Duration::from_secs(10))] {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
|
||||
let origin = format!("http://{}", listener.local_addr().unwrap());
|
||||
let server = (status != 0).then(|| std::thread::spawn(move || {
|
||||
let (mut stream, _) = listener.accept().unwrap();
|
||||
stream.set_read_timeout(Some(Duration::from_secs(3))).unwrap();
|
||||
let mut request = [0; 4096];
|
||||
assert!(stream.read(&mut request).unwrap() > 0);
|
||||
write!(stream, "HTTP/1.1 {status} Test\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", body.len()).unwrap();
|
||||
}));
|
||||
let fixture = canvas_post_fixture();
|
||||
let mut backend = Backend::new(fixture.dir.join("profile")).unwrap();
|
||||
backend.origin = origin;
|
||||
backend.auth = json!({"access_token":"fixture","account":{"id":"fixture-owner"}});
|
||||
backend.http = Client::builder().no_proxy().timeout(Duration::from_secs(3)).build().unwrap().into();
|
||||
let result = backend.image_validate(deadline);
|
||||
assert_eq!(result.as_ref().err().map(String::as_str), expected);
|
||||
assert_eq!(backend.auth["account"]["id"], "fixture-owner");
|
||||
assert_eq!(backend.check_dispatch().is_err(), expected.is_some());
|
||||
if let Some(server) = server { server.join().unwrap(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn response_is_recoverable_until_the_original_request_is_settled() {
|
||||
let fixture = canvas_post_fixture();
|
||||
|
||||
@ -115,11 +115,12 @@ fn knowledge_catalog(pack:&Value, creation:&Value) -> R<Value> {
|
||||
let category=&creation["brief"]["categoryId"];
|
||||
let brand_key=format!("enterprise:{}",brand.as_str().ok_or("项目品牌缺失")?);
|
||||
// 小壹专用通道的模板以发布版本标识来源,旧通道的模板以资源组标识。
|
||||
let source=if pack["enterprise"]["sourceKind"]=="xiaoyi-release" {
|
||||
pack["enterprise"]["snapshotVersion"].as_str()
|
||||
let enterprise = &pack["enterprise"];
|
||||
let source = if enterprise["sourceKind"] == "xiaoyi-release" {
|
||||
enterprise["snapshotVersion"].as_str().ok_or("小壹模板发布版本缺失")?
|
||||
} else {
|
||||
pack["enterprise"]["resourceSetId"].as_str()
|
||||
}.ok_or("模板资源组缺失")?;
|
||||
enterprise["resourceSetId"].as_str().ok_or("模板资源组缺失")?
|
||||
};
|
||||
let revision=&pack["contentHash"];
|
||||
let screens=pack["outputs"].as_array().ok_or("模板页面缺失")?.iter()
|
||||
.map(|output|json!({"id":output["id"],"title":output["name"],"role":"content"})).collect::<Vec<_>>();
|
||||
@ -132,6 +133,13 @@ fn knowledge_catalog(pack:&Value, creation:&Value) -> R<Value> {
|
||||
"template":{"id":pack["id"],"sourceVersion":pack["version"],"sourceCanvas":pack["enterprise"]["canvas"],"screens":screens}}]}))
|
||||
}
|
||||
|
||||
fn matches_knowledge_template(saved: &Value, selected: &Value) -> bool {
|
||||
let binding = &saved["catalog"]["bindings"][0];
|
||||
binding["template"]["id"] == selected["id"]
|
||||
&& binding["template"]["sourceVersion"] == selected["version"]
|
||||
&& binding["revision"] == selected["contentHash"]
|
||||
}
|
||||
|
||||
fn knowledge_rule(b:&Backend,doc:u64,production:bool) -> R<Option<(Option<Value>,Value)>> {
|
||||
let dir=b.project_dir(doc)?;
|
||||
let creation=super::creation::load(&dir)?;
|
||||
@ -144,8 +152,7 @@ fn knowledge_rule(b:&Backend,doc:u64,production:bool) -> R<Option<(Option<Value>
|
||||
return Ok(Some((None,json!({"state":"needs-template","reason":"请先选择知识库品类与模板"}))));
|
||||
}
|
||||
if let Some(saved)=original_rule(&dir)?.filter(|saved|rule_cache::matches_project(saved,brand,category)
|
||||
&& saved["catalog"]["bindings"][0]["template"]["id"]==selected["id"]
|
||||
&& saved["catalog"]["bindings"][0]["template"]["sourceVersion"]==selected["version"]) {
|
||||
&& matches_knowledge_template(saved, selected)) {
|
||||
if creation["designSnapshot"]["rules"]!=saved {
|
||||
can_change_rule(&dir)?;
|
||||
super::creation::attach_agent_rules(&dir,&saved)?;
|
||||
@ -1068,6 +1075,27 @@ mod tests {
|
||||
assert_eq!(saved["catalog"]["source"],"enterprise-knowledge");
|
||||
assert_eq!(saved["catalog"]["bindings"][0]["source"], "b".repeat(32));
|
||||
}
|
||||
#[test]
|
||||
fn release_knowledge_catalog_uses_the_locked_snapshot_version() {
|
||||
let version = "release-version-2";
|
||||
let pack = json!({"id":"desk","version":version,"contentHash":"a".repeat(64),
|
||||
"enterprise":{"sourceKind":"xiaoyi-release","snapshotVersion":version,"canvas":[1440,4000]},
|
||||
"outputs":[{"id":"D01","name":"详情首屏"}]});
|
||||
let creation = json!({"brief":{"brandId":"ekb:brand:顾家","brandName":"顾家",
|
||||
"categoryId":"ekb:category:电脑桌","categoryName":"电脑桌"}});
|
||||
let catalog = knowledge_catalog(&pack, &creation).unwrap();
|
||||
let saved = rule_cache::package("desk", &json!({"catalog":catalog,"revision":pack["contentHash"]}), None).unwrap();
|
||||
assert!(rule_cache::matches_project(&saved, "ekb:brand:顾家", "ekb:category:电脑桌"));
|
||||
let binding = &saved["catalog"]["bindings"][0];
|
||||
assert_eq!(binding["source"], version);
|
||||
assert_eq!(binding["template"]["screens"][0]["id"], "D01");
|
||||
assert!(matches_knowledge_template(&saved, &pack));
|
||||
let mut another_component = pack.clone();
|
||||
another_component["contentHash"] = json!("b".repeat(64));
|
||||
another_component["outputs"] = json!([{"id":"M01","name":"主图"}]);
|
||||
assert!(!matches_knowledge_template(&saved, &another_component));
|
||||
}
|
||||
|
||||
use super::super::{Client, HashMap};
|
||||
#[test]
|
||||
fn reconcile_transport_allows_only_explicit_read_only_actions() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user