@@ -44,7 +44,7 @@ const SHARED_AGENT_DIRS: &[&str] = &["agents/teams"];
4444/// `xyz.block.buzz.app.developer`. This is the authoritative dev/prod
4545/// discriminator shared by `run_boot_migrations`, `sync_shared_agent_data`,
4646/// and `reconcile_target_dir`.
47- fn is_dev_data_dir_name ( name : & str ) -> bool {
47+ pub ( crate ) fn is_dev_data_dir_name ( name : & str ) -> bool {
4848 name == CANONICAL_DEV_IDENTIFIER
4949 || name
5050 . strip_prefix ( CANONICAL_DEV_IDENTIFIER )
@@ -55,7 +55,7 @@ fn canonical_dev_data_dir(current: &Path) -> Option<PathBuf> {
5555 current. parent ( ) . map ( |p| p. join ( CANONICAL_DEV_IDENTIFIER ) )
5656}
5757
58- fn legacy_app_data_dir ( current : & Path ) -> Option < PathBuf > {
58+ pub ( crate ) fn legacy_app_data_dir ( current : & Path ) -> Option < PathBuf > {
5959 let name = current. file_name ( ) ?. to_str ( ) ?;
6060 let legacy_name = if name. starts_with ( CANONICAL_DEV_IDENTIFIER ) {
6161 name. replacen ( CANONICAL_DEV_IDENTIFIER , LEGACY_CANONICAL_DEV_IDENTIFIER , 1 )
@@ -119,6 +119,15 @@ fn copy_dir_all(src: &Path, dst: &Path) -> std::io::Result<()> {
119119/// readers — reader-first loses a launch (stale harness/`mcp_command` until
120120/// the next boot).
121121pub fn run_boot_migrations ( app : & tauri:: AppHandle ) {
122+ run_boot_migrations_inner ( app, false ) ;
123+ }
124+
125+ /// Entry point when a completed reset must suppress dev-nest re-import.
126+ pub fn run_boot_migrations_after_reset ( app : & tauri:: AppHandle ) {
127+ run_boot_migrations_inner ( app, true ) ;
128+ }
129+
130+ fn run_boot_migrations_inner ( app : & tauri:: AppHandle , reset_completed : bool ) {
122131 // Initialize the process-lifetime nest directory before any filesystem
123132 // operation that calls nest_dir(). The discriminator matches the existing
124133 // pattern used by reconcile_target_dir: dev instances have an app-data-dir
@@ -139,8 +148,10 @@ pub fn run_boot_migrations(app: &tauri::AppHandle) {
139148 // ensures the dev nest boots with the correct workspace on its first launch,
140149 // matching what the prod nest had configured. Skip-if-dest-exists so it is
141150 // idempotent and never clobbers a value the dev nest already set explicitly.
142- if is_dev {
143- migrate_dev_repos_dir ( ) ;
151+ // Uses the composed helper so the gate + migration run through the same
152+ // code path that the behavioral test exercises.
153+ if let ( Some ( home) , Some ( dev_nest) ) = ( dirs:: home_dir ( ) , crate :: managed_agents:: nest_dir ( ) ) {
154+ maybe_migrate_dev_repos_dir ( is_dev, reset_completed, & home, & dev_nest) ;
144155 }
145156
146157 migrate_legacy_app_data_dir ( app) ;
@@ -318,31 +329,29 @@ fn migrate_legacy_nest_at(legacy: &Path, current: &Path) -> bool {
318329/// also copies into `~/.buzz-dev` and could otherwise set the sentinel early.
319330const DEV_NEST_MIGRATED_SENTINEL : & str = ".dev-nest-migrated" ;
320331
321- /// Copy the `.repos-dir` dotfile from `~/.buzz` → `~/.buzz-dev`, non-destructively.
322- ///
323- /// Must be called on dev builds BEFORE `resolve_repos_at_boot()` reads the
324- /// dotfile, so the dev nest boots with the correct workspace configuration on
325- /// its first launch. Skip-if-dest-exists so it is idempotent and never
326- /// overwrites a value set directly by the dev nest.
327- fn migrate_dev_repos_dir ( ) {
328- let Some ( home) = dirs:: home_dir ( ) else {
329- return ;
330- } ;
332+ /// Returns true when `migrate_dev_repos_dir` should run: dev build AND no
333+ /// completed reset this boot (a completed reset means the dev nest was just
334+ /// wiped — re-importing from prod would undo the sign-out).
335+ pub ( crate ) fn should_migrate_dev_repos_dir ( is_dev : bool , reset_completed : bool ) -> bool {
336+ is_dev && !reset_completed
337+ }
338+
339+ /// Injectable core: copy `.repos-dir` from `<home>/.buzz/` into `dev_nest`,
340+ /// non-destructively. Extracted so tests can inject temp paths without
341+ /// touching `dirs::home_dir()` or the global `nest_dir()` OnceLock.
342+ pub ( crate ) fn migrate_dev_repos_dir_at ( home : & Path , dev_nest : & Path ) {
331343 let src = home. join ( ".buzz" ) . join ( ".repos-dir" ) ;
332344 if !src. exists ( ) {
333345 return ;
334346 }
335- let Some ( dev_nest) = crate :: managed_agents:: nest_dir ( ) else {
336- return ;
337- } ;
338347 let dst = dev_nest. join ( ".repos-dir" ) ;
339348 // Skip if the dev nest already has its own .repos-dir.
340349 if dst. exists ( ) {
341350 return ;
342351 }
343352 // Ensure the dev nest directory itself exists — this migration runs before
344353 // ensure_nest() in the boot sequence, so the directory may not yet exist.
345- if let Err ( e) = std:: fs:: create_dir_all ( & dev_nest) {
354+ if let Err ( e) = std:: fs:: create_dir_all ( dev_nest) {
346355 eprintln ! (
347356 "buzz-desktop: dev-nest-migration: failed to create dev nest {}: {e}" ,
348357 dev_nest. display( )
@@ -358,6 +367,21 @@ fn migrate_dev_repos_dir() {
358367 }
359368}
360369
370+ /// Composed gate + migration: applies `should_migrate_dev_repos_dir` and, if
371+ /// the gate passes, runs the injectable migration core. This is the seam that
372+ /// `run_boot_migrations_inner` calls with real paths — a future mis-wired flag
373+ /// or inverted gate breaks tests at this level, not just the predicate.
374+ pub ( crate ) fn maybe_migrate_dev_repos_dir (
375+ is_dev : bool ,
376+ reset_completed : bool ,
377+ home : & Path ,
378+ dev_nest : & Path ,
379+ ) {
380+ if should_migrate_dev_repos_dir ( is_dev, reset_completed) {
381+ migrate_dev_repos_dir_at ( home, dev_nest) ;
382+ }
383+ }
384+
361385/// One-time migration of dev-build nest contents from `~/.buzz` → `~/.buzz-dev`.
362386///
363387/// When a dev build first boots after this change ships, it switches from the
0 commit comments