singularity-forge/src/tests/auto-tool-tracking.test.ts
Jeremy McSpadden 3c9762d9b7 refactor: extract 7 focused modules from auto.ts (#898)
Break up the 3,975-line auto.ts into focused, single-concern modules:

- auto-budget.ts: Pure budget alert level and enforcement functions
- auto-tool-tracking.ts: In-flight tool call tracking for idle detection
- auto-observability.ts: Pre-dispatch observability validation and repair
- auto-unit-closeout.ts: Consolidated metrics/activity/memory closeout helper
- auto-direct-dispatch.ts: Manual /gsd dispatch phase command handling
- auto-timeout-recovery.ts: Idle and hard timeout recovery with escalation
- auto-model-selection.ts: Model routing, complexity classification, fallback chains

auto.ts retains orchestration (start/stop/pause, handleAgentEnd, dispatchNextUnit)
and drops from 3,975 to 3,256 lines (-719 lines, -18%).

All extractions are pure moves with re-exports — no behavior changes.
All 1,092 unit tests and 30 integration tests pass.
2026-03-17 11:03:01 -05:00

46 lines
1.3 KiB
TypeScript

import { describe, it, beforeEach } from "node:test";
import assert from "node:assert/strict";
import {
markToolStart,
markToolEnd,
getOldestInFlightToolAgeMs,
getInFlightToolCount,
clearInFlightTools,
} from "../resources/extensions/gsd/auto-tool-tracking.js";
describe("auto-tool-tracking", () => {
beforeEach(() => {
clearInFlightTools();
});
it("tracks tool start and end", () => {
assert.equal(getInFlightToolCount(), 0);
markToolStart("tool-1", true);
assert.equal(getInFlightToolCount(), 1);
markToolEnd("tool-1");
assert.equal(getInFlightToolCount(), 0);
});
it("skips tracking when not active", () => {
markToolStart("tool-1", false);
assert.equal(getInFlightToolCount(), 0);
});
it("returns 0 age when no tools in flight", () => {
assert.equal(getOldestInFlightToolAgeMs(), 0);
});
it("returns positive age for in-flight tools", () => {
markToolStart("tool-1", true);
// Age should be very small (< 100ms)
assert.ok(getOldestInFlightToolAgeMs() < 100);
});
it("clears all in-flight tools", () => {
markToolStart("tool-1", true);
markToolStart("tool-2", true);
assert.equal(getInFlightToolCount(), 2);
clearInFlightTools();
assert.equal(getInFlightToolCount(), 0);
});
});