From 682a57a9877706bbdbfa4128b58257438d089620 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sun, 15 Nov 2026 21:04:35 +0800 Subject: [PATCH] fix(native): keep Objective-C class import coverage partial when candidate completeness is unstated (#11128) --- scripts/verify/architecture-guards.mjs | 8 +++++++ .../javascript/ElectronBoundaryAnalysis.ts | 2 +- .../JavaScriptArtifactGraphStructure.test.ts | 2 +- .../NativeDispatchMetadataInspection.ts | 8 +++++-- src/domain/native/objcSwiftMetadata.ts | 2 +- src/native/AppleDispatchMetadata.test.ts | 21 +++++++++++++++++++ src/native/AppleDispatchMetadata.ts | 5 +++-- .../AppleObjcClassImportBindings.test.ts | 14 +++++++++++++ src/native/AppleObjcClassImportBindings.ts | 18 +++++++++++----- src/native/NativeMacOSProvider.ts | 2 +- 10 files changed, 69 insertions(+), 13 deletions(-) diff --git a/scripts/verify/architecture-guards.mjs b/scripts/verify/architecture-guards.mjs index a3567500cf..03e7a4db29 100644 --- a/scripts/verify/architecture-guards.mjs +++ b/scripts/verify/architecture-guards.mjs @@ -61,6 +61,14 @@ const check = (label, selected, pattern, allow = []) => { ); }; +// Completeness is a claim its producer establishes from examined input. A +// fallback or default of `true` turns an unstated claim into a complete one. +check( + "completeness defaulted to true (leave it unknown or require the producer to state it)", + files, + /\b(?:complete|exhaustive|\w+Complete|\w+Exhaustive|\w+_complete|\w+_exhaustive)\w*\s*(?:\?\?\s*true\b|(?::\s*boolean\s*)?=\s*true\s*[,)])/u, +); + // Prerequisite inspection lifetime is an application contract shared by adapters. check( "provider-owned inspection lifetime (use src/application/ProviderInspectionScope)", diff --git a/src/application/javascript/ElectronBoundaryAnalysis.ts b/src/application/javascript/ElectronBoundaryAnalysis.ts index 9f74f2f2a4..2c8e9cb75d 100644 --- a/src/application/javascript/ElectronBoundaryAnalysis.ts +++ b/src/application/javascript/ElectronBoundaryAnalysis.ts @@ -61,7 +61,7 @@ export interface ElectronIpcContext { export const createElectronIpcContext = ( analysis: JavaScriptArtifactAnalysis, applicationOwner: (file: JavaScriptArtifactFile) => string | null, - coverageComplete = true, + coverageComplete: boolean, ): ElectronIpcContext => { const records = collectElectronIpcRecords(analysis); const owners = new Map( diff --git a/src/application/javascript/JavaScriptArtifactGraphStructure.test.ts b/src/application/javascript/JavaScriptArtifactGraphStructure.test.ts index b429b88d69..800f98d651 100644 --- a/src/application/javascript/JavaScriptArtifactGraphStructure.test.ts +++ b/src/application/javascript/JavaScriptArtifactGraphStructure.test.ts @@ -464,7 +464,7 @@ it("attaches sender validation to the innermost handler after a long minified li addJavaScriptArtifactFiles(context); addElectronIpcBoundaries( context, - createElectronIpcContext(analysis, () => "app"), + createElectronIpcContext(analysis, () => "app", true), ); const handlers = context.accumulator .nodes() diff --git a/src/application/native/NativeDispatchMetadataInspection.ts b/src/application/native/NativeDispatchMetadataInspection.ts index 0c4319d2b5..4ffefaea53 100644 --- a/src/application/native/NativeDispatchMetadataInspection.ts +++ b/src/application/native/NativeDispatchMetadataInspection.ts @@ -44,8 +44,12 @@ export const inspectNativeDispatch = async ( ? {} : { objc_class_import_addresses: [...objcClassImportAddresses], - objc_class_import_addresses_complete: - objcClassImportAddressesComplete ?? true, + ...(objcClassImportAddressesComplete === undefined + ? {} + : { + objc_class_import_addresses_complete: + objcClassImportAddressesComplete, + }), }), }; const binaryMetadata = await analysis.execute( diff --git a/src/domain/native/objcSwiftMetadata.ts b/src/domain/native/objcSwiftMetadata.ts index 015e767c8e..a4a3da094c 100644 --- a/src/domain/native/objcSwiftMetadata.ts +++ b/src/domain/native/objcSwiftMetadata.ts @@ -466,7 +466,7 @@ export const nativeDispatchMetadataInputSchema = z.strictObject({ objc_class_import_addresses_complete: z .boolean() .describe( - "Whether the candidate addresses include every selected class-label row; false keeps binding coverage partial when the existing record budget truncates the scan.", + "Whether the candidate addresses include every selected class-label row. false keeps binding coverage partial when the existing record budget truncates the scan; omitted is unknown and also keeps it partial.", ) .optional(), max_input_bytes: z diff --git a/src/native/AppleDispatchMetadata.test.ts b/src/native/AppleDispatchMetadata.test.ts index 15da9c1ce7..f4d28f96a3 100644 --- a/src/native/AppleDispatchMetadata.test.ts +++ b/src/native/AppleDispatchMetadata.test.ts @@ -468,6 +468,7 @@ describe("Imported class symbol byte identities", () => { provenance, "arm64", ["0x100000b00"], + true, ); expect(result.swift_conformances).toMatchObject([ { @@ -500,6 +501,25 @@ describe("Imported class symbol byte identities", () => { ); }); +describe("Imported class symbol candidate completeness", () => { + it("keeps binding coverage partial when the caller does not state the candidates are complete", () => { + const result = decodeAppleDispatchMetadata( + swiftExternalSwiftBindingImage("objc-class"), + 100, + provenance, + "arm64", + ["0x100000b00"], + ); + expect(result.objc_class_import_bindings).toEqual([ + expect.objectContaining({ symbol: "_OBJC_CLASS_$_NSObject" }), + ]); + expect(result.objc_class_import_binding_coverage).toMatchObject({ + status: "partial", + reason: expect.stringContaining("objc_class_import_addresses_complete"), + }); + }); +}); + describe("Imported library byte identities", () => { it.each(["invalid bytes", "literal replacement character"] as const)( "keeps Swift and Objective-C library identity distinct for %s", @@ -518,6 +538,7 @@ describe("Imported library byte identities", () => { provenance, "arm64", ["0x100000b00"], + true, ); expect(result.swift_conformances).toMatchObject([ { diff --git a/src/native/AppleDispatchMetadata.ts b/src/native/AppleDispatchMetadata.ts index 11775ab5a2..7c7295d823 100644 --- a/src/native/AppleDispatchMetadata.ts +++ b/src/native/AppleDispatchMetadata.ts @@ -76,7 +76,7 @@ export function* decodeAppleDispatchMetadataSteps( provenance: { path: string; sha256: string }, architecture = "arm64", objcClassImportAddresses?: readonly string[], - objcClassImportAddressesComplete = true, + objcClassImportAddressesComplete?: boolean, admittedSlice?: AdmittedMachoSlice, ): Generator { const selected = selectMachoSlice(bytes, { @@ -362,6 +362,7 @@ const inputBudgetExceeded = ( export interface AppleDispatchMetadataOptions { readonly signal?: AbortSignal | undefined; readonly objcClassImportAddresses?: readonly string[] | undefined; + /** Whether the addresses cover every class-label row; omitted is unknown. */ readonly objcClassImportAddressesComplete?: boolean | undefined; /** Caller-selected input budget; the default applies when omitted. */ readonly maxInputBytes?: number | undefined; @@ -421,7 +422,7 @@ export const inspectAppleDispatchMetadata = async ( { path: target.path, sha256: digest }, target.architecture, options.objcClassImportAddresses, - options.objcClassImportAddressesComplete ?? true, + options.objcClassImportAddressesComplete, target.format === "mach-o-universal" ? target.universalSlice : undefined, ); let next = steps.next(); diff --git a/src/native/AppleObjcClassImportBindings.test.ts b/src/native/AppleObjcClassImportBindings.test.ts index b3d0ca64b9..6e176ac6db 100644 --- a/src/native/AppleObjcClassImportBindings.test.ts +++ b/src/native/AppleObjcClassImportBindings.test.ts @@ -225,3 +225,17 @@ describe("Objective-C import binding address inspection", () => { ).toMatchObject({ status: "not_requested", reason: null, examined: 0 }); }); }); + +describe("Objective-C import binding candidate completeness", () => { + it("keeps coverage partial when the candidates' completeness was not stated", () => { + for (const addresses of [["0x1000", "0x1008"], []]) + expect( + inspectObjcClassImportBindings( + createInput({ addresses, addressesComplete: undefined }), + ).coverage, + ).toMatchObject({ + status: "partial", + reason: expect.stringContaining("did not state"), + }); + }); +}); diff --git a/src/native/AppleObjcClassImportBindings.ts b/src/native/AppleObjcClassImportBindings.ts index fd00698dec..56b09b080e 100644 --- a/src/native/AppleObjcClassImportBindings.ts +++ b/src/native/AppleObjcClassImportBindings.ts @@ -18,14 +18,18 @@ export const inspectObjcClassImportBindings = (input: { readonly layout: MachoLayout; readonly fixups: PointerFixups; readonly addresses: readonly string[] | undefined; - readonly addressesComplete: boolean; + /** Whether `addresses` covers every class-label row; undefined is unknown. */ + readonly addressesComplete: boolean | undefined; readonly maxRecords: number; }): ObjcClassImportBindingScan => { const { bytes, layout, fixups, addresses, addressesComplete, maxRecords } = input; - // An explicitly truncated candidate scan keeps its limitation even when no - // candidate was retained. - if (addresses === undefined || (addresses.length === 0 && addressesComplete)) + // A candidate scan that is truncated, or whose completeness was not stated, + // keeps its limitation even when no candidate was retained. + if ( + addresses === undefined || + (addresses.length === 0 && addressesComplete === true) + ) return { bindings: [], coverage: { @@ -47,10 +51,14 @@ export const inspectObjcClassImportBindings = (input: { }; const reasons = new Set(); - if (!addressesComplete) + if (addressesComplete === false) reasons.add( "Candidate address scan reached the existing max_records limit", ); + if (addressesComplete === undefined) + reasons.add( + "The caller did not state whether the candidate addresses include every class-label row (objc_class_import_addresses_complete)", + ); for (const failure of fixups.failures) reasons.add(failure); const bindings: MachoImportBinding[] = []; diff --git a/src/native/NativeMacOSProvider.ts b/src/native/NativeMacOSProvider.ts index 4c69d9bd97..ac3884eacc 100644 --- a/src/native/NativeMacOSProvider.ts +++ b/src/native/NativeMacOSProvider.ts @@ -343,7 +343,7 @@ class NativeMacOSClient implements AnalysisClient { signal: options?.signal, objcClassImportAddresses: input.data.objc_class_import_addresses, objcClassImportAddressesComplete: - input.data.objc_class_import_addresses_complete ?? true, + input.data.objc_class_import_addresses_complete, maxInputBytes: input.data.max_input_bytes, }, ),