oh-my-codex 0.21.48 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +6 -6
- package/Cargo.toml +1 -1
- package/README.md +15 -0
- package/crates/omx-mux/src/herdr.rs +481 -0
- package/crates/omx-mux/src/lib.rs +5 -0
- package/dist/cli/__tests__/session-compare.test.d.ts +2 -0
- package/dist/cli/__tests__/session-compare.test.d.ts.map +1 -0
- package/dist/cli/__tests__/session-compare.test.js +183 -0
- package/dist/cli/__tests__/session-compare.test.js.map +1 -0
- package/dist/cli/__tests__/team.test.js +8 -0
- package/dist/cli/__tests__/team.test.js.map +1 -1
- package/dist/cli/session-compare.d.ts +11 -0
- package/dist/cli/session-compare.d.ts.map +1 -0
- package/dist/cli/session-compare.js +172 -0
- package/dist/cli/session-compare.js.map +1 -0
- package/dist/cli/session-search.d.ts.map +1 -1
- package/dist/cli/session-search.js +7 -0
- package/dist/cli/session-search.js.map +1 -1
- package/dist/cli/team.d.ts.map +1 -1
- package/dist/cli/team.js +2 -0
- package/dist/cli/team.js.map +1 -1
- package/dist/config/__tests__/multiplexer.test.d.ts +2 -0
- package/dist/config/__tests__/multiplexer.test.d.ts.map +1 -0
- package/dist/config/__tests__/multiplexer.test.js +118 -0
- package/dist/config/__tests__/multiplexer.test.js.map +1 -0
- package/dist/config/multiplexer.d.ts +29 -0
- package/dist/config/multiplexer.d.ts.map +1 -0
- package/dist/config/multiplexer.js +91 -0
- package/dist/config/multiplexer.js.map +1 -0
- package/dist/scripts/__tests__/codex-native-hook.test.js +281 -1
- package/dist/scripts/__tests__/codex-native-hook.test.js.map +1 -1
- package/dist/scripts/codex-native-hook.d.ts.map +1 -1
- package/dist/scripts/codex-native-hook.js +8 -2
- package/dist/scripts/codex-native-hook.js.map +1 -1
- package/dist/scripts/notify-hook/team-worker-lease.d.ts +15 -0
- package/dist/scripts/notify-hook/team-worker-lease.d.ts.map +1 -0
- package/dist/scripts/notify-hook/team-worker-lease.js +63 -0
- package/dist/scripts/notify-hook/team-worker-lease.js.map +1 -0
- package/dist/scripts/notify-hook/team-worker-posttooluse.d.ts +1 -0
- package/dist/scripts/notify-hook/team-worker-posttooluse.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-worker-posttooluse.js +16 -5
- package/dist/scripts/notify-hook/team-worker-posttooluse.js.map +1 -1
- package/dist/scripts/notify-hook/team-worker.d.ts +12 -1
- package/dist/scripts/notify-hook/team-worker.d.ts.map +1 -1
- package/dist/scripts/notify-hook/team-worker.js +16 -4
- package/dist/scripts/notify-hook/team-worker.js.map +1 -1
- package/dist/session-history/__tests__/compare.test.d.ts +2 -0
- package/dist/session-history/__tests__/compare.test.d.ts.map +1 -0
- package/dist/session-history/__tests__/compare.test.js +257 -0
- package/dist/session-history/__tests__/compare.test.js.map +1 -0
- package/dist/session-history/compare.d.ts +74 -0
- package/dist/session-history/compare.d.ts.map +1 -0
- package/dist/session-history/compare.js +165 -0
- package/dist/session-history/compare.js.map +1 -0
- package/dist/team/__tests__/api-interop.test.js +3 -3
- package/dist/team/__tests__/cross-rebase-smoke.test.js +263 -31
- package/dist/team/__tests__/cross-rebase-smoke.test.js.map +1 -1
- package/dist/team/__tests__/herdr-session-realherdr.test.d.ts +2 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.d.ts.map +1 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.js +68 -0
- package/dist/team/__tests__/herdr-session-realherdr.test.js.map +1 -0
- package/dist/team/__tests__/herdr-session.test.d.ts +2 -0
- package/dist/team/__tests__/herdr-session.test.d.ts.map +1 -0
- package/dist/team/__tests__/herdr-session.test.js +228 -0
- package/dist/team/__tests__/herdr-session.test.js.map +1 -0
- package/dist/team/__tests__/idle-nudge.test.js +84 -0
- package/dist/team/__tests__/idle-nudge.test.js.map +1 -1
- package/dist/team/__tests__/rebalance-policy.test.js +27 -9
- package/dist/team/__tests__/rebalance-policy.test.js.map +1 -1
- package/dist/team/__tests__/runtime-delivery.test.d.ts +2 -0
- package/dist/team/__tests__/runtime-delivery.test.d.ts.map +1 -0
- package/dist/team/__tests__/runtime-delivery.test.js +570 -0
- package/dist/team/__tests__/runtime-delivery.test.js.map +1 -0
- package/dist/team/__tests__/runtime.test.js +332 -18
- package/dist/team/__tests__/runtime.test.js.map +1 -1
- package/dist/team/__tests__/scaling.test.js +293 -0
- package/dist/team/__tests__/scaling.test.js.map +1 -1
- package/dist/team/__tests__/state-renewal.test.d.ts +2 -0
- package/dist/team/__tests__/state-renewal.test.d.ts.map +1 -0
- package/dist/team/__tests__/state-renewal.test.js +555 -0
- package/dist/team/__tests__/state-renewal.test.js.map +1 -0
- package/dist/team/__tests__/task-lease.test.d.ts +2 -0
- package/dist/team/__tests__/task-lease.test.d.ts.map +1 -0
- package/dist/team/__tests__/task-lease.test.js +179 -0
- package/dist/team/__tests__/task-lease.test.js.map +1 -0
- package/dist/team/__tests__/team-ops-contract.test.js +1 -0
- package/dist/team/__tests__/team-ops-contract.test.js.map +1 -1
- package/dist/team/__tests__/worker-bootstrap.test.js +2 -0
- package/dist/team/__tests__/worker-bootstrap.test.js.map +1 -1
- package/dist/team/api-interop.d.ts +1 -1
- package/dist/team/api-interop.d.ts.map +1 -1
- package/dist/team/api-interop.js +13 -1
- package/dist/team/api-interop.js.map +1 -1
- package/dist/team/goal-workflow.js +1 -1
- package/dist/team/herdr-session.d.ts +234 -0
- package/dist/team/herdr-session.d.ts.map +1 -0
- package/dist/team/herdr-session.js +489 -0
- package/dist/team/herdr-session.js.map +1 -0
- package/dist/team/idle-nudge.d.ts +16 -4
- package/dist/team/idle-nudge.d.ts.map +1 -1
- package/dist/team/idle-nudge.js +51 -19
- package/dist/team/idle-nudge.js.map +1 -1
- package/dist/team/mcp-comm.d.ts +1 -1
- package/dist/team/mcp-comm.d.ts.map +1 -1
- package/dist/team/rebalance-policy.d.ts.map +1 -1
- package/dist/team/rebalance-policy.js +5 -2
- package/dist/team/rebalance-policy.js.map +1 -1
- package/dist/team/runtime.d.ts.map +1 -1
- package/dist/team/runtime.js +356 -81
- package/dist/team/runtime.js.map +1 -1
- package/dist/team/scaling.d.ts.map +1 -1
- package/dist/team/scaling.js +332 -143
- package/dist/team/scaling.js.map +1 -1
- package/dist/team/state/monitor.d.ts +3 -0
- package/dist/team/state/monitor.d.ts.map +1 -1
- package/dist/team/state/monitor.js +3 -0
- package/dist/team/state/monitor.js.map +1 -1
- package/dist/team/state/tasks.d.ts +2 -1
- package/dist/team/state/tasks.d.ts.map +1 -1
- package/dist/team/state/tasks.js +28 -0
- package/dist/team/state/tasks.js.map +1 -1
- package/dist/team/state/types.d.ts +8 -0
- package/dist/team/state/types.d.ts.map +1 -1
- package/dist/team/state/types.js.map +1 -1
- package/dist/team/state.d.ts +14 -2
- package/dist/team/state.d.ts.map +1 -1
- package/dist/team/state.js +29 -5
- package/dist/team/state.js.map +1 -1
- package/dist/team/task-lease.d.ts +4 -0
- package/dist/team/task-lease.d.ts.map +1 -0
- package/dist/team/task-lease.js +74 -0
- package/dist/team/task-lease.js.map +1 -0
- package/dist/team/team-ops.d.ts +2 -1
- package/dist/team/team-ops.d.ts.map +1 -1
- package/dist/team/team-ops.js +1 -0
- package/dist/team/team-ops.js.map +1 -1
- package/dist/team/tmux-session.d.ts +1 -1
- package/dist/team/tmux-session.d.ts.map +1 -1
- package/dist/team/tmux-session.js +10 -2
- package/dist/team/tmux-session.js.map +1 -1
- package/dist/team/worker-bootstrap.d.ts.map +1 -1
- package/dist/team/worker-bootstrap.js +14 -1
- package/dist/team/worker-bootstrap.js.map +1 -1
- package/package.json +1 -1
- package/plugins/oh-my-codex/.codex-plugin/plugin.json +1 -1
- package/plugins/oh-my-codex/skills/worker/SKILL.md +7 -1
- package/skills/worker/SKILL.md +7 -1
- package/src/scripts/__tests__/codex-native-hook.test.ts +279 -0
- package/src/scripts/codex-native-hook.ts +8 -2
- package/src/scripts/notify-hook/team-worker-lease.ts +69 -0
- package/src/scripts/notify-hook/team-worker-posttooluse.ts +16 -4
- package/src/scripts/notify-hook/team-worker.ts +15 -4
|
@@ -4198,4 +4198,297 @@ describe('forced scale-down worktree rollback', () => {
|
|
|
4198
4198
|
}
|
|
4199
4199
|
});
|
|
4200
4200
|
});
|
|
4201
|
+
/**
|
|
4202
|
+
* Fake herdr binary answering the JSON-envelope CLI contract (success on
|
|
4203
|
+
* stdout, error envelope on stderr with exit 1). Every invocation is logged.
|
|
4204
|
+
* Tests pin it via HERDR_BIN_PATH (the trust-pin resolveHerdrBinary honors).
|
|
4205
|
+
*/
|
|
4206
|
+
async function writeFakeHerdrStub(fakeBinDir, herdrLogPath, options = {}) {
|
|
4207
|
+
const herdrStubPath = join(fakeBinDir, 'herdr');
|
|
4208
|
+
const agentStartBranch = options.failAgentStartCode
|
|
4209
|
+
? [
|
|
4210
|
+
`printf '%s' '{"error":{"code":"${options.failAgentStartCode}","message":"stub injected failure"}}' >&2`,
|
|
4211
|
+
'exit 1',
|
|
4212
|
+
].join('\n')
|
|
4213
|
+
: [
|
|
4214
|
+
`printf '%s\\n' '{"id":"cli:agent:start","result":{"agent":{"agent_status":"idle"}}}'`,
|
|
4215
|
+
'exit 0',
|
|
4216
|
+
].join('\n');
|
|
4217
|
+
const paneCloseBranch = options.paneCloseNotFound
|
|
4218
|
+
? [
|
|
4219
|
+
`printf '%s' '{"error":{"code":"pane_not_found","message":"pane already closed"}}' >&2`,
|
|
4220
|
+
'exit 1',
|
|
4221
|
+
].join('\n')
|
|
4222
|
+
: [
|
|
4223
|
+
`printf '%s\\n' '{"id":"cli:pane:close","result":{"type":"ok"}}'`,
|
|
4224
|
+
'exit 0',
|
|
4225
|
+
].join('\n');
|
|
4226
|
+
await writeFile(herdrStubPath, [
|
|
4227
|
+
'#!/bin/sh',
|
|
4228
|
+
`printf '%s\\n' "$*" >> "${herdrLogPath}"`,
|
|
4229
|
+
'cmd="${1:-}"',
|
|
4230
|
+
'sub="${2:-}"',
|
|
4231
|
+
'case "$cmd:$sub" in',
|
|
4232
|
+
' --version:)',
|
|
4233
|
+
' printf \'%s\\n\' "herdr 0.9.5-stub"',
|
|
4234
|
+
' exit 0',
|
|
4235
|
+
' ;;',
|
|
4236
|
+
' workspace:list)',
|
|
4237
|
+
` printf '%s\\n' '{"id":"cli:workspace:list","result":{"workspaces":[],"type":"workspace_list"}}'`,
|
|
4238
|
+
' exit 0',
|
|
4239
|
+
' ;;',
|
|
4240
|
+
' tab:create)',
|
|
4241
|
+
` printf '%s\\n' '{"id":"cli:tab:create","result":{"tab":{"tab_id":"w5:t9"},"root_pane":{"pane_id":"w5:p9"}}}'`,
|
|
4242
|
+
' exit 0',
|
|
4243
|
+
' ;;',
|
|
4244
|
+
' agent:start)',
|
|
4245
|
+
` ${agentStartBranch}`,
|
|
4246
|
+
' ;;',
|
|
4247
|
+
' agent:prompt|agent:get|agent:send-keys|agent:wait)',
|
|
4248
|
+
` printf '%s\\n' '{"id":"cli:agent:result","result":{"agent":{}}}'`,
|
|
4249
|
+
' exit 0',
|
|
4250
|
+
' ;;',
|
|
4251
|
+
' agent:list)',
|
|
4252
|
+
` printf '%s\\n' '{"id":"cli:agent:list","result":{"agents":[],"type":"agent_list"}}'`,
|
|
4253
|
+
' exit 0',
|
|
4254
|
+
' ;;',
|
|
4255
|
+
' pane:close)',
|
|
4256
|
+
` ${paneCloseBranch}`,
|
|
4257
|
+
' ;;',
|
|
4258
|
+
' pane:read)',
|
|
4259
|
+
' printf \'%s\\n\' "› "',
|
|
4260
|
+
' exit 0',
|
|
4261
|
+
' ;;',
|
|
4262
|
+
' *)',
|
|
4263
|
+
` printf '%s\\n' '{"id":"cli:unknown","result":{}}'`,
|
|
4264
|
+
' exit 0',
|
|
4265
|
+
' ;;',
|
|
4266
|
+
'esac',
|
|
4267
|
+
'',
|
|
4268
|
+
].join('\n'));
|
|
4269
|
+
execFileSync('sh', ['-n', herdrStubPath], { stdio: 'pipe' });
|
|
4270
|
+
await chmod(herdrStubPath, 0o755);
|
|
4271
|
+
await writeFile(herdrLogPath, '');
|
|
4272
|
+
return herdrStubPath;
|
|
4273
|
+
}
|
|
4274
|
+
async function readHerdrStubLog(herdrLogPath) {
|
|
4275
|
+
const content = await readFile(herdrLogPath, 'utf-8');
|
|
4276
|
+
const trimmed = content.trim();
|
|
4277
|
+
return trimmed === '' ? [] : trimmed.split('\n');
|
|
4278
|
+
}
|
|
4279
|
+
async function configureHerdrScaleTeam(teamName, cwd, workerPaneIds, dispatchMode = 'transport_direct') {
|
|
4280
|
+
const config = await readTeamConfig(teamName, cwd);
|
|
4281
|
+
assert.ok(config);
|
|
4282
|
+
if (!config)
|
|
4283
|
+
throw new Error(`missing team config for ${teamName}`);
|
|
4284
|
+
config.worker_launch_mode = 'herdr';
|
|
4285
|
+
config.tmux_session = `herdr-${teamName}`;
|
|
4286
|
+
config.leader_pane_id = null;
|
|
4287
|
+
config.hud_pane_id = null;
|
|
4288
|
+
config.tmux_pane_owner_id = undefined;
|
|
4289
|
+
config.workers.forEach((worker, index) => {
|
|
4290
|
+
worker.pane_id = workerPaneIds[index];
|
|
4291
|
+
worker.pid = undefined;
|
|
4292
|
+
});
|
|
4293
|
+
await saveTeamConfig(config, cwd);
|
|
4294
|
+
const manifestPath = join(cwd, '.omx', 'state', 'team', teamName, 'manifest.v2.json');
|
|
4295
|
+
if (!existsSync(manifestPath)) {
|
|
4296
|
+
await mkdir(join(cwd, '.omx', 'state', 'team', teamName), { recursive: true });
|
|
4297
|
+
await writeFile(manifestPath, `${JSON.stringify({ version: 2, policy: {} }, null, 2)}\n`);
|
|
4298
|
+
}
|
|
4299
|
+
const manifest = JSON.parse(await readFile(manifestPath, 'utf-8'));
|
|
4300
|
+
manifest.policy = {
|
|
4301
|
+
...(manifest.policy ?? {}),
|
|
4302
|
+
dispatch_mode: dispatchMode,
|
|
4303
|
+
};
|
|
4304
|
+
await writeFile(manifestPath, JSON.stringify(manifest, null, 2));
|
|
4305
|
+
}
|
|
4306
|
+
describe('scaling on herdr', () => {
|
|
4307
|
+
it('scaleUp spawns a herdr tab+agent in the team workspace and dispatches via agent prompt', async () => {
|
|
4308
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-scale-herdr-up-'));
|
|
4309
|
+
const fakeBinDir = await mkdtemp(join(tmpdir(), 'omx-scale-herdr-up-bin-'));
|
|
4310
|
+
const herdrLogPath = join(fakeBinDir, 'herdr.log');
|
|
4311
|
+
try {
|
|
4312
|
+
const herdrBin = await writeFakeHerdrStub(fakeBinDir, herdrLogPath);
|
|
4313
|
+
await initTeamState('scale-herdr-up', 'task', 'executor', 1, cwd, DEFAULT_MAX_WORKERS, {
|
|
4314
|
+
OMX_TEAM_WORKER_LAUNCH_MODE: 'herdr',
|
|
4315
|
+
});
|
|
4316
|
+
await configureHerdrScaleTeam('scale-herdr-up', cwd, ['w5:p2']);
|
|
4317
|
+
const result = await scaleUp('scale-herdr-up', 1, 'executor', [{ subject: 'new task', description: 'new task', owner: 'worker-2' }], cwd, {
|
|
4318
|
+
OMX_TEAM_SCALING_ENABLED: '1',
|
|
4319
|
+
OMX_MULTIPLEXER: 'herdr',
|
|
4320
|
+
HERDR_BIN_PATH: herdrBin,
|
|
4321
|
+
});
|
|
4322
|
+
assert.equal(result.ok, true, JSON.stringify(result));
|
|
4323
|
+
if (!result.ok)
|
|
4324
|
+
return;
|
|
4325
|
+
assert.equal(result.newWorkerCount, 2);
|
|
4326
|
+
assert.equal(result.nextWorkerIndex, 3);
|
|
4327
|
+
assert.equal(result.addedWorkers[0]?.pane_id, 'w5:p9');
|
|
4328
|
+
assert.equal(result.addedWorkers[0]?.pid, undefined);
|
|
4329
|
+
const config = await readTeamConfig('scale-herdr-up', cwd);
|
|
4330
|
+
assert.ok(config);
|
|
4331
|
+
assert.equal(config?.workers.length, 2);
|
|
4332
|
+
assert.equal(config?.workers[1]?.pane_id, 'w5:p9');
|
|
4333
|
+
assert.equal(config?.workers[1]?.pid, undefined);
|
|
4334
|
+
assert.equal(config?.next_worker_index, 3);
|
|
4335
|
+
const identity = JSON.parse(await readFile(join(cwd, '.omx', 'state', 'team', 'scale-herdr-up', 'workers', 'worker-2', 'identity.json'), 'utf-8'));
|
|
4336
|
+
assert.equal(identity.pane_id, 'w5:p9');
|
|
4337
|
+
const commands = await readHerdrStubLog(herdrLogPath);
|
|
4338
|
+
const tabCreate = commands.find((command) => command.startsWith('tab create '));
|
|
4339
|
+
assert.ok(tabCreate, 'worker spawns through herdr tab create');
|
|
4340
|
+
assert.ok(tabCreate.includes('--workspace w5'), 'tab create pins the derived team workspace');
|
|
4341
|
+
assert.ok(tabCreate.includes('--cwd '), 'tab create pins the worker cwd');
|
|
4342
|
+
assert.ok(tabCreate.includes('--env OMX_TEAM_STATE_ROOT='), 'worker env injected via tab create --env');
|
|
4343
|
+
const agentStart = commands.find((command) => command.startsWith('agent start '));
|
|
4344
|
+
assert.ok(agentStart, 'worker agent started');
|
|
4345
|
+
assert.ok(agentStart.includes('--kind codex'), 'agent kind derived from the launch plan');
|
|
4346
|
+
assert.ok(agentStart.includes('--pane w5:p9'), 'agent pinned to the created pane');
|
|
4347
|
+
const agentPrompt = commands.find((command) => command.startsWith('agent prompt w5:p9 '));
|
|
4348
|
+
assert.ok(agentPrompt, 'bootstrap trigger dispatched through herdr agent prompt');
|
|
4349
|
+
// No tmux authority was consulted anywhere in the herdr path.
|
|
4350
|
+
assert.equal(commands.some((command) => command.startsWith('agent list')), true, 'server liveness checked via agent list');
|
|
4351
|
+
}
|
|
4352
|
+
finally {
|
|
4353
|
+
await rm(cwd, { recursive: true, force: true });
|
|
4354
|
+
await rm(fakeBinDir, { recursive: true, force: true });
|
|
4355
|
+
}
|
|
4356
|
+
});
|
|
4357
|
+
it('scaleUp on herdr rolls back the created pane, task, and worker state when the agent start fails', async () => {
|
|
4358
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-scale-herdr-fail-'));
|
|
4359
|
+
const fakeBinDir = await mkdtemp(join(tmpdir(), 'omx-scale-herdr-fail-bin-'));
|
|
4360
|
+
const herdrLogPath = join(fakeBinDir, 'herdr.log');
|
|
4361
|
+
try {
|
|
4362
|
+
const herdrBin = await writeFakeHerdrStub(fakeBinDir, herdrLogPath, { failAgentStartCode: 'agent_not_found' });
|
|
4363
|
+
await initTeamState('scale-herdr-fail', 'task', 'executor', 1, cwd, DEFAULT_MAX_WORKERS, {
|
|
4364
|
+
OMX_TEAM_WORKER_LAUNCH_MODE: 'herdr',
|
|
4365
|
+
});
|
|
4366
|
+
await configureHerdrScaleTeam('scale-herdr-fail', cwd, ['w5:p2']);
|
|
4367
|
+
const result = await scaleUp('scale-herdr-fail', 1, 'executor', [{ subject: 'new task', description: 'new task', owner: 'worker-2' }], cwd, {
|
|
4368
|
+
OMX_TEAM_SCALING_ENABLED: '1',
|
|
4369
|
+
OMX_MULTIPLEXER: 'herdr',
|
|
4370
|
+
HERDR_BIN_PATH: herdrBin,
|
|
4371
|
+
});
|
|
4372
|
+
assert.equal(result.ok, false);
|
|
4373
|
+
if (result.ok)
|
|
4374
|
+
return;
|
|
4375
|
+
assert.match(result.error, /scale_up_herdr_spawn_failed:worker-2:herdr_agent_not_found/);
|
|
4376
|
+
const commands = await readHerdrStubLog(herdrLogPath);
|
|
4377
|
+
assert.ok(commands.some((command) => command === 'pane close w5:p9'), 'the spawn helper closes its own pane on failure');
|
|
4378
|
+
const config = await readTeamConfig('scale-herdr-fail', cwd);
|
|
4379
|
+
assert.ok(config);
|
|
4380
|
+
assert.equal(config?.workers.length, 1);
|
|
4381
|
+
assert.equal(config?.workers[0]?.pane_id, 'w5:p2');
|
|
4382
|
+
assert.equal(config?.next_worker_index, 2);
|
|
4383
|
+
assert.equal(existsSync(join(cwd, '.omx', 'state', 'team', 'scale-herdr-fail', 'workers', 'worker-2')), false);
|
|
4384
|
+
assert.deepEqual(await readScaleUpTaskPayloads('scale-herdr-fail', cwd), []);
|
|
4385
|
+
}
|
|
4386
|
+
finally {
|
|
4387
|
+
await rm(cwd, { recursive: true, force: true });
|
|
4388
|
+
await rm(fakeBinDir, { recursive: true, force: true });
|
|
4389
|
+
}
|
|
4390
|
+
});
|
|
4391
|
+
it('scaleUp returns a clear error when the herdr backend is selected but the binary is missing', async () => {
|
|
4392
|
+
const result = await scaleUp('scale-herdr-missing', 1, 'executor', [], '/tmp', {
|
|
4393
|
+
OMX_TEAM_SCALING_ENABLED: '1',
|
|
4394
|
+
OMX_MULTIPLEXER: 'herdr',
|
|
4395
|
+
PATH: '',
|
|
4396
|
+
});
|
|
4397
|
+
assert.equal(result.ok, false);
|
|
4398
|
+
if (result.ok)
|
|
4399
|
+
return;
|
|
4400
|
+
assert.match(result.error, /herdr binary is not callable/);
|
|
4401
|
+
});
|
|
4402
|
+
it('scaleDown closes the herdr pane and commits the membership removal', async () => {
|
|
4403
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-scale-herdr-down-'));
|
|
4404
|
+
const fakeBinDir = await mkdtemp(join(tmpdir(), 'omx-scale-herdr-down-bin-'));
|
|
4405
|
+
const herdrLogPath = join(fakeBinDir, 'herdr.log');
|
|
4406
|
+
const previousHerdrBinPath = process.env.HERDR_BIN_PATH;
|
|
4407
|
+
try {
|
|
4408
|
+
const herdrBin = await writeFakeHerdrStub(fakeBinDir, herdrLogPath);
|
|
4409
|
+
// The final cleanup-debt reconcile resolves the binary from the ambient
|
|
4410
|
+
// env, so pin the stub there too (not only in the scaleDown env param).
|
|
4411
|
+
process.env.HERDR_BIN_PATH = herdrBin;
|
|
4412
|
+
await initTeamState('scale-herdr-down', 'task', 'executor', 2, cwd, DEFAULT_MAX_WORKERS, {
|
|
4413
|
+
OMX_TEAM_WORKER_LAUNCH_MODE: 'herdr',
|
|
4414
|
+
});
|
|
4415
|
+
await configureHerdrScaleTeam('scale-herdr-down', cwd, ['w5:p2', 'w5:p3']);
|
|
4416
|
+
const result = await scaleDown('scale-herdr-down', cwd, { workerNames: ['worker-2'] }, {
|
|
4417
|
+
OMX_TEAM_SCALING_ENABLED: '1',
|
|
4418
|
+
OMX_MULTIPLEXER: 'herdr',
|
|
4419
|
+
HERDR_BIN_PATH: herdrBin,
|
|
4420
|
+
});
|
|
4421
|
+
assert.deepEqual(result, { ok: true, removedWorkers: ['worker-2'], newWorkerCount: 1 });
|
|
4422
|
+
const commands = await readHerdrStubLog(herdrLogPath);
|
|
4423
|
+
assert.ok(commands.some((command) => command === 'pane close w5:p3'), 'the removed worker pane is closed through herdr');
|
|
4424
|
+
const config = await readTeamConfig('scale-herdr-down', cwd);
|
|
4425
|
+
assert.ok(config);
|
|
4426
|
+
assert.equal(config?.workers.length, 1);
|
|
4427
|
+
assert.equal(config?.workers[0]?.pane_id, 'w5:p2');
|
|
4428
|
+
assert.equal(existsSync(join(cwd, '.omx', 'state', 'team', 'scale-herdr-down', '.scale-down-cleanup-debt.json')), false);
|
|
4429
|
+
}
|
|
4430
|
+
finally {
|
|
4431
|
+
if (typeof previousHerdrBinPath === 'string')
|
|
4432
|
+
process.env.HERDR_BIN_PATH = previousHerdrBinPath;
|
|
4433
|
+
else
|
|
4434
|
+
delete process.env.HERDR_BIN_PATH;
|
|
4435
|
+
await rm(cwd, { recursive: true, force: true });
|
|
4436
|
+
await rm(fakeBinDir, { recursive: true, force: true });
|
|
4437
|
+
}
|
|
4438
|
+
});
|
|
4439
|
+
it('reconcileScaleDownCleanupDebt resolves herdr pane debt, treating pane_not_found as converged', async () => {
|
|
4440
|
+
const cwd = await mkdtemp(join(tmpdir(), 'omx-scale-herdr-debt-'));
|
|
4441
|
+
const fakeBinDir = await mkdtemp(join(tmpdir(), 'omx-scale-herdr-debt-bin-'));
|
|
4442
|
+
const previousHerdrBinPath = process.env.HERDR_BIN_PATH;
|
|
4443
|
+
try {
|
|
4444
|
+
await initTeamState('scale-herdr-debt', 'task', 'executor', 1, cwd, DEFAULT_MAX_WORKERS, {
|
|
4445
|
+
OMX_TEAM_WORKER_LAUNCH_MODE: 'herdr',
|
|
4446
|
+
});
|
|
4447
|
+
await configureHerdrScaleTeam('scale-herdr-debt', cwd, ['w5:p2']);
|
|
4448
|
+
const config = await readTeamConfig('scale-herdr-debt', cwd);
|
|
4449
|
+
assert.ok(config);
|
|
4450
|
+
const debtPath = join(cwd, '.omx', 'state', 'team', 'scale-herdr-debt', '.scale-down-cleanup-debt.json');
|
|
4451
|
+
const debt = {
|
|
4452
|
+
schema_version: 1,
|
|
4453
|
+
operation: 'scale_down',
|
|
4454
|
+
status: 'unresolved',
|
|
4455
|
+
created_at: new Date().toISOString(),
|
|
4456
|
+
removed_worker_names: ['worker-2'],
|
|
4457
|
+
workers: [{ name: 'worker-2', index: 2, pane_id: 'w5:p9', pid: null }],
|
|
4458
|
+
resource_workers: [{ name: 'worker-2' }],
|
|
4459
|
+
};
|
|
4460
|
+
await writeFile(debtPath, JSON.stringify(debt, null, 2));
|
|
4461
|
+
// A herdr pane recorded with a PID is malformed: herdr panes carry none.
|
|
4462
|
+
const malformedBin = await writeFakeHerdrStub(fakeBinDir, join(fakeBinDir, 'malformed.log'));
|
|
4463
|
+
process.env.HERDR_BIN_PATH = malformedBin;
|
|
4464
|
+
await writeFile(debtPath, JSON.stringify({ ...debt, workers: [{ name: 'worker-2', index: 2, pane_id: 'w5:p9', pid: 4242 }] }, null, 2));
|
|
4465
|
+
const malformed = await reconcileScaleDownCleanupDebt('scale-herdr-debt', cwd, config);
|
|
4466
|
+
assert.equal(malformed.ok, false);
|
|
4467
|
+
if (!malformed.ok)
|
|
4468
|
+
assert.match(malformed.error, /scale_down_cleanup_debt_malformed/);
|
|
4469
|
+
// Still-open pane: close it and converge.
|
|
4470
|
+
const openBin = await writeFakeHerdrStub(fakeBinDir, join(fakeBinDir, 'open.log'), { paneCloseNotFound: false });
|
|
4471
|
+
process.env.HERDR_BIN_PATH = openBin;
|
|
4472
|
+
await writeFile(debtPath, JSON.stringify(debt, null, 2));
|
|
4473
|
+
const openOutcome = await reconcileScaleDownCleanupDebt('scale-herdr-debt', cwd, config);
|
|
4474
|
+
assert.deepEqual(openOutcome, { ok: true });
|
|
4475
|
+
assert.equal(existsSync(debtPath), false, 'converged debt is removed');
|
|
4476
|
+
// Already-closed pane: pane_not_found answers prove convergence.
|
|
4477
|
+
const goneBin = await writeFakeHerdrStub(fakeBinDir, join(fakeBinDir, 'gone.log'), { paneCloseNotFound: true });
|
|
4478
|
+
process.env.HERDR_BIN_PATH = goneBin;
|
|
4479
|
+
await writeFile(debtPath, JSON.stringify(debt, null, 2));
|
|
4480
|
+
const goneOutcome = await reconcileScaleDownCleanupDebt('scale-herdr-debt', cwd, config);
|
|
4481
|
+
assert.deepEqual(goneOutcome, { ok: true });
|
|
4482
|
+
assert.equal(existsSync(debtPath), false);
|
|
4483
|
+
}
|
|
4484
|
+
finally {
|
|
4485
|
+
if (typeof previousHerdrBinPath === 'string')
|
|
4486
|
+
process.env.HERDR_BIN_PATH = previousHerdrBinPath;
|
|
4487
|
+
else
|
|
4488
|
+
delete process.env.HERDR_BIN_PATH;
|
|
4489
|
+
await rm(cwd, { recursive: true, force: true });
|
|
4490
|
+
await rm(fakeBinDir, { recursive: true, force: true });
|
|
4491
|
+
}
|
|
4492
|
+
});
|
|
4493
|
+
});
|
|
4201
4494
|
//# sourceMappingURL=scaling.test.js.map
|