@@ -9396,14 +9396,17 @@ static int dm_exec(const char *db, const char *sql) {
93969396 return changed ;
93979397}
93989398
9399- /* A stored scope this code did not write -- a damaged row -- is not read
9400- * around: the file's declarations would silently be missing from every
9401- * lookup, and references to them would be reported `missing`. The layer
9402- * fails for that run, visibly, and the next index rebuilds from the files. */
9403- TEST (doc_mentions_cs_damaged_stored_scope ) {
9399+ /* One damaged stored scope (A's row, `find` replaced by `put`): 0 when the
9400+ * run that reads it fails visibly and the next one rebuilds; else the step
9401+ * that went wrong (1 setup, 2 the damaged run, 3 the rebuild), with the
9402+ * damaged run's error rows in *errors. */
9403+ static int dm_damaged_scope_run (const char * find , const char * put , int * errors ) {
9404+ * errors = -1 ;
94049405 char tmp [256 ];
94059406 snprintf (tmp , sizeof (tmp ), "/tmp/cbm_dm_dmg_XXXXXX" );
9406- ASSERT_NOT_NULL (cbm_mkdtemp (tmp ));
9407+ if (!cbm_mkdtemp (tmp )) {
9408+ return 1 ;
9409+ }
94079410 char repo [400 ];
94089411 snprintf (repo , sizeof (repo ), "%s/repo" , tmp );
94099412 th_write_file (TH_PATH (repo , "src/A.cs" ), "namespace N\n{\n public class Target { }\n}\n" );
@@ -9414,35 +9417,73 @@ TEST(doc_mentions_cs_damaged_stored_scope) {
94149417 "}\n" );
94159418 char db [512 ];
94169419 snprintf (db , sizeof (db ), "%s/dmg.db" , tmp );
9417- ASSERT_EQ (dm_index (repo , db , NULL ), 0 );
9420+ char sql [512 ];
9421+ snprintf (sql , sizeof (sql ),
9422+ "UPDATE lsp_surface SET defs_json = replace(defs_json, '%s', '%s') "
9423+ "WHERE rel_path = 'src/A.cs' AND instr(defs_json, '%s') > 0" ,
9424+ find , put , find );
94189425 char props [512 ];
94199426 int n = 0 ;
9420- dm_edge (db , "B.Uses" , "A.Target" , props , sizeof (props ), & n );
9421- ASSERT_EQ (n , 1 );
9422- /* one field too many in A's type record: no record this code writes */
9423- ASSERT_EQ (dm_exec (db , "UPDATE lsp_surface SET defs_json = "
9424- "replace(defs_json, '\\nT\\t', '\\nT\\tX\\t') "
9425- "WHERE rel_path = 'src/A.cs' AND instr(defs_json, '\\nT\\t') > 0" ),
9426- 1 );
9427- th_write_file (TH_PATH (repo , "src/B.cs" ),
9428- "namespace N\n"
9429- "{\n"
9430- " /// <summary>Again <see cref=\"Target\"/></summary>\n"
9431- " public class Uses { }\n"
9432- "}\n" );
9433- cbm_pipeline_incremental_test_reset_faults ();
9434- ASSERT_EQ (dm_index (repo , db , NULL ), 0 );
9435- ASSERT_EQ (dm_count (db , "SELECT COUNT(*) FROM doc_link_unresolved WHERE reason = 'error'" ), 1 );
9436- /* never the row an index without A's declarations would write */
9437- ASSERT_EQ (dm_count (db , "SELECT COUNT(*) FROM doc_link_unresolved WHERE raw = 'Target'" ), 0 );
9438- /* the next run rebuilds everything, and the edge is back */
9439- ASSERT_EQ (dm_index (repo , db , NULL ), 0 );
9440- ASSERT_EQ (cbm_pipeline_incremental_test_last_route (), CBM_INCREMENTAL_ROUTE_FORCED_FULL );
9441- ASSERT_EQ (dm_count (db , "SELECT COUNT(*) FROM doc_link_unresolved WHERE reason = 'error'" ), 0 );
9442- dm_edge (db , "B.Uses" , "A.Target" , props , sizeof (props ), & n );
9443- ASSERT_EQ (n , 1 );
9427+ int step = 1 ;
9428+ bool ok = dm_index (repo , db , NULL ) == 0 ;
9429+ if (ok ) {
9430+ dm_edge (db , "B.Uses" , "A.Target" , props , sizeof (props ), & n );
9431+ ok = n == 1 && dm_exec (db , sql ) == 1 ;
9432+ }
9433+ if (ok ) {
9434+ step = 2 ;
9435+ th_write_file (TH_PATH (repo , "src/B.cs" ),
9436+ "namespace N\n"
9437+ "{\n"
9438+ " /// <summary>Again <see cref=\"Target\"/></summary>\n"
9439+ " public class Uses { }\n"
9440+ "}\n" );
9441+ cbm_pipeline_incremental_test_reset_faults ();
9442+ ok = dm_index (repo , db , NULL ) == 0 ;
9443+ * errors = dm_count (db , "SELECT COUNT(*) FROM doc_link_unresolved WHERE reason = 'error'" );
9444+ /* never the row an index without A's declarations would write */
9445+ ok = ok && * errors == 1 &&
9446+ dm_count (db , "SELECT COUNT(*) FROM doc_link_unresolved WHERE raw = 'Target'" ) == 0 ;
9447+ }
9448+ if (ok ) {
9449+ /* the next run rebuilds everything, and the edge is back */
9450+ step = 3 ;
9451+ ok = dm_index (repo , db , NULL ) == 0 &&
9452+ cbm_pipeline_incremental_test_last_route () == CBM_INCREMENTAL_ROUTE_FORCED_FULL &&
9453+ dm_count (db , "SELECT COUNT(*) FROM doc_link_unresolved WHERE reason = 'error'" ) == 0 ;
9454+ if (ok ) {
9455+ dm_edge (db , "B.Uses" , "A.Target" , props , sizeof (props ), & n );
9456+ ok = n == 1 ;
9457+ }
9458+ }
94449459 dm_unlink_db (db );
94459460 th_rmtree (tmp );
9461+ return ok ? 0 : step ;
9462+ }
9463+
9464+ /* A stored scope this code did not write -- a damaged row -- is not read
9465+ * around: the file's declarations would silently be missing from every
9466+ * lookup, and references to them would be reported `missing`. The layer
9467+ * fails for that run, visibly, and the next index rebuilds from the files.
9468+ * R8: a region with an empty name is such a record (the scanner never writes
9469+ * one); read, it would nest a region without deepening the namespace. */
9470+ TEST (doc_mentions_cs_damaged_stored_scope ) {
9471+ static const struct {
9472+ const char * what , * find , * put ;
9473+ } damages [] = {
9474+ {"one field too many in A's type record" , "\\nT\\t" , "\\nT\\tX\\t" },
9475+ {"A's region without a name" , "\\nR\\t1\\t0\\t0\\t0\\tN\\n" , "\\nR\\t1\\t0\\t0\\t0\\t\\n" },
9476+ };
9477+ bool ok = true;
9478+ for (size_t i = 0 ; i < sizeof (damages ) / sizeof (damages [0 ]); i ++ ) {
9479+ int errors = -1 ;
9480+ int step = dm_damaged_scope_run (damages [i ].find , damages [i ].put , & errors );
9481+ if (step != 0 ) {
9482+ printf (" %s: step %d went wrong (%d error rows)\n" , damages [i ].what , step , errors );
9483+ ok = false;
9484+ }
9485+ }
9486+ ASSERT_TRUE (ok );
94469487 PASS ();
94479488}
94489489
0 commit comments