Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/import.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ async function measure(path, clock, tally, regen = false) {
* @returns {Promise<{ sessions: number, chats?: number, work?: number, regen?: number }>}
*/
export async function teamSizes(from, team, { budget = 2000, now = Date.now } = {}) {
const { found } = sessionDirs(from, sessionIdsOf(team))
const clock = { until: now() + budget, now }
const { found } = sessionDirs(from, sessionIdsOf(team))
if (clock.now() > clock.until) return { sessions: found.length }
const chats = { bytes: 0, regen: 0 }
const work = { bytes: 0, regen: 0 }
try {
Expand Down
26 changes: 25 additions & 1 deletion app/test/import.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { after, before, describe, test } from 'node:test'
import { entryListSchema } from '@deepseek-ai/cordis-plugin-include'
import { load } from 'js-yaml'
import { parse } from 'yaml'
import { copySessions, findTeam, importTeam, restoreSessions, sessionIdsOf, teamInUse, userDshHome } from '../src/import.mjs'
import { copySessions, findTeam, importTeam, restoreSessions, sessionIdsOf, teamInUse, teamSizes, userDshHome } from '../src/import.mjs'

const write = (path, text) => {
mkdirSync(dirname(path), { recursive: true })
Expand Down Expand Up @@ -52,6 +52,30 @@ const TEAM = {
}
const TEAM_SESSIONS = [['--team--', 'session-a'], ['--team--', 'session-a2'], ['--team--', 'session-g'], ['--team--', 'session-g0'], ['--team--', 'session-r1'], ['--site--', 'session-b']]

describe('teamSizes', () => {
let root
before(() => { root = mkdtempSync(join(tmpdir(), 'ds-bot-app-sizes-')) })
after(() => { rmSync(root, { recursive: true, force: true }) })

test('counts discovery against the budget and omits sizes when it expires', async () => {
let time = 0
const team = { bots: { bot: { id: 'bot', get segments() { time += 2; return [] } } } }
mkdirSync(join(root, 'sessions', 'group', 'bot'), { recursive: true })
assert.deepEqual(await teamSizes(root, team, { budget: 1, now: () => time }), { sessions: 1 })
})

test('measures a discovered Session within the budget', async () => {
write(join(root, 'sessions', 'group', 'sized', 'chat.txt'), 'chat')
assert.deepEqual(await teamSizes(root, { bots: { sized: { id: 'sized' } } }, { now: () => 0 }), {
sessions: 1, chats: 4, work: 0, regen: 0,
})
})

test('measures an empty team', async () => {
assert.deepEqual(await teamSizes(root, {}, { now: () => 0 }), { sessions: 0, chats: 0, work: 0, regen: 0 })
})
})

function oldHome(root) {
const from = join(root, 'dsh')
write(join(from, 'bot', 'state.json'), JSON.stringify(TEAM))
Expand Down
Loading