diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..24213be --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,319 @@ +# AGENTS.md + +Instructions for coding agents. Humans: start with [CONTRIBUTING.md](CONTRIBUTING.md). + +This file has two parts. **Part 1** describes the CoreTrace project as a whole and the rules +shared by its repositories; it is meant to be the same in each of them. **Part 2** describes +this repository. Where they disagree, Part 2 wins for this repository. Update this file in the +same pull request as the rule, command or architecture it describes. + +# Part 1: the CoreTrace project + +## What CoreTrace is + +CoreTrace finds bugs in C, C++ and Python code by running several analyzers and merging what +they find into one report and one verdict that can gate a CI pipeline. It is split into +repositories of the [CoreTrace organization](https://github.com/CoreTrace), each versioned and +released on its own. + +The open repositories are the open core of a hosted analysis service, the CoreTrace platform, +which is developed separately and is out of scope here: never move a feature out of an open +repository, and never add code that only the hosted service needs. + +## How the repositories fit together + +``` + clients the product + ┌──────────────────────────┐ ┌──────────────────────────────────────────────┐ + │ coretrace-gui (desktop) │ │ coretrace: ctrace │ + │ coretrace-vscode (editor)├───▶│ runs the tools, merges their findings, │ + │ a CI pipeline │ │ gives the verdict │ + └──────────────────────────┘ └───────┬──────────────────────────┬───────────┘ + │ links, in process │ runs, as processes + ┌───────────┴──────────┐ ┌──────────┴──────────────┐ + │ stack analyzer │ │ runtime analyzer │ + │ concurrency analyzer │ │ python analyzer │ + └───────────┬──────────┘ │ cppcheck, flawfinder... │ + │ compile └─────────────────────────┘ + ▼ through + ┌──────────────────────┐ + │ coretrace-compiler │ + └──────────────────────┘ +``` + +| Repository | Role | How it joins the product | +|---|---|---| +| `coretrace` | `ctrace`, the CLI and HTTP server: runs the tools, normalizes and merges their findings, returns the exit code | The entry point; the release archive is built here | +| `coretrace-stack-analyzer` | Stack, buffer, pointer-escape and initialization analysis on LLVM IR | Linked into `ctrace`, at a pinned tag | +| `coretrace-concurrency-analyzer` | Data races, missing joins, lock-order deadlocks | Linked into `ctrace`, at a pinned tag | +| `coretrace-runtime-analyzer` | Instrumented runs: bounds, allocations, vtables | Shipped next to `ctrace`, run as a separate process | +| `coretrace-python-analyzer` | Analysis of Python projects | Shipped next to `ctrace` as a standalone executable, run as a separate process | +| `coretrace-compiler` | Clang integration library | The analyzers compile their inputs through it; one `ctrace` build holds one version of it | +| `coretrace-log` | C++20 logging library | Fetched by `coretrace`, the stack analyzer and `coretrace-compiler` | +| `coretrace-gui` | Desktop interface (Tauri) | A client: it runs an installed `ctrace` | +| `coretrace-vscode` | VS Code extension | A client: it runs `ctrace` and shows its findings in the editor | +| `coretrace-tool-template` | Scaffold for a new tool | Where a convention shared by the tools starts | +| `coretrace-ci-consumer-demo` | Reference CI integration | Uses a release as an outside project would | + +`ctrace` also runs third-party tools when they are installed: cppcheck, flawfinder, ikos, and +TscanCode (a fork kept in `coretrace-TscanCode`). + +### What holds them together + +These are the contracts between the repositories. Whoever changes one breaks the others, so +each change is proposed in an issue first and stays open for comments for 7 days, as +[GOVERNANCE.md](https://github.com/CoreTrace/coretrace/blob/main/GOVERNANCE.md) sets: + +- **The finding model.** Every tool's output is normalized by `ctrace` to one model, written as + text, JSON or SARIF. In SARIF, a finding is identified by its `coretrace/v1` fingerprint. +- **The verdict.** Exit code `0` clean, `1` usage error, `2` findings, `3` incomplete analysis. + A tool that could not run, or could not be read, is never counted as clean. +- **The interfaces of `ctrace`**: its command-line options, its configuration schema, and the + `coretrace-1.0` HTTP protocol of its server. +- **Pinned versions.** A repository takes another at a tag or a commit, never a branch. A fix + in an analyzer reaches users in two steps: a release of the analyzer, then an update of the + pin in `coretrace`. +- **One compiler library per build.** The analyzers linked into `ctrace` must pin the same + `coretrace-compiler` commit; moving it means releasing them together. + +### Where a problem is fixed + +| Symptom | Repository | +|---|---| +| A wrong, missing or duplicated finding | The analyzer that produced it | +| An input that does not compile for the analyzers | `coretrace-compiler` | +| A finding lost or miscounted in the merged report, a wrong exit code, a tool not run | `coretrace` | +| A report shown wrongly | The client: `coretrace-gui` or `coretrace-vscode` | + +Do not work around another repository's defect here: record it there, and take the fix by +updating the pin. + +## How the project is organized + +- **Decisions are made in the open**, in issues and pull requests, by the rules of + [GOVERNANCE.md](https://github.com/CoreTrace/coretrace/blob/main/GOVERNANCE.md). The default + branch takes pull requests whose required checks pass. +- **Not every repository is maintained the same way.** The product and its desktop interface + welcome contributors; others are maintained without contribution calls, or published as is. + The levels are in the + [open-source scope](https://github.com/CoreTrace/coretrace/blob/main/docs/open-source-scope.md). +- **Licenses differ.** Most repositories are under Apache-2.0, some under MIT or GPL-3.0. Use + the license and the file header of the repository you are in, and never copy code from one + repository into another without checking that its license allows it. +- **Each repository is versioned on its own**, with semantic versioning; components in `0.x` + may still change incompatibly between minor versions. + +## Rules for every repository + +### Development + +- **Work from an issue.** A change no issue describes gets one first, to agree on the approach. +- **A change of behavior comes with its test, in the same pull request.** A bug fix comes with + a test that fails without the fix. Write that test first. +- **Fix the cause where every caller passes**, not the symptom on the path the report names. +- **An intermittent test is a bug to fix**, not to retry. Retries are for network steps only. +- **Documentation follows the change** in the same pull request: README, `docs/`, help text, + and the changelog when users see it. +- **Small pull requests, one subject each.** English Conventional Commit titles, such as + `fix(cli): handle missing input`. Fill the pull request template where there is one: what + and why, how it was tested. +- **Validate at the boundary**: arguments, configuration files, request bodies, the output of + another tool. +- **Do not add what the task does not need**: no speculative option, abstraction or + configuration shape. +- **Use the repository's scripts and tools** for formatting, license headers and other checks: + run them and act on what they report, rather than checking by reading. + +### Boundaries + +- Never commit to the default branch, force-push, or merge. Commit, push or open an issue or + a pull request only when the maintainer asks. +- A commit uses the git identity already configured, and holds a subject and a body only: no + co-author and no other trailer. +- Never weaken a gate to make a change pass: a compiler warning, a test, a coverage floor, a + dependency or license check. If a gate is wrong, say so and stop. +- Ask before a run that keeps most cores busy for more than about a minute: a full build, the + whole test suite, a benchmark. +- A suspected vulnerability goes through the repository's `SECURITY.md`, never a public issue. +- When stuck (the build does not configure, a test fails before your change, a rule seems to + block the task), report what you found instead of working around it. + +### Technical debt + +Debt is what makes each change slower or riskier than it should be. Each debt is an issue of +the repository it lies in; the issues are the source of truth. + +**The rule for every change.** Leave no new debt: a pull request must not break an invariant +of its repository, lower the coverage of the files it touches, add an unpinned dependency, or +leave a `TODO` without an issue number. Repay only the debt that lies in the lines the task +already changes. Debt seen elsewhere is recorded, not fixed in passing: a drive-by fix hides +in an unrelated diff and escapes review. + +**The cycle.** Run steps 1 to 3 whenever debt is noticed during a task. Run the whole cycle as +a debt review when the maintainer asks for one, and before each release. + +1. **Observe.** Collect facts, not opinions: a broken invariant, a duplicated source of truth, + dead code or a dead option, a `TODO`, an unpinned or duplicated dependency, a file under its + coverage floor, a static analysis finding, documentation that contradicts the code, a test + that depends on timing. +2. **Qualify against the architecture.** Name the invariant or the contract it harms, in this + repository or between repositories, and what it costs: a wrong result for users, every + change in an area, or one leftover. That gives the severity: `severity/critical` (blocks + reliable use), `severity/major` (structural, costs every change), `severity/minor` (bug or + leftover). Add `refactor` when the fix changes the architecture. If it harms nothing named, + it is a preference, not debt: drop it. +3. **Record.** One debt, one issue, in the repository where the fix belongs: the problem with + its evidence (file, line, command and output), the fix, and acceptance criteria that a test + or a command can check. Draft the issue and give it to the maintainer; create it only when + asked. Check first that no open issue already covers it. +4. **Repay.** One pull request per issue, separate from features. Pin the current behavior + with a test first, then change the structure, then show the test still passes. A repayment + changes no behavior; if it must, that is a separate, announced change. +5. **Verify.** The pull request closes the issue only when its acceptance criteria hold, the + gates pass, and the coverage of the files touched is not lower than before. +6. **Update the register**, where the repository keeps one: move the item from open to repaid, + with the issue and the pull request. At a review, also re-read every open item: still true, + still the same severity, or obsolete. + +One fifth of each iteration is reserved for repayment. Order: critical first, then major debt +in the area the next roadmap item touches, then minor debt in batches. Debt that nothing +planned will ever touch may stay open, with its reason written in the issue. + +**Where the result shows**, in any repository: + +```bash +gh issue list --label severity/critical --state open +gh issue list --label severity/major --state open +gh issue list --label severity/minor --state open +gh issue list --label refactor --state all --limit 100 +``` + +Three indicators are measured the same way at each debt review: static analysis findings, debt +added and repaid in the period, and the time to fix a vulnerability. + +# Part 2: this repository, `coretrace` + +## Scope + +This repository is `ctrace`, under Apache-2.0: the CLI and HTTP server that runs the analyzers +on C, C++ and Python sources, merges their findings into one report (text, JSON, SARIF) and +returns the exit code. It owns the contracts of Part 1: the finding model, the verdict and the +interfaces of `ctrace`. + +The analyzers are fetched at pinned versions (`cmake/*.cmake`). `ctrace` only runs them, reads +their reports and gates on them; the boundary with the hosted platform is in +[GOVERNANCE.md](GOVERNANCE.md) ("Commitments") and +[docs/open-source-scope.md](docs/open-source-scope.md). + +## Commands + +Configure once, as the [README](README.md#build) says for your platform (LLVM/Clang 20, CMake +3.28+, Ninja). Then: + +```bash +cmake --build build --parallel 4 # warnings are errors (CORETRACE_WERROR=ON) +ctest --test-dir build --output-on-failure # everything; needs cppcheck installed +ctest --test-dir build -L unit # in process, about 7 s +ctest --test-dir build -L integration # the real binary on the fixtures of tests/ +./scripts/format-check.sh # ./scripts/format.sh applies the format +./scripts/check-license-compliance.sh # SPDX header on every source file +sh scripts/release/check-pinned-dependencies.sh . # the argument is the source directory +``` + +The first build fetches and compiles the analyzers and takes minutes on every core: ask the +maintainer before starting it, and prefer `-L unit` or one test (`ctest -R `) while +iterating. + +### Scripts + +| When | Script | What it does | +|---|---|---| +| After changing C++ | `./scripts/format.sh`, then `./scripts/format-check.sh` | Applies, then verifies, the `clang-format` style on the project's own sources. CI runs the check with `clang-format` 20 | +| After adding a file | `./scripts/check-license-compliance.sh` | Fails on a tracked source, CMake, shell, Python or YAML file without `SPDX-License-Identifier: Apache-2.0` in its first 12 lines, and names it. It checks; it does not add the header: write it as the first line (`//` in C++, `#` elsewhere) | +| After touching `cmake/*.cmake` | `sh scripts/release/check-pinned-dependencies.sh .` | Fails on a dependency fetched from a branch, or a download without its hash | +| To measure coverage | `sh scripts/ci/coverage.sh build coverage` | Needs a build configured with `-DCORETRACE_COVERAGE=ON` (Clang), so a full build: ask first | +| In a CI step that uses the network | `scripts/ci/retry.sh` | Retries a command with a growing delay. Never for a test | + +No script checks commit messages in this repository: nothing will catch a wrong one. Write the +subject as an English Conventional Commit yourself, `type(scope): summary`, as the pull request +template asks for the title. + +## Architecture + +One pipeline, from the inputs to the verdict. It is the critical path of the +[test policy](docs/quality/test-policy.md): the worst failure of `ctrace` is a wrong verdict. + +| Stage | Where | Role | +|---|---|---| +| 1. Configuration | `src/App/Config.cpp`, `ToolConfig.cpp`, `ShippedDefaults.cpp`, `include/Config/config.hpp` | Built-in defaults < `--config` file < CLI, into one `ProgramConfig` (one struct per section) | +| 2. Inputs | `src/App/Files.cpp`, `src/Process/Tools/CompileCommands.cpp`, `include/Process/Tools/InputPaths.hpp` | Resolve the files; each goes to the tools of its language | +| 3. Tool runs | `include/Process/Tools/ToolsInvoker.hpp`, `src/Process/Tools/*ToolImplementation.cpp`, `include/Process/UnixProcess.hpp` | `ToolInvoker` schedules `IAnalysisTool`s on a thread pool; each writes to a `ToolOutput` | +| 4. Findings | `include/Process/Tools/Diagnostic.hpp`, `src/Process/Tools/Sarif.cpp`, `ReportFile.hpp` | Normalize, order, count, merge | +| 5. Verdict | `include/App/ExitPolicy.hpp`, `main.cpp` | `0` clean, `1` usage, `2` findings, `3` incomplete | + +Server mode (`--ipc serve`, `src/Process/Ipc/`) wraps the same pipeline per HTTP request and +returns the same verdict in `result.gate`. `src/App/Runner.cpp` is the entry of both modes. + +Two kinds of tools: + +- **Linked in process**: the stack and concurrency analyzers (`runsInProcess` in + `include/App/SupportedTools.hpp`). +- **External processes**: cppcheck, flawfinder, tscancode, ikos, and the Python and runtime + analyzers bundled under `libexec/coretrace/`. + +### Invariants + +A change that breaks one of these is wrong, or changes a contract of Part 1. + +1. **Tools know only `IAnalysisTool` and `ToolOutput`.** A tool normalizes its own format to + `Diagnostic`; counting, gating and merging never see a tool-specific format. +2. **Unknown is never clean.** A tool that could not run, or whose output could not be read, + marks its `ToolOutput` failed or unread, and the run exits with 3. Zero findings is a fact + only once the output was interpreted. An incomplete run wins over findings. +3. **Only `main.cpp` decides the exit code.** No `std::exit` or `abort` elsewhere: return the + error. +4. **One configuration, one schema.** A new setting is added to its `ProgramConfig` section, + the loader, the CLI and `docs/configuration.md` together. +5. **One output channel.** Tool results go through `ToolOutput`; status and progress go through + the logger. A tool never writes to `std::cout` or `std::cerr` itself. +6. **Output is deterministic.** Diagnostics are reported in a fixed order, whatever order the + tools finished in; sequential and parallel runs give the same fingerprints (F7 harness). +7. **In-process analyzers run under `inProcessAnalysisMutex()`** + (`include/Process/Tools/InProcessAnalysis.hpp`), until they are proven thread-safe. +8. **Dependencies are pinned** to a tag or commit, never a branch. + +### Adding or changing a tool + +A new tool is a significant change: an accepted issue comes first. Then it touches +`SUPPORTED_TOOLS` (`include/App/SupportedTools.hpp`), `registerTool` and the static or dynamic +list in `ToolsInvoker.hpp`, a class in `include/Process/Tools/AnalysisTools.hpp` with its +`src/Process/Tools/ToolImplementation.cpp`, `CMakeLists.txt`, `docs/configuration.md`, +the README, and tests with a fake tool (`tests/fake-*.sh`) for its failure paths. + +## Tests + +- **Unit tests** go in `tests/_tests.cpp` as `ctrace__tests`, follow the + `TestReport`/`expect` pattern of `tests/tool_output_tests.cpp`, and are added to + `coretrace_unit_tests` in `CMakeLists.txt`. No network, no external tool, no dependence on + timing or ordering. +- **Integration tests** are named after the behavior they check + (`ctrace_exit_3_when_a_tool_cannot_run`). +- What to validate at the boundary, and how: + [docs/quality/input-validation.md](docs/quality/input-validation.md). +- Past debts came from options and shapes nobody needed (#48, #63): the rule of Part 1 against + speculative additions is not theoretical here. + +## Technical debt in this repository + +- The register is [docs/quality/technical-debt.md](docs/quality/technical-debt.md): repaid and + open debt, by review. Step 6 of the cycle updates it. +- The gates of step 5 are: build with `-Werror`, `ctest`, format, license headers, pinned + dependencies. +- Coverage: the `coverage-report` artifact of the "Coverage (llvm-cov)" job of each pull + request, against the floors of the [test policy](docs/quality/test-policy.md); dated copies + are kept in `docs/quality/coverage/`. +- Static analysis: `ctrace` on its own code, with the protocol of + [docs/quality/static-analysis-initial.md](docs/quality/static-analysis-initial.md), so that + two reports can be compared. cppcheck and clang-tidy alone, without building `ctrace`: + [docs/quality/debt-baseline-2026-11-20.md](docs/quality/debt-baseline-2026-11-20.md). +- What the gates caught: [docs/quality/regressions.md](docs/quality/regressions.md). diff --git a/docs/quality/debt-baseline-2026-11-20.md b/docs/quality/debt-baseline-2026-11-20.md new file mode 100644 index 0000000..986ffd5 --- /dev/null +++ b/docs/quality/debt-baseline-2026-11-20.md @@ -0,0 +1,123 @@ +# Debt baseline: cppcheck and clang-tidy + +A measure of `ctrace`'s own code with two external analyzers, to count findings by severity and +name the files that concentrate them. It is the "measure" step of the debt cycle of +[AGENTS.md](../../AGENTS.md): the same commands on a later commit give the trend. + +| | | +|---|---| +| Date | 2026-11-20 | +| Commit | `00965c9` (branch `docs/agents-md`; the code is that of `main` `7de854e`) | +| Scope | The 22 translation units of the `ctrace` target (`src/**/*.cpp`, `main.cpp`) and the project headers they include (`include/`). Tests, `external/` and fetched dependencies are excluded. | +| Machine | macOS 27.0.1, Apple M3 (8 cores) | +| Tools | cppcheck 2.17.1, clang-tidy 20.1.2 (Homebrew LLVM) | +| Not run | The stack and concurrency analyzers: they need a built `ctrace`. See [Limits](#limits). | + +## Summary + +| Tool | Files | Errors | Warnings | Style | Information | +|---|---|---:|---:|---:|---:| +| cppcheck | 22/22 | 0 | 0 | 18 | 8 | +| clang-tidy | 22/22, no compilation error | 0 | 51 | — | — | + +69 findings in 23 files, none at error level. clang-tidy reports every check as a warning: its +families, below, are the useful split. + +| clang-tidy family | Findings | Checks | +|---|---:|---| +| `concurrency` | 16 | `mt-unsafe` ×16 | +| `performance` | 14 | `enum-size` ×6, `no-automatic-move` ×3, `faster-string-find` ×2, `inefficient-string-concatenation` ×2, `avoid-endl` ×1 | +| `bugprone` | 11 | `easily-swappable-parameters` ×9, `exception-escape` ×1, `nondeterministic-pointer-iteration-order` ×1 | +| `cert` | 5 | `err33-c` ×4, `err58-cpp` ×1 | +| `readability` (complexity) | 4 | `function-cognitive-complexity` ×4 | +| `clang-analyzer` | 1 | `optin.performance.Padding` ×1 | + +cppcheck: `useStlAlgorithm` ×17 and `variableScope` ×1 (style); +`normalCheckLevelMaxBranches` ×8 (information: it limited its branch exploration). + +Against the [initial report](static-analysis-initial.md) of 2026-10-13, for cppcheck, the only +tool both runs share: 18 findings then, 18 now. The `constParameterReference` of +`ToolConfig.cpp` is fixed ([#177](https://github.com/CoreTrace/coretrace/issues/177)), and one +more raw loop is flagged in `ApiHandler.cpp` (5 instead of 4). + +## Hotspots + +Findings per file, cppcheck's information notes left out. + +| | File | Findings | clang-tidy | cppcheck | Lines | What | +|---|---|---:|---:|---:|---:|---| +| 1 | `include/Process/UnixProcess.hpp` | 9 | 9 | 0 | 343 | `strerror` ×8 and `getenv` ×1, not thread-safe | +| 2 | `src/Process/Ipc/ApiHandler.cpp` | 6 | 1 | 5 | 543 | 5 raw loops; `run_analysis` has a cognitive complexity of 35 | +| 3 | `src/Process/Tools/StackAnalyzerToolImplementation.cpp` | 6 | 4 | 2 | 627 | `buildAnalyzerArgs` has a cognitive complexity of 68; swappable parameters ×3 | +| 4 | `include/Process/Interrupt.hpp` | 5 | 5 | 0 | 97 | Return values of `std::signal` and `std::raise` ignored ×4 | +| 5 | `src/App/ShippedDefaults.cpp` | 5 | 3 | 2 | 162 | `getenv` and `setenv`; 2 raw loops | + +Then `IpcStrategy.hpp`, `Sarif.cpp` and `ToolConfig.cpp`, with 4 each. + +Functions above clang-tidy's cognitive complexity threshold (25): + +| Function | File | Complexity | +|---|---|---:| +| `applyToolsSection` | `src/App/ToolConfig.cpp:1140` | 100 | +| `buildAnalyzerArgs` | `src/Process/Tools/StackAnalyzerToolImplementation.cpp:96` | 68 | +| `run_analysis` | `src/Process/Ipc/ApiHandler.cpp:294` | 35 | +| `splitCommandLine` | `src/Process/Tools/CompileCommands.cpp:22` | 28 | + +## Proposed triage + +None of these is recorded as debt yet: each line below is a proposal for the maintainer, who +opens the issue. + +| Finding | Location | Proposal | +|---|---|---| +| `concurrency-mt-unsafe`: `strerror` ×13 | `UnixProcess.hpp`, `IpcStrategy.hpp`, `RunDirectory.hpp` | To fix: tools run on a thread pool, and two failures at the same time can mix their error text. One helper over `strerror_r` or `std::system_category().message()` removes all 13. | +| `concurrency-mt-unsafe`: `getenv` ×2, `setenv` ×1 | `UnixProcess.hpp:287`, `ShippedDefaults.cpp:146,157` | `setenv("CT_CLANG")` is accepted: `main.cpp` calls it before any thread starts. The `getenv("PATH")` of `UnixProcess.hpp` runs on pool threads: to check. | +| `bugprone-exception-escape` | `src/ctrace_tools/strings.cpp:32` | To check first: `splitByComma` is `noexcept` and fills a `std::vector`, so an allocation failure ends the process. It is on the configuration stage of the critical path. | +| `cert-err33-c` ×4 | `include/Process/Interrupt.hpp:35,36,91,92` | Probably accepted: `std::signal` and `std::raise` on the way out of the process, where nothing can handle a failure. Say so with a `NOLINT` and its reason. | +| `function-cognitive-complexity` ×4 | table above | `applyToolsSection` (100) and `buildAnalyzerArgs` (68) are the two to split; both are on the critical path. | +| `bugprone-nondeterministic-pointer-iteration-order` | `include/Process/Tools/ToolsInvoker.hpp:411` | Probably a false positive: a `std::stable_partition` on a flag of each queue, not an order on pointer values. To confirm, since a deterministic output is an invariant. | +| `bugprone-easily-swappable-parameters` ×9, `performance-*` ×14, `Padding` ×1, `err58-cpp` ×1 | several | Style and micro-optimizations: decide per check whether it joins the gate, rather than per finding. | +| cppcheck `useStlAlgorithm` ×17, `variableScope` ×1 | several | Already known: D11 of the [register](technical-debt.md), and a false positive of the initial report. | + +## Limits + +- **Two tools out of four.** The stack and concurrency analyzers were not run: this measure + does not replace the final static analysis. +- **`ctrace` only.** No analyzer repository was measured. +- **The check set is a choice.** The repository has no `.clang-tidy`; the families below were + picked for this measure. Another set gives other counts, so only runs with the same set + compare. +- **cppcheck sees no include path**, as when `ctrace` runs it: it checks each `.cpp` without + the project headers. clang-tidy compiles each unit with its real command, and a finding in a + header is counted once, whatever the number of units that include it. +- **A count is a proxy.** 69 findings say where to look, not how much the debt costs; the + triage above already sets some aside. + +## Protocol + +```bash +# Compilation database: configure only, nothing is built +L=$(brew --prefix llvm@20) +cmake -S . -B build -G Ninja -DLLVM_DIR="$L/lib/cmake/llvm" -DClang_DIR="$L/lib/cmake/clang" \ + -DCLANG_EXECUTABLE="$L/bin/clang" -DENABLE_PYTHON_ANALYZER=OFF -DCMAKE_EXPORT_COMPILE_COMMANDS=ON + +# CoreTrace's own translation units, without -Werror, as in the initial report +mkdir -p self +jq '[.[] | select((.file|test("/(src/|main\\.cpp$)")) and ((.output // .command)|contains("CMakeFiles/ctrace.dir"))) + | .command |= gsub(" -Werror"; "")]' build/compile_commands.json > self/compile_commands.json +jq -r '.[].file' self/compile_commands.json | sed "s|^$PWD/||" | sort > self/files.txt + +# cppcheck, with the options ctrace gives it +cppcheck --template='{file}|{line}|{severity}|{id}|{message}' \ + --enable=warning,style,performance,portability --inline-suppr --quiet \ + --file-list=self/files.txt 2> cppcheck.txt + +# clang-tidy, two files at a time (about 90 s) +CHECKS='-*,bugprone-*,clang-analyzer-*,cert-*,concurrency-*,performance-*,portability-*,readability-function-cognitive-complexity,readability-function-size' +xargs -P 2 -n 1 "$L/bin/clang-tidy" -p self --checks="$CHECKS" \ + --header-filter="^$PWD/(src|include)/" --quiet < self/files.txt > clang-tidy.txt +``` + +Counting: one clang-tidy finding per (normalized file, line, column, check), kept when the file +is under `src/`, `include/` or is `main.cpp`. The raw output holds 310 lines for 51 findings, +because a header is reported once per unit that includes it. diff --git a/docs/quality/technical-debt.md b/docs/quality/technical-debt.md index e6fc111..c3eb73b 100644 --- a/docs/quality/technical-debt.md +++ b/docs/quality/technical-debt.md @@ -5,8 +5,8 @@ tracked, what has been repaid, and what is left. | | | |---|---| -| Date | 2026-10-13 | -| Commit | `a4aece8` | +| Date | 2026-11-20 (first version: 2026-10-13, commit `a4aece8`) | +| Commit | `7de854e` | | Sources | Issues labelled `severity/*` or `refactor`; the [initial static analysis](static-analysis-initial.md); the CI coverage report; a review of the build files, the deprecated options and the documentation | ## How debt is tracked @@ -24,13 +24,15 @@ severity: ## Repaid -Three reviews recorded 36 issues. 35 are closed. +Five reviews recorded 51 issues. 43 are closed. | Review | Issues | Critical | Major | Minor | Other | Closed | |---|---|---:|---:|---:|---:|---| | Audit, 2026-09-14 | [#41](https://github.com/CoreTrace/coretrace/issues/41)–[#65](https://github.com/CoreTrace/coretrace/issues/65) | 4 | 11 | 9 | 1 | 24, between 2026-09-19 and 2026-09-27; [#54](https://github.com/CoreTrace/coretrace/issues/54) is still open | | Review, 2026-09-21 | [#89](https://github.com/CoreTrace/coretrace/issues/89)–[#93](https://github.com/CoreTrace/coretrace/issues/93) | 2 | 2 | 1 | 0 | all 5, the next day | | Review, 2026-10-01 to 10-04 | [#133](https://github.com/CoreTrace/coretrace/issues/133), [#136](https://github.com/CoreTrace/coretrace/issues/136), [#142](https://github.com/CoreTrace/coretrace/issues/142)–[#144](https://github.com/CoreTrace/coretrace/issues/144), [#167](https://github.com/CoreTrace/coretrace/issues/167) | 0 | 1 | 3 | 2 | all 6, within 4 days | +| Register, 2026-10-13 | [#169](https://github.com/CoreTrace/coretrace/issues/169), [#172](https://github.com/CoreTrace/coretrace/issues/172)–[#178](https://github.com/CoreTrace/coretrace/issues/178) | 0 | 2 | 6 | 0 | 4, between 2026-10-14 and 2026-10-31; [#172](https://github.com/CoreTrace/coretrace/issues/172), [#173](https://github.com/CoreTrace/coretrace/issues/173), [#174](https://github.com/CoreTrace/coretrace/issues/174) and [#176](https://github.com/CoreTrace/coretrace/issues/176) are still open | +| Review, 2026-10-15 to 10-19 | [#188](https://github.com/CoreTrace/coretrace/issues/188)–[#192](https://github.com/CoreTrace/coretrace/issues/192), [#203](https://github.com/CoreTrace/coretrace/issues/203), [#207](https://github.com/CoreTrace/coretrace/issues/207) | 0 | 2 | 5 | 0 | 4, between 2026-10-16 and 2026-10-25; [#192](https://github.com/CoreTrace/coretrace/issues/192), [#203](https://github.com/CoreTrace/coretrace/issues/203) and [#207](https://github.com/CoreTrace/coretrace/issues/207) are still open | The main repayments: @@ -45,9 +47,14 @@ The main repayments: `-Werror` and runs `ctest` and coverage on every pull request. - **One output channel** instead of three ([#51](https://github.com/CoreTrace/coretrace/issues/51) → [#79](https://github.com/CoreTrace/coretrace/issues/79)). The server is hardened: bounded request bodies, CORS and the shutdown token ([#61](https://github.com/CoreTrace/coretrace/issues/61) → [#85](https://github.com/CoreTrace/coretrace/issues/85)). +- **Runs that end.** The pinned stack analyzer did not finish on CoreTrace's own code; the pin + moved to v0.23.1 ([#169](https://github.com/CoreTrace/coretrace/issues/169) → [#194](https://github.com/CoreTrace/coretrace/issues/194)). Interrupting `ctrace` now stops the running tool and removes + its run directory ([#188](https://github.com/CoreTrace/coretrace/issues/188) → [#206](https://github.com/CoreTrace/coretrace/issues/206)). +- **The gate, again.** A run with no analysis selected, or with unreadable tool output, passed + with exit code 0 ([#189](https://github.com/CoreTrace/coretrace/issues/189) → [#205](https://github.com/CoreTrace/coretrace/issues/205)).
-All 36 issues +All 51 issues | Issue | Severity | Problem | Repaid by | Closed | |---|---|---|---|---| @@ -87,6 +94,21 @@ The main repayments: | [#143](https://github.com/CoreTrace/coretrace/issues/143) | minor | `splitByComma`: undefined behaviour on a lone quote | [#149](https://github.com/CoreTrace/coretrace/issues/149) | 2026-10-01 | | [#144](https://github.com/CoreTrace/coretrace/issues/144) | minor | `mangleFunction`: parameter types inside the namespace | [#150](https://github.com/CoreTrace/coretrace/issues/150) | 2026-10-01 | | [#167](https://github.com/CoreTrace/coretrace/issues/167) | refactor | `isMangled` in the public header | [#168](https://github.com/CoreTrace/coretrace/issues/168) | 2026-10-08 | +| [#169](https://github.com/CoreTrace/coretrace/issues/169) | major | Pinned stack analyzer (v0.22.0) does not finish on CoreTrace's own code | [#194](https://github.com/CoreTrace/coretrace/issues/194) | 2026-10-16 | +| [#172](https://github.com/CoreTrace/coretrace/issues/172) | major | Linked analyzers cannot be stopped | — | open | +| [#173](https://github.com/CoreTrace/coretrace/issues/173) | minor | Deprecated spellings, and `--output-file`, which no tool uses | — | open | +| [#174](https://github.com/CoreTrace/coretrace/issues/174) | minor | Optional tools fetched from `master`; `cmake/ikos.cmake` included nowhere | — | open | +| [#175](https://github.com/CoreTrace/coretrace/issues/175) | minor | `USE_EXTERNAL_CLI11` downloads CLI11 2.3.2 while the vendored header is 2.5.0 | [#217](https://github.com/CoreTrace/coretrace/issues/217) | 2026-10-31 | +| [#176](https://github.com/CoreTrace/coretrace/issues/176) | minor | coretrace-log declared under two names and downloaded twice | — | open | +| [#177](https://github.com/CoreTrace/coretrace/issues/177) | minor | `findStackAnalyzerSection` takes its `LoadContext` by non-const reference | [#214](https://github.com/CoreTrace/coretrace/issues/214) | 2026-10-29 | +| [#178](https://github.com/CoreTrace/coretrace/issues/178) | minor | Wiki's Developer Build page still builds with `make` | wiki edit | 2026-10-14 | +| [#188](https://github.com/CoreTrace/coretrace/issues/188) | major | Interrupting `ctrace` leaves the running tool and its run directory behind | [#206](https://github.com/CoreTrace/coretrace/issues/206) | 2026-10-21 | +| [#189](https://github.com/CoreTrace/coretrace/issues/189) | major | Two runs pass the gate without checking anything | [#205](https://github.com/CoreTrace/coretrace/issues/205) | 2026-10-21 | +| [#190](https://github.com/CoreTrace/coretrace/issues/190) | minor | Inputs starting with `-` become tool options; `--static` with `--invoke` runs a tool twice; missing inputs found late | [#211](https://github.com/CoreTrace/coretrace/issues/211) | 2026-10-25 | +| [#191](https://github.com/CoreTrace/coretrace/issues/191) | minor | Server: a port in use is not detected; errors not reflected in HTTP statuses | [#200](https://github.com/CoreTrace/coretrace/issues/200) | 2026-10-16 | +| [#192](https://github.com/CoreTrace/coretrace/issues/192) | minor | Builds without a build type are unoptimized | — | open | +| [#203](https://github.com/CoreTrace/coretrace/issues/203) | minor | An input name starting with `@` may be read as a response file | — | open | +| [#207](https://github.com/CoreTrace/coretrace/issues/207) | minor | Merged SARIF log drops rule descriptions | partly, [#208](https://github.com/CoreTrace/coretrace/issues/208) | open |
@@ -94,25 +116,25 @@ The main repayments: | | Debt | Area | Severity | Effect | Action | Issue | |---|---|---|---|---|---|---| -| D1 | The pinned stack analyzer (v0.22.0) does not finish on CoreTrace's own code | dependencies | major | `--static` can run for hours on a real project | Release the analyzer from `main`, update the pin | [#169](https://github.com/CoreTrace/coretrace/issues/169) | | D2 | The linked analyzers take no timeout (`docs/configuration.md`); [#137](https://github.com/CoreTrace/coretrace/issues/137) covered external tools only | architecture | major | A stuck analyzer stalls `ctrace`, and a server request with it | Run them in a child process, or give them a cancellation point | [#172](https://github.com/CoreTrace/coretrace/issues/172) | -| D3 | The in-process Clang overflows the stack of worker threads on macOS | dependencies | major | The concurrency analyzer crashes with `SIGBUS` under the default `--jobs` | Fix in `compilerlib` | [coretrace-compiler#204](https://github.com/CoreTrace/coretrace-compiler/issues/204) | +| D3 | The in-process Clang overflows the stack of worker threads on macOS. Fixed in coretrace-compiler on 2026-10-21 ([coretrace-compiler#204](https://github.com/CoreTrace/coretrace-compiler/issues/204)), but the pinned analyzers (stack v0.23.1, concurrency v0.7.1) were released before the fix | dependencies | major | The concurrency analyzer crashes with `SIGBUS` under the default `--jobs` | Release both analyzers on a coretrace-compiler that has the fix, update the pins | — | | D4 | The Windows backend does not compile; the port was reverted | platform | major | No Windows build | Resume the port behind CI | [#54](https://github.com/CoreTrace/coretrace/issues/54) | -| D5 | The analyzers replay `-Werror` from the compilation database | dependencies | minor | An input fails on a warning that only the analyzer's libc++ emits | Drop `-Werror` in both analyzers | [coretrace-stack-analyzer#214](https://github.com/CoreTrace/coretrace-stack-analyzer/issues/214), [coretrace-concurrency-analyzer#199](https://github.com/CoreTrace/coretrace-concurrency-analyzer/issues/199) | +| D5 | The analyzers replay `-Werror` from the compilation database. Fixed in the concurrency analyzer (v0.8.0, 2026-10-15), while `ctrace` still pins v0.7.1; open in the stack analyzer | dependencies | minor | An input fails on a warning that only the analyzer's libc++ emits | Update the concurrency analyzer's pin; drop `-Werror` in the stack analyzer | [coretrace-stack-analyzer#214](https://github.com/CoreTrace/coretrace-stack-analyzer/issues/214) | | D6 | Deprecated spellings kept for compatibility: `--async` and `runtime.async`, `--ipc=socket`, legacy config keys, root-level `invoke` and `input`. `--output-file` is accepted but no tool writes to it | code | minor | Code paths to maintain and test; one option that does nothing | Announce a removal release in `CHANGELOG.md`, then remove them | [#173](https://github.com/CoreTrace/coretrace/issues/173) | | D7 | `cmake/flawfinder.cmake`, `tscancode.cmake` and `ikos.cmake` fetch `master`. `ikos.cmake` is included nowhere | build | minor | Builds with `ENABLE_FLAWFINDER` or `ENABLE_TSCANCODE` are not reproducible; one dead module | Pin a commit, or remove the options; delete `ikos.cmake` | [#174](https://github.com/CoreTrace/coretrace/issues/174) | -| D8 | Two CLI11 versions: 2.5.0 in `external/`, 2.3.2 fetched with `USE_EXTERNAL_CLI11=ON` | build | minor | The option silently downgrades the parser | Remove the option, or pin it to 2.5.0 | [#175](https://github.com/CoreTrace/coretrace/issues/175) | | D9 | coretrace-log declared under two names: `coretrace-logger` here, `coretrace_logger` in coretrace-compiler, which downloads it before checking whether the target exists | build | minor | Downloaded twice; two declarations of this dependency already broke the build once ([#37](https://github.com/CoreTrace/coretrace/issues/37), [#40](https://github.com/CoreTrace/coretrace/issues/40)) | Declare it as `coretrace_logger` | [#176](https://github.com/CoreTrace/coretrace/issues/176) | -| D10 | Unit tests cover 64.6% of the lines (89.6% with integration tests), with no threshold | tests | minor | Least covered: `ApiHandler.hpp` 64.7%, `FlawfinderToolImplementation.cpp` 72.6%, `config.hpp` 73.1%, `RunDirectory.hpp` 76.5%, `HttpServer.cpp` 79.3%, `StackAnalyzerToolImplementation.cpp` 79.4% | Tests for these files; a threshold once the test policy defines the critical path | [#164](https://github.com/CoreTrace/coretrace/issues/164) (`RunDirectory`) | -| D11 | Static analysis: `findStackAnalyzerSection` can take its `LoadContext` by `const&` (`ToolConfig.cpp:1074`); 16 raw loops flagged | code | minor | — | Fix the first; decide on the loops | [#177](https://github.com/CoreTrace/coretrace/issues/177) | -| D12 | The wiki's "Developer Build and Configuration" page still builds with `make` | docs | minor | A newcomer following the wiki gets another build than the README's | Align the page with the README | [#178](https://github.com/CoreTrace/coretrace/issues/178) | -| D13 | The `refactor` label points to a `ROADMAP.md` that does not exist | docs | minor | — | Write the roadmap (due in December), or fix the label | — | +| D10 | Unit tests cover 64.6% of the lines (89.6% with integration tests), with no threshold (measure of 2026-10-15; `RunDirectory` is covered since [#164](https://github.com/CoreTrace/coretrace/issues/164)) | tests | minor | Least covered: `ApiHandler.hpp` 64.7%, `FlawfinderToolImplementation.cpp` 72.6%, `config.hpp` 73.1%, `HttpServer.cpp` 79.3%, `StackAnalyzerToolImplementation.cpp` 79.4% | Tests for these files; a threshold once the test policy defines the critical path | — | +| D11 | Static analysis: 16 raw loops flagged by cppcheck (`useStlAlgorithm`); the `const&` of `findStackAnalyzerSection` is fixed ([#177](https://github.com/CoreTrace/coretrace/issues/177)) | code | minor | — | Decide on the loops, case by case | — | +| D14 | No default `CMAKE_BUILD_TYPE`: the README's commands and CI's main job build without optimization; the job's `--config Release` has no effect with Ninja | build | minor | The stack analyzer runs 3 to 9 times slower in such a build | Default to `Release` on single-config generators; state the build type CI tests | [#192](https://github.com/CoreTrace/coretrace/issues/192) | +| D15 | An input name starting with `@` may be read as a response file by the compiler (not reproduced yet) | code | minor | The file's contents would be expanded as compiler options | Check which tools read `@` arguments; extend `notAnOption()` | [#203](https://github.com/CoreTrace/coretrace/issues/203) | +| D16 | The merged SARIF log has no rule descriptions for the linked analyzers (stack, concurrency). [#208](https://github.com/CoreTrace/coretrace/issues/208) added them for the tools whose SARIF describes its rules | code | minor | GitHub code scanning shows no name or help text for these rules | Pin analyzer releases that expose their rule catalog (both upstream issues are closed: [coretrace-concurrency-analyzer#214](https://github.com/CoreTrace/coretrace-concurrency-analyzer/issues/214), [coretrace-stack-analyzer#242](https://github.com/CoreTrace/coretrace-stack-analyzer/issues/242)), then read it in `ctrace` | [#207](https://github.com/CoreTrace/coretrace/issues/207) | ## Debt in the analyzers -The analyzers track their own debt: coretrace-stack-analyzer has 33 open issues (27 bugs, mostly -false positives), coretrace-concurrency-analyzer 35 (32 bugs), coretrace-compiler 4. It affects -the findings `ctrace` reports, not its code. `ctrace` gets their fixes by updating its pins (D1). +The analyzers track their own debt. On 2026-11-20, coretrace-stack-analyzer has 61 open issues (44 +bugs), coretrace-concurrency-analyzer 59 (56 bugs), coretrace-compiler 10 +(7 bugs). It affects the findings `ctrace` reports, not its code. `ctrace` gets their fixes by +updating its pins (D3, D5). ## Next review