From 2066d9aa17f32f73a7e3deb94d024236d79190e3 Mon Sep 17 00:00:00 2001 From: eleith Date: Wed, 25 Nov 2026 08:29:44 -0800 Subject: [PATCH] fix(seeder): skip links with visit caps --- scripts/seed-visits-data.js | 7 +++---- scripts/seed-visits.js | 1 + scripts/seed-visits.test.js | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/scripts/seed-visits-data.js b/scripts/seed-visits-data.js index 574667d..2085c0b 100644 --- a/scripts/seed-visits-data.js +++ b/scripts/seed-visits-data.js @@ -91,10 +91,9 @@ function requestPaths(links) { { path: '/', weight: 10 }, { path: missingPath, weight: 10 } ]; - // Prefer configured links, with a separate share for base and unmatched requests. - const configured = Object.keys(links); - const popularity = configured.reduce((total, _path, index) => total + 1 / (index + 1), 0); - for (const [index, path] of configured.entries()) { + const uncappedPaths = Object.keys(links).filter((path) => links[path].max_visits === undefined); + const popularity = uncappedPaths.reduce((total, _path, index) => total + 1 / (index + 1), 0); + for (const [index, path] of uncappedPaths.entries()) { const weight = 80 / ((index + 1) * popularity); paths.push({ path, weight }); } diff --git a/scripts/seed-visits.js b/scripts/seed-visits.js index c8ade90..f2f49b2 100644 --- a/scripts/seed-visits.js +++ b/scripts/seed-visits.js @@ -98,6 +98,7 @@ function printPlan(plan, apply) { `UTC window: ${new Date(plan.since).toISOString()} to ${new Date(plan.asOf).toISOString()} (exclusive)` ); console.log(`Sampling seed: ${plan.seed} (timestamps are relative to this run)`); + console.log('Links with max_visits are skipped to preserve their click allowance.'); for (const domain of Object.keys(plan.domains)) console.log(` ${domain}: ${plan.visitsPerDomain} visits`); console.log(`Total: ${plan.total} visits. Reruns append; existing data is not replaced.`); diff --git a/scripts/seed-visits.test.js b/scripts/seed-visits.test.js index 4e52a0d..ecafdfc 100644 --- a/scripts/seed-visits.test.js +++ b/scripts/seed-visits.test.js @@ -167,15 +167,26 @@ test('reports the field when the worker database path conflicts with the default } }); -test('preview leaves existing visits untouched; apply appends visits for every domain', async () => { +test('preview leaves visits untouched; apply seeds every domain without spending click caps', async () => { const directory = await mkdtemp(join(tmpdir(), 'goto-seed-apply-')); try { const { configPath, databasePath } = await deployment(directory); + const cappedOnlyDomain = 'one.example.test'; + const mixedDomain = 'two.example.test'; + const docsPath = '/docs'; + const source = structuredClone(fixture); + source.domains[cappedOnlyDomain].links[docsPath].max_visits = 1; + source.domains[mixedDomain].links['/limited'] = { + url: 'https://example.com/limited', + max_visits: 1 + }; + await writeFile(configPath, JSON.stringify(source)); const existing = await createDatabaseWithExistingVisit(databasePath); const args = ['--config', configPath, '--visits-per-domain', '100', '--seed', '17']; const preview = run(...args); assert.equal(preview.status, 0, preview.stderr); assert.match(preview.stdout, /Dry run/); + assert.match(preview.stdout, /Links with max_visits are skipped/); assert.deepEqual(await readVisits(databasePath), [existing]); const result = run(...args, '--apply'); @@ -188,9 +199,12 @@ test('preview leaves existing visits untouched; apply appends visits for every d existing ); const synthetic = rows.filter((row) => row.user_agent?.endsWith(' GotoSeed/17')); - for (const domain of Object.keys(fixture.domains)) { + for (const domain of Object.keys(source.domains)) { assert.equal(synthetic.filter((row) => row.domain === domain).length, 100); } + assert(!synthetic.some((row) => row.domain === cappedOnlyDomain && row.path === docsPath)); + assert(!synthetic.some((row) => row.domain === mixedDomain && row.path === '/limited')); + assert(synthetic.some((row) => row.domain === mixedDomain && row.path === docsPath)); } finally { await rm(directory, { recursive: true, force: true }); } -- 2.54.1