Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ If a required command fails or emits a warning from project code, fix it in the

- Read the current per-user `biflow/debug.log` first when diagnosing a runtime report. It is permanent newline-delimited JSON across application sessions and is also included by **Diagnostics → Export**. Do not assume it exists before the app has launched, and do not commit a generated `debug.log`.
- Every new or changed desktop user action, background task, platform/helper boundary, warning, ignored failure, and error path in Rust must emit structured `tracing` events that reach `debug.log`. Reuse the command trace helpers in `src-tauri/src/diagnostics.rs` at Tauri boundaries. The separately privileged helper must emit the same safe fields to its service journal; the desktop records each helper request and result in `debug.log` without making the root service write into a user's data directory.
- A command or check that repeats on a timer uses `diagnostics::trace_poll` or `record_poll`, which log only a change of outcome (ADR 0143). Never put `trace_action` or an `info!` success event on a timer.
- Action events must identify `event`, `section`, `initiator`, `cause`, and `trace_route`; use a stable operation/request UUID as `trace_id` when available. Never log passwords, controller secrets, tokens, credentials, subscription links, raw URLs, full settings, direct-rule values, diagnostic targets, or unredacted user content.
- Do not ignore fallible Rust operations with `let _ =` unless failure is provably irrelevant. Log the warning/error and cause when execution continues, and preserve a regression test for diagnostic lifecycle, redaction, and file-size behavior.
- `debug.log` stays in append mode across process launches and is flushed after every event. Do not truncate, rotate, cap, or delete it automatically on startup or shutdown. Only the explicit Diagnostics delete action clears its contents; it must keep the active file handle usable and resume logging immediately.
Expand Down Expand Up @@ -71,6 +72,36 @@ If a required command fails or emits a warning from project code, fix it in the

## Lessons

- A path or a file that reaches the helper over IPC is attacker input, even
from the authorized user: the helper is root and the desktop is not. "Regular,
non-symlink file" is not trust. Check who can change the file and every
directory above it (ADR 0141).
- Do not filter another program's config language with a list of bad words.
OpenVPN quotes, includes, escapes, `setenv opt`, and closes an inline block on
a prefix. Parse it once, allow a known list, and run the rendered copy.
- A dropped future is not a rollback. A timeout around a multi-step operation
needs its own cleanup step and a test that asserts the released state, not
only that the lifecycle lock cleared (ADR 0144).
- Returning Ok because "the same kind of operation is already busy" lets two
callers run together. Serialize work that shares a prepared generation, and
re-check the phase after waiting.
- Replacing an application folder deletes whatever the app keeps beside its
executable. Hiddify's portable build stores subscriptions there. Read the
upstream source for its data folder before removing the old one.
- Go encodes a nil slice as `null`. `#[serde(default)]` does not accept it, so
an idle Mihomo produced "error decoding response body". Run the bundled
binary with no traffic when writing a controller fixture.
- A permanent log plus a one-second poll grew to 4.8 GB. Measure bytes per
minute with the window open when adding an event.
- Never print files from the side-tunnel data folder while diagnosing. They can
hold VPN credentials; list names and sizes only. `NamedTempFile` is not
deleted by a crash, so clear leftovers at startup.
- A runtime `cfg!(target_os = "macos")` branch changes what shared tests see on
a Mac while Linux and Windows stay green. Give each platform list its own
function and test that function by name on every host.
- `cfg(unix)` constants used by a shared type are dead code in the Windows
library build. Run `cargo xwin clippy` after changing the helper.

- Hiddify can rename Linux release assets and wrap its Windows portable files
in an outer directory. Verify the publisher's asset names and SHA-256 values,
assert the real ZIP layout in the installer fixture, and publish the complete
Expand Down
31 changes: 16 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ members = [
]

[workspace.package]
version = "6.2.96"
version = "6.3.0"
edition = "2021"
license = "MIT OR Apache-2.0"
rust-version = "1.88"
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@iran-split/desktop",
"version": "6.2.96",
"version": "6.3.0",
"private": true,
"type": "module",
"scripts": {
Expand Down
16 changes: 15 additions & 1 deletion apps/desktop/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen, within } from "@testing-library/react";
import { act, render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it } from "vitest";
import { App } from "./App";
Expand Down Expand Up @@ -79,6 +79,20 @@ describe("App", () => {
);
});

it("says so when startup replaced unreadable settings", async () => {
render(<App />);
await waitFor(() => expect(useAppStore.getState().boot).not.toBeNull());
const { boot } = useAppStore.getState();
act(() => {
useAppStore.setState({
boot: boot && { ...boot, settings_recovered: "defaults" },
});
});
expect(
await screen.findByText(/The settings file was damaged/),
).toBeInTheDocument();
});

it("opens the legacy About page as the Settings About tab", async () => {
render(<App />);
await homeHeading();
Expand Down
11 changes: 11 additions & 0 deletions apps/desktop/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ export function App() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const settingsRecovered = store.boot?.settings_recovered ?? null;
useEffect(() => {
if (settingsRecovered) {
useAppStore.setState({
error: t(`settingsRecovered_${settingsRecovered}`),
});
}
// Shown once per start; changing the language must not reopen it.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [settingsRecovered]);

useEffect(() => {
let unsubscribe: () => void = () => undefined;
void desktop
Expand Down
2 changes: 2 additions & 0 deletions apps/desktop/src/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ export interface BootstrapResult {
cloud_rules: CloudRulesStatus;
dependencies: DependencyStatus[];
network_status: NetworkStatus;
/** Set when startup replaced settings it could not read. */
settings_recovered?: "last_saved" | "defaults" | null;
}

export type InternetState = "checking" | "online" | "offline";
Expand Down
8 changes: 8 additions & 0 deletions apps/desktop/src/i18n/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ const resources = {
downloadInstall: "Download & install",
downloadOpenVpn: "Download OpenVPN",
downloadPageUnavailable: "Could not open the download page.",
settingsRecovered_last_saved:
"The settings file was damaged. BiFlow loaded your last saved settings.",
settingsRecovered_defaults:
"The settings file was damaged. BiFlow started with default settings; check your clients.",
downloadWindscribeConfig: "Get Windscribe config",
directTooltip:
"Traffic leaves over your physical network with your real IP.",
Expand Down Expand Up @@ -593,6 +597,10 @@ const resources = {
downloadInstall: "دانلود و نصب",
downloadOpenVpn: "دانلود OpenVPN",
downloadPageUnavailable: "صفحهٔ دانلود باز نشد.",
settingsRecovered_last_saved:
"فایل تنظیمات خراب بود. آخرین تنظیمات ذخیره‌شده بارگذاری شد.",
settingsRecovered_defaults:
"فایل تنظیمات خراب بود. برنامه با تنظیمات پیش‌فرض باز شد؛ کلاینت‌ها را بررسی کنید.",
downloadWindscribeConfig: "دانلود کانفیگ Windscribe",
directTooltip: "ترافیک با آی‌پی واقعی از شبکه فیزیکی خارج می‌شود.",
clientDetails: "تنظیمات و میزبان‌های سنجاق‌شده",
Expand Down
1 change: 1 addition & 0 deletions crates/iran-split-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ impl PlatformBackend for DemoBackend {
available: true,
authorized: true,
version: Some("demo".into()),
tun_name: None,
})
}
async fn ensure_hiddify(&self, _cancel: CancellationToken) -> Result<(), CoreError> {
Expand Down
1 change: 1 addition & 0 deletions crates/iran-split-clients/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
tokio-util.workspace = true
uuid.workspace = true

[dev-dependencies]
tempfile.workspace = true
Expand Down
Loading
Loading