refactor(views): share package summary fields (#15610)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-01 20:46:39 +00:00
1 parent 39ec1f7113
commit d71836b7f1
4 files changed
+82 -87

No files matched your search

+3 -2
View File
@@ -32,16 +32,17 @@ export const summaryViewResultBase = {
...viewResultBaseFields,
} as const;
/** Project artifact identity and the complete context for a one-row summary. */
/** Project artifact identity, summary context, and coverage of retained members. */
export const artifactSummaryViewFields = <
Context extends { readonly artifact: z.output<typeof artifactSchema> },
>(
view: z.output<typeof summaryViewSchema>,
context: Context,
examined = 1,
) => ({
kind: "summary" as const,
view,
artifact: { path: context.artifact.path, sha256: context.artifact.sha256 },
summary: context,
coverage: completeWithinViewCoverage(1),
coverage: completeWithinViewCoverage(examined),
});
+25 -27
View File
@@ -1,3 +1,4 @@
import { artifactSummaryViewFields } from "./analysisViewBase.js";
import { viewParentIdentity } from "./viewParentIdentity.js";
import { z } from "zod";
import { debPackageSchema } from "../deb/debPackage.js";
@@ -10,10 +11,7 @@ import {
} from "./analysisViewShape.js";
import { invalidAnalysisView } from "./analysisViewErrors.js";
import { createAnalysisViewResultReader } from "./analysisViewParent.js";
import {
boundedViewLimitations,
completeWithinViewCoverage,
} from "./analysisViewCoverage.js";
import { boundedViewLimitations } from "./analysisViewCoverage.js";
/** Package identity and counts; member rows and relationships stay in the complete parent. */
export const debPackageSummarySchema = debPackageSchema
@@ -56,32 +54,32 @@ export const projectDebPackageView = (
const parsed = readReport(parent);
if (!parsed.ok) return parsed;
const report = parsed.value;
const summary = {
artifact: report.artifact,
ar: report.ar,
coverage: report.coverage,
package: report.control?.package ?? null,
version: report.control?.version?.raw ?? null,
architecture: report.control?.architecture ?? null,
relationship_group_count:
report.control === null
? 0
: relationshipGroupCount(report.control.relationships),
maintainer_script_count: report.control?.maintainer_scripts.length ?? 0,
data_entry_count: report.data_entries.length,
issue_count: report.issues.length,
limitation_count: report.limitations.length,
};
const { artifact, ...fields } = artifactSummaryViewFields(
view,
summary,
summary.data_entry_count,
);
return ok({
...viewParentIdentity(parent, "inspect_deb_package"),
artifact: {
path: report.artifact.path,
sha256: report.artifact.sha256,
},
artifact,
limitations: boundedViewLimitations(parent, report.limitations),
unknowns: [],
kind: "summary" as const,
view,
summary: {
artifact: report.artifact,
ar: report.ar,
coverage: report.coverage,
package: report.control?.package ?? null,
version: report.control?.version?.raw ?? null,
architecture: report.control?.architecture ?? null,
relationship_group_count:
report.control === null
? 0
: relationshipGroupCount(report.control.relationships),
maintainer_script_count: report.control?.maintainer_scripts.length ?? 0,
data_entry_count: report.data_entries.length,
issue_count: report.issues.length,
limitation_count: report.limitations.length,
},
coverage: completeWithinViewCoverage(report.data_entries.length),
...fields,
});
};
+24 -26
View File
@@ -1,3 +1,4 @@
import { artifactSummaryViewFields } from "./analysisViewBase.js";
import { viewParentIdentity } from "./viewParentIdentity.js";
import { z } from "zod";
import { nugetNupkgSchema } from "../nuget/nupkg.js";
@@ -10,10 +11,7 @@ import {
} from "./analysisViewShape.js";
import { invalidAnalysisView } from "./analysisViewErrors.js";
import { createAnalysisViewResultReader } from "./analysisViewParent.js";
import {
boundedViewLimitations,
completeWithinViewCoverage,
} from "./analysisViewCoverage.js";
import { boundedViewLimitations } from "./analysisViewCoverage.js";
/** Package identity and counts; member rows and dependencies stay in the complete parent. */
export const nugetNupkgSummarySchema = nugetNupkgSchema
@@ -47,31 +45,31 @@ export const projectNugetNupkgView = (
const parsed = readReport(parent);
if (!parsed.ok) return parsed;
const report = parsed.value;
const summary = {
artifact: report.artifact,
identity: report.identity,
license: report.license,
repository: report.repository,
nuspec: report.nuspec,
coverage: report.coverage,
dependency_group_count: report.dependency_groups.length,
dependency_count: report.dependency_groups.reduce(
(total, group) => total + group.dependencies.length,
0,
),
content_count: report.contents.length,
limitation_count: report.limitations.length,
};
const { artifact, ...fields } = artifactSummaryViewFields(
view,
summary,
summary.content_count,
);
return ok({
...viewParentIdentity(parent, "inspect_nuget_nupkg"),
artifact: {
path: report.artifact.path,
sha256: report.artifact.sha256,
},
artifact,
limitations: boundedViewLimitations(parent, report.limitations),
unknowns: [],
kind: "summary" as const,
view,
summary: {
artifact: report.artifact,
identity: report.identity,
license: report.license,
repository: report.repository,
nuspec: report.nuspec,
coverage: report.coverage,
dependency_group_count: report.dependency_groups.length,
dependency_count: report.dependency_groups.reduce(
(total, group) => total + group.dependencies.length,
0,
),
content_count: report.contents.length,
limitation_count: report.limitations.length,
},
coverage: completeWithinViewCoverage(report.contents.length),
...fields,
});
};
+30 -32
View File
@@ -1,3 +1,4 @@
import { artifactSummaryViewFields } from "./analysisViewBase.js";
import { viewParentIdentity } from "./viewParentIdentity.js";
import { z } from "zod";
import { vsixPackageSchema } from "../vsix/vsixPackage.js";
@@ -10,10 +11,7 @@ import {
} from "./analysisViewShape.js";
import { invalidAnalysisView } from "./analysisViewErrors.js";
import { createAnalysisViewResultReader } from "./analysisViewParent.js";
import {
boundedViewLimitations,
completeWithinViewCoverage,
} from "./analysisViewCoverage.js";
import { boundedViewLimitations } from "./analysisViewCoverage.js";
/** UTF-16 code-unit caps for summary text fields so summaries stay within the 32 KiB agent budget. */
const SUMMARY_TEXT_UNITS = 200;
@@ -145,41 +143,41 @@ export const projectVsixPackageView = (
`One or more summary text fields were truncated to fit the summary view; inspect parent Evidence ${parent.evidenceId} for complete values.`,
]
: [];
const summary = {
artifact: report.artifact,
vsix_identity: summaryVsixIdentity,
package_identity: summaryPackageIdentity,
identity_disagreements: summaryIdentityDisagreements,
engine: summaryEngine,
target_platform: summaryTargetPlatform,
entry_points: summaryEntryPoints,
signatures: report.signatures,
vsixmanifest: report.vsixmanifest,
package_json: report.package_json,
coverage: report.coverage,
text_truncated: textTruncated,
activation_event_count: report.activation_events.length,
eager_activation_event_count: eagerActivationEventCount,
contribute_key_count: report.contributes.keys.length,
command_count: report.contributes.commands_total,
content_count: report.contents.length,
interesting_member_count: report.interesting_members.length,
limitation_count: report.limitations.length,
};
const { artifact, ...fields } = artifactSummaryViewFields(
view,
summary,
summary.content_count,
);
return ok({
...viewParentIdentity(parent, "inspect_vsix_package"),
artifact: {
path: report.artifact.path,
sha256: report.artifact.sha256,
},
artifact,
limitations: boundedViewLimitations(
parent,
report.limitations,
requiredLimitations,
),
unknowns: [],
kind: "summary" as const,
view,
summary: {
artifact: report.artifact,
vsix_identity: summaryVsixIdentity,
package_identity: summaryPackageIdentity,
identity_disagreements: summaryIdentityDisagreements,
engine: summaryEngine,
target_platform: summaryTargetPlatform,
entry_points: summaryEntryPoints,
signatures: report.signatures,
vsixmanifest: report.vsixmanifest,
package_json: report.package_json,
coverage: report.coverage,
text_truncated: textTruncated,
activation_event_count: report.activation_events.length,
eager_activation_event_count: eagerActivationEventCount,
contribute_key_count: report.contributes.keys.length,
command_count: report.contributes.commands_total,
content_count: report.contents.length,
interesting_member_count: report.interesting_members.length,
limitation_count: report.limitations.length,
},
coverage: completeWithinViewCoverage(report.contents.length),
...fields,
});
};