Files
reverse-engineering-anything/tests/process-global/flutterCliCleanup.test.ts
Adolanium 996ab6e2ae fix(zip): bound the member count of a ZIP inventory (#14997)
* fix(limits): admit a ZIP member count on reader limits

artifact.member_count now resolves artifact_limits.zip.member_count. Recorded Evidence from before this group may omit zip.

* fix(zip): refuse a central directory past the member count

Count every central-directory record before retaining it. The refusal omits required_value because later records stay unread.

* test(zip): cover a central directory past the member count

Three empty members at a count of two refuse through the reader and through the zip format reader.

* docs(limits): name zip.member_count on the member-count setting

The existing REA_ARTIFACT_MEMBER_COUNT seed already supplies that default.

* test(artifacts): select the ZIP member count with the explicit fields

The acceptance case ignores an invalid artifact.member_count seed only when every backed field is selected. zip.member_count is one of those fields.

* fix(schemas): record the ZIP member-count input summaries

extract_artifact and inspect_artifact changed their input compact schema when zip.member_count was advertised.

* fix(zip): keep member count on Flutter, Playwright, and SAZ

Those readers omitted the session count and described the refusal as a byte budget. They now admit artifact.member_count and report the count.

* test(zip): cover member-count refusals outside artifact inventory

A two-member archive at a session count of one stays a count for Flutter, Playwright traces, and SAZ. One member still passes that cap.

* docs(limits): name the ZIP consumers of artifact.member_count

Flutter APK inventory, Playwright trace import, and SAZ decoding use the session count and report it as a count.

* fix(capture): read the fixed-limit boundary from the ceiling

CaptureFormatError keeps that boundary on ceiling. The SAZ reply read cause.boundary, so a fixed-limit reply omitted the field the parent requires.

* fix(limits): recover ZIP member count through the session setting

Flutter, Playwright, and SAZ have no artifact_limits argument. The refusal names artifact.member_count, leaves parameter unset, and tells the caller to raise that setting. sessionSettingConstraint owns the error next to the other resource refusals.

* fix(android): keep a partial JNI report at the ZIP member count

readAndroidJniLibraries already returns a partial inventory when its entry allowance stops the scan. The session member count is that same stop. The reader takes artifact.member_count, and the report names the unexamined remainder instead of aborting the inspection.

* fix(zip): resolve the member count from the selected environment

ZIP admission and its refusal use the launch environment selected for the runtime. Only SAZ sends that count to the capture decoder.

* fix(zip): drop the unused ZipReaderLimits export

Knip reports the type because no caller imports it. ZIP limits stay on the schema.

* fix(playwright): return an invalid member-count seed as a result

The trace catch uses the count captured before the failure. A configuration error stays a Result and keeps the archive hash.

* fix(jni): name the member count on a partial library scan

The partial report keeps the count that stopped the scan and the recovery for artifact.member_count.

* fix(settings): register artifact.member_count for its ZIP consumers

Scoped inspection of the Flutter, Playwright, capture, and JNI operations includes the setting.

* test(artifacts): parse Evidence that omits the audit-log policy

The merged reader-limit schema still accepts a record that omits the Kubernetes audit-log policy.
2026-11-29 13:08:56 -05:00

104 lines
3.6 KiB
TypeScript

import { createCommandCli } from "../support/cli/commandCli.js";
import { expect, it, onTestFinished, vi } from "vitest";
import { registerFlutterCommands } from "../../src/cli/flutterCommands.js";
import { aotFixtureImage } from "../../src/flutter/FlutterBuild.fixture.js";
import { FlutterBuildProvider } from "../../src/flutter/FlutterBuildProvider.js";
import { silentLogger } from "../../src/logger.js";
import {
interceptFlutterRootRemoval,
realRm,
} from "../fixtures/flutterCleanup.js";
import { createFlutterApk } from "../fixtures/flutterApk.js";
vi.mock("node:fs/promises", async (importOriginal) => {
const original = await importOriginal<typeof import("node:fs/promises")>();
return { ...original };
});
/** Serve one command whose first snapshot-root removal fails and is retried on close. */
const serveWithCleanupRetry = async (
command: string,
apk: string,
interrupt: boolean,
retryFails = false,
): Promise<Record<string, unknown>> => {
const inherited = new Set(process.listeners("SIGINT"));
const roots: string[] = [];
interceptFlutterRootRemoval(async (root) => {
roots.push(root);
if (roots.length > 2) return realRm(root, { recursive: true, force: true });
// Deliver SIGINT to the command's own listener during the retry.
if (roots.length === 2 && interrupt)
for (const listener of process.listeners("SIGINT"))
if (!inherited.has(listener)) listener("SIGINT");
if (roots.length === 1 || retryFails)
throw Object.assign(new Error("transient snapshot removal refusal"), {
code: "EACCES",
});
await realRm(root, { recursive: true, force: true });
});
const provider = new FlutterBuildProvider();
onTestFinished(() => provider.close());
const cli = createCommandCli();
registerFlutterCommands(cli, silentLogger, process.env, provider);
let stdout = "";
await cli.serve([command, apk, "--format", "json"], {
stdout: (text) => {
stdout += text;
},
exit: () => {},
});
expect(roots).toEqual([roots[0], roots[0]]);
return JSON.parse(stdout) as Record<string, unknown>;
};
it.each([
["identify-flutter-build", "identify_flutter_build"],
["inspect-dart-aot", "inspect_dart_aot"],
] as const)(
"%s reports SIGINT during the cleanup retry as cancellation with completed facts",
async (command, operation) => {
const apk = await createFlutterApk("cleanup-retry.apk", [
{ path: "lib/arm64-v8a/libapp.so", bytes: aotFixtureImage() },
]);
const exitCode = process.exitCode;
onTestFinished(() => {
process.exitCode = exitCode;
});
const control = await serveWithCleanupRetry(command, apk, false);
expect(control).toMatchObject({
operation,
confidence: "observed",
caller_input_path: apk,
});
expect(process.exitCode).toBe(exitCode);
const interrupted = await serveWithCleanupRetry(command, apk, true);
expect(process.exitCode).toBe(130);
expect(interrupted).toMatchObject({
code: "cancelled",
details: {
operation,
partial_observation: {
operation,
caller_input_path: apk,
subject: { local_path: apk },
confidence: "observed",
normalized_result: control.normalized_result,
},
},
});
const incomplete = await serveWithCleanupRetry(command, apk, true, true);
expect(incomplete).toMatchObject({
code: "cleanup_incomplete",
details: {
resources: [expect.stringContaining("rea-flutter-")],
partial_observation: {
operation,
caller_input_path: apk,
normalized_result: control.normalized_result,
},
},
});
},
);