Files
buzz/desktop/src/features/projects/projectChannelRequestQueue.test.mjs
thomaspblock de188ebf06 feat(projects): add agent and CLI project-home support (#6590)
## Summary
- inject bounded project-home identity and repository context into
managed agent sessions
- add project-aware CLI flows for creating projects, repositories,
issues, and related channels
- match project homes through the existing relay query surface, then
filter channel metadata client-side

This is Part 1 of the channel-first Projects stack. Part 2 contains
project creation and model foundations.

## Testing
- `cargo fmt --all -- --check`
- `cargo clippy -p buzz-cli -p buzz-acp --all-targets -- -D warnings`
- `cargo test -p buzz-cli -p buzz-acp` — 1,184 tests passed, 1 doc test
ignored
- full pre-push gate passed

## Post-Deploy Monitoring & Validation
- validate project-home agent context and project-aware CLI commands
against a staging relay
- healthy signals: project context matches the active channel, explicit
repo coordinates remain stable, and normal channels receive no project
block
- failure signals: cross-channel project context, duplicate project
creation, or commands targeting an unrelated repository; mitigate by
reverting this PR

---------

Signed-off-by: Thomas Petersen <thomasp@squareup.com>
Signed-off-by: Wrench <0eabe6ea5758c1e4c5b68cea4ac42b32c479072883cb28da8110b4a47c32b9a1@buzz.block.builderlab.xyz>
Co-authored-by: Wrench <0eabe6ea5758c1e4c5b68cea4ac42b32c479072883cb28da8110b4a47c32b9a1@buzz.block.builderlab.xyz>
2026-08-26 12:09:06 -07:00

83 lines
2.8 KiB
JavaScript

import assert from "node:assert/strict";
import test from "node:test";
import {
advanceProjectChannelRequestQueue,
createProjectChannelRequestQueue,
enqueueProjectChannelRequest,
MAX_PENDING_PROJECT_CHANNEL_REQUESTS,
} from "./projectChannelRequestQueue.ts";
function candidate(requestId) {
return {
agentPubkey: `agent-${requestId}`,
request: { requestId },
};
}
test("accepted requests advance in order while duplicate active requests stay suppressed", () => {
const queue = createProjectChannelRequestQueue();
const first = candidate("request-a");
const second = candidate("request-b");
assert.deepEqual(enqueueProjectChannelRequest(queue, first), {
status: "show",
candidate: first,
});
assert.deepEqual(enqueueProjectChannelRequest(queue, second), {
status: "queued",
});
assert.deepEqual(enqueueProjectChannelRequest(queue, first), {
status: "duplicate",
});
assert.equal(advanceProjectChannelRequestQueue(queue), second);
assert.deepEqual(enqueueProjectChannelRequest(queue, first), {
status: "duplicate",
});
assert.equal(advanceProjectChannelRequestQueue(queue), null);
});
test("accepted queue drops newest overflow while preserving FIFO and retryability", () => {
const queue = createProjectChannelRequestQueue();
const first = candidate("request-0");
assert.equal(enqueueProjectChannelRequest(queue, first).status, "show");
const pending = Array.from(
{ length: MAX_PENDING_PROJECT_CHANNEL_REQUESTS },
(_, index) => candidate(`request-${index + 1}`),
);
for (const request of pending) {
assert.equal(enqueueProjectChannelRequest(queue, request).status, "queued");
}
const overflow = candidate("request-overflow");
assert.deepEqual(enqueueProjectChannelRequest(queue, overflow), {
status: "overflow",
});
assert.equal(queue.pending.length, MAX_PENDING_PROJECT_CHANNEL_REQUESTS);
assert.equal(queue.seenRequestIds.has(overflow.request.requestId), false);
for (const request of pending) {
assert.equal(advanceProjectChannelRequestQueue(queue), request);
}
assert.equal(advanceProjectChannelRequestQueue(queue), null);
assert.deepEqual(enqueueProjectChannelRequest(queue, overflow), {
status: "show",
candidate: overflow,
});
});
test("dedup history stays bounded without forgetting active or pending requests", () => {
const queue = createProjectChannelRequestQueue();
for (let index = 0; index < 500; index += 1) {
const request = candidate(`request-${index}`);
assert.equal(enqueueProjectChannelRequest(queue, request).status, "show");
assert.deepEqual(enqueueProjectChannelRequest(queue, request), {
status: "duplicate",
});
assert.equal(advanceProjectChannelRequestQueue(queue), null);
}
assert.ok(queue.seenRequestIds.size <= 201);
});