Something went wrong. Try again.
A collaborative coding-agent orchestrator for atproto radl.app
Something went wrong. Try again.
JavaScript
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106// Data-directory resolution: the one thing that decides WHICH instance a `radiald` invocation is.// Every assertion here is about a way an operator can end up running the wrong one.
import assert from 'node:assert/strict'import { mkdtemp, rm, writeFile } from 'node:fs/promises'import { tmpdir } from 'node:os'import { join, resolve } from 'node:path'import { it } from 'node:test'import { describeDataDirSource, instanceId, loadInstance, resolveDataDir } from '../dist/index.js'
const CONFIG = { identifier: 'agent.example', harness: 'claude', agents: { planner: { artifactTypes: ['plan'] } },}
it('resolves the data directory by precedence: flag, env, config, default', () => { const env = { HOME: '/home/op' } const configPath = '/home/op/radial/b.json' const config = { ...CONFIG, dataDir: 'b-state' }
assert.deepEqual( resolveDataDir({ flag: '/flag/state', env, config, configPath, cwd: '/cwd' }), { path: '/flag/state', source: 'flag' }, ) // The flag beats the environment, which beats the file — and the shadowed file value is REPORTED // rather than silently dropped, because a stale export in a shell is invisible otherwise. assert.deepEqual( resolveDataDir({ env: { ...env, RADIAL_DATA_DIR: '/env/state' }, config, configPath, cwd: '/cwd' }), { path: '/env/state', source: 'env', shadowed: '/home/op/radial/b-state' }, ) assert.deepEqual(resolveDataDir({ env, config, configPath, cwd: '/cwd' }), { path: '/home/op/radial/b-state', source: 'config', }) assert.deepEqual(resolveDataDir({ env, config: CONFIG, configPath, cwd: '/cwd' }), { path: '/home/op/.local/state/radial', source: 'default', })})
it('an env var that agrees with the config is not reported as shadowing it', () => { const resolved = resolveDataDir({ env: { HOME: '/home/op', RADIAL_DATA_DIR: '/home/op/radial/b-state' }, config: { ...CONFIG, dataDir: 'b-state' }, configPath: '/home/op/radial/b.json', cwd: '/cwd', }) assert.equal(resolved.source, 'env') assert.equal(resolved.shadowed, undefined)})
it('a config "dataDir" is relative to the CONFIG, and a --data-dir flag is relative to the cwd', () => { // The load-bearing asymmetry: the same `radiald run --config …` from two working directories must // be the same instance, or the whole feature is another way to get the wrong identity. A flag // typed in a shell means what a shell means by it. const config = { ...CONFIG, dataDir: './b-state' } const configPath = '/home/op/radial/b.json' const fromHome = resolveDataDir({ env: { HOME: '/home/op' }, config, configPath, cwd: '/home/op' }) const fromElsewhere = resolveDataDir({ env: { HOME: '/home/op' }, config, configPath, cwd: '/tmp/somewhere' }) assert.equal(fromHome.path, '/home/op/radial/b-state') assert.deepEqual(fromHome, fromElsewhere)
assert.equal( resolveDataDir({ flag: 'b-state', env: { HOME: '/home/op' }, cwd: '/tmp/somewhere' }).path, '/tmp/somewhere/b-state', ) // An absolute `dataDir` is left alone. assert.equal( resolveDataDir({ env: { HOME: '/home/op' }, config: { ...CONFIG, dataDir: '/srv/b' }, configPath }).path, '/srv/b', )})
it('names the rule that chose the directory, for the startup banner', () => { const say = (source) => describeDataDirSource({ path: '/x', source }) assert.equal(say('flag'), 'from --data-dir') assert.equal(say('env'), 'from $RADIAL_DATA_DIR') assert.equal(say('config'), 'from "dataDir" in the config') assert.equal(say('default'), 'the default')})
it('loadInstance opens the sessions file the config points at, without any environment discipline', async () => { const dir = await mkdtemp(join(tmpdir(), 'radial-instance-')) try { const configPath = join(dir, 'b.json') await writeFile(configPath, JSON.stringify({ ...CONFIG, dataDir: 'b-state' })) // Deliberately NO $RADIAL_DATA_DIR: `--config` alone has to fully describe the instance. const instance = await loadInstance({ config: configPath, env: { HOME: dir }, cwd: '/' }) assert.equal(instance.configPath, configPath) assert.equal(instance.dataDir.source, 'config') assert.equal(instance.dataDir.path, join(dir, 'b-state')) assert.equal(instance.sessions.path, join(dir, 'b-state', 'sessions.json')) } finally { await rm(dir, { recursive: true, force: true }) }})
it('instanceId is stable per state directory, and differs between two of them', () => { assert.equal(instanceId('/srv/a/run'), instanceId('/srv/a/run/')) assert.equal(instanceId('/srv/a/run'), instanceId(resolve('/srv/a', 'run'))) assert.notEqual(instanceId('/srv/a/run'), instanceId('/srv/b/run')) // Short enough to read in `docker ps`, and legal in a docker container name. assert.match(instanceId('/srv/a/run'), /^[0-9a-f]{6}$/)})