(t *testing.T)
| 23 | ) |
| 24 | |
| 25 | func TestShouldRunCompileUpdateCheck(t *testing.T) { |
| 26 | origGetFilePath := getCompileUpdateCheckFilePathFunc |
| 27 | origIsTerminal := compileUpdateCheckIsTerminalFunc |
| 28 | t.Cleanup(func() { |
| 29 | getCompileUpdateCheckFilePathFunc = origGetFilePath |
| 30 | compileUpdateCheckIsTerminalFunc = origIsTerminal |
| 31 | }) |
| 32 | |
| 33 | tmpDir := t.TempDir() |
| 34 | lastCheckFile := filepath.Join(tmpDir, compileUpdateCheckFileName) |
| 35 | getCompileUpdateCheckFilePathFunc = func() string { |
| 36 | return lastCheckFile |
| 37 | } |
| 38 | compileUpdateCheckIsTerminalFunc = func() bool { |
| 39 | return true |
| 40 | } |
| 41 | |
| 42 | t.Setenv("CI", "") |
| 43 | t.Setenv("CONTINUOUS_INTEGRATION", "") |
| 44 | t.Setenv("GITHUB_ACTIONS", "") |
| 45 | t.Setenv("GH_AW_MCP_SERVER", "") |
| 46 | t.Setenv(compileUpdateCheckDisableEnv, "") |
| 47 | assert.True(t, shouldRunCompileUpdateCheck(false), "check should run when not disabled") |
| 48 | |
| 49 | require.NoError( |
| 50 | t, |
| 51 | os.WriteFile(lastCheckFile, []byte(time.Now().Format(time.RFC3339)), 0600), |
| 52 | "recent compile update marker should be written", |
| 53 | ) |
| 54 | assert.False(t, shouldRunCompileUpdateCheck(false), "recent marker should suppress the background check") |
| 55 | |
| 56 | t.Setenv(compileUpdateCheckDisableEnv, "1") |
| 57 | assert.False(t, shouldRunCompileUpdateCheck(false), "check should be disabled by environment variable") |
| 58 | |
| 59 | t.Setenv(compileUpdateCheckDisableEnv, "") |
| 60 | assert.False(t, shouldRunCompileUpdateCheck(true), "check should be disabled by flag") |
| 61 | |
| 62 | compileUpdateCheckIsTerminalFunc = func() bool { |
| 63 | return false |
| 64 | } |
| 65 | assert.False(t, shouldRunCompileUpdateCheck(false), "check should be disabled in non-interactive environments") |
| 66 | } |
| 67 | |
| 68 | func TestRunCompileUpdateCheck(t *testing.T) { |
| 69 | originalVersion := GetVersion() |
nothing calls this directly
no test coverage detected