Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ jobs:
run: |
set -euo pipefail
inspector_root="$(node --input-type=module -e 'import path from "node:path"; import { resolvePluginInspectorCliPath } from "./scripts/plugin-inspector-source.mjs"; process.stdout.write(path.dirname(path.dirname(resolvePluginInspectorCliPath())));')"
CRABPOT_PLUGIN_INSPECTOR_CLI=source CRABPOT_PLUGIN_INSPECTOR_DIR="$inspector_root" node scripts/run-plugin-inspector-smoke.mjs --check --runtime --out reports/plugin-inspector-source-smoke
CRABPOT_PLUGIN_INSPECTOR_CLI=source CRABPOT_PLUGIN_INSPECTOR_DIR="$inspector_root" node scripts/run-plugin-inspector-smoke.mjs --check --runtime --resources --out reports/plugin-inspector-source-smoke
packed_root="$(mktemp -d "${RUNNER_TEMP}/plugin-inspector-smoke.XXXXXX")"
trap 'rm -rf "$packed_root"' EXIT
npm pack "$inspector_root" --ignore-scripts --pack-destination "$packed_root" --json > "$packed_root/pack.json"
tarball="$(node --input-type=module -e 'import { readFileSync } from "node:fs"; process.stdout.write(JSON.parse(readFileSync(process.argv[1], "utf8"))[0].filename);' "$packed_root/pack.json")"
npm install --prefix "$packed_root/install" --ignore-scripts --no-audit --no-fund "$packed_root/$tarball"
CRABPOT_PLUGIN_INSPECTOR_BIN="$packed_root/install/node_modules/.bin/plugin-inspector" CRABPOT_PLUGIN_INSPECTOR_DIR="$packed_root/install/node_modules/@openclaw/plugin-inspector" node scripts/run-plugin-inspector-smoke.mjs --check --runtime --out reports/plugin-inspector-packed-smoke
CRABPOT_PLUGIN_INSPECTOR_BIN="$packed_root/install/node_modules/.bin/plugin-inspector" CRABPOT_PLUGIN_INSPECTOR_DIR="$packed_root/install/node_modules/@openclaw/plugin-inspector" node scripts/run-plugin-inspector-smoke.mjs --check --runtime --resources --out reports/plugin-inspector-packed-smoke
- name: Write CI summary artifacts
if: ${{ !cancelled() }}
continue-on-error: true
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.2.2 - Unreleased

- Verify Plugin Inspector's public resource collector in source and packed-package smoke checks, without claiming plugin workload coverage.
- Distinguish caller-owned plugin registry handles from Gateway registry activation in paired resource workloads, preserving exact catalog checks and completed-work requirements.
- Run the report-only bundled resource campaign nightly at 03:43 UTC, retaining manual dispatch, pinned inputs and explicit full-inventory coverage gaps.
- Select resource campaign workloads by inventory distribution while retaining full-inventory coverage gaps and an explicit partial-scope outcome.
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,29 @@ Programmatic callers supplying isolated inputs and runtime can pass an explicit
`gatewayMethodPrerequisites` map to the synthetic runner. Omit satisfied methods
from that map; an empty map exercises every method with normal response checks.

### Inspector resource contract smoke

The source pin includes Inspector's process resource collector. On a trusted
checkout, resolve that source and run the existing smoke with `--resources`:

```bash
inspector_root="$(node --input-type=module -e 'import path from "node:path"; import { resolvePluginInspectorCliPath } from "./scripts/plugin-inspector-source.mjs"; process.stdout.write(path.dirname(path.dirname(resolvePluginInspectorCliPath())));')"
CRABPOT_PLUGIN_INSPECTOR_CLI=source CRABPOT_PLUGIN_INSPECTOR_DIR="$inspector_root" npm run plugin-inspector:smoke -- --resources
```

An explicit `CRABPOT_PLUGIN_INSPECTOR_DIR` selects the source or installed package
under test; without it, the resolver can use a sibling checkout before the pin.
The source and packed CI lanes exercise the public `resource-profile` export and
write `plugin-inspector-resources.json` alongside the existing smoke reports.
The published npm pin stays unchanged until a release includes this API; omit
`--resources` when testing older packages.

This checks collector observations in a fresh child: JSON-transported snapshots,
a retained 1 MiB Buffer, and a timer added then removed. CPU/RSS cover the child
process; other memory and active resources cover its main thread. It does not
measure a plugin workload, peak memory, memory release, or a leak. The child uses
an empty environment; that is not a network sandbox for external plugin code.

### Inspector command limits

Inspector smoke and generated-surface commands default to 10 minutes. Inspector
Expand Down
2 changes: 1 addition & 1 deletion scripts/plugin-inspector-source.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { pathToFileURL } from "node:url";
import { repoRoot } from "./manifest-lib.mjs";
import { configuredTimeoutMs, runOwnedCommand } from "./owned-command.mjs";

export const pluginInspectorRef = "1d27e6906e83e48bd613d49a1921d4d0cf4a4697";
export const pluginInspectorRef = "e2f36f1cdf943826c37303e3632866e12eaf15ce";
export const pluginInspectorPackage = "@openclaw/plugin-inspector@0.3.26";
const defaultGitTimeoutMs = 2 * 60 * 1000;
const defaultNpmTimeoutMs = 2 * 60 * 1000;
Expand Down
18 changes: 16 additions & 2 deletions scripts/run-plugin-inspector-smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const outIndex = args.indexOf("--out");
const outDir = outIndex === -1 ? ".crabpot/plugin-inspector-smoke" : args[outIndex + 1];
const configIndex = args.indexOf("--config");
const configPath = configIndex === -1 ? "crabpot.config.json" : args[configIndex + 1];
if (args.includes("--runtime") && !process.env.CRABPOT_PLUGIN_INSPECTOR_DIR) {
throw new Error("runtime smoke requires CRABPOT_PLUGIN_INSPECTOR_DIR to identify the source or installed package");
if ((args.includes("--runtime") || args.includes("--resources")) && !process.env.CRABPOT_PLUGIN_INSPECTOR_DIR) {
throw new Error("runtime/resource smoke requires CRABPOT_PLUGIN_INSPECTOR_DIR to identify the source or installed package");
}

const inspectorArgs = ["report", "--config", configPath, "--out", outDir, ...(args.includes("--check") ? ["--check"] : [])];
Expand Down Expand Up @@ -62,3 +62,17 @@ if (result.status === 0 && args.includes("--runtime")) {
`${JSON.stringify({ summary: report.summary, results: report.results }, null, 2)}\n`);
console.log("plugin-inspector runtime smoke: PASS (computed tool value; Gateway rejection preserved)");
}

if (result.status === 0 && args.includes("--resources")) {
const resources = runOwnedCommand(process.execPath, [
"test/fixtures/resource-profile-smoke.mjs",
path.resolve(repoRoot, process.env.CRABPOT_PLUGIN_INSPECTOR_DIR),
], { cwd: repoRoot, env: {}, encoding: "utf8", timeout });
assert.ifError(resources.error);
assert.ifError(resources.cleanupError);
assert.equal(resources.status, 0, resources.stderr || resources.stdout);
const report = JSON.parse(resources.stdout);
writeFileSync(path.resolve(repoRoot, outDir, "plugin-inspector-resources.json"),
`${JSON.stringify(report, null, 2)}\n`);
console.log("plugin-inspector resource smoke: PASS (collector contract only; no plugin workload)");
}
46 changes: 46 additions & 0 deletions test/fixtures/resource-profile-smoke.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import assert from "node:assert/strict";
import { createRequire } from "node:module";
import path from "node:path";
import { setImmediate } from "node:timers/promises";
import { pathToFileURL } from "node:url";

// Resolve the public package export in both source and packed installations.
// Importing src/resource-profile.js directly would hide a broken exports map.
const require = createRequire(path.join(process.argv[2], "package.json"));
const { captureProcessResources, diffProcessResources } = await import(pathToFileURL(
require.resolve("@openclaw/plugin-inspector/resource-profile"),
).href);
const capture = () => JSON.parse(JSON.stringify(captureProcessResources()));
await setImmediate();
const before = capture();
const allocation = Buffer.alloc(1024 * 1024, 1);
const timer = setTimeout(() => {}, 60_000);
let active;
try {
active = capture();
} finally {
clearTimeout(timer);
}
await setImmediate();
const disposed = capture();
const allocationDelta = diffProcessResources(before, active);
const disposalDelta = diffProcessResources(active, disposed);
assert.equal(allocation[allocation.length - 1], 1);
assert.equal(before.pid, process.pid);
assert.equal(before.threadId, 0);
for (const sample of [before, active, disposed]) {
for (const value of Object.values(sample.cpuMicros)) assert.ok(Number.isFinite(value) && value >= 0);
for (const value of Object.values(sample.memoryBytes)) assert.ok(Number.isFinite(value) && value >= 0);
}
assert.ok(allocationDelta.wallMs >= 0);
assert.ok(allocationDelta.cpuMs.total >= 0);
assert.ok(allocationDelta.memoryDeltaBytes.arrayBuffers >= allocation.length);
assert.equal(allocationDelta.activeResourceDelta.Timeout, 1);
assert.equal(disposalDelta.activeResourceDelta.Timeout, -1);
process.stdout.write(`${JSON.stringify({
coverage: "collector-contract-only",
runtime: { node: process.version, platform: process.platform, arch: process.arch },
scope: { cpu: "process", rss: "process", otherMemoryAndResources: "thread" },
samples: { before, active, disposed },
deltas: { allocation: allocationDelta, disposal: disposalDelta },
})}\n`);
29 changes: 28 additions & 1 deletion test/plugin-inspector-source.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "../scripts/plugin-inspector-source.mjs";

test("plugin inspector source pin requires an exact prepared checkout", (t) => {
assert.equal(pluginInspectorRef, "1d27e6906e83e48bd613d49a1921d4d0cf4a4697");
assert.equal(pluginInspectorRef, "e2f36f1cdf943826c37303e3632866e12eaf15ce");

const checkoutDir = mkdtempSync(path.join(os.tmpdir(), "crabpot plugin inspector checkout "));
t.after(() => rmSync(checkoutDir, { force: true, recursive: true }));
Expand Down Expand Up @@ -129,6 +129,33 @@ test("plugin inspector smoke check fails on a real missing registration", (t) =>
}
});

test("resource smoke exercises the selected package's public collector export", () => {
const result = spawnSync(process.execPath, [
"test/fixtures/resource-profile-smoke.mjs", path.dirname(path.dirname(resolvePluginInspectorCliPath())),
], { cwd: new URL("..", import.meta.url), env: {}, encoding: "utf8", timeout: 20_000 });
assert.ifError(result.error);
assert.equal(result.status, 0, result.stderr || result.stdout);
const report = JSON.parse(result.stdout);
assert.equal(report.coverage, "collector-contract-only");
assert.equal(report.samples.before.pid, result.pid);
assert.equal(report.deltas.allocation.activeResourceDelta.Timeout, 1);
assert.equal(report.deltas.disposal.activeResourceDelta.Timeout, -1);
});

test("resource smoke fails when the selected package does not export the collector", (t) => {
const root = mkdtempSync(path.join(os.tmpdir(), "crabpot-resource-export-"));
t.after(() => rmSync(root, { force: true, recursive: true }));
writeFileSync(path.join(root, "package.json"), JSON.stringify({
name: "@openclaw/plugin-inspector", exports: { ".": "./index.js" },
}));
const result = spawnSync(process.execPath, ["test/fixtures/resource-profile-smoke.mjs", root], {
cwd: new URL("..", import.meta.url), env: {}, encoding: "utf8", timeout: 20_000,
});
assert.ifError(result.error);
assert.equal(result.status, 1);
assert.match(result.stderr, /ERR_PACKAGE_PATH_NOT_EXPORTED/);
});

test("plugin inspector checkout head probe returns instead of blocking when git hangs", {
skip: process.platform === "win32",
}, (t) => {
Expand Down
Loading