feat(app): engine_info, COMMANDS stops being a lie, and focus follows the tab
S7's four remaining items, together.
**`COMMANDS` was never checked against anything.** It is the array the frontend
types its wrappers against, and nothing tied it to what Tauri actually registers
— so for four stages it listed 32 names while 19 were registered, and a wrapper
for any of the other 13 typechecked, shipped, and would have failed at runtime in
front of a user, on a command that looked implemented. Three tests close it, all
reading the source rather than a duplicate list: `generate_handler!` is a macro,
so there is no runtime list to inspect and a hand-maintained copy would be one
more thing to forget. `NOT_YET` is the honest half — five declared-and-owed
commands, each naming the slice that owes it — and a third test fails if an entry
there already exists, so a stale note cannot outlive the work.
**`engine_info`** returns both engines, because Settings shows a version beside
each radio and asking about the configured one leaves the other blank until it is
picked. It takes a `PyEnv` since `Engine::info` does in the trait and both
adapters — pip's version comes from `<python> -m pip --version`, so there is no
env-free answer. `EngineInfo` pays the full wire cost: membership in
`SCHEMA_TYPES`, not the `JsonSchema` derive, is what puts a type in
`generated.ts`, and it was in neither. Goldens 54 → 55.
**Focus follows the tab.** `Ctrl+3` changed the screen and left focus on whatever
was last clicked, so the next Tab resumed inside the screen the user had just
left and a screen reader announced nothing. It now moves to the new screen's
heading; `key={nav}` on `<main>` is what makes the effect fire on every change
rather than only the first.
**Search's idle empty state.** It rendered a bare empty list before anything was
typed — the first thing a user sees on that screen, saying nothing. UI-SPEC §7's
glyph, sentence and hint, and the hint is the one worth having: results come from
the local index, so it works offline.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
33bc2f967e
commit
ccee3151a7
12 files changed
+236
-5
No files matched your search
@@ -41,6 +41,7 @@ const SCHEMA_TYPES: &[&str] = &[
|
||||
"GuardReport",
|
||||
"Diff",
|
||||
"SnapshotMeta",
|
||||
"EngineInfo",
|
||||
"RollbackPlan",
|
||||
"RollbackPreview",
|
||||
"Hit",
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
---
|
||||
source: crates/pipdock-cli/tests/golden.rs
|
||||
expression: out
|
||||
---
|
||||
{
|
||||
"$defs": {
|
||||
"EngineId": {
|
||||
"description": "Which resolver PipDock is driving.",
|
||||
"oneOf": [
|
||||
{
|
||||
"const": "pip",
|
||||
"description": "`<python> -m pip …`",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"const": "uv",
|
||||
"description": "`uv pip … --python <python>`",
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"description": "Availability and version of an engine for a given environment.",
|
||||
"properties": {
|
||||
"available": {
|
||||
"description": "False means the binary or module could not be found (`PD-ENG-001`).",
|
||||
"type": "boolean"
|
||||
},
|
||||
"id": {
|
||||
"$ref": "#/$defs/EngineId",
|
||||
"description": "Which engine this describes."
|
||||
},
|
||||
"version": {
|
||||
"description": "Reported version, absent when the engine is not available.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id",
|
||||
"available"
|
||||
],
|
||||
"title": "EngineInfo",
|
||||
"type": "object"
|
||||
}
|
||||
@@ -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, GuardReport, Diff, SnapshotMeta, RollbackPlan, RollbackPreview, Hit, PackageMeta, Freshness, RefreshReport, ProgressEvent, FlowStep, Decision, Intent, Code
|
||||
error[PD-PKG-002]: unknown type "NoSuchType"; known types: Dist, OutdatedDist, PyEnv, CheckReport, StepResult, PlanRequest, ResolutionReport, ExecutionSummary, Pin, GuardReport, Diff, SnapshotMeta, EngineInfo, RollbackPlan, RollbackPreview, Hit, PackageMeta, Freshness, RefreshReport, ProgressEvent, FlowStep, Decision, Intent, Code
|
||||
@@ -270,6 +270,7 @@ pub fn json_schema(type_name: &str) -> Result<serde_json::Value> {
|
||||
"GuardReport" => crate::graph::GuardReport,
|
||||
"Diff" => crate::snapshot::Diff,
|
||||
"SnapshotMeta" => crate::snapshot::Meta,
|
||||
"EngineInfo" => crate::model::EngineInfo,
|
||||
"RollbackPlan" => crate::snapshot::RollbackPlan,
|
||||
"RollbackPreview" => crate::flow::RollbackPreview,
|
||||
"Hit" => crate::index::Hit,
|
||||
@@ -298,6 +299,7 @@ pub const SCHEMA_TYPES: &[&str] = &[
|
||||
"GuardReport",
|
||||
"Diff",
|
||||
"SnapshotMeta",
|
||||
"EngineInfo",
|
||||
"RollbackPlan",
|
||||
"RollbackPreview",
|
||||
"Hit",
|
||||
|
||||
@@ -746,6 +746,30 @@ fn forward_progress(
|
||||
});
|
||||
}
|
||||
|
||||
/// Detected version and availability for **both** engines (ARCHITECTURE §7).
|
||||
///
|
||||
/// Both, not the configured one: Settings shows a radio with a version beside each option, so
|
||||
/// asking about the one already selected would leave the other blank until it was chosen.
|
||||
///
|
||||
/// Takes a `PyEnv` because `Engine::info` does in the trait and in both adapters — pip's version
|
||||
/// comes from `<python> -m pip --version`, so there is no env-free answer for it. Settings shows
|
||||
/// "pick an environment" until one is selected rather than reporting a pip that is not there.
|
||||
///
|
||||
/// # Errors
|
||||
/// Never: an engine that cannot be spawned reports `available: false`, which is the answer, not a
|
||||
/// failure. Returns `Wire` because an async command taking a borrowed `State` must.
|
||||
#[tauri::command]
|
||||
pub async fn engine_info(env: PyEnv) -> Wire<Vec<pipdock_core::model::EngineInfo>> {
|
||||
let mut out = Vec::with_capacity(2);
|
||||
for id in [
|
||||
pipdock_core::model::EngineId::Pip,
|
||||
pipdock_core::model::EngineId::Uv,
|
||||
] {
|
||||
out.push(engine::for_id(id).info(&env).await);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
/// 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
|
||||
|
||||
@@ -14,6 +14,22 @@ pub mod state;
|
||||
/// # Panics
|
||||
/// Panics if Tauri cannot build the app context. That means a malformed `tauri.conf.json`, which
|
||||
/// is a build-time mistake rather than a runtime condition, so there is nothing to recover to.
|
||||
/// Commands that are **declared** in ARCHITECTURE §7 and `COMMANDS` but not yet implemented, each
|
||||
/// with the slice that owes it.
|
||||
///
|
||||
/// `COMMANDS` is a bare string array the frontend types its wrappers against, and nothing tied it
|
||||
/// to what is actually registered — so for four stages it listed names that would have failed at
|
||||
/// 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"),
|
||||
("health_run", "Phase 3 — Code Health"),
|
||||
("health_fix", "Phase 3 — Code Health"),
|
||||
("pip_upgrade", "Phase 3 P1 — pip upkeep"),
|
||||
("logs_tail", "M3 — needs the logging subsystem"),
|
||||
];
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
#[allow(
|
||||
clippy::expect_used,
|
||||
@@ -54,6 +70,7 @@ pub fn run() {
|
||||
commands::snapshot_rollback_preview,
|
||||
commands::snapshot_rollback,
|
||||
commands::report_bug_url,
|
||||
commands::engine_info,
|
||||
commands::index_search,
|
||||
commands::index_refresh,
|
||||
commands::pkg_metadata,
|
||||
@@ -65,3 +82,98 @@ pub fn run() {
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running PipDock");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
/// The handler list, read out of this file's own source.
|
||||
///
|
||||
/// `generate_handler!` is a macro, so there is no runtime list to inspect and no way to ask
|
||||
/// Tauri what it registered. Parsing the source is unlovely but it is the only thing that
|
||||
/// cannot drift from the macro — a hand-maintained duplicate would be one more list to forget.
|
||||
fn registered() -> Vec<String> {
|
||||
let src = include_str!("lib.rs");
|
||||
let start = match src.find("invoke_handler(tauri::generate_handler![") {
|
||||
Some(i) => i,
|
||||
None => panic!("the handler list moved; this test parses it out of the source"),
|
||||
};
|
||||
let end = src[start..].find("])").expect("the handler list is closed") + start;
|
||||
src[start..end]
|
||||
.split("commands::")
|
||||
.skip(1)
|
||||
.filter_map(|rest| rest.split(',').next())
|
||||
.map(|name| name.trim().to_owned())
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The names the frontend types its wrappers against.
|
||||
/// The apostrophe that quotes each entry in the TS array.
|
||||
const QUOTE: char = 0x27 as char;
|
||||
|
||||
fn declared() -> Vec<String> {
|
||||
let src = include_str!("../../ui/src/ipc/index.ts");
|
||||
let start = src
|
||||
.find("export const COMMANDS = [")
|
||||
.expect("COMMANDS exists");
|
||||
let end = src[start..].find("] as const").expect("COMMANDS is closed") + start;
|
||||
src[start..end]
|
||||
.lines()
|
||||
.filter_map(|l| l.trim().strip_prefix(QUOTE))
|
||||
.filter_map(|l| l.split(QUOTE).next())
|
||||
.map(str::to_owned)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_declared_command_is_registered_or_owed() {
|
||||
// The failure this catches: `COMMANDS` listed 32 names while 19 were registered, so a
|
||||
// wrapper for any of the other 13 typechecked and then failed at runtime — in front of a
|
||||
// user, on a command that looked implemented.
|
||||
let registered = registered();
|
||||
let owed: Vec<&str> = super::NOT_YET.iter().map(|(n, _)| *n).collect();
|
||||
|
||||
let ghosts: Vec<&String> = declared()
|
||||
.iter()
|
||||
.filter(|c| !registered.contains(c) && !owed.contains(&c.as_str()))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>()
|
||||
.leak()
|
||||
.iter()
|
||||
.collect();
|
||||
assert!(
|
||||
ghosts.is_empty(),
|
||||
"declared in COMMANDS but neither registered nor listed in NOT_YET: {ghosts:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_registered_command_is_declared() {
|
||||
// The other direction: a command Tauri answers that the frontend has no wrapper for is a
|
||||
// surface nobody documented, and ARCHITECTURE §7 says a command not in its table does not
|
||||
// exist.
|
||||
let declared = declared();
|
||||
let undeclared: Vec<String> = registered()
|
||||
.into_iter()
|
||||
.filter(|c| !declared.contains(c))
|
||||
.collect();
|
||||
assert!(
|
||||
undeclared.is_empty(),
|
||||
"registered but missing from COMMANDS and ARCHITECTURE §7: {undeclared:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nothing_is_owed_that_already_exists() {
|
||||
// A stale `NOT_YET` entry is worse than none: it says a command is missing while the
|
||||
// frontend is already calling it.
|
||||
let registered = registered();
|
||||
let stale: Vec<&str> = super::NOT_YET
|
||||
.iter()
|
||||
.map(|(n, _)| *n)
|
||||
.filter(|n| registered.iter().any(|r| r == n))
|
||||
.collect();
|
||||
assert!(
|
||||
stale.is_empty(),
|
||||
"NOT_YET lists commands that exist: {stale:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
+15
-2
@@ -1,4 +1,4 @@
|
||||
import { useEffect } from 'react'
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { NAV_KEYS } from '@/components/nav'
|
||||
@@ -58,11 +58,24 @@ export function App() {
|
||||
const confirmUninstall = usePlanStore((s) => s.confirmUninstall)
|
||||
const resetPlan = usePlanStore((s) => s.reset)
|
||||
const guardOpen = planPhase === 'guard' && guard !== null
|
||||
const mainRef = useRef<HTMLElement>(null)
|
||||
|
||||
useEffect(() => {
|
||||
void checkConsent()
|
||||
}, [checkConsent])
|
||||
|
||||
// UI-SPEC §8's "full keyboard traversal": after Ctrl+3 the focus was still on whatever the user
|
||||
// last clicked, so the next Tab resumed in the old screen and a screen reader announced nothing.
|
||||
// Moving it to the new screen's heading is the smallest thing that makes the shortcut complete.
|
||||
// `key={nav}` on <main> forces a remount, so this fires on every change rather than only the
|
||||
// first — and the heading takes `tabIndex={-1}` from the CSS-free `[tabindex]` below.
|
||||
useEffect(() => {
|
||||
const heading = mainRef.current?.querySelector('h1')
|
||||
if (heading === null || heading === undefined) return
|
||||
heading.setAttribute('tabindex', '-1')
|
||||
heading.focus()
|
||||
}, [nav])
|
||||
|
||||
// UI-SPEC §8: Ctrl+1..8 select tabs, positionally over NAV_KEYS.
|
||||
useEffect(() => {
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
@@ -117,7 +130,7 @@ export function App() {
|
||||
{/* Each screen owns its own scroll container. A virtualizer needs a scroll element it
|
||||
can observe, and nesting one inside an already-scrolling <main> gives two scrollbars
|
||||
and an outer one whose content is already the virtualizer's full height. */}
|
||||
<main className="flex min-w-0 flex-1 flex-col overflow-hidden">
|
||||
<main key={nav} ref={mainRef} className="flex min-w-0 flex-1 flex-col overflow-hidden">
|
||||
{PANEL_PHASES.has(planPhase) ? (
|
||||
<PdPlanPanel
|
||||
onFinished={() => {
|
||||
|
||||
@@ -183,6 +183,16 @@ export type EngineId =
|
||||
| 'pip'
|
||||
| 'uv';
|
||||
|
||||
/** Availability and version of an engine for a given environment. */
|
||||
export interface EngineInfo {
|
||||
/** False means the binary or module could not be found (`PD-ENG-001`). */
|
||||
available: boolean;
|
||||
/** Which engine this describes. */
|
||||
id: EngineId;
|
||||
/** Reported version, absent when the engine is not available. */
|
||||
version?: string | null;
|
||||
}
|
||||
|
||||
/** How an environment was discovered. Surfaced as the source chip in the Environments screen. */
|
||||
export type EnvSource =
|
||||
| 'registry'
|
||||
|
||||
@@ -22,6 +22,7 @@ import type {
|
||||
EngineId,
|
||||
EnvSource,
|
||||
Diff,
|
||||
EngineInfo,
|
||||
ExecutionSummary,
|
||||
FlowStep,
|
||||
GuardReport,
|
||||
@@ -331,6 +332,15 @@ export interface BugReportLink {
|
||||
export const reportBugUrl = (env?: PyEnv, code?: string): Promise<BugReportLink> =>
|
||||
invoke('report_bug_url', { env: env ?? null, code: code ?? null })
|
||||
|
||||
/**
|
||||
* Version and availability for **both** engines.
|
||||
*
|
||||
* Both, because Settings shows a version beside each radio — asking about the configured one would
|
||||
* leave the other blank until it was picked. Takes a `PyEnv` because `Engine::info` does: pip's
|
||||
* version comes from `<python> -m pip --version`, so there is no env-free answer.
|
||||
*/
|
||||
export const engineInfo = (env: PyEnv): Promise<EngineInfo[]> => invoke('engine_info', { env })
|
||||
|
||||
/**
|
||||
* Subscribe to execution progress. Returns the unlisten function.
|
||||
*
|
||||
|
||||
@@ -240,7 +240,9 @@
|
||||
"stale": "cached — could not refresh"
|
||||
},
|
||||
"offline": "OFFLINE",
|
||||
"offlineDetail": "No connection. Search still works from the local index; installing and metadata do not."
|
||||
"offlineDetail": "No connection. Search still works from the local index; installing and metadata do not.",
|
||||
"idle": "search PyPI for something to install",
|
||||
"idleHint": "Start typing a package name. Results come from the local index, so this works offline."
|
||||
},
|
||||
"settings": {
|
||||
"title": "Settings",
|
||||
|
||||
@@ -220,7 +220,9 @@
|
||||
"stale": "đã lưu — không làm mới được"
|
||||
},
|
||||
"offline": "NGOẠI TUYẾN",
|
||||
"offlineDetail": "Không có kết nối. Tìm kiếm vẫn chạy từ danh mục cục bộ; cài đặt và metadata thì không."
|
||||
"offlineDetail": "Không có kết nối. Tìm kiếm vẫn chạy từ danh mục cục bộ; cài đặt và metadata thì không.",
|
||||
"idle": "tìm trên PyPI thứ bạn muốn cài",
|
||||
"idleHint": "Hãy gõ tên gói. Kết quả lấy từ danh mục cục bộ, nên vẫn chạy khi ngoại tuyến."
|
||||
},
|
||||
"settings": {
|
||||
"title": "Cài đặt",
|
||||
|
||||
@@ -128,6 +128,13 @@ export function PdSearch() {
|
||||
<PdEmptyState message={t('search.noResults', { query })} hint={t('search.noResultsHint')} />
|
||||
) : null}
|
||||
|
||||
{/* Before anything is typed. UI-SPEC §7 asks for "one mono glyph + one sentence + one
|
||||
action" on every empty surface, and this one rendered a bare empty list — the first
|
||||
thing a user sees on the screen, saying nothing. */}
|
||||
{query.trim() === '' && ready ? (
|
||||
<PdEmptyState message={t('search.idle')} hint={t('search.idleHint')} />
|
||||
) : null}
|
||||
|
||||
<ul className="mt-3 min-h-0 flex-1 space-y-1 overflow-auto">
|
||||
{hits.map((hit) => {
|
||||
const have = installed.get(hit.name)
|
||||
|
||||
Reference in new issue
Block a user