Skip to content

feat(review): synthetic defect templates for application languages - #533

Merged
dan-petty merged 1 commit into
release/v0.2.23from
feat/503-app-language-defect-templates
Sep 24, 2026
Merged

dan-petty merged 1 commit into
release/v0.2.23from
feat/503-app-language-defect-templates

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Closes #503.

Why

The synthetic defect generator (#415) injected defects into Python, YAML and Dockerfiles only, so review recall could not be measured on other languages.

Changes (src/devops_cli/ai/review/defects.py)

  • Templates span languages. DefectTemplate.finders pairs file suffixes with a finder per language, so --template drop-bounds-check covers every language it knows.

  • Guards in brace languages (TS/JS, Go, Rust, Java, C#, C/C++):

    • drop-bounds-check removes an ordering guard.
    • The new drop-error-check removes a guard that stops on an error or missing value: err != nil, == null, !ptr, is_none(), rc != 0.

    Removal is conservative, so the file stays well formed:

    • Literals and comments are blanked before braces are matched.
    • The guard must be a whole if statement filling its lines.
    • Its body must only exit.
    • No else may follow, and it cannot be the body of a braceless if or loop.
    • Allman braces (C#) are handled.
    • A Go error check needs no init statement, and err must be read again later, or Go would not compile.
  • drop-await: TS/JS and C#. for await and await foreach/using are left alone.

  • disable-tls-verify:

    • TS/JS: rejectUnauthorized, or a new https.Agent;
    • Go: InsecureSkipVerify, or a new tls.Config;
    • Rust: danger_accept_invalid_certs, or Client::builder();
    • C#: an accept-any certificate callback on HttpClientHandler.
  • widen-file-mode:

    • mode arguments of MkdirAll, WriteFile, OpenFile, mkdir, open, chmod and the Node *Sync calls;
    • mode: options and Rust mode()/from_mode();
    • Java PosixFilePermissions.fromString.
  • New unbounded-string-copy (C/C++): strncpy, strncat, snprintf and vsnprintf lose their size argument.

  • Docs: docs/SELF_IMPROVEMENT.md lists each template's languages. It also corrects the stale note that review pages lack line numbers (fixed by fix(review): review pages carry no line numbers, so reported line ranges are guesses #499).

Verification on the pinned samples (#502)

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

Sample Sites Check Result
cJSON (C) 145 gcc -fsyntax-only all compile
express (JS) 9 node --check all parse
fmt (C++) 77 g++ -std=c++20 -fsyntax-only 76 compile; one trips fmt's consteval format-string check (well formed, and the defect is caught when compiled)
ky, cobra, serde_json, gson, serilog 282 tree-sitter errors before/after no new errors, except one site in a serilog file tree-sitter already misparses

A corpus over the eight application samples injected 91 defects:

  • 30 drop-bounds-check;
  • 44 drop-error-check;
  • 13 drop-await;
  • 4 unpin-action-ref in the samples' workflow files.

The samples have no TLS configuration, explicit file modes or bounded C string calls. Those templates are covered by unit tests only.

Found along the way: tree_sitter is not installed in the project, so the AST engine falls back to its regex parser for every language it claims (TS, Go, Rust, Java, HCL). #505 will record this and #506 will fix it.

Test plan

  • tests/test_review_defects_languages.py (34 tests):
    • one guard per language removed whole, with region and evidence;
    • 12 places that must be skipped;
    • 15 one-line defects;
    • a mixed-language corpus.
  • Existing template tests updated to the per-language finders (24 pass)
  • Cyclomatic complexity ≤ 10 (ruff --select C901)
  • uv run devops ci --force: all 13 gates pass

The defect generator injected into Python, YAML and Dockerfiles only, so review
recall could not be measured on other languages.

A template now pairs file suffixes with a finder per language. For TypeScript/
JavaScript, Go, Rust, Java, C# and C/C++:
- drop-bounds-check and the new drop-error-check remove guards;
- drop-await covers TS/JS and C#;
- disable-tls-verify covers rejectUnauthorized, InsecureSkipVerify,
  danger_accept_invalid_certs and an accept-any certificate callback;
- widen-file-mode covers mode arguments and Java permission strings;
- the new unbounded-string-copy turns strncpy, strncat, snprintf and vsnprintf into
  their unbounded forms.

A guard is removed only as a whole statement filling its lines. Its body must only
exit, with no else and no braceless parent, and literals and comments are blanked
before braces are matched. A Go error check is removed only when err is read again, so
the file still compiles.

On the pinned samples, every mutation was applied and checked:
- all 145 cJSON mutations pass gcc;
- all 9 express mutations pass node --check;
- 76 of 77 fmt mutations compile; the other trips fmt's compile-time format check;
- tree-sitter finds no new parse errors in the rest.

Closes #503
@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/p1-high Priority P1: high-impact work for the next planned milestone labels Sep 24, 2026
@dan-petty
dan-petty merged commit a3cfbbd into release/v0.2.23 Sep 24, 2026
7 checks passed
@dan-petty
dan-petty deleted the feat/503-app-language-defect-templates branch September 24, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1-high Priority P1: high-impact work for the next planned milestone 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