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 declared mirror parity (#4175)
[._.]/ Adam Eivy5b9c84847379
diff --git a/.changelog/next/fixed-issue-4175.md b/.changelog/next/fixed-issue-4175.mdnew file mode 100644index 0000000000..db0da3b767--- /dev/null+++ b/.changelog/next/fixed-issue-4175.md@@ -0,0 +1 @@+- Server and client mirror contracts now detect missing parity coverage before drift reaches users.diff --git a/server/lib/appIdentity.mirror.test.js b/server/lib/appIdentity.mirror.test.jsnew file mode 100644index 0000000000..53af99262a--- /dev/null+++ b/server/lib/appIdentity.mirror.test.js@@ -0,0 +1,9 @@+import { describe, expect, it } from 'vitest';+import { PORTOS_APP_ID as serverAppId } from './appIdentity.js';+import { PORTOS_APP_ID as clientAppId } from '../../client/src/lib/appIdentity.js';++describe('appIdentity — server/client mirror parity', () => {+ it('keeps the baseline app id identical', () => {+ expect(clientAppId).toBe(serverAppId);+ });+});diff --git a/server/lib/issueLength.mirror.test.js b/server/lib/issueLength.mirror.test.jsnew file mode 100644index 0000000000..b49ae390b9--- /dev/null+++ b/server/lib/issueLength.mirror.test.js@@ -0,0 +1,55 @@+import { describe, expect, it } from 'vitest';+import {+ CUSTOM_MINUTE_MAX as serverMinuteMax,+ CUSTOM_MINUTE_MIN as serverMinuteMin,+ CUSTOM_PAGE_MAX as serverPageMax,+ CUSTOM_PAGE_MIN as serverPageMin,+ DEFAULT_LENGTH_PROFILE as serverDefaultProfile,+ LENGTH_PROFILES as serverProfiles,+} from './issueLength.js';+import {+ CUSTOM_MINUTE_MAX as clientMinuteMax,+ CUSTOM_MINUTE_MIN as clientMinuteMin,+ CUSTOM_PAGE_MAX as clientPageMax,+ CUSTOM_PAGE_MIN as clientPageMin,+ DEFAULT_LENGTH_PROFILE as clientDefaultProfile,+ LENGTH_PROFILES as clientProfiles,+} from '../../client/src/lib/issueLength.js';++describe('issueLength — server/client picker parity', () => {+ it('keeps the profiles the client displays aligned with server targets', () => {+ const serverPickerProfiles = Object.fromEntries(Object.entries(serverProfiles).map(([id, profile]) => [+ id,+ {+ label: profile.label,+ pageTarget: profile.pageTarget,+ minutesTarget: profile.minutesTarget,+ },+ ]));+ const clientPickerProfiles = Object.fromEntries(Object.entries(clientProfiles).map(([id, profile]) => [+ id,+ {+ label: profile.label,+ pageTarget: profile.pageTarget,+ minutesTarget: profile.minutesTarget,+ },+ ]));++ expect(clientPickerProfiles).toEqual(serverPickerProfiles);+ expect(clientDefaultProfile).toBe(serverDefaultProfile);+ });++ it('keeps every custom-override bound identical', () => {+ expect({+ pageMin: clientPageMin,+ pageMax: clientPageMax,+ minuteMin: clientMinuteMin,+ minuteMax: clientMinuteMax,+ }).toEqual({+ pageMin: serverPageMin,+ pageMax: serverPageMax,+ minuteMin: serverMinuteMin,+ minuteMax: serverMinuteMax,+ });+ });+});diff --git a/server/lib/mirrorCoverage.test.js b/server/lib/mirrorCoverage.test.jsnew file mode 100644index 0000000000..3a9b829455--- /dev/null+++ b/server/lib/mirrorCoverage.test.js@@ -0,0 +1,89 @@+import { describe, expect, it } from 'vitest';+import { readFileSync, readdirSync } from 'fs';+import { basename, dirname, join } from 'path';+import { fileURLToPath } from 'url';++const here = dirname(fileURLToPath(import.meta.url));+const CLIENT_LIB = join(here, '../../client/src/lib');+const CLIENT_README = join(CLIENT_LIB, 'README.md');+const SERVER_README = join(here, 'README.md');++function listTestFiles(dir) {+ return readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {+ const path = join(dir, entry.name);+ if (entry.isDirectory()) return listTestFiles(path);+ return entry.name.endsWith('.test.js') ? [path] : [];+ });+}++function listedMirrorPairs(readme) {+ const rows = [...readme.matchAll(/^\|\s+`([^`]+\.js)`\s+\|\s+(.+)\|$/gm)];+ const pairs = rows.flatMap(([, clientFile, description]) => {+ if (!/\bmirror/i.test(description)) return [];+ const serverMatch = description.match(/server\/lib\/([\w/-]+\.js)/);+ if (!serverMatch || serverMatch[1].includes('/') || clientFile !== basename(serverMatch[1])) return [];+ return [{ clientFile, serverFile: serverMatch[1] }];+ });+ return pairs;+}++function listedServerMirrorPairs(readme) {+ const rows = [...readme.matchAll(/^\|\s+`([^`]+\.js)`\s+\|\s+(.+)\|$/gm)];+ const pairs = rows.flatMap(([, serverFile, description]) => {+ if (!/\bmirror/i.test(description)) return [];+ const clientMatch = description.match(/client\/src\/lib\/([\w/-]+\.js)/);+ if (!clientMatch || clientMatch[1].includes('/') || serverFile !== basename(clientMatch[1])) return [];+ return [{ clientFile: clientMatch[1], serverFile }];+ });+ return pairs;+}++function uniquePairs(pairs) {+ return [...new Map(pairs.map((pair) => [`${pair.serverFile}:${pair.clientFile}`, pair])).values()];+}++function missingParityPins(pairs, testSources) {+ return pairs.filter(({ clientFile, serverFile }) => {+ const serverName = basename(serverFile);+ return !testSources.some(({ path, source }) => (+ path !== fileURLToPath(import.meta.url)+ && (source.includes(`client/src/lib/${clientFile}`) || source.includes(`'./${clientFile}'`))+ && source.includes(serverName)+ ));+ });+}++describe('declared server/client mirror coverage', () => {+ const readme = readFileSync(CLIENT_README, 'utf8');+ const pairs = uniquePairs([+ ...listedMirrorPairs(readme),+ ...listedServerMirrorPairs(readFileSync(SERVER_README, 'utf8')),+ ]);+ const testSources = [...listTestFiles(here), ...listTestFiles(CLIENT_LIB)].map((path) => ({+ path,+ source: readFileSync(path, 'utf8'),+ }));++ it('finds direct same-name mirror declarations in the client catalog', () => {+ expect(pairs).toContainEqual({ clientFile: 'seasonStructure.js', serverFile: 'seasonStructure.js' });+ expect(pairs).toContainEqual({ clientFile: 'shotGrammar.js', serverFile: 'shotGrammar.js' });+ expect(pairs).toContainEqual({ clientFile: 'appIdentity.js', serverFile: 'appIdentity.js' });+ expect(pairs).toContainEqual({ clientFile: 'issueLength.js', serverFile: 'issueLength.js' });+ });++ it('also includes direct same-name declarations from the server catalog', () => {+ expect(pairs).toContainEqual({ clientFile: 'catalogTypes.js', serverFile: 'catalogTypes.js' });+ });++ it('requires every declared direct mirror to have a test that reads both copies', () => {+ const missing = missingParityPins(pairs, testSources);+ expect(missing, `missing parity pins: ${missing.map(({ clientFile }) => clientFile).join(', ')}`).toEqual([]);+ });++ it('reports a synthetic declared mirror when no test reads both copies', () => {+ const synthetic = listedMirrorPairs('| `example.js` | Mirror of `server/lib/example.js`. |');+ expect(missingParityPins(synthetic, [])).toEqual([+ { clientFile: 'example.js', serverFile: 'example.js' },+ ]);+ });+});diff --git a/server/lib/scenePrompt.test.js b/server/lib/scenePrompt.test.jsindex f05b4d1076..37c3f4c59e 100644--- a/server/lib/scenePrompt.test.js+++ b/server/lib/scenePrompt.test.js@@ -1,4 +1,7 @@import { describe, it, expect } from 'vitest';+import { readFileSync } from 'fs';+import { dirname, join } from 'path';+import { fileURLToPath } from 'url';import {normalizeSlugline,normCharKey,@@ -9,6 +12,11 @@ import {buildScenePrompt,__testing,} from './scenePrompt.js';+import { compareDeclaration } from './mirrorParity.js';++const here = dirname(fileURLToPath(import.meta.url));+const SERVER_COPY = join(here, 'scenePrompt.js');+const CLIENT_COPY = join(here, '../../client/src/lib/scenePrompt.js');describe('scenePrompt — normalizeSlugline', () => {it('collapses em/en/hyphen + punctuation + spaces so equivalent sluglines match', () => {@@ -307,3 +315,31 @@ describe('scenePrompt — buildScenePrompt wardrobe appearances', () => {expect(out).not.toContain('Wearing:');});});++describe('scenePrompt — server/client mirror parity', () => {+ const server = readFileSync(SERVER_COPY, 'utf8');+ const client = readFileSync(CLIENT_COPY, 'utf8');+ const mirroredDeclarations = [+ 'PROMPT_MAX',+ 'normalizeSlugline',+ 'normCharKey',+ 'buildCharByKey',+ 'matchSceneCharacters',+ 'matchCharactersInText',+ 'buildPlaceByKey',+ 'matchScenePlace',+ 'matchEntriesByCandidates',+ 'matchPlacesInText',+ 'matchObjectsInText',+ 'appendWardrobe',+ 'buildScenePrompt',+ ];++ for (const name of mirroredDeclarations) {+ it(`keeps ${name} identical`, () => {+ const { clientDecl, serverNorm, clientNorm } = compareDeclaration(server, client, name);+ expect(clientDecl, `client/src/lib/scenePrompt.js is missing ${name}`).not.toBeNull();+ expect(clientNorm).toBe(serverNorm);+ });+ }+});diff --git a/server/lib/seasonStructure.mirror.test.js b/server/lib/seasonStructure.mirror.test.jsnew file mode 100644index 0000000000..17f34d4612--- /dev/null+++ b/server/lib/seasonStructure.mirror.test.js@@ -0,0 +1,23 @@+import { describe, expect, it } from 'vitest';+import { readFileSync } from 'fs';+import { dirname, join } from 'path';+import { fileURLToPath } from 'url';+import { compareDeclaration } from './mirrorParity.js';++const here = dirname(fileURLToPath(import.meta.url));+const SERVER_COPY = join(here, 'seasonStructure.js');+const CLIENT_COPY = join(here, '../../client/src/lib/seasonStructure.js');+const MIRRORED_DECLARATIONS = ['pickSeasonCount', 'recommendStructure', 'describeStructure'];++describe('seasonStructure — server/client mirror parity', () => {+ const server = readFileSync(SERVER_COPY, 'utf8');+ const client = readFileSync(CLIENT_COPY, 'utf8');++ for (const name of MIRRORED_DECLARATIONS) {+ it(`keeps ${name} identical`, () => {+ const { clientDecl, serverNorm, clientNorm } = compareDeclaration(server, client, name);+ expect(clientDecl, `client/src/lib/seasonStructure.js is missing ${name}`).not.toBeNull();+ expect(clientNorm).toBe(serverNorm);+ });+ }+});diff --git a/server/lib/shotGrammar.mirror.test.js b/server/lib/shotGrammar.mirror.test.jsnew file mode 100644index 0000000000..11bf69b819--- /dev/null+++ b/server/lib/shotGrammar.mirror.test.js@@ -0,0 +1,22 @@+import { describe, expect, it } from 'vitest';+import { readFileSync } from 'fs';+import { dirname, join } from 'path';+import { fileURLToPath } from 'url';+import { compareDeclaration } from './mirrorParity.js';++const here = dirname(fileURLToPath(import.meta.url));+const SERVER_COPY = join(here, 'shotGrammar.js');+const CLIENT_COPY = join(here, '../../client/src/lib/shotGrammar.js');++describe('shotGrammar — server/client vocabulary parity', () => {+ const server = readFileSync(SERVER_COPY, 'utf8');+ const client = readFileSync(CLIENT_COPY, 'utf8');++ for (const name of ['SHOT_TYPES', 'SCREEN_DIRECTIONS']) {+ it(`keeps ${name} identical`, () => {+ const { clientDecl, serverNorm, clientNorm } = compareDeclaration(server, client, name);+ expect(clientDecl, `client/src/lib/shotGrammar.js is missing ${name}`).not.toBeNull();+ expect(clientNorm).toBe(serverNorm);+ });+ }+});