Skip to content

Commit f722f9e

Browse files
donjor-agent[bot]donjor
authored andcommitted
fix(desktop): an explicit basic password store keeps saved environments (#1531)
## Problem On a Linux host with no keyring, the desktop app cannot keep a remote environment pairing. 1. `--password-store=basic` is honoured 2. Electron reports encryption unavailable 3. The connection catalog skips the write 4. The next launch needs a new pairing ## Change An explicit `--password-store=basic` calls `safeStorage.setUsePlainTextEncryption(true)` before `ready`. Electron then uses its built-in `basic_text` key: obfuscation only, opted into by the flag. ```sh t3code --password-store=basic ``` Auto mode, keyring backends, macOS, and Windows are unchanged. ## Scope and approval Requested by the maintainer for a keyring-less cloud agent host that must run the Electron app. The upstream test gains only a `safeStorage` mock entry; fork cases live in `DesktopPreReadyPlatform.fork.test.ts`. Rebased as one commit onto `hyprws` `fb8d78ee063`. The `exp/electron-api-automation` hook shared an earlier experimental build; it is not in this PR. ## Verification Real Electron 44.4.2 `safeStorage`, each case with a private D-Bus session, temp `HOME`, and dummy secret: | Case | Store | Backend | Available | Restart decrypt | | --- | --- | --- | --- | --- | | No keyring, no opt-in | `basic` | `basic_text` | `false` | n/a | | No keyring, this fix | `basic` | `basic_text` | `true` | `true` | | Throwaway keyring | auto | `gnome_libsecret` | `true` | `true` | | Throwaway keyring | `gnome-libsecret` | `gnome_libsecret` | `true` | `true` | | No keyring | auto | `gnome_libsecret` | `false` | n/a | The opt-in ran only in `basic` rows; no ciphertext contained the dummy plaintext. | Check | Command | Exit | | --- | --- | --- | | Tests | `vp test run` both `DesktopPreReadyPlatform` files | 0 | | Desktop app tests | `vp test run src/app/` (146) | 0 | | Typecheck | `apps/desktop` `vp run typecheck` | 0 | | Build | `vp run build:desktop` | 0 | | Fork CI | `vp run fork:ci` | 0 | Not checked: a full app pairing round trip on the cloud host. Claude Code (claude-opus-5-5) ## Fork trailers Fork-Domain: upstream-fixes Fork-Tier: bugfix Fork-Upstreamable: yes Co-authored-by: donjor <[email protected]>
1 parent 14b6cd1 commit f722f9e

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { assert, describe, it } from "@effect/vitest";
2+
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
3+
import * as Effect from "effect/Effect";
4+
import * as Layer from "effect/Layer";
5+
import { beforeEach, vi } from "vite-plus/test";
6+
7+
const { getSwitchValueMock, setUsePlainTextEncryptionMock } = vi.hoisted(() => ({
8+
getSwitchValueMock: vi.fn(),
9+
setUsePlainTextEncryptionMock: vi.fn(),
10+
}));
11+
12+
vi.mock("electron", () => ({
13+
app: {
14+
setDesktopName: vi.fn(),
15+
getVersion: () => "0.0.37",
16+
isPackaged: false,
17+
getAppPath: () => "/tmp/app",
18+
commandLine: {
19+
appendSwitch: vi.fn(),
20+
getSwitchValue: getSwitchValueMock,
21+
hasSwitch: (switchName: string) => switchName === "password-store",
22+
},
23+
},
24+
protocol: {
25+
registerSchemesAsPrivileged: vi.fn(),
26+
},
27+
safeStorage: {
28+
setUsePlainTextEncryption: setUsePlainTextEncryptionMock,
29+
},
30+
}));
31+
32+
vi.mock("node:fs", () => ({
33+
readFileSync: () => "{}",
34+
mkdirSync: vi.fn(),
35+
writeFileSync: vi.fn(),
36+
copyFileSync: vi.fn(),
37+
}));
38+
39+
import * as DesktopPreReadyPlatform from "./DesktopPreReadyPlatform.ts";
40+
41+
const buildLinuxOptions = DesktopPreReadyPlatform.DesktopPreReadyElectronOptions.pipe(
42+
Effect.provide(
43+
DesktopPreReadyPlatform.layer.pipe(Layer.provide(Layer.succeed(HostProcessPlatform, "linux"))),
44+
),
45+
);
46+
47+
describe("DesktopPreReadyPlatform plain-text safe storage", () => {
48+
beforeEach(() => {
49+
getSwitchValueMock.mockReset();
50+
setUsePlainTextEncryptionMock.mockReset();
51+
});
52+
53+
it.effect("opts into plain-text encryption for an explicit basic password store", () => {
54+
getSwitchValueMock.mockReturnValue(" basic ");
55+
56+
return Effect.gen(function* () {
57+
yield* buildLinuxOptions;
58+
assert.deepEqual(setUsePlainTextEncryptionMock.mock.calls, [[true]]);
59+
});
60+
});
61+
62+
it.effect("keeps plain-text encryption off for a keyring password store", () => {
63+
getSwitchValueMock.mockReturnValue("gnome-libsecret");
64+
65+
return Effect.gen(function* () {
66+
yield* buildLinuxOptions;
67+
assert.equal(setUsePlainTextEncryptionMock.mock.calls.length, 0);
68+
});
69+
});
70+
});

‎apps/desktop/src/app/DesktopPreReadyPlatform.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ vi.mock("electron", () => ({
4444
protocol: {
4545
registerSchemesAsPrivileged: registerSchemesMock,
4646
},
47+
safeStorage: {
48+
setUsePlainTextEncryption: vi.fn(),
49+
},
4750
}));
4851

4952
vi.mock("node:fs", () => ({

‎apps/desktop/src/app/DesktopPreReadyPlatform.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ export const make = Effect.gen(function* () {
142142
if (disableFeatures !== null) {
143143
Electron.app.commandLine.appendSwitch("disable-features", disableFeatures);
144144
}
145+
// Electron reports basic text as unavailable unless plain text is opted into, which
146+
// would leave saved environments unable to keep their credentials. An explicit
147+
// `--password-store=basic` is that opt-in, for hosts with no keyring to unlock.
148+
if (linuxPasswordStoreCommandLine === "basic") {
149+
Electron.safeStorage.setUsePlainTextEncryption(true);
150+
}
145151
}
146152

147153
return { linux, linuxPasswordStoreCommandLine };

0 commit comments

Comments
 (0)