mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 03:33:25 +00:00
refactor(domain): one owner each for non-empty text schemas and UTF-8 head excerpts (#10569)
Fifteen domain schema files each declared z.string().min(1), eight of them as boundedTextSchema although it bounds nothing. They now share nonEmptyTextSchema from src/domain/textSchemas.ts; the one trimming copy in reconstructionCoverage.ts is renamed trimmedTextSchema. Three private UTF-8 prefix truncators (gdb recent MI records, rizin diagnostics, environment replay) and src/process/boundedUtf8Text.ts are replaced by utf8HeadExcerpt in src/domain/utf8HeadExcerpt.ts, which encodes only the retained prefix and returns a slice of the source text.
This commit is contained in:
1 parent
1ba93b4602
commit
eead7a5815
29 files changed
+236
-173
No files matched your search
@@ -25,7 +25,7 @@ import type {
|
||||
} from "../domain/analysisErrorBase.js";
|
||||
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
|
||||
import { safeParseJson } from "../domain/safeJson.js";
|
||||
import { boundedUtf8Text } from "./boundedUtf8Text.js";
|
||||
import { utf8HeadExcerpt } from "../domain/utf8HeadExcerpt.js";
|
||||
import { createDarwinHelperCache } from "./DarwinHelperCache.js";
|
||||
import { snapshotEnvironment } from "./snapshotEnvironment.js";
|
||||
import {
|
||||
@@ -266,8 +266,8 @@ const compilerFailureFacts = (
|
||||
| undefined => {
|
||||
const failure = execFileOutputFailure(cause);
|
||||
if (failure === undefined) return undefined;
|
||||
const stderr = boundedUtf8Text(failure.stderr, MAX_COMPILER_OUTPUT_BYTES);
|
||||
const stdout = boundedUtf8Text(failure.stdout, MAX_COMPILER_OUTPUT_BYTES);
|
||||
const stderr = utf8HeadExcerpt(failure.stderr, MAX_COMPILER_OUTPUT_BYTES);
|
||||
const stdout = utf8HeadExcerpt(failure.stdout, MAX_COMPILER_OUTPUT_BYTES);
|
||||
const outcome =
|
||||
failure.code === "ETIMEDOUT"
|
||||
? "timed_out"
|
||||
@@ -336,7 +336,7 @@ const compilerInspectionError = (
|
||||
code === "ENOENT"
|
||||
? `macOS process ownership inspection requires the Apple Swift compiler via ${launcher}`
|
||||
: `macOS process ownership helper compilation failed via ${launcher}`;
|
||||
const stderr = boundedUtf8Text(outcome?.stderr ?? "", STDERR_EXCERPT_LIMIT);
|
||||
const stderr = utf8HeadExcerpt(outcome?.stderr ?? "", STDERR_EXCERPT_LIMIT);
|
||||
const diagnostics = stderr.text.trim();
|
||||
const truncated =
|
||||
stderr.truncated ||
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
/** Keep a UTF-8 string within a byte budget without cutting a code point. */
|
||||
export const boundedUtf8Text = (
|
||||
value: string,
|
||||
maximumBytes: number,
|
||||
): { readonly text: string; readonly truncated: boolean } => {
|
||||
let bytes = 0;
|
||||
let end = 0;
|
||||
for (const codePoint of value) {
|
||||
const codePointBytes = Buffer.byteLength(codePoint, "utf8");
|
||||
if (bytes + codePointBytes > maximumBytes)
|
||||
return { text: value.slice(0, end), truncated: true };
|
||||
bytes += codePointBytes;
|
||||
end += codePoint.length;
|
||||
}
|
||||
return { text: value, truncated: false };
|
||||
};
|
||||
Reference in new issue
Block a user