mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-30 05:16:50 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Agents run in git worktrees tied to a workspace branch; when the actual branch diverges from the expected one (e.g. a parent feature branch was renamed), Paperclip currently has no structured field to report *why* the branch is incoherent or whether it can be auto-reconciled > - The workspace-incoherence fingerprint already captures SHA mismatches, but there is no evidence field distinguishing "actual branch is a descendant of expected" (safe to fast-forward) from "branches have diverged" (needs human review) or "SHAs are unavailable" (unknown) > - Operators and future recovery flows need a typed verdict to make decisions without re-running git commands themselves > - This pull request adds `ancestryVerdict` and `plainLanguageReason` evidence fields computed via `git merge-base --is-ancestor`, and scaffolds the off-by-default `enableWorkspaceBranchReconcileForward` instance setting with no runtime behavior yet > - The benefit is that future recovery logic can branch on a typed verdict rather than parsing prose, while the fingerprint v1 payload stays stable ## Linked Issues or Issue Description No public GitHub issue pre-exists for this diagnostic addition. **Problem or motivation** When Paperclip detects that an agent's actual workspace branch differs from the recorded expected branch, the current fingerprint carries only raw SHAs. There is no typed field indicating whether the actual branch is a descendant of the expected one (safe reconcile path) vs. a true divergence (requires human intervention) vs. an indeterminate state (missing SHAs or git errors). Downstream recovery logic cannot branch safely without re-running git. **Proposed solution** Add `ancestryVerdict` and `plainLanguageReason` to the workspace incoherence evidence type; compute via `git merge-base --is-ancestor`; scaffold a feature-flag for future forward-reconcile behavior (`enableWorkspaceBranchReconcileForward`, off by default, not yet read by any runtime path). **Alternatives considered** Encoding the verdict in the existing fingerprint string was rejected because the fingerprint is a stable identity hash, not a mutable evidence bag. Changing it would break monitors keyed on the string. **Roadmap alignment** Supports future workspace auto-reconcile work; ROADMAP.md has no conflicting entry for this diagnostic layer. ## What Changed - `packages/shared/src/types/heartbeat.ts` adds `ancestryVerdict` and `plainLanguageReason` fields to `WorkspaceIncoherenceEvidence` - `packages/shared/src/types/instance.ts` adds `enableWorkspaceBranchReconcileForward` boolean (off by default) - `packages/shared/src/validators/instance.ts` exports the new flag from the settings validator - `server/src/services/workspace-runtime.ts` computes `ancestryVerdict` via `git merge-base --is-ancestor`; falls back to `unknown` on missing SHAs or command errors; excludes verdict fields from fingerprint v1 computation - `server/src/services/instance-settings.ts` wires the new setting through to the settings service - Tests updated in `workspace-runtime.test.ts`, `instance-settings-service.test.ts`, `instance-settings-routes.test.ts`, and `instance.test.ts` (104 tests total) ## Verification ```bash pnpm exec vitest run \ server/src/__tests__/workspace-runtime.test.ts \ server/src/__tests__/instance-settings-service.test.ts \ server/src/__tests__/instance-settings-routes.test.ts \ packages/shared/src/validators/instance.test.ts # 104 tests pass pnpm --filter @paperclipai/shared typecheck pnpm --filter @paperclipai/server typecheck # both exit 0 ``` Manual: trigger a workspace incoherence event and confirm the evidence object carries `ancestryVerdict` and `plainLanguageReason`; confirm the fingerprint string stays `workspace_incoherence:v1:sha256:...`. ## Risks **Low risk.** Purely additive. Fingerprint v1 payload is unchanged. The new flag has no runtime effect in this PR. `git merge-base --is-ancestor` exits non-zero for both "not an ancestor" and "command error"; both are handled and collapsed to typed values with a prose reason. ## Model Used Provider: Anthropic, model: Claude Sonnet 4.6 (`claude-sonnet-4-6`), 200k context, tool use enabled. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [ ] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [ ] I will address all Greptile and reviewer comments before requesting merge --------- Co-authored-by: Paperclip <noreply@paperclip.ing> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
541 lines
17 KiB
TypeScript
541 lines
17 KiB
TypeScript
import express from "express";
|
|
import request from "supertest";
|
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
|
|
const mockInstanceSettingsService = vi.hoisted(() => ({
|
|
get: vi.fn(),
|
|
getGeneral: vi.fn(),
|
|
getExperimental: vi.fn(),
|
|
update: vi.fn(),
|
|
updateGeneral: vi.fn(),
|
|
updateExperimental: vi.fn(),
|
|
listCompanyIds: vi.fn(),
|
|
}));
|
|
const mockHeartbeatService = vi.hoisted(() => ({
|
|
buildIssueGraphLivenessAutoRecoveryPreview: vi.fn(),
|
|
reconcileIssueGraphLiveness: vi.fn(),
|
|
}));
|
|
const mockEnvironmentService = vi.hoisted(() => ({
|
|
getById: vi.fn(),
|
|
}));
|
|
const mockLogActivity = vi.hoisted(() => vi.fn());
|
|
|
|
function registerModuleMocks() {
|
|
vi.doMock("../services/index.js", () => ({
|
|
heartbeatService: () => mockHeartbeatService,
|
|
instanceSettingsService: () => mockInstanceSettingsService,
|
|
logActivity: mockLogActivity,
|
|
}));
|
|
vi.doMock("../services/environments.js", () => ({
|
|
environmentService: () => mockEnvironmentService,
|
|
}));
|
|
}
|
|
|
|
async function createApp(actor: any) {
|
|
const [{ errorHandler }, { instanceSettingsRoutes }] = await Promise.all([
|
|
vi.importActual<typeof import("../middleware/index.js")>("../middleware/index.js"),
|
|
vi.importActual<typeof import("../routes/instance-settings.js")>("../routes/instance-settings.js"),
|
|
]);
|
|
const app = express();
|
|
app.use(express.json());
|
|
app.use((req, _res, next) => {
|
|
req.actor = actor;
|
|
next();
|
|
});
|
|
app.use("/api", instanceSettingsRoutes({} as any));
|
|
app.use(errorHandler);
|
|
return app;
|
|
}
|
|
|
|
describe("instance settings routes", () => {
|
|
beforeEach(() => {
|
|
vi.resetModules();
|
|
vi.doUnmock("../services/index.js");
|
|
vi.doUnmock("../routes/instance-settings.js");
|
|
vi.doUnmock("../routes/authz.js");
|
|
vi.doUnmock("../middleware/index.js");
|
|
registerModuleMocks();
|
|
vi.clearAllMocks();
|
|
mockInstanceSettingsService.get.mockReset();
|
|
mockInstanceSettingsService.getGeneral.mockReset();
|
|
mockInstanceSettingsService.getExperimental.mockReset();
|
|
mockInstanceSettingsService.update.mockReset();
|
|
mockInstanceSettingsService.updateGeneral.mockReset();
|
|
mockInstanceSettingsService.updateExperimental.mockReset();
|
|
mockInstanceSettingsService.listCompanyIds.mockReset();
|
|
mockHeartbeatService.buildIssueGraphLivenessAutoRecoveryPreview.mockReset();
|
|
mockHeartbeatService.reconcileIssueGraphLiveness.mockReset();
|
|
mockEnvironmentService.getById.mockReset();
|
|
mockLogActivity.mockReset();
|
|
mockInstanceSettingsService.get.mockResolvedValue({
|
|
id: "instance-settings-1",
|
|
defaultEnvironmentId: null,
|
|
general: {
|
|
censorUsernameInLogs: false,
|
|
keyboardShortcuts: false,
|
|
feedbackDataSharingPreference: "prompt",
|
|
},
|
|
experimental: {
|
|
enableEnvironments: false,
|
|
enableIsolatedWorkspaces: false,
|
|
enableIssuePlanDecompositions: false,
|
|
enableExperimentalFileViewer: false,
|
|
enableCloudSync: false,
|
|
enableServerInfoDebugView: false,
|
|
autoRestartDevServerWhenIdle: false,
|
|
enableIssueGraphLivenessAutoRecovery: true,
|
|
enableWorkspaceBranchReconcileForward: false,
|
|
issueGraphLivenessAutoRecoveryLookbackHours: 24,
|
|
},
|
|
createdAt: "2026-06-20T00:00:00.000Z",
|
|
updatedAt: "2026-06-20T00:00:00.000Z",
|
|
});
|
|
mockInstanceSettingsService.getGeneral.mockResolvedValue({
|
|
censorUsernameInLogs: false,
|
|
keyboardShortcuts: false,
|
|
feedbackDataSharingPreference: "prompt",
|
|
});
|
|
mockInstanceSettingsService.getExperimental.mockResolvedValue({
|
|
enableEnvironments: false,
|
|
enableIsolatedWorkspaces: false,
|
|
enableIssuePlanDecompositions: false,
|
|
enableExperimentalFileViewer: false,
|
|
enableTaskWatchdogs: false,
|
|
enableCloudSync: false,
|
|
enableExternalObjects: false,
|
|
enableServerInfoDebugView: false,
|
|
autoRestartDevServerWhenIdle: false,
|
|
enableIssueGraphLivenessAutoRecovery: true,
|
|
enableWorkspaceBranchReconcileForward: false,
|
|
issueGraphLivenessAutoRecoveryLookbackHours: 24,
|
|
});
|
|
mockInstanceSettingsService.update.mockResolvedValue({
|
|
id: "instance-settings-1",
|
|
defaultEnvironmentId: "env-1",
|
|
general: {
|
|
censorUsernameInLogs: false,
|
|
keyboardShortcuts: false,
|
|
feedbackDataSharingPreference: "prompt",
|
|
},
|
|
experimental: {
|
|
enableEnvironments: true,
|
|
enableIsolatedWorkspaces: true,
|
|
enableIssuePlanDecompositions: true,
|
|
enableExperimentalFileViewer: true,
|
|
enableCloudSync: true,
|
|
enableServerInfoDebugView: false,
|
|
autoRestartDevServerWhenIdle: false,
|
|
enableIssueGraphLivenessAutoRecovery: true,
|
|
enableWorkspaceBranchReconcileForward: false,
|
|
issueGraphLivenessAutoRecoveryLookbackHours: 24,
|
|
},
|
|
createdAt: "2026-06-20T00:00:00.000Z",
|
|
updatedAt: "2026-06-20T01:00:00.000Z",
|
|
});
|
|
mockInstanceSettingsService.updateGeneral.mockResolvedValue({
|
|
id: "instance-settings-1",
|
|
general: {
|
|
censorUsernameInLogs: true,
|
|
keyboardShortcuts: true,
|
|
feedbackDataSharingPreference: "allowed",
|
|
},
|
|
});
|
|
mockInstanceSettingsService.updateExperimental.mockResolvedValue({
|
|
id: "instance-settings-1",
|
|
experimental: {
|
|
enableEnvironments: true,
|
|
enableIsolatedWorkspaces: true,
|
|
enableIssuePlanDecompositions: true,
|
|
enableExperimentalFileViewer: true,
|
|
enableTaskWatchdogs: true,
|
|
enableCloudSync: true,
|
|
enableExternalObjects: false,
|
|
enableServerInfoDebugView: true,
|
|
autoRestartDevServerWhenIdle: false,
|
|
enableIssueGraphLivenessAutoRecovery: true,
|
|
enableWorkspaceBranchReconcileForward: false,
|
|
issueGraphLivenessAutoRecoveryLookbackHours: 24,
|
|
},
|
|
});
|
|
mockInstanceSettingsService.listCompanyIds.mockResolvedValue(["company-1", "company-2"]);
|
|
mockHeartbeatService.buildIssueGraphLivenessAutoRecoveryPreview.mockResolvedValue({
|
|
lookbackHours: 24,
|
|
cutoff: "2026-04-26T12:00:00.000Z",
|
|
generatedAt: "2026-04-27T12:00:00.000Z",
|
|
findings: 1,
|
|
recoverableFindings: 1,
|
|
skippedOutsideLookback: 0,
|
|
items: [],
|
|
});
|
|
mockHeartbeatService.reconcileIssueGraphLiveness.mockResolvedValue({
|
|
findings: 1,
|
|
autoRecoveryEnabled: true,
|
|
lookbackHours: 24,
|
|
cutoff: "2026-04-26T12:00:00.000Z",
|
|
escalationsCreated: 1,
|
|
existingEscalations: 0,
|
|
skipped: 0,
|
|
skippedAutoRecoveryDisabled: 0,
|
|
skippedOutsideLookback: 0,
|
|
escalationIssueIds: ["issue-2"],
|
|
});
|
|
mockEnvironmentService.getById.mockResolvedValue({
|
|
id: "env-1",
|
|
driver: "local",
|
|
status: "active",
|
|
config: {},
|
|
});
|
|
});
|
|
|
|
it("allows local board users to read and update experimental settings", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
const getRes = await request(app).get("/api/instance/settings/experimental");
|
|
expect(getRes.status).toBe(200);
|
|
expect(getRes.body).toEqual({
|
|
enableEnvironments: false,
|
|
enableIsolatedWorkspaces: false,
|
|
enableIssuePlanDecompositions: false,
|
|
enableExperimentalFileViewer: false,
|
|
enableTaskWatchdogs: false,
|
|
enableCloudSync: false,
|
|
enableExternalObjects: false,
|
|
enableServerInfoDebugView: false,
|
|
autoRestartDevServerWhenIdle: false,
|
|
enableIssueGraphLivenessAutoRecovery: true,
|
|
enableWorkspaceBranchReconcileForward: false,
|
|
issueGraphLivenessAutoRecoveryLookbackHours: 24,
|
|
});
|
|
|
|
const patchRes = await request(app)
|
|
.patch("/api/instance/settings/experimental")
|
|
.send({ enableIsolatedWorkspaces: true });
|
|
|
|
expect(patchRes.status).toBe(200);
|
|
expect(mockInstanceSettingsService.updateExperimental).toHaveBeenCalledWith({
|
|
enableIsolatedWorkspaces: true,
|
|
});
|
|
expect(mockLogActivity).toHaveBeenCalledTimes(2);
|
|
}, 10_000);
|
|
|
|
it("allows local board users to read and update the instance default environment", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
const getRes = await request(app).get("/api/instance/settings");
|
|
expect(getRes.status).toBe(200);
|
|
expect(getRes.body.defaultEnvironmentId).toBeNull();
|
|
|
|
const patchRes = await request(app)
|
|
.patch("/api/instance/settings")
|
|
.send({ defaultEnvironmentId: "11111111-1111-4111-8111-111111111111" });
|
|
|
|
expect(patchRes.status).toBe(200);
|
|
expect(mockInstanceSettingsService.update).toHaveBeenCalledWith({
|
|
defaultEnvironmentId: "11111111-1111-4111-8111-111111111111",
|
|
});
|
|
expect(mockLogActivity).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it("rejects unknown defaultEnvironmentId values with 422", async () => {
|
|
mockEnvironmentService.getById.mockResolvedValue(null);
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
const res = await request(app)
|
|
.patch("/api/instance/settings")
|
|
.send({ defaultEnvironmentId: "11111111-1111-4111-8111-111111111111" });
|
|
|
|
expect(res.status).toBe(422);
|
|
expect(res.body.error).toContain("Environment not found");
|
|
expect(mockInstanceSettingsService.update).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("allows local board users to update guarded dev-server auto-restart", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
await request(app)
|
|
.patch("/api/instance/settings/experimental")
|
|
.send({ autoRestartDevServerWhenIdle: true })
|
|
.expect(200);
|
|
|
|
expect(
|
|
mockInstanceSettingsService.updateExperimental.mock.calls.some(
|
|
([patch]) => patch?.autoRestartDevServerWhenIdle === true,
|
|
),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("allows local board users to update external object detection", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
await request(app)
|
|
.patch("/api/instance/settings/experimental")
|
|
.send({ enableExternalObjects: true })
|
|
.expect(200);
|
|
|
|
expect(mockInstanceSettingsService.updateExperimental).toHaveBeenCalledWith({
|
|
enableExternalObjects: true,
|
|
});
|
|
});
|
|
|
|
it("allows local board users to update the server info debug view", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
await request(app)
|
|
.patch("/api/instance/settings/experimental")
|
|
.send({ enableServerInfoDebugView: true })
|
|
.expect(200);
|
|
|
|
expect(mockInstanceSettingsService.updateExperimental).toHaveBeenCalledWith({
|
|
enableServerInfoDebugView: true,
|
|
});
|
|
});
|
|
|
|
it("allows local board users to update issue graph liveness auto-recovery", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
await request(app)
|
|
.patch("/api/instance/settings/experimental")
|
|
.send({
|
|
enableIssueGraphLivenessAutoRecovery: true,
|
|
issueGraphLivenessAutoRecoveryLookbackHours: 12,
|
|
})
|
|
.expect(200);
|
|
|
|
expect(mockInstanceSettingsService.updateExperimental).toHaveBeenCalledWith({
|
|
enableIssueGraphLivenessAutoRecovery: true,
|
|
issueGraphLivenessAutoRecoveryLookbackHours: 12,
|
|
});
|
|
});
|
|
|
|
it("previews issue graph liveness recovery candidates before enabling", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
const res = await request(app)
|
|
.post("/api/instance/settings/experimental/issue-graph-liveness-auto-recovery/preview")
|
|
.send({ lookbackHours: 12 })
|
|
.expect(200);
|
|
|
|
expect(res.body).toMatchObject({ lookbackHours: 24, recoverableFindings: 1 });
|
|
expect(mockHeartbeatService.buildIssueGraphLivenessAutoRecoveryPreview).toHaveBeenCalledWith({
|
|
lookbackHours: 12,
|
|
});
|
|
});
|
|
|
|
it("kicks off issue graph liveness recovery on demand", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
await request(app)
|
|
.post("/api/instance/settings/experimental/issue-graph-liveness-auto-recovery/run")
|
|
.send({ lookbackHours: 12 })
|
|
.expect(200);
|
|
|
|
expect(mockHeartbeatService.reconcileIssueGraphLiveness).toHaveBeenCalledWith({
|
|
runId: null,
|
|
force: true,
|
|
lookbackHours: 12,
|
|
});
|
|
expect(mockLogActivity).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it("allows local board users to update environment controls", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
await request(app)
|
|
.patch("/api/instance/settings/experimental")
|
|
.send({ enableEnvironments: true })
|
|
.expect(200);
|
|
|
|
expect(mockInstanceSettingsService.updateExperimental).toHaveBeenCalledWith({
|
|
enableEnvironments: true,
|
|
});
|
|
});
|
|
|
|
it("allows local board users to update task watchdog controls", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
await request(app)
|
|
.patch("/api/instance/settings/experimental")
|
|
.send({ enableTaskWatchdogs: true })
|
|
.expect(200);
|
|
|
|
expect(mockInstanceSettingsService.updateExperimental).toHaveBeenCalledWith({
|
|
enableTaskWatchdogs: true,
|
|
});
|
|
});
|
|
|
|
it("allows non-admin board users with company access to read but not update experimental settings", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "user-1",
|
|
source: "session",
|
|
isInstanceAdmin: false,
|
|
companyIds: ["company-1"],
|
|
});
|
|
|
|
await request(app).get("/api/instance/settings/experimental").expect(200);
|
|
|
|
await request(app)
|
|
.patch("/api/instance/settings/experimental")
|
|
.send({ enableTaskWatchdogs: true })
|
|
.expect(403);
|
|
|
|
expect(mockInstanceSettingsService.updateExperimental).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("allows local board users to read and update general settings", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "local-board",
|
|
source: "local_implicit",
|
|
isInstanceAdmin: true,
|
|
});
|
|
|
|
const getRes = await request(app).get("/api/instance/settings/general");
|
|
expect(getRes.status).toBe(200);
|
|
expect(getRes.body).toEqual({
|
|
censorUsernameInLogs: false,
|
|
keyboardShortcuts: false,
|
|
feedbackDataSharingPreference: "prompt",
|
|
});
|
|
|
|
const patchRes = await request(app)
|
|
.patch("/api/instance/settings/general")
|
|
.send({
|
|
censorUsernameInLogs: true,
|
|
keyboardShortcuts: true,
|
|
feedbackDataSharingPreference: "allowed",
|
|
});
|
|
|
|
expect(patchRes.status).toBe(200);
|
|
expect(mockInstanceSettingsService.updateGeneral).toHaveBeenCalledWith({
|
|
censorUsernameInLogs: true,
|
|
keyboardShortcuts: true,
|
|
feedbackDataSharingPreference: "allowed",
|
|
});
|
|
expect(mockLogActivity).toHaveBeenCalledTimes(2);
|
|
});
|
|
|
|
it("allows non-admin board users to read general settings", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "user-1",
|
|
source: "session",
|
|
isInstanceAdmin: false,
|
|
companyIds: ["company-1"],
|
|
});
|
|
|
|
const res = await request(app).get("/api/instance/settings/general");
|
|
|
|
expect(res.status).toBe(200);
|
|
expect(res.body).toEqual({
|
|
censorUsernameInLogs: false,
|
|
keyboardShortcuts: false,
|
|
feedbackDataSharingPreference: "prompt",
|
|
});
|
|
});
|
|
|
|
it("rejects signed-in users without company access from reading general settings", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "user-2",
|
|
source: "session",
|
|
isInstanceAdmin: false,
|
|
companyIds: [],
|
|
memberships: [],
|
|
});
|
|
|
|
const res = await request(app).get("/api/instance/settings/general");
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(mockInstanceSettingsService.getGeneral).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("rejects non-admin board users from updating general settings", async () => {
|
|
const app = await createApp({
|
|
type: "board",
|
|
userId: "user-1",
|
|
source: "session",
|
|
isInstanceAdmin: false,
|
|
companyIds: ["company-1"],
|
|
});
|
|
|
|
const res = await request(app)
|
|
.patch("/api/instance/settings/general")
|
|
.send({ censorUsernameInLogs: true, keyboardShortcuts: true });
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(mockInstanceSettingsService.updateGeneral).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("rejects agent callers", async () => {
|
|
const app = await createApp({
|
|
type: "agent",
|
|
agentId: "agent-1",
|
|
companyId: "company-1",
|
|
source: "agent_key",
|
|
});
|
|
|
|
const res = await request(app)
|
|
.patch("/api/instance/settings/general")
|
|
.send({ feedbackDataSharingPreference: "not_allowed" });
|
|
|
|
expect(res.status).toBe(403);
|
|
expect(mockInstanceSettingsService.updateGeneral).not.toHaveBeenCalled();
|
|
});
|
|
});
|