WIP: preserve failed Codex job issue-205-idew24v8

このコミットが含まれているのは:
Codex Night Worker
2026-11-19 12:29:23 +09:00
コミット efcc363537
17個のファイルの変更、639行の追加、2行の削除
+3
ファイルの表示
@@ -83,6 +83,7 @@ const MaterialSyncSuppressionsPage = lazyPage (
() => import ('@/pages/materials/MaterialSyncSuppressionsPage'))
const CountsResourcePage = lazyPage (() => import ('@/pages/counts/CountsResourcePage'))
const MorePage = lazyPage (() => import ('@/pages/MorePage'))
const SubmissionsPage = lazyPage (() => import ('@/pages/SubmissionsPage'))
const GekanatorUnavailablePage = lazyPage (() => import ('@/pages/GekanatorUnavailablePage'))
const NicoTagListPage = lazyPage (() => import ('@/pages/tags/NicoTagListPage'))
const TOSPage = lazyPage (() => import ('@/pages/TOSPage'))
@@ -217,6 +218,8 @@ export const pageRoutes = (
handle: { preload: CountsResourcePage.preload, prefetch: false, robots: 'noindex' } },
{ path: 'more', element: <MorePage/>,
handle: { preload: MorePage.preload, sitemap: ['static'] } },
{ path: 'submissions', element: <SubmissionsPage user={user}/>,
handle: { preload: SubmissionsPage.preload, robots: 'noindex' } },
{ path: '*', element: <NotFound/>, handle: { notFound: true } }]
+2
ファイルの表示
@@ -129,6 +129,8 @@ export const menuOutline = (
{ ...message ('list'), to: '/users', visible: false },
{ ...message ('currentUser'), to: `/users/${ user?.id }`, visible: false },
{ ...message ('settings'), to: '/users/settings', visible: Boolean (user) }] },
{ ...message ('submissions'), visible: false, subMenu: [
{ ...message ('list'), to: '/submissions' }] },
{ ...message ('legal'), visible: false, subMenu: [
{ ...message ('terms'), to: '/tos' }] }]
}
+5
ファイルの表示
@@ -11,6 +11,11 @@ export const localesKeys = {
root: ['locales'] as const,
index: ['locales', 'index'] as const }
export const submissionsKeys = {
root: ['submissions'] as const,
index: (page: number, locale: LocaleCode) =>
['submissions', locale, 'index', page] as const }
export const postsKeys = {
root: ['posts'] as const,
index: (
+24
ファイルの表示
@@ -0,0 +1,24 @@
import { apiGet, apiPost } from '@/lib/api'
import type { LocaleCode } from '@/lib/locales'
import type { Submission, SubmissionCategory } from '@/types'
export type SubmissionIndex = { submissions: Submission[]
count: number
pageSize: number }
export const fetchSubmissions = (
page: number,
locale: LocaleCode,
): Promise<SubmissionIndex> =>
apiGet ('/submissions', { locale, params: { page } })
export const createSubmission = (
attributes: { category: SubmissionCategory
targetId: string
content: string },
locale: LocaleCode,
): Promise<Submission> =>
apiPost ('/submissions', { category: attributes.category,
target_id: attributes.category === 'opinion' ? null : attributes.targetId,
content: attributes.content }, { locale })
+3 -1
ファイルの表示
@@ -26,5 +26,7 @@
"terms": "エイワンケ イレンカ",
"more": "モㇱマ アン ペ »",
"counts": "ウコピㇱキ",
"externalTags": "ソイタ シロシ"
"externalTags": "ソイタ シロシ",
"submissions": "$t(submissions:title)",
"_untranslated": ["submissions"]
}
+14
ファイルの表示
@@ -0,0 +1,14 @@
{
"_untranslated": ["*"],
"title": "申請・御意見板",
"category": "種別",
"targetId": "対象 ID",
"submit": "送信",
"error": "申請の取得に失敗しました.",
"categories": {
"post_removal": "投稿の除票申請",
"tag_removal": "タグの除票申請",
"material_removal": "素材の除票申請",
"opinion": "御意見板"
}
}
+1
ファイルの表示
@@ -25,4 +25,5 @@
"settings": "設定",
"legal": "法規",
"terms": "利用規約",
"submissions": "$t(submissions:title)",
"more": "その他 »" }
+13
ファイルの表示
@@ -0,0 +1,13 @@
{
"title": "申請・御意見板",
"category": "種別",
"targetId": "対象 ID",
"submit": "送信",
"error": "申請の取得に失敗しました.",
"categories": {
"post_removal": "投稿の除票申請",
"tag_removal": "タグの除票申請",
"material_removal": "素材の除票申請",
"opinion": "御意見板"
}
}
+107
ファイルの表示
@@ -0,0 +1,107 @@
import { fireEvent, screen, waitFor } from '@testing-library/react'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import SubmissionsPage from '@/pages/SubmissionsPage'
import { buildUser } from '@/test/factories'
import { renderWithProviders } from '@/test/render'
const api = vi.hoisted (() => (
{ apiGet: vi.fn (), apiPost: vi.fn (), isApiError: vi.fn () }))
const toastApi = vi.hoisted (() => ({ toast: vi.fn () }))
vi.mock ('@/lib/api', () => api)
vi.mock ('@/components/ui/use-toast', () => toastApi)
const opinion = { id: 1,
category: 'opinion',
targetId: null,
content: '<script>public opinion</script>',
user: { id: 2, name: 'reader' },
createdAt: '2026-11-18T00:00:00Z' }
describe ('SubmissionsPage', () => {
beforeEach (() => {
vi.clearAllMocks ()
api.apiGet.mockResolvedValue ({ submissions: [opinion], count: 1, pageSize: 20 })
api.apiPost.mockResolvedValue ({ id: 2 })
api.isApiError.mockReturnValue (false)
})
it ('allows anonymous reading and renders submitted content as plain text', async () => {
const { container } = renderWithProviders (<SubmissionsPage user={null}/>, {
route: '/ja/submissions' })
expect (await screen.findByText (opinion.content)).toBeInTheDocument ()
expect (container.querySelector ('script')).toBeNull ()
expect (screen.getByRole ('button', { name: '送信' })).toBeDisabled ()
})
for (const category of ['post_removal', 'tag_removal', 'material_removal'])
{
it (`submits ${category} for a guest and refreshes the public list`, async () => {
renderWithProviders (<SubmissionsPage user={buildUser ({ role: 'guest' })}/>, {
route: '/ja/submissions' })
await screen.findByText (opinion.content)
fireEvent.change (screen.getByRole ('combobox'), { target: { value: category } })
fireEvent.change (screen.getByLabelText ('対象 ID'), { target: { value: '42' } })
fireEvent.change (screen.getByLabelText ('内容'), { target: { value: '除票の理由' } })
const calls = api.apiGet.mock.calls.length
fireEvent.click (screen.getByRole ('button', { name: '送信' }))
await waitFor (() => {
expect (api.apiPost).toHaveBeenCalledWith ('/submissions', {
category, target_id: '42', content: '除票の理由' }, { locale: 'ja' })
expect (api.apiGet.mock.calls.length).toBeGreaterThan (calls)
expect (screen.getByLabelText ('内容')).toHaveValue ('')
})
})
}
it ('submits opinions without a target and preserves free text', async () => {
renderWithProviders (<SubmissionsPage user={buildUser ()}/>, {
route: '/ja/submissions' })
fireEvent.change (screen.getByLabelText ('対象 ID'), { target: { value: '42' } })
fireEvent.change (screen.getByRole ('combobox'), { target: { value: 'opinion' } })
expect (screen.queryByLabelText ('対象 ID')).not.toBeInTheDocument ()
const content = '空白 を含む,御意見\n二行目'
fireEvent.change (screen.getByLabelText ('内容'), { target: { value: content } })
fireEvent.click (screen.getByRole ('button', { name: '送信' }))
await waitFor (() => {
expect (api.apiPost).toHaveBeenCalledWith ('/submissions', {
category: 'opinion', target_id: null, content }, { locale: 'ja' })
})
})
it ('retains inputs and shows server validation errors', async () => {
api.isApiError.mockReturnValue (true)
api.apiPost.mockRejectedValue ({ response: { status: 422, data: {
type: 'validation_error', errors: { target_id: ['対象が不正です.'] },
base_errors: [] } } })
renderWithProviders (<SubmissionsPage user={buildUser ()}/>, {
route: '/ja/submissions' })
fireEvent.change (screen.getByLabelText ('対象 ID'), { target: { value: '42' } })
fireEvent.change (screen.getByLabelText ('内容'), { target: { value: '理由' } })
fireEvent.click (screen.getByRole ('button', { name: '送信' }))
expect (await screen.findByText ('対象が不正です.')).toBeInTheDocument ()
expect (screen.getByLabelText ('対象 ID')).toHaveAttribute ('aria-invalid', 'true')
expect (screen.getByLabelText ('内容')).toHaveValue ('理由')
})
it ('uses the existing pagination and Japanese fallback language metadata', async () => {
api.apiGet.mockResolvedValue ({ submissions: [], count: 41, pageSize: 20 })
renderWithProviders (<SubmissionsPage user={null}/>, {
route: '/ain-Kana/submissions?page=2' })
await waitFor (() => {
expect (api.apiGet).toHaveBeenCalledWith ('/submissions', {
locale: 'ain-Kana', params: { page: 2 } })
})
expect (await screen.findByRole ('navigation')).toBeInTheDocument ()
expect (screen.getByRole ('option', { name: '御意見板' })).toHaveAttribute ('lang', 'ja')
expect (screen.getByRole ('heading', { name: '申請・御意見板' })).toBeInTheDocument ()
expect (screen.getByRole ('link', { name: '3' }))
.toHaveAttribute ('href', '/ain-Kana/submissions?page=3')
})
})
+153
ファイルの表示
@@ -0,0 +1,153 @@
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { useState } from 'react'
import { useSearchParams } from 'react-router-dom'
import FieldError from '@/components/common/FieldError'
import Form from '@/components/common/Form'
import FormField from '@/components/common/FormField'
import PageHead from '@/components/common/PageHead'
import PageTitle from '@/components/common/PageTitle'
import Pagination from '@/components/common/Pagination'
import TextArea from '@/components/common/TextArea'
import MainArea from '@/components/layout/MainArea'
import { Button } from '@/components/ui/button'
import { toast } from '@/components/ui/use-toast'
import { submissionsKeys } from '@/lib/queryKeys'
import { createSubmission, fetchSubmissions } from '@/lib/submissions'
import { useLocale, useLocaleNavigate } from '@/lib/useLocale'
import { useUITranslation } from '@/lib/useUITranslation'
import { useValidationErrors } from '@/lib/useValidationErrors'
import { inputClass, localisedDateString } from '@/lib/utils'
import type { FC, FormEvent } from 'react'
import type { SubmissionCategory, User } from '@/types'
const CATEGORIES: SubmissionCategory[] = [
'post_removal', 'tag_removal', 'material_removal', 'opinion']
const SubmissionsPage: FC<{ user: User | null }> = ({ user }) => {
const locale = useLocale ()
const navigate = useLocaleNavigate ()
const { message, label } = useUITranslation ('submissions')
const client = useQueryClient ()
const [query] = useSearchParams ()
const pageValue = query.get ('page') ?? ''
const page =
pageValue.match (/^[1-9][0-9]{0,5}$/)?.[0] === pageValue
? Number (pageValue)
: 1
const [category, setCategory] = useState<SubmissionCategory> ('post_removal')
const [targetId, setTargetId] = useState ('')
const [content, setContent] = useState ('')
const { baseErrors, fieldErrors, clearValidationErrors, applyValidationError } =
useValidationErrors<'category' | 'targetId' | 'content'> ()
const { data, isLoading: loading, isError: errorFlg } = useQuery ({
queryKey: submissionsKeys.index (page, locale),
queryFn: () => fetchSubmissions (page, locale) })
const { mutate, isPending: pending } = useMutation ({
mutationFn: () => createSubmission ({ category, targetId, content }, locale),
onSuccess: async () => {
setTargetId ('')
setContent ('')
await client.invalidateQueries ({ queryKey: submissionsKeys.root })
navigate ('/submissions')
toast ({ title: label ('shared:messages.postSuccess') })
},
onError: error => {
applyValidationError (error)
toast ({ title: label ('shared:messages.postFailed') })
} })
const handleSubmit = (event: FormEvent) => {
event.preventDefault ()
if (pending || user == null) return
clearValidationErrors ()
mutate ()
}
return (
<MainArea>
<PageHead title={message ('title')}/>
<div className="mx-auto max-w-3xl space-y-6">
<PageTitle>{label ('title')}</PageTitle>
<form onSubmit={handleSubmit}>
<fieldset disabled={pending || user == null}>
<Form>
<FieldError messages={baseErrors}/>
<FormField label={label ('category')} messages={fieldErrors.category}>
{({ describedBy, invalid }) => (
<select
value={category}
onChange={event => {
setCategory (event.target.value as SubmissionCategory)
setTargetId ('')
clearValidationErrors ()
}}
aria-label={message ('category').text}
aria-describedby={describedBy}
aria-invalid={invalid}
className={inputClass (invalid)}>
{CATEGORIES.map (value => (
<option key={value} value={value}
lang={message (`categories.${value}`).language}>
{message (`categories.${value}`).text}
</option>))}
</select>)}
</FormField>
{category !== 'opinion' && (
<FormField label={label ('targetId')} messages={fieldErrors.targetId}>
{({ describedBy, invalid }) => (
<input
value={targetId}
onChange={event => setTargetId (event.target.value)}
inputMode="numeric"
pattern="[1-9][0-9]*"
required
aria-label={message ('targetId').text}
aria-describedby={describedBy}
aria-invalid={invalid}
className={inputClass (invalid)}/>)}
</FormField>)}
<FormField label={label ('shared:labels.content')} messages={fieldErrors.content}>
{({ describedBy, invalid }) => (
<TextArea
value={content}
onChange={event => setContent (event.target.value)}
required
maxLength={5000}
aria-label={message ('shared:labels.content').text}
aria-describedby={describedBy}
invalid={invalid}/>)}
</FormField>
<Button type="submit">{label ('submit')}</Button>
</Form>
</fieldset>
</form>
{loading && <p>{label ('shared:messages.loading')}</p>}
{errorFlg && <FieldError messages={[label ('error')]}/>}
<div className="space-y-4">
{data?.submissions.map (submission => (
<article key={submission.id} className="border-b pb-4">
<h2 className="font-semibold">
{label (`categories.${submission.category}`)}
</h2>
{submission.targetId != null && (
<p>{label ('targetId')}: {submission.targetId}</p>)}
<p className="whitespace-pre-wrap break-words">{submission.content}</p>
<div className="text-sm">
{submission.user.name || label ('shared:labels.anonymous')}
{' / '}
<time dateTime={submission.createdAt} lang={locale}>
{localisedDateString (submission.createdAt, locale)}
</time>
</div>
</article>))}
</div>
{data != null && data.count > data.pageSize && (
<Pagination page={page} totalPages={Math.ceil (data.count / data.pageSize)}/>)}
</div>
</MainArea>)
}
export default SubmissionsPage
+13
ファイルの表示
@@ -10,6 +10,19 @@ import type { LocaleCode } from '@/lib/locales'
export type Category = typeof CATEGORIES[number]
export type SubmissionCategory =
| 'post_removal'
| 'tag_removal'
| 'material_removal'
| 'opinion'
export type Submission = { id: number
category: SubmissionCategory
targetId: number | null
content: string
user: Pick<User, 'id' | 'name'>
createdAt: string }
export type Deerjikist = { platform: Platform; code: string }
export type FetchPostsOrder = `${ FetchPostsOrderField }:${ 'asc' | 'desc' }`