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: strengthen lww cross-format + shim verb/all-target coverage (#1847)
[._.]/ Adam Eivy3e549a5a1923
diff --git a/server/lib/agentGuard/index.test.js b/server/lib/agentGuard/index.test.jsindex a6b4dbfc42..5b0839e35d 100644--- a/server/lib/agentGuard/index.test.js+++ b/server/lib/agentGuard/index.test.js@@ -2,7 +2,7 @@ import { describe, it, expect, beforeAll, afterAll } from 'vitest';import { delimiter, dirname, join } from 'node:path';import { fileURLToPath } from 'node:url';import { spawnSync } from 'node:child_process';-import { mkdtempSync, writeFileSync, readFileSync, existsSync, rmSync, chmodSync, statSync } from 'node:fs';+import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, existsSync, rmSync, chmodSync, statSync, symlinkSync } from 'node:fs';import { tmpdir } from 'node:os';import { agentGuardEnv, AGENT_GUARD_BIN } from './index.js';@@ -71,6 +71,7 @@ describeShim('pm2 guard shim (bin/pm2)', () => {let workDir;let stubPm2;let marker;+ let cleanBin; // a PATH dir with the coreutils the shim needs but NO pm2beforeAll(() => {workDir = mkdtempSync(join(tmpdir(), 'agentguard-'));@@ -80,6 +81,16 @@ describeShim('pm2 guard shim (bin/pm2)', () => {// shim blocks, this never runs and the marker stays absent.writeFileSync(stubPm2, `#!/usr/bin/env bash\nprintf '%s\\n' "$*" > '${marker}'\nexit 0\n`);chmodSync(stubPm2, 0o755);++ // Build a pm2-free PATH dir holding just the externals the shim invokes+ // (`tr`, `dirname`) so the "no real pm2 resolvable" test is hermetic instead+ // of depending on whether the host's /usr/bin happens to contain pm2.+ cleanBin = join(workDir, 'cleanbin');+ mkdirSync(cleanBin);+ for (const tool of ['tr', 'dirname']) {+ const src = [`/usr/bin/${tool}`, `/bin/${tool}`].find((p) => existsSync(p));+ if (src) symlinkSync(src, join(cleanBin, tool));+ }});afterAll(() => {@@ -118,10 +129,11 @@ describeShim('pm2 guard shim (bin/pm2)', () => {expect(execedArgs).toBeNull();});- it('blocks `pm2 delete all` / `pm2 stop all` / `pm2 restart all`', () => {- for (const verb of ['delete', 'stop', 'restart']) {+ it('blocks every mirrored daemon-wide verb when the target is `all`', () => {+ // Must match PM2_ALL_TARGET_VERBS in commandSecurity.js.+ for (const verb of ['stop', 'delete', 'del', 'restart', 'reload', 'gracefulreload', 'scale']) {const { code, execedArgs } = runShim([verb, 'all']);- expect(code).toBe(1);+ expect(code, `${verb} all should be blocked`).toBe(1);expect(execedArgs).toBeNull();}});@@ -130,6 +142,13 @@ describeShim('pm2 guard shim (bin/pm2)', () => {expect(runShim(['delete', 'ALL']).code).toBe(1);});+ it('blocks `all` even when it appears after earlier flags/args', () => {+ // The shim scans every arg after the subcommand, not just the first.+ const { code, execedArgs } = runShim(['restart', '--update-env', 'all']);+ expect(code).toBe(1);+ expect(execedArgs).toBeNull();+ });+it('passes a scoped `pm2 restart <name>` through to the real pm2', () => {const { code, execedArgs } = runShim(['restart', 'my-app']);expect(code).toBe(0);@@ -143,10 +162,12 @@ describeShim('pm2 guard shim (bin/pm2)', () => {});it('exits 127 when no real pm2 can be resolved', () => {- // Empty PORTOS_REAL_PM2 + a curated coreutils PATH that has no pm2 (but still- // resolves bash/tr/dirname the shim needs) → the resolver finds none.- const res = spawnSync('bash', [SHIM, 'list'], {- env: { PORTOS_REAL_PM2: '', PATH: '/usr/bin:/bin' },+ // Empty PORTOS_REAL_PM2 + a hermetic PATH containing only tr/dirname (no pm2)+ // → the resolver finds none and the shim bails with 127. bash is invoked by+ // absolute path so it need not be on the restricted PATH.+ const bash = ['/bin/bash', '/usr/bin/bash'].find((p) => existsSync(p)) || 'bash';+ const res = spawnSync(bash, [SHIM, 'list'], {+ env: { PORTOS_REAL_PM2: '', PATH: cleanBin },encoding: 'utf8',});expect(res.status).toBe(127);diff --git a/server/lib/lwwTimestamp.test.js b/server/lib/lwwTimestamp.test.jsindex 0545099547..3aed58a2b4 100644--- a/server/lib/lwwTimestamp.test.js+++ b/server/lib/lwwTimestamp.test.js@@ -73,9 +73,17 @@ describe('compareNewerWins', () => {expect(compareNewerWins(null, undefined)).toBe(false);});- it('compares ISO vs non-ISO formats by epoch value', () => {- // RFC form is one second newer than the ISO form despite different shapes.- expect(compareNewerWins('Fri, 02 Jan 2026 03:04:06 GMT', '2026-01-02T03:04:05.000Z')).toBe(true);+ it('decides newer-wins by epoch even when lexical order disagrees', () => {+ // The 2030 ISO value is chronologically NEWER but sorts EARLIER as a string+ // ('2' < 'F') than the 2026 RFC value — so a lexicographic compare would get+ // BOTH directions wrong. Pinning both directions rules out a string-compare+ // regression that a same-direction case (e.g. RFC newer AND lexically larger)+ // would silently pass.+ const isoNewer = '2030-01-01T00:00:00.000Z';+ const rfcOlder = 'Fri, 02 Jan 2026 03:04:06 GMT';+ expect(isoNewer < rfcOlder).toBe(true); // lexical: ISO sorts first+ expect(compareNewerWins(isoNewer, rfcOlder)).toBe(true); // epoch: ISO is newer → overrides+ expect(compareNewerWins(rfcOlder, isoNewer)).toBe(false); // epoch: RFC is older → loses});it('is antisymmetric for two distinct valid timestamps', () => {@@ -119,8 +127,13 @@ describe('compareEarlierWins', () => {expect(compareEarlierWins(early, late)).toBe(-1 * compareEarlierWins(late, early));});- it('compares ISO vs non-ISO formats by epoch value', () => {- // RFC form is one second earlier → a wins.- expect(compareEarlierWins('Fri, 02 Jan 2026 03:04:04 GMT', '2026-01-02T03:04:05.000Z')).toBe(-1);+ it('decides earlier-wins by epoch even when lexical order disagrees', () => {+ // a (2030 ISO) is chronologically LATER but sorts EARLIER as a string than+ // b (2026 RFC) — a lexicographic compare would wrongly call a "earlier" and+ // return -1; epoch comparison correctly returns 1 (b is earlier, b wins).+ const aLater = '2030-01-01T00:00:00.000Z';+ const bEarlier = 'Fri, 02 Jan 2026 03:04:06 GMT';+ expect(aLater < bEarlier).toBe(true); // lexical: a sorts first+ expect(compareEarlierWins(aLater, bEarlier)).toBe(1); // epoch: b is earlier → b wins});});