Files
reverse-engineering-anything/src/adb/AdbShellOutput.test.ts
T
Yankı Küçük bef3fbbc6e fix(adb): keep a bare numeric wm density as the physical density (#4074)
Older Android builds print `wm density` as a bare number. The parser's
documentation named that form, but only the labeled `Physical density:`
and `Override density:` lines were matched, so a bare `420` left
`physical_density` null in successful display Evidence with no limitation
saying the declaration was unread (#3942).

The parser now reads the first bare numeric line as the physical density
when no labeled physical declaration is present; a labeled declaration
still wins so a mixed dump cannot downgrade the value. Override density
and physical size are unchanged.

Validation: parser unit tests for the labeled, bare, CRLF, mixed and
unrecognized forms, plus a provider-level regression through the
inspect_adb_display operation; two of them fail on main and pass here.
The issue's three CLI controls through `rea inspect-adb-display` against
a stub adb return physical density 420 for the bare form and keep the
labeled and override controls. Typecheck, lint and module boundaries pass.

Closes #3942
2026-10-17 00:15:05 +08:00

119 lines
3.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { parseAmStartOutput, parseWmDensityOutput } from "./AdbShellOutput.js";
describe("parseWmDensityOutput", () => {
it("reads labeled physical and override densities", () => {
expect(
parseWmDensityOutput("Physical density: 420\nOverride density: 480\n"),
).toEqual({ physical: 420, override: 480 });
expect(parseWmDensityOutput("Physical density: 420\n")).toEqual({
physical: 420,
override: null,
});
});
// Older builds print the physical density as a bare number
// (morluto/rea#3942); it must not be lost as an unread declaration.
it("reads a bare numeric density as the physical density", () => {
expect(parseWmDensityOutput("420\n")).toEqual({
physical: 420,
override: null,
});
expect(parseWmDensityOutput("420\r\n")).toEqual({
physical: 420,
override: null,
});
});
it("prefers a labeled physical density over a bare number", () => {
expect(parseWmDensityOutput("560\nPhysical density: 420\n")).toEqual({
physical: 420,
override: null,
});
});
it("reports no density for unrecognized output", () => {
expect(parseWmDensityOutput("")).toEqual({
physical: null,
override: null,
});
expect(parseWmDensityOutput("420dpi\n")).toEqual({
physical: null,
override: null,
});
});
});
const starting =
"Starting: Intent { act=android.intent.action.MAIN cmp=com.example/.Main }";
describe("parseAmStartOutput", () => {
it("recognizes a CRLF wait-timeout report", () => {
expect(
parseAmStartOutput(
`${starting}\r\nStatus: timeout\r\nActivity: com.example/.Main\r\nComplete\r\n`,
),
).toMatchObject({
status: "refused",
activity: "com.example/.Main",
reportedStatus: "timeout",
reason: "am start reported status: timeout",
});
});
it("treats every non-ok status as refusal, including a later status after ok", () => {
expect(
parseAmStartOutput(`${starting}\nStatus: ok\nStatus: timeout\n`),
).toMatchObject({
status: "refused",
reportedStatus: "timeout",
reason: "am start reported status: timeout",
});
expect(
parseAmStartOutput(`${starting}\nStatus: future-value\n`),
).toMatchObject({
status: "refused",
reportedStatus: "future-value",
});
});
it("gives hard errors in either stream priority over status and attempt", () => {
expect(
parseAmStartOutput(
`${starting}\nStatus: timeout\nActivity: com.example/.Main\n`,
"Exception: Activity class does not exist\n",
),
).toEqual({
status: "refused",
startedActivity: "act=android.intent.action.MAIN cmp=com.example/.Main",
activity: "com.example/.Main",
reportedStatus: "timeout",
reason: "Activity class does not exist",
});
expect(
parseAmStartOutput(
`${starting}\nStatus: ok\nError: Activity class does not exist\n`,
),
).toMatchObject({
status: "refused",
reason: "Activity class does not exist",
});
});
it("keeps Starting-only output compatible and refuses no-attempt output", () => {
expect(parseAmStartOutput(starting)).toMatchObject({
status: "started",
reportedStatus: null,
activity: null,
});
expect(
parseAmStartOutput("Status: ok\nWarning: Activity not started\n"),
).toMatchObject({
status: "refused",
startedActivity: null,
reportedStatus: "ok",
});
});
});