Skip to content

Commit 322eeba

Browse files
committed
fix
1 parent 0079ca3 commit 322eeba

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

collector/scripts/notify-reset-watchers.mjs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import fs from 'node:fs';
44
import path from 'node:path';
55
import process from 'node:process';
6-
import { pathToFileURL } from 'node:url';
6+
import { fileURLToPath } from 'node:url';
77
import { DatabaseSync } from 'node:sqlite';
88

99
import {
@@ -744,7 +744,5 @@ async function main() {
744744
}
745745
}
746746

747-
const entryPoint = process.argv[1]
748-
? pathToFileURL(path.resolve(process.argv[1])).href
749-
: null;
750-
if (entryPoint === import.meta.url) await main();
747+
const entryPoint = process.argv[1] ? fs.realpathSync(process.argv[1]) : null;
748+
if (entryPoint === fileURLToPath(import.meta.url)) await main();

collector/test/notify-reset-watchers.test.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import assert from 'node:assert/strict';
22
import fs from 'node:fs';
33
import os from 'node:os';
44
import path from 'node:path';
5+
import { spawnSync } from 'node:child_process';
56
import { DatabaseSync } from 'node:sqlite';
67
import test from 'node:test';
8+
import { fileURLToPath } from 'node:url';
79

810
import {
911
legacyAudienceStats,
@@ -216,3 +218,19 @@ test('reset announcement arguments are safe by default and accept a bounded cana
216218
);
217219
assert.throws(() => parseArgs(['--database', '/backup.sqlite', '--limit', '0']));
218220
});
221+
222+
test('reset announcement CLI runs when invoked through the production-style current symlink', (t) => {
223+
const directory = fs.mkdtempSync(path.join(os.tmpdir(), 'slashmon-reset-cli-test-'));
224+
const current = path.join(directory, 'current');
225+
const script = fileURLToPath(new URL('../scripts/notify-reset-watchers.mjs', import.meta.url));
226+
t.after(() => fs.rmSync(directory, { recursive: true, force: true }));
227+
fs.symlinkSync(script, current);
228+
229+
const result = spawnSync(process.execPath, [current, '--help'], {
230+
encoding: 'utf8',
231+
});
232+
233+
assert.equal(result.status, 0, result.stderr);
234+
assert.match(result.stdout, /^Usage:/);
235+
assert.match(result.stdout, /--database PATH/);
236+
});

0 commit comments

Comments
 (0)