test: cost on harness#5075
Conversation
|
tejas ghatte seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
📝 WalkthroughWalkthroughAdds a report-only "Logs-API cost audit" to the Newman dbverify reporter that classifies billable inference requests, polls the logs API for populated cost, and records PASS/WARN results. Adds configuration flags, summary reporting for WARN counts, exported helper functions, unit tests, and npm test script wiring. ChangesLogs-API Cost Audit
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Newman as Newman Reporter
participant API as Inference API
participant LogsAPI as Logs API
Newman->>API: send request
API-->>Newman: 2xx response
Newman->>Newman: isBillableInferenceURL(url)
alt billable
Newman->>LogsAPI: GET /api/logs/{requestId}
LogsAPI-->>Newman: log row (cost pending)
Newman->>LogsAPI: poll GET /api/logs/{requestId}
LogsAPI-->>Newman: log row with cost
Newman->>Newman: classifyLogCost(log) => PASS/WARN
end
Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Confidence Score: 4/5The e2e DB verification path can be skipped when optional DB drivers are not installed.
tests/e2e/api/package.json Important Files Changed
Reviews (1): Last reviewed commit: "test: cost on harness" | Re-trigger Greptile |
| "optionalDependencies": { | ||
| "pg": "8.13.0", | ||
| "better-sqlite3": "11.0.0" |
There was a problem hiding this comment.
When better-sqlite3 or pg fails to install as an optional dependency, the DB verifier still starts, catches the missing driver, and records DB-backed checks as skipped instead of failing setup. A minimal CI image or unsupported native-addon platform can then pass the Newman run while the requested DB verification never runs.

Summary
Adds a report-only logs-API cost audit to the
newman-reporter-dbverifyNewman reporter. After each successful billable inference response, the reporter fetches the corresponding log row viaGET /api/logs/{request-id}and records whether cost was populated. This audit requires no direct database access — it uses the same API a UI would — and never fails the test run; results surface asWARNentries in the summary.Changes
isBillableInferenceURL()to classify inference endpoints (chat completions, messages, responses, Gemini generateContent, Cohere, embeddings, audio, images) as billable while excluding utility endpoints (token counting, model/file/batch management).verifyInferenceCostViaAPI()which pollsGET /api/logs/{reqId}with exponential-ish back-off (~7.2s total) to account for asynchronous log writes and deferred cost population. Auth errors (401/403) and missing log rows (404 after all retries) surface asWARN, notFAIL.classifyLogCost()to evaluate a fetched log row and emitPASS(cost > 0) orWARN(cost missing/zero).x-request-idresponse header to correlate the request to its log row.printSummary()to count and displayWARNresults alongside pass/fail/skip, with a dedicated console note when any cost checks warn.isBillableInferenceURLandclassifyLogCostfor unit testing.index.test.jswith framework-free unit tests covering billable/non-billable URL classification and cost classification logic.pgandbetter-sqlite3tooptionalDependenciesso environments without native build tooling can still install the package.testscript topackage.jsonthat runs bothlib/pricing.test.jsandnewman-reporter-dbverify/index.test.js.Type of change
Affected areas
How to test
Environment variables:
BIFROST_LOGS_API_COST1(enabled)0,false,no, oroffto disable the cost auditBIFROST_LOGS_API_AUTHAuthorizationheader value for the logs API if dashboard auth is enabledWhen the audit runs, each inference request will produce a
PASS(cost populated) orWARN(cost missing or fetch error) entry in the Newman reporter summary. The run will never be failed by this check.Breaking changes
Related issues
Security considerations
The
BIFROST_LOGS_API_AUTHvalue is passed as anAuthorizationheader to the logs API. It should be treated as a secret and not logged. The reporter already avoids printing it; ensure it is supplied via environment variable rather than committed configuration.Checklist
docs/contributing/README.mdand followed the guidelines