[codex] fix simple-git unsafe env handling

Merged
KI
6mo ago
+390-36

Fixes #4599
Supersedes #4600

What changed

  • Replaces the shell-env PAGER/GIT_PAGER stripping workaround with a simple-git configuration that explicitly allows the user's Git environment/config hooks.
  • Centralizes the simple-git unsafe allow-list in @superset/shared/simple-git-options so desktop and host-service use the same policy.
  • Routes host-service production simple-git construction through one wrapper and adds a lint guard to prevent future direct production simpleGit(...) usage outside approved wrappers.
  • Adds regression coverage proving default simple-git rejects the blocked env while our configured client accepts it.

Why

The allowUnsafeEditor / allowUnsafePager failures are thrown by simple-git@3.36.0, not by Git itself. Superset is a local Git client, so honoring the user's local Git environment is expected. Deleting individual env vars treated one symptom and changed user Git semantics.

Validation

  • bun test packages/shared/src/simple-git-options.test.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/git-client.test.ts packages/host-service/src/runtime/git/simple-git.test.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/shell-env.test.ts
  • bun run lint
  • bun run typecheck in packages/shared
  • bun run typecheck in packages/host-service
  • bun run typecheck in apps/desktop
  • Mutation-checked the regression tests by temporarily removing allowUnsafeEditor and allowUnsafeAlias; both cases failed as expected before restoration.

Summary by cubic

Fixes simple-git unsafe env errors by allowing user Git env/config and centralizing options to honor local Git behavior. Removes the PAGER stripping workaround and routes production Git usage through approved wrappers.

  • Bug Fixes

    • Enable all simple-git@3.36 unsafe flags via @superset/shared/simple-git-options so editor/pager/hooks work as expected.
    • Preserve PAGER/GIT_PAGER in desktop shell env.
    • Add tests covering the explicit unsafe flag list and acceptance of user env vs default rejection.
  • Refactors

    • Add createUserSimpleGit wrapper (host-service) and use shared options in desktop and host-service.
    • Replace direct simple-git usage with wrappers in production paths.
    • Add scripts/check-simple-git-usage.sh and run it in scripts/lint.sh to forbid direct imports/constructors outside tests and approved wrappers.

Summary by CodeRabbit

  • New Features

    • Improved Git integration with centralized configuration for safer, more reliable Git operations across the application.
    • Enhanced environment variable preservation for Git-related settings (editor, pager configurations).
  • Bug Fixes

    • Resolved issues with Git hook handling by implementing consistent Git client initialization.
  • Tests

    • Added comprehensive test coverage for Git client configuration and environment variable handling.

Review Change Stack