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
fix: prefix the diagnostics clock test hooks per the dead-exports convention (#12329)
Adam Eivy60f0976c1d96
diff --git a/server/lib/README.md b/server/lib/README.mdindex 807e59bb1b..7a5523777a 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -925,4 +925,4 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub- `nativeTrash.js`: `moveToNativeTrash(paths)` recycles through OS facilities PortOS owns — one hidden, deadline-bound `osascript` (`NSFileManager.trashItemAtURL`, exported `MACOS_TRASH_SCRIPT`) per file on macOS so each gets Finder Put Back; one Windows PowerShell 5.1 `-EncodedCommand` run (shell32 `SHFileOperationW` with `FOF_ALLOWUNDO`, exported `WINDOWS_TRASH_SCRIPT`, paths in `PORTOS_TRASH_PATHS`, fixed-drive pre-flight) per batch; `trashXdg` per file on Linux. Refusals reject with a coded error (`TRASH_REFUSED` + per-file `report`, `TRASH_DEADLINE`, `TRASH_UNPARSABLE`, `TRASH_UNSUPPORTED_PLATFORM`); no local-directory or permanent-delete fallback.- `nativeTrashXdg.js`: `trashXdg(path)` moves one file into the freedesktop Trash 1.0 directory serving its volume on `node:fs` alone (original names, RFC 2396 `Path=`, `O_EXCL` info reservation, NAME_MAX-bounded names, mount identity from `/proc/self/mountinfo` with a `st_dev` fallback so a bind mount gets its own volume trash instead of an `EXDEV`, physical-parent mount discovery, an owned trash directory is tightened to 0700 and `TRASH_DIR_UNSAFE` refuses a symlinked or foreign-owned one or a volume root whose entries other users could rename, a sticky shared `.Trash` counts only when root or the caller owns it and falls back to `.Trash-<uid>` when it cannot hold the per-user directory, refuses instead of copying across devices); `_topDirTrash(topDir, uid)`, `_parseMountInfo(text)` and `_mountOf(realDir, mounts)` are test hooks.- `nativeTrash.js`: `moveToNativeTrash(paths)` executes the pinned package native recycling helpers on macOS/Windows with hidden windows and a deadline; Linux uses the package XDG adapter. No local-directory or permanent-delete fallback.-- `eventLoopLagProbe.js`: `createEventLoopLagProbe({ clock, intervalMs, toleranceMs })` opens phase-tracking spans that charge overdue time of one shared, span-scoped tick to the current phase, so a slow-operation diagnostic splits each phase into event-loop/host scheduling lag and asynchronous wait (#12329); `systemClock` (globals resolved at call time), `createManualClock()` (deterministic `advance` = on-time timers vs `stall` = blocked loop, for tests), `roundMs`, and `phaseGroup(summary, name)` (a phase plus its `name.` sub-phases).+- `eventLoopLagProbe.js`: `createEventLoopLagProbe({ clock, intervalMs, toleranceMs })` opens phase-tracking spans that charge overdue time of one shared, span-scoped tick to the current phase, so a slow-operation diagnostic splits each phase into event-loop/host scheduling lag and asynchronous wait (#12329); `systemClock` (globals resolved at call time), `__createManualClock()` (deterministic `advance` = on-time timers vs `stall` = blocked loop, for tests), `roundMs`, and `phaseGroup(summary, name)` (a phase plus its `name.` sub-phases).diff --git a/server/lib/eventLoopLagProbe.js b/server/lib/eventLoopLagProbe.jsindex cb6698319d..dd6490dc7e 100644--- a/server/lib/eventLoopLagProbe.js+++ b/server/lib/eventLoopLagProbe.js@@ -26,7 +26,7 @@ export const systemClock = {* responsive loop (every timer fires on schedule); `stall(ms)` models a blocked* one (time passes and overdue timers wait for the next `advance`).*/-export function createManualClock() {+export function __createManualClock() {let now = 0;let seq = 0;const timers = new Map();diff --git a/server/services/cosMergeAdmission.diagnostics.test.js b/server/services/cosMergeAdmission.diagnostics.test.jsindex 1723d5ac53..f2cde89f28 100644--- a/server/services/cosMergeAdmission.diagnostics.test.js+++ b/server/services/cosMergeAdmission.diagnostics.test.js@@ -1,6 +1,6 @@import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { createFileWriteQueue } from '../lib/fileWriteQueue.js';-import { createManualClock } from '../lib/eventLoopLagProbe.js';+import { __createManualClock } from '../lib/eventLoopLagProbe.js';// #12329: a slow admission phase must say whether its time went to waiting on// the state queue, to asynchronous I/O, or to an event loop that could not run.@@ -20,7 +20,7 @@ vi.mock('./cosState.js', () => ({},}));vi.mock('../lib/gitRemote.js', () => ({ getOriginInfo: async () => ({ host: 'github.com', fullName: 'example/repo' }) }));-import { claimMergeAdmission, setMergeAdmissionClockForTests, withPendingMergeAdmission } from './cosMergeAdmission.js';+import { claimMergeAdmission, __setMergeAdmissionClockForTests, withPendingMergeAdmission } from './cosMergeAdmission.js';const deferred = () => {let resolve;@@ -53,8 +53,8 @@ const enqueue = async (start) => {let clock;beforeEach(() => {- clock = createManualClock();- setMergeAdmissionClockForTests(clock);+ clock = __createManualClock();+ __setMergeAdmissionClockForTests(clock);fixture.queue = createFileWriteQueue();fixture.save = null;fixture.state = { agents: { [agentId]: { id: agentId, taskId: 'synthetic-task', status: 'running',@@ -64,7 +64,7 @@ beforeEach(() => {vi.spyOn(console, 'warn').mockImplementation(() => {});vi.spyOn(console, 'error').mockImplementation(() => {});});-afterEach(() => { setMergeAdmissionClockForTests(null); vi.restoreAllMocks(); });+afterEach(() => { __setMergeAdmissionClockForTests(null); vi.restoreAllMocks(); });describe('merge admission slow-operation diagnostics', () => {it('stays silent for a fast settle and reports an ordinary blocked queue as lag-free queue wait', async () => {diff --git a/server/services/cosMergeAdmission.js b/server/services/cosMergeAdmission.jsindex 7483b9a60d..af5c4f24bf 100644--- a/server/services/cosMergeAdmission.js+++ b/server/services/cosMergeAdmission.js@@ -47,7 +47,7 @@ let clock = systemClock;let lagProbe = createEventLoopLagProbe({ clock });/** Inject a deterministic clock; `null` restores the system clock. */-export function setMergeAdmissionClockForTests(next) {+export function __setMergeAdmissionClockForTests(next) {clock = next ?? systemClock;lagProbe = createEventLoopLagProbe({ clock });}diff --git a/server/services/cosState.js b/server/services/cosState.jsindex 1ac823034e..e777eb40ae 100644--- a/server/services/cosState.js+++ b/server/services/cosState.js@@ -63,7 +63,7 @@ let stateClock = systemClock;let stateLagProbe = createEventLoopLagProbe({ clock: stateClock });/** Inject a deterministic clock; `null` restores the system clock. */-export function setCosStateDiagnosticsClockForTests(clock) {+export function __setCosStateDiagnosticsClockForTests(clock) {stateClock = clock ?? systemClock;stateLagProbe = createEventLoopLagProbe({ clock: stateClock });}diff --git a/server/services/cosState.test.js b/server/services/cosState.test.jsindex e2f470d1b0..2ba425a4e8 100644--- a/server/services/cosState.test.js+++ b/server/services/cosState.test.js@@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach, afterAll, vi } from 'vitest';import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'fs';import { join } from 'path';import { mockPathsDataRoot } from '../lib/mockPathsDataRoot.js';-import { createManualClock } from '../lib/eventLoopLagProbe.js';+import { __createManualClock } from '../lib/eventLoopLagProbe.js';const { tempRoot, makeProxy, cleanup } = mockPathsDataRoot({ prefix: 'cos-state-test-' });@@ -446,8 +446,8 @@ describe('live CoS restore boundary', () => {describe('state operation slow diagnostics', () => {it('reports each persistence stage and splits a slow write into I/O wait and loop lag', async () => {const store = await freshModule();- const clock = createManualClock();- store.setCosStateDiagnosticsClockForTests(clock);+ const clock = __createManualClock();+ store.__setCosStateDiagnosticsClockForTests(clock);const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});try {const stages = [];@@ -467,7 +467,7 @@ describe('state operation slow diagnostics', () => {await store.withStateLock(async () => clock.stall(1200));expect(warn.mock.calls.map(([line]) => line)).toEqual(['🐢 CoS state queue slow hold heldMs=1200 waitMs=0 loopLagMs=1100 loopLagMaxMs=1100']);} finally {- store.setCosStateDiagnosticsClockForTests(null);+ store.__setCosStateDiagnosticsClockForTests(null);warn.mockRestore();}});