Files
PaperClipAI/server/src/services/heartbeat-run-runtime-status.test.ts
T
Devin Foley adfbe2d4b9 feat(environments): refer to the managed default environment by name, not the sandbox driver key (#11838)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Managed deployments provision a platform-managed default environment
for agent runs; the UI shows this environment in selectors, the agent
form, run details, and the environments page
> - Those surfaces append the raw driver key to the environment name, so
users see labels like "Paperclip Computer (sandbox)", "Paperclip
Computer · sandbox", and fallback copy such as "Managed sandbox" and
"The sandbox has no ready authentication"
> - "sandbox" is infrastructure vocabulary, not the product name of the
environment; showing it next to the managed environment's name is
confusing and off-brand
> - This pull request renders platform-managed environments by name
alone and rewords the sandbox-phrased copy, while user-created
environments keep the driver suffix so mixed lists stay distinguishable
> - The benefit is that the default environment reads as one clear
product name everywhere, and self-hosted users lose nothing: their own
environments still show the driver

## Linked Issues or Issue Description

**What existing behavior does this improve?**

Display of the platform-managed default environment across the UI.

**Subsystem affected**

UI (environment selectors, agent config form, environments page, agents
page, run details) and the claude-local/codex-local adapter auth checks.

**Current behavior**

The agent form labels the inherited default environment as "Name
(sandbox)". Environment selectors and the environments list render "Name
· sandbox". The agents page describes the environment as "<provider>
sandbox provider". The agent form's fallback label is "Managed sandbox".
Adapter auth checks say "The sandbox has no ready authentication for
this adapter."

**Proposed behavior**

Platform-managed environment rows (`metadata.managedByPaperclip`) render
their name alone. The fallback label is "Paperclip Computer". The agents
page describes managed environments as "Managed by Paperclip". Run
details omit the driver suffix for sandbox-driver environments (the
adjacent Provider entry already identifies the mechanism). Adapter auth
checks say "This environment has no ready authentication for this
adapter."

**Reason and benefit**

The managed environment carries a product name. Appending the raw driver
key ("sandbox") to it is noise and contradicts the product naming.
User-created environments keep the driver suffix, so mixed lists stay
distinguishable.

**Breaking changes**

None. Message text of the auth check is not read programmatically; the
UI keys off `ADAPTER_AUTH_MISSING_CHECK_CODE`. Rows without the managed
marker render exactly as before.

## What Changed

- New `environmentDisplayLabel` helper in
`ui/src/lib/managed-sandbox-environment.ts`: managed rows → name alone;
other rows → "Name · driver".
- `AgentConfigForm`: inherited-default label uses the helper; fallback
copy "Managed sandbox" → "Paperclip Computer"; environment options use
the helper.
- `ProjectProperties`, `CompanyEnvironments`: environment selector
options use the helper; the environments-list row hides the driver
suffix on managed rows; the managed detail page's fallback description
no longer says "sandbox".
- `Agents` page: managed environments are described as "Managed by
Paperclip" instead of "<provider> sandbox provider".
- `CommentThread` run details: the driver suffix is omitted for
sandbox-driver environments.
- claude-local and codex-local adapters: auth-missing check message/hint
reworded from "sandbox" to "environment" (ACP and environment-test
paths); claude-local probe/effort/login hints reworded the same way.
- Run status lines: "Syncing workspace to sandbox", "Exporting git
changes from sandbox", "Starting adapter in sandbox", and friends now
say "environment"; "Finalizing sandbox workspace" → "Finalizing
workspace". Templated transfer-progress lines map the `sandbox`
transport key to "environment" for display (`runtime-progress.ts`).
- Agent form sign-in panel: "Sign in to the sandbox" → "Sign in to the
environment"; "Authenticated. The sandbox has credentials now." → "…The
environment has credentials now."
- Feature catalog + instance settings card: "Managed Sandbox Only" →
"Managed Environment Only" (setting key unchanged; the card keeps its
alphabetical slot).
- Server agents routes: execution-target failure and test-identity copy
no longer say "sandbox"; workspace-mode label "Cloud sandbox" → "Cloud
environment".
- Tests: new `environmentDisplayLabel` unit cases; new `AgentConfigForm`
render case asserting the managed default renders without "(sandbox)" or
"· sandbox"; status-line assertions updated across adapter-utils, server
heartbeat/live-run, and UI chat suites.

## Verification

- `pnpm --filter @paperclipai/ui typecheck` — clean.
- `pnpm --filter @paperclipai/adapter-claude-local typecheck` and
`--filter @paperclipai/adapter-codex-local typecheck` — clean.
- `vitest run` for `managed-sandbox-environment.test.ts`,
`AgentConfigForm.render.test.tsx`, `CompanyEnvironments.test.tsx`,
`Agents.test.tsx`, `CommentThread.test.tsx`, `NewAgent.test.tsx` — all
green (118 tests across the two runs).

## Risks

Low risk. Cosmetic label changes only; no data or API changes. Rows
without `metadata.managedByPaperclip` render exactly as before, so
self-hosted deployments with their own environments see no change. The
only self-hosted-visible wording changes are the adapter auth-check
message and the driver suffix omission on sandbox-driver rows in run
details.

## Model Used

- Claude (Anthropic) — claude-fable-5 (Claude Fable 5), Claude Code CLI,
extended thinking, tool use.

## 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 (no
docs reference these labels)
- [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
- [x] I will address all Greptile and reviewer comments before
requesting merge
2026-08-21 12:51:22 -07:00

195 lines
6.5 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import {
clearAllHeartbeatRunRuntimeStatuses,
clearHeartbeatRunRuntimeStatus,
getHeartbeatRunRuntimeStatus,
MAX_HEARTBEAT_RUN_RUNTIME_STATUS_MESSAGE_CHARS,
setHeartbeatRunRuntimeStatus,
sweepExpiredHeartbeatRunRuntimeStatuses,
touchHeartbeatRunRuntimeStatus,
} from "./heartbeat-run-runtime-status.js";
describe("heartbeat run runtime status store", () => {
afterEach(() => {
clearAllHeartbeatRunRuntimeStatuses();
});
it("stores scoped ephemeral status and expires stale entries", () => {
const updatedAt = new Date("2026-06-24T00:00:00.000Z");
const status = setHeartbeatRunRuntimeStatus({
companyId: "company-1",
issueId: "issue-1",
agentId: "agent-1",
runId: "run-1",
phase: "config_sync",
message: `Syncing workspace with apiKey: "sk-test-secret" ${"x".repeat(300)}`,
currentToolName: `bash apiKey: "sk-tool-secret" ${"x".repeat(120)}`,
lastAssistantSnippet: `Reading apiKey: "sk-snippet-secret" ${"x".repeat(300)}`,
lastEventAt: new Date("2026-06-24T00:00:05.000Z"),
updatedAt,
});
expect(status?.message).toContain("***REDACTED***");
expect(status?.message.length).toBeLessThanOrEqual(MAX_HEARTBEAT_RUN_RUNTIME_STATUS_MESSAGE_CHARS);
expect(status?.currentToolName).toContain("***REDACTED***");
expect(status?.lastAssistantSnippet).toContain("***REDACTED***");
expect(status?.lastEventAt).toEqual(new Date("2026-06-24T00:00:05.000Z"));
expect(getHeartbeatRunRuntimeStatus("run-1", {
companyId: "company-1",
issueId: "issue-1",
agentId: "agent-1",
now: new Date("2026-06-24T00:00:30.000Z"),
})).toMatchObject({
companyId: "company-1",
issueId: "issue-1",
agentId: "agent-1",
runId: "run-1",
phase: "config_sync",
currentToolName: expect.stringContaining("***REDACTED***"),
lastAssistantSnippet: expect.stringContaining("***REDACTED***"),
lastEventAt: new Date("2026-06-24T00:00:05.000Z"),
});
expect(getHeartbeatRunRuntimeStatus("run-1", { companyId: "other-company" })).toBeNull();
expect(getHeartbeatRunRuntimeStatus("run-1", {
companyId: "company-1",
now: new Date("2026-06-24T00:02:00.001Z"),
})).toBeNull();
expect(getHeartbeatRunRuntimeStatus("run-1")).toBeNull();
});
it("clears status explicitly", () => {
setHeartbeatRunRuntimeStatus({
companyId: "company-1",
issueId: null,
agentId: "agent-1",
runId: "run-1",
phase: "finalize",
message: "Finalizing workspace",
});
expect(clearHeartbeatRunRuntimeStatus("run-1")).toBe(true);
expect(getHeartbeatRunRuntimeStatus("run-1")).toBeNull();
});
it("touch refreshes timestamps while preserving the existing status context", () => {
setHeartbeatRunRuntimeStatus({
companyId: "company-1",
issueId: "issue-1",
agentId: "agent-1",
runId: "run-1",
phase: "run_activity",
message: "Using Bash",
currentToolName: "Bash",
lastAssistantSnippet: "Running the tests",
updatedAt: new Date("2026-06-24T00:00:00.000Z"),
lastEventAt: new Date("2026-06-24T00:00:00.000Z"),
});
const touched = touchHeartbeatRunRuntimeStatus({
companyId: "company-1",
issueId: "issue-1",
agentId: "agent-1",
runId: "run-1",
at: new Date("2026-06-24T00:00:45.000Z"),
});
expect(touched).toMatchObject({
runId: "run-1",
phase: "run_activity",
message: "Using Bash",
currentToolName: "Bash",
lastAssistantSnippet: "Running the tests",
updatedAt: new Date("2026-06-24T00:00:45.000Z"),
lastEventAt: new Date("2026-06-24T00:00:45.000Z"),
});
expect(getHeartbeatRunRuntimeStatus("run-1", {
companyId: "company-1",
now: new Date("2026-06-24T00:02:00.000Z"),
})).toMatchObject({ message: "Using Bash" });
});
it("touch does not move timestamps backwards", () => {
setHeartbeatRunRuntimeStatus({
companyId: "company-1",
issueId: null,
agentId: "agent-1",
runId: "run-1",
phase: "run_activity",
message: "Using Bash",
updatedAt: new Date("2026-06-24T00:01:00.000Z"),
lastEventAt: new Date("2026-06-24T00:01:00.000Z"),
});
const touched = touchHeartbeatRunRuntimeStatus({
companyId: "company-1",
issueId: null,
agentId: "agent-1",
runId: "run-1",
at: new Date("2026-06-24T00:00:30.000Z"),
});
expect(touched).toMatchObject({
updatedAt: new Date("2026-06-24T00:01:00.000Z"),
lastEventAt: new Date("2026-06-24T00:01:00.000Z"),
});
});
it("touch creates a fallback run_activity status when none is live", () => {
const created = touchHeartbeatRunRuntimeStatus({
companyId: "company-1",
issueId: "issue-1",
agentId: "agent-1",
runId: "run-1",
at: new Date("2026-06-24T00:00:00.000Z"),
});
expect(created).toMatchObject({
runId: "run-1",
phase: "run_activity",
message: "Receiving agent output",
updatedAt: new Date("2026-06-24T00:00:00.000Z"),
lastEventAt: new Date("2026-06-24T00:00:00.000Z"),
});
// An expired entry is replaced with a fresh fallback rather than revived.
const expiredTouch = touchHeartbeatRunRuntimeStatus({
companyId: "company-1",
issueId: "issue-1",
agentId: "agent-1",
runId: "run-1",
at: new Date("2026-06-24T00:05:00.000Z"),
});
expect(expiredTouch).toMatchObject({
phase: "run_activity",
message: "Receiving agent output",
updatedAt: new Date("2026-06-24T00:05:00.000Z"),
});
});
it("sweeps expired statuses without touching fresh entries", () => {
setHeartbeatRunRuntimeStatus({
companyId: "company-1",
issueId: null,
agentId: "agent-1",
runId: "stale-run",
phase: "git_sync",
message: "Syncing stale workspace",
updatedAt: new Date("2026-06-24T00:00:00.000Z"),
});
setHeartbeatRunRuntimeStatus({
companyId: "company-1",
issueId: null,
agentId: "agent-1",
runId: "fresh-run",
phase: "git_sync",
message: "Syncing fresh workspace",
updatedAt: new Date("2026-06-24T00:01:00.000Z"),
});
const now = new Date("2026-06-24T00:01:31.000Z");
expect(sweepExpiredHeartbeatRunRuntimeStatuses(now)).toBe(1);
expect(getHeartbeatRunRuntimeStatus("stale-run")).toBeNull();
expect(getHeartbeatRunRuntimeStatus("fresh-run", { now })).toMatchObject({ runId: "fresh-run" });
});
});