diff --git a/VERSION b/VERSION index 587c2a0a5..b8a1558ff 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v1.0.48 +v1.0.49 diff --git a/package.json b/package.json index eb5d62b13..72c31e9e2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "dockhand", "private": true, - "version": "1.0.46", + "version": "1.0.49", "type": "module", "scripts": { "dev": "npx vite dev", diff --git a/src/lib/data/changelog.json b/src/lib/data/changelog.json index decc99e11..a11336ea3 100644 --- a/src/lib/data/changelog.json +++ b/src/lib/data/changelog.json @@ -1,7 +1,7 @@ [ { "version": "1.0.49", - "date": "", + "date": "2026-09-22", "comingSoon": true, "changes": [ { "type": "feature", "text": "tag containers and stacks, then filter and group the grid by tag (#781, #870)" }, @@ -26,7 +26,9 @@ { "type": "feature", "text": "clear a search field with the X button in it (#1321)" }, { "type": "fix", "text": "clearing a container's command now reverts it to the image default (#1489)" }, { "type": "feature", "text": "one-shot container exec API returning stdout, stderr and exit code (#1380)" }, - { "type": "feature", "text": "set and change file ownership in the container file browser (#224)" } + { "type": "feature", "text": "set and change file ownership in the container file browser (#224)" }, + { "type": "fix", "text": "cut backup read transactions on S3/B2 by caching the restic index between runs (#1600)" }, + { "type": "fix", "text": "dashboard no longer flashes zero running containers on a remote host (#1608)" } ], "imageTag": "fnsys/dockhand:v1.0.49" }, diff --git a/src/lib/openapi.generated.json b/src/lib/openapi.generated.json index 391b4b79d..ccd13027b 100644 --- a/src/lib/openapi.generated.json +++ b/src/lib/openapi.generated.json @@ -2,7 +2,7 @@ "openapi": "3.0.3", "info": { "title": "Dockhand API", - "version": "1.0.46", + "version": "1.0.49", "description": "Auto-generated from src/routes/**/+server.ts by scripts/generate-openapi.ts. Path, HTTP method, tag, and auth requirement are derived automatically from the route tree and hooks.server.ts PUBLIC_PATHS. Parameters, response status codes, and request body fields are additionally auto-detected from each handler’s own source (query params via url.searchParams, status codes via status:/error(), body fields via destructuring) — adding a new endpoint therefore requires ZERO manual spec edits to show up with real params/responses. An optional, additive `@openapi` JSDoc annotation on a handler replaces the generic auto-descriptions with hand-written summaries, exact types, and examples." }, "servers": [ diff --git a/src/lib/server/backups/restic-script.ts b/src/lib/server/backups/restic-script.ts index 9bd58f14d..cdbd0b156 100644 --- a/src/lib/server/backups/restic-script.ts +++ b/src/lib/server/backups/restic-script.ts @@ -10,6 +10,19 @@ import { isLocalRepo } from './models'; /** The marker line the helper prints carrying restic's real exit code. */ export const EXIT_MARKER = 'DOCKHAND_RESTIC_EXIT='; +/** + * A persistent restic cache for the helper. The helper container is ephemeral + * (removed after each op), so a cache inside it is cold every run and restic + * re-downloads the whole repo index/snapshot metadata from the backend to dedup + * - many object GETs per backup, growing with the repo. A NAMED volume + * (not a host path) is managed by the TARGET daemon, so it survives the helper + * and works identically on local, direct-remote and Hawser envs - no host path + * is reachable on a remote daemon. restic keys its cache per-repo internally, so + * one shared volume serves every destination. + */ +export const RESTIC_CACHE_VOLUME = 'dockhand-restic-cache'; +export const RESTIC_CACHE_PATH = '/root/.cache/restic'; + /** Quote a single argument for safe interpolation into an `sh -c` string. */ export function shellQuote(s: string): string { return `'${s.replace(/'/g, `'\\''`)}'`; @@ -160,6 +173,9 @@ export function buildHelperEnv( `RESTIC_REPOSITORY=${repository}`, `RESTIC_PASSWORD=${password}`, 'RESTIC_PROGRESS_FPS=2', + // Point restic at the mounted persistent cache (buildHelperBinds mounts the + // dockhand-restic-cache volume here) so it isn't cold on every run. + `RESTIC_CACHE_DIR=${RESTIC_CACHE_PATH}`, ]; for (const [k, v] of Object.entries(allowedCloudVars)) env.push(`${k}=${v}`); // PEM CONTENT (not a path) - tlsCertPreamble writes it to a file in the helper. @@ -178,7 +194,10 @@ export function buildHelperBinds( volumeBinds: string[], resolveLocalRepoHostPath: (repoPath: string) => string ): string[] { - const binds = [...volumeBinds]; + // Persistent restic cache first (named volume, daemon-managed, survives the + // ephemeral helper) so backups reuse the repo index instead of re-fetching it + // from the backend every run. + const binds = [`${RESTIC_CACHE_VOLUME}:${RESTIC_CACHE_PATH}`, ...volumeBinds]; if (isLocalRepo(repository)) { binds.push(`${resolveLocalRepoHostPath(repository)}:${repository}`); } diff --git a/src/lib/server/stacks.ts b/src/lib/server/stacks.ts index 24800f157..43591aff5 100644 --- a/src/lib/server/stacks.ts +++ b/src/lib/server/stacks.ts @@ -2565,8 +2565,9 @@ export async function stopStack( // `docker compose stop` interpolates the compose file too, so a stack with required // provider secrets (${VAR:?required}) fails to stop without them - e.g. the - // stop-during-backup path (#1579). - await applyProviderSecretsToComposeResult(result, stackName, envId, `[Stack:${stackName}]`); + // stop-during-backup path (#1579). bestEffort: stopping a stack must not be blocked + // by an unreachable provider, so a resolve failure falls back to on-disk/DB vars. + await applyProviderSecretsToComposeResult(result, stackName, envId, `[Stack:${stackName}]`, true); const composeResult = await executeComposeCommand( 'stop', @@ -2622,8 +2623,10 @@ export async function restartStack( // Resolve secret-provider values up front: every restart mode ends in a compose // command (up/start/restart) that interpolates the compose file, so a stack with - // required provider secrets (${VAR:?required}) fails without them (#1579). - await applyProviderSecretsToComposeResult(result, stackName, envId, `[Stack:${stackName}]`); + // required provider secrets (${VAR:?required}) fails without them (#1579). bestEffort: + // restarting a running stack must not be blocked by an unreachable provider, so a + // resolve failure falls back to on-disk/DB vars rather than aborting the restart. + await applyProviderSecretsToComposeResult(result, stackName, envId, `[Stack:${stackName}]`, true); if (mode === 'recreate') { // Stop first, then bring up with --force-recreate to ensure new container IDs @@ -2934,17 +2937,31 @@ export async function removeStack( // "Remove stack" (deleteFiles=false) leaves the compose/.env/data on disk; "Remove // stack + files" (default) deletes them. if (stackDir && deleteFiles) { - try { - rmSync(stackDir, { recursive: true, force: true }); - } catch (err: any) { - console.error(`Failed to delete stack directory: ${err.message}`); - cleanupErrors.push(`directory: ${err.message}`); + // The local `docker compose down` we just ran had this dir as its cwd + // (executeComposeCommand spawns with cwd: composeFileDir), so on a direct + // env the dir can be transiently busy the instant the process exits - + // rmSync then leaves it (EBUSY/ENOTEMPTY) or existsSync is still true. + // Retry a few times with a short backoff so the just-exited compose child + // releases its cwd/fds. Hawser envs run compose on the agent, so they + // never hit this. + let lastErr = ''; + for (let attempt = 0; attempt < 5; attempt++) { + try { + rmSync(stackDir, { recursive: true, force: true }); + } catch (err: any) { + lastErr = err.message; + } + if (!existsSync(stackDir)) { lastErr = ''; break; } + lastErr = lastErr || 'Directory still exists after deletion attempt'; + await new Promise((r) => setTimeout(r, 200)); } - // Verify deletion succeeded (rmSync with force:true may not throw on some failures) - if (existsSync(stackDir)) { - const verifyErr = 'Directory still exists after deletion attempt'; - console.error(`Failed to delete stack directory: ${verifyErr}`); - cleanupErrors.push(`directory: ${verifyErr}`); + if (lastErr) { + console.error(`Failed to delete stack directory: ${lastErr}`); + // A residual dir under Dockhand's own stacks tree blocks nothing when the + // caller forced removal: the containers are gone and a same-name recreate + // re-clones over it (syncGitStack rmSyncs the path first). So it is a + // warning under force, and only a hard failure (blocks recreate) otherwise. + cleanupErrors.push(`${force ? 'directory-warning' : 'directory'}: ${lastErr}`); } } @@ -3765,10 +3782,11 @@ async function resolveProviderEnvVars( /** * Resolve the bound provider's secrets over a raw (nonSecretVars, secretVars) pair. - * Returns the merged vars. bestEffort=true (tear-down paths) logs and returns the - * inputs unchanged if the provider is unreachable, so a down/remove is never blocked - * by a dead provider. The single source of truth both the compose-result helper and - * removeStack use, so envPath derivation cannot drift between them. + * Returns the merged vars. bestEffort=true (lifecycle paths that must not be blocked by + * an unreachable provider: stop/restart/down/remove) logs and returns the inputs + * unchanged if the provider is down, so the op falls back to the on-disk/DB vars. The + * single source of truth both the compose-result helper and removeStack use, so envPath + * derivation cannot drift between them. */ async function resolveProviderVarsBestEffort( stackName: string, @@ -3817,9 +3835,9 @@ async function applyProviderSecretsToComposeResult( stackName: string, envId: number | null | undefined, logPrefix: string, - // Tear-down paths (down/remove) pass bestEffort: a provider that is unreachable - // must not block bringing a stack down, so a resolve error is logged and the - // compose command proceeds with whatever vars are on disk/DB. + // Lifecycle paths that must not be blocked by an unreachable provider (stop/restart/ + // down/remove) pass bestEffort: a resolve error is logged and the compose command + // proceeds with whatever vars are on disk/DB. Deploy paths (start/up) keep the throw. bestEffort = false ): Promise { if (!result.success || !result.secretVars || !result.nonSecretVars) return; diff --git a/src/lib/utils/merge-partial-stats.ts b/src/lib/utils/merge-partial-stats.ts new file mode 100644 index 000000000..1a60e3dae --- /dev/null +++ b/src/lib/utils/merge-partial-stats.ts @@ -0,0 +1,55 @@ +/** + * Merge a progressive dashboard `partial` stats update into a tile's existing stats, + * IN PLACE (Svelte 5 reactivity relies on mutating the existing objects). + * + * The dashboard stats stream is re-opened periodically (the 30s refresh, a reconnect, + * a tab-visibility resume). Each re-open starts with a SKELETON partial: every data + * section (containers, images, volumes, ...) is a zeroed placeholder flagged + * `loading[section] = true`, filled in by a later partial. A naive deep-merge lets + * those placeholder zeros overwrite the real counts a populated tile already shows - + * and on a slow/remote env the follow-up partial can lag or be lost, leaving the tile + * stuck at zero even though the environment is healthy. + * + * Rule: skip a section's payload while its own `loading` flag is true (keep the prior + * value); still apply the `loading` object itself so the spinner shows. A section with + * no loading flag, or `loading:false`, is real data and is merged normally. On the very + * first load the tile's skeleton already shows zeros, so skipping the placeholder is a + * no-op there - the real partial (loading:false) fills it. + */ +export function mergePartialStats( + existing: Record, + partial: Record +): void { + const loadingFlags = (partial.loading || {}) as Record; + for (const [key, value] of Object.entries(partial)) { + if (value === undefined || key === 'id') continue; + if (loadingFlags[key] === true) continue; // skeleton placeholder - keep prior data + const current = existing[key]; + if ( + current && typeof current === 'object' && !Array.isArray(current) && + value && typeof value === 'object' && !Array.isArray(value) + ) { + Object.assign(current, value); + } else { + existing[key] = value; + } + } +} + +/** + * The subset of a `partial` update that should reach the store, dropping placeholder + * sections (same rule as mergePartialStats) but always keeping `loading`. Returns a new + * object; does not mutate the input. + */ +export function definedPartialForStore( + partial: Record +): Record { + const loadingFlags = (partial.loading || {}) as Record; + const out: Record = {}; + for (const [key, value] of Object.entries(partial)) { + if (value === undefined) continue; + if (key !== 'loading' && loadingFlags[key] === true) continue; + out[key] = value; + } + return out; +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 7857458b4..8d5aa220d 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -24,6 +24,7 @@ import { SearchInput } from '$lib/components/ui/search-input'; import MultiSelectFilter from '$lib/components/MultiSelectFilter.svelte'; import { appSettings } from '$lib/stores/settings'; + import { mergePartialStats, definedPartialForStore } from '$lib/utils/merge-partial-stats'; const LABEL_FILTER_STORAGE_KEY = 'dockhand-dashboard-label-filter'; @@ -521,34 +522,18 @@ }); } } else if (eventType === 'partial') { - // Progressive update - merge partial data into existing stats - // Use deep merge for nested objects to preserve existing values + // Progressive update - merge partial data into existing stats in place + // (Svelte 5 reactivity), skipping SKELETON placeholder sections so a + // re-opened stream's zeroed loading partial can't blank a populated tile. const partialStats = data as Partial & { id: number }; const tile = tiles.find(t => t.id === partialStats.id); if (tile?.stats) { - // Use direct mutation for Svelte 5 reactivity - // Deep merge for nested objects like containers, images, etc. - for (const [key, value] of Object.entries(partialStats)) { - if (value !== undefined && key !== 'id') { - const existing = (tile.stats as any)[key]; - // Deep merge for plain objects (not arrays or null) - if (existing && typeof existing === 'object' && !Array.isArray(existing) && - value && typeof value === 'object' && !Array.isArray(value)) { - Object.assign(existing, value); - } else { - (tile.stats as any)[key] = value; - } - } - } + mergePartialStats(tile.stats as any, partialStats as any); } - // Also update the store with deep merge - const definedStats: Partial = {}; - for (const [key, value] of Object.entries(partialStats)) { - if (value !== undefined) { - (definedStats as any)[key] = value; - } - } - dashboardData.updateTilePartial(partialStats.id, definedStats); + dashboardData.updateTilePartial( + partialStats.id, + definedPartialForStore(partialStats as any) as Partial + ); } else if (eventType === 'stats') { // Update the tile with actual stats (legacy/fallback) const stats = data as EnvironmentStats; diff --git a/static/openapi.json b/static/openapi.json index 391b4b79d..ccd13027b 100644 --- a/static/openapi.json +++ b/static/openapi.json @@ -2,7 +2,7 @@ "openapi": "3.0.3", "info": { "title": "Dockhand API", - "version": "1.0.46", + "version": "1.0.49", "description": "Auto-generated from src/routes/**/+server.ts by scripts/generate-openapi.ts. Path, HTTP method, tag, and auth requirement are derived automatically from the route tree and hooks.server.ts PUBLIC_PATHS. Parameters, response status codes, and request body fields are additionally auto-detected from each handler’s own source (query params via url.searchParams, status codes via status:/error(), body fields via destructuring) — adding a new endpoint therefore requires ZERO manual spec edits to show up with real params/responses. An optional, additive `@openapi` JSDoc annotation on a handler replaces the generic auto-descriptions with hand-written summaries, exact types, and examples." }, "servers": [ diff --git a/tests/backups/restic-script.test.ts b/tests/backups/restic-script.test.ts index 9be45638c..1c96ec5bd 100644 --- a/tests/backups/restic-script.test.ts +++ b/tests/backups/restic-script.test.ts @@ -11,6 +11,8 @@ import { readExitMarker, buildHelperEnv, buildHelperBinds, + RESTIC_CACHE_VOLUME, + RESTIC_CACHE_PATH, localRepoGuard, localRepoChown, classifyProcClose, @@ -161,18 +163,23 @@ describe('binary stdout capture — Buffer.concat is lossless where string conca }); describe('buildHelperEnv', () => { - it('sets repo, password, progress, plus allowlisted cloud vars', () => { + it('sets repo, password, progress, cache dir, plus allowlisted cloud vars', () => { const env = buildHelperEnv('s3:bucket', 'pw', { AWS_ACCESS_KEY_ID: 'k' }); expect(env).toContain('RESTIC_REPOSITORY=s3:bucket'); expect(env).toContain('RESTIC_PASSWORD=pw'); expect(env).toContain('RESTIC_PROGRESS_FPS=2'); + expect(env).toContain(`RESTIC_CACHE_DIR=${RESTIC_CACHE_PATH}`); expect(env).toContain('AWS_ACCESS_KEY_ID=k'); }); + it('points RESTIC_CACHE_DIR at the mounted cache volume path', () => { + const env = buildHelperEnv('s3:bucket', 'p', {}); + expect(env).toContain(`RESTIC_CACHE_DIR=${RESTIC_CACHE_PATH}`); + }); it('is caller-filtered — it does NOT re-filter, so pass the allowlisted map', () => { // The caller passes filterCloudEnvVars(...); this fn trusts that. Given an // empty map, no cloud vars are added. const env = buildHelperEnv('r', 'p', {}); - expect(env).toHaveLength(3); + expect(env).toHaveLength(4); }); it('adds the TLS PEM content vars when certs are supplied', () => { const env = buildHelperEnv('rest:https://x/repo', 'p', {}, { cacert: 'CA-PEM', clientCert: 'CLIENT-PEM' }); @@ -193,13 +200,19 @@ describe('buildHelperEnv', () => { describe('buildHelperBinds', () => { const resolve = (p: string) => `/host${p}`; - it('passes volume binds through unchanged for a remote repo', () => { + const cache = `${RESTIC_CACHE_VOLUME}:${RESTIC_CACHE_PATH}`; + it('prepends the persistent cache volume and passes volume binds through for a remote repo', () => { const binds = buildHelperBinds('s3:bucket', ['vol:/volumes/vol:ro'], resolve); - expect(binds).toEqual(['vol:/volumes/vol:ro']); + expect(binds).toEqual([cache, 'vol:/volumes/vol:ro']); }); - it('adds the repo path bind for a local (filesystem) repo', () => { + it('adds the repo path bind for a local (filesystem) repo, cache still first', () => { const binds = buildHelperBinds('/srv/restic', ['vol:/volumes/vol:ro'], resolve); - expect(binds).toEqual(['vol:/volumes/vol:ro', '/host/srv/restic:/srv/restic']); + expect(binds).toEqual([cache, 'vol:/volumes/vol:ro', '/host/srv/restic:/srv/restic']); + }); + it('mounts the cache as a NAMED volume (no leading slash - daemon-managed, works on remote/hawser)', () => { + const binds = buildHelperBinds('s3:bucket', [], resolve); + expect(binds[0]).toBe(cache); + expect(binds[0].startsWith('/')).toBe(false); }); it('does not mutate the caller array', () => { const input = ['a:/volumes/a:ro']; diff --git a/tests/merge-partial-stats.test.ts b/tests/merge-partial-stats.test.ts new file mode 100644 index 000000000..00cc0378a --- /dev/null +++ b/tests/merge-partial-stats.test.ts @@ -0,0 +1,147 @@ +import { describe, it, expect } from 'bun:test'; +import { mergePartialStats, definedPartialForStore } from '../src/lib/utils/merge-partial-stats'; + +describe('mergePartialStats - skeleton placeholders never blank a populated tile', () => { + it('a skeleton partial (running:0, loading.containers=true) does NOT overwrite the real count', () => { + // The #1608 case: a re-opened stream sends the zeroed skeleton for env 5, which + // already shows 8 running. The zeros must be ignored. + const existing: any = { + id: 5, + online: true, + containers: { total: 8, running: 8, stopped: 0, paused: 0, restarting: 0, unhealthy: 0, pendingUpdates: 0 } + }; + const skeleton: any = { + id: 5, + containers: { total: 0, running: 0, stopped: 0, paused: 0, restarting: 0, unhealthy: 0, pendingUpdates: 0 }, + loading: { containers: true } + }; + mergePartialStats(existing, skeleton); + expect(existing.containers.running).toBe(8); // preserved + expect(existing.containers.total).toBe(8); + expect(existing.loading).toEqual({ containers: true }); // spinner shows + }); + + it('a REAL partial (loading.containers=false) applies the counts', () => { + const existing: any = { + id: 5, + containers: { total: 0, running: 0, stopped: 0, paused: 0, restarting: 0, unhealthy: 0, pendingUpdates: 0 }, + loading: { containers: true } + }; + const real: any = { + id: 5, + online: true, + containers: { total: 8, running: 8, stopped: 0, paused: 0, restarting: 0, unhealthy: 0, pendingUpdates: 0 }, + loading: { containers: false } + }; + mergePartialStats(existing, real); + expect(existing.containers.running).toBe(8); + expect(existing.online).toBe(true); + expect(existing.loading.containers).toBe(false); + }); + + it('a GENUINE drop to zero (running 8 -> 0 with loading:false) IS applied, not treated as a placeholder', () => { + // The other direction of the guard: a user stops all containers. The real partial + // carries loading.containers=false, so the zero must overwrite the prior 8 - it is + // NOT a skeleton placeholder. (A regression that special-cased zero would freeze at 8.) + const existing: any = { containers: { total: 8, running: 8, stopped: 0, paused: 0, restarting: 0, unhealthy: 0, pendingUpdates: 0 } }; + const stopAll: any = { + containers: { total: 8, running: 0, stopped: 8, paused: 0, restarting: 0, unhealthy: 0, pendingUpdates: 0 }, + loading: { containers: false } + }; + mergePartialStats(existing, stopAll); + expect(existing.containers.running).toBe(0); + expect(existing.containers.stopped).toBe(8); + }); + + it('a genuine zero for a non-container section (images 12 -> 0 with loading:false) IS applied', () => { + const existing: any = { images: { total: 12, totalSize: 999 } }; + mergePartialStats(existing, { images: { total: 0, totalSize: 0 }, loading: { images: false } }); + expect(existing.images.total).toBe(0); + expect(existing.images.totalSize).toBe(0); + }); + + it('a loading-only partial (no section payload) merges the loading flags, keeping prior data', () => { + const existing: any = { containers: { running: 8 }, loading: { containers: true } }; + mergePartialStats(existing, { loading: { images: false } }); + expect(existing.containers.running).toBe(8); // untouched (no container payload) + expect(existing.loading).toEqual({ containers: true, images: false }); // loading is deep-merged + }); + + it('an offline partial (online:false, error, loading:undefined) applies the scalars and skips undefined', () => { + const existing: any = { online: true, containers: { running: 8 } }; + mergePartialStats(existing, { online: false, error: 'Connection timeout', loading: undefined }); + expect(existing.online).toBe(false); + expect(existing.error).toBe('Connection timeout'); + expect(existing.containers.running).toBe(8); // no container payload -> untouched + expect('loading' in existing && existing.loading === undefined).toBe(false); // undefined loading skipped + }); + + it('mixes sections: applies a ready section while skipping a still-loading one', () => { + const existing: any = { + containers: { running: 8 }, + images: { total: 12 } + }; + const partial: any = { + containers: { running: 0 }, // still loading -> keep 8 + images: { total: 15 }, // ready -> apply + loading: { containers: true, images: false } + }; + mergePartialStats(existing, partial); + expect(existing.containers.running).toBe(8); + expect(existing.images.total).toBe(15); + }); + + it('applies sections that have NO loading flag (online, metrics, events) - only flagged ones are placeholders', () => { + // online/metrics/events carry no per-section loading flag; a real partial must apply + // them even when it only flags `containers`. The skip is `loading[key] === true`, so a + // missing flag (undefined) is NOT a placeholder. + const existing: any = { online: false, metrics: null, containers: { running: 0 } }; + const real: any = { + online: true, + metrics: { cpuPercent: 5 }, + containers: { running: 8 }, + loading: { containers: false } + }; + mergePartialStats(existing, real); + expect(existing.online).toBe(true); + expect(existing.metrics).toEqual({ cpuPercent: 5 }); + expect(existing.containers.running).toBe(8); + }); + + it('merges non-object scalars and preserves untouched keys', () => { + const existing: any = { online: false, name: 'kasm', containers: { running: 8 } }; + mergePartialStats(existing, { online: true }); + expect(existing.online).toBe(true); + expect(existing.name).toBe('kasm'); + expect(existing.containers.running).toBe(8); + }); + + it('ignores undefined values and the id key', () => { + const existing: any = { id: 5, containers: { running: 8 } }; + mergePartialStats(existing, { id: 99, containers: undefined }); + expect(existing.id).toBe(5); // id never overwritten + expect(existing.containers.running).toBe(8); + }); +}); + +describe('definedPartialForStore - store payload drops placeholder sections but keeps loading', () => { + it('drops a loading section, keeps loading + ready sections', () => { + const partial: any = { + id: 5, + containers: { running: 0 }, + images: { total: 15 }, + loading: { containers: true, images: false } + }; + const out = definedPartialForStore(partial); + expect(out.containers).toBeUndefined(); // placeholder dropped + expect(out.images).toEqual({ total: 15 }); // ready kept + expect(out.loading).toEqual({ containers: true, images: false }); // always kept + expect(out.id).toBe(5); + }); + + it('drops undefined values', () => { + const out = definedPartialForStore({ id: 1, online: undefined, containers: { running: 3 } }); + expect('online' in out).toBe(false); + expect(out.containers).toEqual({ running: 3 }); + }); +});