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:
morluto authored and GitHub committed 2026-11-14 13:28:28 -05:00
1 parent 1ba93b4602
commit eead7a5815
29 files changed
+236 -173

No files matched your search

@@ -1,9 +1,8 @@
import { z } from "zod";
import { javascriptSourceRangeSchema } from "./javascriptSourceCoordinates.js";
import { digestSchema, prefixedDigestSchema } from "../digests.js";
import { nonEmptyTextSchema } from "../textSchemas.js";
const boundedTextSchema = z.string().min(1);
const boundedKeySchema = z.string().min(1);
const unsafePathSegments = new Set(["", ".", ".."]);
const isSafeRelativePath = (path: string): boolean => {
if (path.startsWith("/")) return false;
@@ -63,7 +62,7 @@ const applicationUnavailableReasonSchema = z.enum([
const unavailableFactSchema = z.strictObject({
available: z.literal(false),
reason: applicationUnavailableReasonSchema,
detail: boundedTextSchema,
detail: nonEmptyTextSchema,
});
const availableArtifactSchema = z
@@ -89,7 +88,7 @@ const applicationArtifactReferenceSchema = z.discriminatedUnion("available", [
const sourceRangeSchema = javascriptSourceRangeSchema.safeExtend({
kind: z.literal("source-range"),
source: boundedTextSchema,
source: nonEmptyTextSchema,
});
const fileOffsetRangeSchema = z
@@ -122,19 +121,19 @@ const applicationLocationSchema = z.discriminatedUnion("kind", [
z.strictObject({
kind: z.literal("runtime"),
capture_sha256: digestSchema,
target_key: boundedKeySchema,
frame_key: boundedKeySchema.nullable(),
script_key: boundedKeySchema.nullable(),
target_key: nonEmptyTextSchema,
frame_key: nonEmptyTextSchema.nullable(),
script_key: nonEmptyTextSchema.nullable(),
}),
z.strictObject({
kind: z.literal("native-address"),
address: boundedKeySchema,
symbol: boundedTextSchema.nullable(),
address: nonEmptyTextSchema,
symbol: nonEmptyTextSchema.nullable(),
}),
z.strictObject({
kind: z.literal("package-export"),
package_name: boundedKeySchema,
export_path: boundedTextSchema,
package_name: nonEmptyTextSchema,
export_path: nonEmptyTextSchema,
}),
]);
@@ -247,7 +246,7 @@ const applicationGraphEvidenceBaseSchema = z.strictObject({
location: applicationGraphEvidenceLocationSchema,
extractor: applicationExtractorSchema,
coverage: applicationCoverageSchema,
limitations: z.array(boundedTextSchema),
limitations: z.array(nonEmptyTextSchema),
evidence_ids: z.array(prefixedDigestSchema("ev")),
});
@@ -439,7 +438,7 @@ export const applicationNodeIdentitySchema = z.discriminatedUnion("strategy", [
strategy: z.literal("artifact-local-key"),
stability: z.literal("artifact-version"),
artifact_sha256: digestSchema,
namespace: boundedKeySchema,
namespace: nonEmptyTextSchema,
// The exact artifact-local value, such as `""` from `fetch("")`.
key: z.string(),
}),
@@ -448,13 +447,13 @@ export const applicationNodeIdentitySchema = z.discriminatedUnion("strategy", [
stability: z.literal("capture-only"),
capture_evidence_id: prefixedDigestSchema("ev"),
capture_sha256: digestSchema,
runtime_key: boundedTextSchema,
runtime_key: nonEmptyTextSchema,
}),
z.strictObject({
strategy: z.literal("observation-fingerprint"),
stability: z.literal("observation-only"),
observation_sha256: digestSchema,
scope: boundedTextSchema,
scope: nonEmptyTextSchema,
}),
]);
@@ -8,8 +8,7 @@ import {
} from "./javascriptApplicationEvidenceSchemas.js";
import { jsonValueSchema } from "../jsonValue.js";
import { prefixedDigestSchema } from "../digests.js";
const boundedTextSchema = z.string().min(1);
import { nonEmptyTextSchema } from "../textSchemas.js";
/** An observed IPC channel match whose uniqueness is not established. */
export const IPC_COVERAGE_LIMITED_PAIRING_BASIS =
@@ -148,7 +147,7 @@ export const javascriptApplicationGraphInputSchema = z.strictObject({
nodes: z.array(applicationNodeSchema).min(1),
edges: z.array(applicationEdgeSchema),
coverage: applicationCoverageSchema,
limitations: z.array(boundedTextSchema),
limitations: z.array(nonEmptyTextSchema),
});
/** Strict stored shape for a JavaScript Application Graph. */
@@ -8,10 +8,10 @@ import {
} from "./javascriptApplicationGraph.js";
import { JAVASCRIPT_APPLICATION_NODE_KINDS } from "./javascriptApplicationGraphSchemas.js";
import { prefixedDigestSchema } from "../digests.js";
import { nonEmptyTextSchema } from "../textSchemas.js";
const evidenceIdSchema = prefixedDigestSchema("ev");
const nodeIdSchema = prefixedDigestSchema("jag_node");
const textSchema = z.string().min(1);
/** Check paired version identities and per-side native identity uniqueness. */
const validateApplicationVersionIdentities = (
@@ -128,7 +128,7 @@ const comparisonItemContextShape = {
]),
),
evidence_links: z.array(evidenceIdSchema).min(2),
limitations: z.array(textSchema),
limitations: z.array(nonEmptyTextSchema),
};
const comparisonItemSchema = z.union([
@@ -212,7 +212,7 @@ export const applicationVersionComparisonResultSchema = z
graph: javascriptApplicationGraphSchema,
coverage: comparisonCoverageSchema,
evidence_links: z.array(evidenceIdSchema).min(2),
limitations: z.array(textSchema),
limitations: z.array(nonEmptyTextSchema),
})
.superRefine((result, context) => {
const sourceGraphsComplete =
@@ -4,11 +4,11 @@ import { javascriptSourceRangeSchema } from "./javascriptSourceCoordinates.js";
import { evidenceSchema } from "../evidence.js";
import { prefixedDigestSchema } from "../digests.js";
import { nonEmptyTextSchema } from "../textSchemas.js";
const evidenceIdSchema = prefixedDigestSchema("ev");
const graphIdSchema = prefixedDigestSchema("jag");
const nodeIdSchema = prefixedDigestSchema("jag_node");
const textSchema = z.string().min(1);
const exportNameSchema = z.string();
const semanticPrimitiveSchema = z.union([
z.string(),
@@ -64,9 +64,9 @@ export const compareJavaScriptExportShapesInputSchema = z
.strictObject({
left: evidenceSchema,
right: evidenceSchema,
left_module_path: textSchema,
left_module_path: nonEmptyTextSchema,
left_export_name: exportNameSchema,
right_module_path: textSchema,
right_module_path: nonEmptyTextSchema,
right_export_name: exportNameSchema,
})
.superRefine(validateJavaScriptExportShapeIdentities);
@@ -92,7 +92,7 @@ const projectedReturnFieldSchema = z.discriminatedUnion("state", [
...projectedReturnFieldShape,
state: z.literal("unknown"),
value: z.null(),
reason: textSchema,
reason: nonEmptyTextSchema,
}),
]);
export type ProjectedReturnField = z.infer<typeof projectedReturnFieldSchema>;
@@ -149,9 +149,9 @@ const projectedReturnShapeSchema = z
export const projectedExportReturnShapesSchema = z
.strictObject({
semantic_role: z.literal("export-return-shapes"),
module_path: textSchema,
module_path: nonEmptyTextSchema,
exported_name: exportNameSchema,
callable_id: textSchema,
callable_id: nonEmptyTextSchema,
callable_kind: z.enum(["function", "class", "method"]),
static_return_shapes: z.array(projectedReturnShapeSchema),
return_shape_coverage: z.strictObject({
@@ -177,7 +177,7 @@ export const projectedExportReturnShapesSchema = z
const exportCandidateSchema = z.strictObject({
node_id: nodeIdSchema,
module_path: textSchema,
module_path: nonEmptyTextSchema,
export_name: exportNameSchema,
matches_requested_module: z.boolean(),
matches_requested_export: z.boolean(),
@@ -186,7 +186,7 @@ const exportCandidateSchema = z.strictObject({
const selectorResultShape = {
evidence_id: evidenceIdSchema,
graph_id: graphIdSchema,
requested_module_path: textSchema,
requested_module_path: nonEmptyTextSchema,
requested_export_name: exportNameSchema,
candidates: z.array(exportCandidateSchema),
omitted_candidates: z.int().min(0),
@@ -221,7 +221,7 @@ const valueAvailabilitySchema = z.discriminatedUnion("availability", [
}),
z.strictObject({
availability: z.literal("unknown"),
reason: textSchema,
reason: nonEmptyTextSchema,
}),
]);
@@ -251,7 +251,7 @@ export const javaScriptExportShapeComparisonChangeSchema = z.strictObject({
left_source_range: javascriptSourceRangeSchema.nullable(),
right_source_range: javascriptSourceRangeSchema.nullable(),
evidence_links: z.array(evidenceIdSchema).length(2),
limitations: z.array(textSchema),
limitations: z.array(nonEmptyTextSchema),
});
const inventoryPropertyCoverageSchema = z.strictObject({
@@ -311,7 +311,7 @@ export const javaScriptExportShapeComparisonResultSchema = z.strictObject({
omitted_changes: z.int().min(0),
}),
evidence_links: z.array(evidenceIdSchema).length(2),
limitations: z.array(textSchema),
limitations: z.array(nonEmptyTextSchema),
});
export type ProjectedExportReturnShapes = z.output<
@@ -3,11 +3,11 @@ import { z } from "zod";
import { evidenceSchema, providerSchema } from "../evidence.js";
import { javascriptApplicationGraphSchema } from "./javascriptApplicationGraph.js";
import { digestSchema, prefixedDigestSchema } from "../digests.js";
import { nonEmptyTextSchema } from "../textSchemas.js";
const evidenceIdSchema = prefixedDigestSchema("ev");
const nodeIdSchema = prefixedDigestSchema("jag_node");
const edgeIdSchema = prefixedDigestSchema("jag_edge");
const boundedTextSchema = z.string().min(1);
/** Matching mode for a literal seed: string seeds default to containment. */
export const featureSeedMatchMode = (seed: {
@@ -19,7 +19,7 @@ export const featureSeedMatchMode = (seed: {
const apiSeedSchema = z.union([
z.strictObject({
kind: z.literal("api"),
value: boundedTextSchema,
value: nonEmptyTextSchema,
match: z.enum(["exact", "contains"]).nullable().default(null),
case_sensitive: z.boolean().default(false),
}),
@@ -34,7 +34,7 @@ const apiSeedSchema = z.union([
const apiPathSeedSchema = z.union([
z.strictObject({
kind: z.literal("api"),
value: boundedTextSchema,
value: nonEmptyTextSchema,
match: z.enum(["exact", "contains"]).nullable().default(null),
case_sensitive: z.boolean().default(false),
entry_path: z.array(z.string()).min(1),
@@ -63,7 +63,7 @@ export const applicationFeatureSeedSchema = z.union([
"module",
"native-export",
]),
value: boundedTextSchema,
value: nonEmptyTextSchema,
match: z.enum(["exact", "contains"]).nullable().default(null),
case_sensitive: z.boolean().default(false),
}),
@@ -220,7 +220,7 @@ export const applicationFeatureTraceResultSchema = z.strictObject({
total_seed_matches: z.int().min(0),
}),
evidence_links: z.array(evidenceIdSchema).min(1),
limitations: z.array(boundedTextSchema),
limitations: z.array(nonEmptyTextSchema),
});
export type TraceApplicationFeatureInput = z.infer<
@@ -8,10 +8,10 @@ import { javascriptRuntimeUnresolvedLocationSchema } from "./javascriptRuntimeOb
import { javascriptApplicationGraphSchema } from "./javascriptApplicationGraph.js";
import { digestSchema, prefixedDigestSchema } from "../digests.js";
import { urlDeclaresQueryOrFragment } from "../urlComponents.js";
import { nonEmptyTextSchema } from "../textSchemas.js";
const evidenceIdSchema = prefixedDigestSchema("ev");
const nodeIdSchema = prefixedDigestSchema("jag_node");
const boundedTextSchema = z.string().min(1);
const safePrefixSchema = z
.string()
.refine(
@@ -171,7 +171,7 @@ const captureSummarySchema = z.strictObject({
capture_sha256: digestSchema,
kind: z.enum(["browser", "electron", "v8-inspector", "electron-active"]),
target_node_id: nodeIdSchema,
target_key: boundedTextSchema,
target_key: nonEmptyTextSchema,
target_location: z
.string()
.min(1)
@@ -282,7 +282,7 @@ export const javascriptRuntimeReconciliationResultSchema = z.strictObject({
used_for_primary_matching: z.literal(false),
static_layer_count: z.int().min(0),
runtime_script_declarations: z.int().min(0),
limitation: boundedTextSchema,
limitation: nonEmptyTextSchema,
}),
coverage: z.strictObject({
status: z.enum(["complete-within-inputs", "partial", "truncated"]),
@@ -293,7 +293,7 @@ export const javascriptRuntimeReconciliationResultSchema = z.strictObject({
omitted_graph_items: z.int().min(0),
}),
evidence_links: z.array(evidenceIdSchema).min(2),
limitations: z.array(boundedTextSchema),
limitations: z.array(nonEmptyTextSchema),
});
export type ReconcileJavaScriptRuntimeInput = z.infer<
@@ -9,8 +9,8 @@ import {
} from "./javascriptApplicationEvidenceSchemas.js";
import { jsonValueSchema } from "../jsonValue.js";
import { digestSchema, prefixedDigestSchema } from "../digests.js";
import { nonEmptyTextSchema } from "../textSchemas.js";
const boundedTextSchema = z.string().min(1);
const semanticNodeIdSchema = prefixedDigestSchema("jsrg_node");
const semanticRelationIdSchema = z
.string()
@@ -278,7 +278,7 @@ export const javaScriptSemanticUnknownInputSchema = z.strictObject({
family: z.enum(JAVASCRIPT_SEMANTIC_RELATION_FAMILIES),
relation_kinds: z.array(z.enum(JAVASCRIPT_SEMANTIC_RELATIONS)).min(1),
reason: z.enum(JAVASCRIPT_SEMANTIC_UNKNOWN_REASONS),
detail: boundedTextSchema,
detail: nonEmptyTextSchema,
candidate_node_ids: z.array(semanticNodeIdSchema),
evidence: applicationGraphEvidenceSchema,
});
@@ -315,7 +315,7 @@ export const javaScriptSemanticFingerprintInputSchema = z.strictObject({
algorithm: z.literal("rea.javascript-semantic-function"),
status: z.enum(["complete", "partial", "unavailable"]),
components: fingerprintComponentsSchema,
limitations: z.array(boundedTextSchema),
limitations: z.array(nonEmptyTextSchema),
evidence: applicationGraphEvidenceSchema,
});
@@ -364,7 +364,7 @@ export const javaScriptSemanticGraphInputSchema = z.strictObject({
fingerprints: z.array(javaScriptSemanticFingerprintSchema),
unknowns: z.array(javaScriptSemanticUnknownSchema),
coverage: graphCoverageSchema,
limitations: z.array(boundedTextSchema),
limitations: z.array(nonEmptyTextSchema),
});
/** Stored JavaScript Semantic Relation Graph. */
@@ -5,10 +5,10 @@ import { evidenceSchema } from "../evidence.js";
import { JAVASCRIPT_APPLICATION_NODE_KINDS } from "./javascriptApplicationGraphSchemas.js";
import { historicalSourceGraphSchema } from "../referenceSourceGraph.js";
import { digestSchema, prefixedDigestSchema } from "../digests.js";
import { nonEmptyTextSchema } from "../textSchemas.js";
const evidenceIdSchema = prefixedDigestSchema("ev");
const nodeIdSchema = prefixedDigestSchema("jag_node");
const textSchema = z.string().min(1);
export const SOURCE_TO_BUNDLE_SIGNAL_WEIGHTS = [
["exact-source-digest", 100],
@@ -39,8 +39,8 @@ export const compareSourceToBundleInputSchema = z.strictObject({
const sourceToBundleSignalSchema = z.strictObject({
kind: sourceToBundleSignalKindSchema,
weight: z.int().min(1).max(100),
source_value: textSchema,
current_values: z.array(textSchema).min(1),
source_value: nonEmptyTextSchema,
current_values: z.array(nonEmptyTextSchema).min(1),
});
const sourceToBundleCandidateSchema = z.strictObject({
@@ -55,9 +55,9 @@ const sourceToBundleCandidateSchema = z.strictObject({
const sourceToBundleItemSchema = z.strictObject({
mapping_id: prefixedDigestSchema("stbc_item"),
source_path: textSchema,
source_path: nonEmptyTextSchema,
source_sha256: digestSchema.nullable(),
source_language: textSchema.nullable(),
source_language: nonEmptyTextSchema.nullable(),
status: z.enum([
"unchanged",
"modified",
@@ -70,7 +70,7 @@ const sourceToBundleItemSchema = z.strictObject({
confidence: z.enum(["exact", "high", "medium", "unknown"]),
current_node_ids: z.array(nodeIdSchema),
candidates: z.array(sourceToBundleCandidateSchema),
limitations: z.array(textSchema),
limitations: z.array(nonEmptyTextSchema),
});
/** Deterministic, evidence-bearing historical-source to shipped-bundle comparison. */
@@ -120,7 +120,7 @@ export const sourceToBundleComparisonResultSchema = z.strictObject({
candidate_evaluations: z.int().min(0),
}),
evidence_links: z.array(evidenceIdSchema).length(1),
limitations: z.array(textSchema),
limitations: z.array(nonEmptyTextSchema),
});
export type SourceToBundleComparisonResult = z.infer<