[GH-ISSUE #4689] [GUI] npm test deletes the person's model folder: models-folder.test.mjs removes <drive>\Strata #2140

Closed
opened 2026-11-04 01:57:00 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @vsp99h on GitHub (Oct 30, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/4689

Area

[GUI] (the desktop app — the apps/host test suite)

Desktop app, Terminal or source?

Source (a checkout, npm test in apps/host)

What happened

I ran the app-host test suite in a checkout that had been used for real work. One test deleted
files from my real model folder, C:\Strata\Data\models\:

Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf     (first of four shards)   — gone
mmproj-Qwen3.8-Flash-Next-BF16.gguf                                            — gone

The remaining shards, packs\ and mtp\ are still on disk (112.9 GB). The model is now
missing_or_invalid in strata models list --installed, and the picture reader cannot start.
Expected: a test that only plans a models-folder change should not touch the filesystem outside
its own fixture folder.

The test's own failure line names the folder it attacked:

test at tests\models-folder.test.mjs:71:1
✖ a whole drive is planned as <drive>\Strata, shown as <drive>\Strata\Models (6.413ms)
  Error: EPERM, Permission denied: \\?\C:\Strata '\\?\C:\Strata'
      at rmSync (node:fs:1221:18)
      at TestContext.<anonymous> (…/apps/host/tests/models-folder.test.mjs:78:3)

The code, apps/host/tests/models-folder.test.mjs:71-79 (git blame: every line is 1d6a04012,
2026-10-20, "Settings > Storage: Models folder card … tests"; unchanged since, shipped in every tag
from v0.2.2 to v0.2.8):

test('a whole drive is planned as <drive>\\Strata, shown as <drive>\\Strata\\Models', async t => {
  const f = fixture(t);
  const root = f.root.slice(0, f.root.indexOf(process.platform === 'win32' ? '\\' : '/') + 1) || '/';
  const plan = await f.native.planModelsFolder(root);
  assert.equal(plan.wholeDrive, true);
  assert.equal(plan.folder, join(root, 'Strata'));
  assert.equal(plan.shown, join(root, 'Strata', 'Models'));
  rmSync(join(root, 'Strata'), { recursive: true, force: true });      // ← line 78
});

f.root is realpathSync(mkdtempSync(join(tmpdir(), 'strata-mfolder-'))), so on Windows root
becomes the drive root of %TEMP% — C:\ here — and join(root, 'Strata') is C:\Strata.
That is exactly the path the Storage card produces when a person points Strata at a whole drive,
which is the case this test exists to cover. The fixture only creates <f.root>\install, \data,
\old, \new, and control.planModelsMove is a stub, so the test never creates anything at
that path
: line 78 deletes whatever the person keeps there. force: true hides the case where
the folder does not exist, which is why this passes silently on machines whose models live on
another drive or in Documents\Strata.

This is the only such call in the suite. I went through every rmSync( in apps/host/tests
(about a hundred): each one removes a folder made by mkdtempSync in the same test, including
line 53 of this very file (rmSync(root, …), its own fixture). Line 78 is the only place where the
path is derived from something outside the fixture, and it is derived from the drive root.

Two things make it worse than a normal bad test:

  • AGENTS.md ("tests run with npm test in apps/host") and CONTRIBUTING.md send contributors
    and CI straight at the command that triggers it.
  • scripts/test.mjs states the opposite intent in its header — "Every test file runs against
    scratch copies of the per-user places the host writes to (the owner's real profile is never
    touched)"
    — and 535cacb0 (2026-10-24) redirected LOCALAPPDATA, APPDATA, XDG_*,
    STRATA_COMPONENTS_DIR and STRATA_SETTINGS_FILE into a scratch folder. Deriving a drive root
    inside the test walks straight past all of that.

On Linux and macOS root is /, so the target is /Strata, which normally does not exist and
force: true makes it a no-op — the damage is effectively Windows-only, where %TEMP% and the
model folder usually share C:.

Smallest steps or command that reproduce it

On a Windows machine where the Strata data folder is <drive>\Strata (Settings > Storage > a whole
drive) and %TEMP% is on that same drive:

cd <checkout>\apps\host
npm ci
npm test

or just the one file:

node --test tests\models-folder.test.mjs

The run reports the failure rmSync gives when it cannot finish, and the files under
<drive>\Strata are already gone or marked for deletion by then.

Reproduction status

Reproduced locally

Strata version

commit 529b25c3 (merge of origin/main = 870aedd9, v0.2.8). apps/host/tests/models-folder.test.mjs
in that tree is byte-identical to origin/main (SHA-256 starts 3033925CD34FF67E).

Graphics card, memory and system

RTX 5080 16 GB · 93 GB RAM · Windows 11 Pro 10.0.26300

Model, size and settings

Qwen3.8-Flash-Next UD Q4_K_XL · 524 288 context · pictures on · model files in C:\Strata\Data

Suggested fix

The plan creates nothing, so the cleanup line can simply go, and the "whole drive" case can be
faked inside the fixture:

  const root = join(f.root, 'drive') + sep;          // a fake drive root, inside the fixture
  ...
  assert.equal(plan.folder, join(root, 'Strata'));
  assert.equal(plan.shown, join(root, 'Strata', 'Models'));
  // no rmSync: nothing was created by a plan

If the real drive root must be kept for fidelity, add a guard that fails loudly instead of
deleting — assert.ok(join(root, 'Strata').startsWith(f.root)) before any removal — or skip the
test when <drive>\Strata already exists.

Limits of what I verified

  • Observed: the test ran, rmSync named \\?\C:\Strata, and the two files above disappeared
    from the real folder between a run at 12:14 (folder complete, the model reported ready by
    GET /api/native) and 12:56 (folder short of those two files).
  • Observed, and the only reason more survived: my shell runs under a filesystem sandbox that
    denies writes outside the workspace. It stopped the recursive walk at the directory level, so the
    tree itself survived. The two files that did get removed were the two held open by the running
    engine (strata.exe, --native C:\Strata\Data\models\unsloth-UD-Q4_K_XL\Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf)
    and by the picture reader (strata-vision.exe, --mmproj C:\Strata\Data\models\mmproj-Qwen3.8-Flash-Next-BF16.gguf),
    so Windows kept them as delete-pending and the serving model kept answering.
  • Not tested, stated as reasoning only: without that sandbox I expect the recursive delete to
    take the whole <drive>\Strata tree (weights, packs, mtp). I did not run it unsandboxed and will
    not.
  • Not run: the rest of the suite after this; the fix above.

Search before filing

I searched the tracker (gh search issues --repo Niko1221/Strata) for models-folder, rmSync
and test deletes model folder: rmSync and the last query return nothing, and the models-folder
hits are unrelated. The closest in subject are #4089 (deleting a model stops at a read-only folder)
and #3521 (a Terminal discovery test reading the checkout's own run configs) — different problems.

Originally created by @vsp99h on GitHub (Oct 30, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/4689 ### Area [GUI] (the desktop app — the `apps/host` test suite) ### Desktop app, Terminal or source? Source (a checkout, `npm test` in `apps/host`) ### What happened I ran the app-host test suite in a checkout that had been used for real work. One test deleted files from my **real** model folder, `C:\Strata\Data\models\`: ``` Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf (first of four shards) — gone mmproj-Qwen3.8-Flash-Next-BF16.gguf — gone ``` The remaining shards, `packs\` and `mtp\` are still on disk (112.9 GB). The model is now `missing_or_invalid` in `strata models list --installed`, and the picture reader cannot start. Expected: a test that only plans a models-folder change should not touch the filesystem outside its own fixture folder. The test's own failure line names the folder it attacked: ``` test at tests\models-folder.test.mjs:71:1 ✖ a whole drive is planned as <drive>\Strata, shown as <drive>\Strata\Models (6.413ms) Error: EPERM, Permission denied: \\?\C:\Strata '\\?\C:\Strata' at rmSync (node:fs:1221:18) at TestContext.<anonymous> (…/apps/host/tests/models-folder.test.mjs:78:3) ``` The code, `apps/host/tests/models-folder.test.mjs:71-79` (`git blame`: every line is `1d6a04012`, 2026-10-20, "Settings > Storage: Models folder card … tests"; unchanged since, shipped in every tag from v0.2.2 to v0.2.8): ```js test('a whole drive is planned as <drive>\\Strata, shown as <drive>\\Strata\\Models', async t => { const f = fixture(t); const root = f.root.slice(0, f.root.indexOf(process.platform === 'win32' ? '\\' : '/') + 1) || '/'; const plan = await f.native.planModelsFolder(root); assert.equal(plan.wholeDrive, true); assert.equal(plan.folder, join(root, 'Strata')); assert.equal(plan.shown, join(root, 'Strata', 'Models')); rmSync(join(root, 'Strata'), { recursive: true, force: true }); // ← line 78 }); ``` `f.root` is `realpathSync(mkdtempSync(join(tmpdir(), 'strata-mfolder-')))`, so on Windows `root` becomes the **drive root of `%TEMP%`** — `C:\` here — and `join(root, 'Strata')` is `C:\Strata`. That is exactly the path the Storage card produces when a person points Strata at a whole drive, which is the case this test exists to cover. The fixture only creates `<f.root>\install`, `\data`, `\old`, `\new`, and `control.planModelsMove` is a stub, so **the test never creates anything at that path**: line 78 deletes whatever the person keeps there. `force: true` hides the case where the folder does not exist, which is why this passes silently on machines whose models live on another drive or in `Documents\Strata`. **This is the only such call in the suite.** I went through every `rmSync(` in `apps/host/tests` (about a hundred): each one removes a folder made by `mkdtempSync` in the same test, including line 53 of this very file (`rmSync(root, …)`, its own fixture). Line 78 is the only place where the path is derived from something outside the fixture, and it is derived from the drive root. Two things make it worse than a normal bad test: * `AGENTS.md` ("tests run with `npm test` in `apps/host`") and `CONTRIBUTING.md` send contributors and CI straight at the command that triggers it. * `scripts/test.mjs` states the opposite intent in its header — *"Every test file runs against scratch copies of the per-user places the host writes to (the owner's real profile is never touched)"* — and `535cacb0` (2026-10-24) redirected `LOCALAPPDATA`, `APPDATA`, `XDG_*`, `STRATA_COMPONENTS_DIR` and `STRATA_SETTINGS_FILE` into a scratch folder. Deriving a drive root inside the test walks straight past all of that. On Linux and macOS `root` is `/`, so the target is `/Strata`, which normally does not exist and `force: true` makes it a no-op — the damage is effectively Windows-only, where `%TEMP%` and the model folder usually share `C:`. ### Smallest steps or command that reproduce it On a Windows machine where the Strata data folder is `<drive>\Strata` (Settings > Storage > a whole drive) and `%TEMP%` is on that same drive: ```bat cd <checkout>\apps\host npm ci npm test ``` or just the one file: ```bat node --test tests\models-folder.test.mjs ``` The run reports the failure `rmSync` gives when it cannot finish, and the files under `<drive>\Strata` are already gone or marked for deletion by then. ### Reproduction status Reproduced locally ### Strata version commit `529b25c3` (merge of `origin/main` = `870aedd9`, v0.2.8). `apps/host/tests/models-folder.test.mjs` in that tree is byte-identical to `origin/main` (SHA-256 starts `3033925CD34FF67E`). ### Graphics card, memory and system RTX 5080 16 GB · 93 GB RAM · Windows 11 Pro 10.0.26300 ### Model, size and settings Qwen3.8-Flash-Next UD Q4_K_XL · 524 288 context · pictures on · model files in `C:\Strata\Data` ### Suggested fix The plan creates nothing, so the cleanup line can simply go, and the "whole drive" case can be faked inside the fixture: ```js const root = join(f.root, 'drive') + sep; // a fake drive root, inside the fixture ... assert.equal(plan.folder, join(root, 'Strata')); assert.equal(plan.shown, join(root, 'Strata', 'Models')); // no rmSync: nothing was created by a plan ``` If the real drive root must be kept for fidelity, add a guard that fails loudly instead of deleting — `assert.ok(join(root, 'Strata').startsWith(f.root))` before any removal — or skip the test when `<drive>\Strata` already exists. ### Limits of what I verified * **Observed:** the test ran, `rmSync` named `\\?\C:\Strata`, and the two files above disappeared from the real folder between a run at 12:14 (folder complete, the model reported ready by `GET /api/native`) and 12:56 (folder short of those two files). * **Observed, and the only reason more survived:** my shell runs under a filesystem sandbox that denies writes outside the workspace. It stopped the recursive walk at the directory level, so the tree itself survived. The two files that did get removed were the two held open by the running engine (`strata.exe`, `--native C:\Strata\Data\models\unsloth-UD-Q4_K_XL\Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf`) and by the picture reader (`strata-vision.exe`, `--mmproj C:\Strata\Data\models\mmproj-Qwen3.8-Flash-Next-BF16.gguf`), so Windows kept them as delete-pending and the serving model kept answering. * **Not tested, stated as reasoning only:** without that sandbox I expect the recursive delete to take the whole `<drive>\Strata` tree (weights, packs, mtp). I did not run it unsandboxed and will not. * **Not run:** the rest of the suite after this; the fix above. ### Search before filing I searched the tracker (`gh search issues --repo Niko1221/Strata`) for `models-folder`, `rmSync` and `test deletes model folder`: `rmSync` and the last query return nothing, and the `models-folder` hits are unrelated. The closest in subject are #4089 (deleting a model stops at a read-only folder) and #3521 (a Terminal discovery test reading the checkout's own run configs) — different problems.
Author
Owner

@Niko1221 commented on GitHub (Oct 31, 2026):

Fixed in 0.2.9: that test no longer deletes anything, and it now checks that planning a folder change leaves the disk alone. We're sorry about the files you lost.

<!-- gh-comment-id:6541134589 --> @Niko1221 commented on GitHub (Oct 31, 2026): Fixed in [0.2.9](https://github.com/Niko1221/Strata/releases/tag/v0.2.9): that test no longer deletes anything, and it now checks that planning a folder change leaves the disk alone. We're sorry about the files you lost.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#2140
No description provided.