Skip to content

Commit 2f9bb53

Browse files
committed
fix(host-targets): classify CYGWIN and MINGW as windows, not linux
Cygwin (CYGWIN_NT-*) and Git Bash (MINGW64_NT-*) run on Windows and need Windows binaries. The previous linux classification caused webi.sh to serve Linux ELF binaries (e.g. gh_linux_amd64.tar.gz) which cannot run on Windows hosts. Also add 'gnu' and 'libc' libc fallbacks to the Windows WATERFALL so that Cygwin/MINGW hosts (which report 'gnu' or 'libc' as their libc) can reach msvc-tagged and static Windows packages. Adds host-targets-test.js with explicit os/arch/vendor assertions for all known Cygwin and MINGW user-agent patterns, including the Windows 11 build from issue #1083. Bumps to v1.0.4.
1 parent 9f87804 commit 2f9bb53

4 files changed

Lines changed: 137 additions & 4 deletions

File tree

host-targets-test.js

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
'use strict';
2+
3+
let HostTargets = require('./host-targets.js');
4+
5+
function parseUa(ua) {
6+
let terms = [];
7+
let parts = ua.split(/\s+/g);
8+
for (let part of parts) {
9+
let _terms = part.split(/\//g);
10+
terms = terms.concat(_terms);
11+
}
12+
let target = {};
13+
HostTargets.termsToTarget(target, terms);
14+
return target;
15+
}
16+
17+
function assertField(ua, target, field, expected) {
18+
let actual = target[field];
19+
if (actual !== expected) {
20+
throw new Error(
21+
`[${field}] expected '${expected}' but got '${actual}' for UA:\n ${ua}`,
22+
);
23+
}
24+
}
25+
26+
function testCase(ua, expected) {
27+
let target = parseUa(ua);
28+
for (let [field, value] of Object.entries(expected)) {
29+
assertField(ua, target, field, value);
30+
}
31+
}
32+
33+
async function main() {
34+
// Cygwin on 32-bit Windows (reports 'gnu')
35+
testCase('webi/curl+wget i686/unknown CYGWIN_NT-10.0-WOW/3.3.5(0.341/5/3) gnu', {
36+
os: 'windows',
37+
arch: 'x86',
38+
vendor: 'pc',
39+
});
40+
41+
// Cygwin on 32-bit Windows, legacy curl-only UA
42+
testCase('curl CYGWIN_NT-10.0-WOW/3.3.5(0.341/5/3) i686/unknown gnu', {
43+
os: 'windows',
44+
arch: 'x86',
45+
vendor: 'pc',
46+
});
47+
48+
// Cygwin on 64-bit Windows (reports 'libc'), "Cygwin" prefix variant
49+
testCase('webi/curl x86_64/unknown Cygwin/CYGWIN_NT-10.0/3.3.4(0.341/5/3) libc', {
50+
os: 'windows',
51+
arch: 'x86_64',
52+
vendor: 'pc',
53+
});
54+
55+
// Cygwin on 64-bit Windows 10 (build 19045)
56+
testCase('webi/curl+wget x86_64/unknown Cygwin/CYGWIN_NT-10.0-19045/3.4.10-1.x86_64 libc', {
57+
os: 'windows',
58+
arch: 'x86_64',
59+
vendor: 'pc',
60+
});
61+
62+
// Cygwin on 64-bit Windows 11 (build 26200) — from issue #1083
63+
testCase('webi/curl+wget x86_64/unknown Cygwin/CYGWIN_NT-10.0-26200/3.4.10-1.x86_64 libc', {
64+
os: 'windows',
65+
arch: 'x86_64',
66+
vendor: 'pc',
67+
});
68+
69+
// Cygwin UA with GNU/Linux prefix (webi.sh quirk on some Cygwin installs)
70+
testCase('webi/curl+wget i686/unknown GNU/Linux/CYGWIN_NT-10.0-WOW/3.3.5(0.341/5/3) libc', {
71+
os: 'windows',
72+
arch: 'x86',
73+
vendor: 'pc',
74+
});
75+
76+
// MINGW (Git Bash) on 64-bit Windows, webi UA
77+
testCase('webi/curl x86_64/unknown MINGW64_NT-10.0-19045/3.3.6-341.x86_64 libc', {
78+
os: 'windows',
79+
arch: 'x86_64',
80+
vendor: 'pc',
81+
});
82+
83+
// MINGW (Git Bash), legacy curl-only UA
84+
testCase('curl MINGW64_NT-10.0-19045/3.3.6-341.x86_64 x86_64/unknown libc', {
85+
os: 'windows',
86+
arch: 'x86_64',
87+
vendor: 'pc',
88+
});
89+
90+
// MINGW with Linux prefix in UA path (older Git Bash format)
91+
testCase('curl Linux/MINGW64_NT-10.0-19045/3.3.6-341.x86_64 x86_64/unknown libc', {
92+
os: 'windows',
93+
arch: 'x86_64',
94+
vendor: 'pc',
95+
});
96+
97+
// MINGW with Msys prefix (Msys2 variant)
98+
testCase('webi/curl x86_64/unknown Msys/MINGW64_NT-10.0-19045/3.3.6-341.x86_64 libc', {
99+
os: 'windows',
100+
arch: 'x86_64',
101+
vendor: 'pc',
102+
});
103+
104+
// Sanity: real Linux should NOT be classified as Windows
105+
testCase('webi/curl+wget x86_64/unknown Linux/6.2.0-1012-aws gnu', {
106+
os: 'linux',
107+
arch: 'x86_64',
108+
vendor: 'unknown',
109+
});
110+
111+
// Sanity: Darwin should NOT be classified as Windows
112+
testCase('webi/curl arm64/unknown Darwin/22.6.0', {
113+
os: 'darwin',
114+
arch: 'aarch64',
115+
vendor: 'apple',
116+
});
117+
}
118+
119+
main()
120+
.then(function () {
121+
console.error('');
122+
console.error('PASS');
123+
process.exit(0);
124+
})
125+
.catch(function (e) {
126+
console.error(e.stack);
127+
process.exit(1);
128+
});

host-targets.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ HostTargets.WATERFALL = {
2626
windows: Object.assign(
2727
{
2828
aarch64: ['aarch64', 'x86_64'],
29+
// Cygwin/MINGW report 'gnu' or 'libc'; prefer msvc packages first,
30+
// then static ('none'), then the reported libc
31+
gnu: ['msvc', 'none', 'gnu'],
32+
libc: ['msvc', 'none', 'libc'],
2933
},
3034
X86_64,
3135
),
@@ -78,8 +82,8 @@ HostTargets.TERMS = {
7882
// OS
7983
Android: T.ANDROID,
8084
Linux: T.LINUX,
81-
MINGW: T.LINUX,
82-
CYGWIN: T.LINUX,
85+
MINGW: T.WINDOWS,
86+
CYGWIN: T.WINDOWS,
8387
Darwin: T.DARWIN,
8488
Windows: T.WINDOWS,
8589
win32: { os: 'windows', vendor: 'unknown' },

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "build-classifier",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Determine Host Target Triplet (Arch, Libc, OS, Vendor) from a filenames / download URL and uname / User-Agent strings.",
55
"main": "index.js",
66
"scripts": {
77
"bump": "npm version -m \"chore(release): bump to v%s\"",
88
"fmt": "npm run prettier",
99
"lint": "npm run jshint",
10-
"test": "node lexver-test.js",
10+
"test": "node lexver-test.js && node host-targets-test.js",
1111
"----": "------------------------------------",
1212
"jshint": "npx -p jshint@2.x -- jshint -c ./.jshintrc --exclude 'node_modules/**/*' *.js",
1313
"prettier": "npx -p prettier@3.x -- prettier -w '**/*.{js,md,html}'"

uas.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,6 +2046,7 @@
20462046
"curl Linux/5.15.131-1-pve x86_64/unknown gnu": 2,
20472047
"webi/curl+wget x86_64/unknown GNU/Linux/5.10.0-8-amd64 libc": 1,
20482048
"webi/curl+wget x86_64/unknown Cygwin/CYGWIN_NT-10.0-19045/3.4.10-1.x86_64 libc": 2,
2049+
"webi/curl+wget x86_64/unknown Cygwin/CYGWIN_NT-10.0-26200/3.4.10-1.x86_64 libc": 1,
20492050
"webi/curl+wget x86_64/unknown GNU/Linux/3.10.0-1160.83.1.el7.x86_64 libc": 1,
20502051
"webi/curl+wget x86_64/unknown GNU/Linux/5.4.250-2.1.ve1.x86_64 libc": 1,
20512052
"curl Linux/5.4.250-2.1.ve1.x86_64 x86_64/unknown gnu": 1,

0 commit comments

Comments
 (0)