Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-8800 fix(scripts): run entry guards on real paths so symlinked runs don't silently pass (#10158)
Jiayuan Zhang7a926b824fcf
diff --git a/apps/desktop/scripts/package.mjs b/apps/desktop/scripts/package.mjsindex 9c57e3355d..02f1d07181 100644--- a/apps/desktop/scripts/package.mjs+++ b/apps/desktop/scripts/package.mjs@@ -27,9 +27,9 @@// real `git describe` invocation against a throwaway repo.import { execFileSync, spawnSync } from "node:child_process";-import { rmSync } from "node:fs";+import { realpathSync, rmSync } from "node:fs";import { delimiter, dirname, resolve } from "node:path";-import { fileURLToPath, pathToFileURL } from "node:url";+import { fileURLToPath } from "node:url";const here = dirname(fileURLToPath(import.meta.url));const desktopRoot = resolve(here, "..");@@ -476,7 +476,7 @@ function main() {// Only run when invoked as a CLI, not when imported by a test file.if (process.argv[1] &&- import.meta.url === pathToFileURL(process.argv[1]).href+ realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) {main();}diff --git a/packages/ui/icons/drawings/generate.mjs b/packages/ui/icons/drawings/generate.mjsindex 6462569eeb..e1a2a8df7e 100644--- a/packages/ui/icons/drawings/generate.mjs+++ b/packages/ui/icons/drawings/generate.mjs@@ -3,7 +3,7 @@// pnpm --filter @multica/ui icons --check exit 1 if either is stale// pnpm --filter @multica/ui icons --preview [Name…] write a contact sheet and print its path-import { readFileSync, writeFileSync } from "node:fs";+import { readFileSync, realpathSync, writeFileSync } from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import { fileURLToPath } from "node:url";@@ -96,7 +96,7 @@ figcaption{color:#71717a;max-width:100%;overflow:hidden;text-overflow:ellipsis}</style>${tiles.join("")}`;}-if (process.argv[1] === fileURLToPath(import.meta.url)) {+if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) {const preview = process.argv.indexOf("--preview");if (preview !== -1) {const names = process.argv.slice(preview + 1);diff --git a/scripts/brand/sync.mjs b/scripts/brand/sync.mjsindex 513959413b..2acbc6cba5 100644--- a/scripts/brand/sync.mjs+++ b/scripts/brand/sync.mjs@@ -7,7 +7,7 @@// node scripts/brand/sync.mjs --check exit 1 if any copy drifted (CI)//// Dependency-free on purpose: CI runs it without installing node_modules.-import { readFileSync, writeFileSync } from "node:fs";+import { readFileSync, realpathSync, writeFileSync } from "node:fs";import { dirname, join, resolve } from "node:path";import { fileURLToPath, pathToFileURL } from "node:url";@@ -108,7 +108,7 @@ export async function sync(root, { check = false } = {}) {return drifted;}-if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {+if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) {const args = process.argv.slice(2);const check = args.includes("--check");const rootAt = args.indexOf("--root");diff --git a/scripts/check-dependency-catalog.mjs b/scripts/check-dependency-catalog.mjsindex 0f4f1e775f..02c45c92e3 100644--- a/scripts/check-dependency-catalog.mjs+++ b/scripts/check-dependency-catalog.mjs@@ -14,7 +14,7 @@* Run: node scripts/check-dependency-catalog.mjs*/-import { existsSync, readdirSync, readFileSync } from "node:fs";+import { existsSync, readdirSync, readFileSync, realpathSync } from "node:fs";import { join, resolve } from "node:path";import { fileURLToPath } from "node:url";@@ -141,4 +141,4 @@ function main() {console.log(`Dependency catalog clean (${workspaces.length} workspaces checked).`);}-if (resolve(process.argv[1] ?? "") === fileURLToPath(import.meta.url)) main();+if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) main();diff --git a/scripts/check-dependency-catalog.test.mjs b/scripts/check-dependency-catalog.test.mjsindex 43672d6c4c..ec5260d99f 100644--- a/scripts/check-dependency-catalog.test.mjs+++ b/scripts/check-dependency-catalog.test.mjs@@ -1,5 +1,10 @@import assert from "node:assert/strict";+import { spawnSync } from "node:child_process";+import { copyFileSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from "node:fs";+import { tmpdir } from "node:os";+import { join } from "node:path";import test from "node:test";+import { fileURLToPath } from "node:url";import { catalogViolations, parseWorkspaceManifest } from "./check-dependency-catalog.mjs";@@ -93,3 +98,31 @@ test("allowlisted drift passes until it is gone, then must be removed", () => {assert.equal(aligned.length, 1);assert.match(aligned[0], /^fumadocs-core: allowlisted but no longer/);});++test("still checks when run through a symlinked path", (t) => {+ // Node gives the main module its real path but keeps argv[1] as typed, so a+ // guard comparing the two unresolved would skip main() and exit 0 silently.+ const root = mkdtempSync(join(tmpdir(), "dependency-catalog-entry-"));+ t.after(() => rmSync(root, { recursive: true, force: true }));+ const repo = join(root, "repo");+ mkdirSync(join(repo, "scripts"), { recursive: true });+ copyFileSync(+ fileURLToPath(new URL("./check-dependency-catalog.mjs", import.meta.url)),+ join(repo, "scripts", "check-dependency-catalog.mjs"),+ );+ writeFileSync(join(repo, "pnpm-workspace.yaml"), "packages:\n - packages/*\n");+ writeFileSync(join(repo, "package.json"), "{}");+ for (const name of ["a", "b"]) {+ mkdirSync(join(repo, "packages", name), { recursive: true });+ writeFileSync(join(repo, "packages", name, "package.json"), JSON.stringify({ dependencies: { sonner: "^2.0.7" } }));+ }+ symlinkSync(repo, join(root, "link"), "dir");++ const run = (dir) =>+ spawnSync(process.execPath, [join(root, dir, "scripts", "check-dependency-catalog.mjs")], { encoding: "utf8" });+ const linked = run("link");+ assert.equal(linked.status, 1);+ assert.match(linked.stderr, /sonner: declared by 2 workspaces/);+ const direct = run("repo");+ assert.deepEqual([linked.status, linked.stdout, linked.stderr], [direct.status, direct.stdout, direct.stderr]);+});diff --git a/scripts/check-ui-radius-tokens.mjs b/scripts/check-ui-radius-tokens.mjsindex e00336786f..1796a9a8bb 100644--- a/scripts/check-ui-radius-tokens.mjs+++ b/scripts/check-ui-radius-tokens.mjs@@ -11,7 +11,7 @@* Run: node scripts/check-ui-radius-tokens.mjs*/-import { readdirSync, readFileSync } from "node:fs";+import { readdirSync, readFileSync, realpathSync } from "node:fs";import { extname, join, relative, resolve, sep } from "node:path";import { fileURLToPath } from "node:url";import ts from "typescript";@@ -158,4 +158,4 @@ function main() {console.log(`UI radius tokens clean (${files.length} source files checked).`);}-if (resolve(process.argv[1] ?? "") === fileURLToPath(import.meta.url)) main();+if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) main();diff --git a/scripts/ci-scope.mjs b/scripts/ci-scope.mjsindex 3d8d0b8d0d..f1941999fe 100644--- a/scripts/ci-scope.mjs+++ b/scripts/ci-scope.mjs@@ -1,7 +1,7 @@#!/usr/bin/env node// Path filtering and aggregate gates share this fail-closed decision contract.-import { appendFileSync, readFileSync } from "node:fs";-import { pathToFileURL } from "node:url";+import { appendFileSync, readFileSync, realpathSync } from "node:fs";+import { fileURLToPath } from "node:url";export const filters = JSON.parse(readFileSync(new URL("../.github/ci-paths.json", import.meta.url), "utf8"),@@ -47,7 +47,7 @@ export function checkGate(needs, jobScopes) {}}-if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {+if (process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url))) {try {switch (process.argv[2]) {case "decide": {