fix(agent-backups): validate agent ownership
This commit is contained in:
parent
a279129ad8
commit
be3182793d
2 changed files with 40 additions and 0 deletions
|
|
@ -106,6 +106,41 @@ test("backup progress is delivered to the running backup callback", async () =>
|
||||||
await stopAgentController();
|
await stopAgentController();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("backup events from agents that do not own the active run are ignored", async () => {
|
||||||
|
resetAgentRuntime();
|
||||||
|
controllerMock.sendBackup.mockImplementation(() => Effect.succeed(true));
|
||||||
|
const { agentManager, startAgentController, stopAgentController } = await import("../agents-manager");
|
||||||
|
|
||||||
|
await startAgentController();
|
||||||
|
const resultPromise = agentManager.runBackup("local", {
|
||||||
|
scheduleId: 42,
|
||||||
|
payload: backupPayload,
|
||||||
|
signal: new AbortController().signal,
|
||||||
|
onProgress: vi.fn(),
|
||||||
|
});
|
||||||
|
|
||||||
|
controllerMock.onEvent?.({
|
||||||
|
type: "backup.completed",
|
||||||
|
agentId: "remote",
|
||||||
|
agentName: "Remote Agent",
|
||||||
|
payload: { jobId: "job-1", scheduleId: "schedule-1", exitCode: 0, result: null },
|
||||||
|
});
|
||||||
|
controllerMock.onEvent?.({
|
||||||
|
type: "backup.completed",
|
||||||
|
agentId: "local",
|
||||||
|
agentName: "Local Agent",
|
||||||
|
payload: { jobId: "job-1", scheduleId: "schedule-1", exitCode: 0, result: null },
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(resultPromise).resolves.toEqual({
|
||||||
|
status: "completed",
|
||||||
|
exitCode: 0,
|
||||||
|
result: null,
|
||||||
|
warningDetails: null,
|
||||||
|
});
|
||||||
|
await stopAgentController();
|
||||||
|
});
|
||||||
|
|
||||||
test("backup failed and cancelled events resolve the matching running backup", async () => {
|
test("backup failed and cancelled events resolve the matching running backup", async () => {
|
||||||
resetAgentRuntime();
|
resetAgentRuntime();
|
||||||
controllerMock.sendBackup.mockImplementation(() => Effect.succeed(true));
|
controllerMock.sendBackup.mockImplementation(() => Effect.succeed(true));
|
||||||
|
|
|
||||||
|
|
@ -152,6 +152,11 @@ const getActiveBackupRun = (jobId: string, scheduleId: string, eventName: string
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (activeBackupRun.agentId !== agentId) {
|
||||||
|
logger.warn(`Ignoring ${eventName} for job ${jobId} from unexpected agent ${agentId}`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return activeBackupRun;
|
return activeBackupRun;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue