fix: make hosted downloads controllable and failures diagnosable
Sync source to CNB / Sync Git ref (push) Skipped
Axolotl desktop CI / guardrails (push) Canceled after 0s
Axolotl desktop CI / desktop (macos-latest) (push) Canceled after 0s
Axolotl desktop CI / desktop (ubuntu-latest) (push) Canceled after 0s
Axolotl desktop CI / desktop (windows-latest) (push) Canceled after 0s
Axolotl desktop CI / website (push) Canceled after 0s
Repository checks / typos (push) Canceled after 0s
Repository checks / tombi (push) Canceled after 0s
Rust checks / shear (push) Canceled after 0s
Sync source to CNB / Sync Git ref (push) Skipped
Axolotl desktop CI / guardrails (push) Canceled after 0s
Axolotl desktop CI / desktop (macos-latest) (push) Canceled after 0s
Axolotl desktop CI / desktop (ubuntu-latest) (push) Canceled after 0s
Axolotl desktop CI / desktop (windows-latest) (push) Canceled after 0s
Axolotl desktop CI / website (push) Canceled after 0s
Repository checks / typos (push) Canceled after 0s
Repository checks / tombi (push) Canceled after 0s
Rust checks / shear (push) Canceled after 0s
This commit is contained in:
1 parent
1838afce56
commit
bf95d715a4
17 files changed
+848
-72
No files matched your search
@@ -0,0 +1,96 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import test from 'node:test'
|
||||
|
||||
import {
|
||||
hostedDownloadActions,
|
||||
hostedDownloadState,
|
||||
runHostedDownloadAction,
|
||||
runHostedDownloadControl,
|
||||
} from './hosted-download-controls.ts'
|
||||
|
||||
test('only a controllable parent hosted task offers pause, resume and stop', () => {
|
||||
const bar = {
|
||||
bar_type: {
|
||||
type: 'hosted_pack_sync',
|
||||
instance_id: 'one',
|
||||
state: 'running' as const,
|
||||
can_pause: true,
|
||||
can_cancel: true,
|
||||
},
|
||||
}
|
||||
assert.deepEqual(hostedDownloadActions(bar), ['pause', 'cancel'])
|
||||
assert.deepEqual(hostedDownloadActions({ bar_type: { ...bar.bar_type, state: 'paused' } }), [
|
||||
'resume',
|
||||
'cancel',
|
||||
])
|
||||
for (const state of ['finalizing', 'canceling'] as const) {
|
||||
assert.deepEqual(hostedDownloadActions({ bar_type: { ...bar.bar_type, state } }), [])
|
||||
}
|
||||
assert.deepEqual(
|
||||
hostedDownloadActions({ bar_type: { ...bar.bar_type, type: 'hosted_mod_download' } }),
|
||||
[],
|
||||
)
|
||||
assert.deepEqual(
|
||||
hostedDownloadActions({ bar_type: { type: 'hosted_pack_sync', instance_id: 'one' } }),
|
||||
[],
|
||||
)
|
||||
})
|
||||
|
||||
test('failed and canceled hosted tasks offer direct retry, preserving terminal state', () => {
|
||||
for (const state of ['failed', 'canceled'] as const) {
|
||||
const bar = {
|
||||
bar_type: { type: 'hosted_pack_sync', instance_id: 'one', state, error: 'failure' },
|
||||
}
|
||||
assert.deepEqual(hostedDownloadActions(bar), ['retry'])
|
||||
assert.equal(hostedDownloadState(bar), state)
|
||||
}
|
||||
assert.equal(hostedDownloadState({ bar_type: { error: 'old backend failure' } }), 'failed')
|
||||
})
|
||||
|
||||
test('resume refreshes the session before invoking controls; pause and stop need no session', async () => {
|
||||
const calls: string[] = []
|
||||
const deps = {
|
||||
prepareSession: async () => {
|
||||
calls.push('session')
|
||||
},
|
||||
invoke: async (command: string, args: { instanceId: string }) => {
|
||||
calls.push(`${command}:${args.instanceId}`)
|
||||
},
|
||||
}
|
||||
await runHostedDownloadControl('resume', 'one', deps)
|
||||
await runHostedDownloadControl('pause', 'one', deps)
|
||||
await runHostedDownloadControl('cancel', 'one', deps)
|
||||
assert.deepEqual(calls, [
|
||||
'session',
|
||||
'plugin:install|hosted_resume:one',
|
||||
'plugin:install|hosted_pause:one',
|
||||
'plugin:install|hosted_cancel:one',
|
||||
])
|
||||
})
|
||||
|
||||
test('session refresh failures prevent resume', async () => {
|
||||
await assert.rejects(
|
||||
runHostedDownloadControl('resume', 'one', {
|
||||
prepareSession: async () => {
|
||||
throw new Error('signed out')
|
||||
},
|
||||
invoke: async () => {
|
||||
assert.fail('resume must not run')
|
||||
},
|
||||
}),
|
||||
/signed out/,
|
||||
)
|
||||
})
|
||||
|
||||
test('retry immediately restarts the existing hosted instance through the manager', async () => {
|
||||
const calls: string[] = []
|
||||
await runHostedDownloadAction('retry', 'existing-instance', {
|
||||
retryHosted: async (instanceId) => {
|
||||
calls.push(instanceId)
|
||||
},
|
||||
control: async () => {
|
||||
assert.fail('retry must use the full hosted transaction')
|
||||
},
|
||||
})
|
||||
assert.deepEqual(calls, ['existing-instance'])
|
||||
})
|
||||
@@ -0,0 +1,45 @@
|
||||
import type { LoadingBar } from './state.ts'
|
||||
|
||||
export type HostedDownloadControl = 'pause' | 'resume' | 'cancel'
|
||||
export type HostedDownloadAction = HostedDownloadControl | 'retry'
|
||||
|
||||
export function runHostedDownloadAction(
|
||||
action: HostedDownloadAction,
|
||||
instanceId: string,
|
||||
operations: {
|
||||
retryHosted: (instanceId: string) => Promise<void>
|
||||
control: (action: HostedDownloadControl, instanceId: string) => Promise<void>
|
||||
},
|
||||
) {
|
||||
return action === 'retry'
|
||||
? operations.retryHosted(instanceId)
|
||||
: operations.control(action, instanceId)
|
||||
}
|
||||
|
||||
export function hostedDownloadState(bar: LoadingBar) {
|
||||
return bar.bar_type?.state ?? (bar.bar_type?.error ? 'failed' : 'running')
|
||||
}
|
||||
|
||||
export function hostedDownloadActions(bar: LoadingBar): HostedDownloadAction[] {
|
||||
const type = bar.bar_type
|
||||
if (type?.type !== 'hosted_pack_sync' || !type.instance_id) return []
|
||||
const state = hostedDownloadState(bar)
|
||||
if (state === 'failed' || state === 'canceled') return ['retry']
|
||||
if (state !== 'running' && state !== 'paused') return []
|
||||
const actions: HostedDownloadAction[] = []
|
||||
if (type.can_pause) actions.push(state === 'paused' ? 'resume' : 'pause')
|
||||
if (type.can_cancel) actions.push('cancel')
|
||||
return actions
|
||||
}
|
||||
|
||||
export async function runHostedDownloadControl(
|
||||
action: HostedDownloadControl,
|
||||
instanceId: string,
|
||||
dependencies: {
|
||||
prepareSession: () => Promise<void>
|
||||
invoke: (command: string, args: { instanceId: string }) => Promise<void>
|
||||
},
|
||||
) {
|
||||
if (action === 'resume') await dependencies.prepareSession()
|
||||
await dependencies.invoke(`plugin:install|hosted_${action}`, { instanceId })
|
||||
}
|
||||
@@ -3,6 +3,27 @@ import test from 'node:test'
|
||||
|
||||
import { createHostedDownloadFailures } from './hosted-download-failures.ts'
|
||||
|
||||
test('stopped hosted downloads retain their state and instance for direct retry', () => {
|
||||
const state = createHostedDownloadFailures()
|
||||
state.update({
|
||||
fraction: null,
|
||||
loader_uuid: 'stopped',
|
||||
event: {
|
||||
type: 'hosted_pack_sync',
|
||||
instance_id: 'existing-instance',
|
||||
state: 'canceled',
|
||||
error: 'Stopped by user',
|
||||
can_pause: false,
|
||||
can_cancel: false,
|
||||
},
|
||||
})
|
||||
assert.equal(state.values()[0]?.bar_type?.state, 'canceled')
|
||||
assert.equal(state.values()[0]?.bar_type?.instance_id, 'existing-instance')
|
||||
state.begin('existing-instance', state.values())
|
||||
assert.equal(state.has('existing-instance'), false)
|
||||
assert.equal(state.isRetired('stopped'), true)
|
||||
})
|
||||
|
||||
test('retry clears only its own failure before progress arrives and ignores late old events', () => {
|
||||
const state = createHostedDownloadFailures()
|
||||
const failed = (instanceId: string, loader: string, error: string) => ({
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
skinSiteUser,
|
||||
waitForSkinSiteSession,
|
||||
} from '../composables/skin-site-session.ts'
|
||||
import { type HostedDownloadControl, runHostedDownloadControl } from './hosted-download-controls.ts'
|
||||
import { authenticateInstancePlayer } from './instance-player.ts'
|
||||
|
||||
export const HOSTED_ACCOUNT_REQUIRED_MESSAGE = '您需要登录正版或皮肤站账号后才能操作'
|
||||
@@ -146,6 +147,11 @@ export const hostedCreate = async (gameDirRoot?: string | null) => {
|
||||
}
|
||||
export const hostedBinding = (instanceId: string) =>
|
||||
invokeHosted<HostedBinding | null>('plugin:install|hosted_binding', { instanceId })
|
||||
export const controlHostedDownload = (action: HostedDownloadControl, instanceId: string) =>
|
||||
runHostedDownloadControl(action, instanceId, {
|
||||
prepareSession: prepareHostedSession,
|
||||
invoke: invokeHosted<void>,
|
||||
})
|
||||
export const hostedSync = async (instanceId: string) => {
|
||||
await requireHostedGameAccount()
|
||||
startHostedPackAttempt(instanceId)
|
||||
|
||||
@@ -9,6 +9,9 @@ export interface LoadingBarType {
|
||||
batch_id?: string
|
||||
file_name?: string
|
||||
error?: string | null
|
||||
state?: 'running' | 'paused' | 'canceling' | 'canceled' | 'failed' | 'finalizing'
|
||||
can_pause?: boolean
|
||||
can_cancel?: boolean
|
||||
type?: string
|
||||
version?: string
|
||||
instance_id?: string
|
||||
@@ -28,7 +31,12 @@ export interface LoadingBar {
|
||||
}
|
||||
|
||||
export type OpeningCommandEvent =
|
||||
'RunMRPack' | 'InstallServer' | 'InstallVersion' | 'InstallMod' | 'InstallModpack' | string
|
||||
| 'RunMRPack'
|
||||
| 'InstallServer'
|
||||
| 'InstallVersion'
|
||||
| 'InstallMod'
|
||||
| 'InstallModpack'
|
||||
| string
|
||||
|
||||
export interface OpeningCommand {
|
||||
event: OpeningCommandEvent
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"app.hosted-packs.progress.pause": { "message": "Pause" },
|
||||
"app.hosted-packs.progress.resume": { "message": "Resume" },
|
||||
"app.hosted-packs.progress.stop": { "message": "Stop" },
|
||||
"app.downloads.status.paused": { "message": "Paused" },
|
||||
"app.skin-site.captcha.loading": { "message": "Loading captcha…" },
|
||||
"app.skin-site.captcha.submit": { "message": "Submit" },
|
||||
"app.skin-site.captcha.subtitle": {
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"app.hosted-packs.progress.pause": { "message": "暂停" },
|
||||
"app.hosted-packs.progress.resume": { "message": "继续" },
|
||||
"app.hosted-packs.progress.stop": { "message": "停止" },
|
||||
"app.downloads.status.paused": { "message": "已暂停" },
|
||||
"app.skin-site.captcha.loading": { "message": "正在加载验证码…" },
|
||||
"app.skin-site.captcha.submit": { "message": "验证" },
|
||||
"app.skin-site.captcha.subtitle": {
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
</TagItem>
|
||||
<Badge
|
||||
:color="bar.bar_type?.error ? 'red' : 'orange'"
|
||||
:type="statusLabel(bar.bar_type?.error ? 'failed' : 'running')"
|
||||
:type="statusLabel(hostedDownloadState(bar))"
|
||||
/>
|
||||
</div>
|
||||
<ProgressBar
|
||||
@@ -94,16 +94,35 @@
|
||||
:progress="legacyPercent(bar)"
|
||||
:max="100"
|
||||
:label="formatMessage(messages.progress)"
|
||||
:waiting="!bar.total"
|
||||
:waiting="!bar.total && hostedDownloadState(bar) !== 'paused'"
|
||||
:show-progress="Boolean(bar.total)"
|
||||
/>
|
||||
<RouterLink
|
||||
v-else
|
||||
:to="hostedRetryRoute(bar.bar_type?.instance_id ?? '')"
|
||||
class="mt-3 inline-block text-brand hover:underline"
|
||||
<div
|
||||
v-if="hostedDownloadActions(bar).length"
|
||||
class="mt-3 flex flex-wrap items-center gap-2"
|
||||
>
|
||||
{{ formatMessage(messages.hostedRetry) }}
|
||||
</RouterLink>
|
||||
<ButtonStyled
|
||||
v-for="action in hostedDownloadActions(bar)"
|
||||
:key="action"
|
||||
:color="action === 'retry' ? 'brand' : action === 'cancel' ? 'red' : 'standard'"
|
||||
:type="action === 'retry' ? 'standard' : 'outlined'"
|
||||
size="small"
|
||||
>
|
||||
<button
|
||||
:disabled="busy.has(hostedBusyKey(bar, action))"
|
||||
@click="hostedAction(bar, action)"
|
||||
>
|
||||
{{ formatMessage(hostedActionMessages[action]) }}
|
||||
</button>
|
||||
</ButtonStyled>
|
||||
<RouterLink
|
||||
v-if="bar.bar_type?.error"
|
||||
:to="hostedRetryRoute(bar.bar_type.instance_id ?? '')"
|
||||
class="text-brand hover:underline"
|
||||
>
|
||||
{{ formatMessage(messages.openInstance) }}
|
||||
</RouterLink>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
<Card
|
||||
@@ -471,7 +490,14 @@ import { useRoute, useRouter } from 'vue-router'
|
||||
import MissingModpackContentModal from '@/components/ui/modal/MissingModpackContentModal.vue'
|
||||
import { listPendingCurseForgeManualDownloads } from '@/helpers/curseforge'
|
||||
import type { CurseForgeManualDownloadItem } from '@/helpers/curseforge-manual'
|
||||
import {
|
||||
type HostedDownloadAction,
|
||||
hostedDownloadActions,
|
||||
hostedDownloadState,
|
||||
runHostedDownloadAction,
|
||||
} from '@/helpers/hosted-download-controls'
|
||||
import { hostedRetryRoute } from '@/helpers/hosted-install-retry'
|
||||
import { controlHostedDownload } from '@/helpers/hosted-packs'
|
||||
import {
|
||||
download_job_support_details,
|
||||
type InstallJobSnapshot,
|
||||
@@ -517,10 +543,6 @@ const focusedJobId = computed(() => focusedDownloadJobId(route.query.job))
|
||||
const focusState = ref(createDownloadFocusState(focusedJobId.value))
|
||||
|
||||
const messages = defineMessages({
|
||||
hostedRetry: {
|
||||
id: 'app.hosted-packs.progress.retry',
|
||||
defaultMessage: 'Return to the instance to retry',
|
||||
},
|
||||
newDownload: { id: 'app.downloads.new-download', defaultMessage: 'New download' },
|
||||
inProgress: { id: 'app.downloads.in-progress', defaultMessage: 'In progress' },
|
||||
history: { id: 'app.downloads.history', defaultMessage: 'History' },
|
||||
@@ -653,7 +675,15 @@ const messages = defineMessages({
|
||||
unknownPhase: { id: 'app.downloads.phase.unknown', defaultMessage: 'Working' },
|
||||
})
|
||||
|
||||
const hostedActionMessages = defineMessages({
|
||||
pause: { id: 'app.hosted-packs.progress.pause', defaultMessage: 'Pause' },
|
||||
resume: { id: 'app.hosted-packs.progress.resume', defaultMessage: 'Resume' },
|
||||
cancel: { id: 'app.hosted-packs.progress.stop', defaultMessage: 'Stop' },
|
||||
retry: { id: 'app.downloads.retry', defaultMessage: 'Retry' },
|
||||
})
|
||||
|
||||
const statusMessages = defineMessages({
|
||||
paused: { id: 'app.downloads.status.paused', defaultMessage: 'Paused' },
|
||||
queued: { id: 'app.downloads.status.queued', defaultMessage: 'Queued' },
|
||||
running: { id: 'app.downloads.status.running', defaultMessage: 'Running' },
|
||||
canceling: { id: 'app.downloads.status.canceling', defaultMessage: 'Canceling' },
|
||||
@@ -1262,6 +1292,7 @@ function toggleExpanded(jobId: string) {
|
||||
}
|
||||
|
||||
async function withBusy(jobId: string, action: () => Promise<void>) {
|
||||
if (busy.value.has(jobId)) return
|
||||
busy.value = new Set([...busy.value, jobId])
|
||||
try {
|
||||
await action()
|
||||
@@ -1278,6 +1309,21 @@ async function cancel(job: InstallJobSnapshot) {
|
||||
await withBusy(job.job_id, () => manager.cancel(job.job_id))
|
||||
}
|
||||
|
||||
function hostedBusyKey(bar: LoadingBar, action: HostedDownloadAction) {
|
||||
return `hosted-${action === 'retry' ? 'retry' : 'control'}:${bar.bar_type?.instance_id}`
|
||||
}
|
||||
|
||||
async function hostedAction(bar: LoadingBar, action: HostedDownloadAction) {
|
||||
const instanceId = bar.bar_type?.instance_id
|
||||
if (!instanceId || !hostedDownloadActions(bar).includes(action)) return
|
||||
await withBusy(hostedBusyKey(bar, action), () =>
|
||||
runHostedDownloadAction(action, instanceId, {
|
||||
retryHosted: manager.retryHosted,
|
||||
control: controlHostedDownload,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
async function retry(job: InstallJobSnapshot) {
|
||||
await withBusy(job.job_id, () => manager.retry(job.job_id))
|
||||
}
|
||||
@@ -1293,12 +1339,14 @@ async function resolveMissing(job: InstallJobSnapshot) {
|
||||
(item) =>
|
||||
item.status === 'skipped' && item.manual_url && item.project_id && item.version_id,
|
||||
)
|
||||
.map((item): CurseForgeManualDownloadItem => ({
|
||||
projectId: Number(item.project_id),
|
||||
fileId: Number(item.version_id),
|
||||
fileName: item.name,
|
||||
websiteUrl: item.manual_url ?? undefined,
|
||||
}))
|
||||
.map(
|
||||
(item): CurseForgeManualDownloadItem => ({
|
||||
projectId: Number(item.project_id),
|
||||
fileId: Number(item.version_id),
|
||||
fileName: item.name,
|
||||
websiteUrl: item.manual_url ?? undefined,
|
||||
}),
|
||||
)
|
||||
const instanceId = job.instance_id
|
||||
const hasGeneralMissingItems = job.items.some((item) => item.status === 'failed')
|
||||
if (instanceId && (job.provider === 'curse_forge' || fallbackCurseForgeItems.length > 0)) {
|
||||
|
||||
Reference in new issue
Block a user