forge
Explore
Log in

Don't you dare go Hollow

Send the school's class names with the report payload

Browse files at this commit

49f96655eecb9d8998a1b9c6ab4be1785310ba11Ahmet Kaan GümüşParent: 8ce2e1d
  • feat
    • send the school's class names with the report payload
Show full message
✨ feat(insight): send the school's class names with the report payload

The live document printed raw class UUIDs under its Şube header: the
summaries' own evidence carries class ids, so the renderer had nothing else
to print. A machine identifier on the most human-facing artifact we ship is
exactly the defect the report exists to remove.

Additive payload key `classes: [{id, name}]` — a sibling of `school`, not a
member of it: it is a lookup for the rows, not part of the school's identity.
Read whole from the school's own `class_group` in name order (tens of rows);
a class a row names but the list does not carry is absent on purpose, and the
renderer falls back to an honest label rather than a name invented here. The
row lists are untouched.

Pinned in the payload contract test (the encoded JSON carries `classes`) and
in the round-trip test (a class created through `POST /classes` arrives with
its name).
Local-Gate: c07c6c1e530a9d2924068b3471ee5dbc2c98fd93 (1497 passed, 451s)
.sqlx/query-a1451a96ea5c3c080d934a4f60d8d4f4f7f3ef907fa211f2952951fa5fac2637.jsonadded+38 -0
@@ -0,0 +1,38 @@
1+{
2+ "db_name": "PostgreSQL",
3+ "query": "SELECT id, name FROM class_group ORDER BY name, id",
4+ "describe": {
5+ "columns": [
6+ {
7+ "ordinal": 0,
8+ "name": "id",
9+ "type_info": "Uuid",
10+ "origin": {
11+ "Table": {
12+ "table": "class_group",
13+ "name": "id"
14+ }
15+ }
16+ },
17+ {
18+ "ordinal": 1,
19+ "name": "name",
20+ "type_info": "Text",
21+ "origin": {
22+ "Table": {
23+ "table": "class_group",
24+ "name": "name"
25+ }
26+ }
27+ }
28+ ],
29+ "parameters": {
30+ "Left": []
31+ },
32+ "nullable": [
33+ false,
34+ false
35+ ]
36+ },
37+ "hash": "a1451a96ea5c3c080d934a4f60d8d4f4f7f3ef907fa211f2952951fa5fac2637"
38+}
src/ai/insight.rsmodified+16 -3
@@ -220,6 +220,14 @@ pub struct ReportRequest {
220220 /// The school's own identity, so the document prints a display name
221221 /// rather than a slug.
222222 pub school: ReportSchool,
223+ /// Every class (şube) of the school, id and display name: the summaries'
224+ /// evidence carries class **ids**, and a document that groups by class
225+ /// must print the name a reader recognizes. A sibling key rather than a
226+ /// member of [`Self::school`]: it is a lookup for the rows, not part of
227+ /// the school's identity. A class a row names but this list does not
228+ /// carry (a deleted one) is absent on purpose — the renderer falls back
229+ /// to an honest label, never a name invented here.
230+ pub classes: Vec<ClassLabel>,
223231 /// Every stored summary (with its attention items) in the school.
224232 pub summaries: Vec<SummaryRow>,
225233 pub recommendations: Vec<RecommendationRow>,
@@ -358,9 +366,9 @@ fn malformed(err: serde_json::Error) -> AiError {
358366 // names exist, what each payload is, and how a refusal reads.
359367
360368 pub use crate::db::insight::{
361- AttentionRow, PendingList, ProfileRow, ProfileWriteRequest, PurgeRequest, RecommendationRow,
362- RecommendationWriteRequest, ReportSchool, RunRow, RunWriteRequest, SchoolDirectory,
363- SegmentConfidences, SegmentLabels, SegmentRow, SegmentWriteRequest, SummaryRow,
369+ AttentionRow, ClassLabel, PendingList, ProfileRow, ProfileWriteRequest, PurgeRequest,
370+ RecommendationRow, RecommendationWriteRequest, ReportSchool, RunRow, RunWriteRequest,
371+ SchoolDirectory, SegmentConfidences, SegmentLabels, SegmentRow, SegmentWriteRequest, SummaryRow,
364372 SummaryWriteRequest, TableVerdicts, WriteReceipt,
365373 };
366374
@@ -609,6 +617,10 @@ mod tests {
609617 slug: "demo".into(),
610618 name: "Demo Okulu".into(),
611619 },
620+ classes: vec![ClassLabel {
621+ id: "class-1".into(),
622+ name: "8-A".into(),
623+ }],
612624 summaries: Vec::new(),
613625 recommendations: Vec::new(),
614626 profiles: Vec::new(),
@@ -621,6 +633,7 @@ mod tests {
621633 "run_day": "2026-09-17",
622634 "requested_by": "user-9",
623635 "school": { "id": "school-1", "slug": "demo", "name": "Demo Okulu" },
636+ "classes": [{ "id": "class-1", "name": "8-A" }],
624637 "summaries": [],
625638 "recommendations": [],
626639 "profiles": [],
src/db/insight.rsmodified+31 -0
@@ -326,6 +326,16 @@ pub struct ReportSchool {
326326 pub name: String,
327327 }
328328
329+/// One class (şube) as a rendered document labels it: the id the summaries'
330+/// own evidence carries, and the display name a reader should see in its
331+/// place. A document that prints the id instead is a machine identifier on
332+/// the most human-facing artifact the product ships.
333+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
334+pub struct ClassLabel {
335+ pub id: String,
336+ pub name: String,
337+}
338+
329339 // ---- shared validation -----------------------------------------------------
330340
331341 /// Refuse a batch past [`MAX_INSIGHT_BATCH_ROWS`] rather than taking it
@@ -874,6 +884,27 @@ pub async fn school_identity(
874884 }))
875885 }
876886
887+/// Every class (şube) of the school, id and display name, in name order.
888+///
889+/// The service's summaries carry class ids inside their own evidence objects,
890+/// so a document that groups by class has only those ids to print — and an id
891+/// is not a label. This is the lookup that turns them into names. It is sent
892+/// whole rather than narrowed to the ids the current rows mention: a school's
893+/// class list is tens of rows, and a partial list would make the renderer's
894+/// fallback depend on how complete this read's filters were.
895+pub async fn all_classes(db: &Database) -> Result<Vec<ClassLabel>, AppError> {
896+ let rows = sqlx::query!("SELECT id, name FROM class_group ORDER BY name, id")
897+ .fetch_all(db)
898+ .await?;
899+ Ok(rows
900+ .into_iter()
901+ .map(|row| ClassLabel {
902+ id: row.id.to_string(),
903+ name: row.name,
904+ })
905+ .collect())
906+}
907+
877908 // ---- the school-wide reads the report payload carries -----------------------
878909 //
879910 // Every read above is per-student or per-audience, because that is every
src/web/insights.rsmodified+1 -0
@@ -413,6 +413,7 @@ async fn generate_report(
413413 run_day: run_day.clone(),
414414 requested_by: user.get_id().key(),
415415 school,
416+ classes: db::insight::all_classes(&st.db).await?,
416417 summaries: db::insight::all_summaries(&st.db).await?,
417418 recommendations: db::insight::all_recommendations(&st.db).await?,
418419 profiles: db::insight::all_profiles(&st.db).await?,
tests/insight_report.rsmodified+11 -0
@@ -429,6 +429,7 @@ async fn a_generated_report_is_stored_and_served_to_its_manager() {
429429 let manager_id = common::me_id(&app, &manager).await;
430430 let student = common::login(&app, "ali").await;
431431 let student_id = common::me_id(&app, &student).await;
432+ let class_id = common::create_class(&app, &manager, "8-A", json!({})).await;
432433 seed_report_rows(&db, "2026-09-16", &student_id, &manager_id).await;
433434
434435 let res = generate(&app, &manager, "2026-09-16").await;
@@ -463,6 +464,16 @@ async fn a_generated_report_is_stored_and_served_to_its_manager() {
463464 .is_some_and(|name| !name.is_empty()),
464465 "the school's display name travels"
465466 );
467+ // The class (şube) lookup: the summaries' evidence carries class ids, and
468+ // the document must print the name a reader recognizes.
469+ let classes = request.payload["classes"]
470+ .as_array()
471+ .expect("classes is a list");
472+ let seeded = classes
473+ .iter()
474+ .find(|row| row["id"] == class_id.as_str())
475+ .expect("the school's own class is in the payload");
476+ assert_eq!(seeded["name"], "8-A");
466477 let summaries = request.payload["summaries"]
467478 .as_array()
468479 .expect("summaries is a list");