mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 13:12:26 +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
@@ -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