Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions dashboard/src/pages/ReleaseTaskDetailPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@ function metadataString(source: Record<string, unknown> | null | undefined, ...k
return null
}

function shortDigest(value: string | null) {
if (!value) return ''
const match = value.match(/sha256:([0-9a-f]{64})/i)
return match ? `sha256:${match[1].slice(0, 12)}…` : value.slice(0, 24)
}

function shortSha(value: string | null) {
return value ? `${value.slice(0, 12)}${value.length > 12 ? '…' : ''}` : ''
}

function localPrebuiltCommand(task: ReleaseTask) {
const service = task.service_key || ''
const ref = task.branch_name || 'main'
return [
'cd /Users/cliff/workspace/agent/Synapse-Network',
'',
'bash scripts/deploy/local_build_staging_image.sh \\',
` --service ${service} \\`,
` --ref ${ref} \\`,
` --release-task-id ${task.id}`,
].join('\n')
}

function compactWhitespace(value: string) {
return value
.split('\n')
Expand Down Expand Up @@ -138,6 +161,7 @@ export function ReleaseTaskDetailModal({
const [prebuiltDigest, setPrebuiltDigest] = useState('')
const [prebuiltCommit, setPrebuiltCommit] = useState('')
const [prebuiltBusy, setPrebuiltBusy] = useState(false)
const [commandCopied, setCommandCopied] = useState(false)
if (!task) return null
const hasDeployment = Boolean(task.deployment_record_id)
const showFailure = shouldShowReleaseTaskFailure(task)
Expand All @@ -147,6 +171,7 @@ export function ReleaseTaskDetailModal({
const taskMetadata = (task as ReleaseTask & { task_metadata?: Record<string, unknown> }).task_metadata || {}
const attachedPrebuiltImage = metadataString(taskMetadata, 'prebuiltImageDigest')
const attachedPrebuiltCommit = metadataString(taskMetadata, 'sourceCommitSha')
const buildCommand = localPrebuiltCommand(task)
const isPrebuiltFrontendTask = task.environment === 'staging'
&& task.project_key === 'synapse-network'
&& ['admin-front', 'user-front', 'docs-front'].includes(task.service_key || '')
Expand All @@ -169,6 +194,15 @@ export function ReleaseTaskDetailModal({
setPrebuiltBusy(false)
}
}
const copyBuildCommand = () => {
navigator.clipboard
?.writeText(buildCommand)
.then(() => {
setCommandCopied(true)
window.setTimeout(() => setCommandCopied(false), 1600)
})
.catch(() => setCommandCopied(false))
}
return (
<OverlayModal
open={Boolean(task)}
Expand Down Expand Up @@ -207,13 +241,29 @@ export function ReleaseTaskDetailModal({
<div className="mt-3 space-y-2 rounded-xl border border-[color:var(--ops-state-ready-border)] bg-[color:var(--ops-state-ready-bg)] p-3 text-sm text-[color:var(--ops-state-ready-text)]">
<div>Prebuilt image attached. Staging frontend workflow will deploy by immutable digest and skip Cloud Build.</div>
<div className="break-all font-mono text-xs">{attachedPrebuiltImage}</div>
{attachedPrebuiltCommit ? <div className="font-mono text-xs">commit {attachedPrebuiltCommit}</div> : null}
<div className="text-xs">Digest: <span className="font-mono">{shortDigest(attachedPrebuiltImage)}</span></div>
{attachedPrebuiltCommit ? <div className="font-mono text-xs">commit {shortSha(attachedPrebuiltCommit)}</div> : null}
</div>
) : (
<div className="mt-3 rounded-xl bg-[color:var(--ops-panel)] p-3 text-sm text-[color:var(--ops-text-muted)]">
可选:先用本地 ephemeral worktree 构建并推送镜像,再把 immutable digest 绑定到此任务。发布时 Actions 会校验 digest 并直接部署。
可选:先用本地 ephemeral worktree 构建并推送镜像,再把 immutable digest 绑定到此任务。未绑定时发布会走 Cloud Build,通常会多消耗约 5 分钟 Actions 时间。
</div>
)}
{!attachedPrebuiltImage ? (
<div className="mt-4 rounded-xl border border-[color:var(--ops-stroke-soft)] bg-[color:var(--ops-panel)] p-3">
<div className="mb-2 flex flex-wrap items-center justify-between gap-2">
<div className="text-xs font-semibold uppercase tracking-[0.18em] text-[color:var(--ops-text-caption)]">Local worktree build command</div>
<button
type="button"
className="rounded-lg border border-[color:var(--ops-stroke-strong)] px-3 py-1.5 text-xs"
onClick={copyBuildCommand}
>
{commandCopied ? '已复制' : '复制命令'}
</button>
</div>
<pre className="overflow-auto whitespace-pre-wrap break-words text-xs text-[color:var(--ops-text-muted)]">{buildCommand}</pre>
</div>
) : null}
{canAttachPrebuiltImage ? (
<div className="mt-4 grid gap-3 md:grid-cols-[1.5fr_1fr_auto]">
<label className="text-xs uppercase tracking-[0.18em] text-[color:var(--ops-text-caption)]">
Expand Down
109 changes: 109 additions & 0 deletions dashboard/src/pages/ReleaseTaskPrebuiltImageUi.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// @vitest-environment jsdom

import { render, screen } from '@testing-library/react'
import { describe, expect, it, vi } from 'vitest'
import type { ReleaseTask } from '../api'
import { ReleaseTaskDetailModal } from './ReleaseTaskDetailPanel'
import { ReleaseTasksTable } from './ReleaseTasksTable'

function releaseTask(overrides: Partial<ReleaseTask> & { task_metadata?: Record<string, unknown> } = {}) {
return {
id: 42,
source_type: 'manual',
requirement_id: null,
deployment_record_id: null,
project_key: 'synapse-network',
project_display_name: 'Synapse-Network',
service_key: 'docs-front',
branch_name: 'main',
environment: 'staging',
status: 'requested',
actor: 'operator',
operator: null,
note: 'Manual staging release',
deployment_status: null,
deployment_external_run_id: null,
deployment_external_url: null,
deployment_failure_summary: null,
deployment_health_status: null,
deployment_workflow_file: null,
deployment_commit_sha: null,
deployment_started_at: null,
deployment_finished_at: null,
deployment_metadata: {},
pr_gate: {
branch_exists: true,
pr_exists: false,
pr_url: null,
pr_number: null,
pr_state: 'main',
checks_status: 'success',
checks_summary: 'main 分支可直接发布 staging,不需要 PR gate。',
can_create_pr: false,
can_deploy_staging: true,
blocked_reason: null,
},
created_at: '2026-05-16T12:00:00Z',
updated_at: '2026-05-16T12:00:00Z',
...overrides,
} as ReleaseTask & { task_metadata?: Record<string, unknown> }
}

function renderTable(task: ReleaseTask & { task_metadata?: Record<string, unknown> }) {
render(
<ReleaseTasksTable
tasks={[task]}
total={1}
limit={10}
offset={0}
loading={false}
busyAction={null}
gateStatusByTaskId={{}}
onUpdateStatus={vi.fn()}
onCreatePr={vi.fn()}
onDeployStaging={vi.fn()}
onDeployProduction={vi.fn()}
onRefreshGate={vi.fn()}
onRefresh={vi.fn()}
onOpenDetails={vi.fn()}
onPage={vi.fn()}
/>,
)
}

describe('frontend prebuilt image release UI', () => {
it('shows Cloud Build cost guidance and local worktree command for frontend staging tasks', () => {
const task = releaseTask()
renderTable(task)

expect(screen.getByText(/未绑定 Prebuilt image/)).toBeTruthy()
expect(screen.getByText(/预计多约 5 分钟/)).toBeTruthy()

render(
<ReleaseTaskDetailModal
task={task}
onClose={vi.fn()}
onRefresh={vi.fn()}
onAttachPrebuiltImage={vi.fn()}
/>,
)

expect(screen.getByText('Local worktree build command')).toBeTruthy()
expect(screen.getByText(/scripts\/deploy\/local_build_staging_image\.sh/)).toBeTruthy()
expect(screen.getByText(/--service docs-front/)).toBeTruthy()
expect(screen.getByText(/--release-task-id 42/)).toBeTruthy()
})

it('shows attached frontend prebuilt digest and commit summary', () => {
renderTable(releaseTask({
task_metadata: {
prebuiltImageDigest: `us-central1-docker.pkg.dev/fabled-archive-494108-k5/synapse-staging/docs-front@sha256:${'a'.repeat(64)}`,
sourceCommitSha: 'b'.repeat(40),
},
}))

expect(screen.getByText(/Prebuilt image attached/)).toBeTruthy()
expect(screen.getByText(/sha256:aaaaaaaaaaaa/)).toBeTruthy()
expect(screen.getByText(/commit bbbbbbbbbbbb/)).toBeTruthy()
})
})
25 changes: 24 additions & 1 deletion dashboard/src/pages/ReleaseTasksTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ function CompactListText({ value }: Readonly<{ value: string | null | undefined
)
}

function shortDigest(value: string) {
const match = value.match(/sha256:([0-9a-f]{64})/i)
return match ? `sha256:${match[1].slice(0, 12)}…` : value.slice(0, 24)
}

function shortSha(value: unknown) {
const text = typeof value === 'string' ? value.trim() : ''
return text ? `${text.slice(0, 12)}${text.length > 12 ? '…' : ''}` : ''
}

function isFrontendPrebuiltCandidate(task: ReleaseTask) {
return task.environment === 'staging'
&& task.project_key === 'synapse-network'
&& task.status === 'requested'
&& ['admin-front', 'user-front', 'docs-front'].includes(task.service_key || '')
}

export function ReleaseTasksTable({
tasks,
total,
Expand Down Expand Up @@ -97,6 +114,7 @@ export function ReleaseTasksTable({
const prebuiltImageDigest = typeof taskMetadata.prebuiltImageDigest === 'string'
? taskMetadata.prebuiltImageDigest
: ''
const prebuiltCommit = shortSha(taskMetadata.sourceCommitSha)
const gateLoading = gateState?.status === 'loading'
const gateError = gateState?.status === 'error'
const gateReady = gateState?.status === 'ready'
Expand Down Expand Up @@ -131,7 +149,12 @@ export function ReleaseTasksTable({
) : null}
{prebuiltImageDigest ? (
<div className="mt-2 max-w-xs rounded-lg border border-[color:var(--ops-state-ready-border)] bg-[color:var(--ops-state-ready-bg)] px-2 py-1 text-xs text-[color:var(--ops-state-ready-text)]">
Prebuilt image attached
<div>Prebuilt image attached · {shortDigest(prebuiltImageDigest)}</div>
{prebuiltCommit ? <div className="mt-1 font-mono text-[11px]">commit {prebuiltCommit}</div> : null}
</div>
) : isFrontendPrebuiltCandidate(task) ? (
<div className="mt-2 max-w-xs rounded-lg border border-[color:var(--ops-stroke-soft)] bg-[color:var(--ops-panel)] px-2 py-1 text-xs text-[color:var(--ops-text-caption)]">
未绑定 Prebuilt image;发布将走 Cloud Build,预计多约 5 分钟。
</div>
) : null}
{task.deployment_health_status ? <div className="mt-2 text-xs text-[color:var(--ops-text-caption)]">Health: {STATUS_LABEL[task.deployment_health_status] || task.deployment_health_status}</div> : null}
Expand Down
4 changes: 4 additions & 0 deletions dashboard/src/pages/ReleasesPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const apiMock = vi.hoisted(() => ({
updateReleaseTask: vi.fn(),
createReleaseTaskPr: vi.fn(),
deployReleaseTaskToStaging: vi.fn(),
deployReleaseTask: vi.fn(),
syncReleaseTaskDeploymentStatuses: vi.fn(),
attachReleaseTaskPrebuiltImage: vi.fn(),
getProjectPolicies: vi.fn(),
prepareRelease: vi.fn(),
openReleasePr: vi.fn(),
Expand All @@ -40,6 +42,8 @@ vi.mock('../api', () => ({
vi.mock('../apiReleaseTasks', () => ({
getReleaseTasksPage: apiMock.getReleaseTasksPage,
getReleaseTaskGateStatus: apiMock.getReleaseTaskGateStatus,
deployReleaseTask: apiMock.deployReleaseTask,
attachReleaseTaskPrebuiltImage: apiMock.attachReleaseTaskPrebuiltImage,
}))

function candidate(overrides: Record<string, unknown> = {}) {
Expand Down
Loading