test(usage): prove product usage works on PostgreSQL, and harden the collector default
Everything about this feature had been exercised on SQLite only, which is the engine least likely to show its problems. Adds __tests__/integration/productUsagePg.test.js, following the gated pattern the .picpeak restore suites use: it runs the real migrations 201-203 against a real PostgreSQL and covers what SQLite cannot answer. node-postgres returns bigint as a STRING, and the withdrawal guard compares `cancel_seq` — a `'1' !== 1` slip there would let an activation complete after an opt-out, and SQLite, which hands back a number, would never show it. Booleans are real booleans rather than 0/1, which is what every `configured` signal in a report is built from. And markUsed takes SELECT ... FOR UPDATE on this engine only. Seven cases, all passing against PostgreSQL 15. Removing the compare-and-swap condition fails the withdrawal case there too, so the suite has teeth on that engine and not only on SQLite. CI already provides PICPEAK_PG_TEST_URL, so these run there rather than skipping. The collector default is harder to lose. An unset, empty or whitespace-only USAGE_COLLECTOR_URL now falls back to https://usage.picpeak.app — deployments that template the variable in (docker-compose writes ${USAGE_COLLECTOR_URL:-...}) can hand over an empty string, and that has to mean "use the default" rather than "no collector". A value that is present but malformed is still reported as a configuration error instead of being silently replaced: quietly retargeting a self-hoster's collector at ours would send their reports somewhere they did not choose. Refs #1110
This commit is contained in:
@@ -109,8 +109,15 @@ class UsageService {
|
||||
options.secret ||
|
||||
process.env.USAGE_ENCRYPTION_KEY ||
|
||||
process.env.JWT_SECRET;
|
||||
this.endpoint =
|
||||
options.endpoint || process.env.USAGE_COLLECTOR_URL || DEFAULT_COLLECTOR_URL;
|
||||
// Falls back to the default whenever nothing usable is configured —
|
||||
// unset, empty, or whitespace. Deployments that template the variable in
|
||||
// (docker-compose writes USAGE_COLLECTOR_URL=${USAGE_COLLECTOR_URL:-...})
|
||||
// can hand over an empty string, and that must mean "use the default",
|
||||
// not "no collector". A value that is present but malformed is NOT
|
||||
// silently replaced: quietly retargeting a self-hoster's collector at
|
||||
// ours would send their reports somewhere they did not choose.
|
||||
const configured = (options.endpoint ?? process.env.USAGE_COLLECTOR_URL ?? '').trim();
|
||||
this.endpoint = configured || DEFAULT_COLLECTOR_URL;
|
||||
this.bindingPath =
|
||||
options.bindingPath || path.join(getStoragePath(), 'usage-instance.key');
|
||||
this.encKey = null;
|
||||
|
||||
Reference in New Issue
Block a user