From 45753638dcedc4f580caa7d6034168bb8ce03f60 Mon Sep 17 00:00:00 2001 From: rUv Date: Fri, 30 Oct 2026 16:59:42 -0400 Subject: [PATCH] fix(update): skip the startup update check for CI=1, not only CI=true (#4608) * fix(update): skip the startup update check for CI=1, not only CI=true The startup update check skipped CI only when CI was the literal string 'true'. A CI=1 run (many CI systems, and the mods-cli-bin test) checked, found a newer published CLI and ran npm install @claude-flow/cli@ --save-exact in the working directory during ruflo init. After 3.65.1 was published that install, with native builds, pushed init past the test's 120s child timeout on every branch still at 3.65.0. isCI() now accepts any CI, CONTINUOUS_INTEGRATION or GITHUB_ACTIONS value except empty, 0 or false. Co-Authored-By: RuFlo * fix(update): CI detection reads CI and CONTINUOUS_INTEGRATION only GitHub Actions sets CI=true, so GITHUB_ACTIONS added nothing and broke rate-limiter tests that clear CI to exercise the non-CI path. Co-Authored-By: RuFlo --------- Co-authored-by: r --- .../cli/__tests__/update-ci-detection.test.ts | 36 +++++++++++++++++++ .../cli/src/update/rate-limiter.ts | 14 +++++++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 v3/@claude-flow/cli/__tests__/update-ci-detection.test.ts diff --git a/v3/@claude-flow/cli/__tests__/update-ci-detection.test.ts b/v3/@claude-flow/cli/__tests__/update-ci-detection.test.ts new file mode 100644 index 0000000000..1a754b0b6e --- /dev/null +++ b/v3/@claude-flow/cli/__tests__/update-ci-detection.test.ts @@ -0,0 +1,36 @@ +/** + * The startup update check must skip CI runs however CI is spelled. It matched only + * `CI=true`, so a `CI=1` run checked, found a newer published CLI and ran + * `npm install @claude-flow/cli@ --save-exact` in the working directory during `ruflo init`. + */ +import { afterEach, describe, expect, it } from 'vitest'; +import { isCI, shouldCheckForUpdates } from '../src/update/rate-limiter.js'; + +const saved = { CI: process.env.CI, CONTINUOUS_INTEGRATION: process.env.CONTINUOUS_INTEGRATION }; +afterEach(() => { + for (const [k, v] of Object.entries(saved)) { + if (v === undefined) delete process.env[k]; + else process.env[k] = v; + } +}); + +describe('update check: CI detection', () => { + it.each(['true', '1', 'TRUE', 'yes', 'woodpecker'])('CI=%s is CI', (value) => { + expect(isCI({ CI: value })).toBe(true); + }); + + it.each(['', '0', 'false', 'False'])('CI=%j is not CI', (value) => { + expect(isCI({ CI: value })).toBe(false); + }); + + it('CONTINUOUS_INTEGRATION counts too; no variable is not CI', () => { + expect(isCI({ CONTINUOUS_INTEGRATION: '1' })).toBe(true); + expect(isCI({})).toBe(false); + }); + + it('shouldCheckForUpdates skips a CI=1 run', () => { + delete process.env.CONTINUOUS_INTEGRATION; + process.env.CI = '1'; + expect(shouldCheckForUpdates()).toEqual({ allowed: false, reason: 'CI environment detected' }); + }); +}); diff --git a/v3/@claude-flow/cli/src/update/rate-limiter.ts b/v3/@claude-flow/cli/src/update/rate-limiter.ts index eb8676128c..c977aa331d 100644 --- a/v3/@claude-flow/cli/src/update/rate-limiter.ts +++ b/v3/@claude-flow/cli/src/update/rate-limiter.ts @@ -60,11 +60,23 @@ export function saveState(state: RateLimitState): void { fs.writeFileSync(STATE_FILE, JSON.stringify(state, null, 2)); } +/** + * Whether this is a CI run. CI systems set `CI` to `true`, `1` or other values, so any value + * except empty, `0` or `false` counts (GitHub Actions sets CI=true). Matching only `true` let CI=1 runs check for updates and + * install one (`npm install @claude-flow/cli@`) into the working directory mid-run. + */ +export function isCI(env: NodeJS.ProcessEnv = process.env): boolean { + return ['CI', 'CONTINUOUS_INTEGRATION'].some((name) => { + const value = env[name]; + return value !== undefined && value.trim() !== '' && !/^(0|false)$/i.test(value.trim()); + }); +} + export function shouldCheckForUpdates( intervalHours: number = DEFAULT_INTERVAL_HOURS ): { allowed: boolean; reason?: string } { // Skip in CI environments - if (process.env.CI === 'true' || process.env.CONTINUOUS_INTEGRATION === 'true') { + if (isCI()) { return { allowed: false, reason: 'CI environment detected' }; }