AI: address issue #483

このコミットが含まれているのは:
Codex Night Worker
2026-11-16 13:11:57 +09:00
コミット cb1f947a36
18個のファイルの変更、1352行の追加、0行の削除
+5
ファイルの表示
@@ -16,12 +16,17 @@ import type { User } from '@/types'
const MorePage: FC = () => {
const location = useLocation ()
const { message } = useUITranslation ('shared')
const { label: archiveLabel } = useUITranslation ('archive')
const menu = menuOutline (
{ tag: null, wikiId: null, user: { } as User, pathName: location.pathname })
return (
<MainArea className="md:flex">
<PageHead title={message ('labels.menu')}/>
{import.meta.env.DEV && (
<PrefetchLink to="/static-mirror">
{archiveLabel ('title')}
</PrefetchLink>)}
{[...Array (Math.ceil (menu.length / 4)).keys ()].map (i => (
<div key={i} className="flex-1 mx-16">
+96
ファイルの表示
@@ -0,0 +1,96 @@
import { act, fireEvent, screen, waitFor } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import StaticMirrorPage from '@/pages/StaticMirrorPage'
import { staticMirrorKeys } from '@/lib/queryKeys'
import { renderWithProviders } from '@/test/render'
const api = vi.hoisted (() => ({
apiGet: vi.fn (), apiPost: vi.fn (), startAPIDownload: vi.fn () }))
vi.mock ('@/lib/api', async original => ({
...await original<typeof import ('@/lib/api')> (), ...api }))
const definition = {
resourceLimit: 100, nameLimit: 2000, maxBytes: 8388608, maxSeconds: 60,
concurrency: 1, cooldownSeconds: 60, expirySeconds: 600,
exclusions: ['historical_state', 'unversioned_resources', 'images', 'videos'] }
const ready = {
status: 'ready', dataAt: '2026-11-16T00:00:00.000000Z', processed: 2, total: 2 }
beforeEach (() => {
vi.clearAllMocks ()
api.apiGet.mockImplementation (async (path: string) =>
path === '/static_mirror' ? definition : ready)
api.apiPost.mockResolvedValue ({ job: 'opaque-job' })
api.startAPIDownload.mockReturnValue (vi.fn ())
})
const startGeneration = async () => {
const button = screen.getByRole ('button', { name: 'スナップショット生成' })
await waitFor (() => expect (button).toBeEnabled ())
fireEvent.click (button)
}
describe ('Static Mirror generation', () => {
it ('starts a current snapshot and downloads through the common API', async () => {
const view = renderWithProviders (<StaticMirrorPage/>, { route: '/ja/static-mirror' })
await startGeneration ()
expect (api.apiPost).toHaveBeenCalledWith ('/static_mirror/jobs', { }, { locale: 'ja' })
fireEvent.click (await screen.findByRole ('button', { name: 'ZIP ダウンロード' }))
expect (screen.getByText (ready.dataAt)).toBeInTheDocument ()
expect (screen.getByText ('言語別名称').parentElement).toHaveTextContent ('2000')
expect (api.startAPIDownload).toHaveBeenCalledWith (
'/static_mirror', 'opaque-job', expect.any (Function))
const release = api.startAPIDownload.mock.results[0].value
view.unmount ()
expect (release).toHaveBeenCalled ()
})
it ('shows generation progress and offers the ZIP only after readiness', async () => {
let state = { ...ready, status: 'running', processed: 1 }
api.apiGet.mockImplementation (async (path: string) =>
path === '/static_mirror' ? definition : state)
const view = renderWithProviders (<StaticMirrorPage/>)
await startGeneration ()
expect (await screen.findByText ('生成中')).toBeInTheDocument ()
expect (screen.queryByRole ('button', { name: 'ZIP ダウンロード' })).toBeNull ()
expect (screen.getByRole ('button', { name: 'スナップショット生成' })).toBeDisabled ()
state = ready
await act (async () => {
await view.queryClient.invalidateQueries ({ queryKey: staticMirrorKeys.job ('opaque-job') })
})
expect (await screen.findByRole ('button', { name: 'ZIP ダウンロード' })).toBeEnabled ()
})
it ('keeps failure reasons visible without offering a ZIP', async () => {
api.apiGet.mockImplementation (async (path: string) =>
path === '/static_mirror' ? definition : { ...ready, status: 'failed', error: 'too_large' })
renderWithProviders (<StaticMirrorPage/>)
await startGeneration ()
expect (await screen.findByRole ('alert')).toHaveTextContent ('too_large')
expect (screen.queryByRole ('button', { name: 'ZIP ダウンロード' })).toBeNull ()
})
it ('shows intake limits and revoked downloads using existing error copy', async () => {
api.apiPost.mockRejectedValueOnce ({ isAxiosError: true, response: { status: 429 } })
renderWithProviders (<StaticMirrorPage/>)
await startGeneration ()
expect (await screen.findByRole ('alert')).toHaveTextContent ('HTTP 429')
api.apiGet.mockImplementation (async (path: string) => {
if (path === '/static_mirror') return definition
throw { isAxiosError: true, response: { status: 404 } }
})
await startGeneration ()
await waitFor (() => expect (screen.getByRole ('alert')).toHaveTextContent ('有効期限'))
expect (screen.getByRole ('button', { name: 'スナップショット生成' })).toBeEnabled ()
})
it ('preserves Japanese fallback language metadata for untranslated UI', async () => {
renderWithProviders (<StaticMirrorPage/>, { route: '/ain-Kana/static-mirror' })
await startGeneration ()
expect (api.apiPost).toHaveBeenCalledWith (
'/static_mirror/jobs', { }, { locale: 'ain-Kana' })
expect (screen.getByRole ('heading', { name: 'Static Mirror 生成機能' })
.querySelector ('[lang="ja"]')).toBeInTheDocument ()
})
})
+140
ファイルの表示
@@ -0,0 +1,140 @@
import { useMutation, useQuery } from '@tanstack/react-query'
import { useEffect, useRef, useState } from 'react'
import PageHead from '@/components/common/PageHead'
import PageTitle from '@/components/common/PageTitle'
import MainArea from '@/components/layout/MainArea'
import { Button } from '@/components/ui/button'
import { apiGet, apiPost, isApiError, startAPIDownload } from '@/lib/api'
import { staticMirrorKeys } from '@/lib/queryKeys'
import { useLocale } from '@/lib/useLocale'
import { useUITranslation } from '@/lib/useUITranslation'
type Definition = {
resourceLimit: number
nameLimit: number
maxBytes: number
maxSeconds: number
concurrency: number
cooldownSeconds: number
expirySeconds: number
exclusions: string[] }
type Job = {
status: 'queued' | 'running' | 'ready' | 'failed'
dataAt: string | null
processed: number
total: number | null
error?: string }
const StaticMirrorPage = () => {
const locale = useLocale ()
const { label, message } = useUITranslation ('archive')
const [job, setJob] = useState<string | null> (null)
const [downloadFailed, setDownloadFailed] = useState (false)
const downloadRef = useRef<(() => void) | null> (null)
useEffect (() => () => downloadRef.current?.(), [])
const definition = useQuery ({
queryKey: staticMirrorKeys.definition,
queryFn: () => apiGet<Definition> ('/static_mirror'), retry: false })
const { mutate: start, isPending: pending, error: creationError } = useMutation ({
mutationFn: () => apiPost<{ job: string }> ('/static_mirror/jobs', { }, { locale }),
onSuccess: result => {
downloadRef.current?.()
setDownloadFailed (false)
setJob (result.job)
} })
const status = useQuery ({
queryKey: staticMirrorKeys.job (job),
queryFn: () => apiGet<Job> (`/static_mirror/jobs/${encodeURIComponent (job!)}`),
enabled: job != null,
retry: false,
refetchInterval: query =>
(query.state.error != null
|| ['ready', 'failed'].includes (query.state.data?.status ?? ''))
? false : 1000 })
const unavailable = isApiError (status.error) && status.error.response?.status === 404
const active = job != null && !unavailable
&& !['ready', 'failed'].includes (status.data?.status ?? '')
const error = creationError ?? status.error ?? definition.error
const errorStatus = isApiError (error) ? error.response?.status : null
const metadata = definition.data
const percentage =
(status.data?.total == null || status.data.total === 0)
? 100
: Math.round (100 * status.data.processed / status.data.total)
const download = () => {
if (job == null) return
downloadRef.current?.()
setDownloadFailed (false)
downloadRef.current = startAPIDownload (
'/static_mirror', job, () => setDownloadFailed (true))
}
return (
<MainArea className="space-y-4">
<PageHead title={message ('title')}/>
<PageTitle>{label ('title')}</PageTitle>
<p>{label ('developmentOnly')} / {label ('currentOnly')}</p>
{metadata != null && (
<dl>
<dt>{label ('limits')}</dt>
<dd>
{label ('counts:resources.posts')} / {label ('counts:resources.tags')}:
{' '}{metadata.resourceLimit}
</dd>
<dd>{label ('counts:columns.names')}: {metadata.nameLimit}</dd>
<dd>{metadata.maxBytes} B / {metadata.maxSeconds} s</dd>
<dt>{label ('concurrency')}</dt>
<dd>{metadata.concurrency} / {metadata.cooldownSeconds} s</dd>
<dd>{label ('zip')}: {metadata.expirySeconds} s</dd>
<dt>{label ('exclusions')}</dt>
<dd>
{['counts:resources.tag_descriptions', 'navigation:help',
'counts:resources.materials', 'counts:resources.nico_tags',
'counts:attributes.parent_post_ids', 'counts:attributes.parent_tag_ids',
'counts:columns.sections', 'navigation:history', 'navigation:edit']
.map (key => <span key={key}>{label (key)}{' / '}</span>)}
</dd>
<dt>{label ('externalAssets')}</dt>
<dd>{label ('externalOmissions')}: {label ('externalMedia')}</dd>
<dt>{label ('protection')}</dt>
<dd>{label ('protectionDetails')}</dd>
</dl>)}
<Button onClick={() => start ()}
disabled={metadata == null || pending || active}>
{label ('generation')}
</Button>
{status.data != null && (
<div role="status">
<p>{label ('dataAt')}: <time>{status.data.dataAt ?? '—'}</time></p>
<p>
{status.data.status === 'ready'
? label ('download')
: label (`counts:exportProgress.${status.data.status}`)}
</p>
{status.data.total != null && (
<p>{label ('counts:exportProgress.measured', {
processed: status.data.processed, total: status.data.total,
percent: percentage })}</p>)}
{status.data.status === 'ready' && (
<Button onClick={download}>{label ('download')}</Button>)}
{status.data.error != null && (
<p role="alert">{label ('failure')}: <code>{status.data.error}</code></p>)}
</div>)}
{error != null && (
<p role="alert">
{errorStatus === 404
? label ('counts:downloadErrors.unavailable')
: (errorStatus != null
? label ('counts:errors.http', { status: errorStatus })
: label ('counts:errors.network'))}
</p>)}
{status.error != null && (
<Button onClick={() => status.refetch ()}>{label ('shared:actions.retry')}</Button>)}
{downloadFailed && <p role="alert">{label ('counts:downloadErrors.failed')}</p>}
</MainArea>)
}
export default StaticMirrorPage