mirror of
https://github.com/morluto/rea.git
synced 2026-12-03 13:41:17 -05:00
5f718ce30e
* refactor(kernel): give error-to-message text one owner in a new src/kernel layer * fix(kernel): keep the regex worker's own error text inside its isolated source * refactor(kernel): exclude copies that run in another realm from the error-message guard by name The regex worker's source string and the page.evaluate fetch in PlaywrightScenarioRequest cannot import errorMessage. The guard now names them, so the counted baseline does not invite a later slice to rewrite them. * refactor(kernel): migrate the long tail of inline error-message copies to errorMessage (#11552) Every provider and adapter folder with six or fewer copies now calls errorMessage from src/kernel. Local helpers whose whole body was the copy (failureMessage, gdbErrorMessage, message, describe, reasonOf, recoveryFailureMessage and four local errorMessage definitions) are removed and their call sites call the owner. Refs #11548 * refactor(kernel): give byte-to-hex formatting one owner in src/kernel (#11560) byteToHex returns the two lowercase hexadecimal digits of one byte. All eight inline copies (native, contracts, domain firmware and desktop, pcap) call it, keeping their own 0x, % or \x notation, and a counted guard with an empty baseline keeps new copies out. Refs #11548 * refactor(kernel): give one-shot SHA-256 hex digests one owner in src/kernel (#11562) sha256Hex digests one in-memory value. A counted guard records the one-shot createHash("sha256").update(x).digest("hex") chains (115 in 101 files) and the first slice migrates domain, contracts and process (35 copies), removing local wrappers (sha256, sha256Text, hash) and the exported sha256Text. Incremental and streamed hashing is not counted. Refs #11548 * refactor(kernel): migrate the application layer's inline error-message copies to errorMessage (#11563) All 69 copies in src/application call errorMessage from src/kernel. Local helpers whose whole body was the copy (errorDetail, causeReason and five local errorMessage definitions) are removed and their call sites call the owner. Refs #11548 * refactor(kernel): migrate the native provider's inline error-message copies to errorMessage (#11567) All 49 copies in src/native call errorMessage from src/kernel. The local errorReason helpers in LldbCallTracer and LldbRetainedObservations, whose whole body was the copy, are removed and their call sites call the owner. Refs #11548 * refactor(kernel): migrate the remaining inline error-message copies to errorMessage (#11569)
174 lines
5.3 KiB
TypeScript
174 lines
5.3 KiB
TypeScript
import { PYTHON_PYC_PROVIDER_IDENTITY } from "./PythonPycProviderIdentity.js";
|
|
import {
|
|
projectSelectedArtifactFileFailure,
|
|
projectOwnedArtifactIdentityFailure,
|
|
projectStableArtifactFailure,
|
|
stableArtifactInputFailure,
|
|
projectArtifactCloseFailure,
|
|
artifactFilePrimaryFacts,
|
|
type ArtifactFilePrimaryFacts,
|
|
ArtifactReaderFailure,
|
|
type StableArtifactSnapshot,
|
|
readStableArtifact,
|
|
ArtifactResourceScope,
|
|
} from "../resources/index.js";
|
|
import type { PythonPycPort } from "../ports/python/PythonPycPort.js";
|
|
import type { ExecutionOptions } from "../ports/AnalysisProvider.js";
|
|
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
|
import { AnalysisResourceConstraintError } from "../domain/analysisErrorCore.js";
|
|
import {
|
|
PYTHON_PYC_LIMIT_MAXIMA,
|
|
type InspectPythonPycInput,
|
|
} from "../domain/python/pythonPyc.js";
|
|
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
|
import { err, ok } from "../domain/result.js";
|
|
import { PythonPycResourceFailure } from "./PythonPyc.errors.js";
|
|
import { parseFailureAnalysisError } from "../domain/parseFailureAnalysisError.js";
|
|
import { parsePythonPyc } from "./PythonPycParser.js";
|
|
import { errorMessage } from "../kernel/errorMessage.js";
|
|
|
|
const OPERATION = "inspect_python_pyc";
|
|
|
|
const parserLimitRecovery = (
|
|
limits: PythonPycResourceFailure["reported_limits"],
|
|
) => {
|
|
const actions = (
|
|
Object.keys(
|
|
PYTHON_PYC_LIMIT_MAXIMA,
|
|
) as (keyof typeof PYTHON_PYC_LIMIT_MAXIMA)[]
|
|
).flatMap((field) => {
|
|
const selected = limits[field];
|
|
if (selected === undefined) return [];
|
|
const maximum = PYTHON_PYC_LIMIT_MAXIMA[field];
|
|
const option = `--${field.replaceAll("_", "-")}`;
|
|
return [
|
|
selected < maximum
|
|
? `Raise ${field} (${option}) above ${selected}, up to ${maximum}, on the next call.`
|
|
: `${field} (${option}) is at this operation's maximum of ${maximum}; select a complete artifact within that bound.`,
|
|
];
|
|
});
|
|
return {
|
|
retryable: false as const,
|
|
remediationAction: `${actions.join(" ")} Repeating the unchanged request fails the same way; waiting or adding host memory does not raise these parser limits.`,
|
|
};
|
|
};
|
|
|
|
const failureForPrimary = (
|
|
facts: ArtifactFilePrimaryFacts,
|
|
input: InspectPythonPycInput,
|
|
) => {
|
|
const { cause, origin } = facts;
|
|
if (origin === "owned-or-classified" && cause instanceof AnalysisError)
|
|
return cause;
|
|
const identityFailure = projectOwnedArtifactIdentityFailure(
|
|
facts,
|
|
OPERATION,
|
|
input.path,
|
|
);
|
|
if (identityFailure !== undefined) return identityFailure;
|
|
if (cause instanceof PythonPycResourceFailure)
|
|
return new AnalysisResourceConstraintError(
|
|
OPERATION,
|
|
cause.boundary === "depth" ? "capacity" : "memory",
|
|
cause.message,
|
|
cause.reported_limits,
|
|
{ cause, ...parserLimitRecovery(cause.reported_limits) },
|
|
);
|
|
const formatFailure = parseFailureAnalysisError(OPERATION, input.path, cause);
|
|
if (formatFailure !== undefined) return formatFailure;
|
|
if (
|
|
origin === "owned-or-classified" &&
|
|
cause instanceof ArtifactReaderFailure
|
|
) {
|
|
if (cause.reason === "limit")
|
|
return new AnalysisResourceConstraintError(
|
|
OPERATION,
|
|
"file-size",
|
|
cause.message,
|
|
{ max_file_bytes: input.max_file_bytes },
|
|
{
|
|
cause,
|
|
...parserLimitRecovery({ max_file_bytes: input.max_file_bytes }),
|
|
},
|
|
);
|
|
if (cause.reason === "path" || cause.reason === "format")
|
|
return stableArtifactInputFailure(cause, OPERATION);
|
|
}
|
|
const fileFailure = projectSelectedArtifactFileFailure(
|
|
cause,
|
|
OPERATION,
|
|
input.path,
|
|
"pyc",
|
|
);
|
|
if (fileFailure !== undefined) return fileFailure;
|
|
return new ProviderAdapterError(PYTHON_PYC_PROVIDER_IDENTITY.id, OPERATION, {
|
|
cause,
|
|
diagnostics: {
|
|
path: input.path,
|
|
reason: errorMessage(cause),
|
|
},
|
|
});
|
|
};
|
|
|
|
const failureFor = (
|
|
cause: unknown,
|
|
input: InspectPythonPycInput,
|
|
snapshot?: StableArtifactSnapshot,
|
|
) => {
|
|
const primary = failureForPrimary(artifactFilePrimaryFacts(cause), input);
|
|
return projectStableArtifactFailure(
|
|
cause,
|
|
primary,
|
|
input.path,
|
|
PYTHON_PYC_PROVIDER_IDENTITY.id,
|
|
OPERATION,
|
|
snapshot,
|
|
);
|
|
};
|
|
|
|
/** Portable parser over one bounded, identity-checked regular file. */
|
|
export class PythonPycProvider implements PythonPycPort {
|
|
readonly identity = PYTHON_PYC_PROVIDER_IDENTITY;
|
|
readonly #resources = new ArtifactResourceScope();
|
|
|
|
async close(): Promise<void> {
|
|
try {
|
|
await this.#resources.close();
|
|
} catch (cause: unknown) {
|
|
throw projectArtifactCloseFailure(
|
|
cause,
|
|
PYTHON_PYC_PROVIDER_IDENTITY.id,
|
|
OPERATION,
|
|
);
|
|
}
|
|
}
|
|
|
|
async inspect(input: InspectPythonPycInput, options?: ExecutionOptions) {
|
|
let snapshot: StableArtifactSnapshot | undefined;
|
|
try {
|
|
snapshot = await this.#resources.run(() =>
|
|
readStableArtifact(
|
|
input.path,
|
|
input.max_file_bytes,
|
|
options?.signal,
|
|
undefined,
|
|
this.#resources,
|
|
),
|
|
);
|
|
return ok(
|
|
parsePythonPyc(
|
|
snapshot.bytes,
|
|
{
|
|
path: input.path,
|
|
sha256: snapshot.sha256,
|
|
bytes: snapshot.bytes.length,
|
|
},
|
|
input,
|
|
),
|
|
);
|
|
} catch (cause) {
|
|
return err(failureFor(cause, input, snapshot));
|
|
}
|
|
}
|
|
}
|