Files
reverse-engineering-anything/tests/boundary/cli/apktoolCli.test.ts
T
RRFZ 308a5b2f06 test(providers): give Windows a drive-rooted configured launcher (#12626)
* test(apktool): give Windows a drive-rooted authored launcher

The apktool unit and CLI boundary tests configure REA_APKTOOL_COMMAND
as /authored/apktool, /opt/apktool/apktool or /nonexistent/apktool.
On win32 hosts REA admits a configured launcher only when it is drive-
or UNC-rooted, so 17 cases there failed with the absolute-path refusal
before reaching the behavior they test. On Windows they now use the
same paths under C:\; other hosts keep the original strings.

* test(adb): give Windows a drive-rooted missing adb in the CLI refusals

The two "/nonexistent/adb names the host requirement" cases hit the
same win32 absolute-path refusal as the apktool launcher cases before
reaching the not-found check. On Windows they now use C:\nonexistent\adb.
2026-11-19 20:47:04 -05:00

102 lines
2.7 KiB
TypeScript

import { expect, it } from "vitest";
import {
expectConfigurationRefusal,
serveCli as serve,
} from "./cliServeHarness.js";
const MISSING_APKTOOL =
process.platform === "win32"
? "C:\\nonexistent\\apktool"
: "/nonexistent/apktool";
it.each([
[
["inspect-apktool-client", "--json"],
MISSING_APKTOOL,
`The selected apktool launcher was not found: ${MISSING_APKTOOL}. Set REA_APKTOOL_COMMAND`,
],
[
["decode-android-resources", "/targets/app.apk", "--json"],
MISSING_APKTOOL,
`The selected apktool launcher was not found: ${MISSING_APKTOOL}. Set REA_APKTOOL_COMMAND`,
],
[
["decode-android-resources", "/targets/app.apk", "--json"],
"relative/apktool",
"REA_APKTOOL_COMMAND must be an absolute path to the apktool launcher.",
],
])(
"%j with REA_APKTOOL_COMMAND=%s names the host requirement",
async (argv, command, reason) => {
const result = await serve(argv, { REA_APKTOOL_COMMAND: command });
expectConfigurationRefusal(result, reason);
},
);
it("validates the locale option before launching apktool", async () => {
const result = await serve([
"decode-android-resources",
"/targets/app.apk",
"--locale",
"not a locale",
"--json",
]);
expect(result.exitCode).toBe(1);
expect(JSON.parse(result.stdout)).toMatchObject({
code: "VALIDATION_ERROR",
fieldErrors: [
{
code: "invalid_format",
path: "locale",
},
],
});
});
it("reports each invocation's effective exit status and restores the host status", async () => {
const originalExitCode = process.exitCode;
process.exitCode = 23;
try {
const environment = { REA_APKTOOL_COMMAND: MISSING_APKTOOL };
const failed = await serve(
["inspect-apktool-client", "--json"],
environment,
);
expect(failed.exitCode).toBe(1);
expectConfigurationRefusal(
failed,
"The selected apktool launcher was not found",
);
expect(process.exitCode).toBe(23);
const success = await serve(
["inspect-apktool-client", "--help"],
environment,
);
expect(success.exitCode).toBe(0);
expect(success.stdout).toContain(
"Inspect the caller-selected apktool launcher",
);
expect(process.exitCode).toBe(23);
const parserFailure = await serve(
[
"decode-android-resources",
"/targets/app.apk",
"--locale",
"not a locale",
"--json",
],
environment,
);
expect(parserFailure.exitCode).toBe(1);
expect(JSON.parse(parserFailure.stdout)).toMatchObject({
code: "VALIDATION_ERROR",
});
expect(process.exitCode).toBe(23);
} finally {
process.exitCode = originalExitCode;
}
});