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
cover worktreeHoldExpiresAt at its own module
[._.]/ Adam Eivyca25030041e4
diff --git a/server/lib/worktreeOwnership.test.js b/server/lib/worktreeOwnership.test.jsindex 8558baee6e..0654ed3ee0 100644--- a/server/lib/worktreeOwnership.test.js+++ b/server/lib/worktreeOwnership.test.js@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest';-import { isAgentWorktreeId, isHumanClaimWorktree, worktreeAgentId, worktreeOwnershipReason } from './worktreeOwnership.js';+import { isAgentWorktreeId, isHumanClaimWorktree, worktreeAgentId, worktreeHoldExpiresAt, worktreeOwnershipReason } from './worktreeOwnership.js';describe('worktree ownership', () => {const COS_ROOT = '/repo/data/cos/worktrees';@@ -46,3 +46,49 @@ describe('worktree ownership', () => {expect(isHumanClaimWorktree('claim-issue-42')).toBe(true);});});++describe('worktreeHoldExpiresAt', () => {+ const COS_ROOT = '/repo/data/cos/worktrees';+ const NOW = Date.parse('2026-01-10T00:00:00.000Z');+ const claim = (over = {}) => worktreeHoldExpiresAt({+ path: `${COS_ROOT}/claim-issue-42`, allowStaleClaim: true, ageMs: 2_000, staleClaimIdleMs: 7_000, nowMs: NOW, ...over+ });++ it('dates a stale-claim hold to the moment its window lapses', () => {+ expect(claim()).toBe(new Date(NOW + 5_000).toISOString());+ });++ it('gives no expiry to a claim tree that is ALSO locked', () => {+ // The slug still reads 'worktree-human-claim' (first match wins), but the+ // lock outlives the window — deriving a date from the slug alone would+ // promise a lift that never happens.+ expect(claim({ locked: true })).toBeNull();+ });++ it('gives no expiry to a claim tree whose agent is still live', () => {+ expect(worktreeHoldExpiresAt({+ path: `${COS_ROOT}/claim-issue-42`, allowStaleClaim: true, ageMs: 2_000, staleClaimIdleMs: 7_000,+ activeAgentIds: new Set(['claim-issue-42']), nowMs: NOW+ })).toBeNull();+ });++ it('gives no expiry when the caller has not opted into stale-claim reclamation', () => {+ // Without allowStaleClaim the window never lapses for this caller, so there+ // is no deadline to report.+ expect(claim({ allowStaleClaim: false })).toBeNull();+ });++ it('gives no expiry once the window has already lapsed, or when age is unknown', () => {+ expect(claim({ ageMs: 9_000 })).toBeNull();+ expect(claim({ ageMs: 7_000 })).toBeNull();+ for (const ageMs of [null, undefined, NaN, 'old']) expect(claim({ ageMs })).toBeNull();+ expect(claim({ staleClaimIdleMs: undefined })).toBeNull();+ });++ it('gives no expiry to holds that are not the stale-claim window', () => {+ expect(worktreeHoldExpiresAt({ path: `${COS_ROOT}/agent-live`, activeAgentIds: new Set(['agent-live']), ageMs: 2_000, staleClaimIdleMs: 7_000 })).toBeNull();+ expect(worktreeHoldExpiresAt({ path: null })).toBeNull();+ // A tree nothing holds at all has no expiry either — there is no wait.+ expect(worktreeHoldExpiresAt({ path: `${COS_ROOT}/agent-dead`, activeAgentIds: new Set(), ageMs: 2_000, staleClaimIdleMs: 7_000 })).toBeNull();+ });+});