fix terminal system lines to use server time

This commit is contained in:
npc0-hue
2026-08-24 14:07:33 +08:00
parent 504387c657
commit 3e00737267
4 changed files with 52 additions and 28 deletions
@@ -5,6 +5,7 @@ import { createRoot, type Root } from "react-dom/client";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import type { JobResponse, LogEntryBody, LogStreamResponse, SourceRCONCommandResponse } from "../api/types";
import { formatTerminalServerTime } from "../utils/logTime";
import { ServerManagementTerminalDrawer } from "./ServerManagementTerminalDrawer";
const apiMocks = vi.hoisted(() => ({
@@ -88,6 +89,16 @@ describe("ServerManagementTerminalDrawer", () => {
expect(apiMocks.dispatchSourceRCONCommand).not.toHaveBeenCalled();
});
it("uses the server-provided clock for terminal system lines", async () => {
const serverTime = "2001-02-03T04:05:06Z";
await renderDrawer();
expect(container?.textContent).toContain("时间同步中");
await emitSession("session-server-clock", serverTime);
const systemLine = Array.from(container?.querySelectorAll<HTMLDivElement>(".terminal-line") ?? []).find((line) => line.textContent?.includes("已跟随当前受管进程输出会话"));
expect(systemLine?.querySelector("time")?.textContent).toBe(formatTerminalServerTime(serverTime));
});
it("renders an empty current session without accepting unrelated or sessionless logs", async () => {
await renderDrawer();
@@ -203,8 +214,8 @@ async function renderDrawer() {
expect(apiMocks.openServerLogEvents).toHaveBeenCalledWith("server-1", { historyLimit: 500 });
}
async function emitSession(logSessionId?: string) {
await act(async () => eventStream.emit("session", { serverInstanceId: "server-1", logSessionId, streamCount: logSessionId ? 1 : 0, serverTime: "2026-08-14T00:00:00Z" }));
async function emitSession(logSessionId?: string, serverTime = "2026-08-14T00:00:00Z") {
await act(async () => eventStream.emit("session", { serverInstanceId: "server-1", logSessionId, streamCount: logSessionId ? 1 : 0, serverTime }));
}
async function emitStream(stream: LogStreamResponse) {