import { readdirSync, readFileSync, existsSync } from"node:fs";import { join } from"node:path";import { describe, expect, it } from"vitest";// A `[target.'cfg(…)'.dependencies]` header ENDS the table above it. In #422// the Apple-only `native-tls` table was written in the middle of// `cotton-client`'s `[dependencies]`, so every optional host crate below it —// `tokio-tungstenite`, `cotton-relay-protocol`, `rustls`, `instant-acme`… —// was silently Apple-only. macOS built and tested green; the Linux `rust` job// compiled the tunnel with no crates behind it. `cargo` reports nothing: a// dependency that moved tables is a legal manifest.//// The rule this repo keeps: a target-scoped dependency table comes AFTER every// plain one (`[dependencies]`, `[dev-dependencies]`, `[build-dependencies]`),// so a line under it is scoped on purpose and never by position.const CRATES = join(__dirname, "..", "..", "crates");const PLAIN = /^\[(dependencies|dev-dependencies|build-dependencies)\]\s*$/;const TARGET = /^\[target\..*\.(dependencies|dev-dependencies|build-dependencies)\]\s*$/;function manifests(): string[] { expect(existsSync(CRATES), `no crates dir at ${CRATES} — the Rust core lane's path`).toBe(true);return readdirSync(CRATES) .map((name) => join(CRATES, name, "Cargo.toml")) .filter((path) => existsSync(path));}describe("a target-scoped dependency table comes after every plain one", () => {const files = manifests(); it("finds the crates", () => { expect(files.length).toBeGreaterThan(5); });for (const file of files) { it(file.replace(CRATES + "/", ""), () => {const lines = readFileSync(file, "utf8").split("\n");let firstTarget = -1;for (let i = 0; i < lines.length; i += 1) {const line = lines[i] ?? "";if (TARGET.test(line) && firstTarget < 0) firstTarget = i + 1;if (PLAIN.test(line) && firstTarget >= 0) {thrownewError(`${file}:${i + 1} — \`${line.trim()}\` comes after the target table at line ${firstTarget}; ` +"every dependency written under a `[target…]` header is scoped to that target, " +"so the plain tables go first (#422).", ); } } }); }});