ci/woodpecker/push/woodpecker Pipeline was successful
Replace the retired rc.2 Analysis v2/Trace v2/Execution Events v1 stack with the
single current contract family:
- Analysis v3 (ADR-0069 public boundary): one check --emit artifact carries the
exact source, Markdown AST, heading scopes (heading_span + complete span),
anchors, state-bearing references, calls, resources and diagnostics; the old
revision-3 shape is rejected with a rebuild hint.
- Observation v1: one run/call --output jsonl stream (+ atomic
--observation-file snapshot) decoded by one decoder and projected into the
reader/SSE/export layers; stale/malformed/truncated/incomplete never render
as success.
- CLI Tool revision 1: requires {api_revision:1, analysis:3, observation:1},
product range >=3.0.0-rc.3,<4.0.0, only MARQDO_BIN and
MARQDO_API_REVISION are consumed.
- Remove compatibility branches, retired flags/env vars and duplicate decoders;
re-record Analysis v3 and Observation v1 fixtures; rewrite contract,
integration and security tests (173 passing locally).
- Add check-no-legacy/check-docs/check-observation gates, rc.4 pins in the
CI pipelines, 0.3.0 Tool bundle and evidence manifest support.
See issues #4, #5 and #6; acceptance baseline is CLI source
452e9a32bd9e40dba427d4180691c58bab74449e, archive
9c3f166b5e5b8840d39d10019074e4e1c42432fc23e26c69670e64fdcf4e15d8.
210 lines
7.2 KiB
Rust
210 lines
7.2 KiB
Rust
//! Presentation model: the one intermediate form between verified domain data
|
|
//! and the one `ReaderRenderer` (RFC-VIEW-0002 §5.2).
|
|
//!
|
|
//! Nothing here spawns processes, builds HTML or parses Markdown semantics.
|
|
//! Assembly from Analysis/Trace happens in `reader::assemble`.
|
|
|
|
use crate::config::ViewConfig;
|
|
use crate::protocol::analysis_v3::{CoreDiagnostic, SemanticProjection, ViewWarning};
|
|
use crate::protocol::observation_v1::{RunDisplayState, RunProjection};
|
|
use crate::reader::markdown::DocumentModel;
|
|
use crate::reader::source::{Project, SafeRelativePath};
|
|
|
|
/// Private View presentation-model version. Not a public protocol.
|
|
pub const PRESENTATION_VERSION: u32 = 1;
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum SourceStatus {
|
|
/// No usable `MARQDO_BIN`; prose only, semantics explicitly unverified.
|
|
CoreUnavailable,
|
|
/// `check` succeeded and Analysis v3 was verified.
|
|
StaticOk,
|
|
/// `check` failed; diagnostics shown, semantics revoked.
|
|
CoreError,
|
|
/// Analysis/source digest mismatch or an outdated artifact.
|
|
Stale,
|
|
/// Unknown Analysis/Tool major or product range.
|
|
ProtocolIncompatible,
|
|
/// Analysis `source_digest` differs from the current source bytes.
|
|
SourceMismatch,
|
|
}
|
|
|
|
impl SourceStatus {
|
|
pub fn data_value(&self) -> &'static str {
|
|
match self {
|
|
SourceStatus::CoreUnavailable => "core-unavailable",
|
|
SourceStatus::StaticOk => "static-ok",
|
|
SourceStatus::CoreError => "core-error",
|
|
SourceStatus::Stale => "stale",
|
|
SourceStatus::ProtocolIncompatible => "protocol-incompatible",
|
|
SourceStatus::SourceMismatch => "source-mismatch",
|
|
}
|
|
}
|
|
|
|
pub fn label(&self) -> &'static str {
|
|
match self {
|
|
SourceStatus::CoreUnavailable => "核心不可用 · 语义未验证",
|
|
SourceStatus::StaticOk => "静态检查已通过 · 未运行",
|
|
SourceStatus::CoreError => "Core 检查失败 · 语义不可用",
|
|
SourceStatus::Stale => "语义结果已过期",
|
|
SourceStatus::ProtocolIncompatible => "核心协议不兼容",
|
|
SourceStatus::SourceMismatch => "源码与分析不一致",
|
|
}
|
|
}
|
|
|
|
pub fn semantics_usable(&self) -> bool {
|
|
matches!(self, SourceStatus::StaticOk)
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Navigation {
|
|
pub site_title: String,
|
|
pub documents: Vec<SafeRelativePath>,
|
|
pub active: Option<SafeRelativePath>,
|
|
/// True only when an explicit `view.json` names this document as welcome.
|
|
pub welcome: bool,
|
|
}
|
|
|
|
impl Navigation {
|
|
pub fn from_project(project: &Project, config: &ViewConfig, active: &SafeRelativePath) -> Self {
|
|
let documents = project.list_documents().unwrap_or_default();
|
|
let welcome = config
|
|
.welcome
|
|
.as_ref()
|
|
.map(|welcome| welcome == active)
|
|
.unwrap_or(false);
|
|
Self {
|
|
site_title: config
|
|
.site_title
|
|
.clone()
|
|
.unwrap_or_else(|| "Marqdo".to_string()),
|
|
documents,
|
|
active: Some(active.clone()),
|
|
welcome,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct PresentationModel {
|
|
pub version: u32,
|
|
pub title: String,
|
|
pub document: DocumentModel,
|
|
pub heading_slugs: std::collections::HashMap<crate::reader::source::SourceSpan, String>,
|
|
pub media: std::collections::BTreeMap<String, std::sync::Arc<super::media::Media>>,
|
|
pub semantic: Option<SemanticProjection>,
|
|
pub source_status: SourceStatus,
|
|
/// Human-readable reason for a degraded status (already normalized: no
|
|
/// absolute paths from the Core).
|
|
pub status_note: Option<String>,
|
|
pub diagnostics: Vec<CoreDiagnostic>,
|
|
pub warnings: Vec<ViewWarning>,
|
|
pub navigation: Navigation,
|
|
/// Function/section outline entries rendered from verified Analysis only.
|
|
pub outline: Vec<OutlineEntry>,
|
|
/// Frozen core product version used for this page, when one was consulted.
|
|
pub core_version: Option<String>,
|
|
/// Present only after an explicit user-triggered run whose trace verified.
|
|
pub run: Option<RunProjection>,
|
|
}
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct OutlineEntry {
|
|
pub label: String,
|
|
pub anchor: String,
|
|
pub detail: String,
|
|
pub kind: OutlineKind,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum OutlineKind {
|
|
Function,
|
|
Knowledge,
|
|
Section,
|
|
}
|
|
|
|
impl PresentationModel {
|
|
/// True when the entry module exposes a resolvable `main` (canonical or
|
|
/// unique local name). The dock Run button never substitutes another
|
|
/// function for a missing entry function (RFC-VIEW-0002 §2.4).
|
|
pub fn has_entry_main(&self) -> bool {
|
|
let Some(semantic) = self.semantic.as_ref() else {
|
|
return false;
|
|
};
|
|
semantic.functions.iter().any(|function| {
|
|
let canonical = canonical_function_name(&function.id, &semantic.module_id);
|
|
canonical == "main" || function.local_name == "main"
|
|
})
|
|
}
|
|
|
|
pub fn run_state(&self) -> RunDisplayState {
|
|
match &self.run {
|
|
Some(run) => run.state,
|
|
None => RunDisplayState::NotRun,
|
|
}
|
|
}
|
|
|
|
/// True when a run button may be offered (explicit confirmation still
|
|
/// required). Never true for exports or without a verified core.
|
|
pub fn can_offer_run(&self) -> bool {
|
|
self.source_status.semantics_usable()
|
|
&& self
|
|
.semantic
|
|
.as_ref()
|
|
.map(|semantic| {
|
|
semantic
|
|
.functions
|
|
.iter()
|
|
.any(|function| function.local_name == "main")
|
|
})
|
|
.unwrap_or(false)
|
|
}
|
|
|
|
pub fn functions(&self) -> impl Iterator<Item = &OutlineEntry> {
|
|
self.outline
|
|
.iter()
|
|
.filter(|entry| entry.kind == OutlineKind::Function)
|
|
}
|
|
|
|
pub fn error_diagnostics(&self) -> impl Iterator<Item = &CoreDiagnostic> {
|
|
self.diagnostics
|
|
.iter()
|
|
.filter(|diagnostic| diagnostic.severity == "error")
|
|
}
|
|
}
|
|
|
|
/// Deterministic heading anchor derived from the heading byte span. It never
|
|
/// depends on rendered text, so duplicate headings cannot collide.
|
|
pub fn anchor_for_span(start: u64, end: u64) -> String {
|
|
format!("mq-h-{start:x}-{end:x}")
|
|
}
|
|
|
|
/// Analysis v3 function ids are `<module id>::<canonical name>`.
|
|
fn canonical_function_name(function_id: &str, module_id: &str) -> String {
|
|
function_id
|
|
.strip_prefix(&format!("{module_id}::"))
|
|
.unwrap_or(function_id)
|
|
.to_string()
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn status_values_are_stable() {
|
|
assert_eq!(SourceStatus::StaticOk.data_value(), "static-ok");
|
|
assert_eq!(SourceStatus::CoreError.data_value(), "core-error");
|
|
assert!(SourceStatus::StaticOk.semantics_usable());
|
|
assert!(!SourceStatus::CoreUnavailable.semantics_usable());
|
|
assert!(!SourceStatus::SourceMismatch.semantics_usable());
|
|
}
|
|
|
|
#[test]
|
|
fn heading_anchors_are_deterministic_and_collision_free() {
|
|
assert_eq!(anchor_for_span(1, 2), "mq-h-1-2");
|
|
assert_ne!(anchor_for_span(1, 2), anchor_for_span(1, 3));
|
|
}
|
|
}
|