Skip to content

feat(review): synthetic defect templates for infrastructure code and documentation - #534

Merged
dan-petty merged 1 commit into
release/v0.2.23from
feat/504-infra-doc-defect-templates
Sep 24, 2026
Merged

dan-petty merged 1 commit into
release/v0.2.23from
feat/504-infra-doc-defect-templates

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Closes #504.

Why

The synthetic defect generator (#415, extended in #503) covered only a few YAML and Dockerfile patterns. Infrastructure code and documentation get reviewed too.

New templates (src/devops_cli/ai/review/defects.py)

Area Templates
Terraform expose-public-access, disable-encryption, open-ingress
Dockerfile run-as-root, unverified-download
Shell drop-strict-mode, unquote-expansion, pipe-to-shell, unverified-download
Kubernetes enable-host-network, mount-host-path, drop-resource-limits
Docs contradict-documented-default

disable-tls-verify, widen-file-mode and pipe-to-shell also gain shell, Dockerfile and docs finders:

  • curl --insecure and wget --no-check-certificate;
  • chmod 600 → 666.

Docs changes stay inside fenced code blocks and Hugo code shortcodes.

Keeping files well formed

  • Terraform: blocks are matched by braces on code with strings and # comments blanked. Ingress means an ingress block, an ingress SG rule, an NACL rule with egress = false, or aws_vpc_security_group_ingress_rule. Egress rules, ranges that are already open, and lists spread over lines are left alone.
  • Dockerfile checksums: a check is removed only as a middle segment of a continued RUN. A check that decides an if is left alone.
  • Shell checksums: a check is removed only as a standalone statement, not when it drives ||, && or a block.
  • TLS flags: added only to https downloads.
  • Pipe-to-shell: never applied to a continued line.
  • Unquoting: skipped in assignments, [[ ]], case words and comments.
  • YAML: keys are inserted at their sibling's indentation. limits are removed only under resources, and a file that already sets hostNetwork is skipped.

Verification on the pinned samples (#502)

Every site was applied one at a time and the mutated file checked:

  • python-hcl2 for Terraform;
  • PyYAML for manifests;
  • bash -n for shell scripts and for each Dockerfile RUN.
Category Sites
Terraform open-ingress 9, expose-public-access 1
Kubernetes/Helm enable-host-network 5, mount-host-path 1, drop-resource-limits 1
Dockerfiles + scripts disable-tls-verify 5, unverified-download 2, drop-strict-mode 10
Shell unquote-expansion 566, disable-tls-verify 2, drop-strict-mode 1
Docs disable-tls-verify 4, contradict-documented-default 2

No mutation breaks its file. The sweep caught two problems, both fixed before the numbers above:

  • removing nginx's md5sum -c - ... || { check broke the script;
  • Hugo's code shortcodes weren't recognised as code blocks.

A corpus over the samples injected 31 defects across 11 templates. The samples have no USER lines, encryption settings or script downloads, so run-as-root, disable-encryption and pipe-to-shell are covered by unit tests only.

Test plan

  • tests/test_review_defects_infra.py (45 tests):
    • 26 exact mutations with their evidence;
    • 18 places that must be skipped;
    • a mixed corpus.
  • Existing template tests pass (58)
  • Cyclomatic complexity ≤ 10
  • uv run devops ci --force: all 13 gates pass

…documentation

The defect generator covered a few YAML and Dockerfile patterns. It now injects the
defects reviews of infrastructure code and documentation should catch:
- Terraform: expose-public-access, disable-encryption, open-ingress.
- Dockerfiles: run-as-root, and unverified-download (ADD --checksum or a checksum
  segment of a continued RUN).
- Shell: drop-strict-mode, unquote-expansion, pipe-to-shell, curl --insecure and
  wget --no-check-certificate on https downloads, standalone checksum checks, chmod.
- Kubernetes: enable-host-network, mount-host-path, drop-resource-limits.
- Documentation: insecure example commands inside fenced code blocks and Hugo code
  shortcodes, and contradict-documented-default.

Every site on the pinned samples was applied and still parses: HCL, YAML, bash -n,
and each Dockerfile RUN. A corpus over them injected 31 defects.

Closes #504
@dan-petty dan-petty added this to the v0.2.23 milestone Sep 24, 2026
@dan-petty dan-petty added type/feature Type feature: a new function scope/review Multi-persona code review engine, verification, and findings priority/p2-medium Priority P2: standard work labels Sep 24, 2026
@dan-petty
dan-petty merged commit e13e04f into release/v0.2.23 Sep 24, 2026
7 checks passed
@dan-petty
dan-petty deleted the feat/504-infra-doc-defect-templates branch September 24, 2026 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p2-medium Priority P2: standard work scope/review Multi-persona code review engine, verification, and findings type/feature Type feature: a new function

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant