Files
adolf/scripts/check-duplicates.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

209 lines
4.7 KiB
JavaScript

#!/usr/bin/env node
// Runs duplicate-code detection with repo-specific excludes.
import { spawnSync } from "node:child_process";
import path from "node:path";
import { fileURLToPath } from "node:url";
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
const jscpdBin = path.join(repoRoot, "node_modules", "jscpd", "bin", "jscpd");
const targets = [
"src",
"extensions",
"examples",
"scripts",
"packages",
"ui",
"apps",
"docs",
"qa",
"security",
"test",
"skills",
"openclaw.mjs",
"config/knip.config.ts",
"tsdown.ai.config.ts",
"tsdown.config.ts",
"vitest.config.ts",
];
const sourceExtensions = new Set([".ts", ".tsx", ".js", ".mjs", ".cjs"]);
const sourcePattern = "**/*.{ts,tsx,js,mjs,cjs}";
const testPattern = "**/*.{test,e2e.test,live.test}.{ts,tsx,js,mjs,cjs}";
// Keep local agent support trees and vendored snapshots classified but outside jscpd.
const intentionallyUnscannedPrefixes = [".agents/", "vendor/"];
const generatedIgnores = [
"extensions/qa-matrix/src/shared/**",
"extensions/qa-matrix/src/cli-paths.ts",
"**/node_modules/**",
"**/dist/**",
"**/.git/**",
"**/coverage/**",
"**/build/**",
"**/.build/**",
"**/.artifacts/**",
"vendor/**",
];
const testIgnores = [
"**/*.test.ts",
"**/*.test.tsx",
"**/*.test.js",
"**/*.test.mjs",
"**/*.test.cjs",
"**/*.e2e.test.ts",
"**/*.e2e.test.tsx",
"**/*.e2e.test.js",
"**/*.e2e.test.mjs",
"**/*.e2e.test.cjs",
"**/*.live.test.ts",
"**/*.live.test.tsx",
"**/*.live.test.js",
"**/*.live.test.mjs",
"**/*.live.test.cjs",
];
const commonArgs = [
"--format",
"typescript,javascript",
"--gitignore",
"--noSymlinks",
"--min-lines",
"50",
"--min-tokens",
"300",
];
const json = process.argv.includes("--json");
const coverageOnly = process.argv.includes("--coverage");
function normalizeRepoPath(value) {
return value.split(path.sep).join("/");
}
function isUnderPrefix(value, prefix) {
return value === prefix.slice(0, -1) || value.startsWith(prefix);
}
function isCoveredByTargets(file) {
return targets.some((target) => {
const normalizedTarget = normalizeRepoPath(target);
if (file === normalizedTarget) {
return true;
}
return file.startsWith(`${normalizedTarget}/`);
});
}
function listTrackedSourceFiles() {
const result = spawnSync("git", ["ls-files", "-z"], {
cwd: repoRoot,
encoding: "utf8",
maxBuffer: 64 * 1024 * 1024,
});
if (result.status !== 0) {
throw new Error(result.stderr || "git ls-files failed");
}
return result.stdout
.split("\0")
.filter(Boolean)
.map(normalizeRepoPath)
.filter((file) => sourceExtensions.has(path.extname(file)))
.filter((file) => !intentionallyUnscannedPrefixes.some((prefix) => isUnderPrefix(file, prefix)))
.toSorted((left, right) => left.localeCompare(right));
}
function assertTargetCoverage() {
const uncovered = listTrackedSourceFiles().filter((file) => !isCoveredByTargets(file));
if (uncovered.length === 0) {
console.log(`[dup:check] target coverage ok`);
return true;
}
console.error(
"[dup:check] tracked duplicate-scan source files are outside scan targets or intentional excludes:",
);
for (const file of uncovered) {
console.error(` - ${file}`);
}
return false;
}
function reportArgs(name) {
if (!json) {
return ["--reporters", "console"];
}
return ["--reporters", "json", "--output", path.join(".artifacts", "jscpd", name)];
}
const scans = [
{
name: "production",
targets,
pattern: sourcePattern,
ignore: [...testIgnores, ...generatedIgnores],
},
{
name: "tests",
targets,
pattern: testPattern,
ignore: generatedIgnores,
},
{
name: "src-mixed",
targets: ["src"],
pattern: sourcePattern,
ignore: generatedIgnores,
},
{
name: "extensions-mixed",
targets: ["extensions"],
pattern: sourcePattern,
ignore: generatedIgnores,
},
{
name: "test-mixed",
targets: ["test"],
pattern: sourcePattern,
ignore: generatedIgnores,
},
];
let failed = !assertTargetCoverage();
if (coverageOnly) {
process.exit(failed ? 1 : 0);
}
for (const scan of scans) {
console.log(`\n[dup:check] ${scan.name}`);
const result = spawnSync(
process.execPath,
[
"--max-old-space-size=8192",
jscpdBin,
...scan.targets,
...commonArgs,
"--pattern",
scan.pattern,
"--ignore",
scan.ignore.join(","),
...reportArgs(scan.name),
],
{
cwd: repoRoot,
env: process.env,
stdio: "inherit",
},
);
if (result.status !== 0) {
failed = true;
}
if (result.error) {
console.error(result.error.message);
failed = true;
}
}
if (failed) {
process.exit(1);
}