fix(cli): establish the state root privately before connect locks
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:
| Call | 0.22 | This change |
|---|---|---|
connect cloud --platform ios | cloud_credential_store_unsafe | succeeds, root 0700 |
disconnect | cloud_credential_store_unsafe | succeeds, root 0700 |
disconnect, saved profile names another root | cloud_credential_store_unsafe | succeeds, 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 --checkandoxlint --deny-warningson 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