mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-13 00:25:04 +03:00
Test-quality audit: fix 2 prod bugs, strengthen weak tests, add mutation/fuzz/CI tooling (#5345)
* test(audit): add gremlins/rapid/coverage tooling + AUDIT.md scaffold * test(audit): hygiene sweep (race-clean except logger global; Finding #2) + smell inventory * test(audit): cover untested error/edge branches (TLS proxy+pin, migration tag cleanup=Finding #1) * test(audit): strengthen internal/sub link tests (dedup key, TLS/Reality mapping, clash well-formedness) * test(audit): property (rapid) + fuzz tests for joinHostPort/userinfo/pin/ParseLink * test(audit): tighten frontend subSortIndex rejection assertions + wire coverage * ci(audit): add shuffle gate + non-blocking race job (Finding #2) + fuzz-smoke; document mutation policy * chore(audit): gitignore frontend coverage output * test(audit): exhaustive whole-repo pass — strengthen 5 weak/fake tests (netproxy, CSP, modal per-protocol loops, schema coercions) * docs(contributing): add Testing section (conventions, race/shuffle, fuzz, mutation policy); drop AUDIT.md ledger * fix(logger,migration): guard logBuffer with mutex; execute legacy tag cleanup (tx.Exec); make CI race gate blocking * ci(mutation): add nightly scoped gremlins workflow (informational artifacts) * test(audit): strengthen runtime tests — baseURL scheme/port bounds, isNonEmptySlice, trafficReset * test(audit): strengthen clash tests — reality field mapping + tcp-header validation * test(audit): runtime — egress-proxy + content-type tests; drop redundant bp=='' branch * test(audit): strengthen link parser/helper tests (defaultPort, splitComma, base64, canonicalQuery, tls/reality/transport mapping) * test(audit): strengthen sub/xray/common/netsafe/mtproto/config/middleware tests (kill surviving mutants) * test(audit): raise timeout on protocol-iteration modal tests (heavy re-renders, slow on CI) * fix(logger): GetLogs returns at most c entries (off-by-one fix; addresses PR review) * perf(logger): snapshot logBuffer under lock so GetLogs doesn't block logging; clarify fuzz-seed docs (addresses PR review)
This commit is contained in:
@@ -2,3 +2,4 @@ node_modules/
|
||||
.vite/
|
||||
*.log
|
||||
*.tsbuildinfo
|
||||
coverage/
|
||||
|
||||
Generated
+171
@@ -37,6 +37,7 @@
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@types/swagger-ui-react": "^5.18.0",
|
||||
"@vitejs/plugin-react": "^6.0.2",
|
||||
"@vitest/coverage-v8": "^4.1.8",
|
||||
"eslint": "^10.4.1",
|
||||
"eslint-plugin-react-hooks": "^7.1.1",
|
||||
"globals": "^17.6.0",
|
||||
@@ -456,6 +457,16 @@
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@bcoe/v8-coverage": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-1.0.2.tgz",
|
||||
"integrity": "sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
},
|
||||
"node_modules/@bramus/specificity": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmjs.org/@bramus/specificity/-/specificity-2.4.2.tgz",
|
||||
@@ -3364,6 +3375,37 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/coverage-v8": {
|
||||
"version": "4.1.8",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-4.1.8.tgz",
|
||||
"integrity": "sha512-lt3kovsyHwYe00wq4D1ti0Z974fWj4NLp6siqiyEufUpyFwK9Yhi7rBhac9JL5aA0zoMrJqc4vYPZRUnI7l7nw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@bcoe/v8-coverage": "^1.0.2",
|
||||
"@vitest/utils": "4.1.8",
|
||||
"ast-v8-to-istanbul": "^1.0.0",
|
||||
"istanbul-lib-coverage": "^3.2.2",
|
||||
"istanbul-lib-report": "^3.0.1",
|
||||
"istanbul-reports": "^3.2.0",
|
||||
"magicast": "^0.5.2",
|
||||
"obug": "^2.1.1",
|
||||
"std-env": "^4.0.0-rc.1",
|
||||
"tinyrainbow": "^3.1.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://opencollective.com/vitest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@vitest/browser": "4.1.8",
|
||||
"vitest": "4.1.8"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"@vitest/browser": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/@vitest/expect": {
|
||||
"version": "4.1.8",
|
||||
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-4.1.8.tgz",
|
||||
@@ -3647,6 +3689,25 @@
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/ast-v8-to-istanbul": {
|
||||
"version": "1.0.4",
|
||||
"resolved": "https://registry.npmjs.org/ast-v8-to-istanbul/-/ast-v8-to-istanbul-1.0.4.tgz",
|
||||
"integrity": "sha512-0bC0/4bTSrnwdhU3IsZDwEdojvuPrSg59OYZfKsLRtJZ0u8VBx9DebfqqG8bRdCC0I7vjgxmPi41P0lpkhJHtA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/trace-mapping": "^0.3.31",
|
||||
"estree-walker": "^3.0.3",
|
||||
"js-tokens": "^10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ast-v8-to-istanbul/node_modules/js-tokens": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-10.0.0.tgz",
|
||||
"integrity": "sha512-lM/UBzQmfJRo9ABXbPWemivdCW8V2G8FHaHdypQaIy523snUjog0W71ayWXTjiR+ixeMyVHN2XcpnTd/liPg/Q==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
@@ -4941,6 +5002,16 @@
|
||||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/has-flag": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/has-property-descriptors": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz",
|
||||
@@ -5067,6 +5138,13 @@
|
||||
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/html-escaper": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz",
|
||||
"integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/html-parse-stringify": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/html-parse-stringify/-/html-parse-stringify-3.0.1.tgz",
|
||||
@@ -5320,6 +5398,45 @@
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
"node_modules/istanbul-lib-coverage": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz",
|
||||
"integrity": "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==",
|
||||
"dev": true,
|
||||
"license": "BSD-3-Clause",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/istanbul-lib-report": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz",
|
||||
"integrity": "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==",
|
||||
"dev": true,
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"istanbul-lib-coverage": "^3.0.0",
|
||||
"make-dir": "^4.0.0",
|
||||
"supports-color": "^7.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/istanbul-reports": {
|
||||
"version": "3.2.0",
|
||||
"resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.2.0.tgz",
|
||||
"integrity": "sha512-HGYWWS/ehqTV3xN10i23tkPkpH46MLCIMFNCaaKNavAXTF1RkqxawEPtnjnGZ6XKSInBKkiOA5BKS+aZiY3AvA==",
|
||||
"dev": true,
|
||||
"license": "BSD-3-Clause",
|
||||
"dependencies": {
|
||||
"html-escaper": "^2.0.0",
|
||||
"istanbul-lib-report": "^3.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/js-file-download": {
|
||||
"version": "0.4.12",
|
||||
"resolved": "https://registry.npmjs.org/js-file-download/-/js-file-download-0.4.12.tgz",
|
||||
@@ -5832,6 +5949,47 @@
|
||||
"@jridgewell/sourcemap-codec": "^1.5.5"
|
||||
}
|
||||
},
|
||||
"node_modules/magicast": {
|
||||
"version": "0.5.3",
|
||||
"resolved": "https://registry.npmjs.org/magicast/-/magicast-0.5.3.tgz",
|
||||
"integrity": "sha512-pVKE4UdSQ7DvHzivsCIFx2BJn1mHG6KsyrFcaxFx6tONdneEuThrDx0Cj3AMg58KyN4pzYT+LHOotxDQDjNvkw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@babel/parser": "^7.29.3",
|
||||
"@babel/types": "^7.29.0",
|
||||
"source-map-js": "^1.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/make-dir": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz",
|
||||
"integrity": "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"semver": "^7.5.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/make-dir/node_modules/semver": {
|
||||
"version": "7.8.4",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.8.4.tgz",
|
||||
"integrity": "sha512-rUCObTnP32Q08R2uuIrt7r9PlEonuTmtuXYcW6s5kjdlj3xbnwe+21yXptAUYcMAABLkYYTtnmzb3w3EDZfueA==",
|
||||
"dev": true,
|
||||
"license": "ISC",
|
||||
"bin": {
|
||||
"semver": "bin/semver.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/math-intrinsics": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz",
|
||||
@@ -7033,6 +7191,19 @@
|
||||
"integrity": "sha512-5Z9ZpRzfuH6l/UAvCPAPUo3665Nk2wLaZU3x+TLHKVzIz33+sbJqbtrYoC3KD4/uVOr2Zp+L0LySezP9OHV9yA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/supports-color": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"has-flag": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/swagger-client": {
|
||||
"version": "3.37.4",
|
||||
"resolved": "https://registry.npmjs.org/swagger-client/-/swagger-client-3.37.4.tgz",
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@types/swagger-ui-react": "^5.18.0",
|
||||
"@vitejs/plugin-react": "^6.0.2",
|
||||
"@vitest/coverage-v8": "^4.1.8",
|
||||
"eslint": "^10.4.1",
|
||||
"eslint-plugin-react-hooks": "^7.1.1",
|
||||
"globals": "^17.6.0",
|
||||
@@ -73,4 +74,4 @@
|
||||
"core-js-pure": false,
|
||||
"tree-sitter-json": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`InboundFormModal > field structure is stable for every protocol > http 1`] = `
|
||||
[
|
||||
"Enabled",
|
||||
"Remark",
|
||||
"Protocol",
|
||||
"Address",
|
||||
"Share address strategy",
|
||||
"Subscription sort order",
|
||||
"Port",
|
||||
"Total Flow",
|
||||
"Traffic Reset",
|
||||
"Duration",
|
||||
"Enabled",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`InboundFormModal > field structure is stable for every protocol > hysteria 1`] = `
|
||||
[
|
||||
"Enabled",
|
||||
"Remark",
|
||||
"Protocol",
|
||||
"Address",
|
||||
"Share address strategy",
|
||||
"Subscription sort order",
|
||||
"Port",
|
||||
"Total Flow",
|
||||
"Traffic Reset",
|
||||
"Duration",
|
||||
"Enabled",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`InboundFormModal > field structure is stable for every protocol > mixed 1`] = `
|
||||
[
|
||||
"Enabled",
|
||||
"Remark",
|
||||
"Protocol",
|
||||
"Address",
|
||||
"Share address strategy",
|
||||
"Subscription sort order",
|
||||
"Port",
|
||||
"Total Flow",
|
||||
"Traffic Reset",
|
||||
"Duration",
|
||||
"Enabled",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`InboundFormModal > field structure is stable for every protocol > shadowsocks 1`] = `
|
||||
[
|
||||
"Enabled",
|
||||
"Remark",
|
||||
"Protocol",
|
||||
"Address",
|
||||
"Share address strategy",
|
||||
"Subscription sort order",
|
||||
"Port",
|
||||
"Total Flow",
|
||||
"Traffic Reset",
|
||||
"Duration",
|
||||
"Enabled",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`InboundFormModal > field structure is stable for every protocol > trojan 1`] = `
|
||||
[
|
||||
"Enabled",
|
||||
"Remark",
|
||||
"Protocol",
|
||||
"Address",
|
||||
"Share address strategy",
|
||||
"Subscription sort order",
|
||||
"Port",
|
||||
"Total Flow",
|
||||
"Traffic Reset",
|
||||
"Duration",
|
||||
"Enabled",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`InboundFormModal > field structure is stable for every protocol > tun 1`] = `
|
||||
[
|
||||
"Enabled",
|
||||
"Remark",
|
||||
"Protocol",
|
||||
"Address",
|
||||
"Share address strategy",
|
||||
"Subscription sort order",
|
||||
"Port",
|
||||
"Total Flow",
|
||||
"Traffic Reset",
|
||||
"Duration",
|
||||
"Enabled",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`InboundFormModal > field structure is stable for every protocol > tunnel 1`] = `
|
||||
[
|
||||
"Enabled",
|
||||
"Remark",
|
||||
"Protocol",
|
||||
"Address",
|
||||
"Share address strategy",
|
||||
"Subscription sort order",
|
||||
"Port",
|
||||
"Total Flow",
|
||||
"Traffic Reset",
|
||||
"Duration",
|
||||
"Enabled",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`InboundFormModal > field structure is stable for every protocol > vless 1`] = `
|
||||
[
|
||||
"Enabled",
|
||||
"Remark",
|
||||
"Protocol",
|
||||
"Address",
|
||||
"Share address strategy",
|
||||
"Subscription sort order",
|
||||
"Port",
|
||||
"Total Flow",
|
||||
"Traffic Reset",
|
||||
"Duration",
|
||||
"Enabled",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`InboundFormModal > field structure is stable for every protocol > vmess 1`] = `
|
||||
[
|
||||
"Enabled",
|
||||
"Remark",
|
||||
"Protocol",
|
||||
"Address",
|
||||
"Share address strategy",
|
||||
"Subscription sort order",
|
||||
"Port",
|
||||
"Total Flow",
|
||||
"Traffic Reset",
|
||||
"Duration",
|
||||
"Enabled",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`InboundFormModal > field structure is stable for every protocol > wireguard 1`] = `
|
||||
[
|
||||
"Enabled",
|
||||
"Remark",
|
||||
"Protocol",
|
||||
"Address",
|
||||
"Share address strategy",
|
||||
"Subscription sort order",
|
||||
"Port",
|
||||
"Total Flow",
|
||||
"Traffic Reset",
|
||||
"Duration",
|
||||
"Enabled",
|
||||
]
|
||||
`;
|
||||
@@ -1,141 +0,0 @@
|
||||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
||||
|
||||
exports[`OutboundFormModal > field structure is stable for every protocol > blackhole 1`] = `
|
||||
[
|
||||
"Protocol",
|
||||
"Tag",
|
||||
"Send Through",
|
||||
"Address",
|
||||
"Port",
|
||||
"ID",
|
||||
"Encryption",
|
||||
"Reverse tag",
|
||||
"Mux",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`OutboundFormModal > field structure is stable for every protocol > dns 1`] = `
|
||||
[
|
||||
"Protocol",
|
||||
"Tag",
|
||||
"Send Through",
|
||||
"Address",
|
||||
"Port",
|
||||
"ID",
|
||||
"Encryption",
|
||||
"Reverse tag",
|
||||
"Mux",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`OutboundFormModal > field structure is stable for every protocol > freedom 1`] = `
|
||||
[
|
||||
"Protocol",
|
||||
"Tag",
|
||||
"Send Through",
|
||||
"Address",
|
||||
"Port",
|
||||
"ID",
|
||||
"Encryption",
|
||||
"Reverse tag",
|
||||
"Mux",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`OutboundFormModal > field structure is stable for every protocol > hysteria 1`] = `
|
||||
[
|
||||
"Protocol",
|
||||
"Tag",
|
||||
"Send Through",
|
||||
"Address",
|
||||
"Port",
|
||||
"ID",
|
||||
"Encryption",
|
||||
"Reverse tag",
|
||||
"Mux",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`OutboundFormModal > field structure is stable for every protocol > shadowsocks 1`] = `
|
||||
[
|
||||
"Protocol",
|
||||
"Tag",
|
||||
"Send Through",
|
||||
"Address",
|
||||
"Port",
|
||||
"ID",
|
||||
"Encryption",
|
||||
"Reverse tag",
|
||||
"Mux",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`OutboundFormModal > field structure is stable for every protocol > socks 1`] = `
|
||||
[
|
||||
"Protocol",
|
||||
"Tag",
|
||||
"Send Through",
|
||||
"Address",
|
||||
"Port",
|
||||
"ID",
|
||||
"Encryption",
|
||||
"Reverse tag",
|
||||
"Mux",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`OutboundFormModal > field structure is stable for every protocol > trojan 1`] = `
|
||||
[
|
||||
"Protocol",
|
||||
"Tag",
|
||||
"Send Through",
|
||||
"Address",
|
||||
"Port",
|
||||
"ID",
|
||||
"Encryption",
|
||||
"Reverse tag",
|
||||
"Mux",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`OutboundFormModal > field structure is stable for every protocol > vless 1`] = `
|
||||
[
|
||||
"Protocol",
|
||||
"Tag",
|
||||
"Send Through",
|
||||
"Address",
|
||||
"Port",
|
||||
"ID",
|
||||
"Encryption",
|
||||
"Reverse tag",
|
||||
"Mux",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`OutboundFormModal > field structure is stable for every protocol > vmess 1`] = `
|
||||
[
|
||||
"Protocol",
|
||||
"Tag",
|
||||
"Send Through",
|
||||
"Address",
|
||||
"Port",
|
||||
"ID",
|
||||
"Encryption",
|
||||
"Reverse tag",
|
||||
"Mux",
|
||||
]
|
||||
`;
|
||||
|
||||
exports[`OutboundFormModal > field structure is stable for every protocol > wireguard 1`] = `
|
||||
[
|
||||
"Protocol",
|
||||
"Tag",
|
||||
"Send Through",
|
||||
"Address",
|
||||
"Port",
|
||||
"ID",
|
||||
"Encryption",
|
||||
"Reverse tag",
|
||||
"Mux",
|
||||
]
|
||||
`;
|
||||
@@ -289,8 +289,18 @@ describe('subSortIndex', () => {
|
||||
});
|
||||
|
||||
it('InboundDbFieldsSchema enforces an integer minimum of 1 and defaults to 1', () => {
|
||||
expect(InboundDbFieldsSchema.partial().safeParse({ subSortIndex: 1.5 }).success).toBe(false);
|
||||
expect(InboundDbFieldsSchema.partial().safeParse({ subSortIndex: 0 }).success).toBe(false);
|
||||
// Reject for the RIGHT reason: the issue must be about subSortIndex, not some
|
||||
// unrelated field — otherwise a schema that rejects everything would pass.
|
||||
const nonInt = InboundDbFieldsSchema.partial().safeParse({ subSortIndex: 1.5 });
|
||||
expect(nonInt.success).toBe(false);
|
||||
if (!nonInt.success) expect(nonInt.error.issues[0]?.path).toContain('subSortIndex');
|
||||
|
||||
const belowMin = InboundDbFieldsSchema.partial().safeParse({ subSortIndex: 0 });
|
||||
expect(belowMin.success).toBe(false);
|
||||
if (!belowMin.success) expect(belowMin.error.issues[0]?.path).toContain('subSortIndex');
|
||||
|
||||
// A valid integer >= 1 must pass (guards against a mutant rejecting all values).
|
||||
expect(InboundDbFieldsSchema.partial().safeParse({ subSortIndex: 5 }).success).toBe(true);
|
||||
expect(InboundDbFieldsSchema.parse({}).subSortIndex).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { screen } from '@testing-library/react';
|
||||
import { screen, act } from '@testing-library/react';
|
||||
|
||||
import InboundFormModal from '@/pages/inbounds/form/InboundFormModal';
|
||||
import { DBInbound } from '@/models/dbinbound';
|
||||
@@ -31,15 +31,30 @@ describe('InboundFormModal', () => {
|
||||
expect(fieldLabels().length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('field structure is stable for every protocol', () => {
|
||||
it('field structure differs per protocol (not a vacuous snapshot loop)', async () => {
|
||||
renderModal();
|
||||
const protocols = listSelectOptions('protocol');
|
||||
expect(protocols.length).toBeGreaterThan(3);
|
||||
|
||||
const labelsByProto: Record<string, string[]> = {};
|
||||
for (const proto of protocols) {
|
||||
chooseSelectOption('protocol', proto);
|
||||
expect(fieldLabels()).toMatchSnapshot(proto);
|
||||
// Flush antd Form.useWatch('protocol') before reading — without it every iteration
|
||||
// sees the same pre-update DOM and the loop asserts nothing (the original bug here).
|
||||
await act(async () => { await new Promise((r) => setTimeout(r, 0)); });
|
||||
labelsByProto[proto] = fieldLabels();
|
||||
}
|
||||
});
|
||||
|
||||
// The loop must actually exercise protocol-specific rendering: distinct protocols
|
||||
// must yield distinct field sets (a vacuous loop makes them all identical).
|
||||
const distinctShapes = new Set(Object.values(labelsByProto).map((l) => l.join('|')));
|
||||
expect(distinctShapes.size).toBeGreaterThan(1);
|
||||
|
||||
// Spot-check a protocol-distinguishing field that must appear after the switch.
|
||||
if (labelsByProto.shadowsocks) {
|
||||
expect(labelsByProto.shadowsocks).toContain('Encryption method');
|
||||
}
|
||||
}, 30000); // iterates every protocol, re-rendering a heavy modal each time — slow on CI runners
|
||||
|
||||
it('preserves custom share address strategy when editing a local inbound', async () => {
|
||||
renderWithProviders(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { act } from '@testing-library/react';
|
||||
|
||||
import OutboundFormModal from '@/pages/xray/outbounds/OutboundFormModal';
|
||||
import {
|
||||
@@ -27,13 +28,30 @@ describe('OutboundFormModal', () => {
|
||||
expect(fieldLabels().length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('field structure is stable for every protocol', () => {
|
||||
it('field structure differs per protocol (not a vacuous snapshot loop)', async () => {
|
||||
renderModal(null);
|
||||
const protocols = listSelectOptions('protocol');
|
||||
expect(protocols.length).toBeGreaterThan(3);
|
||||
|
||||
const labelsByProto: Record<string, string[]> = {};
|
||||
for (const proto of protocols) {
|
||||
chooseSelectOption('protocol', proto);
|
||||
expect(fieldLabels()).toMatchSnapshot(proto);
|
||||
// Flush antd Form.useWatch('protocol') so protocol-specific fields render before
|
||||
// reading; otherwise every iteration sees the same default (vless) DOM.
|
||||
await act(async () => { await new Promise((r) => setTimeout(r, 0)); });
|
||||
labelsByProto[proto] = fieldLabels();
|
||||
}
|
||||
});
|
||||
|
||||
// Distinct protocols must yield distinct field sets (a vacuous loop is all-identical).
|
||||
const distinctShapes = new Set(Object.values(labelsByProto).map((l) => l.join('|')));
|
||||
expect(distinctShapes.size).toBeGreaterThan(1);
|
||||
|
||||
// vless carries an Encryption field; wireguard does not — proves real protocol switching.
|
||||
if (labelsByProto.vless) {
|
||||
expect(labelsByProto.vless).toContain('Encryption');
|
||||
}
|
||||
if (labelsByProto.wireguard) {
|
||||
expect(labelsByProto.wireguard).not.toContain('Encryption');
|
||||
}
|
||||
}, 30000); // iterates every protocol, re-rendering a heavy modal each time — slow on CI runners
|
||||
});
|
||||
|
||||
@@ -27,3 +27,35 @@ describe('InboundSettingsSchema fixtures', () => {
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// The fixture tests above pin coerced values only via regenerable snapshots. These
|
||||
// assert the load-bearing transforms directly, so a broken coercion fails independently
|
||||
// of the snapshot baseline.
|
||||
describe('InboundSettingsSchema coercions', () => {
|
||||
it('vmess: defaults alterId to 0 and coerces a string tgId to a number', () => {
|
||||
const parsed = InboundSettingsSchema.parse({
|
||||
protocol: 'vmess',
|
||||
settings: { clients: [{ id: 'u1', email: 'a@b.c', tgId: '12345' }] },
|
||||
});
|
||||
if (parsed.protocol !== 'vmess') throw new Error('discriminator narrowed to the wrong protocol');
|
||||
const client = parsed.settings.clients[0];
|
||||
expect(client.alterId).toBe(0); // .default(0) injected for omitted field
|
||||
expect(client.tgId).toBe(12345); // string -> number transform
|
||||
});
|
||||
|
||||
it('vmess: a non-numeric tgId coerces to 0', () => {
|
||||
const parsed = InboundSettingsSchema.parse({
|
||||
protocol: 'vmess',
|
||||
settings: { clients: [{ id: 'u1', email: 'a@b.c', tgId: 'not-a-number' }] },
|
||||
});
|
||||
if (parsed.protocol !== 'vmess') throw new Error('wrong protocol');
|
||||
expect(parsed.settings.clients[0].tgId).toBe(0); // Number(v) || 0
|
||||
});
|
||||
|
||||
it('vless: defaults decryption and encryption to "none"', () => {
|
||||
const parsed = InboundSettingsSchema.parse({ protocol: 'vless', settings: { clients: [] } });
|
||||
if (parsed.protocol !== 'vless') throw new Error('wrong protocol');
|
||||
expect(parsed.settings.decryption).toBe('none');
|
||||
expect(parsed.settings.encryption).toBe('none');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user