bradsansnow commited on
Commit
08db0a7
·
1 Parent(s): fdb15c0

fix: handle symlinked notify-blocked cli entry

Browse files
.claude/skills/sync-nowai-leaderboard/notify-blocked.mjs CHANGED
@@ -1,12 +1,24 @@
1
  #!/usr/bin/env node
2
 
 
 
3
  import { postTeams } from './lib/teams.mjs';
4
  import {
5
  buildBlockedNotification,
6
  parseBlockedCliArgs,
7
  } from './lib/blocked-notify.mjs';
8
 
9
- const isMain = import.meta.url === `file://${process.argv[1]}`;
 
 
 
 
 
 
 
 
 
 
10
 
11
  if (isMain) {
12
  try {
 
1
  #!/usr/bin/env node
2
 
3
+ import { realpathSync } from 'node:fs';
4
+ import { fileURLToPath } from 'node:url';
5
  import { postTeams } from './lib/teams.mjs';
6
  import {
7
  buildBlockedNotification,
8
  parseBlockedCliArgs,
9
  } from './lib/blocked-notify.mjs';
10
 
11
+ function isMainModule() {
12
+ if (!process.argv[1]) return false;
13
+
14
+ try {
15
+ return realpathSync(fileURLToPath(import.meta.url)) === realpathSync(process.argv[1]);
16
+ } catch {
17
+ return false;
18
+ }
19
+ }
20
+
21
+ const isMain = isMainModule();
22
 
23
  if (isMain) {
24
  try {
.claude/skills/sync-nowai-leaderboard/test/notify-blocked-cli.test.mjs CHANGED
@@ -1,6 +1,9 @@
1
  import { test } from 'node:test';
2
  import assert from 'node:assert/strict';
3
  import { spawnSync } from 'node:child_process';
 
 
 
4
  import { fileURLToPath } from 'node:url';
5
 
6
  const ENTRY = fileURLToPath(new URL('../notify-blocked.mjs', import.meta.url));
@@ -20,3 +23,23 @@ test('notify-blocked CLI exits 1 when no Teams webhook is configured', () => {
20
  assert.match(result.stdout, /\[teams\] not posted\./);
21
  assert.equal(result.stderr, '');
22
  });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import { test } from 'node:test';
2
  import assert from 'node:assert/strict';
3
  import { spawnSync } from 'node:child_process';
4
+ import { mkdtempSync, symlinkSync } from 'node:fs';
5
+ import { tmpdir } from 'node:os';
6
+ import { join } from 'node:path';
7
  import { fileURLToPath } from 'node:url';
8
 
9
  const ENTRY = fileURLToPath(new URL('../notify-blocked.mjs', import.meta.url));
 
23
  assert.match(result.stdout, /\[teams\] not posted\./);
24
  assert.equal(result.stderr, '');
25
  });
26
+
27
+ test('notify-blocked CLI still runs through a symlink path with a space', () => {
28
+ const linkDir = mkdtempSync(join(tmpdir(), 'notify blocked cli '));
29
+ const linkPath = join(linkDir, 'notify-blocked link.mjs');
30
+ symlinkSync(ENTRY, linkPath);
31
+
32
+ const result = spawnSync(
33
+ process.execPath,
34
+ [linkPath, '--reason', 'wrong-branch', '--fact', 'Branch=feature/demo'],
35
+ {
36
+ env: { ...process.env, TEAMS_WEBHOOK_URL: '' },
37
+ encoding: 'utf8',
38
+ },
39
+ );
40
+
41
+ assert.equal(result.status, 1);
42
+ assert.match(result.stdout, /no TEAMS_WEBHOOK_URL set; skipping card/);
43
+ assert.match(result.stdout, /\[teams\] not posted\./);
44
+ assert.equal(result.stderr, '');
45
+ });