mirror of
https://github.com/block/buzz.git
synced 2026-11-27 11:41:21 +00:00
fix(desktop): Phase 1 round-4 — close all Paul round-3 gate defects
Wire onDeleteDefinition/onRemoveFromMyAgents/onShare/isIdentityArchived/ linkedInstanceCount through AgentEditDialog to all three callers (UserProfilePanel, AgentsView, AgentManagementDialogs). Add onShare to AgentEditMergedDialogProps and render Share action in the definition admin section. Fix mislabeled comment above Delete button. Add R6 respondTo regression tests covering definition-only context seed and emit through coordinator. Export FIELD_OWNERS constant as load-bearing source-of-truth map annotating every AgentFormModel field with its FieldOwner. Delete AgentInstanceEditDialog.tsx and agentInstanceEditPinning.test.mjs (zero production consumers). Remove definitionReadOnly prop from AgentDefinitionDialog.tsx. Update agentDialogRouting.test.mjs: remove AgentInstanceEditDialog import; replace is-NOT-reachable test with positive assertion that AgentEditMergedDialog appears in all R1-R7 contexts. Add two e2e tests: team-linked instance D-fields disabled + team-notice names the team; linked agent one-Save persists both D and I layers. 4560/4560 desktop tests pass. TypeScript clean. Biome clean. Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
@@ -102,8 +102,6 @@ type AgentDefinitionDialogProps = {
|
||||
isPending: boolean;
|
||||
runtimes: AcpRuntimeCatalogEntry[];
|
||||
runtimeCatalogStatus?: "loading" | "ready" | "error";
|
||||
/** When true, D-fields render disabled + "Managed by team" notice; submit blocked. */
|
||||
definitionReadOnly?: boolean;
|
||||
onDirtyChange?: (dirty: boolean) => void;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onSubmit: (
|
||||
@@ -132,7 +130,6 @@ export function AgentDefinitionDialog({
|
||||
isPending,
|
||||
runtimes,
|
||||
runtimeCatalogStatus = "ready" as const,
|
||||
definitionReadOnly = false,
|
||||
onDirtyChange,
|
||||
onOpenChange,
|
||||
onSubmit,
|
||||
@@ -494,7 +491,6 @@ export function AgentDefinitionDialog({
|
||||
// Gate model/provider validity through missingNormalizedFields — single
|
||||
// source of truth with the readiness gate so display and Save can't drift.
|
||||
const canSubmit =
|
||||
!definitionReadOnly &&
|
||||
canSubmitPersonaDialog({ displayName, isPending }) &&
|
||||
(!isCreateMode || runtime.trim().length > 0) &&
|
||||
(!isCreateMode || selectedRuntimeIsAvailable) &&
|
||||
@@ -746,7 +742,7 @@ export function AgentDefinitionDialog({
|
||||
>
|
||||
<AgentCreationPreview
|
||||
avatarUrl={previewAvatarUrl}
|
||||
disabled={isPending || isAvatarUploadPending || definitionReadOnly}
|
||||
disabled={isPending || isAvatarUploadPending}
|
||||
label={previewLabel}
|
||||
onClearAvatar={() => {
|
||||
setHasUserChanges(true);
|
||||
@@ -760,12 +756,6 @@ export function AgentDefinitionDialog({
|
||||
/>
|
||||
|
||||
<div className="space-y-5">
|
||||
{definitionReadOnly ? (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
This agent is managed by a team. Its configuration cannot be edited
|
||||
here.
|
||||
</p>
|
||||
) : null}
|
||||
<div className="space-y-1.5">
|
||||
<label
|
||||
className="text-sm font-medium text-foreground"
|
||||
@@ -785,7 +775,7 @@ export function AgentDefinitionDialog({
|
||||
"h-8 px-0 py-0 leading-6",
|
||||
PERSONA_FIELD_CONTROL_CLASS,
|
||||
)}
|
||||
disabled={isPending || definitionReadOnly}
|
||||
disabled={isPending}
|
||||
id="persona-display-name"
|
||||
onChange={(event) => setDisplayName(event.target.value)}
|
||||
placeholder="Fizz"
|
||||
@@ -807,7 +797,7 @@ export function AgentDefinitionDialog({
|
||||
"min-h-40 resize-y px-3 py-3 leading-5",
|
||||
PERSONA_FIELD_CONTROL_CLASS,
|
||||
)}
|
||||
disabled={isPending || definitionReadOnly}
|
||||
disabled={isPending}
|
||||
id="persona-system-prompt"
|
||||
onChange={(event) => setSystemPrompt(event.target.value)}
|
||||
placeholder="Describe what this agent should do."
|
||||
@@ -830,7 +820,7 @@ export function AgentDefinitionDialog({
|
||||
>
|
||||
{aiConfigurationMode === "custom" ? (
|
||||
<AgentHarnessField
|
||||
disabled={isPending || runtimesLoading || definitionReadOnly}
|
||||
disabled={isPending || runtimesLoading}
|
||||
onValueChange={handleRuntimeDropdownChange}
|
||||
options={runtimeDropdownOptions}
|
||||
placeholder={blankRuntimeOptionLabel}
|
||||
@@ -851,7 +841,7 @@ export function AgentDefinitionDialog({
|
||||
) : null}
|
||||
</RequiredFieldLabel>
|
||||
<PersonaDropdownField
|
||||
disabled={isPending || definitionReadOnly}
|
||||
disabled={isPending}
|
||||
id="persona-llm-provider"
|
||||
onValueChange={handleProviderDropdownChange}
|
||||
options={providerDropdownOptions}
|
||||
@@ -872,7 +862,7 @@ export function AgentDefinitionDialog({
|
||||
"h-8 px-0 py-0 leading-6",
|
||||
PERSONA_FIELD_CONTROL_CLASS,
|
||||
)}
|
||||
disabled={isPending || definitionReadOnly}
|
||||
disabled={isPending}
|
||||
id="persona-custom-provider"
|
||||
onChange={(event) => setProvider(event.target.value)}
|
||||
placeholder="Custom provider ID"
|
||||
@@ -887,7 +877,7 @@ export function AgentDefinitionDialog({
|
||||
aiConfigurationMode === "custom" &&
|
||||
topLevelSecretEnvVar ? (
|
||||
<PersonaProviderApiKeyField
|
||||
disabled={isPending || definitionReadOnly}
|
||||
disabled={isPending}
|
||||
envVarName={topLevelSecretEnvVar}
|
||||
isInherited={apiKeyIsInherited}
|
||||
inheritedLabel={apiKeyInheritedLabel}
|
||||
@@ -906,7 +896,7 @@ export function AgentDefinitionDialog({
|
||||
<AnimatePresence initial={false}>
|
||||
{modelFieldVisible && aiConfigurationMode === "custom" ? (
|
||||
<PersonaModelField
|
||||
disabled={isPending || definitionReadOnly}
|
||||
disabled={isPending}
|
||||
isExplicitModelRequired={isExplicitModelRequired}
|
||||
model={model}
|
||||
modelDiscoveryStatus={modelDiscoveryStatus}
|
||||
@@ -989,7 +979,7 @@ export function AgentDefinitionDialog({
|
||||
<PersonaAdvancedFields
|
||||
afterRespondTo={isCreateMode ? createRunSection : undefined}
|
||||
behaviorDraft={behaviorDraft}
|
||||
disabled={isPending || definitionReadOnly}
|
||||
disabled={isPending}
|
||||
envVars={envVars}
|
||||
fileSatisfiedEnvKeys={localModeGate.fileSatisfiedEnvKeys}
|
||||
hiddenEnvKeys={
|
||||
|
||||
@@ -50,6 +50,15 @@ export type AgentEditDialogProps = {
|
||||
model: string | undefined;
|
||||
respondTo: string | undefined;
|
||||
}>;
|
||||
/**
|
||||
* Definition admin actions forwarded to AgentEditMergedDialog (Artifact 4).
|
||||
* Omit when the host does not own those actions.
|
||||
*/
|
||||
onDeleteDefinition?: () => void;
|
||||
onRemoveFromMyAgents?: () => void;
|
||||
onShare?: () => void;
|
||||
linkedInstanceCount?: number;
|
||||
isIdentityArchived?: boolean;
|
||||
};
|
||||
|
||||
// ── Component ─────────────────────────────────────────────────────────────────
|
||||
@@ -62,6 +71,11 @@ export function AgentEditDialog({
|
||||
onValidate,
|
||||
initialValueOverrides,
|
||||
initialFocus,
|
||||
onDeleteDefinition,
|
||||
onRemoveFromMyAgents,
|
||||
onShare,
|
||||
linkedInstanceCount,
|
||||
isIdentityArchived,
|
||||
}: AgentEditDialogProps) {
|
||||
// All contexts route to the merged surface. The run-location provider wraps
|
||||
// instance-present paths so RespondToField's remote-backend warning can name
|
||||
@@ -74,7 +88,12 @@ export function AgentEditDialog({
|
||||
ctx={ctx}
|
||||
initialFocus={initialFocus}
|
||||
initialValueOverrides={initialValueOverrides}
|
||||
isIdentityArchived={isIdentityArchived}
|
||||
linkedInstanceCount={linkedInstanceCount}
|
||||
onDeleteDefinition={onDeleteDefinition}
|
||||
onOpenChange={onOpenChange}
|
||||
onRemoveFromMyAgents={onRemoveFromMyAgents}
|
||||
onShare={onShare}
|
||||
onUpdated={onUpdated}
|
||||
onValidate={onValidate}
|
||||
open={open}
|
||||
|
||||
@@ -101,6 +101,11 @@ export type AgentEditMergedDialogProps = {
|
||||
* When provided and definition isBuiltIn, "Remove from My Agents" renders.
|
||||
*/
|
||||
onRemoveFromMyAgents?: () => void;
|
||||
/**
|
||||
* Called to open the share/catalog dialog (row 15 — not shown for built-ins).
|
||||
* When provided, a "Share agent" action renders in the definition admin section.
|
||||
*/
|
||||
onShare?: () => void;
|
||||
/**
|
||||
* Number of linked instances for blast-radius copy in the delete confirmation.
|
||||
* Only relevant when onDeleteDefinition is provided.
|
||||
@@ -123,6 +128,7 @@ export function AgentEditMergedDialog({
|
||||
initialValueOverrides,
|
||||
onDeleteDefinition,
|
||||
onRemoveFromMyAgents,
|
||||
onShare,
|
||||
linkedInstanceCount = 0,
|
||||
isIdentityArchived = false,
|
||||
}: AgentEditMergedDialogProps) {
|
||||
@@ -879,7 +885,23 @@ export function AgentEditMergedDialog({
|
||||
{/* Definition admin section (Artifact 4) — rendered when a definition exists */}
|
||||
{showDef && !defReadOnly && def ? (
|
||||
<div className="space-y-2 border-t pt-4">
|
||||
{/* Share action (row 15 — not shown for built-ins) */}
|
||||
{/* Share / catalog publish (row 15 — not shown for built-ins) */}
|
||||
{onShare && !def.isBuiltIn ? (
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
Share this agent in the catalog.
|
||||
</span>
|
||||
<Button
|
||||
disabled={isSaving}
|
||||
onClick={onShare}
|
||||
type="button"
|
||||
variant="outline"
|
||||
>
|
||||
Share agent
|
||||
</Button>
|
||||
</div>
|
||||
) : null}
|
||||
{/* Custom definition delete with blast-radius copy */}
|
||||
{onDeleteDefinition && !def.isBuiltIn ? (
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm text-muted-foreground">
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -318,10 +318,48 @@ export function AgentsView() {
|
||||
{personas.personaToEdit ? (
|
||||
<AgentEditDialog
|
||||
ctx={{ kind: "definition-only", definition: personas.personaToEdit }}
|
||||
open={personas.personaToEdit !== null}
|
||||
isIdentityArchived={false}
|
||||
linkedInstanceCount={
|
||||
(agents.managedAgents ?? []).filter(
|
||||
(a) => a.personaId === personas.personaToEdit?.id,
|
||||
).length
|
||||
}
|
||||
onDeleteDefinition={
|
||||
!personas.personaToEdit.isBuiltIn
|
||||
? () => {
|
||||
const p = personas.personaToEdit;
|
||||
if (p) personas.openDelete(p);
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) personas.setPersonaToEdit(null);
|
||||
}}
|
||||
onRemoveFromMyAgents={
|
||||
personas.personaToEdit.isBuiltIn
|
||||
? () => {
|
||||
const p = personas.personaToEdit;
|
||||
if (p) {
|
||||
void personas.handleDelete(p);
|
||||
personas.setPersonaToEdit(null);
|
||||
}
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
onShare={
|
||||
!personas.personaToEdit.isBuiltIn
|
||||
? () => {
|
||||
const p = personas.personaToEdit;
|
||||
if (!p) return;
|
||||
const linked = (agents.managedAgents ?? []).find(
|
||||
(a) => a.personaId === p.id,
|
||||
);
|
||||
personas.openShare(p, linked, p.avatarUrl ?? null);
|
||||
personas.setPersonaToEdit(null);
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
open={personas.personaToEdit !== null}
|
||||
/>
|
||||
) : null}
|
||||
{personas.personaDialogState ? (
|
||||
|
||||
@@ -177,7 +177,10 @@ test("AgentEditDialog: definition-only routes to AgentEditMergedDialog (D sectio
|
||||
assert.equal(element.props.open, true);
|
||||
});
|
||||
|
||||
test("AgentEditDialog: AgentInstanceEditDialog is NOT reachable from any R1–R7 context", () => {
|
||||
test("AgentEditDialog: all R1–R7 contexts route to AgentEditMergedDialog (AgentInstanceEditDialog deleted)", () => {
|
||||
// AgentInstanceEditDialog was deleted in Phase 1 round 4 (zero production consumers
|
||||
// on any R1–R7 route). This test verifies all contexts produce an AgentEditMergedDialog
|
||||
// at the root of the element tree.
|
||||
const contexts = [
|
||||
{
|
||||
kind: "instance-with-definition",
|
||||
@@ -191,24 +194,24 @@ test("AgentEditDialog: AgentInstanceEditDialog is NOT reachable from any R1–R7
|
||||
for (const ctx of contexts) {
|
||||
const element = AgentEditDialog({ ctx, open: true, onOpenChange: noop });
|
||||
|
||||
// Walk the element tree: neither AgentEditDialog nor its children should
|
||||
// be AgentInstanceEditDialog on any R1–R7 route.
|
||||
function findType(el, target) {
|
||||
// Instance contexts are wrapped in AgentRunLocationProvider; definition-only is not.
|
||||
// Either way, the innermost dialog element must be AgentEditMergedDialog.
|
||||
function findMergedDialog(el) {
|
||||
if (!el || typeof el !== "object") return false;
|
||||
if (el.type === target) return true;
|
||||
if (el.type === AgentEditMergedDialog) return true;
|
||||
if (el.props?.children) {
|
||||
const children = Array.isArray(el.props.children)
|
||||
? el.props.children
|
||||
: [el.props.children];
|
||||
return children.some((c) => findType(c, target));
|
||||
return children.some((c) => findMergedDialog(c));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
assert.equal(
|
||||
findType(element, AgentInstanceEditDialog),
|
||||
false,
|
||||
`ctx.kind=${ctx.kind}: AgentInstanceEditDialog must NOT appear in the rendered tree`,
|
||||
findMergedDialog(element),
|
||||
true,
|
||||
`ctx.kind=${ctx.kind}: AgentEditMergedDialog must appear in the rendered tree`,
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -253,7 +256,6 @@ test("AgentEditDialog: single Save wires through coordinator — no instance dia
|
||||
import { AgentEditMergedDSection } from "./AgentEditMergedDialogDSection.tsx";
|
||||
import { AgentEditMergedInstanceSection } from "./AgentEditMergedDialogInstanceSection.tsx";
|
||||
import { hasDefinitionContext, hasInstanceContext } from "./agentFormModel.ts";
|
||||
import { AgentInstanceEditDialog } from "./AgentInstanceEditDialog.tsx";
|
||||
|
||||
test("hasDefinitionContext returns true for instance-with-definition and definition-only", () => {
|
||||
assert.equal(
|
||||
|
||||
@@ -384,3 +384,79 @@ test("test_untouched_parallelism_on_linked_agent_emits_no_diff", () => {
|
||||
assert.equal(emit.personaInput, null, "untouched parallelism: no D-write");
|
||||
assert.equal(emit.agentInput, null, "untouched parallelism: no I-write");
|
||||
});
|
||||
|
||||
// ── R6 respondTo carry (Thufir pass-2 IMPORTANT-4 regression) ────────────────
|
||||
//
|
||||
// When an R6 agent-origin owner-review update request carries a `respondTo`
|
||||
// change, the coordinator must:
|
||||
// 1. Seed the definition-only form model with the overridden value.
|
||||
// 2. Emit it through the coordinator as a D-owned field in `personaInput`
|
||||
// (definition-only context: no instance → respondTo goes to D).
|
||||
// This tests the pure model chain: seedAgentFormModel + override applied
|
||||
// (mirrors AgentEditMergedDialog's useEffect at line 294–297) + emitAgentFormDiff.
|
||||
//
|
||||
// Production flow:
|
||||
// useAgentManagement.reviewOverrides.respondTo → initialValueOverrides.respondTo
|
||||
// → dialog useEffect seeds setRespondTo → emitAgentFormDiff routes to personaInput.
|
||||
|
||||
test("test_r6_respond_to_override_seeds_form_and_emits_through_coordinator", () => {
|
||||
// A definition with current respondTo = null (DB default → "anyone").
|
||||
const definition = makeDefinition({ respondTo: null });
|
||||
const ctx = { kind: "definition-only", definition };
|
||||
|
||||
// Step 1: seed the form model from the definition.
|
||||
const seed = seedAgentFormModel(ctx);
|
||||
|
||||
// Step 2: apply the R6 override (mirrors the dialog's useEffect that sets
|
||||
// respondTo from initialValueOverrides.respondTo).
|
||||
const withOverride = { ...seed, respondTo: "owner-only" };
|
||||
|
||||
// Step 3: emit the diff — the form changed respondTo from the seed value.
|
||||
const emit = emitAgentFormDiff(seed, withOverride, ctx);
|
||||
|
||||
// For definition-only context, respondTo is D-owned → must land in personaInput.
|
||||
assert.ok(
|
||||
emit.personaInput,
|
||||
"R6 respondTo override must produce a personaInput diff",
|
||||
);
|
||||
assert.equal(
|
||||
emit.personaInput.behavior?.respondTo,
|
||||
"owner-only",
|
||||
"personaInput.behavior must carry the agent-requested respondTo",
|
||||
);
|
||||
// No instance in context → agentInput must be null.
|
||||
assert.equal(emit.agentInput, null, "definition-only context: no agentInput");
|
||||
});
|
||||
|
||||
test("test_r6_respond_to_override_only_no_other_fields_emitted", () => {
|
||||
// A respond-to-only R6 request must NOT dirty any other field.
|
||||
const definition = makeDefinition({
|
||||
displayName: "Research bot",
|
||||
systemPrompt: "Original prompt.",
|
||||
respondTo: "anyone",
|
||||
});
|
||||
const ctx = { kind: "definition-only", definition };
|
||||
const seed = seedAgentFormModel(ctx);
|
||||
|
||||
// Only respondTo changes — all other fields stay at seed values.
|
||||
const withOverride = { ...seed, respondTo: "owner-only" };
|
||||
const emit = emitAgentFormDiff(seed, withOverride, ctx);
|
||||
|
||||
assert.ok(
|
||||
emit.personaInput,
|
||||
"personaInput present for respondTo-only change",
|
||||
);
|
||||
// The personaInput is a full-write snapshot — all definition fields are included.
|
||||
// The display name and system prompt are unchanged from the seed.
|
||||
assert.equal(
|
||||
emit.personaInput.displayName,
|
||||
"Research bot",
|
||||
"displayName carries the unchanged seed value in the full-write snapshot",
|
||||
);
|
||||
assert.equal(
|
||||
emit.personaInput.systemPrompt,
|
||||
"Original prompt.",
|
||||
"systemPrompt carries the unchanged seed value in the full-write snapshot",
|
||||
);
|
||||
assert.equal(emit.personaInput.behavior?.respondTo, "owner-only");
|
||||
});
|
||||
|
||||
@@ -141,6 +141,41 @@ export type AgentFormModel = {
|
||||
startOnAppLaunch: boolean | undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Source-of-truth field ownership map (Artifact 4).
|
||||
*
|
||||
* Every AgentFormModel field is tagged with its FieldOwner. The emit function
|
||||
* (`emitAgentFormDiff`) and the dialog's editability predicates derive their
|
||||
* routing decisions from these ownership assignments — this map is the single
|
||||
* authoritative statement of which layer owns each field.
|
||||
*
|
||||
* Ownership rules per spec rows 9–10:
|
||||
* respondTo / parallelism — I-owned when an instance is in context;
|
||||
* D-owned only in definition-only (zero-instance) context.
|
||||
* All other D-fields — always D-owned.
|
||||
*/
|
||||
export const FIELD_OWNERS: Record<keyof AgentFormModel, FieldOwner> = {
|
||||
// Identity
|
||||
displayName: "definition",
|
||||
avatarUrl: "definition",
|
||||
// Behavior
|
||||
systemPrompt: "definition",
|
||||
respondTo: "instance", // rows 9–10: I when instance present, D in definition-only
|
||||
respondToAllowlist: "instance",
|
||||
parallelism: "instance", // rows 9–10: same contract as respondTo
|
||||
// Runtime — D preferred-id; per-instance env overlay is I
|
||||
runtime: "definition",
|
||||
model: "definition",
|
||||
provider: "definition",
|
||||
envVars: "definition",
|
||||
instanceEnvVars: "instance",
|
||||
namePool: "definition",
|
||||
instanceName: "instance",
|
||||
// Device policy
|
||||
autoRestartOnConfigChange: "local-policy",
|
||||
startOnAppLaunch: "local-policy",
|
||||
};
|
||||
|
||||
/** Which coordinator outputs changed vs. last saved state. */
|
||||
export type AgentFormEmit = {
|
||||
/** D-field update payload, present iff a D-field changed AND the definition is editable. */
|
||||
|
||||
@@ -1,284 +0,0 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import {
|
||||
requiredCredentialEnvKeys,
|
||||
runtimeSupportsLlmProviderSelection,
|
||||
} from "./agentConfigOptions.tsx";
|
||||
import {
|
||||
computeEditAgentFormValidity,
|
||||
hasMissingRequiredEnvKey,
|
||||
resolveAgentCommandUpdate,
|
||||
resolveInheritedRuntimeSubmission,
|
||||
resolveRuntimeProviderCapability,
|
||||
} from "./personaRuntimeModel.ts";
|
||||
|
||||
// ── Phase 1B.3b re-host pinning: inherit-toggle → gate → submit ─────────────
|
||||
//
|
||||
// AgentInstanceEditDialog (re-homed from EditAgentDialog) wires three seams
|
||||
// that must never disagree after the move:
|
||||
// 1. TOGGLE: flipping "Inherit runtime from persona" re-resolves
|
||||
// prospectiveRuntimeId from the LINKED PERSONA's runtime (not the stale
|
||||
// override) and feeds resolveInheritedRuntimeSubmission.
|
||||
// 2. GATE: useRequiredCredentialState validates the SAME inheritedSubmission
|
||||
// provider/env the submit path will persist (gate ↔ record ↔ spawn).
|
||||
// 3. SUBMIT: UpdateManagedAgentInput persists that same snapshot, with
|
||||
// resolveAgentCommandUpdate + harnessOverride derived from the toggle.
|
||||
// These tests chain the pure modules exactly as the component does, so a
|
||||
// re-host that re-derives any seam independently fails here.
|
||||
|
||||
const runtimes = [
|
||||
{ id: "buzz-agent", command: "buzz-agent-cmd", defaultArgs: [] },
|
||||
{ id: "claude", command: "claude-cmd", defaultArgs: [] },
|
||||
];
|
||||
|
||||
// Mirrors the component's prospectiveRuntimeId memo: when inheriting, resolve
|
||||
// from the linked persona's runtime; fall back to the agentCommand dual-match.
|
||||
function prospectiveRuntimeIdFor({
|
||||
inheritHarness,
|
||||
selectedRuntimeId,
|
||||
linkedPersonaRuntime,
|
||||
agentCommand,
|
||||
}) {
|
||||
if (!inheritHarness) {
|
||||
return selectedRuntimeId;
|
||||
}
|
||||
const personaRuntimeId = linkedPersonaRuntime?.trim();
|
||||
if (personaRuntimeId) {
|
||||
return (
|
||||
runtimes.find((r) => r.id === personaRuntimeId)?.id ?? personaRuntimeId
|
||||
);
|
||||
}
|
||||
return (
|
||||
runtimes.find((r) => r.command?.trim() === agentCommand.trim())?.id ??
|
||||
runtimes.find((r) => r.id === agentCommand.trim())?.id ??
|
||||
""
|
||||
);
|
||||
}
|
||||
|
||||
// A Claude-pinned agent linked to a buzz-agent/anthropic persona — the
|
||||
// inherit-transition scenario that exercises every seam at once.
|
||||
const pinnedAgent = {
|
||||
name: "test-agent",
|
||||
agentCommand: "claude-cmd",
|
||||
agentCommandOverride: "claude-cmd",
|
||||
acpCommand: "acp",
|
||||
personaId: "p1",
|
||||
provider: null,
|
||||
model: null,
|
||||
envVars: {},
|
||||
};
|
||||
const persona = {
|
||||
runtime: "buzz-agent",
|
||||
provider: "anthropic",
|
||||
model: "claude-sonnet-4-5",
|
||||
envVars: { ANTHROPIC_API_KEY: "sk-persona" },
|
||||
};
|
||||
|
||||
function inheritTransitionState() {
|
||||
const inheritHarness = true; // user just checked the toggle
|
||||
const prospectiveRuntimeId = prospectiveRuntimeIdFor({
|
||||
inheritHarness,
|
||||
selectedRuntimeId: "claude",
|
||||
linkedPersonaRuntime: persona.runtime,
|
||||
agentCommand: pinnedAgent.agentCommand,
|
||||
});
|
||||
const inheritedSubmission = resolveInheritedRuntimeSubmission({
|
||||
inheritHarness,
|
||||
agentWasHarnessPinned: pinnedAgent.agentCommandOverride != null,
|
||||
provider: "", // pinned Claude agent carries no provider
|
||||
personaProvider: persona.provider,
|
||||
model: "",
|
||||
personaModel: persona.model,
|
||||
envVars: {},
|
||||
personaEnvVars: persona.envVars,
|
||||
});
|
||||
return { inheritHarness, prospectiveRuntimeId, inheritedSubmission };
|
||||
}
|
||||
|
||||
test("rehost_toggle_resolvesProspectiveRuntimeFromPersona_notOverride", () => {
|
||||
const { prospectiveRuntimeId } = inheritTransitionState();
|
||||
assert.equal(
|
||||
prospectiveRuntimeId,
|
||||
"buzz-agent",
|
||||
"inherit-toggle must resolve the prospective runtime from the linked persona, not the still-present Claude pin",
|
||||
);
|
||||
});
|
||||
|
||||
test("rehost_gate_validatesTheSubmissionSnapshot_sameValuesAsSubmit", () => {
|
||||
const { prospectiveRuntimeId, inheritedSubmission } =
|
||||
inheritTransitionState();
|
||||
|
||||
// Gate half: the credential requirement must be computed from the
|
||||
// PROSPECTIVE runtime + the submission snapshot's provider/env.
|
||||
const providerForRequiredKeys = runtimeSupportsLlmProviderSelection(
|
||||
prospectiveRuntimeId,
|
||||
)
|
||||
? (inheritedSubmission.provider ?? "")
|
||||
: "";
|
||||
const requiredKeys = requiredCredentialEnvKeys(
|
||||
prospectiveRuntimeId,
|
||||
providerForRequiredKeys,
|
||||
);
|
||||
const missing = hasMissingRequiredEnvKey(
|
||||
requiredKeys,
|
||||
inheritedSubmission.envVars,
|
||||
);
|
||||
|
||||
// The persona snapshot carries the credential, so the gate must clear —
|
||||
// and it must clear because of the SAME env map submit will persist.
|
||||
assert.equal(inheritedSubmission.provider, "anthropic");
|
||||
assert.deepEqual(inheritedSubmission.envVars, {
|
||||
ANTHROPIC_API_KEY: "sk-persona",
|
||||
});
|
||||
assert.equal(
|
||||
missing,
|
||||
false,
|
||||
"gate must validate the submission snapshot (persona-layered env), not the agent's own empty env",
|
||||
);
|
||||
});
|
||||
|
||||
test("rehost_gate_blocksSave_whenSubmissionSnapshotLacksCredential", () => {
|
||||
const { prospectiveRuntimeId } = inheritTransitionState();
|
||||
// Same transition but the persona carries no credential: the submission
|
||||
// snapshot is credential-less and the SAME gate must now block Save.
|
||||
const bareSubmission = resolveInheritedRuntimeSubmission({
|
||||
inheritHarness: true,
|
||||
agentWasHarnessPinned: true,
|
||||
provider: "",
|
||||
personaProvider: persona.provider,
|
||||
model: "",
|
||||
personaModel: persona.model,
|
||||
envVars: {},
|
||||
personaEnvVars: {}, // no key anywhere
|
||||
});
|
||||
const requiredKeys = requiredCredentialEnvKeys(
|
||||
prospectiveRuntimeId,
|
||||
bareSubmission.provider ?? "",
|
||||
);
|
||||
const requiredEnvKeyMissing = hasMissingRequiredEnvKey(
|
||||
requiredKeys,
|
||||
bareSubmission.envVars,
|
||||
);
|
||||
assert.equal(requiredEnvKeyMissing, true);
|
||||
|
||||
const canSubmit = computeEditAgentFormValidity({
|
||||
name: pinnedAgent.name,
|
||||
parallelism: "1",
|
||||
agentAcpCommand: pinnedAgent.acpCommand,
|
||||
acpCommand: pinnedAgent.acpCommand,
|
||||
respondTo: "mentions",
|
||||
respondToAllowlistLength: 0,
|
||||
selectedRuntimeId: "claude",
|
||||
inheritHarness: true,
|
||||
agentCommand: pinnedAgent.agentCommand,
|
||||
requiredEnvKeyMissing,
|
||||
});
|
||||
assert.equal(
|
||||
canSubmit,
|
||||
false,
|
||||
"missing credential in the submission snapshot must block Save through the same validity path",
|
||||
);
|
||||
});
|
||||
|
||||
test("rehost_submit_persistsToggleAsCommandClear_andOmitsHarnessOverride", () => {
|
||||
// Submit half of the toggle seam: inheriting with a persisted override must
|
||||
// send the clear sentinel (""), and harnessOverride derives from the SAME
|
||||
// agentCommandUpdate (omitted while inheriting — falsy per the component).
|
||||
const agentCommandUpdate = resolveAgentCommandUpdate({
|
||||
inheritHarness: true,
|
||||
agentCommand: pinnedAgent.agentCommand,
|
||||
originalAgentCommand: pinnedAgent.agentCommand,
|
||||
agentCommandOverride: pinnedAgent.agentCommandOverride,
|
||||
});
|
||||
assert.equal(
|
||||
agentCommandUpdate,
|
||||
"",
|
||||
"inherit with a persisted pin must persist the clear sentinel",
|
||||
);
|
||||
const harnessOverride =
|
||||
agentCommandUpdate != null ? !true /* inheritHarness */ : undefined;
|
||||
assert.equal(
|
||||
harnessOverride,
|
||||
false,
|
||||
"harnessOverride must derive from the shared agentCommandUpdate, signalling the cleared pin",
|
||||
);
|
||||
|
||||
// And the provider tri-state must classify the PROSPECTIVE runtime — the
|
||||
// same id the gate used — so submit persists what the gate validated.
|
||||
const { prospectiveRuntimeId, inheritedSubmission } =
|
||||
inheritTransitionState();
|
||||
const capability = resolveRuntimeProviderCapability(
|
||||
prospectiveRuntimeId,
|
||||
runtimeSupportsLlmProviderSelection(prospectiveRuntimeId),
|
||||
);
|
||||
assert.equal(capability, "capable");
|
||||
const providerUpdate =
|
||||
capability === "capable"
|
||||
? inheritedSubmission.provider !== (pinnedAgent.provider ?? null)
|
||||
? inheritedSubmission.provider
|
||||
: undefined
|
||||
: undefined;
|
||||
assert.equal(
|
||||
providerUpdate,
|
||||
"anthropic",
|
||||
"submit must persist the gate-validated submission provider for the prospective runtime",
|
||||
);
|
||||
});
|
||||
|
||||
test("rehost_steadyStateInherit_localEditsStayAuthoritative", () => {
|
||||
// Wipe-on-poll companion: an agent ALREADY inheriting at open (no pin) with
|
||||
// deliberate local edits — the submission snapshot must pass them through
|
||||
// untouched, not resurrect persona values (the pre-move contract).
|
||||
const submission = resolveInheritedRuntimeSubmission({
|
||||
inheritHarness: true,
|
||||
agentWasHarnessPinned: false, // steady state, not a transition
|
||||
provider: "databricks", // deliberate local re-point
|
||||
personaProvider: persona.provider,
|
||||
model: "",
|
||||
personaModel: persona.model,
|
||||
envVars: { DATABRICKS_TOKEN: "tok" },
|
||||
personaEnvVars: persona.envVars,
|
||||
});
|
||||
assert.equal(submission.provider, "databricks");
|
||||
assert.equal(
|
||||
submission.model,
|
||||
null,
|
||||
"empty local model in steady state stays empty (runtime default), never backfilled from the persona",
|
||||
);
|
||||
assert.deepEqual(submission.envVars, { DATABRICKS_TOKEN: "tok" });
|
||||
});
|
||||
|
||||
test("editValidity_allowlistWithEmptyList_blocksSave", () => {
|
||||
// PR #1667 review: the edit-path crash-loop guard (respondToValid) was
|
||||
// never exercised — every other row uses a non-allowlist mode. An agent
|
||||
// saved as allowlist-with-empty-list crash-loops at startup.
|
||||
const base = {
|
||||
name: pinnedAgent.name,
|
||||
parallelism: "1",
|
||||
agentAcpCommand: pinnedAgent.acpCommand,
|
||||
acpCommand: pinnedAgent.acpCommand,
|
||||
selectedRuntimeId: "claude",
|
||||
inheritHarness: true,
|
||||
agentCommand: pinnedAgent.agentCommand,
|
||||
requiredEnvKeyMissing: false,
|
||||
};
|
||||
assert.equal(
|
||||
computeEditAgentFormValidity({
|
||||
...base,
|
||||
respondTo: "allowlist",
|
||||
respondToAllowlistLength: 0,
|
||||
}),
|
||||
false,
|
||||
"allowlist with an empty list must block Save",
|
||||
);
|
||||
assert.equal(
|
||||
computeEditAgentFormValidity({
|
||||
...base,
|
||||
respondTo: "allowlist",
|
||||
respondToAllowlistLength: 1,
|
||||
}),
|
||||
true,
|
||||
"allowlist with at least one pubkey must allow Save",
|
||||
);
|
||||
});
|
||||
@@ -304,15 +304,11 @@ export function UserProfilePanel({
|
||||
// Does THIS desktop hold the agent's seckey (or is this an editable persona)?
|
||||
// Gates edit (which needs the key) and grants owner access when managed locally.
|
||||
const isOwner = resolvedPersona ? true : managedAgentOwner;
|
||||
// Is the viewer the agent's declared owner (NIP-OA `ownerPubkey == me`)? This
|
||||
// is the right signal for viewing owner-scoped data (activity feed, memory):
|
||||
// the relay routes and the client decrypts those frames with the owner's OWN
|
||||
// key, so the agent's seckey is never needed. Computed here (before the gates
|
||||
// that consume it) so visibility keys off declared ownership, not key custody.
|
||||
// Is the viewer the agent's declared owner (NIP-OA `ownerPubkey == me`)?
|
||||
// Visibility keys off declared ownership, not key custody.
|
||||
const isCurrentUserOwner = ownsAuthorAgent(profile, currentPubkey);
|
||||
// The viewer may see owner-scoped data if they declared-own the agent OR they
|
||||
// manage it locally (older agents may not advertise an owner pubkey). Every
|
||||
// real boundary is server-side, so this only controls what UI we paint.
|
||||
// Viewer may see owner-scoped data if declared-owner OR locally managed;
|
||||
// real boundaries are server-side.
|
||||
const viewerIsOwner = isCurrentUserOwner || isOwner === true;
|
||||
|
||||
const activityAgent = React.useMemo(
|
||||
@@ -327,9 +323,7 @@ export function UserProfilePanel({
|
||||
}),
|
||||
[effectivePubkey, isBot, managedAgent, profile, relayAgent, viewerIsOwner],
|
||||
);
|
||||
// Observer ingestion (frame decryption + derived active-turn liveness) is
|
||||
// owner-global — mounted once in AppShell via useAgentObserverIngestion —
|
||||
// covering both locally managed agents and declared-owned relay agents.
|
||||
// Observer ingestion is owner-global — mounted once in AppShell.
|
||||
const canEditAgent =
|
||||
isOwner === true &&
|
||||
(managedAgent !== undefined || resolvedPersona !== undefined);
|
||||
@@ -633,9 +627,7 @@ export function UserProfilePanel({
|
||||
|
||||
const handleAddedToChannel = React.useCallback(
|
||||
(channel: Channel, result: AttachManagedAgentToChannelResult) => {
|
||||
if (result.started) {
|
||||
toast.success(`Added ${result.agent.name} to ${channel.name}.`);
|
||||
} else if (result.membershipAdded) {
|
||||
if (result.started || result.membershipAdded) {
|
||||
toast.success(`Added ${result.agent.name} to ${channel.name}.`);
|
||||
} else {
|
||||
toast.success(`${result.agent.name} is already in ${channel.name}.`);
|
||||
@@ -920,10 +912,18 @@ export function UserProfilePanel({
|
||||
<AgentEditDialog
|
||||
ctx={editCtx}
|
||||
initialFocus={editAgentFocus}
|
||||
isIdentityArchived={archiveActions.isArchived === true}
|
||||
linkedInstanceCount={personaInstances.length}
|
||||
onDeleteDefinition={
|
||||
resolvedPersona?.isBuiltIn ? undefined : handleDeletePersona
|
||||
}
|
||||
onOpenChange={(next) => {
|
||||
setEditAgentOpen(next);
|
||||
if (!next) setEditAgentFocus(undefined);
|
||||
}}
|
||||
onRemoveFromMyAgents={
|
||||
resolvedPersona?.isBuiltIn ? handleDeletePersona : undefined
|
||||
}
|
||||
open={editAgentOpen}
|
||||
/>
|
||||
) : null;
|
||||
|
||||
@@ -408,3 +408,134 @@ test.describe("edit agent dialog", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("merged dialog — team-linked and D+I wiring", () => {
|
||||
const TEAM_PERSONA_ID = "persona-team-e2e";
|
||||
const TEAM_AGENT_PUBKEY = TEST_IDENTITIES.tyler.pubkey;
|
||||
const TEAM_AGENT_NAME = "Tyler Agent";
|
||||
|
||||
test("team-linked instance: D-fields render disabled in the merged dialog", async ({
|
||||
page,
|
||||
}) => {
|
||||
// Seed a team-managed persona so the merged dialog shows D-fields as read-only.
|
||||
await installMockBridge(page, {
|
||||
managedAgents: [
|
||||
{
|
||||
pubkey: TEAM_AGENT_PUBKEY,
|
||||
name: TEAM_AGENT_NAME,
|
||||
personaId: TEAM_PERSONA_ID,
|
||||
status: "stopped",
|
||||
channelNames: ["agents"],
|
||||
},
|
||||
],
|
||||
personas: [
|
||||
{
|
||||
id: TEAM_PERSONA_ID,
|
||||
displayName: "Team Bot",
|
||||
systemPrompt: "Team-managed agent.",
|
||||
sourceTeam: "team-acme",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await page.goto("/");
|
||||
await page.getByTestId("open-agents-view").click();
|
||||
|
||||
const agentButton = page.getByRole("button", {
|
||||
name: "Team Bot agent profile",
|
||||
});
|
||||
await expect(agentButton).toBeVisible({ timeout: 10_000 });
|
||||
await agentButton.click();
|
||||
|
||||
await expect(page.getByTestId("user-profile-panel")).toBeVisible({
|
||||
timeout: 10_000,
|
||||
});
|
||||
await page.getByTestId("user-profile-edit-agent").click();
|
||||
|
||||
await expect(page.getByTestId("edit-agent-dialog")).toBeVisible({
|
||||
timeout: 10_000,
|
||||
});
|
||||
|
||||
// D-fields must be disabled for team-managed definitions.
|
||||
await expect(page.locator("#edit-agent-display-name")).toBeDisabled();
|
||||
await expect(page.locator("#edit-agent-system-prompt")).toBeDisabled();
|
||||
|
||||
// The "Managed by team X" notice must identify the team.
|
||||
await expect(page.getByTestId("team-managed-notice")).toBeVisible();
|
||||
await expect(page.getByTestId("team-managed-notice")).toContainText(
|
||||
"team-acme",
|
||||
);
|
||||
|
||||
// I-fields (instance name, respond-to) remain editable.
|
||||
await expect(page.locator("#edit-agent-name")).not.toBeDisabled();
|
||||
});
|
||||
|
||||
test("linked agent: edit D-field and I-field, one Save persists both layers", async ({
|
||||
page,
|
||||
}) => {
|
||||
// Seed a persona-linked agent. The merged dialog must write both the
|
||||
// D-layer (persona displayName) and I-layer (instance name) in a single Save.
|
||||
const LINKED_PERSONA_ID = "persona-linked-e2e";
|
||||
const LINKED_PUBKEY = TEST_IDENTITIES.tyler.pubkey;
|
||||
|
||||
await installMockBridge(page, {
|
||||
managedAgents: [
|
||||
{
|
||||
pubkey: LINKED_PUBKEY,
|
||||
name: "Original Instance Name",
|
||||
personaId: LINKED_PERSONA_ID,
|
||||
status: "stopped",
|
||||
channelNames: ["agents"],
|
||||
},
|
||||
],
|
||||
personas: [
|
||||
{
|
||||
id: LINKED_PERSONA_ID,
|
||||
displayName: "Original Definition Name",
|
||||
systemPrompt: "Original prompt.",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await page.goto("/");
|
||||
await page.getByTestId("open-agents-view").click();
|
||||
|
||||
const agentButton = page.getByRole("button", {
|
||||
name: "Original Definition Name agent profile",
|
||||
});
|
||||
await expect(agentButton).toBeVisible({ timeout: 10_000 });
|
||||
await agentButton.click();
|
||||
|
||||
await expect(page.getByTestId("user-profile-panel")).toBeVisible({
|
||||
timeout: 10_000,
|
||||
});
|
||||
await page.getByTestId("user-profile-edit-agent").click();
|
||||
|
||||
await expect(page.getByTestId("edit-agent-dialog")).toBeVisible({
|
||||
timeout: 10_000,
|
||||
});
|
||||
|
||||
// Edit a D-field (definition display name) and an I-field (instance name)
|
||||
// in the same dialog open.
|
||||
await page.locator("#edit-agent-display-name").fill("Renamed Definition");
|
||||
await page.locator("#edit-agent-name").fill("Renamed Instance");
|
||||
|
||||
// One Save click — both layers must be persisted.
|
||||
await page.getByTestId("edit-agent-dialog-submit").click();
|
||||
await expect(page.getByTestId("edit-agent-dialog")).not.toBeVisible();
|
||||
|
||||
// Reopen and verify both changes persisted (mock bridge echoes saves to store).
|
||||
await page.getByTestId("user-profile-edit-agent").click();
|
||||
await expect(page.getByTestId("edit-agent-dialog")).toBeVisible({
|
||||
timeout: 10_000,
|
||||
});
|
||||
await expect(page.locator("#edit-agent-display-name")).toHaveValue(
|
||||
"Renamed Definition",
|
||||
{ timeout: 10_000 },
|
||||
);
|
||||
await expect(page.locator("#edit-agent-name")).toHaveValue(
|
||||
"Renamed Instance",
|
||||
{ timeout: 10_000 },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -820,10 +820,10 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394"
|
||||
sha256: "1741988757a65eb6b36abe716829688cf01910bbf91c34354ff7ec1c3de2b349"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.17.0"
|
||||
version: "1.18.0"
|
||||
mime:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1297,26 +1297,26 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test
|
||||
sha256: "280d6d890011ca966ad08df7e8a4ddfab0fb3aa49f96ed6de56e3521347a9ae7"
|
||||
sha256: "8d9ceddbab833f180fbefed08afa76d7c03513dfdba87ffcec2718b02bbcbf20"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.30.0"
|
||||
version: "1.31.0"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
sha256: "8161c84903fd860b26bfdefb7963b3f0b68fee7adea0f59ef805ecca346f0c7a"
|
||||
sha256: "949a932224383300f01be9221c39180316445ecb8e7547f70a41a35bf421fb9e"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.10"
|
||||
version: "0.7.11"
|
||||
test_core:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_core
|
||||
sha256: "0381bd1585d1a924763c308100f2138205252fb90c9d4eeaf28489ee65ccde51"
|
||||
sha256: "1991d4cfe85d5043241acac92962c3977c8d2f2add1ee73130c7b286417d1d34"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.16"
|
||||
version: "0.6.17"
|
||||
tuple:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
Reference in New Issue
Block a user