Skip to content

extract ~/-expanding expandHome to fileUtils + add HF download --local-dir / --ignore flags#526

Merged
atomantic merged 4 commits into
mainfrom
extract-expandhome-helper
May 29, 2026
Merged

extract ~/-expanding expandHome to fileUtils + add HF download --local-dir / --ignore flags#526
atomantic merged 4 commits into
mainfrom
extract-expandhome-helper

Conversation

@atomantic

Copy link
Copy Markdown
Owner

Summary

  • expandHome extracted to server/lib/fileUtils.js. The same ~/foo → absolute helper was inlined in server/lib/mediaModels.js and server/services/referenceRepos.js. Consolidated into one shared export and added a typeof p !== 'string' guard so non-string input falls through instead of throwing on .startsWith (the old mediaModels copy would have thrown). Re-exported via the server/lib/index.js barrel and documented in the lib README.
  • scripts/hf_download_repo.py gains --local-dir and --ignore flags. Both are needed by the upcoming HiDream-O1 BYOV installer: --local-dir materializes the repo as a flat copy (HiDream-O1's installer needs a real on-disk repo, not the standard HF cache symlinks); --ignore is a repeatable fnmatch skip pattern so the caller can drop non-weight subdirs (scripts/, docs/) on download.
  • server/lib/runners.test.js backfilled for HIDREAM/QWEN. The runtime module already exports both runner-family ids and the client mirror already carries them — the test was stale and only checked the original four (mflux, flux2, z-image, ernie).

Test plan

  • npm test -- --run lib/runners.test.js services/referenceRepos.test.js lib/mediaModels.test.js lib/index.test.js — 38 passed, 0 failed
  • HiDream-O1 installer end-to-end with --local-dir + --ignore (deferred to the installer PR that exercises these flags)

atomantic added 3 commits May 29, 2026 08:11
…-local-dir` / `--ignore` flags

`expandHome` was duplicated inline in `server/lib/mediaModels.js` and
`server/services/referenceRepos.js`. Moved to `server/lib/fileUtils.js`
and added a `typeof p !== 'string'` guard so a non-string input falls
through instead of throwing on `.startsWith` (the old mediaModels copy
would have thrown). Updated the lib README and barrel-tracked exports.

`scripts/hf_download_repo.py` gains two flags needed by the upcoming
HiDream-O1 BYOV installer:

  --local-dir   materialize the repo as a flat copy at a given path
                instead of relying on the standard HF cache symlinks
                (HiDream-O1's installer needs a real on-disk repo)
  --ignore PAT  fnmatch glob skip filter, repeatable — lets the caller
                drop non-weight subdirs (scripts/, docs/) on download

Also backfills `RUNNER_FAMILIES.HIDREAM` / `QWEN` cases in
`server/lib/runners.test.js` (the runtime module already exports them
and the client mirror already carries them — the test was stale).
…ect unit tests

- voice/config.js `expandPath` is now a re-export of the shared
  `expandHome` (5 caller sites under server/services/voice/ keep
  working via the alias).
- routes/scaffold.js now routes its `~` / `~/` / `~\` handling through
  `expandHome` instead of its own inline branch — required extending
  `expandHome` to also accept `~\` (Windows). Embedded `~` chars
  (e.g. `iCloud~md~obsidian`) still pass through unchanged.
- lib/fileUtils.test.js gets a direct describe block for `expandHome`
  covering bare `~`, `~/foo`, `~\foo`, absolute / relative / empty
  passthrough, non-string passthrough, and the embedded-tilde case.
- runners.test.js now exercises `isQwen` alongside `isHiDream` so the
  predicate pair stays in sync if either is renamed/dropped.
Gemini's /do:review pass against PR #526 surfaced a real-looking latent
bug in `server/services/videoGen/local.js:571` — the `lastImageWillBeUsed`
gate skips the ltx2 FFLF case where both start AND end frames are
provided, leaving the end frame unresized. Out-of-scope from PR #526
(which only touches `expandHome` consolidation + HF download flags), so
filed as a PLAN follow-up for verification + triage instead of applying.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Consolidates ~ / ~/... home-directory expansion into a shared server/lib/fileUtils.js#expandHome, updates server callsites to use it, and extends the HuggingFace prefetch script to support BYOV-style downloads via --local-dir plus selective skipping via --ignore.

Changes:

  • Extract expandHome into server/lib/fileUtils.js and update callsites (voice config path expansion, reference repos, scaffold directory browsing, media models).
  • Add --local-dir and repeatable --ignore glob patterns to scripts/hf_download_repo.py.
  • Refresh runner-family tests to include HIDREAM/QWEN and document expandHome in the lib README.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
server/services/voice/config.js Replaces local expandPath implementation with expandHome alias for shared behavior.
server/services/referenceRepos.test.js Updates fileUtils mock to include expandHome.
server/services/referenceRepos.js Uses shared expandHome from fileUtils instead of inline helper.
server/routes/scaffold.js Uses shared expandHome for ~ path handling in directory browser route.
server/lib/runners.test.js Extends runner-family assertions and predicate tests to HIDREAM/QWEN.
server/lib/README.md Documents expandHome as a fileUtils.js export.
server/lib/mediaModels.js Uses shared expandHome for localPath expansion.
server/lib/fileUtils.test.js Adds unit tests covering expandHome behavior and edge cases.
server/lib/fileUtils.js Introduces expandHome(p) utility.
scripts/hf_download_repo.py Adds --local-dir + --ignore and wires them into download flow.
PLAN.md Adds a planning note about a potential ltx2 FFLF resize issue (out of scope of the code changes).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/hf_download_repo.py Outdated
…ymlinks)

`hf_hub_download(..., local_dir=...)` defaulted to symlinking into the
HF cache on huggingface_hub < 0.23 — which defeats the whole point of
`--local-dir` for BYOV installers like HiDream-O1 that need real files
to walk a flat on-disk repo.

Pass `local_dir_use_symlinks=False` whenever `--local-dir` is set, but
gate it on a one-time `inspect.signature` probe: newer huggingface_hub
deprecated the kwarg (always copies) and eventually removed it, so the
probe keeps us forward-compatible as the FLUX.2 venv rolls upstream.
@atomantic atomantic merged commit b516f35 into main May 29, 2026
2 checks passed
@atomantic atomantic deleted the extract-expandhome-helper branch May 29, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants