fix(clients): preserve portable MCP schemas in native workflows (#1580)

* test(clients): verify native Command Code workflows

* docs: synchronize Italian provider guide links

* fix(contracts): make ADB identifier patterns portable

* fix(contracts): preserve portable ADB patterns after formatting
This commit is contained in:
Ysopwnable
2026-10-11 00:09:43 +08:00
committed by GitHub
parent c1b5ccf0a4
commit 6d8f95e38d
5 changed files with 569 additions and 15 deletions
+82
View File
@@ -0,0 +1,82 @@
import { expect, it } from "vitest";
import { adbInputSchemas } from "./adbDeviceAnalysis.js";
it("preserves ADB key, action and component admission when making advertised patterns portable", () => {
const serial = "emulator-5554";
const variants = [
{
previous: /^[A-Za-z0-9._-]+$/u,
max: 256,
accepts: (key: string) =>
adbInputSchemas.read_adb_setting.safeParse({
serial,
namespace: "global",
key,
}).success,
},
{
previous: /^[A-Za-z0-9._-]+$/u,
max: 256,
accepts: (key: string) =>
adbInputSchemas.start_adb_activity.safeParse({
serial,
action: "android.intent.action.VIEW",
extras: [{ key, type: "string", value: "payload" }],
}).success,
},
{
previous: /^[A-Za-z][A-Za-z0-9._-]*$/u,
max: 256,
accepts: (action: string) =>
adbInputSchemas.start_adb_activity.safeParse({ serial, action })
.success,
},
{
previous: /^[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]*)?$/u,
max: 512,
accepts: (component: string) =>
adbInputSchemas.start_adb_activity.safeParse({
serial,
action: "android.intent.action.VIEW",
component,
}).success,
},
];
const samples = [
"",
"screen_brightness",
"0",
"_",
".",
"-",
"android.intent.action.VIEW",
"com.example/.MainActivity",
"com.example/",
"com.example/a/b",
"a\n",
"a\r\n",
"é",
"aé",
"a b",
"a\\b",
"a".repeat(256),
"a".repeat(257),
"a".repeat(512),
"a".repeat(513),
];
for (let code = 0; code < 128; code += 1) {
const character = String.fromCharCode(code);
samples.push(character, `a${character}`, `a${character}b`);
}
for (const variant of variants)
for (const sample of samples)
expect(
variant.accepts(sample),
JSON.stringify({ pattern: variant.previous.source, sample }),
).toBe(
sample.length > 0 &&
sample.length <= variant.max &&
variant.previous.test(sample),
);
});
+10 -15
View File
@@ -1,5 +1,6 @@
import { z } from "zod";
import { localPathStringSchema } from "../localPath.js";
import { IDENTIFIER_PATTERN } from "../stringPatterns.js";
/**
* Device serials as adb prints them: emulator-5554, USB identifiers, and
@@ -29,6 +30,9 @@ const packageNameSchema = z
"Package name must be dot-separated Java identifiers",
);
const keyStringSchema = z.string().min(1).max(256);
const keyPattern = /^[A-Za-z0-9._\x2d]+$/u;
/**
* Caller intent for ADB-backed device inspection and acquisition.
*
@@ -174,14 +178,8 @@ export const adbInputSchemas = {
namespace: z
.enum(["system", "secure", "global"])
.describe("Settings namespace to read"),
key: z
.string()
.min(1)
.max(256)
.regex(
/^[A-Za-z0-9._\-]+$/u,
"Setting keys are restricted to identifiers",
)
key: keyStringSchema
.regex(keyPattern, "Setting keys are restricted to identifiers")
.describe("Setting key to read"),
}),
collect_adb_bugreport: z.strictObject({
@@ -241,7 +239,7 @@ export const adbInputSchemas = {
.min(1)
.max(256)
.regex(
/^[A-Za-z][A-Za-z0-9._\-]*$/u,
IDENTIFIER_PATTERN,
"Intent action must be a dotted identifier such as android.intent.action.VIEW",
)
.describe("Intent action to start"),
@@ -257,7 +255,7 @@ export const adbInputSchemas = {
.min(1)
.max(512)
.regex(
/^[A-Za-z0-9._\-]+(\/[A-Za-z0-9._\-]*)?$/u,
/^[A-Za-z0-9._\x2d]+(\/[A-Za-z0-9._\x2d]*)?$/u,
"Component must be package/activity form",
)
.optional()
@@ -265,11 +263,8 @@ export const adbInputSchemas = {
extras: z
.array(
z.strictObject({
key: z
.string()
.min(1)
.max(256)
.regex(/^[A-Za-z0-9._\-]+$/u, "Extra keys are identifiers")
key: keyStringSchema
.regex(keyPattern, "Extra keys are identifiers")
.describe("Extra key"),
type: z
.enum(["string", "boolean", "int", "long", "float"])