Private
Public Access
CI / rust (push) Successful in 3m6s
CI / go (push) Successful in 33s
CI / js (push) Successful in 34s
Standalone clients that resolve a machine unique ID (OS machine ID first, falling back to a generated UUID persisted to disk), detect hostname/IP/ container/orchestrator, and register+re-ping origin.warky.dev's public service-checkin endpoint on a daily interval. Ported from icy2's internal origincheckin package but extended to the full check-in contract and made dependency-light for external reuse. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { mkdtempSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import * as machineId from "../src/machineId.js";
|
|
|
|
function tempInstallIdPath(): string {
|
|
const dir = mkdtempSync(join(tmpdir(), "origin-client-test-"));
|
|
return join(dir, "install-id");
|
|
}
|
|
|
|
describe("resolveMachineId", () => {
|
|
afterEach(() => {
|
|
machineId.machineIdDetector.current = machineId.detectOsMachineId;
|
|
});
|
|
|
|
it("prefers an explicit override", () => {
|
|
machineId.machineIdDetector.current = () => "os-machine-id";
|
|
expect(machineId.resolveMachineId("explicit-id", tempInstallIdPath())).toBe("explicit-id");
|
|
});
|
|
|
|
it("uses the OS machine id when available", () => {
|
|
machineId.machineIdDetector.current = () => "os-machine-id";
|
|
expect(machineId.resolveMachineId(undefined, tempInstallIdPath())).toBe("os-machine-id");
|
|
});
|
|
|
|
it("falls back to a generated id and persists it across calls", () => {
|
|
machineId.machineIdDetector.current = () => undefined;
|
|
const path = tempInstallIdPath();
|
|
|
|
const first = machineId.resolveMachineId(undefined, path);
|
|
expect(first.length).toBeGreaterThan(0);
|
|
|
|
const second = machineId.resolveMachineId(undefined, path);
|
|
expect(second).toBe(first);
|
|
});
|
|
|
|
it("logs a warning when the OS id is unavailable", () => {
|
|
machineId.machineIdDetector.current = () => undefined;
|
|
const warn = vi.fn();
|
|
machineId.resolveMachineId(undefined, tempInstallIdPath(), { warn });
|
|
expect(warn).toHaveBeenCalled();
|
|
});
|
|
});
|