dsh-workspace-mover 2.0.3 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import test from 'node:test';
2
2
  import assert from 'node:assert/strict';
3
- import { buildBadgeFiles, buildState, mergeHistory, normalizeClonesResponse, normalizePathsResponse, normalizeReferrersResponse, normalizeViewsResponse, parseHistory } from '../.github/scripts/traffic-badge-core.mjs';
3
+ import { buildBadgeFiles, buildState, buildStructuredDaily, mergeHistory, normalizeClonesResponse, normalizePathsResponse, normalizeReferrersResponse, normalizeViewsResponse, parseHistory } from '../.github/scripts/traffic-badge-core.mjs';
4
4
 
5
5
  const snapshot = {
6
6
  count: 12,
@@ -55,12 +55,26 @@ test('schema migration preserves the old value as a legacy estimate only', () =>
55
55
  assert.equal(state.lastWindow.count, 12);
56
56
  });
57
57
 
58
- test('badge exposes only observed GitHub clones and 14d uniques', () => {
58
+ test('badge exposes cumulative clones and cumulative uniques since the observation start', () => {
59
59
  const state = buildState({}, parseHistory('{"date":"2026-09-08","count":5,"uniques":3}\n{"date":"2026-09-09","count":7,"uniques":4}\n'), normalizeClonesResponse(snapshot), '2026-09-10T00:00:00Z');
60
+ assert.equal(state.cumulativeUniques, 7);
60
61
  const files = buildBadgeFiles(state);
61
62
  const total = JSON.parse(files['wsm-clones-total.json'].content);
62
63
  assert.equal(total.label, 'GitHub clones observed');
63
- assert.match(total.message, /12 since 2026-09-08/);
64
- assert.match(total.message, /7 unique/);
64
+ assert.equal(total.message, '12 since 2026-09-08 · 7 unique');
65
65
  assert.equal(files['wsm-clones-14d.json'], undefined);
66
66
  });
67
+
68
+ test('structured daily backfills JSONL-only early days without clobbering views', () => {
69
+ const existing = [{ date: '2026-09-09', clones: { date: '2026-09-09', count: 7, uniques: 4 }, views: { date: '2026-09-09', count: 2, uniques: 1 } }];
70
+ const historyRows = parseHistory('{"date":"2026-09-07","count":1,"uniques":1}\n{"date":"2026-09-08","count":5,"uniques":3}\n{"date":"2026-09-09","count":99,"uniques":99}\n');
71
+ const cloneDays = [{ date: '2026-09-09', count: 7, uniques: 4 }];
72
+ const viewDays = [{ date: '2026-09-09', count: 2, uniques: 1 }];
73
+ const daily = buildStructuredDaily(existing, historyRows, cloneDays, viewDays);
74
+ assert.deepEqual(daily.map((row) => row.date), ['2026-09-07', '2026-09-08', '2026-09-09']);
75
+ assert.deepEqual(daily[0].clones, { date: '2026-09-07', count: 1, uniques: 1 });
76
+ assert.equal(daily[0].views, undefined, 'JSONL 回填行没有 views 数据');
77
+ // JSONL 与快照冲突时快照优先:09-09 保持 7/4,且 views 不丢
78
+ assert.deepEqual(daily[2].clones, { date: '2026-09-09', count: 7, uniques: 4 });
79
+ assert.deepEqual(daily[2].views, { date: '2026-09-09', count: 2, uniques: 1 });
80
+ });