feat(cloud): SECRETS-EFFECTIVE-SHARED in the agent host panel, missing-secrets ask and secret request card (no Personal in shared workspaces)

This commit is contained in:
Neil
2026-11-12 23:04:00 -08:00
parent a065360a31
commit be58dc0f02
20 changed files with 383 additions and 66 deletions
@@ -22,7 +22,6 @@ import {
type ShadowedKey
} from './cloud-panel-sections-model'
import {
isGuestInSharedWorkspace,
type CloudPanelAddSecret,
type CloudPanelSectionsLoad
} from './use-cloud-panel-sections'
@@ -253,19 +252,11 @@ export function CloudEnvironmentPanelSection({
number={number}
title={t('agentHostPanel.section.env', 'Environment')}
help={
data && isGuestInSharedWorkspace(data)
? `${t('agentHostPanel.help.cloudEnv', 'From Cloud secrets: Repository, then Personal, then Shared.')} ${
data.sharing?.ownerName
? t(
'agentHostPanel.env.guestOwner',
'In a shared workspace, Personal values come from its owner, {{owner}}, not from you.',
{ owner: data.sharing.ownerName }
)
: t(
'agentHostPanel.env.guest',
'In a shared workspace, Personal values come from its owner, not from you.'
)
}`
data?.withoutPersonal
? `${t('agentHostPanel.help.cloudEnv', 'From Cloud secrets: Repository, then Personal, then Shared.')} ${t(
'agentHostPanel.env.sharedNoPersonal',
'A shared workspace gets nobody’s Personal values, not even its owner’s, so only Repository and Shared apply.'
)}`
: t(
'agentHostPanel.help.cloudEnv',
'From Cloud secrets: Repository, then Personal, then Shared.'
@@ -97,7 +97,7 @@ describe('shared workspaces (D13)', () => {
])
})
it('applies only to a teammate who is not the owner', () => {
it('applies in every shared workspace, the owner’s too (SEC-5), and never in an unshared one', () => {
const declared = ['NPM_TOKEN', 'SENTRY_DSN', 'DATABASE_URL']
const base = { effective: values, envVarNames: declared, repoKey: null, asleep: false }
expect(
@@ -106,8 +106,14 @@ describe('shared workspaces (D13)', () => {
sharing: { shared: true, ownerName: 'Ada', isOwner: false }
}).missing
).toEqual(['NPM_TOKEN'])
const owner = cloudPanelSectionsData({
...base,
sharing: { shared: true, ownerName: null, isOwner: true }
})
expect(owner.withoutPersonal).toBe(true)
expect(owner.missing).toEqual(['NPM_TOKEN'])
expect(
cloudPanelSectionsData({ ...base, sharing: { shared: true, ownerName: null, isOwner: true } })
cloudPanelSectionsData({ ...base, sharing: { shared: false, ownerName: null, isOwner: true } })
.missing
).toEqual([])
})
@@ -24,17 +24,12 @@ export type CloudPanelSectionsData = {
/** Shared with teammates (D13), and whose workspace it is; null when unknown. */
sharing: CloudWorkspaceSharing | null
/**
* The caller's Personal values are left out: a teammate in a shared workspace, or a workspace whose
* sharing couldn't be read (D13 fails closed: it may be someone else's shared workspace).
* Personal values are left out: a shared workspace gets nobody's Personal secrets, not even its
* owner's (SEC-5), and one whose sharing couldn't be read fails closed the same way (D13).
*/
withoutPersonal: boolean
}
/** A teammate's view of someone else's shared workspace: only their non-Personal values apply. */
export function isGuestInSharedWorkspace(data: Pick<CloudPanelSectionsData, 'sharing'>): boolean {
return data.sharing !== null && data.sharing.shared && !data.sharing.isOwner
}
export function cloudPanelSectionsData(args: {
effective: CloudSecretsEffective
envVarNames: readonly string[] | null
@@ -44,7 +39,7 @@ export function cloudPanelSectionsData(args: {
/** The workspace's sharing read failed; treat it as possibly someone else's shared workspace. */
sharingUnknown?: boolean
}): CloudPanelSectionsData {
const withoutPersonal = args.sharingUnknown === true || isGuestInSharedWorkspace(args)
const withoutPersonal = args.sharingUnknown === true || args.sharing?.shared === true
const effective = withoutPersonal ? withoutCallerPersonal(args.effective) : args.effective
return {
withoutPersonal,
@@ -88,12 +83,22 @@ export function useCloudPanelSections(args: {
}
let cancelled = false
void (async () => {
const [effective, list, sharing] = await Promise.all([
secrets.effective(repoKey ? { repo: repoKey } : {}).catch(() => null),
window.api.orcaCloudEnvironments?.list().catch(() => null) ?? Promise.resolve(null),
runtimeEnvironmentId
? secrets.workspaceSharing({ runtimeEnvironmentId }).catch(() => null)
: Promise.resolve(null)
const listing =
window.api.orcaCloudEnvironments?.list().catch(() => null) ?? Promise.resolve(null)
const sharing = runtimeEnvironmentId
? await secrets.workspaceSharing({ runtimeEnvironmentId }).catch(() => null)
: null
// SEC-5: a shared workspace (or one whose sharing can't be read) gets no Personal values, so ask
// the control plane for exactly what such a workspace receives.
const shared = runtimeEnvironmentId !== null && !(sharing?.ok && !sharing.value.shared)
const [effective, list] = await Promise.all([
secrets
.effective({
...(repoKey ? { repo: repoKey } : {}),
...(shared ? { workspace: 'shared' as const } : {})
})
.catch(() => null),
listing
])
if (cancelled) {
return
@@ -32,7 +32,8 @@ const BASE: SecretRequestCardModel = {
fieldError: null,
more: 0,
canRestart: true,
collapsed: false
collapsed: false,
sharedWorkspace: false
}
/** A terminal pane behind the card, as it sits over a Claude session. */
@@ -58,6 +59,10 @@ export const open = frame({ value: 'npm_9f2cA81bX7' })
export const openWithMore = frame({ more: 2 })
export const repoHint = frame({ suggestedRepo: true })
export const personalOnly = frame({ scopes: ['personal'] })
/** SEC-5: a shared workspace, and the person can write the repository: Repository only. */
export const sharedRepoOnly = frame({ sharedWorkspace: true, scopes: ['repo'], scope: 'repo' })
/** SEC-5: a shared workspace, and nothing this person can write reaches it. */
export const sharedNoScope = frame({ sharedWorkspace: true, scopes: [], scope: 'personal' })
export const unknownAgent = frame({ agent: null, canRestart: false })
export const longReason = frame({
reason:
@@ -31,7 +31,8 @@ const BASE: SecretRequestCardModel = {
fieldError: null,
more: 0,
canRestart: false,
collapsed: false
collapsed: false,
sharedWorkspace: false
}
afterEach(cleanup)
@@ -34,8 +34,13 @@ export type SecretRequestCardModel = {
reason: string | null
/** The agent suggested Repository. A hint only: it never preselects (D2). */
suggestedRepo: boolean
/** Personal always; Repository only when the person can write it. Never Shared (D6). */
/**
* Personal, plus Repository when the person can write it. Never Shared (D6). In a shared workspace
* Personal is left out (SEC-5), so this can be empty: then the card says who can add it instead.
*/
scopes: readonly SecretRequestScope[]
/** The workspace is shared with teammates, so it gets no Personal secrets (SEC-5). */
sharedWorkspace: boolean
scope: SecretRequestScope
value: string
phase: SecretRequestCardPhase
@@ -91,7 +96,7 @@ export function SecretRequestCard({
const agentName = model.agent ?? t('secretRequest.anAgent', 'an agent')
const done = model.phase === 'saved' || model.phase === 'savedAfterExpiry'
const saving = model.phase === 'saving'
const canSave = model.value.length > 0 && !saving
const canSave = model.value.length > 0 && !saving && model.scopes.length > 0
const ownRef = React.useRef<HTMLDivElement>(null)
const focusedWithin = React.useRef(false)
@@ -230,6 +235,21 @@ export function SecretRequestCard({
/>
) : (
<>
{model.scopes.length === 0 ? (
<InlineError
tone="neutral"
title={t(
'secretRequest.sharedNoScope',
'This workspace is shared, so it doesn’t get personal secrets.'
)}
detail={t(
'secretRequest.sharedAskAdmin',
'Ask an owner or admin to add {{name}} to this repository’s secrets.',
{ name: model.name }
)}
density="compact"
/>
) : (
<div data-secret-request-field="" className="flex flex-col gap-1.5">
<Label htmlFor={`${id}-value`} className="sr-only">
{t('secretRequest.valueLabel', 'Value for {{name}}', { name: model.name })}
@@ -273,6 +293,12 @@ export function SecretRequestCard({
'Saves to your Cloud secrets. Commands in this workspace can read it as ${{name}}.',
{ name: model.name }
)}
{model.sharedWorkspace
? ` ${t(
'secretRequest.sharedRepoOnly',
'This workspace is shared, so it only gets repository and shared values.'
)}`
: null}
</p>
{model.suggestedRepo && model.scopes.includes('repo') ? (
<p className="text-xs text-muted-foreground">
@@ -282,6 +308,7 @@ export function SecretRequestCard({
</p>
) : null}
</div>
)}
{model.phase === 'failed' ? (
<InlineError
title={t('secretRequest.unreachable', 'Couldn’t reach Orca Cloud.')}
@@ -111,7 +111,7 @@ export function SecretRequestScopeControl({
if (scopes.length < 2) {
return (
<span className="inline-flex h-8 shrink-0 items-center rounded-full border border-border px-2.5 text-xs text-muted-foreground">
{cloudSecretScopeLabel('personal', t)}
{cloudSecretScopeLabel(scopes[0] ?? 'personal', t)}
</span>
)
}
@@ -22,6 +22,7 @@ const NOW = 1_700_000_000_000
const put = vi.fn()
const refreshEnv = vi.fn()
const effective = vi.fn()
const workspaceSharing = vi.fn()
function event(patch: Partial<SecretRequestedEvent> = {}): SecretRequestedEvent {
return {
@@ -68,12 +69,18 @@ describe('S4-b secret request card', () => {
put.mockResolvedValue({ ok: true, value: {} })
refreshEnv.mockResolvedValue({ ok: true, value: true })
effective.mockResolvedValue({ ok: false, error: 'unavailable' })
workspaceSharing.mockResolvedValue({
ok: true,
value: { shared: false, ownerName: null, isOwner: true }
})
rpc.mockImplementation(async (_target, method: string) =>
method === 'secrets.touchRequest'
? { expiresAt: Date.now() + 15 * 60_000 }
: { outcome: 'provided' }
)
Object.assign(window, { api: { cloudSecrets: { put, refreshEnv, effective } } })
Object.assign(window, {
api: { cloudSecrets: { put, refreshEnv, effective, workspaceSharing } }
})
applySecretRequested('env-1', event())
})
afterEach(() => {
@@ -93,6 +100,29 @@ describe('S4-b secret request card', () => {
expect(screen.getByText(/Commands in this workspace can read it as \$NPM_TOKEN/)).toBeTruthy()
})
it('in a shared workspace never offers Personal (SEC-5): says who can add it instead', async () => {
workspaceSharing.mockResolvedValue({
ok: true,
value: { shared: true, ownerName: 'Ada', isOwner: false }
})
render(<Harness />)
await act(async () => {})
expect(workspaceSharing).toHaveBeenCalledWith({ runtimeEnvironmentId: 'env-1' })
expect(screen.getByText('This workspace is shared, so it doesn’t get personal secrets.')).toBeTruthy()
expect(screen.queryByLabelText('Value for NPM_TOKEN')).toBeNull()
expect(screen.getByRole('button', { name: 'Add secret' }).getAttribute('aria-disabled')).toBe(
'true'
)
expect(put).not.toHaveBeenCalled()
})
it('fails closed when the workspace sharing can’t be read', async () => {
workspaceSharing.mockRejectedValue(new Error('down'))
render(<Harness />)
await act(async () => {})
expect(screen.queryByLabelText('Value for NPM_TOKEN')).toBeNull()
})
it('saves through Cloud secrets, then tells orcad the outcome without the value', async () => {
render(<Harness />)
fireEvent.change(valueInput(), { target: { value: 'npm_secret_1' } })
@@ -27,6 +27,7 @@ import {
type SecretsResolveRequestResult,
type SecretsTouchRequestResult
} from '../../../../shared/secret-request-contract'
import { cloudWorkspaceSecretsMode } from '@/lib/orca-cloud/cloud-workspace-secrets-mode'
import type { CloudSecretsErrorCode } from '../../../../shared/cloud-secrets/cloud-secrets-wire'
import type {
SecretRequestCardActions,
@@ -121,6 +122,9 @@ export function useSecretRequestCard(args: {
const [fieldError, setFieldError] = useState<string | null>(null)
const [focused, setFocused] = useState(false)
const [repoWritable, setRepoWritable] = useState(false)
// SEC-5: a shared workspace gets no Personal secrets, so a Personal save would never reach it.
// Unknown until read: Personal stays offered meanwhile, as before this check existed.
const [sharedWorkspace, setSharedWorkspace] = useState(false)
const [collapsed, setCollapsed] = useState(false)
const repoKey = useWorkspaceRepoKey(event.worktreeId ?? worktreeId)
const openPanel = useAgentHostPanelOpener()
@@ -140,6 +144,18 @@ export function useSecretRequestCard(args: {
}
}, [repoKey])
useEffect(() => {
let cancelled = false
void cloudWorkspaceSecretsMode(environmentId).then((mode) => {
if (!cancelled) {
setSharedWorkspace(mode === 'shared')
}
})
return () => {
cancelled = true
}
}, [environmentId])
// The card's own clock: an open request past its expiry shows as expired and drops what was typed.
useEffect(() => {
if (local !== null) {
@@ -196,12 +212,19 @@ export function useSecretRequestCard(args: {
}
}, [holding, environmentId, requestId])
const scopes: SecretRequestScope[] = repoKey && repoWritable ? ['personal', 'repo'] : ['personal']
const effectiveScope: SecretRequestScope = scopes.includes(scope) ? scope : 'personal'
const repoScope = repoKey !== null && repoWritable
const scopes: SecretRequestScope[] = sharedWorkspace
? repoScope
? ['repo']
: []
: repoScope
? ['personal', 'repo']
: ['personal']
const effectiveScope: SecretRequestScope = scopes.includes(scope) ? scope : (scopes[0] ?? 'personal')
const add = useCallback(async () => {
const api = window.api.cloudSecrets
if (!value || local !== null) {
if (!value || local !== null || scopes.length === 0) {
return
}
setFailed(false)
@@ -236,7 +259,7 @@ export function useSecretRequestCard(args: {
requestId,
outcome === 'provided' ? 'saved' : 'savedAfterExpiry'
)
}, [value, local, environmentId, requestId, effectiveScope, repoKey, event.name, t])
}, [value, local, scopes.length, environmentId, requestId, effectiveScope, repoKey, event.name, t])
const phase: SecretRequestCardPhase =
local === 'saving'
@@ -258,6 +281,7 @@ export function useSecretRequestCard(args: {
suggestedRepo: event.scope === 'repo',
scopes,
scope: effectiveScope,
sharedWorkspace,
// An expired request shows no field, and what was typed doesn't come back.
value: local === 'expired' ? '' : value,
phase,
@@ -25,7 +25,7 @@ import type {
import {
isTeamAdmin,
parseScope,
writableScopes,
askScopes,
type CloudSecretsAskData
} from './cloud-secrets-ask-model'
@@ -130,10 +130,11 @@ export function CloudSecretsAskForm({
const id = React.useId()
const headingId = `${id}-heading`
const admin = isTeamAdmin(data.caller)
const scopes = writableScopes(data.caller, { repo: data.repoKey !== null, shared: true })
const scopes = askScopes(data)
const fallbackScope = scopes[0] ?? 'personal'
const filled = data.missing.filter((name) => (state.values[name] ?? '').length > 0)
const saving = state.phase === 'saving'
const canSave = filled.length > 0 && !saving
const canSave = filled.length > 0 && !saving && scopes.length > 0
if (state.phase === 'skipped') {
return (
@@ -275,13 +276,13 @@ export function CloudSecretsAskForm({
onChange={(value) => actions.onValueChange(name, value)}
placeholder={t('cloudSecretsAsk.valuePlaceholder', 'Value')}
invalid={Boolean(refusal)}
disabled={saving}
disabled={saving || scopes.length === 0}
describedBy={refusal ? errorId : undefined}
/>
</div>
{scopes.length > 1 ? (
{scopes.length === 0 ? null : scopes.length > 1 ? (
<Select
value={state.scopes[name] ?? 'personal'}
value={state.scopes[name] ?? fallbackScope}
onValueChange={(scope) => actions.onScopeChange(name, parseScope(scope))}
disabled={saving}
>
@@ -302,7 +303,7 @@ export function CloudSecretsAskForm({
</Select>
) : (
<span className="inline-flex h-8 items-center rounded-full border border-border px-2.5 text-xs text-muted-foreground">
{cloudSecretScopeLabel('personal', t)}
{cloudSecretScopeLabel(fallbackScope, t)}
</span>
)}
{refusal ? (
@@ -337,10 +338,15 @@ export function CloudSecretsAskForm({
<p className="min-w-0 flex-1 basis-60 text-xs leading-5 text-muted-foreground">
{admin
? t('cloudSecrets.editor.help', 'Write-only. You won’t see it again after saving.')
: t(
'cloudSecretsAsk.memberFooter',
'Saved to your personal Cloud secrets, so only your workspaces get them. To set them for the whole team, ask an owner or admin.'
)}
: data.shared
? t(
'cloudSecretsAsk.sharedMemberFooter',
'This workspace is shared, so it doesn’t get personal secrets. Ask an owner or admin to add the missing values to this repository or the team.'
)
: t(
'cloudSecretsAsk.memberFooter',
'Saved to your personal Cloud secrets, so only your workspaces get them. To set them for the whole team, ask an owner or admin.'
)}
</p>
<div className="flex shrink-0 items-center gap-2">
<Button
@@ -19,6 +19,8 @@ import {
useCloudSecretsMissing
} from '@/lib/orca-cloud/cloud-secrets-missing-notice-store'
import { CloudSecretsAskForm } from './CloudSecretsAskForm'
import { useAppStore } from '@/store'
import { runtimeEnvironmentIdOrLocalUnlessTwin } from '@/lib/workspace/ownership/worktree-runtime-owner'
import { useCloudSecretsAskLoad } from './use-cloud-secrets-ask'
import { useCloudSecretsAskForm } from './use-cloud-secrets-ask-form'
@@ -96,7 +98,11 @@ function CloudSecretsAskDialogBody({
repoKey: string
}): React.JSX.Element {
const t = useTranslate()
const { load, reload } = useCloudSecretsAskLoad(repoKey)
// The workspace's runtime environment, so a shared one isn't offered Personal values (SEC-5).
const runtimeEnvironmentId = useAppStore((state) =>
runtimeEnvironmentIdOrLocalUnlessTwin(state, workspaceId)
)
const { load, reload } = useCloudSecretsAskLoad(repoKey, runtimeEnvironmentId)
const data = load.status === 'ready' ? load.data : null
// Filled elsewhere since the sheet closed: the notice follows what is really missing now.
useEffect(() => {
@@ -4,6 +4,7 @@ import type {
CloudSecretsEffective
} from '../../../../shared/cloud-secrets/cloud-secrets-wire'
import {
askScopes,
cloudSecretsAskData,
environmentForRepo,
githubRepoKey,
@@ -81,6 +82,13 @@ describe('writableScopes', () => {
// A secret request never offers Shared, and Repository needs a repo.
expect(writableScopes(admin, { repo: false, shared: false })).toEqual(['personal'])
})
it('leaves Personal out for a shared workspace (SEC-5)', () => {
const repoWriter = { canWrite: { personal: true, org: false, repo: true } }
expect(askScopes({ caller: MEMBER, repoKey: 'github.com/a/b', shared: true })).toEqual([])
expect(askScopes({ caller: repoWriter, repoKey: 'github.com/a/b', shared: true })).toEqual(['repo'])
expect(askScopes({ caller: MEMBER, repoKey: 'github.com/a/b', shared: false })).toEqual(['personal'])
})
})
describe('cloudSecretsAskData', () => {
@@ -56,12 +56,15 @@ export function missingSecretNames(
return missing
}
/** Scopes a person can save a missing value to, Personal first. Shared only where asked for. */
/**
* Scopes a person can save a missing value to, Personal first. Shared only where asked for.
* `personal: false` for a workspace shared with teammates: it gets no Personal values (SEC-5).
*/
export function writableScopes(
caller: Pick<CloudSecretsCaller, 'canWrite'>,
options: { repo: boolean; shared: boolean }
options: { repo: boolean; shared: boolean; personal?: boolean }
): CloudSecretScope[] {
const scopes: CloudSecretScope[] = ['personal']
const scopes: CloudSecretScope[] = options.personal === false ? [] : ['personal']
if (options.repo && caller.canWrite.repo) {
scopes.push('repo')
}
@@ -85,12 +88,25 @@ export type CloudSecretsAskData = {
/** The environment has been built, so its install script ran without the missing team values. */
built: boolean
repoKey: string | null
/** The workspace is shared with teammates: no Personal values reach it, so none are offered (SEC-5). */
shared: boolean
}
/** Where this person can save a missing value for this workspace; empty when nowhere reaches it. */
export function askScopes(data: Pick<CloudSecretsAskData, 'caller' | 'repoKey' | 'shared'>): CloudSecretScope[] {
return writableScopes(data.caller, {
repo: data.repoKey !== null,
shared: true,
personal: !data.shared
})
}
export function cloudSecretsAskData(args: {
environment: Pick<HostedEnvironmentListEntry, 'name' | 'envVarNames' | 'activeBuildId'>
effective: CloudSecretsEffective
repoKey: string | null
/** Answered by the control plane for a shared workspace (`effective.workspace === 'shared'`). */
shared?: boolean
}): CloudSecretsAskData {
const declared = args.environment.envVarNames.filter(
(name) => cloudSecretKind(name) !== 'agent_key'
@@ -101,7 +117,8 @@ export function cloudSecretsAskData(args: {
missing: missingSecretNames(declared, args.effective),
caller: args.effective.caller,
built: args.environment.activeBuildId !== null,
repoKey: args.repoKey
repoKey: args.repoKey,
shared: args.shared === true
}
}
@@ -1,6 +1,6 @@
import { useCallback, useMemo, useState } from 'react'
import type { CloudSecretScope } from '../../../../shared/cloud-secrets/cloud-secrets-wire'
import { applyDotenvPaste, type CloudSecretsAskData } from './cloud-secrets-ask-model'
import { applyDotenvPaste, askScopes, type CloudSecretsAskData } from './cloud-secrets-ask-model'
import {
EMPTY_ASK_STATE,
type CloudSecretsAskFormActions,
@@ -31,9 +31,17 @@ export function useCloudSecretsAskForm(args: {
return
}
setState((current) => ({ ...current, phase: 'saving', refused: {} }))
// Unchosen names go to the first scope offered (Personal, or Repository in a shared workspace).
const fallback = askScopes(data)[0]
if (!fallback) {
return
}
const scopes = Object.fromEntries(
Object.keys(values).map((name) => [name, state.scopes[name] ?? fallback])
)
const result = await saveMissingSecrets({
values,
scopes: state.scopes,
scopes,
repoKey: data.repoKey,
refreshRuntimeEnvironmentId
})
@@ -1,5 +1,6 @@
// Loads what S2 and the panel's section 3 need for one repo: the org environment that lists it and the
// caller's effective Cloud secrets. Two reads, no new endpoint; nothing here wakes a sandbox.
import { cloudWorkspaceSecretsMode } from '@/lib/orca-cloud/cloud-workspace-secrets-mode'
import { useCallback, useEffect, useState } from 'react'
import {
cloudSecretsErrorCode,
@@ -30,7 +31,11 @@ export type CloudSecretsAskLoad =
environment: HostedEnvironmentListEntry
}
export function useCloudSecretsAskLoad(repoKey: string | null): {
export function useCloudSecretsAskLoad(
repoKey: string | null,
/** The workspace's runtime environment; its sharing decides whether Personal values count (SEC-5). */
runtimeEnvironmentId: string | null = null
): {
load: CloudSecretsAskLoad
reload: () => void
} {
@@ -45,10 +50,13 @@ export function useCloudSecretsAskLoad(repoKey: string | null): {
}
let cancelled = false
void (async () => {
const [list, effective] = await Promise.all([
const [list, mode] = await Promise.all([
environments.list().catch(() => null),
secrets.effective({ repo: repoKey }).catch(() => null)
cloudWorkspaceSecretsMode(runtimeEnvironmentId)
])
const effective = await secrets
.effective({ repo: repoKey, ...(mode === 'shared' ? { workspace: mode } : {}) })
.catch(() => null)
if (cancelled) {
return
}
@@ -68,7 +76,12 @@ export function useCloudSecretsAskLoad(repoKey: string | null): {
}
setLoad({
status: 'ready',
data: cloudSecretsAskData({ environment, effective: effective.value, repoKey }),
data: cloudSecretsAskData({
environment,
effective: effective.value,
repoKey,
shared: mode === 'shared'
}),
effective: effective.value,
environment
})
@@ -76,7 +89,7 @@ export function useCloudSecretsAskLoad(repoKey: string | null): {
return () => {
cancelled = true
}
}, [repoKey, generation])
}, [repoKey, runtimeEnvironmentId, generation])
const reload = useCallback(() => setGeneration((value) => value + 1), [])
return { load, reload }
}
@@ -399,6 +399,22 @@ export const secretsMember = secretsFrame(
secretsRow(secretsData('member', { missing: ['STRIPE_TEST_KEY', 'DATABASE_URL'] }))
)
export const secretsBuildOnlyTeam = secretsFrame(secretsRow(secretsData('member', { built: true })))
/** SEC-5: the same form for a shared workspace (missing-secrets sheet): no Personal to offer. */
export const secretsSharedMember = secretsFrame(secretsRow(secretsData('member', { shared: true })))
export const secretsSharedRepoWriter = secretsFrame(
secretsRow(
secretsData('member', {
shared: true,
caller: {
userId: 'u_me',
orgId: 'org_acme',
orgRole: 'member',
canWrite: { personal: true, org: false, repo: true }
}
}),
{ values: TYPED }
)
)
export const secretsPasted = secretsFrame(
secretsRow(secretsData('admin'), {
values: { ...TYPED, SENTRY_DSN: 'https://k@o1.ingest.sentry.io/1' },
@@ -33,6 +33,7 @@ export function secretsData(
caller: role === 'admin' ? ADMIN : MEMBER,
built: false,
repoKey: 'github.com/acme/web',
shared: false,
...patch
}
}
+8 -3
View File
@@ -28391,7 +28391,8 @@
"guestOwner": "In a shared workspace, Personal values come from its owner, {{owner}}, not from you.",
"guest": "In a shared workspace, Personal values come from its owner, not from you.",
"empty": "No variables from Cloud secrets yet.",
"overrides": "overrides {{scopes}}"
"overrides": "overrides {{scopes}}",
"sharedNoPersonal": "A shared workspace gets nobody’s Personal values, not even its owner’s, so only Repository and Shared apply."
},
"keys": {
"askAdmin": "Ask an owner or admin to add one.",
@@ -28577,7 +28578,8 @@
"loading": "Loading secrets…",
"nothingMissing": "Nothing is missing.",
"dialogTitle": "Add missing secrets",
"dialogDetail": "Values go to your Cloud secrets. New terminals and agents in this workspace get them within a few seconds."
"dialogDetail": "Values go to your Cloud secrets. New terminals and agents in this workspace get them within a few seconds.",
"sharedMemberFooter": "This workspace is shared, so it doesn’t get personal secrets. Ask an owner or admin to add the missing values to this repository or the team."
},
"cloudAgents": {
"source": {
@@ -28623,7 +28625,10 @@
"unseenIn": "In {{workspace}}. The request waits up to 15 minutes.",
"unseen": "Open that workspace to answer. The request waits up to 15 minutes.",
"openWorkspace": "Open",
"helpBeforeSave": "Saves to your Cloud secrets. Commands in this workspace can read it as ${{name}}."
"helpBeforeSave": "Saves to your Cloud secrets. Commands in this workspace can read it as ${{name}}.",
"sharedNoScope": "This workspace is shared, so it doesn’t get personal secrets.",
"sharedAskAdmin": "Ask an owner or admin to add {{name}} to this repository’s secrets.",
"sharedRepoOnly": "This workspace is shared, so it only gets repository and shared values."
},
"agentApiKeys": {
"cloud": {
@@ -0,0 +1,124 @@
// @vitest-environment happy-dom
// SECRETS-EFFECTIVE-SHARED: workspace-scoped secrets views ask for exactly what a shared workspace gets
// (no Personal values, SEC-5): the agent host panel's Environment section and the missing-secrets ask.
// The secret request card is covered in use-secret-request-card.test.tsx.
import { renderHook, waitFor } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { CloudSecretsEffective } from '../../../../shared/cloud-secrets/cloud-secrets-wire'
import { useCloudPanelSections } from '@/components/agent-host-panel/cloud-sections/use-cloud-panel-sections'
import { useCloudSecretsAskLoad } from '@/components/cloud-secrets-ask/use-cloud-secrets-ask'
import { cloudWorkspaceSecretsMode } from './cloud-workspace-secrets-mode'
const REPO = 'github.com/acme/web'
const effective = vi.fn()
const workspaceSharing = vi.fn()
const list = vi.fn()
function answer(workspace: 'private' | 'shared'): { ok: true; value: CloudSecretsEffective } {
return {
ok: true,
value: {
workspace,
caller: {
userId: 'u',
orgId: 'o',
orgRole: 'member',
canWrite: { personal: true, org: false, repo: false }
},
precedence: { env: ['repo', 'personal', 'org'], agent_key: ['org', 'repo', 'personal'] },
// What the control plane answers: a shared workspace never lists the Personal value.
secrets:
workspace === 'shared'
? []
: [{ name: 'SENTRY_DSN', kind: 'env', scope: 'personal', hint: null, updatedAt: 0, shadowed: [] }]
}
}
}
function sharing(shared: boolean, isOwner = true) {
return { ok: true, value: { shared, ownerName: null, isOwner } }
}
beforeEach(() => {
effective.mockImplementation(async (request: { workspace?: 'shared' }) =>
answer(request.workspace ?? 'private')
)
list.mockResolvedValue({
ok: true,
data: {
environments: [
{
name: 'acme-web',
repos: [{ url: 'https://github.com/acme/web' }],
envVarNames: ['SENTRY_DSN'],
activeBuildId: null
}
]
}
})
Object.assign(window, {
api: { cloudSecrets: { effective, workspaceSharing }, orcaCloudEnvironments: { list } }
})
})
afterEach(() => {
vi.clearAllMocks()
})
describe('cloudWorkspaceSecretsMode', () => {
it('shared or unreadable sharing is "shared"; unshared or no environment is "private"', async () => {
workspaceSharing.mockResolvedValueOnce(sharing(true))
expect(await cloudWorkspaceSecretsMode('env-1')).toBe('shared')
workspaceSharing.mockResolvedValueOnce(sharing(false))
expect(await cloudWorkspaceSecretsMode('env-1')).toBe('private')
workspaceSharing.mockResolvedValueOnce({ ok: false, error: 'unavailable' })
expect(await cloudWorkspaceSecretsMode('env-1')).toBe('shared')
workspaceSharing.mockRejectedValueOnce(new Error('down'))
expect(await cloudWorkspaceSecretsMode('env-1')).toBe('shared')
expect(await cloudWorkspaceSecretsMode(null)).toBe('private')
})
})
describe('agent host panel Environment section', () => {
it('asks for the shared view in a shared workspace, the owner’s own included', async () => {
workspaceSharing.mockResolvedValue(sharing(true, true))
const { result } = renderHook(() =>
useCloudPanelSections({ repoKey: REPO, runtimeEnvironmentId: 'env-1', asleep: false })
)
await waitFor(() => expect(result.current.load.status).toBe('ready'))
expect(effective).toHaveBeenCalledWith({ repo: REPO, workspace: 'shared' })
const load = result.current.load
expect(load.status === 'ready' && load.data.withoutPersonal).toBe(true)
expect(load.status === 'ready' && load.data.missing).toEqual(['SENTRY_DSN'])
})
it('an unshared workspace keeps the default view', async () => {
workspaceSharing.mockResolvedValue(sharing(false))
const { result } = renderHook(() =>
useCloudPanelSections({ repoKey: REPO, runtimeEnvironmentId: 'env-1', asleep: false })
)
await waitFor(() => expect(result.current.load.status).toBe('ready'))
expect(effective).toHaveBeenCalledWith({ repo: REPO })
const load = result.current.load
expect(load.status === 'ready' && load.data.missing).toEqual([])
})
})
describe('missing-secrets ask', () => {
it('a shared workspace: shared view, Personal not counted, and the form knows it', async () => {
workspaceSharing.mockResolvedValue(sharing(true, false))
const { result } = renderHook(() => useCloudSecretsAskLoad(REPO, 'env-1'))
await waitFor(() => expect(result.current.load.status).toBe('ready'))
expect(effective).toHaveBeenCalledWith({ repo: REPO, workspace: 'shared' })
const load = result.current.load
expect(load.status === 'ready' && load.data).toMatchObject({ shared: true, missing: ['SENTRY_DSN'] })
})
it('no runtime environment (the build sheet, before the workspace exists): default view', async () => {
const { result } = renderHook(() => useCloudSecretsAskLoad(REPO))
await waitFor(() => expect(result.current.load.status).toBe('ready'))
expect(workspaceSharing).not.toHaveBeenCalled()
expect(effective).toHaveBeenCalledWith({ repo: REPO })
const load = result.current.load
expect(load.status === 'ready' && load.data).toMatchObject({ shared: false, missing: [] })
})
})
@@ -0,0 +1,24 @@
// SEC-5: a cloud workspace shared with teammates gets no personal secrets (its owner's or anyone's).
// What a workspace-scoped secrets view should answer for: the shared mode drops personal values.
import type { CloudSecretWorkspaceMode } from '../../../../shared/cloud-secrets/cloud-secrets-wire'
/**
* 'shared' when the workspace is shared, or when its sharing can't be read (fails closed, like D13):
* promising a personal value that the workspace won't get is the mismatch SEC-5 removes.
* No runtime environment (a workspace still being created, or none known): 'private'.
*/
export async function cloudWorkspaceSecretsMode(
runtimeEnvironmentId: string | null
): Promise<CloudSecretWorkspaceMode> {
const secrets = window.api.cloudSecrets
if (!runtimeEnvironmentId || !secrets) {
return 'private'
}
let sharing: Awaited<ReturnType<typeof secrets.workspaceSharing>> | null = null
try {
sharing = await secrets.workspaceSharing({ runtimeEnvironmentId })
} catch {
sharing = null
}
return sharing?.ok && !sharing.value.shared ? 'private' : 'shared'
}