Compare commits

..

2 Commits

Author SHA1 Message Date
vorotamoroz 19f0b3d145 fix(cli): replace the headless log handler 2026-08-01 15:30:46 +00:00
vorotamoroz 3ba9feaac7 Merge pull request #1063 from vrtmrz/feature/p2p-connection-check
Add a browser-assisted P2P connection check
2026-08-01 03:51:06 +09:00
2 changed files with 56 additions and 1 deletions
@@ -0,0 +1,55 @@
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
const mocks = vi.hoisted(() => ({
setLogHandler: vi.fn(),
}));
vi.mock("./services/NodeServiceHub", () => ({
NodeServiceContext: class {},
NodeServiceHub: class {
API = {
addLog: {
setHandler: mocks.setLogHandler,
},
};
},
}));
import { main } from "./main";
function createStandardIoMock() {
return {
readStdin: vi.fn(async () => ""),
prompt: vi.fn(async () => ""),
writeStdout: vi.fn(),
writeStderr: vi.fn(),
};
}
describe("CLI log handler", () => {
const originalArgv = process.argv.slice();
let databasePath: string;
beforeEach(async () => {
databasePath = await mkdtemp(join(tmpdir(), "livesync-cli-log-handler-"));
mocks.setLogHandler.mockReset();
mocks.setLogHandler.mockImplementation(() => {
throw new Error("__LOG_HANDLER_CONFIGURED__");
});
});
afterEach(async () => {
process.argv = originalArgv.slice();
await rm(databasePath, { recursive: true, force: true });
});
it("replaces the default Headless API log handler", async () => {
process.argv = ["node", "livesync-cli", databasePath, "remote-ls"];
await expect(main(createStandardIoMock())).rejects.toThrow("__LOG_HANDLER_CONFIGURED__");
expect(mocks.setLogHandler).toHaveBeenCalledWith(expect.any(Function), true);
});
});
+1 -1
View File
@@ -399,7 +399,7 @@ export async function main(
if (!options.verbose) return;
}
writeStderrLine(standardIo, prefix, message);
});
}, true);
// Prevent replication result from being processed automatically in non-daemon commands.
// In daemon mode the default handler must run so changes are applied to the filesystem.
if (options.command !== "daemon") {