fix(win32): winsock was never started on the --mcp path, so Windows could not resolve anything
WSAStartup() sat in the CGI branch of main() (and separately in the --daemon branch), after the argument loop. `plugin_ntfy.exe --mcp` therefore returned from main's dispatch with a cold winsock, and every getaddrinfo() failed: ntfy_send came back "cannot resolve ntfy.sh:443" on a real Windows box while --meta looked completely healthy. That is the single most-used face of this plugin -- the tool an agent calls -- and it was the one face no cross-platform smoke had ever RUN, because --meta is not a socket. Moved the startup to the top of main() before dispatch and added a source-level guard to tests/run.sh that pins WSAStartup's line before the mode dispatch, so the regression cannot come back quietly. The three checks are static (the PE cannot be executed here) and say so. 185 passed / 0 failed from a clean tree (make clean && make).
AuthorPico <picobot@scorpioplayer.com>
Date2026-11-14 06:41:14
Commit928b3785
Parents9e740e5e
Changed files
plugin.json+1−1■■
src/plugin_ntfy.c+11−1■■■■■
tests/run.sh+20−1■■■■■
3 files+32−3
Diff
plugin.json+1−1■■
index e397699..60cbdb8 100644
--- a/plugin.json
+++ b/plugin.json
@@ -6,7 +6,7 @@
66 "title": "ntfy Push & Pub/Sub Channel Connector",
77 "summary": "Zero-dependency ntfy connector with two faces: an MCP tool (ntfy_send) so the agent can push alerts and report summaries to your phone, and a supervised channel daemon that subscribes to a topic's NDJSON stream, holds every unknown sender in a default-deny pairing queue, forwards only approved senders' messages to a SCORPIOX BOT session through POST /inbox, and publishes the agent's newest reply back to the publish topic. Setup, pairing approval and a live daemon log live behind node authentication; TLS verification is fail-closed against a bundled root store with an SPKI pin option for self-hosted relays.",
88 "category": "network",
9- "version": "1.0.2",
9+ "version": "1.0.3",
1010 "license": "MIT",
1111 "kind": "hybrid",
1212 "mcp": true,
src/plugin_ntfy.c+11−1■■■■■
index e312a11..16e6bfc 100644
--- a/src/plugin_ntfy.c
+++ b/src/plugin_ntfy.c
@@ -100,7 +100,7 @@
100100
101101 #define PLUGIN_SLUG "ntfy"
102102 #define PLUGIN_ID "plugin_ntfy"
103-#define PLUGIN_VER "1.0.2"
103+#define PLUGIN_VER "1.0.3"
104104 #define SELF_SOURCE_ID "scorpiox-bot-plugin-ntfy"
105105
106106 /* The tag every notification THIS plugin publishes carries. A second,
@@ -1942,6 +1942,16 @@ int main(int argc, char **argv)
19421942 int embed;
19431943 int i;
19441944
1945+#if defined(_WIN32)
1946+ /* Winsock has to be up before ANY mode touches the resolver. It used to
1947+ * be started only on the CGI path (and separately for --daemon), so
1948+ * `plugin_ntfy.exe --mcp` ran with a cold winsock: getaddrinfo() failed
1949+ * straight away and every ntfy_send came back "cannot resolve
1950+ * ntfy.sh:443". Verified on a real Windows box -- the MCP face is the
1951+ * face an agent actually uses. */
1952+ { WSADATA wsa; WSAStartup(MAKEWORD(2, 2), &wsa); }
1953+#endif
1954+
19451955 for (i = 1; i < argc; i++) {
19461956 if (!strcmp(argv[i], "--meta") || !strcmp(argv[i], "-m"))
19471957 return mode_meta();
tests/run.sh+20−1■■■■■
index c7e47a7..adc8813 100755
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -592,9 +592,28 @@ fi
592592 if [ -f plugin_ntfy.exe ]; then
593593 MAGIC=$(head -c 2 plugin_ntfy.exe)
594594 if [ "$MAGIC" = "MZ" ]; then pass "the windows artifact has a PE header"; else fail "plugin_ntfy.exe is not a PE"; fi
595+fi
596+
597+# ---------------------------------------------------------------- win32 guards
598+section "windows guards (static)"
599+# Neither of these can be RUN offline, and both have already shipped broken
600+# once, so the source itself carries the assertion.
601+SRC=$(cat src/plugin_ntfy.c)
602+# WSAStartup must sit in main(), before the mode dispatch -- not inside the
603+# CGI branch. It used to live only there, so plugin_ntfy.exe --mcp ran with a
604+# cold winsock and every ntfy_send died at "cannot resolve ntfy.sh:443" on a
605+# real Windows box while --meta looked fine.
606+WSA_MAIN=$(awk '/^int main\(/{f=1} f && /WSAStartup/{print NR; exit}' src/plugin_ntfy.c)
607+DISPATCH=$(awk '/^int main\(/{f=1} f && /mode_mcp\(\)/{print NR; exit}' src/plugin_ntfy.c)
608+if [ -n "$WSA_MAIN" ] && [ -n "$DISPATCH" ] && [ "$WSA_MAIN" -lt "$DISPATCH" ]; then
609+ pass "winsock starts in main() before any mode dispatch"
595610 else
596- printf ' (plugin_ntfy.exe not built here - covered by the dist publish)\n'
611+ fail "winsock must be started in main() before the mode dispatch"
597612 fi
613+check "the --mcp face is dispatched from main, not only the env" 'if (!strcmp(argv[i], "--mcp"))' "$SRC"
614+# stdout must be binary on Windows: text mode turns our \n into \r\n and
615+# double-terminates the CGI headers.
616+check "_setmode(_fileno(stdout), _O_BINARY) on the windows path" '_O_BINARY' "$SRC"
598617
599618 # ---------------------------------------------------------------- secrets
600619 section "git history secret audit"
601620
plugin.json+1−1■■
index e397699..60cbdb8 100644index e397699..60cbdb8 100644
--- a/plugin.json--- a/plugin.json
+++ b/plugin.json+++ b/plugin.json
@@ -6,7 +6,7 @@@@ -6,7 +6,7 @@
6 "title": "ntfy Push & Pub/Sub Channel Connector",6 "title": "ntfy Push & Pub/Sub Channel Connector",
7 "summary": "Zero-dependency ntfy connector with two faces: an MCP tool (ntfy_send) so the agent can push alerts and report summaries to your phone, and a supervised channel daemon that subscribes to a topic's NDJSON stream, holds every unknown sender in a default-deny pairing queue, forwards only approved senders' messages to a SCORPIOX BOT session through POST /inbox, and publishes the agent's newest reply back to the publish topic. Setup, pairing approval and a live daemon log live behind node authentication; TLS verification is fail-closed against a bundled root store with an SPKI pin option for self-hosted relays.",7 "summary": "Zero-dependency ntfy connector with two faces: an MCP tool (ntfy_send) so the agent can push alerts and report summaries to your phone, and a supervised channel daemon that subscribes to a topic's NDJSON stream, holds every unknown sender in a default-deny pairing queue, forwards only approved senders' messages to a SCORPIOX BOT session through POST /inbox, and publishes the agent's newest reply back to the publish topic. Setup, pairing approval and a live daemon log live behind node authentication; TLS verification is fail-closed against a bundled root store with an SPKI pin option for self-hosted relays.",
8 "category": "network",8 "category": "network",
9- "version": "1.0.2",9+ "version": "1.0.3",
10 "license": "MIT",10 "license": "MIT",
11 "kind": "hybrid",11 "kind": "hybrid",
12 "mcp": true,12 "mcp": true,
src/plugin_ntfy.c+11−1■■■■■
index e312a11..16e6bfc 100644index e312a11..16e6bfc 100644
--- a/src/plugin_ntfy.c--- a/src/plugin_ntfy.c
+++ b/src/plugin_ntfy.c+++ b/src/plugin_ntfy.c
@@ -100,7 +100,7 @@@@ -100,7 +100,7 @@
100 100
101 #define PLUGIN_SLUG "ntfy"101 #define PLUGIN_SLUG "ntfy"
102 #define PLUGIN_ID "plugin_ntfy"102 #define PLUGIN_ID "plugin_ntfy"
103-#define PLUGIN_VER "1.0.2"103+#define PLUGIN_VER "1.0.3"
104 #define SELF_SOURCE_ID "scorpiox-bot-plugin-ntfy"104 #define SELF_SOURCE_ID "scorpiox-bot-plugin-ntfy"
105 105
106 /* The tag every notification THIS plugin publishes carries. A second,106 /* The tag every notification THIS plugin publishes carries. A second,
@@ -1942,6 +1942,16 @@ int main(int argc, char **argv)@@ -1942,6 +1942,16 @@ int main(int argc, char **argv)
1942 int embed;1942 int embed;
1943 int i;1943 int i;
1944 1944
1945+#if defined(_WIN32)
1946+ /* Winsock has to be up before ANY mode touches the resolver. It used to
1947+ * be started only on the CGI path (and separately for --daemon), so
1948+ * `plugin_ntfy.exe --mcp` ran with a cold winsock: getaddrinfo() failed
1949+ * straight away and every ntfy_send came back "cannot resolve
1950+ * ntfy.sh:443". Verified on a real Windows box -- the MCP face is the
1951+ * face an agent actually uses. */
1952+ { WSADATA wsa; WSAStartup(MAKEWORD(2, 2), &wsa); }
1953+#endif
1954+
1945 for (i = 1; i < argc; i++) {1955 for (i = 1; i < argc; i++) {
1946 if (!strcmp(argv[i], "--meta") || !strcmp(argv[i], "-m"))1956 if (!strcmp(argv[i], "--meta") || !strcmp(argv[i], "-m"))
1947 return mode_meta();1957 return mode_meta();
tests/run.sh+20−1■■■■■
index c7e47a7..adc8813 100755index c7e47a7..adc8813 100755
--- a/tests/run.sh--- a/tests/run.sh
+++ b/tests/run.sh+++ b/tests/run.sh
@@ -592,9 +592,28 @@ fi@@ -592,9 +592,28 @@ fi
592 if [ -f plugin_ntfy.exe ]; then592 if [ -f plugin_ntfy.exe ]; then
593 MAGIC=$(head -c 2 plugin_ntfy.exe)593 MAGIC=$(head -c 2 plugin_ntfy.exe)
594 if [ "$MAGIC" = "MZ" ]; then pass "the windows artifact has a PE header"; else fail "plugin_ntfy.exe is not a PE"; fi594 if [ "$MAGIC" = "MZ" ]; then pass "the windows artifact has a PE header"; else fail "plugin_ntfy.exe is not a PE"; fi
595+fi
596+
597+# ---------------------------------------------------------------- win32 guards
598+section "windows guards (static)"
599+# Neither of these can be RUN offline, and both have already shipped broken
600+# once, so the source itself carries the assertion.
601+SRC=$(cat src/plugin_ntfy.c)
602+# WSAStartup must sit in main(), before the mode dispatch -- not inside the
603+# CGI branch. It used to live only there, so plugin_ntfy.exe --mcp ran with a
604+# cold winsock and every ntfy_send died at "cannot resolve ntfy.sh:443" on a
605+# real Windows box while --meta looked fine.
606+WSA_MAIN=$(awk '/^int main\(/{f=1} f && /WSAStartup/{print NR; exit}' src/plugin_ntfy.c)
607+DISPATCH=$(awk '/^int main\(/{f=1} f && /mode_mcp\(\)/{print NR; exit}' src/plugin_ntfy.c)
608+if [ -n "$WSA_MAIN" ] && [ -n "$DISPATCH" ] && [ "$WSA_MAIN" -lt "$DISPATCH" ]; then
609+ pass "winsock starts in main() before any mode dispatch"
595 else610 else
596- printf ' (plugin_ntfy.exe not built here - covered by the dist publish)\n'611+ fail "winsock must be started in main() before the mode dispatch"
597 fi612 fi
613+check "the --mcp face is dispatched from main, not only the env" 'if (!strcmp(argv[i], "--mcp"))' "$SRC"
614+# stdout must be binary on Windows: text mode turns our \n into \r\n and
615+# double-terminates the CGI headers.
616+check "_setmode(_fileno(stdout), _O_BINARY) on the windows path" '_O_BINARY' "$SRC"
598 617
599 # ---------------------------------------------------------------- secrets618 # ---------------------------------------------------------------- secrets
600 section "git history secret audit"619 section "git history secret audit"
601620