Skip to content

Fix GitHub import subdirectory handling#443

Draft
cursor[bot] wants to merge 2 commits into
developfrom
cm/critical-bug-investigation-6c44
Draft

Fix GitHub import subdirectory handling#443
cursor[bot] wants to merge 2 commits into
developfrom
cm/critical-bug-investigation-6c44

Conversation

@cursor

@cursor cursor Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fixes a critical onboarding/import regression where GitHub repo refs like owner/repo?dir=hosts/work parsed dir but still finalized the active config directory to the repository root.
  • Impact: monorepo imports could silently select the wrong flake root, fail host discovery/rebuild, or apply a root-level flake different from the user-requested subdir.
  • Root cause: RepoRef.subdir was populated by parse_repo_ref, but config_import_github moved the spec into the clone task and always called finalize_imported_dir(&target) afterward.
  • Fix: keep the parsed spec after clone, resolve the imported root through the requested subdir, require flake.nix in that subdir, and finalize app state to that resolved path.
  • Also fixes a nearby crash regression where detect_username() unwrapped whoami::username() before falling back to USER/unknown.
  • Adds a tiny Linux-only test-build fix for a stale macOS-only test import so the Rust suite can run locally under unused = deny.

Test Plan

  • cargo +stable test --manifest-path "apps/native/src-tauri/Cargo.toml" bootstrap::import::tests
  • cargo +stable test --manifest-path "apps/native/src-tauri/Cargo.toml" commands::config::tests
  • cargo +stable test --manifest-path "apps/native/src-tauri/Cargo.toml" bootstrap::default_config::tests
  • cargo +stable test --manifest-path "apps/native/src-tauri/Cargo.toml" (501 passed; 2 ignored)

Docs

  • No docs update needed
Open in Web View Automation 

Co-authored-by: cooper <czxtm@users.noreply.github.com>
Co-authored-by: cooper <czxtm@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor
Warnings
⚠️ PR is marked WIP / draft — do not merge until ready for review.

📋 PR Overview

Lines changed 120 (+107 / -13)
Files 0 added, 3 modified, 0 deleted
Draft / WIP yes
Has Test Plan yes
No Test Plan Needed no
New UI components no
New Storybook stories no
New Rust modules no
New TS source files no
New tests no
package.json touched no
Cargo.toml touched no
Infra / CI touched no

🔬 Coverage

Report Lines Statements Functions Branches
apps/native/coverage/coverage-summary.json 28.7% 28.9% 27.3% 21.9%

Generated by 🚫 dangerJS against 77c515a

@darkmatter

darkmatter Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

🎨 Storybook preview

Open Storybook preview

Updated for 77c515a


❌ Failed snapshots (1)

These stories' HTML snapshots changed. Update snapshots ↗ to regenerate baselines and open a PR:

Widget/DarwinWidget › Onboarding With Directory

Widget/DarwinWidget › Onboarding With Directory


Accept changes

  • Click here to accept these changes
What does this do?

The screenshots above show UI changes detected by the Storybook
snapshot tests run on this PR. Each image is the rendered output of
a Storybook story from the code in this PR branch; the snapshot
test compared it against the committed baseline in
__snapshots__/ and flagged the difference.

Checking the box tells the darkmatter[bot] to regenerate the
baselines from this PR's current code and commit them directly to
this branch. The new baselines become the source of truth for
future runs — only accept after confirming the visual changes are
intentional.

Comparison baseline: the committed __snapshots__/ files on this
PR branch (carried forward from develop). Accept updates them in
place on this branch.

@czxtm

Copy link
Copy Markdown
Member

/bot review this code

@czxtm

Copy link
Copy Markdown
Member

/oc review this code

1 similar comment
@czxtm

Copy link
Copy Markdown
Member

/oc review this code

@czxtm

Copy link
Copy Markdown
Member

/bot review code

@czxtm

Copy link
Copy Markdown
Member

/dm review code

@czxtm

Copy link
Copy Markdown
Member

/oc review code

@czxtm

Copy link
Copy Markdown
Member

/dm review this PR

@darkmatter

darkmatter Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Code review — PR #443

Reviewing cm/critical-bug-investigation-6c44develop (19 files, +755/−1033).


🔴 Must fix before merge

1. apps/native/src/components/widget/controls/repo-import.tsx — personal repo in example text

The placeholder example was changed from the project repo to a personal one:

- A public GitHub repo, e.g. <span className="font-mono">github.com/darkmatter/nixmac</span>.
+ A public GitHub repo, e.g. <span className="font-mono">czxtm/darwin</span>.

czxtm/darwin is a contributor's personal repo — this is a debug artifact. Revert to github.com/darkmatter/nixmac or a similarly illustrative public repo.

2. repo-import.tsx — help text reverts to #branch syntax

The PR adds ?ref=/?dir= query-parameter support, but the hint text was reverted to the old #branch style:

- Add <span>?ref= and/or ?dir=</span> to clone a specific branch or use a subdirectory.
+ Add <span>#branch</span> to clone a specific branch.

This contradicts the feature being shipped. The develop branch already has the correct ?ref=/?dir= text; this should be retained.

3. repo-import.tsx — removed keyboard-behaviour attributes

autoCapitalize="none", autoCorrect="off", and spellCheck={false} were silently dropped from the <Input>. These prevent autocorrect mangling of owner/repo strings on macOS and iOS. Their removal is a UX regression.


🟡 Worth addressing

4. escape_nix_string moved without porting its tests

The function was moved from evolve/nix_file_editor.rs (which had a direct test covering backslash, ${ interpolation, quotes, etc.) to system/scanner.rs (private, no dedicated test). It is only exercised indirectly through to_nix_value. The ${ anti-interpolation path is the subtle case; add a targeted test in scanner.rs.

5. git/query.rs — PR branch does not include ddb4f87

The fix "Fix git status diff dropping +/-/space line origin markers" (#439) landed in develop after this branch was cut. The code and its test (test_status_diff_preserves_line_origin_markers) are absent from this branch. GitHub's auto-merge ref (refs/pull/443/merge) exists so the merge itself should re-apply the fix from develop's side, but please confirm the merged result compiles cleanly and the test survives — the diff presented here shows the fix as "removed" which is alarming without that confirmation.

6. main.rsregister_managed_state inlined, tests deleted

The helper function and its tests were removed; managed-state setup is now duplicated between CLI and GUI paths without test coverage. The duplication itself is low risk (8 lines each), but the lack of tests means future unintentional divergence won't be caught. Consider at minimum a comment noting they must stay in sync.


✅ What's good

  • resolve_imported_repo_root (commands/config.rs) — clean separation from clone_repo; validates subdir existence and flake.nix presence; validate_subdir blocks path traversal before it reaches target.join(subdir). The two new tests cover both the happy path and the missing-flake.nix case.

  • generate_system_defaults_nix (system/scanner.rs) — much simpler than the prior nix-AST editing path; removes the nix eval dependency on system.primaryUser in favour of detect_username(). New test suite covers bool/int/float/string/map coercion to Nix values.

  • scan_system_defaults early return when system-defaults.nix already exists is reasonable UX (hides the CTA after first apply). Worth a one-line doc comment explaining the intent.

  • flags.ts simplification removes the dead bitmask filesystem-section code. The simpler boolean flag is all that was actually needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants