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:
morluto authored and GitHub committed 2026-11-18 22:01:30 -05:00
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 =