fix(native)!: preserve incomplete native UI captures (#991)
* fix(native): preserve unknown accessibility child counts * fix(native): align helper buffer with capture budget * fix(native): align Swift helper JSON wire size * fix(native): bound raw helper output to scenario budget
This commit is contained in:
@@ -5,6 +5,7 @@ import { fileURLToPath } from "node:url";
|
||||
import { execFileOutput } from "../process/ExecFileOutput.js";
|
||||
import { safeParseJson } from "../domain/safeJson.js";
|
||||
import type { NativeUiHelper } from "./NativeUiObservation.js";
|
||||
import { NATIVE_UI_HELPER_MAX_BUFFER } from "./NativeUiOutputBudget.js";
|
||||
|
||||
/** Lazily compile one owned helper per observation/scenario and remove its compiler cache. */
|
||||
export const createNativeUiHelperRuntime = () => {
|
||||
@@ -50,7 +51,7 @@ export const createNativeUiHelperRuntime = () => {
|
||||
[JSON.stringify(parameters)],
|
||||
{
|
||||
timeout: 30_000,
|
||||
maxBuffer: 16 * 1024 * 1024,
|
||||
maxBuffer: NATIVE_UI_HELPER_MAX_BUFFER,
|
||||
...(signal === undefined ? {} : { signal }),
|
||||
},
|
||||
);
|
||||
|
||||
@@ -111,6 +111,37 @@ describe("native UI screenshot validation", () => {
|
||||
);
|
||||
expect(result.ok).toBe(true);
|
||||
});
|
||||
|
||||
it("preserves an unknown AX child count and its truncation gap", async () => {
|
||||
const partial = {
|
||||
...snapshot,
|
||||
nodes: [
|
||||
{
|
||||
path: [],
|
||||
role: "AXWindow",
|
||||
title: "Fixture",
|
||||
value: null,
|
||||
actions: [],
|
||||
children_count: null,
|
||||
},
|
||||
],
|
||||
truncated: true,
|
||||
gaps: ["AX child count unavailable at path []: AXError -25204"],
|
||||
};
|
||||
const result = await observeNativeUi(
|
||||
target,
|
||||
"observe_native_ui",
|
||||
{ ...scope, accessibility: true },
|
||||
{ invoke: async () => ({ ok: true, result: partial }) },
|
||||
);
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok)
|
||||
expect(result.value.initial).toMatchObject({
|
||||
truncated: true,
|
||||
gaps: ["AX child count unavailable at path []: AXError -25204"],
|
||||
nodes: [{ children_count: null }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("native UI capture selection and budgets", () => {
|
||||
@@ -205,6 +236,27 @@ describe("native UI capture selection and budgets", () => {
|
||||
outcome: "cancelled",
|
||||
});
|
||||
});
|
||||
it("reports aggregate output exhaustion after individually valid captures", async () => {
|
||||
const largeSnapshot = {
|
||||
...snapshot,
|
||||
window: { ...snapshot.window, title: "x".repeat(17 * 1024 * 1024) },
|
||||
};
|
||||
const result = await observeNativeUi(
|
||||
target,
|
||||
"capture_native_ui_scenario",
|
||||
{
|
||||
...scope,
|
||||
steps: [{ kind: "wait", milliseconds: 0 }],
|
||||
},
|
||||
{ invoke: async () => ({ ok: true, result: largeSnapshot }) },
|
||||
);
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok)
|
||||
expect(result.value.steps[0]).toMatchObject({
|
||||
outcome: "failed",
|
||||
reason: expect.stringContaining("64 MiB output budget"),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("native UI target and cancellation failures", () => {
|
||||
|
||||
@@ -16,6 +16,10 @@ import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
import { type AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { err, ok, type Result } from "../domain/result.js";
|
||||
import { createNativeUiHelperRuntime } from "./NativeUiHelperRuntime.js";
|
||||
import {
|
||||
NATIVE_UI_OUTPUT_BUDGET_BYTES,
|
||||
NATIVE_UI_OUTPUT_WEIGHT,
|
||||
} from "./NativeUiOutputBudget.js";
|
||||
|
||||
const helper = fileURLToPath(
|
||||
new URL("../../bridge/native/ReaNativeUI.swift", import.meta.url),
|
||||
@@ -135,8 +139,10 @@ const observeWithHelper = async (
|
||||
),
|
||||
);
|
||||
launchTime = response.result.window.launch_time;
|
||||
outputBytes += 2 * Buffer.byteLength(JSON.stringify(response.result));
|
||||
if (outputBytes > 64 * 1024 * 1024)
|
||||
outputBytes +=
|
||||
NATIVE_UI_OUTPUT_WEIGHT *
|
||||
Buffer.byteLength(JSON.stringify(response.result));
|
||||
if (outputBytes > NATIVE_UI_OUTPUT_BUDGET_BYTES)
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"native-macos",
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
const HELPER_SUCCESS_WRAPPER = Buffer.from(
|
||||
JSON.stringify({ ok: true, result: {} }),
|
||||
);
|
||||
|
||||
/** Scenario output is charged at twice the encoded result size before return. */
|
||||
export const NATIVE_UI_OUTPUT_BUDGET_BYTES = 64 * 1024 * 1024;
|
||||
export const NATIVE_UI_OUTPUT_WEIGHT = 2;
|
||||
|
||||
/** Bytes added around a result by the helper's success JSON response. */
|
||||
export const NATIVE_UI_HELPER_ENVELOPE_BYTES =
|
||||
HELPER_SUCCESS_WRAPPER.byteLength - Buffer.byteLength("{}");
|
||||
|
||||
/** Raw helper output is bounded by the scenario's existing unweighted byte budget. */
|
||||
export const NATIVE_UI_HELPER_MAX_BUFFER =
|
||||
NATIVE_UI_OUTPUT_BUDGET_BYTES + NATIVE_UI_HELPER_ENVELOPE_BYTES;
|
||||
Reference in New Issue
Block a user