fix: resolve outside_scope design links inside the explicit --root
WEB-00's probe and the Preview fixture exposed a real boundary: when an entry's nearest CLI project root is a subdirectory, a component link like `../shared/x.mq.md` is reported as outside_scope without candidate_path even though it is inside the design command's explicit --root. Design now derives the physical candidate from the public reference URL only for that state, resolves it relative to the source module, requires the canonical target to stay inside --root, and still verifies the exact anchor through the target module's Analysis. No private loader, file search or label guessing is introduced; other states keep failing with the candidate diagnostic. Adds a real-CLI contract test and records the rule/limitation in the evidence. Refs cflmy/marqdo-web-design#1, cflmy/marqdo#6
This commit was merged in pull request #6.
This commit is contained in:
1 parent
495d2e4bf7
commit
2f18dede85
3 files changed
+67
-11
No files matched your search
+36
-10
@@ -335,6 +335,34 @@ fn parse_initial(value: &str) -> Result<bool, &'static str> {
|
||||
}
|
||||
}
|
||||
|
||||
fn design_candidate(
|
||||
reference: &serde_json::Value,
|
||||
link: &Link,
|
||||
module: &Module,
|
||||
) -> Result<String, LoadError> {
|
||||
if let Some(candidate) = reference["candidate_path"].as_str() {
|
||||
if !candidate.is_empty() {
|
||||
return Ok(candidate.to_string());
|
||||
}
|
||||
}
|
||||
// A link inside the explicit design --root can lie outside the CLI's nearest
|
||||
// project root (for example a component referencing `../shared/x.mq.md`).
|
||||
// Analysis then reports `outside_scope` without candidate_path; the public
|
||||
// reference URL plus the explicit design root still determine the physical
|
||||
// target, so derive it and require the root check afterwards.
|
||||
if reference["state"].as_str() == Some("outside_scope") {
|
||||
let raw = link.url.split('#').next().unwrap_or("");
|
||||
if !raw.is_empty() && !raw.starts_with('/') && !raw.contains("://") && !raw.contains('\\') {
|
||||
return Ok(raw.to_string());
|
||||
}
|
||||
}
|
||||
Err(LoadError::Design(vec![Diagnostic::error(
|
||||
"web.link.candidate",
|
||||
"design link must expose a project-relative candidate path",
|
||||
)
|
||||
.at(module.relative.clone(), Some(link.span))]))
|
||||
}
|
||||
|
||||
fn json_span(span: (usize, usize)) -> Span {
|
||||
Span {
|
||||
start: span.0,
|
||||
@@ -395,18 +423,15 @@ impl Loader {
|
||||
link: &Link,
|
||||
) -> Result<(Module, Unit, String), LoadError> {
|
||||
let reference = find_reference(module, link)?;
|
||||
let candidate = reference["candidate_path"]
|
||||
.as_str()
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let fragment = reference["fragment"].as_str().unwrap_or("").to_string();
|
||||
if candidate.is_empty() || fragment.is_empty() {
|
||||
if fragment.is_empty() {
|
||||
return Err(LoadError::Design(vec![Diagnostic::error(
|
||||
"web.link.candidate",
|
||||
"design link must expose a candidate_path and a fragment",
|
||||
"design link must expose an exact anchor fragment",
|
||||
)
|
||||
.at(module.relative.clone(), Some(link.span))]));
|
||||
}
|
||||
let candidate = design_candidate(reference, link, module)?;
|
||||
if Path::new(&candidate).is_absolute() || link.url.contains("://") {
|
||||
return Err(LoadError::Design(vec![Diagnostic::error(
|
||||
"web.link.absolute",
|
||||
@@ -451,10 +476,6 @@ impl Loader {
|
||||
link: &Link,
|
||||
) -> Result<(Module, Unit), LoadError> {
|
||||
let reference = find_reference(module, link)?;
|
||||
let candidate = reference["candidate_path"]
|
||||
.as_str()
|
||||
.unwrap_or("")
|
||||
.to_string();
|
||||
let fragment = reference["fragment"].as_str().unwrap_or("").to_string();
|
||||
if fragment.is_empty() {
|
||||
return Err(LoadError::Design(vec![Diagnostic::error(
|
||||
@@ -463,6 +484,11 @@ impl Loader {
|
||||
)
|
||||
.at(module.relative.clone(), Some(link.span))]));
|
||||
}
|
||||
let candidate = match design_candidate(reference, link, module) {
|
||||
Ok(candidate) => candidate,
|
||||
Err(_) if reference["fragment"].as_str().is_some() => String::new(),
|
||||
Err(error) => return Err(error),
|
||||
};
|
||||
let target_module = if candidate.is_empty() {
|
||||
module.clone()
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user