67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
buildChildResourceRequests,
|
|
type DiscoverySnapshot,
|
|
} from "../src/agents/provisioning.js";
|
|
|
|
function parentSnapshot(): DiscoverySnapshot {
|
|
return {
|
|
sessionId: "parent-session",
|
|
workspaceRoot: "/repo",
|
|
workingDirectory: "/repo/.ai_ops/worktrees/parent",
|
|
hardConstraints: [
|
|
{
|
|
kind: "git-worktree",
|
|
allocation: {
|
|
repoRoot: "/repo",
|
|
worktreeRoot: "/repo/.ai_ops/worktrees",
|
|
worktreePath: "/repo/.ai_ops/worktrees/parent",
|
|
baseRef: "HEAD",
|
|
targetPath: "src/agents",
|
|
},
|
|
},
|
|
{
|
|
kind: "port-range",
|
|
allocation: {
|
|
basePort: 36000,
|
|
blockSize: 32,
|
|
blockCount: 512,
|
|
blockIndex: 2,
|
|
startPort: 36064,
|
|
endPort: 36095,
|
|
primaryPort: 36064,
|
|
lockPath: "/repo/.ai_ops/locks/ports/36064-36095.lock",
|
|
},
|
|
},
|
|
],
|
|
softConstraints: {
|
|
env: {},
|
|
promptSections: [],
|
|
metadata: {},
|
|
},
|
|
};
|
|
}
|
|
|
|
test("builds deterministic child suballocation requests", () => {
|
|
const requests = buildChildResourceRequests({
|
|
parentSnapshot: parentSnapshot(),
|
|
childSessionId: "child-1",
|
|
childIndex: 1,
|
|
childCount: 4,
|
|
});
|
|
|
|
assert.equal(requests.length, 2);
|
|
|
|
const gitRequest = requests.find((entry) => entry.kind === "git-worktree");
|
|
assert.ok(gitRequest);
|
|
assert.equal(typeof gitRequest.options?.rootDirectory, "string");
|
|
assert.equal(gitRequest.options?.targetPath, "src/agents");
|
|
|
|
const portRequest = requests.find((entry) => entry.kind === "port-range");
|
|
assert.ok(portRequest);
|
|
assert.equal(portRequest.options?.basePort, 36072);
|
|
assert.equal(portRequest.options?.blockSize, 8);
|
|
assert.equal(portRequest.options?.blockCount, 1);
|
|
});
|