Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

32 lines
1.2 KiB
Go

package hooks
import (
"os"
"path/filepath"
"testing"
"github.com/zzet/gortex/internal/profiles"
)
// TestMain ensures hook tests never write telemetry to the user's real
// ~/.cache/gortex/hook-decisions.jsonl. Tests that want to inspect the
// log redirect it again via t.Setenv to a per-test tmp file.
func TestMain(m *testing.M) {
// Pin the instruction profile so a developer machine that ran
// `gortex instructions switch` cannot change hook-tier behavior
// in unrelated tests; tier tests stub activeHookTier directly.
_ = os.Setenv(profiles.ActiveEnv, profiles.DefaultName)
dir, err := os.MkdirTemp("", "gortex-hooks-test")
if err == nil {
_ = os.Setenv("GORTEX_HOOK_LOG", filepath.Join(dir, "hook-decisions.jsonl"))
defer func() { _ = os.RemoveAll(dir) }()
}
// Default the file-indexed / file-summary probes to "not indexed" so no
// test dials a real daemon. Tests needing an indexed verdict stub
// fileIndexedFn / fileSummaryFn (fakeIndexedBridge / newIndexedBridge /
// stubBridge) and restore these defaults on cleanup.
fileIndexedFn = func(_, _ string) (bool, int) { return false, 0 }
fileSummaryFn = func(_, _ string) (*hookFileSummary, bool) { return nil, false }
os.Exit(m.Run())
}