Files
rea/tests/boundary/cli/desktopNativeRecognitionCli.test.ts
T
morluto 46b73f5b81 feat(desktop)!: recognise native releases and rank application probes first (#14264)
* feat(desktop)!: recognise native releases and rank application probes first

inspect-desktop-application returned nothing for native Qt or SDL
releases, gave Godot candidates no probe, and listed every BCL facade of
a self-contained .NET release as an equal inspect_managed_artifact probe.

- A native candidate names the shallowest main executables when no
  other runtime is recognised. Its PE probes are inspect_pe_imports and
  inspect_pe_resources.
- Component markers name Qt, SDL, wxWidgets, GTK and the MSVC runtime
  from the files a release ships.
- Each Godot pack carrier gets an inspect_artifact probe.
- Probes carry a priority. Assemblies with a matching runtimeconfig,
  deps.json or pdb come first, and runtime facades are counted once in
  deferred_probes instead of probed one by one.

BREAKING CHANGE: the desktop application result adds the native family,
the ui-framework and runtime-library component categories, new probe
operations, a required probe priority and deferred_probes.

Fixes #14173
Refs #14179

* fix(desktop): select Godot packs with open_binary, summarize deferred probes and match Unix wxWidgets names

inspect_artifact reads the active target and takes no path, so a Godot
pack probe now selects its carrier with open_binary and names
inspect_artifact as the follow-up, as the ASAR probe does. The default
summary carries deferred_probes, the release-audit fixtures include the
field, and the wxWidgets marker accepts libwx_*.so and .dylib names.

* fix(desktop): read Unix mains without host executable marking and describe resource probes accurately

Windows cannot mark ELF or Mach-O files executable, so the reader also
reads headers of Contents/MacOS entries and extensionless root files.
The inspect_pe_resources probe now describes the resource-tree inventory
it returns.
2026-11-24 04:19:57 +00:00

109 lines
4.0 KiB
TypeScript

import { mkdir, writeFile } from "node:fs/promises";
import { join } from "node:path";
import { expect } from "vitest";
import { buildManagedPeFixture } from "../../../src/dotnet/ManagedPe.fixture.js";
import { desktopApplicationSchema } from "../../../src/domain/desktopApplication.js";
import { parseEvidence } from "../../../src/domain/evidence.js";
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { cliTest } from "../../support/cli/cliFixture.js";
/** A complete PE image whose CLI directory is cleared: a native Windows image. */
const nativePe = (): Buffer => {
const bytes = buildManagedPeFixture({ references: [] });
const optional = bytes.readUInt32LE(0x3c) + 24;
const directories =
optional + (bytes.readUInt16LE(optional) === 0x20b ? 112 : 96);
bytes.fill(0, directories + 14 * 8, directories + 15 * 8);
return bytes;
};
cliTest(
"recognises a native SDL release the same way over CLI and MCP",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-desktop-native-cli-");
for (const [path, bytes] of [
["PPSSPPWindows64.exe", nativePe()],
["SDL2.dll", nativePe()],
["assets/ui_atlas.zim", "atlas"],
] as const) {
await mkdir(join(root, path, ".."), { recursive: true });
await writeFile(join(root, path), bytes);
}
const result = await cli.run({
arguments: ["inspect-desktop-application", root, "--json"],
});
expect(result.exitCode, result.stderr).toBe(0);
const report = desktopApplicationSchema.parse(
parseEvidence(result.json).normalized_result,
);
const pathOf = new Map(
report.files.map((file) => [file.file_id, file.path]),
);
expect(report.candidates.map(({ family }) => family)).toEqual(["native"]);
expect(report.components.map(({ name }) => name)).toEqual(["SDL"]);
expect(
report.next_probes.map(({ operation, file_id }) => [
operation,
pathOf.get(file_id),
]),
).toEqual([
["inspect_pe_imports", "PPSSPPWindows64.exe"],
["inspect_pe_resources", "PPSSPPWindows64.exe"],
]);
const call = await cli.sharedMcpCall!();
const response = await call("inspect_desktop_application", {
path: root,
detail: "complete",
});
expect(response.isError, JSON.stringify(response.content)).not.toBe(true);
const mcp = desktopApplicationSchema.parse(
parseEvidence(response.structuredContent).normalized_result,
);
expect({
candidates: mcp.candidates,
components: mcp.components,
next_probes: mcp.next_probes,
deferred_probes: mcp.deferred_probes,
}).toEqual({
candidates: report.candidates,
components: report.components,
next_probes: report.next_probes,
deferred_probes: report.deferred_probes,
});
},
);
cliTest(
"keeps deferred runtime-facade counts in the default MCP summary",
async ({ cli }) => {
const root = await createTestTempDirectory("rea-desktop-deferred-mcp-");
const assembly = buildManagedPeFixture({ references: ["System.Runtime"] });
for (const name of ["Game.dll", "System.Xml.dll", "System.Linq.dll"])
await writeFile(join(root, name), assembly);
await writeFile(join(root, "Game.runtimeconfig.json"), "{}");
const call = await cli.sharedMcpCall!();
const response = await call("inspect_desktop_application", { path: root });
expect(response.isError, JSON.stringify(response.content)).not.toBe(true);
const summary = parseEvidence(response.structuredContent)
.normalized_result as {
summary: { deferred_probes: unknown; next_probe_groups: unknown };
};
expect(summary.summary.deferred_probes).toEqual([
expect.objectContaining({
operation: "inspect_managed_artifact",
reason: "runtime-facade",
count: 2,
}),
]);
expect(summary.summary.next_probe_groups).toEqual([
expect.objectContaining({
operation: "inspect_managed_artifact",
count: 1,
example: expect.objectContaining({ priority: "application" }),
}),
]);
},
);