Files
warkanumandClaude Sonnet 5 2590e404f5
CI / rust (push) Successful in 3m6s
CI / go (push) Successful in 33s
CI / js (push) Successful in 34s
feat: initial Go/JS/Rust Origin check-in client SDKs
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>
2026-08-01 15:25:30 +02:00

44 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { hostname, isContainerIdLike, parseCgroupContainerId } from "../src/hostInfo.js";
describe("parseCgroupContainerId", () => {
it("parses a cgroup v1 docker path", () => {
const data = "12:memory:/docker/9f8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b\n";
expect(parseCgroupContainerId(data)).toBe("9f8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b");
});
it("parses a cgroup v2 systemd scope", () => {
const data = "0::/system.slice/docker-9f8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b.scope\n";
expect(parseCgroupContainerId(data)).toBe("9f8b7c6d5e4f3a2b1c0d9e8f7a6b5c4d3e2f1a0b9c8d7e6f5a4b3c2d1e0f9a8b");
});
it("returns empty on a non-container host", () => {
expect(parseCgroupContainerId("0::/user.slice/user-1000.slice/session-2.scope\n")).toBe("");
});
it("returns empty for empty input", () => {
expect(parseCgroupContainerId("")).toBe("");
});
});
describe("isContainerIdLike", () => {
it("accepts a hex id of valid length", () => {
expect(isContainerIdLike("9f8b7c6d5e4f")).toBe(true);
});
it("rejects short strings", () => {
expect(isContainerIdLike("short")).toBe(false);
});
it("rejects non-hex strings", () => {
expect(isContainerIdLike("session-2")).toBe(false);
});
it("rejects empty strings", () => {
expect(isContainerIdLike("")).toBe(false);
});
});
describe("hostname", () => {
it("returns a non-empty value", () => {
expect(hostname().length).toBeGreaterThan(0);
});
});