ci: enforce workspace package contracts

This commit is contained in:
Dandaedre 2026-09-29 21:41:10 +02:00
parent f57758d355
commit e9667a6842
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
6 changed files with 179 additions and 1 deletions

View File

@ -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]]

12
Jenkinsfile vendored
View File

@ -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 '''

View File

@ -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`.

10
scripts/package-workspace.sh Executable file
View File

@ -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 "$@"

View File

@ -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.

151
tests/workspace_contract.rs Normal file
View File

@ -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<Path>) -> 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)
);
}