From 77ca18cc33fcffc07a51ff0191834570a1664873 Mon Sep 17 00:00:00 2001 From: poli0981 <127664709+poli0981@users.noreply.github.com> Date: Fri, 16 Oct 2026 22:24:40 +0700 Subject: [PATCH] feat(app): the GUI logs, says when it cannot start, and shows where the log is - The GUI writes data\logs\pipdock..log through the same core::logging the CLI uses, with the panic hook installed, so a crash leaves a record where it used to leave nothing. - A data folder that cannot be opened is said in a dialog before any window exists (U18). The store was opened inside Tauri's setup hook, whose failure is a panic in the event loop: a release build has no console, so the user double-clicked and nothing happened. It now opens before Tauri starts, and the failure shows the code, the message and the log path through rfd - already in the tree via tauri-plugin-dialog, so Cargo.lock gains one dependency edge and no crate. It is the one place GUI copy is written in Rust (both languages at once), because no webview exists yet to load a catalog. - logs_tail returns LogTail { dir, lines } - a new schema, so schema-LogTail is blessed and schema-unknown-type lists one more type. NOT_YET is down to one entry, env_add_manual. - Settings gains a Logs row: the folder, as a path, and "Copy recent log", which re-reads the tail at the moment of copying so the clipboard holds the run that just went wrong. The clipboard permission "Copy full log" already had is enough; no capability changes. en + vi copy. Co-Authored-By: Claude Opus 5.5 --- Cargo.lock | 1 + crates/pipdock-cli/tests/golden.rs | 1 + .../snapshots/golden__schema-LogTail.snap | 27 +++++++ .../golden__schema-unknown-type.snap | 2 +- crates/pipdock-core/src/cache.rs | 9 +-- crates/pipdock-core/src/logging.rs | 24 ++++-- crates/pipdock-core/src/plan/mod.rs | 2 + docs/ARCHITECTURE.md | 2 +- src-tauri/Cargo.toml | 3 + src-tauri/src/commands.rs | 24 ++++++ src-tauri/src/lib.rs | 80 ++++++++++++++++--- ui/src/components/PdCacheUsage.tsx | 6 +- ui/src/components/PdLogs.test.tsx | 43 ++++++++++ ui/src/components/PdLogs.tsx | 76 ++++++++++++++++++ ui/src/ipc/generated.ts | 8 ++ ui/src/ipc/index.ts | 44 ++++++---- ui/src/locales/en/common.json | 9 ++- ui/src/locales/vi/common.json | 31 ++++--- ui/src/screens/PdSettings.tsx | 2 + ui/src/test/ipc.ts | 3 + 20 files changed, 340 insertions(+), 57 deletions(-) create mode 100644 crates/pipdock-cli/tests/snapshots/golden__schema-LogTail.snap create mode 100644 ui/src/components/PdLogs.test.tsx create mode 100644 ui/src/components/PdLogs.tsx diff --git a/Cargo.lock b/Cargo.lock index 45f1999..355715f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3203,6 +3203,7 @@ version = "1.3.0" dependencies = [ "jiff", "pipdock-core", + "rfd", "serde", "serde_json", "tauri", diff --git a/crates/pipdock-cli/tests/golden.rs b/crates/pipdock-cli/tests/golden.rs index 2e31ed9..babc841 100644 --- a/crates/pipdock-cli/tests/golden.rs +++ b/crates/pipdock-cli/tests/golden.rs @@ -64,6 +64,7 @@ const SCHEMA_TYPES: &[&str] = &[ "HealthReport", "AuditReport", "FixReport", + "LogTail", ]; fn pipdock() -> Command { diff --git a/crates/pipdock-cli/tests/snapshots/golden__schema-LogTail.snap b/crates/pipdock-cli/tests/snapshots/golden__schema-LogTail.snap new file mode 100644 index 0000000..53d90b7 --- /dev/null +++ b/crates/pipdock-cli/tests/snapshots/golden__schema-LogTail.snap @@ -0,0 +1,27 @@ +--- +source: crates/pipdock-cli/tests/golden.rs +expression: out +--- +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "description": "The end of PipDock's own log, for Settings' Logs row (ARCHITECTURE §7).", + "properties": { + "dir": { + "description": "The folder the log files are in. A path — data, never localized (I18N §2).", + "type": "string" + }, + "lines": { + "description": "The most recent lines, oldest first. Empty when nothing has been logged yet.", + "items": { + "type": "string" + }, + "type": "array" + } + }, + "required": [ + "dir", + "lines" + ], + "title": "LogTail", + "type": "object" +} diff --git a/crates/pipdock-cli/tests/snapshots/golden__schema-unknown-type.snap b/crates/pipdock-cli/tests/snapshots/golden__schema-unknown-type.snap index 126d654..3d7b03e 100644 --- a/crates/pipdock-cli/tests/snapshots/golden__schema-unknown-type.snap +++ b/crates/pipdock-cli/tests/snapshots/golden__schema-unknown-type.snap @@ -2,4 +2,4 @@ source: crates/pipdock-cli/tests/golden.rs expression: "stderr_of(&[\"schema\", \"NoSuchType\"])" --- -error[PD-PKG-002]: unknown type "NoSuchType"; known types: Dist, OutdatedDist, PyEnv, CheckReport, StepResult, PlanRequest, ResolutionReport, ExecutionSummary, Pin, PinSuggestion, ParsedRequirements, CacheUsage, CacheTarget, GuardReport, DepsGraph, Diff, SnapshotMeta, EngineInfo, RollbackPlan, RollbackPreview, Hit, PackageMeta, Freshness, RefreshReport, ProgressEvent, FlowStep, Decision, Intent, Code, HealthReport, AuditReport, FixReport +error[PD-PKG-002]: unknown type "NoSuchType"; known types: Dist, OutdatedDist, PyEnv, CheckReport, StepResult, PlanRequest, ResolutionReport, ExecutionSummary, Pin, PinSuggestion, ParsedRequirements, CacheUsage, CacheTarget, GuardReport, DepsGraph, Diff, SnapshotMeta, EngineInfo, RollbackPlan, RollbackPreview, Hit, PackageMeta, Freshness, RefreshReport, ProgressEvent, FlowStep, Decision, Intent, Code, HealthReport, AuditReport, FixReport, LogTail diff --git a/crates/pipdock-core/src/cache.rs b/crates/pipdock-core/src/cache.rs index 05abf5a..fecb2bf 100644 --- a/crates/pipdock-core/src/cache.rs +++ b/crates/pipdock-core/src/cache.rs @@ -19,12 +19,11 @@ //! reported so the number is honest about where the space went; refreshing the index is //! `index refresh`, which replaces rows rather than deleting a file. //! -//! # There are no log files +//! # Log files are not a target //! -//! [`crate::LOG_RETENTION_DAYS`] has never had a reader. The only log is the in-memory ring buffer -//! behind *Report bug*, and `logs_tail` is still owed. When the logging subsystem lands it becomes -//! a fourth entry here; until then, reporting a "logs" line of zero bytes would be inventing a -//! thing that does not exist. +//! Since 1.4.0 there are log files (`crate::logging`), and they look after themselves: the sweep +//! keeps [`crate::LOG_RETENTION_DAYS`] and nothing more, so a "clear logs" button would only take +//! away the one record a bug report needs. Settings shows where they are instead. use std::path::{Path, PathBuf}; diff --git a/crates/pipdock-core/src/logging.rs b/crates/pipdock-core/src/logging.rs index 2cbd40c..9e9896c 100644 --- a/crates/pipdock-core/src/logging.rs +++ b/crates/pipdock-core/src/logging.rs @@ -135,14 +135,26 @@ pub fn sweep(dir: &Path, keep_days: u32, now: jiff::Timestamp) -> usize { .count() } +/// The end of PipDock's own log, for Settings' Logs row (ARCHITECTURE §7). +#[derive( + Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize, schemars::JsonSchema, +)] +#[serde(rename_all = "camelCase")] +pub struct LogTail { + /// The folder the log files are in. A path — data, never localized (I18N §2). + pub dir: String, + /// The most recent lines, oldest first. Empty when nothing has been logged yet. + pub lines: Vec, +} + /// The last `max_lines` lines across the newest log files in `dir`, oldest first. /// /// Reads backwards through the files by date, so a tail that straddles midnight still has the /// lines from before it. Bounded: at most a few files are read. #[must_use] -pub fn tail(dir: &Path, max_lines: usize) -> String { +pub fn tail(dir: &Path, max_lines: usize) -> Vec { let Ok(entries) = std::fs::read_dir(dir) else { - return String::new(); + return Vec::new(); }; let mut files: Vec<(jiff::civil::Date, String, PathBuf)> = entries .flatten() @@ -167,7 +179,7 @@ pub fn tail(dir: &Path, max_lines: usize) -> String { } } let start = lines.len().saturating_sub(max_lines); - lines[start..].join("\n") + lines.split_off(start) } /// Record a panic in the log before the default hook prints it. @@ -255,9 +267,9 @@ mod tests { std::fs::create_dir_all(&dir).expect("dir"); std::fs::write(dir.join("pipdock.2026-10-15.log"), "a\nb\nc\n").expect("seed"); std::fs::write(dir.join("pipdock.2026-10-16.log"), "d\ne\n").expect("seed"); - assert_eq!(tail(&dir, 3), "c\nd\ne"); - assert_eq!(tail(&dir, 50), "a\nb\nc\nd\ne"); - assert_eq!(tail(&scratch("absent"), 5), ""); + assert_eq!(tail(&dir, 3), ["c", "d", "e"]); + assert_eq!(tail(&dir, 50), ["a", "b", "c", "d", "e"]); + assert!(tail(&scratch("absent"), 5).is_empty()); let _ = std::fs::remove_dir_all(&dir); } } diff --git a/crates/pipdock-core/src/plan/mod.rs b/crates/pipdock-core/src/plan/mod.rs index d4e0c90..a788f8f 100644 --- a/crates/pipdock-core/src/plan/mod.rs +++ b/crates/pipdock-core/src/plan/mod.rs @@ -351,6 +351,7 @@ pub fn json_schema(type_name: &str) -> Result { "HealthReport" => crate::health::HealthReport, "AuditReport" => crate::audit::AuditReport, "FixReport" => crate::health::fix::FixReport, + "LogTail" => crate::logging::LogTail, } } @@ -388,6 +389,7 @@ pub const SCHEMA_TYPES: &[&str] = &[ "HealthReport", "AuditReport", "FixReport", + "LogTail", ]; /// DATA-FLOW §9.3: a report older than this is refused by [`execute`] and must be re-resolved. diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 2db25f9..2d23a4a 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -158,7 +158,7 @@ This table is the surface. A command that is not listed here does not exist; add | `cache_clear` | `number` | Delete one cache target, resolving to the bytes freed. Takes a `Target` **enum, never a path** — `cache::clear` is the only thing that turns one into a directory. `index.db` is deliberately not a target: it holds settings, pins and the consent record as well as the package index, and *clear the cache* must never take a user's pins. | | `legal_consent_get` | `ConsentState` | Whether the legal gate can be skipped for this build's documents. | | `legal_consent_set` | `Consent` | Record acceptance. | -| `logs_tail` | `string[]` | Tail of the in-memory log ring buffer, for the console drawer. | +| `logs_tail` | `LogTail` | The end of PipDock's own log files (`data\logs\`, kept `LOG_RETENTION_DAYS`) and the folder they are in, for Settings' Logs row. Never fails: no log yet is an empty tail. | | `report_bug_url` | `string` | Prefilled GitHub issue URL (ERROR-CATALOG §4). Built in Rust so it cannot drift from `pipdock self report-bug`. **Nothing is ever sent automatically.** | Events (Tauri event channel): `plan-progress` streams live subprocess output to the in-app console; `scan-progress`; `health-progress`. diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 956b691..57e7b6f 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -39,6 +39,9 @@ tracing = "0.1.44" # certain it owned the mutation in flight. tauri-plugin-single-instance = "2.5.4" tracing-subscriber = { version = "0.3.23", features = ["env-filter"] } +# The one dialog that has to work before Tauri does: the data folder could not be opened, so there +# is no app to show anything in. Already in the tree through tauri-plugin-dialog, with its features. +rfd = { version = "0.16", default-features = false, features = ["common-controls-v6"] } [dev-dependencies] # `Sessions` is the one thing in this crate with a protocol worth testing on its own, and every diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 979c262..da554a6 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -1456,6 +1456,30 @@ pub async fn engine_info(env: PyEnv) -> Wire, + lines: Option, +) -> Wire { + let dir = pipdock_core::logging::log_dir(&state.app_data); + let wanted = lines.unwrap_or(200).min(2_000); + let read = dir.clone(); + let lines = tokio::task::spawn_blocking(move || pipdock_core::logging::tail(&read, wanted)) + .await + .unwrap_or_default(); + Ok(pipdock_core::logging::LogTail { + dir: dir.display().to_string(), + lines, + }) +} + /// A prefilled GitHub issue URL, and the log to put on the clipboard (ERROR-CATALOG §4). /// /// Two fields because §4.3 splits them: the URL carries a truncated, tail-biased excerpt so GitHub diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 16c90b5..48354f6 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -22,10 +22,61 @@ pub mod state; /// runtime, and typechecked the whole time. This list is what makes the gap explicit instead of /// invisible: a name here is a promise with a date on it, and the test below fails the moment /// `COMMANDS` and reality disagree in either direction. -pub const NOT_YET: &[(&str, &str)] = &[ - ("env_add_manual", "M3 — Browse… has no surface yet"), - ("logs_tail", "M3 — needs the logging subsystem"), -]; +pub const NOT_YET: &[(&str, &str)] = &[("env_add_manual", "M3 — Browse… has no surface yet")]; + +/// Start the app's own log: `data\logs\pipdock..log`, at `PIPDOCK_LOG` or INFO. +/// +/// The GUI has no terminal, so before 1.4.0 a panic or a failed startup left no trace at all. +fn init_logging(app_data: &std::path::Path) -> std::path::PathBuf { + use tracing_subscriber::layer::SubscriberExt as _; + use tracing_subscriber::util::SubscriberInitExt as _; + use tracing_subscriber::{EnvFilter, Layer as _, fmt}; + + let dir = pipdock_core::logging::log_dir(app_data); + pipdock_core::logging::sweep( + &dir, + pipdock_core::LOG_RETENTION_DAYS, + jiff::Timestamp::now(), + ); + let file = pipdock_core::logging::DailyFile::new(&dir, "pipdock"); + let path = file.current_path(); + let level = EnvFilter::try_from_env("PIPDOCK_LOG").unwrap_or_else(|_| EnvFilter::new("info")); + let _ = tracing_subscriber::registry() + .with( + fmt::layer() + .with_ansi(false) + .with_writer(move || file.clone()) + .with_filter(level), + ) + .try_init(); + pipdock_core::logging::install_panic_hook(); + tracing::info!(target: "pipdock::app", version = env!("CARGO_PKG_VERSION"), "start"); + path +} + +/// Say that PipDock cannot start, and why, before any window exists (U18). +/// +/// The store used to be opened inside Tauri's `setup`, whose failure is a `panic!` in the event +/// loop: a release build has no console, so a data folder that could not be opened meant a +/// double-click that did nothing at all. This runs before Tauri does, so it cannot use the +/// catalogs the webview loads — the one place GUI copy is written in Rust, both languages at once, +/// with the code and the log path as data (I18N §1's exception, stated). +fn startup_failed(e: &pipdock_core::PdError, log: &std::path::Path) { + let detail = format!( + "PipDock could not open its data folder and has to close.\n\ + PipDock không mở được thư mục dữ liệu và phải đóng.\n\n\ + {}: {}\n\n{}", + e.code, + e.message, + log.display() + ); + let _ = rfd::MessageDialog::new() + .set_level(rfd::MessageLevel::Error) + .set_title("PipDock") + .set_description(detail) + .set_buttons(rfd::MessageButtons::Ok) + .show(); +} #[cfg_attr(mobile, tauri::mobile_entry_point)] #[allow( @@ -35,6 +86,17 @@ pub const NOT_YET: &[(&str, &str)] = &[ pub fn run() { use tauri::Manager as _; + let log = init_logging(&pipdock_core::store::default_app_data()); + // Opened before Tauri starts, so a failure can be *said*: see `startup_failed`. + let state = match state::AppState::new() { + Ok(state) => state, + Err(e) => { + tracing::error!(target: "pipdock::app", code = %e.code, message = %e.message, "could not start"); + startup_failed(&e, &log); + return; + } + }; + tauri::Builder::default() // **First, before every other plugin.** The single-instance handler has to be registered // before anything that could take a lock or open the store, because a second launch runs @@ -54,11 +116,10 @@ pub fn run() { .plugin(tauri_plugin_dialog::init()) .plugin(tauri_plugin_opener::init()) .plugin(tauri_plugin_clipboard_manager::init()) - .setup(|app| { - // Opening the store is the one startup step that can fail for a reason the user can - // act on (a data directory that is not writable). Failing here, before a window is - // shown, beats every command failing later with the same cause. - app.manage(state::AppState::new()?); + .setup(move |app| { + // Already open: the one startup step that can fail for a reason the user can act on + // ran before Tauri, where its failure can reach the user. + app.manage(state); Ok(()) }) .invoke_handler(tauri::generate_handler![ @@ -104,6 +165,7 @@ pub fn run() { commands::settings_set, commands::legal_consent_get, commands::legal_consent_set, + commands::logs_tail, ]) .run(tauri::generate_context!()) .expect("error while running PipDock"); diff --git a/ui/src/components/PdCacheUsage.tsx b/ui/src/components/PdCacheUsage.tsx index a6bda8e..0ce4198 100644 --- a/ui/src/components/PdCacheUsage.tsx +++ b/ui/src/components/PdCacheUsage.tsx @@ -1,9 +1,9 @@ /** * What PipDock has written to disk, and what can be removed — PRD P1-4. * - * **Three artefacts, not four.** There are no log files: `LOG_RETENTION_DAYS` has never had a - * reader, the only log is the in-memory ring buffer behind *Report bug*, and `logs_tail` is still - * owed. A "logs — 0 B" row would be inventing a thing that does not exist. + * **Logs are not a row here.** They exist since 1.4.0 and look after themselves — the sweep keeps + * `LOG_RETENTION_DAYS` and nothing more — so a *Clear* would only take away what a bug report + * needs. `PdLogs`, below this on the Settings screen, says where they are. * * **`index.db` has no Clear button**, and its row says why. It holds the package index *and* the * settings *and* the pin list *and* the legal-consent record in one SQLite file, so a "clear the diff --git a/ui/src/components/PdLogs.test.tsx b/ui/src/components/PdLogs.test.tsx new file mode 100644 index 0000000..e19748c --- /dev/null +++ b/ui/src/components/PdLogs.test.tsx @@ -0,0 +1,43 @@ +import { fireEvent, render, screen, waitFor } from '@testing-library/react' +import { beforeEach, describe, expect, it, vi } from 'vitest' + +import '@/i18n' +import * as ipc from '@/ipc' + +import { PdLogs } from './PdLogs' + +vi.mock('@/ipc', async () => { + const { ipcMock } = await import('@/test/ipc') + return ipcMock() +}) + +vi.mock('@tauri-apps/plugin-clipboard-manager', () => ({ + writeText: vi.fn().mockResolvedValue(undefined), +})) + +const { writeText } = await import('@tauri-apps/plugin-clipboard-manager') +const logsTail = vi.mocked(ipc.logsTail) + +describe('PdLogs', () => { + beforeEach(() => { + logsTail.mockResolvedValue({ dir: 'C:/data/logs', lines: [] }) + }) + + it('shows where the log is, as a path', async () => { + render() + expect(await screen.findByText('C:/data/logs')).toBeInTheDocument() + expect(screen.getByText(/nothing has been logged yet/i)).toBeInTheDocument() + }) + + it('copies what the log says at the moment of copying', async () => { + render() + await screen.findByText('C:/data/logs') + // The run the user is reporting happened after the screen opened. + logsTail.mockResolvedValue({ dir: 'C:/data/logs', lines: ['spawn', 'exited code=Some(1)'] }) + fireEvent.click(screen.getByRole('button', { name: /copy recent log/i })) + await waitFor(() => { + expect(writeText).toHaveBeenCalledWith('spawn\nexited code=Some(1)') + }) + expect(await screen.findByText(/copied/i)).toBeInTheDocument() + }) +}) diff --git a/ui/src/components/PdLogs.tsx b/ui/src/components/PdLogs.tsx new file mode 100644 index 0000000..067101e --- /dev/null +++ b/ui/src/components/PdLogs.tsx @@ -0,0 +1,76 @@ +/** + * Where PipDock's own log is, and a way to hand its recent lines to someone — Settings. + * + * The log files arrived in 1.4.0 (`data\logs\`, kept 14 days by the sweep, never sent anywhere). + * There is no *Clear*: the sweep already keeps no more than that, and the files are the one record a + * bug report needs. The folder path is shown as data — a path is never translated (I18N §2) — and + * *Copy recent log* puts the tail on the clipboard, which `clipboard-manager:allow-write-text` + * already grants for *Copy full log*; no capability is widened for it. + */ + +import { writeText } from '@tauri-apps/plugin-clipboard-manager' +import { useEffect, useState } from 'react' +import { useTranslation } from 'react-i18next' + +import { logsTail, type LogTail } from '@/ipc' + +export function PdLogs() { + const { t } = useTranslation() + const [tail, setTail] = useState(null) + const [copied, setCopied] = useState(false) + + // Once on mount, like the cache figures beside it: the log only grows while something runs, and + // a copy re-reads it anyway. + useEffect(() => { + let alive = true + void logsTail().then( + (next) => { + if (alive) setTail(next) + }, + () => { + // `logs_tail` never fails by contract; a rejection here is a bridge failure, and the + // row simply stays without a path rather than showing an error for a convenience. + }, + ) + return () => { + alive = false + } + }, []) + + const copy = async () => { + // Read again at the moment of copying, so the clipboard holds what the log says *now* — + // typically the run that just went wrong — not what it said when the screen opened. + const fresh = await logsTail() + setTail(fresh) + await writeText(fresh.lines.join('\n')) + setCopied(true) + } + + return ( +
+

+ {t('settings.logs')} +

+

{t('settings.logsDetail')}

+ {tail !== null ? ( +

{tail.dir}

+ ) : null} +
+ + + {copied ? t('settings.logsCopied') : null} + {tail !== null && tail.lines.length === 0 && !copied ? t('settings.logsEmpty') : null} + +
+
+ ) +} diff --git a/ui/src/ipc/generated.ts b/ui/src/ipc/generated.ts index c943ed4..44a66af 100644 --- a/ui/src/ipc/generated.ts +++ b/ui/src/ipc/generated.ts @@ -637,6 +637,14 @@ export type Intent = | { all: boolean; except?: string[]; forceLatest?: boolean; intent: 'update'; pkgs?: string[] } | { intent: 'install'; specs: string[] }; +/** The end of PipDock's own log, for Settings' Logs row (ARCHITECTURE §7). */ +export interface LogTail { + /** The folder the log files are in. A path — data, never localized (I18N §2). */ + dir: string; + /** The most recent lines, oldest first. Empty when nothing has been logged yet. */ + lines: string[]; +} + /** How a hit matched, in ranking order. */ export type MatchKind = | 'exact' diff --git a/ui/src/ipc/index.ts b/ui/src/ipc/index.ts index 9afd828..8c4bbba 100644 --- a/ui/src/ipc/index.ts +++ b/ui/src/ipc/index.ts @@ -17,30 +17,31 @@ import { open, save } from '@tauri-apps/plugin-dialog' import type { AuditReport, - Decision, - DepsGraph, - Dist, - Freshness, - Hit, - EngineId, - EnvSource, - Diff, - EngineInfo, - ExecutionSummary, - FlowStep, - GuardReport, - Intent, - OutdatedDist, - PackageMeta, CacheTarget, CacheUsage, + Decision, + DepsGraph, + Diff, + Dist, + EngineId, + EngineInfo, + EnvSource, + ExecutionSummary, + FixReport, + FlowStep, + Freshness, + GuardReport, + HealthReport, + Hit, + Intent, + LogTail, + OutdatedDist, + PackageMeta, ParsedRequirements, Pin, PinSuggestion, ProgressEvent, PyEnv, - HealthReport, - FixReport, RefreshReport, RollbackPreview, SnapshotMeta, @@ -431,6 +432,15 @@ export interface BugReportLink { * The URL carries a truncated excerpt because GitHub rejects very long ones; the full log comes * back separately so the UI can put it on the clipboard and say it did (§4.3). */ +/** + * The end of PipDock's own log, and the folder it is in — Settings' Logs row. + * + * Never rejects by contract: no log yet is an empty `lines`. `lines` defaults to 200 and the + * command clamps it, because the result crosses the bridge whole. + */ +export const logsTail = (lines?: number): Promise => + invoke('logs_tail', { lines: lines ?? null }) + export const reportBugUrl = (env?: PyEnv, code?: string): Promise => invoke('report_bug_url', { env: env ?? null, code: code ?? null }) diff --git a/ui/src/locales/en/common.json b/ui/src/locales/en/common.json index cba5980..399d8de 100644 --- a/ui/src/locales/en/common.json +++ b/ui/src/locales/en/common.json @@ -121,7 +121,7 @@ "deps": { "title": "Dependencies", "back": "Back to packages", - "loading": "Reading this environment's dependencies\u2026", + "loading": "Reading this environment's dependencies…", "dependents_one": "{{count}} package requires this", "dependents_other": "{{count}} packages require this", "dependencies_one": "Requires {{count}} package", @@ -426,7 +426,12 @@ "pinThresholdDetail": "How many other packages must depend on something before the Pins screen suggests pinning it. Zero turns the suggestions off.", "override": "Allow externally managed environments", "overrideDetail": "PEP 668 marks some Pythons as managed by the operating system. Installing into one can break system tools, and there is no undo beyond a snapshot. Leave this off unless you know why you need it.", - "saved": "Saved" + "saved": "Saved", + "logs": "Logs", + "logsDetail": "PipDock keeps its own log for 14 days in this folder. Nothing in it is sent anywhere; copy it into a bug report if you want someone to read it.", + "logsCopy": "Copy recent log", + "logsCopied": "Copied", + "logsEmpty": "Nothing has been logged yet." }, "legal": { "title": "Before you start", diff --git a/ui/src/locales/vi/common.json b/ui/src/locales/vi/common.json index cc6e5fd..9c99944 100644 --- a/ui/src/locales/vi/common.json +++ b/ui/src/locales/vi/common.json @@ -115,19 +115,19 @@ "orphanOutdated_other": "{{count}} gói có bản cập nhật nhưng không có trong danh sách này." }, "deps": { - "title": "Ph\u1ee5 thu\u1ed9c", - "back": "Quay l\u1ea1i danh s\u00e1ch g\u00f3i", - "loading": "\u0110ang \u0111\u1ecdc ph\u1ee5 thu\u1ed9c c\u1ee7a m\u00f4i tr\u01b0\u1eddng n\u00e0y\u2026", - "dependents_other": "{{count}} g\u00f3i c\u1ea7n g\u00f3i n\u00e0y", - "dependencies_other": "C\u1ea7n {{count}} g\u00f3i", - "more_other": "C\u00f2n {{count}} m\u1ee5c kh\u00f4ng hi\u1ec3n th\u1ecb", - "none": "Kh\u00f4ng c\u00f3 g\u00ec \u1edf \u0111\u00e2y", - "unconstrained": "(phi\u00ean b\u1ea3n b\u1ea5t k\u1ef3)", + "title": "Phụ thuộc", + "back": "Quay lại danh sách gói", + "loading": "Đang đọc phụ thuộc của môi trường này…", + "dependents_other": "{{count}} gói cần gói này", + "dependencies_other": "Cần {{count}} gói", + "more_other": "Còn {{count}} mục không hiển thị", + "none": "Không có gì ở đây", + "unconstrained": "(phiên bản bất kỳ)", "focusOn": "Xem {{pkg}}", - "impact_other": "G\u1ee1 g\u00f3i n\u00e0y s\u1ebd l\u00e0m {{count}} g\u00f3i thi\u1ebfu ph\u1ee5 thu\u1ed9c.", - "reach_other": "G\u00f3i n\u00e0y k\u00e9o theo {{count}} g\u00f3i kh\u00e1c.", - "unsatisfied_other": "{{count}} y\u00eau c\u1ea7u kh\u00f4ng c\u00f3 g\u00f3i n\u00e0o \u0111\u00e1p \u1ee9ng: {{packages}}", - "unknownPackage": "{{pkg}} kh\u00f4ng c\u00f3 trong danh s\u00e1ch c\u1ee7a m\u00f4i tr\u01b0\u1eddng n\u00e0y." + "impact_other": "Gỡ gói này sẽ làm {{count}} gói thiếu phụ thuộc.", + "reach_other": "Gói này kéo theo {{count}} gói khác.", + "unsatisfied_other": "{{count}} yêu cầu không có gói nào đáp ứng: {{packages}}", + "unknownPackage": "{{pkg}} không có trong danh sách của môi trường này." }, "plan": { "section": { @@ -382,7 +382,12 @@ "pinThresholdDetail": "Cần bao nhiêu gói khác phụ thuộc vào một gói thì màn hình Ghim mới gợi ý ghim nó. Đặt 0 để tắt gợi ý.", "override": "Cho phép môi trường do hệ thống quản lý", "overrideDetail": "PEP 668 đánh dấu một số bản Python là do hệ điều hành quản lý. Cài vào đó có thể làm hỏng công cụ hệ thống, và không có cách hoàn tác nào ngoài ảnh chụp. Hãy để tắt trừ khi bạn biết rõ vì sao cần bật.", - "saved": "Đã lưu" + "saved": "Đã lưu", + "logs": "Nhật ký", + "logsDetail": "PipDock giữ nhật ký của chính nó trong 14 ngày tại thư mục này. Không có gì trong đó được gửi đi; hãy sao chép vào báo lỗi nếu bạn muốn ai đó đọc.", + "logsCopy": "Sao chép nhật ký gần đây", + "logsCopied": "Đã sao chép", + "logsEmpty": "Chưa có gì được ghi." }, "legal": { "title": "Trước khi bắt đầu", diff --git a/ui/src/screens/PdSettings.tsx b/ui/src/screens/PdSettings.tsx index 71c7cbc..4294c9c 100644 --- a/ui/src/screens/PdSettings.tsx +++ b/ui/src/screens/PdSettings.tsx @@ -14,6 +14,7 @@ import { useTranslation } from 'react-i18next' import { PdCacheUsage } from '@/components/PdCacheUsage' import { PdErrorRow } from '@/components/PdErrorRow' +import { PdLogs } from '@/components/PdLogs' import { SUPPORTED_LOCALES, type Locale } from '@/i18n' import { useSettingsStore } from '@/stores' @@ -132,6 +133,7 @@ export function PdSettings() { + ) } diff --git a/ui/src/test/ipc.ts b/ui/src/test/ipc.ts index 3a65ed8..5d6d02f 100644 --- a/ui/src/test/ipc.ts +++ b/ui/src/test/ipc.ts @@ -59,6 +59,7 @@ export interface IpcMock { healthFix: ReturnType healthDirty: ReturnType reportBugUrl: ReturnType + logsTail: ReturnType appInfo: ReturnType isPdError: (value: unknown) => boolean } @@ -114,6 +115,8 @@ export function ipcMock(): IpcMock { healthSaveReport: vi.fn().mockResolvedValue([]), healthFix: vi.fn(), healthDirty: vi.fn().mockResolvedValue(null), + // Settings renders the Logs row, so every Settings test needs this to resolve to a real shape. + logsTail: vi.fn().mockResolvedValue({ dir: 'C:/data/logs', lines: [] }), // `PdErrorRow` asks for this on mount, so any test that renders a screen containing an error // needs it — a gap that only appears once a *screen* is under test rather than the row alone. //