Skip to content

Fix mainInParentDirectory failing when initdb is not on PATH#2400

Merged
amitaibu merged 2 commits intofix-2397-mainInParentDirectory-initdbfrom
copilot/sub-pr-2398
Feb 12, 2026
Merged

Fix mainInParentDirectory failing when initdb is not on PATH#2400
amitaibu merged 2 commits intofix-2397-mainInParentDirectory-initdbfrom
copilot/sub-pr-2398

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 12, 2026

When running mainInParentDirectory in wrapped dev server mode, Postgres initialization commands failed if they weren't available on the system PATH outside of the direnv environment.

Changes

  • Route Postgres commands through direnv: Modified IHP.IDE.Postgres to wrap initdb, postgres, createdb, psql, and pg_ctl calls with direnv exec . when wrapWithDirenv is enabled
  • Fix SQL imports: Changed from shell redirection to psql -f invocation for consistency with wrapped execution
  • Fix Paths_ihp_ide.getDataFileName: Enhanced path resolution in ghci/dev mode to check IHP_LIB environment variable, enabling IHPSchema.sql discovery when running from parent directory
  • Add regression test: Created Test.IDE.PostgresSpec to verify wrapped command execution and IHPSchema loading

Implementation

The fix introduces a procDirenvAware helper that conditionally wraps commands:

callProcessDirenvAware :: (?context :: Context) => OsPath -> [String] -> IO ()
callProcessDirenvAware command args = do
    commandStr <- decodeUtf command
    if ?context.wrapWithDirenv
        then Process.callProcess "direnv" (["exec", ".", commandStr] <> args)
        else Process.callProcess commandStr args

Path resolution now checks IHP_LIB before falling back to relative paths:

ihpLibCandidates :: FilePath -> IO [FilePath]
ihpLibCandidates path = do
    ihpLib <- lookupEnv "IHP_LIB"
    pure case ihpLib of
        Nothing -> []
        Just ihpLibPath ->
            let ihpIdePath = takeDirectory (takeDirectory ihpLibPath)
             in [ ihpIdePath </> path
                , ihpIdePath </> "data" </> path
                ]

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

The test was expecting IHPSchema.sql to be at a specific path in the test directory, but in the Nix build environment, getDataFileName resolves to the actual source directory. Changed the assertion to just check that IHPSchema.sql is loaded with -f flag, regardless of the absolute path.

Co-authored-by: amitaibu <125707+amitaibu@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix mainInParentDirectory failing when initdb is not on PATH Fix mainInParentDirectory failing when initdb is not on PATH Feb 12, 2026
Copilot AI requested a review from amitaibu February 12, 2026 13:49
@amitaibu amitaibu marked this pull request as ready for review February 12, 2026 14:03
@amitaibu amitaibu merged commit 9c9ddd2 into fix-2397-mainInParentDirectory-initdb Feb 12, 2026
@amitaibu amitaibu deleted the copilot/sub-pr-2398 branch February 12, 2026 14:04
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