Skip to content

Commit 4f7fa84

Browse files
authored
Merge pull request DeusData#2359 from TheDarkniteFalls/codex/gh023-branch-head-regression
test(pipeline): cover changed-file and empty-commit Branch HEAD refresh
2 parents 11b662f + efb2312 commit 4f7fa84

1 file changed

Lines changed: 42 additions & 5 deletions

File tree

‎tests/test_pipeline.c‎

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8981,9 +8981,10 @@ static int branch_head_match_count(cbm_store_t *store, const char *project, cons
89818981
return matches;
89828982
}
89838983

8984-
/* Git context is graph input even when every repository file is unchanged.
8985-
* Construct the second pipeline before moving HEAD so the test also proves
8986-
* that run start refreshes the snapshot captured by cbm_pipeline_new(). */
8984+
/* Regression for #1213: index A, re-index B after a tracked source change,
8985+
* then re-index C after an empty commit. Each successful run publishes its
8986+
* run-start HEAD. Construct the final pipeline before moving HEAD to also
8987+
* cover refreshing the snapshot captured by cbm_pipeline_new(). */
89878988
TEST(pipeline_git_context_change_forces_full_and_refreshes_branch) {
89888989
if (!git_available()) {
89898990
FAIL("git unavailable");
@@ -9026,6 +9027,42 @@ TEST(pipeline_git_context_change_forces_full_and_refreshes_branch) {
90269027
snprintf(project, sizeof(project), "%s", cbm_pipeline_project_name(baseline));
90279028
cbm_pipeline_free(baseline);
90289029

9030+
cbm_store_t *initial_store = cbm_store_open_path(db_path);
9031+
ASSERT_NOT_NULL(initial_store);
9032+
int initial_matches = branch_head_match_count(initial_store, project, initial_head);
9033+
cbm_store_close(initial_store);
9034+
ASSERT_EQ(initial_matches, 1);
9035+
9036+
/* B: a committed source change must advance the existing project's HEAD. */
9037+
ASSERT_EQ(th_write_file(TH_PATH(repo, "stable.py"), "def StableGitContext():\n return 2\n"),
9038+
0);
9039+
snprintf(cmd, sizeof(cmd),
9040+
"git -C \"%s\" -c user.name=\"CBM Test\" "
9041+
"-c user.email=\"cbm@example.invalid\" commit -am \"source change\" >%s 2>&1",
9042+
repo, null_dev);
9043+
ASSERT_EQ(run_cmd(cmd), 0);
9044+
cbm_git_context_t source_ctx = {0};
9045+
ASSERT_EQ(cbm_git_context_resolve(repo, &source_ctx), 0);
9046+
ASSERT_NOT_NULL(source_ctx.head_sha);
9047+
char source_head[128];
9048+
snprintf(source_head, sizeof(source_head), "%s", source_ctx.head_sha);
9049+
cbm_git_context_free(&source_ctx);
9050+
ASSERT_TRUE(strcmp(initial_head, source_head) != 0);
9051+
9052+
cbm_pipeline_t *after_source_change = cbm_pipeline_new(repo, db_path, CBM_MODE_FAST);
9053+
ASSERT_NOT_NULL(after_source_change);
9054+
int source_rc = cbm_pipeline_run(after_source_change);
9055+
cbm_pipeline_free(after_source_change);
9056+
ASSERT_EQ(source_rc, 0);
9057+
cbm_store_t *source_store = cbm_store_open_path(db_path);
9058+
ASSERT_NOT_NULL(source_store);
9059+
int source_matches = branch_head_match_count(source_store, project, source_head);
9060+
int initial_stale_matches = branch_head_match_count(source_store, project, initial_head);
9061+
cbm_store_close(source_store);
9062+
ASSERT_EQ(source_matches, 1);
9063+
ASSERT_EQ(initial_stale_matches, 0);
9064+
9065+
/* C: no file hashes change, but the empty commit must still advance HEAD. */
90299066
cbm_pipeline_t *after_head_move = cbm_pipeline_new(repo, db_path, CBM_MODE_FAST);
90309067
ASSERT_NOT_NULL(after_head_move);
90319068
snprintf(cmd, sizeof(cmd),
@@ -9040,7 +9077,7 @@ TEST(pipeline_git_context_change_forces_full_and_refreshes_branch) {
90409077
char changed_head[128];
90419078
snprintf(changed_head, sizeof(changed_head), "%s", changed_ctx.head_sha);
90429079
cbm_git_context_free(&changed_ctx);
9043-
ASSERT_TRUE(strcmp(initial_head, changed_head) != 0);
9080+
ASSERT_TRUE(strcmp(source_head, changed_head) != 0);
90449081

90459082
cbm_pipeline_incremental_test_reset_faults();
90469083
int changed_rc = cbm_pipeline_run(after_head_move);
@@ -9049,7 +9086,7 @@ TEST(pipeline_git_context_change_forces_full_and_refreshes_branch) {
90499086

90509087
cbm_store_t *store = cbm_store_open_path(db_path);
90519088
int changed_branch_matches = store ? branch_head_match_count(store, project, changed_head) : -1;
9052-
int stale_branch_matches = store ? branch_head_match_count(store, project, initial_head) : -1;
9089+
int stale_branch_matches = store ? branch_head_match_count(store, project, source_head) : -1;
90539090
cbm_file_hash_t git_input = {0};
90549091
int git_input_rc =
90559092
store ? cbm_store_get_file_hash(

0 commit comments

Comments
 (0)