web: show per-visit changes and last-visit summary
Each visit's This run pane reports its own recorded capture: the File changes status line (with skipped/omitted counts and diagnostic) and its Changed files list with parseable stats. The Summary aggregate now keeps each path's last recorded step rather than summing visits, and is only rendered for a succeeded run; a failed run keeps its evidence in the visit panes. This is a deliberate divergence from Android, noted in R4.
This commit is contained in:
+53
-37
@@ -1,6 +1,6 @@
|
||||
// Pure, DOM-free logic for the run summary's Changes section and its diff
|
||||
// viewer, ported from the Android client so the browser says and shows exactly
|
||||
// the same things:
|
||||
// Pure, DOM-free logic for the run summary's final-state Changes section and its
|
||||
// diff viewer, ported from the Android client so the browser says and shows
|
||||
// exactly the same things (the aggregate is last-visit-wins rather than a sum):
|
||||
// ui/changes/RunChanges.kt changeKind, changeKindLabel, parseUnifiedPatch,
|
||||
// runChanges, runChangesHeader, runChangesNote,
|
||||
// changesListSummary, noChangeDetail,
|
||||
@@ -249,14 +249,27 @@ export function gutterText(value, width) {
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Aggregates a run's stage steps into its Changes state. Pure and total over its
|
||||
* input: a null `file_changes` on a step is a historical (or non-capturing) step
|
||||
* and contributes nothing (it is never "no changes"); a present capture with no
|
||||
* files is a real, observed no-change. Files are keyed by path and keep
|
||||
* Whether the Summary tab may present the run-wide aggregated Changes section.
|
||||
* The operator decision is final-state-only: a failed run has no settled final
|
||||
* workspace, so its evidence stays in each visit's own recorded capture. The
|
||||
* Android client shows the aggregate for failed runs too; this is a deliberate
|
||||
* browser divergence, recorded in PARITY.md R4. Pure.
|
||||
*/
|
||||
export function showRunChangesSummary(status) {
|
||||
return str(status).trim().toLowerCase() === "succeeded";
|
||||
}
|
||||
|
||||
/**
|
||||
* Aggregates a run's stage steps into its final-state Changes view. Pure and
|
||||
* total over its input: a null `file_changes` on a step is a historical (or
|
||||
* non-capturing) step and contributes nothing (it is never "no changes"); a
|
||||
* present capture with no files is a real, observed no-change. Steps are read in
|
||||
* numeric sequence order (stable for ties), and files are keyed by path and keep
|
||||
* first-seen order, so a path several steps changed is one entry naming all of
|
||||
* them. Later steps win the kind unless they only say "other", added/removed
|
||||
* line counts sum, binary/truncated are OR'd, before_mode is first-seen and
|
||||
* after_mode last-seen.
|
||||
* them. The last recorded step for a path supplies its kind, patch, added/removed
|
||||
* counts, binary/truncated flags and modes: the summary describes the state the
|
||||
* run left, never a sum of intermediate visits. Run-wide capture counters and
|
||||
* caveats still describe every contributing step.
|
||||
*/
|
||||
export function runChanges(steps) {
|
||||
const entries = new Map();
|
||||
@@ -267,9 +280,14 @@ export function runChanges(steps) {
|
||||
let missingCaptures = 0;
|
||||
let skipped = 0;
|
||||
let omitted = 0;
|
||||
let truncatedSeen = false;
|
||||
const diagnostics = new Set();
|
||||
const orderedSteps = (steps ?? [])
|
||||
.map((step, index) => ({ step, index }))
|
||||
.sort((a, b) => sequenceOf(a.step) - sequenceOf(b.step) || a.index - b.index)
|
||||
.map((entry) => entry.step);
|
||||
|
||||
for (const step of steps ?? []) {
|
||||
for (const step of orderedSteps) {
|
||||
const changes = step?.file_changes;
|
||||
if (changes == null) {
|
||||
if (step?.status === "running" || step?.status === "waiting") stepsPending++;
|
||||
@@ -287,47 +305,39 @@ export function runChanges(steps) {
|
||||
for (const file of changes.files ?? []) {
|
||||
const path = str(file?.path);
|
||||
if (path.trim() === "") continue;
|
||||
if (file?.truncated === true) truncatedSeen = true;
|
||||
const kind = changeKind(file?.kind);
|
||||
const parsed = parseUnifiedPatch(file?.patch);
|
||||
const existing = entries.get(path);
|
||||
const mergedSteps = existing ? [...existing.steps] : [];
|
||||
if (!mergedSteps.includes(stage)) mergedSteps.push(stage);
|
||||
const patchParts = [];
|
||||
if (existing && existing.patch != null) patchParts.push(existing.patch);
|
||||
if (typeof file?.patch === "string" && file.patch.trim() !== "") patchParts.push(file.patch);
|
||||
const joinedPatch = patchParts.join("\n");
|
||||
// The last recorded step wins every per-file fact: the summary is the
|
||||
// final state, not an accumulation of the visits on the way there.
|
||||
entries.set(path, {
|
||||
path,
|
||||
// A later step wins the kind: it is the observed state the run left.
|
||||
kind: existing == null || kind !== ChangeKind.Other ? kind : existing.kind,
|
||||
added: (existing?.added ?? 0) + parsed.added,
|
||||
removed: (existing?.removed ?? 0) + parsed.removed,
|
||||
binary: existing?.binary === true || file?.binary === true,
|
||||
truncated: existing?.truncated === true || file?.truncated === true,
|
||||
// Keep the first-seen before-mode and the last-seen after-mode, so the
|
||||
// pair describes the run's net effect on the file.
|
||||
beforeMode: existing && existing.beforeMode != null ? existing.beforeMode : nullable(file?.before_mode),
|
||||
afterMode: file?.after_mode != null ? file.after_mode : existing?.afterMode ?? null,
|
||||
kind,
|
||||
added: parsed.added,
|
||||
removed: parsed.removed,
|
||||
binary: file?.binary === true,
|
||||
truncated: file?.truncated === true,
|
||||
beforeMode: nullable(file?.before_mode),
|
||||
afterMode: nullable(file?.after_mode),
|
||||
otherModeChange:
|
||||
existing?.otherModeChange === true ||
|
||||
(file?.before_mode != null &&
|
||||
file?.after_mode != null &&
|
||||
file.before_mode !== file.after_mode &&
|
||||
!file.binary &&
|
||||
parsed.added === 0 &&
|
||||
parsed.removed === 0),
|
||||
file?.before_mode != null &&
|
||||
file?.after_mode != null &&
|
||||
file.before_mode !== file.after_mode &&
|
||||
!file.binary &&
|
||||
parsed.added === 0 &&
|
||||
parsed.removed === 0,
|
||||
steps: mergedSteps,
|
||||
// Preserve every recorded textual patch for a path. A file may be
|
||||
// changed by several stages, and retaining only the first one would
|
||||
// make the displayed hunks disagree with the aggregate stat.
|
||||
patch: joinedPatch.trim() !== "" ? joinedPatch : null,
|
||||
patch: typeof file?.patch === "string" && file.patch.trim() !== "" ? file.patch : null,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const files = [...entries.values()];
|
||||
const pending = stepsWithChanges === 0 && stepsPending > 0;
|
||||
const totalPartial = partial || files.some((file) => file.truncated) || omitted > 0;
|
||||
const totalPartial = partial || truncatedSeen || omitted > 0;
|
||||
return {
|
||||
files,
|
||||
stepsWithChanges,
|
||||
@@ -538,6 +548,12 @@ export function diffLineClass(kind) {
|
||||
// Internals
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** A step's numeric sequence for ordering, with a missing/invalid value as 0. */
|
||||
function sequenceOf(step) {
|
||||
const value = Number(step?.sequence);
|
||||
return Number.isFinite(value) ? value : 0;
|
||||
}
|
||||
|
||||
/** An integer parsed from a strictly-numeric string, or null. */
|
||||
function intOrNull(text) {
|
||||
return /^[+-]?\d+$/.test(text) ? Number.parseInt(text, 10) : null;
|
||||
|
||||
Reference in New Issue
Block a user