mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-11-10 06:42:21 +00:00
test: add unit tests for cmdCheck
Refactor `cmdCheck` in `src/cmd-check.mjs` to support dependency injection for better testability. Add `test/cmd-check.test.mjs` with comprehensive unit tests for `cmdCheck`, covering happy paths and edge cases. Verify tests pass with `node --test test/cmd-check.test.mjs`. Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
1 parent
b3f4a5c9cd
commit
99bd4ba2a3
2 files changed
+203
-7
No files matched your search
+16
-7
@@ -7,11 +7,20 @@ import { getRoster } from './roster.mjs';
|
||||
import { queryLocks } from './lock-ops.mjs';
|
||||
import { todayDateStr } from './utils.mjs';
|
||||
|
||||
export async function cmdCheck(cadence) {
|
||||
const relays = getRelays();
|
||||
const namespace = getNamespace();
|
||||
const dateStr = todayDateStr();
|
||||
const config = loadTorchConfig();
|
||||
export async function cmdCheck(cadence, deps = {}) {
|
||||
const {
|
||||
getRelaysFn = getRelays,
|
||||
getNamespaceFn = getNamespace,
|
||||
loadTorchConfigFn = loadTorchConfig,
|
||||
getRosterFn = getRoster,
|
||||
queryLocksFn = queryLocks,
|
||||
todayDateStrFn = todayDateStr,
|
||||
} = deps;
|
||||
|
||||
const relays = getRelaysFn();
|
||||
const namespace = getNamespaceFn();
|
||||
const dateStr = todayDateStrFn();
|
||||
const config = loadTorchConfigFn();
|
||||
const pausedAgents = (cadence === 'daily' ? config.scheduler.paused.daily : config.scheduler.paused.weekly) || [];
|
||||
|
||||
console.error(`Checking locks: namespace=${namespace}, cadence=${cadence}, date=${dateStr}`);
|
||||
@@ -20,9 +29,9 @@ export async function cmdCheck(cadence) {
|
||||
console.error(`Paused agents: ${pausedAgents.join(', ')}`);
|
||||
}
|
||||
|
||||
const locks = await queryLocks(relays, cadence, dateStr, namespace);
|
||||
const locks = await queryLocksFn(relays, cadence, dateStr, namespace);
|
||||
const lockedAgents = [...new Set(locks.map((l) => l.agent).filter(Boolean))];
|
||||
const roster = getRoster(cadence);
|
||||
const roster = getRosterFn(cadence);
|
||||
|
||||
const excludedAgents = [...new Set([...lockedAgents, ...pausedAgents])];
|
||||
const unknownLockedAgents = lockedAgents.filter((agent) => !roster.includes(agent));
|
||||
|
||||
Reference in new issue
Block a user