fix(cli): register first-run projects on Windows#1775
Conversation
Use OS home resolution and Windows-aware registry path comparisons so first-run config creation registers projects globally across platforms.
Test Coverage Report
Per-file breakdown
Uncovered lines
|
Greptile SummaryThis PR fixes three Windows-specific regressions in the first-run flow:
Confidence Score: 5/5Safe to merge — all three Windows regressions are correctly addressed and the changes are well-contained. All three fixes (homedir(), global registration, case-insensitive registry comparisons) are correct and the new try/catch in autoCreateConfig ensures registration failures never break the first-run flow. Tests cover the happy path and collision path. The only gap is a missing POSIX counterpart to the new Windows test, which is a coverage nit with no functional impact. No files require special attention.
|
| Filename | Overview |
|---|---|
| packages/core/src/global-config.ts | Introduces registryPathCompareKey/registryPathsEqual helpers using realpathSync + Windows lowercasing; replaces three bare resolve(a) === b comparisons in registerProjectInGlobalConfig and updates isCanonicalGlobalConfigPath. |
| packages/cli/src/commands/start.ts | Adds registerProjectInGlobalConfig call in a try/catch after writing the first-run YAML, and switches tilde expansion in addProjectToConfig to homedir(). Registration failure is gracefully downgraded to a warning. |
| packages/cli/src/lib/path-equality.ts | Replaces process.env[HOME] with homedir() for tilde expansion — the correct cross-platform fix. |
| packages/cli/src/lib/resolve-project.ts | Single-line fix in fromPath: replaces process.env[HOME] |
| packages/core/src/tests/global-config.test.ts | Adds a Windows-only test for isCanonicalGlobalConfigPath case-insensitive comparison. The guide requires a paired POSIX test, which is absent. |
| packages/cli/tests/commands/start.test.ts | Two new tests cover global-registration on first run: one asserts successful registration, one asserts graceful downgrade on collision. |
| packages/cli/vitest.config.ts | Adds a path alias for @aoagents/ao-plugin-runtime-process so the new start.test.ts cases can resolve the runtime plugin. |
Sequence Diagram
sequenceDiagram
participant User as User (ao start)
participant AC as autoCreateConfig
participant FS as Filesystem
participant GC as registerProjectInGlobalConfig
participant Registry as Global Config
User->>AC: ao start (first run, no config)
AC->>FS: writeFileSync(agent-orchestrator.yaml)
FS-->>AC: OK
AC->>GC: registerProjectInGlobalConfig(projectId, name, path, localConfig)
GC->>GC: normalizeRegisteredProjectPath realpathSync + resolve
GC->>Registry: withFileLockSync loadGlobalConfig
Registry-->>GC: existing entries
GC->>GC: registryPathsEqual resolve + realpathSync + lowercase on Windows
alt No collision
GC->>Registry: saveGlobalConfig atomic write
GC-->>AC: effectiveProjectId
AC->>User: Registered in global config
else Path already registered
GC-->>AC: throws Error
AC->>User: Warning Could not register
end
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
packages/core/src/__tests__/global-config.test.ts:507-520
**Missing paired POSIX branch test for `registryPathCompareKey`**
`docs/CROSS_PLATFORM.md` requires that any new platform-branching code have both a Windows test and a POSIX test exercised on every CI host. The new Windows case (mocking `process.platform = "win32"`) is covered here, but there is no counterpart test that mocks `process.platform = "linux"` and asserts that `isCanonicalGlobalConfigPath` treats different-cased paths as distinct (POSIX is case-sensitive). Without it, a future change that accidentally lowercases on all platforms would pass CI silently.
Reviews (2): Last reviewed commit: "fix(cli): handle first-run registration ..." | Re-trigger Greptile
Warn when global registration collides after local config creation and canonicalize registry path comparisons through realpath when possible.
Summary
~expansion instead of relying onHOME.Fixes #1561.
Test plan
pnpm --filter @aoagents/ao-core test -- src/__tests__/global-config.test.tspnpm --filter @aoagents/ao-cli test -- __tests__/lib/path-equality.test.ts __tests__/commands/start.test.tspnpm --filter @aoagents/ao-core typecheck && pnpm --filter @aoagents/ao-core build && pnpm --filter @aoagents/ao-cli typecheck && pnpm --filter @aoagents/ao-cli build