Packaged desktop showed no sessions in 1.12.4. Root cause: the sanitized session-list proxy path added in #1538 forwarded the renderer's "authorization" header (the OpenChamber UI client token) to the managed OpenCode upstream alongside the managed "Authorization" credential. OpenCode does not recognize UI client tokens, so every session-list request answered 401 — only in the packaged app, because only its renderer (openchamber-ui:// origin) attaches a bearer token; dev web and dev Electron run same-origin without one. The legacy http-proxy path overwrote the header correctly, which is why everything except session lists kept working. Proxy fix: - proxy-headers: filter the client "authorization" header out of forwarded request headers; the OpenCode upstream must only ever see its own managed credentials. Covered by tests. Desktop cwd: - electron: launch the managed OpenCode CLI from the user home instead of app userData, matching upstream desktop behavior. userData-as-cwd made OpenCode treat the app-data folder as a separate empty workspace. Home directory poisoning loop: - directoryPersistence: stop replaying localStorage homeDirectory through synchronizeHomeDirectory on boot/auth resync. The persisted value is only a boot-time cache; replaying it re-wrote stale values (e.g. a project path) into desktop settings on every start, overriding the authoritative /api/fs/home resolution. - persistence: never overwrite an injected window.__OPENCHAMBER_HOME__ with a persisted value. - useDirectoryStore: host switches happen in place (no reload), so re-resolve home from the new runtime's /api/fs/home on endpoint change instead of keeping the previous host's value. - opencode client: only short-circuit to the injected desktop home when the active runtime is local; remote runtimes ask /api/fs/home. Settings hygiene: - persistSettings: log field names only — change payloads can carry credentials (UI password, client tokens, tunnel tokens) that must not reach the log file; drop step-by-step log chatter. - validateProjectEntries: only stat project paths when the incoming update actually touches the projects list, not on every settings save. - remove the write-only approvedDirectories setting everywhere and add a migration that strips the stale key from persisted settings. Tests: - usePluginsStore.test: register an own runtime-fetch module mock so the suite is independent of process-global mock.module leakage from other files, and restore globalThis.fetch after the suite. - persistence.test: clean up the window global created for the suite.
24 lines
793 B
JavaScript
24 lines
793 B
JavaScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { resolveManagedOpenCodeCwd } from './opencode-cwd.mjs';
|
|
|
|
describe('resolveManagedOpenCodeCwd', () => {
|
|
it('defaults managed OpenCode cwd to the user home directory', () => {
|
|
expect(resolveManagedOpenCodeCwd({ env: {}, homedir: () => '/Users/example' })).toBe('/Users/example');
|
|
});
|
|
|
|
it('preserves an explicit cwd override', () => {
|
|
expect(resolveManagedOpenCodeCwd({
|
|
env: { OPENCHAMBER_OPENCODE_CWD: '/tmp/opencode-cwd' },
|
|
homedir: () => '/Users/example',
|
|
})).toBe('/tmp/opencode-cwd');
|
|
});
|
|
|
|
it('ignores a blank cwd override', () => {
|
|
expect(resolveManagedOpenCodeCwd({
|
|
env: { OPENCHAMBER_OPENCODE_CWD: ' ' },
|
|
homedir: () => '/Users/example',
|
|
})).toBe('/Users/example');
|
|
});
|
|
});
|