Skip to content

armgit / hypit

Public Imported from GitHub
0

Clone any viral video with AI agents. Not just a script, the whole workflow: swap the face, the words, the B-roll, ship 100 variants in one command, and get your 100M views.

fix: the hygiene scan spells its paths one way on every platform

rpone2bca6728c53e
diff --git a/test/repository-hygiene.test.mjs b/test/repository-hygiene.test.mjs
index abce45dc..a741eabb 100644
--- a/test/repository-hygiene.test.mjs
+++ b/test/repository-hygiene.test.mjs
@@ -1,10 +1,12 @@
import assert from "node:assert/strict";
import { readdir, readFile, stat } from "node:fs/promises";
-import { extname, relative } from "node:path";
+import { extname, relative, sep } from "node:path";
import test from "node:test";
+import { fileURLToPath } from "node:url";
import ts from "typescript";
const repositoryRoot = new URL("../", import.meta.url);
+const repositoryRootPath = fileURLToPath(repositoryRoot);
const scanRoots = ["docs", "examples", "packages", "services", "test"];
const rootTextFiles = ["README.md", "package.json", "pnpm-workspace.yaml", "tsconfig.json"];
const ignoredDirectories = new Set(["node_modules", "dist", "output", ".hypit", ".svml", ".vitepress"]);
@@ -19,7 +21,10 @@ async function repositoryEntries() {
for (const entry of await readdir(url, { withFileTypes: true })) {
if (entry.name.startsWith(".") || ignoredDirectories.has(entry.name)) continue;
const child = new URL(`./${entry.name}${entry.isDirectory() ? "/" : ""}`, url);
- const path = relative(repositoryRoot.pathname, child.pathname);
+ // Every rule below matches this path with a forward-slash pattern, so it has to be spelled
+ // one way on every platform. `URL.pathname` is neither: on Windows it carries a leading
+ // slash before the drive letter, and it percent-encodes a name containing a space.
+ const path = relative(repositoryRootPath, fileURLToPath(child)).split(sep).join("/");
entries.push({ path, child, isFile: entry.isFile() });
if (entry.isDirectory()) await visit(child);
}
@@ -41,6 +46,24 @@ function lineOf(source, offset) {
return source.slice(0, offset).split("\n").length;
}
+/**
+ * Every rule below filters `entry.path` against a forward-slash pattern. A scan that yields
+ * platform-shaped paths, or reaches the wrong tree, or reaches nothing at all, turns each of
+ * them into a loop that never enters its body — which reports exactly what a clean repository
+ * reports. This test is what makes the others mean anything.
+ */
+test("the repository scan reaches the repository", async () => {
+ const entries = await repositoryEntries();
+ const paths = new Set(entries.map((entry) => entry.path));
+ assert.ok(paths.has("test/repository-hygiene.test.mjs"), "the scan must reach this file");
+ assert.deepEqual(entries.filter((entry) => entry.path.includes("\\")).map((entry) => entry.path).slice(0, 5), [],
+ "entry paths are repository-relative and separated by forward slashes");
+ const sources = entries.filter((entry) => /^packages\/[^/]+\/src\/.*\.ts$/u.test(entry.path));
+ assert.ok(sources.length > 300, `expected the package sources, found ${sources.length}`);
+ const manifests = entries.filter((entry) => /^packages\/[^/]+\/package\.json$/u.test(entry.path));
+ assert.ok(manifests.length > 50, `expected the package manifests, found ${manifests.length}`);
+});
+
test("public repository contains no workstation paths or high-confidence secret bytes", async () => {
const workstationPath = /(?:\/Users\/[A-Za-z0-9._-]+\/|\/home\/[A-Za-z0-9._-]+\/|[A-Za-z]:\\Users\\[^\\]+\\)/gu;
const secretBytes = /(?:AKIA[0-9A-Z]{16}|AIza[0-9A-Za-z_-]{30,}|-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----)/gu;
@@ -262,3 +285,42 @@ test("a declared Surface preview names a picture that exists", async () => {
}
assert.deepEqual(failures, [], `declared previews without a picture:\n${failures.join("\n")}`);
});
+
+/** The `child_process` entry points that start a program, and where each one takes its options. */
+const PROCESS_STARTERS = new Map([
+ ["spawn", 2], ["spawnSync", 2], ["execFile", 2], ["execFileSync", 2], ["fork", 2],
+ ["exec", 1], ["execSync", 1],
+]);
+
+test("every child process is started with its console window hidden", async () => {
+ // On Windows a console program started without `windowsHide` is given a window, and the window
+ // is shown. A render is a tree of them — ffmpeg per Need, a browser, a transcriber that re-execs
+ // Python, which opens a pool of workers — so the flag being absent is not one window but dozens,
+ // opening and closing over whatever the author was doing. There is no call here that wants one.
+ const entries = await repositoryEntries();
+ const failures = [];
+ for (const entry of entries) {
+ if (!entry.isFile || !/\.(?:ts|tsx|mts|cts|mjs)$/u.test(entry.path)) continue;
+ const source = await readFile(entry.child, "utf8");
+ if (![...PROCESS_STARTERS.keys()].some((name) => source.includes(name))) continue;
+ const file = ts.createSourceFile(entry.path, source, ts.ScriptTarget.Latest, true,
+ entry.path.endsWith(".tsx") ? ts.ScriptKind.TSX
+ : entry.path.endsWith(".mjs") ? ts.ScriptKind.JS : ts.ScriptKind.TS);
+ const visit = (node) => {
+ if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
+ const at = PROCESS_STARTERS.get(node.expression.text);
+ const options = at === undefined ? undefined : node.arguments[at];
+ // Only a literal can be read here. A call that passes its options along has none to check,
+ // and is answered where the object it passes was written.
+ if (options !== undefined && ts.isObjectLiteralExpression(options)
+ && !objectProperties(options).has("windowsHide")) {
+ const { line } = file.getLineAndCharacterOfPosition(options.getStart(file));
+ failures.push(`${entry.path}:${line + 1} (${node.expression.text})`);
+ }
+ }
+ ts.forEachChild(node, visit);
+ };
+ visit(file);
+ }
+ assert.deepEqual(failures, [], `child processes started with a visible console:\n${failures.join("\n")}`);
+});