@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.
- package/lib/__tests__/mirror-sync.test.js +387 -5
- package/lib/mattpocock-license-verdict.json +1 -1
- package/lib/mirror-sync.js +202 -15
- package/package.json +1 -1
- package/plugins/claude-code/.claude-plugin/plugin.json +1 -1
- package/plugins/claude-code/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/claude-code/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/claude-code/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/lib/hooks.d.ts +10 -1
- package/plugins/dsh/lib/hooks.d.ts.map +1 -1
- package/plugins/dsh/lib/hooks.js +56 -5
- package/plugins/dsh/lib/index.js +6 -1
- package/plugins/dsh/package.json +1 -1
- package/plugins/dsh/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/dsh/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/dsh/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/dsh/src/hooks.test.ts +70 -0
- package/plugins/dsh/src/hooks.ts +66 -5
- package/plugins/dsh/src/index.ts +6 -1
- package/plugins/opencode/package.json +1 -1
- package/plugins/opencode/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/opencode/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/opencode/skills/test-specification-alignment/AGENTS.md +1 -1
- package/plugins/qoder/plugin.json +1 -1
- package/plugins/qoder/skills/delphi-review/AGENTS.md +1 -1
- package/plugins/qoder/skills/sprint-flow/AGENTS.md +1 -1
- package/plugins/qoder/skills/test-specification-alignment/AGENTS.md +1 -1
- package/scripts/generate-mirrors.cjs +10 -0
- package/skills/delphi-review/AGENTS.md +1 -1
- package/skills/sprint-flow/AGENTS.md +1 -1
- package/skills/test-specification-alignment/AGENTS.md +1 -1
- package/mock-policy/__tests__/config.test.ts +0 -292
- package/mock-policy/__tests__/gate-m3.test.ts +0 -379
- package/mock-policy/__tests__/integration.test.ts +0 -600
- package/mock-policy/__tests__/mock-decision-engine.test.ts +0 -231
- package/mock-policy/__tests__/schema.test.ts +0 -239
- package/mock-policy/__tests__/scope-scanner.test.ts +0 -541
- package/mutation/__tests__/detect-ai-test.test.ts +0 -152
- package/mutation/__tests__/gate-m-survivors.test.ts +0 -167
- package/mutation/__tests__/gate-m.test.ts +0 -246
- package/mutation/__tests__/go-mutant-runner.test.ts +0 -288
- package/mutation/__tests__/gremlins-runner.test.ts +0 -167
- package/mutation/__tests__/init-baseline.test.ts +0 -347
- package/mutation/__tests__/mutation-mirror.test.ts +0 -49
- package/mutation/__tests__/mutmut-runner.test.ts +0 -1049
- package/mutation/__tests__/pitest-gradle-availability.test.ts +0 -74
- package/mutation/__tests__/pitest-runner.test.ts +0 -574
- package/mutation/__tests__/runners-index.test.ts +0 -162
- package/mutation/__tests__/stryker-runner.test.ts +0 -455
- package/mutation/__tests__/test-filter-parity.test.ts +0 -40
- package/mutation/__tests__/update-baseline.test.ts +0 -395
- package/principles/__tests__/adapter-metrics.test.ts +0 -292
- package/principles/__tests__/analyze-read-failure.test.ts +0 -70
- package/principles/__tests__/analyzer.test.ts +0 -367
- package/principles/__tests__/baseline-entry-total-warnings.test.ts +0 -76
- package/principles/__tests__/baseline-prune-timeout.test.ts +0 -71
- package/principles/__tests__/baseline-prune.test.ts +0 -399
- package/principles/__tests__/baseline-storage.test.ts +0 -188
- package/principles/__tests__/baseline.test.ts +0 -330
- package/principles/__tests__/boy-scout-init-baseline.test.ts +0 -167
- package/principles/__tests__/boy-scout-integration.test.ts +0 -355
- package/principles/__tests__/boy-scout.test.ts +0 -893
- package/principles/__tests__/cli-files-separators.test.ts +0 -69
- package/principles/__tests__/config-arch-group.test.ts +0 -106
- package/principles/__tests__/config-enforcement.test.ts +0 -470
- package/principles/__tests__/config-git-timeout.test.ts +0 -66
- package/principles/__tests__/config-merge-warnings.test.ts +0 -148
- package/principles/__tests__/config.test.ts +0 -78
- package/principles/__tests__/direct-execution.test.ts +0 -187
- package/principles/__tests__/index.test.ts +0 -94
- package/principles/__tests__/issue-587-java-member-count.test.ts +0 -279
- package/principles/__tests__/issue-588-lsp-java-false-positives.test.ts +0 -213
- package/principles/__tests__/lint-baseline.test.ts +0 -314
- package/principles/__tests__/many-exports-reexport.test.ts +0 -40
- package/principles/__tests__/reporter.test.ts +0 -660
- package/principles/__tests__/types.test.ts +0 -103
- package/principles/__tests__/warnings-baseline-budgets.test.ts +0 -74
- package/principles/adapters/__tests__/base.test.ts +0 -95
- package/principles/adapters/__tests__/cpp-code-block.test.ts +0 -123
- package/principles/adapters/__tests__/cpp-scanner-equivalence.test.ts +0 -67
- package/principles/adapters/__tests__/cpp.test.ts +0 -290
- package/principles/adapters/__tests__/dart.test.ts +0 -84
- package/principles/adapters/__tests__/go.test.ts +0 -68
- package/principles/adapters/__tests__/java.test.ts +0 -385
- package/principles/adapters/__tests__/kotlin.test.ts +0 -76
- package/principles/adapters/__tests__/objectivec.test.ts +0 -453
- package/principles/adapters/__tests__/python.test.ts +0 -84
- package/principles/adapters/__tests__/swift.test.ts +0 -68
- package/principles/adapters/__tests__/typescript-block-comment-lines.test.ts +0 -53
- package/principles/adapters/__tests__/typescript-masking.test.ts +0 -96
- package/principles/adapters/__tests__/typescript.test.ts +0 -116
- package/principles/rules/__tests__/clean-code/code-duplication.test.ts +0 -85
- package/principles/rules/__tests__/clean-code/deep-nesting.test.ts +0 -73
- package/principles/rules/__tests__/clean-code/god-class.test.ts +0 -109
- package/principles/rules/__tests__/clean-code/large-file.test.ts +0 -73
- package/principles/rules/__tests__/clean-code/long-function.test.ts +0 -81
- package/principles/rules/__tests__/clean-code/magic-numbers.test.ts +0 -68
- package/principles/rules/__tests__/clean-code/many-exports.test.ts +0 -123
- package/principles/rules/__tests__/clean-code/missing-error-handling.test.ts +0 -171
- package/principles/rules/__tests__/clean-code/too-many-params.test.ts +0 -58
- package/principles/rules/__tests__/clean-code/unused-imports.test.ts +0 -107
- package/principles/rules/__tests__/index.test.ts +0 -49
- package/principles/rules/__tests__/solid/dip.test.ts +0 -119
- package/principles/rules/__tests__/solid/isp.test.ts +0 -58
- package/principles/rules/__tests__/solid/issue-588-lsp-base-contract.test.ts +0 -252
- package/principles/rules/__tests__/solid/lsp.test.ts +0 -186
- package/principles/rules/__tests__/solid/ocp.test.ts +0 -67
- package/principles/rules/__tests__/solid/srp.test.ts +0 -87
- package/principles/rules/arch/__tests__/dependency.test.ts +0 -180
- package/principles/rules/arch/__tests__/naming.test.ts +0 -133
- package/principles/rules/arch/__tests__/shared.test.ts +0 -113
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test REQ-457
|
|
3
|
-
* @intent Config resolution shells out to git on every principles run, inside a git
|
|
4
|
-
* hook. Every such call must be bounded: an unbounded one turns a wedged git
|
|
5
|
-
* into a commit that never returns. Covers gitToplevel(), which sits on the
|
|
6
|
-
* default path because gate-4.sh passes no --config.
|
|
7
|
-
* @covers AC-457-12
|
|
8
|
-
*
|
|
9
|
-
* Mocks child_process rather than shimming git on PATH -- execFileSync resolves PATH
|
|
10
|
-
* without PATHEXT unless shell is set, so a stub binary is silently ignored and the
|
|
11
|
-
* test would pass while proving nothing.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
15
|
-
|
|
16
|
-
const execFileSyncMock = vi.fn();
|
|
17
|
-
|
|
18
|
-
vi.mock('child_process', () => ({
|
|
19
|
-
execFileSync: (...args: unknown[]) => execFileSyncMock(...args),
|
|
20
|
-
}));
|
|
21
|
-
|
|
22
|
-
import { loadConfig } from '../config';
|
|
23
|
-
|
|
24
|
-
/** Long enough for a healthy `git rev-parse`, short enough not to wedge a hook. */
|
|
25
|
-
const MAX_ACCEPTABLE_GIT_TIMEOUT_MS = 30_000;
|
|
26
|
-
|
|
27
|
-
describe('config loading git invocation (#457)', () => {
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
execFileSyncMock.mockReset();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('AC-457-12: bounds every git call with a timeout', async () => {
|
|
33
|
-
execFileSyncMock.mockReturnValue('/tmp/project\n');
|
|
34
|
-
|
|
35
|
-
await loadConfig();
|
|
36
|
-
|
|
37
|
-
expect(execFileSyncMock).toHaveBeenCalled();
|
|
38
|
-
for (const call of execFileSyncMock.mock.calls) {
|
|
39
|
-
const options = call[2] as { timeout?: number };
|
|
40
|
-
expect(typeof options.timeout).toBe('number');
|
|
41
|
-
expect(options.timeout).toBeGreaterThan(0);
|
|
42
|
-
expect(options.timeout).toBeLessThanOrEqual(MAX_ACCEPTABLE_GIT_TIMEOUT_MS);
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('AC-457-12: a hung git falls back to defaults instead of hanging the hook', async () => {
|
|
47
|
-
execFileSyncMock.mockImplementation(() => {
|
|
48
|
-
const error = new Error('spawnSync git ETIMEDOUT') as Error & { signal?: string };
|
|
49
|
-
error.signal = 'SIGTERM';
|
|
50
|
-
throw error;
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// Must resolve. If this rejects or blocks, the pre-commit hook hangs with it.
|
|
54
|
-
// Compared against the same resolution with a working git so the assertion does
|
|
55
|
-
// not hard-code a threshold the repo's own .principlesrc may override.
|
|
56
|
-
execFileSyncMock.mockReturnValue('/tmp/project\n');
|
|
57
|
-
const baseline = await loadConfig();
|
|
58
|
-
execFileSyncMock.mockImplementation(() => {
|
|
59
|
-
throw Object.assign(new Error('spawnSync git ETIMEDOUT'), { signal: 'SIGTERM' });
|
|
60
|
-
});
|
|
61
|
-
const degraded = await loadConfig();
|
|
62
|
-
|
|
63
|
-
expect(degraded.rules['clean-code']['large-file'].threshold)
|
|
64
|
-
.toBe(baseline.rules['clean-code']['large-file'].threshold);
|
|
65
|
-
});
|
|
66
|
-
});
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test REQ-620
|
|
3
|
-
* @intent Pin mergeRule's mistyped-override handling, which had NO coverage
|
|
4
|
-
* before this change: nothing asserted the warning text or the
|
|
5
|
-
* keep-the-default outcome for a bad .principlesrc value. That gap
|
|
6
|
-
* meant the four per-key loops could be consolidated into one guarded
|
|
7
|
-
* loop without any test noticing, so these tests are what makes the
|
|
8
|
-
* consolidation verifiable rather than merely plausible.
|
|
9
|
-
*
|
|
10
|
-
* Two properties per key category:
|
|
11
|
-
* 1. a correctly-typed override is applied;
|
|
12
|
-
* 2. a mistyped one is REJECTED and the default survives, with a
|
|
13
|
-
* warning naming the rule and the key.
|
|
14
|
-
* Property 2 is the one with teeth: silently accepting a bad value
|
|
15
|
-
* would let a project believe it tightened a gate.
|
|
16
|
-
*
|
|
17
|
-
* .principlesrc is JSON (config.ts parses it with JSON.parse), so the
|
|
18
|
-
* fixtures are JSON objects rather than YAML text.
|
|
19
|
-
* @covers AC-620-05
|
|
20
|
-
*/
|
|
21
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
22
|
-
import fs from 'node:fs';
|
|
23
|
-
import os from 'node:os';
|
|
24
|
-
import path from 'node:path';
|
|
25
|
-
import { loadConfig, getDefaultConfig } from '../config';
|
|
26
|
-
|
|
27
|
-
let tmpDirs: string[] = [];
|
|
28
|
-
let warnings: string[];
|
|
29
|
-
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
tmpDirs = [];
|
|
32
|
-
warnings = [];
|
|
33
|
-
// config.ts reports through process.stderr.write, not console.warn, so the
|
|
34
|
-
// spy has to sit on the stream. (Mocking console.warn instead silently
|
|
35
|
-
// captured nothing and made every "must warn" assertion look like a bug.)
|
|
36
|
-
vi.spyOn(process.stderr, 'write').mockImplementation((chunk: unknown) => {
|
|
37
|
-
warnings.push(String(chunk));
|
|
38
|
-
return true;
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
afterEach(() => {
|
|
43
|
-
vi.restoreAllMocks();
|
|
44
|
-
for (const dir of tmpDirs) fs.rmSync(dir, { recursive: true, force: true });
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
function warnText(): string {
|
|
48
|
-
return warnings.join('\n');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** Default value of one key on `clean-code.long-function`. */
|
|
52
|
-
function defaultFor(key: string): unknown {
|
|
53
|
-
const rule = getDefaultConfig().rules['clean-code']['long-function'] as unknown as Record<string, unknown>;
|
|
54
|
-
return rule[key];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** Write a .principlesrc from RAW JSON text and load it unchanged. */
|
|
58
|
-
async function loadRaw(jsonText: string) {
|
|
59
|
-
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'xp-gate-cfg-'));
|
|
60
|
-
tmpDirs.push(dir);
|
|
61
|
-
const cfgPath = path.join(dir, '.principlesrc');
|
|
62
|
-
fs.writeFileSync(cfgPath, jsonText, 'utf8');
|
|
63
|
-
return loadConfig(cfgPath);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Write a .principlesrc overriding `clean-code.long-function` and load it. */
|
|
67
|
-
async function loadWithRule(overrides: Record<string, unknown>) {
|
|
68
|
-
return loadRaw(JSON.stringify({ rules: { 'clean-code': { 'long-function': overrides } } }));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
describe('AC-620-05: a mistyped rule override keeps the default and warns', () => {
|
|
72
|
-
it('accepts a well-typed numeric override (threshold)', async () => {
|
|
73
|
-
const merged = await loadWithRule({ threshold: 12 });
|
|
74
|
-
expect(merged.rules['clean-code']['long-function'].threshold).toBe(12);
|
|
75
|
-
expect(warnText()).not.toMatch(/threshold/);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('rejects a non-numeric threshold and keeps the default', async () => {
|
|
79
|
-
const merged = await loadWithRule({ threshold: 'not-a-number' });
|
|
80
|
-
expect(merged.rules['clean-code']['long-function'].threshold).toBe(defaultFor('threshold'));
|
|
81
|
-
expect(warnText()).toMatch(/threshold/);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('rejects a non-finite threshold and keeps the default', async () => {
|
|
85
|
-
// A guard that only checks `typeof value === 'number'` would accept these
|
|
86
|
-
// and compare every function against NaN (or Infinity, which nothing ever
|
|
87
|
-
// exceeds -- silently disabling the rule).
|
|
88
|
-
//
|
|
89
|
-
// These literals have to be written as raw JSON TEXT: JSON.stringify turns
|
|
90
|
-
// NaN and Infinity into `null`, so handing them to the object-based helper
|
|
91
|
-
// would inject null and the test would pass against a broken guard. That
|
|
92
|
-
// exact mistake made the first version of this test vacuous.
|
|
93
|
-
const fallback = defaultFor('threshold');
|
|
94
|
-
for (const literal of ['1e999', '-1e999']) {
|
|
95
|
-
warnings = [];
|
|
96
|
-
const merged = await loadRaw(
|
|
97
|
-
`{"rules":{"clean-code":{"long-function":{"threshold":${literal}}}}}`,
|
|
98
|
-
);
|
|
99
|
-
expect(merged.rules['clean-code']['long-function'].threshold).toBe(fallback);
|
|
100
|
-
expect(warnText()).toMatch(/threshold/);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('accepts a well-typed array override (exclude)', async () => {
|
|
105
|
-
const merged = await loadWithRule({ exclude: ['**/skip.ts'] });
|
|
106
|
-
expect(merged.rules['clean-code']['long-function'].exclude).toEqual(['**/skip.ts']);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it('rejects a scalar where an array is expected and keeps the default', async () => {
|
|
110
|
-
const merged = await loadWithRule({ exclude: '**/skip.ts' });
|
|
111
|
-
expect(merged.rules['clean-code']['long-function'].exclude).toEqual(defaultFor('exclude'));
|
|
112
|
-
expect(warnText()).toMatch(/exclude/);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('copies the accepted array instead of aliasing the parsed one', async () => {
|
|
116
|
-
// mergeRule spreads array candidates; sharing the reference would let a
|
|
117
|
-
// later mutation of the caller's array leak into the active config.
|
|
118
|
-
const source = ['**/skip.ts'];
|
|
119
|
-
const merged = await loadWithRule({ exclude: source });
|
|
120
|
-
expect(merged.rules['clean-code']['long-function'].exclude).not.toBe(source);
|
|
121
|
-
expect(merged.rules['clean-code']['long-function'].exclude).toEqual(source);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('accepts a well-typed enum override (severity)', async () => {
|
|
125
|
-
const merged = await loadWithRule({ severity: 'error' });
|
|
126
|
-
expect(merged.rules['clean-code']['long-function'].severity).toBe('error');
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it('rejects an out-of-vocabulary severity and keeps the default', async () => {
|
|
130
|
-
// The dangerous case: a project writes a severity it believes is blocking
|
|
131
|
-
// but misspells it. Silently keeping the default would let that belief stand.
|
|
132
|
-
const merged = await loadWithRule({ severity: 'fatal' });
|
|
133
|
-
expect(merged.rules['clean-code']['long-function'].severity).toBe(defaultFor('severity'));
|
|
134
|
-
expect(warnText()).toMatch(/severity/);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('rejects a non-boolean enabled flag and keeps the default', async () => {
|
|
138
|
-
const merged = await loadWithRule({ enabled: 'yes' });
|
|
139
|
-
expect(typeof merged.rules['clean-code']['long-function'].enabled).toBe('boolean');
|
|
140
|
-
expect(warnText()).toMatch(/enabled/);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
it('names the offending rule and key in the warning', async () => {
|
|
144
|
-
await loadWithRule({ severity: 'fatal' });
|
|
145
|
-
expect(warnText()).toContain('long-function');
|
|
146
|
-
expect(warnText()).toContain('severity');
|
|
147
|
-
});
|
|
148
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test config.ts - Configuration loader
|
|
3
|
-
* @intent Verify config loads thresholds correctly from .principlesrc
|
|
4
|
-
* @covers clean-code-solid-checker-design Section 11
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { describe, it, expect } from 'vitest';
|
|
8
|
-
import { loadConfig, getDefaultConfig } from '../config';
|
|
9
|
-
|
|
10
|
-
describe('config.ts - Configuration Loader', () => {
|
|
11
|
-
describe('getDefaultConfig', () => {
|
|
12
|
-
it('should return default thresholds matching design spec', () => {
|
|
13
|
-
const config = getDefaultConfig();
|
|
14
|
-
|
|
15
|
-
// Clean code thresholds from design Section 6
|
|
16
|
-
expect(config.rules['clean-code']['long-function'].threshold).toBe(50);
|
|
17
|
-
expect(config.rules['clean-code']['large-file'].threshold).toBe(1150);
|
|
18
|
-
expect(config.rules['clean-code']['god-class'].threshold).toBe(15);
|
|
19
|
-
expect(config.rules['clean-code']['deep-nesting'].threshold).toBe(4);
|
|
20
|
-
expect(config.rules['clean-code']['too-many-params'].threshold).toBe(7);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('should include magic numbers exclusion list', () => {
|
|
24
|
-
const config = getDefaultConfig();
|
|
25
|
-
const magicNumbersExclude = config.rules['clean-code']['magic-numbers'].exclude;
|
|
26
|
-
|
|
27
|
-
expect(magicNumbersExclude).toContain(0);
|
|
28
|
-
expect(magicNumbersExclude).toContain(1);
|
|
29
|
-
expect(magicNumbersExclude).toContain(-1);
|
|
30
|
-
expect(magicNumbersExclude).toContain(2);
|
|
31
|
-
expect(magicNumbersExclude).toContain(10);
|
|
32
|
-
expect(magicNumbersExclude).toContain(100);
|
|
33
|
-
expect(magicNumbersExclude).toContain(1000);
|
|
34
|
-
expect(magicNumbersExclude).toContain(60);
|
|
35
|
-
expect(magicNumbersExclude).toContain(24);
|
|
36
|
-
expect(magicNumbersExclude).toContain(7);
|
|
37
|
-
expect(magicNumbersExclude).toContain(30);
|
|
38
|
-
expect(magicNumbersExclude).toContain(365);
|
|
39
|
-
expect(magicNumbersExclude).toContain(256);
|
|
40
|
-
expect(magicNumbersExclude).toContain(1024);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should include SOLID thresholds from design Section 7', () => {
|
|
44
|
-
const config = getDefaultConfig();
|
|
45
|
-
|
|
46
|
-
expect(config.rules['solid']['srp'].methodThreshold).toBe(15);
|
|
47
|
-
expect(config.rules['solid']['isp'].methodThreshold).toBe(10);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should include DIP exclusion list', () => {
|
|
51
|
-
const config = getDefaultConfig();
|
|
52
|
-
const dipExclude = config.rules['solid']['dip'].exclude;
|
|
53
|
-
|
|
54
|
-
expect(dipExclude).toContain('Date');
|
|
55
|
-
expect(dipExclude).toContain('Map');
|
|
56
|
-
expect(dipExclude).toContain('Set');
|
|
57
|
-
expect(dipExclude).toContain('Error');
|
|
58
|
-
expect(dipExclude).toContain('Array');
|
|
59
|
-
expect(dipExclude).toContain('Object');
|
|
60
|
-
expect(dipExclude).toContain('Promise');
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe('loadConfig', () => {
|
|
65
|
-
it('should load .principlesrc from project root', async () => {
|
|
66
|
-
// This will fail until config.ts exists
|
|
67
|
-
const config = await loadConfig();
|
|
68
|
-
expect(config).toBeDefined();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should override defaults with project config', async () => {
|
|
72
|
-
// If .principlesrc has custom threshold, it should override
|
|
73
|
-
const config = await loadConfig();
|
|
74
|
-
// Actual test depends on .principlesrc content
|
|
75
|
-
expect(config.rules).toBeDefined();
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test REQ-DSH-012
|
|
3
|
-
* @intent 验证 CLI 入口的直接执行判据在 Windows 路径下成立:`isDirectExecution()`
|
|
4
|
-
* 必须用 pathToFileURL() 规范化路径,而不是字符串拼接 `file://${argv[1]}`,
|
|
5
|
-
* 否则 win32 下 `file://D:\a\b.ts` 与 `import.meta.url`(`file:///D:/a/b.ts`)
|
|
6
|
-
* 永不相等,Gate 4 永远静默通过(缺陷 #444)
|
|
7
|
-
* @covers AC-DSH-012-01
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { describe, it, expect } from 'vitest';
|
|
11
|
-
import * as fs from 'node:fs';
|
|
12
|
-
import * as os from 'node:os';
|
|
13
|
-
import { pathToFileURL } from 'node:url';
|
|
14
|
-
import { resolve, join } from 'node:path';
|
|
15
|
-
import { isDirectExecution } from '../index';
|
|
16
|
-
|
|
17
|
-
describe('isDirectExecution (Gate 4 CLI entry detection)', () => {
|
|
18
|
-
describe('Windows paths (#444)', () => {
|
|
19
|
-
it('matches a backslash Windows argv[1] against its import.meta.url', () => {
|
|
20
|
-
const argv1 = 'D:\\projects\\xp-gate\\src\\principles\\index.ts';
|
|
21
|
-
const metaUrl = pathToFileURL(argv1).href;
|
|
22
|
-
|
|
23
|
-
expect(isDirectExecution(argv1, metaUrl)).toBe(true);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('matches a forward-slash Windows argv[1]', () => {
|
|
27
|
-
const argv1 = 'D:/projects/xp-gate/src/principles/index.ts';
|
|
28
|
-
const metaUrl = pathToFileURL(argv1).href;
|
|
29
|
-
|
|
30
|
-
expect(isDirectExecution(argv1, metaUrl)).toBe(true);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('does NOT rely on naive file:// string concatenation', () => {
|
|
34
|
-
// The pre-fix implementation built `file://${argv1}`, which on Windows
|
|
35
|
-
// yields `file://D:\…` and can never equal the normalized metaUrl.
|
|
36
|
-
const argv1 = 'D:\\projects\\xp-gate\\src\\principles\\index.ts';
|
|
37
|
-
const naive = `file://${argv1}`;
|
|
38
|
-
const metaUrl = pathToFileURL(argv1).href;
|
|
39
|
-
|
|
40
|
-
expect(naive).not.toBe(metaUrl);
|
|
41
|
-
expect(isDirectExecution(argv1, metaUrl)).toBe(true);
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
describe('POSIX paths (no regression)', () => {
|
|
46
|
-
it('matches a POSIX argv[1] against its import.meta.url', () => {
|
|
47
|
-
const argv1 = '/home/u/xp-gate/src/principles/index.ts';
|
|
48
|
-
const metaUrl = pathToFileURL(argv1).href;
|
|
49
|
-
|
|
50
|
-
expect(isDirectExecution(argv1, metaUrl)).toBe(true);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe('negative cases', () => {
|
|
55
|
-
it('returns false when imported as a module (different file)', () => {
|
|
56
|
-
const argv1 = 'D:\\projects\\xp-gate\\src\\principles\\index.ts';
|
|
57
|
-
const metaUrl = pathToFileURL(
|
|
58
|
-
'D:\\projects\\xp-gate\\src\\principles\\analyzer.ts',
|
|
59
|
-
).href;
|
|
60
|
-
|
|
61
|
-
expect(isDirectExecution(argv1, metaUrl)).toBe(false);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('returns false when argv[1] is missing', () => {
|
|
65
|
-
expect(isDirectExecution(undefined, 'file:///x/y.ts')).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('returns false when there is no import.meta.url (CJS without require.main)', () => {
|
|
69
|
-
expect(isDirectExecution('D:\\a\\b.ts', undefined)).toBe(false);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('does not match on a mere suffix collision', () => {
|
|
73
|
-
const argv1 = 'D:\\projects\\xp-gate\\index.ts';
|
|
74
|
-
const metaUrl = pathToFileURL('D:\\other\\xp-gate\\index.ts').href;
|
|
75
|
-
|
|
76
|
-
expect(isDirectExecution(argv1, metaUrl)).toBe(false);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
describe('relative argv[1] (tsx passes the resolved path)', () => {
|
|
80
|
-
it('resolves a relative argv[1] before comparing', () => {
|
|
81
|
-
const rel = 'src/principles/index.ts';
|
|
82
|
-
const abs = resolve(process.cwd(), rel);
|
|
83
|
-
const metaUrl = pathToFileURL(abs).href;
|
|
84
|
-
|
|
85
|
-
expect(isDirectExecution(rel, metaUrl)).toBe(true);
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* @test REQ-DSH-017
|
|
91
|
-
* @intent 验证 boy-scout 的旧判据 `argv[1].includes('boy-scout')` 被替换后:
|
|
92
|
-
* 子串撞名不再误触发(误报方向),且 argv[1] 不含文件名的真实调用
|
|
93
|
-
* (CI 下的路径)能正确触发(漏报方向,缺陷 #453)
|
|
94
|
-
* @covers AC-DSH-017-01
|
|
95
|
-
*/
|
|
96
|
-
describe('substring matching is not used (#453)', () => {
|
|
97
|
-
const SELF = pathToFileURL(resolve('src/principles/boy-scout.ts')).href;
|
|
98
|
-
|
|
99
|
-
it('is false for an unrelated path that merely contains the name', () => {
|
|
100
|
-
// `includes('boy-scout')` was true here, wrongly starting the CLI.
|
|
101
|
-
const decoy = resolve('tmp/boy-scout-notes/run.ts');
|
|
102
|
-
expect(isDirectExecution(decoy, SELF)).toBe(false);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('is true for the real script even when argv[1] does not repeat the name', () => {
|
|
106
|
-
// CI shape: the runner is argv[1]; only URL comparison against this
|
|
107
|
-
// module's own URL identifies the entry point. The old guard no-oped
|
|
108
|
-
// here, so the CLI printed nothing and the stdout assertion failed.
|
|
109
|
-
const abs = resolve('src/principles/boy-scout.ts');
|
|
110
|
-
expect(isDirectExecution(abs, SELF)).toBe(true);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('is false when argv[1] is a different file in the same directory', () => {
|
|
114
|
-
const sibling = resolve('src/principles/boy-scout.test.ts');
|
|
115
|
-
expect(isDirectExecution(sibling, SELF)).toBe(false);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('has no default metaUrl -- import.meta.url must come from the caller', () => {
|
|
119
|
-
// `import.meta.url` is evaluated where it is WRITTEN. If this function
|
|
120
|
-
// defaulted metaUrl to its own import.meta.url, every caller would compare
|
|
121
|
-
// against direct-execution.ts and always get false, which is exactly the
|
|
122
|
-
// silent no-op (#453) it was written to remove. Calling with one argument
|
|
123
|
-
// must therefore not accidentally report "direct execution".
|
|
124
|
-
const oneArg = isDirectExecution as unknown as (a?: string) => boolean;
|
|
125
|
-
expect(oneArg(resolve('src/principles/boy-scout.ts'))).toBe(false);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it('matches through a symlinked path (Node realpaths ESM, argv[1] does not)', () => {
|
|
129
|
-
// Node resolves ESM module URLs through symlinks while argv[1] keeps the
|
|
130
|
-
// path the caller typed, so a bin shim / npm link / symlinked checkout
|
|
131
|
-
// compares unequal without realpath on both sides -- the same silent
|
|
132
|
-
// no-op class as #453.
|
|
133
|
-
const target = resolve('src/principles/direct-execution.ts');
|
|
134
|
-
const linkDir = fs.mkdtempSync(join(os.tmpdir(), 'xpgate-symlink-'));
|
|
135
|
-
const link = join(linkDir, 'entry.ts');
|
|
136
|
-
let linked = false;
|
|
137
|
-
try {
|
|
138
|
-
fs.symlinkSync(target, link, 'file');
|
|
139
|
-
linked = true;
|
|
140
|
-
} catch {
|
|
141
|
-
// Windows needs SeCreateSymbolicLinkPrivilege or Developer Mode. Creating
|
|
142
|
-
// a symlink is the only way to exercise this, so when it is unavailable we
|
|
143
|
-
// skip LOUDLY: silently returning here would leave an assertion that can
|
|
144
|
-
// never fail, which is worse than no test.
|
|
145
|
-
console.warn(
|
|
146
|
-
'[skip] symlink privilege unavailable on this host; ' +
|
|
147
|
-
'the realpath comparison in isDirectExecution is NOT covered by this run.',
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
if (!linked) {
|
|
151
|
-
// The non-symlinked case is still worth asserting on such hosts.
|
|
152
|
-
const metaUrl = pathToFileURL(fs.realpathSync(target)).href;
|
|
153
|
-
expect(isDirectExecution(target, metaUrl)).toBe(true);
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
try {
|
|
157
|
-
const metaUrl = pathToFileURL(fs.realpathSync(target)).href;
|
|
158
|
-
// argv[1] is the SYMLINK path; metaUrl is the REAL path.
|
|
159
|
-
expect(isDirectExecution(link, metaUrl)).toBe(true);
|
|
160
|
-
// And the link must not be mistaken for an unrelated file.
|
|
161
|
-
expect(isDirectExecution(link, pathToFileURL(resolve('src/principles/index.ts')).href)).toBe(
|
|
162
|
-
false,
|
|
163
|
-
);
|
|
164
|
-
} finally {
|
|
165
|
-
fs.rmSync(linkDir, { recursive: true, force: true });
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('realpath comparison is what makes the symlink case work', () => {
|
|
170
|
-
// Privilege-free proof that canonicalisation is load-bearing: build the two
|
|
171
|
-
// URL spellings a symlinked launch produces and show the raw comparison
|
|
172
|
-
// fails while the realpath'd one succeeds. Uses a junction-free path pair
|
|
173
|
-
// (forward vs backslashes plus a redundant segment) that resolves to the
|
|
174
|
-
// same file on every platform.
|
|
175
|
-
const target = resolve('src/principles/direct-execution.ts');
|
|
176
|
-
const verbatim = pathToFileURL(target).href;
|
|
177
|
-
const redundant = pathToFileURL(resolve('src/principles/../principles/direct-execution.ts')).href;
|
|
178
|
-
|
|
179
|
-
// `resolve` normalises the redundant segment, so both spellings agree --
|
|
180
|
-
// proving the comparison survives segment-level differences.
|
|
181
|
-
expect(redundant).toBe(verbatim);
|
|
182
|
-
expect(isDirectExecution(resolve('src/principles/../principles/direct-execution.ts'), verbatim)).toBe(
|
|
183
|
-
true,
|
|
184
|
-
);
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @test index.ts - CLI entry point
|
|
3
|
-
* @intent Verify CLI parses arguments and runs analysis correctly
|
|
4
|
-
* @covers clean-code-solid-checker-design Section 3 (Integration)
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
8
|
-
import { main, parseArgs } from '../index';
|
|
9
|
-
import { resetActiveConfig } from '../config';
|
|
10
|
-
|
|
11
|
-
describe('index.ts - CLI Entry Point', () => {
|
|
12
|
-
// Each main() call installs the config it loads. Production runs one process
|
|
13
|
-
// per invocation; this file calls main() repeatedly in one process, so the
|
|
14
|
-
// documented reset-per-run lifecycle is what keeps #457's replacement
|
|
15
|
-
// guardrail from reporting the test harness itself.
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
resetActiveConfig();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
describe('parseArgs', () => {
|
|
22
|
-
it('should parse --files argument', () => {
|
|
23
|
-
const args = ['--files', 'test.ts test2.ts'];
|
|
24
|
-
const options = parseArgs(args);
|
|
25
|
-
|
|
26
|
-
expect(options.files).toEqual(['test.ts', 'test2.ts']);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it('should parse --format argument', () => {
|
|
30
|
-
const args = ['--files', 'test.ts', '--format', 'json'];
|
|
31
|
-
const options = parseArgs(args);
|
|
32
|
-
|
|
33
|
-
expect(options.format).toBe('json');
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should parse --changed-only flag', () => {
|
|
37
|
-
const args = ['--files', 'test.ts', '--changed-only'];
|
|
38
|
-
const options = parseArgs(args);
|
|
39
|
-
|
|
40
|
-
expect(options.changedOnly).toBe(true);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should parse --show-score flag', () => {
|
|
44
|
-
const args = ['--files', 'test.ts', '--show-score'];
|
|
45
|
-
const options = parseArgs(args);
|
|
46
|
-
|
|
47
|
-
expect(options.showScore).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should default format to console', () => {
|
|
51
|
-
const args = ['--files', 'test.ts'];
|
|
52
|
-
const options = parseArgs(args);
|
|
53
|
-
|
|
54
|
-
expect(options.format).toBe('console');
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('should handle positional file arguments', () => {
|
|
58
|
-
const args = ['test.ts', 'test2.ts'];
|
|
59
|
-
const options = parseArgs(args);
|
|
60
|
-
|
|
61
|
-
expect(options.files).toEqual(['test.ts', 'test2.ts']);
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
describe('main', () => {
|
|
66
|
-
beforeEach(() => {
|
|
67
|
-
vi.spyOn(console, 'log').mockImplementation(() => undefined);
|
|
68
|
-
vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('should return 2 when no files provided', async () => {
|
|
72
|
-
const result = await main([]);
|
|
73
|
-
|
|
74
|
-
// 2, not 1. Exit 1 asserts "I examined files and found ERROR-severity
|
|
75
|
-
// violations"; a gate that sees 1 with an empty report reads a clean pass, so
|
|
76
|
-
// a miswired hook would announce PASSED having checked nothing (#457).
|
|
77
|
-
expect(result).toBe(2);
|
|
78
|
-
expect(console.error).toHaveBeenCalled();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('should run analysis on provided files', async () => {
|
|
82
|
-
const result = await main(['--files', 'src/principles/types.ts']);
|
|
83
|
-
|
|
84
|
-
expect(result).toBeDefined();
|
|
85
|
-
expect(console.log).toHaveBeenCalled();
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should return 0 when no violations', async () => {
|
|
89
|
-
const result = await main(['--files', 'src/principles/types.ts', '--format', 'json']);
|
|
90
|
-
|
|
91
|
-
expect(result).toBe(0);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
});
|