Add route-D web contract and experiment matrix
Route-D preview JSON now reports durationMs on the flat, project and edit paths, and project preview/PDF responses carry X-Preview-Engine (route-d or v1), including cache hits and silent fallback. The server tests assert the headers, the duration field and both PDF engines. docs/WEB_ROUTE_D_EXPERIMENT.md records the audit verdict, the initial contract probe, the supported/gap matrix, the three-project trial plan and the prioritised backlog; ROUTE_D_STATUS.md links to it and the test counts move to 1063.
This commit is contained in:
1 parent
c49afbdecb
commit
1058122388
7 files changed
+190
-20
No files matched your search
+29
-13
@@ -113,7 +113,7 @@ fn handle_request(
|
||||
}
|
||||
};
|
||||
match compiler.compile(&source, &input_path.display().to_string()) {
|
||||
Ok(pdf) => respond_pdf(request, pdf),
|
||||
Ok(pdf) => respond_pdf(request, pdf, "v1"),
|
||||
Err(error) => respond(request, 422, "text/plain; charset=utf-8", &error),
|
||||
}
|
||||
}
|
||||
@@ -181,12 +181,12 @@ fn handle_request(
|
||||
};
|
||||
let key = route_d_flat_cache_key(&source);
|
||||
if let Some(pdf) = route_d_cached_flat_pdf(key) {
|
||||
return respond_pdf_with_cache(request, pdf, "hit");
|
||||
return respond_pdf_with_cache(request, pdf, "hit", "route-d");
|
||||
}
|
||||
match route_d::pdf_bytes(&source) {
|
||||
Ok(pdf) => {
|
||||
store_route_d_flat_pdf(key, &pdf);
|
||||
respond_pdf_with_cache(request, pdf, "miss")
|
||||
respond_pdf_with_cache(request, pdf, "miss", "route-d")
|
||||
}
|
||||
Err(error) => respond_api_error(request, 422, &error),
|
||||
}
|
||||
@@ -432,33 +432,44 @@ fn respond_with_cache(
|
||||
.map_err(|error| format!("could not send response: {error}"))
|
||||
}
|
||||
|
||||
fn respond_pdf_with_cache(request: Request, pdf: Vec<u8>, cache_state: &str) -> Result<(), String> {
|
||||
fn respond_pdf_with_cache(
|
||||
request: Request,
|
||||
pdf: Vec<u8>,
|
||||
cache_state: &str,
|
||||
engine: &str,
|
||||
) -> Result<(), String> {
|
||||
let content_type = Header::from_bytes("Content-Type", "application/pdf")
|
||||
.map_err(|_| "invalid PDF response header".to_string())?;
|
||||
let disposition = Header::from_bytes("Content-Disposition", "inline; filename=preview.pdf")
|
||||
.map_err(|_| "invalid PDF response header".to_string())?;
|
||||
let cache = Header::from_bytes("X-Texrra-Cache", cache_state)
|
||||
.map_err(|_| "invalid cache response header".to_string())?;
|
||||
let engine = Header::from_bytes("X-Preview-Engine", engine)
|
||||
.map_err(|_| "invalid engine response header".to_string())?;
|
||||
request
|
||||
.respond(
|
||||
Response::from_data(pdf)
|
||||
.with_header(content_type)
|
||||
.with_header(disposition)
|
||||
.with_header(cache),
|
||||
.with_header(cache)
|
||||
.with_header(engine),
|
||||
)
|
||||
.map_err(|error| format!("could not send PDF response: {error}"))
|
||||
}
|
||||
|
||||
fn respond_pdf(request: Request, pdf: Vec<u8>) -> Result<(), String> {
|
||||
fn respond_pdf(request: Request, pdf: Vec<u8>, engine: &str) -> Result<(), String> {
|
||||
let content_type = Header::from_bytes("Content-Type", "application/pdf")
|
||||
.map_err(|_| "invalid PDF response header".to_string())?;
|
||||
let disposition = Header::from_bytes("Content-Disposition", "inline; filename=preview.pdf")
|
||||
.map_err(|_| "invalid PDF response header".to_string())?;
|
||||
let engine = Header::from_bytes("X-Preview-Engine", engine)
|
||||
.map_err(|_| "invalid engine response header".to_string())?;
|
||||
request
|
||||
.respond(
|
||||
Response::from_data(pdf)
|
||||
.with_header(content_type)
|
||||
.with_header(disposition),
|
||||
.with_header(disposition)
|
||||
.with_header(engine),
|
||||
)
|
||||
.map_err(|error| format!("could not send PDF response: {error}"))
|
||||
}
|
||||
@@ -1297,18 +1308,23 @@ fn handle_project_request(
|
||||
let images = load_project_images(&expanded, &store, id);
|
||||
let key = route_d_cache_key(id, &expanded, &images);
|
||||
if let Some(json) = route_d_cached_preview(&key) {
|
||||
return respond_json(request, 200, &preview_without_changes(&json));
|
||||
return respond_json_engine(
|
||||
request,
|
||||
200,
|
||||
&preview_without_changes(&json),
|
||||
"route-d",
|
||||
);
|
||||
}
|
||||
match route_d::project_preview_json_with_images(id, &expanded, &images) {
|
||||
Ok(json) => {
|
||||
store_route_d_preview(key, json.clone());
|
||||
return respond_json(request, 200, &json);
|
||||
return respond_json_engine(request, 200, &json, "route-d");
|
||||
}
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
match compiler.preview_json(&source, &file_name) {
|
||||
Ok(json) => respond_json(request, 200, &json),
|
||||
Ok(json) => respond_json_engine(request, 200, &json, "v1"),
|
||||
Err(error) => respond(
|
||||
request,
|
||||
422,
|
||||
@@ -1327,18 +1343,18 @@ fn handle_project_request(
|
||||
let images = load_project_images(&expanded, &store, id);
|
||||
let key = route_d_cache_key(id, &expanded, &images);
|
||||
if let Some(pdf) = route_d_cached_pdf(&key) {
|
||||
return respond_pdf_with_cache(request, pdf, "hit");
|
||||
return respond_pdf_with_cache(request, pdf, "hit", "route-d");
|
||||
}
|
||||
match route_d::pdf_bytes_with_images(&expanded, &images) {
|
||||
Ok(pdf) => {
|
||||
store_route_d_pdf(key, &pdf);
|
||||
return respond_pdf_with_cache(request, pdf, "miss");
|
||||
return respond_pdf_with_cache(request, pdf, "miss", "route-d");
|
||||
}
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
match compiler.compile(&source, &file_name) {
|
||||
Ok(pdf) => respond_pdf(request, pdf),
|
||||
Ok(pdf) => respond_pdf(request, pdf, "v1"),
|
||||
Err(error) => respond(request, 422, "text/plain; charset=utf-8", &error),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user