mirror of
https://github.com/block/buzz.git
synced 2026-11-29 04:32:08 +00:00
fix(agents): wire observed-state settlement, team D-field read-only, coordinator tests
Address all pass-1 CHANGES_REQUIRED findings from Thufir's review: CRITICAL-1+2: AgentEditDialog now delegates instance contexts entirely to AgentInstanceEditDialog (all I/L fields, correct testid). Definition-only contexts use AgentDefinitionDialog + Artifact 3 coordinator. Removed the type-cast hack (onUpdated?.(undefined as unknown as ManagedAgent)); the definition-only path correctly does not call onUpdated. IMPORTANT-3: AgentDefinitionDialog gains definitionReadOnly prop — when set, all D-fields render disabled and a 'Managed by team' notice is shown; canSubmit is gated; coordinator also guards against a misconfigured bypass. isDefinitionReadOnly in agentFormModel.ts checks sourceTeam at the diff layer too. IMPORTANT-4: Coordinator now settles from observed state on BOTH success and error paths (not just error). The old 'no firstError → success' branch is gone; the result is derived entirely from re-fetched observed store comparison. Absent entity after refetch = not persisted. Per-policy failure tracking: each policy tracked individually; unattempted policies also reported failed. IMPORTANT-5: Publish success toast uses personaSaveNotice (not generic 'saved'). Publication status tracked through updatePersonaAndPublish return value. Tests added: - agentFormModel.test.mjs: 3 new tests covering team D-field unemittability (test_team_definition_emits_no_personaInput_even_when_fields_differ, test_team_definition_with_instance_emits_no_personaInput_but_allows_instance_diff, plus the env-clobber variants already present) - agentSaveCoordinator.test.mjs (new file): 11 tests covering write ordering, local-save/publish failure, observed-state mismatch, and partial policy failure Full desktop test suite: 4553/4553 passing. TypeScript clean. Biome clean. File-size gate: AgentDefinitionDialog.tsx 1041 lines (limit 1041). Co-authored-by: Will Pfleger <pfleger.will@gmail.com> Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
This commit is contained in:
@@ -212,3 +212,88 @@ test("test_env_clobber_dropped_even_when_definition_env_differs_from_instance_en
|
||||
assert.ok(emit.personaInput, "definition should be updated");
|
||||
assert.equal(emit.agentInput, null, "instance env must not be clobbered");
|
||||
});
|
||||
|
||||
// ── Regression test 3 (AC5): team D-field emits no personaInput ──────────────
|
||||
//
|
||||
// Spec pass-4 amendment: team-managed D-fields are structurally unemittable.
|
||||
// emitAgentFormDiff with a definition-only context whose definition has a
|
||||
// sourceTeam set must return personaInput:null even when D-fields differ.
|
||||
|
||||
test("test_team_definition_emits_no_personaInput_even_when_fields_differ", () => {
|
||||
// Team-managed definition: sourceTeam is set.
|
||||
const definition = makeDefinition({
|
||||
sourceTeam: "team-acme",
|
||||
displayName: "Team Bot",
|
||||
systemPrompt: "Team-managed instructions.",
|
||||
});
|
||||
|
||||
const ctx = { kind: "definition-only", definition };
|
||||
const saved = seedAgentFormModel(ctx);
|
||||
|
||||
// Simulate user attempting to change D-fields (should be blocked structurally,
|
||||
// but the diff function is the last defence if the UI layer fails to block it).
|
||||
const next = {
|
||||
...saved,
|
||||
displayName: "Tampered Name",
|
||||
systemPrompt: "Tampered prompt.",
|
||||
};
|
||||
|
||||
const emit = emitAgentFormDiff(saved, next, ctx);
|
||||
|
||||
assert.equal(
|
||||
emit.personaInput,
|
||||
null,
|
||||
"personaInput must be null for team-managed definition-only contexts",
|
||||
);
|
||||
assert.equal(
|
||||
emit.agentInput,
|
||||
null,
|
||||
"agentInput must be null for definition-only contexts",
|
||||
);
|
||||
assert.deepEqual(
|
||||
emit.policySets,
|
||||
[],
|
||||
"policySets must be empty for definition-only contexts without an instance",
|
||||
);
|
||||
});
|
||||
|
||||
test("test_team_definition_with_instance_emits_no_personaInput_but_allows_instance_diff", () => {
|
||||
// Team-managed definition linked to an instance: D-fields must be unemittable
|
||||
// but I/L fields (respondTo, etc.) are still editable.
|
||||
const definition = makeDefinition({
|
||||
sourceTeam: "team-acme",
|
||||
displayName: "Team Bot",
|
||||
systemPrompt: "Team-managed instructions.",
|
||||
});
|
||||
const instance = makeInstance({
|
||||
respondTo: "owner-only",
|
||||
parallelism: 1,
|
||||
});
|
||||
|
||||
const ctx = { kind: "instance-with-definition", definition, instance };
|
||||
const saved = seedAgentFormModel(ctx);
|
||||
|
||||
// User tries to edit a D-field AND an I-field simultaneously.
|
||||
const next = {
|
||||
...saved,
|
||||
displayName: "Tampered Name", // D-field — team-managed, must not emit
|
||||
respondTo: "anyone", // I-field — instance-owned, must emit
|
||||
};
|
||||
|
||||
const emit = emitAgentFormDiff(saved, next, ctx);
|
||||
|
||||
assert.equal(
|
||||
emit.personaInput,
|
||||
null,
|
||||
"personaInput must be null even when D-field differs for team-managed definition",
|
||||
);
|
||||
assert.ok(
|
||||
emit.agentInput,
|
||||
"agentInput must be emitted when an I-field changed",
|
||||
);
|
||||
assert.equal(
|
||||
emit.agentInput.respondTo,
|
||||
"anyone",
|
||||
"agentInput should carry the updated respondTo",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user