Files
PaperClipAI/ui/src/pages/Secrets.test.ts
T
Dotta 1a57a2abec refactor(ui): prune 36 thin mocked jsdom UI tests and consolidate replay masking checks (#22834)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The `@paperclipai/ui` Vitest suite includes 182 component/page test
files, many of which boot full jsdom and React module graphs with 6–19
mocks solely to verify wiring that Playwright E2E specs already exercise
end-to-end.
> - Auth, security, permission, privacy, error-boundary, pure-logic
`ui/src/lib` / `ui/src/hooks` / `ui/src/api` suites, and complex
interactive client logic must stay intact.
> - This pull request removes 36 thin
mocked/E2E-duplicated/synthetic-perf jsdom component/page test files
(-17,367 LOC), consolidates 7 tiny single-purpose session-replay privacy
tests into `ui/src/lib/analytics/replay-masking.test.tsx` with 100% of
assertions preserved, converts 2 pure-logic suites from `jsdom` to
`node`, and updates affected feature/agent-access map references plus
`.github/workflows/ci-incremental-qualification.yml`.
> - The benefit is cutting full `@paperclipai/ui` suite execution to
~36s locally (~42s fewer raw test seconds and 42 fewer jsdom boots)
while preserving 100% of auth, permission, privacy, and pure-logic
coverage.

## Linked Issues or Issue Description

Refs #22804

**What existing behavior does this improve?**
UI Vitest runtime, signal-to-noise ratio, and jsdom boot overhead in
`ui/src/`.

**Subsystem affected**
ui/ — React + Vite board UI

**Current behavior**
36 thin mocked/E2E-duplicated/synthetic-perf jsdom component/page tests
and 7 tiny single-purpose session-replay privacy files pay full
jsdom+React boot overhead on every UI PR despite duplicate Playwright
E2E and pure-logic coverage.

**Proposed behavior**
Remove the 36 thin mocked/E2E-duplicated jsdom suites, consolidate the 7
session-replay privacy suites into
`ui/src/lib/analytics/replay-masking.test.tsx`, convert 2 pure-logic
suites to `node`, and keep all maps and incremental qualification checks
aligned.

## What Changed

- **Deleted 36 thin mocked / E2E-duplicated / synthetic-perf jsdom
suites (`-17,367 LOC`):**
- Mocked chat-adapter setup & banner wiring (4 files), heavily mocked
`Inbox.test.tsx` shell (1 file, 19 mocks; pure logic in
`ui/src/lib/inbox.test.ts` and browser E2E retained), synthetic jsdom
microbenchmarks & mocked app/browse/connector wiring (9 files), mocked
AI-connection & agent-config wiring (6 files), and thin
presentational/mocked component wiring (16 files).
- **Consolidated 7 tiny session-replay privacy tests into
`ui/src/lib/analytics/replay-masking.test.tsx` (498 LOC, 100% of
assertions preserved):** `AccountQuotaPanels`, `WebhookFields`,
`AiConnectionPicker`, `AiConnectionAccountControls`,
`AiConnectionIdentity`, `AiConnectionPoolRunDetails`, and
`AgentSetupPrompt`.
- **Converted 2 pure-logic suites from `jsdom` to `node` (0 assertions
lost):** `ui/src/pages/Secrets.test.ts` and
`ui/src/pages/tools/ProfilesTab.test.ts`.
- **Retained 100% of high-signal UI coverage:** all 276 `ui/src/lib`, 56
`ui/src/hooks`, 19 `ui/src/context`, 26 `ui/src/api`, 14
`ui/src/adapters`, 6 `ui/src/plugins`, all 94 pure-logic `node`
component/page tests, and all
auth/security/permission/privacy/error-boundary/complex-interactive
suites.
- **Updated references:** updated the 7 affected `maps/` files to
reference current canonical suites and updated
`.github/workflows/ci-incremental-qualification.yml`
(`ui/src/pages/Inbox.tsx → Inbox.test.tsx` to `ui/src/pages/Auth.tsx →
Auth.test.tsx`).

## Verification

- `pnpm exec vitest run --project @paperclipai/ui` — **557/557 files,
6,916 passed | 1 skipped (`36.14s`)**
- `pnpm --filter @paperclipai/ui typecheck` — **PASS (0 errors)**
- `node scripts/storybook-catalog.mjs` — **PASS (371 files, 3,480
stories)**
- `node scripts/check-maps.mjs` — **PASS (35 areas, 192 capability
IDs)**
- `node scripts/check-query-error-rendering.mjs` — **PASS (0 findings)**
- `node scripts/check-test-budget.mjs --base origin/master` — **PASS
(588 nightly suites validated)**
- Verified `.github/workflows/ci-incremental-qualification.yml`
`qualify_test_selection` check locally (`Auth.tsx → Auth.test.tsx`) —
**PASS**

## Risks

- Low risk: zero production UI code changed; all auth, permission,
privacy, replay-masking, error-boundary, pure-logic, and Playwright E2E
behavioral checks remain intact.

## Model Used

- Google Gemini (Antigravity agent swarm) with extended reasoning, tool
use, and local test execution (`e2e-opt`, `verifier`, `ci-pipeline`).

## 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
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-11-24 16:49:28 -06:00

314 lines
9.8 KiB
TypeScript

import { describe, expect, it } from "vitest";
import type { CompanySecretProviderConfig, SecretProviderDescriptor } from "@paperclipai/shared";
import {
buildCreateVaultOptions,
findCreateProviderReplacement,
getAwsManagedPathPreview,
getCreateProviderBlockReason,
getDefaultProviderConfigId,
getProviderConfigBlockReason,
parseEnvAssignment,
} from "./Secrets";
import type { SecretProviderHealthResponse } from "../api/secrets";
const awsProvider: SecretProviderDescriptor = {
id: "aws_secrets_manager",
label: "AWS Secrets Manager",
requiresExternalRef: false,
supportsManagedValues: true,
supportsExternalReferences: true,
configured: true,
};
const localProvider: SecretProviderDescriptor = {
id: "local_encrypted",
label: "Local encrypted (default)",
requiresExternalRef: false,
supportsManagedValues: true,
supportsExternalReferences: false,
configured: true,
};
function providerConfig(
overrides: Partial<CompanySecretProviderConfig> & Pick<CompanySecretProviderConfig, "id" | "provider">,
): CompanySecretProviderConfig {
return {
companyId: "company-1",
displayName: overrides.id,
status: "ready",
isDefault: false,
config: {},
healthStatus: null,
healthCheckedAt: null,
healthMessage: null,
healthDetails: null,
disabledAt: null,
createdByAgentId: null,
createdByUserId: null,
createdAt: new Date("2026-01-01T00:00:00Z"),
updatedAt: new Date("2026-01-01T00:00:00Z"),
...overrides,
};
}
describe("Secrets page provider helpers", () => {
it("previews the derived AWS managed path from provider health details", () => {
const health: SecretProviderHealthResponse = {
providers: [
{
provider: "aws_secrets_manager",
status: "ok",
message: "AWS Secrets Manager provider is configured",
details: {
prefix: "paperclip",
deploymentId: "prod-us-1",
},
},
],
};
expect(
getAwsManagedPathPreview({
provider: awsProvider,
health,
companyId: "company-123",
secretKeySource: "Anthropic API Key",
}),
).toBe("paperclip/prod-us-1/company-123/anthropic-api-key");
});
it("blocks unconfigured providers before create submission", () => {
expect(
getCreateProviderBlockReason(
{ ...awsProvider, configured: false },
"managed",
null,
),
).toBe(
"AWS Secrets Manager is not set up on this Paperclip server. Choose a vault that is ready, or ask your administrator to set it up.",
);
});
it("uses provider health copy when an unconfigured provider reports missing bootstrap inputs", () => {
const health: SecretProviderHealthResponse = {
providers: [
{
provider: "aws_secrets_manager",
status: "warn",
message:
"AWS Secrets Manager provider is not ready: missing PAPERCLIP_SECRETS_AWS_DEPLOYMENT_ID.",
},
],
};
expect(
getCreateProviderBlockReason(
{ ...awsProvider, configured: false },
"managed",
health,
),
).toBe(
"AWS Secrets Manager is not set up on this Paperclip server. Choose a vault that is ready, or ask your administrator to set it up. AWS Secrets Manager provider is not ready: missing PAPERCLIP_SECRETS_AWS_DEPLOYMENT_ID.",
);
});
it("allows an unconfigured AWS deployment default when a ready AWS provider vault is selected", () => {
expect(
getCreateProviderBlockReason(
{ ...awsProvider, configured: false },
"external",
null,
providerConfig({
id: "aws-prod",
provider: "aws_secrets_manager",
displayName: "AWS prod",
status: "ready",
}),
),
).toBeNull();
});
it("names the selected provider vault block before deployment-default AWS config", () => {
expect(
getCreateProviderBlockReason(
{ ...awsProvider, configured: false },
"external",
null,
providerConfig({
id: "aws-disabled",
provider: "aws_secrets_manager",
displayName: "AWS disabled",
status: "disabled",
}),
),
).toBe("This vault is disabled.");
});
it("blocks provider modes the backend does not support", () => {
expect(
getCreateProviderBlockReason(
localProvider,
"external",
null,
),
).toBe("Local encrypted (default) does not support linked external references.");
});
it("switching to external mode prefers AWS instead of staying on local encrypted when a ready AWS vault exists", () => {
expect(
findCreateProviderReplacement({
providers: [localProvider, { ...awsProvider, configured: false }],
providerConfigs: [
providerConfig({
id: "aws-prod",
provider: "aws_secrets_manager",
displayName: "AWS prod",
status: "ready",
isDefault: true,
}),
],
currentProvider: "local_encrypted",
mode: "external",
health: null,
})?.id,
).toBe("aws_secrets_manager");
});
it("chooses the ready default provider vault for a provider", () => {
expect(
getDefaultProviderConfigId(
[
{
id: "draft",
provider: "aws_secrets_manager",
status: "disabled",
isDefault: true,
},
{
id: "prod",
provider: "aws_secrets_manager",
status: "ready",
isDefault: true,
},
] as never,
"aws_secrets_manager",
),
).toBe("prod");
});
it("explains why coming-soon provider vaults cannot be selected", () => {
expect(
getProviderConfigBlockReason({
id: "vault-draft",
provider: "vault",
status: "coming_soon",
} as never),
).toBe("Paperclip can't store or read secrets in this vault yet.");
});
it("falls back to a plain sentence when an unhealthy vault reports no message", () => {
expect(
getProviderConfigBlockReason(
providerConfig({ id: "aws-down", provider: "aws_secrets_manager", healthStatus: "error" }),
),
).toBe("Paperclip couldn't reach this vault.");
});
});
describe("buildCreateVaultOptions", () => {
const build = (
overrides: Partial<Parameters<typeof buildCreateVaultOptions>[0]> = {},
) =>
buildCreateVaultOptions({
providers: [localProvider, awsProvider],
providerConfigs: [],
mode: "managed",
health: null,
...overrides,
});
it("offers only Paperclip's own storage when nothing else is set up", () => {
expect(build({ providers: [localProvider, { ...awsProvider, configured: false }] })).toEqual([
{
value: "local_encrypted:",
provider: "local_encrypted",
providerConfigId: "",
label: "Paperclip (default)",
blockReason: null,
},
]);
});
it("offers a provider's connected vaults in place of its built-in storage", () => {
const options = build({
providerConfigs: [
providerConfig({ id: "team", provider: "local_encrypted", displayName: "Team vault" }),
providerConfig({ id: "aws-prod", provider: "aws_secrets_manager", displayName: "prod-us-east", isDefault: true }),
],
});
expect(options.map((option) => option.label)).toEqual([
"Team vault · Paperclip-encrypted (default)",
"prod-us-east · AWS Secrets Manager",
]);
expect(options.map((option) => option.value)).toEqual([
"local_encrypted:team",
"aws_secrets_manager:aws-prod",
]);
expect(options.every((option) => option.blockReason === null)).toBe(true);
});
it("keeps an unhealthy vault in the list with its reason and drops disabled and coming-soon ones", () => {
const options = build({
providers: [localProvider, { ...awsProvider, configured: false }],
providerConfigs: [
providerConfig({
id: "aws-down",
provider: "aws_secrets_manager",
displayName: "staging-eu",
healthStatus: "error",
healthMessage: "AWS denied access.",
}),
providerConfig({ id: "aws-off", provider: "aws_secrets_manager", status: "disabled" }),
providerConfig({ id: "aws-draft", provider: "aws_secrets_manager", status: "coming_soon" }),
],
});
expect(options.map((option) => option.value)).toEqual(["local_encrypted:", "aws_secrets_manager:aws-down"]);
expect(options[1].blockReason).toBe("AWS denied access.");
});
it("marks Paperclip's own storage as blocked for linking instead of hiding it", () => {
const options = build({ mode: "external" });
expect(options[0]).toMatchObject({
value: "local_encrypted:",
blockReason: "Local encrypted (default) does not support linked external references.",
});
expect(options[1]).toMatchObject({ value: "aws_secrets_manager:", blockReason: null });
});
});
describe("parseEnvAssignment", () => {
it("splits NAME=value, with or without export and quotes", () => {
expect(parseEnvAssignment("GITHUB_TOKEN=ghp_abc")).toEqual({ name: "GITHUB_TOKEN", value: "ghp_abc" });
expect(parseEnvAssignment(' export LINEAR_API_KEY="lin_api_1" ')).toEqual({
name: "LINEAR_API_KEY",
value: "lin_api_1",
});
expect(parseEnvAssignment("DATABASE_URL='postgres://u:p@host/db?sslmode=require'")).toEqual({
name: "DATABASE_URL",
value: "postgres://u:p@host/db?sslmode=require",
});
});
it("leaves anything that is not a single assignment alone", () => {
expect(parseEnvAssignment("ghp_abc")).toBeNull();
expect(parseEnvAssignment("A=1\nB=2")).toBeNull();
expect(parseEnvAssignment("1BAD=value")).toBeNull();
expect(parseEnvAssignment("EMPTY=")).toBeNull();
expect(parseEnvAssignment('EMPTY=""')).toBeNull();
});
});