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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
test: pin the settled input value before submits whose payload is asserted (#3353)
[._.]/ Adam Eivy454be772d6b1
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 77e277dafb..1d4311ce57 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -156,3 +156,4 @@- **[issue-3313] The URL search-param patch helper is now one hook instead of three copies.** `updateParams(patch, { replace })` — merge a patch into the query string, dropping keys set to empty so a cleared filter leaves the URL clean — had been re-typed into Catalog, Media Collections, and (in a narrower single-key form) the 3D page. It now lives in `useUrlParams`, which reads the live params off a ref because react-router's functional updater hands the callback the params captured at the render that memoized it — a debounced `?q=` write armed before a sort change would otherwise navigate with the pre-change snapshot and silently drop the sort the user just picked. The hook is also referentially stable, so the debounce effects on those pages stop re-arming every time an unrelated param changes.- **[issue-3335] Deleting a prompt stage now checks the source, not a hand-written list of ten.** `DELETE /api/prompts/:stage` force-guarded exactly the ten curated CoS/Brain/Memory stages, so removing `pipeline-series-concept-judge` (or roughly a hundred others PortOS resolves by literal key) succeeded with no warning and left the feature naming it throwing `Stage <key> not found` on its next run. Adding them all to the curated table was the wrong fix — the same table drives the Prompt Manager's `SYSTEM` badge and its "System only" filter, and badging ~100 of 127 rows makes both meaningless. Deletion protection is now a second, generated set: a checked-in manifest indexes every stage key a `server/` source names, including the ones reached only through an interpolated prefix like `pipeline-panel-${personaId}`, and a drift test fails until a new call site is regenerated into it. The badge and the filter still show the same ten stages; the delete dialog now names the files that reference the one you're about to remove.- **[issue-3288] Video render submission is no longer a 717-line route handler — and a failed lookup mid-request stops orphaning your upload.** `POST /api/video-gen` did request validation, backend-pin resolution, model checks, durable staging for four upload kinds with rollback bookkeeping, IC-LoRA/keyframe/a2v validation, render-history lookups, LoRA normalization and chunk resolution inline, with twenty-plus throw sites sharing mutable cleanup state — so every new video-gen parameter meant editing the monolith and risking an unrelated validation branch. That whole region now lives in `services/videoGen/prepareParams.js`, mirroring what `imageGen` already did, and the route is a thin parse → prepare → enqueue → respond shell. Validation order and the exact cleanup-on-throw unwind are preserved verbatim, pinned by the existing route suite plus a new service suite. The extraction also closed a real leak (#3326): every *explicit* throw released the staged uploads, but a plain rejected `await` — a music-video project or track lookup, a render-history read, or the enqueue itself — bubbled straight past them, orphaning up to 100MB per request under `data/uploads` with no job to ever clean it up. One rollback guard now covers every rejection point at once and stays correct as new awaits are added, rethrowing the original error untouched.+- **[issue-3353] Client tests that type into a field and then submit no longer race the keystrokes.** A Stacker News save test failed on CI for a pull request whose entire diff was a dependency config file, and passed on the rerun. The cause is a shape that suite had in six places: `user.type` enters `20` as two separate events, and nothing between the last keystroke and the Save click asserted that the controlled input had actually reached `20` — so under load the click could send a payload built from the intermediate `2`, or from the post-clear empty string that `Number('')` turns into `0`. Waiting on the assertion cannot recover from that, because the call has already happened with the wrong argument and re-waiting never produces a second one. A shared `src/test/settledInput.js` helper now pins the settled input value between the keystrokes and whatever depends on them, and all six instances in the Stacker News suite plus five more with the identical shape — in the CoS agent card and reviewer picker, the sprite reference workflow, and the media jobs queue — now use it. The failure mode it replaces is an honest one — an input that never settles now fails saying so, rather than silently asserting against a half-typed value.diff --git a/client/src/components/cos/ReviewerPicker.test.jsx b/client/src/components/cos/ReviewerPicker.test.jsxindex cf7a46b335..7548acb424 100644--- a/client/src/components/cos/ReviewerPicker.test.jsx+++ b/client/src/components/cos/ReviewerPicker.test.jsx@@ -2,6 +2,7 @@ import { describe, it, expect, vi } from 'vitest';import { render, screen, fireEvent } from '@testing-library/react';import userEvent from '@testing-library/user-event';import ReviewerPicker from './ReviewerPicker';+import { typeSettled } from '../../test/settledInput';describe('ReviewerPicker', () => {it('renders the selected reviewers in order with numbered badges', () => {@@ -81,7 +82,7 @@ describe('ReviewerPicker', () => {const onChange = vi.fn();const user = userEvent.setup();render(<ReviewerPicker reviewers={['copilot']} onChange={onChange} />);- await user.type(screen.getByLabelText('Add a GitHub reviewer username'), '@CodeReviewbot');+ await typeSettled(user, screen.getByLabelText('Add a GitHub reviewer username'), '@CodeReviewbot');await user.click(screen.getByRole('button', { name: /^Add$/ }));expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ usernames: ['CodeReviewbot'] }));});diff --git a/client/src/components/cos/tabs/AgentCard.test.jsx b/client/src/components/cos/tabs/AgentCard.test.jsxindex a4bda8fe78..473fc5c89e 100644--- a/client/src/components/cos/tabs/AgentCard.test.jsx+++ b/client/src/components/cos/tabs/AgentCard.test.jsx@@ -2,6 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { render, screen, waitFor } from '@testing-library/react';import userEvent from '@testing-library/user-event';import { MemoryRouter } from 'react-router-dom';+import { typeSettled } from '../../../test/settledInput';vi.mock('../../../services/api', () => ({submitCosAgentFeedback: vi.fn(),@@ -107,7 +108,7 @@ describe('AgentCard feedback', () => {);await user.click(screen.getByRole('button', { name: 'Add feedback comment' }));- await user.type(screen.getByPlaceholderText('What made this work well or poorly?'), updatedAgent.feedback.comment);+ await typeSettled(user, screen.getByPlaceholderText('What made this work well or poorly?'), updatedAgent.feedback.comment);await user.click(screen.getByRole('button', { name: 'Needs work' }));expect(api.submitCosAgentFeedback).toHaveBeenCalledWith(@@ -136,7 +137,7 @@ describe('AgentCard feedback', () => {);await user.click(screen.getByRole('button', { name: 'Add feedback detail' }));- await user.type(screen.getByPlaceholderText('What made this work well or poorly?'), detailedAgent.feedback.comment);+ await typeSettled(user, screen.getByPlaceholderText('What made this work well or poorly?'), detailedAgent.feedback.comment);await user.click(screen.getByRole('button', { name: 'Save detail' }));expect(api.submitCosAgentFeedback).toHaveBeenCalledWith(diff --git a/client/src/components/media/MediaJobsQueue.test.jsx b/client/src/components/media/MediaJobsQueue.test.jsxindex 208ddcf091..322cc03f69 100644--- a/client/src/components/media/MediaJobsQueue.test.jsx+++ b/client/src/components/media/MediaJobsQueue.test.jsx@@ -1,6 +1,7 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, waitFor } from '@testing-library/react';import userEvent from '@testing-library/user-event';+import { retypeSettled } from '../../test/settledInput';// Mock the media-jobs API so the queue renders a controlled job list without// the network. useAutoRefetch calls the fetcher on mount.@@ -191,8 +192,7 @@ describe('MediaJobsQueue — Agy retry model field', () => {const input = await screen.findByLabelText('Agy model');expect(input.value).toBe('gemini-3.5-flash-high');- await user.clear(input);- await user.type(input, 'gemini-3.1-pro-high');+ await retypeSettled(user, input, 'gemini-3.1-pro-high');await user.click(screen.getByRole('button', { name: /Retry with changes/i }));expect(retryMediaJob).toHaveBeenCalledWith(diff --git a/client/src/components/sprites/ReferenceWorkflow.test.jsx b/client/src/components/sprites/ReferenceWorkflow.test.jsxindex 7bff2825a3..07e9b8ee4c 100644--- a/client/src/components/sprites/ReferenceWorkflow.test.jsx+++ b/client/src/components/sprites/ReferenceWorkflow.test.jsx@@ -1,6 +1,7 @@import { describe, expect, it, vi } from 'vitest';import { render, screen, within } from '@testing-library/react';import userEvent from '@testing-library/user-event';+import { typeSettled } from '../../test/settledInput';vi.mock('../../services/apiSprites.js', () => ({generateSpriteReference: vi.fn(() => Promise.resolve({ jobId: 'job-1' })),@@ -201,7 +202,7 @@ describe('ReferenceWorkflow workspace', () => {renderWorkflow();const turnaround = screen.getByRole('region', { name: 'Turnaround sheet' });const note = within(turnaround).getByPlaceholderText(/Correction for this attempt/);- await user.type(note, 'add the missing sleeve pocket');+ await typeSettled(user, note, 'add the missing sleeve pocket');await user.click(within(turnaround).getByRole('button', { name: 'Re-process with note' }));expect(generateSpriteReference).toHaveBeenCalledWith('example-pioneer', {target: 'turnaround',diff --git a/client/src/pages/StackerNews.test.jsx b/client/src/pages/StackerNews.test.jsxindex b8226de11b..85ddf72976 100644--- a/client/src/pages/StackerNews.test.jsx+++ b/client/src/pages/StackerNews.test.jsx@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';import { act, render, screen, waitFor, within } from '@testing-library/react';import userEvent from '@testing-library/user-event';import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';+import { clearSettled, retypeSettled, typeSettled } from '../test/settledInput';const api = {getStackerNewsAccounts: vi.fn(),@@ -102,8 +103,7 @@ describe('StackerNews', () => {api.updateStackerNewsAccount.mockResolvedValue({ ...accounts[0], monitoringIntervalMinutes: 20 });renderPage('/stacker-news/a1/accounts?snAccount=edit&snAccountTab=monitoring');const interval = await screen.findByLabelText('Monitoring interval (minutes)', { selector: '#edit-account-interval' });- await user.clear(interval);- await user.type(interval, '20');+ await retypeSettled(user, interval, '20');await user.click(screen.getByRole('button', { name: 'Save account' }));await waitFor(() => expect(api.updateStackerNewsAccount).toHaveBeenCalledWith('a1', expect.objectContaining({ monitoringIntervalMinutes: 20 }), { silent: true }));// A successful save closes the drawer and clears its search params.@@ -138,7 +138,7 @@ describe('StackerNews', () => {const user = userEvent.setup();renderPage('/stacker-news/a1/accounts?snAccount=edit&snAccountTab=stewardship');const tone = await screen.findByLabelText('Tone', { selector: '#edit-account-tone' });- await user.type(tone, 'measured');+ await typeSettled(user, tone, 'measured');await user.click(drawerTab('Budgets'));expect(currentUrl()).toContain('snAccountTab=budgets');expect(screen.getByLabelText('Max/hour', { selector: '#edit-account-hour-budget' })).toBeInTheDocument();@@ -149,7 +149,8 @@ describe('StackerNews', () => {it('reports an invalid field from an unmounted drawer tab and switches to it', async () => {const user = userEvent.setup();renderPage('/stacker-news/a1/accounts?snAccount=edit&snAccountTab=monitoring');- await user.clear(await screen.findByLabelText('Monitoring interval (minutes)', { selector: '#edit-account-interval' }));+ const interval = await screen.findByLabelText('Monitoring interval (minutes)', { selector: '#edit-account-interval' });+ await clearSettled(user, interval);await user.click(drawerTab('Budgets'));await user.click(screen.getByRole('button', { name: 'Save account' }));expect(await screen.findByText(/Monitoring interval \(minutes\) must be a whole number from 5 to 1440/)).toBeInTheDocument();@@ -198,8 +199,7 @@ describe('StackerNews', () => {api.updateStackerNewsAccount.mockReturnValue(save.promise);renderPage('/stacker-news/a1/accounts?snAccount=edit&snAccountTab=monitoring');const interval = await screen.findByLabelText('Monitoring interval (minutes)', { selector: '#edit-account-interval' });- await user.clear(interval);- await user.type(interval, '20');+ await retypeSettled(user, interval, '20');expect(screen.getByText(/Unsaved changes to @art_steward/)).toBeInTheDocument();expect(screen.getByRole('button', { name: 'Check API identity' })).toBeDisabled();expect(screen.getByRole('button', { name: 'Check browser identity' })).toBeDisabled();@@ -214,8 +214,7 @@ describe('StackerNews', () => {const user = userEvent.setup();renderPage('/stacker-news/a1/accounts?snAccount=edit&snAccountTab=monitoring');const interval = await screen.findByLabelText('Monitoring interval (minutes)', { selector: '#edit-account-interval' });- await user.clear(interval);- await user.type(interval, '20');+ await retypeSettled(user, interval, '20');// Closing keeps the draft (a 19-field edit should survive a detour), so the// dependent actions stay disabled until the draft is saved or discarded.await user.click(screen.getByRole('button', { name: 'Close' }));@@ -274,8 +273,7 @@ describe('StackerNews', () => {api.updateStackerNewsAccount.mockReturnValue(save.promise);renderPage('/stacker-news/a1/accounts?snAccount=edit&snAccountTab=monitoring');const interval = await screen.findByLabelText('Monitoring interval (minutes)', { selector: '#edit-account-interval' });- await user.clear(interval);- await user.type(interval, '20');+ await retypeSettled(user, interval, '20');await user.click(screen.getByRole('button', { name: 'Save account' }));// Selecting another account navigates by path, which drops the drawer params.await user.click(screen.getByRole('button', { name: /Personal/ }));diff --git a/client/src/test/settledInput.js b/client/src/test/settledInput.jsnew file mode 100644index 0000000000..df83baabfb--- /dev/null+++ b/client/src/test/settledInput.js@@ -0,0 +1,40 @@+import { waitFor } from '@testing-library/react';+import { expect } from 'vitest';++// `user.type` dispatches one event per keystroke and `user.clear` empties the+// field in its own event. Anything that reads state derived from the input right+// after them — a submit click whose payload is asserted, a dirty-state check —+// can observe a partial value (`2` instead of `20`, or the post-clear empty+// string, which `Number('')` turns into 0). A `waitFor` on the payload cannot+// rescue that: the call already happened with the wrong argument, and re-waiting+// never produces a second one.+//+// Pinning the settled input value in between turns a load-dependent flake into+// either a pass or an honest, immediately-legible failure.++const settled = (input, value) => waitFor(() => expect(input).toHaveValue(value));++// A `type="number"` input reads its value back coerced, and empty as `null`.+const readBack = (input, text) => (input.type === 'number' ? Number(text) : text);+const emptyValue = (input) => (input.type === 'number' ? null : '');++// Type into an empty field, then pin the result before whatever depends on it.+// Pass `value` explicitly when `text` carries key descriptors (`'a{Enter}'`) and+// so does not equal what the field ends up holding.+export async function typeSettled(user, input, text, value = readBack(input, text)) {+ await user.type(input, text);+ await settled(input, value);+}++// Empty a prefilled field and pin it — the post-clear empty string is its own+// wrong-payload window, separate from the keystrokes that follow.+export async function clearSettled(user, input) {+ await user.clear(input);+ await settled(input, emptyValue(input));+}++// Replace a prefilled field's contents, pinning both halves.+export async function retypeSettled(user, input, text, value) {+ await clearSettled(user, input);+ await typeSettled(user, input, text, value);+}