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

simplify: add server↔client registry parity test, derive FTS parity check from the registry, fix stale test-path comments

[._.]/ Adam Eivy26c290c070a6
diff --git a/client/src/lib/catalogTypes.js b/client/src/lib/catalogTypes.js
index 21d37b566d..16d48ba32a 100644
--- a/client/src/lib/catalogTypes.js
+++ b/client/src/lib/catalogTypes.js
@@ -6,7 +6,7 @@
* content key/label, the snippet fallback chain, and the per-type editor field
* list.
*
- * Drift is asserted by `client/src/lib/catalogTypes.test.js` against the
+ * Drift is asserted by `server/lib/catalogTypes.parity.test.js` against the
* server registry's shared fields — if you change one side, change the other.
*
* Adding a type: add an entry here AND in the server registry (+ one migration
@@ -107,7 +107,7 @@ export const CATALOG_TYPES = Object.freeze([
* picker on the ingredient detail page. `label` is the from→to direction;
* `inverseLabel` renders the same stored edge from the `to` side.
*
- * Drift is asserted by `client/src/lib/catalogTypes.test.js` against the server
+ * Drift is asserted by `server/lib/catalogTypes.parity.test.js` against the server
* registry — change one side, change the other.
*/
export const RELATION_KINDS = Object.freeze([
@@ -143,7 +143,7 @@ export function getRelationKind(id) {
* Catalog ingredient MEDIA-attachment kinds — client mirror of
* `server/lib/catalogTypes.js` MEDIA_KINDS. Drives the "Media" panel attach
* picker / drag-drop on the ingredient detail page. `accept` is the file-input
- * MIME filter. Drift is asserted by `client/src/lib/catalogTypes.test.js`
+ * MIME filter. Drift is asserted by `server/lib/catalogTypes.parity.test.js`
* against the server registry — change one side, change the other.
*/
export const MEDIA_KINDS = Object.freeze([
diff --git a/server/lib/catalogTypes.parity.test.js b/server/lib/catalogTypes.parity.test.js
new file mode 100644
index 0000000000..fbf1c8b003
--- /dev/null
+++ b/server/lib/catalogTypes.parity.test.js
@@ -0,0 +1,60 @@
+/**
+ * Cross-package parity for the catalog type registry.
+ *
+ * `server/lib/catalogTypes.js` is the source of truth; `client/src/lib/
+ * catalogTypes.js` is a hand-maintained mirror (the client can't import the
+ * server module — it pulls in server-only deps via storyBible.js). This suite
+ * imports BOTH and asserts the fields the UI relies on stay identical, so a
+ * server-side registry change that isn't mirrored to the client fails CI here
+ * instead of silently drifting (badge colors, primary-content keys, snippet
+ * fallbacks, relation/media kind ids, tag canonicalization).
+ *
+ * It lives server-side because the server registry can't load under the client
+ * (jsdom) runner, but the pure client mirror loads fine here.
+ */
+
+import { describe, it, expect } from 'vitest';
+import {
+ CATALOG_TYPES as SERVER_TYPES,
+ RELATION_KINDS as SERVER_REL,
+ MEDIA_KINDS as SERVER_MEDIA,
+ canonicalTagKey as serverCanonicalTagKey,
+} from './catalogTypes.js';
+import {
+ CATALOG_TYPES as CLIENT_TYPES,
+ RELATION_KINDS as CLIENT_REL,
+ MEDIA_KINDS as CLIENT_MEDIA,
+ canonicalTagKey as clientCanonicalTagKey,
+} from '../../client/src/lib/catalogTypes.js';
+
+// The fields the client mirror MUST match the server on — the ones the UI
+// reads. `ftsFields` / `extractionShape` / `payloadSchemaVersion` are
+// server-only concerns and intentionally not mirrored.
+const MIRRORED_FIELDS = ['id', 'label', 'badgeColor', 'primaryContentKey', 'primaryContentLabel', 'snippetFallbackKeys'];
+
+describe('catalog type registry — server↔client parity', () => {
+ it('exposes the same type ids in the same order', () => {
+ expect(CLIENT_TYPES.map((t) => t.id)).toEqual(SERVER_TYPES.map((t) => t.id));
+ });
+
+ it('matches every mirrored field for each type', () => {
+ for (const s of SERVER_TYPES) {
+ const c = CLIENT_TYPES.find((t) => t.id === s.id);
+ expect(c, `client mirror missing type ${s.id}`).toBeTruthy();
+ for (const f of MIRRORED_FIELDS) {
+ expect(c[f], `${s.id}.${f} drifted between server and client`).toEqual(s[f]);
+ }
+ }
+ });
+
+ it('matches relation + media kind ids', () => {
+ expect(CLIENT_REL.map((r) => r.id)).toEqual(SERVER_REL.map((r) => r.id));
+ expect(CLIENT_MEDIA.map((m) => m.id)).toEqual(SERVER_MEDIA.map((m) => m.id));
+ });
+
+ it('canonicalTagKey behaves identically across server and client', () => {
+ for (const s of ['Film Noir', 'noir', ' Spaced Out ', 'UPPER', 'já-vu', '']) {
+ expect(clientCanonicalTagKey(s)).toBe(serverCanonicalTagKey(s));
+ }
+ });
+});
diff --git a/server/lib/db.catalogDdlParity.test.js b/server/lib/db.catalogDdlParity.test.js
index ab9ef71443..50b789d141 100644
--- a/server/lib/db.catalogDdlParity.test.js
+++ b/server/lib/db.catalogDdlParity.test.js
@@ -15,6 +15,7 @@
*/
import { describe, it, expect } from 'vitest';
+import { FTS_PAYLOAD_FIELDS } from './catalogTypes.js';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import { dirname, join } from 'node:path';
@@ -168,11 +169,15 @@ describe('catalog DDL parity (init-db.sql ↔ db.js ensureSchema)', () => {
const sqlKeys = extractPayloadFtsKeys(INIT_SQL);
const jsKeys = extractPayloadFtsKeys(DB_JS);
expect([...sqlKeys].sort()).toEqual([...jsKeys].sort());
- // Sanity: today's v2 expression covers the bible-backfilled character
- // fields. If either drops below the documented set the test is lying.
- for (const required of ['description', 'physicalDescription', 'personality', 'background', 'summary', 'notes']) {
- expect(sqlKeys.has(required), `init-db.sql search_tsv missing ${required}`).toBe(true);
- expect(jsKeys.has(required), `db.js search_tsv missing ${required}`).toBe(true);
+ // The registry (`catalogTypes.FTS_PAYLOAD_FIELDS`) is the single source of
+ // truth for which payload keys the FTS column must index. Derive the
+ // required set from it rather than a hand-maintained list, so adding a
+ // type's `ftsFields` without updating BOTH DDL sources fails here instead
+ // of silently de-indexing the field.
+ expect(FTS_PAYLOAD_FIELDS.length, 'registry declares no FTS payload fields').toBeGreaterThan(0);
+ for (const required of FTS_PAYLOAD_FIELDS) {
+ expect(sqlKeys.has(required), `init-db.sql search_tsv missing registry FTS field ${required}`).toBe(true);
+ expect(jsKeys.has(required), `db.js search_tsv missing registry FTS field ${required}`).toBe(true);
}
});
});