mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
refactor(kernel): give error-message, byte-hex and SHA-256 hex helpers one owner in a new src/kernel layer (#11542)
* 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)
This commit is contained in:
1 parent
ff0176256a
commit
5f718ce30e
291 files changed
+976
-978
No files matched your search
@@ -5,7 +5,7 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { readImportSpecifiers } from "./import-specifiers.mjs";
|
||||
import { isLayerException } from "./module-layers.mjs";
|
||||
|
||||
const PURE_LAYERS = new Set(["domain", "contracts"]);
|
||||
const PURE_LAYERS = new Set(["kernel", "domain", "contracts"]);
|
||||
const MIGRATED_PROVIDER_ROOTS = new Set([
|
||||
"sqlite",
|
||||
"evm",
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
* layer. An undeclared unit fails the check, so a new directory must choose
|
||||
* its layer when it is added.
|
||||
*
|
||||
* The order follows docs/architecture/architecture.mermaid: domain and
|
||||
* The order follows docs/architecture/architecture.mermaid: the dependency-free
|
||||
* kernel helpers that every layer may use, domain and
|
||||
* contracts at the centre, the process/filesystem foundation, the ports
|
||||
* that providers implement and application consumes, the shared provider
|
||||
* core (src/providers), provider adapters,
|
||||
@@ -12,6 +13,7 @@
|
||||
* MCP entry points.
|
||||
*/
|
||||
export const LAYER_ORDER = Object.freeze([
|
||||
"kernel",
|
||||
"domain",
|
||||
"contracts",
|
||||
"foundation",
|
||||
@@ -27,6 +29,7 @@ const units = (layer, names) => names.map((name) => [name, layer]);
|
||||
|
||||
export const UNIT_LAYERS = Object.freeze(
|
||||
Object.fromEntries([
|
||||
...units("kernel", ["kernel"]),
|
||||
...units("domain", ["domain"]),
|
||||
...units("contracts", ["contracts"]),
|
||||
...units("foundation", [
|
||||
|
||||
@@ -6,7 +6,7 @@ export const SOURCE_TEST_PROJECTS = [
|
||||
name: "domain",
|
||||
group: "source",
|
||||
isolate: false,
|
||||
include: ["src/{contracts,domain,ports}/**/*.test.ts"],
|
||||
include: ["src/{contracts,domain,kernel,ports}/**/*.test.ts"],
|
||||
},
|
||||
{
|
||||
name: "services",
|
||||
|
||||
@@ -324,7 +324,7 @@ const checkCounted = (label, key, selected, pattern, owners) => {
|
||||
if (owners.includes(file.path)) continue;
|
||||
const count =
|
||||
typeof pattern === "function"
|
||||
? pattern(file.content)
|
||||
? pattern(file.content, file.path)
|
||||
: (file.content.match(pattern)?.length ?? 0);
|
||||
if (count > 0) counts.set(file.path, count);
|
||||
}
|
||||
@@ -484,6 +484,51 @@ checkCounted(
|
||||
["src/pcap/TsharkJsonPackets.ts"],
|
||||
);
|
||||
|
||||
// Text from an unknown caught value has one owner, src/kernel/errorMessage.ts.
|
||||
// The pattern matches the inline copy with the same expression in all three
|
||||
// places; a named local helper with this body is the same copy.
|
||||
// Copies that run in another realm cannot import the owner and are excluded by
|
||||
// name, so no slice rewrites them: the regex worker's source string and a
|
||||
// fetch run inside the browser page through page.evaluate.
|
||||
const ISOLATED_ERROR_MESSAGE_COPIES = new Map([
|
||||
["src/browser/PlaywrightScenarioRequest.ts", 1],
|
||||
["src/process/RegexMatcher.ts", 1],
|
||||
]);
|
||||
const inlineErrorMessage =
|
||||
/(?<![\w$.])([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\s+instanceof\s+Error\s*\?\s*\1\.message\s*:\s*String\(\s*\1\s*\)/gu;
|
||||
checkCounted(
|
||||
"inline error-to-message conversion (use errorMessage from src/kernel/errorMessage)",
|
||||
"inline-error-message",
|
||||
files,
|
||||
(content, path) =>
|
||||
Math.max(
|
||||
0,
|
||||
(content.match(inlineErrorMessage)?.length ?? 0) -
|
||||
(ISOLATED_ERROR_MESSAGE_COPIES.get(path) ?? 0),
|
||||
),
|
||||
["src/kernel/errorMessage.ts"],
|
||||
);
|
||||
|
||||
// Two hexadecimal digits for one byte have one owner, src/kernel/byteToHex.ts.
|
||||
checkCounted(
|
||||
"inline byte-to-hex formatting (use byteToHex from src/kernel/byteToHex)",
|
||||
"inline-byte-hex",
|
||||
files,
|
||||
/\.toString\(16\)\s*\.padStart\(\s*2\s*,\s*"0"\s*\)/gu,
|
||||
["src/kernel/byteToHex.ts"],
|
||||
);
|
||||
|
||||
// A one-shot SHA-256 hex digest of an in-memory value has one owner,
|
||||
// src/kernel/sha256Hex.ts. Incremental and streamed hashing (a Hash updated
|
||||
// more than once) is not counted.
|
||||
checkCounted(
|
||||
"one-shot SHA-256 hex digest (use sha256Hex from src/kernel/sha256Hex)",
|
||||
"inline-sha256-hex",
|
||||
files,
|
||||
/createHash\(\s*"sha256"\s*\)\s*\.update\((?:[^()]|\((?:[^()]|\((?:[^()]|\([^()]*\))*\))*\))*\)\s*\.digest\(\s*"hex"\s*\)/gu,
|
||||
["src/kernel/sha256Hex.ts"],
|
||||
);
|
||||
|
||||
// Strict UTF-8 decoding has one owner, src/domain/strictUtf8.ts, which makes
|
||||
// each site state its byte-order-mark policy. A local fatal decoder silently
|
||||
// strips a leading BOM unless it remembers ignoreBOM. The pattern matches the
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"src/adb/AdbProvider.ts": 1,
|
||||
"src/android/AndroidJniLibraries.ts": 2,
|
||||
"src/apkSignature/apkCertificateFacts.ts": 1,
|
||||
"src/application/GuidanceAccess.ts": 1,
|
||||
"src/application/LinuxHopperPublisher.ts": 2,
|
||||
"src/application/ReferenceSourceImportEntries.ts": 1,
|
||||
"src/application/SetupRecoveryBackup.ts": 1,
|
||||
"src/application/ValidateSelectedWebScript.ts": 1,
|
||||
"src/application/WebScriptExportService.ts": 1,
|
||||
"src/application/WebSourceLocationService.ts": 1,
|
||||
"src/application/decompileDirectory/exportTree.ts": 2,
|
||||
"src/application/desktop/DesktopBuildWitness.ts": 1,
|
||||
"src/application/desktop/DesktopBuildWitnessRecord.ts": 1,
|
||||
"src/application/desktop/DesktopExportFiles.ts": 1,
|
||||
"src/application/desktop/DesktopExportWithheld.ts": 1,
|
||||
"src/application/desktop/DesktopRetainedContent.ts": 1,
|
||||
"src/application/environment/environmentBundleWrite.ts": 1,
|
||||
"src/application/javascript/JavaScriptArtifactAnalysis.ts": 1,
|
||||
"src/application/javascript/JavaScriptArtifactGraphFindings.ts": 1,
|
||||
"src/artifacts/DesktopFileInspection.ts": 1,
|
||||
"src/artifacts/apple/InterfaceBuilderAnalysis.ts": 1,
|
||||
"src/artifacts/apple/KeyedArchiveReader.ts": 1,
|
||||
"src/artifacts/javascript/JavaScriptArtifactFiles.ts": 1,
|
||||
"src/artifacts/nodeSea/NodeSeaLocation.ts": 1,
|
||||
"src/browser/CdpCaptureStorageFingerprints.ts": 1,
|
||||
"src/browser/CdpWebMcpDiscovery.ts": 1,
|
||||
"src/browser/PlaywrightElectronActiveProvider.ts": 1,
|
||||
"src/browser/PlaywrightScenarioArtifacts.ts": 2,
|
||||
"src/browser/WebSourceMapFetcher.ts": 1,
|
||||
"src/browser/assets/PublishWebScripts.ts": 1,
|
||||
"src/browser/history/HarCapture.ts": 1,
|
||||
"src/browser/history/SazProjection.ts": 1,
|
||||
"src/browser/history/protobuf/ProtobufCapture.ts": 1,
|
||||
"src/browser/network/PlaywrightNetworkContent.ts": 1,
|
||||
"src/cutter/CutterBridgeSource.ts": 1,
|
||||
"src/desktop/AgentEnvComputer.ts": 1,
|
||||
"src/desktop/BuildComputerController.ts": 1,
|
||||
"src/desktop/DesktopContentStore.ts": 1,
|
||||
"src/desktop/GpgvKeyCheck.ts": 1,
|
||||
"src/dotnet/ManagedSnapshot.ts": 1,
|
||||
"src/erlang/BeamParser.ts": 1,
|
||||
"src/evm/EvmoleInterfaceProvider.ts": 1,
|
||||
"src/evm/EvmoleInterfaceWorker.ts": 1,
|
||||
"src/firmware/FirmwarePublication.ts": 1,
|
||||
"src/frida/FridaInstrumentationManager.ts": 3,
|
||||
"src/ghidra/GhidraAnalysisSeeds.ts": 1,
|
||||
"src/ghidra/GhidraCheckpoint.ts": 1,
|
||||
"src/ghidra/GhidraExecutableHeader.ts": 1,
|
||||
"src/ghidra/GhidraInstallationProperties.ts": 1,
|
||||
"src/ghidra/GhidraLoadImageValues.ts": 1,
|
||||
"src/ghidra/extensions/GhidraExtensions.ts": 2,
|
||||
"src/gpu/GpuSource.ts": 1,
|
||||
"src/inspector/V8InspectorCaptureProjection.ts": 1,
|
||||
"src/javascript/analysis/JavaScriptAnalysisWorker.ts": 2,
|
||||
"src/javascript/analysis/JavaScriptAnalysisWorkerServer.ts": 2,
|
||||
"src/javascript/recovery/RecoveryFiles.ts": 1,
|
||||
"src/javascript/sourceMaps/TraceSourceMap.ts": 2,
|
||||
"src/kuna/KunaProjectCache.ts": 1,
|
||||
"src/kuna/KunaProjectExport.ts": 1,
|
||||
"src/kuna/KunaReferenceFiles.ts": 1,
|
||||
"src/main/deferredRuntime.ts": 1,
|
||||
"src/native/AppleDispatchMetadata.ts": 1,
|
||||
"src/native/elf/ElfNoteParser.ts": 1,
|
||||
"src/native/elf/KernelModuleParser.ts": 1,
|
||||
"src/native/pe/PeCertificateParser.ts": 1,
|
||||
"src/native/windows/WindowsShortcutParser.ts": 1,
|
||||
"src/python/PythonPycParser.ts": 1,
|
||||
"src/v8/V8CodeCacheParser.ts": 1,
|
||||
"src/wasm/WabtArtifactProvider.ts": 1
|
||||
}
|
||||
Reference in new issue
Block a user