Skip to content

fix: resolve home directory via cross-platform helper (partial #68) - #87

Merged
igancev merged 1 commit into
igancev:mainfrom
mvanhorn:fix/68-windows-home-env-var
Jun 2, 2026
Merged

igancev merged 1 commit into
igancev:mainfrom
mvanhorn:fix/68-windows-home-env-var

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

InitCommand and YamlConfigProvider read getenv('HOME') directly to expand the leading ~ in the default config path. On Windows that env var is usually unset (the OS uses USERPROFILE, with HOMEDRIVE + HOMEPATH as a documented fallback for shells / containers that strip USERPROFILE), so ~/.config/work-reporter/... quietly resolved to /.config/work-reporter/... at the filesystem root and init + work:report silently misbehaved.

What changed

  • New Igancev\WorkReporter\Platform\HomeDirectory::resolve() helper that returns the canonical home directory per platform: HOME on POSIX, USERPROFILE on Windows with the documented HOMEDRIVE + HOMEPATH fallback. Returns an empty string when nothing is set so callers see the same shape as the prior (string)getenv(...) cast (no behavior change in error reporting paths).
  • src/Cli/InitCommand.php: swap the bare getenv('HOME') for HomeDirectory::resolve().
  • src/Config/YamlConfigProvider.php: same swap.
  • tests/Unit/Platform/HomeDirectoryTest.php: per-platform branches: POSIX returns HOME, Windows prefers USERPROFILE even when HOMEDRIVE+HOMEPATH are set, Windows falls back to HOMEDRIVE+HOMEPATH when USERPROFILE is empty, and all-unset returns "". Each test skips on the other OS family; cross-OS assertions exercise on a future Windows CI lane.

Scope

This is a partial fix for #68 — only the env-var handling item on the checklist. The remaining items (Windows binary build workflow, README install section, Windows binary smoke test) are intentionally left for follow-up PRs so each item stays atomic per CLAUDE.md / CONTRIBUTING.md guidance. Happy to take any of those in a follow-up if you want.

Verification

Local (macOS / PHP 8.5):

vendor/bin/phpunit tests/Unit/Platform/HomeDirectoryTest.php
# 4 tests, 2 assertions, 2 skipped (Windows-only branches)

vendor/bin/phpunit tests/Unit/InitCommandTest.php tests/Unit/Config/YamlConfigProviderTest.php
# 27 tests, 63 assertions, no regressions

make cs            # 72/72 files clean
make stat-analyze  # phpstan 0 errors

Closes part of #68 (env-var handling only).

…v#68)

InitCommand and YamlConfigProvider read \`getenv('HOME')\` directly to
expand the leading \`~\` in the default config path. On Windows that env
var is usually unset (the OS uses \`USERPROFILE\` plus optional
\`HOMEDRIVE\` / \`HOMEPATH\` as the fallback chain), so \`~/.config/...\`
quietly resolved to \`/.config/...\` at filesystem root and \`init\` /
\`work:report\` silently misbehaved.

Introduce \`Igancev\\WorkReporter\\Platform\\HomeDirectory::resolve()\`
that returns the canonical home path per platform: \`HOME\` on POSIX,
\`USERPROFILE\` on Windows with the documented \`HOMEDRIVE\` + \`HOMEPATH\`
fallback for containers/services that strip \`USERPROFILE\`. The helper
returns an empty string when nothing is set so callers see the same
shape as the prior \`(string)getenv(...)\` cast.

Scope: only the env-var leg of igancev#68's checklist. CI workflow for the
Windows binary, README install section, and end-to-end Windows binary
verification are intentionally left for follow-up PRs so each item
stays atomic per CLAUDE.md / CONTRIBUTING.md guidance.

Verification:

    vendor/bin/phpunit tests/Unit/Platform/HomeDirectoryTest.php
    vendor/bin/phpunit tests/Unit/InitCommandTest.php \
        tests/Unit/Config/YamlConfigProviderTest.php
    make cs
    make stat-analyze

all pass on macOS (POSIX path); the Windows-only assertions are
skipped on POSIX runners and exercised on a future Windows CI lane.
@igancev

igancev commented May 29, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR, @mvanhorn, and sorry for the delay — I've been a bit busy lately. I'll go through your proposal soon. Really appreciate your contribution!

@igancev
igancev merged commit 8f0aaca into igancev:main Jun 2, 2026
2 checks passed
@igancev

igancev commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Reviewed and merged - looks clean, nice refactoring. No critical issues found. Thanks for the contribution, @mvanhorn ! 👍

@mvanhorn

mvanhorn commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Appreciate the merge @igancev, the cross-platform home directory helper makes the reporter portable.

@mvanhorn

mvanhorn commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @igancev! The cross-platform home directory helper should hold up on Windows too.

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.

2 participants