Skip to content

Isolate Git test fixtures from the developer's global git config #425

Open

Description

@levifig

TestWorktreeStorageMissingMainPreservesCanonicalIdentity fails on any machine whose global git config sets worktree.useRelativePaths = true. Found on 22 October while rebasing #422: the test fails on main (02f36e9, and also 182157e) on such a machine and passes with GIT_CONFIG_GLOBAL=/dev/null. Run alone or with the other worktree storage tests, it fails every time, so a developer checking worktree behavior gets a false failure. Two full make verify-local runs on the same machine passed it, for a reason not yet understood.

Steps to reproduce

  1. Set git config --global worktree.useRelativePaths true.
  2. Run env -u LOAF_DB go test ./internal/cli -run TestWorktreeStorageMissingMainPreservesCanonicalIdentity -count=1.
  3. The relative-pointer-true case fails because filepath.Rel cannot relate the already-relative gitdir path to the absolute worktree path. With GIT_CONFIG_GLOBAL=/dev/null the test passes.

Definition of Done

  • The test helpers that create Git fixtures run git without reading the developer's global or system config, so the suite gives the same result on every machine.
  • TestWorktreeStorageMissingMainPreservesCanonicalIdentity passes with worktree.useRelativePaths = true set globally and with it unset.
  • Product behavior is unchanged.

Out of Scope

  • Changing how Loaf resolves relative gitdir pointers; the test's relative case already covers that once its setup works.

Verification

  • The test passes with worktree.useRelativePaths = true in the global config and with it unset.
  • go test ./internal/cli -run TestWorktreeStorage -count=1 and make verify-local both pass on a machine with that setting.

Agent notes
  • Start: gitCLI, initCLIGitRepo and addCLILinkedWorktree in internal/cli/cli_test.go, around line 12770.
  • Find: some tests already isolate git with GIT_CONFIG_GLOBAL=/dev/null and GIT_CONFIG_NOSYSTEM=1, for example internal/cli/journal_test.go:470 and internal/cli/enumerated_reader_unix_test.go:170.
  • Findings: the failing setup is at internal/cli/worktree_storage_gate_test.go:196. Git 2.56.0 with the setting writes the linked worktree's pointer as gitdir: ../001/.git/worktrees/001-missing-main, so filepath.Rel(linked, target) fails. It fails when run alone or with -run TestWorktreeStorage, in foreground and background shells with the same HOME, XDG_CONFIG_HOME and git config, yet passed in two full make verify-local runs that night. No test in the package sets GIT_CONFIG_GLOBAL or XDG_CONFIG_HOME outside t.Setenv, so why the full run passes is unexplained.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions