Files
rea/tests/process-global/apktoolEnvironment.test.ts
morlutoandmorluto 1eca600515 fix(apktool): resolve Windows PATH launchers before invocation (#2802)
* fix(apktool): resolve Windows PATH launchers before invocation

Resolve the default launcher through the selected PATH/PATHEXT before choosing native process creation or the existing conservative cmd.exe wrapper. Reuse the resulting selection and one canonical environment for the version probe and decode.

Follow-up to the release #1693 review of #1777. Source inspected and formatted; tests, builds, check reruns and real Windows Apktool execution were skipped at maintainer request.

* fix(apktool): bound lookup and retain only selected environment

Source inspection and targeted formatting only. Tests, builds, lint, typechecks and provider workloads were not run at the user's explicit request.

* fix(apktool): use supported timeout diagnostics

Retain lookup phase through AnalysisErrorOptions diagnostics while preserving the operation and timeout identity. Source inspection and targeted formatting only; tests, checks, builds and provider workloads were skipped at the user request.

---------

Co-authored-by: morluto <morluto@users.noreply.github.com>
2026-10-13 22:00:47 +08:00

54 lines
2.1 KiB
TypeScript

import { afterEach, expect, it, onTestFinished, vi } from "vitest";
import { ApktoolProvider } from "../../src/apktool/ApktoolProvider.js";
import { execFileOutput } from "../../src/process/ExecFileOutput.js";
vi.mock("../../src/process/ExecFileOutput.js", async (importOriginal) => ({
...(await importOriginal<
typeof import("../../src/process/ExecFileOutput.js")
>()),
execFileOutput: vi.fn(async () => ({ stdout: "2.7.0-stub\n", stderr: "" })),
}));
afterEach(() => {
vi.unstubAllEnvs();
vi.mocked(execFileOutput).mockClear();
});
it.skipIf(process.platform === "win32")(
"keeps an explicit environment's PATH choice and samples ambient inheritance per operation",
async () => {
vi.stubEnv("REA_APKTOOL_COMMAND", "/ambient/initial-apktool");
vi.stubEnv("REA_APKTOOL_TEST_INHERITED_VALUE", "initial");
const provider = new ApktoolProvider({ environment: {} });
onTestFinished(() => provider.close());
vi.stubEnv("REA_APKTOOL_COMMAND", "/ambient/changed-apktool");
vi.stubEnv("REA_APKTOOL_TEST_INHERITED_VALUE", "changed");
await provider.inspectAvailability();
expect(vi.mocked(execFileOutput).mock.lastCall?.[0]).toBe("apktool");
expect(vi.mocked(execFileOutput).mock.lastCall?.[2]?.env).toMatchObject({
REA_APKTOOL_COMMAND: undefined,
REA_APKTOOL_TEST_INHERITED_VALUE: "changed",
});
vi.stubEnv("REA_APKTOOL_TEST_INHERITED_VALUE", undefined);
await provider.inspectAvailability();
expect(
vi.mocked(execFileOutput).mock.lastCall?.[2]?.env
?.REA_APKTOOL_TEST_INHERITED_VALUE,
).toBeUndefined();
},
);
it.skipIf(process.platform === "win32")(
"inherits the current default launcher when no environment was selected",
async () => {
vi.stubEnv("REA_APKTOOL_COMMAND", "/ambient/initial-apktool");
const provider = new ApktoolProvider();
onTestFinished(() => provider.close());
vi.stubEnv("REA_APKTOOL_COMMAND", "/ambient/later-apktool");
await provider.inspectAvailability();
expect(vi.mocked(execFileOutput).mock.lastCall?.[0]).toBe(
"/ambient/later-apktool",
);
},
);