Skip to content

swift test writes a real key into ~/.config/tacet/ on the developer's machine #20

Description

@drycode

The Swift test suite creates ~/.config/tacet/key in the real home directory of whoever runs it. swift/Tests/TacetCoreTests/KeyFileTests.swift:6 asserts the opposite in a comment:

the real ~/.config/tacet/key is never touched.

Reproduction

rm -rf ~/.config/tacet
cd swift && swift test
ls -la ~/.config/tacet/     # key, 44 bytes, mode 600

Reproduced twice; the file timestamp matches the test-run second exactly.

Severity

Lower than it first looks, and worth recording why. Behaviour is create-if-absent, verified directly:

key before tests: cc32ca79d0f2b7c0
key after tests:  cc32ca79d0f2b7c0

An existing key is not overwritten, so this has never rotated a live secret out from under a running client. If it did overwrite, every client would start failing with a silent 401 after any test run — the same failure the dictate→hark rename produced.

Why it matters anyway

  1. A test run generates real key material outside the repo, on any machine including CI runners.
  2. It made the rename genuinely confusing: ~/.config/tacet/ appeared populated with a key that did not match the live ~/.config/hark/key, which looks exactly like a botched migration. Anyone moving config with mv would have hit "directory not empty" and, resolving it the obvious way, could have installed the test key as the live one and broken every client.

Fix

Point the tests at a temp directory. Config.swift:41 already honours TACET_CONFIG; KeyFile.swift:21 resolves homeDirectoryForCurrentUser unconditionally and does not. Giving KeyFile the same override — and setting it in the test harness — closes it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions