Tarot readings: AI-written, drawn on the server, sold as units
A new Kártyajóslás page: choose a spread (1, 3 or 5 cards), ask a question, pick the cards from the fanned deck and watch them turn over; the reading is written by the detailed-analysis model from the cards, their positions and base meanings, the question and the reader's Sun, Moon and Ascendant. The server shuffles and draws, so nobody can draw again for free. A reading is a 'tarot' analysis (worker, retries, fallback, refunds and admin regeneration as for analyses), uses one 'tarot' unit, and survives recalculations; deleting the account deletes it. Packages carry 2/5/10 readings, the new +5 kártyajóslás addon costs 1 000 Ft. The card artwork comes from the tarot design studio (celestial astrolabe style); the deck JSON is shared by the frontend and the prompt. A public example is at /kartyajoslas/pelda. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -927,4 +927,66 @@ mod analyses {
|
||||
assert!(user.starts_with("Képletadatok:\n\nSYNASTRY") && user.contains("Person 2"), "both charts");
|
||||
assert!(!user.contains("Szeged") && !user.contains("Pécs"));
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn tarot_readings_are_written_in_the_quick_lane_and_refunded_on_failure(db: PgPool) {
|
||||
let s = setup(&db).await;
|
||||
let tarot = json!({"spread": "trinity", "question": "Merre induljak tovább?",
|
||||
"cards": [{"card": "major-0", "reversed": false}, {"card": "cups-3", "reversed": true},
|
||||
{"card": "major-17", "reversed": false}],
|
||||
"sun": "cancer", "moon": "pisces", "ascendant": "aries"});
|
||||
let reading = |id: Uuid| {
|
||||
sqlx::query(
|
||||
"INSERT INTO analyses (id, kind, requested_by, language, model, prompt_version, cache_key, \
|
||||
credits_charged, tarot) \
|
||||
VALUES ($1, 'tarot', $2, 'hu', 'test/analysis', 'v3', 'tarot|x', 1, $3)",
|
||||
)
|
||||
.bind(id)
|
||||
.bind(s.user)
|
||||
.bind(&tarot)
|
||||
};
|
||||
let done = Uuid::now_v7();
|
||||
reading(done).execute(&db).await.unwrap();
|
||||
let written = json!({"title": "Új kezdet csendben", "summary": "Összefoglaló.",
|
||||
"cards": [{"body": "Első."}, {"body": "Második."}, {"body": "Harmadik."}],
|
||||
"synthesis": "Együtt.", "advice": "Lépj."});
|
||||
let (fake, url) = fake_openrouter(vec![reply(&written), (400, json!({"error": {"message": "bad"}}))]).await;
|
||||
let a = analyzer(&db, &url);
|
||||
// Not in the slow lane: a reading should not wait behind long analyses.
|
||||
assert!(a.claim(Lane::Slow).await.unwrap().is_none());
|
||||
let job = a.claim(Lane::Quick).await.unwrap().expect("the reading");
|
||||
a.handle(job).await;
|
||||
let (status, title): (String, Option<String>) =
|
||||
sqlx::query_as("SELECT status, content->>'title' FROM analyses WHERE id = $1")
|
||||
.bind(done)
|
||||
.fetch_one(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!((status.as_str(), title.as_deref()), ("done", Some("Új kezdet csendben")));
|
||||
{
|
||||
let requests = fake.requests.lock().unwrap();
|
||||
assert_eq!(requests[0]["model"], "test/analysis");
|
||||
let user = requests[0]["messages"][1]["content"].as_str().unwrap();
|
||||
assert!(
|
||||
user.contains("Merre induljak tovább?") && user.contains("A Bolond") && user.contains("Nap: Rák"),
|
||||
"{user}"
|
||||
);
|
||||
assert_eq!(requests[0]["response_format"]["json_schema"]["name"], "tarot_reading");
|
||||
}
|
||||
|
||||
// A permanent failure gives the tarot unit back.
|
||||
let failed = Uuid::now_v7();
|
||||
reading(failed).execute(&db).await.unwrap();
|
||||
let job = a.claim(Lane::Quick).await.unwrap().expect("the second reading");
|
||||
a.handle(job).await;
|
||||
let (status, refund): (String, Option<String>) = sqlx::query_as(
|
||||
"SELECT a.status, (SELECT unit FROM credit_ledger WHERE analysis_id = a.id AND reason = 'refund') \
|
||||
FROM analyses a WHERE a.id = $1",
|
||||
)
|
||||
.bind(failed)
|
||||
.fetch_one(&db)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!((status.as_str(), refund.as_deref()), ("failed", Some("tarot")));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user