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
4 changes: 2 additions & 2 deletions docs/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ High-density product roadmap, engineering milestones, and open-source integratio
- [x] **A Shipped Release Closes Its Epic While the Roadmap Header Lags (P2 - Medium, Issue #521)**:
- *Context & Rationale*: Release epic #297 stayed open after v0.2.22 shipped, with its tag, GitHub release and closed milestone. The epic sync closed an epic only when its roadmap header said Completed, and each release had marked the previous one done, one step late. Eight delivered v0.2.22 entries were also left unticked.
- *Delivered*: The epic sync treats a closed milestone as a completed release. The roadmap marks v0.2.22 Completed and v0.2.23 the active release, and ticks the eight delivered entries with their PRs. Running the sync closed #297 at 20 of 20 deliverables.
- [ ] **Finding Locations Keep Paths With `+`, `@`, `~` or `%` (P2 - Medium, Issue #498)**:
- [x] **Finding Locations Keep Paths With `+`, `@`, `~` or `%` (P2 - Medium, Issue #498)**:
- *Context & Rationale*: `canonicalize_finding_location` matches paths with `[a-zA-Z0-9_\-./\\]`. A path outside that class falls through to a fallback that keeps its first path-like fragment, so every finding on files under a corpus named `playbooks+core+...` was saved as `.data/reviews/corpora/playbooks`, with no file and no lines.
- *Deliverable*: Accept the characters file names legitimately use, with regression tests for each, line ranges included.
- *Delivered*: The location patterns share one path character class that accepts letters and digits of any script and `+`, `@`, `~` and `%`. Paths such as `include/c++/`, `node_modules/@scope/`, `logo@2x.svg`, `~/.config/` and `100%-coverage.md` keep their file and lines: alone, as ranges, normalized from `#L` anchors and `, lines`, and extracted from prose.

### Reactive Workstation Command Center, Interactive TUI & Unified Operations Hub (v0.2.24 - Scheduled)
- [ ] **Reactive Multi-Workspace Textual TUI Architecture & Master-Detail Navigation (`devops dashboard`, `devops tui`) (P0 - Critical)**:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Task 498: Finding Locations Keep Paths With `+`, `@`, `~` or `%`

**Issue**: [#498](https://github.com/dan-petty/devops-cli/issues/498)
**Status**: Backlog
**Status**: Done
**Milestone**: `v0.2.23`
**Priority**: `priority/p2-medium`
**Scope**: `type/bug`, `scope/review`, `priority/p2-medium`
Expand All @@ -15,8 +15,18 @@ falls through to a fallback that keeps its first path-like fragment. Every findi
a corpus named `playbooks+core+...` (#415) was saved as `.data/reviews/corpora/playbooks`, with no
file and no lines.

#### Key Deliverables:
- Accept the characters file names legitimately use (`+`, `@`, `~`, `%`) in every location pattern.
- Regression tests for each character, line ranges included.
- Maintain cyclomatic complexity $M \le 10$ and nesting depth $\le 5$.
- 100% passing across Gated CI validation suite (`uv run devops ci`).
### Key Deliverables Completed:

- [x] **One path character class**: the three location patterns (a path with lines, a
`file:target` location, and a location embedded in prose) share `_PATH_CHARS`. It accepts
letters and digits of any script and the punctuation file names use: `+` (`c++`,
`playbooks+core`), `@` (`@scope`, `logo@2x`), `~` (`~/.config`) and `%` (`100%`).
- [x] **Automated Tests & Quality Gates**:
- `tests/test_review_location_paths.py`: for a path with each character and one with
non-ASCII letters:
- it survives alone, with a line and with a range;
- reversed ranges, `#L` anchors, backticks and `, lines` are normalized as for any path;
- it is extracted whole from prose;
- a scoped package's `file:target` location is kept;
- the #415 corpus finding keeps its file and lines through the `Finding` model.
- 100% passing status across Gated CI validation suite (`uv run devops ci`).
21 changes: 15 additions & 6 deletions src/devops_cli/ai/review_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,18 @@ def _parse_finding_references(raw_ref: Any) -> list[str]:

_MARKDOWN_LINK_REGEX = re.compile(r"\[([^\]]+)\]\([^)]+\)")

# Characters a path segment may hold: letters and digits of any script, and the punctuation file
# names use (`c++`, `@scope`, `logo@2x`, `~/.config`, `100%`). A narrower class cut a path at the
# first other character and kept the fragment before it.
_SEGMENT_CHARS = r"\w\-.+@~%"
_PATH_CHARS = rf"{_SEGMENT_CHARS}/\\"
_LOCATION_REGEX = re.compile(rf"^([{_PATH_CHARS}]+)(?::(\d+)(?:-(\d+))?)?$")
_TARGET_LOCATION_REGEX = re.compile(rf"^([{_PATH_CHARS}]+):([{_PATH_CHARS}]+)$")
_EMBEDDED_LOCATION_REGEX = re.compile(
rf"(?:^|[\s:\"'`])([{_PATH_CHARS}]+/[{_SEGMENT_CHARS}]+|[\w\-]+\.[\w\-]+)"
r"(?::(\d+)(?:-(\d+))?)?"
)


_SCRATCHPAD_PREFIX_REGEX = re.compile(
r"^(?:(?:We|I)\s+(?:need to|must|should|will|have to)\b|Let's\b|Looking at\b|Reviewing\b|Checking\b|Based on\b)[^.\n]*[.?!:]\s*",
Expand Down Expand Up @@ -336,7 +348,7 @@ def canonicalize_finding_location(location: str) -> str:
):
return ""

m_loc = re.match(r"^([a-zA-Z0-9_\-./\\]+)(?::(\d+)(?:-(\d+))?)?$", loc)
m_loc = _LOCATION_REGEX.match(loc)
if m_loc:
file_path = m_loc.group(1).replace("\\", "/")
s_str = m_loc.group(2)
Expand All @@ -356,15 +368,12 @@ def canonicalize_finding_location(location: str) -> str:
return f"{file_path}:{s_line}"

# Match general target specifiers without spaces, e.g. uv.lock:jinja2, Dockerfile:cve-1, k8s/app.yaml:Deployment/app
m_target = re.match(r"^([a-zA-Z0-9_\-./\\]+):([a-zA-Z0-9_\-./\\]+)$", loc)
m_target = _TARGET_LOCATION_REGEX.match(loc)
if m_target:
return f"{m_target.group(1).replace('\\', '/')}:{m_target.group(2)}"

# Extract embedded valid file location if present in conversational or scratchpad text
m_embedded = re.search(
r"(?:^|[\s:\"'`])([a-zA-Z0-9_\-./\\]+/[a-zA-Z0-9_\-.]+|[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-]+)(?::(\d+)(?:-(\d+))?)?",
loc,
)
m_embedded = _EMBEDDED_LOCATION_REGEX.search(loc)
if m_embedded:
candidate_file = m_embedded.group(1).replace("\\", "/").rstrip(".")
if (
Expand Down
74 changes: 74 additions & 0 deletions tests/test_review_location_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Finding locations keep paths with `+`, `@`, `~`, `%` and non-ASCII letters (#498).

Location patterns matched paths with `[a-zA-Z0-9_\\-./\\\\]` only. A path outside that class fell
through to a fallback that kept its first path-like fragment, so every finding under a corpus
named `playbooks+core+...` was saved as `.data/reviews/corpora/playbooks`, with no file and no
lines.
"""

from __future__ import annotations

import pytest

from devops_cli.ai.review_schema import Finding, canonicalize_finding_location

_PATHS = [
".data/reviews/corpora/playbooks+core+security-1/files/core/audit.py",
"include/c++/vector.hpp",
"node_modules/@scope/pkg/index.js",
"assets/logo@2x.svg",
"~/.config/devops/config.yaml",
"docs/100%-coverage.md",
"docs/café/résumé.md",
]


@pytest.mark.parametrize("path", _PATHS)
def test_a_path_keeps_every_character_with_its_lines(path: str) -> None:
"""Verify the whole path survives, alone, with a line and with a range."""
canonical = tuple(
canonicalize_finding_location(loc) for loc in (path, f"{path}:7", f"{path}:12-20")
)

assert canonical == (path, f"{path}:7", f"{path}:12-20")


@pytest.mark.parametrize("path", _PATHS)
def test_a_path_is_normalized_like_any_other(path: str) -> None:
"""Verify reversed ranges, `#L` anchors, backticks and `, lines` apply to these paths."""
canonical = tuple(
canonicalize_finding_location(loc)
for loc in (f"{path}:20-12", f"{path}#L7", f"`{path}:7`", f"{path}, lines 12-20")
)

assert canonical == (f"{path}:12-20", f"{path}:7", f"{path}:7", f"{path}:12-20")


@pytest.mark.parametrize("path", _PATHS)
def test_a_path_embedded_in_prose_is_extracted_whole(path: str) -> None:
"""Verify a location the model buried in a sentence keeps its full path."""
location = canonicalize_finding_location(f"We need the lines. So location: {path}:12-20.")

assert location == f"{path}:12-20"


def test_a_dependency_target_keeps_a_scoped_package_path() -> None:
"""Verify `file:target` locations accept the same path characters."""
location = canonicalize_finding_location("packages/@scope/web/package.json:lodash")

assert location == "packages/@scope/web/package.json:lodash"


def test_a_finding_under_a_plus_named_corpus_keeps_its_file_and_lines() -> None:
"""Verify the #415 corpus case end to end through the Finding model."""
finding = Finding(
severity="HIGH",
location=".data/reviews/corpora/playbooks+core+security+crypto/files/crypto/kh.py:248-250",
title="Directory created world-writable",
description="mkdir(mode=0o777)",
)

assert (finding.location, finding.is_empty) == (
".data/reviews/corpora/playbooks+core+security+crypto/files/crypto/kh.py:248-250",
False,
)
Loading