([\s\S]*?)<\/div>/.exec(card) || ['', ''])[1]),
+ delta: /class="delta /.test(card),
+ }));
+}
+
+function snapshot(over = {}) {
+ return {
+ asOf: '2026-11-02', generatedAt: '', provenance: '', retentionDays: 90, wauWindowDays: 7, mauWindowDays: 30,
+ totalInstalls: 400, wau: 120, mau: 340, engagedMau: 60, engagedMinDays: 2,
+ wauGrowth7d: null, mauGrowth30d: null, engagedGrowth30d: null,
+ ...over,
+ };
+}
+
+const withheldTool = (tool, versions = [{ version: '1.0.0', installs: null }]) => (
+ { tool, product: tool, totalInstalls: null, wau: null, mau: null, engagedMau: null, versions }
+);
+
+test('normalizeAdoptionFeed keeps a tool row whose figures are withheld and floors every count under ten to null', () => {
+ const { normalizeAdoptionFeed } = require(join(ROOT, 'lib', 'telemetry.js'));
+ const n = normalizeAdoptionFeed({
+ totalInstalls: 0, wau: 9, mau: 10, engagedMau: null,
+ tools: [
+ { tool: 'tool-a', totalInstalls: null, wau: null, mau: null, engagedMau: null, versions: [{ version: '1.0.0', installs: null }] },
+ { tool: 'tool-b', totalInstalls: 0, wau: 1, mau: 9, engagedMau: 0, versions: [{ version: '2.0.0', installs: 3 }] },
+ { tool: 'tool-c', totalInstalls: 12, wau: 10, mau: 11, engagedMau: 10, versions: [{ version: '3.0.0', installs: 10 }] },
+ { tool: 'tool-x', totalInstalls: 'many', wau: 10, mau: 10, engagedMau: 10 }, // not a figure: dropped
+ ],
+ byCountry: [{ countryCode: 'AA', installs: 4 }, { countryCode: 'BB', installs: 25 }],
+ });
+ assert.deepStrictEqual(
+ [n.totalInstalls, n.wau, n.mau, n.engagedMau], [null, null, 10, null],
+ 'fleet: 0 and 9 and a withheld figure are null, 10 is kept'
+ );
+ assert.deepStrictEqual(n.tools.map(t => t.tool), ['tool-a', 'tool-b', 'tool-c'], 'the withheld row is kept, the untrusted one dropped');
+ assert.deepStrictEqual(n.tools.map(t => [t.totalInstalls, t.wau, t.mau, t.engagedMau]), [
+ [null, null, null, null],
+ [null, null, null, null],
+ [12, 10, 11, 10],
+ ]);
+ assert.deepStrictEqual(n.tools.map(t => t.versions), [
+ [{ version: '1.0.0', installs: null }],
+ [{ version: '2.0.0', installs: null }],
+ [{ version: '3.0.0', installs: 10 }],
+ ]);
+ assert.deepStrictEqual(n.byCountry, [{ countryCode: 'AA', installs: null }, { countryCode: 'BB', installs: 25 }]);
+});
+
+test('normalizeAdoptionFeed accepts a fleet whose totals are all withheld, and still rejects one that omits them', () => {
+ const { normalizeAdoptionFeed } = require(join(ROOT, 'lib', 'telemetry.js'));
+ const n = normalizeAdoptionFeed({ totalInstalls: null, wau: null, mau: null, engagedMau: null, tools: [] });
+ assert.deepStrictEqual([n.totalInstalls, n.wau, n.mau, n.engagedMau], [null, null, null, null]);
+ assert.throws(() => normalizeAdoptionFeed({ wau: null, mau: null }), /fleet totals/, 'a missing total is not a withheld one');
+ assert.throws(() => normalizeAdoptionFeed({ totalInstalls: 50, wau: 20, mau: 30, engagedMau: 'x' }), /engagedMau/);
+});
+
+test('a feed whose per-tool totalInstalls, wau, mau and engagedMau are null keeps the row through the store, the API and the dashboard, each cell reading "fewer than 10", never 0', async () => {
+ const dir = tmp('chain');
+ try {
+ mkdirSync(join(dir, 'data'));
+ const dbFile = storeAt(join(dir, 'data', 'analytics.db'), NOT_NULL_SCHEMA);
+ const run = await collect({
+ generatedAt: '2026-11-02T00:00:00Z', provenance: 'synthetic feed', retentionDays: 90, wauWindowDays: 7,
+ mauWindowDays: 30, totalInstalls: 400, wau: 120, mau: 340, engagedMau: 60, engagedMinDays: 2,
+ tools: [
+ { tool: 'tool-a', totalInstalls: null, wau: null, mau: null, engagedMau: null, versions: [{ version: '1.0.0', installs: null }] },
+ { tool: 'tool-b', totalInstalls: 300, wau: 110, mau: 300, engagedMau: 55, versions: [{ version: '2.0.0', installs: 250 }] },
+ ],
+ byCountry: [],
+ }, dbFile);
+ assert.equal(run.status, 0, `the collection is stored; output:\n${run.stdout}\n${run.stderr}`);
+
+ const body = await serveTelemetry(dir);
+ const a = body.tools.find(t => t.tool === 'tool-a');
+ assert.ok(a, `the API keeps the row whose figures are withheld; served: ${JSON.stringify(body.tools.map(t => t.tool))}`);
+ for (const field of ['totalInstalls', 'wau', 'mau', 'engagedMau']) {
+ assert.strictEqual(a[field], null, `${field} is served as null, never 0`);
+ }
+ assert.deepStrictEqual(a.versions, [{ version: '1.0.0', installs: null }]);
+
+ const { TelemetrySection } = await dashboard('TelemetrySection');
+ const row = tableRows(render(TelemetrySection, { data: body })).find(cells => cells[0].startsWith('tool-a'));
+ assert.ok(row, 'the dashboard keeps the row');
+ assert.deepStrictEqual(row.slice(1), [LABEL, LABEL, LABEL, LABEL, `each version ${LABEL}`]);
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test('the dashboard reads "fewer than 10" in every withheld cell, never 0, and states the rule once', async () => {
+ const { TelemetrySection } = await dashboard('TelemetrySection');
+ const html = render(TelemetrySection, {
+ data: {
+ snapshot: snapshot({ totalInstalls: null, wau: null, mau: null, engagedMau: null, provenance: 'Synthetic provenance.' }),
+ tools: [
+ { tool: 'tool-b', product: 'Tool B', totalInstalls: 300, wau: 110, mau: 300, engagedMau: 55, versions: [{ version: '2.0.0', installs: 250 }] },
+ withheldTool('tool-a'),
+ ],
+ byCountry: [{ countryCode: 'BB', installs: 25 }, { countryCode: 'AA', installs: null }],
+ },
+ });
+ const cards = kpis(html);
+ assert.deepStrictEqual(cards.map(c => [c.label, c.value]), [
+ ['Engaged monthly users', LABEL],
+ ['Reported MAU', LABEL],
+ ['Reported WAU', LABEL],
+ ]);
+ const rows = tableRows(html);
+ assert.deepStrictEqual(rows, [
+ ['Tool Btool-b', '300', '55', '300', '110', '2.0.0 · 250'],
+ ['tool-a', LABEL, LABEL, LABEL, LABEL, `each version ${LABEL}`],
+ ]);
+ for (const cell of rows.flat()) assert.doesNotMatch(cell, /^0$|· 0$/, `no withheld cell reads 0: ${cell}`);
+ const chipRow = /
([\s\S]*?)<\/div>/.exec(html);
+ assert.ok(chipRow, 'the country chips render');
+ const chips = chipRow[1].split(' text(p.slice(p.indexOf('>') + 1)));
+ assert.deepStrictEqual(chips, ['BB · 25', `AA · ${LABEL}`]);
+ assert.ok(text(html).includes(`Synthetic provenance. ${NOTE}`), 'the provenance carries the withheld note');
+ assert.equal(text(html).split(NOTE).length - 1, 1, 'the note is stated once');
+});
+
+test('the overview KPI reads "fewer than 10" for a withheld engaged or reported count, never 0', async () => {
+ const { ActiveCliUsersKpi } = await dashboard('ActiveCliUsersKpi');
+ const [card] = kpis(render(ActiveCliUsersKpi, { snapshot: snapshot({ engagedMau: null, mau: null, engagedGrowth30d: 5 }) }));
+ assert.deepStrictEqual(card, {
+ label: 'Active CLI Users', value: LABEL, sub: `engaged monthly · ${LABEL} reported`, delta: false,
+ });
+ const [measured] = kpis(render(ActiveCliUsersKpi, { snapshot: snapshot({ engagedMau: 60, mau: 340, engagedGrowth30d: 12 }) }));
+ assert.deepStrictEqual([measured.value, measured.sub, measured.delta], ['60', 'engaged monthly · 340 reported', true]);
+});
+
+test('a figure the dashboard computes leaves a withheld cell out: no change against a withheld side, no withheld version named as the top one', async () => {
+ const { TelemetrySection } = await dashboard('TelemetrySection');
+ const html = render(TelemetrySection, {
+ data: {
+ // engaged 12 now, 7 a month ago (withheld): no change can be computed.
+ // MAU 330 now, 300 a month ago: both measured, so the change shows.
+ // WAU withheld now: no change either.
+ snapshot: snapshot({ engagedMau: 12, engagedGrowth30d: 5, mau: 330, mauGrowth30d: 30, wau: null, wauGrowth7d: 4 }),
+ tools: [{
+ tool: 'tool-c', product: 'tool-c', totalInstalls: 80, wau: 20, mau: 60, engagedMau: 15,
+ // A withheld version listed first is never taken as the top one.
+ versions: [{ version: '2.0.0', installs: null }, { version: '1.1.0', installs: 15 }, { version: '1.0.0', installs: 40 }],
+ }],
+ byCountry: [],
+ },
+ });
+ assert.deepStrictEqual(kpis(html).map(c => [c.label, c.delta]), [
+ ['Engaged monthly users', false],
+ ['Reported MAU', true],
+ ['Reported WAU', false],
+ ]);
+ assert.match(html, /\+10%/, 'the measured change is computed from measured values only');
+ assert.deepStrictEqual(tableRows(html)[0][5], '1.0.0 · 40');
+});
+
+test('/api/telemetry serves only floored counts, keeps every row, and orders a withheld row after the measured ones by name, never by the count it hides', async () => {
+ const dir = tmp('api');
+ try {
+ mkdirSync(join(dir, 'data'));
+ // A store holding NULLs and, as an older store did, raw counts under ten.
+ storeAt(join(dir, 'data', 'analytics.db'), NULLABLE_SCHEMA, (db) => {
+ db.prepare('INSERT INTO telemetry_snapshots (date, total_installs, wau, mau, engaged_mau) VALUES (?, ?, ?, ?, ?)')
+ .run('2026-11-02', 0, 9, 120, null);
+ const tool = db.prepare('INSERT INTO telemetry_tool_snapshots (date, tool, total_installs, wau, mau, engaged_mau) VALUES (?, ?, ?, ?, ?, ?)');
+ tool.run('2026-11-02', 'tool-c', 0, 20, 50, 12);
+ tool.run('2026-11-02', 'tool-a', null, null, null, null);
+ tool.run('2026-11-02', 'tool-b', 0, 3, 7, 1);
+ tool.run('2026-11-02', 'tool-d', 0, 1, 3, 0);
+ const version = db.prepare('INSERT INTO telemetry_version_snapshots (date, tool, version, installs) VALUES (?, ?, ?, ?)');
+ version.run('2026-11-02', 'tool-c', '1.0.0', 30);
+ version.run('2026-11-02', 'tool-c', '1.1.0', 8);
+ version.run('2026-11-02', 'tool-c', '0.9.0', 4);
+ version.run('2026-11-02', 'tool-c', '0.8.0', null);
+ const country = db.prepare('INSERT INTO telemetry_country_snapshots (date, country_code, installs) VALUES (?, ?, ?)');
+ country.run('2026-11-02', 'BB', 6);
+ country.run('2026-11-02', 'AA', 2);
+ country.run('2026-11-02', 'CC', 11);
+ });
+ const body = await serveTelemetry(dir);
+ const s = body.snapshot;
+ assert.deepStrictEqual([s.totalInstalls, s.wau, s.mau, s.engagedMau], [null, null, 120, null]);
+ assert.deepStrictEqual(body.tools.map(t => [t.tool, t.totalInstalls, t.wau, t.mau, t.engagedMau]), [
+ ['tool-c', null, 20, 50, 12],
+ ['tool-a', null, null, null, null],
+ ['tool-b', null, null, null, null],
+ ['tool-d', null, null, null, null],
+ ]);
+ assert.deepStrictEqual(body.tools[0].versions, [
+ { version: '1.0.0', installs: 30 },
+ { version: '0.8.0', installs: null },
+ { version: '0.9.0', installs: null },
+ { version: '1.1.0', installs: null },
+ ]);
+ assert.deepStrictEqual(body.byCountry, [
+ { countryCode: 'CC', installs: 11 },
+ { countryCode: 'AA', installs: null },
+ { countryCode: 'BB', installs: null },
+ ]);
+ assert.deepStrictEqual(body.withheld, { below: 10, label: LABEL });
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test('the collector stores NULL for a withheld figure and for a count from 0 to 9, stores 10 or more as is, and keeps every row', async () => {
+ const dir = tmp('collect');
+ try {
+ const dbFile = storeAt(join(dir, 'analytics.db'), NOT_NULL_SCHEMA);
+ const run = await collect({
+ retentionDays: 90, wauWindowDays: 7, mauWindowDays: 30, engagedMinDays: 2,
+ totalInstalls: 0, wau: 9, mau: 10, engagedMau: null,
+ tools: [
+ {
+ tool: 'tool-a', totalInstalls: null, wau: 1, mau: 9, engagedMau: 0,
+ versions: [{ version: '1.0.0', installs: null }, { version: '0.9.0', installs: 3 }, { version: '0.8.0', installs: 10 }],
+ },
+ { tool: 'tool-b', totalInstalls: 12, wau: 10, mau: 11, engagedMau: 10, versions: [] },
+ ],
+ byCountry: [{ countryCode: 'AA', installs: 4 }, { countryCode: 'BB', installs: 10 }],
+ }, dbFile);
+ assert.equal(run.status, 0, `output:\n${run.stdout}\n${run.stderr}`);
+ readOnly(dbFile, (db) => {
+ assert.deepStrictEqual(db.prepare('SELECT total_installs, wau, mau, engaged_mau FROM telemetry_snapshots').all(), [
+ { total_installs: null, wau: null, mau: 10, engaged_mau: null },
+ ]);
+ assert.deepStrictEqual(
+ db.prepare('SELECT tool, total_installs, wau, mau, engaged_mau FROM telemetry_tool_snapshots ORDER BY tool').all(), [
+ { tool: 'tool-a', total_installs: null, wau: null, mau: null, engaged_mau: null },
+ { tool: 'tool-b', total_installs: 12, wau: 10, mau: 11, engaged_mau: 10 },
+ ]
+ );
+ assert.deepStrictEqual(db.prepare('SELECT version, installs FROM telemetry_version_snapshots ORDER BY version').all(), [
+ { version: '0.8.0', installs: 10 },
+ { version: '0.9.0', installs: null },
+ { version: '1.0.0', installs: null },
+ ]);
+ assert.deepStrictEqual(db.prepare('SELECT country_code, installs FROM telemetry_country_snapshots ORDER BY country_code').all(), [
+ { country_code: 'AA', installs: null },
+ { country_code: 'BB', installs: 10 },
+ ]);
+ for (const [table, cols] of Object.entries(COUNT_COLUMNS)) {
+ for (const c of db.prepare(`PRAGMA table_info(${table})`).all().filter(c => cols.includes(c.name))) {
+ assert.deepStrictEqual([c.notnull, c.dflt_value], [0, null], `${table}.${c.name} is nullable with no default`);
+ }
+ }
+ });
+ assert.match(
+ run.stdout,
+ new RegExp(`Installs: ${LABEL} \\| WAU: ${LABEL} \\| MAU: 10 \\| engaged\\(MAU\\): ${LABEL} \\| tools: 2 \\| countries: 2`),
+ 'the public log line carries floored figures only'
+ );
+ assert.equal(JSON.parse(readFileSync(join(dir, 'telemetry-badge.json'), 'utf8')).message, '10');
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test('the store step sets every stored count from 0 to 9 to withheld, zero included, keeps every row and every count of 10 or more, and changes nothing on a second run', async () => {
+ const dir = tmp('floor');
+ try {
+ const dbFile = storeAt(join(dir, 'analytics.db'), NOT_NULL_SCHEMA, (db) => {
+ const fleet = db.prepare('INSERT INTO telemetry_snapshots (date, total_installs, wau, mau, engaged_mau) VALUES (?, ?, ?, ?, ?)');
+ fleet.run('2026-10-01', 0, 3, 120, 9);
+ fleet.run('2026-10-02', 0, 15, 130, 40);
+ const tool = db.prepare('INSERT INTO telemetry_tool_snapshots (date, tool, total_installs, wau, mau, engaged_mau) VALUES (?, ?, ?, ?, ?, ?)');
+ tool.run('2026-10-01', 'tool-a', 0, 1, 9, 0);
+ tool.run('2026-10-01', 'tool-b', 0, 25, 60, 12);
+ tool.run('2026-10-02', 'tool-a', 0, 10, 11, 2);
+ const version = db.prepare('INSERT INTO telemetry_version_snapshots (date, tool, version, installs) VALUES (?, ?, ?, ?)');
+ version.run('2026-10-01', 'tool-a', '1.0.0', 4);
+ version.run('2026-10-01', 'tool-b', '2.0.0', 33);
+ version.run('2026-10-02', 'tool-a', '1.0.0', 0);
+ const country = db.prepare('INSERT INTO telemetry_country_snapshots (date, country_code, installs) VALUES (?, ?, ?)');
+ country.run('2026-10-01', 'AA', 5);
+ country.run('2026-10-01', 'BB', 18);
+ });
+ assert.deepStrictEqual(underTenCounts(dbFile), [3, 2, 1], 'the fixture holds counts under ten');
+
+ const first = await floorStore(dbFile);
+ assert.equal(first.status, 0, `output:\n${first.stdout}\n${first.stderr}`);
+ assert.deepStrictEqual(underTenCounts(dbFile), [0, 0, 0], 'per tool, per version and fleet: no count from 0 to 9 is left');
+ readOnly(dbFile, (db) => {
+ assert.deepStrictEqual(db.prepare('SELECT date, total_installs, wau, mau, engaged_mau FROM telemetry_snapshots ORDER BY date').all(), [
+ { date: '2026-10-01', total_installs: null, wau: null, mau: 120, engaged_mau: null },
+ { date: '2026-10-02', total_installs: null, wau: 15, mau: 130, engaged_mau: 40 },
+ ]);
+ assert.deepStrictEqual(db.prepare('SELECT date, tool, total_installs, wau, mau, engaged_mau FROM telemetry_tool_snapshots ORDER BY date, tool').all(), [
+ { date: '2026-10-01', tool: 'tool-a', total_installs: null, wau: null, mau: null, engaged_mau: null },
+ { date: '2026-10-01', tool: 'tool-b', total_installs: null, wau: 25, mau: 60, engaged_mau: 12 },
+ { date: '2026-10-02', tool: 'tool-a', total_installs: null, wau: 10, mau: 11, engaged_mau: null },
+ ]);
+ assert.deepStrictEqual(db.prepare('SELECT date, tool, version, installs FROM telemetry_version_snapshots ORDER BY date, tool').all(), [
+ { date: '2026-10-01', tool: 'tool-a', version: '1.0.0', installs: null },
+ { date: '2026-10-01', tool: 'tool-b', version: '2.0.0', installs: 33 },
+ { date: '2026-10-02', tool: 'tool-a', version: '1.0.0', installs: null },
+ ]);
+ assert.deepStrictEqual(db.prepare('SELECT country_code, installs FROM telemetry_country_snapshots ORDER BY country_code').all(), [
+ { country_code: 'AA', installs: null },
+ { country_code: 'BB', installs: 18 },
+ ]);
+ for (const [table, cols] of Object.entries(COUNT_COLUMNS)) {
+ for (const c of db.prepare(`PRAGMA table_info(${table})`).all().filter(c => cols.includes(c.name))) {
+ assert.deepStrictEqual([c.notnull, c.dflt_value], [0, null], `${table}.${c.name} is nullable with no default`);
+ }
+ }
+ const indexes = db.prepare("SELECT name FROM sqlite_master WHERE type = 'index' AND name LIKE 'idx_telemetry_%' ORDER BY name").pluck().all();
+ assert.deepStrictEqual(indexes, ['idx_telemetry_country_date', 'idx_telemetry_tool_date', 'idx_telemetry_version_date']);
+ });
+
+ const before = sha256(dbFile);
+ const second = await floorStore(dbFile);
+ assert.equal(second.status, 0, `output:\n${second.stdout}\n${second.stderr}`);
+ assert.equal(sha256(dbFile), before, 'a second run leaves the file byte for byte as it was');
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test('the store step refuses a table it could only rebuild by dropping a column, and leaves the store byte for byte as it was', async () => {
+ const dir = tmp('refuse');
+ try {
+ const dbFile = storeAt(
+ join(dir, 'analytics.db'),
+ NOT_NULL_SCHEMA.replace('collected_at DATETIME DEFAULT CURRENT_TIMESTAMP, UNIQUE(date, tool)', 'note TEXT, collected_at DATETIME DEFAULT CURRENT_TIMESTAMP, UNIQUE(date, tool)'),
+ (db) => {
+ db.prepare('INSERT INTO telemetry_snapshots (date, total_installs, wau, mau, engaged_mau) VALUES (?, ?, ?, ?, ?)').run('2026-10-01', 0, 3, 120, 9);
+ db.prepare('INSERT INTO telemetry_tool_snapshots (date, tool, wau, note) VALUES (?, ?, ?, ?)').run('2026-10-01', 'tool-a', 4, 'kept');
+ }
+ );
+ const before = sha256(dbFile);
+ const run = await floorStore(dbFile);
+ assert.equal(run.status, 1, `output:\n${run.stdout}\n${run.stderr}`);
+ assert.match(run.stderr, /telemetry_tool_snapshots has columns the floored schema does not carry: note/);
+ assert.equal(sha256(dbFile), before, 'no table was rebuilt and no count was changed');
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test('on a copy of the committed store, the store step leaves no count from 0 to 9 per tool, per version or fleet, and keeps every row and every count of 10 or more', async () => {
+ const dir = tmp('committed');
+ try {
+ const dbFile = join(dir, 'analytics.db');
+ copyFileSync(join(ROOT, 'data', 'analytics.db'), dbFile);
+ const shape = (file) => readOnly(file, db => Object.entries(COUNT_COLUMNS).map(([table, cols]) => [
+ table,
+ db.prepare(`SELECT count(*) FROM ${table}`).pluck().get(),
+ ...cols.map(c => db.prepare(`SELECT count(*) FROM ${table} WHERE ${c} >= 10`).pluck().get()),
+ ]));
+ const before = shape(dbFile);
+ const run = await floorStore(dbFile);
+ assert.equal(run.status, 0, `output:\n${run.stdout}\n${run.stderr}`);
+ assert.deepStrictEqual(underTenCounts(dbFile), [0, 0, 0]);
+ assert.deepStrictEqual(shape(dbFile), before, 'row counts and counts of 10 or more are unchanged');
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test('the store step rewrites the summary telemetry block from the floored store and leaves every other key as it was', async () => {
+ const dir = tmp('summary');
+ try {
+ const dbFile = storeAt(join(dir, 'analytics.db'), NOT_NULL_SCHEMA, (db) => {
+ db.prepare('INSERT INTO telemetry_snapshots (date, provenance, total_installs, wau, mau, engaged_mau) VALUES (?, ?, ?, ?, ?, ?)')
+ .run('2026-11-02', 'synthetic', 0, 4, 120, 30);
+ db.prepare('INSERT INTO telemetry_tool_snapshots (date, tool, total_installs, wau, mau, engaged_mau) VALUES (?, ?, ?, ?, ?, ?)')
+ .run('2026-11-02', 'tool-a', 0, 2, 5, 1);
+ });
+ const summaryFile = join(dir, 'summary.json');
+ const summary = {
+ lastUpdated: '2026-11-02T06:10:00.000Z',
+ total: {
+ npm: 1234,
+ telemetry: { asOf: '2026-11-02', totalInstalls: 0, wau: 4, mau: 120, engagedMau: 30, tools: 1, countries: 0, provenance: 'synthetic' },
+ chromeUsers: 50,
+ },
+ series: { downloads: { value: 99 } },
+ };
+ writeFileSync(summaryFile, JSON.stringify(summary, null, 2));
+ const run = await floorStore(dbFile, summaryFile);
+ assert.equal(run.status, 0, `output:\n${run.stdout}\n${run.stderr}`);
+ const out = JSON.parse(readFileSync(summaryFile, 'utf8'));
+ assert.deepStrictEqual(out.total.telemetry, {
+ asOf: '2026-11-02', totalInstalls: null, wau: null, mau: 120, engagedMau: 30,
+ withheld: { below: 10, label: LABEL }, tools: 1, countries: 0, provenance: 'synthetic',
+ });
+ assert.deepStrictEqual({ ...out, total: { ...out.total, telemetry: null } }, { ...summary, total: { ...summary.total, telemetry: null } });
+ assert.deepStrictEqual(Object.keys(out.total), Object.keys(summary.total), 'key order is kept');
+ } finally {
+ rmSync(dir, { recursive: true, force: true });
+ }
+});
+
+test('the summary builder publishes a telemetry count under ten, and a withheld one, as null, never as 0', () => {
+ const { buildSummary } = require(join(ROOT, 'lib', 'summary.js'));
+ const src = new Database(join(ROOT, 'data', 'analytics.db'), { readonly: true });
+ const db = new Database(src.serialize());
+ src.close();
+ const dataDir = tmp('build');
+ try {
+ // A fleet table with nullable counts holding synthetic rows.
+ db.exec('DROP TABLE telemetry_snapshots');
+ db.exec(NULLABLE_SCHEMA.split(';')[0]);
+ db.prepare('INSERT INTO telemetry_snapshots (date, provenance, total_installs, wau, mau, engaged_mau) VALUES (?, ?, ?, ?, ?, ?)')
+ .run('2999-01-02', 'synthetic', null, 3, 120, null);
+ const t = buildSummary(db, { dataDir, env: {} }).total.telemetry;
+ assert.deepStrictEqual([t.asOf, t.totalInstalls, t.wau, t.mau, t.engagedMau], ['2999-01-02', null, null, 120, null]);
+ assert.deepStrictEqual(t.withheld, { below: 10, label: LABEL });
+ } finally {
+ db.close();
+ rmSync(dataDir, { recursive: true, force: true });
+ }
+});
diff --git a/test/telemetry.test.js b/test/telemetry.test.js
index 59ba388d7..fb3e8e7de 100644
--- a/test/telemetry.test.js
+++ b/test/telemetry.test.js
@@ -76,7 +76,7 @@ test('normalizeAdoptionFeed passes a valid feed through', () => {
test('normalizeAdoptionFeed defaults provenance + engagedMau when absent (never fabricated)', () => {
const n = normalizeAdoptionFeed({ totalInstalls: 10, wau: 5, mau: 8 });
assert.equal(n.provenance, '');
- assert.equal(n.engagedMau, 0); // absent → 0, not invented
+ assert.strictEqual(n.engagedMau, null); // absent → withheld (null), never a 0
assert.equal(n.tools.length, 0);
});