Skip to content
Open
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
46 changes: 46 additions & 0 deletions web/e2e/stories/app-delete.mock.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Route } from '@playwright/test'
import { test, expect, seed, captureWrite, withExpectedFailures } from '../support/fixtures'

test.describe('App delete @app', () => {
Expand Down Expand Up @@ -69,4 +70,49 @@ test.describe('App delete @app', () => {
await expect(main.getByText(appPath, { exact: true })).toBeVisible()
await expect(page.getByRole('heading', { level: 1, name: app.name, exact: true })).toHaveCount(0)
})

// APT-1234: Platform refuses to delete an app that still has work areas (412 `branch_has_active_delivery`, the
// blockers counted by kind). Only that answer is rewritten in the browser; once they are gone the same dialog
// deletes the app.
test('a deletion stopped by the app\'s remaining work areas says what blocks it and what to do, never the platform\'s message @mock @story', async ({ page, mock }, testInfo) => {
void mock
const app = seed.apps.keihi
const stackPath = `/api/v1/projects/${seed.projectId}/application-stacks/${app.slug}`
const deletes: number[] = []
await page.route(`**${stackPath}`, (route: Route) => {
if (route.request().method() !== 'DELETE') return route.continue()
deletes.push(412)
return route.fulfill({ status: 412, json: { error: { code: 'failed_precondition', message: 'application branch still has active delivery consumers', details: {
reason: 'branch_has_active_delivery',
activeConsumers: [{ kind: 'DevWorkspace', count: 2 }],
nextActions: ['Stop or delete the listed delivery consumers, then retry the Application Branch deletion.'],
} } } })
})

await page.goto(`/${app.groupPath}/${app.slug}/-/settings`)
await expect(page.getByRole('heading', { level: 1, name: app.name, exact: true })).toBeVisible()
await expect(page.getByTestId('env-table').getByRole('row').filter({ hasText: 'APP_TITLE' })).toContainText(app.slug)
await page.getByRole('region', { name: '危険な操作', exact: true }).getByRole('button', { name: '削除する', exact: true }).click()
const dialog = page.getByRole('dialog', { name: `「${app.name}」を削除しますか?`, exact: true })
await dialog.getByLabel(`確認のため「${app.name}」と入力してください。`, { exact: true }).fill(app.name)
const confirm = dialog.getByRole('button', { name: '完全に削除する', exact: true })

await withExpectedFailures([{ method: 'DELETE', path: stackPath, status: 412, count: 1, reason: 'the app still has work areas' }], async () => {
await confirm.click()
const refusal = dialog.getByRole('alert')
await expect(refusal).toContainText('このアプリにはまだ残っているものがあるため、削除できませんでした')
await expect(refusal).toContainText('このアプリの作業場所が 2 か所残っています。')
await expect(refusal).toContainText('この画面からは片づけられません。基盤の担当者に片づけてもらってから、もう一度「完全に削除する」を押してください。')
})
for (const word of ['application branch', 'delivery consumers', 'DevWorkspace', '操作に失敗しました']) await expect(dialog.getByText(word)).toHaveCount(0)
expect(deletes).toEqual([412])
expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true)
await page.screenshot({ path: testInfo.outputPath('delete-blocked.png'), fullPage: true })

// The work areas are gone: the same dialog deletes the app.
await page.unroute(`**${stackPath}`)
await confirm.click()
await expect(page).toHaveURL(`/${app.groupPath}`)
await expect(page.getByRole('main').getByRole('link', { name: new RegExp(app.name) })).toHaveCount(0)
})
})
89 changes: 89 additions & 0 deletions web/e2e/stories/improve-start-refused.mock.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import type { APIRequestContext, Route } from '@playwright/test'
import { test, expect, seed, withExpectedFailures, type MockControl } from '../support/fixtures'

// APT-1232: Platform refuses a new improvement run while the session's proposal awaits the owner's review or is
// closed (409 `source_change_proposal_run_blocked`). A start the page still offered (its last read of the proposal
// was older than the refusal) is answered on screen in the user's words, once, with no retry; and while the
// proposal awaits review or is closed, the change card explains why instead of offering 「この内容で直す」. Only the
// proposal read is rewritten in the browser (an older phase, as an earlier read showed it); the mock answers the start.
const project = `/api/v1/projects/${seed.projectId}`
const PENDING = { title: '提案の確認を待っています', reason: '所有者が提案を確認しているあいだは、作業を進められません。やり直しを求められたら、そこから続けられます。' }
const CLOSED = { title: 'この提案は締め切られています', reason: '反映・見送り・取り下げ・期限切れのどれかで終わっていて、この提案では続けられません。続けて直すときは、アプリの画面の「AIで直す」から始めてください。' }

/**
* 山田 (an owner of 見積作成, so also its reviewer) improves it until the proposal awaits review, asks for changes,
* talks a new change through (the conversation shows it with 「この内容で直す」), and sends the proposal back for review.
*/
async function changeAwaitingReview(request: APIRequestContext, mock: MockControl): Promise<{ draftId: string; proposalPath: string }> {
const created = await (await request.post(`${project}/application-drafts`, { data: { kind: 'improvement', applicationStackId: seed.apps.mitsumori.slug, title: seed.apps.mitsumori.name, intent: '一覧に絞り込みを足したい' } })).json()
const draftPath = `${project}/application-drafts/${created.id as string}`
const talk = async (messages: string[]) => {
for (const message of messages) {
expect((await request.post(`${draftPath}/conversation-turns`, { data: { message } })).ok()).toBe(true)
await mock.advance()
}
}
await talk(['一覧に絞り込みを足したい', '状態で絞り込みたい'])
expect((await request.post(`${draftPath}/implementation-runs`, { data: {} })).ok()).toBe(true)
for (let i = 0; i < 12; i++) await mock.advance()
const proposalPath = `${project}/source-change-proposals/${(await (await request.get(draftPath)).json()).proposalId as string}`
expect((await (await request.get(proposalPath)).json()).phase).toBe('Proposed')
expect((await request.post(`${proposalPath}/decisions`, { data: { decision: 'RequestChanges', comment: '今月の分も表示してください' } })).ok()).toBe(true)
await talk(['CSV で書き出したい', '今月の分だけ'])
expect((await request.post(`${proposalPath}/submit`)).ok()).toBe(true)
expect((await (await request.get(proposalPath)).json()).phase).toBe('Proposed')
return { draftId: created.id as string, proposalPath }
}

test.describe('improvement start refused @improve', () => {
test.afterEach(async ({ page }) => {
await page.unrouteAll({ behavior: 'ignoreErrors' })
})

test('a refused start is said once in the user\'s words with no retry; a waiting or closed proposal explains instead of offering 「この内容で直す」 @mock @story', async ({ page, request, mock }, testInfo) => {
test.setTimeout(90_000)
const { draftId, proposalPath } = await changeAwaitingReview(request, mock)
// The page's last read of the proposal still shows it sent back for changes.
let stale = true
await page.route(`**${proposalPath}`, async (route: Route) => {
if (route.request().method() !== 'GET' || !stale) return route.continue()
const response = await route.fetch()
return route.fulfill({ response, json: { ...(await response.json()), phase: 'ChangesRequested' } })
})
const starts: number[] = []
page.on('response', (response) => {
if (response.request().method() === 'POST' && new URL(response.url()).pathname === `${project}/application-drafts/${draftId}/implementation-runs`) starts.push(response.status())
})

await page.goto(`/-/improve/${draftId}`)
const card = page.getByTestId('improve-proposal')
const start = card.getByRole('button', { name: 'この内容で直す', exact: true })
await expect(start).toBeEnabled()

await withExpectedFailures([{ method: 'POST', path: `${project}/application-drafts/{draftId}/implementation-runs`, status: 409, count: 1, reason: 'Platform refuses a new run while the proposal awaits review' }], async () => {
await start.click()
const refusal = card.getByRole('alert')
await expect(refusal).toContainText(PENDING.title)
await expect(refusal).toContainText(PENDING.reason)
})
await expect(card.getByRole('button', { name: 'もう一度試す', exact: true })).toHaveCount(0)
await expect(start).toBeDisabled()
await expect(page.getByText('source change proposal')).toHaveCount(0)
expect(starts).toEqual([409])
expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true)
await page.screenshot({ path: testInfo.outputPath('start-refused.png'), fullPage: true })

// The next read shows the proposal awaiting review: the card explains, and 「この内容で直す」 is not offered.
stale = false
await expect(card.getByRole('status').filter({ hasText: PENDING.title })).toContainText(PENDING.reason, { timeout: 15_000 })
await expect(card.getByRole('button')).toHaveCount(0)
await expect(card.getByRole('alert')).toHaveCount(0)

// The owner declines: the card says the proposal is closed and where to start again; nothing is sent.
expect((await request.post(`${proposalPath}/decisions`, { data: { decision: 'Reject' } })).ok()).toBe(true)
await expect(card.getByRole('status').filter({ hasText: CLOSED.title })).toContainText(CLOSED.reason, { timeout: 15_000 })
await expect(card.getByRole('button')).toHaveCount(0)
await page.screenshot({ path: testInfo.outputPath('proposal-closed.png'), fullPage: true })
expect(starts).toEqual([409])
})
})
13 changes: 13 additions & 0 deletions web/src/copy/apps.en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ export const appsEn: typeof apps = {
deleteKeepsRepository: (repository?: string) =>
repository ? `Your code on GitHub (${repository}) will be kept.` : 'Your code on GitHub will be kept.',
deleteSourceBusy: 'The app has stopped but is still connected to your code; wait a moment, then choose “Delete permanently” again.',
deleteRefused: {
inUse: 'Some parts of this app are still left, so it was not deleted',
workAreas: (count: number) => `This app still has ${count === 1 ? '1 work area' : `${count} work areas`} left.`,
workAreasNext: 'They cannot be cleared from this screen. Ask your administrator to clear them, then choose “Delete permanently” again.',
others: 'Something else connected to this app is still left.',
othersNext: 'Wait a moment, then choose “Delete permanently” again. If this continues, contact your administrator.',
waiting: 'The app is not ready to be deleted yet',
waitingWorkAreas: (count: number) => `${count === 1 ? '1 work area' : `${count} work areas`} of this app ${count === 1 ? 'is' : 'are'} being cleared.`,
waitingOthers: 'Things connected to this app are being cleared.',
waitingNext: 'Wait a moment, then choose “Delete permanently” again.',
failed: 'The app could not be deleted',
failedNext: 'Wait a moment, then choose “Delete permanently” again. If this continues, contact your administrator.',
},
deleteAction: 'Delete',
deleteConfirm: 'Delete permanently',
deleting: 'Deleting…',
Expand Down
19 changes: 19 additions & 0 deletions web/src/copy/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,25 @@ export const apps = {
deleteKeepsRepository: (repository?: string) =>
repository ? `GitHub の置き場(${repository})は消さずに残ります。` : 'GitHub の置き場は消さずに残ります。',
deleteSourceBusy: 'アプリは止めましたが、置き場とのつながりをまだ外せていません。少し待ってから、もう一度「完全に削除する」を押してください。',
/**
* Platform refused the deletion: something of the app is still left (`inUse`; its work areas are named and
* counted, whatever made them and whether or not they run, and nothing in the console removes them) or is
* still being removed (`waiting`: the user presses again shortly; the console does not wait on its own).
* Never Platform's own message.
*/
deleteRefused: {
inUse: 'このアプリにはまだ残っているものがあるため、削除できませんでした',
workAreas: (count: number) => `このアプリの作業場所が ${count} か所残っています。`,
workAreasNext: 'この画面からは片づけられません。基盤の担当者に片づけてもらってから、もう一度「完全に削除する」を押してください。',
others: 'このアプリにつながっている、ほかのものがまだ残っています。',
othersNext: '少し待ってから、もう一度「完全に削除する」を押してください。続くときは基盤の担当者に相談してください。',
waiting: '削除の準備がまだ終わっていません',
waitingWorkAreas: (count: number) => `このアプリの作業場所 ${count} か所を片づけています。`,
waitingOthers: 'このアプリにつながっているものを片づけています。',
waitingNext: '少し待ってから、もう一度「完全に削除する」を押してください。',
failed: '削除できませんでした',
failedNext: '少し待ってから、もう一度「完全に削除する」を押してください。続くときは基盤の担当者に相談してください。',
},
deleteAction: '削除する',
deleteConfirm: '完全に削除する',
deleting: '削除しています…',
Expand Down
3 changes: 2 additions & 1 deletion web/src/dev/mock-improve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ test('question → proposal → run → review, in the application workspace', a
expect(current.proposalId).toBeDefined()
const proposalPath = `${project}/source-change-proposals/${current.proposalId}`
expect((await call('GET', proposalPath)).body.phase).toBe('Proposed')
expect((await call('POST', `${path}/implementation-runs`)).status).toBe(409)
// Like Platform, a start while the proposal awaits review is refused with its own code (not another tab's `conflict`).
expect(await call('POST', `${path}/implementation-runs`)).toMatchObject({ status: 409, body: { error: { code: 'source_change_proposal_run_blocked' } } })
expect((await call('POST', `${proposalPath}/decisions`, { decision: 'RequestChanges', comment: '今月の分も表示してください' })).status).toBe(200)

// The next request starts over with a question, then a new proposal with new tasks.
Expand Down
4 changes: 3 additions & 1 deletion web/src/dev/mock-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2306,7 +2306,9 @@ const routes: Array<[method: string, pattern: RegExp, handler: Handler]> = [
if (!draft) return error(404, 'not_found', 'application draft not found')
if (state.role === 'Viewer') return error(403, 'forbidden', 'team role Viewer cannot implement applications')
const proposal = draft.proposalId ? state.proposals.get(draft.proposalId) : undefined
if (proposal && (proposalWaiting(proposal.phase) || proposalTerminal(proposal.phase))) return error(409, 'conflict', 'proposal is awaiting review or is closed')
// Like platform-api (application_draft_proposal.go admitImprovementImplementation): a run starts only while the
// proposal is drafted or sent back for changes (not in ApplyFailed either), refused with its own code.
if (proposal && proposal.phase !== 'Drafting' && proposal.phase !== 'ChangesRequested') return error(409, 'source_change_proposal_run_blocked', 'source change proposal is awaiting review, applying, or closed')
const handoff = draft.creationPlan?.implementationHandoff
if (draft.phase !== 'created' || !draft.createdApplicationId || !handoff?.tasks.length) return error(412, 'failed_precondition', 'created application and handoff tasks are required')
const previous = draft.implementationRuns?.at(-1)
Expand Down
Loading
Loading