feat(files): copy & duplicate, bulk actions, disk-backed uploads, and an accessible file tree (#1409)

* perf(files): spool uploads to disk instead of buffering in memory

Switch the stack file-explorer upload from multer memoryStorage to
diskStorage and stream the spooled temp file through the file-root
gateway, so an upload is never held fully in RAM. Authorization and
root resolution now run before multer spools, so an unauthorized or
read-only-root request is rejected without writing a temp file, and the
spool is removed on every exit path. The named-volume helper write
verifies the written byte count, since cat cannot report a short write.

* feat(files): copy and duplicate files in the explorer

Add a copy capability to the stack file explorer: a same-folder
Duplicate (auto-suffixed name) and a "Copy to..." destination picker,
on both filesystem and named-volume roots. Copying is within-root,
symlink-leaf-safe, blocks a directory copy into its own subtree, and
refuses to create a protected name (compose/.env) at the stack root
while still allowing a protected file to be duplicated under a new name.

* feat(files): make the file tree keyboard accessible

Bring the stack file explorer tree to the WCAG tree pattern: rows are
treeitems carrying aria-level, aria-selected, and aria-expanded, with a
single roving tabindex and full keyboard navigation (arrow keys,
Home/End, Enter/Space) over a flattened visible-node list that stays in
lockstep with the rendered rows. A polite live region announces the
selected file. No visual change to the tree.

* feat(files): bulk select, delete, move, and download files

Add multi-select to the stack file explorer (checkboxes plus Shift and
Ctrl/Cmd click over the visible order) driving three bulk actions:
delete, move, and download as a streamed .tar.gz. All run within the
active root on both filesystem and named-volume backends, report
per-item results so partial failures surface (with the failed items
kept selected for retry), normalize ancestor/descendant selections
server-side, and cap the archive entry and byte counts before any
bytes are streamed. Protected compose/.env files are excluded from
bulk delete and move but may still be downloaded.

* docs(files): document copy, bulk actions, and keyboard navigation

Add the copy/duplicate and multi-select bulk delete/move/download
sections to the Files & Volumes page, a keyboard-navigation note for the
tree, an updated context-menu reference, and bulk troubleshooting entries.

* fix(files): inline path-injection barriers at the new file-op sinks

CodeQL js/path-injection does not credit the wrapped isPathWithinBase
containment check, so the new copy/bulk/disk-upload flows tripped the
gate. Inline the canonical path.resolve + startsWith barrier at the
realpath sink in resolveSafePathWithin (covers every user-relPath flow)
and confirm the multer spool path resolves within UPLOAD_TMP_DIR before
unlinking it or streaming it onward. Behavior is unchanged; the paths
were already validated.

* fix(files): guard the ancestor-walk realpath sink too

The first barrier covered realpath(target), but the ENOENT ancestor
walk re-derives the path via path.dirname, which static analysis treats
as a fresh tainted value. Add the same inline containment barrier before
that realpath and resolve the root case via the untainted base, so the
only tainted realpath input is one the startsWith check has cleared.
Behavior is unchanged.

* fix(files): resolve the root case off the taint path in the ancestor walk

The compound guard on existing (the same variable as the startsWith
subject) was not credited as a sanitizer. Handle the root case before
the barrier by resolving the untainted base directly, leaving a plain
canonical startsWith guard on the strictly-within ancestor. Behavior is
unchanged.

* fix(files): harden helper-backend bulk download and uploads

Address three issues found in the named-volume (helper) backend:

- Bulk download could send 200 headers before discovering a file the
  helper download path refuses, tearing the archive mid-stream. The
  prewalk now rejects symlinks, non-regular ("other") entries, and
  files over the per-file download cap before any header (400/413).
  FileEntry gains an 'other' type so non-regular entries stay distinct
  from regular files as they pass through the gateway.
- The helper directory listing was fully buffered before the archive
  entry cap could fire. listDir now accepts a limit; the list script
  stops after limit+1 rows and the gateway reports truncation.
- A stdin pipeline error during a helper upload masked the container's
  real nonzero exit code (and its 4xx mapping) as a generic 500. The
  nonzero exit now wins; the masked stream error is logged.

* feat(files): add a New file toolbar button with server-enforced create-only

The stack file explorer could create a folder from a toolbar button but a
new file only from a folder's right-click menu, so a file could not be
created at the stack root at all. Add a New file toolbar button beside New
folder, targeting the current directory.

Creating a file now routes through a new createEmptyStackFile helper that
posts a zero-byte file through the existing upload endpoint with overwrite
off, so the server's exclusive-create path rejects an existing name instead
of clobbering it. A file collision surfaces inline in the dialog; a folder
collision and other failures surface as a toast.

* fix(files): widen the tree row hit area and add horizontal scroll for long names

Right-clicking a file tree row only opened the Sencho context menu when the
click landed on the filename; the rest of the row fell through to the native
browser menu, and long names were truncated with no way to read them.

Make each row span the full pane width (and grow with its content) so the
whole row is the context-menu trigger, and let the tree scroll horizontally
so a long name is reachable instead of clipped. A new opt-in horizontal prop
on ScrollArea adds the styled horizontal scrollbar without clamping content
width.

* docs(files): document the New file button, full-row right-click, and long-name scrolling

* test(files): cover createEmptyStackFile targeting the stack root

Add an API-layer case for the empty-directory (stack root) create path, the
primary reason the New file toolbar button exists, so a regression in the
root-level URL would be caught at unit speed rather than only in e2e.
This commit is contained in:
Anso
2026-06-22 19:33:06 -04:00
committed by GitHub
parent 9480cc98bb
commit 37e6e48b40
26 changed files with 3100 additions and 138 deletions
+55
View File
@@ -430,6 +430,61 @@ test.describe('Stack file explorer: UI lifecycle', () => {
page.locator('span.font-mono').filter({ hasText: /^lifecycle-new-folder$/ }).first(),
).toBeVisible({ timeout: 8_000 });
});
test('the New file toolbar button creates a root-level file', async ({ page }) => {
await page.getByRole('button', { name: 'New file' }).click();
await page.getByLabel('File name').fill('ui-new-file.txt');
await page.getByRole('button', { name: /^create$/i }).click();
await expect(page.getByText(/file created/i).first()).toBeVisible({ timeout: 8_000 });
await expect(
page.locator('span.font-mono').filter({ hasText: /^ui-new-file\.txt$/ }).first(),
).toBeVisible({ timeout: 8_000 });
});
test('creating a duplicate name is blocked and does not overwrite the existing file', async ({ page }) => {
await fs.writeFile(nodePath.join(stackDir(), 'dup-guard.txt'), 'original\n');
await page.reload();
await openFilesTab(page);
await page.getByRole('button', { name: 'New file' }).click();
await page.getByLabel('File name').fill('dup-guard.txt');
await page.getByRole('button', { name: /^create$/i }).click();
await expect(page.getByText(/a file with that name already exists/i)).toBeVisible({ timeout: 8_000 });
// The server rejected the create, so the existing contents are intact.
expect(await fs.readFile(nodePath.join(stackDir(), 'dup-guard.txt'), 'utf-8')).toBe('original\n');
});
test('right-clicking away from the filename still opens the Sencho context menu', async ({ page }) => {
const row = page.locator('[role="treeitem"]').filter({ hasText: 'compose.yaml' }).first();
await expect(row).toBeVisible({ timeout: 8_000 });
const box = await row.boundingBox();
if (!box) throw new Error('no bounding box for the compose.yaml row');
// Right-click near the right edge, well past the filename text: the whole
// row is the trigger, so the Sencho menu (not the native one) must open.
await row.click({ button: 'right', position: { x: box.width - 6, y: box.height / 2 } });
await expect(page.getByText('Rename')).toBeVisible({ timeout: 5_000 });
});
test('a long filename overflows the pane horizontally instead of being clipped', async ({ page }) => {
const longName = 'a-really-long-file-name-that-should-overflow-the-narrow-file-tree-pane.txt';
await fs.writeFile(nodePath.join(stackDir(), longName), '');
await page.reload();
await openFilesTab(page);
await expect(
page.locator('span.font-mono').filter({ hasText: longName }).first(),
).toBeVisible({ timeout: 8_000 });
// The tree's scroll viewport overflows horizontally, so the name is reachable
// by scrolling rather than truncated.
const overflows = await page.getByTestId('file-tree-root-dropzone').evaluate((el) => {
const vp = el.closest('[data-radix-scroll-area-viewport]') as HTMLElement | null;
return vp ? vp.scrollWidth > vp.clientWidth : false;
});
expect(overflows).toBe(true);
});
});
// ---------------------------------------------------------------------------