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 review: enforce slugline-or-name invariant on updateSetting

Adam Eivy641e5b4003b8
diff --git a/server/services/writersRoom/settings.js b/server/services/writersRoom/settings.js
index ec5cc0a268..5888552154 100644
--- a/server/services/writersRoom/settings.js
+++ b/server/services/writersRoom/settings.js
@@ -121,7 +121,6 @@ export async function updateSetting(workId, settingId, patch = {}) {
if (patch[field] === undefined) continue;
if (field === 'slugline' || field === 'name') {
const newVal = String(patch[field] || '').trim();
- if (field === 'slugline' && !newVal && !next.name) throw badRequest('Setting needs slugline or name');
const key = normalizeSlugline(newVal);
if (key) {
const conflict = state.settings.some((s) => s.id !== settingId && normalizeSlugline(s.slugline || s.name) === key);
@@ -132,6 +131,14 @@ export async function updateSetting(workId, settingId, patch = {}) {
next[field] = patch[field];
}
}
+ // Enforce the same invariant as `createSetting`: at least one of
+ // `slugline` / `name` must be non-empty. Without this final check, a
+ // PATCH that blanks the only non-empty identifier (e.g. a name-only
+ // setting receiving `{ name: '' }`, or a slugline-only setting being
+ // sent `{ slugline: '' }`) would silently leave the setting unaddressable.
+ if (!next.slugline && !next.name) {
+ throw badRequest('Setting needs slugline or name');
+ }
next.source = 'user';
next.updatedAt = nowIso();
state.settings[idx] = next;
diff --git a/server/services/writersRoom/settings.test.js b/server/services/writersRoom/settings.test.js
index cc4970f55d..eea3c55008 100644
--- a/server/services/writersRoom/settings.test.js
+++ b/server/services/writersRoom/settings.test.js
@@ -92,6 +92,24 @@ describe('writers room — settings CRUD', () => {
await deleteSetting(id, s.id);
expect(await listSettings(id)).toHaveLength(0);
});
+
+ it('rejects an update that would leave both slugline and name blank (name-only created)', async () => {
+ // Setting was created via name only — slugline=''. Blanking the name
+ // would leave the record unaddressable; the update must reject.
+ const id = await newWork();
+ const s = await createSetting(id, { name: 'The Glass Atrium' });
+ await expect(updateSetting(id, s.id, { name: '' })).rejects.toThrow(/slugline or name/i);
+ });
+
+ it('rejects an update that would leave both slugline and name blank (slugline-only created)', async () => {
+ const id = await newWork();
+ const s = await createSetting(id, { slugline: 'INT. ATTIC — DUSK' });
+ // Note: createSetting auto-fills name from slugline when name is omitted,
+ // so we explicitly clear name first via update, then attempt to clear
+ // slugline. The combined-blank invariant must still fire.
+ await updateSetting(id, s.id, { name: '' });
+ await expect(updateSetting(id, s.id, { slugline: '' })).rejects.toThrow(/slugline or name/i);
+ });
});
describe('writers room — settings merge', () => {