修正创作进度耗时计算

This commit is contained in:
2026-04-26 16:14:46 +08:00
parent 47ef9b9ca6
commit 79048a8c16
2 changed files with 28 additions and 1 deletions

View File

@@ -128,6 +128,19 @@ test('maps running draft_foundation operation to refined generation progress ste
expect(isDraftFoundationOperationRunning(baseOperation)).toBe(true);
});
test('calculates elapsed time from operation startedAt before local fallback', () => {
const progress = buildAgentDraftFoundationGenerationProgress(
{
...baseOperation,
startedAt: '1970-01-01T00:00:01.000Z',
},
4_000,
6_000,
);
expect(progress?.elapsedMs).toBe(5_000);
});
test('maps auto asset phases to refined generation progress steps', () => {
const progress = buildAgentDraftFoundationGenerationProgress(
{

View File

@@ -380,6 +380,18 @@ function parseOperationUpdatedAtMs(
return Number.isFinite(parsedMs) ? parsedMs : null;
}
function parseOperationStartedAtMs(
operation: CustomWorldAgentOperationRecord,
) {
const rawStartedAt = operation.startedAt?.trim();
if (!rawStartedAt) {
return null;
}
const parsedMs = Date.parse(rawStartedAt);
return Number.isFinite(parsedMs) ? parsedMs : null;
}
function resolveAgentDraftFoundationStepIndex(
operation: CustomWorldAgentOperationRecord,
) {
@@ -517,7 +529,7 @@ export function isDraftFoundationOperationRunning(
export function buildAgentDraftFoundationGenerationProgress(
operation: CustomWorldAgentOperationRecord | null | undefined,
startedAtMs: number | null,
fallbackStartedAtMs: number | null,
nowMs = Date.now(),
): CustomWorldGenerationProgress | null {
if (!isDraftFoundationOperation(operation)) {
@@ -526,6 +538,8 @@ export function buildAgentDraftFoundationGenerationProgress(
const activeStepIndex = resolveAgentDraftFoundationStepIndex(operation);
const overallProgress = resolveFailedProgress(operation, activeStepIndex);
// 中文注释:总耗时必须绑定服务端 operation 创建时间,避免刷新或前端重挂载后重新计时。
const startedAtMs = parseOperationStartedAtMs(operation) ?? fallbackStartedAtMs;
const elapsedMs = startedAtMs ? Math.max(0, nowMs - startedAtMs) : 0;
const estimatedRemainingMs = resolveEstimatedRemainingMs(
overallProgress,