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

+30 -1
View File
@@ -294,8 +294,37 @@ impl<'a> Mapper<'a> {
);
return None;
}
// The remainder of the condition paragraph is description only. The
// semantic mapper does not descend into it, so an executable `Strong`
// or `Emph` there would otherwise be silently swallowed. Reject it as
// a hard shape error instead of guessing the author's intent.
for tail in first.children.iter().skip(1) {
if matches!(tail.kind, MdKind::Strong | MdKind::Emph) {
self.error_with_hint(
codes::MARKDOWN_INVALID_CONSTRUCT,
Some(tail.span),
format!(
"`{}` inside a list-item condition paragraph is not executed and cannot be silently ignored",
tail.kind.tag()
),
"put executable statements in their own paragraph after the condition line",
);
return None;
}
}
let literal = condition_node.literal.clone().unwrap_or_default();
let segments = PayloadSegments::single(&literal, condition_node.span);
// `condition_node.span` includes the backtick delimiters. The payload
// map must start at the first literal byte so parse diagnostics and
// expression spans point at the expression, not at a delimiter.
let ticks = match condition_node.kind {
MdKind::Code { ticks } => ticks,
_ => 0,
};
let literal_span = Span::new(
condition_node.span.start.saturating_add(ticks),
condition_node.span.end.saturating_sub(ticks),
);
let segments = PayloadSegments::single(&literal, literal_span);
match parse_expression(&literal) {
Ok(mut expr) => {
segments.rewrite_expr(&mut expr);
+97
View File
@@ -259,3 +259,100 @@ mod tests {
assert!(error.reason.contains("emph"));
}
}
#[cfg(test)]
mod extra_span_tests {
use super::*;
use marqdo_markdown::parse;
fn first_strong(source: &str) -> MdNode {
let doc = parse(source);
let mut found = None;
doc.root.walk(&mut |node| {
if found.is_none() && node.kind == MdKind::Strong {
found = Some(node.clone());
}
});
found.expect("strong node")
}
#[test]
fn double_backtick_code_span_maps_inside_both_delimiters() {
let source = "**``n = 2 ** 3``**";
let node = first_strong(source);
let (payload, segments) = PayloadSegments::of(&node).unwrap();
assert_eq!(payload, "n = 2 ** 3");
let two = payload.find('2').expect("literal 2");
let span = segments.map_span(Span::new(two, two + 1));
assert_eq!(&source[span.start..span.end], "2");
assert_eq!(&source[2..4], "``");
assert_eq!(&source[span.start..span.start + 6], "2 ** 3");
}
#[test]
fn utf8_prefix_and_multiline_payload_map_to_original_bytes() {
let source = "**中文 = `2 ** 3`**";
let node = first_strong(source);
let (payload, segments) = PayloadSegments::of(&node).unwrap();
assert_eq!(payload, "中文 = 2 ** 3");
let chinese = payload.find("中文").expect("chinese");
let span = segments.map_span(Span::new(chinese, chinese + "中文".len()));
assert_eq!(&source[span.start..span.end], "中文");
let power = payload.find("2 ** 3").expect("power");
let span = segments.map_span(Span::new(power, power + "2 ** 3".len()));
assert_eq!(&source[span.start..span.end], "2 ** 3");
}
#[test]
fn condition_literal_span_excludes_backticks_for_one_and_two_ticks() {
for source in ["## f\n\n1. `n ** 2 ==`\n", "## f\n\n1. ``n ** 2 ==``\n"] {
let result = crate::analyze_source("index.mq.md", source);
let diagnostic = result
.diagnostics
.iter()
.find(|diagnostic| diagnostic.code == marqdo_value::codes::EXPR_PARSE)
.unwrap_or_else(|| panic!("no expr.parse diagnostic for {source:?}"));
let span = diagnostic
.span
.expect("condition parse error has a source span");
assert_eq!(
source.as_bytes()[span.start],
b'`',
"span must stop before the closing backtick: {span:?} in {source:?}"
);
assert_eq!(
&source[span.start.saturating_sub(2)..span.start],
"==",
"span must point at the missing operand"
);
}
}
#[test]
fn condition_description_rejects_executable_roles() {
for tail in ["**print(1)**", "*1*"] {
let source = format!("## f\n\n1. `n > 0` {tail}\n\n > print(1)\n");
let result = crate::analyze_source("index.mq.md", &source);
assert!(
result
.diagnostics
.iter()
.any(|diagnostic| diagnostic.code
== marqdo_value::codes::MARKDOWN_INVALID_CONSTRUCT),
"executable tail `{tail}` was not rejected: {:#?}",
result.diagnostics
);
}
}
#[test]
fn condition_description_allows_inert_inline_content() {
let source = "## f\n\n**n = 1**\n\n1. `n > 0` 普通说明、`惰性代码` 与 [链接](#f)。\n\n > print(1)\n";
let result = crate::analyze_source("index.mq.md", source);
assert!(
!result.has_errors(),
"inert description was rejected: {:#?}",
result.diagnostics
);
}
}