1- import { getOrCreateInstallationId , readGlobalConfig , updateGlobalConfig } from '../global-config' ;
1+ import {
2+ getOrCreateInstallationId ,
3+ readGlobalConfig ,
4+ readGlobalConfigSync ,
5+ updateGlobalConfig ,
6+ } from '../../lib/schemas/io/global-config' ;
27import { createTempConfig } from './helpers/temp-config' ;
38import { readFile , writeFile } from 'fs/promises' ;
49import { afterAll , beforeEach , describe , expect , it } from 'vitest' ;
@@ -21,10 +26,29 @@ describe('global-config', () => {
2126 it ( 'returns empty object when file is missing or invalid' , async ( ) => {
2227 expect ( await readGlobalConfig ( tmp . testDir + '/nonexistent.json' ) ) . toEqual ( { } ) ;
2328
24- await writeFile ( tmp . configFile , JSON . stringify ( { telemetry : { enabled : 'false' } } ) ) ;
29+ await writeFile ( tmp . configFile , 'not json' ) ;
2530 expect ( await readGlobalConfig ( tmp . configFile ) ) . toEqual ( { } ) ;
2631 } ) ;
2732
33+ it ( 'drops invalid fields while preserving valid ones' , async ( ) => {
34+ await writeFile (
35+ tmp . configFile ,
36+ JSON . stringify ( {
37+ transactionSearchIndexPercentage : 'not-a-number' ,
38+ uvIndex : 'https://valid.url' ,
39+ telemetry : { enabled : 'yes' , endpoint : 'https://example.com' } ,
40+ } )
41+ ) ;
42+
43+ const config = await readGlobalConfig ( tmp . configFile ) ;
44+
45+ expect ( config ) . toEqual ( {
46+ transactionSearchIndexPercentage : undefined ,
47+ uvIndex : 'https://valid.url' ,
48+ telemetry : { enabled : undefined , endpoint : 'https://example.com' } ,
49+ } ) ;
50+ } ) ;
51+
2852 it ( 'preserves unknown fields via passthrough' , async ( ) => {
2953 const full = {
3054 installationId : 'abc-123' ,
@@ -39,6 +63,21 @@ describe('global-config', () => {
3963 } ) ;
4064 } ) ;
4165
66+ describe ( 'readGlobalConfigSync' , ( ) => {
67+ it ( 'returns parsed config when file exists' , async ( ) => {
68+ await writeFile ( tmp . configFile , JSON . stringify ( { telemetry : { enabled : false } } ) ) ;
69+
70+ expect ( readGlobalConfigSync ( tmp . configFile ) ) . toEqual ( { telemetry : { enabled : false } } ) ;
71+ } ) ;
72+
73+ it ( 'returns empty object when file is missing or invalid' , async ( ) => {
74+ expect ( readGlobalConfigSync ( tmp . testDir + '/nonexistent.json' ) ) . toEqual ( { } ) ;
75+
76+ await writeFile ( tmp . configFile , 'not json' ) ;
77+ expect ( readGlobalConfigSync ( tmp . configFile ) ) . toEqual ( { } ) ;
78+ } ) ;
79+ } ) ;
80+
4281 describe ( 'updateGlobalConfig' , ( ) => {
4382 it ( 'creates directory and writes config when none exists' , async ( ) => {
4483 const fresh = createTempConfig ( 'gc-fresh' ) ;
0 commit comments