merge: retain main CI planning and artifact checks

This commit is contained in:
64579525
2026-10-13 19:37:50 +08:00
136 changed files with 34298 additions and 798 deletions
@@ -61,7 +61,13 @@ afterEach(async () => {
});
describe("native macOS provider discovery", () => {
it.each(["ordinary.fixture", " spaced.fixture ", " leading", "trailing "])(
it.each([
"ordinary.fixture",
" spaced.fixture ",
" leading",
"trailing ",
"literal\r\nidentifier\r",
])(
"preserves the exact signing identifier %j reported by codesign",
(identifier) => {
const parsed = parseCodeSignature(
@@ -74,31 +80,68 @@ describe("native macOS provider discovery", () => {
},
);
it("separates echoed path and identifier text from signature fields", () => {
const path = "/apps/x\nAuthority=Forged\nIdentifier=forged";
const identifier = "x\nFormat=forged\nAuthority=Forged-5555";
const parsed = parseCodeSignature(
[
`Executable=${path}`,
`Identifier=${identifier}`,
"Format=Mach-O thin (arm64)",
"CodeDirectory v=20400 size=342 flags=0x2(adhoc) hashes=2+2",
"CDHash=6aee90e6",
"Signature=adhoc",
"TeamIdentifier=not set",
"",
].join("\r\n"),
false,
["/elsewhere", path],
);
expect(parsed).toMatchObject({
identifier,
format: "Mach-O thin (arm64)",
authorities: [],
cdhashes: ["6aee90e6"],
team_identifier: null,
});
});
it.each(["\n", "\r\n"])(
"separates echoed path and identifier text from signature fields (%j)",
(newline) => {
const path = "/apps/x\r\nAuthority=Forged\nIdentifier=forged";
const identifier = "x\r\nFormat=forged\nAuthority=Forged-5555\r";
const parsed = parseCodeSignature(
[
`Executable=${path}`,
`Identifier=${identifier}`,
"Format=Mach-O thin (arm64)",
"CodeDirectory v=20400 size=342 flags=0x2(adhoc) hashes=2+2",
"CDHash=6aee90e6",
"Signature=adhoc",
"TeamIdentifier=not set",
"",
].join(newline),
false,
["/elsewhere", path],
);
expect(parsed).toMatchObject({
identifier,
format: "Mach-O thin (arm64)",
authorities: [],
cdhashes: ["6aee90e6"],
team_identifier: null,
});
},
);
it.each([
{ executable: "", paths: [], newline: "\r\n", identifier: "fixture" },
{
executable: "Executable=/apps/fixture\r\n",
paths: [],
newline: "\r\n",
identifier: "fixture\nFormat=payload\r",
},
{
executable: "Executable=/apps/fixture\n",
paths: ["/elsewhere"],
newline: "\n",
identifier: "fixture\r\nFormat=payload\r",
},
{
executable: "Executable=/apps/fixture\r\n",
paths: ["/elsewhere"],
newline: "\r\n",
identifier: "fixture\r",
},
])(
"frames the identifier without a matching executable path: %j",
({ executable, paths, newline, identifier }) => {
const parsed = parseCodeSignature(
`${executable}Identifier=${identifier}${newline}Format=Mach-O thin (arm64)${newline}TeamIdentifier=not set${newline}`,
false,
paths,
);
expect(parsed.identifier).toBe(identifier);
expect(parsed.format).toBe("Mach-O thin (arm64)");
expect(parsed.team_identifier).toBeNull();
},
);
it.each(["timeout", "output-limit"] as const)(
"preserves %s resolution failures with their captured output and cleanup status",
@@ -1,7 +1,11 @@
import { expect, it } from "vitest";
import { CPU } from "../../../../src/artifacts/apple/MachoImage.fixture.js";
import { inspectMachoSchema } from "../../../../src/domain/native/nativeInspection.js";
import { err } from "../../../../src/domain/result.js";
import { NativeCommandFailure } from "../../../../src/native/CommandRunner.js";
import {
NativeCommandFailure,
type NativeCommandRunner,
} from "../../../../src/native/CommandRunner.js";
import { NativeMacOSProvider } from "../../../../src/native/NativeMacOSProvider.js";
import {
NativeFixtureRunner,
@@ -9,6 +13,35 @@ import {
nativeMachoTarget,
} from "../../../fixtures/nativeCommands.js";
/** Replay fixtures, failing any slice command that does not name the expected slice. */
const sliceSelectingRunner = (
fixtures: NativeFixtureRunner,
selected: string,
dyldArchitecture: string,
calls: {
readonly tool: string;
readonly arguments_: readonly string[];
}[] = [],
): NativeCommandRunner => ({
run(tool, arguments_) {
calls.push({ tool, arguments_ });
const expected = tool === "dyld_info" ? dyldArchitecture : selected;
if (
!["file", "lipo"].includes(tool) &&
!arguments_.some(
(argument, index) =>
argument === expected ||
argument === `--arch=${expected}` ||
(argument === "-arch" && arguments_[index + 1] === expected),
)
)
return Promise.resolve(
err(new NativeCommandFailure(tool, "nonzero-exit", 1)),
);
return fixtures.run(tool, arguments_);
},
});
it("does not attribute the first universal slice's UUID and segments to the selected target", async () => {
const singleSlice = await nativeFixture("otool-load.txt");
const selected = new NativeFixtureRunner();
@@ -58,18 +91,39 @@ it.each([
selected: "arm64e",
dyldArchitecture: "arm64e.v1",
},
])(
{
architectures: ["arm64v8", "arm64e.v1"],
selected: "arm64e",
dyldArchitecture: "arm64e.v1",
},
{
architectures: ["arm64e.v1", "arm64v8"],
selected: "arm64e",
dyldArchitecture: "arm64e.v1",
},
] as const)(
"selects the $dyldArchitecture slice of a universal arm64e target",
async ({ architectures, selected, dyldArchitecture }) => {
const calls: {
readonly tool: string;
readonly arguments_: readonly string[];
}[] = [];
const cpus = {
x86_64: CPU.x86_64,
arm64e: CPU.arm64e,
arm64v8: { type: CPU.arm64.type, subtype: 1 },
"arm64e.x1": { type: CPU.arm64.type, subtype: 0x8000000c },
"arm64e.v1": { type: CPU.arm64.type, subtype: 0x81000002 },
};
const lipo = architectures
.map(
(architecture, index) =>
`architecture ${architecture}\n cputype 16777228\n cpusubtype 2\n offset ${index * 16384}\n size 8192\n align 2^14 (16384)`,
)
.map((architecture, index) => {
const cpu = cpus[architecture];
const subtype =
architecture === "arm64e.v1"
? "CPU_SUBTYPE_ARM64E\n capabilities PTR_AUTH_VERSION USERSPACE 1"
: String(cpu.subtype);
return `architecture ${architecture}\n cputype ${cpu.type}\n cpusubtype ${subtype}\n offset ${index * 16384}\n size 8192\n align 2^14 (16384)`;
})
.join("\n");
const fixtures = new NativeFixtureRunner({
lipo,
@@ -77,25 +131,7 @@ it.each([
});
const client = new NativeMacOSProvider(
{},
{
run(tool, arguments_) {
calls.push({ tool, arguments_ });
const expected = tool === "dyld_info" ? dyldArchitecture : selected;
if (
!["file", "lipo"].includes(tool) &&
!arguments_.some(
(argument, index) =>
argument === expected ||
argument === `--arch=${expected}` ||
(argument === "-arch" && arguments_[index + 1] === expected),
)
)
return Promise.resolve(
err(new NativeCommandFailure(tool, "nonzero-exit", 1)),
);
return fixtures.run(tool, arguments_);
},
},
sliceSelectingRunner(fixtures, selected, dyldArchitecture, calls),
"darwin",
).createClient(nativeMachoTarget("/owned/universal"));
@@ -104,6 +140,11 @@ it.each([
if (!result.ok) throw result.error;
expect(result.value.result).toMatchObject({
uuid: "01234567-89AB-CDEF-0123-456789ABCDEF",
selected_architecture: {
name: dyldArchitecture,
container_file_offset:
architectures.findIndex((name) => name === dyldArchitecture) * 16384,
},
architectures: {
items: architectures.map((name) => ({ name })),
},
@@ -116,6 +157,36 @@ it.each([
},
);
it.each([
{ capture: "calculator.txt", selected: "arm64e" },
{ capture: "shortcut-droplet.txt", selected: "arm64" },
])(
"selects one slice when every universal slice has the target's CPU type ($capture)",
async ({ capture, selected }) => {
const base = nativeMachoTarget("/owned/universal");
if (base.kind !== "executable")
throw new Error("Expected executable fixture");
// Admission names arm64, arm64e and arm64e.x1 slices by one CPU family.
const target = { ...base, availableArchitectures: ["arm64"] as const };
const fixtures = new NativeFixtureRunner({
lipo: await nativeFixture(`lipo-same-cpu/${capture}`),
});
const result = await new NativeMacOSProvider(
{},
sliceSelectingRunner(fixtures, selected, selected),
"darwin",
)
.createClient(target)
.execute("inspect_macho", {});
if (!result.ok) throw result.error;
expect(result.value.result).toMatchObject({
selected_architecture: { name: selected, container_file_offset: 16384 },
architectures: { total: 2 },
});
},
);
it("projects universal segment evidence into the selected slice's container offsets", async () => {
const client = new NativeMacOSProvider(
{},