fix(cli): establish the state root privately before connect locks

Merged
TH
3d ago
+103-5

Summary

Fixes #5137. The base is 0.22, so the issue needs manual closing after merge.

Under umask 002, the connection lock created a missing state root at 0775, and cloud admission refused it. connect and disconnect now establish the root through admitDaemonStateRoot during connection resolution, before the lock and the update notifier. disconnect also establishes a missing root named by the saved profile, which appears only after claimed defaults merge.

Existing roots are treated as before: an owned discovery root open to group or others is tightened to 0700. Missing parent directories of a new root are also created at 0700.

Supersedes #5148 with the smaller route suggested in its review.

Before / after

Missing state directory, umask 002:

Call0.22This change
connect cloud --platform ioscloud_credential_store_unsafesucceeds, root 0700
disconnectcloud_credential_store_unsafesucceeds, root 0700
disconnect, saved profile names another rootcloud_credential_store_unsafesucceeds, root and parent 0700

Validation

Tested at f9b4e7fa73f86b3c16eda8827e0f8066f112e70b on macOS.

  • vitest run --project unit-core src/__tests__/cli-state-root-admission.test.ts: 7 passed.
  • Failing first: the two fresh-root cases without any production change, and the saved-profile case at 23537c9.
  • oxfmt --check and oxlint --deny-warnings on changed files: passed.

Other tests and gates are left to CI.

Unchanged: on the saved-profile route, the record under the discovery root remains after disconnect, also observed on 0.22 under umask 022.

šŸ¤– Generated with Claude Code