/** * NO COMMENT SENDS A READER TO THE ELECTRON MAC APP'S SOURCE TREE. * * `apps/cotton-mac/src/` was the Electron app — a main process, a renderer and * the IPC between them. #395 replaced it with a Swift package over the Rust * core and deleted the tree whole. * * Why that is worth a guard rather than a tidy-up. A provenance comment is * read by somebody who wants to see the original, and the shape of the * sentence — "a port of X" — says X is a file they can open. It is not, and * nothing tells them so: `tsc`, `cargo` and the import graph cannot see inside * a comment, so the path rots silently and the reader spends the search * finding out. The repo already knows this failure mode — a guard that reads * another package's file BY PATH goes quiet, not red, when the file moves * (AGENTS.md, *Tests*) — and this is the same fact one layer down, in prose. * * THE FIX IS NOT TO RELABEL THE PROVENANCE. This guard once said it was — * "name it as history" — and the owner has since ruled the other way: a * sentence whose only content is where the code came from is an obituary and * goes, and a sentence that still explains a live decision is rewritten in the * present tense with the citation removed. Neither outcome leaves a path * behind, which is what this guard is actually about. * * One form survives and is exempt below: * * … (`git log --diff-filter=D --oneline -- apps/cotton-mac/src/main/lan.ts`) * * It is the runbooks' own idiom, and a line that hands the reader the command * to read the file out of git is not sending them anywhere that does not * exist. The other form this comment used to recommend — "a port of the * deleted Electron app's `main/backup/runtime.ts`" — is exactly what the * phrasing sweep removes, so nothing should be written that way again. * * WHAT THIS DOES NOT COVER, and why. `apps/cotton-mac/__tests__/` is the same * story — comments naming test files that went with the app — but that * DIRECTORY still exists (`iconset.test.ts` is in it), so the marker cannot * be a prefix and the honest guard is "a path under `apps/cotton-mac/` that * is not on disk", which is a different and larger test. It is named here so * the next person does not have to rediscover the gap. */ import { execFileSync } from "node:child_process"; import { dirname, relative, resolve } from "node:path"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; const REPO_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "../.."); const THIS_FILE = relative(REPO_ROOT, fileURLToPath(import.meta.url)); /** The deleted tree, spelled the way every surviving comment spelled it. */ const MARKER = "apps/cotton-mac/src/"; /** A line that hands the reader the command to read the file out of git. */ const ARCHAEOLOGY = "--diff-filter=D"; interface Offender { path: string; line: number; text: string; } /** * Every line in the tree that names the deleted source tree. * * `git grep` rather than a hand-rolled walk: it knows what is tracked, so * `node_modules`, build output and generated native trees are out by * construction rather than by an ignore list that would rot. `--untracked` is * on because a file added but not yet committed is still a file that ships. */ function linesNamingTheDeletedTree(): Offender[] { let output = ""; try { output = execFileSync( "git", ["grep", "--fixed-strings", "--line-number", "--untracked", MARKER], { cwd: REPO_ROOT, encoding: "utf8", maxBuffer: 32 * 1024 * 1024 }, ); } catch (error) { // `git grep` exits 1 when nothing matched, which is the state we want. if ((error as { status?: number }).status === 1) return []; throw error; } return output .split("\n") .filter(Boolean) .map((row) => { const [path, line, ...rest] = row.split(":"); return { path, line: Number(line), text: rest.join(":") }; }) .filter((offender) => offender.path !== THIS_FILE) .filter((offender) => !offender.text.includes(ARCHAEOLOGY)); } describe("the Electron Mac app's source tree", () => { it("is named by no comment, doc or runbook step anywhere in the tree", () => { const offenders = linesNamingTheDeletedTree(); expect( offenders.map((offender) => `${offender.path}:${offender.line}`), `A comment must not send a reader to ${MARKER}, which #395 deleted. Say it as ` + "history instead — \"the deleted Electron app's `main/…`\" — or hand the reader " + `the command (a line carrying \`${ARCHAEOLOGY}\` is exempt).`, ).toEqual([]); }); });