mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 15:33:56 +08:00
refactor(application): migrate 7 standalone format services onto executeArtifactInspection (#13861)
Closes #13860
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { ElectronFusePort } from "../../ports/electron/ElectronFusePort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
import {
|
||||
electronFuseReportSchema,
|
||||
inspectElectronFusesInputSchema,
|
||||
} from "../../domain/electron/electronFuses.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import { createElectronFuseEvidence } from "../../domain/electron/electronFuseEvidence.js";
|
||||
import { err, type Result } from "../../domain/result.js";
|
||||
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
||||
import { parseAnalysisInput } from "../AnalysisInput.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
const OPERATION = "inspect_electron_fuses";
|
||||
|
||||
@@ -24,37 +22,26 @@ export class ElectronFuseService {
|
||||
}
|
||||
|
||||
/** Read fuse wires for one explicitly selected path without launching it. */
|
||||
async inspect(
|
||||
inspect(
|
||||
rawInput: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
const input = parseAnalysisInput(
|
||||
OPERATION,
|
||||
rawInput,
|
||||
inspectElectronFusesInputSchema,
|
||||
options?.signal,
|
||||
);
|
||||
if (!input.ok) return input;
|
||||
const inspected = await this.provider.inspect(input.value, options);
|
||||
if (!inspected.ok) return inspected;
|
||||
const report = electronFuseReportSchema.safeParse(inspected.value);
|
||||
if (
|
||||
!report.success ||
|
||||
report.data.artifact.selected_path !== input.value.path
|
||||
)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
OPERATION,
|
||||
return executeArtifactInspection(
|
||||
{
|
||||
operation: OPERATION,
|
||||
inputSchema: inspectElectronFusesInputSchema,
|
||||
outputSchema: electronFuseReportSchema,
|
||||
provider: this.provider,
|
||||
invalidOutputMessage:
|
||||
"Electron fuse reader returned a malformed report or changed the selected artifact identity.",
|
||||
),
|
||||
);
|
||||
return completeProviderEvidence(
|
||||
createElectronFuseEvidence(
|
||||
input.value,
|
||||
report.data,
|
||||
this.provider.identity,
|
||||
),
|
||||
options?.signal,
|
||||
toParameters: (input) => input,
|
||||
validateReport: (report, parameters) =>
|
||||
report.artifact.selected_path === parameters.path,
|
||||
buildEvidence: (report, identity, parameters) =>
|
||||
createElectronFuseEvidence(parameters, report, identity),
|
||||
},
|
||||
rawInput,
|
||||
options,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { BeamPort } from "../../ports/erlang/BeamPort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
inspectErlangBeamInputSchema,
|
||||
erlangBeamSchema,
|
||||
type ErlangBeam,
|
||||
} from "../../domain/erlang/beam.js";
|
||||
import { err, type Result } from "../../domain/result.js";
|
||||
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
||||
import { parseAnalysisInput } from "../AnalysisInput.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
const OPERATION = "inspect_erlang_beam";
|
||||
|
||||
@@ -22,62 +20,54 @@ export class BeamService {
|
||||
return this.provider.close();
|
||||
}
|
||||
|
||||
async inspect(
|
||||
inspect(
|
||||
rawInput: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
const input = parseAnalysisInput(
|
||||
OPERATION,
|
||||
rawInput,
|
||||
inspectErlangBeamInputSchema,
|
||||
options?.signal,
|
||||
);
|
||||
if (!input.ok) return input;
|
||||
const result = await this.provider.inspect(input.value, options);
|
||||
if (!result.ok) return result;
|
||||
const report = erlangBeamSchema.safeParse(result.value);
|
||||
if (
|
||||
!report.success ||
|
||||
report.data.artifact.path !== input.value.path ||
|
||||
!validReport(
|
||||
report.data,
|
||||
input.value.max_chunks,
|
||||
input.value.max_atoms,
|
||||
input.value.max_file_bytes,
|
||||
)
|
||||
)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
OPERATION,
|
||||
return executeArtifactInspection(
|
||||
{
|
||||
operation: OPERATION,
|
||||
inputSchema: inspectErlangBeamInputSchema,
|
||||
outputSchema: erlangBeamSchema,
|
||||
provider: this.provider,
|
||||
invalidOutputMessage:
|
||||
"BEAM provider returned malformed output or changed artifact identity.",
|
||||
),
|
||||
);
|
||||
const value = report.data;
|
||||
return completeProviderEvidence(
|
||||
createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
format: "file",
|
||||
sha256: value.artifact.sha256,
|
||||
},
|
||||
this.provider.identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters: input.value,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [
|
||||
{ kind: "artifact-path" as const, path: value.artifact.path },
|
||||
toParameters: (input) => input,
|
||||
validateReport: (report, parameters) =>
|
||||
report.artifact.path === parameters.path &&
|
||||
validReport(
|
||||
report,
|
||||
parameters.max_chunks,
|
||||
parameters.max_atoms,
|
||||
parameters.max_file_bytes,
|
||||
),
|
||||
buildEvidence: (value, identity, parameters) =>
|
||||
createEvidence(
|
||||
{
|
||||
kind: "file-offset-range" as const,
|
||||
start: value.form.location.offset,
|
||||
end: value.form.location.offset + value.form.location.bytes,
|
||||
path: value.artifact.path,
|
||||
format: "file",
|
||||
sha256: value.artifact.sha256,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
options?.signal,
|
||||
identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [
|
||||
{ kind: "artifact-path" as const, path: value.artifact.path },
|
||||
{
|
||||
kind: "file-offset-range" as const,
|
||||
start: value.form.location.offset,
|
||||
end: value.form.location.offset + value.form.location.bytes,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
rawInput,
|
||||
options,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,26 +6,16 @@ import {
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { GoBinaryPort } from "../../ports/go/GoBinaryPort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
goBinarySchema,
|
||||
inspectGoBinaryInputSchema,
|
||||
} from "../../domain/go/goBinary.js";
|
||||
import { err, type Result } from "../../domain/result.js";
|
||||
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
||||
import { parseAnalysisInput } from "../AnalysisInput.js";
|
||||
import {
|
||||
requireAnalysisViewRetention,
|
||||
summarizeRetainedAnalysis,
|
||||
type AnalysisViewRetention,
|
||||
} from "../analysisView/AnalysisViewService.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import type { AnalysisViewRetention } from "../analysisView/AnalysisViewService.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
const OPERATION = "inspect_go_binary";
|
||||
const NO_RETENTION: AnalysisViewRetention = {
|
||||
recordEvidence: undefined,
|
||||
evidenceById: undefined,
|
||||
};
|
||||
|
||||
/** Shared exact input validation and artifact-bound Evidence for CLI and MCP. */
|
||||
export class GoBinaryService {
|
||||
@@ -36,76 +26,63 @@ export class GoBinaryService {
|
||||
}
|
||||
|
||||
/** Inspect one explicitly selected file without acquiring a binary session. */
|
||||
async inspect(
|
||||
inspect(
|
||||
rawInput: unknown,
|
||||
options?: ExecutionOptions,
|
||||
retention: AnalysisViewRetention = NO_RETENTION,
|
||||
retention?: AnalysisViewRetention,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
const input = parseAnalysisInput(
|
||||
OPERATION,
|
||||
rawInput,
|
||||
inspectGoBinaryInputSchema,
|
||||
options?.signal,
|
||||
);
|
||||
if (!input.ok) return input;
|
||||
const { detail, ...providerInput } = input.value;
|
||||
if (detail === "summary") {
|
||||
const ready = requireAnalysisViewRetention(OPERATION, retention);
|
||||
if (!ready.ok) return ready;
|
||||
}
|
||||
const inspected = await this.provider.inspect(providerInput, options);
|
||||
if (!inspected.ok) return inspected;
|
||||
const report = goBinarySchema.safeParse(inspected.value);
|
||||
if (
|
||||
!report.success ||
|
||||
report.data.artifact.path !== input.value.path ||
|
||||
!machoSelectionAnswersArchitecture(
|
||||
report.data.selected_slice,
|
||||
input.value.architecture,
|
||||
)
|
||||
)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
OPERATION,
|
||||
return executeArtifactInspection(
|
||||
{
|
||||
operation: OPERATION,
|
||||
inputSchema: inspectGoBinaryInputSchema,
|
||||
outputSchema: goBinarySchema,
|
||||
provider: this.provider,
|
||||
invalidOutputMessage:
|
||||
"Go build-information reader returned malformed metadata or changed the selected artifact or slice identity.",
|
||||
),
|
||||
);
|
||||
const value = report.data;
|
||||
const architecture = binaryMetadataArchitecture(value.architecture);
|
||||
const completed = completeProviderEvidence(
|
||||
createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
sha256: value.artifact.sha256,
|
||||
format: metadataReportSubjectFormat(value),
|
||||
...(architecture === undefined ? {} : { architecture }),
|
||||
toParameters: ({ detail: _detail, ...providerInput }) => providerInput,
|
||||
selectRetainedView: ({ detail }) =>
|
||||
detail === "summary" ? { kind: "summary" } : undefined,
|
||||
validateReport: (report, parameters) =>
|
||||
report.artifact.path === parameters.path &&
|
||||
machoSelectionAnswersArchitecture(
|
||||
report.selected_slice,
|
||||
parameters.architecture,
|
||||
),
|
||||
buildEvidence: (value, identity, parameters) => {
|
||||
const architecture = binaryMetadataArchitecture(value.architecture);
|
||||
return createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
sha256: value.artifact.sha256,
|
||||
format: metadataReportSubjectFormat(value),
|
||||
...(architecture === undefined ? {} : { architecture }),
|
||||
},
|
||||
identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [
|
||||
{ kind: "artifact-path", path: value.artifact.path },
|
||||
...(value.build_info === null
|
||||
? []
|
||||
: [
|
||||
{
|
||||
kind: "file-offset-range" as const,
|
||||
start: value.build_info.header_offset,
|
||||
end: value.build_info.header_offset + 32,
|
||||
},
|
||||
]),
|
||||
],
|
||||
},
|
||||
);
|
||||
},
|
||||
this.provider.identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters: providerInput,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [
|
||||
{ kind: "artifact-path", path: value.artifact.path },
|
||||
...(value.build_info === null
|
||||
? []
|
||||
: [
|
||||
{
|
||||
kind: "file-offset-range" as const,
|
||||
start: value.build_info.header_offset,
|
||||
end: value.build_info.header_offset + 32,
|
||||
},
|
||||
]),
|
||||
],
|
||||
},
|
||||
),
|
||||
options?.signal,
|
||||
},
|
||||
rawInput,
|
||||
options,
|
||||
retention,
|
||||
);
|
||||
if (!completed.ok) return completed;
|
||||
return detail === "summary"
|
||||
? summarizeRetainedAnalysis(completed.value, retention)
|
||||
: completed;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { NugetNupkgPort } from "../../ports/nuget/NugetNupkgPort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
inspectNugetNupkgInputSchema,
|
||||
nugetNupkgSchema,
|
||||
type NugetNupkg,
|
||||
} from "../../domain/nuget/nupkg.js";
|
||||
import { err, type Result } from "../../domain/result.js";
|
||||
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
||||
import {
|
||||
callerAnalysisParameters,
|
||||
parseAnalysisInput,
|
||||
} from "../AnalysisInput.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { callerAnalysisParameters } from "../AnalysisInput.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
const OPERATION = "inspect_nuget_nupkg";
|
||||
|
||||
@@ -25,53 +21,45 @@ export class NugetNupkgService {
|
||||
return this.provider.close();
|
||||
}
|
||||
|
||||
async inspect(
|
||||
inspect(
|
||||
rawInput: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
const selectedParameters = callerAnalysisParameters(rawInput);
|
||||
const input = parseAnalysisInput(
|
||||
OPERATION,
|
||||
rawInput,
|
||||
inspectNugetNupkgInputSchema,
|
||||
options?.signal,
|
||||
);
|
||||
if (!input.ok) return input;
|
||||
const result = await this.provider.inspect(input.value, options);
|
||||
if (!result.ok) return result;
|
||||
const report = nugetNupkgSchema.safeParse(result.value);
|
||||
if (
|
||||
!report.success ||
|
||||
report.data.artifact.path !== input.value.path ||
|
||||
!validReport(report.data, input.value)
|
||||
)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
OPERATION,
|
||||
return executeArtifactInspection(
|
||||
{
|
||||
operation: OPERATION,
|
||||
inputSchema: inspectNugetNupkgInputSchema,
|
||||
outputSchema: nugetNupkgSchema,
|
||||
provider: this.provider,
|
||||
invalidOutputMessage:
|
||||
"NuGet nupkg provider returned malformed output or changed artifact identity.",
|
||||
),
|
||||
);
|
||||
const value = report.data;
|
||||
return completeProviderEvidence(
|
||||
createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
format: "file",
|
||||
sha256: value.artifact.sha256,
|
||||
},
|
||||
this.provider.identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters: selectedParameters(input.value),
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [
|
||||
{ kind: "artifact-path" as const, path: value.artifact.path },
|
||||
],
|
||||
},
|
||||
),
|
||||
options?.signal,
|
||||
toParameters: (input) => input,
|
||||
validateReport: (report, parameters) =>
|
||||
report.artifact.path === parameters.path &&
|
||||
validReport(report, parameters),
|
||||
buildEvidence: (value, identity, parameters) =>
|
||||
createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
format: "file",
|
||||
sha256: value.artifact.sha256,
|
||||
},
|
||||
identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters: selectedParameters(parameters),
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [
|
||||
{ kind: "artifact-path" as const, path: value.artifact.path },
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
rawInput,
|
||||
options,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { PythonPycPort } from "../../ports/python/PythonPycPort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
inspectPythonPycInputSchema,
|
||||
PYTHON_PYC_HEADER_BYTES,
|
||||
pythonPycSchema,
|
||||
} from "../../domain/python/pythonPyc.js";
|
||||
import { err, type Result } from "../../domain/result.js";
|
||||
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
||||
import { parseAnalysisInput } from "../AnalysisInput.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
const OPERATION = "inspect_python_pyc";
|
||||
|
||||
@@ -22,64 +20,56 @@ export class PythonPycService {
|
||||
return this.provider.close();
|
||||
}
|
||||
|
||||
async inspect(
|
||||
inspect(
|
||||
rawInput: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
const input = parseAnalysisInput(
|
||||
OPERATION,
|
||||
rawInput,
|
||||
inspectPythonPycInputSchema,
|
||||
options?.signal,
|
||||
);
|
||||
if (!input.ok) return input;
|
||||
const result = await this.provider.inspect(input.value, options);
|
||||
if (!result.ok) return result;
|
||||
const report = pythonPycSchema.safeParse(result.value);
|
||||
if (
|
||||
!report.success ||
|
||||
report.data.artifact.path !== input.value.path ||
|
||||
report.data.artifact.bytes > input.value.max_file_bytes ||
|
||||
report.data.coverage.objects > input.value.max_objects ||
|
||||
report.data.coverage.marshal_depth > input.value.max_depth
|
||||
)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
OPERATION,
|
||||
return executeArtifactInspection(
|
||||
{
|
||||
operation: OPERATION,
|
||||
inputSchema: inspectPythonPycInputSchema,
|
||||
outputSchema: pythonPycSchema,
|
||||
provider: this.provider,
|
||||
invalidOutputMessage:
|
||||
"Python pyc provider returned malformed output or changed artifact identity.",
|
||||
),
|
||||
);
|
||||
const value = report.data;
|
||||
return completeProviderEvidence(
|
||||
createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
format: "file",
|
||||
sha256: value.artifact.sha256,
|
||||
},
|
||||
this.provider.identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters: input.value,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [
|
||||
{ kind: "artifact-path", path: value.artifact.path },
|
||||
toParameters: (input) => input,
|
||||
validateReport: (report, parameters) =>
|
||||
report.artifact.path === parameters.path &&
|
||||
report.artifact.bytes <= parameters.max_file_bytes &&
|
||||
report.coverage.objects <= parameters.max_objects &&
|
||||
report.coverage.marshal_depth <= parameters.max_depth,
|
||||
buildEvidence: (value, identity, parameters) =>
|
||||
createEvidence(
|
||||
{
|
||||
kind: "file-offset-range",
|
||||
start: 0,
|
||||
end: PYTHON_PYC_HEADER_BYTES,
|
||||
path: value.artifact.path,
|
||||
format: "file",
|
||||
sha256: value.artifact.sha256,
|
||||
},
|
||||
identity,
|
||||
{
|
||||
kind: "file-offset-range",
|
||||
start: PYTHON_PYC_HEADER_BYTES,
|
||||
end: value.artifact.bytes,
|
||||
operation: OPERATION,
|
||||
parameters,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [
|
||||
{ kind: "artifact-path", path: value.artifact.path },
|
||||
{
|
||||
kind: "file-offset-range",
|
||||
start: 0,
|
||||
end: PYTHON_PYC_HEADER_BYTES,
|
||||
},
|
||||
{
|
||||
kind: "file-offset-range",
|
||||
start: PYTHON_PYC_HEADER_BYTES,
|
||||
end: value.artifact.bytes,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
options?.signal,
|
||||
),
|
||||
},
|
||||
rawInput,
|
||||
options,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,21 +6,15 @@ import {
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { RustBinaryPort } from "../../ports/rust/RustBinaryPort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
rustBinarySchema,
|
||||
type InspectRustBinaryInput,
|
||||
} from "../../domain/rust/rustBinary.js";
|
||||
import { inspectRustBinaryRequestSchema } from "../../domain/rust/rustBinaryQuery.js";
|
||||
import { err, type Result } from "../../domain/result.js";
|
||||
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
||||
import { parseAnalysisInput } from "../AnalysisInput.js";
|
||||
import {
|
||||
requireAnalysisViewRetention,
|
||||
projectRetainedAnalysis,
|
||||
type AnalysisViewRetention,
|
||||
} from "../analysisView/AnalysisViewService.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import type { AnalysisViewRetention } from "../analysisView/AnalysisViewService.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
const OPERATION = "inspect_rust_binary";
|
||||
|
||||
@@ -33,55 +27,40 @@ export class RustBinaryService {
|
||||
}
|
||||
|
||||
/** Inspect one explicitly selected file without acquiring a binary session. */
|
||||
async inspect(
|
||||
inspect(
|
||||
rawInput: unknown,
|
||||
options?: ExecutionOptions,
|
||||
retention: AnalysisViewRetention = {
|
||||
recordEvidence: undefined,
|
||||
evidenceById: undefined,
|
||||
},
|
||||
retention?: AnalysisViewRetention,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
const input = parseAnalysisInput(
|
||||
OPERATION,
|
||||
rawInput,
|
||||
inspectRustBinaryRequestSchema,
|
||||
options?.signal,
|
||||
);
|
||||
if (!input.ok) return input;
|
||||
const { detail, view, ...parameters } = input.value;
|
||||
const compact = detail === "summary" || view !== undefined;
|
||||
if (compact) {
|
||||
const ready = requireAnalysisViewRetention(OPERATION, retention);
|
||||
if (!ready.ok) return ready;
|
||||
}
|
||||
const inspected = await this.provider.inspect(parameters, options);
|
||||
if (!inspected.ok) return inspected;
|
||||
const report = rustBinarySchema.safeParse(inspected.value);
|
||||
if (
|
||||
!report.success ||
|
||||
report.data.artifact.path !== input.value.path ||
|
||||
!machoSelectionAnswersArchitecture(
|
||||
report.data.selected_slice,
|
||||
input.value.architecture,
|
||||
)
|
||||
)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
OPERATION,
|
||||
return executeArtifactInspection(
|
||||
{
|
||||
operation: OPERATION,
|
||||
inputSchema: inspectRustBinaryRequestSchema,
|
||||
outputSchema: rustBinarySchema,
|
||||
provider: this.provider,
|
||||
invalidOutputMessage:
|
||||
"Rust dependency reader returned malformed metadata or changed the selected artifact or slice identity.",
|
||||
),
|
||||
);
|
||||
const completed = completeProviderEvidence(
|
||||
evidenceFor(this.provider.identity, parameters, report.data),
|
||||
options?.signal,
|
||||
toParameters: ({ detail: _detail, view: _view, ...parameters }) =>
|
||||
parameters,
|
||||
selectRetainedView: ({ detail, view }) =>
|
||||
detail === "summary" || view !== undefined
|
||||
? view === undefined
|
||||
? { kind: "summary" }
|
||||
: { kind: "rust", ...view }
|
||||
: undefined,
|
||||
validateReport: (report, parameters) =>
|
||||
report.artifact.path === parameters.path &&
|
||||
machoSelectionAnswersArchitecture(
|
||||
report.selected_slice,
|
||||
parameters.architecture,
|
||||
),
|
||||
buildEvidence: (report, identity, parameters) =>
|
||||
evidenceFor(identity, parameters, report),
|
||||
},
|
||||
rawInput,
|
||||
options,
|
||||
retention,
|
||||
);
|
||||
return compact && completed.ok
|
||||
? projectRetainedAnalysis(
|
||||
completed.value,
|
||||
retention,
|
||||
view === undefined ? { kind: "summary" } : { kind: "rust", ...view },
|
||||
)
|
||||
: completed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { V8CodeCachePort } from "../../ports/v8CodeCache/V8CodeCachePort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { AnalysisOutputError } from "../../domain/analysisErrorCore.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
inspectV8CodeCacheInputSchema,
|
||||
v8CodeCacheSchema,
|
||||
type V8CodeCache,
|
||||
} from "../../domain/v8/v8CodeCache.js";
|
||||
import { err, type Result } from "../../domain/result.js";
|
||||
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
||||
import { parseAnalysisInput } from "../AnalysisInput.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
const OPERATION = "inspect_v8_code_cache";
|
||||
|
||||
@@ -22,57 +20,49 @@ export class V8CodeCacheService {
|
||||
return this.provider.close();
|
||||
}
|
||||
|
||||
async inspect(
|
||||
inspect(
|
||||
rawInput: unknown,
|
||||
options?: ExecutionOptions,
|
||||
): Promise<Result<Evidence, AnalysisError>> {
|
||||
const input = parseAnalysisInput(
|
||||
OPERATION,
|
||||
rawInput,
|
||||
inspectV8CodeCacheInputSchema,
|
||||
options?.signal,
|
||||
);
|
||||
if (!input.ok) return input;
|
||||
const result = await this.provider.inspect(input.value, options);
|
||||
if (!result.ok) return result;
|
||||
const report = v8CodeCacheSchema.safeParse(result.value);
|
||||
if (
|
||||
!report.success ||
|
||||
report.data.artifact.path !== input.value.path ||
|
||||
!validReport(report.data, input.value)
|
||||
)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
OPERATION,
|
||||
return executeArtifactInspection(
|
||||
{
|
||||
operation: OPERATION,
|
||||
inputSchema: inspectV8CodeCacheInputSchema,
|
||||
outputSchema: v8CodeCacheSchema,
|
||||
provider: this.provider,
|
||||
invalidOutputMessage:
|
||||
"V8 code cache provider returned malformed output or changed artifact identity.",
|
||||
),
|
||||
);
|
||||
const value = report.data;
|
||||
return completeProviderEvidence(
|
||||
createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
format: "file",
|
||||
sha256: value.artifact.sha256,
|
||||
},
|
||||
this.provider.identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters: input.value,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [
|
||||
{ kind: "artifact-path" as const, path: value.artifact.path },
|
||||
toParameters: (input) => input,
|
||||
validateReport: (report, parameters) =>
|
||||
report.artifact.path === parameters.path &&
|
||||
validReport(report, parameters),
|
||||
buildEvidence: (value, identity, parameters) =>
|
||||
createEvidence(
|
||||
{
|
||||
kind: "file-offset-range" as const,
|
||||
start: value.payload.offset,
|
||||
end: value.payload.offset + value.payload.bytes,
|
||||
path: value.artifact.path,
|
||||
format: "file",
|
||||
sha256: value.artifact.sha256,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
options?.signal,
|
||||
identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [
|
||||
{ kind: "artifact-path" as const, path: value.artifact.path },
|
||||
{
|
||||
kind: "file-offset-range" as const,
|
||||
start: value.payload.offset,
|
||||
end: value.payload.offset + value.payload.bytes,
|
||||
},
|
||||
],
|
||||
},
|
||||
),
|
||||
},
|
||||
rawInput,
|
||||
options,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user