fix: close release-gate defects in platform cfg, strict launch, and semantics

WHY
- macOS/Windows failed to compile because `cfg!` left `linux::probe()` in the
  type-checked branch (E0433).
- GitHub-hosted Linux can pass the strict probe and then fail the real launch
  with EAGAIN; the CLI test treated the inspect snapshot as a permanent promise.
- The security matrix shared process-id-based scratch paths, so parallel
  `cargo test --workspace` made its own tests clobber each other.
- Condition paragraphs silently ignored executable `Strong`/`Emph`, and
  condition parse spans included the code-span backticks.
- The corpus had no native power/control-flow/inert fixtures and no independent
  generic Tool consumers.

WHAT
- Dispatch strict detection through `#[cfg]` functions; add a non-Linux
  compile/fail-closed regression test.
- Split `linux::run` into an injectable probe/spawn seam; test probe-OK ->
  launch-EAGAIN returns LaunchFailed and never executes unrestricted.
- Make the Linux CLI contract accept only (a) successful isolated run or
  (b) non-zero, diagnosed, fail-closed refusal with no project stdout.
- Give each security test a unique project/outside path and compile the helper
  once.
- Reject executable roles in a condition paragraph; map condition expressions
  from the literal bytes inside the backticks.
- Add 10 AST, 8 semantic, 4 compile-negative and 2 runtime-negative fixtures
  for power, branch/loop conditions, source spans, inert prose/code fences and
  error boundaries.
- Add `sample-view`/`sample-knowledge`/`sample-proof` independent Tool v1
  packages and an end-to-end Analysis/Trace consumer test.
- Add a locked path-dependency content-tamper test.

TESTS
- cargo fmt --all -- --check
- cargo clippy --workspace --all-targets -- -D warnings
- cargo test --workspace --locked
- G-C VM lane (separate evidence commit/run)

CI_URL
- none from this host: the checkout has a Gitee remote and no GitHub
  credentials. Windows/macOS CI remains UNVERIFIED.

BREAKING_CHANGE
- An executable node in a list-item condition paragraph is now a hard
  `markdown.invalid_construct` error instead of being silently ignored.

SECURITY_SCOPE
- strict remains fail-closed; no downgrade, no new capability, L2 still
  rejected. G-C still requires the dedicated self-hosted lane for CI-signed
  evidence.
This commit is contained in:
cflmy committed 2026-11-20 15:40:17 +08:00
1 parent c9f01aa8fb
commit d05f36fd26
65 files changed
+2134 -87

No files matched your search

+57 -20
View File
@@ -111,34 +111,55 @@ impl PlatformCapabilities {
/// security contract. The isolated worker transport is implemented, but a
/// plain child process is not an OS sandbox.
pub fn detect() -> Self {
let strict = if cfg!(target_os = "linux") {
match linux::probe() {
Ok(mechanism) => StrictIsolation::Available { mechanism },
Err(reason) => StrictIsolation::Unavailable { reason },
}
} else if cfg!(target_os = "macos") {
StrictIsolation::Unavailable {
reason: "no verified macOS sandbox adapter is implemented in this build"
.to_string(),
}
} else if cfg!(target_os = "windows") {
StrictIsolation::Unavailable {
reason: "no verified Windows job-object/appcontainer adapter is implemented in this build".to_string(),
}
} else {
StrictIsolation::Unavailable {
reason: "platform isolation is not implemented for this target".to_string(),
}
};
Self {
os: std::env::consts::OS.to_string(),
arch: std::env::consts::ARCH.to_string(),
strict,
strict: detect_strict(),
worker_processes: true,
}
}
}
/// Detect strict isolation using only code that is compiled for the current
/// platform.
///
/// `cfg!` is a boolean constant and does **not** remove the other branch from
/// type checking. Using it around `linux::probe()` made macOS/Windows builds
/// reference a module that is not compiled there (`E0433`). The platform
/// dispatch therefore lives in dedicated `#[cfg]` functions.
#[cfg(target_os = "linux")]
fn detect_strict() -> StrictIsolation {
match linux::probe() {
Ok(mechanism) => StrictIsolation::Available { mechanism },
Err(reason) => StrictIsolation::Unavailable { reason },
}
}
#[cfg(target_os = "macos")]
fn detect_strict() -> StrictIsolation {
StrictIsolation::Unavailable {
reason: "no verified macOS sandbox adapter is implemented in this build".to_string(),
}
}
#[cfg(target_os = "windows")]
fn detect_strict() -> StrictIsolation {
StrictIsolation::Unavailable {
reason: "no verified Windows job-object/appcontainer adapter is implemented in this build"
.to_string(),
}
}
#[cfg(not(any(target_os = "linux", target_os = "macos", target_os = "windows")))]
fn detect_strict() -> StrictIsolation {
StrictIsolation::Unavailable {
reason: format!(
"platform isolation is not implemented for `{}`",
std::env::consts::OS
),
}
}
/// Failure to apply the requested sandbox mode.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SandboxError {
@@ -263,4 +284,20 @@ mod tests {
assert!(enforce(SandboxMode::Pure, &platform).is_ok());
assert!(enforce(SandboxMode::Project, &platform).is_ok());
}
/// macOS and Windows must compile without the Linux-only `linux` module,
/// report strict as unavailable, and still refuse strict execution. This
/// is the regression guard for the `E0433` platform-detection defect.
#[cfg(not(target_os = "linux"))]
#[test]
fn non_linux_detection_is_compiled_and_fails_closed() {
let platform = PlatformCapabilities::detect();
assert!(matches!(
platform.strict,
StrictIsolation::Unavailable { .. }
));
let error = enforce(SandboxMode::Strict, &platform).expect_err("strict must refuse");
assert!(matches!(error, SandboxError::StrictUnavailable { .. }));
assert!(!platform.strict.describe().contains("available via"));
}
}