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
2 changes: 2 additions & 0 deletions changelog.d/1299.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### Fixed
- `devops docs check` validates an option written inside optional-group brackets (`[-v <ver>]`, `[--json]`) instead of skipping it as a placeholder, so a misspelled option in a synopsis fails the check (#1299).
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Task: The docs check validates the options inside optional-group brackets (#1299)

**Issue**: [#1299](https://github.com/dan-petty/devops-cli/issues/1299)
**Status**: Done
**Milestone**: v0.2.30
**Priority**: priority/p3-low
**Scope**: type/bug, scope/docs, priority/p3-low

## Description

`is_placeholder` in `src/devops_cli/docs/markdown_argv_collector.py` treats every word that starts with `[` or ends with `]` as a placeholder, and the resolver lets a placeholder stand for any number of tokens. An option written inside a synopsis optional group, such as `[-v` or `[--no-such-flag]`, was therefore never checked, so a misspelled option there passed `devops docs check`. The hole came in with #921.

Requiring a matched bracket pair was rejected: `shlex` splits `[-v <ver>]` into `[-v` and `<ver>]`, so neither word carries both brackets and the synopsis lines in `RELEASE_CYCLE.md` would stop resolving.

The fix is `_argv_token`, which `_tokenize_command` now calls for each word. It removes one leading `[` and one trailing `]`; a word that then starts with `-` is that option and goes to the resolver as a literal. Every other word keeps the existing `is_placeholder` mapping, so `<ver>]`, `INT]`, `[OPTIONS]` and `[ARGS]...` stay placeholders.

With the fix, the `-p` and `-v` options in the `devops release` table of `RELEASE_CYCLE.md` (lines 141-145) are checked against the command tree, and they resolve. All checked docs stay at 0 findings.

## Acceptance Criteria

- [x] `[-v <ver>]` resolves with `-v` checked as an option, and `[--no-such-flag]` is reported as an unknown option: `test_an_option_in_optional_group_brackets_is_validated` in `tests/test_docs_knowledge_base_argv.py`.
- [x] `changelog.d/1299.md` records the fix under `### Fixed`. `CHANGELOG.md` and `docs/ROADMAP.md` are not edited.
- [x] `uv run devops ci` passes.
4 changes: 2 additions & 2 deletions docs/agent/tasks/task-921-docs-name-only-what-exists.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
## Description
The hand-written documentation files (`ARCHITECTURE.md`, `README.md`, `RELEASE_CYCLE.md`, `docs/SDLC.md`, `docs/ROUTINE_TASKS.md`, `docs/DEVCONTAINER_USAGE.md`, `docs/VISION.md`, `k8s/README.md`, and `k8s/llm/profiles/README.md`) contained references to non-existent or deprecated commands, incorrect option flags, removed architecture classes/protocols (`ProcessExecutionPipeline`, `@cli_command_handler`, `StagePipeline`), out-of-date GPU inference profiles/tiers, and inaccurate CI/SDLC checks.

To permanently prevent documentation drift, the static Markdown command line argv collector was extended to collect and validate command references across all hand-written documentation files. The collector recognizes standard documentation placeholders and option bracket notation (`[-v <ver>]`, `[ARGS]...`), mapping them to `ArgvPlaceholder`. Hand-written documentation validation is integrated directly into `DocGenerator.check_docs()` and executed on `devops docs check` and throughout CI. All verified defects across the 9 hand-written documentation files were rectified.
To permanently prevent documentation drift, the static Markdown command line argv collector was extended to collect and validate command references across all hand-written documentation files. The collector maps standard documentation placeholders such as `<ver>]` and `[ARGS]...` to `ArgvPlaceholder`; since #1299, an option written inside optional-group brackets (`[-v`) is validated as that option. Hand-written documentation validation is integrated directly into `DocGenerator.check_docs()` and executed on `devops docs check` and throughout CI. All verified defects across the 9 hand-written documentation files were rectified.

## Key Changes
- **Constants & Configuration** (`src/devops_cli/config/constants.py`):
- Defined `CONST_DOCS_ARGV_KNOWN_PLACEHOLDERS` (`COMMAND`, `ARGS`, `OPTIONS`, `SUBCOMMAND`, `PARAMS`) and `CONST_HANDWRITTEN_DOCS_PATHS` covering the 9 canonical hand-written documentation paths.
- **Markdown Argv Collector & Placeholders** (`src/devops_cli/docs/markdown_argv_collector.py`):
- Updated `is_placeholder()` to recognize known uppercase placeholder tokens and bracketed option patterns (e.g., `[-v`, `<ver>]`).
- Updated `is_placeholder()` to recognize known uppercase placeholder tokens and bracketed words (e.g., `<ver>]`); since #1299, the option in `[-v` is validated rather than read as a placeholder.
- Added `collect_handwritten_docs_argv_references(root_dir)` and `check_handwritten_docs_argv(root_dir)`.
- **Docs Check Integration** (`src/devops_cli/docs/generator.py`):
- Wired `check_handwritten_docs_argv(self.root_dir)` into `DocGenerator.check_docs()` so `devops docs check` continuously audits hand-written documentation alongside MCP tools and the offline knowledge base.
Expand Down
16 changes: 13 additions & 3 deletions src/devops_cli/docs/markdown_argv_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,19 @@ def _tokenize_command(raw_args: str) -> tuple[ArgvToken, ...]:
parts = shlex.split(cleaned, comments=True)
except ValueError:
parts = cleaned.split()
return tuple(
ArgvPlaceholder(expression=part) if is_placeholder(part) else part for part in parts
)
return tuple(_argv_token(part) for part in parts)


def _argv_token(part: str) -> ArgvToken:
"""The token a document's word stands for.

An option written inside a synopsis optional group (`[-v`, `[--json]`) is that option, so
the check validates it.
"""
option = part.removeprefix("[").removesuffix("]")
if option.startswith("-"):
return option
return ArgvPlaceholder(expression=part) if is_placeholder(part) else part


def _extract_fenced_references(lines: Sequence[str], path: str) -> list[DevopsArgvReference]:
Expand Down
34 changes: 33 additions & 1 deletion tests/test_docs_knowledge_base_argv.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
from typer.testing import CliRunner

from devops_cli.commands.docs import app as docs_app
from devops_cli.docs.command_resolver import ArgvPlaceholder, module_click_command
from devops_cli.docs.command_resolver import (
ArgvPlaceholder,
CommandReferenceDefect,
CommandReferenceFinding,
module_click_command,
resolve_devops_argv,
)
from devops_cli.docs.generator import DocGenerator
from devops_cli.docs.markdown_argv_collector import (
collect_handwritten_docs_argv_references,
Expand Down Expand Up @@ -193,3 +199,29 @@ def test_handwritten_docs_defective_reference_fails_resolution() -> None:
refs = collect_markdown_argv_references(defective_md, "test_defective.md")
unresolved = describe_unresolved_references(refs)
assert len(unresolved) == 2


def test_an_option_in_optional_group_brackets_is_validated() -> None:
"""Verify an option written inside a synopsis optional group is checked, not skipped."""
markdown = """\
```bash
devops release pr [-v <ver>]
devops release pr [--no-such-flag]
```
"""
references = collect_markdown_argv_references(markdown, "x.md")

assert (
references[0].tokens,
[resolve_devops_argv(reference.tokens) for reference in references],
) == (
("release", "pr", "-v", ArgvPlaceholder(expression="<ver>]")),
[
None,
CommandReferenceFinding(
defect=CommandReferenceDefect.UNKNOWN_OPTION,
command_path="devops release pr",
token="--no-such-flag",
),
],
)
Loading