Files
rea/tests/boundary/cli/nativeDispatchPropertyAttributes.test.ts
T
morluto 060587b456 fix(cli): prefer native byte inspection for automatic dispatch metadata
Allow the composed one-shot dispatch workflow to open a covered Mach-O
without selecting a deep provider. The registry still owns selector
precedence; explicit request/environment choices remain binding, while
non-Mach-O and unsupported hosts retain deep symbol fallback. Requested
snapshots keep ordinary binding and profile semantics.

Share runtime composition and target admission with the native byte reader.
Keep target parsing, resource ownership and Evidence on the original session.

Validation: 13 focused files, 192 passed and 2 skipped; npm run check passed.
The six previously blocked native property CLI controls now pass. Ten measured
CLI workflows preserved exact metadata facts; warm raw reply token medians
1344/927, elapsed .475/.547s, CPU .691/.745s, sampled family RSS351.2/359.3MiB
baseline/candidate. Baseline used explicit Ghidra workaround; true cold and
full-agent costs unmeasured. No speed/memory improvement or Windows claim.

Refs #4555
2026-10-17 03:11:32 +08:00

165 lines
5.5 KiB
TypeScript

import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { describe, expect } from "vitest";
import { machoWithPropertyAttributes } from "../../fixtures/objcPropertyMacho.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
describe.skipIf(process.platform !== "darwin")(
"native dispatch property attributes",
() => {
cliTest.for([
["complete nonatomic", "Tq,N", "nonatomic", false, "complete"],
["complete default", 'T@"NSString",C', "atomic", false, "complete"],
["unfinished quote", 'T@"NSString', null, null, "partial"],
["unfinished quote after R", 'R,T@"NSString', null, true, "partial"],
] as const)(
"reports established property flags only for $0 attributes",
async ([, attributes, atomicity, readonly, facet], { cli }) => {
const directory = await createTestTempDirectory("rea-objc-property-");
const path = join(directory, "fixture.bin");
await writeFile(path, machoWithPropertyAttributes(attributes));
const output = await cli.run({
arguments: ["inspect-native-dispatch-metadata", path, "--json"],
environment: { REA_LOG_LEVEL: "silent" },
});
expect(output.exitCode, `${output.stdout}\n${output.stderr}`).toBe(0);
const property = {
atomicity,
is_readonly: readonly,
attributes: expect.arrayContaining([
{ name: "T", value: expect.any(String) },
]),
};
expect(output.json).toMatchObject({
normalized_result: {
result: {
objc_classes: [
{
name: "Fixture",
properties: [
{ name: "first", ...property },
{ name: "second", ...property },
],
},
],
coverage: expect.arrayContaining([
expect.objectContaining({
facet: "objc_properties_categories",
status: facet,
reason:
facet === "partial"
? expect.stringContaining(
"property_attributes_incomplete",
)
: null,
}),
]),
},
},
});
},
);
},
);
describe.skipIf(process.platform !== "darwin")(
"native dispatch property record isolation",
() => {
cliTest.for([
[
"an unmapped name pointer",
{ secondNameOffset: 0x2000 },
"first",
"0x100000518",
],
["an empty name", { firstName: "" }, "second", "0x100000508"],
] as const)(
"retains the valid sibling of a property with $0",
async ([, layout, kept, location], { cli }) => {
const directory = await createTestTempDirectory("rea-objc-property-");
const path = join(directory, "fixture.bin");
await writeFile(path, machoWithPropertyAttributes("Tq,N", layout));
const output = await cli.run({
arguments: ["inspect-native-dispatch-metadata", path, "--json"],
environment: { REA_LOG_LEVEL: "silent" },
});
expect(output.exitCode, `${output.stdout}\n${output.stderr}`).toBe(0);
expect(output.json).toMatchObject({
normalized_result: {
result: {
objc_classes: [
{
name: "Fixture",
properties: [{ name: kept, atomicity: "nonatomic" }],
},
],
coverage: expect.arrayContaining([
expect.objectContaining({
facet: "objc_properties_categories",
status: "partial",
reason: expect.stringContaining(
`property_decode_failed at ${location}: Fixture: property`,
),
}),
]),
},
},
});
},
);
},
);
describe.skipIf(process.platform !== "darwin")(
"native dispatch provider choice",
() => {
cliTest.for([
[[], "missing", 1, "unknown_provider"],
[["--provider", "missing"], "auto", 1, "unknown_provider"],
[["--provider", "auto"], "missing", 0, null],
] as const)(
"preserves explicit selection %j",
async ([options, configured, exitCode, reason], { cli }) => {
const directory = await createTestTempDirectory(
"rea-dispatch-provider-choice-",
);
const path = join(directory, "fixture.bin");
await writeFile(path, machoWithPropertyAttributes("Tq,N"));
const output = await cli.run({
arguments: [
"inspect-native-dispatch-metadata",
path,
...options,
"--json",
],
environment: {
REA_LOG_LEVEL: "silent",
REA_ANALYSIS_PROVIDER: configured,
},
});
expect(output.exitCode, `${output.stdout}\n${output.stderr}`).toBe(
exitCode,
);
if (reason !== null)
expect(output.json).toMatchObject({
code: "capability_unavailable",
details: {
selection_reason: reason,
requested_provider_id: "missing",
},
});
else
expect(output.json).toMatchObject({
normalized_result: {
provider: { id: "native-macos" },
result: { objc_classes: [{ name: "Fixture" }] },
},
});
},
);
},
);