2025-12-14 00:48:58 +00:00
|
|
|
import * as fs from "node:fs/promises";
|
|
|
|
|
import * as os from "node:os";
|
|
|
|
|
import * as path from "node:path";
|
2026-02-22 00:38:25 -08:00
|
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
2025-12-14 00:48:58 +00:00
|
|
|
import {
|
|
|
|
|
cameraTempPath,
|
|
|
|
|
parseCameraClipPayload,
|
|
|
|
|
parseCameraSnapPayload,
|
2026-02-18 23:47:52 +00:00
|
|
|
writeCameraClipPayloadToFile,
|
2025-12-14 00:48:58 +00:00
|
|
|
writeBase64ToFile,
|
2026-02-13 23:49:28 +08:00
|
|
|
writeUrlToFile,
|
2025-12-14 00:48:58 +00:00
|
|
|
} from "./nodes-camera.js";
|
2026-02-16 02:00:59 +00:00
|
|
|
import { parseScreenRecordPayload, screenRecordTempPath } from "./nodes-screen.js";
|
2025-12-14 00:48:58 +00:00
|
|
|
|
2026-02-21 19:12:09 +00:00
|
|
|
async function withTempDir<T>(prefix: string, run: (dir: string) => Promise<T>): Promise<T> {
|
|
|
|
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
|
|
|
|
|
try {
|
|
|
|
|
return await run(dir);
|
|
|
|
|
} finally {
|
|
|
|
|
await fs.rm(dir, { recursive: true, force: true });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 19:51:58 +00:00
|
|
|
async function withCameraTempDir<T>(run: (dir: string) => Promise<T>): Promise<T> {
|
|
|
|
|
return await withTempDir("openclaw-test-", run);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-14 00:48:58 +00:00
|
|
|
describe("nodes camera helpers", () => {
|
2026-02-22 00:38:25 -08:00
|
|
|
const originalArgv = [...process.argv];
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
process.argv = ["node", "ironclaw"];
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-21 19:36:52 +00:00
|
|
|
function stubFetchResponse(response: Response) {
|
|
|
|
|
vi.stubGlobal(
|
|
|
|
|
"fetch",
|
|
|
|
|
vi.fn(async () => response),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-14 00:48:58 +00:00
|
|
|
it("parses camera.snap payload", () => {
|
|
|
|
|
expect(
|
|
|
|
|
parseCameraSnapPayload({
|
|
|
|
|
format: "jpg",
|
|
|
|
|
base64: "aGk=",
|
|
|
|
|
width: 10,
|
|
|
|
|
height: 20,
|
|
|
|
|
}),
|
|
|
|
|
).toEqual({ format: "jpg", base64: "aGk=", width: 10, height: 20 });
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("rejects invalid camera.snap payload", () => {
|
|
|
|
|
expect(() => parseCameraSnapPayload({ format: "jpg" })).toThrow(
|
|
|
|
|
/invalid camera\.snap payload/i,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("parses camera.clip payload", () => {
|
|
|
|
|
expect(
|
|
|
|
|
parseCameraClipPayload({
|
|
|
|
|
format: "mp4",
|
|
|
|
|
base64: "AAEC",
|
|
|
|
|
durationMs: 1234,
|
|
|
|
|
hasAudio: true,
|
|
|
|
|
}),
|
|
|
|
|
).toEqual({
|
|
|
|
|
format: "mp4",
|
|
|
|
|
base64: "AAEC",
|
|
|
|
|
durationMs: 1234,
|
|
|
|
|
hasAudio: true,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-02-21 19:51:58 +00:00
|
|
|
it("rejects invalid camera.clip payload", () => {
|
|
|
|
|
expect(() =>
|
|
|
|
|
parseCameraClipPayload({ format: "mp4", base64: "AAEC", durationMs: 1234 }),
|
|
|
|
|
).toThrow(/invalid camera\.clip payload/i);
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-14 00:48:58 +00:00
|
|
|
it("builds stable temp paths when id provided", () => {
|
|
|
|
|
const p = cameraTempPath({
|
|
|
|
|
kind: "snap",
|
|
|
|
|
facing: "front",
|
|
|
|
|
ext: "jpg",
|
|
|
|
|
tmpDir: "/tmp",
|
|
|
|
|
id: "id1",
|
|
|
|
|
});
|
Ironclaw rename: update CLI binary references, fix Next.js invocation, harden package resolution
Comprehensive update to complete the openclaw → ironclaw CLI rename across the
codebase, fix build/runtime issues, and add test coverage for infra modules.
CLI binary rename (openclaw → ironclaw):
- Update DEFAULT_CLI_NAME and all argv parsing to recognize "ironclaw" binary
- Extend package name sets (CORE_PACKAGE_NAMES, ALL_PACKAGE_NAMES) to include
both "ironclaw" and "openclaw" for backward compatibility
- Update NPM registry URL to fetch from ironclaw package
- Update gateway lock detection, port listener classification, and launchd/systemd
service scanning to recognize ironclaw-prefixed services and binaries
- Update daemon inspect markers and legacy detection for ironclaw
- Update voice-call extension core-bridge to resolve ironclaw package root
- Fix install instructions in embeddings error messages (npm i -g ironclaw@latest)
Web app / Next.js fixes:
- Replace fragile `npx next` invocations with direct `node next-bin` resolution
to avoid broken pnpm virtual-store symlinks in global installs
- Add resolveNextBin() helper that resolves apps/web/node_modules/next directly
Infra hardening:
- Workspace templates: compute both source and dist fallback paths for template
directory resolution (fixes templates not found in bundled builds)
- Control UI assets: recognize both "openclaw" and "ironclaw" package names
- Update-check, update-runner, update-cli: normalize ironclaw@ tag prefixes
New tests:
- Add openclaw-root.test.ts, ports-format.test.ts, update-global.test.ts
- Add workspace-templates.test.ts and control-ui-assets.test.ts coverage
- Add argv.test.ts coverage for ironclaw binary detection
Test fixes (28 failures → 0):
- Update all test assertions expecting "openclaw" CLI command output to "ironclaw"
- Fix version.test.ts package name from "openclaw" to "ironclaw"
- Fix camera/canvas temp path patterns in nodes-camera and program.nodes-media tests
- Fix pairing message, telegram bot, channels, daemon, onboard, gateway tool,
status, and profile test expectations
Version: 2026.2.10-1.2 (published to npm as ironclaw@2026.2.10-1.2)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 12:19:49 -08:00
|
|
|
expect(p).toBe(path.join("/tmp", "ironclaw-camera-snap-front-id1.jpg"));
|
2025-12-14 00:48:58 +00:00
|
|
|
});
|
|
|
|
|
|
2026-02-18 23:47:52 +00:00
|
|
|
it("writes camera clip payload to temp path", async () => {
|
2026-02-21 19:51:58 +00:00
|
|
|
await withCameraTempDir(async (dir) => {
|
2026-02-18 23:47:52 +00:00
|
|
|
const out = await writeCameraClipPayloadToFile({
|
|
|
|
|
payload: {
|
|
|
|
|
format: "mp4",
|
|
|
|
|
base64: "aGk=",
|
|
|
|
|
durationMs: 200,
|
|
|
|
|
hasAudio: false,
|
|
|
|
|
},
|
|
|
|
|
facing: "front",
|
|
|
|
|
tmpDir: dir,
|
|
|
|
|
id: "clip1",
|
|
|
|
|
});
|
2026-02-22 00:38:25 -08:00
|
|
|
expect(out).toBe(path.join(dir, "ironclaw-camera-clip-front-clip1.mp4"));
|
2026-02-18 23:47:52 +00:00
|
|
|
await expect(fs.readFile(out, "utf8")).resolves.toBe("hi");
|
2026-02-21 19:12:09 +00:00
|
|
|
});
|
2026-02-18 23:47:52 +00:00
|
|
|
});
|
|
|
|
|
|
2026-02-21 19:51:58 +00:00
|
|
|
it("writes camera clip payload from url", async () => {
|
|
|
|
|
stubFetchResponse(new Response("url-clip", { status: 200 }));
|
|
|
|
|
await withCameraTempDir(async (dir) => {
|
|
|
|
|
const out = await writeCameraClipPayloadToFile({
|
|
|
|
|
payload: {
|
|
|
|
|
format: "mp4",
|
|
|
|
|
url: "https://example.com/clip.mp4",
|
|
|
|
|
durationMs: 200,
|
|
|
|
|
hasAudio: false,
|
|
|
|
|
},
|
|
|
|
|
facing: "back",
|
|
|
|
|
tmpDir: dir,
|
|
|
|
|
id: "clip2",
|
|
|
|
|
});
|
2026-02-22 00:38:25 -08:00
|
|
|
expect(out).toBe(path.join(dir, "ironclaw-camera-clip-back-clip2.mp4"));
|
2026-02-21 19:51:58 +00:00
|
|
|
await expect(fs.readFile(out, "utf8")).resolves.toBe("url-clip");
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-14 00:48:58 +00:00
|
|
|
it("writes base64 to file", async () => {
|
2026-02-21 19:51:58 +00:00
|
|
|
await withCameraTempDir(async (dir) => {
|
2026-02-21 19:12:09 +00:00
|
|
|
const out = path.join(dir, "x.bin");
|
|
|
|
|
await writeBase64ToFile(out, "aGk=");
|
|
|
|
|
await expect(fs.readFile(out, "utf8")).resolves.toBe("hi");
|
|
|
|
|
});
|
2025-12-14 00:48:58 +00:00
|
|
|
});
|
2026-02-13 23:49:28 +08:00
|
|
|
|
|
|
|
|
afterEach(() => {
|
2026-02-22 00:38:25 -08:00
|
|
|
process.argv = [...originalArgv];
|
2026-02-13 23:49:28 +08:00
|
|
|
vi.unstubAllGlobals();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("writes url payload to file", async () => {
|
2026-02-21 19:36:52 +00:00
|
|
|
stubFetchResponse(new Response("url-content", { status: 200 }));
|
2026-02-21 19:51:58 +00:00
|
|
|
await withCameraTempDir(async (dir) => {
|
2026-02-21 19:12:09 +00:00
|
|
|
const out = path.join(dir, "x.bin");
|
2026-02-13 23:49:28 +08:00
|
|
|
await writeUrlToFile(out, "https://example.com/clip.mp4");
|
|
|
|
|
await expect(fs.readFile(out, "utf8")).resolves.toBe("url-content");
|
2026-02-21 19:12:09 +00:00
|
|
|
});
|
2026-02-13 23:49:28 +08:00
|
|
|
});
|
|
|
|
|
|
2026-02-21 23:24:43 +00:00
|
|
|
it("rejects invalid url payload responses", async () => {
|
2026-02-22 00:38:25 +01:00
|
|
|
const cases: Array<{
|
|
|
|
|
name: string;
|
|
|
|
|
url: string;
|
|
|
|
|
response?: Response;
|
|
|
|
|
expectedMessage: RegExp;
|
|
|
|
|
}> = [
|
2026-02-21 23:24:43 +00:00
|
|
|
{
|
|
|
|
|
name: "non-https url",
|
|
|
|
|
url: "http://example.com/x.bin",
|
|
|
|
|
expectedMessage: /only https/i,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "oversized content-length",
|
|
|
|
|
url: "https://example.com/huge.bin",
|
|
|
|
|
response: new Response("tiny", {
|
|
|
|
|
status: 200,
|
|
|
|
|
headers: { "content-length": String(999_999_999) },
|
|
|
|
|
}),
|
|
|
|
|
expectedMessage: /exceeds max/i,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "non-ok status",
|
|
|
|
|
url: "https://example.com/down.bin",
|
|
|
|
|
response: new Response("down", { status: 503, statusText: "Service Unavailable" }),
|
|
|
|
|
expectedMessage: /503/i,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "empty response body",
|
|
|
|
|
url: "https://example.com/empty.bin",
|
|
|
|
|
response: new Response(null, { status: 200 }),
|
|
|
|
|
expectedMessage: /empty response body/i,
|
|
|
|
|
},
|
2026-02-22 00:38:25 +01:00
|
|
|
];
|
2026-02-21 23:24:43 +00:00
|
|
|
|
|
|
|
|
for (const testCase of cases) {
|
|
|
|
|
if (testCase.response) {
|
|
|
|
|
stubFetchResponse(testCase.response);
|
|
|
|
|
}
|
|
|
|
|
await expect(writeUrlToFile("/tmp/ignored", testCase.url), testCase.name).rejects.toThrow(
|
|
|
|
|
testCase.expectedMessage,
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-02-21 19:36:52 +00:00
|
|
|
});
|
2026-02-21 19:51:58 +00:00
|
|
|
|
|
|
|
|
it("removes partially written file when url stream fails", async () => {
|
|
|
|
|
const stream = new ReadableStream<Uint8Array>({
|
|
|
|
|
start(controller) {
|
|
|
|
|
controller.enqueue(new TextEncoder().encode("partial"));
|
|
|
|
|
controller.error(new Error("stream exploded"));
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
stubFetchResponse(new Response(stream, { status: 200 }));
|
|
|
|
|
|
|
|
|
|
await withCameraTempDir(async (dir) => {
|
|
|
|
|
const out = path.join(dir, "broken.bin");
|
|
|
|
|
await expect(writeUrlToFile(out, "https://example.com/broken.bin")).rejects.toThrow(
|
|
|
|
|
/stream exploded/i,
|
|
|
|
|
);
|
|
|
|
|
await expect(fs.stat(out)).rejects.toThrow();
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-12-14 00:48:58 +00:00
|
|
|
});
|
2026-02-16 02:00:59 +00:00
|
|
|
|
|
|
|
|
describe("nodes screen helpers", () => {
|
|
|
|
|
it("parses screen.record payload", () => {
|
|
|
|
|
const payload = parseScreenRecordPayload({
|
|
|
|
|
format: "mp4",
|
|
|
|
|
base64: "Zm9v",
|
|
|
|
|
durationMs: 1000,
|
|
|
|
|
fps: 12,
|
|
|
|
|
screenIndex: 0,
|
|
|
|
|
hasAudio: true,
|
|
|
|
|
});
|
|
|
|
|
expect(payload.format).toBe("mp4");
|
|
|
|
|
expect(payload.base64).toBe("Zm9v");
|
|
|
|
|
expect(payload.durationMs).toBe(1000);
|
|
|
|
|
expect(payload.fps).toBe(12);
|
|
|
|
|
expect(payload.screenIndex).toBe(0);
|
|
|
|
|
expect(payload.hasAudio).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("drops invalid optional fields instead of throwing", () => {
|
|
|
|
|
const payload = parseScreenRecordPayload({
|
|
|
|
|
format: "mp4",
|
|
|
|
|
base64: "Zm9v",
|
|
|
|
|
durationMs: "nope",
|
|
|
|
|
fps: null,
|
|
|
|
|
screenIndex: "0",
|
|
|
|
|
hasAudio: 1,
|
|
|
|
|
});
|
|
|
|
|
expect(payload.durationMs).toBeUndefined();
|
|
|
|
|
expect(payload.fps).toBeUndefined();
|
|
|
|
|
expect(payload.screenIndex).toBeUndefined();
|
|
|
|
|
expect(payload.hasAudio).toBeUndefined();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("rejects invalid screen.record payload", () => {
|
|
|
|
|
expect(() => parseScreenRecordPayload({ format: "mp4" })).toThrow(
|
|
|
|
|
/invalid screen\.record payload/i,
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("builds screen record temp path", () => {
|
|
|
|
|
const p = screenRecordTempPath({
|
|
|
|
|
ext: "mp4",
|
|
|
|
|
tmpDir: "/tmp",
|
|
|
|
|
id: "id1",
|
|
|
|
|
});
|
|
|
|
|
expect(p).toBe(path.join("/tmp", "openclaw-screen-record-id1.mp4"));
|
|
|
|
|
});
|
|
|
|
|
});
|