@eduardbar/drift 1.2.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gga +50 -0
- package/.github/actions/drift-review/README.md +60 -0
- package/.github/actions/drift-review/action.yml +131 -0
- package/.github/actions/drift-scan/README.md +28 -32
- package/.github/actions/drift-scan/action.yml +78 -14
- package/.github/workflows/publish-vscode.yml +3 -3
- package/.github/workflows/publish.yml +3 -3
- package/.github/workflows/review-pr.yml +94 -9
- package/AGENTS.md +75 -245
- package/CHANGELOG.md +28 -0
- package/README.md +308 -51
- package/ROADMAP.md +6 -5
- package/dist/analyzer.d.ts +2 -2
- package/dist/analyzer.js +420 -159
- package/dist/benchmark.d.ts +2 -0
- package/dist/benchmark.js +204 -0
- package/dist/cli.js +693 -67
- package/dist/config.js +16 -2
- package/dist/diff.js +66 -10
- package/dist/doctor.d.ts +5 -0
- package/dist/doctor.js +133 -0
- package/dist/format.d.ts +17 -0
- package/dist/format.js +45 -0
- package/dist/git.js +12 -0
- package/dist/guard-types.d.ts +57 -0
- package/dist/guard-types.js +2 -0
- package/dist/guard.d.ts +14 -0
- package/dist/guard.js +239 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.js +6 -1
- package/dist/init.d.ts +15 -0
- package/dist/init.js +273 -0
- package/dist/map-cycles.d.ts +2 -0
- package/dist/map-cycles.js +34 -0
- package/dist/map-svg.d.ts +19 -0
- package/dist/map-svg.js +97 -0
- package/dist/map.js +78 -138
- package/dist/metrics.js +70 -55
- package/dist/output-metadata.d.ts +13 -0
- package/dist/output-metadata.js +17 -0
- package/dist/plugins-capabilities.d.ts +4 -0
- package/dist/plugins-capabilities.js +21 -0
- package/dist/plugins-messages.d.ts +10 -0
- package/dist/plugins-messages.js +16 -0
- package/dist/plugins-rules.d.ts +9 -0
- package/dist/plugins-rules.js +137 -0
- package/dist/plugins.d.ts +2 -1
- package/dist/plugins.js +80 -28
- package/dist/printer.js +4 -0
- package/dist/reporter-constants.d.ts +16 -0
- package/dist/reporter-constants.js +39 -0
- package/dist/reporter.d.ts +3 -3
- package/dist/reporter.js +35 -55
- package/dist/review.d.ts +2 -1
- package/dist/review.js +4 -3
- package/dist/rules/comments.js +2 -2
- package/dist/rules/complexity.js +2 -7
- package/dist/rules/nesting.js +3 -13
- package/dist/rules/phase0-basic.js +10 -10
- package/dist/rules/phase3-configurable.js +23 -15
- package/dist/rules/shared.d.ts +2 -0
- package/dist/rules/shared.js +27 -3
- package/dist/saas/constants.d.ts +15 -0
- package/dist/saas/constants.js +48 -0
- package/dist/saas/dashboard.d.ts +8 -0
- package/dist/saas/dashboard.js +132 -0
- package/dist/saas/errors.d.ts +19 -0
- package/dist/saas/errors.js +37 -0
- package/dist/saas/helpers.d.ts +21 -0
- package/dist/saas/helpers.js +110 -0
- package/dist/saas/ingest.d.ts +3 -0
- package/dist/saas/ingest.js +249 -0
- package/dist/saas/organization.d.ts +5 -0
- package/dist/saas/organization.js +82 -0
- package/dist/saas/plan-change.d.ts +10 -0
- package/dist/saas/plan-change.js +15 -0
- package/dist/saas/store.d.ts +21 -0
- package/dist/saas/store.js +159 -0
- package/dist/saas/types.d.ts +191 -0
- package/dist/saas/types.js +2 -0
- package/dist/saas.d.ts +8 -82
- package/dist/saas.js +7 -320
- package/dist/sarif.d.ts +74 -0
- package/dist/sarif.js +122 -0
- package/dist/trust-advanced.d.ts +14 -0
- package/dist/trust-advanced.js +65 -0
- package/dist/trust-kpi-fs.d.ts +3 -0
- package/dist/trust-kpi-fs.js +141 -0
- package/dist/trust-kpi-parse.d.ts +7 -0
- package/dist/trust-kpi-parse.js +186 -0
- package/dist/trust-kpi-types.d.ts +16 -0
- package/dist/trust-kpi-types.js +2 -0
- package/dist/trust-kpi.d.ts +7 -0
- package/dist/trust-kpi.js +185 -0
- package/dist/trust-policy.d.ts +32 -0
- package/dist/trust-policy.js +160 -0
- package/dist/trust-render.d.ts +9 -0
- package/dist/trust-render.js +54 -0
- package/dist/trust-scoring.d.ts +9 -0
- package/dist/trust-scoring.js +208 -0
- package/dist/trust.d.ts +37 -0
- package/dist/trust.js +168 -0
- package/dist/types/app.d.ts +30 -0
- package/dist/types/app.js +2 -0
- package/dist/types/config.d.ts +25 -0
- package/dist/types/config.js +2 -0
- package/dist/types/core.d.ts +100 -0
- package/dist/types/core.js +2 -0
- package/dist/types/diff.d.ts +55 -0
- package/dist/types/diff.js +2 -0
- package/dist/types/plugin.d.ts +41 -0
- package/dist/types/plugin.js +2 -0
- package/dist/types/trust.d.ts +120 -0
- package/dist/types/trust.js +2 -0
- package/dist/types.d.ts +8 -211
- package/docs/PRD.md +187 -109
- package/docs/plugin-contract.md +61 -0
- package/docs/release-notes-draft.md +40 -0
- package/docs/rules-catalog.md +49 -0
- package/docs/trust-core-release-checklist.md +87 -0
- package/package.json +6 -3
- package/packages/vscode-drift/src/code-actions.ts +1 -1
- package/schemas/drift-ai-output.v1.json +162 -0
- package/schemas/drift-report.v1.json +151 -0
- package/schemas/drift-trust.v1.json +131 -0
- package/scripts/smoke-repo.mjs +394 -0
- package/src/analyzer.ts +484 -155
- package/src/benchmark.ts +266 -0
- package/src/cli.ts +840 -85
- package/src/config.ts +19 -2
- package/src/diff.ts +84 -10
- package/src/doctor.ts +173 -0
- package/src/format.ts +81 -0
- package/src/git.ts +16 -0
- package/src/guard-types.ts +64 -0
- package/src/guard.ts +324 -0
- package/src/index.ts +83 -0
- package/src/init.ts +298 -0
- package/src/map-cycles.ts +38 -0
- package/src/map-svg.ts +124 -0
- package/src/map.ts +111 -142
- package/src/metrics.ts +78 -59
- package/src/output-metadata.ts +30 -0
- package/src/plugins-capabilities.ts +36 -0
- package/src/plugins-messages.ts +35 -0
- package/src/plugins-rules.ts +296 -0
- package/src/plugins.ts +148 -27
- package/src/printer.ts +4 -0
- package/src/reporter-constants.ts +46 -0
- package/src/reporter.ts +64 -65
- package/src/review.ts +6 -4
- package/src/rules/comments.ts +2 -2
- package/src/rules/complexity.ts +2 -7
- package/src/rules/nesting.ts +3 -13
- package/src/rules/phase0-basic.ts +11 -12
- package/src/rules/phase3-configurable.ts +39 -26
- package/src/rules/shared.ts +31 -3
- package/src/saas/constants.ts +56 -0
- package/src/saas/dashboard.ts +172 -0
- package/src/saas/errors.ts +45 -0
- package/src/saas/helpers.ts +140 -0
- package/src/saas/ingest.ts +278 -0
- package/src/saas/organization.ts +99 -0
- package/src/saas/plan-change.ts +19 -0
- package/src/saas/store.ts +172 -0
- package/src/saas/types.ts +216 -0
- package/src/saas.ts +49 -433
- package/src/sarif.ts +232 -0
- package/src/trust-advanced.ts +99 -0
- package/src/trust-kpi-fs.ts +169 -0
- package/src/trust-kpi-parse.ts +219 -0
- package/src/trust-kpi-types.ts +19 -0
- package/src/trust-kpi.ts +210 -0
- package/src/trust-policy.ts +246 -0
- package/src/trust-render.ts +61 -0
- package/src/trust-scoring.ts +231 -0
- package/src/trust.ts +260 -0
- package/src/types/app.ts +30 -0
- package/src/types/config.ts +27 -0
- package/src/types/core.ts +105 -0
- package/src/types/diff.ts +61 -0
- package/src/types/plugin.ts +46 -0
- package/src/types/trust.ts +134 -0
- package/src/types.ts +78 -238
- package/tests/cli-sarif.test.ts +92 -0
- package/tests/diff.test.ts +124 -0
- package/tests/format.test.ts +157 -0
- package/tests/new-features.test.ts +80 -1
- package/tests/phase1-init-doctor-guard.test.ts +199 -0
- package/tests/plugins.test.ts +219 -0
- package/tests/rules.test.ts +23 -1
- package/tests/saas-foundation.test.ts +358 -1
- package/tests/sarif.test.ts +160 -0
- package/tests/trust-kpi.test.ts +147 -0
- package/tests/trust.test.ts +602 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { diffToSarif, toSarif } from '../src/sarif.js'
|
|
3
|
+
import type { DriftDiff, DriftReport } from '../src/types.js'
|
|
4
|
+
|
|
5
|
+
describe('toSarif', () => {
|
|
6
|
+
function createReport(): DriftReport {
|
|
7
|
+
return {
|
|
8
|
+
scannedAt: '2026-03-17T10:20:30.000Z',
|
|
9
|
+
targetPath: '/repo',
|
|
10
|
+
files: [{
|
|
11
|
+
path: 'src/app.ts',
|
|
12
|
+
score: 72,
|
|
13
|
+
issues: [
|
|
14
|
+
{
|
|
15
|
+
rule: 'large-file',
|
|
16
|
+
severity: 'error',
|
|
17
|
+
message: 'File exceeds threshold',
|
|
18
|
+
line: 14,
|
|
19
|
+
column: 3,
|
|
20
|
+
snippet: 'export function app() {}',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
rule: 'debug-leftover',
|
|
24
|
+
severity: 'warning',
|
|
25
|
+
message: 'console.log detected',
|
|
26
|
+
line: 22,
|
|
27
|
+
column: 1,
|
|
28
|
+
snippet: 'console.log(value)',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
rule: 'plugin-warning',
|
|
32
|
+
severity: 'info',
|
|
33
|
+
message: 'Plugin diagnostic',
|
|
34
|
+
line: 1,
|
|
35
|
+
column: 1,
|
|
36
|
+
snippet: 'app.ts',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
}],
|
|
40
|
+
totalIssues: 3,
|
|
41
|
+
totalScore: 72,
|
|
42
|
+
totalFiles: 1,
|
|
43
|
+
summary: {
|
|
44
|
+
errors: 1,
|
|
45
|
+
warnings: 1,
|
|
46
|
+
infos: 1,
|
|
47
|
+
byRule: {
|
|
48
|
+
'large-file': 1,
|
|
49
|
+
'debug-leftover': 1,
|
|
50
|
+
'plugin-warning': 1,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
quality: {
|
|
54
|
+
overall: 90,
|
|
55
|
+
dimensions: {
|
|
56
|
+
architecture: 91,
|
|
57
|
+
complexity: 87,
|
|
58
|
+
'ai-patterns': 92,
|
|
59
|
+
testing: 89,
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
maintenanceRisk: {
|
|
63
|
+
score: 20,
|
|
64
|
+
level: 'low',
|
|
65
|
+
hotspots: [],
|
|
66
|
+
signals: {
|
|
67
|
+
highComplexityFiles: 0,
|
|
68
|
+
filesWithoutNearbyTests: 0,
|
|
69
|
+
frequentChangeFiles: 0,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
it('maps drift severities to SARIF levels', () => {
|
|
76
|
+
const sarif = toSarif(createReport())
|
|
77
|
+
const levels = sarif.runs[0].results.map((result) => result.level)
|
|
78
|
+
|
|
79
|
+
expect(levels).toContain('error')
|
|
80
|
+
expect(levels).toContain('warning')
|
|
81
|
+
expect(levels).toContain('note')
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('builds SARIF minimal valid structure', () => {
|
|
85
|
+
const sarif = toSarif(createReport())
|
|
86
|
+
|
|
87
|
+
expect(sarif.version).toBe('2.1.0')
|
|
88
|
+
expect(sarif.runs).toHaveLength(1)
|
|
89
|
+
expect(sarif.runs[0].tool.driver.name).toBe('drift')
|
|
90
|
+
expect(Array.isArray(sarif.runs[0].results)).toBe(true)
|
|
91
|
+
expect(sarif.runs[0].results).toHaveLength(3)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('maps message and location fields for each issue', () => {
|
|
95
|
+
const sarif = toSarif(createReport())
|
|
96
|
+
const result = sarif.runs[0].results.find((item) => item.ruleId === 'large-file')
|
|
97
|
+
|
|
98
|
+
expect(result).toBeDefined()
|
|
99
|
+
expect(result?.message.text).toBe('File exceeds threshold')
|
|
100
|
+
expect(result?.locations[0].physicalLocation.artifactLocation.uri).toBe('src/app.ts')
|
|
101
|
+
expect(result?.locations[0].physicalLocation.region.startLine).toBe(14)
|
|
102
|
+
expect(result?.locations[0].physicalLocation.region.startColumn).toBe(3)
|
|
103
|
+
expect(result?.properties?.weight).toBe(20)
|
|
104
|
+
expect(result?.properties?.fileScore).toBe(72)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('maps diff newIssues to SARIF results', () => {
|
|
108
|
+
const diff: DriftDiff = {
|
|
109
|
+
baseRef: 'origin/main',
|
|
110
|
+
projectPath: '/repo',
|
|
111
|
+
scannedAt: '2026-03-17T10:20:30.000Z',
|
|
112
|
+
files: [
|
|
113
|
+
{
|
|
114
|
+
path: 'src/app.ts',
|
|
115
|
+
scoreBefore: 60,
|
|
116
|
+
scoreAfter: 72,
|
|
117
|
+
scoreDelta: 12,
|
|
118
|
+
newIssues: [
|
|
119
|
+
{
|
|
120
|
+
rule: 'debug-leftover',
|
|
121
|
+
severity: 'warning',
|
|
122
|
+
message: 'console.log detected',
|
|
123
|
+
line: 22,
|
|
124
|
+
column: 1,
|
|
125
|
+
snippet: 'console.log(value)',
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
resolvedIssues: [
|
|
129
|
+
{
|
|
130
|
+
rule: 'magic-number',
|
|
131
|
+
severity: 'info',
|
|
132
|
+
message: 'legacy issue resolved',
|
|
133
|
+
line: 10,
|
|
134
|
+
column: 5,
|
|
135
|
+
snippet: '42',
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
],
|
|
140
|
+
totalScoreBefore: 60,
|
|
141
|
+
totalScoreAfter: 72,
|
|
142
|
+
totalDelta: 12,
|
|
143
|
+
newIssuesCount: 1,
|
|
144
|
+
resolvedIssuesCount: 1,
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const sarif = diffToSarif(diff)
|
|
148
|
+
|
|
149
|
+
expect(sarif.version).toBe('2.1.0')
|
|
150
|
+
expect(sarif.runs[0].results).toHaveLength(1)
|
|
151
|
+
expect(sarif.runs[0].results[0]?.ruleId).toBe('debug-leftover')
|
|
152
|
+
expect(sarif.runs[0].results[0]?.locations[0]?.physicalLocation?.artifactLocation?.uri).toBe('src/app.ts')
|
|
153
|
+
expect(sarif.runs[0].results[0]?.properties?.baseRef).toBe('origin/main')
|
|
154
|
+
expect(sarif.runs[0].results[0]?.properties?.scoreDelta).toBe(12)
|
|
155
|
+
expect(sarif.runs[0].results[0]?.properties?.changeType).toBe('new-issue')
|
|
156
|
+
expect(sarif.runs[0].properties.baseRef).toBe('origin/main')
|
|
157
|
+
expect(sarif.runs[0].properties.newIssuesCount).toBe(1)
|
|
158
|
+
expect(sarif.runs[0].properties.resolvedIssuesCount).toBe(1)
|
|
159
|
+
})
|
|
160
|
+
})
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import { tmpdir } from 'node:os'
|
|
4
|
+
import { join } from 'node:path'
|
|
5
|
+
import { computeTrustKpis } from '../src/trust-kpi.js'
|
|
6
|
+
|
|
7
|
+
describe('trust KPI aggregation', () => {
|
|
8
|
+
let tempDir = ''
|
|
9
|
+
|
|
10
|
+
afterEach(() => {
|
|
11
|
+
if (tempDir) rmSync(tempDir, { recursive: true, force: true })
|
|
12
|
+
tempDir = ''
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('aggregates trust KPIs and diff trends from JSON artifacts', () => {
|
|
16
|
+
tempDir = mkdtempSync(join(tmpdir(), 'drift-kpi-aggregate-'))
|
|
17
|
+
|
|
18
|
+
writeFileSync(join(tempDir, 'trust-a.json'), JSON.stringify({
|
|
19
|
+
$schema: 'schemas/drift-trust.v1.json',
|
|
20
|
+
toolVersion: '1.3.0',
|
|
21
|
+
trust_score: 80,
|
|
22
|
+
merge_risk: 'LOW',
|
|
23
|
+
diff_context: {
|
|
24
|
+
baseRef: 'origin/main',
|
|
25
|
+
status: 'improved',
|
|
26
|
+
scoreDelta: -5,
|
|
27
|
+
newIssues: 1,
|
|
28
|
+
resolvedIssues: 3,
|
|
29
|
+
filesChanged: 2,
|
|
30
|
+
penalty: 0,
|
|
31
|
+
bonus: 7,
|
|
32
|
+
netImpact: -7,
|
|
33
|
+
},
|
|
34
|
+
}, null, 2))
|
|
35
|
+
|
|
36
|
+
writeFileSync(join(tempDir, 'trust-b.json'), JSON.stringify({
|
|
37
|
+
$schema: 'schemas/drift-trust.v1.json',
|
|
38
|
+
toolVersion: '1.3.0',
|
|
39
|
+
trust_score: 60,
|
|
40
|
+
merge_risk: 'MEDIUM',
|
|
41
|
+
diff_context: {
|
|
42
|
+
baseRef: 'origin/main',
|
|
43
|
+
status: 'regressed',
|
|
44
|
+
scoreDelta: 8,
|
|
45
|
+
newIssues: 4,
|
|
46
|
+
resolvedIssues: 1,
|
|
47
|
+
filesChanged: 3,
|
|
48
|
+
penalty: 9,
|
|
49
|
+
bonus: 0,
|
|
50
|
+
netImpact: 9,
|
|
51
|
+
},
|
|
52
|
+
}, null, 2))
|
|
53
|
+
|
|
54
|
+
writeFileSync(join(tempDir, 'trust-c.json'), JSON.stringify({
|
|
55
|
+
$schema: 'schemas/drift-trust.v1.json',
|
|
56
|
+
toolVersion: '1.3.0',
|
|
57
|
+
trust_score: 30,
|
|
58
|
+
merge_risk: 'HIGH',
|
|
59
|
+
}, null, 2))
|
|
60
|
+
|
|
61
|
+
const kpi = computeTrustKpis(tempDir)
|
|
62
|
+
|
|
63
|
+
expect(kpi.files).toEqual({ matched: 3, parsed: 3, malformed: 0 })
|
|
64
|
+
expect(kpi.prsEvaluated).toBe(3)
|
|
65
|
+
expect(kpi.mergeRiskDistribution).toEqual({ LOW: 1, MEDIUM: 1, HIGH: 1, CRITICAL: 0 })
|
|
66
|
+
expect(kpi.highRiskRatio).toBe(0.3333)
|
|
67
|
+
expect(kpi.trustScore).toEqual({ average: 56.67, median: 60, min: 30, max: 80 })
|
|
68
|
+
|
|
69
|
+
expect(kpi.diffTrend.available).toBe(true)
|
|
70
|
+
expect(kpi.diffTrend.samples).toBe(2)
|
|
71
|
+
expect(kpi.diffTrend.statusDistribution).toEqual({ improved: 1, regressed: 1, neutral: 0 })
|
|
72
|
+
expect(kpi.diffTrend.scoreDelta).toEqual({ average: 1.5, median: 1.5 })
|
|
73
|
+
expect(kpi.diffTrend.issues).toEqual({ newTotal: 5, resolvedTotal: 4, netNew: 1 })
|
|
74
|
+
expect(kpi.diagnostics).toEqual([])
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('keeps parsing resilient and reports diagnostics for malformed artifacts', () => {
|
|
78
|
+
tempDir = mkdtempSync(join(tmpdir(), 'drift-kpi-parse-'))
|
|
79
|
+
|
|
80
|
+
writeFileSync(join(tempDir, 'valid.json'), JSON.stringify({
|
|
81
|
+
$schema: 'schemas/drift-trust.v1.json',
|
|
82
|
+
toolVersion: '1.3.0',
|
|
83
|
+
trust_score: 70,
|
|
84
|
+
merge_risk: 'MEDIUM',
|
|
85
|
+
diff_context: {
|
|
86
|
+
scoreDelta: 2,
|
|
87
|
+
newIssues: 3,
|
|
88
|
+
resolvedIssues: 1,
|
|
89
|
+
},
|
|
90
|
+
}, null, 2))
|
|
91
|
+
|
|
92
|
+
writeFileSync(join(tempDir, 'broken.json'), '{"trust_score":70')
|
|
93
|
+
writeFileSync(join(tempDir, 'invalid-shape.json'), JSON.stringify({ trust_score: 70 }, null, 2))
|
|
94
|
+
writeFileSync(join(tempDir, 'bad-diff.json'), JSON.stringify({
|
|
95
|
+
$schema: 'schemas/drift-trust.v1.json',
|
|
96
|
+
toolVersion: '1.3.0',
|
|
97
|
+
trust_score: 50,
|
|
98
|
+
merge_risk: 'HIGH',
|
|
99
|
+
diff_context: 'oops',
|
|
100
|
+
}, null, 2))
|
|
101
|
+
|
|
102
|
+
writeFileSync(join(tempDir, 'wrong-schema.json'), JSON.stringify({
|
|
103
|
+
$schema: 'schemas/drift-report.v1.json',
|
|
104
|
+
toolVersion: '1.3.0',
|
|
105
|
+
trust_score: 65,
|
|
106
|
+
merge_risk: 'MEDIUM',
|
|
107
|
+
}, null, 2))
|
|
108
|
+
|
|
109
|
+
const kpi = computeTrustKpis(tempDir)
|
|
110
|
+
|
|
111
|
+
expect(kpi.files.matched).toBe(5)
|
|
112
|
+
expect(kpi.files.parsed).toBe(2)
|
|
113
|
+
expect(kpi.files.malformed).toBe(3)
|
|
114
|
+
expect(kpi.prsEvaluated).toBe(2)
|
|
115
|
+
|
|
116
|
+
const byCode = new Set(kpi.diagnostics.map((diagnostic) => diagnostic.code))
|
|
117
|
+
expect(byCode.has('parse-failed')).toBe(true)
|
|
118
|
+
expect(byCode.has('invalid-shape')).toBe(true)
|
|
119
|
+
expect(byCode.has('invalid-diff-context')).toBe(true)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('supports glob input selection for trust artifacts', () => {
|
|
123
|
+
tempDir = mkdtempSync(join(tmpdir(), 'drift-kpi-glob-'))
|
|
124
|
+
mkdirSync(join(tempDir, 'nested'))
|
|
125
|
+
|
|
126
|
+
writeFileSync(join(tempDir, 'trust-1.json'), JSON.stringify({
|
|
127
|
+
$schema: 'schemas/drift-trust.v1.json',
|
|
128
|
+
toolVersion: '1.3.0',
|
|
129
|
+
trust_score: 90,
|
|
130
|
+
merge_risk: 'LOW',
|
|
131
|
+
}))
|
|
132
|
+
writeFileSync(join(tempDir, 'nested', 'trust-2.json'), JSON.stringify({
|
|
133
|
+
$schema: 'schemas/drift-trust.v1.json',
|
|
134
|
+
toolVersion: '1.3.0',
|
|
135
|
+
trust_score: 20,
|
|
136
|
+
merge_risk: 'CRITICAL',
|
|
137
|
+
}))
|
|
138
|
+
writeFileSync(join(tempDir, 'other.json'), JSON.stringify({ trust_score: 55, merge_risk: 'MEDIUM' }))
|
|
139
|
+
|
|
140
|
+
const pattern = join(tempDir, '**', 'trust-*.json')
|
|
141
|
+
const kpi = computeTrustKpis(pattern)
|
|
142
|
+
|
|
143
|
+
expect(kpi.files).toEqual({ matched: 2, parsed: 2, malformed: 0 })
|
|
144
|
+
expect(kpi.mergeRiskDistribution).toEqual({ LOW: 1, MEDIUM: 0, HIGH: 0, CRITICAL: 1 })
|
|
145
|
+
expect(kpi.trustScore.average).toBe(55)
|
|
146
|
+
})
|
|
147
|
+
})
|