mirror of
http://192.168.0.88:13333/lywsvip/openclaw-zero-token.git
synced 2026-05-10 09:08:54 +08:00
Major upgrade from e26988a38 to upstream v2026.3.28 (f9b107928).
Key changes:
- Upstream src/, ui/, extensions/ (89 bundled extensions)
- Zero-token web providers preserved in src/zero-token/
- AskOnce plugin restored and registered as CLI command
- Added missing packages: @anthropic-ai/vertex-sdk, @modelcontextprotocol/sdk
- Fixed tsconfig rootDir, skipLibCheck for plugin-sdk DTS build
- Added askonce to bundled plugin metadata and package.json exports
- Fixed AskOnce CLI command registration (missing commands metadata)
- Restored AskOnce adapter imports (correct 5-level relative paths)
- Removed stale migration artifacts from root directory
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { describe, it, expect, beforeEach, afterEach } from "vitest";
|
|
import { buildImportUrl } from "./import-url.js";
|
|
|
|
describe("buildImportUrl", () => {
|
|
let tmpDir: string;
|
|
let tmpFile: string;
|
|
|
|
beforeEach(() => {
|
|
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "import-url-test-"));
|
|
tmpFile = path.join(tmpDir, "handler.js");
|
|
fs.writeFileSync(tmpFile, "export default () => {};");
|
|
});
|
|
|
|
afterEach(() => {
|
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
});
|
|
|
|
it("returns bare URL for bundled hooks (no query string)", () => {
|
|
const url = buildImportUrl(tmpFile, "openclaw-bundled");
|
|
expect(url).not.toContain("?t=");
|
|
expect(url).toMatch(/^file:\/\//);
|
|
});
|
|
|
|
it("appends mtime-based cache buster for workspace hooks", () => {
|
|
const url = buildImportUrl(tmpFile, "openclaw-workspace");
|
|
expect(url).toMatch(/\?t=[\d.]+&s=\d+/);
|
|
|
|
const { mtimeMs, size } = fs.statSync(tmpFile);
|
|
expect(url).toContain(`?t=${mtimeMs}`);
|
|
expect(url).toContain(`&s=${size}`);
|
|
});
|
|
|
|
it("appends mtime-based cache buster for managed hooks", () => {
|
|
const url = buildImportUrl(tmpFile, "openclaw-managed");
|
|
expect(url).toMatch(/\?t=[\d.]+&s=\d+/);
|
|
});
|
|
|
|
it("appends mtime-based cache buster for plugin hooks", () => {
|
|
const url = buildImportUrl(tmpFile, "openclaw-plugin");
|
|
expect(url).toMatch(/\?t=[\d.]+&s=\d+/);
|
|
});
|
|
|
|
it("returns same URL for bundled hooks across calls (cacheable)", () => {
|
|
const url1 = buildImportUrl(tmpFile, "openclaw-bundled");
|
|
const url2 = buildImportUrl(tmpFile, "openclaw-bundled");
|
|
expect(url1).toBe(url2);
|
|
});
|
|
|
|
it("returns same URL for workspace hooks when file is unchanged", () => {
|
|
const url1 = buildImportUrl(tmpFile, "openclaw-workspace");
|
|
const url2 = buildImportUrl(tmpFile, "openclaw-workspace");
|
|
expect(url1).toBe(url2);
|
|
});
|
|
|
|
it("falls back to Date.now() when file does not exist", () => {
|
|
const url = buildImportUrl("/nonexistent/handler.js", "openclaw-workspace");
|
|
expect(url).toMatch(/\?t=\d+/);
|
|
});
|
|
});
|