mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 21:23:45 +00:00
fix(desktop): share state and window admission with exported verifiers (#12154)
* fix(desktop): share state view admission with the exported verifier Refs #12133 * fix(desktop): share keyfile syntax with exported state readers Refs #12141 * fix(desktop): share X11 window property interpretation Refs #12140
This commit is contained in:
1 parent
461cedd73c
commit
0aee26def4
13 files changed
+534
-273
No files matched your search
@@ -29,7 +29,6 @@ import {
|
||||
} from "../../../src/domain/desktop/appExportPython.js";
|
||||
import {
|
||||
detectStateFormat,
|
||||
keyfileView,
|
||||
textSyntaxFormat,
|
||||
textualView,
|
||||
} from "../../../src/domain/desktop/stateFormats.js";
|
||||
@@ -447,7 +446,8 @@ windows = json.loads(${JSON.stringify(table)})
|
||||
if sys.argv[1:3] == ["-root", "_NET_CLIENT_LIST"]:
|
||||
print("_NET_CLIENT_LIST(WINDOW): window id # " + ", ".join(windows))
|
||||
else:
|
||||
print(windows[sys.argv[2]])
|
||||
window = sys.argv[2].lower()
|
||||
print(next((props for xid, props in windows.items() if xid.lower() == window), ""))
|
||||
`,
|
||||
);
|
||||
await chmod(join(bin, "xprop"), 0o755);
|
||||
@@ -501,6 +501,56 @@ it("holds readiness until a window of the app's class that the taskbar lists is
|
||||
).toBe("False");
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
"canonicalizes a hexadecimal window id",
|
||||
{ "0xA00007": 'WM_CLASS(STRING) = "editor", "ModelEditor"' },
|
||||
"ModelEditor",
|
||||
"True",
|
||||
],
|
||||
[
|
||||
"decodes an escaped class",
|
||||
{ "0x1": String.raw`WM_CLASS(STRING) = "editor", "Model\042Editor"` },
|
||||
'Model"Editor',
|
||||
"True",
|
||||
],
|
||||
[
|
||||
"requires the class field",
|
||||
{ "0x1": 'WM_CLASS(STRING) = "ModelEditor", "OtherApp"' },
|
||||
"ModelEditor",
|
||||
"False",
|
||||
],
|
||||
[
|
||||
"finds no class property",
|
||||
{ "0x1": "WM_CLASS: not found." },
|
||||
"ModelEditor",
|
||||
"False",
|
||||
],
|
||||
[
|
||||
"cannot decode the class property",
|
||||
{ "0x1": String.raw`WM_CLASS(STRING) = "editor", "Model\qEditor"` },
|
||||
"ModelEditor",
|
||||
"False",
|
||||
],
|
||||
[
|
||||
"observes a differently cased class",
|
||||
{ "0x1": 'WM_CLASS(STRING) = "editor", "modeleditor"' },
|
||||
"ModelEditor",
|
||||
"False",
|
||||
],
|
||||
[
|
||||
"reads splash markers from their own properties",
|
||||
{ "0x1": 'WM_CLASS(STRING) = "editor", "_NET_WM_STATE_SKIP_TASKBAR"' },
|
||||
"_NET_WM_STATE_SKIP_TASKBAR",
|
||||
"True",
|
||||
],
|
||||
])(
|
||||
"interprets X11 readiness when xprop %s",
|
||||
async (_, windows, class_, ready) => {
|
||||
expect(taskbarWindow(await fakeXprop(windows), class_)).toBe(ready);
|
||||
},
|
||||
);
|
||||
|
||||
/** The exported module's JSON verdict for each text, with only its standard library imports: its view or its error. */
|
||||
const pythonJson = (texts: readonly string[]) => {
|
||||
const imports = PYTHON_IMPORTS.split("\n")
|
||||
@@ -803,29 +853,43 @@ with sqlite3.connect(":memory:") as db:
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps the same keyfile whitespace as the retained state view", async () => {
|
||||
const inputs = [
|
||||
"[ui]\nsuffix=hello \nunicode=\u00a0hello\u00a0\npadded= hello\n",
|
||||
"[ui]\r\nsuffix=hello \r\nunicode=\u00a0hello\u00a0\u00a0\r\npadded=\thello\r\n",
|
||||
];
|
||||
const imports = PYTHON_IMPORTS.split("\n")
|
||||
.filter((line) => !line.includes("agentenv_protocol"))
|
||||
.join("\n");
|
||||
const program = `${imports}${PYTHON_HELPERS}
|
||||
print(json.dumps([_text_view("settings.ini", text, len(text.encode()))["view"]["groups"] for text in json.load(sys.stdin)]))
|
||||
`;
|
||||
const root = await createTestTempDirectory("rea-keyfile-python-");
|
||||
const script = join(root, "fixture.py");
|
||||
await writeFile(script, program, "utf8");
|
||||
const output = execFileSync(
|
||||
process.platform === "win32" ? "python" : "python3",
|
||||
["-I", "-B", "-X", "utf8", script],
|
||||
it("agrees on keyfile whitespace in both state readers", () => {
|
||||
const files = [
|
||||
["settings.ini", "[ui]\n\u0085\nzoom=2\n"],
|
||||
["settings.ini", "[ui]\n\ufeffzoom=2\n"],
|
||||
[
|
||||
"settings.ini",
|
||||
"[ui]\r\nsuffix=hello \r\nunicode=\u00a0hello\u00a0\u00a0\r\npadded=\thello\r\n",
|
||||
],
|
||||
] as const;
|
||||
const expected = [
|
||||
{
|
||||
input: JSON.stringify(inputs),
|
||||
encoding: "utf8",
|
||||
format: "text",
|
||||
view: {
|
||||
lines: ["[ui]", "\u0085", "zoom=2"],
|
||||
line_count: 3,
|
||||
truncated: false,
|
||||
},
|
||||
error: null,
|
||||
},
|
||||
);
|
||||
expect(JSON.parse(output)).toEqual(inputs.map(keyfileView));
|
||||
{ format: "keyfile", view: { groups: { ui: { zoom: "2" } } }, error: null },
|
||||
{
|
||||
format: "keyfile",
|
||||
view: {
|
||||
groups: {
|
||||
ui: {
|
||||
suffix: "hello ",
|
||||
unicode: "\u00a0hello\u00a0\u00a0",
|
||||
padded: "hello",
|
||||
},
|
||||
},
|
||||
},
|
||||
error: null,
|
||||
},
|
||||
];
|
||||
const { python, rea } = textViews(files);
|
||||
expect(rea).toEqual(expected);
|
||||
expect(python).toEqual(expected);
|
||||
});
|
||||
|
||||
const hasPydantic2 =
|
||||
|
||||
@@ -28,6 +28,7 @@ import {
|
||||
readerAnswerView,
|
||||
readerCommand,
|
||||
} from "../../../src/domain/desktop/appTaskReaders.js";
|
||||
import { appStateViews } from "../../../src/domain/desktop/appStateViews.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
/** The protocol client calls the verifier makes, replaced so it reads the given views. */
|
||||
@@ -109,7 +110,8 @@ async def get_data(url, **_):
|
||||
file=types.SimpleNamespace(bytes=base64.b64encode(
|
||||
(file_contents[path] if path in file_contents else json.dumps(view)).encode()).decode()))
|
||||
for path, view in views.items()]
|
||||
return types.SimpleNamespace(parts=[*files, types.SimpleNamespace(kind="data", data={"state": views})])
|
||||
state_parts = scenario.get("state_parts", [{"kind": "data", "data": {"state": views}}])
|
||||
return types.SimpleNamespace(parts=[*files, *(types.SimpleNamespace(**part) for part in state_parts)])
|
||||
|
||||
|
||||
async def sleep(seconds):
|
||||
@@ -205,6 +207,7 @@ const runVerifier = async (
|
||||
readonly answers?: Readonly<Record<string, unknown>>;
|
||||
readonly retryAnswers?: Readonly<Record<string, unknown>>;
|
||||
readonly fileContents?: Readonly<Record<string, string>>;
|
||||
readonly stateParts?: readonly Record<string, unknown>[];
|
||||
readonly exec?: boolean;
|
||||
readonly cleanupFailures?: number;
|
||||
readonly retry?: boolean;
|
||||
@@ -251,6 +254,7 @@ const runVerifier = async (
|
||||
answers: computer.answers,
|
||||
retry_answers: computer.retryAnswers,
|
||||
file_contents: computer.fileContents,
|
||||
state_parts: computer.stateParts,
|
||||
exec: computer.exec ?? true,
|
||||
cleanup_failures: computer.cleanupFailures,
|
||||
retry: computer.retry,
|
||||
@@ -285,6 +289,55 @@ const linesPresent = (...lines: string[]): DesktopTaskCheck => ({
|
||||
const graded = ({ results }: VerifierOutput) =>
|
||||
results.map(({ result, settled, read_cut }) => [result, settled, read_cut]);
|
||||
|
||||
it("grades the first valid state part with the same view admission as the host witness", async () => {
|
||||
const file = "Documents/today.txt";
|
||||
const checks: DesktopTaskCheck[] = [
|
||||
{ id: "present", kind: "file_present", file },
|
||||
linesPresent("milk"),
|
||||
];
|
||||
const statePart = (state: unknown) => ({ kind: "data", data: { state } });
|
||||
const malformed = [
|
||||
statePart({ [file]: { format: "text" } }),
|
||||
statePart({ [file]: { format: 7, view: null } }),
|
||||
statePart({ [file]: { format: "text", view: null, error: 7 } }),
|
||||
];
|
||||
const host = appStateViews([...malformed, statePart({})]);
|
||||
if (!host.ok) throw new Error(host.error);
|
||||
expect(
|
||||
evaluateTaskChecks(checks, host.value).map(({ passed }) => passed),
|
||||
).toEqual([false, false]);
|
||||
const empty = await runVerifier(checks, [[0, {}]], [], {
|
||||
stateParts: [...malformed, statePart({})],
|
||||
});
|
||||
expect(empty.results).toEqual([
|
||||
expect.objectContaining({ result: false }),
|
||||
expect.objectContaining({
|
||||
result: false,
|
||||
description: expect.stringContaining("has no line"),
|
||||
}),
|
||||
]);
|
||||
|
||||
const valid = [statePart(today("milk")), statePart({})];
|
||||
const first = await runVerifier(checks, [[0, {}]], [], { stateParts: valid });
|
||||
expect(first.results.map(({ result }) => result)).toEqual([true, true]);
|
||||
const unreadable = await runVerifier(checks, [[0, {}]], [], {
|
||||
stateParts: [
|
||||
statePart({ [file]: { format: null, view: null, error: "read failed" } }),
|
||||
statePart(today("milk")),
|
||||
],
|
||||
});
|
||||
expect(unreadable.results[1]).toMatchObject({
|
||||
result: false,
|
||||
description: expect.stringContaining("read failed"),
|
||||
});
|
||||
const invalid = await runVerifier(checks, [[0, {}]], [], {
|
||||
stateParts: [{ kind: "data", data: null }, ...malformed],
|
||||
reportFailure: true,
|
||||
});
|
||||
expect(invalid.results).toEqual([]);
|
||||
expect(invalid.first_error).toMatch(/returned no state views/u);
|
||||
});
|
||||
|
||||
it("evaluates every kind of file check without computer-exec as REA does", async () => {
|
||||
const checks: DesktopTaskCheck[] = CHECK_CASES.map(([check], index) => ({
|
||||
...check,
|
||||
|
||||
Reference in new issue
Block a user