Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | 54x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 54x 54x | import type { components } from '@/types/api'
type Run = components['schemas']['Run']
type Project = components['schemas']['Project']
type Pipeline = components['schemas']['Pipeline']
let runId = 0
export function createMockRun(overrides?: Partial<Run>): Run {
runId++
const phases = ['pending', 'running', 'succeeded', 'failed'] as const
const projects = [
{ id: crypto.randomUUID(), name: 'My Application' },
{ id: crypto.randomUUID(), name: 'Documentation Site' },
{ id: crypto.randomUUID(), name: 'API Gateway' },
]
const pipelines = [
{ id: crypto.randomUUID(), name: 'Doc quality' },
{ id: crypto.randomUUID(), name: 'PR Review' },
{ id: crypto.randomUUID(), name: 'Release build' },
]
const sources = ['manual', 'webhook', 'schedule', 'cli'] as const
const phase = overrides?.phase ?? phases[Math.floor(Math.random() * 4)]
const project = projects[Math.floor(Math.random() * 3)]
const pipeline = pipelines[Math.floor(Math.random() * 3)]
const source = sources[Math.floor(Math.random() * 4)]
const daysAgo = Math.floor(Math.random() * 7)
const created = new Date(Date.now() - daysAgo * 86400000 - Math.random() * 3600000).toISOString()
return {
run_id: `run-${runId}`,
phase,
project_id: project.id,
project_name: project.name,
pipeline_id: pipeline.id,
pipeline_name: pipeline.name,
source_type: source,
source_metadata: null,
error: phase === 'failed'
? { message: 'Pipeline step failed', code: 'EXECUTION_ERROR', step: 'analyze', details: null }
: null,
output: phase === 'succeeded'
? 'Pipeline completed successfully.\n- Step analyze: All checks passed\n- Step review: Approved\n- Output: agent-platform/pipeline-1/output'
: null,
exit_code: phase === 'failed' ? 1 : 0,
token_input: Math.floor(Math.random() * 100000),
token_output: Math.floor(Math.random() * 50000),
created_at: created,
updated_at: created,
started_at: phase !== 'pending' ? created : null,
completed_at: phase === 'succeeded' || phase === 'failed' ? new Date().toISOString() : null,
...overrides,
} as Run
}
const staticProjects = [
{ id: 'proj-1', name: 'My Application', repo: 'git@github.com:org/myapp.git', count: 3 },
{ id: 'proj-2', name: 'Documentation Site', repo: 'github.com:org/docs.git', count: 1 },
{ id: 'proj-3', name: 'API Gateway', repo: 'git@github.com:org/gateway.git', count: 5 },
]
const statuses = ['succeeded', 'failed', 'running'] as const
export function createMockProject(overrides?: Partial<Project> & { last_run_status?: string; last_run_at?: string }): Project {
const p = staticProjects[Math.floor(Math.random() * 3)]
const status = statuses[Math.floor(Math.random() * 3)]
return {
id: p.id,
name: p.name,
repo_url: p.repo,
deploy_key_secret: p.id === 'proj-1' ? 'myapp-deploy-key' : null,
repo_token_encrypted: p.id === 'proj-1' ? 'base64-encrypted-value' : null,
description: p.id === 'proj-1' ? 'Main application repository' : null,
pipeline_count: p.count,
last_run_status: status,
last_run_at: new Date(Date.now() - Math.random() * 86400000).toISOString(),
created_at: new Date(Date.now() - 30 * 86400000).toISOString(),
updated_at: new Date().toISOString(),
...overrides,
} as Project
}
const mockPipelineDefs = [
{ name: 'Doc quality', manifest: 'git@gitea.keskikuja.site:org/manifests.git#manifests/doc-quality/', secret: null, branch: null },
{ name: 'PR Review', manifest: 'git@gitea.keskikuja.site:org/manifests.git#manifests/review-pr/', secret: 'deploy-key-manifests', branch: 'review-output' },
{ name: 'Release build', manifest: 'git@gitea.keskikuja.site:org/manifests.git#manifests/release/', secret: null, branch: 'release-output' },
]
export function createMockPipeline(overrides?: Partial<Pipeline> & { last_run_status?: string; last_run_at?: string }): Pipeline {
const def = mockPipelineDefs[Math.floor(Math.random() * 3)]
const status = statuses[Math.floor(Math.random() * 3)]
return {
id: crypto.randomUUID(),
project_id: 'proj-1',
name: def.name,
manifest_source_url: def.manifest,
manifest_secret: def.secret,
output_branch: def.branch,
last_run_status: status,
last_run_at: new Date(Date.now() - Math.random() * 86400000).toISOString(),
enabled: true,
description: null,
created_at: new Date(Date.now() - 30 * 86400000).toISOString(),
updated_at: new Date().toISOString(),
...overrides,
} as Pipeline
}
|