test: dedupe gateway config reload mock reads

This commit is contained in:
Peter Steinberger
2026-05-12 20:33:30 +01:00
parent ea7f74ffc9
commit d18bbfe7ae
2 changed files with 32 additions and 17 deletions
@@ -126,19 +126,23 @@ describe("rotateTranscriptAfterCompaction", () => {
expect(header.cwd).toBe(dir);
const messages = successor.buildSessionContext().messages;
expect(
messages.map((message) =>
message.role === "compactionSummary"
? {
role: message.role,
summary: message.summary,
tokensBefore: message.tokensBefore,
}
: {
role: message.role,
content: message.content,
timestamp: message.timestamp,
},
),
messages.map((message) => {
if (message.role === "compactionSummary") {
return {
role: message.role,
summary: message.summary,
tokensBefore: message.tokensBefore,
};
}
if (!("content" in message)) {
throw new Error(`expected ${message.role} message content`);
}
return {
role: message.role,
content: message.content,
timestamp: message.timestamp,
};
}),
).toEqual([
{
role: "compactionSummary",
+15 -4
View File
@@ -634,7 +634,7 @@ type ReloaderHarness = ReturnType<typeof createReloaderHarness>;
function getOnlyRestartCall(harness: ReloaderHarness): [GatewayReloadPlan, OpenClawConfig] {
expect(harness.onRestart).toHaveBeenCalledTimes(1);
const call = harness.onRestart.mock.calls.at(0);
const call = harness.onRestart.mock.calls[0];
if (!call) {
throw new Error("expected one restart call");
}
@@ -643,13 +643,24 @@ function getOnlyRestartCall(harness: ReloaderHarness): [GatewayReloadPlan, OpenC
function getOnlyHotReloadCall(harness: ReloaderHarness): [GatewayReloadPlan, OpenClawConfig] {
expect(harness.onHotReload).toHaveBeenCalledTimes(1);
const call = harness.onHotReload.mock.calls.at(0);
const call = harness.onHotReload.mock.calls[0];
if (!call) {
throw new Error("expected one hot reload call");
}
return call;
}
function getOnlyPromoteSnapshotCall(promoteSnapshot: {
mock: { calls: Array<readonly [ConfigFileSnapshot, string]> };
}): readonly [ConfigFileSnapshot, string] {
expect(promoteSnapshot).toHaveBeenCalledTimes(1);
const call = promoteSnapshot.mock.calls[0];
if (!call) {
throw new Error("expected one promote snapshot call");
}
return call;
}
describe("startGatewayConfigReloader", () => {
beforeEach(() => {
vi.useFakeTimers();
@@ -958,7 +969,7 @@ describe("startGatewayConfigReloader", () => {
expect(readSnapshot).toHaveBeenCalledTimes(1);
expect(harness.onHotReload).toHaveBeenCalledTimes(1);
const [promotedSnapshot, promotionReason] = promoteSnapshot.mock.calls.at(0) ?? [];
const [promotedSnapshot, promotionReason] = getOnlyPromoteSnapshotCall(promoteSnapshot);
expect(promotedSnapshot?.hash).toBe("internal-1");
expect(promotionReason).toBe("in-process-write");
@@ -997,7 +1008,7 @@ describe("startGatewayConfigReloader", () => {
expect(harness.log.info).toHaveBeenCalledWith(
"config reload skipped by writer intent (caller handles follow-up)",
);
const [promotedSnapshot, promotionReason] = promoteSnapshot.mock.calls.at(0) ?? [];
const [promotedSnapshot, promotionReason] = getOnlyPromoteSnapshotCall(promoteSnapshot);
expect(promotedSnapshot?.hash).toBe("internal-none");
expect(promotionReason).toBe("in-process-write");