Skip to content

Commit 3752542

Browse files
fix: skip auto-update in headless mode
1 parent 171a0d8 commit 3752542

File tree

6 files changed

+50
-4
lines changed

6 files changed

+50
-4
lines changed

src/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@ import modelCommand from './commands/model.js';
1212
import hookCommand, { isCalledFromGitHook } from './commands/hook.js';
1313
import prCommand from './commands/pr.js';
1414
import { checkAndAutoUpdate } from './utils/auto-update.js';
15+
import { isHeadless } from './utils/headless.js';
1516

1617
// Auto-update check - runs in production to update under the hood
1718
// Skip during git hooks to avoid breaking commit flow
18-
if (!isCalledFromGitHook && version !== '0.0.0-semantic-release') {
19+
if (!isCalledFromGitHook && !isHeadless() && version !== '0.0.0-semantic-release') {
1920
const distTag = version.includes('-') ? 'develop' : 'latest';
2021

2122
// Check for updates and auto-update if available
2223
checkAndAutoUpdate({
2324
pkg,
2425
distTag,
26+
headless: false,
2527
});
2628
}
2729

src/commands/aicommits.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ import {
2424
import { KnownError, handleCommandError } from '../utils/error.js';
2525

2626
import { getCommitMessage } from '../utils/commit-helpers.js';
27-
28-
const isHeadless = () => !process.stdout.isTTY;
27+
import { isHeadless } from '../utils/headless.js';
2928

3029
export default async (
3130
generate: number | undefined,

src/utils/auto-update.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const execAsync = promisify(exec);
66
export interface AutoUpdateOptions {
77
pkg: { name: string; version: string };
88
distTag?: string;
9+
headless?: boolean;
910
}
1011

1112
// Parse version string into comparable parts
@@ -128,7 +129,11 @@ async function runBackgroundUpdate(
128129
export async function checkAndAutoUpdate(
129130
options: AutoUpdateOptions
130131
): Promise<void> {
131-
const { pkg, distTag = 'latest' } = options;
132+
const { pkg, distTag = 'latest', headless = false } = options;
133+
134+
if (headless) {
135+
return;
136+
}
132137

133138
// Skip for development/semantic-release versions
134139
if (

src/utils/headless.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const isHeadless = () => !process.stdout.isTTY;

tests/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe } from 'manten';
22

33
describe('aicommits', ({ runTestSuite }) => {
44
runTestSuite(import('./specs/cli/index.js'));
5+
runTestSuite(import('./specs/auto-update.js'));
56
runTestSuite(import('./specs/openai/index.js'));
67
runTestSuite(import('./specs/togetherai/index.js'));
78
runTestSuite(import('./specs/config.js'));

tests/specs/auto-update.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { testSuite, expect } from 'manten';
2+
import { checkAndAutoUpdate } from '../../src/utils/auto-update.js';
3+
4+
export default testSuite(({ describe }) => {
5+
describe('Auto update', ({ test }) => {
6+
test('skips update checks entirely in headless mode', async () => {
7+
const originalFetch = globalThis.fetch;
8+
const originalConsoleLog = console.log;
9+
const fetchCalls: string[] = [];
10+
const consoleCalls: string[] = [];
11+
12+
globalThis.fetch = (async (input: string | URL | Request) => {
13+
fetchCalls.push(String(input));
14+
throw new Error('fetch should not be called in headless mode');
15+
}) as typeof fetch;
16+
17+
console.log = (...args: unknown[]) => {
18+
consoleCalls.push(args.join(' '));
19+
};
20+
21+
try {
22+
await checkAndAutoUpdate({
23+
pkg: {
24+
name: 'aicommits',
25+
version: '1.0.0',
26+
},
27+
headless: true,
28+
});
29+
} finally {
30+
globalThis.fetch = originalFetch;
31+
console.log = originalConsoleLog;
32+
}
33+
34+
expect(fetchCalls).toEqual([]);
35+
expect(consoleCalls).toEqual([]);
36+
});
37+
});
38+
});

0 commit comments

Comments
 (0)