Files
buzz/desktop/src/features/projects/projectChannelCreation.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

106 lines
2.7 KiB
JavaScript

import assert from "node:assert/strict";
import { test } from "node:test";
import { buildProjectRelatedChannelPatchTemplate } from "./projectChannelCreation.ts";
import {
MAX_PROJECT_RELATED_CHANNELS,
PROJECT_RELATED_CHANNEL_TAG,
} from "./projectModels.ts";
const OWNER = "a".repeat(64);
const OTHER = "b".repeat(64);
const CHANNEL_A = "11111111-1111-4111-8111-111111111111";
const CHANNEL_B = "22222222-2222-4222-8222-222222222222";
function liveHead(tags = []) {
return {
content: "",
created_at: 100,
id: "project-head",
kind: 30621,
pubkey: OWNER,
sig: "sig",
tags: [
["d", "sprout"],
["name", "Sprout"],
["buzz-channel", CHANNEL_A],
...tags,
],
};
}
test("appends a related channel tag and preserves the live head", () => {
const patched = buildProjectRelatedChannelPatchTemplate({
channelId: CHANNEL_B,
liveHead: liveHead([["description", "A project"]]),
ownerPubkey: OWNER,
});
assert.equal(patched.alreadyBound, false);
assert.deepEqual(patched.project.tags, [
["d", "sprout"],
["name", "Sprout"],
["buzz-channel", CHANNEL_A],
["description", "A project"],
[PROJECT_RELATED_CHANNEL_TAG, CHANNEL_B],
]);
});
test("is idempotent when the related channel is already tagged", () => {
const patched = buildProjectRelatedChannelPatchTemplate({
channelId: CHANNEL_B,
liveHead: liveHead([[PROJECT_RELATED_CHANNEL_TAG, CHANNEL_B]]),
ownerPubkey: OWNER,
});
assert.equal(patched.alreadyBound, true);
assert.equal(
patched.project.tags.filter((tag) => tag[0] === PROJECT_RELATED_CHANNEL_TAG)
.length,
1,
);
});
test("refuses to bind the home channel as a related channel", () => {
assert.throws(
() =>
buildProjectRelatedChannelPatchTemplate({
channelId: CHANNEL_A,
liveHead: liveHead(),
ownerPubkey: OWNER,
}),
/already this project's home/,
);
});
test("only the project owner can add related channels", () => {
assert.throws(
() =>
buildProjectRelatedChannelPatchTemplate({
channelId: CHANNEL_B,
liveHead: liveHead(),
ownerPubkey: OTHER,
}),
/Only the project owner/,
);
});
test("caps extra related channels", () => {
const tags = Array.from(
{ length: MAX_PROJECT_RELATED_CHANNELS },
(_, index) => {
const suffix = String(index + 1).padStart(12, "0");
return [PROJECT_RELATED_CHANNEL_TAG, `33333333-3333-4333-8333-${suffix}`];
},
);
assert.throws(
() =>
buildProjectRelatedChannelPatchTemplate({
channelId: CHANNEL_B,
liveHead: liveHead(tags),
ownerPubkey: OWNER,
}),
/extra channels/,
);
});