11import test from "node:test" ;
22import assert from "node:assert/strict" ;
3+ import fs from "node:fs" ;
4+ import os from "node:os" ;
5+ import path from "node:path" ;
36import { createServer } from "node:http" ;
7+ import { pathToFileURL } from "node:url" ;
48import {
59 parseArgs ,
610 normalizeBrokerUrl ,
@@ -9,6 +13,7 @@ import {
913 registerWithBroker ,
1014 upsertEnvContent ,
1115 runRegistration ,
16+ isMainModule ,
1217} from "./broker-register.mjs" ;
1318
1419const FIXTURE_SERVER_KEYS = {
@@ -53,6 +58,24 @@ test("parseArgs sets verbose=true for -v and --verbose", () => {
5358 assert . equal ( long . verbose , true ) ;
5459} ) ;
5560
61+ test ( "isMainModule handles symlink argv path" , ( ) => {
62+ const tempDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , "broker-register-main-" ) ) ;
63+ const realFile = path . join ( tempDir , "real.mjs" ) ;
64+ const symlinkFile = path . join ( tempDir , "link.mjs" ) ;
65+
66+ try {
67+ fs . writeFileSync ( realFile , "export default 1;\n" , "utf8" ) ;
68+ fs . symlinkSync ( realFile , symlinkFile ) ;
69+
70+ const moduleUrl = pathToFileURL ( fs . realpathSync ( realFile ) ) . href ;
71+ assert . equal ( isMainModule ( moduleUrl , symlinkFile ) , true ) ;
72+ } finally {
73+ try { fs . unlinkSync ( symlinkFile ) ; } catch { }
74+ try { fs . unlinkSync ( realFile ) ; } catch { }
75+ try { fs . rmdirSync ( tempDir ) ; } catch { }
76+ }
77+ } ) ;
78+
5679test ( "parseArgs accepts registration token" , ( ) => {
5780 const parsed = parseArgs ( [ "--registration-token" , "token-123" ] ) ;
5881 assert . equal ( parsed . registrationToken , "token-123" ) ;
0 commit comments