mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-12-04 22:41:40 +09:00
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@<latest> --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 <ruv@ruv.net> * 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 <ruv@ruv.net> --------- Co-authored-by: r <r@x>
This commit is contained in:
1 parent
4114d92514
commit
45753638dc
2 files changed
+49
-1
No files matched your search
@@ -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@<latest> --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' });
|
||||
});
|
||||
});
|
||||
@@ -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@<latest>`) 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' };
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user