π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Enforce binding projection declaration order
Manav Rathidbde5cb7b6b3
diff --git a/rust/checks/dependency-boundaries/check.mjs b/rust/checks/dependency-boundaries/check.mjsindex 9052df6894..98a4c5d0a6 100644--- a/rust/checks/dependency-boundaries/check.mjs+++ b/rust/checks/dependency-boundaries/check.mjs@@ -1,5 +1,5 @@import { execFileSync } from "node:child_process";-import { existsSync } from "node:fs";+import { existsSync, readFileSync } from "node:fs";import { isAbsolute, relative, resolve, sep } from "node:path";const requestedRoot = resolve(process.argv[2]);@@ -76,6 +76,32 @@ for (const manifest of git(process.exitCode = 1;}+for (const path of git(+ "ls-files",+ "--cached",+ "--others",+ "--exclude-standard",+ "-z",+ "--",+ "rust/bindings/wasm/lib/src",+ "rust/bindings/frb/lib/src",+)+ .split("\0")+ .filter((path) => path.endsWith(".rs") && existsSync(resolve(root, path)))) {+ const source = readFileSync(resolve(root, path), "utf8");+ const declarations = [+ ...source.matchAll(+ /^\s*pub\s+(?:async\s+)?(?:struct|enum|type|fn)\s+([A-Za-z_][A-Za-z0-9_]*)/gm,+ ),+ ].map((match) => match[1]);+ const error = declarations.find((name) => name.endsWith("Error"));+ if (!error || declarations[0] === error) continue;+ console.error(+ `${path}: ${declarations[0]} precedes ${error}; put boundary errors before exported types and functions`,+ );+ process.exitCode = 1;+}+function git(...args) {return execFileSync("git", args, { cwd: root, encoding: "utf8" });}diff --git a/rust/checks/dependency-boundaries/test.mjs b/rust/checks/dependency-boundaries/test.mjsindex 0f985167c6..8f1f2f3973 100644--- a/rust/checks/dependency-boundaries/test.mjs+++ b/rust/checks/dependency-boundaries/test.mjs@@ -71,6 +71,29 @@ for (const domainName of ["core", "assets", "location-dataset"]) {assert.equal(result.status, 0, result.stderr);}+result = run({+ projections: {+ "rust/bindings/wasm/lib/src/projection.rs":+ "pub struct Output;\npub enum Error { Other }\n",+ "rust/bindings/frb/lib/src/projection.rs":+ "pub fn operation() {}\npub enum LockerError { Other }\n",+ },+});+assert.equal(result.status, 1, result.stderr);+assert.match(result.stderr, /projection\.rs: Output precedes Error/);+assert.match(result.stderr, /projection\.rs: operation precedes LockerError/);++result = run({+ projections: {+ "rust/bindings/wasm/lib/src/projection.rs":+ "pub enum Error { Other }\npub struct Output;\n",+ "rust/bindings/frb/lib/src/projection.rs":+ "pub enum LockerError { Other }\npub fn operation() {}\n",+ },+});+assert.equal(result.status, 0, result.stderr);+assert.equal(result.stderr, "");+function run({source = "pub fn domain() {}\n",framework,@@ -81,6 +104,7 @@ function run({dependencyKind = "dev-dependencies",domainName = "domain",bindingDependencyKind,+ projections = {},} = {}) {const root = mkdtempSync(join(tmpdir(), "ente-rust-dependencies-"));try {@@ -113,6 +137,9 @@ function run({: "",));write(root, "rust/bindings/wasm/lib/src/lib.rs", "pub fn binding() {}\n");+ for (const [path, source] of Object.entries(projections)) {+ write(root, path, source);+ }if (framework) {write(root, "rust/vendor/framework/Cargo.toml", packageToml(framework));write(root, "rust/vendor/framework/src/lib.rs", "pub fn framework() {}\n");