mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 22:45:47 +00:00
perf(firmware): hoist per-record Zod schemas, fuse report scans, and fast-path extractionProblemFacts (#13542)
This commit is contained in:
1 parent
c7401ea330
commit
234f42bec1
1 file changed
+29
-23
@@ -65,6 +65,12 @@ const multiFile = z.object({
|
||||
extraction_reports: z.array(jsonValueSchema),
|
||||
});
|
||||
const hashes = z.object({ sha256: digestSchema });
|
||||
const fileMagic = z.object({ mime_type: z.string() });
|
||||
const chunkDetail = z.object({
|
||||
handler_name: z.string(),
|
||||
is_encrypted: z.boolean(),
|
||||
extraction_reports: z.array(jsonValueSchema),
|
||||
});
|
||||
/**
|
||||
* The provider's structured missing-dependency report. Non-strict on purpose:
|
||||
* unfamiliar extra fields stay in retained diagnostics, only the dependency
|
||||
@@ -94,15 +100,23 @@ const extractionProblemFacts = (
|
||||
const kinds = new Set<ExtractionFailureKind>();
|
||||
let dependencies: DependencyFacts | null = null;
|
||||
for (const item of reports) {
|
||||
const parsed = missingDependency.safeParse(item);
|
||||
if (parsed.success) {
|
||||
if (typeof item !== "object" || item === null) continue;
|
||||
const candidate = item as Record<string, unknown>;
|
||||
const parsed =
|
||||
candidate.__typename__ === "ExtractorDependencyNotFoundReport"
|
||||
? missingDependency.safeParse(item)
|
||||
: null;
|
||||
if (parsed?.success) {
|
||||
kinds.add("missing-extractor-dependency");
|
||||
dependencies ??= { names: new Set<string>(), unnamed: false };
|
||||
if (parsed.data.dependencies.length === 0) dependencies.unnamed = true;
|
||||
for (const name of parsed.data.dependencies)
|
||||
if (name === "") dependencies.unnamed = true;
|
||||
else dependencies.names.add(name);
|
||||
} else if (extractionError.safeParse(item).success)
|
||||
} else if (
|
||||
candidate.severity === "ERROR" &&
|
||||
extractionError.safeParse(item).success
|
||||
)
|
||||
kinds.add("extractor-failure");
|
||||
}
|
||||
return { failureKinds: [...kinds], dependencies };
|
||||
@@ -327,9 +341,16 @@ export const normalizeUnblobReport = (
|
||||
);
|
||||
seen.add(path);
|
||||
if (record.task.depth >= context.maxDepth) depths.push(path);
|
||||
const metadata = record.reports.find(
|
||||
(r) => r.__typename__ === "StatReport",
|
||||
);
|
||||
let metadata: (typeof record.reports)[number] | undefined;
|
||||
let hash: (typeof record.reports)[number] | undefined;
|
||||
let magic: (typeof record.reports)[number] | undefined;
|
||||
for (const r of record.reports) {
|
||||
if (metadata === undefined && r.__typename__ === "StatReport")
|
||||
metadata = r;
|
||||
else if (hash === undefined && r.__typename__ === "HashReport") hash = r;
|
||||
else if (magic === undefined && r.__typename__ === "FileMagicReport")
|
||||
magic = r;
|
||||
}
|
||||
if (metadata === undefined)
|
||||
throw new AnalysisOutputError(
|
||||
"extract_firmware",
|
||||
@@ -355,17 +376,10 @@ export const normalizeUnblobReport = (
|
||||
"Selected input was not reported as a regular file",
|
||||
);
|
||||
sizes.set(path, parsedStat.size);
|
||||
const hash = record.reports.find((r) => r.__typename__ === "HashReport");
|
||||
const magic = record.reports.find(
|
||||
(r) => r.__typename__ === "FileMagicReport",
|
||||
);
|
||||
if (parsedStat.is_file && !parsedStat.is_link)
|
||||
files.set(path, {
|
||||
sha256: hash === undefined ? null : hashes.parse(hash).sha256,
|
||||
mimeType:
|
||||
magic === undefined
|
||||
? null
|
||||
: z.object({ mime_type: z.string() }).parse(magic).mime_type,
|
||||
mimeType: magic === undefined ? null : fileMagic.parse(magic).mime_type,
|
||||
depth: record.task.depth,
|
||||
});
|
||||
for (const item of record.reports) {
|
||||
@@ -403,15 +417,7 @@ export const normalizeUnblobReport = (
|
||||
`Invalid chunk bounds for ${path}`,
|
||||
);
|
||||
const detail =
|
||||
item.__typename__ === "ChunkReport"
|
||||
? z
|
||||
.object({
|
||||
handler_name: z.string(),
|
||||
is_encrypted: z.boolean(),
|
||||
extraction_reports: z.array(jsonValueSchema),
|
||||
})
|
||||
.parse(item)
|
||||
: null;
|
||||
item.__typename__ === "ChunkReport" ? chunkDetail.parse(item) : null;
|
||||
const problems = extractionProblemFacts(
|
||||
detail?.extraction_reports ?? [],
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user