fraim-framework 2.0.41 → 2.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -109,13 +109,14 @@ async function testScriptExecutability() {
109
109
  const scriptsDir = (0, path_1.join)(projectRoot, 'registry', 'scripts');
110
110
  const scriptPath = (0, path_1.join)(scriptsDir, 'cleanup-branch.ts');
111
111
  if ((0, fs_1.existsSync)(scriptPath)) {
112
- // Test that the script can be parsed without import errors
113
- const result = (0, child_process_1.execSync)(`npx tsx ${scriptPath} --help`, {
112
+ // Test that the script can be compiled/parsed without import errors
113
+ // Use tsx --check to validate syntax without executing
114
+ const result = (0, child_process_1.execSync)(`npx tsx --check ${scriptPath}`, {
114
115
  stdio: 'pipe',
115
- encoding: 'utf-8'
116
+ encoding: 'utf-8',
117
+ timeout: 5000 // 5 second timeout
116
118
  });
117
- // Should show help without errors
118
- (0, node_assert_1.default)(result.includes('Branch Cleanup Script'), 'cleanup-branch.ts should show help without import errors');
119
+ console.log(' ✅ Script compiles without import errors');
119
120
  }
120
121
  return true;
121
122
  }
@@ -125,7 +126,18 @@ async function testScriptExecutability() {
125
126
  console.error(' ❌ Script has import errors:', error.message);
126
127
  return false;
127
128
  }
128
- // Other errors (like missing git repo) are acceptable for this test
129
+ // Timeout errors indicate the script is hanging
130
+ if (error.message.includes('ETIMEDOUT') || error.message.includes('timeout')) {
131
+ console.error(' ❌ Script compilation timed out:', error.message);
132
+ return false;
133
+ }
134
+ // TypeScript compilation errors
135
+ if (error.message.includes('error TS')) {
136
+ console.error(' ❌ Script has TypeScript compilation errors:', error.message);
137
+ return false;
138
+ }
139
+ // Other errors might be acceptable
140
+ console.log(' ℹ️ Script compilation had non-critical error (acceptable):', error.message);
129
141
  return true;
130
142
  }
131
143
  }
@@ -0,0 +1,279 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const node_test_1 = require("node:test");
40
+ const node_assert_1 = __importDefault(require("node:assert"));
41
+ const fs_1 = __importDefault(require("fs"));
42
+ const path_1 = __importDefault(require("path"));
43
+ const os_1 = __importDefault(require("os"));
44
+ // Test the configuration system without interactive prompts
45
+ (0, node_test_1.test)('Config System - Global vs Local Config Separation', async () => {
46
+ // Create temporary directories for testing
47
+ const tempHomeDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-home-' + Date.now());
48
+ const tempProjectDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-project-' + Date.now());
49
+ fs_1.default.mkdirSync(tempHomeDir, { recursive: true });
50
+ fs_1.default.mkdirSync(tempProjectDir, { recursive: true });
51
+ // Mock os.homedir and process.cwd
52
+ const originalHomedir = os_1.default.homedir;
53
+ const originalCwd = process.cwd;
54
+ os_1.default.homedir = () => tempHomeDir;
55
+ process.cwd = () => tempProjectDir;
56
+ try {
57
+ // Test 1: Global config structure
58
+ const globalConfigDir = path_1.default.join(tempHomeDir, '.fraim');
59
+ const globalConfigPath = path_1.default.join(globalConfigDir, 'config.json');
60
+ fs_1.default.mkdirSync(globalConfigDir, { recursive: true });
61
+ const globalConfig = {
62
+ version: '2.0.27',
63
+ apiKey: 'fraim_test_user_key',
64
+ githubToken: 'ghp_test_github_token',
65
+ configuredAt: new Date().toISOString(),
66
+ userPreferences: {
67
+ autoSync: true,
68
+ backupConfigs: true
69
+ }
70
+ };
71
+ fs_1.default.writeFileSync(globalConfigPath, JSON.stringify(globalConfig, null, 2));
72
+ // Test 2: Local config structure
73
+ const localConfigDir = path_1.default.join(tempProjectDir, '.fraim');
74
+ const localConfigPath = path_1.default.join(localConfigDir, 'config.json');
75
+ fs_1.default.mkdirSync(localConfigDir, { recursive: true });
76
+ const localConfig = {
77
+ version: '2.0.27',
78
+ project: {
79
+ name: 'test-project'
80
+ },
81
+ git: {
82
+ defaultBranch: 'main',
83
+ repoOwner: 'testuser',
84
+ repoName: 'test-project'
85
+ },
86
+ customizations: {
87
+ workflowsPath: '.fraim/workflows'
88
+ }
89
+ };
90
+ fs_1.default.writeFileSync(localConfigPath, JSON.stringify(localConfig, null, 2));
91
+ // Test 3: Verify separation - global config has secrets, local doesn't
92
+ const globalData = JSON.parse(fs_1.default.readFileSync(globalConfigPath, 'utf8'));
93
+ const localData = JSON.parse(fs_1.default.readFileSync(localConfigPath, 'utf8'));
94
+ // Global config should have secrets
95
+ (0, node_assert_1.default)(globalData.apiKey, 'Global config should have apiKey');
96
+ (0, node_assert_1.default)(globalData.githubToken, 'Global config should have githubToken');
97
+ (0, node_assert_1.default)(globalData.userPreferences, 'Global config should have userPreferences');
98
+ // Local config should NOT have secrets
99
+ (0, node_assert_1.default)(!localData.apiKey, 'Local config should NOT have apiKey');
100
+ (0, node_assert_1.default)(!localData.githubToken, 'Local config should NOT have githubToken');
101
+ (0, node_assert_1.default)(!localData.userPreferences, 'Local config should NOT have userPreferences');
102
+ // Local config should have project settings
103
+ (0, node_assert_1.default)(localData.project, 'Local config should have project settings');
104
+ (0, node_assert_1.default)(localData.git, 'Local config should have git settings');
105
+ (0, node_assert_1.default)(localData.customizations, 'Local config should have customizations');
106
+ console.log('✅ Config separation test passed');
107
+ }
108
+ finally {
109
+ // Cleanup
110
+ fs_1.default.rmSync(tempHomeDir, { recursive: true, force: true });
111
+ fs_1.default.rmSync(tempProjectDir, { recursive: true, force: true });
112
+ // Restore original functions
113
+ os_1.default.homedir = originalHomedir;
114
+ process.cwd = originalCwd;
115
+ }
116
+ });
117
+ (0, node_test_1.test)('Config System - loadGlobalConfig function behavior', async () => {
118
+ // Import the function dynamically to avoid module loading issues
119
+ const { loadGlobalConfig } = await Promise.resolve().then(() => __importStar(require('../src/cli/commands/add-ide')));
120
+ const tempHomeDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-load-' + Date.now());
121
+ const originalHomedir = os_1.default.homedir;
122
+ os_1.default.homedir = () => tempHomeDir;
123
+ try {
124
+ // Test 1: No global config exists
125
+ const result1 = loadGlobalConfig();
126
+ node_assert_1.default.strictEqual(result1, null, 'Should return null when no config exists');
127
+ // Test 2: Create global config with both keys
128
+ const globalConfigDir = path_1.default.join(tempHomeDir, '.fraim');
129
+ const globalConfigPath = path_1.default.join(globalConfigDir, 'config.json');
130
+ fs_1.default.mkdirSync(globalConfigDir, { recursive: true });
131
+ const completeConfig = {
132
+ version: '2.0.27',
133
+ apiKey: 'fraim_complete_key',
134
+ githubToken: 'ghp_complete_token',
135
+ configuredAt: new Date().toISOString()
136
+ };
137
+ fs_1.default.writeFileSync(globalConfigPath, JSON.stringify(completeConfig, null, 2));
138
+ const result2 = loadGlobalConfig();
139
+ (0, node_assert_1.default)(result2, 'Should return config object');
140
+ node_assert_1.default.strictEqual(result2.fraimKey, 'fraim_complete_key', 'Should extract FRAIM key');
141
+ node_assert_1.default.strictEqual(result2.githubToken, 'ghp_complete_token', 'Should extract GitHub token');
142
+ // Test 3: Config with missing GitHub token
143
+ const incompleteConfig = {
144
+ version: '2.0.27',
145
+ apiKey: 'fraim_incomplete_key',
146
+ configuredAt: new Date().toISOString()
147
+ // No githubToken
148
+ };
149
+ fs_1.default.writeFileSync(globalConfigPath, JSON.stringify(incompleteConfig, null, 2));
150
+ const result3 = loadGlobalConfig();
151
+ (0, node_assert_1.default)(result3, 'Should return config object even without GitHub token');
152
+ node_assert_1.default.strictEqual(result3.fraimKey, 'fraim_incomplete_key', 'Should extract FRAIM key');
153
+ node_assert_1.default.strictEqual(result3.githubToken, undefined, 'GitHub token should be undefined');
154
+ // Test 4: Corrupted config file
155
+ fs_1.default.writeFileSync(globalConfigPath, 'invalid json content');
156
+ const result4 = loadGlobalConfig();
157
+ node_assert_1.default.strictEqual(result4, null, 'Should return null for corrupted config');
158
+ console.log('✅ loadGlobalConfig function tests passed');
159
+ }
160
+ finally {
161
+ // Cleanup
162
+ fs_1.default.rmSync(tempHomeDir, { recursive: true, force: true });
163
+ os_1.default.homedir = originalHomedir;
164
+ }
165
+ });
166
+ (0, node_test_1.test)('Config System - saveGlobalConfig function behavior', async () => {
167
+ const tempHomeDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-save-' + Date.now());
168
+ const originalHomedir = os_1.default.homedir;
169
+ os_1.default.homedir = () => tempHomeDir;
170
+ try {
171
+ // Import the setup command to test saveGlobalConfig indirectly
172
+ // We'll test by checking the file it creates
173
+ const globalConfigDir = path_1.default.join(tempHomeDir, '.fraim');
174
+ const globalConfigPath = path_1.default.join(globalConfigDir, 'config.json');
175
+ // Test 1: Save config with both keys
176
+ // We can't directly test the private function, so we'll test the file structure
177
+ fs_1.default.mkdirSync(globalConfigDir, { recursive: true });
178
+ const testConfig = {
179
+ version: '2.0.27',
180
+ apiKey: 'fraim_test_save_key',
181
+ githubToken: 'ghp_test_save_token',
182
+ configuredAt: new Date().toISOString(),
183
+ userPreferences: {
184
+ autoSync: true,
185
+ backupConfigs: true
186
+ }
187
+ };
188
+ fs_1.default.writeFileSync(globalConfigPath, JSON.stringify(testConfig, null, 2));
189
+ // Verify the file was created correctly
190
+ (0, node_assert_1.default)(fs_1.default.existsSync(globalConfigPath), 'Global config file should exist');
191
+ const savedConfig = JSON.parse(fs_1.default.readFileSync(globalConfigPath, 'utf8'));
192
+ node_assert_1.default.strictEqual(savedConfig.apiKey, 'fraim_test_save_key', 'FRAIM key should be saved');
193
+ node_assert_1.default.strictEqual(savedConfig.githubToken, 'ghp_test_save_token', 'GitHub token should be saved');
194
+ (0, node_assert_1.default)(savedConfig.userPreferences, 'User preferences should be saved');
195
+ // Test 2: Save config without GitHub token
196
+ const configWithoutGithub = {
197
+ version: '2.0.27',
198
+ apiKey: 'fraim_test_no_github',
199
+ githubToken: undefined,
200
+ configuredAt: new Date().toISOString(),
201
+ userPreferences: {
202
+ autoSync: true,
203
+ backupConfigs: true
204
+ }
205
+ };
206
+ fs_1.default.writeFileSync(globalConfigPath, JSON.stringify(configWithoutGithub, null, 2));
207
+ const savedConfig2 = JSON.parse(fs_1.default.readFileSync(globalConfigPath, 'utf8'));
208
+ node_assert_1.default.strictEqual(savedConfig2.apiKey, 'fraim_test_no_github', 'FRAIM key should be saved');
209
+ node_assert_1.default.strictEqual(savedConfig2.githubToken, undefined, 'GitHub token should be undefined');
210
+ console.log('✅ saveGlobalConfig behavior tests passed');
211
+ }
212
+ finally {
213
+ // Cleanup
214
+ fs_1.default.rmSync(tempHomeDir, { recursive: true, force: true });
215
+ os_1.default.homedir = originalHomedir;
216
+ }
217
+ });
218
+ (0, node_test_1.test)('Config System - Path Resolution', async () => {
219
+ // Test that global and local configs use correct paths
220
+ const tempHomeDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-paths-' + Date.now());
221
+ const tempProjectDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-project-paths-' + Date.now());
222
+ const originalHomedir = os_1.default.homedir;
223
+ const originalCwd = process.cwd;
224
+ os_1.default.homedir = () => tempHomeDir;
225
+ process.cwd = () => tempProjectDir;
226
+ try {
227
+ // Expected paths
228
+ const expectedGlobalPath = path_1.default.join(tempHomeDir, '.fraim', 'config.json');
229
+ const expectedLocalPath = path_1.default.join(tempProjectDir, '.fraim', 'config.json');
230
+ // Create both configs
231
+ fs_1.default.mkdirSync(path_1.default.dirname(expectedGlobalPath), { recursive: true });
232
+ fs_1.default.mkdirSync(path_1.default.dirname(expectedLocalPath), { recursive: true });
233
+ const globalConfig = { apiKey: 'global_key', githubToken: 'global_token' };
234
+ const localConfig = { project: { name: 'local_project' } };
235
+ fs_1.default.writeFileSync(expectedGlobalPath, JSON.stringify(globalConfig, null, 2));
236
+ fs_1.default.writeFileSync(expectedLocalPath, JSON.stringify(localConfig, null, 2));
237
+ // Verify paths are correct
238
+ (0, node_assert_1.default)(fs_1.default.existsSync(expectedGlobalPath), 'Global config should exist at expected path');
239
+ (0, node_assert_1.default)(fs_1.default.existsSync(expectedLocalPath), 'Local config should exist at expected path');
240
+ // Verify they're different files with different content
241
+ const globalData = JSON.parse(fs_1.default.readFileSync(expectedGlobalPath, 'utf8'));
242
+ const localData = JSON.parse(fs_1.default.readFileSync(expectedLocalPath, 'utf8'));
243
+ (0, node_assert_1.default)(globalData.apiKey, 'Global config should have API key');
244
+ (0, node_assert_1.default)(!localData.apiKey, 'Local config should not have API key');
245
+ (0, node_assert_1.default)(localData.project, 'Local config should have project info');
246
+ (0, node_assert_1.default)(!globalData.project, 'Global config should not have project info');
247
+ console.log('✅ Path resolution tests passed');
248
+ }
249
+ finally {
250
+ // Cleanup
251
+ fs_1.default.rmSync(tempHomeDir, { recursive: true, force: true });
252
+ fs_1.default.rmSync(tempProjectDir, { recursive: true, force: true });
253
+ os_1.default.homedir = originalHomedir;
254
+ process.cwd = originalCwd;
255
+ }
256
+ });
257
+ (0, node_test_1.test)('Config System - Cross-platform Path Handling', async () => {
258
+ // Test that paths work correctly on different platforms
259
+ const tempHomeDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-cross-platform-' + Date.now());
260
+ const originalHomedir = os_1.default.homedir;
261
+ os_1.default.homedir = () => tempHomeDir;
262
+ try {
263
+ // Test path.join usage (should work on all platforms)
264
+ const globalConfigPath = path_1.default.join(tempHomeDir, '.fraim', 'config.json');
265
+ // Create the config
266
+ fs_1.default.mkdirSync(path_1.default.dirname(globalConfigPath), { recursive: true });
267
+ fs_1.default.writeFileSync(globalConfigPath, JSON.stringify({ test: 'cross-platform' }, null, 2));
268
+ // Verify it exists and is readable
269
+ (0, node_assert_1.default)(fs_1.default.existsSync(globalConfigPath), 'Config should exist with cross-platform path');
270
+ const data = JSON.parse(fs_1.default.readFileSync(globalConfigPath, 'utf8'));
271
+ node_assert_1.default.strictEqual(data.test, 'cross-platform', 'Config should be readable');
272
+ console.log('✅ Cross-platform path tests passed');
273
+ }
274
+ finally {
275
+ // Cleanup
276
+ fs_1.default.rmSync(tempHomeDir, { recursive: true, force: true });
277
+ os_1.default.homedir = originalHomedir;
278
+ }
279
+ });
@@ -55,7 +55,7 @@ const token_validator_1 = require("../src/cli/setup/token-validator");
55
55
  (0, node_assert_1.default)(typeof ide.name === 'string', 'IDE should have name');
56
56
  (0, node_assert_1.default)(typeof ide.configPath === 'string', 'IDE should have configPath');
57
57
  (0, node_assert_1.default)(['json', 'toml'].includes(ide.configFormat), 'IDE should have valid configFormat');
58
- (0, node_assert_1.default)(['standard', 'kiro', 'codex', 'windsurf'].includes(ide.configType), 'IDE should have valid configType');
58
+ (0, node_assert_1.default)(['standard', 'kiro', 'codex', 'windsurf', 'claude'].includes(ide.configType), 'IDE should have valid configType');
59
59
  (0, node_assert_1.default)(typeof ide.detectMethod === 'function', 'IDE should have detectMethod');
60
60
  });
61
61
  });
@@ -0,0 +1,322 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ const node_test_1 = require("node:test");
40
+ const node_assert_1 = __importDefault(require("node:assert"));
41
+ const fs_1 = __importDefault(require("fs"));
42
+ const path_1 = __importDefault(require("path"));
43
+ const os_1 = __importDefault(require("os"));
44
+ // Test various setup scenarios without interactive prompts
45
+ (0, node_test_1.test)('Setup Scenarios - Fresh Installation', async () => {
46
+ const tempHomeDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-fresh-' + Date.now());
47
+ const originalHomedir = os_1.default.homedir;
48
+ os_1.default.homedir = () => tempHomeDir;
49
+ try {
50
+ // Test 1: No existing global config
51
+ const globalConfigPath = path_1.default.join(tempHomeDir, '.fraim', 'config.json');
52
+ // Verify no config exists initially
53
+ (0, node_assert_1.default)(!fs_1.default.existsSync(globalConfigPath), 'No global config should exist initially');
54
+ // Simulate what setup command would create
55
+ fs_1.default.mkdirSync(path_1.default.dirname(globalConfigPath), { recursive: true });
56
+ const newConfig = {
57
+ version: '2.0.27',
58
+ apiKey: 'fraim_fresh_install_key',
59
+ githubToken: 'ghp_fresh_install_token',
60
+ configuredAt: new Date().toISOString(),
61
+ userPreferences: {
62
+ autoSync: true,
63
+ backupConfigs: true
64
+ }
65
+ };
66
+ fs_1.default.writeFileSync(globalConfigPath, JSON.stringify(newConfig, null, 2));
67
+ // Verify config was created correctly
68
+ (0, node_assert_1.default)(fs_1.default.existsSync(globalConfigPath), 'Global config should be created');
69
+ const savedConfig = JSON.parse(fs_1.default.readFileSync(globalConfigPath, 'utf8'));
70
+ node_assert_1.default.strictEqual(savedConfig.apiKey, 'fraim_fresh_install_key', 'FRAIM key should be saved');
71
+ node_assert_1.default.strictEqual(savedConfig.githubToken, 'ghp_fresh_install_token', 'GitHub token should be saved');
72
+ (0, node_assert_1.default)(savedConfig.userPreferences, 'User preferences should be saved');
73
+ console.log('✅ Fresh installation scenario passed');
74
+ }
75
+ finally {
76
+ // Cleanup
77
+ fs_1.default.rmSync(tempHomeDir, { recursive: true, force: true });
78
+ os_1.default.homedir = originalHomedir;
79
+ }
80
+ });
81
+ (0, node_test_1.test)('Setup Scenarios - Existing Config Without GitHub Token', async () => {
82
+ const tempHomeDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-existing-' + Date.now());
83
+ const originalHomedir = os_1.default.homedir;
84
+ os_1.default.homedir = () => tempHomeDir;
85
+ try {
86
+ const globalConfigPath = path_1.default.join(tempHomeDir, '.fraim', 'config.json');
87
+ // Create existing config without GitHub token (simulates old version)
88
+ fs_1.default.mkdirSync(path_1.default.dirname(globalConfigPath), { recursive: true });
89
+ const oldConfig = {
90
+ version: '2.0.20',
91
+ apiKey: 'fraim_existing_key',
92
+ configuredAt: '2024-01-01T00:00:00.000Z',
93
+ userPreferences: {
94
+ autoSync: true,
95
+ backupConfigs: true
96
+ }
97
+ // No githubToken
98
+ };
99
+ fs_1.default.writeFileSync(globalConfigPath, JSON.stringify(oldConfig, null, 2));
100
+ // Test loadGlobalConfig behavior with missing GitHub token
101
+ const { loadGlobalConfig } = await Promise.resolve().then(() => __importStar(require('../src/cli/commands/add-ide')));
102
+ const result = loadGlobalConfig();
103
+ (0, node_assert_1.default)(result, 'Should load existing config');
104
+ node_assert_1.default.strictEqual(result.fraimKey, 'fraim_existing_key', 'Should preserve existing FRAIM key');
105
+ node_assert_1.default.strictEqual(result.githubToken, undefined, 'GitHub token should be undefined');
106
+ // Simulate adding GitHub token (what add-ide would do)
107
+ const updatedConfig = {
108
+ ...oldConfig,
109
+ githubToken: 'ghp_newly_added_token',
110
+ version: '2.0.27'
111
+ };
112
+ fs_1.default.writeFileSync(globalConfigPath, JSON.stringify(updatedConfig, null, 2));
113
+ // Verify token was added
114
+ const result2 = loadGlobalConfig();
115
+ (0, node_assert_1.default)(result2, 'Should load updated config');
116
+ node_assert_1.default.strictEqual(result2.fraimKey, 'fraim_existing_key', 'Should preserve existing FRAIM key');
117
+ node_assert_1.default.strictEqual(result2.githubToken, 'ghp_newly_added_token', 'Should have new GitHub token');
118
+ console.log('✅ Existing config without GitHub token scenario passed');
119
+ }
120
+ finally {
121
+ // Cleanup
122
+ fs_1.default.rmSync(tempHomeDir, { recursive: true, force: true });
123
+ os_1.default.homedir = originalHomedir;
124
+ }
125
+ });
126
+ (0, node_test_1.test)('Setup Scenarios - Corrupted Config Recovery', async () => {
127
+ const tempHomeDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-corrupted-' + Date.now());
128
+ const originalHomedir = os_1.default.homedir;
129
+ os_1.default.homedir = () => tempHomeDir;
130
+ try {
131
+ const globalConfigPath = path_1.default.join(tempHomeDir, '.fraim', 'config.json');
132
+ // Create corrupted config file
133
+ fs_1.default.mkdirSync(path_1.default.dirname(globalConfigPath), { recursive: true });
134
+ fs_1.default.writeFileSync(globalConfigPath, 'invalid json content {');
135
+ // Test loadGlobalConfig behavior with corrupted file
136
+ const { loadGlobalConfig } = await Promise.resolve().then(() => __importStar(require('../src/cli/commands/add-ide')));
137
+ const result = loadGlobalConfig();
138
+ node_assert_1.default.strictEqual(result, null, 'Should return null for corrupted config');
139
+ // Simulate recovery by creating new config
140
+ const newConfig = {
141
+ version: '2.0.27',
142
+ apiKey: 'fraim_recovered_key',
143
+ githubToken: 'ghp_recovered_token',
144
+ configuredAt: new Date().toISOString(),
145
+ userPreferences: {
146
+ autoSync: true,
147
+ backupConfigs: true
148
+ }
149
+ };
150
+ fs_1.default.writeFileSync(globalConfigPath, JSON.stringify(newConfig, null, 2));
151
+ // Verify recovery
152
+ const result2 = loadGlobalConfig();
153
+ (0, node_assert_1.default)(result2, 'Should load recovered config');
154
+ node_assert_1.default.strictEqual(result2.fraimKey, 'fraim_recovered_key', 'Should have recovered FRAIM key');
155
+ node_assert_1.default.strictEqual(result2.githubToken, 'ghp_recovered_token', 'Should have recovered GitHub token');
156
+ console.log('✅ Corrupted config recovery scenario passed');
157
+ }
158
+ finally {
159
+ // Cleanup
160
+ fs_1.default.rmSync(tempHomeDir, { recursive: true, force: true });
161
+ os_1.default.homedir = originalHomedir;
162
+ }
163
+ });
164
+ (0, node_test_1.test)('Setup Scenarios - Multiple Users Same Machine', async () => {
165
+ // Simulate multiple users on the same machine
166
+ const user1HomeDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-user1-' + Date.now());
167
+ const user2HomeDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-user2-' + Date.now());
168
+ const originalHomedir = os_1.default.homedir;
169
+ try {
170
+ // User 1 setup
171
+ os_1.default.homedir = () => user1HomeDir;
172
+ const user1ConfigPath = path_1.default.join(user1HomeDir, '.fraim', 'config.json');
173
+ fs_1.default.mkdirSync(path_1.default.dirname(user1ConfigPath), { recursive: true });
174
+ const user1Config = {
175
+ version: '2.0.27',
176
+ apiKey: 'fraim_user1_key',
177
+ githubToken: 'ghp_user1_token',
178
+ configuredAt: new Date().toISOString(),
179
+ userPreferences: {
180
+ autoSync: true,
181
+ backupConfigs: true
182
+ }
183
+ };
184
+ fs_1.default.writeFileSync(user1ConfigPath, JSON.stringify(user1Config, null, 2));
185
+ // User 2 setup
186
+ os_1.default.homedir = () => user2HomeDir;
187
+ const user2ConfigPath = path_1.default.join(user2HomeDir, '.fraim', 'config.json');
188
+ fs_1.default.mkdirSync(path_1.default.dirname(user2ConfigPath), { recursive: true });
189
+ const user2Config = {
190
+ version: '2.0.27',
191
+ apiKey: 'fraim_user2_key',
192
+ githubToken: 'ghp_user2_token',
193
+ configuredAt: new Date().toISOString(),
194
+ userPreferences: {
195
+ autoSync: false,
196
+ backupConfigs: false
197
+ }
198
+ };
199
+ fs_1.default.writeFileSync(user2ConfigPath, JSON.stringify(user2Config, null, 2));
200
+ // Verify both configs exist and are separate
201
+ (0, node_assert_1.default)(fs_1.default.existsSync(user1ConfigPath), 'User 1 config should exist');
202
+ (0, node_assert_1.default)(fs_1.default.existsSync(user2ConfigPath), 'User 2 config should exist');
203
+ const user1Data = JSON.parse(fs_1.default.readFileSync(user1ConfigPath, 'utf8'));
204
+ const user2Data = JSON.parse(fs_1.default.readFileSync(user2ConfigPath, 'utf8'));
205
+ // Verify they have different keys
206
+ node_assert_1.default.strictEqual(user1Data.apiKey, 'fraim_user1_key', 'User 1 should have their own key');
207
+ node_assert_1.default.strictEqual(user2Data.apiKey, 'fraim_user2_key', 'User 2 should have their own key');
208
+ node_assert_1.default.notStrictEqual(user1Data.apiKey, user2Data.apiKey, 'Users should have different keys');
209
+ // Verify they have different preferences
210
+ node_assert_1.default.strictEqual(user1Data.userPreferences.autoSync, true, 'User 1 preferences');
211
+ node_assert_1.default.strictEqual(user2Data.userPreferences.autoSync, false, 'User 2 preferences');
212
+ console.log('✅ Multiple users scenario passed');
213
+ }
214
+ finally {
215
+ // Cleanup
216
+ fs_1.default.rmSync(user1HomeDir, { recursive: true, force: true });
217
+ fs_1.default.rmSync(user2HomeDir, { recursive: true, force: true });
218
+ os_1.default.homedir = originalHomedir;
219
+ }
220
+ });
221
+ (0, node_test_1.test)('Setup Scenarios - Project Config Independence', async () => {
222
+ const tempHomeDir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-independence-home-' + Date.now());
223
+ const project1Dir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-project1-' + Date.now());
224
+ const project2Dir = path_1.default.join(os_1.default.tmpdir(), '.fraim-test-project2-' + Date.now());
225
+ const originalHomedir = os_1.default.homedir;
226
+ const originalCwd = process.cwd;
227
+ os_1.default.homedir = () => tempHomeDir;
228
+ try {
229
+ // Create global config
230
+ const globalConfigPath = path_1.default.join(tempHomeDir, '.fraim', 'config.json');
231
+ fs_1.default.mkdirSync(path_1.default.dirname(globalConfigPath), { recursive: true });
232
+ const globalConfig = {
233
+ version: '2.0.27',
234
+ apiKey: 'fraim_global_key',
235
+ githubToken: 'ghp_global_token',
236
+ configuredAt: new Date().toISOString(),
237
+ userPreferences: {
238
+ autoSync: true,
239
+ backupConfigs: true
240
+ }
241
+ };
242
+ fs_1.default.writeFileSync(globalConfigPath, JSON.stringify(globalConfig, null, 2));
243
+ // Create project 1 config
244
+ process.cwd = () => project1Dir;
245
+ const project1ConfigPath = path_1.default.join(project1Dir, '.fraim', 'config.json');
246
+ fs_1.default.mkdirSync(path_1.default.dirname(project1ConfigPath), { recursive: true });
247
+ const project1Config = {
248
+ version: '2.0.27',
249
+ project: {
250
+ name: 'project-one'
251
+ },
252
+ git: {
253
+ defaultBranch: 'main',
254
+ repoOwner: 'user',
255
+ repoName: 'project-one'
256
+ }
257
+ };
258
+ fs_1.default.writeFileSync(project1ConfigPath, JSON.stringify(project1Config, null, 2));
259
+ // Create project 2 config
260
+ process.cwd = () => project2Dir;
261
+ const project2ConfigPath = path_1.default.join(project2Dir, '.fraim', 'config.json');
262
+ fs_1.default.mkdirSync(path_1.default.dirname(project2ConfigPath), { recursive: true });
263
+ const project2Config = {
264
+ version: '2.0.27',
265
+ project: {
266
+ name: 'project-two'
267
+ },
268
+ git: {
269
+ defaultBranch: 'master',
270
+ repoOwner: 'user',
271
+ repoName: 'project-two'
272
+ }
273
+ };
274
+ fs_1.default.writeFileSync(project2ConfigPath, JSON.stringify(project2Config, null, 2));
275
+ // Verify all configs exist
276
+ (0, node_assert_1.default)(fs_1.default.existsSync(globalConfigPath), 'Global config should exist');
277
+ (0, node_assert_1.default)(fs_1.default.existsSync(project1ConfigPath), 'Project 1 config should exist');
278
+ (0, node_assert_1.default)(fs_1.default.existsSync(project2ConfigPath), 'Project 2 config should exist');
279
+ // Verify global config has secrets, projects don't
280
+ const globalData = JSON.parse(fs_1.default.readFileSync(globalConfigPath, 'utf8'));
281
+ const project1Data = JSON.parse(fs_1.default.readFileSync(project1ConfigPath, 'utf8'));
282
+ const project2Data = JSON.parse(fs_1.default.readFileSync(project2ConfigPath, 'utf8'));
283
+ // Global should have secrets
284
+ (0, node_assert_1.default)(globalData.apiKey, 'Global config should have API key');
285
+ (0, node_assert_1.default)(globalData.githubToken, 'Global config should have GitHub token');
286
+ // Projects should not have secrets
287
+ (0, node_assert_1.default)(!project1Data.apiKey, 'Project 1 should not have API key');
288
+ (0, node_assert_1.default)(!project1Data.githubToken, 'Project 1 should not have GitHub token');
289
+ (0, node_assert_1.default)(!project2Data.apiKey, 'Project 2 should not have API key');
290
+ (0, node_assert_1.default)(!project2Data.githubToken, 'Project 2 should not have GitHub token');
291
+ // Projects should have different settings
292
+ node_assert_1.default.strictEqual(project1Data.project.name, 'project-one', 'Project 1 name');
293
+ node_assert_1.default.strictEqual(project2Data.project.name, 'project-two', 'Project 2 name');
294
+ node_assert_1.default.strictEqual(project1Data.git.defaultBranch, 'main', 'Project 1 branch');
295
+ node_assert_1.default.strictEqual(project2Data.git.defaultBranch, 'master', 'Project 2 branch');
296
+ console.log('✅ Project config independence scenario passed');
297
+ }
298
+ finally {
299
+ // Cleanup
300
+ fs_1.default.rmSync(tempHomeDir, { recursive: true, force: true });
301
+ fs_1.default.rmSync(project1Dir, { recursive: true, force: true });
302
+ fs_1.default.rmSync(project2Dir, { recursive: true, force: true });
303
+ os_1.default.homedir = originalHomedir;
304
+ process.cwd = originalCwd;
305
+ }
306
+ });
307
+ (0, node_test_1.test)('Setup Scenarios - Token Validation Edge Cases', async () => {
308
+ // Test various token format validations
309
+ const { isValidTokenFormat } = await Promise.resolve().then(() => __importStar(require('../src/cli/setup/token-validator')));
310
+ // Test FRAIM key validation
311
+ (0, node_assert_1.default)(isValidTokenFormat('fraim_valid_key_123', 'fraim'), 'Valid FRAIM key should pass');
312
+ (0, node_assert_1.default)(!isValidTokenFormat('invalid_key', 'fraim'), 'Invalid FRAIM key should fail');
313
+ (0, node_assert_1.default)(!isValidTokenFormat('', 'fraim'), 'Empty FRAIM key should fail');
314
+ (0, node_assert_1.default)(!isValidTokenFormat('github_pat_123', 'fraim'), 'GitHub token as FRAIM key should fail');
315
+ // Test GitHub token validation
316
+ (0, node_assert_1.default)(isValidTokenFormat('ghp_valid_token_123', 'github'), 'Valid GitHub classic token should pass');
317
+ (0, node_assert_1.default)(isValidTokenFormat('github_pat_valid_token_123', 'github'), 'Valid GitHub PAT should pass');
318
+ (0, node_assert_1.default)(!isValidTokenFormat('invalid_token', 'github'), 'Invalid GitHub token should fail');
319
+ (0, node_assert_1.default)(!isValidTokenFormat('', 'github'), 'Empty GitHub token should fail');
320
+ (0, node_assert_1.default)(!isValidTokenFormat('fraim_123', 'github'), 'FRAIM key as GitHub token should fail');
321
+ console.log('✅ Token validation edge cases passed');
322
+ });