mirror of
https://github.com/morluto/rea.git
synced 2026-10-26 17:35:11 +00:00
Project default and multiple selected localized string tables from one immutable decode pass. Remove the need for repeated APK snapshotting, digesting, version probing, apktool d invocations, and workspace enumeration. - Contract: add optional locales array to decode_android_resources input schema (bounded to 20 locales) and structured string_tables to output schema with per-table status, strings, total_count, unparsed_count, and coverage. Preserve legacy strings and locale fields for complete backward compatibility. - Bounds: enforce 32 MiB aggregate XML read cap and 10,000 aggregate string entries cap across batched projections. Handle missing, oversized, and malformed tables per-table without failing or losing completed tables. - Lifecycle: maintain strict descriptor cleanup and provider-owned workspace removal in finally, preserving typed cancellation and failure details. - Adapters: add --locales repeatable option to CLI and update MCP contract. Validation: 10 service tests, 3 CLI boundary tests, and MCP boundary schema tests pass. Fast typecheck/lint and turbo docs:check:built pass. Fixes #4777
142 lines
3.7 KiB
TypeScript
142 lines
3.7 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { Cli } from "incur";
|
|
import pino from "pino";
|
|
|
|
import type { ApktoolResourceAnalysisPort } from "../../../src/application/apktool/ApktoolResourceAnalysisPort.js";
|
|
import { createAnalysisExecution } from "../../../src/application/AnalysisProvider.js";
|
|
import { registerApktoolCommands } from "../../../src/cli/apktoolCommands.js";
|
|
import { presentOmittableDefaults } from "../../../src/cli/omittableDefaults.js";
|
|
import type { ApktoolRequest } from "../../../src/domain/apktool/apktoolResourceAnalysis.js";
|
|
import { ok } from "../../../src/domain/result.js";
|
|
|
|
const invoke = async (argv: readonly string[]) => {
|
|
const requests: ApktoolRequest[] = [];
|
|
const provider: ApktoolResourceAnalysisPort = {
|
|
async inspectAvailability() {
|
|
throw new Error("unexpected provider probe");
|
|
},
|
|
async close() {},
|
|
async execute(request) {
|
|
requests.push(request);
|
|
return ok(
|
|
createAnalysisExecution(
|
|
{ strings: [] },
|
|
{ id: "apktool", name: "Apktool", version: null },
|
|
),
|
|
);
|
|
},
|
|
};
|
|
const cli = Cli.create("rea", { sync: false });
|
|
registerApktoolCommands(cli, pino({ level: "silent" }), {}, provider);
|
|
presentOmittableDefaults(cli);
|
|
|
|
let stdout = "";
|
|
let exitCode = 0;
|
|
await cli.serve([...argv], {
|
|
env: {},
|
|
exit: (code) => {
|
|
exitCode = code;
|
|
},
|
|
stdout: (text) => {
|
|
stdout += text;
|
|
},
|
|
});
|
|
return { exitCode, stdout, requests };
|
|
};
|
|
|
|
/**
|
|
* Locales the apktool input owner admits. The owner's own rejection message
|
|
* advertises `b+zh+Hans+CN`, so the CLI cannot be narrower than this list
|
|
* without refusing a caller-selected locale the decoding lane supports.
|
|
*/
|
|
const OWNER_ADMITTED_LOCALES = [
|
|
"de",
|
|
"pt-BR",
|
|
"pt-rBR",
|
|
"zh-rCN",
|
|
"en-419",
|
|
"b+zh+Hans+CN",
|
|
"b+sr+Latn+RS+REVISED",
|
|
"b+fil+Latn+419+ABCDEFGH",
|
|
] as const;
|
|
|
|
it("forwards every locale the apktool input owner admits", async () => {
|
|
for (const locale of OWNER_ADMITTED_LOCALES) {
|
|
const result = await invoke([
|
|
"decode-android-resources",
|
|
"/targets/app.apk",
|
|
"--locale",
|
|
locale,
|
|
"--json",
|
|
]);
|
|
|
|
expect(result.exitCode, `exit code for locale ${locale}`).toBe(0);
|
|
expect(result.requests, `request for locale ${locale}`).toEqual([
|
|
{
|
|
operation: "decode_android_resources",
|
|
input: { path: "/targets/app.apk", include_strings: true, locale },
|
|
},
|
|
]);
|
|
}
|
|
});
|
|
|
|
it("forwards repeated --locales to project multiple localized tables", async () => {
|
|
const result = await invoke([
|
|
"decode-android-resources",
|
|
"/targets/app.apk",
|
|
"--locales",
|
|
"de",
|
|
"--locales",
|
|
"pt-BR",
|
|
"--json",
|
|
]);
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.requests).toEqual([
|
|
{
|
|
operation: "decode_android_resources",
|
|
input: {
|
|
path: "/targets/app.apk",
|
|
include_strings: true,
|
|
locales: ["de", "pt-BR"],
|
|
},
|
|
},
|
|
]);
|
|
});
|
|
|
|
it("still refuses a locale the apktool input owner refuses", async () => {
|
|
const result = await invoke([
|
|
"decode-android-resources",
|
|
"/targets/app.apk",
|
|
"--locale",
|
|
"not a locale",
|
|
"--json",
|
|
]);
|
|
|
|
expect(result.exitCode).not.toBe(0);
|
|
expect(result.requests).toEqual([]);
|
|
});
|
|
|
|
it("forwards --no-strings with --locale preserving caller options", async () => {
|
|
const result = await invoke([
|
|
"decode-android-resources",
|
|
"/targets/app.apk",
|
|
"--no-strings",
|
|
"--locale",
|
|
"de",
|
|
"--json",
|
|
]);
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.requests).toEqual([
|
|
{
|
|
operation: "decode_android_resources",
|
|
input: {
|
|
path: "/targets/app.apk",
|
|
include_strings: false,
|
|
locale: "de",
|
|
},
|
|
},
|
|
]);
|
|
});
|