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

address /simplify review: verify the FormField name, share the scan, label JobsTab's forms (#4156)

[._.]/ Adam Eivy1d310560b3b7
diff --git a/client/src/a11yConventions.test.js b/client/src/a11yConventions.test.js
index 4b1af047e4..d0a61efe29 100644
--- a/client/src/a11yConventions.test.js
+++ b/client/src/a11yConventions.test.js
@@ -472,30 +472,21 @@ function localHtmlForForwarders(src) {
const cached = htmlForForwardersBySource.get(src);
if (cached) return cached;
const forwarders = new Map();
- const re = /function\s+([A-Z][\w]*)\s*\(/g;
- let match;
- while ((match = re.exec(src))) {
- const parenIndex = match.index + match[0].length - 1;
- const params = balancedCallAt(src, parenIndex);
- if (!params) continue;
- const bodyStart = src.indexOf('{', parenIndex + params.length);
- if (bodyStart === -1) continue;
- const bodyEnd = matchingBraceEnd(src, bodyStart);
- if (bodyEnd === -1) continue;
- const body = src.slice(bodyStart, bodyEnd);
+ forEachLocalComponent(src, (name, body, params) => {
// The <label> has to do both jobs before the call site's attributes can be
// trusted: point at one prop, and render another prop as its own text. A
// component that forwards the id onto a <label> it never fills with text
// names nothing.
const shape = /<label\b[^>]*\bhtmlFor\s*=\s*\{\s*([A-Za-z_$][\w$]*)\s*\}(?:[^>]*[^/>])?>(?:(?!<\/label>)[\s\S])*?\{\s*([A-Za-z_$][\w$]*)\s*\}/.exec(body);
- if (!shape) continue;
+ if (!shape) return;
const [, idProp, labelProp] = shape;
// Both names must be parameters of this component. A <label> pointed at a
// module-level constant forwards nothing from the call site, so reading the
// call site's same-named attribute would exempt an unrelated control.
- if (![idProp, labelProp].every((prop) => new RegExp(`\\b${prop}\\b`).test(params))) continue;
- forwarders.set(match[1], { idProp, labelProp });
- }
+ const parameterNames = new Set(params.match(/[A-Za-z_$][\w$]*/g));
+ if (!parameterNames.has(idProp) || !parameterNames.has(labelProp)) return;
+ forwarders.set(name, { idProp, labelProp });
+ });
htmlForForwardersBySource.set(src, forwarders);
return forwarders;
}
@@ -584,23 +575,18 @@ function hasUsableNativeInputName(tag) {
// crediting every control in a `.map()` would exempt the ones that stay
// unnamed).
function isEnclosedInListCall(src, start, index) {
- const callStack = [];
- for (let cursor = start; cursor < index; cursor++) {
- const c = src[cursor];
- if (c === '"' || c === "'" || c === '`') {
- for (cursor++; cursor < index && src[cursor] !== c; cursor++) if (src[cursor] === '\\') cursor++;
- continue;
- }
- // Only a call that still encloses the control disqualifies it. A `.map()`
- // in the ternary's OTHER branch has already closed by then, so testing for
- // the text anywhere before the control would reject the whole shape.
- if (c === '(') callStack.push(/\.(?:map|flatMap)\s*$/.test(src.slice(start, cursor)));
- else if (c === ')') callStack.pop();
+ // Only a call that STILL encloses the control disqualifies it — a `.map()`
+ // in the ternary's other branch has already closed by then, so testing for
+ // the text anywhere before the control would reject the whole shape.
+ for (const call of src.slice(start, index).matchAll(/\.(?:map|flatMap)\s*\(/g)) {
+ const openParen = start + call.index + call[0].length - 1;
+ const args = balancedCallAt(src, openParen);
+ if (!args || openParen + args.length > index) return true;
}
- return callStack.some(Boolean);
+ return false;
}
-function isDirectElementInExpression(src, start, end, index) {
+function isDirectElementInExpression(src, start, index) {
if (isEnclosedInListCall(src, start, index)) return false;
let depth = 0;
let cursor = start;
@@ -613,20 +599,33 @@ function isDirectElementInExpression(src, start, end, index) {
}
if (src.startsWith('</', cursor)) {
const close = src.indexOf('>', cursor);
- if (close === -1 || close > end) return false;
+ if (close === -1) return false;
if (depth > 0) depth--;
cursor = close + 1;
continue;
}
const tag = tagBoundaryAt(src, cursor);
- if (!tag || tag.end > end) return false;
+ if (!tag) return false;
if (!tag.selfClosing) depth++;
cursor = tag.end;
}
return depth === 0;
}
+// The other two recognizers read a wrapper's own source before trusting it.
+// This one cannot — FormField is imported, not declared here — so at minimum
+// require that the name really is the shared component. Without the check a
+// file that declares or imports its own `FormField` exempts every control
+// under it, and that is the guard's widest exemption by far.
+// Matches every specifier the tree actually uses — `../ui/FormField`,
+// `../components/ui/FormField`, the one `.jsx`-suffixed import, and
+// `./FormField` from inside components/ui itself.
+function importsSharedFormField(src) {
+ return /\bfrom\s+['"](?:[^'"]*\/)?(?:ui\/)?FormField(?:\.jsx?)?['"]/.test(src);
+}
+
function isNestedInLabeledFormField(src, index) {
+ if (!importsSharedFormField(src)) return false;
const formRe = /<FormField\b/g;
let formMatch;
while ((formMatch = formRe.exec(src)) && formMatch.index < index) {
@@ -649,7 +648,7 @@ function isNestedInLabeledFormField(src, index) {
if (end === -1) break;
if (end >= index) {
// The control lives inside this expression rather than after it.
- if (depth === 0 && firstChild === null && isDirectElementInExpression(src, cursor + 1, end, index)) return true;
+ if (depth === 0 && firstChild === null && isDirectElementInExpression(src, cursor + 1, index)) return true;
break;
}
if (src.slice(cursor + 1, end).trim()) firstChild = firstChild || 'expression';
@@ -718,12 +717,14 @@ function isNestedInLabeledFormField(src, index) {
// from elsewhere stays unknown (FormField has its own dedicated check), and
// only `function` declarations are matched — a missed wrapper is a false
// negative that simply leaves its controls on the allowlist.
-const labelWrapperNamesBySource = new Map();
-
-function localLabelWrapperNames(src) {
- const cached = labelWrapperNamesBySource.get(src);
- if (cached) return cached;
- const names = new Set();
+// Both wrapper recognizers below need the same three things out of a same-file
+// component — its name, its body, and (for one of them) its parameter list —
+// so they walk
+// declarations through this one iterator rather than each re-deriving the
+// boundaries. Only `function` declarations are matched; an arrow-function
+// component stays invisible, which is a false negative that simply leaves its
+// controls on the allowlist (tracked in #4317).
+function forEachLocalComponent(src, visit) {
const re = /function\s+([A-Z][\w]*)\s*\(/g;
let match;
while ((match = re.exec(src))) {
@@ -737,14 +738,24 @@ function localLabelWrapperNames(src) {
if (bodyStart === -1) continue;
const bodyEnd = matchingBraceEnd(src, bodyStart);
if (bodyEnd === -1) continue;
- const body = src.slice(bodyStart, bodyEnd);
+ visit(match[1], src.slice(bodyStart, bodyEnd), params);
+ }
+}
+
+const labelWrapperNamesBySource = new Map();
+
+function localLabelWrapperNames(src) {
+ const cached = labelWrapperNamesBySource.get(src);
+ if (cached) return cached;
+ const names = new Set();
+ forEachLocalComponent(src, (name, body) => {
// {children} must sit inside a <label> — no </label> may intervene, or a
// component rendering `<label>Header</label>{children}<label>Footer</label>`
// would register as a wrapper and exempt controls it never labels. The
// opening tag must also not be self-closing (`<label … />` wraps nothing,
// so anything after it is outside the label).
- if (/<label\b(?:[^>]*[^/>])?>(?:(?!<\/label>)[\s\S])*?\{\s*children\s*\}/.test(body)) names.add(match[1]);
- }
+ if (/<label\b(?:[^>]*[^/>])?>(?:(?!<\/label>)[\s\S])*?\{\s*children\s*\}/.test(body)) names.add(name);
+ });
labelWrapperNamesBySource.set(src, names);
return names;
}
@@ -1100,23 +1111,33 @@ describe('a11y conventions', () => {
expect(offenders, `Icon-only <button> with no aria-label/aria-labelledby — title alone isn't touch-discoverable and isn't reliably read as the accessible name; see media/MediaCard.jsx's Annotate button for the convention:\n${offenders.join('\n')}`).toEqual([]);
});
- it('gives every input an accessible name', () => {
- // These controls live in compact peer-management rows where visible labels
- // would break the layout. Keep explicit names on each input so placeholders
- // never become their only screen-reader context.
- const offenders = [];
+ // Both rules below ask the same question of every tracked file and differ
+ // only in which direction they compare the answer against the allowlist, so
+ // they share one scan. Two copies would each re-lex ~11MB of source, and —
+ // worse — could drift on what "unnamed" means, which would quietly turn the
+ // burn-down check vacuously green.
+ let unnamedAnchors = null;
+ const unnamedInputAnchors = () => {
+ if (unnamedAnchors) return unnamedAnchors;
+ unnamedAnchors = new Set();
for (const file of trackedJsxFiles()) {
- const src = readFileSync(join(CLIENT_ROOT, file), 'utf8');
- const scanSrc = maskComments(src);
+ const scanSrc = maskComments(readFileSync(join(CLIENT_ROOT, file), 'utf8'));
const re = /<input\b/g;
let m;
while ((m = re.exec(scanSrc))) {
const tag = openingTagAt(scanSrc, m.index, '<input'.length);
- const location = inputSourceAnchor(file, scanSrc, m.index);
- if (!tag || hasAccessibleInputName(scanSrc, tag, m.index) || PREEXISTING_INPUT_NAME_ALLOWLIST.has(location)) continue;
- offenders.push(location);
+ if (!tag || hasAccessibleInputName(scanSrc, tag, m.index)) continue;
+ unnamedAnchors.add(inputSourceAnchor(file, scanSrc, m.index));
}
}
+ return unnamedAnchors;
+ };
+
+ it('gives every input an accessible name', () => {
+ // These controls live in compact peer-management rows where visible labels
+ // would break the layout. Keep explicit names on each input so placeholders
+ // never become their only screen-reader context.
+ const offenders = [...unnamedInputAnchors()].filter((anchor) => !PREEXISTING_INPUT_NAME_ALLOWLIST.has(anchor));
expect(offenders, `Input without an accessible name — add aria-label/aria-labelledby or an explicit/implicit <label>, or exclude type="hidden":\n${offenders.join('\n')}`).toEqual([]);
});
@@ -1125,18 +1146,8 @@ describe('a11y conventions', () => {
// or deleted, or renamed so its anchor no longer resolves — is dead weight
// that quietly re-exempts the next input to land on that same anchor. Fail
// on it so #4297's burn-down stays honest instead of drifting.
- const offending = new Set();
- for (const file of trackedJsxFiles()) {
- const scanSrc = maskComments(readFileSync(join(CLIENT_ROOT, file), 'utf8'));
- const re = /<input\b/g;
- let m;
- while ((m = re.exec(scanSrc))) {
- const tag = openingTagAt(scanSrc, m.index, '<input'.length);
- if (!tag || hasAccessibleInputName(scanSrc, tag, m.index)) continue;
- offending.add(inputSourceAnchor(file, scanSrc, m.index));
- }
- }
- const stale = [...PREEXISTING_INPUT_NAME_ALLOWLIST].filter((entry) => !offending.has(entry));
+ const unnamed = unnamedInputAnchors();
+ const stale = [...PREEXISTING_INPUT_NAME_ALLOWLIST].filter((entry) => !unnamed.has(entry));
expect(stale, `PREEXISTING_INPUT_NAME_ALLOWLIST entries that no longer match an unnamed input — delete them:\n${stale.join('\n')}`).toEqual([]);
});
@@ -1196,7 +1207,9 @@ describe('a11y conventions', () => {
// veto that matters is a rendered LIST — Children.map flattens it and
// clones only the first element, so crediting each control in a `.map()`
// would exempt every one after the first.
- const field = (child) => `<FormField label="Rounds">\n ${child}\n</FormField>`;
+ // The wrapper is only credited when the file really imports the shared
+ // component, so every fixture carries the import a real call site would.
+ const field = (child) => `import FormField from '../ui/FormField';\n<FormField label="Rounds">\n ${child}\n</FormField>`;
const index = (src) => src.indexOf('<input');
const ternary = field(`{isSelect ? (<select><option>a</option></select>) : (<input type="number" />)}`);
@@ -1218,6 +1231,13 @@ describe('a11y conventions', () => {
// An unlabeled FormField names nothing, whatever its child looks like.
const unlabeled = ternary.replace(' label="Rounds"', '');
expect(isNestedInLabeledFormField(unlabeled, index(unlabeled))).toBe(false);
+
+ // This recognizer trusts a component it cannot read the source of, so the
+ // name alone must not be enough — a file with its own local `FormField`
+ // would otherwise exempt every control under it, and that is the widest
+ // exemption the guard grants.
+ const foreign = ternary.replace("from '../ui/FormField'", "from './LocalFormField'");
+ expect(isNestedInLabeledFormField(foreign, index(foreign))).toBe(false);
});
it('meets the 44px touch-target minimum on Close buttons', () => {
diff --git a/client/src/components/cos/tabs/JobsTab.jsx b/client/src/components/cos/tabs/JobsTab.jsx
index 57ced83f07..930878f07a 100644
--- a/client/src/components/cos/tabs/JobsTab.jsx
+++ b/client/src/components/cos/tabs/JobsTab.jsx
@@ -9,6 +9,7 @@ import { effectiveModelFor, effortAwareModelOptions } from '../../../utils/provi
import ProviderModelSelector from '../../ProviderModelSelector';
import EffortSelect from '../EffortSelect';
import InlineConfirmRow from '../../ui/InlineConfirmRow';
+import FormField from '../../ui/FormField';
import { useConfirmDelete } from '../../../hooks/useConfirmDelete';
const INTERVAL_OPTIONS = [
@@ -229,7 +230,7 @@ function ScheduleFields({ data, onChange }) {
className="flex-1 px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm font-mono"
placeholder="0 7 * * *"
title="Cron expression: minute hour dayOfMonth month dayOfWeek"
- aria-label="Cron expression"
+ aria-label="Cron expression: minute hour dayOfMonth month dayOfWeek"
/>
<select
value=""
@@ -264,7 +265,7 @@ function ScheduleFields({ data, onChange }) {
onChange={e => onChange('scheduledTime', e.target.value || null)}
className="px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
title="Run at specific time (leave empty for any time)"
- aria-label="Run at a specific time"
+ aria-label="Run at a specific time (leave empty for any time)"
/>
</div>
)}
@@ -457,22 +458,22 @@ function JobCard({ job, apps, providers, onToggle, onTrigger, onDelete, onUpdate
<div className="border-t border-port-border p-4 space-y-3">
{editing ? (
<>
- <input
- type="text"
- value={editData.name}
- aria-label="Job name"
- onChange={e => setEditData(d => ({ ...d, name: e.target.value }))}
- className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
- placeholder="Job name"
- />
- <input
- type="text"
- value={editData.description}
- aria-label="Job description"
- onChange={e => setEditData(d => ({ ...d, description: e.target.value }))}
- className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
- placeholder="Description"
- />
+ <FormField label="Job name" labelClassName="block text-xs text-gray-400 mb-1">
+ <input
+ type="text"
+ value={editData.name}
+ onChange={e => setEditData(d => ({ ...d, name: e.target.value }))}
+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
+ />
+ </FormField>
+ <FormField label="Description" labelClassName="block text-xs text-gray-400 mb-1">
+ <input
+ type="text"
+ value={editData.description}
+ onChange={e => setEditData(d => ({ ...d, description: e.target.value }))}
+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
+ />
+ </FormField>
<div className="flex gap-3">
<select
value={editData.type}
@@ -803,40 +804,42 @@ export default function JobsTab() {
<div className="bg-port-card border border-port-accent/50 rounded-lg p-4">
<div className="space-y-3">
<div className="flex gap-3">
+ <FormField label="Job name *" className="flex-1" labelClassName="block text-xs text-gray-400 mb-1">
+ <input
+ type="text"
+ value={newJob.name}
+ onChange={e => setNewJob(j => ({ ...j, name: e.target.value }))}
+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
+ />
+ </FormField>
+ <FormField label="Type" labelClassName="block text-xs text-gray-400 mb-1">
+ <select
+ value={newJob.type}
+ onChange={e => setNewJob(j => ({ ...j, type: e.target.value }))}
+ className="px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
+ >
+ {JOB_TYPE_OPTIONS.map(opt => (
+ <option key={opt.value} value={opt.value}>{opt.label}</option>
+ ))}
+ </select>
+ </FormField>
+ <FormField label="Category" labelClassName="block text-xs text-gray-400 mb-1">
+ <input
+ type="text"
+ value={newJob.category}
+ onChange={e => setNewJob(j => ({ ...j, category: e.target.value }))}
+ className="w-40 px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
+ />
+ </FormField>
+ </div>
+ <FormField label="Description" labelClassName="block text-xs text-gray-400 mb-1">
<input
type="text"
- placeholder="Job name *"
- aria-label="New job name"
- value={newJob.name}
- onChange={e => setNewJob(j => ({ ...j, name: e.target.value }))}
- className="flex-1 px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
- />
- <select
- value={newJob.type}
- onChange={e => setNewJob(j => ({ ...j, type: e.target.value }))}
- className="px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
- >
- {JOB_TYPE_OPTIONS.map(opt => (
- <option key={opt.value} value={opt.value}>{opt.label}</option>
- ))}
- </select>
- <input
- type="text"
- placeholder="Category"
- aria-label="New job category"
- value={newJob.category}
- onChange={e => setNewJob(j => ({ ...j, category: e.target.value }))}
- className="w-40 px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
+ value={newJob.description}
+ onChange={e => setNewJob(j => ({ ...j, description: e.target.value }))}
+ className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
/>
- </div>
- <input
- type="text"
- placeholder="Description"
- aria-label="New job description"
- value={newJob.description}
- onChange={e => setNewJob(j => ({ ...j, description: e.target.value }))}
- className="w-full px-3 py-2 bg-port-bg border border-port-border rounded-lg text-white text-sm"
- />
+ </FormField>
<div className="flex gap-3">
<select
value={newJob.priority}