fix(ui): the held-back row named the dependent twice

The preview rendered `scipy requires scipy 1.11.4 requires numpy <1.28.0,>=1.21.6`.
`graph::blockers_for` assembled a whole English sentence into `Blocker.constraint`
while also setting `by`, and `PdConflictRow` passed both to `plan.blocker`, whose
template is `{{by}} requires {{constraint}}`. It has shipped in every release that
had a preview.

The sentence lived in Rust because the CLI prints that field alone, so the CLI was
the one head it looked right in — hard invariant 4 the wrong way round. `Blocker`
now carries `by`, `version` and a bare requirement: the shape its own doc has
described since M1 (`"requests<2.31"`) and the shape `graph::BrokenDependent` has
always used. Each head writes its own sentence — `run.rs` gains `blocker_line`,
mirroring the guard composition a few hundred lines below it, and the GUI
interpolates the same three fields `PdUninstallDialog` already does.

Why the suites were green. `PdPreviewDiff.test.tsx` *did* assert this sentence, and
asserted the correct one, because the fixture's blockers were hand-written to the
documented shape while core had drifted away from it. `fixtures.rs`'s own module doc
says hand-writing that JSON "would defeat the guarantee", and `guard_report()` is
computed for exactly that reason; the plan fixture's blockers were the one exception.
They are computed now, from the same rows — which is also why there are two: `pandas
2.1.4` and `scipy 1.11.4` both exclude 2.5.1, and only one was ever written down. The
force-latest confirm consequently names both and exercises the plural branch of
`forceWarning`, which nothing did before.

`PdConflictRow` gets its first test. Checked against the bug rather than trusted
green: restoring the sentence in core and regenerating the fixture fails it on the
doubled text, and removing it passes again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
poli0981andClaude Opus 5 committed 2026-08-18 09:05:59 +07:00
1 parent 2068f73f6a
commit adaa363f7c
12 files changed
+206 -27

No files matched your search

+18 -2
View File
@@ -649,6 +649,22 @@ fn decide(
out
}
/// One blocker, as a sentence.
///
/// Assembled here because this head is English-only (PRD P0-14) and `plan::Blocker` carries data
/// rather than phrasing (hard invariant 4). The GUI builds the same sentence from `plan.blocker`
/// in its own catalogs; the shape mirrors the guard's, which composes `BrokenDependent` the same
/// way a few hundred lines below.
///
/// No culprit means no culprit: ARCHITECTURE §3 says show the constraint rather than guess.
fn blocker_line(b: &plan::Blocker) -> String {
match (&b.by, &b.version) {
(Some(by), Some(v)) => format!("{by} {v} requires {}", b.constraint),
(Some(by), None) => format!("{by} requires {}", b.constraint),
(None, _) => b.constraint.clone(),
}
}
/// The per-package prompt from CLI-SPEC §4.
fn prompt_decision(held: &plan::HeldBack) -> plan::Decision {
use std::io::Write as _;
@@ -658,7 +674,7 @@ fn prompt_decision(held: &plan::HeldBack) -> plan::Decision {
held.pkg, held.resolved, held.latest
);
for blocker in &held.blockers {
println!(" — {}", blocker.constraint);
println!(" — {}", blocker_line(blocker));
}
print!(" [C]ompatible (default) [S]kip [F]orce latest: ");
let _ = std::io::stdout().flush();
@@ -716,7 +732,7 @@ fn print_preview(opts: &GlobalOpts, report: &plan::ResolutionReport) {
for h in &report.held_back {
println!(" {:<32} {} (latest {})", h.pkg, h.resolved, h.latest);
for b in &h.blockers {
println!(" {}", b.constraint);
println!(" {}", blocker_line(b));
}
if h.blockers.is_empty() {
// ARCHITECTURE §3: no culprit is invented, and the row says so plainly rather
@@ -19,8 +19,15 @@ expression: out
"description": "The package imposing the constraint, absent when attribution is ambiguous."
},
"constraint": {
"description": "The constraint text, e.g. `\"requests<2.31\"`.",
"description": "The requirement holding the package back, e.g. `\"requests<2.31\"`.\n\n**Data, not a sentence** — hard invariant 4. Until Slice 0 this carried\n`\"scipy 1.11.4 requires numpy <1.28.0,>=1.21.6\"`, a phrase assembled in Rust, which the\nGUI then wrapped in `\"{{by}} requires {{constraint}}\"` and rendered naming the dependent\n**twice**. Only the CLI looked right, because it prints this field alone. The shape here\nnow matches `BrokenDependent.constraint`, which the guard dialog has always composed\ncorrectly.",
"type": "string"
},
"version": {
"description": "The installed version of [`Self::by`], when the probe knew it.\n\nSplit out for the same reason [`crate::graph::BrokenDependent`] splits it: the two heads\nphrase this differently — the CLI writes `scipy 1.11.4 requires …` itself, the GUI\ninterpolates `plan.blocker` — and neither can un-join a string Rust joined for it.",
"type": [
"string",
"null"
]
}
},
"required": [
@@ -19,8 +19,15 @@ expression: out
"description": "The package imposing the constraint, absent when attribution is ambiguous."
},
"constraint": {
"description": "The constraint text, e.g. `\"requests<2.31\"`.",
"description": "The requirement holding the package back, e.g. `\"requests<2.31\"`.\n\n**Data, not a sentence** — hard invariant 4. Until Slice 0 this carried\n`\"scipy 1.11.4 requires numpy <1.28.0,>=1.21.6\"`, a phrase assembled in Rust, which the\nGUI then wrapped in `\"{{by}} requires {{constraint}}\"` and rendered naming the dependent\n**twice**. Only the CLI looked right, because it prints this field alone. The shape here\nnow matches `BrokenDependent.constraint`, which the guard dialog has always composed\ncorrectly.",
"type": "string"
},
"version": {
"description": "The installed version of [`Self::by`], when the probe knew it.\n\nSplit out for the same reason [`crate::graph::BrokenDependent`] splits it: the two heads\nphrase this differently — the CLI writes `scipy 1.11.4 requires …` itself, the GUI\ninterpolates `plan.blocker` — and neither can un-join a string Rust joined for it.",
"type": [
"string",
"null"
]
}
},
"required": [
+21 -5
View File
@@ -120,7 +120,7 @@ fn pin_list() -> Vec<Pin> {
/// subject. `Downgrade` in particular: it is the variant UI-SPEC had no section for, and a
/// compatible resolve produces it routinely.
fn flow_step() -> crate::flow::FlowStep {
use crate::plan::{Blocker, Change, ChangeKind, HeldBack, ImpossibleDetail, ResolutionReport};
use crate::plan::{Change, ChangeKind, HeldBack, ImpossibleDetail, ResolutionReport};
let pkg = |n: &str| PkgName::parse(n).unwrap_or_else(|e| panic!("fixture name {n:?}: {e:?}"));
let change = |name: &str, from: Option<&str>, to: &str, kind: ChangeKind| Change {
@@ -144,10 +144,7 @@ fn flow_step() -> crate::flow::FlowStep {
pkg: pkg("numpy"),
resolved: Version("1.26.4".to_owned()),
latest: Version("2.5.1".to_owned()),
blockers: vec![Blocker {
by: Some(pkg("scipy")),
constraint: "numpy<1.28.0,>=1.21.6".to_owned(),
}],
blockers: numpy_blockers(),
}],
impossible: Some(ImpossibleDetail {
explanation: "no version of oldlib is compatible with python 3.12".to_owned(),
@@ -200,6 +197,25 @@ fn execution_summary() -> crate::plan::ExecutionSummary {
}
}
/// Why `numpy` cannot go to `latest`, from the same scenario.
///
/// **Computed, not written**, for the reason [`guard_report`] gives and for one more, learned the
/// expensive way. The hand-written version of this list carried a `constraint` of
/// `"numpy<1.28.0,>=1.21.6"` — the shape [`crate::plan::Blocker`]'s own doc describes — while
/// `blockers_for` had drifted to emitting a whole English sentence. So `PdPreviewDiff` asserted a
/// row the application could not actually render, `PdConflictRow` wrapped the real value in
/// `plan.blocker` and named the dependent twice, and every suite stayed green. Slice 0.
///
/// Two blockers come back rather than the one that was written here: `scipy` and `pandas` both
/// declare specifiers that exclude 2.5.1, which is the same fact about the same rows that makes
/// this set worth using for the guard.
fn numpy_blockers() -> Vec<crate::plan::Blocker> {
let target = crate::compat::PyVersion::parse("2.5.1")
.unwrap_or_else(|e| panic!("fixture version \"2.5.1\": {e:?}"));
let numpy = PkgName::parse("numpy").unwrap_or_else(|e| panic!("fixture name \"numpy\": {e:?}"));
crate::graph::ReverseDeps::build_for(&pkg_list(), "3.12.4").blockers_for(&numpy, &target)
}
/// What `uninstall_guard` returns for removing `numpy` from the same scenario.
///
/// **Computed, not written.** Running the real graph over the real `pkg_list()` is what makes this
+16 -12
View File
@@ -269,13 +269,13 @@ impl ReverseDeps {
continue;
}
if !satisfies(&req.constraint, target) {
let named = match self.versions.get(dependent) {
Some(v) => format!("{dependent} {v}"),
None => dependent.to_string(),
};
// Three fields, no phrasing: `by` and `version` name the culprit and
// `constraint` is the requirement it declared, exactly as `breaking_dependents`
// fills `BrokenDependent`. Each head writes its own sentence.
out.push(Blocker {
by: Some(dependent.clone()),
constraint: format!("{named} requires {} {}", pkg, req.constraint),
version: self.versions.get(dependent).cloned(),
constraint: format!("{pkg}{}", req.constraint),
});
}
}
@@ -613,11 +613,12 @@ mod tests {
1,
"anyio permits 1.0.9 and must not be named"
);
// Three fields, no phrasing (hard invariant 4). The CLI joins them with "requires" and
// the GUI interpolates `plan.blocker`; a sentence built here is one both heads then have
// to un-build, which is how the preview came to name the dependent twice.
assert_eq!(blockers[0].by.as_ref(), Some(&pkg("httpx")));
assert_eq!(
blockers[0].constraint,
"httpx 0.23.0 requires httpcore >=0.15.0,<0.16.0"
);
assert_eq!(blockers[0].version.as_deref(), Some("0.23.0"));
assert_eq!(blockers[0].constraint, "httpcore>=0.15.0,<0.16.0");
}
#[test]
@@ -649,12 +650,15 @@ mod tests {
let g = ReverseDeps::build_for(&dists, "3.12.10");
let found = g.blockers_for(&pkg("numpy"), &latest);
let named: Vec<&str> = found.iter().map(|b| b.constraint.trim()).collect();
let named: Vec<(Option<&str>, &str)> = found
.iter()
.map(|b| (b.version.as_deref(), b.constraint.trim()))
.collect();
assert_eq!(
named,
[
"pandas 2.1.4 requires numpy <2,>=1.26.0",
"statsmodels 0.14.1 requires numpy <2,>=1.18",
(Some("2.1.4"), "numpy<2,>=1.26.0"),
(Some("0.14.1"), "numpy<2,>=1.18"),
],
"only the branches in force on 3.12 may be named"
);
+16 -1
View File
@@ -86,7 +86,21 @@ pub struct Blocker {
/// The package imposing the constraint, absent when attribution is ambiguous.
#[serde(skip_serializing_if = "Option::is_none")]
pub by: Option<PkgName>,
/// The constraint text, e.g. `"requests<2.31"`.
/// The installed version of [`Self::by`], when the probe knew it.
///
/// Split out for the same reason [`crate::graph::BrokenDependent`] splits it: the two heads
/// phrase this differently — the CLI writes `scipy 1.11.4 requires …` itself, the GUI
/// interpolates `plan.blocker` — and neither can un-join a string Rust joined for it.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub version: Option<String>,
/// The requirement holding the package back, e.g. `"requests<2.31"`.
///
/// **Data, not a sentence** — hard invariant 4. Until Slice 0 this carried
/// `"scipy 1.11.4 requires numpy <1.28.0,>=1.21.6"`, a phrase assembled in Rust, which the
/// GUI then wrapped in `"{{by}} requires {{constraint}}"` and rendered naming the dependent
/// **twice**. Only the CLI looked right, because it prints this field alone. The shape here
/// now matches `BrokenDependent.constraint`, which the guard dialog has always composed
/// correctly.
pub constraint: String,
}
@@ -915,6 +929,7 @@ mod tests {
latest: Version("2.32.3".into()),
blockers: vec![Blocker {
by: Some(PkgName::parse("apiclient").unwrap()),
version: None,
constraint: "requests<2.31".into(),
}],
};
+1 -1
View File
@@ -268,7 +268,7 @@ mod tests {
assert!(
held.blockers[0]
.constraint
.contains("httpcore >=0.15.0,<0.16.0")
.contains("httpcore>=0.15.0,<0.16.0")
);
assert!(!report.is_clean(), "a held-back package needs a decision");
}
+82
View File
@@ -0,0 +1,82 @@
/**
* The held-back row — UI-SPEC §4's three-way control, and the blocker sentence under it.
*
* **Why this file exists.** For two releases the preview rendered `scipy requires scipy 1.11.4
* requires numpy <1.28.0,>=1.21.6`: `graph::blockers_for` built a whole English sentence into
* `Blocker.constraint` and this component wrapped it in `plan.blocker` a second time. Neither
* suite could see it. `PdPreviewDiff.test.tsx` asserted the *right* sentence against a fixture
* whose blockers were hand-written to the shape `Blocker`'s own doc describes — a shape core had
* stopped producing — and this component had no test of its own at all. The fixture is computed
* from the real graph now (`fixtures::numpy_blockers`), so the two cannot drift apart again.
*
* The blockers here therefore come from that fixture rather than from literals, for the reason
* `PdUninstallDialog.test.tsx` gives about `GuardReport`.
*/
import { render, screen, within } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import { PdConflictRow } from '@/components/PdConflictRow'
import type { Blocker, FlowStep } from '@/ipc'
import flowStep from '@/test/fixtures/flow_step.json'
const STEP = flowStep as FlowStep
if (!('report' in STEP)) throw new Error('the fixture must be a step carrying a report')
/** The computed blockers holding `numpy` back: `pandas 2.1.4` and `scipy 1.11.4`. */
const BLOCKERS = STEP.report.heldBack?.[0]?.blockers ?? []
function setup(blockers: readonly Blocker[], impossible = false) {
const onChoose = vi.fn()
render(
<ul>
<PdConflictRow
pkg="numpy"
resolved="1.26.4"
latest="2.5.1"
blockers={blockers}
impossible={impossible}
value={undefined}
onChoose={onChoose}
/>
</ul>,
)
return { onChoose }
}
describe('PdConflictRow', () => {
it('names each blocker once, with its version and its constraint', () => {
// The defect this file was written for. `getByText` is exact by default, so a doubled
// dependent name fails here rather than merely looking wrong.
setup(BLOCKERS)
expect(screen.getByText('pandas 2.1.4 requires numpy<2,>=1.26.0')).toBeInTheDocument()
expect(screen.getByText('scipy 1.11.4 requires numpy<1.28.0,>=1.21.6')).toBeInTheDocument()
expect(screen.queryByText(/requires.*requires/)).not.toBeInTheDocument()
})
it('drops the version clause when the probe did not know one', () => {
setup([{ by: 'scipy', constraint: 'numpy<1.28.0,>=1.21.6' }])
expect(screen.getByText('scipy requires numpy<1.28.0,>=1.21.6')).toBeInTheDocument()
})
it('shows an unattributed constraint verbatim rather than inventing a culprit', () => {
// ARCHITECTURE §3: if attribution is ambiguous, show the constraint without a culprit. This
// is also the shape `PdPreviewDiff` synthesizes for an impossible row.
setup([{ constraint: 'no version of oldlib is compatible with python 3.12' }], true)
expect(
screen.getByText('no version of oldlib is compatible with python 3.12'),
).toBeInTheDocument()
})
it('refuses Keep compatible on an impossible row', () => {
// `default_decision(is_impossible = true, …)` returns Skip, so the control mirrors the core
// rather than offering a choice it would refuse to honour.
setup(BLOCKERS, true)
const group = screen.getByRole('radiogroup', { name: 'numpy' })
expect(within(group).getByRole('radio', { name: /keep compatible/i })).toBeDisabled()
})
})
+8 -1
View File
@@ -77,7 +77,14 @@ export function PdConflictRow({
<li key={`${b.by ?? ''}-${b.constraint}-${String(i)}`} className="text-data text-text-dim">
{b.by == null
? b.constraint
: t('plan.blocker', { by: b.by, constraint: b.constraint })}
: t('plan.blocker', {
// Assembled here, from three fields, for the same reason `PdUninstallDialog`
// assembles the guard's: a sentence joined in Rust cannot be un-joined by a
// catalog. Until Slice 0 `constraint` arrived as a whole English phrase and
// this template wrapped it again, naming the dependent twice.
by: b.version == null ? b.by : `${b.by} ${b.version}`,
constraint: b.constraint,
})}
</li>
))}
</ul>
+4 -2
View File
@@ -94,7 +94,7 @@ describe('the 3-way conflict control', () => {
// PRD G2: conflicts are explained in one sentence a user can act on.
setup()
expect(
within(rowFor('numpy')).getByText('scipy requires numpy<1.28.0,>=1.21.6'),
within(rowFor('numpy')).getByText('scipy 1.11.4 requires numpy<1.28.0,>=1.21.6'),
).toBeInTheDocument()
})
@@ -106,7 +106,9 @@ describe('the 3-way conflict control', () => {
expect(onChoose).not.toHaveBeenCalled()
const dialog = within(rowFor('numpy')).getByRole('alertdialog')
expect(within(dialog).getByText(/breaks scipy/)).toBeInTheDocument()
// Both dependents that exclude 2.5.1, from the computed fixture — so this also covers
// the plural branch of `forceWarning`, which nothing else does.
expect(within(dialog).getByText(/breaks pandas, scipy/)).toBeInTheDocument()
fireEvent.click(within(dialog).getByRole('button', { name: 'Force latest' }))
expect(onChoose).toHaveBeenCalledWith('numpy', 'force-latest')
+18 -1
View File
@@ -16,8 +16,25 @@
export interface Blocker {
/** The package imposing the constraint, absent when attribution is ambiguous. */
by?: PkgName | null;
/** The constraint text, e.g. `"requests<2.31"`. */
/**
* The requirement holding the package back, e.g. `"requests<2.31"`.
*
* **Data, not a sentence** — hard invariant 4. Until Slice 0 this carried
* `"scipy 1.11.4 requires numpy <1.28.0,>=1.21.6"`, a phrase assembled in Rust, which the
* GUI then wrapped in `"{{by}} requires {{constraint}}"` and rendered naming the dependent
* **twice**. Only the CLI looked right, because it prints this field alone. The shape here
* now matches `BrokenDependent.constraint`, which the guard dialog has always composed
* correctly.
*/
constraint: string;
/**
* The installed version of [`Self::by`], when the probe knew it.
*
* Split out for the same reason [`crate::graph::BrokenDependent`] splits it: the two heads
* phrase this differently — the CLI writes `scipy 1.11.4 requires …` itself, the GUI
* interpolates `plan.blocker` — and neither can un-join a string Rust joined for it.
*/
version?: string | null;
}
/**
+6
View File
@@ -37,8 +37,14 @@
"resolved": "1.26.4",
"latest": "2.5.1",
"blockers": [
{
"by": "pandas",
"version": "2.1.4",
"constraint": "numpy<2,>=1.26.0"
},
{
"by": "scipy",
"version": "1.11.4",
"constraint": "numpy<1.28.0,>=1.21.6"
}
]