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: verify duration key compatibility within workspace boundaries (#9339)
[._.]/ Adam Eivy5d6c15dfe8e1
diff --git a/client/src/lib/cosDurationEstimate.test.js b/client/src/lib/cosDurationEstimate.test.jsnew file mode 100644index 0000000000..e0bcea5940--- /dev/null+++ b/client/src/lib/cosDurationEstimate.test.js@@ -0,0 +1,38 @@+import { describe, it, expect } from 'vitest';+import { executionDurationKey as serverExecutionDurationKey } from '../../../server/lib/executionDurationKey.js';+import { executionDurationKey, estimateCosDuration } from './cosDurationEstimate.js';++const taskType = 'self-improve:release-check';+const task = { taskType: 'scheduled', description: '[self-improvement] release-check - verify the release' };++describe('persisted execution-duration key compatibility', () => {+ it.each([+ ['high', 'self-improve:release-check|claude|opus|high'],+ [undefined, 'self-improve:release-check|claude|opus|default']+ ])('reads existing history for effort %s with the unchanged server key', (effort, expectedKey) => {+ const identity = { taskType, providerId: 'claude', model: 'opus', effort };+ expect(serverExecutionDurationKey(identity)).toBe(expectedKey);+ expect(executionDurationKey(identity)).toBe(expectedKey);+ const durations = {+ _byExecution: { [expectedKey]: { avgDurationMs: 60_000, completed: 3 } },+ [taskType]: { avgDurationMs: 300_000, completed: 20 }+ };+ expect(estimateCosDuration({ durations, task, agentMetadata: identity }))+ .toMatchObject({ basis: 'execution', estimatedMs: 60_000, basedOn: 3 });+ });++ it('preserves the published task-type and overall fallback without an execution threshold', () => {+ const durations = {+ _byExecution: { 'self-improve:release-check|claude|opus|high': { avgDurationMs: 60_000, completed: 2 } },+ _byExecutionProviderModel: { 'self-improve:release-check|claude|opus': { avgDurationMs: 90_000, completed: 2 } },+ [taskType]: { avgDurationMs: 300_000, completed: 1 },+ _overall: { avgDurationMs: 400_000, completed: 1 }+ };+ const agentMetadata = { providerId: 'claude', model: 'opus', effort: 'high' };+ expect(estimateCosDuration({ durations, task, agentMetadata }))+ .toMatchObject({ basis: 'task-type', estimatedMs: 300_000, basedOn: 1 });+ delete durations[taskType];+ expect(estimateCosDuration({ durations, task, agentMetadata }))+ .toMatchObject({ basis: 'overall', estimatedMs: 400_000, basedOn: 1 });+ });+});diff --git a/server/services/taskLearning/executionDurations.test.js b/server/services/taskLearning/executionDurations.test.jsindex 80812faff1..537f7af6c6 100644--- a/server/services/taskLearning/executionDurations.test.js+++ b/server/services/taskLearning/executionDurations.test.js@@ -25,7 +25,6 @@ import { recordTaskCompletion } from './metrics.js';import { getTaskDurationEstimate, getAllTaskDurations } from './durations.js';import { loadLearningData, saveLearningData, executionDurationKey } from './store.js';import { executionKeyPrefixOf } from '../../lib/executionDurationKey.js';-import { executionDurationKey as clientExecutionDurationKey, estimateCosDuration } from '../../../client/src/lib/cosDurationEstimate.js';const emptyData = () => ({version: 2,@@ -73,21 +72,19 @@ beforeEach(() => {vi.clearAllMocks();});-// Pins the persisted wire format through both entrypoints, including old history.+// Pins the persisted wire format through the recorder and published history.describe('execution-duration persisted key compatibility', () => {it.each([['high', 'self-improve:release-check|claude|opus|high'],[undefined, 'self-improve:release-check|claude|opus|default']- ])('keeps server and browser keys stable for effort %s', async (effort, expectedKey) => {+ ])('keeps recorded and published keys stable for effort %s', async (effort, expectedKey) => {const identity = { taskType: 'self-improve:release-check', providerId: 'claude', model: 'opus', effort };expect(executionDurationKey(identity)).toBe(expectedKey);- expect(clientExecutionDurationKey(identity)).toBe(expectedKey);const data = await record(Array.from({ length: 3 }, () => agentOn({ ...identity, effort: effort ?? null, duration: 60_000 })));expect(Object.keys(data.byTaskTypeExecution)).toEqual([expectedKey]);const durations = await getAllTaskDurations();- expect(estimateCosDuration({ durations, task: TASK, agentMetadata: identity }))- .toMatchObject({ basis: 'execution', estimatedMs: 60_000, basedOn: 3 });+ expect(durations._byExecution[expectedKey]).toMatchObject({ avgDurationMs: 60_000, completed: 3 });});});@@ -240,7 +237,6 @@ describe('getAllTaskDurations — reserved keys', () => {expect(Object.keys(out).filter((k) => !k.startsWith('_')), 'only real task types are top-level').toEqual(['self-improve:release-check']);expect(executionKeyPrefixOf(lowKey)).toBe('self-improve:release-check|ollama|local-coder');- expect(clientExecutionDurationKey({ taskType: 'self-improve:release-check', providerId: 'ollama', model: 'local-coder', effort: 'low' })).toBe(lowKey);expect(out._byExecution[lowKey]).toMatchObject({ avgDurationMs: 400_000, completed: 2 });expect(out._byExecutionProviderModel['self-improve:release-check|ollama|local-coder']).toMatchObject({ avgDurationMs: 500_000, completed: 4 });