repometry 0.3.0 → 0.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/package.json +1 -1
- package/target/main/resources/report/json/report-v2.schema.json +12 -1
- package/target/main/resources/viewer/files.css +16 -9
- package/target/main/resources/viewer/styles.css +13 -2
- package/target/main/ts/api/git/git.d.ts +1 -1
- package/target/main/ts/api/git/git.js +21 -5
- package/target/main/ts/api/git/inspection-source.d.ts +1 -1
- package/target/main/ts/api/git/inspection-source.js +10 -4
- package/target/main/ts/api/git/local.d.ts +1 -1
- package/target/main/ts/api/git/local.js +29 -10
- package/target/main/ts/api/worker/worker-protocol.js +34 -9
- package/target/main/ts/compose/analyze-snapshot.d.ts +1 -0
- package/target/main/ts/compose/analyze-snapshot.js +50 -17
- package/target/main/ts/compose/inspect.js +2 -2
- package/target/main/ts/compose/plugin-list.js +2 -1
- package/target/main/ts/compose/security-plugins.d.ts +1 -0
- package/target/main/ts/compose/security-plugins.js +7 -0
- package/target/main/ts/core/engine/manifest.js +3 -2
- package/target/main/ts/core/engine/plugin.d.ts +2 -0
- package/target/main/ts/core/model/line-coverage.d.ts +2 -0
- package/target/main/ts/core/model/line-coverage.js +19 -1
- package/target/main/ts/core/model/source.d.ts +3 -0
- package/target/main/ts/core/model/source.js +4 -1
- package/target/main/ts/core/usecases/inspect.js +2 -2
- package/target/main/ts/plugins/coverage/coverage.d.ts +4 -3
- package/target/main/ts/plugins/coverage/coverage.js +46 -17
- package/target/main/ts/plugins/language-js/js-security.d.ts +4 -0
- package/target/main/ts/plugins/language-js/js-security.js +508 -0
- package/target/main/ts/plugins/security/actions-security.d.ts +2 -0
- package/target/main/ts/plugins/security/actions-security.js +581 -0
- package/target/main/ts/plugins/security/dockerfile.d.ts +2 -0
- package/target/main/ts/plugins/security/dockerfile.js +488 -0
- package/target/main/ts/plugins/security/npm-supply-chain.d.ts +4 -0
- package/target/main/ts/plugins/security/npm-supply-chain.js +368 -0
- package/target/main/ts/plugins/security/secrets.d.ts +12 -0
- package/target/main/ts/plugins/security/secrets.js +254 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +7 -0
- package/target/main/ts/report/html/app/viewer-files.js +60 -10
- package/target/main/ts/report/html/app/viewer-filter.js +8 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-source.js +71 -11
- package/target/main/ts/report/html/site/badges.d.ts +1 -4
- package/target/main/ts/report/html/site/badges.js +28 -19
- package/target/main/ts/report/json/projections/commit-summary.js +2 -11
- package/target/main/ts/report/json/projections/inspection-context.js +6 -12
- package/target/main/ts/report/json/projections/security-summary.d.ts +11 -0
- package/target/main/ts/report/json/projections/security-summary.js +22 -0
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { DataContract } from '../engine/plugin.js';
|
|
2
2
|
export type CoveredLineRange = readonly [first: number, last: number];
|
|
3
|
+
export type HitRun = readonly [first: number, last: number, count: number];
|
|
3
4
|
export interface FileLineCoverage {
|
|
4
5
|
readonly covered: readonly CoveredLineRange[];
|
|
5
6
|
readonly uncovered: readonly CoveredLineRange[];
|
|
6
7
|
readonly partial?: readonly CoveredLineRange[];
|
|
8
|
+
readonly hits?: readonly HitRun[];
|
|
7
9
|
}
|
|
8
10
|
export type LineCoverage = Readonly<Record<string, FileLineCoverage>>;
|
|
9
11
|
export declare const lcovLines: DataContract<LineCoverage>;
|
|
@@ -2,7 +2,7 @@ import { isRecord } from '../engine/plugin.js';
|
|
|
2
2
|
export const lcovLines = {
|
|
3
3
|
id: 'repometry.lcov-lines/v1',
|
|
4
4
|
accepts: (value) => isRecord(value) && Object.values(value).every(file => isRecord(file) && isMerged(file.covered) && isMerged(file.uncovered) &&
|
|
5
|
-
(file.partial === undefined || isMerged(file.partial))),
|
|
5
|
+
(file.partial === undefined || isMerged(file.partial)) && (file.hits === undefined || isMergedHits(file.hits))),
|
|
6
6
|
};
|
|
7
7
|
function isMerged(value) {
|
|
8
8
|
if (!Array.isArray(value))
|
|
@@ -19,3 +19,21 @@ function isMerged(value) {
|
|
|
19
19
|
}
|
|
20
20
|
return true;
|
|
21
21
|
}
|
|
22
|
+
function isMergedHits(value) {
|
|
23
|
+
if (!Array.isArray(value))
|
|
24
|
+
return false;
|
|
25
|
+
let previousEnd = 0;
|
|
26
|
+
let previousCount = -1;
|
|
27
|
+
for (const run of value) {
|
|
28
|
+
if (!Array.isArray(run) || run.length !== 3)
|
|
29
|
+
return false;
|
|
30
|
+
const [first, last, count] = run;
|
|
31
|
+
if (typeof first !== 'number' || typeof last !== 'number' || typeof count !== 'number' || !Number.isSafeInteger(first)
|
|
32
|
+
|| !Number.isSafeInteger(last) || !Number.isSafeInteger(count) || first <= previousEnd || last < first || count < 0
|
|
33
|
+
|| (first === previousEnd + 1 && count === previousCount))
|
|
34
|
+
return false;
|
|
35
|
+
previousEnd = last;
|
|
36
|
+
previousCount = count;
|
|
37
|
+
}
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
@@ -9,6 +9,8 @@ export interface SourceFile {
|
|
|
9
9
|
readonly path: string;
|
|
10
10
|
readonly bytes: Uint8Array;
|
|
11
11
|
}
|
|
12
|
+
export declare const maxClaimedFileBytes: number;
|
|
13
|
+
export declare function isClaimedText(bytes: Uint8Array): boolean;
|
|
12
14
|
export interface InventoryFile {
|
|
13
15
|
readonly path: string;
|
|
14
16
|
readonly lines: number | null;
|
|
@@ -20,4 +22,5 @@ export interface SourceSnapshot {
|
|
|
20
22
|
readonly files: readonly SourceFile[];
|
|
21
23
|
readonly inventory?: readonly InventoryFile[];
|
|
22
24
|
readonly generatedExcluded?: readonly string[];
|
|
25
|
+
readonly oversizedClaims?: readonly string[];
|
|
23
26
|
}
|
|
@@ -2,7 +2,7 @@ import { isDeepStrictEqual } from 'node:util';
|
|
|
2
2
|
import { isRecord } from '../engine/plugin.js';
|
|
3
3
|
import { normalizeFindingIgnore, partitionFindings } from '../model/finding-ignore.js';
|
|
4
4
|
import { reportSchema } from '../model/report.js';
|
|
5
|
-
import { digest } from '../model/snapshot.js';
|
|
5
|
+
import { digest, isSourcePath } from '../model/snapshot.js';
|
|
6
6
|
import { normalizeExclusions, sourceExclusionMatcher } from '../profile/exclusions.js';
|
|
7
7
|
export async function executeInspection(options, ports) {
|
|
8
8
|
const excludedPaths = normalizeExclusions(options.exclude ?? []);
|
|
@@ -28,7 +28,7 @@ export async function executeInspection(options, ports) {
|
|
|
28
28
|
appliedConfig: { ...findings.appliedConfig, findingIgnore: ignore },
|
|
29
29
|
...(findings.findings === undefined ? {} : partitionFindings(findings.findings, ignore)) };
|
|
30
30
|
const result = snapshot.subject.kind === 'commit' && ports.recordChurn
|
|
31
|
-
? await ports.recordChurn(filtered, root, snapshot.files.map(file => file.path)) : filtered;
|
|
31
|
+
? await ports.recordChurn(filtered, root, snapshot.files.filter(file => isSourcePath(file.path)).map(file => file.path)) : filtered;
|
|
32
32
|
await source.save(result);
|
|
33
33
|
return result;
|
|
34
34
|
}
|
|
@@ -5,6 +5,7 @@ export interface CoverageInput {
|
|
|
5
5
|
readonly text: string;
|
|
6
6
|
readonly root: string;
|
|
7
7
|
readonly sourceLines: ReadonlyMap<string, number>;
|
|
8
|
+
readonly codeLines?: ReadonlyMap<string, ReadonlySet<number>>;
|
|
8
9
|
readonly excludes?: (path: string) => boolean;
|
|
9
10
|
}
|
|
10
11
|
interface CoverageResult {
|
|
@@ -18,9 +19,9 @@ interface CoverageResult {
|
|
|
18
19
|
export declare const lcovInput: DataContract<CoverageInput>;
|
|
19
20
|
export declare const coverageResult: DataContract<CoverageResult>;
|
|
20
21
|
export declare const coverage: Plugin;
|
|
21
|
-
export declare function mapCoverage({ text, root, sourceLines, excludes }: CoverageInput): {
|
|
22
|
-
files: Map<string, Map<number,
|
|
23
|
-
branches: Map<string, Map<string,
|
|
22
|
+
export declare function mapCoverage({ text, root, sourceLines, codeLines, excludes }: CoverageInput): {
|
|
23
|
+
files: Map<string, Map<number, number>>;
|
|
24
|
+
branches: Map<string, Map<string, number>>;
|
|
24
25
|
functions: Map<string, Map<string, boolean>>;
|
|
25
26
|
gaps: Map<string, string>;
|
|
26
27
|
};
|
|
@@ -8,6 +8,7 @@ export const lcovInput = {
|
|
|
8
8
|
id: 'repometry.lcov-input/v1',
|
|
9
9
|
accepts: (value) => isRecord(value) && typeof value.text === 'string'
|
|
10
10
|
&& typeof value.root === 'string' && value.sourceLines instanceof Map
|
|
11
|
+
&& (value.codeLines === undefined || value.codeLines instanceof Map)
|
|
11
12
|
&& (value.excludes === undefined || typeof value.excludes === 'function'),
|
|
12
13
|
};
|
|
13
14
|
export const coverageResult = {
|
|
@@ -35,7 +36,8 @@ export const coverage = {
|
|
|
35
36
|
{ id: definitions.coveredFunctions, label: 'Covered functions', unit: 'count', scope: 'file', aggregate: 'sum', better: 'higher', group: 'Coverage' },
|
|
36
37
|
{ id: definitions.coverableFunctions, label: 'Measured functions', unit: 'count', scope: 'file', aggregate: 'sum', better: 'none', group: 'Coverage' },
|
|
37
38
|
] }, { contract: lcovLines.id, persistence: 'report',
|
|
38
|
-
schema: { ...reportSchema.$defs.lcovLines,
|
|
39
|
+
schema: { ...reportSchema.$defs.lcovLines,
|
|
40
|
+
$defs: { lcovLineRanges: reportSchema.$defs.lcovLineRanges, lcovHitRuns: reportSchema.$defs.lcovHitRuns } } }],
|
|
39
41
|
operations: [{
|
|
40
42
|
id: 'import',
|
|
41
43
|
role: 'inspection',
|
|
@@ -50,7 +52,7 @@ export const coverage = {
|
|
|
50
52
|
execute: inputs => inputs.read('coverage', coverageResult).lineCoverage,
|
|
51
53
|
}],
|
|
52
54
|
};
|
|
53
|
-
export function mapCoverage({ text, root, sourceLines, excludes }) {
|
|
55
|
+
export function mapCoverage({ text, root, sourceLines, codeLines, excludes }) {
|
|
54
56
|
const files = new Map();
|
|
55
57
|
// Branches by line, block and branch. Functions by name and its occurrence in the record: tools such as c8 repeat a
|
|
56
58
|
// name for different functions and list FNDA in FN order. Several reports merge by any hit.
|
|
@@ -81,6 +83,8 @@ export function mapCoverage({ text, root, sourceLines, excludes }) {
|
|
|
81
83
|
continue;
|
|
82
84
|
if (!sourceLines.has(active))
|
|
83
85
|
gaps.set(active, 'LCOV source is outside the inspected file set');
|
|
86
|
+
else if (codeLines && !codeLines.has(active))
|
|
87
|
+
gaps.set(active, 'LCOV source has no classified code lines');
|
|
84
88
|
else if (!files.has(active))
|
|
85
89
|
files.set(active, new Map());
|
|
86
90
|
}
|
|
@@ -98,8 +102,8 @@ export function mapCoverage({ text, root, sourceLines, excludes }) {
|
|
|
98
102
|
const limit = sourceLines.get(active);
|
|
99
103
|
if (limit !== undefined && number > limit)
|
|
100
104
|
gaps.set(active, 'LCOV refers to a line outside the inspected source');
|
|
101
|
-
else if (file)
|
|
102
|
-
file
|
|
105
|
+
else if (file && (!codeLines || codeLines.get(active)?.has(number)))
|
|
106
|
+
addHits(file, number, hits, index + 1);
|
|
103
107
|
}
|
|
104
108
|
else if (line.startsWith('BRDA:') || line.startsWith('FN:') || line.startsWith('FNDA:')) {
|
|
105
109
|
if (active === undefined)
|
|
@@ -110,10 +114,10 @@ export function mapCoverage({ text, root, sourceLines, excludes }) {
|
|
|
110
114
|
const declaration = /^FN:[1-9]\d*(?:,[1-9]\d*)?,(.+)$/.exec(line);
|
|
111
115
|
const call = /^FNDA:(\d+),(.+)$/.exec(line);
|
|
112
116
|
if (branch) {
|
|
113
|
-
const taken = branch[4]
|
|
117
|
+
const taken = branch[4] === '-' ? 0 : Number(branch[4]);
|
|
114
118
|
const key = `${branch[1]},${branch[2]},${branch[3]}`;
|
|
115
119
|
const file = branches.get(active) ?? new Map();
|
|
116
|
-
file
|
|
120
|
+
addHits(file, key, taken, index + 1);
|
|
117
121
|
branches.set(active, file);
|
|
118
122
|
}
|
|
119
123
|
else if (declaration) {
|
|
@@ -142,6 +146,12 @@ export function mapCoverage({ text, root, sourceLines, excludes }) {
|
|
|
142
146
|
const functions = new Map([...declared].map(([path, names]) => [path, new Map([...names].map(name => [name, called.get(path)?.get(name) ?? false]))]));
|
|
143
147
|
return { files, branches, functions, gaps };
|
|
144
148
|
}
|
|
149
|
+
function addHits(hits, key, count, record) {
|
|
150
|
+
const total = (hits.get(key) ?? 0) + count;
|
|
151
|
+
if (!Number.isSafeInteger(total))
|
|
152
|
+
throw new Error(`LCOV hit count exceeds the supported integer range at line ${record}`);
|
|
153
|
+
hits.set(key, total);
|
|
154
|
+
}
|
|
145
155
|
function importCoverage(input) {
|
|
146
156
|
const { files, branches, functions, gaps } = mapCoverage(input);
|
|
147
157
|
const rows = [];
|
|
@@ -154,11 +164,14 @@ function importCoverage(input) {
|
|
|
154
164
|
const hitLines = [], missedLines = [];
|
|
155
165
|
for (const [line, hit] of hits)
|
|
156
166
|
(hit ? hitLines : missedLines).push(line);
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
167
|
+
const partialHits = partiallyCoveredLines(branches.get(path), input.sourceLines.get(path), input.codeLines?.get(path));
|
|
168
|
+
const partial = mergedRanges([...partialHits.keys()]);
|
|
169
|
+
if (hits.size || partial.length) {
|
|
170
|
+
// A BRDA-only partial line has at least as many hits as its most frequently taken branch.
|
|
171
|
+
const measured = new Map([...partialHits, ...hits]);
|
|
172
|
+
lineCoverage.push([path, { covered: mergedRanges(hitLines), uncovered: mergedRanges(missedLines),
|
|
173
|
+
...(partial.length ? { partial } : {}), hits: mergedHits(measured) }]);
|
|
174
|
+
}
|
|
162
175
|
const covered = hitLines.length;
|
|
163
176
|
totalCovered += covered;
|
|
164
177
|
totalLines += hits.size;
|
|
@@ -176,14 +189,19 @@ function importCoverage(input) {
|
|
|
176
189
|
return { measurements: [...rows, ...counts, ...extra], lineCoverage: Object.fromEntries(lineCoverage),
|
|
177
190
|
gaps: [...gaps].sort(([left], [right]) => comparePaths(left, right)).map(([path, reason]) => ({ path, reason })) };
|
|
178
191
|
}
|
|
179
|
-
function partiallyCoveredLines(branches, lastLine) {
|
|
180
|
-
const taken = new
|
|
181
|
-
|
|
192
|
+
function partiallyCoveredLines(branches, lastLine, codeLines) {
|
|
193
|
+
const taken = new Map();
|
|
194
|
+
const missed = new Set();
|
|
195
|
+
for (const [branch, count] of branches ?? []) {
|
|
182
196
|
const line = Number(branch.slice(0, branch.indexOf(',')));
|
|
183
|
-
if (line
|
|
184
|
-
|
|
197
|
+
if (line > lastLine || (codeLines && !codeLines.has(line)))
|
|
198
|
+
continue;
|
|
199
|
+
if (count === 0)
|
|
200
|
+
missed.add(line);
|
|
201
|
+
else
|
|
202
|
+
taken.set(line, Math.max(taken.get(line) ?? 0, count));
|
|
185
203
|
}
|
|
186
|
-
return [...taken].filter(line => missed.has(line));
|
|
204
|
+
return new Map([...taken].filter(([line]) => missed.has(line)));
|
|
187
205
|
}
|
|
188
206
|
function mergedRanges(lines) {
|
|
189
207
|
const ranges = [];
|
|
@@ -196,6 +214,17 @@ function mergedRanges(lines) {
|
|
|
196
214
|
}
|
|
197
215
|
return ranges;
|
|
198
216
|
}
|
|
217
|
+
function mergedHits(hits) {
|
|
218
|
+
const runs = [];
|
|
219
|
+
for (const [line, count] of [...hits].sort(([left], [right]) => left - right)) {
|
|
220
|
+
const previous = runs.at(-1);
|
|
221
|
+
if (previous && previous[1] + 1 === line && previous[2] === count)
|
|
222
|
+
previous[1] = line;
|
|
223
|
+
else
|
|
224
|
+
runs.push([line, line, count]);
|
|
225
|
+
}
|
|
226
|
+
return runs;
|
|
227
|
+
}
|
|
199
228
|
/** Per-file and repository ratios with their counts, for a kind the LCOV reports; nothing when it reports none. */
|
|
200
229
|
function hitRows(files, gaps, ratioId, coveredId, totalId) {
|
|
201
230
|
const rows = [];
|