Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: deterministically drive UpdateTab reconcile flow to fix flaky Restarting-button race (#2065)

Adam Eivy9c725ae6929b
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 2aa2f0d27a..be72d50f60 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -30,6 +30,7 @@
## Internal
+- Deflaked the `UpdateTab reconcile flow` tests, which intermittently failed CI with "Unable to find role=button and name 'Restarting...'" (#2065). The component mirrors `updating` into `updatingRef` via a passive effect, and the disconnect handler's guard reads that ref synchronously; since `runUpdate()` calls `setUpdating(true)` outside any `act` (after two awaits), the "Reconciling..." button could commit — satisfying the test's `waitFor` — a scheduler tick before the ref-sync effect ran, leaving the ref stale-false when `disconnect` fired so the confirmation timer never armed. The test now flushes pending effects (`await act(async () => {})`) before firing `disconnect`, syncing the ref to the state production always reaches over real network time. Test-only change; no product behavior touched.
- Consolidated five component-local duration/uptime/time-until formatters onto the shared `utils/formatters.js` helpers (`formatDurationMs`, `timeUntil`), per the "do not re-define formatters inside components" convention (#2028). `formatDurationMs` gained a day bucket (`2d 3h`) so long uptimes no longer render as an unbounded hours count; ProcessesTab, CityHud, Shell session ages, the CoS QuickSummary "next job" countdown, and the Loops interval label now all route through the shared helpers, and a `console.log` in `memoryClassifier.js` was collapsed to a single interpolated line.
- Migration 155 heals `data/prompts/stages/cd-treatment.md` installs that #1808's anchor-based migration 148 left stranded (#2042). Installs seeded before the `imageStrength` scene knob (older pre-#1808 template) got the `## Cast & ingredients` list but missed the per-scene `"cast": [{ "ingredientId": … }]` field, so the Creative Director cast-threading regression test stayed red on the runtime template and migration 148 (already applied) never re-ran. The new hash-driven prompt-replace upgrades those copies (and both pristine pre-#1808 shipped versions) to the current shipped reference, leaving hand-customized copies untouched. Also folds `cd-treatment.md` into `buildPromptDriftTables` so setup-data.js's drift warning classifies a stranded copy correctly.
- Replaced the last hardcoded `port-*` hex stragglers with design tokens (#2031). The Security page's audio-level meter used raw `#ef4444`/`#f59e0b`/`#22c55e` in an inline `backgroundColor`; these now resolve through `rgb(var(--port-error))`/`--port-warning`/`--port-success` so they track the theme. The Chief-of-Staff page's "CoS" wordmark gradient was duplicated inline three times and is now a single module-level `COS_TITLE_GRADIENT` constant. Visual output is unchanged.
diff --git a/client/src/components/apps/tabs/UpdateTab.test.jsx b/client/src/components/apps/tabs/UpdateTab.test.jsx
index e189bfb74b..cbe6a161dd 100644
--- a/client/src/components/apps/tabs/UpdateTab.test.jsx
+++ b/client/src/components/apps/tabs/UpdateTab.test.jsx
@@ -39,6 +39,18 @@ const OUT_OF_SYNC_STATUS = {
// Fires 'disconnect' and advances past the 1.5s unreachability-confirmation
// delay in handleDisconnect, flushing the checkHealth() microtask through it.
const fireDisconnectAndConfirm = async () => {
+ // Flush pending passive effects FIRST. The component mirrors `updating` into
+ // `updatingRef` via a separate effect (`useEffect(() => { updatingRef.current
+ // = updating }, [updating])`), and handleDisconnect's guard reads that ref
+ // synchronously. runUpdate() calls setUpdating(true) outside any act (after
+ // two awaits), so the "Reconciling..." button — driven directly by the
+ // `updating` state — can commit to the DOM (and satisfy the caller's waitFor)
+ // a scheduler tick before the ref-sync effect runs. Without this flush the
+ // ref can still be stale-false when we fire 'disconnect', the confirmation
+ // timer never arms, and "Restarting..." never appears: the intermittent CI
+ // failure (#2065). Draining effects here syncs the ref to the state
+ // production always reaches over real network time.
+ await act(async () => {});
vi.useFakeTimers();
handlers.get('disconnect')();
await act(async () => { await vi.advanceTimersByTimeAsync(1500); });
@@ -99,6 +111,10 @@ describe('UpdateTab reconcile flow', () => {
// before the 1.5s confirmation delay elapsed. Nothing is left mounted to
// ever dismiss a toast.loading({ duration: Infinity }) popped after this.
mockCheckHealth.mockResolvedValue(null);
+ // Flush pending effects so updatingRef is true when we fire 'disconnect'
+ // (see fireDisconnectAndConfirm) — otherwise the confirmation timer never
+ // arms and this asserts "no toast" for the wrong reason.
+ await act(async () => {});
vi.useFakeTimers();
handlers.get('disconnect')();
unmount();