@@ -18948,11 +18948,12 @@ TEST(pipeline_semantic_edges_carry_p) {
1894818948 PASS();
1894918949}
1895018950
18951- /* The p a stored candidate row must carry: the curve of the row's kind and
18952- * position (read from its evidence) at its score, two decimals; -1 for an
18953- * unknown kind or position. *is_function: a function candidate (top 5). */
18954- static double doc_row_want(const char *evidence, cbm_sem_doc_format_t fmt, float score,
18955- bool *is_function) {
18951+ /* The p a stored candidate row of a section embedding diagrams of family fam
18952+ * must carry: the curve of the row's kind and position (read from its
18953+ * evidence) at its score, two decimals; -1 for an unknown kind or position.
18954+ * *is_function: a function candidate (top 5). */
18955+ static double doc_row_want_family(const char *evidence, cbm_sem_doc_format_t fmt,
18956+ cbm_sem_diag_family_t fam, float score, bool *is_function) {
1895618957 static const struct {
1895718958 const char *name;
1895818959 cbm_sem_doc_kind_t kind;
@@ -18973,8 +18974,14 @@ static double doc_row_want(const char *evidence, cbm_sem_doc_format_t fmt, float
1897318974 }
1897418975 *is_function = k == 0;
1897518976 return k < 0 || p < 0 ? -1.0
18976- : cbm_sem_p_2dp(cbm_sem_doc_calibrated_p(fmt, KINDS[k].kind,
18977- POSITIONS[p].pos, score));
18977+ : cbm_sem_p_2dp(cbm_sem_doc_section_p(fmt, fam, KINDS[k].kind,
18978+ POSITIONS[p].pos, score));
18979+ }
18980+
18981+ /* doc_row_want_family for a section without a diagram. */
18982+ static double doc_row_want(const char *evidence, cbm_sem_doc_format_t fmt, float score,
18983+ bool *is_function) {
18984+ return doc_row_want_family(evidence, fmt, CBM_SEM_DIAG_NONE, score, is_function);
1897818985}
1897918986
1898018987/* Count a section's stored doc -> code candidates (section QN containing
@@ -19219,6 +19226,133 @@ TEST(pipeline_doc_candidates_skip_exact_links_and_use_format_curves) {
1921919226 PASS();
1922019227}
1922119228
19229+ /* The rows of a section (its QN contains heading): their count; *bad the
19230+ * rows off the curve of the section's diagram family fam; *own the rows
19231+ * whose p differs from a section without a diagram. */
19232+ static int doc_family_rows(cbm_store_t *s, const char *heading, cbm_sem_diag_family_t fam, int *bad,
19233+ int *own) {
19234+ sqlite3_stmt *st = NULL;
19235+ *bad = 0;
19236+ *own = 0;
19237+ if (sqlite3_prepare_v2(cbm_store_get_db(s),
19238+ "SELECT score, p, evidence FROM doc_link_candidates "
19239+ "WHERE instr(section_qn, ?1) > 0",
19240+ -1, &st, NULL) != SQLITE_OK) {
19241+ return -1;
19242+ }
19243+ sqlite3_bind_text(st, 1, heading, -1, SQLITE_TRANSIENT);
19244+ int n = 0;
19245+ while (sqlite3_step(st) == SQLITE_ROW) {
19246+ float score = (float)sqlite3_column_double(st, 0);
19247+ double p = sqlite3_column_double(st, 1);
19248+ const char *ev = (const char *)sqlite3_column_text(st, 2);
19249+ bool is_function = false;
19250+ double want = doc_row_want_family(ev, CBM_SEM_DOC_FMT_MARKDOWN, fam, score, &is_function);
19251+ *bad += want <= 0.0 || p != want;
19252+ *own += want != doc_row_want(ev, CBM_SEM_DOC_FMT_MARKDOWN, score, &is_function);
19253+ n++;
19254+ }
19255+ sqlite3_finalize(st);
19256+ return n;
19257+ }
19258+
19259+ /* The diagram_kind of the Diagram a section (its QN contains heading)
19260+ * DEFINES, "" without one. */
19261+ static void doc_section_diagram_kind(cbm_store_t *s, const char *heading, char *out,
19262+ size_t out_sz) {
19263+ sqlite3_stmt *st = NULL;
19264+ out[0] = '\0';
19265+ if (sqlite3_prepare_v2(cbm_store_get_db(s),
19266+ "SELECT json_extract(d.properties, '$.diagram_kind') FROM edges e "
19267+ "JOIN nodes a ON a.id = e.source_id JOIN nodes d ON d.id = e.target_id "
19268+ "WHERE e.type = 'DEFINES' AND a.label = 'Section' "
19269+ "AND d.label = 'Diagram' AND instr(a.qualified_name, ?1) > 0",
19270+ -1, &st, NULL) != SQLITE_OK) {
19271+ return;
19272+ }
19273+ sqlite3_bind_text(st, 1, heading, -1, SQLITE_TRANSIENT);
19274+ if (sqlite3_step(st) == SQLITE_ROW && sqlite3_column_text(st, 0)) {
19275+ snprintf(out, out_sz, "%s", (const char *)sqlite3_column_text(st, 0));
19276+ }
19277+ sqlite3_finalize(st);
19278+ }
19279+
19280+ /* A Markdown section that embeds a diagram takes its diagram family's judged
19281+ * curve (DIAG-C): a sequence diagram is structural, a flowchart is prose; a
19282+ * section without a diagram keeps the Markdown curve. Some rows of each
19283+ * diagram section must carry a p the Markdown curve would not give. */
19284+ TEST(pipeline_doc_candidates_diagram_family_curves) {
19285+ char tmp[256];
19286+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_docdiag_XXXXXX");
19287+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));
19288+ static const char *const subjects[] = {"mail", "cache", "queue", "user", "server", "client"};
19289+ for (size_t i = 0; i < sizeof(subjects) / sizeof(subjects[0]); i++) {
19290+ write_py_family(tmp, subjects[i]);
19291+ }
19292+ char docs[512];
19293+ snprintf(docs, sizeof(docs), "%s/docs", tmp);
19294+ ASSERT_TRUE(cbm_mkdir_p(docs, 0755));
19295+ write_temp_file(
19296+ tmp, "docs/mail.md",
19297+ "# Mail loading\n\n"
19298+ "Load the mail config from disk and validate every mail field before the "
19299+ "parsed mail settings are returned; missing mail fields fail the validation.\n\n"
19300+ "```mermaid\nsequenceDiagram\n"
19301+ " participant Loader\n participant Validator\n"
19302+ " Loader->>Validator: validate mail config\n```\n\n"
19303+ "# Mail writing\n\n"
19304+ "Write the mail config back to disk after validating it, so the written "
19305+ "mail config file always carries every mail field it needs.\n\n"
19306+ "```mermaid\nflowchart TD\n"
19307+ " validate[validate mail config] --> write[write mail config]\n```\n\n"
19308+ "# Mail parsing\n\n"
19309+ "Parse the mail config file and return the parsed mail settings; the mail "
19310+ "config is loaded from disk and every mail field is validated first.\n");
19311+ char db[512];
19312+ snprintf(db, sizeof(db), "%s/docdiag.db", tmp);
19313+ cbm_pipeline_incremental_test_reset_faults();
19314+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db, CBM_MODE_FULL);
19315+ ASSERT_NOT_NULL(p);
19316+ ASSERT_EQ(cbm_pipeline_run(p), 0);
19317+ cbm_pipeline_free(p);
19318+
19319+ cbm_store_t *s = cbm_store_open_path(db);
19320+ ASSERT_NOT_NULL(s);
19321+ char seq_kind[32];
19322+ char flow_kind[32];
19323+ char none_kind[32];
19324+ doc_section_diagram_kind(s, "Mail-loading", seq_kind, sizeof(seq_kind));
19325+ doc_section_diagram_kind(s, "Mail-writing", flow_kind, sizeof(flow_kind));
19326+ doc_section_diagram_kind(s, "Mail-parsing", none_kind, sizeof(none_kind));
19327+ int seq_bad = 0;
19328+ int seq_own = 0;
19329+ int flow_bad = 0;
19330+ int flow_own = 0;
19331+ int none_bad = 0;
19332+ int none_own = 0;
19333+ int seq = doc_family_rows(s, "Mail-loading", CBM_SEM_DIAG_STRUCTURAL, &seq_bad, &seq_own);
19334+ int flow = doc_family_rows(s, "Mail-writing", CBM_SEM_DIAG_PROSE, &flow_bad, &flow_own);
19335+ int none = doc_family_rows(s, "Mail-parsing", CBM_SEM_DIAG_NONE, &none_bad, &none_own);
19336+ cbm_store_close(s);
19337+ th_rmtree(tmp);
19338+ cbm_pipeline_incremental_test_reset_faults();
19339+ ASSERT_STR_EQ(seq_kind, "sequence");
19340+ ASSERT_STR_EQ(flow_kind, "flowchart");
19341+ ASSERT_STR_EQ(none_kind, "");
19342+ ASSERT_EQ(cbm_sem_diag_family("mermaid", seq_kind), CBM_SEM_DIAG_STRUCTURAL);
19343+ ASSERT_EQ(cbm_sem_diag_family("mermaid", flow_kind), CBM_SEM_DIAG_PROSE);
19344+ ASSERT_GT(seq, 0);
19345+ ASSERT_EQ(seq_bad, 0);
19346+ ASSERT_GT(seq_own, 0);
19347+ ASSERT_GT(flow, 0);
19348+ ASSERT_EQ(flow_bad, 0);
19349+ ASSERT_GT(flow_own, 0);
19350+ ASSERT_GT(none, 0);
19351+ ASSERT_EQ(none_bad, 0);
19352+ ASSERT_EQ(none_own, 0);
19353+ PASS();
19354+ }
19355+
1922219356/* Lines of a CBM_SEM_DOC_SIGNALS dump whose section file, kind, position,
1922319357 * home and target file equal the given values (NULL: any). */
1922419358static int doc_signal_count(const char *dump, const char *sec_file, const char *kind,
@@ -20312,6 +20446,7 @@ SUITE(pipeline) {
2031220446 RUN_TEST(pipeline_doc_candidates_published_and_kept_by_delta);
2031320447 RUN_TEST(pipeline_doc_candidates_skip_exact_links_and_use_format_curves);
2031420448 RUN_TEST(pipeline_doc_candidates_home_position_and_kinds);
20449+ RUN_TEST(pipeline_doc_candidates_diagram_family_curves);
2031520450 RUN_TEST(pipeline_cpp_static_factory_pointer_receiver_issue1153);
2031620451 RUN_TEST(pipeline_cpp_static_factory_reference_receiver_issue1153);
2031720452 RUN_TEST(pipeline_cpp_static_factory_unique_ptr_receiver_issue1153);
0 commit comments