Files
hyperframes/scripts/check-symlinks.mjs
T
James RussoandClaude Opus 5.5 9320c44e13 fix: docs image upload publishes only regular files, and CI rejects new symlinks (#7776)
scripts/upload-docs-images.sh synced docs/images/ with the AWS CLI's default
of following symbolic links, so a link committed under docs/images/ would
publish whatever it pointed to on the machine running the upload. The script
now stops before any AWS call when docs/images is not a real folder in the
checkout or when anything under it is a link or not a regular file, and the
sync passes --no-follow-symlinks as well.

A new check, scripts/check-symlinks.mjs, fails CI when a tracked symbolic
link is not one of the two the repo already means to have.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 00:47:08 +00:00

61 lines
2.0 KiB
JavaScript

import { spawnSync } from "node:child_process";
import { resolve } from "node:path";
import { fileURLToPath } from "node:url";
/**
* The symbolic links the repo means to track. Any other link fails the check: tooling that publishes or reads
* the tree (the docs image upload, registry and skills packaging) would follow it to whatever it names on the
* machine running it.
*/
export const ALLOWED_SYMLINKS = new Set([
"packages/cli/src/audio/scripts",
"packages/producer/tests/render-symlinked-assets/src/shared",
]);
/** Paths of `git ls-files -s -z` entries with the symlink mode (120000). */
export function symlinkPaths(stagedListing) {
return stagedListing
.split("\0")
.filter(Boolean)
.filter((entry) => entry.startsWith("120000 "))
.map((entry) => entry.slice(entry.indexOf("\t") + 1));
}
export function findUnexpectedSymlinks(paths, allowed = ALLOWED_SYMLINKS) {
return paths.filter((path) => !allowed.has(path)).sort();
}
export function readStagedListing(cwd = process.cwd()) {
const result = spawnSync("git", ["ls-files", "-s", "-z"], {
cwd,
encoding: "utf8",
maxBuffer: 64 * 1024 * 1024,
});
if (result.error) throw result.error;
if (result.status !== 0) {
throw new Error(result.stderr.trim() || `git ls-files exited with status ${result.status}`);
}
return result.stdout;
}
export function checkSymlinks(cwd = process.cwd()) {
return findUnexpectedSymlinks(symlinkPaths(readStagedListing(cwd)));
}
function main() {
const unexpected = checkSymlinks();
if (unexpected.length === 0) {
console.log("Symlink check passed.");
return;
}
console.error(
"Symbolic links are tracked that are not on the allowlist in scripts/check-symlinks.mjs:",
);
for (const path of unexpected) console.error(`- ${path}`);
console.error("Commit the file itself instead of a link to it.");
process.exitCode = 1;
}
const entryPath = process.argv[1] ? resolve(process.argv[1]) : null;
if (entryPath === fileURLToPath(import.meta.url)) main();