chore: pr feedbacks
This commit is contained in:
parent
e2498ff638
commit
e4499c395f
5 changed files with 30 additions and 13 deletions
|
|
@ -90,7 +90,9 @@ const getActiveBackupRun = (jobId: string, scheduleId: string, eventName: string
|
|||
}
|
||||
|
||||
if (activeBackupRun.scheduleShortId !== scheduleId) {
|
||||
logger.warn(`Ignoring ${eventName} for job ${jobId} due to schedule mismatch ${scheduleId} from agent ${agentId}`);
|
||||
logger.warn(
|
||||
`Ignoring ${eventName} for job ${jobId} due to schedule mismatch ${scheduleId} from agent ${agentId}`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -308,7 +310,9 @@ export const startLocalAgent = async () => {
|
|||
await spawnLocalAgentProcess(runtime);
|
||||
|
||||
if (!runtime.agentManager) {
|
||||
return;
|
||||
throw new Error(
|
||||
`startLocalAgent spawned ${LOCAL_AGENT_ID} via spawnLocalAgentProcess, but runtime.agentManager is missing; waitForAgentReady cannot check readiness`,
|
||||
);
|
||||
}
|
||||
|
||||
if (!(await runtime.agentManager.waitForAgentReady(LOCAL_AGENT_ID))) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { afterEach, describe, expect, test, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
||||
import { Scheduler } from "../../../core/scheduler";
|
||||
import * as bootstrapModule from "../bootstrap";
|
||||
import { agentManager } from "../../agents/agents-manager";
|
||||
|
|
@ -12,8 +12,14 @@ const loadShutdownModule = async () => {
|
|||
return import(moduleUrl.href);
|
||||
};
|
||||
|
||||
let originalEnableLocalAgent: boolean;
|
||||
|
||||
beforeEach(() => {
|
||||
originalEnableLocalAgent = config.flags.enableLocalAgent;
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
config.flags.enableLocalAgent = true;
|
||||
config.flags.enableLocalAgent = originalEnableLocalAgent;
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
|
|
@ -28,7 +34,7 @@ describe("shutdown", () => {
|
|||
});
|
||||
const runVolumeCommand = vi.spyOn(agentManager, "runVolumeCommand");
|
||||
|
||||
await createTestVolume({
|
||||
const volume = await createTestVolume({
|
||||
name: "Shutdown test volume",
|
||||
config: {
|
||||
backend: "directory",
|
||||
|
|
@ -47,6 +53,9 @@ describe("shutdown", () => {
|
|||
|
||||
expect(events).toEqual(["scheduler.stop", "agents.stop"]);
|
||||
expect(runVolumeCommand).not.toHaveBeenCalled();
|
||||
const updated = await db.query.volumesTable.findFirst({ where: { id: volume.id } });
|
||||
expect(updated).toBeDefined();
|
||||
expect(updated!.status).toBe("mounted");
|
||||
});
|
||||
|
||||
test("keeps legacy controller-local fallback unmount on shutdown", async () => {
|
||||
|
|
@ -58,6 +67,9 @@ describe("shutdown", () => {
|
|||
vi.spyOn(bootstrapModule, "stopApplicationRuntime").mockImplementation(async () => {
|
||||
events.push("agents.stop");
|
||||
});
|
||||
const runVolumeCommand = vi.spyOn(agentManager, "runVolumeCommand").mockImplementation(async () => {
|
||||
throw new Error("runVolumeCommand should not be called during fallback shutdown");
|
||||
});
|
||||
|
||||
const volume = await createTestVolume({
|
||||
name: "Fallback shutdown test volume",
|
||||
|
|
@ -71,6 +83,8 @@ describe("shutdown", () => {
|
|||
|
||||
const updated = await db.query.volumesTable.findFirst({ where: { id: volume.id } });
|
||||
expect(events).toEqual(["scheduler.stop", "agents.stop"]);
|
||||
expect(updated?.status).toBe("unmounted");
|
||||
expect(runVolumeCommand).not.toHaveBeenCalled();
|
||||
expect(updated).toBeDefined();
|
||||
expect(updated!.status).toBe("unmounted");
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ const volumeForAgent = async (volume: Volume): Promise<Volume> => ({
|
|||
|
||||
const volumeForHost = async (volume: Volume): Promise<AgentVolume> => ({
|
||||
...volume,
|
||||
shortId: volume.shortId,
|
||||
config: await decryptVolumeConfig(volume.config),
|
||||
provisioningId: volume.provisioningId ?? null,
|
||||
});
|
||||
|
|
@ -211,7 +210,7 @@ const getVolume = async (shortId: ShortId) => {
|
|||
let statfs: Partial<StatFs> = {};
|
||||
if (volume.status === "mounted") {
|
||||
statfs = await withTimeout(
|
||||
!shouldUseControllerLocalVolumeFallback(volume)
|
||||
shouldRunViaAgent(volume)
|
||||
? runVolumeCommand(volume.agentId, {
|
||||
name: "volume.statfs",
|
||||
volume: await volumeForAgent(volume),
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ afterEach(() => {
|
|||
});
|
||||
|
||||
const runVolumeCommand = async (payload: VolumeCommandPayload) => {
|
||||
const outboundMessages: string[] = [];
|
||||
const outboundMessages: AgentWireMessage[] = [];
|
||||
const context = fromPartial<ControllerCommandContext>({
|
||||
offerOutbound: (message: AgentWireMessage) =>
|
||||
Effect.sync(() => {
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ let tempRoot: string | undefined;
|
|||
let mockMountPoints: string[] = [];
|
||||
|
||||
afterEach(async () => {
|
||||
vi.doUnmock("./constants");
|
||||
vi.doUnmock("./fs");
|
||||
vi.doUnmock("../constants");
|
||||
vi.doUnmock("../fs");
|
||||
vi.resetModules();
|
||||
mockMountPoints = [];
|
||||
if (tempRoot) {
|
||||
|
|
@ -20,8 +20,8 @@ afterEach(async () => {
|
|||
const loadCleanup = async () => {
|
||||
vi.resetModules();
|
||||
tempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "zerobyte-agent-cleanup-"));
|
||||
vi.doMock("./constants", () => ({ VOLUME_MOUNT_BASE: tempRoot }));
|
||||
vi.doMock("./fs", () => ({
|
||||
vi.doMock("../constants", () => ({ VOLUME_MOUNT_BASE: tempRoot }));
|
||||
vi.doMock("../fs", () => ({
|
||||
readMountInfo: async () => mockMountPoints.map((mountPoint) => ({ mountPoint, fstype: "fuse.sshfs" })),
|
||||
}));
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue