Files
adolf/scripts/check-deprecated-api-usage.mjs
alvis bedb527145
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
Vendor OpenClaw source as Adolf fork baseline
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
2026-07-05 09:36:54 +00:00

210 lines
6.5 KiB
JavaScript

#!/usr/bin/env node
// Scans source files for usage of deprecated API markers.
import fs from "node:fs";
import path from "node:path";
import { collectDeprecatedInternalConfigApiViolations } from "./lib/deprecated-config-api-guard.mjs";
import { buildDeprecatedPluginSdkModuleSpecifiers } from "./lib/deprecated-plugin-sdk-usage.mjs";
import { escapeRegExp } from "./lib/regexp.mjs";
const repoRoot = process.cwd();
const sourceExtensions = new Set([".ts", ".tsx", ".js", ".mjs", ".mts"]);
const skippedSegments = new Set(["node_modules", "dist", "build", "coverage", ".turbo"]);
const skippedFilePatterns = [
/\.test\.[cm]?[jt]sx?$/u,
/\.spec\.[cm]?[jt]sx?$/u,
/\.e2e\.[cm]?[jt]sx?$/u,
/\.test-(?:harness|loader|support)\.[cm]?[jt]sx?$/u,
/\.contract-test-support\.[cm]?[jt]sx?$/u,
/(?:^|\/)test-(?:helpers|support)\.[cm]?[jt]sx?$/u,
/(?:^|\/)(?:test-helpers|test-support)\//u,
/^extensions\/test-support\//u,
/^src\/channels\/plugins\/contracts\/test-helpers\//u,
/^src\/plugins\/contracts\/tts-contract-suites\.ts$/u,
/\.d\.ts$/u,
];
function toRepoPath(filePath) {
return path.relative(repoRoot, filePath).split(path.sep).join("/");
}
function shouldSkipFile(filePath, rule) {
const repoPath = toRepoPath(filePath);
return (rule.skippedFilePatterns ?? skippedFilePatterns).some((pattern) =>
pattern.test(repoPath),
);
}
function* walk(dir, rule) {
if (!fs.existsSync(dir)) {
return;
}
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
if (skippedSegments.has(entry.name)) {
continue;
}
const entryPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
yield* walk(entryPath, rule);
continue;
}
if (!entry.isFile() || !sourceExtensions.has(path.extname(entry.name))) {
continue;
}
if (!shouldSkipFile(entryPath, rule)) {
yield entryPath;
}
}
}
function collectIdentifierRuleViolations(rule) {
const allowedFiles = new Set(rule.allowedFiles ?? []);
const pattern = new RegExp(
`\\b(?:${rule.names.map((name) => escapeRegExp(name)).join("|")})\\b`,
"gu",
);
const violations = [];
for (const root of rule.roots) {
for (const filePath of walk(path.join(repoRoot, root), rule)) {
const repoPath = toRepoPath(filePath);
if (allowedFiles.has(repoPath)) {
continue;
}
const source = fs.readFileSync(filePath, "utf8");
for (const match of source.matchAll(pattern)) {
const line = source.slice(0, match.index).split("\n").length;
violations.push(`${repoPath}:${line}: ${match[0]} (${rule.message})`);
}
}
}
return violations;
}
function collectModuleSpecifierRuleViolations(rule) {
const allowedFiles = new Set(rule.allowedFiles ?? []);
const specifierPattern = rule.moduleSpecifiers
.map((specifier) => escapeRegExp(specifier))
.join("|");
const patterns = [
new RegExp(
`\\bimport\\s+(?:type\\s+)?(?:[^"']+?\\s+from\\s+)?["'](${specifierPattern})["']`,
"gu",
),
new RegExp(
`\\bexport\\s+(?:type\\s+)?(?:\\*\\s+from\\s+|[^"']+?\\s+from\\s+)["'](${specifierPattern})["']`,
"gu",
),
new RegExp(`\\bimport\\(\\s*["'](${specifierPattern})["']\\s*\\)`, "gu"),
];
const violations = [];
for (const root of rule.roots) {
for (const filePath of walk(path.join(repoRoot, root), rule)) {
const repoPath = toRepoPath(filePath);
if (allowedFiles.has(repoPath)) {
continue;
}
const source = fs.readFileSync(filePath, "utf8");
for (const pattern of patterns) {
for (const match of source.matchAll(pattern)) {
const line = source.slice(0, match.index).split("\n").length;
violations.push(`${repoPath}:${line}: ${match[1]} (${rule.message})`);
}
}
}
}
return violations;
}
function collectRuleViolations(rule) {
if (rule.collect) {
return rule.collect();
}
if (rule.moduleSpecifiers) {
return collectModuleSpecifierRuleViolations(rule);
}
return collectIdentifierRuleViolations(rule);
}
const rules = [
{
id: "internal-config-api",
collect: () => collectDeprecatedInternalConfigApiViolations(),
},
{
id: "plugin-sdk-compat-subpaths",
roots: ["src", "packages"],
moduleSpecifiers: buildDeprecatedPluginSdkModuleSpecifiers(),
message: "use focused non-deprecated plugin SDK subpaths",
},
{
id: "extension-plugin-sdk-compat-subpaths",
roots: ["extensions"],
moduleSpecifiers: buildDeprecatedPluginSdkModuleSpecifiers(),
message: "extensions must use focused non-deprecated plugin SDK subpaths",
},
{
id: "message-api",
roots: ["src", "extensions", "packages"],
names: [
"deliverOutboundPayloads",
"dispatchChannelMessageReplyWithBase",
"recordChannelMessageReplyDispatch",
"buildChannelMessageReplyDispatchBase",
"hasFinalChannelMessageReplyDispatch",
"hasVisibleChannelMessageReplyDispatch",
"resolveChannelMessageReplyDispatchCounts",
"createChannelTurnReplyPipeline",
"deliverDurableInboundReplyPayload",
],
allowedFiles: [
"src/channels/turn/durable-delivery.ts",
"src/channels/turn/kernel.ts",
"src/channels/message/inbound-reply-dispatch.ts",
"src/infra/outbound/deliver-runtime.ts",
"src/infra/outbound/deliver.ts",
"src/plugin-sdk/channel-message-runtime.ts",
"src/plugin-sdk/channel-message.ts",
"src/plugin-sdk/channel-test-helpers.ts",
"src/plugin-sdk/inbound-reply-dispatch.ts",
"src/plugin-sdk/outbound-runtime.ts",
"src/plugin-sdk/test-helpers/outbound-delivery.ts",
"src/plugin-sdk/testing.ts",
],
message: "use sendDurableMessageBatch or deliverInboundReplyWithMessageSendContext",
},
];
const selectedRuleIds = new Set(
process.argv
.slice(2)
.filter((arg) => arg.startsWith("--rule="))
.map((arg) => arg.slice("--rule=".length)),
);
const selectedRules =
selectedRuleIds.size === 0 ? rules : rules.filter((rule) => selectedRuleIds.has(rule.id));
const unknownRuleIds = [...selectedRuleIds].filter((id) => !rules.some((rule) => rule.id === id));
if (unknownRuleIds.length > 0) {
console.error(`Unknown deprecated API usage rule(s): ${unknownRuleIds.join(", ")}`);
process.exit(1);
}
const violations = selectedRules.flatMap((rule) =>
collectRuleViolations(rule).map((violation) => `${rule.id}: ${violation}`),
);
if (violations.length > 0) {
console.error("Deprecated API usage guard failed:");
for (const violation of violations) {
console.error(`- ${violation}`);
}
process.exit(1);
}
console.log("deprecated API usage guard passed");