mirror of
https://github.com/morluto/rea.git
synced 2026-11-07 07:16:13 +00:00
fix(cli): align ADB directory and package query schemas (#8974)
* fix(cli): align ADB directory and package query schemas * fix(cli): preserve ADB selector correction details
This commit is contained in:
1 parent
65986d0a0f
commit
1dc83b160d
3 files changed
+44
-12
No files matched your search
+3
-12
@@ -207,10 +207,7 @@ export const registerAdbCommands = (
|
||||
description: "List one device directory with kinds, permissions, and sizes",
|
||||
args: z.object({
|
||||
serial,
|
||||
"device-path": z
|
||||
.string()
|
||||
.min(1)
|
||||
.describe("Absolute device directory path to list"),
|
||||
"device-path": adbInputSchemas.list_adb_directory.shape.device_path,
|
||||
}),
|
||||
run: ({ args }) =>
|
||||
execute(CLI_COMMANDS.listAdbDirectory, "list_adb_directory", {
|
||||
@@ -275,15 +272,9 @@ export const registerAdbCommands = (
|
||||
});
|
||||
cli.command(CLI_COMMANDS.resolveAdbPackages, {
|
||||
description: "Find installed packages by case-insensitive name substring",
|
||||
args: z.object({
|
||||
serial,
|
||||
query: z.string().min(2).describe("Package-name substring to find"),
|
||||
}),
|
||||
args: adbInputSchemas.resolve_adb_packages,
|
||||
run: ({ args }) =>
|
||||
execute(CLI_COMMANDS.resolveAdbPackages, "resolve_adb_packages", {
|
||||
serial: args.serial,
|
||||
query: args.query,
|
||||
}),
|
||||
execute(CLI_COMMANDS.resolveAdbPackages, "resolve_adb_packages", args),
|
||||
});
|
||||
cli.command(CLI_COMMANDS.installAdbPackage, {
|
||||
description:
|
||||
|
||||
@@ -20,6 +20,8 @@ const adbPackageCommands = new Set([
|
||||
const isAdbSelector = (command: string, field: string): boolean =>
|
||||
(command.includes("-adb-") && field === "serial") ||
|
||||
(adbPackageCommands.has(command) && field === "package") ||
|
||||
(command === "list-adb-directory" && field === "device-path") ||
|
||||
(command === "resolve-adb-packages" && field === "query") ||
|
||||
(command === "start-adb-activity" &&
|
||||
["action", "component", "data-uri"].includes(field));
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import { expect } from "vitest";
|
||||
|
||||
import { toolContract } from "../../../src/contracts/toolContracts.js";
|
||||
@@ -10,6 +11,44 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest, runFileCli } from "../../support/cli/cliFixture.js";
|
||||
|
||||
const PACKAGE_LINE = "package:/data/app/example/base.apk=com.example.app";
|
||||
|
||||
cliTest.for([
|
||||
{
|
||||
command: "list-adb-directory",
|
||||
field: "device-path",
|
||||
valid: "/sdcard",
|
||||
invalid: "sdcard",
|
||||
constraint: { expected: "regex" },
|
||||
},
|
||||
{
|
||||
command: "resolve-adb-packages",
|
||||
field: "query",
|
||||
valid: "a".repeat(256),
|
||||
invalid: "a".repeat(257),
|
||||
constraint: { maximum: 256 },
|
||||
},
|
||||
])(
|
||||
"publishes the enforced ADB selector constraint for $command",
|
||||
async ({ command, field, valid, invalid, constraint }, { cli }) => {
|
||||
const schema = await cli.run({
|
||||
arguments: [command, "--schema", "--json"],
|
||||
});
|
||||
expect(schema.exitCode, schema.stderr).toBe(0);
|
||||
const output = schema.json as { args: Parameters<Ajv2020["compile"]>[0] };
|
||||
const validate = new Ajv2020({ strict: false }).compile(output.args);
|
||||
const serial = "emulator-5554";
|
||||
expect(validate({ serial, [field]: valid })).toBe(true);
|
||||
expect(validate({ serial, [field]: invalid })).toBe(false);
|
||||
const result = await cli.run({
|
||||
arguments: [command, serial, invalid, "--json"],
|
||||
});
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.json).toMatchObject({
|
||||
code: "VALIDATION_ERROR",
|
||||
fieldErrors: [expect.objectContaining({ path: field, ...constraint })],
|
||||
});
|
||||
},
|
||||
);
|
||||
const unrecognized = (count: number) =>
|
||||
Array.from(
|
||||
{ length: count },
|
||||
|
||||
Reference in new issue
Block a user