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: cover lock release on failure, the missing-draft path, and partial effort-map filtering (#3635)
[._.]/ Adam Eivy18659a6bc19d
diff --git a/server/services/codeReview.test.js b/server/services/codeReview.test.jsindex be30b109bb..a6dca65482 100644--- a/server/services/codeReview.test.js+++ b/server/services/codeReview.test.js@@ -340,6 +340,17 @@ describe('codeReview helpers', () => {expect(out.reviewerEfforts).toEqual({})})+ it('strips only the unusable entries from a mixed effort map', async () => {+ mockedSettings.current = { codeReview: { reviewers: ['codex', 'antigravity'] } }+ const out = await resolveReviewLoopOptions(+ { reviewerEfforts: { codex: 'minimal', antigravity: 'max' } },+ testDeps,+ )+ // `minimal` is on codex's ladder and `max` is not on agy's — one bad entry+ // must not take the whole map down with it.+ expect(out.reviewerEfforts).toEqual({ codex: 'minimal' })+ })+it('drops a stale out-of-ladder scalar from the saved defaults', async () => {// settings.json is hand-editable, so the scalars are re-validated rather// than trusted — an unusable level must not surface as a pin.diff --git a/server/services/x.test.js b/server/services/x.test.jsindex 9c06e7da34..c6ce319aa4 100644--- a/server/services/x.test.js+++ b/server/services/x.test.js@@ -218,6 +218,22 @@ describe('syncAccount error reporting', () => {await syncAccount('acct-1');expect(executeXBrowserRead).toHaveBeenCalledTimes(6);});++ // The release lives in a `.finally()`, so a failed read must free the account+ // too — otherwise the cached rejection is handed to every later sync and the+ // account can never be retried without a restart.+ it('releases the sync lock after a failed read so the account can be retried', async () => {+ executeXBrowserRead.mockRejectedValue(new Error('browser session died'));+ await expect(syncAccount('acct-1')).rejects.toThrow('browser session died');++ executeXBrowserRead.mockImplementation(async (name) => (name === 'people'+ ? { handles: ['example_user'], exactMatch: true }+ : { profile: { username: 'example_user' }, posts: [] }));+ const client = { query: vi.fn().mockResolvedValue({ rows: [] }) };+ withTransaction.mockImplementation(async (callback) => callback(client));++ await expect(syncAccount('acct-1')).resolves.toMatchObject({ ingested: 0 });+ });});describe('reviewDraft state transitions', () => {@@ -295,6 +311,16 @@ describe('openApprovedDraft approval gates', () => {const opened = await openApprovedDraft('draft-1');expect(openXHandoff).toHaveBeenCalledWith({ kind: 'compose', value: 'hello world' });expect(opened.state).toBe('opened');+ // Both statements bind the id the caller asked for — the mock answers any+ // SQL, so the parameter is what pins the lookup to the right draft.+ const bound = query.mock.calls.filter(([sql]) => /x_drafts/.test(sql)).map(([, params]) => params[0]);+ expect(bound).toEqual(['draft-1', 'draft-1']);+ });++ it('returns null for a draft id that does not exist', async () => {+ mockDraft(null);+ await expect(openApprovedDraft('draft-missing')).resolves.toBeNull();+ expect(openXHandoff).not.toHaveBeenCalled();});// The 24h gate is the feature's safety story: an approval the user made@@ -308,6 +334,7 @@ describe('openApprovedDraft approval gates', () => {it('still opens a draft approved just inside the 24h window', async () => {mockDraft(draftRow({ approved_at: new Date(Date.now() - 23 * 60 * 60 * 1000).toISOString() }));await expect(openApprovedDraft('draft-fresh')).resolves.toMatchObject({ state: 'opened' });+ expect(openXHandoff).toHaveBeenCalledWith({ kind: 'compose', value: 'hello world' });});it('refuses an approved-state draft with no approval timestamp', async () => {@@ -336,5 +363,19 @@ describe('openApprovedDraft approval gates', () => {const second = openApprovedDraft('draft-1');await Promise.all([first, second]);expect(openXHandoff).toHaveBeenCalledTimes(1);++ // The lock releases once the run settles, so a later open is a fresh handoff.+ await openApprovedDraft('draft-1');+ expect(openXHandoff).toHaveBeenCalledTimes(2);+ });++ // Same `.finally()` release as syncAccount: a refused open must not leave the+ // cached rejection behind for every later attempt on that draft.+ it('releases the open lock after a refusal so a re-approved draft can open', async () => {+ mockDraft(draftRow({ approved_at: new Date(Date.now() - 25 * 60 * 60 * 1000).toISOString() }));+ await expect(openApprovedDraft('draft-1')).rejects.toThrow('X draft approval is stale');++ mockDraft(draftRow());+ await expect(openApprovedDraft('draft-1')).resolves.toMatchObject({ state: 'opened' });});});