Repository navigation
docs: take the chart version from Chart.yaml - #481
Conversation
The docs hard-coded the version of the library chart foca-common (in
the dependency snippet of docs/helm-chart.md and the verification
commands of docs/deployment.md), which went stale with each chart
release. Add the placeholder {{ chart_version }} to the docs hook,
replaced with the version of charts/foca-common/Chart.yaml (final
versions only), use it in the docs, and extend the drift guard to the
current chart version, allowing Chart.yaml, the example app's chart,
the changelog, the migration guides and statements of what applies
before, since or up to a chart release.
Closes #472
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Match the version of a dependency only after its name: foca-common, so that versions of API specs and service info don't count, and match Helm commands with --version. Test an invalid chart via the hook, use the placeholder for inspecting a release, and split the hook's module docstring and the contributing guide's paragraph. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Also match --version before the chart or after other options, on a continuation line, and after a commented dependency name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideDocumentation now derives the independent Sequence diagram for chart version substitution in documentationsequenceDiagram
participant MkDocs
participant Hook as docs/hooks.py
participant Chart as charts/foca-common/Chart.yaml
participant Page as Documentation page
MkDocs->>Hook: on_page_markdown(markdown, page, config, files)
alt CHART_VARIABLE is present
Hook->>Chart: read_text(encoding="utf-8")
Hook->>Hook: chart_version(chart)
Hook->>Hook: substitute_chart_version(markdown, version)
Hook-->>MkDocs: rendered markdown with chart version
else CHART_VARIABLE is absent
Hook-->>MkDocs: unchanged markdown
end
Flow diagram for chart version drift preventionflowchart TD
Chart[Chart.yaml version] --> Docs[Documentation placeholders]
Docs --> Build[mkdocs build]
Build --> Rendered[Rendered chart-version commands]
Chart --> Guard[test_version_mentions.py]
Guard -->|approved references only| Pass[Tests pass]
Guard -->|hard-coded chart version found| Fail[Tests fail]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #481 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 29 29
Lines 3444 3444
=========================================
Hits 3444 3444
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 5 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="docs/hooks.py" line_range="37" />
<code_context>
VARIABLE = "{{ version }}"
# Version that the docs show if `CITATION.cff` has no `version`
UNRELEASED = "X.Y.Z"
+CHART = Path("charts/foca-common/Chart.yaml")
+# Placeholder of the version of the library chart in pages
+CHART_VARIABLE = "{{ chart_version }}"
</code_context>
<issue_to_address>
**Live preview keeps stale chart version**
When a contributor changes `charts/foca-common/Chart.yaml` while `mkdocs serve` is running, `on_page_markdown` reads the chart version, but `mkdocs.yml` does not watch `Chart.yaml`, so MkDocs does not rebuild the affected pages and the live preview continues showing the old version.
Add `charts/foca-common/Chart.yaml` to the files watched by MkDocs.
Also at `docs/hooks.py:155-158`.
</issue_to_address>
### Comment 2
<location path="docs/hooks.py" line_range="156-159" />
<code_context>
+ )
+ markdown = substitute_version(markdown, version)
+ if CHART_VARIABLE in markdown:
+ markdown = substitute_chart_version(
+ markdown, chart_version((root / CHART).read_text(encoding="utf-8"))
+ )
+ return markdown
</code_context>
<issue_to_address>
**Build can mix chart versions**
When `charts/foca-common/Chart.yaml` is edited while a documentation build is rendering pages, `on_page_markdown` reads `Chart.yaml` separately for every page containing the placeholder. If that file changes between rendering two such pages, one build emits pages with different chart versions, so readers see inconsistent commands and dependency examples.
Read and validate the chart version once per build, then use that same value for every page.
</issue_to_address>
### Comment 3
<location path="tests/test_version_mentions.py" line_range="103" />
<code_context>
+# Mentions of the chart version: the chart (an OCI reference, its package,
+# or in prose), its release tag, and the `version` of a dependency on it
+CHART_MENTIONS = (
+ r"(?i:\bfoca-common)(?:[:@\-]|\s+v?)v?{version}{end}",
+ r"\bchart-v{version}{end}",
+ # Helm commands (`helm show chart <ref>/foca-common --version X`, also
</code_context>
<issue_to_address>
**Chart version prose goes undetected**
When a tracked file describes the chart as “foca-common version X.Y.Z”, `CHART_MENTIONS` does not match this wording, so the drift-guard test passes even when the current chart version is hard-coded.
Add a pattern that matches a version following “foca-common version”.
</issue_to_address>
### Comment 4
<location path="tests/test_version_mentions.py" line_range="103" />
<code_context>
+# Mentions of the chart version: the chart (an OCI reference, its package,
+# or in prose), its release tag, and the `version` of a dependency on it
+CHART_MENTIONS = (
+ r"(?i:\bfoca-common)(?:[:@\-]|\s+v?)v?{version}{end}",
+ r"\bchart-v{version}{end}",
+ # Helm commands (`helm show chart <ref>/foca-common --version X`, also
</code_context>
<issue_to_address>
**Version-first mentions go undetected**
When the current chart version appears before `foca-common` in prose or in a continued Helm command, `CHART_MENTIONS` and the reverse-order Helm pattern do not match these forms, so the drift test passes while the current chart version is hard-coded.
Extend the mention patterns to match reverse-order prose and continued Helm commands with `--version` before the chart reference.
Also at `tests/test_version_mentions.py:108`, `tests/test_version_mentions.py:112`.
</issue_to_address>
### Comment 5
<location path="tests/test_version_mentions.py" line_range="112" />
<code_context>
+ # Patterns with a newline are matched against the previous and the
+ # current line: Helm commands continued on the next line, and the
+ # `version` of a dependency on the line after its `name`
+ r"(?i:\bfoca-common)\S*(?:\s+\S+)*?\s*\\\n\s*--version[=\s]+[\"']?{version}{end}",
+ r"\bname:\s*[\"']?foca-common[\"']?\s*(?:#.*)?\n\s*version:\s*[\"']?{version}{end}",
+)
</code_context>
<issue_to_address>
**Some continued Helm commands evade the guard**
When a Helm command puts an option such as `--untar` on its own continued line between the chart reference and `--version`, `mentions` checks a continued command using only the immediately previous line and the current line. If another continued option intervenes, the chart reference and hard-coded `--version` are never matched together, so the drift test passes with a stale version in a valid multiline command.
Track the start of an ongoing Helm command across continuation lines, or match the complete continued command before checking its chart version.
</issue_to_address>Sourcery assessment
Approval pending. 5 findings to address first.
Blocking findings: docs/hooks.py:37, docs/hooks.py:159, tests/test_version_mentions.py:103, tests/test_version_mentions.py:103, tests/test_version_mentions.py:112
Rebuild the docs on changes of the chart version in mkdocs serve, and also find "foca-common version X" in the drift guard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
Maintainer decision of 2026-10-24: take the current version of the library chart
foca-commonfrom one source, as FOCA's own version since #453/PR #462 (mirroring cloud-registry's chart-version placeholder of cloud-registry PR #224 where it fits; there the chart version follows the app version, here it is independent).docs/hooks.py): new placeholder,chart_versionin double curly braces (CHART_VARIABLE), replaced with theversionofcharts/foca-common/Chart.yaml(read with PyYAML; only finalX.Y.Zversions, as only those are released, else the build fails). Each file is only read if its placeholder is used.helm show chartcommand ofdocs/helm-chart.md, and the verification commands ofdocs/deployment.md. Statements about particular chart releases ("before/since foca-common 0.2.0", "from version 0.2.0 on") stay as they are.docs/contributing.mddescribes the placeholder and the guard.tests/test_version_mentions.py): also fails if the current chart version is hard-coded as the chart's version:foca-common:X,foca-common X,chart-vX, Helm's--version Xwithfoca-common(also on a continuation line), and theversionof a dependency on the line aftername: foca-common. Allowed:Chart.yaml, the example app's chart (Chart.yaml,Chart.lock: Helm can't take the version from elsewhere), the changelog, the migration guides, and "before/since/from/up to/until" statements. Checked against the old docs (all 5 hard-coded lines are caught) and for chart versions 0.3.0, 1.0.0 and 1.1.0 (no false positives, e.g., from OpenAPIinfo.version).Verification
pytestwith MongoDB 7 (coverage), after mergingdev(incl. feat!: tighten group checks and error details #475, refactor!: remove get_enforcer() #477, fix(chart): use a keep-alive of 100 s #478): 2368 passed, 1 skipped;coverage report: 100%mypy: no issues;ruff check: clean;pre-commit run --all-files: all hooks passedmkdocs build --strict: no warnings; the built pages show the chart version (0.2.0)mkdocs servewatchesChart.yaml, "foca-common version X" is found; declined (replied, resolved): read the chart version once per build (the hook readsCITATION.cffper page the same way), version-first prose and multi-line continued Helm commands (rare forms; broader patterns would flag other versions).versionmatched only aftername: foca-common(it matched anyversion:line), Helm--versionforms, a hook test for an invalid chart, docstring and docs wording.Declined review findings
hooks.chart_version()instead of readingChart.yamlthemselves: declined, the tests keep an independent oracle, andtest_version_mentions.pydoesn't load the hooks.NamedTuple: optional, declined to keep the guard's structure as it was.nameandversionare not caught: accepted (the docs use name, version, repository); a test pins it.Notes
devmay show a chart version that is not released yet, as the chart's version is raised with its first change after a release (documented indocs/contributing.md). Taking the latestchart-v*tag instead would need tags in the docs build; left as is.Open questions
None.
Closes #472
🤖 Generated with Claude Code