refactor(kernel): migrate the remaining SHA-256 hex digests to sha256Hex and move isRecord into src/kernel (#11571)

* refactor(kernel): migrate the remaining one-shot SHA-256 hex digests to sha256Hex

* refactor(kernel): move isRecord into src/kernel and replace its inline copies (#11574)

* fix(scripts): import isRecord from src/kernel in the managed manifest parser
This commit is contained in:
morluto authored and GitHub committed 2026-11-15 20:53:36 -05:00
1 parent 9ecfb109e8
commit b51ed4c3ec
157 files changed
+397 -589

No files matched your search

@@ -24,7 +24,7 @@ import type {
JavaScriptSemanticProjectionCapacity,
JavaScriptSemanticFileProjection,
} from "../../domain/javascript/javascriptSemanticFileProjection.js";
import { createHash, randomUUID } from "node:crypto";
import { randomUUID } from "node:crypto";
import { readFile, rm, stat } from "node:fs/promises";
import { join } from "node:path";
import { writeJavaScriptAnalysisSourceTransfer } from "./JavaScriptAnalysisSourceTransfer.js";
@@ -100,6 +100,7 @@ import {
type JavaScriptWorkerMessage,
} from "./JavaScriptAnalysisWorkerProtocol.js";
import { errorMessage } from "../../kernel/errorMessage.js";
import { sha256Hex } from "../../kernel/sha256Hex.js";
const OPERATION = "analyze_javascript_application";
const PROVIDER = "javascript-static-analysis";
@@ -392,7 +393,7 @@ export class JavaScriptAnalysisWorker {
this.limits.memberMutationAllowance ??
DEFAULT_JAVASCRIPT_MEMBER_MUTATION_ALLOWANCE,
),
text_sha256: createHash("sha256").update(file.text.value).digest("hex"),
text_sha256: sha256Hex(file.text.value),
file: metadata,
package_type: packageType,
purpose,
@@ -866,10 +867,7 @@ export class JavaScriptAnalysisWorker {
},
);
const checkpoint = await readFile(path);
if (
expected !== undefined &&
createHash("sha256").update(checkpoint).digest("hex") !== expected.sha256
)
if (expected !== undefined && sha256Hex(checkpoint) !== expected.sha256)
throw new AnalysisOutputError(
OPERATION,
"JavaScript static checkpoint digest does not match",
@@ -10,7 +10,6 @@ import type {
JavaScriptSemanticProjectionCapacity,
JavaScriptSemanticFileProjection,
} from "../../domain/javascript/javascriptSemanticFileProjection.js";
import { createHash } from "node:crypto";
import { readFile, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { getHeapStatistics } from "node:v8";
@@ -38,6 +37,7 @@ import {
type JavaScriptWorkerMessage,
} from "./JavaScriptAnalysisWorkerProtocol.js";
import { errorMessage } from "../../kernel/errorMessage.js";
import { sha256Hex } from "../../kernel/sha256Hex.js";
/** Trusted composition callback; this provider owns framing and temporary I/O. */
export interface JavaScriptSourceWorkerAnalyzer {
@@ -122,9 +122,7 @@ const analyzeJob = async (
try {
let resultBudgetBytes = 0;
const source = await readFile(join(root, `${request.id}.source`), "utf8");
if (
createHash("sha256").update(source).digest("hex") !== request.text_sha256
)
if (sha256Hex(source) !== request.text_sha256)
throw new TypeError(
"JavaScript worker source text digest does not match its request",
);
@@ -180,7 +178,7 @@ const analyzeJob = async (
kind: "static",
id: request.id,
bytes,
sha256: createHash("sha256").update(text).digest("hex"),
sha256: sha256Hex(text),
});
const next = await requests.next();
if (next.done || !next.value.ok)
+2 -5
View File
@@ -37,13 +37,10 @@ import {
import { RECOVERY_LIMITS, wakaruFixedLimitRecovery } from "./WakaruRelease.js";
import { isStrictUtf8 } from "../../domain/strictUtf8.js";
import { errorMessage } from "../../kernel/errorMessage.js";
import { sha256Hex } from "../../kernel/sha256Hex.js";
const OPERATION = "recover_javascript_sources";
/** Fingerprint exact selected or derived bytes. */
export const recoveryDigest = (bytes: Uint8Array): string =>
createHash("sha256").update(bytes).digest("hex");
/** A file exceeded the byte bound its caller selected; the caller owns what that bound means. */
class RecoveryFileSizeError extends AnalysisOutputError {
constructor(
@@ -255,7 +252,7 @@ const snapshotRecoveryInput = async (
path,
snapshot_path: snapshotPath,
relative_path: relativePath,
sha256: recoveryDigest(bytes),
sha256: sha256Hex(bytes),
bytes: bytes.length,
};
};
+3 -3
View File
@@ -12,9 +12,9 @@ import {
} from "../../domain/javascript/javascriptRecovery.js";
import {
readRecoveryFile,
recoveryDigest,
type RecoveryInputSnapshot,
} from "./RecoveryFiles.js";
import { sha256Hex } from "../../kernel/sha256Hex.js";
import {
recoveryRanges,
validateRecoverySourceMap,
@@ -49,7 +49,7 @@ export const publishWakaruArtifacts = async (
): Promise<JavaScriptRecoveryResult> => {
const { tree, sources, parsed, staging, signal, resources } = context;
const write = async (path: string, bytes: Buffer) => {
const sha256 = recoveryDigest(bytes);
const sha256 = sha256Hex(bytes);
const file = await tree.write(
path,
Readable.from([bytes]),
@@ -71,7 +71,7 @@ export const publishWakaruArtifacts = async (
signal,
resources,
);
if (recoveryDigest(snapshot) !== source.sha256)
if (sha256Hex(snapshot) !== source.sha256)
throw new AnalysisOutputError(
"recover_javascript_sources",
`The input snapshot changed during recovery: ${source.path}`,
+3 -5
View File
@@ -4,7 +4,6 @@ import {
sourceMapLimitRecovery,
type SourceMapLimits,
} from "../../domain/sourceMapLimits.js";
import { createHash } from "node:crypto";
import { createRequire } from "node:module";
import { getHeapStatistics } from "node:v8";
import {
@@ -30,6 +29,7 @@ import {
type SourceMapSourceDeclaration,
} from "../../domain/sourceMapFormat.js";
import { decodeValidatedSourceMapLeaves } from "../../domain/decodedSourceMap.js";
import { sha256Hex } from "../../kernel/sha256Hex.js";
/** Decode with the pinned upstream codec; preserve every equal-position candidate. */
export const traceSourceMap = (
@@ -94,7 +94,7 @@ export const traceSourceMap = (
.parse(metadata).version;
const runtime = javaScriptRuntime(process.versions);
return webSourceMapReportSchema.parse({
source_map_sha256: createHash("sha256").update(text).digest("hex"),
source_map_sha256: sha256Hex(text),
url_context: url,
engine: { id: "jridgewell-trace-mapping", version },
// Bun reports V8-shaped heap statistics but ignores the codec's heap flags.
@@ -201,9 +201,7 @@ const originalMatch = (
: {
state: "embedded",
text: declaration.content,
utf8_sha256: createHash("sha256")
.update(declaration.content)
.digest("hex"),
utf8_sha256: sha256Hex(declaration.content),
utf8_bytes: Buffer.byteLength(declaration.content),
representation: "UTF-8 encoding of decoded sourcesContent text",
},