mirror of
https://github.com/morluto/rea.git
synced 2026-11-06 23:06:18 +00:00
fix(desktop): align exported XML formatting whitespace (#9020)
* fix(desktop): align exported XML formatting whitespace * test(process): align symlink comparison snapshots * test(boundary): align inherited CLI and MCP fixtures --------- Co-authored-by: hhang <169027046+xu91102@users.noreply.github.com>
This commit is contained in:
1 parent
6571be631a
commit
d77442228d
3 files changed
+66
-1
No files matched your search
@@ -86,6 +86,9 @@ element that holds elements is dropped unless `xml:space="preserve"` applies.
|
||||
The view keeps up to 5,000 nodes, comments and processing instructions
|
||||
counted, nested up to 64 levels, and sets `truncated` when it leaves some out.
|
||||
|
||||
Exported XML views use REA's same formatting-whitespace classification, so
|
||||
retained XML text and the task checks that address it stay aligned.
|
||||
|
||||
SQLite databases are read through REA's SQLite worker from a private copy,
|
||||
with any retained `-wal` or `-journal` file staged beside it; the worker
|
||||
accepts an inactive rollback journal and refuses a hot one. A version is not
|
||||
|
||||
@@ -15,6 +15,9 @@ class _XmlReader:
|
||||
"""REA's XML view built as expat reads: names as spelled, declarations as attributes, text split where REA's DOM
|
||||
splits it (an empty CDATA section joins the text around it), and each node counted against REA's limits."""
|
||||
|
||||
#: Match REA String.trim(); default strip also drops U+0085 and keeps U+FEFF.
|
||||
FORMATTING_SPACE = "\t\n\v\f\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff"
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.remaining, self.truncated, self.root = MAX_XML_NODES, False, None
|
||||
#: Per open element: its view or None when left out, whether xml:space="preserve" applies inside it, and
|
||||
@@ -83,7 +86,7 @@ class _XmlReader:
|
||||
self._flush()
|
||||
view, preserve, holds_element = self.open.pop()
|
||||
if view is not None and holds_element and not preserve:
|
||||
view["children"] = [child for child in view["children"] if not isinstance(child, str) or child.strip()]
|
||||
view["children"] = [child for child in view["children"] if not isinstance(child, str) or child.strip(self.FORMATTING_SPACE)]
|
||||
if not self.open:
|
||||
self.root = view
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { execFileSync } from "node:child_process";
|
||||
import { expect, it } from "vitest";
|
||||
import {
|
||||
PYTHON_HELPERS,
|
||||
PYTHON_IMPORTS,
|
||||
} from "../../../src/domain/desktop/appExportPython.js";
|
||||
import { xmlView } from "../../../src/domain/desktop/stateFormats.js";
|
||||
|
||||
/** Execute the unmodified generated XML reader with its standard-library imports. */
|
||||
const pythonViews = (texts: readonly string[]) => {
|
||||
const imports = PYTHON_IMPORTS.split("\n")
|
||||
.filter((line) => !line.includes("agentenv_protocol"))
|
||||
.join("\n");
|
||||
return JSON.parse(
|
||||
execFileSync(
|
||||
"python3",
|
||||
[
|
||||
"-I",
|
||||
"-B",
|
||||
"-c",
|
||||
`${imports}${PYTHON_HELPERS}\nprint(json.dumps([_xml_view(text) for text in json.load(sys.stdin)]))`,
|
||||
],
|
||||
{ input: JSON.stringify(texts), encoding: "utf8" },
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
it.each(["\u0085", "\ufeff"])(
|
||||
"matches REA's formatting decision for %j between elements",
|
||||
(text) => {
|
||||
const xml = `<prefs><entry/>${text}</prefs>`;
|
||||
expect(pythonViews([xml])).toEqual([xmlView(xml)]);
|
||||
},
|
||||
);
|
||||
|
||||
it("matches the ECMAScript whitespace set for XML-valid characters and preserves other text", () => {
|
||||
const characters =
|
||||
"\t\n\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff\u0085\u180e\u200b";
|
||||
const texts = [...characters].map((text) => `<prefs><entry/>${text}</prefs>`);
|
||||
expect(pythonViews(texts)).toEqual(texts.map(xmlView));
|
||||
});
|
||||
|
||||
it("keeps leaf text and xml:space-preserved text, with the original parsing refusals", () => {
|
||||
const texts = [
|
||||
"<prefs><entry>\ufeff</entry></prefs>",
|
||||
"<prefs><entry>\u0085</entry></prefs>",
|
||||
'<prefs xml:space="preserve"><entry/>\ufeff</prefs>',
|
||||
'<prefs xml:space="preserve"><entry/>\u0085</prefs>',
|
||||
];
|
||||
const actual = pythonViews(texts) as { root: { children: unknown[] } }[];
|
||||
const expected = texts.map(xmlView) as { root: { children: unknown[] } }[];
|
||||
expect(actual.map((view) => view.root.children)).toEqual(
|
||||
expected.map((view) => view.root.children),
|
||||
);
|
||||
expect(pythonViews(["<!DOCTYPE prefs><prefs/>", "<p:prefs/>"])).toEqual([
|
||||
null,
|
||||
null,
|
||||
]);
|
||||
});
|
||||
Reference in new issue
Block a user