sinapse-ai 1.9.0 → 1.9.1

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.
Files changed (88) hide show
  1. package/.claude/rules/mandatory-delegation.md +1 -1
  2. package/.codex/delegation-matrix.json +4 -3
  3. package/.codex/delegation-parity.json +4 -3
  4. package/.codex/instructions.md +2 -2
  5. package/.sinapse-ai/constitution.md +2 -2
  6. package/.sinapse-ai/core/doctor/checks/git-hooks.js +76 -10
  7. package/.sinapse-ai/core/execution/subagent-dispatcher.js +1 -1
  8. package/.sinapse-ai/core/synapse/engine.js +15 -0
  9. package/.sinapse-ai/data/entity-registry.yaml +13 -13
  10. package/.sinapse-ai/development/agents/snps-orqx.md +4 -4
  11. package/.sinapse-ai/git-hooks/lib/secret-scanner-core.js +76 -4
  12. package/.sinapse-ai/git-hooks/pre-push +7 -1
  13. package/.sinapse-ai/install-manifest.yaml +9 -9
  14. package/AGENTS.md +2 -2
  15. package/CHANGELOG.md +1247 -0
  16. package/bin/commands/uninstall.js +2 -2
  17. package/bin/utils/secret-scanner-core.js +76 -4
  18. package/docs/agent-reference-guide.md +1 -1
  19. package/docs/framework/architecture-overview.md +4 -4
  20. package/docs/framework/guiding-principles.md +9 -9
  21. package/docs/getting-started.md +1 -1
  22. package/docs/guides/agent-reference.md +1 -1
  23. package/docs/guides/codex-config.md +4 -5
  24. package/docs/pt/architecture/sub-orqx-pattern.md +20 -18
  25. package/package.json +8 -2
  26. package/packages/installer/src/installer/git-hooks-installer.js +3 -1
  27. package/packages/installer/src/wizard/ide-config-generator.js +9 -1
  28. package/packages/installer/src/wizard/index.js +3 -4
  29. package/scripts/regenerate-orqx-stubs.ps1 +0 -1
  30. package/scripts/sync-counts.js +10 -2
  31. package/scripts/sync-squad-yaml-components.js +108 -6
  32. package/scripts/validate-squad-orqx.js +19 -9
  33. package/sinapse/agents/sinapse-orqx.md +4 -4
  34. package/sinapse/agents/snps-orqx.md +4 -4
  35. package/sinapse/knowledge-base/routing-catalog.md +1 -1
  36. package/sinapse/tasks/diagnose-and-route.md +1 -1
  37. package/sinapse/tasks/squad-status-report.md +1 -1
  38. package/squads/claude-code-mastery/agents/claude-mastery-chief.md +1 -1
  39. package/squads/claude-code-mastery/agents/hooks-architect.md +60 -68
  40. package/squads/claude-code-mastery/knowledge-base/swarm-orchestration-patterns.md +1 -1
  41. package/squads/claude-code-mastery/tasks/audit-setup.md +1 -1
  42. package/squads/claude-code-mastery/workflows/optimization-cycle.yaml +4 -4
  43. package/squads/claude-code-mastery/workflows/project-setup-cycle.yaml +4 -4
  44. package/squads/squad-animations/README.md +1 -1
  45. package/squads/squad-cloning/README.md +1 -1
  46. package/squads/squad-commercial/README.md +1 -1
  47. package/squads/squad-content/README.md +1 -1
  48. package/squads/squad-copy/README.md +1 -1
  49. package/squads/squad-council/README.md +1 -1
  50. package/squads/squad-courses/README.md +1 -1
  51. package/squads/squad-cybersecurity/README.md +1 -1
  52. package/squads/squad-design/README.md +1 -1
  53. package/squads/squad-finance/README.md +1 -1
  54. package/squads/squad-growth/README.md +1 -1
  55. package/squads/squad-paidmedia/README.md +1 -1
  56. package/squads/squad-product/README.md +1 -1
  57. package/squads/squad-research/README.md +1 -1
  58. package/squads/squad-storytelling/README.md +1 -1
  59. package/.sinapse-ai/core/memory/__tests__/active-modules.verify.js +0 -265
  60. package/.sinapse-ai/core/permissions/__tests__/permission-mode.test.js +0 -293
  61. package/.sinapse-ai/infrastructure/tests/project-status-loader.test.js +0 -569
  62. package/.sinapse-ai/infrastructure/tests/regression-suite-v2.md +0 -622
  63. package/.sinapse-ai/infrastructure/tests/validate-module.js +0 -98
  64. package/.sinapse-ai/infrastructure/tests/worktree-manager.test.js +0 -620
  65. package/.sinapse-ai/workflow-intelligence/__tests__/confidence-scorer.test.js +0 -335
  66. package/.sinapse-ai/workflow-intelligence/__tests__/integration.test.js +0 -340
  67. package/.sinapse-ai/workflow-intelligence/__tests__/suggestion-engine.test.js +0 -438
  68. package/.sinapse-ai/workflow-intelligence/__tests__/wave-analyzer.test.js +0 -448
  69. package/.sinapse-ai/workflow-intelligence/__tests__/workflow-registry.test.js +0 -303
  70. package/packages/installer/src/__tests__/performance-benchmark.js +0 -383
  71. package/packages/installer/tests/integration/environment-configuration.test.js +0 -332
  72. package/packages/installer/tests/integration/wizard-detection.test.js +0 -352
  73. package/packages/installer/tests/unit/artifact-copy-pipeline/artifact-copy-pipeline.test.js +0 -402
  74. package/packages/installer/tests/unit/claude-md-template-v5/claude-md-template-v5.test.js +0 -193
  75. package/packages/installer/tests/unit/config-validator.test.js +0 -315
  76. package/packages/installer/tests/unit/detection/detect-project-type.test.js +0 -539
  77. package/packages/installer/tests/unit/doctor/doctor-checks.test.js +0 -675
  78. package/packages/installer/tests/unit/doctor/doctor-orchestrator.test.js +0 -192
  79. package/packages/installer/tests/unit/entity-registry-bootstrap.test.js +0 -192
  80. package/packages/installer/tests/unit/env-template.test.js +0 -187
  81. package/packages/installer/tests/unit/generate-settings-json/generate-settings-json.test.js +0 -310
  82. package/packages/installer/tests/unit/git-hooks-installer.test.js +0 -262
  83. package/packages/installer/tests/unit/ide-sync-integration/ide-sync-integration.test.js +0 -231
  84. package/packages/installer/tests/unit/merger/env-merger.test.js +0 -191
  85. package/packages/installer/tests/unit/merger/markdown-merger.test.js +0 -262
  86. package/packages/installer/tests/unit/merger/strategies.test.js +0 -154
  87. package/packages/installer/tests/unit/merger/yaml-merger.test.js +0 -328
  88. package/packages/sinapse-install/tests/unit/chrome-brain.smoke.test.js +0 -66
@@ -1,332 +0,0 @@
1
- /**
2
- * Integration Tests: Environment Configuration
3
- * Story 1.6: Environment Configuration
4
- *
5
- * Tests for configure-environment.js with file system operations
6
- */
7
-
8
- const fs = require('fs-extra');
9
- const path = require('path');
10
- const os = require('os');
11
- const { configureEnvironment, updateGitignore } = require('../../src/config/configure-environment');
12
-
13
- /**
14
- * Cleanup helper with retry logic for flaky file system operations
15
- * Handles ENOTEMPTY and EBUSY errors common in CI environments
16
- * @param {string} dir - Directory to remove
17
- * @param {number} maxRetries - Maximum retry attempts
18
- * @param {number} retryDelay - Delay between retries in ms
19
- */
20
- async function cleanupWithRetry(dir, maxRetries = 5, retryDelay = 100) {
21
- for (let attempt = 1; attempt <= maxRetries; attempt++) {
22
- try {
23
- if (await fs.pathExists(dir)) {
24
- await fs.remove(dir);
25
- }
26
- return;
27
- } catch (error) {
28
- const isRetryable = error.code && ['ENOTEMPTY', 'EBUSY', 'EPERM', 'EACCES'].includes(error.code);
29
- if (attempt === maxRetries || !isRetryable) {
30
- // Last attempt failed or non-retryable error, log but don't throw
31
- console.warn(`Warning: Failed to cleanup ${dir} after ${attempt} attempts:`, error.code);
32
- return;
33
- }
34
- // Linear backoff (100ms, 200ms, 300ms...)
35
- await new Promise(resolve => setTimeout(resolve, retryDelay * attempt));
36
- }
37
- }
38
- }
39
-
40
- describe('Environment Configuration Integration', () => {
41
- let testDir;
42
- let testId;
43
-
44
- beforeEach(async () => {
45
- // Create unique temporary test directory with random suffix to avoid collisions
46
- testId = `${Date.now()}-${Math.random().toString(36).substring(2, 8)}`;
47
- testDir = path.join(os.tmpdir(), `sinapse-env-test-${testId}`);
48
- await fs.ensureDir(testDir);
49
- });
50
-
51
- afterEach(async () => {
52
- // Small delay to allow file handles to close
53
- await new Promise(resolve => setTimeout(resolve, 50));
54
- // Cleanup test directory with retry logic
55
- await cleanupWithRetry(testDir);
56
- });
57
-
58
- describe('configureEnvironment', () => {
59
- it('should create .env file with skip prompts', async () => {
60
- const result = await configureEnvironment({
61
- targetDir: testDir,
62
- skipPrompts: true,
63
- projectType: 'GREENFIELD',
64
- selectedIDEs: ['vscode'],
65
- mcpServers: [],
66
- });
67
-
68
- expect(result.envCreated).toBe(true);
69
-
70
- const envPath = path.join(testDir, '.env');
71
- expect(await fs.pathExists(envPath)).toBe(true);
72
-
73
- const content = await fs.readFile(envPath, 'utf8');
74
- expect(content).toContain('NODE_ENV=development');
75
- // Version-agnostic: check SINAPSE_VERSION exists with valid semver format
76
- expect(content).toMatch(/SINAPSE_VERSION=\d+\.\d+\.\d+/);
77
- });
78
-
79
- it('should create .env.example file', async () => {
80
- const result = await configureEnvironment({
81
- targetDir: testDir,
82
- skipPrompts: true,
83
- });
84
-
85
- expect(result.envExampleCreated).toBe(true);
86
-
87
- const envExamplePath = path.join(testDir, '.env.example');
88
- expect(await fs.pathExists(envExamplePath)).toBe(true);
89
-
90
- const content = await fs.readFile(envExamplePath, 'utf8');
91
- expect(content).toContain('OPENAI_API_KEY=');
92
- expect(content).not.toMatch(/sk-[a-zA-Z0-9]{20,}/);
93
- });
94
-
95
- it('should create core-config.yaml', async () => {
96
- const result = await configureEnvironment({
97
- targetDir: testDir,
98
- skipPrompts: true,
99
- projectType: 'BROWNFIELD',
100
- selectedIDEs: ['vscode', 'cursor'],
101
- mcpServers: [{ name: 'github' }, { name: 'exa' }],
102
- });
103
-
104
- expect(result.coreConfigCreated).toBe(true);
105
-
106
- const configPath = path.join(testDir, '.sinapse-ai', 'core-config.yaml');
107
- expect(await fs.pathExists(configPath)).toBe(true);
108
-
109
- const content = await fs.readFile(configPath, 'utf8');
110
- expect(content).toContain('type: BROWNFIELD');
111
- expect(content).toContain('- vscode');
112
- expect(content).toContain('- cursor');
113
- expect(content).toContain('- github');
114
- expect(content).toContain('- exa');
115
- });
116
-
117
- it('should update .gitignore', async () => {
118
- const result = await configureEnvironment({
119
- targetDir: testDir,
120
- skipPrompts: true,
121
- });
122
-
123
- expect(result.gitignoreUpdated).toBe(true);
124
-
125
- const gitignorePath = path.join(testDir, '.gitignore');
126
- expect(await fs.pathExists(gitignorePath)).toBe(true);
127
-
128
- const content = await fs.readFile(gitignorePath, 'utf8');
129
- expect(content).toContain('.env');
130
- });
131
-
132
- it('should set .env file permissions on Unix', async () => {
133
- if (process.platform === 'win32') {
134
- // Skip on Windows
135
- return;
136
- }
137
-
138
- await configureEnvironment({
139
- targetDir: testDir,
140
- skipPrompts: true,
141
- });
142
-
143
- const envPath = path.join(testDir, '.env');
144
- const stats = await fs.stat(envPath);
145
-
146
- // Check permissions are 0600 (owner read/write only)
147
- const mode = stats.mode & 0o777;
148
- expect(mode).toBe(0o600);
149
- });
150
-
151
- it('should preserve existing .env values via merge (Story 10.38)', async () => {
152
- // Create existing .env with a user-defined value
153
- const envPath = path.join(testDir, '.env');
154
- await fs.writeFile(envPath, 'EXISTING_KEY=existing_value', 'utf8');
155
-
156
- // Story 10.38: merge-only policy — existing values are ALWAYS preserved.
157
- await configureEnvironment({
158
- targetDir: testDir,
159
- skipPrompts: true,
160
- });
161
-
162
- const content = await fs.readFile(envPath, 'utf8');
163
- // User value is preserved
164
- expect(content).toContain('EXISTING_KEY=existing_value');
165
- // SINAPSE variables are added
166
- expect(content).toMatch(/OPENROUTER_API_KEY|ANTHROPIC_API_KEY|OPENAI_API_KEY/);
167
- });
168
-
169
- it('should handle errors gracefully', async () => {
170
- // Try to write to a read-only directory (simulate permission error)
171
- const readOnlyDir = path.join(testDir, 'readonly');
172
- await fs.ensureDir(readOnlyDir);
173
-
174
- // Note: This test is platform-dependent and may not work on all systems
175
- // Just verify the function handles errors
176
- try {
177
- await configureEnvironment({
178
- targetDir: '/invalid/path/that/does/not/exist',
179
- skipPrompts: true,
180
- });
181
- fail('Should have thrown an error');
182
- } catch (error) {
183
- expect(error).toBeDefined();
184
- }
185
- });
186
- });
187
-
188
- describe('updateGitignore', () => {
189
- it('should create .gitignore if not exists', async () => {
190
- await updateGitignore(testDir);
191
-
192
- const gitignorePath = path.join(testDir, '.gitignore');
193
- expect(await fs.pathExists(gitignorePath)).toBe(true);
194
-
195
- const content = await fs.readFile(gitignorePath, 'utf8');
196
- expect(content).toContain('.env');
197
- });
198
-
199
- it('should append to existing .gitignore', async () => {
200
- const gitignorePath = path.join(testDir, '.gitignore');
201
- await fs.writeFile(gitignorePath, 'node_modules\n*.log\n', 'utf8');
202
-
203
- await updateGitignore(testDir);
204
-
205
- const content = await fs.readFile(gitignorePath, 'utf8');
206
- expect(content).toContain('node_modules');
207
- expect(content).toContain('*.log');
208
- expect(content).toContain('.env');
209
- });
210
-
211
- it('should not duplicate .env entry', async () => {
212
- const gitignorePath = path.join(testDir, '.gitignore');
213
- await fs.writeFile(gitignorePath, '.env\n', 'utf8');
214
-
215
- await updateGitignore(testDir);
216
-
217
- const content = await fs.readFile(gitignorePath, 'utf8');
218
- const lines = content.split('\n').filter(line => line.trim() === '.env' || line.trim() === '/.env');
219
- expect(lines.length).toBe(1);
220
- });
221
-
222
- it('should recognize existing .env entry with slash', async () => {
223
- const gitignorePath = path.join(testDir, '.gitignore');
224
- await fs.writeFile(gitignorePath, '/.env\n', 'utf8');
225
-
226
- await updateGitignore(testDir);
227
-
228
- const content = await fs.readFile(gitignorePath, 'utf8');
229
- const lines = content.split('\n').filter(line => line.trim() === '.env' || line.trim() === '/.env');
230
- expect(lines.length).toBe(1);
231
- });
232
- });
233
-
234
- describe('Wizard Integration', () => {
235
- it('should integrate with wizard state from previous stories', async () => {
236
- // Simulate wizard state from Stories 1.3, 1.4, 1.5
237
- const wizardState = {
238
- projectType: 'GREENFIELD',
239
- selectedIDEs: ['vscode', 'cursor'],
240
- mcpServers: [
241
- { name: 'github', id: 'github' },
242
- { name: 'exa', id: 'exa' },
243
- ],
244
- };
245
-
246
- const result = await configureEnvironment({
247
- targetDir: testDir,
248
- skipPrompts: true,
249
- ...wizardState,
250
- });
251
-
252
- // Verify all files created
253
- expect(result.envCreated).toBe(true);
254
- expect(result.coreConfigCreated).toBe(true);
255
- expect(result.gitignoreUpdated).toBe(true);
256
-
257
- // Verify core-config includes wizard state
258
- const configPath = path.join(testDir, '.sinapse-ai', 'core-config.yaml');
259
- const configContent = await fs.readFile(configPath, 'utf8');
260
-
261
- expect(configContent).toContain('GREENFIELD');
262
- expect(configContent).toContain('vscode');
263
- expect(configContent).toContain('cursor');
264
- expect(configContent).toContain('github');
265
- expect(configContent).toContain('exa');
266
- });
267
- });
268
-
269
- describe('Cross-Platform Compatibility', () => {
270
- it('should handle Windows paths', async () => {
271
- const result = await configureEnvironment({
272
- targetDir: testDir,
273
- skipPrompts: true,
274
- });
275
-
276
- expect(result.envCreated).toBe(true);
277
- expect(result.coreConfigCreated).toBe(true);
278
- });
279
-
280
- it('should create valid YAML on all platforms', async () => {
281
- await configureEnvironment({
282
- targetDir: testDir,
283
- skipPrompts: true,
284
- projectType: 'GREENFIELD',
285
- });
286
-
287
- const yaml = require('js-yaml');
288
- const configPath = path.join(testDir, '.sinapse-ai', 'core-config.yaml');
289
- const content = await fs.readFile(configPath, 'utf8');
290
-
291
- // Should parse without errors
292
- const parsed = yaml.load(content);
293
- expect(parsed).toBeDefined();
294
- expect(parsed.project.type).toBe('GREENFIELD');
295
- });
296
- });
297
-
298
- describe('File Structure', () => {
299
- it('should create correct directory structure', async () => {
300
- await configureEnvironment({
301
- targetDir: testDir,
302
- skipPrompts: true,
303
- });
304
-
305
- // Check all expected files exist
306
- const expectedFiles = [
307
- '.env',
308
- '.env.example',
309
- '.gitignore',
310
- '.sinapse-ai/core-config.yaml',
311
- ];
312
-
313
- for (const file of expectedFiles) {
314
- const filePath = path.join(testDir, file);
315
- expect(await fs.pathExists(filePath)).toBe(true);
316
- }
317
- });
318
-
319
- it('should create .sinapse-ai directory if missing', async () => {
320
- const sinapsecoreDir = path.join(testDir, '.sinapse-ai');
321
- expect(await fs.pathExists(sinapsecoreDir)).toBe(false);
322
-
323
- await configureEnvironment({
324
- targetDir: testDir,
325
- skipPrompts: true,
326
- });
327
-
328
- expect(await fs.pathExists(sinapsecoreDir)).toBe(true);
329
- });
330
- });
331
- });
332
-
@@ -1,352 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { runWizard, getProjectType, confirmProjectType } = require('../../src/wizard/wizard');
4
- const { detectProjectType } = require('../../src/detection/detect-project-type');
5
-
6
- // Mock fs module
7
- jest.mock('fs');
8
-
9
- // Mock console methods to avoid test output pollution
10
- global.console = {
11
- ...console,
12
- log: jest.fn(),
13
- error: jest.fn(),
14
- };
15
-
16
- describe('Wizard Integration with Project Type Detection', () => {
17
- beforeEach(() => {
18
- jest.clearAllMocks();
19
- });
20
-
21
- // ============================================================================
22
- // Task 1.3.5.2: Test full wizard flow with GREENFIELD detection
23
- // ============================================================================
24
- describe('GREENFIELD Detection Flow', () => {
25
- test('wizard correctly detects and processes GREENFIELD project', async () => {
26
- // Setup: Empty directory (directory exists but no markers)
27
- const targetPath = path.resolve('/test-greenfield');
28
- fs.existsSync.mockImplementation((checkPath) => {
29
- if (checkPath === targetPath) return true; // Directory exists
30
- // No markers exist
31
- if (checkPath.includes('.sinapse-ai')) return false;
32
- if (checkPath.includes('package.json')) return false;
33
- if (checkPath.includes('.git')) return false;
34
- return false;
35
- });
36
- fs.readdirSync.mockReturnValue([]);
37
-
38
- const result = await runWizard({ targetDir: '/test-greenfield' });
39
-
40
- expect(result.projectType).toBe('GREENFIELD');
41
- expect(result.targetDir).toBe('/test-greenfield');
42
- // Output uses lowercase format for display
43
- expect(console.log).toHaveBeenCalledWith(expect.stringContaining('greenfield'));
44
- });
45
-
46
- test('getProjectType helper returns GREENFIELD for empty directory', () => {
47
- const targetPath = path.resolve('/test/empty');
48
- fs.existsSync.mockImplementation((checkPath) => {
49
- if (checkPath === targetPath) return true;
50
- if (checkPath.includes('.sinapse-ai')) return false;
51
- if (checkPath.includes('package.json')) return false;
52
- if (checkPath.includes('.git')) return false;
53
- return false;
54
- });
55
- fs.readdirSync.mockReturnValue([]);
56
-
57
- const type = getProjectType('/test/empty');
58
-
59
- expect(type).toBe('GREENFIELD');
60
- });
61
- });
62
-
63
- // ============================================================================
64
- // Task 1.3.5.3: Test full wizard flow with BROWNFIELD detection
65
- // ============================================================================
66
- describe('BROWNFIELD Detection Flow', () => {
67
- test('wizard correctly detects and processes BROWNFIELD project with package.json', async () => {
68
- // Setup: Directory with package.json
69
- const targetPath = path.resolve('/test-brownfield');
70
- fs.existsSync.mockImplementation((checkPath) => {
71
- if (checkPath === targetPath) return true;
72
- if (checkPath.includes('.sinapse-ai')) return false; // No SINAPSE
73
- if (checkPath.includes('package.json')) return true; // Has package.json
74
- if (checkPath.includes('.git')) return false;
75
- return false;
76
- });
77
- fs.readdirSync.mockReturnValue(['package.json', 'src', 'README.md']);
78
-
79
- const result = await runWizard({ targetDir: '/test-brownfield' });
80
-
81
- expect(result.projectType).toBe('BROWNFIELD');
82
- expect(result.targetDir).toBe('/test-brownfield');
83
- expect(console.log).toHaveBeenCalledWith(expect.stringContaining('brownfield'));
84
- });
85
-
86
- test('wizard correctly detects and processes BROWNFIELD project with .git', async () => {
87
- // Setup: Directory with .git
88
- const targetPath = path.resolve('/test-git');
89
- fs.existsSync.mockImplementation((checkPath) => {
90
- if (checkPath === targetPath) return true;
91
- if (checkPath.includes('.sinapse-ai')) return false; // No SINAPSE
92
- if (checkPath.includes('package.json')) return false;
93
- if (checkPath.includes('.git')) return true; // Has .git
94
- return false;
95
- });
96
- fs.readdirSync.mockReturnValue(['.git', 'README.md']);
97
-
98
- const result = await runWizard({ targetDir: '/test-git' });
99
-
100
- expect(result.projectType).toBe('BROWNFIELD');
101
- expect(console.log).toHaveBeenCalledWith(expect.stringContaining('brownfield'));
102
- });
103
-
104
- test('getProjectType helper returns BROWNFIELD for existing project', () => {
105
- const targetPath = path.resolve('/test/brownfield');
106
- fs.existsSync.mockImplementation((checkPath) => {
107
- if (checkPath === targetPath) return true;
108
- if (checkPath.includes('.sinapse-ai')) return false;
109
- if (checkPath.includes('package.json')) return true;
110
- if (checkPath.includes('.git')) return false;
111
- return false;
112
- });
113
- fs.readdirSync.mockReturnValue(['package.json', 'src']);
114
-
115
- const type = getProjectType('/test/brownfield');
116
-
117
- expect(type).toBe('BROWNFIELD');
118
- });
119
- });
120
-
121
- // ============================================================================
122
- // Task 1.3.5.4: Test full wizard flow with EXISTING_SINAPSE detection
123
- // ============================================================================
124
- describe('EXISTING_SINAPSE Detection Flow', () => {
125
- test('wizard correctly detects and processes EXISTING_SINAPSE installation', async () => {
126
- // Setup: Directory with .sinapse-ai
127
- fs.existsSync.mockImplementation((checkPath) => {
128
- if (checkPath.includes('test-existing')) return true;
129
- if (checkPath.endsWith('.sinapse-ai')) return true;
130
- return true; // Other files exist
131
- });
132
- fs.readdirSync.mockReturnValue(['.sinapse-ai', 'package.json', '.git']);
133
-
134
- const result = await runWizard({ targetDir: '/test-existing' });
135
-
136
- expect(result.projectType).toBe('EXISTING_SINAPSE');
137
- expect(result.targetDir).toBe('/test-existing');
138
- // Output shows "brownfield" since EXISTING_SINAPSE is treated as brownfield update
139
- expect(console.log).toHaveBeenCalledWith(expect.stringContaining('brownfield'));
140
- });
141
-
142
- test('confirmProjectType shows update/reinstall message for EXISTING_SINAPSE', async () => {
143
- const confirmed = await confirmProjectType('EXISTING_SINAPSE');
144
-
145
- expect(confirmed).toBe('EXISTING_SINAPSE');
146
- expect(console.log).toHaveBeenCalledWith(
147
- expect.stringContaining('update or reinstall'),
148
- );
149
- });
150
-
151
- test('getProjectType helper returns EXISTING_SINAPSE when .sinapse-ai exists', () => {
152
- fs.existsSync.mockImplementation((checkPath) => {
153
- if (checkPath.includes('existing')) return true;
154
- if (checkPath.endsWith('.sinapse-ai')) return true;
155
- return false;
156
- });
157
- fs.readdirSync.mockReturnValue(['.sinapse-ai']);
158
-
159
- const type = getProjectType('/test/existing');
160
-
161
- expect(type).toBe('EXISTING_SINAPSE');
162
- });
163
- });
164
-
165
- // ============================================================================
166
- // Task 1.3.5.5: Test user override of detection result
167
- // ============================================================================
168
- describe('User Override Functionality', () => {
169
- test('confirmProjectType accepts detected type', async () => {
170
- const confirmed = await confirmProjectType('GREENFIELD');
171
-
172
- expect(confirmed).toBe('GREENFIELD');
173
- expect(console.log).toHaveBeenCalledWith(expect.stringContaining('GREENFIELD'));
174
- });
175
-
176
- test('confirmProjectType shows appropriate message for each type', async () => {
177
- const types = ['GREENFIELD', 'BROWNFIELD', 'EXISTING_SINAPSE', 'UNKNOWN'];
178
-
179
- for (const type of types) {
180
- jest.clearAllMocks();
181
- const confirmed = await confirmProjectType(type);
182
-
183
- expect(confirmed).toBe(type);
184
- expect(console.log).toHaveBeenCalledWith(expect.stringContaining(type));
185
- }
186
- });
187
-
188
- test('confirmProjectType provides description for GREENFIELD', async () => {
189
- await confirmProjectType('GREENFIELD');
190
-
191
- expect(console.log).toHaveBeenCalledWith(
192
- expect.stringContaining('New project'),
193
- );
194
- });
195
-
196
- test('confirmProjectType provides description for BROWNFIELD', async () => {
197
- await confirmProjectType('BROWNFIELD');
198
-
199
- expect(console.log).toHaveBeenCalledWith(
200
- expect.stringContaining('Existing project'),
201
- );
202
- });
203
- });
204
-
205
- // ============================================================================
206
- // Task 1.3.5.6: Test error handling and fallback to manual selection
207
- // ============================================================================
208
- describe('Error Handling in Wizard Flow', () => {
209
- test('wizard propagates detection errors correctly', async () => {
210
- // Setup: Invalid directory
211
- fs.existsSync.mockImplementation((checkPath) => {
212
- if (checkPath.includes('invalid')) return false;
213
- return false;
214
- });
215
-
216
- await expect(runWizard({ targetDir: '/invalid' })).rejects.toThrow(
217
- 'Directory does not exist',
218
- );
219
- });
220
-
221
- test('wizard logs error message on detection failure', async () => {
222
- // Setup: Permission error
223
- fs.existsSync.mockImplementation(() => {
224
- throw new Error('EACCES: permission denied');
225
- });
226
-
227
- await expect(runWizard({ targetDir: '/denied' })).rejects.toThrow();
228
- // Check that console.error was called with the error message
229
- const errorCalls = console.error.mock.calls;
230
- const hasInstallationFailed = errorCalls.some(call =>
231
- call.some(arg => String(arg).includes('Installation failed')),
232
- );
233
- expect(hasInstallationFailed).toBe(true);
234
- });
235
-
236
- test('confirmProjectType handles UNKNOWN type gracefully', async () => {
237
- const confirmed = await confirmProjectType('UNKNOWN');
238
-
239
- expect(confirmed).toBe('UNKNOWN');
240
- expect(console.log).toHaveBeenCalledWith(
241
- expect.stringContaining('Manual selection required'),
242
- );
243
- });
244
- });
245
-
246
- // ============================================================================
247
- // Task 1.3.5.7: Verify detection result flows correctly to Story 1.4
248
- // ============================================================================
249
- describe('Integration with Downstream Stories', () => {
250
- test('wizard returns configuration object with projectType for downstream use', async () => {
251
- const targetPath = path.resolve('/test/downstream');
252
- fs.existsSync.mockImplementation((checkPath) => {
253
- if (checkPath === targetPath) return true;
254
- if (checkPath.includes('.sinapse-ai')) return false;
255
- if (checkPath.includes('package.json')) return false;
256
- if (checkPath.includes('.git')) return false;
257
- return false;
258
- });
259
- fs.readdirSync.mockReturnValue([]);
260
-
261
- const config = await runWizard({ targetDir: '/test/downstream' });
262
-
263
- // Verify config has required fields for downstream stories
264
- expect(config).toHaveProperty('projectType');
265
- expect(config).toHaveProperty('targetDir');
266
- expect(config.projectType).toBe('GREENFIELD');
267
- expect(config.targetDir).toBe('/test/downstream');
268
- });
269
-
270
- test('getProjectType can be called independently by downstream stories', () => {
271
- const targetPath = path.resolve('/test/standalone');
272
- fs.existsSync.mockImplementation((checkPath) => {
273
- if (checkPath === targetPath) return true;
274
- if (checkPath.includes('.sinapse-ai')) return false;
275
- if (checkPath.includes('package.json')) return false;
276
- if (checkPath.includes('.git')) return false;
277
- return false;
278
- });
279
- fs.readdirSync.mockReturnValue([]);
280
-
281
- // Story 1.4 (IDE Selection) can call this directly
282
- const type = getProjectType('/test/standalone');
283
-
284
- expect(type).toBe('GREENFIELD');
285
- expect(typeof type).toBe('string');
286
- });
287
-
288
- test('detection result remains consistent across multiple calls', () => {
289
- const targetPath = path.resolve('/test/consistent');
290
- fs.existsSync.mockImplementation((checkPath) => {
291
- if (checkPath === targetPath) return true;
292
- if (checkPath.includes('.sinapse-ai')) return false;
293
- if (checkPath.includes('package.json')) return true;
294
- if (checkPath.includes('.git')) return false;
295
- return false;
296
- });
297
- fs.readdirSync.mockReturnValue(['package.json']);
298
-
299
- const type1 = getProjectType('/test/consistent');
300
- const type2 = getProjectType('/test/consistent');
301
- const type3 = detectProjectType('/test/consistent');
302
-
303
- expect(type1).toBe(type2);
304
- expect(type2).toBe(type3);
305
- expect(type1).toBe('BROWNFIELD');
306
- });
307
- });
308
-
309
- // ============================================================================
310
- // Default Behavior Tests
311
- // ============================================================================
312
- describe('Default Wizard Behavior', () => {
313
- test('wizard uses process.cwd() when no targetDir provided', async () => {
314
- const mockCwd = process.cwd();
315
-
316
- fs.existsSync.mockImplementation((checkPath) => {
317
- if (checkPath === path.resolve(mockCwd)) return true;
318
- return false;
319
- });
320
- fs.readdirSync.mockReturnValue([]);
321
-
322
- const result = await runWizard();
323
-
324
- expect(result.targetDir).toBe(mockCwd);
325
- expect(result.projectType).toBe('GREENFIELD');
326
- });
327
-
328
- test('wizard displays welcome message', async () => {
329
- fs.existsSync.mockImplementation(() => true);
330
- fs.readdirSync.mockReturnValue([]);
331
-
332
- await runWizard({ targetDir: '/test' });
333
-
334
- expect(console.log).toHaveBeenCalledWith(
335
- expect.stringContaining('Welcome to SINAPSE Installer'),
336
- );
337
- });
338
-
339
- test('wizard displays detection step message', async () => {
340
- fs.existsSync.mockImplementation(() => true);
341
- fs.readdirSync.mockReturnValue([]);
342
-
343
- await runWizard({ targetDir: '/test' });
344
-
345
- expect(console.log).toHaveBeenCalledWith(
346
- expect.stringContaining('Analyzing project directory'),
347
- );
348
- });
349
- });
350
- });
351
-
352
-