Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions crates/intent/src/graph_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,14 @@ fn req_traces_in(document: &Document) -> Vec<ReqTrace> {
{
cursor += 1;
}
let contains_placeholder = bytes.get(cursor) == Some(&b'<');
let followed_by_angle_bracket = bytes.get(cursor) == Some(&b'<');
while cursor > target_start && bytes[cursor - 1] == b'.' {
cursor -= 1;
}
if cursor > target_start && !contains_placeholder {
let target = &line[target_start..cursor];
let incomplete_placeholder =
followed_by_angle_bracket && !is_complete_req_target(target);
if cursor > target_start && !incomplete_placeholder {
traces.push(ReqTrace {
written: line[target_start..cursor].to_string(),
range: line_start + found..line_start + cursor,
Expand All @@ -727,6 +730,23 @@ fn is_req_target_byte(byte: u8) -> bool {
byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'_' | b'-' | b'/' | b'#')
}

fn is_complete_req_target(target: &str) -> bool {
let id = target
.rsplit_once('#')
.map_or(target, |(_, fragment)| fragment);
let normalized;
let id = if id.bytes().any(|byte| byte.is_ascii_lowercase()) {
normalized = id.to_ascii_uppercase();
normalized.as_str()
} else {
id
};
let bytes = id.as_bytes();
qualified_id_end(bytes, 0)
.or_else(|| local_id_end(bytes, 0))
.is_some_and(|end| end == bytes.len())
Comment thread
schickling-assistant marked this conversation as resolved.
Resolved
}

fn resolve_req_trace(
corpus_root: &Path,
repository_root: &Path,
Expand Down
19 changes: 16 additions & 3 deletions crates/intent/tests/intent_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ fn graph_json_recognizes_all_supported_requirement_definition_forms() {
.expect("requirements");
fs::write(
h.repo.join("context/intent/spec.md"),
"# Spec\n\nThis builds on [requirements](./requirements.md).\n\nAPP-R02 and R03 constrain the graph.\nreq: APP-R02\nreq: <ID>\nreq: <repo-relative-requirements-path>#<ID>\nreq: requirements.md#<ID>\nreq: APP-<ID>\n",
"# Spec\n\nThis builds on [requirements](./requirements.md).\n\nAPP-R02 and R03 constrain the graph.\nreq: APP-R02\nreq: APP-R02<br>\nreq: APP-R02<!-- note -->\nreq: app-r02<br>\nreq: <ID>\nreq: <repo-relative-requirements-path>#<ID>\nreq: requirements.md#<ID>\nreq: APP-<ID>\n",
)
.expect("spec");

Expand Down Expand Up @@ -517,10 +517,23 @@ fn graph_json_recognizes_all_supported_requirement_definition_forms() {
.collect::<Vec<_>>();
assert_eq!(
traces.len(),
1,
4,
"template placeholders must not become requirement traces: {traces:#?}"
);
assert_eq!(traces[0]["written_target"], "APP-R02");
assert_eq!(
traces
.iter()
.filter(|trace| trace["written_target"] == "APP-R02")
.count(),
3,
"HTML immediately after a complete target must preserve the trace: {traces:#?}"
);
assert!(
traces.iter().any(|trace| {
trace["written_target"] == "app-r02" && trace["normalized_target"] == "APP-R02"
}),
"completeness must use the same case normalization as resolution: {traces:#?}"
);
}

#[test]
Expand Down
Loading