mirror of
https://github.com/block/buzz.git
synced 2026-11-05 08:51:10 +00:00
## Why Terminal task correctness alone does not guard Buzz-native collaboration behavior such as exact reply routing, non-waking narrative names, batched agent synthesis, thread isolation, and ambiguous identity targeting. ## What - Add five medium/hard Harbor tasks for multiline delivery, narrative agent names, interleaved agent reports, cross-thread requests, and ambiguous user mentions - Add signed scripted-event fixtures, duplicate-display-name profiles, and public-only evidence export support - Add positive and adversarial verifier fixtures covering dropped inputs, extra posts, incorrect routing, and unintended mentions ## Risk Assessment Low — changes are limited to benchmark tooling and datasets; production behavior is exercised but not modified. ## References - Grounded in behavior reported in `buzz-community` and public issues #5787, #5176, #5839, #4942, #4072, #4303, and #6257 - Live Claude Sonnet 4.6 smoke run: 2/5 passed; the three failures exposed top-level instead of threaded delivery, empty narrative output, and silent ambiguous-identity completion - Live GPT-5.6 Luna run (`buzz-native-solo-luna.yaml`): 3/5 passed. Passed `ambiguous-user-mention`, `cross-thread-requests`, and `interleaved-agent-reports`. Failed `multiline-message` and `narrative-agent-names` because both omitted the event-level user mention despite otherwise-correct content and threading. <img width="1176" height="805" alt="Screenshot 2026-08-21 at 11 11 17 AM" src="https://github.com/user-attachments/assets/fc259ec9-892c-4436-b022-1bf85415617d" /> Signed-off-by: Salman Mohammed <smohammed@squareup.com>
189 lines
6.8 KiB
Python
189 lines
6.8 KiB
Python
"""Provisioner unit tests — no relay or Postgres required."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
|
|
import coincurve
|
|
import pytest
|
|
from harbor_buzz_orchestra.task_fixtures import DirectoryEntry
|
|
|
|
from harbor_buzz_testbed.provisioner import (
|
|
BuzzTrialProvisioner,
|
|
ProvisioningError,
|
|
TestbedConfig,
|
|
)
|
|
|
|
OWNER_SECRET = "0" * 63 + "3"
|
|
|
|
|
|
def config(**overrides) -> TestbedConfig:
|
|
defaults = {
|
|
"relay_http_url": "http://localhost:3000",
|
|
"relay_ws_url": "ws://host.docker.internal:3000",
|
|
"owner_secret_key": OWNER_SECRET,
|
|
"postgres_dsn": "postgresql://unused",
|
|
"llm_api_keys": {"databricks/glm": "glm-key", "databricks/opus": "opus-key"},
|
|
}
|
|
defaults.update(overrides)
|
|
return TestbedConfig(**defaults)
|
|
|
|
|
|
def test_mint_credentials_expands_roster(manifest):
|
|
credentials = BuzzTrialProvisioner(config())._mint_credentials(manifest)
|
|
assert [c.agent_id for c in credentials] == [
|
|
"orch-opus-1",
|
|
"worker-glm-1",
|
|
"worker-glm-2",
|
|
]
|
|
assert credentials[0].role == "orchestrator"
|
|
assert credentials[0].llm_api_key == "opus-key"
|
|
assert {c.llm_api_key for c in credentials[1:]} == {"glm-key"}
|
|
|
|
|
|
def test_mint_credentials_keys_are_fresh_and_attested(manifest):
|
|
provisioner = BuzzTrialProvisioner(config())
|
|
first = provisioner._mint_credentials(manifest)
|
|
second = provisioner._mint_credentials(manifest)
|
|
all_secrets = [c.nostr_secret_key for c in first + second]
|
|
assert len(all_secrets) == len(set(all_secrets)), "keys must never be reused"
|
|
owner_pubkey = coincurve.PrivateKey(bytes.fromhex(OWNER_SECRET)).public_key_xonly
|
|
for credential in first:
|
|
tag = json.loads(credential.nostr_auth_tag)
|
|
assert tag[:3] == ["auth", owner_pubkey.format().hex(), ""]
|
|
digest = hashlib.sha256(
|
|
f"nostr:agent-auth:{credential.nostr_pubkey}:".encode()
|
|
).digest()
|
|
assert owner_pubkey.verify(bytes.fromhex(tag[3]), digest)
|
|
|
|
|
|
def test_mint_user_is_attested_and_not_an_agent():
|
|
provisioner = BuzzTrialProvisioner(config())
|
|
user = provisioner._mint_user()
|
|
assert user.agent_id == "user"
|
|
assert user.role == "user"
|
|
assert user.llm_endpoint == "" and user.llm_api_key == ""
|
|
owner_pubkey = coincurve.PrivateKey(bytes.fromhex(OWNER_SECRET)).public_key_xonly
|
|
tag = json.loads(user.nostr_auth_tag)
|
|
assert tag[:3] == ["auth", owner_pubkey.format().hex(), ""]
|
|
|
|
|
|
def test_user_mention_task_gets_stable_three_word_user_identity():
|
|
provisioner = BuzzTrialProvisioner(config(user_secret_key="7" * 64))
|
|
|
|
first = provisioner._mint_user("user-mention")
|
|
second = provisioner._mint_user("user-mention")
|
|
|
|
assert first.agent_id == "John Vincent Doe"
|
|
assert len(first.agent_id.split()) == 3
|
|
assert first.nostr_secret_key == second.nostr_secret_key
|
|
assert first.nostr_secret_key != "7" * 64
|
|
assert first.role == "user"
|
|
|
|
|
|
def test_pinned_user_secret_reuses_one_identity():
|
|
pinned = "7" * 64
|
|
provisioner = BuzzTrialProvisioner(config(user_secret_key=pinned))
|
|
first = provisioner._mint_user()
|
|
second = provisioner._mint_user()
|
|
assert first.nostr_secret_key == pinned
|
|
assert first.nostr_pubkey == second.nostr_pubkey
|
|
expected = coincurve.PrivateKey(bytes.fromhex(pinned)).public_key_xonly
|
|
assert first.nostr_pubkey == expected.format().hex()
|
|
# Still a user, still attested by the owner.
|
|
assert first.role == "user"
|
|
owner_pubkey = coincurve.PrivateKey(bytes.fromhex(OWNER_SECRET)).public_key_xonly
|
|
assert json.loads(first.nostr_auth_tag)[1] == owner_pubkey.format().hex()
|
|
|
|
|
|
def test_teardown_skips_archiving_when_disabled():
|
|
provisioner = BuzzTrialProvisioner(config(archive_on_teardown=False))
|
|
# Any attribute access would fail on this handle — teardown must return
|
|
# before touching the CLI or Postgres.
|
|
provisioner.teardown(handle=None)
|
|
|
|
|
|
def test_mint_credentials_missing_api_key_is_explicit(manifest):
|
|
provisioner = BuzzTrialProvisioner(config(llm_api_keys={}))
|
|
with pytest.raises(ProvisioningError, match="databricks/"):
|
|
provisioner._mint_credentials(manifest)
|
|
|
|
|
|
def test_directory_credentials_are_stable_distinct_and_attested():
|
|
provisioner = BuzzTrialProvisioner(config())
|
|
|
|
first = provisioner._directory_credential(
|
|
DirectoryEntry("benchmark-user-01", "user")
|
|
)
|
|
again = provisioner._directory_credential(
|
|
DirectoryEntry("benchmark-user-01", "user")
|
|
)
|
|
other = provisioner._directory_credential(DirectoryEntry("benchmark-bot-01", "bot"))
|
|
|
|
assert first.nostr_secret_key == again.nostr_secret_key
|
|
assert first.nostr_pubkey == again.nostr_pubkey
|
|
assert first.nostr_pubkey != other.nostr_pubkey
|
|
assert first.role == "user" and other.role == "bot"
|
|
assert json.loads(first.nostr_auth_tag)[2] == ""
|
|
|
|
|
|
def test_seed_directory_has_50_users_10_bots_and_skips_existing(monkeypatch):
|
|
provisioner = BuzzTrialProvisioner(config())
|
|
|
|
class Observer:
|
|
def profiles(self, pubkeys):
|
|
return [{"pubkey": pubkeys[0]}]
|
|
|
|
published = []
|
|
|
|
class Publisher:
|
|
def set_profile(self, name, about=None):
|
|
published.append((name, about))
|
|
|
|
monkeypatch.setattr(provisioner, "_cli_for", lambda _credential: Publisher())
|
|
|
|
directory = provisioner._seed_directory("create-channel-invite-users", Observer())
|
|
|
|
assert len(directory) == 60
|
|
assert sum(identity.role == "user" for identity in directory) == 50
|
|
assert sum(identity.role == "bot" for identity in directory) == 10
|
|
assert len(published) == 59
|
|
assert (directory[0].name, None) not in published
|
|
|
|
|
|
def test_duplicate_display_names_keep_distinct_stable_identities():
|
|
provisioner = BuzzTrialProvisioner(config())
|
|
first = provisioner._directory_credential(
|
|
DirectoryEntry("Taylor Morgan Lee", "user", identity_id="release")
|
|
)
|
|
second = provisioner._directory_credential(
|
|
DirectoryEntry("Taylor Morgan Lee", "user", identity_id="observer")
|
|
)
|
|
|
|
assert first.agent_id == second.agent_id == "Taylor Morgan Lee"
|
|
assert first.nostr_pubkey != second.nostr_pubkey
|
|
|
|
|
|
def test_lock_key_is_deterministic_and_distinct():
|
|
calls: list[int] = []
|
|
|
|
class FakeConn:
|
|
def execute(self, _query, params):
|
|
calls.append(params[0])
|
|
|
|
BuzzTrialProvisioner._lock_trial(FakeConn(), "run-a", "trial-1")
|
|
BuzzTrialProvisioner._lock_trial(FakeConn(), "run-a", "trial-1")
|
|
BuzzTrialProvisioner._lock_trial(FakeConn(), "run-a", "trial-2")
|
|
assert calls[0] == calls[1]
|
|
assert calls[0] != calls[2]
|
|
assert all(-(2**63) <= key < 2**63 for key in calls)
|
|
|
|
|
|
def test_healthcheck_fails_fast_when_relay_down():
|
|
provisioner = BuzzTrialProvisioner(
|
|
config(relay_http_url="http://localhost:1", postgres_dsn="postgresql://unused")
|
|
)
|
|
with pytest.raises(ProvisioningError, match="relay unreachable"):
|
|
provisioner.healthcheck()
|