Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(create): never let a trainer reinstall move the trainer folder

purpleefa4bb8722d5
diff --git a/e2e/trainer-reinstall-confirm.spec.ts b/e2e/trainer-reinstall-confirm.spec.ts
index 9d279a3e..68de36f3 100644
--- a/e2e/trainer-reinstall-confirm.spec.ts
+++ b/e2e/trainer-reinstall-confirm.spec.ts
@@ -151,9 +151,13 @@ test('confirming a reinstall of an already customized install keeps sending that
test('a rejected install still counts as one call -- the note shows the error, not a second attempt', async ({ page }, testInfo) => {
// The Rust validation runs on whatever path install_character_trainer gets
- // handed, independent of whether a human typed it. This uses a broken
- // suggestedRoot to reach that path without an editable field.
- await gotoReadyTrainer(page, { customized: false, suggestedRoot: 'relative-path-not-allowed', root: 'C:\\test-trainer' })
+ // handed, independent of whether a human typed it. B1-Korruktur
+ // (review-teil17-lintfix.md): a reinstall now ignores `suggestedRoot`
+ // entirely -- it only ever sends a path when the trainer is already
+ // customized, and that path is `status.root`. So a broken `root` on an
+ // already customized install is the only way left to reach this
+ // rejection without an editable field.
+ await gotoReadyTrainer(page, { customized: true, suggestedRoot: null, root: 'relative-path-not-allowed' })
await page.getByRole('button', { name: 'Reinstall trainer', exact: true }).click()
const dialog = page.getByRole('dialog', { name: 'Reinstall the trainer?' })
await dialog.getByRole('button', { name: 'Reinstall', exact: true }).click()
diff --git a/src/components/create/experimental/SpecialIntentControls.tsx b/src/components/create/experimental/SpecialIntentControls.tsx
index 01b31548..e1237691 100644
--- a/src/components/create/experimental/SpecialIntentControls.tsx
+++ b/src/components/create/experimental/SpecialIntentControls.tsx
@@ -461,25 +461,33 @@ function LocalTrainControls() {
return () => clearInterval(t)
}, [busy])
- const startInstall = async () => {
+ const runInstall = async (path: string) => {
setBusy('install')
setNote('Setting up the trainer...')
- try { await installCharacterTrainer(installPath.trim() || undefined) } catch (e) {
+ try { await installCharacterTrainer(path.trim() || undefined) } catch (e) {
setNote(e instanceof Error ? e.message : 'Install could not start.')
setBusy(null)
}
}
- // Blocker-Korrektur (Final Review, 19.09.2026): der Reinstall-Dialog hat
- // keinen eigenen Pfad mehr. Bestaetigen schickt GENAU das Argument, das der
- // Knopf vor dem Z5-Umbau schickte -- `installPath.trim() || undefined`, der
- // Zustand des Erstsetup-Gates oben, den ein Kunde, der das Feld nie
- // angefasst hat, nie auf einen nicht-leeren Wert gebracht hat. Ohne diese
- // Wiederverwendung wuerde jeder gewoehnliche Reinstall `trainer_root` auf
- // einen nicht-leeren String setzen und `trainer_root_is_customized()`
- // ungewollt auf true kippen.
+ // The setup-gate button keeps using whatever the customer typed there
+ // (or the pre-filled suggestion, or their own customized root).
+ const startInstall = () => runInstall(installPath)
+ // B1-Korrektur (Final Review Teil 17, review-teil17-lintfix.md): a
+ // reinstall must NEVER move the trainer folder. `installPath` above also
+ // carries `suggestedRoot` once no customized root exists (so the
+ // erstsetup gate can show it), but that suggestion is for the FIRST
+ // installation only. Sending it here on a bare "confirm the reinstall"
+ // click wrote it into `trainer_root`, flipped
+ // `trainer_root_is_customized()` to true for a customer who never
+ // touched this setting, and moved the pip/HF/torch caches away from an
+ // existing installation -- exactly the migration this dialog's text
+ // ("training photos and downloaded base models are not touched")
+ // promises will not happen. A reinstall therefore sends the customer's
+ // own root only if the trainer is already customized, and `undefined`
+ // (the default, i.e. today's location) in every other case.
const confirmReinstall = async () => {
setReinstallOpen(false)
- await startInstall()
+ await runInstall(status?.customized ? status.root : '')
}
const startBases = async () => {
if (!status) return
diff --git a/src/components/create/experimental/__tests__/k5-trainer-install-path-reaches-backend.test.tsx b/src/components/create/experimental/__tests__/k5-trainer-install-path-reaches-backend.test.tsx
index 0198e3d2..94cb541d 100644
--- a/src/components/create/experimental/__tests__/k5-trainer-install-path-reaches-backend.test.tsx
+++ b/src/components/create/experimental/__tests__/k5-trainer-install-path-reaches-backend.test.tsx
@@ -94,8 +94,13 @@ describe('K5: der Installationspfad des Trainers erreicht den Aufruf', () => {
// installPath immer weg, trainer_root_is_customized() konnte nie wahr
// werden. Nagelt fest, dass der Aufruf jetzt IMMER ein (moeglicherweise
// leeres) Argument mitgibt, nicht die alte parameterlose Form.
+ //
+ // B1-Korrektur (Final Review Teil 17, review-teil17-lintfix.md): der
+ // eigentliche Aufruf sitzt jetzt in `runInstall(path)`, gemeinsam fuer
+ // das Erstsetup-Gate (`installPath`) und den Reinstall-Dialog (der NIE
+ // den Vorschlag schickt, siehe trainer-install-path-derived-state.test.tsx).
expect(quelle).not.toContain('installCharacterTrainer()')
- expect(quelle).toContain('installCharacterTrainer(installPath.trim() || undefined)')
+ expect(quelle).toContain('installCharacterTrainer(path.trim() || undefined)')
})
it('das Feld ist die kleinste vorhandene Form: dieselbe Musterzeile wie der ComfyUI-Pfad', () => {
@@ -107,6 +112,6 @@ describe('K5: der Installationspfad des Trainers erreicht den Aufruf', () => {
// Installationsziel" wie Settings > ComfyUI, nicht ein zweites
// Bedienkonzept fuer denselben Zweck.
expect(settings).toContain("runInstall(customPath.trim() || status?.path || '')")
- expect(quelle).toContain("installPath.trim() || undefined")
+ expect(quelle).toContain("path.trim() || undefined")
})
})
diff --git a/src/components/create/experimental/__tests__/trainer-install-path-derived-state.test.tsx b/src/components/create/experimental/__tests__/trainer-install-path-derived-state.test.tsx
index 9052ddc3..2a148669 100644
--- a/src/components/create/experimental/__tests__/trainer-install-path-derived-state.test.tsx
+++ b/src/components/create/experimental/__tests__/trainer-install-path-derived-state.test.tsx
@@ -23,10 +23,25 @@
* visible field); this file covers the two cases that only show up once
* `envReady` is true and the field itself is gone.
*
+ * B1-Korrektur (Final Review Teil 17, review-teil17-lintfix.md, BLOCKIEREND):
+ * the first version of this file expected the Reinstall dialog to send a
+ * `suggestedRoot` when the trainer was not customized. That is the same
+ * blocker review-trainerconfirm-webdraft.md already flagged once: a plain
+ * "confirm" on the reinstall dialog wrote a folder the customer never chose
+ * into `trainer_root`, which flips `trainer_root_is_customized()` to true
+ * and moves the pip/HF/torch caches away from an install that predates the
+ * move -- exactly what the dialog's own text promises will not happen. A
+ * suggestion is only ever for the FIRST installation (the setup gate before
+ * `envReady`); a reinstall of an existing trainer must never move it. The
+ * cases below were corrected to match `confirmReinstall`'s fix: it sends
+ * `status.root` only when the trainer is already customized, `undefined`
+ * (today's location, unchanged) in every other case -- suggestedRoot never
+ * reaches `installCharacterTrainer` through this dialog at all.
+ *
* Run: npx vitest run src/components/create/experimental/__tests__/trainer-install-path-derived-state.test.tsx
*/
import { beforeEach, describe, expect, it, vi } from 'vitest'
-import { cleanup, fireEvent, render, screen } from '@testing-library/react'
+import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
vi.mock('../../../../api/backend', () => ({
isTauri: () => true,
@@ -100,14 +115,16 @@ describe('Lint-Fix Wahrheitstabelle: abgeleiteter installPath ueber den Reinstal
expect(installCharacterTrainer).toHaveBeenCalledWith('D:\\CustomTrainer')
})
- it('customized: false, suggestedRoot gesetzt -- der Vorschlag zaehlt, nicht der aktuelle root', async () => {
- // Deckt exakt den Fall ab, den e2e/trainer-reinstall-confirm.spec.ts fuer
- // die abgelehnte Installation braucht: ohne editierbares Feld ist dies
- // der einzige Weg, wie ein vom Nutzer nicht getippter Pfad ueberhaupt bei
- // install_character_trainer ankommt.
+ it('B1-KORREKTUR: customized: false, suggestedRoot gesetzt -- der Reinstall ignoriert den Vorschlag, sendet undefined', async () => {
+ // VORHER (Blocker, review-teil17-lintfix.md B1): dieser Fall erwartete
+ // `installCharacterTrainer` mit dem Vorschlag -- ein Kunde, der bloss
+ // "Reinstall" bestaetigt, haette damit `trainer_root` auf einen Ordner
+ // gesetzt, den er nie gewaehlt hat. Ein Vorschlag gilt nur fuer die
+ // ERSTE Installation (das Erstsetup-Gate, das hier gar nicht rendert,
+ // weil envReady bereits wahr ist).
mockedStatus = readyStatus({ customized: false, suggestedRoot: '/mnt/e/LU-Trainer', root: 'C:\\test-trainer' })
await openAndConfirmReinstall()
- expect(installCharacterTrainer).toHaveBeenCalledWith('/mnt/e/LU-Trainer')
+ expect(installCharacterTrainer).toHaveBeenCalledWith(undefined)
})
it('GEGENPROBE: customized true UND suggestedRoot gesetzt -- der eigene Ordner gewinnt, nicht der Vorschlag', async () => {
@@ -116,3 +133,39 @@ describe('Lint-Fix Wahrheitstabelle: abgeleiteter installPath ueber den Reinstal
expect(installCharacterTrainer).toHaveBeenCalledWith('D:\\CustomTrainer')
})
})
+
+describe('B3: ein zurueckgezogener suggestedRoot im laufenden Panel (Erstsetup-Gate, envReady false)', () => {
+ it('THE FIX: verschwindet der Vorschlag aus einem spaeteren Status, faellt das Feld auf leer zurueck statt den alten Vorschlag festzuhalten', async () => {
+ mockedStatus = {
+ envReady: false, basesReady: false, dit: null, textEncoder: null, vae: null,
+ root: '/data/lu/musubi', customized: false, suggestedRoot: '/mnt/e/LU-Trainer',
+ install: { status: 'idle', logs: [] },
+ }
+ render(<SpecialControls intent="character" />)
+ const feld = (await screen.findByDisplayValue('/mnt/e/LU-Trainer')) as HTMLInputElement
+ expect(feld.value).toBe('/mnt/e/LU-Trainer')
+
+ // Ein Klick auf "Set up trainer" startet die 2s-Umfrage in
+ // LocalTrainControls, die characterTrainerStatus erneut aufruft -- der
+ // einzige Weg im Panel, wie ein spaeterer Status (der Kunde hat ComfyUI
+ // in der Zwischenzeit auf dasselbe Laufwerk umgestellt) ueberhaupt
+ // ankommt, ohne die Komponente neu zu montieren. Der Mock schliesst die
+ // Installation im selben Poll ab ("complete" statt "installing"), damit
+ // `busy` wieder auf null faellt und das Feld (das waehrend `busy ===
+ // 'install'` ausgeblendet ist) mit dem neuen Status erneut sichtbar
+ // wird. Fake Timer erst NACH dem Erstrender, sonst haengt
+ // findByDisplayValue an seinem eigenen realen Poll-Intervall.
+ mockedStatus = { ...mockedStatus, suggestedRoot: null, install: { status: 'complete', logs: [] } }
+ vi.useFakeTimers()
+ try {
+ fireEvent.click(screen.getByRole('button', { name: 'Set up trainer' }))
+ await act(async () => { await vi.advanceTimersByTimeAsync(2000) })
+ } finally {
+ vi.useRealTimers()
+ }
+
+ expect(screen.queryByDisplayValue('/mnt/e/LU-Trainer')).toBeNull()
+ const feldDanach = screen.getByPlaceholderText('e.g. D:\\LU-Trainer') as HTMLInputElement
+ expect(feldDanach.value).toBe('')
+ })
+})