Srql/rust tests #2420
No reviewers
Labels
No labels
1week
2weeks
Failed compliance check
IP cameras
NATS
Possible security concern
Review effort 1/5
Review effort 2/5
Review effort 3/5
Review effort 4/5
Review effort 5/5
UI
aardvark
accessibility
amd64
api
arm64
auth
back-end
bgp
blog
bug
build
checkers
ci-cd
cleanup
cnpg
codex
core
dependencies
device-management
documentation
duplicate
dusk
ebpf
enhancement
eta 1d
eta 1hr
eta 3d
eta 3hr
feature
fieldsurvey
github_actions
go
good first issue
help wanted
invalid
javascript
k8s
log-collector
mapper
mtr
needs-triage
netflow
network-sweep
observability
oracle
otel
plug-in
proton
python
question
reddit
redhat
research
rperf
rperf-checker
rust
sdk
security
serviceradar-agent
serviceradar-agent-gateway
serviceradar-web
serviceradar-web-ng
siem
snmp
sysmon
topology
ubiquiti
wasm
wontfix
zen-engine
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
carverauto/serviceradar!2420
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "refs/pull/2420/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from GitHub pull request.
Original GitHub pull request: #1952
Original author: @mfreeman451
Original URL: https://github.com/carverauto/serviceradar/pull/1952
Original created: 2025-11-18T16:26:22Z
Original updated: 2025-11-19T04:09:21Z
Original head: carverauto/serviceradar:srql/rust_tests
Original base: main
Original merged: 2025-11-19T04:08:49Z by @mfreeman451
User description
IMPORTANT: Please sign the Developer Certificate of Origin
Thank you for your contribution to ServiceRadar. Please note, when contributing, the developer must include
a DCO sign-off statement indicating the DCO acceptance in one commit message. Here
is an example DCO Signed-off-by line in a commit message:
Describe your changes
Issue ticket number and link
Code checklist before requesting a review
PR Type
Tests, Enhancement
Description
Add comprehensive unit tests for SRQL query modules
cpu_metrics.rs: stats query validation with aggregation and groupinginterfaces.rs: count aggregation query generationlogs.rs: multi-field stats query with JSON payload shapingRefactor query planning logic into standalone functions for testability
build_query_plan()anddetermine_limit()fromQueryEngineimplAdd integration tests for SRQL DSL end-to-end scenarios
Create OpenSpec proposal for SRQL API test harness
Diagram Walkthrough
File Walkthrough
cpu_metrics.rs
Add CPU metrics stats query unit testsrust/srql/src/query/cpu_metrics.rs
#[cfg(test)]module withstats_query_matches_cpu_language_reference()teststats_plan()constructs testQueryPlanwith time rangeand filters
count
interfaces.rs
Add interfaces count aggregation unit testsrust/srql/src/query/interfaces.rs
#[cfg(test)]module withstats_count_interfaces_emits_count_query()teststats_plan()creates test plan with device filter and timerange
logs.rs
Add logs stats query aggregation unit testsrust/srql/src/query/logs.rs
#[cfg(test)]module withstats_query_counts_logs_for_service()test
shaping
stats_plan()constructs plan with service name filter and24-hour time range
construction
mod.rs
Refactor query planning and add integration testsrust/srql/src/query/mod.rs
build_query_plan()anddetermine_limit()as standalonefunctions from
QueryEngineimplexecute_query()andtranslate_query()to call extractedfunctions
#[cfg(test)]module with 6 integration testsdiscovery sources, service types, interfaces IP filtering, pollers
health/status
plan_for()andtest_config()support deterministic testexecution
time range resolution
proposal.md
OpenSpec proposal for SRQL API test harnessopenspec/changes/add-srql-api-tests/proposal.md
negative-path coverage, translator unit tests
documentation updates required
codes
spec.md
SRQL API test requirements and scenariosopenspec/changes/add-srql-api-tests/specs/srql/spec.md
validation, DSL semantics unit tests
invalid DSL 400 response, missing auth 401 response, availability
filter alignment, aggregation example queries
docs/docs/srql-language-reference.mdtasks.md
SRQL API test implementation tasksopenspec/changes/add-srql-api-tests/tasks.md
coverage tests, CI/docs updates
integration tests, error handling, auth validation, unit tests, CI
wiring, and contributor documentation
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/1952#issuecomment-3548485519
Original created: 2025-11-18T16:27:05Z
PR Compliance Guide 🔍
(Compliance updated until commit
github.com/carverauto/serviceradar@990449075c)Below is a summary of compliance checks for this PR:
Insecure DB auth
Description: The local Postgres bootstrap script disables authentication by setting pg_hba.conf to
trust for all hosts (both IPv4 and IPv6), which is unsafe if the container port becomes
reachable outside the test harness.
harness.rs [37-56]
Referred Code
Unverified image load
Description: The harness loads a container image from a local tar archive path (
/opt/cnpg_image.tar)without verifying integrity or signature, allowing a tampered image to be used if the file
is replaced.
harness.rs [468-499]
Referred Code
Exposed database service
Description: The service exposes the CNPG primary via a public LoadBalancer with shared IP annotations
and no NetworkPolicy, increasing risk of unauthorized external database access if
credentials leak.
services.yaml [1-21]
Referred Code
Hardcoded secret placeholders
Description: Kubernetes Secret manifest contains placeholder plaintext passwords in version control,
which may lead to accidental use or leakage if applied without replacement.
cnpg-test-credentials.yaml [1-10]
Referred Code
Hardcoded admin secret
Description: Admin Secret manifest includes a plaintext placeholder password; committing admin
credential templates with defaults risks accidental deployment with weak/known values.
cnpg-test-admin-credentials.yaml [1-10]
Referred Code
Secret exposure via CI env
Description: CI workflow exports database URLs (including credentials) via environment variables; if
job logs or steps echo these values, secrets could be exposed—masking and least-privilege
secrets recommended.
main.yml [15-18]
Referred Code
CI secrets handling
Description: GitHub Actions workflow passes DB connection secrets as environment variables to jobs;
ensure no steps print env, and prefer GitHub Actions secrets with explicit masking and
least-privileged DB roles.
tests-rust.yml [21-25]
Referred Code
Public router exposure
Description: The
routermethod was made public, increasing the surface where a misconfigured callercould expose routes without required middleware (e.g., auth); verify all entrypoints
enforce authentication.
server.rs [48-52]
Referred Code
🎫 No ticket provided
Codebase context is not defined
Follow the guide to enable codebase context checks.
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting
Status: Passed
Generic: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.
Status:
Secrets Exposure: The code logs connection details including database names and hosts and may read secrets
from files; ensure no credentials are logged and avoid printing DSNs even in tests.
Referred Code
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.
Status:
Action Logging: The new test harness performs critical actions (database resets, seeding, remote lock
acquisition) without adding explicit audit logging of who/when/what for these operations.
Referred Code
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation
Status:
Error Handling: Database bootstrap and extension installation handle some errors but rely on retries and
may surface generic errors without contextual logging for all edge cases (e.g., Docker
failures, missing fixtures).
Referred Code
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.
Status:
Sensitive Details: Helper functions print connection parsing errors and detailed paths which could expose
internal details when running in CI; confirm these are limited to test context and not
user-facing.
Referred Code
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities
Status:
Shell Usage: The harness invokes external commands (docker/skopeo) and constructs SQL statements;
although inputs are controlled, review quoting and environment use to ensure no injection
risk in CI contexts.
Referred Code
Compliance status legend
🟢 - Fully Compliant🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label
Previous compliance checks
Compliance check up to commit 6f91b3a
No security concerns identified
No security vulnerabilities detected by AI analysis. Human verification advised for critical code.🎫 No ticket provided
Codebase context is not defined
Follow the guide to enable codebase context checks.
Generic: Meaningful Naming and Self-Documenting Code
Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting
Status: Passed
Generic: Secure Error Handling
Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.
Status: Passed
Generic: Secure Logging Practices
Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.
Status: Passed
Generic: Comprehensive Audit Trails
Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.
Status:
No audit logs: New functions and tests add query planning and SQL generation behavior without any audit
logging of critical actions such as query execution or translation.
Referred Code
Generic: Robust Error Handling and Edge Case Management
Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation
Status:
Limited errors: Added tests assert on SQL strings but do not validate error branches or edge cases like
empty stats, invalid fields, or time ranges, leaving robustness unverified in new code
paths.
Referred Code
Generic: Security-First Input Validation and Data Handling
Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities
Status:
Limit clamping: While limits are clamped, new planning code relies on AST parsing and cursor decoding
without added validation in this diff; verify external inputs are fully validated
upstream.
Referred Code
Imported GitHub PR comment.
Original author: @qodo-code-review[bot]
Original URL: https://github.com/carverauto/serviceradar/pull/1952#issuecomment-3548508030
Original created: 2025-11-18T16:32:37Z
PR Code Suggestions ✨
Explore these optional code suggestions:
Implement tests against a database
Replace fragile SQL string-based tests with more robust tests that execute
queries against a seeded database to validate actual results, aligning the
implementation with the strategy proposed in the PR's own design documents.
Examples:
rust/srql/src/query/mod.rs [269-274]
openspec/changes/add-srql-api-tests/proposal.md [7-10]
Solution Walkthrough:
Before:
After:
Suggestion importance[1-10]: 9
__
Why: The suggestion correctly identifies that the new tests rely on fragile SQL string assertions, and advocates for the more robust database-backed testing strategy already outlined in the PR's own
openspecproposal.