Add GET /enhance/prompts: recent distinct Enhance prompts
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c6d04589d1
commit
cdc339021b
7 files changed
+243
-3
No files matched your search
@@ -263,6 +263,7 @@ impl Fx {
|
||||
.service(super::get_templates)
|
||||
.service(super::submit)
|
||||
.service(super::list_jobs)
|
||||
.service(super::recent_prompts)
|
||||
.service(super::get_job)
|
||||
.service(super::preview)
|
||||
.service(super::approve)
|
||||
@@ -991,3 +992,62 @@ async fn busy_queue_blocks_the_free() {
|
||||
fx.svc.idle_check().await;
|
||||
assert_eq!(fx.mock.free_calls.load(Ordering::SeqCst), 0);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn recent_prompts_lists_distinct_trimmed_prompts_even_when_discarded() {
|
||||
let fx = fx().await;
|
||||
fx.put(PHOTO, b"photo");
|
||||
let mut ids = Vec::new();
|
||||
for prompt in ["warmer", " warmer ", "less grain"] {
|
||||
let (st, job, _) = call(
|
||||
&fx,
|
||||
"POST",
|
||||
"/enhance",
|
||||
Some(json!({"path": PHOTO, "template": "restore", "prompt": prompt})),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(st, 200);
|
||||
ids.push(job["id"].as_str().unwrap().to_string());
|
||||
}
|
||||
call(
|
||||
&fx,
|
||||
"POST",
|
||||
&format!("/enhance/jobs/{}/discard", ids[0]),
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
|
||||
let (st, body, _) = call(&fx, "GET", "/enhance/prompts", None).await;
|
||||
assert_eq!(st, 200);
|
||||
let rows = body["prompts"].as_array().unwrap();
|
||||
let texts: Vec<(&str, i64)> = rows
|
||||
.iter()
|
||||
.map(|r| (r["prompt"].as_str().unwrap(), r["uses"].as_i64().unwrap()))
|
||||
.collect();
|
||||
assert_eq!(texts.iter().map(|t| t.1).sum::<i64>(), 3);
|
||||
assert!(texts.contains(&("warmer", 2)) && texts.contains(&("less grain", 1)));
|
||||
assert_eq!(rows[0]["template"], "restore");
|
||||
assert!(rows[0]["last_used"].as_i64().unwrap() > 0);
|
||||
|
||||
let (_, body, _) = call(&fx, "GET", "/enhance/prompts?templates=nope", None).await;
|
||||
assert_eq!(body, json!({"prompts": []}));
|
||||
let (_, body, _) = call(
|
||||
&fx,
|
||||
"GET",
|
||||
"/enhance/prompts?templates=nope,restore&limit=0",
|
||||
None,
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
body["prompts"].as_array().unwrap().len(),
|
||||
1,
|
||||
"limit clamps to 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn recent_prompts_answers_when_enhance_is_off() {
|
||||
let fx = fx_with(None, |c| c.url = None).await;
|
||||
let (st, body, _) = call(&fx, "GET", "/enhance/prompts", None).await;
|
||||
assert_eq!((st, body), (200, json!({"prompts": []})));
|
||||
}
|
||||
Reference in new issue
Block a user