skrypt-ai 0.6.1 → 0.8.0

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 (180) hide show
  1. package/dist/audit/doc-parser.d.ts +5 -0
  2. package/dist/audit/doc-parser.js +106 -0
  3. package/dist/audit/index.d.ts +4 -0
  4. package/dist/audit/index.js +4 -0
  5. package/dist/audit/matcher.d.ts +6 -0
  6. package/dist/audit/matcher.js +94 -0
  7. package/dist/audit/reporter.d.ts +9 -0
  8. package/dist/audit/reporter.js +106 -0
  9. package/dist/audit/types.d.ts +37 -0
  10. package/dist/auth/index.js +6 -4
  11. package/dist/cli.js +12 -2
  12. package/dist/commands/audit.d.ts +2 -0
  13. package/dist/commands/audit.js +59 -0
  14. package/dist/commands/config.d.ts +2 -0
  15. package/dist/commands/config.js +73 -0
  16. package/dist/commands/{generate.d.ts → generate/index.d.ts} +1 -0
  17. package/dist/commands/generate/index.js +393 -0
  18. package/dist/commands/generate/scan.d.ts +41 -0
  19. package/dist/commands/generate/scan.js +256 -0
  20. package/dist/commands/generate/verify.d.ts +14 -0
  21. package/dist/commands/generate/verify.js +122 -0
  22. package/dist/commands/generate/write.d.ts +25 -0
  23. package/dist/commands/generate/write.js +120 -0
  24. package/dist/commands/import.js +4 -1
  25. package/dist/commands/llms-txt.js +6 -4
  26. package/dist/commands/refresh.d.ts +2 -0
  27. package/dist/commands/refresh.js +158 -0
  28. package/dist/commands/review.d.ts +2 -0
  29. package/dist/commands/review.js +110 -0
  30. package/dist/commands/test.js +177 -236
  31. package/dist/commands/watch.js +29 -20
  32. package/dist/config/loader.d.ts +6 -2
  33. package/dist/config/loader.js +39 -3
  34. package/dist/config/types.d.ts +7 -0
  35. package/dist/generator/agents-md.d.ts +25 -0
  36. package/dist/generator/agents-md.js +122 -0
  37. package/dist/generator/generator.js +2 -1
  38. package/dist/generator/index.d.ts +2 -0
  39. package/dist/generator/index.js +2 -0
  40. package/dist/generator/mdx-serializer.d.ts +11 -0
  41. package/dist/generator/mdx-serializer.js +135 -0
  42. package/dist/generator/organizer.d.ts +1 -16
  43. package/dist/generator/organizer.js +0 -38
  44. package/dist/generator/types.d.ts +3 -0
  45. package/dist/generator/writer.js +65 -32
  46. package/dist/github/org-discovery.d.ts +17 -0
  47. package/dist/github/org-discovery.js +93 -0
  48. package/dist/llm/index.d.ts +2 -0
  49. package/dist/llm/index.js +8 -2
  50. package/dist/llm/proxy-client.d.ts +32 -0
  51. package/dist/llm/proxy-client.js +103 -0
  52. package/dist/next-actions/actions.d.ts +2 -0
  53. package/dist/next-actions/actions.js +190 -0
  54. package/dist/next-actions/index.d.ts +6 -0
  55. package/dist/next-actions/index.js +39 -0
  56. package/dist/next-actions/setup.d.ts +2 -0
  57. package/dist/next-actions/setup.js +72 -0
  58. package/dist/next-actions/state.d.ts +7 -0
  59. package/dist/next-actions/state.js +68 -0
  60. package/dist/next-actions/suggest.d.ts +3 -0
  61. package/dist/next-actions/suggest.js +47 -0
  62. package/dist/next-actions/types.d.ts +26 -0
  63. package/dist/refresh/differ.d.ts +9 -0
  64. package/dist/refresh/differ.js +67 -0
  65. package/dist/refresh/index.d.ts +4 -0
  66. package/dist/refresh/index.js +4 -0
  67. package/dist/refresh/manifest.d.ts +18 -0
  68. package/dist/refresh/manifest.js +71 -0
  69. package/dist/refresh/splicer.d.ts +9 -0
  70. package/dist/refresh/splicer.js +50 -0
  71. package/dist/refresh/types.d.ts +37 -0
  72. package/dist/review/index.d.ts +8 -0
  73. package/dist/review/index.js +94 -0
  74. package/dist/review/parser.d.ts +16 -0
  75. package/dist/review/parser.js +95 -0
  76. package/dist/review/types.d.ts +18 -0
  77. package/dist/scanner/csharp.d.ts +0 -4
  78. package/dist/scanner/csharp.js +9 -49
  79. package/dist/scanner/go.d.ts +0 -3
  80. package/dist/scanner/go.js +8 -35
  81. package/dist/scanner/java.d.ts +0 -4
  82. package/dist/scanner/java.js +9 -49
  83. package/dist/scanner/kotlin.d.ts +0 -3
  84. package/dist/scanner/kotlin.js +6 -33
  85. package/dist/scanner/php.d.ts +0 -10
  86. package/dist/scanner/php.js +11 -55
  87. package/dist/scanner/ruby.d.ts +0 -3
  88. package/dist/scanner/ruby.js +8 -38
  89. package/dist/scanner/rust.d.ts +0 -3
  90. package/dist/scanner/rust.js +10 -37
  91. package/dist/scanner/swift.d.ts +0 -3
  92. package/dist/scanner/swift.js +8 -35
  93. package/dist/scanner/types.d.ts +2 -0
  94. package/dist/scanner/utils.d.ts +41 -0
  95. package/dist/scanner/utils.js +97 -0
  96. package/dist/structure/index.d.ts +19 -0
  97. package/dist/structure/index.js +92 -0
  98. package/dist/structure/planner.d.ts +8 -0
  99. package/dist/structure/planner.js +180 -0
  100. package/dist/structure/topology.d.ts +16 -0
  101. package/dist/structure/topology.js +49 -0
  102. package/dist/structure/types.d.ts +26 -0
  103. package/dist/template/docs.json +5 -2
  104. package/dist/template/next.config.mjs +31 -0
  105. package/dist/template/package.json +5 -3
  106. package/dist/template/src/app/layout.tsx +13 -13
  107. package/dist/template/src/app/llms-full.md/route.ts +29 -0
  108. package/dist/template/src/app/llms.txt/route.ts +29 -0
  109. package/dist/template/src/app/md/[...slug]/route.ts +174 -0
  110. package/dist/template/src/app/reference/route.ts +22 -18
  111. package/dist/template/src/app/sitemap.ts +1 -1
  112. package/dist/template/src/components/ai-chat-impl.tsx +206 -0
  113. package/dist/template/src/components/ai-chat.tsx +20 -193
  114. package/dist/template/src/components/mdx/index.tsx +27 -4
  115. package/dist/template/src/lib/fonts.ts +135 -0
  116. package/dist/template/src/middleware.ts +101 -0
  117. package/dist/template/src/styles/globals.css +28 -20
  118. package/dist/testing/comparator.d.ts +7 -0
  119. package/dist/testing/comparator.js +77 -0
  120. package/dist/testing/docker.d.ts +21 -0
  121. package/dist/testing/docker.js +234 -0
  122. package/dist/testing/env.d.ts +16 -0
  123. package/dist/testing/env.js +58 -0
  124. package/dist/testing/extractor.d.ts +9 -0
  125. package/dist/testing/extractor.js +195 -0
  126. package/dist/testing/index.d.ts +6 -0
  127. package/dist/testing/index.js +6 -0
  128. package/dist/testing/runner.d.ts +5 -0
  129. package/dist/testing/runner.js +225 -0
  130. package/dist/testing/types.d.ts +58 -0
  131. package/dist/utils/files.d.ts +0 -8
  132. package/dist/utils/files.js +0 -33
  133. package/package.json +1 -1
  134. package/dist/autofix/autofix.test.js +0 -487
  135. package/dist/commands/generate.js +0 -445
  136. package/dist/generator/generator.test.js +0 -259
  137. package/dist/generator/writer.test.js +0 -411
  138. package/dist/llm/llm.manual-test.js +0 -112
  139. package/dist/llm/llm.mock-test.d.ts +0 -4
  140. package/dist/llm/llm.mock-test.js +0 -79
  141. package/dist/plugins/index.d.ts +0 -47
  142. package/dist/plugins/index.js +0 -181
  143. package/dist/scanner/content-type.test.js +0 -231
  144. package/dist/scanner/integration.test.d.ts +0 -4
  145. package/dist/scanner/integration.test.js +0 -180
  146. package/dist/scanner/scanner.test.js +0 -210
  147. package/dist/scanner/typescript.manual-test.d.ts +0 -1
  148. package/dist/scanner/typescript.manual-test.js +0 -112
  149. package/dist/template/src/app/docs/auth/page.mdx +0 -589
  150. package/dist/template/src/app/docs/autofix/page.mdx +0 -624
  151. package/dist/template/src/app/docs/cli/page.mdx +0 -217
  152. package/dist/template/src/app/docs/config/page.mdx +0 -428
  153. package/dist/template/src/app/docs/configuration/page.mdx +0 -86
  154. package/dist/template/src/app/docs/deployment/page.mdx +0 -112
  155. package/dist/template/src/app/docs/generator/generator.md +0 -504
  156. package/dist/template/src/app/docs/generator/organizer.md +0 -779
  157. package/dist/template/src/app/docs/generator/page.mdx +0 -613
  158. package/dist/template/src/app/docs/github/page.mdx +0 -502
  159. package/dist/template/src/app/docs/llm/anthropic-client.md +0 -549
  160. package/dist/template/src/app/docs/llm/index.md +0 -471
  161. package/dist/template/src/app/docs/llm/page.mdx +0 -428
  162. package/dist/template/src/app/docs/plugins/page.mdx +0 -1793
  163. package/dist/template/src/app/docs/pro/page.mdx +0 -121
  164. package/dist/template/src/app/docs/quickstart/page.mdx +0 -93
  165. package/dist/template/src/app/docs/scanner/content-type.md +0 -599
  166. package/dist/template/src/app/docs/scanner/index.md +0 -212
  167. package/dist/template/src/app/docs/scanner/page.mdx +0 -307
  168. package/dist/template/src/app/docs/scanner/python.md +0 -469
  169. package/dist/template/src/app/docs/scanner/python_parser.md +0 -1056
  170. package/dist/template/src/app/docs/scanner/rust.md +0 -325
  171. package/dist/template/src/app/docs/scanner/typescript.md +0 -201
  172. package/dist/template/src/app/icon.tsx +0 -29
  173. package/dist/utils/validation.d.ts +0 -1
  174. package/dist/utils/validation.js +0 -12
  175. /package/dist/{autofix/autofix.test.d.ts → audit/types.js} +0 -0
  176. /package/dist/{generator/generator.test.d.ts → next-actions/types.js} +0 -0
  177. /package/dist/{generator/writer.test.d.ts → refresh/types.js} +0 -0
  178. /package/dist/{llm/llm.manual-test.d.ts → review/types.js} +0 -0
  179. /package/dist/{scanner/content-type.test.d.ts → structure/types.js} +0 -0
  180. /package/dist/{scanner/scanner.test.d.ts → testing/types.js} +0 -0
@@ -1,180 +0,0 @@
1
- /**
2
- * Integration tests for the full scanning pipeline
3
- */
4
- import { describe, it, expect, beforeAll, afterAll } from 'vitest';
5
- import { writeFileSync, mkdirSync, rmSync, existsSync } from 'fs';
6
- import { join } from 'path';
7
- import { scanDirectory, scanFile } from './index.js';
8
- const TEST_DIR = join(process.cwd(), 'test-fixtures');
9
- describe('Scanner Integration', () => {
10
- beforeAll(() => {
11
- // Create test fixtures
12
- mkdirSync(TEST_DIR, { recursive: true });
13
- // TypeScript file
14
- writeFileSync(join(TEST_DIR, 'sample.ts'), `
15
- /**
16
- * Add two numbers
17
- * @param a First number
18
- * @param b Second number
19
- */
20
- export function add(a: number, b: number): number {
21
- return a + b;
22
- }
23
-
24
- export class Calculator {
25
- value: number = 0;
26
-
27
- add(n: number): this {
28
- this.value += n;
29
- return this;
30
- }
31
- }
32
- `);
33
- // Python file
34
- writeFileSync(join(TEST_DIR, 'utils.py'), `
35
- """Utility functions."""
36
-
37
- def greet(name: str) -> str:
38
- """Greet someone by name."""
39
- return f"Hello, {name}!"
40
-
41
- class Helper:
42
- """Helper class."""
43
-
44
- def process(self, data: dict) -> dict:
45
- """Process data."""
46
- return data
47
- `);
48
- // Go file
49
- writeFileSync(join(TEST_DIR, 'handlers.go'), `
50
- package handlers
51
-
52
- // GetUser retrieves a user
53
- func GetUser(id string) string {
54
- return id
55
- }
56
-
57
- type Service struct {
58
- name string
59
- }
60
- `);
61
- // Rust file
62
- writeFileSync(join(TEST_DIR, 'lib.rs'), `
63
- /// Configuration struct
64
- pub struct Config {
65
- pub name: String,
66
- }
67
-
68
- impl Config {
69
- /// Create new config
70
- pub fn new() -> Self {
71
- Config { name: String::new() }
72
- }
73
- }
74
-
75
- /// Parse config from string
76
- pub fn parse_config(s: &str) -> Config {
77
- Config { name: s.to_string() }
78
- }
79
- `);
80
- });
81
- afterAll(() => {
82
- // Cleanup test fixtures
83
- if (existsSync(TEST_DIR)) {
84
- rmSync(TEST_DIR, { recursive: true });
85
- }
86
- });
87
- describe('scanDirectory', () => {
88
- it('scans all supported languages', async () => {
89
- const result = await scanDirectory(TEST_DIR);
90
- expect(result.errors).toHaveLength(0);
91
- expect(result.files.length).toBeGreaterThanOrEqual(4);
92
- expect(result.totalElements).toBeGreaterThanOrEqual(8);
93
- // Check we found elements from each language
94
- const languages = new Set(result.files.map(f => f.language));
95
- expect(languages.has('typescript')).toBe(true);
96
- expect(languages.has('python')).toBe(true);
97
- expect(languages.has('go')).toBe(true);
98
- expect(languages.has('rust')).toBe(true);
99
- });
100
- it('respects exclude patterns', async () => {
101
- const result = await scanDirectory(TEST_DIR, {
102
- exclude: ['**/utils.py']
103
- });
104
- // Should not find the utils.py file
105
- const fileNames = result.files.map(f => f.filePath);
106
- const hasPython = fileNames.some(f => f.includes('utils.py'));
107
- expect(hasPython).toBe(false);
108
- });
109
- it('respects include patterns', async () => {
110
- const result = await scanDirectory(TEST_DIR, {
111
- include: ['**/*.ts']
112
- });
113
- expect(result.files.length).toBe(1);
114
- expect(result.files[0].language).toBe('typescript');
115
- });
116
- it('calls progress callback', async () => {
117
- const progress = [];
118
- await scanDirectory(TEST_DIR, {
119
- onProgress: (current, total) => {
120
- progress.push({ current, total });
121
- }
122
- });
123
- expect(progress.length).toBeGreaterThan(0);
124
- expect(progress[0].current).toBe(1);
125
- });
126
- });
127
- describe('scanFile', () => {
128
- it('scans a single TypeScript file', async () => {
129
- const result = await scanFile(join(TEST_DIR, 'sample.ts'));
130
- expect(result.errors).toHaveLength(0);
131
- expect(result.language).toBe('typescript');
132
- expect(result.elements.length).toBeGreaterThanOrEqual(2);
133
- const functionNames = result.elements.map(e => e.name);
134
- expect(functionNames).toContain('add');
135
- expect(functionNames).toContain('Calculator');
136
- });
137
- it('scans a single Python file', async () => {
138
- const result = await scanFile(join(TEST_DIR, 'utils.py'));
139
- expect(result.errors).toHaveLength(0);
140
- expect(result.language).toBe('python');
141
- const names = result.elements.map(e => e.name);
142
- expect(names).toContain('greet');
143
- expect(names).toContain('Helper');
144
- });
145
- it('returns error for unsupported file type', async () => {
146
- const result = await scanFile(join(TEST_DIR, 'unknown.xyz'));
147
- expect(result.errors.length).toBeGreaterThan(0);
148
- expect(result.elements).toHaveLength(0);
149
- });
150
- });
151
- describe('single file via scanDirectory', () => {
152
- it('accepts a single file path', async () => {
153
- const result = await scanDirectory(join(TEST_DIR, 'sample.ts'));
154
- expect(result.errors).toHaveLength(0);
155
- expect(result.files.length).toBe(1);
156
- expect(result.files[0].language).toBe('typescript');
157
- });
158
- });
159
- describe('element extraction', () => {
160
- it('extracts function parameters', async () => {
161
- const result = await scanFile(join(TEST_DIR, 'sample.ts'));
162
- const addFn = result.elements.find(e => e.name === 'add');
163
- expect(addFn).toBeDefined();
164
- expect(addFn?.parameters).toHaveLength(2);
165
- expect(addFn?.parameters[0].name).toBe('a');
166
- expect(addFn?.parameters[0].type).toBe('number');
167
- });
168
- it('extracts docstrings', async () => {
169
- const result = await scanFile(join(TEST_DIR, 'sample.ts'));
170
- const addFn = result.elements.find(e => e.name === 'add');
171
- expect(addFn?.docstring).toContain('Add two numbers');
172
- });
173
- it('extracts class methods', async () => {
174
- const result = await scanFile(join(TEST_DIR, 'sample.ts'));
175
- const addMethod = result.elements.find(e => e.name === 'add' && e.kind === 'method');
176
- expect(addMethod).toBeDefined();
177
- expect(addMethod?.parentClass).toBe('Calculator');
178
- });
179
- });
180
- });
@@ -1,210 +0,0 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { scanFile, scanDirectory } from './index.js';
3
- import { join } from 'path';
4
- const TESTDATA = join(process.cwd(), 'testdata');
5
- describe('Scanner', () => {
6
- describe('scanFile', () => {
7
- describe('Python files', () => {
8
- it('should scan Python file and extract elements', async () => {
9
- const result = await scanFile(join(TESTDATA, 'sample.py'));
10
- expect(result.errors).toHaveLength(0);
11
- expect(result.language).toBe('python');
12
- expect(result.elements.length).toBeGreaterThan(0);
13
- });
14
- it('should find expected Python functions', async () => {
15
- const result = await scanFile(join(TESTDATA, 'sample.py'));
16
- const names = result.elements.map(e => e.name);
17
- expect(names).toContain('greet');
18
- expect(names).toContain('fetch_data');
19
- });
20
- it('should find Python class and methods', async () => {
21
- const result = await scanFile(join(TESTDATA, 'sample.py'));
22
- const names = result.elements.map(e => e.name);
23
- expect(names).toContain('Calculator');
24
- expect(names).toContain('add');
25
- expect(names).toContain('multiply');
26
- });
27
- it('should exclude private Python elements', async () => {
28
- const result = await scanFile(join(TESTDATA, 'sample.py'));
29
- const names = result.elements.map(e => e.name);
30
- expect(names).not.toContain('_private_method');
31
- expect(names).not.toContain('_private_function');
32
- expect(names).not.toContain('_PrivateClass');
33
- });
34
- it('should detect async Python functions', async () => {
35
- const result = await scanFile(join(TESTDATA, 'sample.py'));
36
- const fetchData = result.elements.find(e => e.name === 'fetch_data');
37
- expect(fetchData).toBeDefined();
38
- expect(fetchData?.isAsync).toBe(true);
39
- });
40
- it('should extract Python function parameters', async () => {
41
- const result = await scanFile(join(TESTDATA, 'sample.py'));
42
- const greet = result.elements.find(e => e.name === 'greet');
43
- expect(greet).toBeDefined();
44
- expect(greet?.parameters).toHaveLength(2);
45
- expect(greet?.parameters[0].name).toBe('name');
46
- expect(greet?.parameters[0].type).toBe('str');
47
- });
48
- it('should extract Python docstrings', async () => {
49
- const result = await scanFile(join(TESTDATA, 'sample.py'));
50
- const greet = result.elements.find(e => e.name === 'greet');
51
- expect(greet?.docstring).toContain('Generate a greeting');
52
- });
53
- });
54
- describe('TypeScript files', () => {
55
- it('should scan TypeScript file and extract elements', async () => {
56
- const result = await scanFile(join(TESTDATA, 'sample.ts'));
57
- expect(result.errors).toHaveLength(0);
58
- expect(result.language).toBe('typescript');
59
- expect(result.elements.length).toBeGreaterThan(0);
60
- });
61
- it('should find expected TypeScript functions', async () => {
62
- const result = await scanFile(join(TESTDATA, 'sample.ts'));
63
- const names = result.elements.map(e => e.name);
64
- expect(names).toContain('greet');
65
- expect(names).toContain('fetchData');
66
- expect(names).toContain('processItems');
67
- });
68
- it('should find TypeScript class and methods', async () => {
69
- const result = await scanFile(join(TESTDATA, 'sample.ts'));
70
- const names = result.elements.map(e => e.name);
71
- expect(names).toContain('Calculator');
72
- expect(names).toContain('add');
73
- expect(names).toContain('multiply');
74
- });
75
- it('should exclude non-exported TypeScript elements', async () => {
76
- const result = await scanFile(join(TESTDATA, 'sample.ts'));
77
- const names = result.elements.map(e => e.name);
78
- expect(names).not.toContain('internalHelper');
79
- expect(names).not.toContain('_privateFunction');
80
- });
81
- it('should detect async TypeScript functions', async () => {
82
- const result = await scanFile(join(TESTDATA, 'sample.ts'));
83
- const fetchData = result.elements.find(e => e.name === 'fetchData');
84
- const processItems = result.elements.find(e => e.name === 'processItems');
85
- expect(fetchData?.isAsync).toBe(true);
86
- expect(processItems?.isAsync).toBe(true);
87
- });
88
- it('should set parentClass for methods', async () => {
89
- const result = await scanFile(join(TESTDATA, 'sample.ts'));
90
- const addMethod = result.elements.find(e => e.name === 'add');
91
- expect(addMethod?.parentClass).toBe('Calculator');
92
- expect(addMethod?.kind).toBe('method');
93
- });
94
- });
95
- describe('Go files', () => {
96
- it('should scan Go file and extract elements', async () => {
97
- const result = await scanFile(join(TESTDATA, 'sample.go'));
98
- expect(result.errors).toHaveLength(0);
99
- expect(result.language).toBe('go');
100
- expect(result.elements.length).toBeGreaterThan(0);
101
- });
102
- it('should find exported Go functions', async () => {
103
- const result = await scanFile(join(TESTDATA, 'sample.go'));
104
- const names = result.elements.map(e => e.name);
105
- expect(names).toContain('Greet');
106
- expect(names).toContain('FetchData');
107
- expect(names).toContain('NewCalculator');
108
- expect(names).toContain('ProcessItems');
109
- });
110
- it('should find Go types', async () => {
111
- const result = await scanFile(join(TESTDATA, 'sample.go'));
112
- const names = result.elements.map(e => e.name);
113
- expect(names).toContain('Config');
114
- expect(names).toContain('Calculator');
115
- expect(names).toContain('Client');
116
- });
117
- it('should find Go methods', async () => {
118
- const result = await scanFile(join(TESTDATA, 'sample.go'));
119
- const names = result.elements.map(e => e.name);
120
- expect(names).toContain('Add');
121
- expect(names).toContain('Multiply');
122
- });
123
- it('should exclude non-exported Go functions', async () => {
124
- const result = await scanFile(join(TESTDATA, 'sample.go'));
125
- const names = result.elements.map(e => e.name);
126
- expect(names).not.toContain('privateFunction');
127
- expect(names).not.toContain('privateMethod');
128
- });
129
- it('should extract Go doc comments', async () => {
130
- const result = await scanFile(join(TESTDATA, 'sample.go'));
131
- const greet = result.elements.find(e => e.name === 'Greet');
132
- expect(greet?.docstring).toContain('generates a greeting');
133
- });
134
- });
135
- describe('Rust files', () => {
136
- it('should scan Rust file and extract elements', async () => {
137
- const result = await scanFile(join(TESTDATA, 'sample.rs'));
138
- expect(result.errors).toHaveLength(0);
139
- expect(result.language).toBe('rust');
140
- expect(result.elements.length).toBeGreaterThan(0);
141
- });
142
- it('should find pub Rust functions', async () => {
143
- const result = await scanFile(join(TESTDATA, 'sample.rs'));
144
- const names = result.elements.map(e => e.name);
145
- expect(names).toContain('greet');
146
- expect(names).toContain('fetch_data');
147
- expect(names).toContain('process_items');
148
- });
149
- it('should find pub Rust types', async () => {
150
- const result = await scanFile(join(TESTDATA, 'sample.rs'));
151
- const names = result.elements.map(e => e.name);
152
- expect(names).toContain('Config');
153
- expect(names).toContain('Calculator');
154
- expect(names).toContain('Client');
155
- });
156
- it('should find pub impl methods', async () => {
157
- const result = await scanFile(join(TESTDATA, 'sample.rs'));
158
- const names = result.elements.map(e => e.name);
159
- expect(names).toContain('new');
160
- expect(names).toContain('add');
161
- expect(names).toContain('multiply');
162
- });
163
- it('should exclude non-pub Rust functions', async () => {
164
- const result = await scanFile(join(TESTDATA, 'sample.rs'));
165
- const names = result.elements.map(e => e.name);
166
- expect(names).not.toContain('private_function');
167
- expect(names).not.toContain('private_method');
168
- });
169
- it('should detect async Rust functions', async () => {
170
- const result = await scanFile(join(TESTDATA, 'sample.rs'));
171
- const fetchData = result.elements.find(e => e.name === 'fetch_data');
172
- expect(fetchData?.isAsync).toBe(true);
173
- });
174
- it('should extract Rust doc comments', async () => {
175
- const result = await scanFile(join(TESTDATA, 'sample.rs'));
176
- const greet = result.elements.find(e => e.name === 'greet');
177
- expect(greet?.docstring).toContain('Generate a greeting');
178
- });
179
- });
180
- });
181
- describe('scanDirectory', () => {
182
- it('should scan multiple files in directory', async () => {
183
- const result = await scanDirectory(TESTDATA, {
184
- include: ['**/*.py', '**/*.ts', '**/*.go', '**/*.rs'],
185
- exclude: [],
186
- });
187
- expect(result.files.length).toBeGreaterThanOrEqual(4);
188
- expect(result.totalElements).toBeGreaterThan(0);
189
- expect(result.errors).toHaveLength(0);
190
- });
191
- it('should respect include patterns', async () => {
192
- const result = await scanDirectory(TESTDATA, {
193
- include: ['**/*.py'],
194
- exclude: [],
195
- });
196
- expect(result.files.every(f => f.language === 'python')).toBe(true);
197
- });
198
- it('should have files from all languages', async () => {
199
- const result = await scanDirectory(TESTDATA, {
200
- include: ['**/*.py', '**/*.ts', '**/*.go', '**/*.rs'],
201
- exclude: [],
202
- });
203
- const languages = new Set(result.files.map(f => f.language));
204
- expect(languages.has('python')).toBe(true);
205
- expect(languages.has('typescript')).toBe(true);
206
- expect(languages.has('go')).toBe(true);
207
- expect(languages.has('rust')).toBe(true);
208
- });
209
- });
210
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,112 +0,0 @@
1
- import { scanFile, scanDirectory } from './index.js';
2
- async function runTests() {
3
- console.log('=== TypeScript Scanner Tests ===\n');
4
- // Test 1: Scan single TypeScript file
5
- console.log('Test 1: Scan single TypeScript file');
6
- const result = await scanFile('testdata/sample.ts');
7
- if (result.errors.length > 0) {
8
- console.log(' ✗ errors:', result.errors);
9
- process.exit(1);
10
- }
11
- console.log(` found ${result.elements.length} elements`);
12
- console.log(` language: ${result.language}`);
13
- // Check we found expected elements
14
- const names = result.elements.map(e => e.name);
15
- const expected = ['greet', 'fetchData', 'processItems', 'Calculator', 'constructor', 'add', 'multiply'];
16
- for (const name of expected) {
17
- if (!names.includes(name)) {
18
- console.log(` ✗ missing expected element: ${name}`);
19
- console.log(' found:', names);
20
- process.exit(1);
21
- }
22
- }
23
- // Check private/non-exported elements are excluded
24
- const excluded = ['_privateMethod', '_privateFunction', 'internalHelper'];
25
- for (const name of excluded) {
26
- if (names.includes(name)) {
27
- console.log(` ✗ should have excluded: ${name}`);
28
- process.exit(1);
29
- }
30
- }
31
- console.log(' ✓ found all expected elements');
32
- console.log(' ✓ excluded private/non-exported elements\n');
33
- // Test 2: Check function details
34
- console.log('Test 2: Check function details');
35
- const greet = result.elements.find(e => e.name === 'greet');
36
- if (greet.kind !== 'function') {
37
- console.log(` ✗ greet.kind should be 'function', got '${greet.kind}'`);
38
- process.exit(1);
39
- }
40
- if (greet.parameters.length !== 2) {
41
- console.log(` ✗ greet should have 2 params, got ${greet.parameters.length}`);
42
- process.exit(1);
43
- }
44
- if (greet.returnType !== 'string') {
45
- console.log(` ✗ greet.returnType should be 'string', got '${greet.returnType}'`);
46
- process.exit(1);
47
- }
48
- console.log(' ✓ function details correct\n');
49
- // Test 3: Check async function
50
- console.log('Test 3: Check async function');
51
- const fetchData = result.elements.find(e => e.name === 'fetchData');
52
- if (!fetchData.isAsync) {
53
- console.log(' ✗ fetchData should be async');
54
- process.exit(1);
55
- }
56
- console.log(' ✓ async detected correctly\n');
57
- // Test 4: Check arrow function
58
- console.log('Test 4: Check arrow function');
59
- const processItems = result.elements.find(e => e.name === 'processItems');
60
- if (processItems.kind !== 'function') {
61
- console.log(` ✗ processItems.kind should be 'function', got '${processItems.kind}'`);
62
- process.exit(1);
63
- }
64
- if (!processItems.isAsync) {
65
- console.log(' ✗ processItems should be async');
66
- process.exit(1);
67
- }
68
- console.log(' ✓ arrow function detected correctly\n');
69
- // Test 5: Check class and methods
70
- console.log('Test 5: Check class and methods');
71
- const calculator = result.elements.find(e => e.name === 'Calculator');
72
- const addMethod = result.elements.find(e => e.name === 'add');
73
- if (calculator.kind !== 'class') {
74
- console.log(` ✗ Calculator.kind should be 'class', got '${calculator.kind}'`);
75
- process.exit(1);
76
- }
77
- if (addMethod.kind !== 'method') {
78
- console.log(` ✗ add.kind should be 'method', got '${addMethod.kind}'`);
79
- process.exit(1);
80
- }
81
- if (addMethod.parentClass !== 'Calculator') {
82
- console.log(` ✗ add.parentClass should be 'Calculator', got '${addMethod.parentClass}'`);
83
- process.exit(1);
84
- }
85
- console.log(' ✓ class and methods correct\n');
86
- // Test 6: Scan directory with both Python and TypeScript
87
- console.log('Test 6: Scan directory with multiple languages');
88
- const dirResult = await scanDirectory('testdata', {
89
- include: ['**/*.py', '**/*.ts'],
90
- exclude: []
91
- });
92
- console.log(` scanned ${dirResult.files.length} files`);
93
- console.log(` found ${dirResult.totalElements} total elements`);
94
- const languages = new Set(dirResult.files.map(f => f.language));
95
- if (!languages.has('python') || !languages.has('typescript')) {
96
- console.log(' ✗ should have found both Python and TypeScript');
97
- console.log(' languages:', [...languages]);
98
- process.exit(1);
99
- }
100
- console.log(' ✓ multi-language scan works\n');
101
- // Print summary of all elements
102
- console.log('=== Elements Found ===');
103
- for (const el of result.elements) {
104
- const prefix = el.parentClass ? `${el.parentClass}.` : '';
105
- console.log(` [${el.kind}] ${prefix}${el.name}`);
106
- }
107
- console.log('\n✓ All TypeScript scanner tests passed');
108
- }
109
- runTests().catch(err => {
110
- console.error('Test failed:', err);
111
- process.exit(1);
112
- });