repometry 0.0.0-dev.0 → 0.1.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/LICENSE +21 -0
- package/README.md +24 -1
- package/package.json +48 -7
- package/target/main/resources/report/json/compact-json-v1.schema.json +24 -0
- package/target/main/resources/report/json/comparison-v1.schema.json +65 -0
- package/target/main/resources/report/json/config-v1.schema.json +34 -0
- package/target/main/resources/report/json/diff-coverage-v1.schema.json +55 -0
- package/target/main/resources/report/json/file-metrics-v1.schema.json +134 -0
- package/target/main/resources/report/json/inspection-context-v1.schema.json +172 -0
- package/target/main/resources/report/json/metabranch-v1.schema.json +9 -0
- package/target/main/resources/report/json/metric-catalog-v1.schema.json +31 -0
- package/target/main/resources/report/json/public-history-v1.schema.json +50 -0
- package/target/main/resources/report/json/pull-review-v1.schema.json +97 -0
- package/target/main/resources/report/json/quality-history-v1.schema.json +51 -0
- package/target/main/resources/report/json/report-v1.schema.json +65 -0
- package/target/main/resources/report/json/report-v2.schema.json +238 -0
- package/target/main/resources/report/json/repository-summary-v1.schema.json +181 -0
- package/target/main/resources/report/json/viewer-details-v1.schema.json +343 -0
- package/target/main/resources/report/json/viewer-inspection-v1.schema.json +13 -0
- package/target/main/resources/viewer/files.css +578 -0
- package/target/main/resources/viewer/index.html +130 -0
- package/target/main/resources/viewer/projects.html +52 -0
- package/target/main/resources/viewer/styles.css +586 -0
- package/target/main/resources/viewer/viewer-pulls.css +64 -0
- package/target/main/ts/api/gh/github-pr-comment.d.ts +4 -0
- package/target/main/ts/api/gh/github-pr-comment.js +107 -0
- package/target/main/ts/api/gh/github.d.ts +6 -0
- package/target/main/ts/api/gh/github.js +91 -0
- package/target/main/ts/api/git/blob-batch.d.ts +10 -0
- package/target/main/ts/api/git/blob-batch.js +105 -0
- package/target/main/ts/api/git/changes.d.ts +22 -0
- package/target/main/ts/api/git/changes.js +107 -0
- package/target/main/ts/api/git/commit-metadata.d.ts +3 -0
- package/target/main/ts/api/git/commit-metadata.js +54 -0
- package/target/main/ts/api/git/git-churn.d.ts +9 -0
- package/target/main/ts/api/git/git-churn.js +70 -0
- package/target/main/ts/api/git/git-reader.d.ts +16 -0
- package/target/main/ts/api/git/git-reader.js +73 -0
- package/target/main/ts/api/git/git.d.ts +21 -0
- package/target/main/ts/api/git/git.js +152 -0
- package/target/main/ts/api/git/inspection-source.d.ts +15 -0
- package/target/main/ts/api/git/inspection-source.js +30 -0
- package/target/main/ts/api/git/local-sources.d.ts +5 -0
- package/target/main/ts/api/git/local-sources.js +46 -0
- package/target/main/ts/api/git/local.d.ts +3 -0
- package/target/main/ts/api/git/local.js +35 -0
- package/target/main/ts/api/git/metabranch-worktree.d.ts +1 -0
- package/target/main/ts/api/git/metabranch-worktree.js +34 -0
- package/target/main/ts/api/git/source-cache.d.ts +3 -0
- package/target/main/ts/api/git/source-cache.js +56 -0
- package/target/main/ts/api/import/finding-import.d.ts +9 -0
- package/target/main/ts/api/import/finding-import.js +226 -0
- package/target/main/ts/api/import/lcov-files.d.ts +5 -0
- package/target/main/ts/api/import/lcov-files.js +13 -0
- package/target/main/ts/api/import/profile-file.d.ts +4 -0
- package/target/main/ts/api/import/profile-file.js +16 -0
- package/target/main/ts/api/worker/remote-executor.d.ts +2 -0
- package/target/main/ts/api/worker/remote-executor.js +45 -0
- package/target/main/ts/api/worker/worker-protocol.d.ts +7 -0
- package/target/main/ts/api/worker/worker-protocol.js +101 -0
- package/target/main/ts/api/worker/worker.d.ts +5 -0
- package/target/main/ts/api/worker/worker.js +85 -0
- package/target/main/ts/cli/arguments.d.ts +28 -0
- package/target/main/ts/cli/arguments.js +110 -0
- package/target/main/ts/cli/config.d.ts +14 -0
- package/target/main/ts/cli/config.js +60 -0
- package/target/main/ts/cli/github-pr-comment.d.ts +1 -0
- package/target/main/ts/cli/github-pr-comment.js +12 -0
- package/target/main/ts/cli/imports.d.ts +7 -0
- package/target/main/ts/cli/imports.js +29 -0
- package/target/main/ts/cli/main.d.ts +2 -0
- package/target/main/ts/cli/main.js +343 -284
- package/target/main/ts/cli/reporting.d.ts +18 -0
- package/target/main/ts/cli/reporting.js +108 -0
- package/target/main/ts/cli/revisions.d.ts +6 -0
- package/target/main/ts/cli/revisions.js +15 -0
- package/target/main/ts/cli/store.d.ts +13 -0
- package/target/main/ts/cli/store.js +38 -0
- package/target/main/ts/compose/analyze-snapshot.d.ts +4 -0
- package/target/main/ts/compose/analyze-snapshot.js +163 -0
- package/target/main/ts/compose/attach-churn.d.ts +2 -0
- package/target/main/ts/compose/attach-churn.js +37 -0
- package/target/main/ts/compose/diff-coverage.d.ts +20 -0
- package/target/main/ts/compose/diff-coverage.js +56 -0
- package/target/main/ts/compose/inspect.d.ts +23 -0
- package/target/main/ts/compose/inspect.js +44 -0
- package/target/main/ts/compose/plugin-list.d.ts +6 -0
- package/target/main/ts/compose/plugin-list.js +9 -0
- package/target/main/ts/compose/prepare-metabranch.d.ts +9 -0
- package/target/main/ts/compose/prepare-metabranch.js +16 -0
- package/target/main/ts/compose/review.d.ts +16 -0
- package/target/main/ts/compose/review.js +38 -0
- package/target/main/ts/compose/sources.d.ts +3 -0
- package/target/main/ts/compose/sources.js +29 -0
- package/target/main/ts/core/engine/execute.d.ts +10 -0
- package/target/main/ts/core/engine/execute.js +49 -0
- package/target/main/ts/core/engine/manifest.d.ts +4 -0
- package/target/main/ts/core/engine/manifest.js +104 -0
- package/target/main/ts/core/engine/plan.d.ts +22 -0
- package/target/main/ts/core/engine/plan.js +106 -0
- package/target/main/ts/core/engine/plugin.d.ts +59 -0
- package/target/main/ts/core/engine/plugin.js +4 -0
- package/target/main/ts/core/engine/report-products.d.ts +16 -0
- package/target/main/ts/core/engine/report-products.js +85 -0
- package/target/main/ts/core/model/changes.d.ts +8 -0
- package/target/main/ts/core/model/changes.js +1 -0
- package/target/main/ts/core/model/churn.d.ts +11 -0
- package/target/main/ts/core/model/churn.js +5 -0
- package/target/main/ts/core/model/clone-source.d.ts +16 -0
- package/target/main/ts/core/model/clone-source.js +14 -0
- package/target/main/ts/core/model/code-structure.d.ts +30 -0
- package/target/main/ts/core/model/code-structure.js +31 -0
- package/target/main/ts/core/model/comparison.d.ts +24 -0
- package/target/main/ts/core/model/comparison.js +1 -0
- package/target/main/ts/core/model/diff-coverage.d.ts +23 -0
- package/target/main/ts/core/model/diff-coverage.js +1 -0
- package/target/main/ts/core/model/finding-ignore.d.ts +8 -0
- package/target/main/ts/core/model/finding-ignore.js +35 -0
- package/target/main/ts/core/model/finding.d.ts +28 -0
- package/target/main/ts/core/model/finding.js +29 -0
- package/target/main/ts/core/model/ignore-rule.d.ts +11 -0
- package/target/main/ts/core/model/ignore-rule.js +1 -0
- package/target/main/ts/core/model/measurement.d.ts +27 -0
- package/target/main/ts/core/model/measurement.js +24 -0
- package/target/main/ts/core/model/metric-descriptor.d.ts +17 -0
- package/target/main/ts/core/model/metric-descriptor.js +1 -0
- package/target/main/ts/core/model/plugin-data.d.ts +25 -0
- package/target/main/ts/core/model/plugin-data.js +1 -0
- package/target/main/ts/core/model/pull-review.d.ts +48 -0
- package/target/main/ts/core/model/pull-review.js +1 -0
- package/target/main/ts/core/model/quality-summary.d.ts +42 -0
- package/target/main/ts/core/model/quality-summary.js +64 -0
- package/target/main/ts/core/model/report.d.ts +32 -0
- package/target/main/ts/core/model/report.js +5 -0
- package/target/main/ts/core/model/scanner-import.d.ts +39 -0
- package/target/main/ts/core/model/scanner-import.js +28 -0
- package/target/main/ts/core/model/snapshot.d.ts +15 -0
- package/target/main/ts/core/model/snapshot.js +50 -0
- package/target/main/ts/core/model/source-locator.d.ts +7 -0
- package/target/main/ts/core/model/source-locator.js +1 -0
- package/target/main/ts/core/model/source.d.ts +23 -0
- package/target/main/ts/core/model/source.js +1 -0
- package/target/main/ts/core/ports/report.d.ts +9 -0
- package/target/main/ts/core/ports/report.js +1 -0
- package/target/main/ts/core/ports/source-provider.d.ts +14 -0
- package/target/main/ts/core/ports/source-provider.js +4 -0
- package/target/main/ts/core/profile/exclusions.d.ts +11 -0
- package/target/main/ts/core/profile/exclusions.js +57 -0
- package/target/main/ts/core/profile/maintainability.d.ts +31 -0
- package/target/main/ts/core/profile/maintainability.js +9 -0
- package/target/main/ts/core/profile/profile.d.ts +4 -0
- package/target/main/ts/core/profile/profile.js +10 -0
- package/target/main/ts/core/usecases/compare.d.ts +6 -0
- package/target/main/ts/core/usecases/compare.js +145 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.d.ts +6 -0
- package/target/main/ts/core/usecases/diff-coverage-policy.js +10 -0
- package/target/main/ts/core/usecases/diff-coverage.d.ts +40 -0
- package/target/main/ts/core/usecases/diff-coverage.js +15 -0
- package/target/main/ts/core/usecases/inspect.d.ts +38 -0
- package/target/main/ts/core/usecases/inspect.js +41 -0
- package/target/main/ts/core/usecases/review.d.ts +31 -0
- package/target/main/ts/core/usecases/review.js +128 -0
- package/target/main/ts/index.d.ts +35 -0
- package/target/main/ts/index.js +17 -13
- package/target/main/ts/plugin.d.ts +14 -0
- package/target/main/ts/plugin.js +5 -0
- package/target/main/ts/plugins/coverage/coverage.d.ts +23 -0
- package/target/main/ts/plugins/coverage/coverage.js +120 -0
- package/target/main/ts/plugins/coverage/diff-coverage.d.ts +7 -0
- package/target/main/ts/plugins/coverage/diff-coverage.js +89 -0
- package/target/main/ts/plugins/duplication/duplication.d.ts +4 -0
- package/target/main/ts/plugins/duplication/duplication.js +93 -0
- package/target/main/ts/plugins/language-js/babel-provider.d.ts +10 -0
- package/target/main/ts/plugins/language-js/babel-provider.js +46 -0
- package/target/main/ts/plugins/language-js/clone-candidates.d.ts +3 -0
- package/target/main/ts/plugins/language-js/clone-candidates.js +64 -0
- package/target/main/ts/plugins/language-js/code-lines.d.ts +6 -0
- package/target/main/ts/plugins/language-js/code-lines.js +35 -0
- package/target/main/ts/plugins/language-js/function-facts.d.ts +8 -0
- package/target/main/ts/plugins/language-js/function-facts.js +60 -0
- package/target/main/ts/plugins/language-js/structural-observations.d.ts +8 -0
- package/target/main/ts/plugins/language-js/structural-observations.js +79 -0
- package/target/main/ts/plugins/maintainability/maintainability.d.ts +9 -0
- package/target/main/ts/plugins/maintainability/maintainability.js +42 -0
- package/target/main/ts/plugins/maintainability/structural-smells.d.ts +3 -0
- package/target/main/ts/plugins/maintainability/structural-smells.js +15 -0
- package/target/main/ts/plugins/source/forges.d.ts +4 -0
- package/target/main/ts/plugins/source/forges.js +79 -0
- package/target/main/ts/plugins/structure/structure.d.ts +2 -0
- package/target/main/ts/plugins/structure/structure.js +37 -0
- package/target/main/ts/report/html/app/viewer-access.d.ts +19 -0
- package/target/main/ts/report/html/app/viewer-access.js +25 -0
- package/target/main/ts/report/html/app/viewer-chart.d.ts +101 -0
- package/target/main/ts/report/html/app/viewer-chart.js +711 -0
- package/target/main/ts/report/html/app/viewer-commits.d.ts +36 -0
- package/target/main/ts/report/html/app/viewer-commits.js +280 -0
- package/target/main/ts/report/html/app/viewer-data.d.ts +23 -0
- package/target/main/ts/report/html/app/viewer-data.js +105 -0
- package/target/main/ts/report/html/app/viewer-files.d.ts +117 -0
- package/target/main/ts/report/html/app/viewer-files.js +2087 -0
- package/target/main/ts/report/html/app/viewer-filter.d.ts +113 -0
- package/target/main/ts/report/html/app/viewer-filter.js +492 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.d.ts +68 -0
- package/target/main/ts/report/html/app/viewer-metric-registry.js +206 -0
- package/target/main/ts/report/html/app/viewer-metrics.d.ts +44 -0
- package/target/main/ts/report/html/app/viewer-metrics.js +172 -0
- package/target/main/ts/report/html/app/viewer-profile.d.ts +17 -0
- package/target/main/ts/report/html/app/viewer-profile.js +401 -0
- package/target/main/ts/report/html/app/viewer-projects.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer-projects.js +90 -0
- package/target/main/ts/report/html/app/viewer-pulls.d.ts +3 -0
- package/target/main/ts/report/html/app/viewer-pulls.js +242 -0
- package/target/main/ts/report/html/app/viewer-source.d.ts +75 -0
- package/target/main/ts/report/html/app/viewer-source.js +313 -0
- package/target/main/ts/report/html/app/viewer-trends.d.ts +74 -0
- package/target/main/ts/report/html/app/viewer-trends.js +413 -0
- package/target/main/ts/report/html/app/viewer.d.ts +1 -0
- package/target/main/ts/report/html/app/viewer.js +794 -0
- package/target/main/ts/report/html/site/badges.d.ts +14 -0
- package/target/main/ts/report/html/site/badges.js +39 -0
- package/target/main/ts/report/html/site/export-site.d.ts +21 -0
- package/target/main/ts/report/html/site/export-site.js +157 -0
- package/target/main/ts/report/html/site/exported-server.d.ts +6 -0
- package/target/main/ts/report/html/site/exported-server.js +70 -0
- package/target/main/ts/report/html/site/local-server.d.ts +7 -0
- package/target/main/ts/report/html/site/local-server.js +64 -0
- package/target/main/ts/report/html/site/projects.d.ts +3 -0
- package/target/main/ts/report/html/site/projects.js +79 -0
- package/target/main/ts/report/html/site/server.d.ts +4 -0
- package/target/main/ts/report/html/site/server.js +64 -0
- package/target/main/ts/report/html/site/source-route.d.ts +6 -0
- package/target/main/ts/report/html/site/source-route.js +22 -0
- package/target/main/ts/report/json/projections/commit-summary.d.ts +11 -0
- package/target/main/ts/report/json/projections/commit-summary.js +118 -0
- package/target/main/ts/report/json/projections/components.d.ts +4 -0
- package/target/main/ts/report/json/projections/components.js +29 -0
- package/target/main/ts/report/json/projections/file-metrics.d.ts +5 -0
- package/target/main/ts/report/json/projections/file-metrics.js +243 -0
- package/target/main/ts/report/json/projections/inspection-context.d.ts +6 -0
- package/target/main/ts/report/json/projections/inspection-context.js +92 -0
- package/target/main/ts/report/json/projections/inspection-details.d.ts +11 -0
- package/target/main/ts/report/json/projections/inspection-details.js +69 -0
- package/target/main/ts/report/json/projections/metric-values.d.ts +7 -0
- package/target/main/ts/report/json/projections/metric-values.js +57 -0
- package/target/main/ts/report/json/projections/public-history.d.ts +4 -0
- package/target/main/ts/report/json/projections/public-history.js +16 -0
- package/target/main/ts/report/json/store/components.d.ts +2 -0
- package/target/main/ts/report/json/store/components.js +31 -0
- package/target/main/ts/report/json/store/local-store.d.ts +13 -0
- package/target/main/ts/report/json/store/local-store.js +179 -0
- package/target/main/ts/report/json/store/pull-review-store.d.ts +3 -0
- package/target/main/ts/report/json/store/pull-review-store.js +51 -0
- package/target/main/ts/report/json/validation/metabranch.d.ts +4 -0
- package/target/main/ts/report/json/validation/metabranch.js +7 -0
- package/target/main/ts/report/json/validation/report.d.ts +15 -0
- package/target/main/ts/report/json/validation/report.js +64 -0
- package/target/main/ts/report/json/validation/summary-validation.d.ts +4 -0
- package/target/main/ts/report/json/validation/summary-validation.js +27 -0
- package/target/main/ts/report/json/wire/compact-json.d.ts +11 -0
- package/target/main/ts/report/json/wire/compact-json.js +76 -0
- package/target/main/ts/report/json/wire/component-model.d.ts +9 -0
- package/target/main/ts/report/json/wire/component-model.js +1 -0
- package/target/main/ts/report/json/wire/domain-types.d.ts +2 -0
- package/target/main/ts/report/json/wire/domain-types.js +1 -0
- package/target/main/ts/report/json/wire/file-metrics-model.d.ts +77 -0
- package/target/main/ts/report/json/wire/file-metrics-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-context-model.d.ts +26 -0
- package/target/main/ts/report/json/wire/inspection-context-model.js +1 -0
- package/target/main/ts/report/json/wire/inspection-details-model.d.ts +82 -0
- package/target/main/ts/report/json/wire/inspection-details-model.js +1 -0
- package/target/main/ts/report/json/wire/project-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/project-model.js +1 -0
- package/target/main/ts/report/json/wire/public-history-model.d.ts +42 -0
- package/target/main/ts/report/json/wire/public-history-model.js +6 -0
- package/target/main/ts/report/json/wire/pull-review-model.d.ts +7 -0
- package/target/main/ts/report/json/wire/pull-review-model.js +1 -0
- package/target/main/ts/report/json/wire/summary-model.d.ts +45 -0
- package/target/main/ts/report/json/wire/summary-model.js +1 -0
- package/target/main/ts/report.d.ts +11 -0
- package/target/main/ts/report.js +5 -0
- package/index.js +0 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { extname } from 'node:path';
|
|
3
|
+
import { isRecord } from '../engine/plugin.js';
|
|
4
|
+
export const sourceFile = {
|
|
5
|
+
id: 'repometry.source-file/v1',
|
|
6
|
+
accepts: (value) => isRecord(value) && typeof value.path === 'string' && value.bytes instanceof Uint8Array,
|
|
7
|
+
};
|
|
8
|
+
export const sourceDirectoriesExcluded = ['.git', '.repometry', 'node_modules', 'target'];
|
|
9
|
+
export const sourceExtensions = ['.js', '.mjs', '.cjs', '.jsx', '.ts', '.mts', '.cts', '.tsx'];
|
|
10
|
+
const excluded = new Set(sourceDirectoriesExcluded);
|
|
11
|
+
const extensions = new Set(sourceExtensions);
|
|
12
|
+
export function isSourcePath(path) {
|
|
13
|
+
return extensions.has(extname(path)) && !path.split('/').slice(0, -1).some(isExcludedDirectory);
|
|
14
|
+
}
|
|
15
|
+
export function isExcludedDirectory(name) {
|
|
16
|
+
return excluded.has(name);
|
|
17
|
+
}
|
|
18
|
+
export function digest(bytes) {
|
|
19
|
+
return createHash('sha256').update(bytes).digest('hex');
|
|
20
|
+
}
|
|
21
|
+
export function utf8(bytes) {
|
|
22
|
+
return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);
|
|
23
|
+
}
|
|
24
|
+
export function physicalLines(text) {
|
|
25
|
+
if (text === '')
|
|
26
|
+
return 0;
|
|
27
|
+
return text.split(/\r\n|[\n\r\u2028\u2029]/).length - Number(/[\n\r\u2028\u2029]$/.test(text));
|
|
28
|
+
}
|
|
29
|
+
export function sourceLineCounts(files) {
|
|
30
|
+
const decoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
31
|
+
return new Map(files.map(file => [file.path, physicalLines(decoder.decode(file.bytes))]));
|
|
32
|
+
}
|
|
33
|
+
export function textLineCount(bytes) {
|
|
34
|
+
if (bytes.includes(0))
|
|
35
|
+
return null;
|
|
36
|
+
try {
|
|
37
|
+
return physicalLines(utf8(bytes));
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function comparePaths(left, right) {
|
|
44
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
45
|
+
}
|
|
46
|
+
export function workingSnapshot(files) {
|
|
47
|
+
files.sort((left, right) => comparePaths(left.path, right.path));
|
|
48
|
+
const id = digest(JSON.stringify(files.map(file => [file.path, digest(file.bytes)])));
|
|
49
|
+
return { subject: { kind: 'working-tree', id }, files };
|
|
50
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type Subject = {
|
|
2
|
+
readonly kind: 'commit';
|
|
3
|
+
readonly id: string;
|
|
4
|
+
} | {
|
|
5
|
+
readonly kind: 'working-tree';
|
|
6
|
+
readonly id: string;
|
|
7
|
+
};
|
|
8
|
+
export interface SourceFile {
|
|
9
|
+
readonly path: string;
|
|
10
|
+
readonly bytes: Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
export interface InventoryFile {
|
|
13
|
+
readonly path: string;
|
|
14
|
+
readonly lines: number | null;
|
|
15
|
+
/** Size in bytes, from Git or the file system; independent of formatting, unlike lines. */
|
|
16
|
+
readonly bytes?: number;
|
|
17
|
+
}
|
|
18
|
+
export interface SourceSnapshot {
|
|
19
|
+
readonly subject: Subject;
|
|
20
|
+
readonly files: readonly SourceFile[];
|
|
21
|
+
readonly inventory?: readonly InventoryFile[];
|
|
22
|
+
readonly generatedExcluded?: readonly string[];
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Report } from '../model/report.js';
|
|
2
|
+
import type { Subject } from '../model/source.js';
|
|
3
|
+
export interface ReportReader {
|
|
4
|
+
read(subject: Subject): Promise<Report>;
|
|
5
|
+
list(): Promise<readonly Report[]>;
|
|
6
|
+
}
|
|
7
|
+
export interface ReportWriter {
|
|
8
|
+
save(report: Report): Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Plugin } from '../engine/plugin.js';
|
|
2
|
+
import type { SourceLocator } from '../model/source-locator.js';
|
|
3
|
+
export interface SourceContext {
|
|
4
|
+
readonly option?: string;
|
|
5
|
+
readonly remotes: readonly string[];
|
|
6
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
7
|
+
}
|
|
8
|
+
export interface SourceProvider {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
locate(context: SourceContext): SourceLocator | undefined;
|
|
11
|
+
read?(revision: string, path: string, signal?: AbortSignal): Promise<Uint8Array | undefined>;
|
|
12
|
+
}
|
|
13
|
+
export type SourcePlugin = Plugin & SourceProvider;
|
|
14
|
+
export declare function isSourcePathname(path: string): boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const defaultSourceExclusions: readonly ['**/.yarn', '**/.pnp.{js,cjs,loader.mjs}', '**/vendor', '**/third_party', '**/*.min.{js,cjs,mjs}', '**/*{.,-}bundle.{js,cjs,mjs}'];
|
|
2
|
+
export declare function sourceExclusionMatcher(patterns: readonly string[], generated?: readonly string[]): (path: string) => boolean;
|
|
3
|
+
export declare const generatedSourcePolicy: {
|
|
4
|
+
readonly version: 1;
|
|
5
|
+
readonly minBytes: 1024;
|
|
6
|
+
readonly minMeanLineLength: 300;
|
|
7
|
+
};
|
|
8
|
+
/** Detect generated text by its source-map trailer or the density of its nonblank lines. */
|
|
9
|
+
export declare function isGeneratedSource(bytes: Uint8Array): boolean;
|
|
10
|
+
export declare function normalizeExclusions(value: unknown): readonly string[];
|
|
11
|
+
export declare function exclusionMatcher(patterns: readonly string[]): (path: string) => boolean;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { posix } from 'node:path';
|
|
2
|
+
export const defaultSourceExclusions = [
|
|
3
|
+
'**/.yarn', '**/.pnp.{js,cjs,loader.mjs}', '**/vendor', '**/third_party',
|
|
4
|
+
'**/*.min.{js,cjs,mjs}', '**/*{.,-}bundle.{js,cjs,mjs}',
|
|
5
|
+
];
|
|
6
|
+
export function sourceExclusionMatcher(patterns, generated = []) {
|
|
7
|
+
const matches = exclusionMatcher([...defaultSourceExclusions, ...patterns]);
|
|
8
|
+
const generatedPaths = new Set(generated);
|
|
9
|
+
return path => generatedPaths.has(path) || matches(path);
|
|
10
|
+
}
|
|
11
|
+
export const generatedSourcePolicy = { version: 1, minBytes: 1024, minMeanLineLength: 300 };
|
|
12
|
+
/** Detect generated text by its source-map trailer or the density of its nonblank lines. */
|
|
13
|
+
export function isGeneratedSource(bytes) {
|
|
14
|
+
const source = new TextDecoder().decode(bytes);
|
|
15
|
+
if (/(?:^|\n)[ \t]*(?:\/\/[#@][ \t]*sourceMappingURL=\S+|\/\*[#@][ \t]*sourceMappingURL=[^\r\n]+\*\/)[ \t\r\n]*$/.test(source))
|
|
16
|
+
return true;
|
|
17
|
+
if (bytes.length < generatedSourcePolicy.minBytes)
|
|
18
|
+
return false;
|
|
19
|
+
const lines = source.split(/\r\n|[\n\r\u2028\u2029]/).map(line => line.trim()).filter(Boolean);
|
|
20
|
+
return lines.reduce((sum, line) => sum + line.length, 0) > lines.length * generatedSourcePolicy.minMeanLineLength;
|
|
21
|
+
}
|
|
22
|
+
export function normalizeExclusions(value) {
|
|
23
|
+
if (!Array.isArray(value))
|
|
24
|
+
throw new Error('Profile exclude must be an array of repository-relative paths or globs');
|
|
25
|
+
const patterns = new Set();
|
|
26
|
+
for (const item of value) {
|
|
27
|
+
if (typeof item !== 'string')
|
|
28
|
+
throw new Error('Each exclusion must be a string');
|
|
29
|
+
const pattern = item.replace(/^(?:\.\/)+/, '').replace(/\/+$/, '');
|
|
30
|
+
if (!isRelativePath(pattern) || /[\\\0]/.test(pattern) || /^[#!]/.test(pattern)) {
|
|
31
|
+
throw new Error(`Invalid source exclusion: ${JSON.stringify(item)}. Use a repository-relative path or glob.`);
|
|
32
|
+
}
|
|
33
|
+
patterns.add(pattern);
|
|
34
|
+
}
|
|
35
|
+
return [...patterns];
|
|
36
|
+
}
|
|
37
|
+
export function exclusionMatcher(patterns) {
|
|
38
|
+
if (patterns.length === 0)
|
|
39
|
+
return () => false;
|
|
40
|
+
return path => {
|
|
41
|
+
if (!isRelativePath(path))
|
|
42
|
+
return false;
|
|
43
|
+
// A rule that matches a directory excludes its entire subtree.
|
|
44
|
+
let candidate = path;
|
|
45
|
+
for (;;) {
|
|
46
|
+
if (patterns.some(pattern => candidate === pattern || posix.matchesGlob(candidate, pattern)))
|
|
47
|
+
return true;
|
|
48
|
+
const slash = candidate.lastIndexOf('/');
|
|
49
|
+
if (slash === -1)
|
|
50
|
+
return false;
|
|
51
|
+
candidate = candidate.slice(0, slash);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function isRelativePath(path) {
|
|
56
|
+
return !/^[A-Za-z]:/.test(path) && path.split('/').every(part => part !== '' && part !== '.' && part !== '..');
|
|
57
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export declare const structuralRules: {
|
|
2
|
+
readonly 'function-parameters': {
|
|
3
|
+
readonly limit: 5;
|
|
4
|
+
readonly minutesPerExcess: 10;
|
|
5
|
+
};
|
|
6
|
+
readonly 'return-statements': {
|
|
7
|
+
readonly limit: 6;
|
|
8
|
+
readonly minutesPerExcess: 10;
|
|
9
|
+
};
|
|
10
|
+
readonly 'boolean-logic': {
|
|
11
|
+
readonly limit: 4;
|
|
12
|
+
readonly minutesPerExcess: 10;
|
|
13
|
+
};
|
|
14
|
+
readonly 'nested-control-flow': {
|
|
15
|
+
readonly limit: 4;
|
|
16
|
+
readonly minutesPerExcess: 20;
|
|
17
|
+
};
|
|
18
|
+
readonly 'function-complexity': {
|
|
19
|
+
readonly limit: 15;
|
|
20
|
+
readonly minutesPerExcess: 10;
|
|
21
|
+
};
|
|
22
|
+
readonly 'file-complexity': {
|
|
23
|
+
readonly limit: 50;
|
|
24
|
+
readonly minutesPerExcess: 5;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export declare const duplicationSettings: {
|
|
28
|
+
readonly minCodeLines: 12;
|
|
29
|
+
readonly minNodes: 50;
|
|
30
|
+
readonly minutesPerRepeatedLine: 2;
|
|
31
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const structuralRules = {
|
|
2
|
+
'function-parameters': { limit: 5, minutesPerExcess: 10 },
|
|
3
|
+
'return-statements': { limit: 6, minutesPerExcess: 10 },
|
|
4
|
+
'boolean-logic': { limit: 4, minutesPerExcess: 10 },
|
|
5
|
+
'nested-control-flow': { limit: 4, minutesPerExcess: 20 },
|
|
6
|
+
'function-complexity': { limit: 15, minutesPerExcess: 10 },
|
|
7
|
+
'file-complexity': { limit: 50, minutesPerExcess: 5 },
|
|
8
|
+
};
|
|
9
|
+
export const duplicationSettings = { minCodeLines: 12, minNodes: 50, minutesPerRepeatedLine: 2 };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isRecord } from '../engine/plugin.js';
|
|
2
|
+
import { normalizeFindingIgnore } from '../model/finding-ignore.js';
|
|
3
|
+
import { normalizeExclusions } from './exclusions.js';
|
|
4
|
+
export function normalizeProfile(profile) {
|
|
5
|
+
if (!isRecord(profile) || Object.keys(profile).some(key => key !== 'exclude' && key !== 'ignore')) {
|
|
6
|
+
throw new Error('Expected a JSON profile with optional exclude and ignore arrays');
|
|
7
|
+
}
|
|
8
|
+
return { exclude: normalizeExclusions(profile.exclude === undefined ? [] : profile.exclude),
|
|
9
|
+
ignore: normalizeFindingIgnore(profile.ignore === undefined ? [] : profile.ignore) };
|
|
10
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Report } from '../model/report.js';
|
|
2
|
+
import type { InspectionComparison, Observation } from '../model/comparison.js';
|
|
3
|
+
export { comparisonSchema } from '../model/comparison.js';
|
|
4
|
+
export type { InspectionComparison } from '../model/comparison.js';
|
|
5
|
+
export declare function compareInspections(baseline: Report, current: Report): InspectionComparison;
|
|
6
|
+
export declare function observeCoverage(report: Report): Observation;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { isRecord } from '../engine/plugin.js';
|
|
3
|
+
import { definitions } from '../model/measurement.js';
|
|
4
|
+
import { comparePaths } from '../model/snapshot.js';
|
|
5
|
+
import { comparisonSchema } from '../model/comparison.js';
|
|
6
|
+
export { comparisonSchema } from '../model/comparison.js';
|
|
7
|
+
const metrics = {
|
|
8
|
+
physicalLines: { definition: definitions.lines, operation: 'structure/size' },
|
|
9
|
+
functions: { definition: definitions.functions, operation: 'structure/size' },
|
|
10
|
+
maxCyclomaticComplexity: { definition: definitions.complexity, operation: 'structure/complexity' },
|
|
11
|
+
lineCoverage: { definition: definitions.coverage, operation: 'lcov/import' },
|
|
12
|
+
};
|
|
13
|
+
export function compareInspections(baseline, current) {
|
|
14
|
+
const scopes = [sourceScope(baseline), sourceScope(current)];
|
|
15
|
+
const scopeReason = scopes.some(scope => scope === null) ? 'source-scope-unknown'
|
|
16
|
+
: isDeepStrictEqual(scopes[0], scopes[1]) ? null : 'source-scope-changed';
|
|
17
|
+
const compare = (metric) => compareMetric(metric, baseline, current, scopeReason);
|
|
18
|
+
return { schema: comparisonSchema, baseline: subject(baseline), current: subject(current), metrics: {
|
|
19
|
+
physicalLines: compare(metrics.physicalLines), functions: compare(metrics.functions),
|
|
20
|
+
maxCyclomaticComplexity: compare(metrics.maxCyclomaticComplexity), lineCoverage: compare(metrics.lineCoverage),
|
|
21
|
+
} };
|
|
22
|
+
}
|
|
23
|
+
function compareMetric(metric, baseline, current, scopeReason) {
|
|
24
|
+
const before = observe(baseline, metric);
|
|
25
|
+
const after = observe(current, metric);
|
|
26
|
+
const unit = metric.definition === definitions.coverage ? 'percent' : 'count';
|
|
27
|
+
const base = { definition: metric.definition, unit, baseline: before, current: after, delta: null };
|
|
28
|
+
if (before.status !== 'complete' || after.status !== 'complete' || before.value === null || after.value === null) {
|
|
29
|
+
return { ...base, status: 'unavailable', reason: 'observations-unavailable' };
|
|
30
|
+
}
|
|
31
|
+
if (scopeReason) {
|
|
32
|
+
return { ...base, status: scopeReason === 'source-scope-unknown' ? 'unavailable' : 'incompatible', reason: scopeReason };
|
|
33
|
+
}
|
|
34
|
+
const beforeMethod = method(baseline, metric);
|
|
35
|
+
const afterMethod = method(current, metric);
|
|
36
|
+
if (!beforeMethod || !afterMethod)
|
|
37
|
+
return { ...base, status: 'unavailable', reason: 'method-unknown' };
|
|
38
|
+
if (!isDeepStrictEqual(beforeMethod, afterMethod))
|
|
39
|
+
return { ...base, status: 'incompatible', reason: 'method-changed' };
|
|
40
|
+
return { ...base, status: 'comparable', reason: null, delta: after.value - before.value };
|
|
41
|
+
}
|
|
42
|
+
function observe(report, metric) {
|
|
43
|
+
if (metric.definition === definitions.coverage)
|
|
44
|
+
return observeCoverage(report);
|
|
45
|
+
const maximum = metric.definition === definitions.complexity;
|
|
46
|
+
const target = maximum ? 'function' : 'file';
|
|
47
|
+
const rows = report.measurements.filter(row => row.definition === metric.definition && row.target === target);
|
|
48
|
+
const partial = report.scope.parsed < report.scope.files || hasDiagnostic(report, metric.operation, 'babel-syntax/parse');
|
|
49
|
+
const expected = maximum ? fileCount(report.measurements, definitions.functions, report.scope.files) : report.scope.files;
|
|
50
|
+
const value = integerAggregate(rows, maximum);
|
|
51
|
+
if (partial)
|
|
52
|
+
return { status: 'partial', value };
|
|
53
|
+
if (expected === null || rows.length !== expected || (!maximum && !distinctPaths(rows))) {
|
|
54
|
+
return { status: 'unavailable', value: null };
|
|
55
|
+
}
|
|
56
|
+
if (expected === 0)
|
|
57
|
+
return { status: 'not-applicable', value: null };
|
|
58
|
+
return { status: value === null ? 'unavailable' : 'complete', value };
|
|
59
|
+
}
|
|
60
|
+
export function observeCoverage(report) {
|
|
61
|
+
const rows = report.measurements.filter(row => row.definition === definitions.coverage && row.target === 'repository');
|
|
62
|
+
const row = rows.length === 1 ? rows[0] : undefined;
|
|
63
|
+
const partial = hasDiagnostic(report, 'lcov/import');
|
|
64
|
+
if (row?.covered === undefined || row.total === undefined)
|
|
65
|
+
return { status: partial ? 'partial' : 'unavailable', value: null };
|
|
66
|
+
const value = row.total > 0 ? 100 * row.covered / row.total : null;
|
|
67
|
+
return { status: partial ? 'partial' : value === null ? 'not-applicable' : 'complete', value, covered: row.covered, total: row.total };
|
|
68
|
+
}
|
|
69
|
+
function fileCount(measurements, definition, expected) {
|
|
70
|
+
const rows = measurements.filter(row => row.definition === definition && row.target === 'file');
|
|
71
|
+
if (rows.length !== expected || !distinctPaths(rows))
|
|
72
|
+
return null;
|
|
73
|
+
return rows.length === 0 ? 0 : integerAggregate(rows, false);
|
|
74
|
+
}
|
|
75
|
+
function distinctPaths(rows) {
|
|
76
|
+
const paths = new Set(rows.map(row => row.path));
|
|
77
|
+
return !paths.has(undefined) && paths.size === rows.length;
|
|
78
|
+
}
|
|
79
|
+
function integerAggregate(rows, maximum) {
|
|
80
|
+
if (rows.length === 0)
|
|
81
|
+
return null;
|
|
82
|
+
let result = 0;
|
|
83
|
+
for (const { value } of rows) {
|
|
84
|
+
if (value === null || !Number.isSafeInteger(value) || value < 0)
|
|
85
|
+
return null;
|
|
86
|
+
result = maximum ? Math.max(result, value) : result + value;
|
|
87
|
+
}
|
|
88
|
+
return Number.isSafeInteger(result) ? result : null;
|
|
89
|
+
}
|
|
90
|
+
function hasDiagnostic(report, ...operations) {
|
|
91
|
+
return report.diagnostics.some(item => operations.includes(item.operation));
|
|
92
|
+
}
|
|
93
|
+
function sourceScope(report) {
|
|
94
|
+
const { source, profile } = report.appliedConfig;
|
|
95
|
+
if (!isRecord(source))
|
|
96
|
+
return null;
|
|
97
|
+
const paths = orderedStrings(source.excludedPaths === undefined && profile === 'js-ts/v1' ? [] : source.excludedPaths);
|
|
98
|
+
const defaults = orderedStrings(source.defaultExclusions ?? []);
|
|
99
|
+
const directories = orderedStrings(source.excludedDirectories);
|
|
100
|
+
const extensions = orderedStrings(source.extensions);
|
|
101
|
+
const excludedOutput = source.excludedOutput;
|
|
102
|
+
if (!paths || !defaults || !directories || !extensions || (excludedOutput !== null && typeof excludedOutput !== 'string'))
|
|
103
|
+
return null;
|
|
104
|
+
return { kind: report.subject.kind, paths: orderedStrings([...paths, ...defaults]), directories, extensions, excludedOutput,
|
|
105
|
+
generatedSourcePolicy: source.generatedSourcePolicy ?? null };
|
|
106
|
+
}
|
|
107
|
+
function orderedStrings(value) {
|
|
108
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === 'string'))
|
|
109
|
+
return null;
|
|
110
|
+
return [...new Set(value)].sort(comparePaths);
|
|
111
|
+
}
|
|
112
|
+
function method(report, metric) {
|
|
113
|
+
const definition = report.definitions[metric.definition];
|
|
114
|
+
const { plugins, operations, parser, coverage } = report.appliedConfig;
|
|
115
|
+
const importsCoverage = metric.definition === definitions.coverage;
|
|
116
|
+
const pluginIds = importsCoverage ? ['lcov'] : ['babel-syntax', 'structure'];
|
|
117
|
+
const operationKeys = importsCoverage ? [metric.operation] : ['babel-syntax/parse', metric.operation];
|
|
118
|
+
const toolchain = recordedEntries(plugins, 'id', pluginIds);
|
|
119
|
+
const bindings = recordedEntries(operations, 'key', operationKeys);
|
|
120
|
+
const settings = importsCoverage ? coverage : parser;
|
|
121
|
+
if (typeof definition !== 'string' || !toolchain || !bindings || !isRecord(settings))
|
|
122
|
+
return null;
|
|
123
|
+
if (importsCoverage && typeof settings.merge !== 'string')
|
|
124
|
+
return null;
|
|
125
|
+
if (!importsCoverage)
|
|
126
|
+
return { definition, toolchain, bindings, settings };
|
|
127
|
+
const { inputDigest, inputDigests, pathBase, ...importSettings } = settings;
|
|
128
|
+
return { definition, toolchain, bindings, settings: importSettings };
|
|
129
|
+
}
|
|
130
|
+
function recordedEntries(value, key, names) {
|
|
131
|
+
if (!Array.isArray(value))
|
|
132
|
+
return null;
|
|
133
|
+
const entries = value.filter(isRecord);
|
|
134
|
+
const matches = names.map(name => entries.filter(entry => entry[key] === name));
|
|
135
|
+
if (matches.some(group => group.length !== 1))
|
|
136
|
+
return null;
|
|
137
|
+
const recorded = matches.map(group => group[0]);
|
|
138
|
+
const valid = key === 'id'
|
|
139
|
+
? recorded.every(entry => typeof entry.version === 'string' && typeof entry.api === 'string' && isRecord(entry.tools))
|
|
140
|
+
: recorded.every(entry => isRecord(entry.inputs));
|
|
141
|
+
return valid ? recorded : null;
|
|
142
|
+
}
|
|
143
|
+
function subject({ subject, generatedAt, status, scope }) {
|
|
144
|
+
return { subject, generatedAt, status, scope };
|
|
145
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { DiffCoverage } from '../model/diff-coverage.js';
|
|
2
|
+
export interface CoverageDecision {
|
|
3
|
+
readonly status: 'passed' | 'failed' | 'not-applicable' | 'indeterminate';
|
|
4
|
+
readonly minimumPercent: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function assessDiffCoverage(result: DiffCoverage, minimumPercent: number): CoverageDecision;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function assessDiffCoverage(result, minimumPercent) {
|
|
2
|
+
if (!Number.isFinite(minimumPercent) || minimumPercent < 0 || minimumPercent > 100) {
|
|
3
|
+
throw new Error('Minimum diff coverage must be a percentage from 0 to 100');
|
|
4
|
+
}
|
|
5
|
+
if (result.status === 'partial')
|
|
6
|
+
return { status: 'indeterminate', minimumPercent };
|
|
7
|
+
if (result.percent === null)
|
|
8
|
+
return { status: 'not-applicable', minimumPercent };
|
|
9
|
+
return { status: result.percent >= minimumPercent ? 'passed' : 'failed', minimumPercent };
|
|
10
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { GitChanges } from '../model/changes.js';
|
|
2
|
+
import type { DiffCoverage, DiffCoverageResult } from '../model/diff-coverage.js';
|
|
3
|
+
import type { SourceSnapshot } from '../model/source.js';
|
|
4
|
+
import type { CoverageDecision } from './diff-coverage-policy.js';
|
|
5
|
+
export declare const diffCoverageSchema = "urn:repometry:schema:diff-coverage:1";
|
|
6
|
+
export interface DiffCoverageReport extends DiffCoverage {
|
|
7
|
+
readonly schema: typeof diffCoverageSchema;
|
|
8
|
+
readonly requestedBase: string;
|
|
9
|
+
readonly base: string;
|
|
10
|
+
readonly head: string;
|
|
11
|
+
readonly generatedAt: string;
|
|
12
|
+
readonly appliedConfig: Readonly<Record<string, unknown>>;
|
|
13
|
+
readonly decision: CoverageDecision | null;
|
|
14
|
+
}
|
|
15
|
+
export interface DiffCoverageSource {
|
|
16
|
+
readonly requestedBase: string;
|
|
17
|
+
readonly base: string;
|
|
18
|
+
readonly head: string;
|
|
19
|
+
readonly snapshot: SourceSnapshot;
|
|
20
|
+
readonly changes: GitChanges;
|
|
21
|
+
readonly root: string;
|
|
22
|
+
readonly lcovText: string;
|
|
23
|
+
readonly appliedConfig: Readonly<Record<string, unknown>>;
|
|
24
|
+
}
|
|
25
|
+
export interface DiffCoveragePorts {
|
|
26
|
+
readInputs(excludedPaths: readonly string[], excludes: (path: string) => boolean): Promise<DiffCoverageSource>;
|
|
27
|
+
measure(source: DiffCoverageSource, excludes: (path: string) => boolean): Promise<DiffCoverageResult>;
|
|
28
|
+
}
|
|
29
|
+
interface DiffCoverageOptions {
|
|
30
|
+
readonly exclude?: readonly string[];
|
|
31
|
+
readonly minimumPercent?: number;
|
|
32
|
+
}
|
|
33
|
+
export declare function executeDiffCoverage(options: DiffCoverageOptions, ports: DiffCoveragePorts): Promise<{
|
|
34
|
+
report: DiffCoverageReport;
|
|
35
|
+
uncovered: readonly {
|
|
36
|
+
readonly path: string;
|
|
37
|
+
readonly lines: readonly number[];
|
|
38
|
+
}[];
|
|
39
|
+
}>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { normalizeExclusions, sourceExclusionMatcher } from '../profile/exclusions.js';
|
|
2
|
+
import { assessDiffCoverage } from './diff-coverage-policy.js';
|
|
3
|
+
export const diffCoverageSchema = 'urn:repometry:schema:diff-coverage:1';
|
|
4
|
+
export async function executeDiffCoverage(options, ports) {
|
|
5
|
+
const excludedPaths = normalizeExclusions(options.exclude ?? []);
|
|
6
|
+
const source = await ports.readInputs(excludedPaths, sourceExclusionMatcher(excludedPaths));
|
|
7
|
+
const value = await ports.measure(source, sourceExclusionMatcher(excludedPaths, source.snapshot.generatedExcluded));
|
|
8
|
+
const { uncovered, ...observation } = value;
|
|
9
|
+
const { requestedBase, base, head, appliedConfig } = source;
|
|
10
|
+
const report = {
|
|
11
|
+
schema: diffCoverageSchema, requestedBase, base, head, generatedAt: new Date().toISOString(), appliedConfig,
|
|
12
|
+
...observation, decision: options.minimumPercent === undefined ? null : assessDiffCoverage(value, options.minimumPercent),
|
|
13
|
+
};
|
|
14
|
+
return { report, uncovered };
|
|
15
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { FindingIgnoreRule } from '../model/finding-ignore.js';
|
|
2
|
+
import type { Report } from '../model/report.js';
|
|
3
|
+
import type { SourceSnapshot } from '../model/source.js';
|
|
4
|
+
export interface AnalysisInput {
|
|
5
|
+
/** The source adapter has already applied the exclusions to this snapshot. */
|
|
6
|
+
readonly snapshot: SourceSnapshot;
|
|
7
|
+
readonly excludedOutput: string | null;
|
|
8
|
+
readonly excludedPaths?: readonly string[];
|
|
9
|
+
readonly coverage?: {
|
|
10
|
+
readonly text: string;
|
|
11
|
+
readonly sourceRoot: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export type AnalysisExecutor = (input: AnalysisInput) => Promise<Report>;
|
|
15
|
+
type Excludes = (path: string) => boolean;
|
|
16
|
+
interface InspectionSource {
|
|
17
|
+
readonly snapshot: SourceSnapshot;
|
|
18
|
+
readonly root: string;
|
|
19
|
+
readonly excludedOutput: string | null;
|
|
20
|
+
save(report: Report): Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
interface InspectionCoverage {
|
|
23
|
+
readonly text: string;
|
|
24
|
+
readonly inputDigests: readonly string[];
|
|
25
|
+
}
|
|
26
|
+
export interface InspectionPorts {
|
|
27
|
+
readSource(excludes: Excludes): Promise<InspectionSource>;
|
|
28
|
+
readonly analyze: AnalysisExecutor;
|
|
29
|
+
readCoverage?(): Promise<InspectionCoverage>;
|
|
30
|
+
importFindings?(report: Report, root: string, excludes: Excludes): Promise<Report>;
|
|
31
|
+
recordChurn?(report: Report, root: string, paths: readonly string[]): Promise<Report>;
|
|
32
|
+
}
|
|
33
|
+
export interface InspectionOptions {
|
|
34
|
+
readonly exclude?: readonly string[];
|
|
35
|
+
readonly ignore?: readonly FindingIgnoreRule[];
|
|
36
|
+
}
|
|
37
|
+
export declare function executeInspection(options: InspectionOptions, ports: InspectionPorts): Promise<Report>;
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { isDeepStrictEqual } from 'node:util';
|
|
2
|
+
import { isRecord } from '../engine/plugin.js';
|
|
3
|
+
import { normalizeFindingIgnore, partitionFindings } from '../model/finding-ignore.js';
|
|
4
|
+
import { reportSchema } from '../model/report.js';
|
|
5
|
+
import { digest } from '../model/snapshot.js';
|
|
6
|
+
import { normalizeExclusions, sourceExclusionMatcher } from '../profile/exclusions.js';
|
|
7
|
+
export async function executeInspection(options, ports) {
|
|
8
|
+
const excludedPaths = normalizeExclusions(options.exclude ?? []);
|
|
9
|
+
const ignore = normalizeFindingIgnore(options.ignore ?? []);
|
|
10
|
+
const source = await ports.readSource(sourceExclusionMatcher(excludedPaths));
|
|
11
|
+
const { snapshot, root, excludedOutput } = source;
|
|
12
|
+
const lcov = await ports.readCoverage?.();
|
|
13
|
+
const report = await ports.analyze({
|
|
14
|
+
snapshot, excludedOutput, excludedPaths,
|
|
15
|
+
coverage: lcov === undefined ? undefined : { text: lcov.text, sourceRoot: root },
|
|
16
|
+
});
|
|
17
|
+
if (report.subject.kind !== snapshot.subject.kind || report.subject.id !== snapshot.subject.id) {
|
|
18
|
+
throw new Error('Analysis result belongs to a different source snapshot');
|
|
19
|
+
}
|
|
20
|
+
const appliedSource = report.appliedConfig.source;
|
|
21
|
+
if (excludedPaths.length > 0 && (!isRecord(appliedSource) || !isDeepStrictEqual(appliedSource.excludedPaths, excludedPaths))) {
|
|
22
|
+
throw new Error('Analysis result does not record the requested source exclusions');
|
|
23
|
+
}
|
|
24
|
+
const covered = lcov && lcov.inputDigests.length > 1 ? withLcovDigests(report, lcov) : report;
|
|
25
|
+
const findings = ports.importFindings
|
|
26
|
+
? await ports.importFindings(covered, root, sourceExclusionMatcher(excludedPaths, snapshot.generatedExcluded)) : covered;
|
|
27
|
+
const filtered = ignore.length === 0 ? findings : { ...findings, schema: reportSchema,
|
|
28
|
+
appliedConfig: { ...findings.appliedConfig, findingIgnore: ignore },
|
|
29
|
+
...(findings.findings === undefined ? {} : partitionFindings(findings.findings, ignore)) };
|
|
30
|
+
const result = snapshot.subject.kind === 'commit' && ports.recordChurn
|
|
31
|
+
? await ports.recordChurn(filtered, root, snapshot.files.map(file => file.path)) : filtered;
|
|
32
|
+
await source.save(result);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
function withLcovDigests(report, { text, inputDigests }) {
|
|
36
|
+
const coverage = report.appliedConfig.coverage;
|
|
37
|
+
if (!isRecord(coverage) || coverage.inputDigest !== digest(text)) {
|
|
38
|
+
throw new Error('Analysis result does not record the requested LCOV inputs');
|
|
39
|
+
}
|
|
40
|
+
return { ...report, appliedConfig: { ...report.appliedConfig, coverage: { ...coverage, inputDigests } } };
|
|
41
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { PullReview } from '../model/pull-review.js';
|
|
2
|
+
import type { Report } from '../model/report.js';
|
|
3
|
+
import type { DiffCoverageReport } from './diff-coverage.js';
|
|
4
|
+
export interface ReviewOptions {
|
|
5
|
+
readonly number?: number;
|
|
6
|
+
readonly minimumLines?: number;
|
|
7
|
+
readonly minimumPercent?: number;
|
|
8
|
+
readonly maxCoverageDrop?: number;
|
|
9
|
+
readonly maxNewIssues?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface ReviewPorts {
|
|
12
|
+
readHead(id: string): Promise<Report | null>;
|
|
13
|
+
readBase(id: string): Promise<Report | null>;
|
|
14
|
+
readRevisions(): Promise<{
|
|
15
|
+
head: string;
|
|
16
|
+
base: string;
|
|
17
|
+
mergeBase(): Promise<string>;
|
|
18
|
+
}>;
|
|
19
|
+
measureChanged?(): Promise<{
|
|
20
|
+
report: DiffCoverageReport;
|
|
21
|
+
uncovered: PullReview['diff']['uncovered'];
|
|
22
|
+
}>;
|
|
23
|
+
}
|
|
24
|
+
export declare function executeReview(options: ReviewOptions, ports: ReviewPorts): Promise<PullReview>;
|
|
25
|
+
type ChangedLines = Pick<DiffCoverageReport, 'generatedAt' | 'requestedBase' | 'base' | 'head' | 'covered' | 'total' | 'percent' | 'files' | 'gaps' | 'decision'> & {
|
|
26
|
+
readonly status: PullReview['diff']['status'];
|
|
27
|
+
readonly appliedConfig?: DiffCoverageReport['appliedConfig'];
|
|
28
|
+
};
|
|
29
|
+
export declare function projectReview(request: ReviewOptions, diff: ChangedLines, uncovered: PullReview['diff']['uncovered'], head: Report | null, base: Report | null): PullReview;
|
|
30
|
+
export declare function reviewExitCode(review: PullReview): number;
|
|
31
|
+
export {};
|