Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
200 lines
5.9 KiB
TypeScript
200 lines
5.9 KiB
TypeScript
// Gh Read tests cover gh read script behavior.
|
|
import { execFileSync } from "node:child_process";
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
buildReadPermissions,
|
|
githubJson,
|
|
normalizeRepo,
|
|
parsePermissionKeys,
|
|
parseRepoArg,
|
|
readBoundedGitHubErrorText,
|
|
readBoundedGitHubJson,
|
|
resolveGitHubFetchTimeoutMs,
|
|
} from "../../scripts/gh-read.js";
|
|
|
|
describe("gh-read helpers", () => {
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it("prints wrapper usage before reading auth env", () => {
|
|
let stderr = "";
|
|
try {
|
|
execFileSync("bash", ["scripts/gh-read"], {
|
|
cwd: process.cwd(),
|
|
encoding: "utf8",
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
} catch (error) {
|
|
stderr = String((error as { stderr?: unknown }).stderr ?? error);
|
|
}
|
|
|
|
expect(stderr).toContain("usage: scripts/gh-read <gh args...>");
|
|
expect(stderr).toContain("OPENCLAW_GH_READ_APP_ID");
|
|
});
|
|
|
|
it("finds repo from gh args", () => {
|
|
expect(parseRepoArg(["pr", "view", "42", "-R", "openclaw/openclaw"])).toBe("openclaw/openclaw");
|
|
expect(parseRepoArg(["run", "list", "--repo=openclaw/docs"])).toBe("openclaw/docs");
|
|
expect(parseRepoArg(["pr", "view", "42"])).toBeNull();
|
|
});
|
|
|
|
it("normalizes repo strings from common git formats", () => {
|
|
expect(normalizeRepo("openclaw/openclaw")).toBe("openclaw/openclaw");
|
|
expect(normalizeRepo("github.com/openclaw/openclaw")).toBe("openclaw/openclaw");
|
|
expect(normalizeRepo("https://github.com/openclaw/openclaw.git")).toBe("openclaw/openclaw");
|
|
expect(normalizeRepo("git@github.com:openclaw/openclaw.git")).toBe("openclaw/openclaw");
|
|
expect(normalizeRepo("invalid")).toBeNull();
|
|
});
|
|
|
|
it("builds a read-only permission subset from granted permissions", () => {
|
|
expect(
|
|
buildReadPermissions(
|
|
{
|
|
actions: "write",
|
|
issues: "read",
|
|
administration: "write",
|
|
metadata: "read",
|
|
statuses: null,
|
|
},
|
|
["actions", "issues", "metadata", "statuses", "administration"],
|
|
),
|
|
).toEqual({
|
|
administration: "read",
|
|
actions: "read",
|
|
issues: "read",
|
|
metadata: "read",
|
|
});
|
|
});
|
|
|
|
it("parses permission key overrides", () => {
|
|
expect(parsePermissionKeys(undefined)).toContain("pull_requests");
|
|
expect(parsePermissionKeys("actions, contents ,issues")).toEqual([
|
|
"actions",
|
|
"contents",
|
|
"issues",
|
|
]);
|
|
});
|
|
|
|
it("aborts stalled GitHub API fetches at the request timeout", async () => {
|
|
let signal: AbortSignal | undefined;
|
|
let markFetchStarted!: () => void;
|
|
const fetchStarted = new Promise<void>((resolve) => {
|
|
markFetchStarted = resolve;
|
|
});
|
|
|
|
vi.useFakeTimers();
|
|
const request = githubJson("/app", "token", undefined, {
|
|
timeoutMs: 5,
|
|
fetchImpl: ((_url, init) => {
|
|
signal = init?.signal ?? undefined;
|
|
markFetchStarted();
|
|
return new Promise(() => {});
|
|
}) as typeof fetch,
|
|
});
|
|
const rejection = expect(request).rejects.toThrow(/GitHub API GET \/app exceeded timeout/u);
|
|
|
|
await fetchStarted;
|
|
await vi.advanceTimersByTimeAsync(5);
|
|
|
|
await rejection;
|
|
expect(signal?.aborted).toBe(true);
|
|
});
|
|
|
|
it("times out stalled GitHub API response body reads", async () => {
|
|
let canceled = false;
|
|
vi.useFakeTimers();
|
|
const response = new Response(
|
|
new ReadableStream({
|
|
pull() {
|
|
return new Promise(() => {});
|
|
},
|
|
cancel() {
|
|
canceled = true;
|
|
},
|
|
}),
|
|
{ status: 200 },
|
|
);
|
|
const request = githubJson("/app/installations", "token", undefined, {
|
|
timeoutMs: 5,
|
|
fetchImpl: (() => Promise.resolve(response)) as typeof fetch,
|
|
});
|
|
const rejection = expect(request).rejects.toThrow(
|
|
/GitHub API GET \/app\/installations exceeded timeout/u,
|
|
);
|
|
|
|
await vi.advanceTimersByTimeAsync(5);
|
|
|
|
await rejection;
|
|
await Promise.resolve();
|
|
expect(canceled).toBe(true);
|
|
});
|
|
|
|
it("bounds GitHub API error response bodies", async () => {
|
|
const tail = "tail-sentinel-should-not-appear";
|
|
const response = new Response(`${"x".repeat(5000)}${tail}`, {
|
|
status: 500,
|
|
});
|
|
|
|
const text = await readBoundedGitHubErrorText(response);
|
|
|
|
expect(text).toContain("[truncated]");
|
|
expect(text).not.toContain(tail);
|
|
expect(text.length).toBeLessThan(4200);
|
|
});
|
|
|
|
it("reads bounded GitHub API JSON responses", async () => {
|
|
await expect(readBoundedGitHubJson(new Response('{"id":123}'), 1024)).resolves.toEqual({
|
|
id: 123,
|
|
});
|
|
});
|
|
|
|
it("rejects oversized GitHub API JSON responses by content length", async () => {
|
|
let canceled = false;
|
|
const response = new Response(
|
|
new ReadableStream({
|
|
cancel() {
|
|
canceled = true;
|
|
},
|
|
}),
|
|
{
|
|
headers: {
|
|
"content-length": "1025",
|
|
},
|
|
},
|
|
);
|
|
|
|
await expect(readBoundedGitHubJson(response, 1024)).rejects.toMatchObject({
|
|
code: "ETOOBIG",
|
|
message: "GitHub API response body exceeded 1024 bytes",
|
|
});
|
|
expect(canceled).toBe(true);
|
|
});
|
|
|
|
it("rejects oversized streamed GitHub API JSON responses", async () => {
|
|
const encoder = new TextEncoder();
|
|
const response = new Response(
|
|
new ReadableStream({
|
|
start(controller) {
|
|
controller.enqueue(encoder.encode('{"body":"'));
|
|
controller.enqueue(encoder.encode("x".repeat(1024)));
|
|
controller.enqueue(encoder.encode('"}'));
|
|
controller.close();
|
|
},
|
|
}),
|
|
);
|
|
|
|
await expect(readBoundedGitHubJson(response, 1024)).rejects.toMatchObject({
|
|
code: "ETOOBIG",
|
|
message: "GitHub API response body exceeded 1024 bytes",
|
|
});
|
|
});
|
|
|
|
it("rejects invalid GitHub API timeout values", () => {
|
|
expect(resolveGitHubFetchTimeoutMs("1000")).toBe(1000);
|
|
expect(() => resolveGitHubFetchTimeoutMs("1s")).toThrow(
|
|
/OPENCLAW_GH_READ_FETCH_TIMEOUT_MS must be an integer/u,
|
|
);
|
|
});
|
|
});
|