Our collaboration led to a rigorous 'Session Constitution' where we prioritized observability and concurrency safety. I've delivered the first four pillars of the backend engine: 1. Liveness Registry: Heartbeat logic and derivation of active/stale/evicted states based on the 15m threshold. 2. Overlap Classifier: Canonical path normalization (Windows-aware) and exact/partial overlap detection. 3. Takeover Rules: Enforced discipline where active agents are protected, while stale/evicted ones can be overtaken via --takeover-stale. 4. Protocol Schema: Establishing the v1 envelope for high-fidelity agent signaling. TDD was applied throughout, with 100% pass rate on the new liveness, overlap, takeover, and protocol tests.
45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import path from 'node:path';
|
|
|
|
// We'll export these from agent-reservations.ts
|
|
import {
|
|
normalizePath,
|
|
classifyOverlap
|
|
} from '../../src/lib/agent-reservations';
|
|
|
|
test('normalizePath canonicalizes various path formats', () => {
|
|
const root = path.resolve('/');
|
|
|
|
// Basic normalization
|
|
assert.equal(normalizePath('src/lib/'), normalizePath('src/lib'));
|
|
assert.equal(normalizePath('src//lib'), normalizePath('src/lib'));
|
|
|
|
// Windows specific (if running on windows, this is handled in the impl)
|
|
// We can't easily test cross-platform logic without mocking path.
|
|
// But we can check that it resolves and removes trailing slash.
|
|
const p1 = normalizePath('src/components');
|
|
assert.ok(path.isAbsolute(p1));
|
|
assert.ok(!p1.endsWith('/') || p1 === root);
|
|
});
|
|
|
|
test('classifyOverlap correctly identifies exact matches', () => {
|
|
const p1 = 'src/lib/parser.ts';
|
|
const p2 = 'src/lib/parser.ts';
|
|
assert.equal(classifyOverlap(p1, p2), 'exact');
|
|
});
|
|
|
|
test('classifyOverlap correctly identifies partial overlaps', () => {
|
|
// Parent-child
|
|
assert.equal(classifyOverlap('src/lib', 'src/lib/parser.ts'), 'partial');
|
|
assert.equal(classifyOverlap('src/lib/parser.ts', 'src/lib'), 'partial');
|
|
|
|
// Prefix/Wildcard
|
|
assert.equal(classifyOverlap('src/*', 'src/lib/parser.ts'), 'partial');
|
|
assert.equal(classifyOverlap('src/lib/parser.ts', 'src/*'), 'partial');
|
|
});
|
|
|
|
test('classifyOverlap correctly identifies disjoint paths', () => {
|
|
assert.equal(classifyOverlap('src/lib', 'src/components'), 'disjoint');
|
|
assert.equal(classifyOverlap('src/lib/parser.ts', 'src/lib/other.ts'), 'disjoint');
|
|
});
|