huskies: merge 1009

This commit is contained in:
dave
2026-05-13 22:50:13 +00:00
parent a5cd3a2152
commit 4e007bb770
56 changed files with 453 additions and 384 deletions
+60 -8
View File
@@ -276,6 +276,57 @@ pub fn migrate_legacy_stage_strings() {
);
}
/// Clear legacy node-hex claims from `claim_agent` and `claim_ts` registers.
///
/// Pre-1009 nodes wrote the Ed25519 hex pubkey as `claimed_by`. That value
/// cannot be converted to an `AgentName`, so the safe migration is to wipe
/// any existing claim rather than carry over a semantically invalid string.
///
/// Only clears entries where `claim_agent` looks like a legacy node hex value
/// (64 hex chars). Entries that are already empty or contain an agent-name
/// string (shorter, mixed case) are left untouched.
pub fn migrate_node_claims_to_agent_claims() {
let Some(state_mutex) = get_crdt() else {
return;
};
let stale_indices: Vec<usize> = {
let Ok(state) = state_mutex.lock() else {
return;
};
state
.index
.values()
.copied()
.filter(|&idx| {
let item = &state.crdt.doc.items[idx];
match item.claim_agent.view() {
JsonValue::String(s) => {
s.len() == 64 && s.chars().all(|c| c.is_ascii_hexdigit())
}
_ => false,
}
})
.collect()
};
if stale_indices.is_empty() {
return;
}
let Ok(mut state) = state_mutex.lock() else {
return;
};
let count = stale_indices.len();
for idx in stale_indices {
apply_and_persist(&mut state, |s| {
s.crdt.doc.items[idx].claim_agent.set(String::new())
});
apply_and_persist(&mut state, |s| s.crdt.doc.items[idx].claim_ts.set(0.0));
}
slog!("[crdt] Cleared {count} legacy node-hex claim(s) from claim_agent/claim_ts");
}
#[cfg(test)]
mod stage_migration_tests {
use super::super::super::state::init_for_test;
@@ -299,8 +350,6 @@ mod stage_migration_tests {
None,
None,
None,
None,
None,
);
// Then overwrite the stage register with the raw legacy string,
// bypassing `db::normalise_stage_str` / `write_item_str`'s mapping.
@@ -318,7 +367,11 @@ mod stage_migration_tests {
let cases: &[(&str, &str, Stage)] = &[
("9501_legacy_upcoming", "0_upcoming", Stage::Upcoming),
("9502_legacy_backlog", "1_backlog", Stage::Backlog),
("9503_legacy_coding", "2_current", Stage::Coding),
(
"9503_legacy_coding",
"2_current",
Stage::Coding { claim: None },
),
(
"9504_legacy_blocked",
"2_blocked",
@@ -333,6 +386,7 @@ mod stage_migration_tests {
Stage::Merge {
feature_branch: BranchName(String::new()),
commits_ahead: NonZeroU32::new(1).unwrap(),
claim: None,
},
),
(
@@ -398,14 +452,12 @@ mod stage_migration_tests {
// Seed two items: one already in clean form, one in legacy form.
write_item(
"9520_already_clean",
&Stage::Coding,
&Stage::Coding { claim: None },
Some("Already Clean"),
None,
None,
None,
None,
None,
None,
);
seed_with_raw_stage("9521_needs_migration", "2_current");
@@ -416,11 +468,11 @@ mod stage_migration_tests {
let migrated = read_item("9521_needs_migration").unwrap();
assert!(matches!(
clean.stage(),
crate::pipeline_state::Stage::Coding
crate::pipeline_state::Stage::Coding { .. }
));
assert!(matches!(
migrated.stage(),
crate::pipeline_state::Stage::Coding
crate::pipeline_state::Stage::Coding { .. }
));
}