diff --git a/docs/features/dashboard.md b/docs/features/dashboard.md index b8f7caec7b..2fe73b949c 100644 --- a/docs/features/dashboard.md +++ b/docs/features/dashboard.md @@ -133,6 +133,16 @@ Until then the grant is kept as typed and reaches nobody. With sign-in on, **Set **Tokens** links to Namespaces in your org for giving a person access: a token is for a tool, agent or script. +**Settings** on a namespace you manage changes its description, visibility, spend caps, +join rule and capture consent. On a memory namespace it also sets the +[proposal policy](memory/writing.md#proposals): the counts of passed and failed graded +runs that mark a proposal ready to accept, and the count of failed graded runs that marks +one ready to reject, which also rejects it when rejecting is automatic. Loom never accepts +a proposal; an admin of the namespace who did not propose it does. The same dialog sets +the extraction +[coverage sweep](memory/extraction.md#operator-extraction-policy) to always, never, or +left to Loom, which runs it only on fact-dense turns. + The dashboard's text follows the [copy rules](../development/dashboard-design.md#rules-a-change-is-checked-against): its sentences name what you see, never an operation or an API path; an operation's name shows diff --git a/docs/features/memory/extraction.md b/docs/features/memory/extraction.md index 62d81aa5a4..d17208ea7b 100644 --- a/docs/features/memory/extraction.md +++ b/docs/features/memory/extraction.md @@ -783,8 +783,9 @@ curl -sX POST http://localhost:7777/v1/extraction_policy.set \ passes cannot read it. An extraction under a policy can therefore keep fewer facts than the same extraction without one. Two settings get more facts from the same turns, and both follow the policy: `coverage_sweep=true` on the namespace - (`namespace.register`) gives the turns and statements the first pass cited nowhere a - second reading on every ingest, for one more model call, and a call's own + (`namespace.register`, or the namespace's settings in the dashboard) gives the turns + and statements the first pass cited nowhere a second reading on every ingest, for one + more model call, and a call's own `extraction_instructions` (a prompt suffix of up to 4,096 characters) says what else to keep. `session.brief_save` never runs its deterministic builder under a policy diff --git a/docs/features/namespaces-and-sharing.md b/docs/features/namespaces-and-sharing.md index fb14153abf..0167cf711c 100644 --- a/docs/features/namespaces-and-sharing.md +++ b/docs/features/namespaces-and-sharing.md @@ -23,7 +23,8 @@ a live grant on the name. Re-registering is a partial update: an omitted field keeps its stored value. `tags` is replaced whole. For `conflict_threshold`, `capture_generation_io` and `coverage_sweep`, omitted keeps the stored choice and an explicit -`null` returns to the server default. +`null` returns to the server default. The namespace's **Settings** in the [dashboard](dashboard.md) set +`proposal_policy` and `coverage_sweep` too. | Field | What it controls | | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | diff --git a/frontend/src/api/admin.register.test.ts b/frontend/src/api/admin.register.test.ts new file mode 100644 index 0000000000..09e3c2cf47 --- /dev/null +++ b/frontend/src/api/admin.register.test.ts @@ -0,0 +1,41 @@ +import { afterEach, describe, expect, it, vi } from "vitest"; + +// The server keeps a setting a register call omits and reads an explicit null as "return +// to the default", so the client sends the proposal policy and the coverage sweep only +// when the caller set them, null included. +const post = vi.hoisted(() => vi.fn(async () => ({ registered: true, namespace: "team", updated_at: "" }))); +vi.mock("../api", async (importOriginal) => ({ ...(await importOriginal()), post })); +import { registerNamespace } from "./admin"; + +const id = { org: "acme", namespace: "team" }; +const sent = () => { + expect(post).toHaveBeenCalledTimes(1); + const [path, body] = post.mock.calls[0] as unknown as [string, Record]; + expect(path).toBe("/v1/namespace.register"); + return body; +}; + +afterEach(() => vi.clearAllMocks()); + +describe("registerNamespace", () => { + it("sends coverage_sweep null when set and omits it when not", async () => { + await registerNamespace(id, { owner_email: "owner@example.com", coverage_sweep: null }); + const body = sent(); + expect("coverage_sweep" in body).toBe(true); + expect(body["coverage_sweep"]).toBeNull(); + post.mockClear(); + + await registerNamespace(id, { owner_email: "owner@example.com" }); + expect("coverage_sweep" in sent()).toBe(false); + }); + + it("sends the proposal policy when set and omits it when not", async () => { + const policy = { mode: "auto", min_passes: 3, max_fails: 1, reject_after_fails: 4 } as const; + await registerNamespace(id, { owner_email: "owner@example.com", proposal_policy: policy }); + expect(sent()["proposal_policy"]).toEqual(policy); + post.mockClear(); + + await registerNamespace(id, { owner_email: "owner@example.com" }); + expect("proposal_policy" in sent()).toBe(false); + }); +}); diff --git a/frontend/src/api/admin.ts b/frontend/src/api/admin.ts index 25077942eb..acbd5b6857 100644 --- a/frontend/src/api/admin.ts +++ b/frontend/src/api/admin.ts @@ -249,6 +249,17 @@ export interface ConsolidationRunRow { // ===== Namespace flags ===== +/** A namespace's rule for proposals. In either mode the two thresholds mark a proposal + * ready to accept and `reject_after_fails` failed graded runs mark it ready to reject, + * which is checked first (0 never marks one). Under `auto` that count also rejects the + * proposal. No mode accepts one. */ +export interface ProposalPolicy { + mode: "manual" | "auto"; + min_passes: number; + max_fails: number; + reject_after_fails: number; +} + export interface NamespaceInfo { namespace: string; owner_email: string; @@ -259,6 +270,11 @@ export interface NamespaceInfo { /** null/undefined = inherit the server default; false = this namespace declined * to have its prompt/completion text captured. */ capture_generation_io?: boolean | null; + /** true and false force the extraction coverage sweep on and off; null/undefined leaves + * it to each ingest's density. */ + coverage_sweep?: boolean | null; + /** The defaults (manual, 2 passed, 0 failed, never rejects) when none is stored. */ + proposal_policy?: ProposalPolicy; daily_cost_cap_usd?: number; daily_user_cost_cap_usd?: number; budget_alert_inbox?: string; @@ -317,6 +333,10 @@ export interface NamespaceRegisterFields { /** Omit to keep the stored value. */ join_policy?: "inherit" | "open" | "approval" | "closed"; capture_generation_io?: boolean | null; + /** Omit to keep the stored choice; null returns it to each ingest's density. */ + coverage_sweep?: boolean | null; + /** Omit to keep the stored policy; it is written whole. */ + proposal_policy?: ProposalPolicy; } type RegisterResult = { registered: boolean; namespace: string; updated_at: string; visibility?: string }; @@ -353,6 +373,13 @@ export async function registerNamespace( if (opts.capture_generation_io !== undefined) { body["capture_generation_io"] = opts.capture_generation_io; } + // The same rule: omitted keeps the stored value, and a null sweep is sent as null. + if (opts.coverage_sweep !== undefined) { + body["coverage_sweep"] = opts.coverage_sweep; + } + if (opts.proposal_policy !== undefined) { + body["proposal_policy"] = opts.proposal_policy; + } return post("/v1/namespace.register", body); } diff --git a/frontend/src/flows/NamespacePolicyControls.tsx b/frontend/src/flows/NamespacePolicyControls.tsx new file mode 100644 index 0000000000..df7dcd68a1 --- /dev/null +++ b/frontend/src/flows/NamespacePolicyControls.tsx @@ -0,0 +1,155 @@ +import { forwardRef, useImperativeHandle, useState } from "react"; +import { NumberField } from "@clickhouse/click-ui/NumberField"; +import { Select } from "@clickhouse/click-ui/Select"; +import type { NamespaceInfo, NamespaceRegisterFields, ProposalPolicy } from "../api"; +import { oneOf } from "../lib/oneOf"; + +interface Props { + namespace: NamespaceInfo; + locked: boolean; + save: (patch: Partial) => Promise; +} + +export interface PolicyControlsHandle { + cancelDrafts: () => boolean; +} + +// What a namespace with no stored policy runs with. +const DEFAULT_POLICY: ProposalPolicy = { mode: "manual", min_passes: 2, max_fails: 0, reject_after_fails: 0 }; + +type Count = "min_passes" | "max_fails" | "reject_after_fails"; +// The range the server takes for each count. +const LOWEST: Record = { min_passes: 1, max_fails: 0, reject_after_fails: 0 }; +const HIGHEST = 1000; +const NO_DRAFTS: Record = { min_passes: null, max_fails: null, reject_after_fails: null }; + +// The stored sweep is true, false or null; a Select's values are strings. +const SWEEP = [ + ["inherit", "Let Loom decide", null], + ["always", "Always", true], + ["never", "Never", false], +] as const; + +/** A memory namespace's proposal policy and its coverage sweep, in the settings dialog. */ +export const NamespacePolicyControls = forwardRef(function NamespacePolicyControls( + { namespace, locked, save }, + ref, +) { + const policy = namespace.proposal_policy ?? DEFAULT_POLICY; + // A count's text while it is being edited; a count with no draft shows the stored one. + const [drafts, setDrafts] = useState(NO_DRAFTS); + + // The dialog's Escape handler asks first: Escape restores a typed count before it closes. + useImperativeHandle( + ref, + () => ({ + cancelDrafts() { + if (Object.values(drafts).every((text) => text === null)) return false; + setDrafts(NO_DRAFTS); + return true; + }, + }), + [drafts], + ); + + // Blur (and Enter, which blurs) commits a whole number in the count's range that differs + // from the stored one; anything else reverts without a request. The server replaces the + // policy whole, so the other three fields go with it. + const commit = async (count: Count) => { + const text = drafts[count]; + if (text === null) return; + const value = Number(text); + const inRange = Number.isInteger(value) && value >= LOWEST[count] && value <= HIGHEST; + if (text.trim() !== "" && inRange && value !== policy[count]) { + await save({ proposal_policy: { ...policy, [count]: value } }); + } + setDrafts((current) => ({ ...current, [count]: null })); + }; + + const countField = (count: Count, id: string, label: string, hintId: string) => ( + setDrafts((current) => ({ ...current, [count]: text }))} + onBlur={() => void commit(count)} + onKeyDown={(e) => { + if (e.key === "Enter") e.currentTarget.blur(); + }} + /> + ); + + const sweep = SWEEP.find(([, , stored]) => stored === (namespace.coverage_sweep ?? null)) ?? SWEEP[0]; + + return ( + <> +
+ Proposals +
+
+ {countField("min_passes", "ns-proposal-min-passes", "Passed graded runs needed", "ns-proposal-ready-hint")} + {countField("max_fails", "ns-proposal-max-fails", "Failed graded runs allowed", "ns-proposal-ready-hint")} +
+

+ A proposal is marked ready to accept after this many graded runs passed and at most this many failed. +

+
+ {/* A Select, as the dialog's other single choices are: each pick saves. */} + { + const next = SWEEP.find(([value]) => value === v); + if (next && next[0] !== sweep[0]) void save({ coverage_sweep: next[2] }); + }} + options={SWEEP.map(([value, label]) => ({ value, label }))} + /> +

+ After extracting facts from a conversation, Loom reads the turns no fact came from once more. It finds more + facts in dense material and costs one more model call. Left to Loom, it runs only on fact-dense turns. +

+ + + ); +}); diff --git a/frontend/src/flows/NamespaceSettingsDialog.policy.test.tsx b/frontend/src/flows/NamespaceSettingsDialog.policy.test.tsx new file mode 100644 index 0000000000..75f9eceee0 --- /dev/null +++ b/frontend/src/flows/NamespaceSettingsDialog.policy.test.tsx @@ -0,0 +1,310 @@ +/** The settings dialog shows and saves a memory namespace's proposal policy and its + * coverage sweep. Each save is one register call that carries the whole policy (or the + * sweep, null included) beside the settings a re-registration would otherwise reset. */ +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import userEvent from "@testing-library/user-event"; +import { act, fireEvent, render, screen, within } from "../test/rtl"; +import { NamespaceSettingsDialog } from "./NamespaceSettingsDialog"; +import { useStore } from "../lib/state"; +import { resetNamespaceRoleCache } from "../lib/namespaceRole"; +import { toastError } from "../components/Toast"; +import type { MyNamespaceEntry, NamespaceInfo, ProposalPolicy } from "../api"; + +vi.mock("../components/Toast", () => ({ toast: vi.fn(), toastError: vi.fn(), ToastViewport: () => null })); + +const WAIT = { timeout: 5000 }; +const NEEDS = "Needs admin on team. An admin of it can grant that."; +const PASSES = "Passed graded runs needed"; +const FAILS = "Failed graded runs allowed"; +// The third count's label follows the mode: it rejects only when rejecting is automatic. +const REJECT_AFTER = "Failed graded runs that reject"; +const MARK_AFTER = "Failed graded runs that mark ready to reject"; +const NEVER_ACCEPTS = "Loom never accepts a proposal. An admin of this namespace who did not propose it accepts it."; + +const base: NamespaceInfo = { + namespace: "team", + owner_email: "owner@example.com", + description: "what the team knows", + tags: ["billing"], + active: true, + consolidation_enabled: false, + conflict_threshold: null, + daily_cost_cap_usd: 5, + created_at: "", + updated_at: "", +}; + +const grant = (role: MyNamespaceEntry["role"]): MyNamespaceEntry => ({ + namespace: "team", + role, + status: "active", + visibility: "private", + description: "", + joined_at: null, + is_new: false, +}); + +// The dialog runs on the real namespace clients over a fake `fetch`, so a test reads the +// body the server would receive. `stored` is what namespace.get answers; a register call +// with a policy or a sweep changes it, as the server's row would. `refusal` is the message +// the server refuses the next register call with. +let stored: NamespaceInfo; +let refusal: string | null; +const fetchMock = vi.fn(async (path: string, init: { body: string }) => { + const answer = (body: unknown, status = 200) => new Response(JSON.stringify(body), { status }); + const body = JSON.parse(init.body) as Partial; + if (path === "/v1/namespace.get") return answer({ found: true, ...stored }); + if (path !== "/v1/namespace.register") throw new Error(`unexpected call: ${path}`); + if (refusal) return answer({ detail: refusal }, 422); + if (body.proposal_policy !== undefined) stored = { ...stored, proposal_policy: body.proposal_policy }; + if ("coverage_sweep" in body) stored = { ...stored, coverage_sweep: body.coverage_sweep }; + return answer({ registered: true, namespace: "team", updated_at: "" }); +}); + +// The clients are real, so a read or a save is several promise turns: a task later, every +// one of them has run. +const settle = () => act(async () => void (await new Promise((resolve) => setTimeout(resolve, 0)))); + +const registered = () => + fetchMock.mock.calls + .filter(([path]) => path === "/v1/namespace.register") + .map(([, init]) => JSON.parse(init.body) as NamespaceInfo); + +async function open( + info: Partial = {}, + role: MyNamespaceEntry["role"] = "admin", + onOpenChange: (open: boolean) => void = () => undefined, +) { + stored = { ...base, ...info }; + useStore.setState({ + whoami: { authenticated: true, subject: "me@example.com", org: "dev", roles: ["USER"] }, + myNamespaces: [grant(role)], + }); + render(); + await settle(); +} + +const field = (label: string) => { + const input = screen.getByLabelText(label); + if (!(input instanceof HTMLInputElement)) throw new Error(`${label} is not an input`); + return input; +}; + +async function type(label: string, text: string) { + const input = field(label); + input.focus(); + fireEvent.change(input, { target: { value: text } }); + fireEvent.blur(input); + await settle(); + return input; +} + +// Click UI's Select opens its options in a popover dialog, the last one open. +async function pick(label: string, option: string) { + await userEvent.click(screen.getByLabelText(label)); + const options = (await screen.findAllByRole("dialog", undefined, WAIT)).at(-1) as HTMLElement; + await userEvent.click(await within(options).findByText(option, undefined, WAIT)); + await settle(); +} + +beforeEach(() => { + vi.clearAllMocks(); + resetNamespaceRoleCache(); + refusal = null; + vi.stubGlobal("fetch", fetchMock); +}); +afterEach(() => vi.unstubAllGlobals()); + +describe("NamespaceSettingsDialog proposal policy", () => { + it("shows the stored policy", async () => { + await open({ proposal_policy: { mode: "auto", min_passes: 3, max_fails: 1, reject_after_fails: 4 } }); + expect(field(PASSES)).toHaveValue(3); + expect(field(FAILS)).toHaveValue(1); + expect(screen.getByLabelText("Rejecting")).toHaveTextContent("Automatically"); + expect(field(REJECT_AFTER)).toHaveValue(4); + }); + + it("shows the defaults when no policy is stored", async () => { + await open(); + expect(field(PASSES)).toHaveValue(2); + expect(field(FAILS)).toHaveValue(0); + expect(screen.getByLabelText("Rejecting")).toHaveTextContent("By a person only"); + expect(field(MARK_AFTER)).toHaveValue(0); + }); + + it("saves the whole policy with the other settings intact", async () => { + await open({ proposal_policy: { mode: "auto", min_passes: 3, max_fails: 1, reject_after_fails: 4 } }); + await type(PASSES, "5"); + expect(registered()).toHaveLength(1); + const body = registered()[0]; + expect(body.proposal_policy).toEqual({ mode: "auto", min_passes: 5, max_fails: 1, reject_after_fails: 4 }); + expect(body).toMatchObject({ + org: "dev", + namespace: "team", + owner_email: "owner@example.com", + description: "what the team knows", + tags: ["billing"], + daily_cost_cap_usd: 5, + }); + // The dialog shows what the server answers after the save. + expect(field(PASSES)).toHaveValue(5); + }); + + it.each([ + [FAILS, "2", { max_fails: 2 }], + [REJECT_AFTER, "0", { reject_after_fails: 0 }], + ])("%s commits on Enter with the rest of the policy", async (label, text, change) => { + const policy: ProposalPolicy = { mode: "auto", min_passes: 3, max_fails: 1, reject_after_fails: 4 }; + await open({ proposal_policy: policy }); + const input = field(label); + input.focus(); + fireEvent.change(input, { target: { value: text } }); + fireEvent.keyDown(input, { key: "Enter" }); + await settle(); + expect(registered().map((body) => body.proposal_policy)).toEqual([{ ...policy, ...change }]); + }); + + // The count marks a proposal ready to reject in either mode, so a stored one is never hidden. + it("shows the reject count in both modes and words it by the mode", async () => { + await open({ proposal_policy: { mode: "manual", min_passes: 2, max_fails: 5, reject_after_fails: 3 } }); + expect(screen.queryByLabelText(REJECT_AFTER)).toBeNull(); + const marks = field(MARK_AFTER); + expect(marks).toHaveValue(3); + expect(marks).toHaveAccessibleDescription( + "A proposal is marked ready to reject after this many failed graded runs. 0 never marks one.", + ); + await pick("Rejecting", "Automatically"); + expect(registered().map((body) => body.proposal_policy)).toEqual([ + { mode: "auto", min_passes: 2, max_fails: 5, reject_after_fails: 3 }, + ]); + expect(screen.queryByLabelText(MARK_AFTER)).toBeNull(); + const rejects = field(REJECT_AFTER); + expect(rejects).toHaveValue(3); + expect(rejects).toHaveAccessibleDescription( + "Reject a proposal after this many failed graded runs. 0 never rejects.", + ); + }); + + it("clears a stored reject count while rejecting is by a person only", async () => { + await open({ proposal_policy: { mode: "manual", min_passes: 2, max_fails: 0, reject_after_fails: 3 } }); + await type(MARK_AFTER, "0"); + expect(registered().map((body) => body.proposal_policy)).toEqual([ + { mode: "manual", min_passes: 2, max_fails: 0, reject_after_fails: 0 }, + ]); + expect(field(MARK_AFTER)).toHaveValue(0); + }); + + it.each([ + [PASSES, "0"], + [PASSES, "1001"], + [PASSES, "2.5"], + [PASSES, ""], + [PASSES, "3"], + [FAILS, "-1"], + [FAILS, "1001"], + [REJECT_AFTER, "-1"], + [REJECT_AFTER, "1001"], + ])("a number out of range, partial or unchanged reverts without a request: %s %j", async (label, text) => { + const policy: ProposalPolicy = { mode: "auto", min_passes: 3, max_fails: 1, reject_after_fails: 4 }; + await open({ proposal_policy: policy }); + const input = await type(label, text); + expect(registered()).toEqual([]); + expect(input).toHaveValue( + policy[label === PASSES ? "min_passes" : label === FAILS ? "max_fails" : "reject_after_fails"], + ); + }); + + it("says that Loom never accepts a proposal", async () => { + await open({ proposal_policy: { mode: "auto", min_passes: 3, max_fails: 1, reject_after_fails: 4 } }); + const group = screen.getByRole("group", { name: "Proposals" }); + expect(within(group).getByText(NEVER_ACCEPTS)).toBeInTheDocument(); + expect(group).toHaveTextContent("A proposal is marked ready to accept after"); + // No wording under which the policy, or Loom, accepts or decides. + const text = (group.textContent ?? "").replace(NEVER_ACCEPTS, ""); + expect(text).not.toMatch(/accepts|accepted|accepting|decide/i); + }); + + it("a refused save shows the server's message and returns to the stored value", async () => { + await open(); + refusal = "this namespace takes no proposal policy"; + const input = await type(PASSES, "7"); + expect(registered()).toHaveLength(1); + expect(toastError).toHaveBeenCalledWith("Save failed", expect.objectContaining({ message: refusal })); + expect(input).toHaveValue(2); + }); + + it("Escape restores a typed number before it closes the dialog", async () => { + const onOpenChange = vi.fn(); + await open({}, "admin", onOpenChange); + const input = field(PASSES); + input.focus(); + fireEvent.change(input, { target: { value: "9" } }); + fireEvent.keyDown(input, { key: "Escape" }); + expect(onOpenChange).not.toHaveBeenCalled(); + expect(input).toHaveValue(2); + fireEvent.blur(input); + await settle(); + expect(registered()).toEqual([]); + input.focus(); + fireEvent.keyDown(input, { key: "Escape" }); + expect(onOpenChange).toHaveBeenCalledWith(false); + }); +}); + +describe("NamespaceSettingsDialog coverage sweep", () => { + it.each([ + [{ coverage_sweep: true }, "Always"], + [{ coverage_sweep: false }, "Never"], + [{ coverage_sweep: null }, "Let Loom decide"], + [{}, "Let Loom decide"], + ])("shows the three sweep states: %j reads %s", async (info, label) => { + await open(info); + const sweep = screen.getByLabelText("Coverage sweep"); + expect(sweep).toHaveTextContent(label); + expect(sweep).toHaveAccessibleDescription(/Loom reads the turns no fact came from once more/); + }); + + it("sends null for Let Loom decide, and true and false for the other two", async () => { + await open({ coverage_sweep: true }); + await pick("Coverage sweep", "Let Loom decide"); + expect(registered()).toHaveLength(1); + expect("coverage_sweep" in registered()[0]).toBe(true); + expect(registered()[0].coverage_sweep).toBeNull(); + expect(registered()[0]).toMatchObject({ + owner_email: "owner@example.com", + tags: ["billing"], + daily_cost_cap_usd: 5, + }); + expect(screen.getByLabelText("Coverage sweep")).toHaveTextContent("Let Loom decide"); + + await pick("Coverage sweep", "Never"); + expect(registered().at(-1)?.coverage_sweep).toBe(false); + expect(screen.getByLabelText("Coverage sweep")).toHaveTextContent("Never"); + + await pick("Coverage sweep", "Always"); + expect(registered().at(-1)?.coverage_sweep).toBe(true); + expect(registered()).toHaveLength(3); + }); +}); + +describe("NamespaceSettingsDialog policy and sweep, by caller and kind", () => { + it("disables both controls with the reason when the caller may not manage the namespace", async () => { + await open({ proposal_policy: { mode: "auto", min_passes: 3, max_fails: 1, reject_after_fails: 4 } }, "writer"); + expect(screen.getByTestId("settings-locked")).toHaveTextContent(NEEDS); + for (const label of [PASSES, FAILS, REJECT_AFTER, "Rejecting", "Coverage sweep"]) { + expect(screen.getByLabelText(label)).toBeDisabled(); + } + // The stored values stay in view. + expect(field(PASSES)).toHaveValue(3); + expect(screen.getByText(NEVER_ACCEPTS)).toBeInTheDocument(); + }); + + it("shows neither control on a repository", async () => { + await open({ kind: "code", coverage_sweep: true }); + expect(screen.getByLabelText("How people join")).toBeInTheDocument(); + expect(screen.queryByRole("group", { name: "Proposals" })).toBeNull(); + expect(screen.queryByLabelText(PASSES)).toBeNull(); + expect(screen.queryByLabelText("Coverage sweep")).toBeNull(); + expect(screen.queryByText(NEVER_ACCEPTS)).toBeNull(); + }); +}); diff --git a/frontend/src/flows/NamespaceSettingsDialog.tsx b/frontend/src/flows/NamespaceSettingsDialog.tsx index 16164d47b2..21ed84b821 100644 --- a/frontend/src/flows/NamespaceSettingsDialog.tsx +++ b/frontend/src/flows/NamespaceSettingsDialog.tsx @@ -24,6 +24,7 @@ import { Modal } from "../components/ui/Modal"; import { Loading, Unavailable } from "../components/ui"; import { COST_CAP_EFFECT } from "../lib/costCap"; import { NamespaceBudgetAlerts, type BudgetAlertsHandle } from "./NamespaceBudgetAlerts"; +import { NamespacePolicyControls, type PolicyControlsHandle } from "./NamespacePolicyControls"; const REPO_JOIN_RULES = [ ["open", "Open", "Anyone in the org joins instantly as a reader."], @@ -63,6 +64,7 @@ export function NamespaceSettingsDialog({ open, onOpenChange, org, namespace, la // previous namespace is never shown under this one or used to build its save. const key = JSON.stringify([org, namespace]); const budgetAlertsRef = useRef(null); + const policyRef = useRef(null); const keyRef = useRef(key); keyRef.current = key; const [loaded, setLoaded] = useState<{ key: string; info: NamespaceInfo | null } | null>(null); @@ -194,9 +196,10 @@ export function NamespaceSettingsDialog({ open, onOpenChange, org, namespace, la title={`Settings ยท ${namespace}`} className="w-full max-w-[600px]" onEscapeKeyDown={(e) => { - // Escape while editing the cap restores it; the next Escape closes the dialog. + // Escape while editing a number restores it; the next Escape closes the dialog. const cancelledBudgetDraft = budgetAlertsRef.current?.cancelDrafts() ?? false; - if (capDraft === null && !cancelledBudgetDraft) return; + const cancelledPolicyDraft = policyRef.current?.cancelDrafts() ?? false; + if (capDraft === null && !cancelledBudgetDraft && !cancelledPolicyDraft) return; e.preventDefault(); setCapEdit(null); }} @@ -377,6 +380,14 @@ export function NamespaceSettingsDialog({ open, onOpenChange, org, namespace, la minute.

+ + )}