Skip to content

fix(desktop): honor XDG_CONFIG_HOME in locale-ipc and preferences-ipc#71

Merged
hqhq1025 merged 2 commits intomainfrom
wt/loop-fix-xdg-config-paths
Apr 19, 2026
Merged

fix(desktop): honor XDG_CONFIG_HOME in locale-ipc and preferences-ipc#71
hqhq1025 merged 2 commits intomainfrom
wt/loop-fix-xdg-config-paths

Conversation

@hqhq1025
Copy link
Copy Markdown
Collaborator

Bug

apps/desktop/src/main/config.ts honors XDG_CONFIG_HOME via configDir(), but locale-ipc.ts and preferences-ipc.ts hardcoded join(homedir(), '.config', 'open-codesign'). With XDG_CONFIG_HOME=/custom/path, config.toml lands under /custom/path/open-codesign/ while locale.json and preferences.json stay under ~/.config/open-codesign/ — split state. Violates CLAUDE.md hard constraint: "respect XDG base dirs / Electron app.getPath()".

Fix

Both modules now call configDir() lazily inside the read/write functions (env var read at call time, matching config.ts). Dropped the no-longer-needed homedir import and the CONFIG_DIR wrapper constants.

Tests

  • preferences-ipc.test.ts: added a case asserting XDG_CONFIG_HOME redirects the readFile path.
  • locale-ipc.test.ts (new): single test asserting writeFile uses the XDG path when locale:set runs.
  • All 214 desktop tests pass; typecheck and lint green.

PRINCIPLES §5b

  • Compatibility ✅ — default behavior unchanged when XDG_CONFIG_HOME is unset; existing ~/.config/open-codesign/ files keep working.
  • Upgradeability ✅ — schemaVersion fields preserved; no on-disk format changes.
  • No bloat ✅ — net-negative on imports; no new dependencies.
  • Elegance ✅ — single source of truth (configDir()) for all on-disk config paths.

locale-ipc and preferences-ipc previously hardcoded
join(homedir(), '.config', 'open-codesign') for their persisted JSON files,
while config.ts honored XDG_CONFIG_HOME. Setting XDG_CONFIG_HOME=/custom
caused config.toml to land under the custom path while locale.json /
preferences.json stayed under ~/.config/open-codesign — split state.

Switch both modules to call configDir() lazily inside read/write fns so the
env var is read at call time, matching config.ts. Adds a test in each module
asserting that XDG_CONFIG_HOME redirects the persisted file path.
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings

  • [Minor] Test cleanup leaks XDG_CONFIG_HOME as literal string — assigning process.env['XDG_CONFIG_HOME'] = undefined does not unset env vars in Node; it leaves the string "undefined", which can contaminate later tests and hide path-resolution regressions, evidence apps/desktop/src/main/locale-ipc.test.ts:42, apps/desktop/src/main/preferences-ipc.test.ts:57.
    Suggested fix:
    if (prev === undefined) delete process.env['XDG_CONFIG_HOME'];
    else process.env['XDG_CONFIG_HOME'] = prev;

Summary

  • Review mode: initial
  • 1 issue found in added test cleanup logic.
  • Required context docs docs/VISION.md and docs/PRINCIPLES.md: Not found in repo/docs.

Testing

  • Not run (automation)

open-codesign Bot

const firstCall = writeFileMock.mock.calls[0];
expect(firstCall?.[0]).toBe('/tmp/xdg-locale-test/open-codesign/locale.json');
} finally {
if (prev === undefined) process.env['XDG_CONFIG_HOME'] = undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.env['XDG_CONFIG_HOME'] = undefined does not unset the variable; Node stores the literal string "undefined". This can leak into following tests.

Suggested fix:

if (prev === undefined) delete process.env['XDG_CONFIG_HOME'];
else process.env['XDG_CONFIG_HOME'] = prev;

'utf8',
);
} finally {
if (prev === undefined) process.env['XDG_CONFIG_HOME'] = undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same cleanup issue here: assigning undefined leaves a string value in process.env. Use deletion when the previous value was absent.

Suggested fix:

if (prev === undefined) delete process.env['XDG_CONFIG_HOME'];
else process.env['XDG_CONFIG_HOME'] = prev;

@hqhq1025 hqhq1025 merged commit 4487c1d into main Apr 19, 2026
5 of 6 checks passed
@hqhq1025 hqhq1025 deleted the wt/loop-fix-xdg-config-paths branch April 19, 2026 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant