chore: sync current main into the CI baseline repair
Validate the formatting and reconstruction fixture repairs against the latest merged feature and correctness changes. Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
@@ -810,7 +810,6 @@ describe("web source-map sourcesContent validation", () => {
|
||||
it.each([
|
||||
["a scalar sourcesContent value", { sourcesContent: "source" }],
|
||||
["a non-string, non-null source entry", { sourcesContent: [42] }],
|
||||
["a sourcesContent array with the wrong length", { sourcesContent: [] }],
|
||||
])("reports %s as invalid", async (_description, content) => {
|
||||
const result = await fetchWebSourceMaps([request], input(), undefined, {
|
||||
fetch: () =>
|
||||
@@ -841,6 +840,50 @@ describe("web source-map sourcesContent validation", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
["shorter", ["import './a.ts';"]],
|
||||
["longer", ["import './a.ts';", null, "unused trailing content"]],
|
||||
])(
|
||||
"keeps every source declaration when sourcesContent is %s than sources",
|
||||
async (_length, sourcesContent) => {
|
||||
const result = await fetchWebSourceMaps([request], input(), undefined, {
|
||||
fetch: () =>
|
||||
Promise.resolve(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
version: 3,
|
||||
sources: ["a.ts", "b.ts"],
|
||||
sourcesContent,
|
||||
names: [],
|
||||
mappings: "",
|
||||
}),
|
||||
{ status: 200 },
|
||||
),
|
||||
),
|
||||
});
|
||||
|
||||
expect(result.items[0]).toMatchObject({
|
||||
status: "included",
|
||||
limitation: null,
|
||||
original_sources: [
|
||||
{
|
||||
source_index: 0,
|
||||
declaration_index: 0,
|
||||
source: `${origin}/assets/a.ts`,
|
||||
artifact: { text: "import './a.ts';" },
|
||||
},
|
||||
{
|
||||
source_index: 1,
|
||||
declaration_index: 1,
|
||||
source: `${origin}/assets/b.ts`,
|
||||
artifact: null,
|
||||
},
|
||||
],
|
||||
});
|
||||
expect(result.items[0]?.original_sources).toHaveLength(2);
|
||||
},
|
||||
);
|
||||
|
||||
it("accepts null source-map source contents", async () => {
|
||||
const result = await fetchWebSourceMaps([request], input(), undefined, {
|
||||
fetch: () =>
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
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",
|
||||
] 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("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([]);
|
||||
});
|
||||
@@ -135,7 +135,6 @@ it("retains every source declared by every included local source map", async ()
|
||||
it.each([
|
||||
["a non-array sourcesContent value", { sourcesContent: "source" }],
|
||||
["a non-string, non-null source entry", { sourcesContent: [42] }],
|
||||
["a source-content array with the wrong length", { sourcesContent: [] }],
|
||||
])(
|
||||
"reports %s as an invalid local source map",
|
||||
async (_description, content) => {
|
||||
@@ -210,6 +209,51 @@ it("accepts omitted and explicitly null source-map source contents", async () =>
|
||||
expect(result.graph.coverage.status).toBe("complete");
|
||||
});
|
||||
|
||||
it.each([
|
||||
["shorter", ["export const answer = 42;"]],
|
||||
["longer", ["export const answer = 42;", null, "unused trailing content"]],
|
||||
])(
|
||||
"keeps every source declaration when sourcesContent is %s than sources",
|
||||
async (length, sourcesContent) => {
|
||||
const root = await createTestTempDirectory(
|
||||
`rea-javascript-${length}-source-content-`,
|
||||
);
|
||||
await writeFile(
|
||||
join(root, "bundle.js.map"),
|
||||
JSON.stringify({
|
||||
version: 3,
|
||||
sources: ["a.ts", "b.ts"],
|
||||
sourcesContent,
|
||||
names: [],
|
||||
mappings: "AAAA;ACAA",
|
||||
}),
|
||||
);
|
||||
|
||||
const result = await reconstructJavaScriptArtifact({ input_path: root });
|
||||
const originals = result.graph.nodes.filter(
|
||||
({ identity }) => identity.strategy === "source-map-original",
|
||||
);
|
||||
|
||||
expect(
|
||||
originals
|
||||
.map(({ identity, observations }) => ({
|
||||
original_source:
|
||||
"original_source" in identity ? identity.original_source : null,
|
||||
source_index: observations[0]?.properties.source_index,
|
||||
content_available: observations[0]?.properties.content_available,
|
||||
}))
|
||||
.sort(
|
||||
(left, right) =>
|
||||
Number(left.source_index) - Number(right.source_index),
|
||||
),
|
||||
).toEqual([
|
||||
{ original_source: "a.ts", source_index: 0, content_available: true },
|
||||
{ original_source: "b.ts", source_index: 1, content_available: false },
|
||||
]);
|
||||
expect(result.graph.coverage.status).toBe("complete");
|
||||
},
|
||||
);
|
||||
|
||||
it("retains unnamed source declarations without shifting later source evidence", async () => {
|
||||
const root = await createTestTempDirectory("rea-javascript-unnamed-source-");
|
||||
const text = JSON.stringify({
|
||||
|
||||
Reference in New Issue
Block a user