@@ -637,6 +637,71 @@ TEST(pipeline_structure_nodes) {
637637 * ADR before the delete and restores it after the rebuild. Reproduce-first:
638638 * index, store an ADR, force a full re-index by adding files, assert the ADR
639639 * is still present and unchanged. */
640+ /* #1665: a persistence artifact export failure must not be reported as a
641+ * repo_path problem. Create the artifact directory as a regular FILE so
642+ * cbm_mkdir_p(.codebase-memory) fails deterministically (works as root too),
643+ * run with persistence enabled, and assert: the run fails, the DB was
644+ * published (publish happens before export), the pipeline snapshots the export
645+ * error, and a clean re-run leaves the snapshot empty. */
646+ TEST(pipeline_export_error_snapshot_on_artifact_failure) {
647+ char tmp[256];
648+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_export1665_XXXXXX");
649+ if (!cbm_mkdtemp(tmp)) {
650+ FAIL("failed to create temp dir");
651+ }
652+
653+ char path[512];
654+ snprintf(path, sizeof(path), "%s/main.py", tmp);
655+ FILE *f = fopen(path, "w");
656+ ASSERT_NOT_NULL(f);
657+ fprintf(f, "def foo():\n pass\n");
658+ fclose(f);
659+
660+ char db_path[512];
661+ snprintf(db_path, sizeof(db_path), "%s/test.db", tmp);
662+
663+ /* Block the artifact directory: a FILE at .codebase-memory makes the
664+ * export's mkdir_p fail with a deterministic error on every platform. */
665+ char art_block[512];
666+ snprintf(art_block, sizeof(art_block), "%s/.codebase-memory", tmp);
667+ f = fopen(art_block, "w");
668+ ASSERT_NOT_NULL(f);
669+ fprintf(f, "block\n");
670+ fclose(f);
671+
672+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
673+ ASSERT_NOT_NULL(p);
674+ cbm_pipeline_set_persistence(p, true);
675+
676+ int rc = cbm_pipeline_run(p);
677+ ASSERT_NEQ(rc, 0);
678+
679+ /* The export runs after publish, so the DB must exist despite the failure. */
680+ struct stat db_st;
681+ ASSERT_EQ(stat(db_path, &db_st), 0);
682+
683+ const char *export_error = cbm_pipeline_export_error(p);
684+ ASSERT_NOT_NULL(export_error);
685+ ASSERT_TRUE(export_error[0] != '\0');
686+ ASSERT_NOT_NULL(strstr(export_error, "prepare_artifact_dir"));
687+ cbm_pipeline_free(p);
688+
689+ /* Control: remove the blocker; a fresh run succeeds and leaves no snapshot. */
690+ (void)cbm_unlink(art_block);
691+ cbm_pipeline_t *p2 = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
692+ ASSERT_NOT_NULL(p2);
693+ cbm_pipeline_set_persistence(p2, true);
694+ rc = cbm_pipeline_run(p2);
695+ ASSERT_EQ(rc, 0);
696+ const char *export_error2 = cbm_pipeline_export_error(p2);
697+ ASSERT_NOT_NULL(export_error2);
698+ ASSERT_TRUE(export_error2[0] == '\0');
699+ cbm_pipeline_free(p2);
700+
701+ rm_rf(tmp);
702+ PASS();
703+ }
704+
640705TEST(pipeline_adr_survives_full_reindex) {
641706 char tmp[256];
642707 snprintf(tmp, sizeof(tmp), "/tmp/cbm_adr_XXXXXX");
@@ -15780,6 +15845,7 @@ SUITE(pipeline) {
1578015845 RUN_TEST(pipeline_structure_nodes);
1578115846 RUN_TEST(pipeline_committed_counts_match_persisted);
1578215847 RUN_TEST(pipeline_adr_survives_full_reindex);
15848+ RUN_TEST(pipeline_export_error_snapshot_on_artifact_failure);
1578315849 RUN_TEST(pipeline_structure_edges);
1578415850 RUN_TEST(pipeline_branch_root_structure);
1578515851 RUN_TEST(pipeline_project_name_derived);
0 commit comments