Files pane
- F16: a drag-out released back inside the app no longer re-imports its own
staged copy over the container original. An in-flight flag (cleared from the
drag plugin's `onEvent` channel, with a watchdog) suppresses the drop and the
"Drop files into …" hint, and an exact staged-path filter is the second line
of defence — the `path|size|modified` cache could otherwise write a
minutes-old snapshot over a file an agent had since rewritten.
- F17: a slow upload/rename no longer yanks the user back to the directory the
operation started in. Every operation captures its target path and re-lists
only if the user is still there; failures go to the toast host either way.
- The grid keeps keyboard focus. Roving tabindex (one tab stop, not one per
row) plus focus restore after navigation, rename commit/cancel and Escape.
- Transient failures now surface in `ToastHost` (z-[60], persistent aria-live)
instead of a `role="alert"` 300 rows down a scroller or behind a modal
overlay. The inline error is kept only for the listing failure.
- `navigate` is sequenced by generation; "Save to host…" sets `busy`.
- Grid a11y: column headers, a text affordance for folder vs file, a live
region that is mounted empty and announces completion, Label-in-Name fixed.
- FileViewerModal: the blob URL is released only once its replacement exists;
the preview is a focusable, named, scrollable region.
Native drop routing
- New `lib/dropTarget.ts`: the hit test now refuses a drop while any
`[aria-modal="true"]` dialog or `[data-blocks-drop]` overlay is up, and
checks z-order where the environment can answer it. Shared by FilesTab and
TerminalView; App's shutdown overlay opts in.
Disk
- A partially failed reclaim says so in words ("… — 2 of 5 failed"), not by hue
alone.
- The scan/reclaim race is closed: every mutation retires an in-flight scan, so
a scan can no longer repaint a pre-reclaim report plus a clickable plan of
objects that are gone. Scan is disabled while working; the status is a live
region; a failed destructive action keeps its dialog open and reports there.
- The "unknown" layer count gets a screen-reader fallback; `--text-disabled`
no longer carries live information.
Terminal / OAuth
- After the toast is dismissed, a truncated heuristic guess can no longer fill
the slot that an exact OSC 8 or relay URL occupied — the detector remembers
every exact URL and drops any candidate that is a strict prefix of one.
- The prompt is reachable by keyboard: Ctrl+Shift+O jumps to the default
action, Escape dismisses, focus returns to the terminal, and auto-dismiss
holds off while focus is inside. It deliberately does not steal focus.
- UrlToast renders through `ui/Button` and `--shadow-overlay`.
Elsewhere
- AuthBridgeRow: a pushed `auth-bridge-changed` status always outranks an older
awaited toggle result.
- The last two ad-hoc byte formatters route through `lib/formatBytes`.
Contract for the backend agent: `upload_file_to_container` refusing to
overwrite must satisfy `isFileExistsError` in `src/lib/uploadErrors.ts` (marker
`FILE_EXISTS`) and accept an `overwrite` argument; the frontend turns that into
an `ui/Modal` Replace/Skip prompt rather than a raw error string.
Tests: 536 -> 627 passing. `npm run build` and `npx tsc --noEmit` green.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GBq2rGum6GX7xXgsas1fDc
122 lines
5.6 KiB
TypeScript
122 lines
5.6 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { formatBytes, formatBytesCeiling, formatBytesDelta } from "./formatBytes";
|
|
|
|
describe("formatBytes", () => {
|
|
it("defaults to base 1000, because that is what Docker prints", () => {
|
|
// The Disk panel exists to explain `docker system df`, which formats with
|
|
// `units.HumanSize` — base 1000. Showing 26.1 GB against a terminal saying
|
|
// 28.0 GB for the same build cache reads as a bug in the panel.
|
|
expect(formatBytes(28_000_000_000)).toBe("28.0 GB");
|
|
expect(formatBytes(1_000)).toBe("1.0 KB");
|
|
expect(formatBytes(1_500_000)).toBe("1.5 MB");
|
|
expect(formatBytes(12_273_392_374)).toBe("12.3 GB");
|
|
});
|
|
|
|
it("leaves whole bytes without a decimal point", () => {
|
|
expect(formatBytes(0)).toBe("0 B");
|
|
expect(formatBytes(512)).toBe("512 B");
|
|
expect(formatBytes(999)).toBe("999 B");
|
|
});
|
|
|
|
it("reproduces the Project Home convention exactly under `binary`", () => {
|
|
// Three modules import `projects/home/format.ts#formatBytes`, which is now
|
|
// this function. Its output had to be byte-identical or re-pointing it
|
|
// would have quietly changed every file listing in the app.
|
|
expect(formatBytes(1023, { binary: true })).toBe("1023 B");
|
|
expect(formatBytes(1024, { binary: true })).toBe("1.0 KB");
|
|
expect(formatBytes(1024 * 1024, { binary: true })).toBe("1.0 MB");
|
|
expect(formatBytes(1024 * 1024 * 1024, { binary: true })).toBe("1.0 GB");
|
|
expect(formatBytes(1_610_612_736, { binary: true })).toBe("1.5 GB");
|
|
});
|
|
|
|
it("absorbs the last two ad-hoc formatters, behaviour change and all", () => {
|
|
// `UpdateDialog.formatSize` and the inline `toFixed(1)` in
|
|
// `useProjectActions` both divided by 1024 and both stopped at MB. Routing
|
|
// them here is what finally makes this the *only* byte formatter, and it
|
|
// changes two things on purpose — pinned so neither reads as a regression
|
|
// to whoever meets them next.
|
|
//
|
|
// KB gains a decimal, matching every other size in the app:
|
|
expect(formatBytes(512 * 1024, { binary: true })).toBe("512.0 KB");
|
|
// and the ladder no longer bottoms out at a five-digit megabyte count:
|
|
expect(formatBytes(2 * 1024 ** 3, { binary: true })).toBe("2.0 GB");
|
|
// Sub-kilobyte sizes stop rendering as "0 KB", which is what the old
|
|
// `(bytes / 1024).toFixed(0)` said about every release asset under 512 B.
|
|
expect(formatBytes(400, { binary: true })).toBe("400 B");
|
|
});
|
|
|
|
it("reproduces the migration convention exactly by default", () => {
|
|
// `migrationCopy.formatDataSize` is now a call to this, and its output is
|
|
// asserted in MigrateContainerModal.test.tsx.
|
|
expect(formatBytes(41_000_000)).toBe("41.0 MB");
|
|
expect(formatBytes(3_800_000_000)).toBe("3.8 GB");
|
|
});
|
|
|
|
it("labels binary units honestly when asked to", () => {
|
|
expect(formatBytes(1024, { binary: true, iec: true })).toBe("1.0 KiB");
|
|
expect(formatBytes(1024 ** 3, { binary: true, iec: true })).toBe("1.0 GiB");
|
|
});
|
|
|
|
it("climbs to TB rather than showing five-digit gigabytes", () => {
|
|
expect(formatBytes(2_500_000_000_000)).toBe("2.5 TB");
|
|
});
|
|
|
|
it("promotes the unit when rounding lands on a whole step", () => {
|
|
// `toFixed` runs after the divide loop, so a value just under a boundary
|
|
// rounds up into a unit the loop had already ruled out. This is the app's
|
|
// only byte formatter and the panel is full of near-boundary sizes.
|
|
expect(formatBytes(999_999)).toBe("1.0 MB");
|
|
expect(formatBytes(999_999_999)).toBe("1.0 GB");
|
|
expect(formatBytes(999_999_999_999)).toBe("1.0 TB");
|
|
expect(formatBytes(1_048_575, { binary: true })).toBe("1.0 MB");
|
|
|
|
// Just below the rounding threshold it must NOT promote.
|
|
expect(formatBytes(999_949)).toBe("999.9 KB");
|
|
expect(formatBytes(999_400, { precision: 0 })).toBe("999 KB");
|
|
|
|
// The top unit has nowhere to go: it renders a whole step rather than
|
|
// running off the end of the unit array.
|
|
expect(formatBytes(999_999_999_999_999_999)).toBe("1000.0 PB");
|
|
});
|
|
|
|
it("renders an em dash for a size the daemon did not compute", () => {
|
|
// Docker reports -1 for "not calculated" on shared sizes and volume ref
|
|
// counts. `NaN GB` in the middle of a table is worse than nothing.
|
|
expect(formatBytes(-1)).toBe("—");
|
|
expect(formatBytes(NaN)).toBe("—");
|
|
expect(formatBytes(Infinity)).toBe("—");
|
|
});
|
|
|
|
it("honours a requested precision", () => {
|
|
expect(formatBytes(1_234_567_890, { precision: 2 })).toBe("1.23 GB");
|
|
expect(formatBytes(1_234_567_890, { precision: 0 })).toBe("1 GB");
|
|
});
|
|
});
|
|
|
|
describe("formatBytesDelta", () => {
|
|
it("signs a figure that is being added rather than measured", () => {
|
|
// "Next commit adds +868.0 MB" — the sign is what makes it read as a cost
|
|
// about to be incurred rather than a size already on disk.
|
|
expect(formatBytesDelta(868_000_000)).toBe("+868.0 MB");
|
|
expect(formatBytesDelta(0)).toBe("+0 B");
|
|
});
|
|
|
|
it("does not sign an unknown", () => {
|
|
expect(formatBytesDelta(-1)).toBe("—");
|
|
});
|
|
});
|
|
|
|
describe("formatBytesCeiling", () => {
|
|
it("says 'up to', because a compaction's yield is a bound not a promise", () => {
|
|
// Every other figure in the Disk panel is measured. This one cannot be
|
|
// known until the rewrite runs, and rendering it through a separate
|
|
// function is what stops it being read as a guarantee.
|
|
expect(formatBytesCeiling(5_100_000_000)).toBe("up to 5.1 GB");
|
|
});
|
|
|
|
it("refuses to imply a saving when there is no bound to give", () => {
|
|
expect(formatBytesCeiling(0)).toBe("an unknown amount");
|
|
expect(formatBytesCeiling(-1)).toBe("an unknown amount");
|
|
});
|
|
});
|