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
34 changes: 34 additions & 0 deletions web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,40 @@ entries are unaffected. Only the image entry shows the existing registry
prerequisite. Successful reads are unchanged. Registry 401, 5xx, network and
contract failures—and every failure of the other reads—still fail the query.

## 自分の作業場所 (My workspaces)

The header's laptop icon (badge: running count) opens a drawer with the
caller's own DevWorkspaces, read from `GET dev-workspaces?owner=me`
(`@appthrust/api-schema` ≥ 0.1.8). Admin work, Project policy and other
people's workspaces stay in the Dashboard. `src/features/workspaces/` holds the
drawer, the delete dialog, the lease hint and their model; the reader keeps only
the fields the drawer shows, with open `state`, `scope` and source volume state
(a server without `state` reads the state its phase stands for).

- Groups: 動いている (Ready, Degraded, Committing, Starting), 休止中 (Sleeping)
and 停止・使用終了・失敗 (everything else, including states this console does
not know). Each row: name, state, target and one line — the lease countdown,
when the source data is released, 「停止した作業場所のデータは、削除するまで残ります」
or, for Retired, when Platform deletes it.
- Actions come only from `allowedActions`: 開く/再開する (`open`, to the AI
session page that uses the workspace, else its draft's build page; no page, no
action), 延長する (`extendLease`, immediate), 停止する (`stop`, confirmed),
再開する on a Stopped or Failed row (`start` or `restart`: there is no start
route, so both call restart) and 削除する (`delete`, not offered on running
rows). Retired workspaces cannot run again (both are false) and are deleted by Platform.
- The header line comes from `summary`; 片づける (shown while
`idleRetained > 0`) checks the idle Sleeping and Stopped rows by the server's
rule over `idleAfter`. Delete repeats the Dashboard warning (unpushed changes are
lost; rows without a pushed branch or pull request are named) and sends one
`DELETE` per row with its own `Idempotency-Key`, reused by 失敗したものをもう一度.
- The build and improve session headers show the session workspace's lease
(「あと 12 分で休止」, warning color from five minutes before); the owner
extends it with one click.

The list is re-read every 30 seconds. The mock seeds six workspaces for 山田
(Running 2, Sleeping 2, Stopped 1, Retired 1); see the top of
`src/dev/mock-platform.ts`.


## Excel から作る

Expand Down
4 changes: 2 additions & 2 deletions web/bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions web/e2e/stories/my-workspaces.mock.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { test, expect, seed, captureWrite } from '../support/fixtures'

const workspaces = `/api/v1/projects/${seed.projectId}/dev-workspaces`

test.describe('My workspaces @workspaces', () => {
test('opens my workspaces in three groups, extends a lease, shows a Retired row, and deletes idle ones behind the unpushed-changes warning @mock @story', async ({ page }) => {
await page.goto('/')
// The header entry carries the running count (Ready + Degraded of the six seeded workspaces).
const entry = page.getByRole('button', { name: '自分の作業場所(動いているもの 2 件)', exact: true })
await expect(entry).toBeVisible()
await expect(page.getByTestId('my-workspaces-badge')).toHaveText('2')
await entry.click()

const drawer = page.getByRole('dialog', { name: '自分の作業場所', exact: true })
await expect(drawer.getByTestId('my-workspaces-summary')).toHaveText('データを残している作業場所 6 件 · 7 日以上使っていないもの 2 件')
const group = (name: string) => drawer.getByRole('region', { name: new RegExp(`^${name}`) })
const running = group('動いている')
const sleeping = group('休止中')
const other = group('停止・使用終了・失敗')
await expect(running.getByRole('listitem')).toHaveCount(2)
await expect(sleeping.getByRole('listitem')).toHaveCount(2)
await expect(other.getByRole('listitem')).toHaveCount(2)

// Running rows: the lease countdown, the Degraded one inside the five-minute warning.
const ready = drawer.locator('[data-workspace-id="devws-mitsumori-fix"]')
await expect(ready.getByTestId('workspace-line')).toHaveText(/^あと 4[12] 分で休止します$/)
const degraded = drawer.locator('[data-workspace-id="devws-nippo-filter"]')
await expect(degraded.getByTestId('workspace-line')).toHaveText(/^あと [1-3] 分で休止します$/)
await expect(degraded.getByTestId('workspace-line')).toHaveClass(/text-busy-ink/)
// Sleeping: resumable, with when its data is released; running rows cannot be chosen for deletion.
await expect(sleeping.getByRole('listitem').first()).toContainText(/データは .+ まで残ります/)
await expect(running.getByRole('checkbox')).toHaveCount(0)

// Extend lease: immediate, with Idempotency-Key, and the row shows the renewed hour.
const extended = await captureWrite(page, 'POST', `${workspaces}/devws-mitsumori-fix/extend-lease`, () =>
ready.getByRole('button', { name: '「見積の明細を直す」を延長する', exact: true }).click())
expect(await extended.request.headerValue('idempotency-key')).toBeTruthy()
expect((await extended.request.response())?.status()).toBe(202)
await expect(drawer.getByRole('status').filter({ hasText: '「見積の明細を直す」の休止までの時間を延ばしました。' })).toBeVisible()
await expect(ready.getByTestId('workspace-line')).toHaveText(/^あと (60|59) 分で休止します$/)

// Stopped: Platform allows `start` (not `restart`); there is no start route, so 再開する calls restart. It sits beside 削除する.
const stopped = drawer.locator('[data-workspace-id="devws-kintai-csv"]')
await expect(stopped.getByRole('button')).toHaveText(['再開する', '削除する'])
await expect(stopped.getByRole('button', { name: '「勤怠を CSV で出す」を再開する', exact: true })).toBeEnabled()

// Retired: unusable, deleted by Platform on its date; deleting is the only action.
const retired = drawer.locator('[data-workspace-id="devws-mitsumori-old"]')
await expect(retired).toContainText('使用終了')
await expect(retired.getByTestId('workspace-line')).toHaveText(/^もう使えません。.+ に自動で削除されます。$/)
await expect(retired.getByRole('button')).toHaveText(['削除する'])
await expect(retired.getByRole('link')).toHaveCount(0)

// 片づける checks the idle Sleeping and Stopped rows, never the Retired one.
await drawer.getByRole('button', { name: '片づける', exact: true }).click()
await expect(drawer.getByRole('checkbox', { name: '「売上ダッシュボード」を選ぶ', exact: true })).toBeChecked()
await expect(drawer.getByRole('checkbox', { name: '「勤怠を CSV で出す」を選ぶ', exact: true })).toBeChecked()
await expect(drawer.getByRole('checkbox', { name: '「経費に領収書を添付する」を選ぶ', exact: true })).not.toBeChecked()
await expect(drawer.getByRole('checkbox', { name: '「見積の旧作業場所」を選ぶ', exact: true })).not.toBeChecked()

// Delete: the Dashboard's warning, and rows whose work never left the workspace are named.
await drawer.getByRole('button', { name: '選んだ 2 件を削除', exact: true }).click()
const confirm = page.getByRole('dialog', { name: '作業場所 2 件を削除しますか?', exact: true })
await expect(confirm).toContainText('置き場に送っていない変更は消えます。')
await expect(confirm).toContainText('2 件は置き場に送っていません。変更はこの作業場所にしかありません。')
const rows = confirm.getByRole('list', { name: '削除する作業場所', exact: true }).getByRole('listitem')
await expect(rows).toHaveCount(2)
await expect(rows.filter({ hasText: '置き場に未送信' })).toHaveCount(2)

const deletes = ['devws-uriage-board', 'devws-kintai-csv'].map((id) =>
page.waitForResponse((response) => response.request().method() === 'DELETE' && new URL(response.url()).pathname === `${workspaces}/${id}`))
await confirm.getByRole('button', { name: '2 件を削除する', exact: true }).click()
for (const response of await Promise.all(deletes)) {
expect(response.status()).toBe(202)
expect(await response.request().headerValue('idempotency-key')).toBeTruthy()
}
await expect(rows.filter({ hasText: '削除を受け付けました' })).toHaveCount(2)
// The footer's 閉じる replaces 削除する once the run is over (the header ✕ is the other 閉じる).
await expect(confirm.getByRole('button', { name: '閉じる', exact: true })).toHaveCount(2)
await confirm.getByRole('button', { name: '閉じる', exact: true }).last().click()
await expect(confirm).toBeHidden()
await expect(drawer.locator('[data-workspace-id="devws-uriage-board"], [data-workspace-id="devws-kintai-csv"]')).toHaveCount(0)
await expect(drawer.getByTestId('my-workspaces-summary')).toHaveText('データを残している作業場所 4 件 · 7 日以上使っていないもの 0 件')
await expect(drawer.getByRole('button', { name: '片づける', exact: true })).toHaveCount(0)
})
})
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"test:e2e:mock": "playwright test --config e2e/playwright.config.ts --grep @mock"
},
"dependencies": {
"@appthrust/api-schema": "^0.1.7",
"@appthrust/api-schema": "^0.1.8",
"@appthrust/app-launcher": "^0.1.5",
"@appthrust/platform-dashboard-i18n": "^0.1.5",
"@orpc/client": "^1.13.13",
Expand Down
66 changes: 65 additions & 1 deletion web/src/api/contracts/platform/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { describe, expect, test } from 'bun:test'
import { isOneOf, type PreviewWorkspace } from '../../../model/contracts/build'
import { previewDatabaseStatus } from '../../../features/build/implement/runtime'
import { assertWireContractCases } from '../../testing/wire-contract-cases'
import { getDevWorkspaceContract, restartDevWorkspaceContract } from './workspace'
import type { MyWorkspace } from '../../../model/contracts/workspace'
import { deleteDevWorkspaceContract, extendDevWorkspaceLeaseContract, getDevWorkspaceContract, listDevWorkspacesContract, restartDevWorkspaceContract, stopDevWorkspaceContract } from './workspace'

const SECRET = 'SENTINEL-workspace-91d4'
const at = '2026-11-13T00:00:00Z'
Expand Down Expand Up @@ -100,3 +101,66 @@ describe('DevWorkspace restart (platformApiRestartDevWorkspace)', () => {
])
})
})

/** A row of `GET dev-workspaces?owner=me` as Platform 0.1.8 marshals it (`state`, `lease`, `allowedActions`, `sourceVolume`). */
const actions = { open: true, stop: true, start: false, restart: true, extendLease: true, keepLonger: false, delete: true, commit: true, blockedBy: {} }
const wireRow = {
...wireWorkspace, ownedByCaller: true, state: 'Ready', lastActivityAt: at,
lease: { lastActivityAt: at, expiresAt: '2026-11-13T01:00:00Z', ttlSeconds: 3600, source: 'default' },
sourceVolume: { state: 'Retained', releaseAt: '2026-11-20T00:00:00Z', retention: { class: null, project: null, effective: null, source: 'none', policyValid: true } },
runtime: { ready: true, editorReady: true, previewReady: true, codexReady: true, claudeReady: false, sandboxRuntime: 'GVisor' },
allowedActions: actions,
}
const domainRow: MyWorkspace = {
id: 'ws-1', projectId: 'project-1', displayName: '見積の作業場所', draftId: 'draft-1', ownedByCaller: true, lastActivityAt: at,
scope: { kind: 'known', value: 'applicationDraft' }, state: { kind: 'known', value: 'Ready' },
lease: { lastActivityAt: at, expiresAt: '2026-11-13T01:00:00Z', ttlSeconds: 3600 },
sourceVolume: { state: { kind: 'known', value: 'Retained' }, releaseAt: '2026-11-20T00:00:00Z' },
allowedActions: actions,
}
const summary = { total: 1, active: 1, sleeping: 0, stopped: 0, retainedSourceVolumes: 1, idleRetained: 0, degraded: 0, retired: 0 }
const wireList = { data: [wireRow], meta: { total: 1 }, summary, idleAfter: '168h0m0s' }
const listWith = (row: unknown) => ({ ...wireList, data: [row] })

describe('My workspaces list (platformApiListDevWorkspaces, owner=me)', () => {
test('wire variants', () => {
assertWireContractCases(listDevWorkspacesContract, [
{ name: 'a row keeps only what the drawer shows', variant: 'present', path: '/', wire: wireList, expect: { accept: true, value: { data: [domainRow], summary, idleAfter: '168h0m0s' } } },
{ name: 'no workspaces', variant: 'empty', path: '/data', wire: { ...wireList, data: [], summary: { ...summary, total: 0, active: 0, retainedSourceVolumes: 0 } }, expect: { accept: true, check: (list) => expect(list.data).toEqual([]) } },
{ name: 'an unknown state is unknown, never running', variant: 'unknown', path: '/data/*/state', wire: listWith({ ...wireRow, state: SECRET }), expect: { accept: true, check: (list) => expect(list.data[0]?.state).toEqual({ kind: 'unknown' }) } },
{ name: 'a server without `state` reads the state its phase stands for', variant: 'absent', path: '/data/*/state', wire: listWith({ ...wireRow, state: undefined, phase: 'Stopping' }), expect: { accept: true, check: (list) => expect(list.data[0]?.state).toEqual({ kind: 'known', value: 'Stopped' }) } },
{ name: 'without `state`, an unknown phase is an unknown state', variant: 'unknown', path: '/data/*/phase', wire: listWith({ ...wireRow, state: undefined, phase: SECRET }), expect: { accept: true, check: (list) => expect(list.data[0]?.state).toEqual({ kind: 'unknown' }) } },
{ name: 'an unknown scope is unknown', variant: 'unknown', path: '/data/*/scope', wire: listWith({ ...wireRow, scope: SECRET }), expect: { accept: true, check: (list) => expect(list.data[0]?.scope).toEqual({ kind: 'unknown' }) } },
{ name: 'an unknown source volume state is unknown', variant: 'unknown', path: '/data/*/sourceVolume/state', wire: listWith({ ...wireRow, sourceVolume: { state: SECRET } }), expect: { accept: true, check: (list) => expect(list.data[0]?.sourceVolume?.state).toEqual({ kind: 'unknown' }) } },
{ name: 'an unknown lease source or sandbox runtime does not break the row', variant: 'unknown', path: '/data/*/lease/source', wire: listWith({ ...wireRow, lease: { ...wireRow.lease, source: SECRET }, runtime: { ...wireRow.runtime, sandboxRuntime: SECRET } }), expect: { accept: true, check: (list) => expect(list.data[0]?.lease).toEqual(domainRow.lease) } },
{ name: 'a server without allowed actions offers none', variant: 'absent', path: '/data/*/allowedActions', wire: listWith({ ...wireRow, allowedActions: undefined }), expect: { accept: true, check: (list) => expect(list.data[0]?.allowedActions).toBeUndefined() } },
{ name: 'a Retired row keeps when Platform deletes it', variant: 'present', path: '/data/*/retired', wire: listWith({ ...wireRow, state: 'Retired', phase: 'Failed', retired: { at, reason: 'RuntimeTargetReplaced', deleteAt: '2026-11-20T00:00:00Z' } }), expect: { accept: true, check: (list) => { expect(list.data[0]?.state).toEqual({ kind: 'known', value: 'Retired' }); expect(list.data[0]?.retired?.deleteAt).toBe('2026-11-20T00:00:00Z') } } },
{ name: 'broken allowed actions are broken, not "nothing allowed"', variant: 'unknown', path: '/data/*/allowedActions', wire: listWith({ ...wireRow, allowedActions: { ...actions, delete: SECRET } }), expect: { accept: false, issues: [{ path: '/data/*/allowedActions/delete', code: 'invalid_type' }] } },
{ name: 'a summary is required', variant: 'absent', path: '/summary', wire: { ...wireList, summary: undefined }, expect: { accept: false, issues: [{ path: '/summary', code: 'missing' }] } },
{ name: 'idleAfter is required', variant: 'absent', path: '/idleAfter', wire: { ...wireList, idleAfter: undefined }, expect: { accept: false, issues: [{ path: '/idleAfter', code: 'missing' }] } },
{ name: 'null data is broken', variant: 'null', path: '/data', wire: { ...wireList, data: null }, expect: { accept: false, issues: [{ path: '/data', code: 'invalid_type' }] } },
])
})
})

describe('My workspaces writes (extend-lease, stop, delete)', () => {
const operation = { id: 'op-2', type: 'devWorkspace.extendLease', state: 'accepted', writeChannel: 'A', resource: { kind: 'DevWorkspace', id: 'ws-1', projectId: 'project-1' }, createdAt: at, links: { self: '/api/v1/operations/op-2' } }
const wireWrite = { ...wireRow, operation, resource: wireRow }

test('extend-lease and stop read the written row', () => {
for (const contract of [extendDevWorkspaceLeaseContract, stopDevWorkspaceContract]) {
assertWireContractCases(contract, [
{ name: 'the written workspace is the answer\'s resource', variant: 'present', path: '/resource', wire: wireWrite, expect: { accept: true, value: domainRow } },
{ name: 'an answer without its resource is broken', variant: 'absent', path: '/resource', wire: { ...wireRow, operation }, expect: { accept: false, issues: [{ path: '/resource', code: 'missing' }] } },
{ name: 'an unknown state of the written workspace is unknown', variant: 'unknown', path: '/resource/state', wire: { ...wireWrite, resource: { ...wireRow, state: SECRET } }, expect: { accept: true, check: (workspace) => expect(workspace.state).toEqual({ kind: 'unknown' }) } },
])
}
})

test('delete reads the accepted workspace id', () => {
assertWireContractCases(deleteDevWorkspaceContract, [
{ name: 'the receipt names the workspace', variant: 'present', path: '/operation', wire: { pendingSync: false, operation: { ...operation, type: 'devWorkspace.delete' } }, expect: { accept: true, value: { id: 'ws-1' } } },
{ name: 'an answer without its receipt is broken', variant: 'absent', path: '/operation', wire: { pendingSync: false }, expect: { accept: false, issues: [{ path: '/operation', code: 'missing' }] } },
])
})
})
Loading