Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/cli/__tests__/global-config.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { getOrCreateInstallationId, readGlobalConfig, updateGlobalConfig } from '../global-config';
import {
getOrCreateInstallationId,
readGlobalConfig,
readGlobalConfigSync,
updateGlobalConfig,
} from '../../lib/schemas/io/global-config';
import { createTempConfig } from './helpers/temp-config';
import { readFile, writeFile } from 'fs/promises';
import { afterAll, beforeEach, describe, expect, it } from 'vitest';
Expand Down Expand Up @@ -39,6 +44,21 @@ describe('global-config', () => {
});
});

describe('readGlobalConfigSync', () => {
it('returns parsed config when file exists', async () => {
await writeFile(tmp.configFile, JSON.stringify({ telemetry: { enabled: false } }));

expect(readGlobalConfigSync(tmp.configFile)).toEqual({ telemetry: { enabled: false } });
});

it('returns empty object when file is missing or invalid', async () => {
expect(readGlobalConfigSync(tmp.testDir + '/nonexistent.json')).toEqual({});

await writeFile(tmp.configFile, 'not json');
expect(readGlobalConfigSync(tmp.configFile)).toEqual({});
});
});

describe('updateGlobalConfig', () => {
it('creates directory and writes config when none exists', async () => {
const fresh = createTempConfig('gc-fresh');
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getOrCreateInstallationId } from '../lib/schemas/io/global-config';
import { registerAdd } from './commands/add';
import { registerCreate } from './commands/create';
import { registerDeploy } from './commands/deploy';
Expand All @@ -19,7 +20,6 @@ import { registerTraces } from './commands/traces';
import { registerUpdate } from './commands/update';
import { registerValidate } from './commands/validate';
import { PACKAGE_VERSION } from './constants';
import { getOrCreateInstallationId } from './global-config';
import { ALL_PRIMITIVES } from './primitives';
import { App } from './tui/App';
import { LayoutProvider } from './tui/context';
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/telemetry/__tests__/telemetry.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { readGlobalConfig } from '../../../../lib/schemas/io/global-config';
import { createTempConfig } from '../../../__tests__/helpers/temp-config';
import { readGlobalConfig } from '../../../global-config';
import { handleTelemetryDisable, handleTelemetryEnable, handleTelemetryStatus } from '../actions';
import { chmod, mkdir, rm, writeFile } from 'fs/promises';
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/telemetry/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GLOBAL_CONFIG_DIR, GLOBAL_CONFIG_FILE, updateGlobalConfig } from '../../global-config.js';
import { GLOBAL_CONFIG_DIR, GLOBAL_CONFIG_FILE, updateGlobalConfig } from '../../../lib/schemas/io/global-config.js';
import { resolveTelemetryPreference } from '../../telemetry/resolve.js';

export async function handleTelemetryDisable(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { setupTransactionSearch } from '../post-deploy-observability.js';
import { beforeEach, describe, expect, it, vi } from 'vitest';

const { mockEnableTransactionSearch, mockReadCliConfig } = vi.hoisted(() => ({
const { mockEnableTransactionSearch, mockReadGlobalConfigSync } = vi.hoisted(() => ({
mockEnableTransactionSearch: vi.fn(),
mockReadCliConfig: vi.fn(),
mockReadGlobalConfigSync: vi.fn(),
}));

vi.mock('../../../aws/transaction-search', () => ({
enableTransactionSearch: mockEnableTransactionSearch,
}));

vi.mock('../../../../lib/schemas/io/cli-config', () => ({
readCliConfig: mockReadCliConfig,
vi.mock('../../../../lib/schemas/io/global-config', () => ({
readGlobalConfigSync: mockReadGlobalConfigSync,
}));

describe('setupTransactionSearch', () => {
beforeEach(() => {
vi.clearAllMocks();
mockReadCliConfig.mockReturnValue({});
mockReadGlobalConfigSync.mockReturnValue({});
mockEnableTransactionSearch.mockResolvedValue({ success: true });
});

Expand All @@ -33,7 +33,7 @@ describe('setupTransactionSearch', () => {
});

it('passes custom transactionSearchIndexPercentage from config', async () => {
mockReadCliConfig.mockReturnValue({ transactionSearchIndexPercentage: 25 });
mockReadGlobalConfigSync.mockReturnValue({ transactionSearchIndexPercentage: 25 });

const result = await setupTransactionSearch({
region: 'us-east-1',
Expand All @@ -57,7 +57,7 @@ describe('setupTransactionSearch', () => {
});

it('skips when disableTransactionSearch is true in config', async () => {
mockReadCliConfig.mockReturnValue({ disableTransactionSearch: true });
mockReadGlobalConfigSync.mockReturnValue({ disableTransactionSearch: true });

const result = await setupTransactionSearch({
region: 'us-east-1',
Expand Down
4 changes: 2 additions & 2 deletions src/cli/operations/deploy/post-deploy-observability.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readCliConfig } from '../../../lib/schemas/io/cli-config';
import { readGlobalConfigSync } from '../../../lib/schemas/io/global-config';
import { enableTransactionSearch } from '../../aws/transaction-search';

export interface TransactionSearchSetupOptions {
Expand Down Expand Up @@ -31,7 +31,7 @@ export async function setupTransactionSearch(
return { success: true };
}

const config = readCliConfig();
const config = readGlobalConfigSync();
if (config.disableTransactionSearch) {
return { success: true };
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/telemetry/resolve.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { readGlobalConfig } from '../global-config.js';
import { readGlobalConfig } from '../../lib/schemas/io/global-config.js';

export interface TelemetryPreference {
enabled: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/lib/packaging/build-args.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { readCliConfig } from '../schemas/io/cli-config';
import { readGlobalConfigSync } from '../schemas/io/global-config';

/**
* Return Docker --build-arg flags for UV index URLs configured in ~/.agentcore/config.json.
* Returns an empty array when no custom indexes are configured.
*/
export function getUvBuildArgs(): string[] {
const config = readCliConfig();
const config = readGlobalConfigSync();
const args: string[] = [];
if (config.uvDefaultIndex) args.push('--build-arg', `UV_DEFAULT_INDEX=${config.uvDefaultIndex}`);
if (config.uvIndex) args.push('--build-arg', `UV_INDEX=${config.uvIndex}`);
Expand Down
36 changes: 0 additions & 36 deletions src/lib/schemas/io/cli-config.ts

This file was deleted.

23 changes: 17 additions & 6 deletions src/cli/global-config.ts → src/lib/schemas/io/global-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { readFileSync } from 'fs';
import { mkdir, readFile, writeFile } from 'fs/promises';
import { randomUUID } from 'node:crypto';
import { homedir } from 'os';
Expand All @@ -9,18 +10,19 @@ export const GLOBAL_CONFIG_FILE = join(GLOBAL_CONFIG_DIR, 'config.json');

const GlobalConfigSchema = z
.object({
installationId: z.string().optional(),
uvDefaultIndex: z.string().optional(),
uvIndex: z.string().optional(),
disableTransactionSearch: z.boolean().optional(),
transactionSearchIndexPercentage: z.number().min(0).max(100).optional(),
installationId: z.string().optional().catch(undefined),
uvDefaultIndex: z.string().optional().catch(undefined),
uvIndex: z.string().optional().catch(undefined),
disableTransactionSearch: z.boolean().optional().catch(undefined),
transactionSearchIndexPercentage: z.number().int().min(0).max(100).optional().catch(undefined),
telemetry: z
.object({
enabled: z.boolean().optional(),
endpoint: z.string().optional(),
audit: z.boolean().optional(),
})
.optional(),
.optional()
.catch(undefined),
})
.passthrough();

Expand All @@ -35,6 +37,15 @@ export async function readGlobalConfig(configFile = GLOBAL_CONFIG_FILE): Promise
}
}

export function readGlobalConfigSync(configFile = GLOBAL_CONFIG_FILE): GlobalConfig {
try {
const data = readFileSync(configFile, 'utf-8');
return GlobalConfigSchema.parse(JSON.parse(data));
} catch {
return {};
}
}

export async function updateGlobalConfig(
partial: GlobalConfig,
configDir = GLOBAL_CONFIG_DIR,
Expand Down
1 change: 0 additions & 1 deletion src/lib/schemas/io/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ export {
type PathConfig,
} from './path-resolver';
export { ConfigIO, createConfigIO, getSchemaUrlForVersion } from './config-io';
export { readCliConfig, type CliConfig } from './cli-config';
Loading