From e9667a684295c0018640b4f16d56a45d548e5ab5 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Tue, 29 Sep 2026 21:41:10 +0200 Subject: [PATCH] ci: enforce workspace package contracts --- Cargo.toml | 1 + Jenkinsfile | 12 +++ docs/releasing.md | 4 + scripts/package-workspace.sh | 10 +++ tasks.md | 2 +- tests/workspace_contract.rs | 151 +++++++++++++++++++++++++++++++++++ 6 files changed, 179 insertions(+), 1 deletion(-) create mode 100755 scripts/package-workspace.sh create mode 100644 tests/workspace_contract.rs diff --git a/Cargo.toml b/Cargo.toml index c1ae7e0..ed46657 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,6 +45,7 @@ edition.workspace = true rust-version.workspace = true license.workspace = true repository.workspace = true +description = "Heuristic low-care signal detector, ASCII formatter, and language server" autobins = false [[bin]] diff --git a/Jenkinsfile b/Jenkinsfile index 071f255..e7a688d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -215,6 +215,18 @@ pipeline { } } + stage('Workspace Packages') { + steps { + sh ''' + set -eu + + echo "Assembling all publishable workspace packages..." + + scripts/package-workspace.sh --no-verify + ''' + } + } + stage('Build Release') { steps { sh ''' diff --git a/docs/releasing.md b/docs/releasing.md index 27d4209..82732aa 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -6,6 +6,10 @@ toolchain recorded in `BUILD-INFO`. If publishing Rust packages, publish and verify `john-slop-core` first, `john-slop-lsp` second, and the root `john_slop` facade last. All three versions must remain synchronized; path dependencies carry matching registry versions. +Before publication, assemble all three crates in Cargo's dependency order with +`scripts/package-workspace.sh --no-verify`. The flag is required until the +matching core and LSP versions exist in the registry; after publication, rerun +the script without it to verify the registry-form dependency graph. 1. Ensure `CHANGELOG.md`, `Cargo.toml`, `Cargo.lock`, documentation, and the version badge agree; run every command in `docs/development.md`. diff --git a/scripts/package-workspace.sh b/scripts/package-workspace.sh new file mode 100755 index 0000000..0b72699 --- /dev/null +++ b/scripts/package-workspace.sh @@ -0,0 +1,10 @@ +#!/bin/sh +set -eu + +repository_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) +cd "$repository_dir" + +# Cargo packages workspace members in dependency order. Verification is useful +# after the matching core/LSP versions exist in the registry; pre-publication CI +# passes --no-verify because registry-form path dependencies are not live yet. +cargo package --locked --workspace "$@" diff --git a/tasks.md b/tasks.md index fa47578..f0ab3a9 100644 --- a/tasks.md +++ b/tasks.md @@ -349,7 +349,7 @@ complete measurements are in `docs/experiments/crate-boundary.md`. package as the workspace root; centralize shared package metadata, dependency versions, and lint policy with Cargo workspace inheritance while retaining per-package feature activation and optionality. -- [ ] Add automated workspace-contract checks for membership, synchronized +- [x] Add automated workspace-contract checks for membership, synchronized versions, inherited dependency sources, and core/LSP feature isolation. Make CI, packaging, and publication guidance explicitly workspace-aware and verify every publishable package in dependency order. diff --git a/tests/workspace_contract.rs b/tests/workspace_contract.rs new file mode 100644 index 0000000..3f99050 --- /dev/null +++ b/tests/workspace_contract.rs @@ -0,0 +1,151 @@ +use std::{fs, path::Path, process::Command}; + +use toml::Value; + +const PACKAGE_MANIFESTS: [&str; 3] = [ + "Cargo.toml", + "crates/john-slop-core/Cargo.toml", + "crates/john-slop-lsp/Cargo.toml", +]; +const INHERITED_PACKAGE_FIELDS: [&str; 5] = [ + "version", + "edition", + "rust-version", + "license", + "repository", +]; + +fn manifest(path: impl AsRef) -> Value { + let path = path.as_ref(); + let source = fs::read_to_string(path) + .unwrap_or_else(|error| panic!("failed to read {}: {error}", path.display())); + toml::from_str(&source) + .unwrap_or_else(|error| panic!("failed to parse {}: {error}", path.display())) +} + +fn string_array<'a>(value: &'a Value, label: &str) -> Vec<&'a str> { + value + .as_array() + .unwrap_or_else(|| panic!("{label} must be an array")) + .iter() + .map(|entry| { + entry + .as_str() + .unwrap_or_else(|| panic!("{label} entries must be strings")) + }) + .collect() +} + +#[test] +fn workspace_members_and_resolved_versions_are_synchronized() { + let root = manifest("Cargo.toml"); + let workspace = root["workspace"] + .as_table() + .expect("workspace must be a table"); + assert_eq!( + string_array(&workspace["members"], "workspace.members"), + ["crates/john-slop-core", "crates/john-slop-lsp"] + ); + assert_eq!( + string_array(&workspace["default-members"], "workspace.default-members"), + [".", "crates/john-slop-core", "crates/john-slop-lsp"] + ); + + let output = Command::new(env!("CARGO")) + .args(["metadata", "--locked", "--no-deps", "--format-version", "1"]) + .output() + .expect("cargo metadata must run"); + assert!( + output.status.success(), + "cargo metadata failed: {}", + String::from_utf8_lossy(&output.stderr) + ); + let metadata: serde_json::Value = + serde_json::from_slice(&output.stdout).expect("cargo metadata must emit JSON"); + let packages = metadata["packages"] + .as_array() + .expect("metadata packages must be an array"); + assert_eq!(packages.len(), 3); + assert!(packages.iter().all(|package| package["version"] == "0.1.0")); +} + +#[test] +fn packages_inherit_metadata_and_dependency_sources() { + let root = manifest("Cargo.toml"); + let workspace_dependencies = root["workspace"]["dependencies"] + .as_table() + .expect("workspace.dependencies must be a table"); + + for path in PACKAGE_MANIFESTS { + let package_manifest = manifest(path); + let package = package_manifest["package"] + .as_table() + .unwrap_or_else(|| panic!("{path} package must be a table")); + for field in INHERITED_PACKAGE_FIELDS { + assert_eq!( + package[field]["workspace"].as_bool(), + Some(true), + "{path} must inherit package.{field}" + ); + } + + for section in ["dependencies", "dev-dependencies"] { + let Some(dependencies) = package_manifest.get(section).and_then(Value::as_table) else { + continue; + }; + for (name, specification) in dependencies { + assert!( + workspace_dependencies.contains_key(name), + "{path} {section}.{name} is missing from workspace.dependencies" + ); + assert_eq!( + specification.get("workspace").and_then(Value::as_bool), + Some(true), + "{path} {section}.{name} must inherit its workspace requirement" + ); + } + } + } +} + +#[test] +fn core_and_lsp_feature_boundaries_remain_explicit() { + let root = manifest("Cargo.toml"); + let core = manifest("crates/john-slop-core/Cargo.toml"); + let lsp = manifest("crates/john-slop-lsp/Cargo.toml"); + + let core_dependencies = core["dependencies"] + .as_table() + .expect("core dependencies must be a table"); + for forbidden in ["clap", "john-slop-lsp-engine", "tokio", "tower-lsp-server"] { + assert!( + !core_dependencies.contains_key(forbidden), + "john-slop-core must not depend on {forbidden}" + ); + } + + assert!( + root["workspace"]["dependencies"]["tokio"] + .get("features") + .is_none() + ); + assert_eq!( + string_array( + &lsp["dependencies"]["tokio"]["features"], + "john-slop-lsp tokio features" + ), + ["sync"] + ); + assert_eq!( + root["dependencies"]["john-slop-lsp-engine"]["optional"].as_bool(), + Some(true) + ); + assert_eq!( + root["dependencies"]["tokio"]["optional"].as_bool(), + Some(true) + ); + assert_eq!( + root["dependencies"]["tower-lsp-server"]["optional"].as_bool(), + Some(true) + ); +}