@boyingliu01/xp-gate 0.38.76 → 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 (104) 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/package.json +1 -1
  10. package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
  11. package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
  12. package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
  13. package/plugins/opencode/package.json +1 -1
  14. package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
  15. package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
  16. package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
  17. package/plugins/qoder/plugin.json +1 -1
  18. package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
  19. package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
  20. package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
  21. package/scripts/generate-mirrors.cjs +10 -0
  22. package/skills/delphi-review/AGENTS.md +1 -1
  23. package/skills/sprint-flow/AGENTS.md +1 -1
  24. package/skills/test-specification-alignment/AGENTS.md +1 -1
  25. package/mock-policy/__tests__/config.test.ts +0 -292
  26. package/mock-policy/__tests__/gate-m3.test.ts +0 -379
  27. package/mock-policy/__tests__/integration.test.ts +0 -600
  28. package/mock-policy/__tests__/mock-decision-engine.test.ts +0 -231
  29. package/mock-policy/__tests__/schema.test.ts +0 -239
  30. package/mock-policy/__tests__/scope-scanner.test.ts +0 -541
  31. package/mutation/__tests__/detect-ai-test.test.ts +0 -152
  32. package/mutation/__tests__/gate-m-survivors.test.ts +0 -167
  33. package/mutation/__tests__/gate-m.test.ts +0 -246
  34. package/mutation/__tests__/go-mutant-runner.test.ts +0 -288
  35. package/mutation/__tests__/gremlins-runner.test.ts +0 -167
  36. package/mutation/__tests__/init-baseline.test.ts +0 -347
  37. package/mutation/__tests__/mutation-mirror.test.ts +0 -49
  38. package/mutation/__tests__/mutmut-runner.test.ts +0 -1049
  39. package/mutation/__tests__/pitest-gradle-availability.test.ts +0 -74
  40. package/mutation/__tests__/pitest-runner.test.ts +0 -574
  41. package/mutation/__tests__/runners-index.test.ts +0 -162
  42. package/mutation/__tests__/stryker-runner.test.ts +0 -455
  43. package/mutation/__tests__/test-filter-parity.test.ts +0 -40
  44. package/mutation/__tests__/update-baseline.test.ts +0 -395
  45. package/principles/__tests__/adapter-metrics.test.ts +0 -292
  46. package/principles/__tests__/analyze-read-failure.test.ts +0 -70
  47. package/principles/__tests__/analyzer.test.ts +0 -367
  48. package/principles/__tests__/baseline-entry-total-warnings.test.ts +0 -76
  49. package/principles/__tests__/baseline-prune-timeout.test.ts +0 -71
  50. package/principles/__tests__/baseline-prune.test.ts +0 -399
  51. package/principles/__tests__/baseline-storage.test.ts +0 -188
  52. package/principles/__tests__/baseline.test.ts +0 -330
  53. package/principles/__tests__/boy-scout-init-baseline.test.ts +0 -167
  54. package/principles/__tests__/boy-scout-integration.test.ts +0 -355
  55. package/principles/__tests__/boy-scout.test.ts +0 -893
  56. package/principles/__tests__/cli-files-separators.test.ts +0 -69
  57. package/principles/__tests__/config-arch-group.test.ts +0 -106
  58. package/principles/__tests__/config-enforcement.test.ts +0 -470
  59. package/principles/__tests__/config-git-timeout.test.ts +0 -66
  60. package/principles/__tests__/config-merge-warnings.test.ts +0 -148
  61. package/principles/__tests__/config.test.ts +0 -78
  62. package/principles/__tests__/direct-execution.test.ts +0 -187
  63. package/principles/__tests__/index.test.ts +0 -94
  64. package/principles/__tests__/issue-587-java-member-count.test.ts +0 -279
  65. package/principles/__tests__/issue-588-lsp-java-false-positives.test.ts +0 -213
  66. package/principles/__tests__/lint-baseline.test.ts +0 -314
  67. package/principles/__tests__/many-exports-reexport.test.ts +0 -40
  68. package/principles/__tests__/reporter.test.ts +0 -660
  69. package/principles/__tests__/types.test.ts +0 -103
  70. package/principles/__tests__/warnings-baseline-budgets.test.ts +0 -74
  71. package/principles/adapters/__tests__/base.test.ts +0 -95
  72. package/principles/adapters/__tests__/cpp-code-block.test.ts +0 -123
  73. package/principles/adapters/__tests__/cpp-scanner-equivalence.test.ts +0 -67
  74. package/principles/adapters/__tests__/cpp.test.ts +0 -290
  75. package/principles/adapters/__tests__/dart.test.ts +0 -84
  76. package/principles/adapters/__tests__/go.test.ts +0 -68
  77. package/principles/adapters/__tests__/java.test.ts +0 -385
  78. package/principles/adapters/__tests__/kotlin.test.ts +0 -76
  79. package/principles/adapters/__tests__/objectivec.test.ts +0 -453
  80. package/principles/adapters/__tests__/python.test.ts +0 -84
  81. package/principles/adapters/__tests__/swift.test.ts +0 -68
  82. package/principles/adapters/__tests__/typescript-block-comment-lines.test.ts +0 -53
  83. package/principles/adapters/__tests__/typescript-masking.test.ts +0 -96
  84. package/principles/adapters/__tests__/typescript.test.ts +0 -116
  85. package/principles/rules/__tests__/clean-code/code-duplication.test.ts +0 -85
  86. package/principles/rules/__tests__/clean-code/deep-nesting.test.ts +0 -73
  87. package/principles/rules/__tests__/clean-code/god-class.test.ts +0 -109
  88. package/principles/rules/__tests__/clean-code/large-file.test.ts +0 -73
  89. package/principles/rules/__tests__/clean-code/long-function.test.ts +0 -81
  90. package/principles/rules/__tests__/clean-code/magic-numbers.test.ts +0 -68
  91. package/principles/rules/__tests__/clean-code/many-exports.test.ts +0 -123
  92. package/principles/rules/__tests__/clean-code/missing-error-handling.test.ts +0 -171
  93. package/principles/rules/__tests__/clean-code/too-many-params.test.ts +0 -58
  94. package/principles/rules/__tests__/clean-code/unused-imports.test.ts +0 -107
  95. package/principles/rules/__tests__/index.test.ts +0 -49
  96. package/principles/rules/__tests__/solid/dip.test.ts +0 -119
  97. package/principles/rules/__tests__/solid/isp.test.ts +0 -58
  98. package/principles/rules/__tests__/solid/issue-588-lsp-base-contract.test.ts +0 -252
  99. package/principles/rules/__tests__/solid/lsp.test.ts +0 -186
  100. package/principles/rules/__tests__/solid/ocp.test.ts +0 -67
  101. package/principles/rules/__tests__/solid/srp.test.ts +0 -87
  102. package/principles/rules/arch/__tests__/dependency.test.ts +0 -180
  103. package/principles/rules/arch/__tests__/naming.test.ts +0 -133
  104. package/principles/rules/arch/__tests__/shared.test.ts +0 -113
@@ -1,167 +0,0 @@
1
- /**
2
- * @test #544 - Gate M survivor detail for retro
3
- * @intent Verify Gate M reports per-file mutant outcome counts, not just a
4
- * score. #544: the pre-push journal carried
5
- * {skip_reason, duration_ms, mutation_score} and nothing else, so
6
- * `xp-gate retro` could not answer "which module has the most surviving
7
- * mutants". The data was never missing at the source: Stryker's JSON
8
- * reporter emits files[].nrOfSurvivedMutants, and stryker-types.ts
9
- * already declares it. The counts were dropped on the way through, then
10
- * buildMutationScores hardcoded {mutants: 0, killed: 0, survived: 0}.
11
- * Three zeros written next to a real score read as "measured: no
12
- * survivors" -- the same class of false success this project keeps
13
- * fixing, so unknown must stay absent, never zero.
14
- * @covers REQ-MUT-001 AC-001
15
- */
16
-
17
- import { describe, it, expect } from 'vitest';
18
- import {
19
- summarizeSurvivors,
20
- buildMutationScores,
21
- type StrykerReportLike,
22
- type SurvivorSummary,
23
- } from '../gate-m';
24
-
25
- /** A report shaped like Stryker's JSON output. */
26
- function report(files: Record<string, [number, number, number]>): StrykerReportLike {
27
- const entries = Object.entries(files);
28
- const totalMutants = entries.reduce((a, [, v]) => a + v[0], 0);
29
- const totalKilled = entries.reduce((a, [, v]) => a + v[1], 0);
30
- const totalSurvived = entries.reduce((a, [, v]) => a + v[2], 0);
31
- return {
32
- mutationScore: totalMutants > 0 ? parseFloat(((totalKilled / totalMutants) * 100).toFixed(1)) : 100,
33
- nrOfMutants: totalMutants,
34
- nrOfKilledMutants: totalKilled,
35
- nrOfSurvivedMutants: totalSurvived,
36
- files: Object.fromEntries(
37
- entries.map(([k, [m, kd, sv]]) => [k, {
38
- mutationScore: m > 0 ? parseFloat(((kd / m) * 100).toFixed(1)) : 100,
39
- nrOfMutants: m,
40
- nrOfKilledMutants: kd,
41
- nrOfSurvivedMutants: sv,
42
- }])
43
- ),
44
- };
45
- }
46
-
47
- /** Narrow to a non-null summary, failing the test with a clear message. */
48
- function expectSummary(s: SurvivorSummary | null): SurvivorSummary {
49
- expect(s).not.toBeNull();
50
- if (s === null) throw new Error('expected a survivor summary, got null');
51
- return s;
52
- }
53
-
54
- describe('AC-544: Gate M survivor detail', () => {
55
- it('reports per-file survived counts from the Stryker report', () => {
56
- const summary = expectSummary(summarizeSurvivors(report({
57
- 'src/mutation/gate-m.ts': [20, 8, 12],
58
- 'src/principles/analyzer.ts': [10, 3, 7],
59
- })));
60
-
61
- expect(summary.survivedByFile).toEqual({
62
- 'src/mutation/gate-m.ts': 12,
63
- 'src/principles/analyzer.ts': 7,
64
- });
65
- });
66
-
67
- it('totals killed, survived and mutants', () => {
68
- const summary = expectSummary(summarizeSurvivors(report({
69
- 'a.ts': [20, 8, 12],
70
- 'b.ts': [10, 3, 7],
71
- })));
72
-
73
- expect(summary.mutants).toBe(30);
74
- expect(summary.killed).toBe(11);
75
- expect(summary.survived).toBe(19);
76
- });
77
-
78
- it('orders survivedByFile worst-first so retro can take the top N', () => {
79
- const summary = expectSummary(summarizeSurvivors(report({
80
- 'small.ts': [10, 9, 1],
81
- 'worst.ts': [10, 0, 10],
82
- 'middle.ts': [10, 5, 5],
83
- })));
84
-
85
- expect(Object.keys(summary.survivedByFile)).toEqual(['worst.ts', 'middle.ts', 'small.ts']);
86
- });
87
-
88
- it('caps the per-file map so one huge repo cannot bloat the journal', () => {
89
- const many: Record<string, [number, number, number]> = {};
90
- // Every file must have at least one survivor, otherwise this asserts on a
91
- // smaller population than intended and the count below drifts.
92
- for (let i = 0; i < 50; i++) {
93
- const survived = (i % 9) + 1; // 1..9, never 0
94
- many[`f${i}.ts`] = [10, 10 - survived, survived];
95
- }
96
-
97
- const summary = expectSummary(summarizeSurvivors(report(many), { limit: 20 }));
98
-
99
- expect(Object.keys(summary.survivedByFile)).toHaveLength(20);
100
- // Truncation must be visible, not silent: a capped list that looks complete
101
- // is how "top 20" gets mistaken for "all files".
102
- expect(summary.truncated).toBe(true);
103
- expect(summary.filesWithSurvivors).toBe(50);
104
- });
105
-
106
- it('does not claim truncation when everything fits', () => {
107
- const summary = expectSummary(summarizeSurvivors(report({ 'a.ts': [10, 5, 5] }), { limit: 20 }));
108
- expect(summary.truncated).toBe(false);
109
- });
110
-
111
- it('omits files with zero survivors', () => {
112
- const summary = expectSummary(summarizeSurvivors(report({
113
- 'clean.ts': [10, 10, 0],
114
- 'dirty.ts': [10, 4, 6],
115
- })));
116
-
117
- expect(summary.survivedByFile).toEqual({ 'dirty.ts': 6 });
118
- });
119
-
120
- it('degrades to null instead of inventing zeros when no report is available', () => {
121
- // A missing/timed-out report must not be reported as "0 survivors" -- that
122
- // is the #544 failure repeated. null means unknown.
123
- expect(summarizeSurvivors(null)).toBeNull();
124
- });
125
-
126
- it('degrades to null when the report has no per-file section', () => {
127
- expect(summarizeSurvivors({
128
- mutationScore: 80,
129
- nrOfMutants: 10,
130
- nrOfKilledMutants: 8,
131
- nrOfSurvivedMutants: 2,
132
- })).toBeNull();
133
- });
134
- });
135
-
136
- describe('buildMutationScores carries the real counts (#544)', () => {
137
- it('reports measured mutant counts instead of hardcoded zeros', () => {
138
- // The original defect: the score was real and the three counts beside it
139
- // were literal zeros, which reads as "measured, no survivors". A consumer
140
- // that trusts `survived: 0` concludes the module is adequately tested.
141
- const scores = buildMutationScores({ 'a.ts': 78.4 }, {
142
- 'a.ts': { mutants: 30, killed: 25, survived: 5 },
143
- });
144
-
145
- expect(scores['a.ts']).toEqual({ score: 78.4, mutants: 30, killed: 25, survived: 5 });
146
- });
147
-
148
- it('leaves counts absent when they were never measured', () => {
149
- // Absent must stay absent -- not fabricated as zero.
150
- const scores = buildMutationScores({ 'a.ts': 50 }, {});
151
-
152
- expect(scores['a.ts'].score).toBe(50);
153
- expect(scores['a.ts'].mutants).toBeUndefined();
154
- expect(scores['a.ts'].survived).toBeUndefined();
155
- });
156
-
157
- it('keeps a genuinely zero-survivor file at zero', () => {
158
- // The distinction this whole change is about: measured zero is a real,
159
- // meaningful value and must survive the trip.
160
- const scores = buildMutationScores({ 'clean.ts': 100 }, {
161
- 'clean.ts': { mutants: 12, killed: 12, survived: 0 },
162
- });
163
-
164
- expect(scores['clean.ts'].survived).toBe(0);
165
- expect(scores['clean.ts'].mutants).toBe(12);
166
- });
167
- });
@@ -1,246 +0,0 @@
1
- /**
2
- * @test gate-m.ts - Mutation Testing Gate
3
- * @intent Verify CLI parsing, threshold evaluation, and result formatting
4
- * @covers REQ-MUT-001 AC-001, AC-002, AC-004
5
- */
6
-
7
- import { describe, it, expect, vi } from 'vitest';
8
- import fs from 'fs/promises';
9
-
10
- // The REAL filter is under test: the previous local duplicate diverged from
11
- // gate-m.ts (which is multi-language via registered runners) and could not
12
- // catch #480 for that exact reason.
13
- import { filterSourceFiles } from '../gate-m';
14
- import { detectAITestCharacteristics } from '../detect-ai-test';
15
-
16
- /* jscpd:disable */
17
- function parseArgs(args: string[]): {
18
- changedFiles: string[];
19
- baselinePath: string;
20
- criticalPathsPath: string;
21
- timeoutMs: number;
22
- } {
23
- const options = {
24
- changedFiles: [] as string[],
25
- baselinePath: '.mutation-baseline.json',
26
- criticalPathsPath: '.mutation-critical-paths',
27
- timeoutMs: 120000
28
- };
29
-
30
- for (let i = 0; i < args.length; i++) {
31
- switch (args[i]) {
32
- case '--changed-files': {
33
- const next = args[++i];
34
- if (next) {
35
- options.changedFiles = next.split(',').map(f => f.trim()).filter(Boolean);
36
- }
37
- break;
38
- }
39
- case '--baseline': {
40
- const next = args[++i];
41
- if (next) options.baselinePath = next;
42
- break;
43
- }
44
- case '--critical-paths': {
45
- const next = args[++i];
46
- if (next) options.criticalPathsPath = next;
47
- break;
48
- }
49
- case '--timeout': {
50
- const next = args[++i];
51
- if (next) options.timeoutMs = parseInt(next, 10);
52
- break;
53
- }
54
- }
55
- }
56
-
57
- return options;
58
- }
59
- /* jscpd:enable */
60
-
61
- vi.mock('fs/promises');
62
-
63
- describe('gate-m.ts - Mutation Testing Gate', () => {
64
- describe('parseArgs', () => {
65
- it('should parse --changed-files argument', () => {
66
- const result = parseArgs(['--changed-files', 'src/foo.ts,src/bar.ts']);
67
-
68
- expect(result.changedFiles).toEqual(['src/foo.ts', 'src/bar.ts']);
69
- });
70
-
71
- it('should parse --baseline argument', () => {
72
- const result = parseArgs(['--baseline', '.custom-baseline.json']);
73
-
74
- expect(result.baselinePath).toBe('.custom-baseline.json');
75
- });
76
-
77
- it('should parse --critical-paths argument', () => {
78
- const result = parseArgs(['--critical-paths', '.custom-paths.json']);
79
-
80
- expect(result.criticalPathsPath).toBe('.custom-paths.json');
81
- });
82
-
83
- it('should parse --timeout argument', () => {
84
- const result = parseArgs(['--timeout', '60000']);
85
-
86
- expect(result.timeoutMs).toBe(60000);
87
- });
88
-
89
- it('should use default values when no args provided', () => {
90
- const result = parseArgs([]);
91
-
92
- expect(result.changedFiles).toEqual([]);
93
- expect(result.baselinePath).toBe('.mutation-baseline.json');
94
- expect(result.criticalPathsPath).toBe('.mutation-critical-paths');
95
- expect(result.timeoutMs).toBe(120000);
96
- });
97
- });
98
-
99
- describe('filterSourceFiles', () => {
100
- it('should filter out .test.ts files', () => {
101
- const files = ['src/foo.ts', 'src/foo.test.ts'];
102
- const result = filterSourceFiles(files);
103
-
104
- expect(result).toEqual(['src/foo.ts']);
105
- });
106
-
107
- it('should filter out .d.ts files', () => {
108
- const files = ['src/foo.ts', 'src/foo.d.ts'];
109
- const result = filterSourceFiles(files);
110
-
111
- expect(result).toEqual(['src/foo.ts']);
112
- });
113
-
114
- it('should filter out files in /adapters/ directory', () => {
115
- const files = ['src/foo.ts', 'src/adapters/foo.ts'];
116
- const result = filterSourceFiles(files);
117
-
118
- expect(result).toEqual(['src/foo.ts']);
119
- });
120
-
121
- it('should filter out files with no registered runner', () => {
122
- const files = ['src/foo.ts', 'src/bar.js', 'src/baz.py'];
123
- const result = filterSourceFiles(files);
124
-
125
- // .ts (stryker) and .py (mutmut) have registered runners; .js has none.
126
- expect(result).toEqual(['src/foo.ts', 'src/baz.py']);
127
- });
128
-
129
- it('should filter out test-tree helpers not named *.test.* (#480)', () => {
130
- const files = [
131
- 'tests/e2e/helpers/e2e-server.ts',
132
- 'test/fixtures/setup.py',
133
- 'src/__tests__/harness.ts',
134
- 'tests\\e2e\\helpers\\e2e-server.ts',
135
- ];
136
- const result = filterSourceFiles(files);
137
-
138
- expect(result).toEqual([]);
139
-
140
- // The same exclusion inside a list that also carries production source:
141
- // `a/b/tests/` is a tree segment, and src/foo.ts must survive next to it.
142
- expect(filterSourceFiles(['src/foo.ts', 'a/b/tests/fixture-factory.ts'])).toEqual(['src/foo.ts']);
143
- });
144
-
145
- // Round 2 feasibility FC-03: only the test-tree regex read `normalized`, the
146
- // `.test.`/`_test.`, Java/Kotlin and /adapters/ checks read the raw path, so a
147
- // backslash-delimited path was judged by two different views of one string.
148
- it('should judge every exclusion against one separator view of the path (#480)', () => {
149
- for (const files of [
150
- ['src\\adapters\\router.ts'],
151
- ['src\\FooTest.java'],
152
- ['src/FooTest.java'],
153
- ['src/PaymentTests.kt'],
154
- ['src/BillingSpec.kts'],
155
- ['src\\helper_test.go'],
156
- ['src\\__tests__\\harness.ts'],
157
- ['src\\legacy.d.ts'],
158
- ]) {
159
- expect(filterSourceFiles(files)).toEqual([]);
160
- }
161
- });
162
-
163
- // The same class as #480: pre-push excludes *.spec.* from the mutation
164
- // candidate list, gate-m.ts did not, so the two definitions of "not
165
- // production code" already disagreed on spec-named test files.
166
- it('should filter out *.spec.* test files, as pre-push already does (#480)', () => {
167
- expect(filterSourceFiles(['src/login.spec.ts'])).toEqual([]);
168
- expect(filterSourceFiles(['src\\login.spec.ts'])).toEqual([]);
169
- });
170
-
171
- it('should not exclude production paths that merely contain "test" as a substring (#480)', () => {
172
- // Round 2 technical MN-02 asked whether the tree segment is anchored: it is,
173
- // so only a whole path segment named test/tests/__tests__ excludes.
174
- const files = [
175
- 'src/latest/foo.ts',
176
- 'src/protest/foo.ts',
177
- 'src/test-utils/foo.ts',
178
- 'src/mytests/foo.ts',
179
- 'testing/reporter.ts',
180
- 'src/test-data.ts',
181
- 'tests-helper.ts',
182
- ];
183
- const result = filterSourceFiles(files);
184
-
185
- expect(result).toEqual(files);
186
- });
187
-
188
- it('should return empty array when no source files', () => {
189
- const files = ['src/foo.test.ts', 'src/bar.d.ts'];
190
- const result = filterSourceFiles(files);
191
-
192
- expect(result).toEqual([]);
193
- });
194
- });
195
-
196
- describe('threshold evaluation', () => {
197
- it('should pass when score >= threshold', async () => {
198
- const mockContent = `
199
- import { describe, it, expect } from 'vitest';
200
-
201
- describe('Calculator', () => {
202
- it('should add two numbers', () => {
203
- expect(1 + 1).toBe(2);
204
- });
205
- });
206
- `;
207
-
208
- vi.mocked(fs.readFile).mockResolvedValue(mockContent);
209
-
210
- const result = await detectAITestCharacteristics('test.ts');
211
-
212
- expect(result.mockDensity).toBeLessThanOrEqual(30);
213
- expect(result.isAiGenerated).toBe(false);
214
- });
215
-
216
- it('should fail when score < threshold', async () => {
217
- const mockContent = `
218
- import { describe, it, expect, vi } from 'vitest';
219
-
220
- describe('UserService', () => {
221
- it('should fetch user', async () => {
222
- const mockFn = vi.fn();
223
- const mockResolve = vi.mockResolvedValue({ id: '1' });
224
- const mockReturn = vi.mockReturnValue({ id: '1' });
225
- const mockRej = vi.mockRejectedValue(new Error('fail'));
226
- const mockImpl = vi.mockImplementation(() => ({ id: '1' }));
227
- const spy = vi.spyOn(obj, 'method');
228
- const mock = vi.mock('module', () => ({ fn: vi.fn() }));
229
- const mReset = vi.mockReset();
230
- const mClear = vi.mockClear();
231
- const mRestore = vi.mockRestore();
232
-
233
- await expect(service.getUser('1')).resolves.toEqual({ id: '1' });
234
- });
235
- });
236
- `;
237
-
238
- vi.mocked(fs.readFile).mockResolvedValue(mockContent);
239
-
240
- const result = await detectAITestCharacteristics('test.ts');
241
-
242
- expect(result.mockDensity).toBeGreaterThan(30);
243
- expect(result.isAiGenerated).toBe(true);
244
- });
245
- });
246
- });
@@ -1,288 +0,0 @@
1
- /**
2
- * @test REQ-MUT-005 Go mutation runner
3
- * @intent Verify GoMutantRunner registration, availability checks, and JSON report parsing
4
- * @covers AC-MUT-005, AC-MUT-006
5
- */
6
-
7
- import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
8
- import { spawn, spawnSync, type ChildProcess } from 'child_process';
9
- import { writeFileSync, mkdirSync } from 'fs';
10
- import { tmpdir } from 'os';
11
- import { join } from 'path';
12
-
13
- vi.mock('child_process', () => ({
14
- spawn: vi.fn(),
15
- spawnSync: vi.fn(),
16
- }));
17
-
18
- describe('GoMutantRunner', () => {
19
- let GoMutantRunner: typeof import('../runners/go-mutant-runner').GoMutantRunner;
20
- let tmpDir: string;
21
-
22
- beforeEach(async () => {
23
- vi.clearAllMocks();
24
- tmpDir = join(tmpdir(), `xp-gate-go-test-${Date.now()}`);
25
- mkdirSync(tmpDir, { recursive: true });
26
- GoMutantRunner = (await import('../runners/go-mutant-runner')).GoMutantRunner;
27
- });
28
-
29
- afterEach(() => {
30
- try { process.kill(process.pid, 0); } catch { /* noop */ }
31
- });
32
-
33
- describe('name and extensions', () => {
34
- it('should have name "gomutants"', () => {
35
- const runner = new GoMutantRunner();
36
- expect(runner.name).toBe('gomutants');
37
- });
38
-
39
- it('should handle .go extension', () => {
40
- const runner = new GoMutantRunner();
41
- expect(runner.extensions).toContain('go');
42
- expect(runner.extensions).not.toContain('ts');
43
- expect(runner.extensions).not.toContain('py');
44
- });
45
- });
46
-
47
- describe('isAvailable', () => {
48
- it('should return true when gomutants is installed', async () => {
49
- vi.mocked(spawnSync).mockReturnValue({
50
- status: 0,
51
- output: [],
52
- pid: 0,
53
- signal: null,
54
- } as unknown as ReturnType<typeof spawnSync>);
55
-
56
- const runner = new GoMutantRunner();
57
- const result = await runner.isAvailable();
58
- expect(result).toBe(true);
59
- expect(spawnSync).toHaveBeenCalledWith('gomutants', ['--version'], {
60
- stdio: 'pipe',
61
- timeout: 5000,
62
- });
63
- });
64
-
65
- it('should return false when gomutants is not installed', async () => {
66
- vi.mocked(spawnSync).mockReturnValue({
67
- status: 1,
68
- output: [],
69
- pid: 0,
70
- signal: null,
71
- } as unknown as ReturnType<typeof spawnSync>);
72
-
73
- const runner = new GoMutantRunner();
74
- const result = await runner.isAvailable();
75
- expect(result).toBe(false);
76
- });
77
-
78
- it('should return false when spawnSync throws', async () => {
79
- vi.mocked(spawnSync).mockImplementation(() => {
80
- throw new Error('ENOENT');
81
- });
82
-
83
- const runner = new GoMutantRunner();
84
- const result = await runner.isAvailable();
85
- expect(result).toBe(false);
86
- });
87
- });
88
-
89
- describe('run', () => {
90
- it('should spawn gomutants with correct args', async () => {
91
- let closeCb: ((code: number | null) => void) | null = null;
92
- const mockChild = {
93
- stdout: { on: vi.fn() },
94
- stderr: { on: vi.fn() },
95
- on: vi.fn((event, cb) => {
96
- if (event === 'close') closeCb = cb;
97
- }),
98
- kill: vi.fn(),
99
- killed: false,
100
- };
101
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
102
-
103
- writeFileSync(join(tmpDir, '.gomutants-report.json'), JSON.stringify({
104
- test_efficacy: 80,
105
- mutants_total: 10,
106
- mutants_killed: 8,
107
- mutants_lived: 2,
108
- mutants_not_viable: 0,
109
- mutants_not_covered: 0,
110
- }));
111
-
112
- const runner = new GoMutantRunner();
113
- const promise = runner.run({
114
- files: ['src/main.go'],
115
- timeoutMs: 60000,
116
- cwd: tmpDir,
117
- });
118
-
119
- closeCb!(0);
120
- const result = await promise;
121
-
122
- expect(spawn).toHaveBeenCalledWith('gomutants', [
123
- '--output',
124
- expect.stringContaining('.gomutants-report.json'),
125
- '--quiet',
126
- ], expect.objectContaining({ cwd: tmpDir }));
127
-
128
- expect(result.timedOut).toBe(false);
129
- expect(result.report!.mutationScore).toBe(80);
130
- expect(result.report!.nrOfMutants).toBe(10);
131
- expect(result.report!.nrOfKilledMutants).toBe(8);
132
- expect(result.report!.nrOfSurvivedMutants).toBe(2);
133
- });
134
-
135
- it('should return timedOut=true when killed', async () => {
136
- const mockChild = {
137
- stdout: { on: vi.fn() },
138
- stderr: { on: vi.fn() },
139
- on: vi.fn((event, cb) => {
140
- if (event === 'close') setTimeout(() => cb(null), 10);
141
- }),
142
- kill: vi.fn(),
143
- killed: false,
144
- };
145
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
146
-
147
- const runner = new GoMutantRunner();
148
- const result = await runner.run({
149
- files: ['src/main.go'],
150
- timeoutMs: 100,
151
- cwd: tmpDir,
152
- });
153
-
154
- expect(result.timedOut).toBe(true);
155
- expect(result.report).toBeNull();
156
- });
157
-
158
- it('should return error when spawn fails', async () => {
159
- const mockChild = {
160
- stdout: { on: vi.fn() },
161
- stderr: { on: vi.fn() },
162
- on: vi.fn((event, cb) => {
163
- if (event === 'error') setTimeout(() => cb(new Error('spawn ENOENT')), 10);
164
- }),
165
- kill: vi.fn(),
166
- killed: false,
167
- };
168
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
169
-
170
- const runner = new GoMutantRunner();
171
- const result = await runner.run({
172
- files: ['src/main.go'],
173
- timeoutMs: 60000,
174
- cwd: tmpDir,
175
- });
176
-
177
- expect(result.report).toBeNull();
178
- expect(result.timedOut).toBe(false);
179
- expect(result.error).toBe('spawn ENOENT');
180
- });
181
-
182
- it('should handle gomutants exit code 10 (below threshold) with report', async () => {
183
- let stderrCb: ((d: Buffer) => void) | null = null;
184
- const mockChild = {
185
- stdout: { on: vi.fn() },
186
- stderr: { on: vi.fn((_event: string, cb: (d: Buffer) => void) => { stderrCb = cb; }) },
187
- on: vi.fn((event, cb) => {
188
- if (event === 'close') {
189
- setTimeout(() => {
190
- if (stderrCb) stderrCb(Buffer.from('below threshold'));
191
- cb(10);
192
- }, 10);
193
- }
194
- }),
195
- kill: vi.fn(),
196
- killed: false,
197
- };
198
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
199
-
200
- writeFileSync(join(tmpDir, '.gomutants-report.json'), JSON.stringify({
201
- test_efficacy: 45,
202
- mutants_total: 50,
203
- mutants_killed: 22,
204
- mutants_lived: 18,
205
- mutants_not_covered: 10,
206
- }));
207
-
208
- const runner = new GoMutantRunner();
209
- const result = await runner.run({
210
- files: ['src/main.go'],
211
- timeoutMs: 60000,
212
- cwd: tmpDir,
213
- });
214
-
215
- expect(result.timedOut).toBe(false);
216
- expect(result.report).not.toBeNull();
217
- expect(result.report!.mutationScore).toBe(45);
218
- expect(result.error).toBeTruthy();
219
- });
220
-
221
- it('should return null report when report file does not exist', async () => {
222
- const mockChild = {
223
- stdout: { on: vi.fn() },
224
- stderr: { on: vi.fn() },
225
- on: vi.fn((event, cb) => {
226
- if (event === 'close') setTimeout(() => cb(0), 10);
227
- }),
228
- kill: vi.fn(),
229
- killed: false,
230
- };
231
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
232
-
233
- const runner = new GoMutantRunner();
234
- const result = await runner.run({
235
- files: ['src/main.go'],
236
- timeoutMs: 60000,
237
- cwd: tmpDir,
238
- });
239
-
240
- expect(result.report).toBeNull();
241
- expect(result.timedOut).toBe(false);
242
- });
243
-
244
- it('should parse files array from report', async () => {
245
- let closeCb: ((code: number | null) => void) | null = null;
246
- const mockChild = {
247
- stdout: { on: vi.fn() },
248
- stderr: { on: vi.fn() },
249
- on: vi.fn((event, cb) => {
250
- if (event === 'close') closeCb = cb;
251
- }),
252
- kill: vi.fn(),
253
- killed: false,
254
- };
255
- vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
256
-
257
- writeFileSync(join(tmpDir, '.gomutants-report.json'), JSON.stringify({
258
- test_efficacy: 80,
259
- mutants_total: 20,
260
- mutants_killed: 16,
261
- mutants_lived: 4,
262
- mutants_not_viable: 0,
263
- mutants_not_covered: 0,
264
- files: [
265
- {
266
- file_name: 'calculator.go',
267
- mutations: Array(12).fill({ status: 'KILLED' }).concat(Array(8).fill({ status: 'LIVED' })),
268
- },
269
- ],
270
- }));
271
-
272
- const runner = new GoMutantRunner();
273
- const promise = runner.run({
274
- files: ['src/calculator.go'],
275
- timeoutMs: 60000,
276
- cwd: tmpDir,
277
- });
278
-
279
- closeCb!(0);
280
- const result = await promise;
281
-
282
- expect(result.report).not.toBeNull();
283
- expect(result.report!.files).toBeDefined();
284
- expect(result.report!.files!['calculator.go'].mutationScore).toBe(60);
285
- expect(result.report!.files!['calculator.go'].nrOfMutants).toBe(20);
286
- });
287
- });
288
- });