ACPX extension: support acpx any-version probe via --help

This commit is contained in:
Onur
2026-02-28 21:02:25 +01:00
committed by Onur Solmaz
parent 921ebfb25e
commit 9cae5107d1
2 changed files with 31 additions and 5 deletions

View File

@@ -45,6 +45,11 @@ describe("acpx ensure", () => {
version: ACPX_PINNED_VERSION,
expectedVersion: ACPX_PINNED_VERSION,
});
expect(spawnAndCollectMock).toHaveBeenCalledWith({
command: "/plugin/node_modules/.bin/acpx",
args: ["--version"],
cwd: "/plugin",
});
});
it("reports version mismatch", async () => {
@@ -70,9 +75,9 @@ describe("acpx ensure", () => {
});
});
it("accepts any installed version when expectedVersion is unset", async () => {
it("accepts command availability when expectedVersion is unset", async () => {
spawnAndCollectMock.mockResolvedValueOnce({
stdout: "acpx 9.9.9\n",
stdout: "Usage: acpx [options]\n",
stderr: "",
code: 0,
error: null,
@@ -86,9 +91,14 @@ describe("acpx ensure", () => {
expect(result).toEqual({
ok: true,
version: "9.9.9",
version: "unknown",
expectedVersion: undefined,
});
expect(spawnAndCollectMock).toHaveBeenCalledWith({
command: "/custom/acpx",
args: ["--help"],
cwd: "/custom",
});
});
it("installs and verifies pinned acpx when precheck fails", async () => {

View File

@@ -25,6 +25,10 @@ function extractVersion(stdout: string, stderr: string): string | null {
return match?.[0] ?? null;
}
function isExpectedVersionConfigured(value: string | undefined): value is string {
return typeof value === "string" && value.trim().length > 0;
}
export async function checkAcpxVersion(params: {
command: string;
cwd?: string;
@@ -33,9 +37,11 @@ export async function checkAcpxVersion(params: {
const expectedVersion = params.expectedVersion?.trim() || undefined;
const installCommand = buildAcpxLocalInstallCommand(expectedVersion ?? ACPX_PINNED_VERSION);
const cwd = params.cwd ?? ACPX_PLUGIN_ROOT;
const hasExpectedVersion = isExpectedVersionConfigured(expectedVersion);
const probeArgs = hasExpectedVersion ? ["--version"] : ["--help"];
const result = await spawnAndCollect({
command: params.command,
args: ["--version"],
args: probeArgs,
cwd,
});
@@ -64,12 +70,22 @@ export async function checkAcpxVersion(params: {
return {
ok: false,
reason: "execution-failed",
message: stderr || `acpx --version failed with code ${result.code ?? "unknown"}`,
message:
stderr ||
`acpx ${hasExpectedVersion ? "--version" : "--help"} failed with code ${result.code ?? "unknown"}`,
expectedVersion,
installCommand,
};
}
if (!hasExpectedVersion) {
return {
ok: true,
version: "unknown",
expectedVersion,
};
}
const installedVersion = extractVersion(result.stdout, result.stderr);
if (!installedVersion) {
return {