mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 22:45:47 +00:00
fix(desktop): explain unavailable dconf descriptor paths (#13391)
This commit is contained in:
1 parent
de0679e2c0
commit
5b2bc6c43d
6 files changed
+135
-108
No files matched your search
@@ -5,7 +5,10 @@ import { expect, it } from "vitest";
|
||||
import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js";
|
||||
import { dumpDconfDatabase } from "../../desktop/DconfDatabaseReader.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { desktopApplicationStateSchema } from "../../domain/desktop/desktopState.js";
|
||||
import {
|
||||
desktopApplicationStateSchema,
|
||||
type DconfViewFailure,
|
||||
} from "../../domain/desktop/desktopState.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import { inspectDesktopApplicationState } from "./DesktopApplicationState.js";
|
||||
import {
|
||||
@@ -37,9 +40,10 @@ const dconfCapture = async () => {
|
||||
);
|
||||
};
|
||||
|
||||
const expectLaunchRefusal = (
|
||||
const expectReadRefusal = (
|
||||
evidence: Evidence | AnalysisError,
|
||||
command: string,
|
||||
failure: DconfViewFailure,
|
||||
error: string | ReturnType<typeof expect.stringMatching>,
|
||||
) => {
|
||||
if (!("normalized_result" in evidence)) throw evidence;
|
||||
const state = desktopApplicationStateSchema.parse(evidence.normalized_result);
|
||||
@@ -50,35 +54,39 @@ const expectLaunchRefusal = (
|
||||
expect.objectContaining({
|
||||
format: "dconf",
|
||||
view: null,
|
||||
view_failure: {
|
||||
kind: "launch-failed",
|
||||
code: "EACCES",
|
||||
exit_code: null,
|
||||
command,
|
||||
stderr: null,
|
||||
},
|
||||
view_error: error,
|
||||
view_failure: failure,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
};
|
||||
|
||||
it("carries a classified dconf failure into state Evidence", async () => {
|
||||
const command = "/selected/dconf";
|
||||
it("carries an unavailable descriptor into state Evidence with no empty view", async () => {
|
||||
const folder = await dconfCapture();
|
||||
const evidence = await inspectDesktopApplicationState(folder, {
|
||||
...readers,
|
||||
dconf: async () => ({
|
||||
ok: false,
|
||||
error: "execution denied",
|
||||
kind: "launch-failed",
|
||||
code: "EACCES",
|
||||
error: "descriptor path unavailable",
|
||||
kind: "descriptor-unavailable",
|
||||
code: "ENOENT",
|
||||
exitCode: null,
|
||||
command,
|
||||
command: null,
|
||||
stderr: null,
|
||||
}),
|
||||
});
|
||||
expectLaunchRefusal(evidence, command);
|
||||
expectReadRefusal(
|
||||
evidence,
|
||||
{
|
||||
kind: "descriptor-unavailable",
|
||||
code: "ENOENT",
|
||||
exit_code: null,
|
||||
command: null,
|
||||
stderr: null,
|
||||
},
|
||||
"descriptor path unavailable",
|
||||
);
|
||||
});
|
||||
|
||||
it.skipIf(process.platform !== "linux")(
|
||||
@@ -93,6 +101,16 @@ it.skipIf(process.platform !== "linux")(
|
||||
dconf: (database, signal) =>
|
||||
dumpDconfDatabase(database, { REA_DCONF_COMMAND: command }, signal),
|
||||
});
|
||||
expectLaunchRefusal(evidence, command);
|
||||
expectReadRefusal(
|
||||
evidence,
|
||||
{
|
||||
kind: "launch-failed",
|
||||
code: "EACCES",
|
||||
exit_code: null,
|
||||
command,
|
||||
stderr: null,
|
||||
},
|
||||
expect.stringMatching(/\S/u),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -140,58 +140,49 @@ it.skipIf(process.platform !== "linux").each([false, true])(
|
||||
);
|
||||
|
||||
describe.skipIf(process.platform !== "linux")("dumpDconfDatabase", () => {
|
||||
it.each(["ordinary", "hash#stage", "line\nbreak"])(
|
||||
"binds the selected descriptor without changing the launch directory: %s",
|
||||
async (name) => {
|
||||
const tools = await createTestTempDirectory("dconf-tool-");
|
||||
const command = join(tools, "dconf");
|
||||
it.each([
|
||||
{ directory: "ordinary", name: "user" },
|
||||
{ directory: "hash#stage", name: "user\nother" },
|
||||
{ directory: "line\nbreak", name: "user#other" },
|
||||
{ directory: "ordinary", name: "user " },
|
||||
])(
|
||||
"binds the selected descriptor for $directory and $name",
|
||||
async ({ directory, name }) => {
|
||||
const root = await createTestTempDirectory("dconf-staged-");
|
||||
const staged = join(root, directory);
|
||||
const database = join(staged, name);
|
||||
await mkdir(staged);
|
||||
await writeFile(database, "selected GVariant bytes");
|
||||
await writeFile(join(staged, "decoy"), "other bytes");
|
||||
const command = join(root, "reader");
|
||||
await writeFile(
|
||||
command,
|
||||
'#!/bin/sh\nprintf "%s\\n" "$PWD"\ncat "$DCONF_PROFILE"\n',
|
||||
{
|
||||
mode: 0o755,
|
||||
},
|
||||
[
|
||||
`#!${process.execPath}`,
|
||||
'const fs = require("node:fs");',
|
||||
'const profile = fs.readFileSync(process.env.DCONF_PROFILE, "utf8");',
|
||||
'const bytes = fs.readFileSync(profile.trimEnd().slice("file-db:".length), "utf8");',
|
||||
"console.log(JSON.stringify({ cwd: process.cwd(), profile, bytes }));",
|
||||
].join("\n"),
|
||||
{ mode: 0o755 },
|
||||
);
|
||||
const staged = join(await createTestTempDirectory("dconf-staged-"), name);
|
||||
await mkdir(staged);
|
||||
const database = join(staged, "user");
|
||||
await writeFile(database, "GVariant");
|
||||
|
||||
const dump = await dumpDconfDatabase(database, {
|
||||
PATH: process.env.PATH,
|
||||
REA_DCONF_COMMAND: command,
|
||||
});
|
||||
|
||||
expect(dump.ok).toBe(true);
|
||||
if (!dump.ok) throw new Error(dump.error);
|
||||
expect(dump.text.split("\n")).toEqual([
|
||||
process.cwd(),
|
||||
expect.stringMatching(
|
||||
new RegExp(`^file-db:/proc/${process.pid}/fd/\\d+$`),
|
||||
expect(JSON.parse(dump.text)).toEqual({
|
||||
cwd: process.cwd(),
|
||||
profile: expect.stringMatching(
|
||||
new RegExp(`^file-db:/proc/${process.pid}/fd/\\d+\n$`),
|
||||
),
|
||||
"",
|
||||
bytes: "selected GVariant bytes",
|
||||
});
|
||||
expect((await readdir(staged)).sort()).toEqual([
|
||||
"decoy",
|
||||
"profile",
|
||||
name,
|
||||
]);
|
||||
expect((await readdir(staged)).sort()).toEqual(["profile", "user"]);
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["user#other", "user\nother", "user "])(
|
||||
"keeps profile metacharacters out of the selected descriptor: %j",
|
||||
async (name) => {
|
||||
const staged = await createTestTempDirectory("dconf-profile-name-");
|
||||
await writeFile(join(staged, name), "GVariant");
|
||||
const command = join(staged, "reader");
|
||||
await writeFile(
|
||||
command,
|
||||
`#!${process.execPath}\nconst fs = require("node:fs"); const profile = fs.readFileSync(process.env.DCONF_PROFILE, "utf8"); process.stdout.write(fs.readFileSync(profile.trim().slice("file-db:".length)));\n`,
|
||||
{ mode: 0o755 },
|
||||
);
|
||||
expect(
|
||||
await dumpDconfDatabase(join(staged, name), {
|
||||
PATH: process.env.PATH,
|
||||
REA_DCONF_COMMAND: command,
|
||||
}),
|
||||
).toEqual({ ok: true, text: "GVariant" });
|
||||
},
|
||||
);
|
||||
|
||||
@@ -322,27 +313,7 @@ describe.skipIf(process.platform !== "linux")(
|
||||
});
|
||||
});
|
||||
|
||||
it("retains the selected command and errno when execution is denied", async () => {
|
||||
const root = await createTestTempDirectory("dconf-denied-command-");
|
||||
const command = join(root, "dconf");
|
||||
await writeFile(command, "#!/bin/sh\nexit 17\n", { mode: 0o600 });
|
||||
|
||||
await writeFile(join(root, "user"), "GVariant");
|
||||
const dump = await dumpDconfDatabase(join(root, "user"), {
|
||||
REA_DCONF_COMMAND: command,
|
||||
});
|
||||
|
||||
expect(dump).toMatchObject({
|
||||
ok: false,
|
||||
kind: "launch-failed",
|
||||
code: "EACCES",
|
||||
exitCode: null,
|
||||
command,
|
||||
stderr: null,
|
||||
});
|
||||
});
|
||||
|
||||
it.each(["", " \t\n", "reader refused the database\n"])(
|
||||
it.each([" \t\n", " reader refused the database\n"])(
|
||||
"retains a nonzero command's reason with stderr %j",
|
||||
async (stderr) => {
|
||||
const root = await createTestTempDirectory("dconf-command-exit-");
|
||||
@@ -367,6 +338,7 @@ describe.skipIf(process.platform !== "linux")(
|
||||
exitCode: 17,
|
||||
command,
|
||||
stderr: stderr.trim() === "" ? null : stderr.trim(),
|
||||
error: stderr.trim() || `Command failed: ${command} dump / (exit 17)`,
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -630,27 +602,33 @@ it.skipIf(process.platform !== "linux")(
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform !== "linux")(
|
||||
"refuses unavailable descriptor paths instead of reporting an empty database",
|
||||
async () => {
|
||||
const root = await createTestTempDirectory("dconf-no-fd-path-");
|
||||
const database = join(root, "user");
|
||||
await writeFile(database, "GVariant");
|
||||
closeFault.missingDescriptorPath = true;
|
||||
expect(
|
||||
await dumpDconfDatabase(database, {
|
||||
REA_DCONF_COMMAND: "/must-not-start-with-unavailable-descriptor-paths",
|
||||
}),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
kind: "descriptor-unavailable",
|
||||
code: "ENOENT",
|
||||
exitCode: null,
|
||||
command: null,
|
||||
stderr: null,
|
||||
});
|
||||
},
|
||||
);
|
||||
it("refuses unavailable descriptor paths instead of reporting an empty database", async () => {
|
||||
const root = await createTestTempDirectory("dconf-no-fd-path-");
|
||||
const database = join(root, "user");
|
||||
await writeFile(database, "GVariant");
|
||||
closeFault.missingDescriptorPath = true;
|
||||
closeFault.path = database;
|
||||
const launch = vi.spyOn(providerProcess, "spawnOwnedProviderProcess");
|
||||
expect(
|
||||
await dumpDconfDatabase(database, {
|
||||
REA_DCONF_COMMAND: "/must-not-start-with-unavailable-descriptor-paths",
|
||||
}),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
kind: "descriptor-unavailable",
|
||||
code: "ENOENT",
|
||||
exitCode: null,
|
||||
command: null,
|
||||
stderr: null,
|
||||
});
|
||||
expect(launch).not.toHaveBeenCalled();
|
||||
expect(await readdir(root)).toEqual(["user"]);
|
||||
expect(closeFault.handles).toHaveLength(1);
|
||||
const [handle] = closeFault.handles;
|
||||
if (handle === undefined)
|
||||
throw new Error("Expected an owned database descriptor");
|
||||
await expect(handle.stat()).rejects.toMatchObject({ code: "EBADF" });
|
||||
});
|
||||
|
||||
it.skipIf(process.platform !== "linux")(
|
||||
"retains a physical profile write failure",
|
||||
|
||||
@@ -277,7 +277,7 @@ export const unreadDconfLimitation = (
|
||||
return version?.present === true &&
|
||||
version.checkpoint_index > 0 &&
|
||||
version.view_error !== null
|
||||
? [{ home, error: version.view_error }]
|
||||
? [{ home, error: version.view_error, kind: version.view_failure?.kind }]
|
||||
: [];
|
||||
});
|
||||
if (unread.length === 0) return undefined;
|
||||
@@ -286,7 +286,14 @@ export const unreadDconfLimitation = (
|
||||
false,
|
||||
);
|
||||
const errors = [...new Set(unread.map(({ error }) => error))].join("; ");
|
||||
return `${names} changed by the seed checkpoint but could not be read (${errors}), so the app's settings stored in dconf, if any, are not seeded. Export where dconf-cli is installed, or with REA_DCONF_COMMAND naming dconf; a build computer installs it, so capture again on a new one.`;
|
||||
const recovery = new Set(
|
||||
unread.map(({ kind }) =>
|
||||
kind === "descriptor-unavailable"
|
||||
? "Export on Linux with readable /proc file descriptors to recover these settings."
|
||||
: "Export where dconf-cli is installed, or with REA_DCONF_COMMAND naming dconf; a build computer installs it, so capture again on a new one.",
|
||||
),
|
||||
);
|
||||
return `${names} changed by the seed checkpoint but could not be read (${errors}), so the app's settings stored in dconf, if any, are not seeded. ${[...recovery].join(" ")}`;
|
||||
};
|
||||
|
||||
/** Files in the desktop Trash at the seed, which the state view never makes the app's, so the seed leaves them out. */
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
writeCaptureFolder,
|
||||
} from "../../../src/application/desktop/desktopCapture.fixture.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import { hasReadableProcDescriptor } from "../../fixtures/desktopDconfHost.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
import { cliTest } from "../../support/cli/cliFixture.js";
|
||||
import { serveCli as serve } from "./cliServeHarness.js";
|
||||
@@ -250,8 +251,14 @@ it("names a dconf database that changed by the seed but could not be read, so th
|
||||
"changed by the seed checkpoint but could not be read",
|
||||
),
|
||||
]);
|
||||
if (process.platform === "linux")
|
||||
if (await hasReadableProcDescriptor())
|
||||
expect(unread[0]).toContain("dconf is not installed (dconf-cli)");
|
||||
else {
|
||||
expect(unread[0]).toContain(
|
||||
"Export on Linux with readable /proc file descriptors",
|
||||
);
|
||||
expect(unread[0]).not.toContain("where dconf-cli is installed");
|
||||
}
|
||||
expect(
|
||||
await readFile(join(root, "bundle/envs/notes/notes_app.py"), "utf8"),
|
||||
).toContain('DCONF = ""');
|
||||
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
VALID_BUILD_SCREENSHOT,
|
||||
} from "../../fixtures/buildScreenshotData.js";
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { hasReadableProcDescriptor } from "../../fixtures/desktopDconfHost.js";
|
||||
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
||||
|
||||
const files = async (root: string, prefix = ""): Promise<string[]> =>
|
||||
@@ -328,7 +329,7 @@ it("returns a draft note's read error when only a dconf database REA cannot read
|
||||
),
|
||||
},
|
||||
};
|
||||
// The draft runs with no dconf on its PATH, so it cannot read the database; the note never gets eggs, so the export refuses the task.
|
||||
// The subprocess has no dconf command on Linux and no descriptor path on other hosts.
|
||||
const { client } = await fakes({
|
||||
recorded,
|
||||
extraContent: [before, after],
|
||||
@@ -349,8 +350,10 @@ it("returns a draft note's read error when only a dconf database REA cannot read
|
||||
{
|
||||
code: "unreadable_changes",
|
||||
message: expect.any(String),
|
||||
files: [{ file: ".config/dconf/user", role: expect.any(String) }],
|
||||
error: "dconf is not installed (dconf-cli); set REA_DCONF_COMMAND",
|
||||
files: [{ file: ".config/dconf/user", role: "shared_desktop" }],
|
||||
error: (await hasReadableProcDescriptor())
|
||||
? "dconf is not installed (dconf-cli); set REA_DCONF_COMMAND"
|
||||
: expect.stringContaining("/proc/"),
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
import { open, stat } from "node:fs/promises";
|
||||
|
||||
/** Probe the host prerequisite separately from the dconf reader under test. */
|
||||
export const hasReadableProcDescriptor = async (): Promise<boolean> => {
|
||||
const handle = await open(new URL(import.meta.url), "r");
|
||||
try {
|
||||
await stat(`/proc/${process.pid}/fd/${handle.fd}`);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
} finally {
|
||||
await handle.close();
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user