fix(app): honor DEEPCHAT_E2E_USER_DATA_DIR before startup#1995
Conversation
📝 WalkthroughWalkthroughThe change documents profile-scoped Electron user-data behavior and applies the trimmed ChangesProfile-scoped user data
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/main/provider/providerDbLoader.test.ts (1)
109-123: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winEnsure environment variables are restored if assertions fail.
If an
expectassertion fails, the test will throw an error and the cleanup code (lines 117-121) will not execute, potentially polluting the environment for subsequent tests in this file.Since you are using Vitest, consider using
vi.stubEnvwhich safely handles environment variable mocking and can be easily cleaned up, or wrap the assertions in atry...finallyblock.♻️ Proposed refactor using `vi.stubEnv`
- it('resolves DEEPCHAT_E2E_USER_DATA_DIR as provider-db base directory', async () => { - const oldDir = process.env.DEEPCHAT_E2E_USER_DATA_DIR + it('resolves DEEPCHAT_E2E_USER_DATA_DIR as provider-db base directory', async () => { const e2eUserDataRoot = path.join(tempRoot, 'e2e-user-data') - process.env.DEEPCHAT_E2E_USER_DATA_DIR = e2eUserDataRoot + vi.stubEnv('DEEPCHAT_E2E_USER_DATA_DIR', e2eUserDataRoot) const ProviderDbLoader = await importLoader() new ProviderDbLoader() expect(fs.existsSync(path.join(e2eUserDataRoot, 'provider-db'))).toBe(true) expect(fs.existsSync(getCacheDir())).toBe(false) - if (oldDir === undefined) { - delete process.env.DEEPCHAT_E2E_USER_DATA_DIR - } else { - process.env.DEEPCHAT_E2E_USER_DATA_DIR = oldDir - } + vi.unstubAllEnvs() })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@test/main/provider/providerDbLoader.test.ts` around lines 109 - 123, Update the test “resolves DEEPCHAT_E2E_USER_DATA_DIR as provider-db base directory” to guarantee environment cleanup when assertions fail. Use Vitest’s vi.stubEnv with the appropriate restoration mechanism, or move the existing environment restoration into a finally block surrounding the setup and assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@test/main/provider/providerDbLoader.test.ts`:
- Around line 109-123: Update the test “resolves DEEPCHAT_E2E_USER_DATA_DIR as
provider-db base directory” to guarantee environment cleanup when assertions
fail. Use Vitest’s vi.stubEnv with the appropriate restoration mechanism, or
move the existing environment restoration into a finally block surrounding the
setup and assertions.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ff86753d-9575-4337-b7cd-b8170d8f225d
📒 Files selected for processing (5)
docs/architecture/user-data-profile-path/spec.mdsrc/main/provider/providerDbLoader.tssrc/shared/logger.tstest/e2e/fixtures/electronApp.tstest/main/provider/providerDbLoader.test.ts
Description
I want to launch Deepchat with a dedicated user profile in Agent sandbox, but fail. I use
DEEPCHAT_E2E_USER_DATA_DIRto isolate development profile from the installed application. However, two early calls toapp.getPath('userData'), before the app starts, resolve to the installed profile path.logs/main.logfromsrc/shared/logger.tsprovider-db/meta.jsonfromsrc/main/provider/providerDbLoader.tsRisks
ElectronStore<ToolPolicySettings>insrc/main/plugin/toolPolicyStore.tsis also a suspicious early path resolver. (But DeepChat can run in Agent sandbox after those two fixes, so I don't fix this one.)Summary by CodeRabbit
Documentation
Bug Fixes
Tests