Renaming a variable in a compose service's environment (and, with * `dockerfile`, in a Dockerfile's ENV) replaces its container-scoped EnvVar; * the unchanged compose file and Dockerfile keep theirs, once. `legacy`: * through the full-load route, else the closure-repair route (a renamed ENV * is a new Variable name, which the closure route leaves to a full * rebuild). Returns "old=N new=M kee
| 4034 | * is a new Variable name, which the closure route leaves to a full |
| 4035 | * rebuild). Returns "old=N new=M keep=K", or NULL. */ |
| 4036 | static char *incremental_env_edit(bool legacy, bool dockerfile, cbm_incremental_route_t *route) { |
| 4037 | char tmp[256]; |
| 4038 | snprintf(tmp, sizeof(tmp), "/tmp/cbm_envedit_XXXXXX"); |
| 4039 | if (!cbm_mkdtemp(tmp)) { |
| 4040 | return NULL; |
| 4041 | } |
| 4042 | write_temp_file(tmp, "Dockerfile", |
| 4043 | dockerfile ? "FROM alpine:3.20\nENV OLD_D=1\n" : "FROM alpine:3.20\nENV KEEP_D=1\n"); |
| 4044 | write_temp_file(tmp, "compose.yaml", |
| 4045 | "services:\n web:\n image: acme/web\n environment:\n OLD_C: x\n"); |
| 4046 | write_temp_file(tmp, "compose.other.yaml", |
| 4047 | "services:\n api:\n image: acme/api\n environment:\n - KEEP_C\n"); |
| 4048 | char db_path[512]; |
| 4049 | snprintf(db_path, sizeof(db_path), "%s/envedit.db", tmp); |
| 4050 | static const char old_q[] = |
| 4051 | "SELECT COUNT(*) FROM nodes WHERE label='EnvVar' AND name IN ('OLD_C','OLD_D')"; |
| 4052 | static const char new_q[] = |
| 4053 | "SELECT COUNT(*) FROM edges e JOIN nodes t ON t.id=e.target_id WHERE " |
| 4054 | "e.type='CONFIGURES' AND json_extract(e.properties,'$.strategy')='env_set' AND " |
| 4055 | "t.name IN ('NEW_C','NEW_D')"; |
| 4056 | static const char keep_q[] = |
| 4057 | "SELECT COUNT(*) FROM edges e JOIN nodes t ON t.id=e.target_id WHERE " |
| 4058 | "e.type='CONFIGURES' AND json_extract(e.properties,'$.strategy')='env_set' AND " |
| 4059 | "t.name IN ('KEEP_C','KEEP_D')"; |
| 4060 | if (k8s_inc_index(tmp, db_path) != 0 || k8s_inc_count(db_path, old_q) != (dockerfile ? 2 : 1) || |
| 4061 | k8s_inc_count(db_path, keep_q) != (dockerfile ? 1 : 2)) { |
| 4062 | th_rmtree(tmp); |
| 4063 | return NULL; |
| 4064 | } |
| 4065 | if (dockerfile) { |
| 4066 | write_temp_file(tmp, "Dockerfile", "FROM alpine:3.20\nENV NEW_D=1\n"); |
| 4067 | } |
| 4068 | write_temp_file(tmp, "compose.yaml", |
| 4069 | "services:\n web:\n image: acme/web\n environment:\n NEW_C: x\n"); |
| 4070 | #if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API |
| 4071 | if (legacy) { |
| 4072 | cbm_pipeline_incremental_test_force_legacy_partial_once(); |
| 4073 | } |
| 4074 | #else |
| 4075 | (void)legacy; |
| 4076 | #endif |
| 4077 | char *out = NULL; |
| 4078 | if (k8s_inc_index(tmp, db_path) == 0) { |
| 4079 | char buf[64]; |
| 4080 | snprintf(buf, sizeof(buf), "old=%d new=%d keep=%d", k8s_inc_count(db_path, old_q), |
| 4081 | k8s_inc_count(db_path, new_q), k8s_inc_count(db_path, keep_q)); |
| 4082 | out = strdup(buf); |
| 4083 | } |
| 4084 | *route = cbm_pipeline_incremental_test_last_route(); |
| 4085 | th_rmtree(tmp); |
| 4086 | return out; |
| 4087 | } |
| 4088 | |
| 4089 | TEST(incremental_env_edit_replaces_scoped_envvars) { |
| 4090 | cbm_incremental_route_t route = CBM_INCREMENTAL_ROUTE_NONE; |
no test coverage detected