Skip to content
Merged
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
3 changes: 3 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
transform: {
'^.+\\.(t|j)sx?$': '@swc/jest'
},
// Disable telemetry during testing to avoid polluting analytics
testEnvironment: 'node',
setupFiles: ['<rootDir>/test/setup.js'],
// The root of your source code, typically /src
// `<rootDir>` is a token Jest substitutes
roots: ['<rootDir>'],
Expand Down
5 changes: 1 addition & 4 deletions src/PersistedConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ export interface GlobalConfig {
telemetry: TelemetryConfig;
hasShownTelemetryNotice: boolean;
lastUpdated?: string;
// Future extensibility:
// updates?: UpdatePreferences;
// preferences?: UserPreferences;
}

/**
Expand All @@ -25,7 +22,7 @@ export interface TelemetryConfig {
anonymousId: string;
endpoint: string;
trackingId: string;
apiSecret?: string;
apiSecret: string;
}

const CONFIG_DIR = path.join(os.homedir(), '.the-codegen-project');
Expand Down
27 changes: 3 additions & 24 deletions src/commands/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,10 @@ export default class Telemetry extends Command {
Logger.info('│ Telemetry Status │');
Logger.info('└─────────────────────────────────────────────┘\n');

// Check environment variable overrides
const envDisabled =
process.env.CODEGEN_TELEMETRY_DISABLED === '1' ||
process.env.DO_NOT_TRACK === '1';

if (envDisabled) {
Logger.info('Status: ❌ DISABLED (via environment variable)');
Logger.info('\nEnvironment variables:');
if (process.env.CODEGEN_TELEMETRY_DISABLED === '1') {
Logger.info(' CODEGEN_TELEMETRY_DISABLED=1');
}
if (process.env.DO_NOT_TRACK === '1') {
Logger.info(' DO_NOT_TRACK=1');
}
} else {
Logger.info(`Status: ${enabled ? '✅ ENABLED' : '❌ DISABLED'}`);
}

Logger.info(`Status: ${enabled ? '✅ ENABLED' : '❌ DISABLED'}`);
Logger.info(`\nConfig file: ${configPath}`);
Logger.info(`Anonymous ID: ${config.anonymousId || 'Not set'}`);
Logger.info(`Endpoint: ${config.endpoint || 'Not set'}`);

if (process.env.CODEGEN_TELEMETRY_ENDPOINT) {
Logger.info(` (overridden by CODEGEN_TELEMETRY_ENDPOINT)`);
}
Logger.info(`Anonymous ID: ${config.anonymousId}`);
Logger.info(`Endpoint: ${config.endpoint}`);

Logger.info('\nWhat we collect:');
Logger.info(' ✓ Command usage and flags');
Expand Down
13 changes: 7 additions & 6 deletions src/telemetry/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import {ProjectTelemetryConfig} from '../codegen/types';
* This function never throws - returns disabled config on any error.
*
* Priority order (highest to lowest):
* 1. DO_NOT_TRACK or CODEGEN_TELEMETRY_DISABLED environment variables
* 2. Environment variable overrides (endpoint, tracking ID, API secret)
* 3. Project-level config (from codegen.config.js)
* 4. Global config file (~/.the-codegen-project/config.json)
* 1. Project-level config (from codegen.config.js)
* 2. Global config file (~/.the-codegen-project/config.json)
* 3. Environment variable overrides (CODEGEN_TELEMETRY_DISABLED, DO_NOT_TRACK)
*
* @param projectConfig - Optional project-level telemetry config from codegen.config.js
* @returns Promise resolving to telemetry configuration
Expand All @@ -30,7 +29,8 @@ export async function getTelemetryConfig(
...globalConfig.telemetry,
...(projectConfig ?? {})
};
// 4. Apply environment variable overrides (highest priority for values)

// Apply environment variable overrides
if (
process.env.CODEGEN_TELEMETRY_DISABLED === '1' ||
process.env.DO_NOT_TRACK
Expand Down Expand Up @@ -84,6 +84,7 @@ function createDisabledTelemetryConfig(): TelemetryConfig {
enabled: false,
anonymousId: '',
endpoint: '',
trackingId: ''
trackingId: '',
apiSecret: ''
};
}
19 changes: 11 additions & 8 deletions test/commands/telemetry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,31 @@ describe('telemetry command', () => {
});

describe('environment variable handling', () => {
it('should show DO_NOT_TRACK in status when set', async () => {
it('should show DISABLED when DO_NOT_TRACK is set', async () => {
// Save and clear global test setup
const originalCodegenDisabled = process.env.CODEGEN_TELEMETRY_DISABLED;
delete process.env.CODEGEN_TELEMETRY_DISABLED;

process.env.DO_NOT_TRACK = '1';

const {stdout, error} = await runCommand('telemetry status');

expect(error).toBeUndefined();
expect(stdout).toContain('DISABLED');
expect(stdout).toContain('DO_NOT_TRACK=1');

delete process.env.DO_NOT_TRACK;
// Restore global test setup
if (originalCodegenDisabled) {
process.env.CODEGEN_TELEMETRY_DISABLED = originalCodegenDisabled;
}
});

it('should show CODEGEN_TELEMETRY_DISABLED in status when set', async () => {
process.env.CODEGEN_TELEMETRY_DISABLED = '1';

it('should show DISABLED when CODEGEN_TELEMETRY_DISABLED is set', async () => {
// CODEGEN_TELEMETRY_DISABLED is already set by test setup
const {stdout, error} = await runCommand('telemetry status');

expect(error).toBeUndefined();
expect(stdout).toContain('DISABLED');
expect(stdout).toContain('CODEGEN_TELEMETRY_DISABLED=1');

delete process.env.CODEGEN_TELEMETRY_DISABLED;
});
});

Expand Down
5 changes: 1 addition & 4 deletions test/configs/config-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ export default {
language: 'typescript',
protocols: ['nats']
}
],
telemetry: {
enabled: false
}
]
};
5 changes: 1 addition & 4 deletions test/configs/config-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ export default {
return 'Hello World!';
}
}
],
telemetry: {
enabled: false
}
]
};
5 changes: 1 addition & 4 deletions test/configs/config-implicit.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ export default {
outputPath: './src/__gen__/',
protocols: ['nats']
}
],
telemetry: {
enabled: false
}
]
};
5 changes: 1 addition & 4 deletions test/configs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@ export default {
// Not needed, as we can look in the AsyncAPI file, but we can overwrite it
serializationType: 'json',
}
],
telemetry: {
enabled: false
}
]
};
5 changes: 1 addition & 4 deletions test/configs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@
"outputPath": "./src/__gen__/",
"serializationType": "json"
}
],
"telemetry": {
"enabled": false
}
]
}
5 changes: 1 addition & 4 deletions test/configs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ const config: TheCodegenConfiguration = {
// Not needed, as we can look in the AsyncAPI file, but we can overwrite it
serializationType: 'json',
},
],
telemetry: {
enabled: false
}
]
};

export default config;
4 changes: 1 addition & 3 deletions test/configs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ language: typescript
generators:
- preset: payloads
outputPath: "./src/__gen__/"
serializationType: json
telemetry:
enabled: false
serializationType: json
5 changes: 1 addition & 4 deletions test/configs/invalid-input-type-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ export default {
preset: 'payloads',
outputPath: './output'
}
],
telemetry: {
enabled: false
}
]
};

5 changes: 1 addition & 4 deletions test/configs/invalid-preset-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ export default {
preset: 'completely-invalid-preset-name',
outputPath: './output'
}
],
telemetry: {
enabled: false
}
]
};

5 changes: 1 addition & 4 deletions test/configs/invalid-test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@ export default {
preset: 'invalid-preset-that-does-not-exist',
outputPath: './output'
}
],
telemetry: {
enabled: false
}
]
};
6 changes: 1 addition & 5 deletions test/configs/malformed-test-config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
export default {
inputType: 'asyncapi',
// Missing required inputPath field
telemetry: {
enabled: false
}
inputType: 'asyncapi'
};

5 changes: 1 addition & 4 deletions test/configs/openapi-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@
"outputPath": "./src/__gen__/",
"id": "openapi-types"
}
],
"telemetry": {
"enabled": false
}
]
}
5 changes: 1 addition & 4 deletions test/runtime/typescript/codegen-openapi.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,5 @@ export default {
preset: 'types',
outputPath: './src/openapi',
}
],
telemetry: {
enabled: false
}
]
};
5 changes: 1 addition & 4 deletions test/runtime/typescript/codegen-regular.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,5 @@ export default {
outputPath: './src/client',
protocols: ['nats']
}
],
telemetry: {
enabled: false
}
]
};
5 changes: 1 addition & 4 deletions test/runtime/typescript/codegen-request-reply.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,5 @@ export default {
outputPath: './src/request-reply/client',
protocols: ['nats']
}
],
telemetry: {
enabled: false
}
]
};
6 changes: 3 additions & 3 deletions test/runtime/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"test:http:auth": "jest -- ./test/channels/request_reply/http_client/api_auth.spec.ts",
"test:http:oauth2": "jest -- ./test/channels/http_client/oauth2_client_credentials.spec.ts ./test/channels/http_client/oauth2_implicit_flow.spec.ts ./test/channels/http_client/oauth2_password_flow.spec.ts ./test/channels/http_client/oauth2_refresh_token.spec.ts",
"generate": "npm run generate:regular && npm run generate:request:reply && npm run generate:openapi",
"generate:request:reply": "node ../../../bin/run.mjs generate ./codegen-request-reply.mjs",
"generate:regular": "node ../../../bin/run.mjs generate ./codegen-regular.mjs",
"generate:openapi": "node ../../../bin/run.mjs generate ./codegen-openapi.mjs",
"generate:request:reply": "CODEGEN_TELEMETRY_DISABLED=1 node ../../../bin/run.mjs generate ./codegen-request-reply.mjs",
"generate:regular": "CODEGEN_TELEMETRY_DISABLED=1 node ../../../bin/run.mjs generate ./codegen-regular.mjs",
"generate:openapi": "CODEGEN_TELEMETRY_DISABLED=1 node ../../../bin/run.mjs generate ./codegen-openapi.mjs",
"debug:generate": "node --inspect-brk ../../../bin/run.mjs generate"
},
"dependencies": {
Expand Down
5 changes: 5 additions & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Global test setup - runs before all tests
// Disable telemetry during testing to avoid polluting analytics with test data
// eslint-disable-next-line no-undef
process.env.CODEGEN_TELEMETRY_DISABLED = '1';