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 docs/ROADMAP_WORKFLOW.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ The runner Job runs the checks that a person runs in the devcontainer, from the

Tests hold the drift: each local hook runs a tool that the runner image holds, each scoped row is a row of `devops ci`, and the branches of the Job pass the branch-name hook.

A change that removes, renames or tightens a setting that `k8s/devops/configmap.example.yaml` or the live ConfigMap names says in its OpenSpec proposal and in a comment on its pull request how the live ConfigMap changes first ([Go-live check](../k8s/README.md#go-live-check)).

## Measure the implement job

The implement job has a baseline score. The command that gives it calls a model through the gateway, so it runs on demand and is no part of `devops ci`.
Expand Down
2 changes: 2 additions & 0 deletions k8s/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ kubectl -n devops get cm devops-cli-config -o jsonpath='{.data.devops-cli\.yaml}
kubectl -n devops rollout restart deployment/roadmap-service
```

A change that removes, renames or tightens a setting that `k8s/devops/configmap.example.yaml` or the live ConfigMap names says in its OpenSpec proposal and in a comment on its pull request how the live ConfigMap changes first: apply the ConfigMap with `deploy-stack`, then let the image roll. Git does not hold the live ConfigMap, so a test cannot read it. `deploy-stack` loads its rendering into `Settings` before it applies it, and `tests/k8s/test_k8s_configmap_keys.py` fails if the example names a key that no setting declares.

Then do these checks, and do them again every 15 minutes for the first 2 hours. If a check fails, do the stop switch. If an alert of the rule group `roadmap-service` or `roadmap-service-webhooks` fires, do what its row in Alerts says. Select each series of the Service with `job="roadmap-service"`, as the alert rules do.

1. The pod runs: `kubectl -n devops get pod -l app.kubernetes.io/name=roadmap-service` shows one pod `Running`, with no restart and no `OOMKilled`.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
schema: spec-driven
created: 2026-11-08
skip_specs: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Design

## Decisions

- **Walk `model_fields` in a module of `src/`, and report the dotted path of each unknown key.**: The tests must fail on the base tree, and `devops ci fail-to-pass` overlays the `tests/` tree of the head, so the helper cannot live under `tests/`. A dotted path such as `roadmap.implement.not_a_setting` names the key in a form that an author can search in the example.
- **Go into a value only when the field is a nested model.**: A mapping field such as the ladder (`dict[str, list[str]]`) holds user keys, not field names, so the walk does not read its keys. The validator of the ladder checks them (`_check_ladder`).
- **Render the example with `render_active_devops_configmap` and fake settings.**: The test then walks the same text that a deploy applies, with the `service` section that the deploy sets, and the load by `Settings.model_validate` is the check that `deploy-stack` runs.
- **Keep the live ConfigMap out of the test.**: A test of the repository cannot read the cluster. The rule in the two documents makes the author change the live ConfigMap first, and `deploy-stack` refuses a rendering that does not load.
- **Put the rule in `k8s/README.md` and `docs/ROADMAP_WORKFLOW.md`, and not in the pull request template.**: The body of a pull request becomes the squash message, so a template line would enter the history. The rule asks for a comment on the pull request and a paragraph in the proposal.
- **Pin the phrase in `tests/invariants/`.**: The invariant test fails when a later edit drops the rule from one of the two documents.

## Rejected alternatives

- **Set `extra="forbid"` on the models of `Settings`.**: It changes a public behavior: a config file with an old key then fails to load. `grep -n "extra=" src/devops_cli/config/settings.py` shows 14 models that ignore an unknown key, so the change would break each user file that holds one.
- **Check the live ConfigMap in a test.**: The cluster holds it and git does not, and a test never reaches a cluster.
- **Use `kubeconform` or `kubectl diff`.**: They check the shape of a manifest. The settings are one string in the key `devops-cli.yaml`, so they do not see a key inside it.
- **Add a line to the pull request template.**: The template body becomes the squash message.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Proposal

## Why

Issue #4093 reports that on 2026-11-07 the roadmap Service crashed after a release, because the live ConfigMap `devops-cli-config` still held two ladder keys that PR #4074 had removed. The example `k8s/devops/configmap.example.yaml` was correct, and a test of it would have failed. The live ConfigMap is not in git, and no document tells an author to change it first.

A second gap is still open. Most models of `Settings` set `extra="ignore"`, so a key that a change removes from a model, and that stays in the example, loads with no error. No test reports it.

## What Changes

- Add `unknown_setting_keys(config, model=Settings)` in the new module `src/devops_cli/config/setting_keys.py`. It walks the keys of a settings mapping against `model_fields` of the models, goes into each nested model, and returns the dotted path of each key that no model declares. It reads no file and starts no process.
- Add `tests/k8s/test_k8s_configmap_keys.py` with three tests. `test_every_key_of_the_example_is_a_setting` renders the example with `render_active_devops_configmap` and fake settings, loads it with `Settings.model_validate`, and expects no unknown key. `test_an_unknown_key_in_a_copy_of_the_example_is_reported` adds `roadmap.implement.not_a_setting: 1`, and a second case adds a top-level key, and expects the report to name each one. `test_an_unknown_ladder_step_class_in_a_copy_of_the_example_fails_to_load` adds the ladder key `plan` and expects the error "the ladder names no step class".
- Add the rule to `k8s/README.md` (the paragraph "Go-live check") and to `docs/ROADMAP_WORKFLOW.md`: a pull request that removes, renames or tightens a setting that the example ConfigMap names says, in its OpenSpec proposal and in a comment on the pull request, how the live ConfigMap changes first and in which order: apply the ConfigMap, then let the image roll. The pull request body stays as the template sets it, because it becomes the squash message, so the change adds no line to the template.
- Add `tests/invariants/test_configmap_rollout_rule.py`, which asserts that each of the two documents holds the phrase "removes, renames or tightens" on one line.
- State here that a test of the repository cannot read the live ConfigMap. The check at deploy time covers the cluster: `render_devops_configmap_content` in `src/devops_cli/k8s/configmap.py` calls `Settings.model_validate` on the rendering, and `devops k8s deploy-stack --stack devops` refuses to apply a rendering that does not load.
- This change removes, renames and tightens no setting, so it needs no rollout step for the live ConfigMap.
- The change adds a module that no consumer observes (a helper that only tests call) and edits documents and tests, so it has no spec delta.
- The change fits one pull request.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

None.

## Impact

- Source: `src/devops_cli/config/setting_keys.py` (new)
- Tests: `tests/k8s/test_k8s_configmap_keys.py` (new), `tests/invariants/test_configmap_rollout_rule.py` (new)
- Documents: `k8s/README.md`, `docs/ROADMAP_WORKFLOW.md`

## Feasibility

- Command output of 2026-11-08, from a probe script that walks `model_fields` of `Settings` (nested models only) over the example `k8s/devops/configmap.example.yaml`: `keys walked: 52 unknown: []`. So the example holds 0 unknown keys now, and the claim of the issue ("none is unknown") is confirmed by a tool.
- The same probe, after it added `roadmap.implement.not_a_setting: 1` and a top-level `bogus: 1` to a copy, printed `['roadmap.implement.not_a_setting', 'bogus']`. `Settings.model_validate` loaded the same copy with no error, because `extra="ignore"` holds for those models. So the gap is real, and a walk over `model_fields` closes it with no new dependency.
- `grep -n "extra=" src/devops_cli/config/settings.py` shows 13 models with `extra="ignore"` and `validate_assignment=True`, one with `extra="ignore"` alone and 3 with `extra="forbid"`. So most models ignore an unknown key.
- `render_active_devops_configmap(k8s_dir, settings)` in `src/devops_cli/k8s/configmap.py` renders and validates the example with fake settings, and `tests/k8s/test_k8s_configmap.py` uses the same pattern (`Settings(service=ServiceConfig(repos, github_app))`). No test of the repository reads the live ConfigMap, and none can: the cluster holds it and git does not.
- `src/devops_cli/config/settings.py` `_check_ladder` raises "the ladder names no step class" for a ladder key that is no step class, so the third test passes on the load alone.
- The phrase "removes, renames or tightens" is in no file of the tree now (`git grep -n "removes, renames or tightens"` prints nothing).
- Open and merged pull requests: #4074 removed the ladder keys (merged). #1231 (a generated ConfigMap) is closed. No open pull request does this work. Open #4121 (issue #4094) edits only the example values, so it does not conflict.
- `devops ci fail-to-pass` overlays the `tests/` tree of the head on the base tree, so a helper in `tests/support/` would also exist on the base. The helper is therefore a module of `src/`, and the new tests fail on the base by a missing module.

## Existing Tool Considered

Pydantic reports a key that no field declares when a model sets `extra="forbid"`. The ConfigMap loader could validate with strict copies of the models, but that changes a public behavior: `extra="ignore"` lets old config files load, and the 3 models that forbid keys already show the cost of that (#2201). `kubeconform` and `kubectl diff` check the shape of a manifest, not the meaning of the settings inside the string `devops-cli.yaml`, so they do not fit. The change builds one small walk over `model_fields`. Cost: about 30,000 tokens to build, low to keep (a new setting needs no edit, because the walk follows `model_fields`), and about 1 hour. A repeat of the crash of 2026-11-07 stops the roadmap Service until a person applies the ConfigMap. The change deletes no internal code.

## Dependencies

None.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Tasks

## 1. Report a key of the example that no setting declares

Reads: `src/devops_cli/config/settings.py`, `src/devops_cli/k8s/configmap.py`, `k8s/devops/configmap.example.yaml`, `tests/k8s/test_k8s_configmap.py`, `tests/config/test_k8s_devops_runtime.py`. Changes: `tests/k8s/test_k8s_configmap_keys.py` (new), `src/devops_cli/config/setting_keys.py` (new).

- [x] 1.1 Write `test_every_key_of_the_example_is_a_setting`, `test_an_unknown_key_in_a_copy_of_the_example_is_reported` and `test_an_unknown_ladder_step_class_in_a_copy_of_the_example_fails_to_load` in `tests/k8s/test_k8s_configmap_keys.py`. Each renders the example with `render_active_devops_configmap` and fake settings. The tests import `unknown_setting_keys` from `devops_cli.config.setting_keys`, which does not exist on the base
- Verification: `$ uv run devops ci fail-to-pass --base origin/main` fails on the base
- [x] 1.2 Add `src/devops_cli/config/setting_keys.py` with `unknown_setting_keys(config, model=Settings)`. It returns the dotted path of each key of `config` that no field of `model` or of a nested model declares, in the order of the mapping. It goes into a value only when the field is a nested model (alone or in an optional), and reads no key of a plain mapping field
- Verification: `$ uv run devops ci test tests/k8s/test_k8s_configmap_keys.py` passes

## 2. Tell an author to change the live ConfigMap first

Reads: `k8s/README.md`, `docs/ROADMAP_WORKFLOW.md`, `.github/pull_request_template.md`. Changes: `tests/invariants/test_configmap_rollout_rule.py` (new), `k8s/README.md`, `docs/ROADMAP_WORKFLOW.md`.

- [x] 2.1 Write `test_the_document_holds_the_rule_for_the_live_configmap` in `tests/invariants/test_configmap_rollout_rule.py`. It asserts that `k8s/README.md` and `docs/ROADMAP_WORKFLOW.md` each hold the phrase "removes, renames or tightens" on exactly one line
- Verification: `$ uv run devops ci fail-to-pass --base origin/main` fails on the base
- [x] 2.2 Add one paragraph to "Go-live check" in `k8s/README.md` and one paragraph to `docs/ROADMAP_WORKFLOW.md` (after "Checks of the implement job", or the section that fits the rule best). Each says: a pull request that removes, renames or tightens a setting that `k8s/devops/configmap.example.yaml` or the live ConfigMap names says, in its OpenSpec proposal and in a comment on the pull request, how the live ConfigMap changes first and in which order (apply the ConfigMap with `devops k8s deploy-stack --stack devops`, then let the image roll); and that a test cannot read the live ConfigMap, so `deploy-stack` validates the rendering before it applies it. Add nothing to the pull request template
- Verification: `$ uv run devops ci test tests/invariants/test_configmap_rollout_rule.py` passes
- [x] 2.3 Check the documents
- Verification: `$ uv run devops ci docs` passes

## Criteria

- Group 1: `uv run pytest tests/k8s/test_k8s_configmap_keys.py::test_every_key_of_the_example_is_a_setting` fails on the base because the helper that walks the keys does not exist, and passes after the change.
- Group 1: `uv run pytest tests/k8s/test_k8s_configmap_keys.py::test_an_unknown_key_in_a_copy_of_the_example_is_reported` fails on the base for the same reason. The test adds `roadmap.implement.not_a_setting: 1` to a copy and expects the report to name it.
- Group 1: `uv run pytest tests/k8s/test_k8s_configmap_keys.py::test_an_unknown_ladder_step_class_in_a_copy_of_the_example_fails_to_load` adds the key `plan` to the ladder of a copy and expects the error "the ladder names no step class".
- Group 2: `grep -n "removes, renames or tightens" docs/ROADMAP_WORKFLOW.md k8s/README.md` prints one line in each file after the change, and a test in `tests/invariants/` asserts that both files hold the phrase.

## Workflow follow-up

- Pending a person: review the diff in tuicr (tuicr -r <base>..HEAD).
48 changes: 48 additions & 0 deletions src/devops_cli/config/setting_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""Find the keys of a settings mapping that no settings model declares (#4093).

Most models of `Settings` set `extra="ignore"`, so a key that a change removes from a model loads
with no error when a file still holds it. This walk reports such a key by its dotted path.
"""

from __future__ import annotations

import typing
from collections.abc import Mapping
from typing import Any

from pydantic import BaseModel

from devops_cli.config.settings import Settings


def unknown_setting_keys(
config: Mapping[str, Any], model: type[BaseModel] = Settings, *, prefix: str = ""
) -> list[str]:
"""The dotted path of each key of `config` that no field of `model` or of a nested model
declares, in the order of the mapping.

The walk goes into a value only when the field is a model, alone or in an optional. It reads
no key of a plain mapping field, because such a field holds keys of the user and not names of
fields.
"""
unknown: list[str] = []
for key, value in config.items():
path = f"{prefix}{key}"
field = model.model_fields.get(key)
if field is None:
unknown.append(path)
continue
nested = _nested_model(field.annotation)
if nested is not None and isinstance(value, Mapping):
unknown.extend(unknown_setting_keys(value, nested, prefix=f"{path}."))
return unknown


def _nested_model(annotation: Any) -> type[BaseModel] | None:
"""The model that an annotation names, alone or in an optional, else nothing."""
if isinstance(annotation, type) and issubclass(annotation, BaseModel):
return annotation
for argument in typing.get_args(annotation):
if isinstance(argument, type) and issubclass(argument, BaseModel):
return argument
return None
22 changes: 22 additions & 0 deletions tests/invariants/test_configmap_rollout_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""The two documents that tell how a setting changes name the rule for the live ConfigMap (#4093).

The ConfigMap `devops-cli-config` lives in the cluster, and git does not hold it. A pull request
that removes, renames or tightens a setting that the example ConfigMap names must say how the live
ConfigMap changes first. `k8s/README.md` and `docs/ROADMAP_WORKFLOW.md` each hold that rule.
"""

from __future__ import annotations

import pytest

from tests.support.paths import REPO_ROOT

RULE = "removes, renames or tightens"


@pytest.mark.parametrize("document", ["k8s/README.md", "docs/ROADMAP_WORKFLOW.md"])
def test_the_document_holds_the_rule_for_the_live_configmap(document: str) -> None:
"""The phrase of the rule is in the document, on one line."""
lines = (REPO_ROOT / document).read_text(encoding="utf-8").splitlines()

assert sum(RULE in line for line in lines) == 1
73 changes: 73 additions & 0 deletions tests/k8s/test_k8s_configmap_keys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""The example ConfigMap names only settings that `Settings` declares (#4093).

Most models of `Settings` set `extra="ignore"`, so a key that a change removes from a model and
that stays in `k8s/devops/configmap.example.yaml` loads with no error. These tests walk each key of
the rendered example against the fields of the models. A test cannot read the live ConfigMap:
`devops k8s deploy-stack` validates its rendering before it applies it, and covers the cluster.
"""

from __future__ import annotations

import copy
from typing import Any

import pytest
import yaml
from pydantic import ValidationError

from devops_cli.config.setting_keys import unknown_setting_keys
from devops_cli.config.settings import GitHubAppConfig, ServiceConfig, Settings
from devops_cli.k8s.configmap import render_active_devops_configmap
from tests.support.paths import REPO_ROOT

APP = GitHubAppConfig(app_id=1001, installation_id=42, slug="devops-roadmap")


def _example_config() -> dict[str, Any]:
"""The settings that the example ConfigMap holds, as a deploy renders them."""
rendered = render_active_devops_configmap(
k8s_dir=REPO_ROOT / "k8s",
settings=Settings(service=ServiceConfig(repos=["example-org/repo"], github_app=APP)),
)
config: dict[str, Any] = yaml.safe_load(yaml.safe_load(rendered)["data"]["devops-cli.yaml"])
return config


def test_every_key_of_the_example_is_a_setting() -> None:
"""No key of the example is unknown, and the whole example loads into `Settings`."""
config = _example_config()

Settings.model_validate(config)

assert unknown_setting_keys(config) == []


@pytest.mark.parametrize(
("path", "reported"),
[
(("roadmap", "implement", "not_a_setting"), "roadmap.implement.not_a_setting"),
(("not_a_section",), "not_a_section"),
],
)
def test_an_unknown_key_in_a_copy_of_the_example_is_reported(
path: tuple[str, ...], reported: str
) -> None:
"""A key that no model declares is reported with its full path, though the load accepts it."""
config = copy.deepcopy(_example_config())
section = config
for part in path[:-1]:
section = section[part]
section[path[-1]] = 1

Settings.model_validate(config)

assert unknown_setting_keys(config) == [reported]


def test_an_unknown_ladder_step_class_in_a_copy_of_the_example_fails_to_load() -> None:
"""The ladder refuses a step class that no step has: the load catches this one already."""
config = copy.deepcopy(_example_config())
config["roadmap"]["implement"]["ladder"]["plan"] = ["devops-coder"]

with pytest.raises(ValidationError, match="the ladder names no step class"):
Settings.model_validate(config)