Skip to content

test: isolate HOME per package so tests cannot write real user settings - #20

Merged
philband merged 1 commit into
mainfrom
fix/test-home-isolation
Aug 2, 2026
Merged

philband merged 1 commit into
mainfrom
fix/test-home-isolation

Conversation

@philband

@philband philband commented Aug 2, 2026

Copy link
Copy Markdown
Owner

What happened

Once init began binding tools into the local registry (#19), any test that invoked it without an isolated HOME wrote into the developer's real settings.yaml. That is not hypothetical — it occurred during development of #19, in the window after init gained the write and before fakeSOPS gained HOME isolation:

providers:
  sops:
    executable: /opt/homebrew/Cellar/dotenvsec/0.7.0/bin/dotenvsec-provider-sops   # real
    source: bundled                                                                 # real
    plugin_path: /var/folders/.../TestInitGitLocalInheritedReadOnly148068561/002    # test
    tools:
      sops:
        executable: /private/var/folders/.../TestInitGitLocalInheritedReadOnly.../sops

The blast radius is larger than a corrupted field. LoadSettings is on the path of every command, so an older binary encountering the unknown fields fails on every invocation — including the prompt hook. The symptom was dotenvsec: validate YAML fields: field plugin_path not found in type config.ProviderEntry on plain git log, in a directory with no scope at all.

Fix

Isolating inside fakeSOPS only protects tests that remember to call it, which is exactly the assumption that failed. TestMain isolates HOME and XDG_CONFIG_HOME for every package that reads or writes settings (cli, app, config, identity), so no future test can reach the real path regardless of which helpers it uses.

Verification

Checksummed the real settings.yaml, ran the full suite, re-checksummed — byte-identical. Without this change the same procedure mutates it. just lint clean, all packages pass.

Once init began binding tools into the local registry, any test invoking it
without an isolated HOME wrote into the developer's real settings.yaml.
That happened: temporary-directory paths were saved as plugin_path and
tools.sops under a genuine provider entry, and because LoadSettings is on
the path of every command, an older binary reading those unknown fields
failed on every invocation, including the shell hook.

Isolating inside a shared helper only protects tests that remember to call
it. TestMain isolates HOME and XDG_CONFIG_HOME for every package that
reads or writes settings, so no future test can reach the real path
regardless of which helpers it uses.
@philband
philband merged commit 9e31350 into main Aug 2, 2026
7 checks passed
@philband
philband deleted the fix/test-home-isolation branch August 2, 2026 14:10
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