File tree Expand file tree Collapse file tree 6 files changed +50
-4
lines changed
Expand file tree Collapse file tree 6 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -12,16 +12,18 @@ import modelCommand from './commands/model.js';
1212import hookCommand , { isCalledFromGitHook } from './commands/hook.js' ;
1313import prCommand from './commands/pr.js' ;
1414import { 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
Original file line number Diff line number Diff line change @@ -24,8 +24,7 @@ import {
2424import { KnownError , handleCommandError } from '../utils/error.js' ;
2525
2626import { getCommitMessage } from '../utils/commit-helpers.js' ;
27-
28- const isHeadless = ( ) => ! process . stdout . isTTY ;
27+ import { isHeadless } from '../utils/headless.js' ;
2928
3029export default async (
3130 generate : number | undefined ,
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ const execAsync = promisify(exec);
66export 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(
128129export 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 (
Original file line number Diff line number Diff line change 1+ export const isHeadless = ( ) => ! process . stdout . isTTY ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { describe } from 'manten';
22
33describe ( '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' ) ) ;
Original file line number Diff line number Diff line change 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+ } ) ;
You can’t perform that action at this time.
0 commit comments