@boyingliu01/xp-gate 0.38.75 → 0.38.77

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 (111) hide show
  1. package/lib/__tests__/mirror-sync.test.js +387 -5
  2. package/lib/mattpocock-license-verdict.json +1 -1
  3. package/lib/mirror-sync.js +202 -15
  4. package/package.json +1 -1
  5. package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
  6. package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
  7. package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
  8. package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
  9. package/plugins/dsh/lib/hooks.d.ts +10 -1
  10. package/plugins/dsh/lib/hooks.d.ts.map +1 -1
  11. package/plugins/dsh/lib/hooks.js +56 -5
  12. package/plugins/dsh/lib/index.js +6 -1
  13. package/plugins/dsh/package.json +1 -1
  14. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  15. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  16. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  17. package/plugins/dsh/src/hooks.test.ts +70 -0
  18. package/plugins/dsh/src/hooks.ts +66 -5
  19. package/plugins/dsh/src/index.ts +6 -1
  20. package/plugins/opencode/package.json +1 -1
  21. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  22. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  23. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  24. package/plugins/qoder/plugin.json +1 -1
  25. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  26. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  27. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  28. package/scripts/generate-mirrors.cjs +10 -0
  29. package/skills/delphi-review/AGENTS.md +1 -1
  30. package/skills/sprint-flow/AGENTS.md +1 -1
  31. package/skills/test-specification-alignment/AGENTS.md +1 -1
  32. package/mock-policy/__tests__/config.test.ts +0 -292
  33. package/mock-policy/__tests__/gate-m3.test.ts +0 -379
  34. package/mock-policy/__tests__/integration.test.ts +0 -600
  35. package/mock-policy/__tests__/mock-decision-engine.test.ts +0 -231
  36. package/mock-policy/__tests__/schema.test.ts +0 -239
  37. package/mock-policy/__tests__/scope-scanner.test.ts +0 -541
  38. package/mutation/__tests__/detect-ai-test.test.ts +0 -152
  39. package/mutation/__tests__/gate-m-survivors.test.ts +0 -167
  40. package/mutation/__tests__/gate-m.test.ts +0 -246
  41. package/mutation/__tests__/go-mutant-runner.test.ts +0 -288
  42. package/mutation/__tests__/gremlins-runner.test.ts +0 -167
  43. package/mutation/__tests__/init-baseline.test.ts +0 -347
  44. package/mutation/__tests__/mutation-mirror.test.ts +0 -49
  45. package/mutation/__tests__/mutmut-runner.test.ts +0 -1049
  46. package/mutation/__tests__/pitest-gradle-availability.test.ts +0 -74
  47. package/mutation/__tests__/pitest-runner.test.ts +0 -574
  48. package/mutation/__tests__/runners-index.test.ts +0 -162
  49. package/mutation/__tests__/stryker-runner.test.ts +0 -455
  50. package/mutation/__tests__/test-filter-parity.test.ts +0 -40
  51. package/mutation/__tests__/update-baseline.test.ts +0 -395
  52. package/principles/__tests__/adapter-metrics.test.ts +0 -292
  53. package/principles/__tests__/analyze-read-failure.test.ts +0 -70
  54. package/principles/__tests__/analyzer.test.ts +0 -367
  55. package/principles/__tests__/baseline-entry-total-warnings.test.ts +0 -76
  56. package/principles/__tests__/baseline-prune-timeout.test.ts +0 -71
  57. package/principles/__tests__/baseline-prune.test.ts +0 -399
  58. package/principles/__tests__/baseline-storage.test.ts +0 -188
  59. package/principles/__tests__/baseline.test.ts +0 -330
  60. package/principles/__tests__/boy-scout-init-baseline.test.ts +0 -167
  61. package/principles/__tests__/boy-scout-integration.test.ts +0 -355
  62. package/principles/__tests__/boy-scout.test.ts +0 -893
  63. package/principles/__tests__/cli-files-separators.test.ts +0 -69
  64. package/principles/__tests__/config-arch-group.test.ts +0 -106
  65. package/principles/__tests__/config-enforcement.test.ts +0 -470
  66. package/principles/__tests__/config-git-timeout.test.ts +0 -66
  67. package/principles/__tests__/config-merge-warnings.test.ts +0 -148
  68. package/principles/__tests__/config.test.ts +0 -78
  69. package/principles/__tests__/direct-execution.test.ts +0 -187
  70. package/principles/__tests__/index.test.ts +0 -94
  71. package/principles/__tests__/issue-587-java-member-count.test.ts +0 -279
  72. package/principles/__tests__/issue-588-lsp-java-false-positives.test.ts +0 -213
  73. package/principles/__tests__/lint-baseline.test.ts +0 -314
  74. package/principles/__tests__/many-exports-reexport.test.ts +0 -40
  75. package/principles/__tests__/reporter.test.ts +0 -660
  76. package/principles/__tests__/types.test.ts +0 -103
  77. package/principles/__tests__/warnings-baseline-budgets.test.ts +0 -74
  78. package/principles/adapters/__tests__/base.test.ts +0 -95
  79. package/principles/adapters/__tests__/cpp-code-block.test.ts +0 -123
  80. package/principles/adapters/__tests__/cpp-scanner-equivalence.test.ts +0 -67
  81. package/principles/adapters/__tests__/cpp.test.ts +0 -290
  82. package/principles/adapters/__tests__/dart.test.ts +0 -84
  83. package/principles/adapters/__tests__/go.test.ts +0 -68
  84. package/principles/adapters/__tests__/java.test.ts +0 -385
  85. package/principles/adapters/__tests__/kotlin.test.ts +0 -76
  86. package/principles/adapters/__tests__/objectivec.test.ts +0 -453
  87. package/principles/adapters/__tests__/python.test.ts +0 -84
  88. package/principles/adapters/__tests__/swift.test.ts +0 -68
  89. package/principles/adapters/__tests__/typescript-block-comment-lines.test.ts +0 -53
  90. package/principles/adapters/__tests__/typescript-masking.test.ts +0 -96
  91. package/principles/adapters/__tests__/typescript.test.ts +0 -116
  92. package/principles/rules/__tests__/clean-code/code-duplication.test.ts +0 -85
  93. package/principles/rules/__tests__/clean-code/deep-nesting.test.ts +0 -73
  94. package/principles/rules/__tests__/clean-code/god-class.test.ts +0 -109
  95. package/principles/rules/__tests__/clean-code/large-file.test.ts +0 -73
  96. package/principles/rules/__tests__/clean-code/long-function.test.ts +0 -81
  97. package/principles/rules/__tests__/clean-code/magic-numbers.test.ts +0 -68
  98. package/principles/rules/__tests__/clean-code/many-exports.test.ts +0 -123
  99. package/principles/rules/__tests__/clean-code/missing-error-handling.test.ts +0 -171
  100. package/principles/rules/__tests__/clean-code/too-many-params.test.ts +0 -58
  101. package/principles/rules/__tests__/clean-code/unused-imports.test.ts +0 -107
  102. package/principles/rules/__tests__/index.test.ts +0 -49
  103. package/principles/rules/__tests__/solid/dip.test.ts +0 -119
  104. package/principles/rules/__tests__/solid/isp.test.ts +0 -58
  105. package/principles/rules/__tests__/solid/issue-588-lsp-base-contract.test.ts +0 -252
  106. package/principles/rules/__tests__/solid/lsp.test.ts +0 -186
  107. package/principles/rules/__tests__/solid/ocp.test.ts +0 -67
  108. package/principles/rules/__tests__/solid/srp.test.ts +0 -87
  109. package/principles/rules/arch/__tests__/dependency.test.ts +0 -180
  110. package/principles/rules/arch/__tests__/naming.test.ts +0 -133
  111. package/principles/rules/arch/__tests__/shared.test.ts +0 -113
@@ -1,453 +0,0 @@
1
- import { describe, it, expect, vi, type Mock } from 'vitest';;
2
- import { ObjectiveCAdapter } from '../objectivec';
3
-
4
- vi.mock('fs', () => ({
5
- readFileSync: vi.fn(),
6
- existsSync: vi.fn(() => true),
7
- }));
8
-
9
- import { readFileSync } from 'fs';
10
-
11
- /**
12
- * @test REQ-QG-001 Language Coverage Extension
13
- * @intent Verify Objective-C adapter implementation for quality gates
14
- * @covers AC-QG-001-05, AC-QG-001-06, AC-QG-001-08
15
- */
16
- describe('ObjectiveCAdapter', () => {
17
-
18
- /**
19
- * @test REQ-QG-001
20
- * @covers AC-QG-001-05
21
- */
22
- it('should implement the Adapter interface', () => {
23
- (readFileSync as Mock).mockReturnValue('@implementation Test @end');
24
- const adapter = new ObjectiveCAdapter('test.m');
25
-
26
- expect(adapter).toHaveProperty('detectLanguage');
27
- expect(adapter).toHaveProperty('parseAST');
28
- expect(adapter).toHaveProperty('extractFunctions');
29
- expect(adapter).toHaveProperty('extractClasses');
30
- });
31
-
32
- /**
33
- * @test REQ-QG-001
34
- * @covers AC-QG-001-08
35
- */
36
- it('should detect language as objectivec for .m files', () => {
37
- (readFileSync as Mock).mockReturnValue('@implementation Test @end');
38
- const adapter = new ObjectiveCAdapter('test.m');
39
- const detected = adapter.detectLanguage();
40
- expect(detected).toBe('objectivec');
41
- });
42
-
43
- /**
44
- * @test REQ-QG-001
45
- * @covers AC-QG-001-08
46
- */
47
- it('should detect language as objectivec for .mm files (Objective-C++)', () => {
48
- (readFileSync as Mock).mockReturnValue('@implementation Test @end');
49
- const adapter = new ObjectiveCAdapter('test.mm');
50
- const detected = adapter.detectLanguage();
51
- expect(detected).toBe('objectivec');
52
- });
53
-
54
- /**
55
- * @test REQ-QG-001
56
- * @covers AC-QG-001-06
57
- */
58
- it('should parse Objective-C file AST correctly', () => {
59
- (readFileSync as Mock).mockReturnValue('@implementation Test @end');
60
- const adapter = new ObjectiveCAdapter('test.m');
61
- const ast = adapter.parseAST();
62
- expect(ast).toHaveProperty('content');
63
- expect(ast).toHaveProperty('language');
64
- expect(ast).toHaveProperty('filePath');
65
- expect((ast as { language: unknown }).language).toBe('objectivec');
66
- });
67
-
68
- /**
69
- * @test REQ-QG-001
70
- * @covers AC-QG-001-06
71
- */
72
- it('should extract Objective-C instance methods', () => {
73
- (readFileSync as Mock).mockReturnValue(`
74
- @implementation Calculator
75
- - (int)add:(int)a to:(int)b {
76
- return a + b;
77
- }
78
- - (void)printResult {
79
- NSLog(@"Result");
80
- }
81
- @end
82
- `);
83
- const adapter = new ObjectiveCAdapter('Calculator.m');
84
- const functions = adapter.extractFunctions();
85
- expect(Array.isArray(functions)).toBe(true);
86
- expect(functions.length).toBeGreaterThan(0);
87
- });
88
-
89
- /**
90
- * @test REQ-QG-001
91
- * @covers AC-QG-001-06
92
- */
93
- it('should extract Objective-C class methods', () => {
94
- (readFileSync as Mock).mockReturnValue(`
95
- @implementation StringUtils
96
- + (NSString *)trim:(NSString *)str {
97
- return [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
98
- }
99
- + (BOOL)isEmpty:(NSString *)str {
100
- return [str length] == 0;
101
- }
102
- @end
103
- `);
104
- const adapter = new ObjectiveCAdapter('StringUtils.m');
105
- const functions = adapter.extractFunctions();
106
- expect(Array.isArray(functions)).toBe(true);
107
- });
108
-
109
- /**
110
- * @test REQ-QG-001
111
- * @covers AC-QG-001-06
112
- */
113
- it('should extract C functions from Objective-C file', () => {
114
- (readFileSync as Mock).mockReturnValue(`
115
- int helperFunction(int x) {
116
- return x * 2;
117
- }
118
-
119
- void logDebug(const char *msg) {
120
- printf("%s\\n", msg);
121
- }
122
-
123
- @implementation Helper
124
- - (void)process {
125
- int result = helperFunction(5);
126
- }
127
- @end
128
- `);
129
- const adapter = new ObjectiveCAdapter('Helper.m');
130
- const functions = adapter.extractFunctions();
131
- expect(Array.isArray(functions)).toBe(true);
132
- expect(functions.some(fn => (fn as {type: string}).type === 'function')).toBe(true);
133
- });
134
-
135
- /**
136
- * @test REQ-QG-001
137
- * @covers AC-QG-001-06
138
- */
139
- it('should extract @implementation declarations', () => {
140
- (readFileSync as Mock).mockReturnValue(`
141
- @implementation MyClass
142
- - (void)doSomething {}
143
- @end
144
- `);
145
- const adapter = new ObjectiveCAdapter('MyClass.m');
146
- const classes = adapter.extractClasses();
147
- expect(Array.isArray(classes)).toBe(true);
148
- expect(classes.some(cls => (cls as {name: string}).name === 'MyClass')).toBe(true);
149
- expect(classes.some(cls => (cls as {type: string}).type === 'implementation')).toBe(true);
150
- });
151
-
152
- /**
153
- * @test REQ-QG-001
154
- * @covers AC-QG-001-06
155
- */
156
- it('should extract @interface declarations', () => {
157
- (readFileSync as Mock).mockReturnValue(`
158
- @interface MyProtocol
159
- - (void)requiredMethod;
160
- @end
161
- `);
162
- const adapter = new ObjectiveCAdapter('MyProtocol.m');
163
- const classes = adapter.extractClasses();
164
- expect(Array.isArray(classes)).toBe(true);
165
- expect(classes.some(cls => (cls as {name: string}).name === 'MyProtocol')).toBe(true);
166
- expect(classes.some(cls => (cls as {type: string}).type === 'interface')).toBe(true);
167
- });
168
-
169
- /**
170
- * @test REQ-QG-001
171
- * @covers AC-QG-001-06
172
- */
173
- it('should handle multiple @implementation blocks', () => {
174
- (readFileSync as Mock).mockReturnValue(`
175
- @implementation FirstClass
176
- - (void)method1 {}
177
- @end
178
-
179
- @implementation SecondClass
180
- - (void)method2 {}
181
- @end
182
- `);
183
- const adapter = new ObjectiveCAdapter('Multiple.m');
184
- const classes = adapter.extractClasses();
185
- expect(Array.isArray(classes)).toBe(true);
186
- expect(classes.length).toBeGreaterThanOrEqual(2);
187
- });
188
-
189
- /**
190
- * @test REQ-QG-001
191
- * @covers AC-QG-001-06
192
- */
193
- it('should handle Objective-C inheritance syntax', () => {
194
- (readFileSync as Mock).mockReturnValue(`
195
- @interface ChildClass : ParentClass
196
- - (void)overrideMethod;
197
- @end
198
- `);
199
- const adapter = new ObjectiveCAdapter('ChildClass.m');
200
- const classes = adapter.extractClasses();
201
- expect(Array.isArray(classes)).toBe(true);
202
- expect(classes.some(cls => (cls as {name: string}).name === 'ChildClass')).toBe(true);
203
- });
204
-
205
- /**
206
- * @test REQ-QG-001
207
- * @covers AC-QG-001-06
208
- */
209
- it('should handle Objective-C categories', () => {
210
- (readFileSync as Mock).mockReturnValue(`
211
- @implementation NSString (Extensions)
212
- - (NSString *)reversed {
213
- // implementation
214
- }
215
- @end
216
- `);
217
- const adapter = new ObjectiveCAdapter('Extensions.m');
218
- const classes = adapter.extractClasses();
219
- expect(Array.isArray(classes)).toBe(true);
220
- });
221
-
222
- /**
223
- * @test REQ-QG-001
224
- * @covers AC-QG-001-06
225
- */
226
- it('should handle Objective-C properties', () => {
227
- (readFileSync as Mock).mockReturnValue(`
228
- @interface Person
229
- @property (nonatomic, strong) NSString *name;
230
- @property (nonatomic) NSInteger age;
231
- - (void)introduce;
232
- @end
233
-
234
- @implementation Person
235
- - (void)introduce {
236
- NSLog(@"Hi, I'm %@", self.name);
237
- }
238
- @end
239
- `);
240
- const adapter = new ObjectiveCAdapter('Person.m');
241
- const classes = adapter.extractClasses();
242
- expect(Array.isArray(classes)).toBe(true);
243
- const functions = adapter.extractFunctions();
244
- expect(Array.isArray(functions)).toBe(true);
245
- });
246
-
247
- /**
248
- * @test REQ-QG-001
249
- * @covers AC-QG-001-06, AC-QG-001-08
250
- */
251
- it('should handle Objective-C++ (.mm) files with C++ content', () => {
252
- (readFileSync as Mock).mockReturnValue(`
253
- #import <Foundation/Foundation.h>
254
- #include <vector>
255
-
256
- @implementation MixedClass {
257
- std::vector<int> _data;
258
- }
259
-
260
- - (void)processCpp {
261
- _data.push_back(42);
262
- }
263
-
264
- @end
265
- `);
266
- const adapter = new ObjectiveCAdapter('Mixed.mm');
267
- expect(adapter.detectLanguage()).toBe('objectivec');
268
- const classes = adapter.extractClasses();
269
- expect(Array.isArray(classes)).toBe(true);
270
- });
271
-
272
- /**
273
- * @test REQ-QG-001
274
- * @covers AC-QG-001-05
275
- */
276
- it('should count physical lines correctly', () => {
277
- (readFileSync as Mock).mockReturnValue('@implementation Test\n- (void)method {}\n@end');
278
- const adapter = new ObjectiveCAdapter('test.m');
279
- const lineCount = adapter.countLines();
280
- expect(lineCount).toBe(3);
281
- });
282
-
283
- /**
284
- * @test REQ-QG-001
285
- * @covers AC-QG-001-06
286
- */
287
- it('should handle empty file', () => {
288
- (readFileSync as Mock).mockReturnValue('');
289
- const adapter = new ObjectiveCAdapter('empty.m');
290
- const functions = adapter.extractFunctions();
291
- const classes = adapter.extractClasses();
292
- expect(functions.length).toBe(0);
293
- expect(classes.length).toBe(0);
294
- });
295
-
296
- /**
297
- * @test REQ-QG-001
298
- * @covers AC-QG-001-06
299
- */
300
- it('should handle Objective-C literals and modern syntax', () => {
301
- (readFileSync as Mock).mockReturnValue(`
302
- @implementation ModernObjC
303
- - (NSArray *)getItems {
304
- return @[ @"one", @"two", @"three" ];
305
- }
306
- - (NSDictionary *)getDict {
307
- return @{ @"key": @"value" };
308
- }
309
- - (NSNumber *)getNumber {
310
- return @42;
311
- }
312
- @end
313
- `);
314
- const adapter = new ObjectiveCAdapter('ModernObjC.m');
315
- const functions = adapter.extractFunctions();
316
- expect(Array.isArray(functions)).toBe(true);
317
- });
318
-
319
- /**
320
- * @test REQ-QG-001
321
- * @covers AC-QG-001-06
322
- */
323
- it('should handle Objective-C blocks', () => {
324
- (readFileSync as Mock).mockReturnValue(`
325
- @implementation BlockUser
326
- - (void)useBlock {
327
- void (^myBlock)(void) = ^{
328
- NSLog(@"Block executed");
329
- };
330
- myBlock();
331
- }
332
- @end
333
- `);
334
- const adapter = new ObjectiveCAdapter('BlockUser.m');
335
- const functions = adapter.extractFunctions();
336
- expect(Array.isArray(functions)).toBe(true);
337
- });
338
-
339
- /**
340
- * @test REQ-QG-001
341
- * @covers AC-QG-001-08
342
- */
343
- it('should handle preprocessor directives', () => {
344
- (readFileSync as Mock).mockReturnValue(`
345
- #import <Foundation/Foundation.h>
346
- #define MAX_SIZE 100
347
-
348
- #ifdef DEBUG
349
- @implementation DebugHelper
350
- - (void)logDebug {}
351
- @end
352
- #endif
353
- `);
354
- const adapter = new ObjectiveCAdapter('Preprocessor.m');
355
- expect(adapter.detectLanguage()).toBe('objectivec');
356
- });
357
-
358
- /**
359
- * @test REQ-QG-001
360
- * @covers AC-QG-001-05
361
- */
362
- it('should throw error when file cannot be read', () => {
363
- (readFileSync as Mock).mockImplementation(() => {
364
- throw new Error('Could not read file');
365
- });
366
-
367
- expect(() => {
368
- new ObjectiveCAdapter('nonexistent-file.m');
369
- }).toThrow('Could not read file:');
370
- });
371
-
372
- /**
373
- * @test REQ-QG-001
374
- * @covers AC-QG-001-06
375
- */
376
- it('should extract method with multiple parameters', () => {
377
- (readFileSync as Mock).mockReturnValue(`
378
- @implementation MultiParam
379
- - (void)drawRect:(CGRect)rect withColor:(UIColor *)color andAlpha:(float)alpha {
380
- // drawing code
381
- }
382
- @end
383
- `);
384
- const adapter = new ObjectiveCAdapter('MultiParam.m');
385
- const functions = adapter.extractFunctions();
386
- expect(Array.isArray(functions)).toBe(true);
387
- });
388
-
389
- /**
390
- * @test REQ-QG-001
391
- * @covers AC-QG-001-05, AC-QG-001-06
392
- */
393
- it('should handle static inline C functions', () => {
394
- (readFileSync as Mock).mockReturnValue(`
395
- static inline int fastAdd(int a, int b) {
396
- return a + b;
397
- }
398
-
399
- @implementation FastMath
400
- - (int)compute {
401
- return fastAdd(1, 2);
402
- }
403
- @end
404
- `);
405
- const adapter = new ObjectiveCAdapter('FastMath.m');
406
- const functions = adapter.extractFunctions();
407
- expect(Array.isArray(functions)).toBe(true);
408
- expect(functions.some(fn => (fn as {type: string}).type === 'function')).toBe(true);
409
- });
410
-
411
- /**
412
- * @test REQ-QG-001
413
- * @covers AC-QG-001-05
414
- */
415
- it('should extract line number for extracted elements', () => {
416
- (readFileSync as Mock).mockReturnValue(`
417
- @implementation LineTest
418
- - (void)firstMethod {}
419
- - (void)secondMethod {}
420
- @end
421
- `);
422
- const adapter = new ObjectiveCAdapter('LineTest.m');
423
- const functions = adapter.extractFunctions();
424
- expect(functions.every(fn => typeof (fn as {line: number}).line === 'number')).toBe(true);
425
- });
426
-
427
- /**
428
- * @test REQ-QG-001
429
- * @covers AC-QG-001-05
430
- */
431
- it('should extract code block for methods', () => {
432
- (readFileSync as Mock).mockReturnValue(`
433
- @implementation CodeBlockTest
434
- - (int)calculate {
435
- int result = 0;
436
- for (int i = 0; i < 10; i++) {
437
- result += i;
438
- }
439
- return result;
440
- }
441
- @end
442
- `);
443
- const adapter = new ObjectiveCAdapter('CodeBlockTest.m');
444
- const functions = adapter.extractFunctions();
445
- expect(functions.every(fn => typeof (fn as {code: string}).code === 'string')).toBe(true);
446
- });
447
-
448
- it('should fall back to super.detectLanguage for non-m/non-mm extensions', () => {
449
- (readFileSync as Mock).mockReturnValue('content');
450
- const adapter = new ObjectiveCAdapter('test.ts');
451
- expect(adapter.detectLanguage()).toBe('typescript');
452
- });
453
- });
@@ -1,84 +0,0 @@
1
- import { describe, it, expect, vi, type Mock } from 'vitest';;
2
- import { PythonAdapter } from '../python';
3
-
4
- vi.mock('fs', () => ({
5
- readFileSync: vi.fn(),
6
- existsSync: vi.fn(() => true),
7
- }));
8
-
9
- import { readFileSync } from 'fs';
10
-
11
- describe('PythonAdapter', () => {
12
- it('should implement the Adapter interface', () => {
13
- (readFileSync as Mock).mockReturnValue('def test_fn(): pass\nclass TestClass:');
14
- const adapter = new PythonAdapter('test.py');
15
-
16
- expect(adapter).toHaveProperty('detectLanguage');
17
- expect(adapter).toHaveProperty('parseAST');
18
- expect(adapter).toHaveProperty('extractFunctions');
19
- expect(adapter).toHaveProperty('extractClasses');
20
- expect(adapter).toHaveProperty('countLines');
21
- });
22
-
23
- it('should detect language as python for .py files', () => {
24
- (readFileSync as Mock).mockReturnValue('def test_fn(): pass');
25
- const adapter = new PythonAdapter('test.py');
26
- const detected = adapter.detectLanguage();
27
- expect(detected).toBe('python');
28
- });
29
-
30
- it('should parse Python file AST correctly', () => {
31
- (readFileSync as Mock).mockReturnValue('def test_fn(): pass\nclass TestClass:');
32
- const adapter = new PythonAdapter('test.py');
33
- const ast = adapter.parseAST();
34
- expect(ast).toHaveProperty('content');
35
- expect(ast).toHaveProperty('language');
36
- expect(ast).toHaveProperty('filePath');
37
- expect((ast as { language: unknown }).language).toBe('python');
38
- });
39
-
40
- it('should extract functions from Python AST', () => {
41
- (readFileSync as Mock).mockReturnValue('def test_fn(): pass\nclass TestClass:');
42
- const adapter = new PythonAdapter('test.py');
43
- const functions = adapter.extractFunctions();
44
- expect(Array.isArray(functions)).toBe(true);
45
- expect(functions.some(fn => (fn as {name: string}).name === 'test_fn')).toBe(true);
46
- });
47
-
48
- it('should extract classes from Python AST', () => {
49
- (readFileSync as Mock).mockReturnValue('def test_fn(): pass\nclass TestClass:');
50
- const adapter = new PythonAdapter('test.py');
51
- const classes = adapter.extractClasses();
52
- expect(Array.isArray(classes)).toBe(true);
53
- expect(classes.some(cls => (cls as {name: string}).name === 'TestClass')).toBe(true);
54
- });
55
-
56
- it('should count Python file physical lines', () => {
57
- (readFileSync as Mock).mockReturnValue('def test_fn(): pass\ndef test_fn2(): pass');
58
- const adapter = new PythonAdapter('test.py');
59
- const lineCount = adapter.countLines();
60
- expect(lineCount).toBe(2);
61
- });
62
-
63
- it('should handle async functions in Python', () => {
64
- (readFileSync as Mock).mockReturnValue('async def async_fn(): pass');
65
- const adapter = new PythonAdapter('test.py');
66
- const functions = adapter.extractFunctions();
67
- expect(Array.isArray(functions)).toBe(true);
68
- });
69
-
70
- it('should fall back to super.detectLanguage for non-py extensions', () => {
71
- (readFileSync as Mock).mockReturnValue('content');
72
- const adapter = new PythonAdapter('test.ts');
73
- expect(adapter.detectLanguage()).toBe('typescript');
74
- });
75
-
76
- it('should extract code block with indented body', () => {
77
- (readFileSync as Mock).mockReturnValue('def outer():\n inner()\n return 0');
78
- const adapter = new PythonAdapter('test.py');
79
- const functions = adapter.extractFunctions();
80
- expect(Array.isArray(functions)).toBe(true);
81
- expect(functions.length).toBe(1);
82
- expect((functions[0] as {name: string}).name).toBe('outer');
83
- });
84
- });
@@ -1,68 +0,0 @@
1
- import { describe, it, expect, vi, type Mock } from 'vitest';;
2
- import { SwiftAdapter } from '../swift';
3
-
4
- vi.mock('fs', () => ({
5
- readFileSync: vi.fn(),
6
- existsSync: vi.fn(() => true),
7
- }));
8
-
9
- import { readFileSync } from 'fs';
10
-
11
- describe('SwiftAdapter', () => {
12
- it('should implement the Adapter interface', () => {
13
- (readFileSync as Mock).mockReturnValue('func testFn() {}\nclass TestClass {}');
14
- const adapter = new SwiftAdapter('test.swift');
15
-
16
- expect(adapter).toHaveProperty('detectLanguage');
17
- expect(adapter).toHaveProperty('parseAST');
18
- expect(adapter).toHaveProperty('extractFunctions');
19
- expect(adapter).toHaveProperty('extractClasses');
20
- expect(adapter).toHaveProperty('countLines');
21
- });
22
-
23
- it('should detect language as swift for .swift files', () => {
24
- (readFileSync as Mock).mockReturnValue('func testFn() {}');
25
- const adapter = new SwiftAdapter('test.swift');
26
- const detected = adapter.detectLanguage();
27
- expect(detected).toBe('swift');
28
- });
29
-
30
- it('should parse Swift file AST correctly', () => {
31
- (readFileSync as Mock).mockReturnValue('func testFn() {}\nclass TestClass {}');
32
- const adapter = new SwiftAdapter('test.swift');
33
- const ast = adapter.parseAST();
34
- expect(ast).toHaveProperty('content');
35
- expect(ast).toHaveProperty('language');
36
- expect(ast).toHaveProperty('filePath');
37
- expect((ast as { language: unknown }).language).toBe('swift');
38
- });
39
-
40
- it('should extract functions from Swift AST', () => {
41
- (readFileSync as Mock).mockReturnValue('func testFn() {}\nclass TestClass {}');
42
- const adapter = new SwiftAdapter('test.swift');
43
- const functions = adapter.extractFunctions();
44
- expect(Array.isArray(functions)).toBe(true);
45
- expect(functions.some(fn => (fn as {name: string}).name === 'testFn')).toBe(true);
46
- });
47
-
48
- it('should extract classes from Swift AST', () => {
49
- (readFileSync as Mock).mockReturnValue('func testFn() {}\nclass TestClass {}');
50
- const adapter = new SwiftAdapter('test.swift');
51
- const classes = adapter.extractClasses();
52
- expect(Array.isArray(classes)).toBe(true);
53
- expect(classes.some(cls => (cls as {name: string}).name === 'TestClass')).toBe(true);
54
- });
55
-
56
- it('should count Swift file physical lines', () => {
57
- (readFileSync as Mock).mockReturnValue('func testFn() {}\nfunc testFn2() {}');
58
- const adapter = new SwiftAdapter('test.swift');
59
- const lineCount = adapter.countLines();
60
- expect(lineCount).toBe(2);
61
- });
62
-
63
- it('should fall back to super.detectLanguage for non-swift extensions', () => {
64
- (readFileSync as Mock).mockReturnValue('content');
65
- const adapter = new SwiftAdapter('test.py');
66
- expect(adapter.detectLanguage()).toBe('python');
67
- });
68
- });
@@ -1,53 +0,0 @@
1
- /**
2
- * @test REQ-620
3
- * @intent Prove the block-comment masking defect before fixing it. The masker's
4
- * contract is to preserve offsets and newlines so that `lineOf()` and
5
- * every line-numbered violation stays correct. A block comment
6
- * containing a newline is currently collapsed, shifting every later
7
- * line number up -- which silently mislabels every violation that
8
- * follows a multi-line comment in the file.
9
- * @covers AC-620-02
10
- */
11
- import { describe, it, expect, vi } from 'vitest';
12
- import { TypeScriptAdapter } from '../typescript';
13
-
14
- vi.mock('fs', () => ({
15
- readFileSync: vi.fn(),
16
- existsSync: vi.fn(() => true),
17
- }));
18
-
19
- import { readFileSync } from 'fs';
20
-
21
- function mask(src: string): string {
22
- (readFileSync as unknown as { mockReturnValue: (v: string) => void }).mockReturnValue(src);
23
- const adapter = new TypeScriptAdapter('probe.ts');
24
- return (adapter as unknown as { maskedSource: string }).maskedSource;
25
- }
26
-
27
- describe('AC-620-02: a multi-line block comment must not shift later line numbers', () => {
28
- it('keeps the newline inside a block comment', () => {
29
- const src = '/* a\nb */\nconst keep = 1;';
30
- const out = mask(src);
31
- expect(out.split('\n').length).toBe(src.split('\n').length);
32
- });
33
-
34
- it('keeps the line count when the block comment spans three lines', () => {
35
- const src = '/* one\ntwo\nthree */\nconst keep = 1;\nconst also = 2;';
36
- const out = mask(src);
37
- expect(out.split('\n').length).toBe(src.split('\n').length);
38
- expect(out).toContain('const keep = 1;');
39
- expect(out).toContain('const also = 2;');
40
- });
41
-
42
- it('reports a function line number that matches the physical source', () => {
43
- // The function starts on physical line 4; a collapsed block comment would
44
- // make the adapter report line 2.
45
- const src = ['/* a', 'b', 'c */', 'function target() {', ' return 1;', '}'].join('\n');
46
- (readFileSync as unknown as { mockReturnValue: (v: string) => void }).mockReturnValue(src);
47
- const adapter = new TypeScriptAdapter('probe.ts');
48
- const fns = adapter.extractFunctions() as Array<{ name: string; line: number }>;
49
- const target = fns.find((f) => f.name === 'target');
50
- expect(target).toBeDefined();
51
- expect(target!.line).toBe(4);
52
- });
53
- });