mirror of
https://github.com/morluto/rea.git
synced 2026-11-30 10:27:42 +00:00
* feat(flutter)!: give Flutter APK admission per-call apk_limits identify_flutter_build and inspect_dart_aot refused a large but ordinary APK at seven fixed allowances (APK snapshot, ZIP metadata, library read, cumulative extraction, ABI count, library path and snapshot-hash candidates) with no recovery. They now accept apk_limits (CLI --apk-limits JSON) with today's values as defaults. Each refusal reports details.limit naming the apk_limits field, its effective value and range. The domain owns one bounds object that feeds both the schema and the reported limit. library_path_bytes is capped by the 16-bit ZIP name field, and the inspect_dart_aot ABI selector length now follows that maximum instead of the old 1 KiB default. BREAKING CHANGE: Flutter size, inventory and candidate refusals report details.limit instead of a fixed_ceiling refusal, and the inspect_dart_aot abi selector admits labels up to 65,521 characters. * fix(flutter): bound library_path_bytes by the decoded ZIP name size Inventory counts a library path's decoded UTF-8 bytes, and one stored byte decodes to at most three (a CP437 box-drawing character), so the maximum is three times the 16-bit stored name length rather than the stored length itself. The ABI selector keeps its character bound from the stored name. Recovery tests now assert the reported facts after raising a limit.
176 lines
5.2 KiB
TypeScript
176 lines
5.2 KiB
TypeScript
import { expect, it } from "vitest";
|
|
import { Ajv } from "ajv";
|
|
import type { AnySchema } from "ajv";
|
|
|
|
import { aotFixtureImage } from "../../../src/flutter/FlutterBuild.fixture.js";
|
|
import { flutterInputSchemas } from "../../../src/domain/flutter/flutterBuildAnalysis.js";
|
|
import { createFlutterApk } from "../../fixtures/flutterApk.js";
|
|
import { serveCli } from "./cliServeHarness.js";
|
|
|
|
it.each(["identify-flutter-build", "inspect-dart-aot"])(
|
|
"%s advertises a schema through the public CLI",
|
|
async (command) => {
|
|
const result = await serveCli([command, "--schema", "--json"]);
|
|
expect(result.exitCode).toBe(0);
|
|
expect(JSON.parse(result.stdout)).toBeTruthy();
|
|
},
|
|
);
|
|
|
|
it("reports an unreadable target with an input refusal", async () => {
|
|
const result = await serveCli([
|
|
"identify-flutter-build",
|
|
"/nonexistent/app.apk",
|
|
"--json",
|
|
]);
|
|
expect(result.stdout).toContain("invalid_request");
|
|
});
|
|
|
|
it.each(["identify-flutter-build", "inspect-dart-aot"])(
|
|
"%s uses canonical local-path validation before provider admission",
|
|
async (command) => {
|
|
const result = await serveCli([command, "fixture\u0000.apk", "--json"]);
|
|
expect(JSON.parse(result.stdout)).toMatchObject({
|
|
code: "VALIDATION_ERROR",
|
|
fieldErrors: [
|
|
expect.objectContaining({
|
|
path: "path",
|
|
message: expect.stringContaining("NUL"),
|
|
}),
|
|
],
|
|
});
|
|
},
|
|
);
|
|
|
|
it("advertises and validates one ABI selector grammar with field correction guidance", async () => {
|
|
const advertised = await serveCli(["inspect-dart-aot", "--schema", "--json"]);
|
|
expect(advertised.exitCode).toBe(0);
|
|
const schema = JSON.parse(advertised.stdout) as { options: AnySchema };
|
|
const ajv = new Ajv({ strict: false });
|
|
expect(ajv.validateSchema(schema.options)).toBe(true);
|
|
const accepts = ajv.compile(schema.options);
|
|
const abiSchema = flutterInputSchemas.inspect_dart_aot.shape.abi;
|
|
for (const abi of [
|
|
"ARM64-V8A",
|
|
"ARM64",
|
|
"arm64.v8a",
|
|
"A",
|
|
"a",
|
|
"abi\\label",
|
|
"abi\nlabel",
|
|
"l".repeat(65_521),
|
|
"😀".repeat(65_521),
|
|
]) {
|
|
expect(accepts({ abi })).toBe(true);
|
|
expect(abiSchema.safeParse(abi).success).toBe(true);
|
|
}
|
|
for (const abi of [
|
|
"",
|
|
"lib/x86_64",
|
|
"l".repeat(65_522),
|
|
"😀".repeat(65_522),
|
|
"l".repeat(65_521) + "\n",
|
|
]) {
|
|
expect(accepts({ abi })).toBe(false);
|
|
expect(abiSchema.safeParse(abi).success).toBe(false);
|
|
const rejected = await serveCli([
|
|
"inspect-dart-aot",
|
|
"/nonexistent/app.apk",
|
|
"--abi",
|
|
abi,
|
|
"--json",
|
|
]);
|
|
expect(JSON.parse(rejected.stdout)).toMatchObject({
|
|
code: "VALIDATION_ERROR",
|
|
fieldErrors: [
|
|
expect.objectContaining({
|
|
path: "abi",
|
|
message: expect.stringContaining("ABI"),
|
|
}),
|
|
],
|
|
});
|
|
}
|
|
});
|
|
|
|
it("inspects the caller-selected nonstandard ABI through the public CLI", async () => {
|
|
const path = await createFlutterApk("selector.apk", [
|
|
{ path: "lib/ARM64-V8A/libapp.so", bytes: aotFixtureImage("a".repeat(32)) },
|
|
{ path: "lib/x86_64/libapp.so", bytes: aotFixtureImage("b".repeat(32)) },
|
|
]);
|
|
const selected = await serveCli([
|
|
"inspect-dart-aot",
|
|
path,
|
|
"--abi",
|
|
"ARM64-V8A",
|
|
"--pool-policy",
|
|
'{"contains":"package:animations/","uri_limit":1}',
|
|
"--json",
|
|
]);
|
|
expect(selected.exitCode).toBe(0);
|
|
expect(JSON.parse(selected.stdout)).toMatchObject({
|
|
caller_input_path: path,
|
|
parameters: {
|
|
path,
|
|
abi: "ARM64-V8A",
|
|
pool_policy: { contains: "package:animations/", uri_limit: 1 },
|
|
},
|
|
normalized_result: {
|
|
abi: "ARM64-V8A",
|
|
string_pool: {
|
|
package_uris: ["package:animations/src/fade_scale_transition.dart"],
|
|
package_uri_count_at_least: 1,
|
|
policy: { uri_limit: 1, contains: "package:animations/" },
|
|
},
|
|
libapp: { snapshot_hash: "a".repeat(32), coverage: "complete" },
|
|
},
|
|
});
|
|
const invalid = await serveCli([
|
|
"inspect-dart-aot",
|
|
path,
|
|
"--pool-policy",
|
|
'{"uri_limit":0}',
|
|
"--json",
|
|
]);
|
|
expect(JSON.parse(invalid.stdout).code).toBe("VALIDATION_ERROR");
|
|
});
|
|
|
|
it("refuses at apk_limits.abi_count and recovers the same APK through the public CLI", async () => {
|
|
const path = await createFlutterApk("two-abis.apk", [
|
|
{ path: "lib/arm64-v8a/libapp.so", bytes: aotFixtureImage("a".repeat(32)) },
|
|
{ path: "lib/x86_64/libapp.so", bytes: aotFixtureImage("b".repeat(32)) },
|
|
]);
|
|
const refused = await serveCli([
|
|
"identify-flutter-build",
|
|
path,
|
|
"--apk-limits",
|
|
'{"abi_count":1}',
|
|
"--json",
|
|
]);
|
|
expect(JSON.parse(refused.stdout)).toMatchObject({
|
|
code: "resource_constraint",
|
|
retryable: false,
|
|
details: {
|
|
limit: {
|
|
control_kind: "parameter",
|
|
parameter: "apk_limits.abi_count",
|
|
effective_value: 1,
|
|
unit: "count",
|
|
minimum: 1,
|
|
maximum: 0x7fffffff,
|
|
default_value: 32,
|
|
applies_at: "next_call",
|
|
},
|
|
},
|
|
});
|
|
const recovered = await serveCli([
|
|
"identify-flutter-build",
|
|
path,
|
|
"--apk-limits",
|
|
'{"abi_count":2}',
|
|
"--json",
|
|
]);
|
|
expect(recovered.exitCode, recovered.stdout).toBe(0);
|
|
expect(JSON.parse(recovered.stdout)).toMatchObject({
|
|
parameters: { path, apk_limits: { abi_count: 2 } },
|
|
});
|
|
});
|