merge: retain main CI planning and artifact checks
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
import {
|
||||
DYLIB_RESOLUTION_LIMITATIONS,
|
||||
deriveFindings,
|
||||
type TracedRootSlice,
|
||||
} from "./dylibResolutionFindings.js";
|
||||
|
||||
/**
|
||||
@@ -568,6 +569,7 @@ export const traceDylibLoading = async (
|
||||
for (const path of request.unclassified ?? [])
|
||||
images.set(path, await view.image(path));
|
||||
const roots: DylibTrace["roots"][number][] = [];
|
||||
const rootSlices: TracedRootSlice[] = [];
|
||||
const edges: Edge[] = [];
|
||||
const withoutArchitecture: string[] = [];
|
||||
const environmentRoots = new Set<string>();
|
||||
@@ -597,6 +599,7 @@ export const traceDylibLoading = async (
|
||||
)
|
||||
environmentRoots.add(root);
|
||||
roots.push({ image: root, architecture: slice.architecture });
|
||||
rootSlices.push({ image: root, slice });
|
||||
edges.push(
|
||||
...(await traceProcess(
|
||||
{
|
||||
@@ -641,7 +644,7 @@ export const traceDylibLoading = async (
|
||||
facts.status === "parsed" ? facts.slices.map(withoutDependencies) : [],
|
||||
})),
|
||||
edges,
|
||||
findings: deriveFindings(edges, roots, images),
|
||||
findings: deriveFindings(edges, rootSlices),
|
||||
coverage: {
|
||||
status:
|
||||
unparsed.length === 0 &&
|
||||
|
||||
@@ -1,14 +1,18 @@
|
||||
import type {
|
||||
DylibEdge as Edge,
|
||||
DylibFinding as Finding,
|
||||
DylibTrace,
|
||||
MachoImageFacts,
|
||||
MachoSlice,
|
||||
} from "./dylibResolution.js";
|
||||
|
||||
/** One traced process root with the exact slice it was traced from. */
|
||||
export interface TracedRootSlice {
|
||||
readonly image: string;
|
||||
readonly slice: MachoSlice;
|
||||
}
|
||||
|
||||
export const deriveFindings = (
|
||||
edges: readonly Edge[],
|
||||
roots: DylibTrace["roots"],
|
||||
images: ReadonlyMap<string, MachoImageFacts>,
|
||||
roots: readonly TracedRootSlice[],
|
||||
): Finding[] => {
|
||||
const findings: Finding[] = [];
|
||||
edges.forEach((edge, index) => {
|
||||
@@ -32,15 +36,11 @@ export const deriveFindings = (
|
||||
explanation: `The modeled dyld search checks ${earlier.join(", ")} before ${edge.resolution.image ?? edge.install_name}. A compatible Mach-O placed at an earlier modeled path could take precedence over that fallback, subject to unmodeled search inputs and code-signing library validation; library validation is not evaluated here (see inspect_signature).${edge.loader_conditional ? " This loader loads only conditionally; if it never loads, this search never occurs." : ""}${edge.resolution.status === "conditional" ? " Unmodeled environment overrides or earlier unknown candidates may take precedence; placing an image at this rpath does not establish which image dyld will load." : ""}`,
|
||||
});
|
||||
});
|
||||
for (const { image, architecture } of roots) {
|
||||
const facts = images.get(image);
|
||||
const slice =
|
||||
facts?.status === "parsed"
|
||||
? facts.slices.find(
|
||||
(candidate) => candidate.architecture === architecture,
|
||||
)
|
||||
: undefined;
|
||||
const environment = slice?.dyld_environment ?? [];
|
||||
// Slices can share an architecture name (arm64e and arm64e.x1), so each
|
||||
// finding uses the slice its root was traced from, not a name lookup.
|
||||
for (const { image, slice } of roots) {
|
||||
const { architecture } = slice;
|
||||
const environment = slice.dyld_environment;
|
||||
if (environment.length > 0)
|
||||
findings.push({
|
||||
kind: "dyld-environment-present",
|
||||
@@ -48,7 +48,7 @@ export const deriveFindings = (
|
||||
image,
|
||||
basis: "derived",
|
||||
explanation:
|
||||
slice?.file_type === "execute"
|
||||
slice.file_type === "execute"
|
||||
? `${image} (${architecture}) sets dyld environment variables through LC_DYLD_ENVIRONMENT (${environment.join(", ")}); any image-selection overrides they request are not modeled. Diagnostic settings alone do not alter resolution.`
|
||||
: `${image} (${architecture}) contains LC_DYLD_ENVIRONMENT (${environment.join(", ")}). Dyld reads these commands only from the main executable; entries in this non-executable root are observations and do not alter resolution.`,
|
||||
});
|
||||
|
||||
@@ -8,7 +8,6 @@ import {
|
||||
parseNames,
|
||||
parseProcedures,
|
||||
parseRelatedAddresses,
|
||||
parseSegmentImageBase,
|
||||
parseSegments,
|
||||
} from "./hopperValues.js";
|
||||
|
||||
@@ -66,19 +65,6 @@ describe("Hopper boundary values", () => {
|
||||
ok: true,
|
||||
value: ["fixture"],
|
||||
});
|
||||
expect(
|
||||
parseSegmentImageBase([
|
||||
{ image_base: "0x100000" },
|
||||
{ image_base: "0x100000" },
|
||||
]),
|
||||
).toBe("0x100000");
|
||||
expect(
|
||||
parseSegmentImageBase([
|
||||
{ image_base: "0x100000" },
|
||||
{ image_base: "0x200000" },
|
||||
]),
|
||||
).toBeUndefined();
|
||||
expect(parseSegmentImageBase([{ name: "__TEXT" }])).toBeUndefined();
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
||||
+14
-12
@@ -20,6 +20,8 @@ export interface SegmentSummary {
|
||||
readonly readable: boolean | null;
|
||||
readonly writable: boolean | null;
|
||||
readonly executable: boolean | null;
|
||||
readonly image_base?: string;
|
||||
readonly address_space?: string;
|
||||
}
|
||||
|
||||
/** Return a bounded byte distance between canonical addresses in one space. */
|
||||
@@ -58,10 +60,9 @@ const segmentSchema = z.object({
|
||||
readable: z.boolean().nullable(),
|
||||
writable: z.boolean().nullable(),
|
||||
executable: z.boolean().nullable(),
|
||||
image_base: z.string().min(1).exactOptional(),
|
||||
address_space: z.string().min(1).exactOptional(),
|
||||
});
|
||||
const segmentImageBaseSchema = z
|
||||
.object({ image_base: z.string().min(1) })
|
||||
.passthrough();
|
||||
const unavailableAnalysisFactSchema = z
|
||||
.object({ available: z.literal(false), reason: z.string() })
|
||||
.strict();
|
||||
@@ -415,7 +416,7 @@ export const parseRelatedAddresses = (
|
||||
: invalid(`${relation} list`, parsed.error);
|
||||
};
|
||||
|
||||
/** Parse direct or wrapped Hopper segment records. */
|
||||
/** Preserve reported address context in direct or wrapped provider segments. */
|
||||
export const parseSegments = (
|
||||
value: JsonValue,
|
||||
): Result<readonly SegmentSummary[], HopperProtocolError> => {
|
||||
@@ -427,14 +428,15 @@ export const parseSegments = (
|
||||
: invalid("segment list", parsed.error);
|
||||
};
|
||||
|
||||
/** Return a provider-reported image base only when every segment agrees on it. */
|
||||
export const parseSegmentImageBase = (value: JsonValue): string | undefined => {
|
||||
const parsed = z
|
||||
.array(segmentImageBaseSchema)
|
||||
.safeParse(unwrapProperty(value, "segments"));
|
||||
if (!parsed.success) return undefined;
|
||||
const bases = new Set(parsed.data.map(({ image_base }) => image_base));
|
||||
return bases.size === 1 ? parsed.data[0]?.image_base : undefined;
|
||||
/** Return a reported overview base only when every parsed segment agrees. */
|
||||
export const parseSegmentImageBase = (
|
||||
segments: readonly SegmentSummary[],
|
||||
): string | undefined => {
|
||||
const base = segments[0]?.image_base;
|
||||
return base !== undefined &&
|
||||
segments.every((segment) => segment.image_base === base)
|
||||
? base
|
||||
: undefined;
|
||||
};
|
||||
|
||||
/** Parse direct or wrapped Hopper document names. */
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { analyzeJavaScriptStaticSource } from "./javascriptStaticAnalysis.js";
|
||||
|
||||
const registration = (runtime: string, callback: string, chunk = 1) =>
|
||||
"(globalThis." +
|
||||
runtime +
|
||||
" = globalThis." +
|
||||
runtime +
|
||||
" || []).push([[" +
|
||||
chunk +
|
||||
"], {a: function() {}}, " +
|
||||
callback +
|
||||
"]);";
|
||||
|
||||
it.each(["webpackChunkFixture", "rspackChunkFixture"])(
|
||||
"keeps differing callback facts for %s independent of source order",
|
||||
(runtime) => {
|
||||
const first = registration(
|
||||
runtime,
|
||||
'function(r) { r(7); r.e("chunk-a"); }',
|
||||
);
|
||||
const second = registration(
|
||||
runtime,
|
||||
'function(r) { r(8); r.e("chunk-b"); }',
|
||||
);
|
||||
for (const source of [first + "\n" + second, second + "\n" + first]) {
|
||||
const result = analyzeJavaScriptStaticSource(source);
|
||||
expect(result.parse_status).toBe("complete");
|
||||
expect(result.bundler_registrations).toHaveLength(2);
|
||||
expect(
|
||||
result.bundler_registrations.flatMap((r) => r.entry_module_keys).sort(),
|
||||
).toEqual(["7", "8"]);
|
||||
expect(
|
||||
result.bundler_registrations.flatMap((r) => r.async_chunk_keys).sort(),
|
||||
).toEqual(["chunk-a", "chunk-b"]);
|
||||
}
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(first + "\n" + first).bundler_registrations,
|
||||
).toHaveLength(1);
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(first).bundler_registrations[0],
|
||||
).toMatchObject({
|
||||
entry_module_keys: ["7"],
|
||||
async_chunk_keys: ["chunk-a"],
|
||||
});
|
||||
expect(
|
||||
analyzeJavaScriptStaticSource(second).bundler_registrations[0],
|
||||
).toMatchObject({
|
||||
entry_module_keys: ["8"],
|
||||
async_chunk_keys: ["chunk-b"],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
["function(r) { r(7); }", "function(r) { r(8); }"],
|
||||
['function(r) { r.e("a"); }', 'function(r) { r.e("b"); }'],
|
||||
["function(r) {}", "function(s) {}"],
|
||||
["function(r) {}", "function(r) { r(dynamic); }"],
|
||||
["function(r) {}", "function(r) { r.e(dynamic); }"],
|
||||
])("retains callback metadata differences: %s / %s", (left, right) => {
|
||||
const result = analyzeJavaScriptStaticSource(
|
||||
registration("webpackChunkFixture", left) +
|
||||
"\n" +
|
||||
registration("webpackChunkFixture", right),
|
||||
);
|
||||
expect(result.bundler_registrations).toHaveLength(2);
|
||||
});
|
||||
|
||||
it("retains distinct chunk identities with identical callbacks", () => {
|
||||
const callback = "function(r) { r(7); }";
|
||||
const result = analyzeJavaScriptStaticSource(
|
||||
registration("webpackChunkFixture", callback, 1) +
|
||||
"\n" +
|
||||
registration("webpackChunkFixture", callback, 2),
|
||||
);
|
||||
expect(result.bundler_registrations).toHaveLength(2);
|
||||
});
|
||||
@@ -691,6 +691,14 @@ export const registrationKey = (
|
||||
registration.runtime,
|
||||
registration.chunk_keys,
|
||||
String(registration.unknown_chunk_keys),
|
||||
// Equal factory tables can be registered with different runtime callbacks.
|
||||
// Both early collection and finalization must retain those recovered facts.
|
||||
registration.runtime_require_name,
|
||||
registration.runtime_module_cache_status,
|
||||
registration.entry_module_keys,
|
||||
String(registration.unknown_entry_module_keys),
|
||||
registration.async_chunk_keys,
|
||||
String(registration.unknown_async_chunk_keys),
|
||||
registration.modules.map(({ module_key: key, source_sha256: digest }) => [
|
||||
key,
|
||||
digest,
|
||||
|
||||
Reference in New Issue
Block a user