Commit Graph
2 Commits
Author SHA1 Message Date
Tejas ChopraandClaude Opus 5.5 c7a223dac0 ci(codeql): exclude tests/ from CodeQL scanning (#4047)
## Description

**In plain words:** 17 of our open CodeQL alerts are in `tests/`. 16 are
normal test code that CodeQL misreads, and **1 was a real problem, fixed
in this PR before the exclusion takes effect**:
- **15** are tests checking that a URL appears in some output, e.g.
`assert "https://…" in output`. CodeQL reads that as a weak URL security
check.
- **1** is a fake test server listening on all network interfaces
(`tests/gateway/fake_provider.py`).
- **1 is real:** `tests/test_google_multimodal_e2e.py` printed the first
10 characters of the runner's real `GOOGLE_API_KEY` (alert 51). This PR
removes that print (`dc01e95c`). It is the same one-line change as in
#4045, so the two merge cleanly in either order.

Once that print is gone, what remains under `tests/` is noise that
buries real findings: test code never ships to users. Excluding `tests/`
is standard practice, and production code (`headroom/`, `scripts/`,
plugins, workflows) is still scanned.

Part of getting CodeQL to 0 open alerts for SOC 2 (risk R-10). Companion
to #4045.

## Type of Change

- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [x] Code refactoring (no functional changes): CI configuration only

## Changes Made

- `.github/workflows/security.yml`: the CodeQL `init` step gets
  ```yaml
  config: |
    paths-ignore:
      - tests
  ```
plus a comment explaining why. Nothing else changes: same languages,
same `security-extended` query suite, same triggers.
- `tests/test_google_multimodal_e2e.py`: `print(f"Using API key:
{api_key[:10]}...")` becomes `print("Using API key from environment")`.

## Testing

- [ ] Unit tests pass (`pytest`): not applicable; the only Python change
is one `print` in a manual e2e script, checked with `py_compile`
- [x] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`): not applicable
- [ ] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
$ python -c "import yaml; d=yaml.safe_load(open('.github/workflows/security.yml')); \
    print([s['with'] for s in d['jobs']['codeql']['steps'] if s.get('name')=='Initialize CodeQL'])"
[{'languages': '${{ matrix.language }}', 'queries': 'security-extended', 'config': 'paths-ignore:\n  - tests\n'}]

# Open CodeQL alerts on main before this PR, by location:
$ gh api 'repos/headroomlabs-ai/headroom/code-scanning/alerts?ref=refs/heads/main&state=open' ...
     15 code
     17 tests/
```

CI on this PR: `test (3)` (`tests/test_onnx_dependency_contract.py`) and
`test (4)` (`tests/test_xai_cache_economics.py`) fail identically on
`main`'s latest CI run (run 37806990929). This PR changes no Python.

## Real Behavior Proof

- Environment: GitHub Actions CodeQL (`github/codeql-action@v4`),
`security.yml` on `main`.
- Exact command / steps: the YAML parses, and the `config` block reaches
the CodeQL `init` step as shown above. The CodeQL scans on this PR
completed successfully for `python` and `javascript-typescript`.
- Observed result: before merge, `main` has 17 open alerts under
`tests/`.
- Not tested: the closure of those 17 alerts can only be observed after
merge. On pull requests, CodeQL reports only alerts on changed lines, so
this PR's own scan can't show it. After merge, the push-triggered scan
of `main` should close all 17. I'll confirm the count on `main` and post
it here.

## Runtime Rollout Safety

- Rollout-managed feature(s): none.
- Minimum rollout channel: n/a.
- Stable/default behavior changed: no product behavior changes. CodeQL
stops analysing files under `tests/`.
- Kill switch / disable path: remove the `config` block.
- Unsafe override required: no.
- Qualification impact: none.
- Rollback path: revert this PR. The next scan of `main` will re-report
test-code alerts.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation (none
needed)
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works (CI config only; verified after merge as described above)
- [x] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md`

## Additional Notes

- Trade-off: a real vulnerability inside test code would no longer be
flagged. Test code doesn't ship, and the alternative was dismissing 17
alerts one by one as "used in tests" and repeating that for every new
one.
- **Devin's review asked for runtime proof.** See "Not tested" above:
the proof is the post-merge scan of `main`, which I'll post as a
comment.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 22:38:47 -05:00
chopratejasandClaude Opus 4.5 62ee1dc9e3 Add E2E tests for Google multimodal content preservation
- Tests for text-only, image, function calling, function response, mixed conversation
- Tests skip automatically when GOOGLE_API_KEY not set (CI-safe)
- Can run standalone: GOOGLE_API_KEY=key python tests/test_google_multimodal_e2e.py

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 21:01:25 -08:00