* chore(frontend,docs): move to TypeScript 7 and replace ESLint with oxlint
TypeScript 7 is the native Go port and ships no programmatic compiler
API, so typescript-eslint cannot run at all: it peer-pins
typescript >=4.8.4 <6.1.0 (canary too) and hard-crashes with
"typescript-eslint does not support TS 7.0". Upstream support is
tracked in typescript-eslint#10940 and targets TS >=7.1.
Rather than wait, or carry Microsoft's side-by-side alias (which keeps
a second TS 6 install alive purely to feed the linter), both projects
move to oxlint, which never depended on the TypeScript API.
Typecheck drops from ~9.7s to ~2.2s and 167 packages leave frontend/.
oxlint has no no-restricted-syntax, so the #6121/#6127 cleared-
InputNumber guard is reimplemented as a JS plugin in
frontend/tools/oxlint/. It was verified to still fire in
pages/settings/** and pages/xray/** and to stay exempt in *Modal.tsx.
The type-aware @deprecated sweep survives too, as
`npm run lint:deprecated`: oxlint's type-aware mode runs on
oxlint-tsgolint, which drives the TS 7 typescript-go checker, so the
TS 7 move is what makes it possible.
Behaviour is preserved rather than tightened. jsx-a11y/prefer-tag-over-role
is off in both configs because it was never part of the recommended sets
ESLint actually ran, and oxlint honours the existing eslint-disable
comments, so no source churn was needed.
Two real fixes fell out of the stricter linting:
- outbound-link-parser.test.ts used `out?.streamSettings` behind an `as`
cast, which hid the optional chain from ESLint and would throw on a
null parse; the rest of the file already used `out!`.
- InputAddon's conditional role/tabIndex/onKeyDown is genuinely
accessible but oxlint cannot evaluate it, so it gets a scoped disable.
* chore(docs): replace Prettier with oxfmt
oxfmt is the oxc project's Prettier-compatible formatter, so this pairs
with the oxlint move and drops the last JS-based tool from the docs
toolchain.
The swap is behaviour-preserving. Running Prettier and oxfmt over the
same files, with the existing .prettierrc.json settings migrated via
`oxfmt --migrate=prettier`, produces byte-identical output on every
file. (Comparing them outside the project directory is misleading:
Prettier silently falls back to its defaults when it cannot find its
config, which looks like a mismatch but is not one.)
The 18 files reformatted here were already failing `pnpm format:check`
before this change — Prettier wanted the exact same edits. The check is
not part of docs-ci.yml, which is why the drift went unnoticed.
.prettierignore becomes ignorePatterns in .oxfmtrc.json, keeping the
deliberate MDX exclusion: reflowing MDX prose merges headings into
paragraphs and collapses lists inside Steps/Callout components. Both
that and the generated fumadocs-openapi reference output were verified
untouched.
oxfmt is pinned to 0.63.0 rather than latest. pnpm 11's built-in
minimumReleaseAge policy rejects same-day releases, and 0.64.0 would
have made pnpm silently append 20 waiver lines to pnpm-workspace.yaml.
* style(frontend): adopt oxfmt and format src
frontend/ has never had a formatter, so this reformats 344 of 497 files
in src/. The change is purely whitespace, quoting and line wrapping —
no logic is touched. It is kept in its own commit so it does not bury
the TypeScript 7 / oxlint migration or the git blame for the code
itself.
Settings match docs/ and the code as it was already written: single
quotes, semicolons, trailing commas, 2-space indent, 100 columns. That
was measured rather than assumed — src/ was already uniformly
single-quoted and 2-space indented, with p90 line length at 75.
Formatting is scoped to src/ (mirroring `oxlint src`) and
.oxfmtrc.json ignores src/generated. Both matter: `make gen-check`
compares src/generated and public/openapi.json, and
`make msw-worker-check` byte-compares public/mockServiceWorker.js
against the installed MSW runtime, so reformatting any of them breaks
the gate.
Reflowing also moves `eslint-disable-next-line` comments off the line
they guard, which broke two suppressions that had been silently
correct before:
- clone-inbound-modal.test.tsx: the object literal became multi-line,
leaving `} as any;` four lines below its no-explicit-any disable.
- ClientsPage.tsx: the useMemo dependency array moved onto its own
line, out from under its exhaustive-deps disable.
Both comments were relocated onto the line they actually guard, and
verified to still suppress by removing them and watching the errors
return.
* ci: enforce formatting in CI and make verify
Adding oxfmt in the previous two commits gave both projects a formatter
but nothing that checks it, which is how docs/ had already drifted to 18
unformatted files: docs-ci.yml runs typecheck, lint, test and build, but
never format:check, so Prettier's complaints were only ever visible to
whoever ran it by hand.
Wire `format:check` into the frontend job in ci.yml and the docs job in
docs-ci.yml, and add a `format-check` target to `make verify` so the
local gate keeps mirroring CI as the Makefile header promises.
Verified the step actually bites rather than passing vacuously: adding
a badly formatted line to a source file in each project makes both
`make format-check` and `pnpm format:check` fail, and reverting it makes
them pass again.
No workflow referenced ESLint or Prettier by name — they all invoke the
package scripts — so the tooling swap needed no other CI changes.
* ci: trigger CI on Makefile changes
The path filters listed **.go, go.mod, go.sum, frontend/**, .nvmrc and
ci.yml itself, but not the Makefile — so a change to the canonical task
runner that ci.yml is meant to mirror could land without any job
running. The previous commit, which edits both, only triggers because
it happens to touch ci.yml too.
* fix(frontend): replace deprecated Ant Design 6 APIs in the geo components
`npm run lint:deprecated` reported five uses of props Ant Design 6 has
deprecated. All five are gone, and the matching runtime warnings no
longer appear in the test output.
Tag `bordered={false}` becomes `variant="filled"` and Space `direction`
becomes `orientation`; both are the one-to-one replacements named in
antd's own deprecation messages, and `direction`/`orientation` share the
same Orientation type.
Input `addonAfter` is the one that is not a rename. It becomes a
`Space.Compact block` wrapping the Input and the browse Button, which is
antd's documented migration. `block` keeps the field filling its form
row as the addon did. Note this is a deliberate visual change: the
button used to be a borderless `type="text"` icon sitting inside the
addon's grey box, and is now a regular button whose border joins the
input. The tooltip, aria-label, ref, id and onBlur wiring are unchanged,
so the react-hook-form binding in RuleFormModal and the existing tests
still address it the same way.
Only these five were deprecated. The other `bordered` props in the tree
sit on QRCode, Table, Descriptions and Alert, where the prop is not
deprecated, and these were the only two Space `direction` uses in the
codebase.
* fix(frontend): restore lint rules lost in the oxlint migration, and test the guard
Addresses the review on #6262.
The frontend config re-enabled only no-explicit-any and no-unused-vars
and left the rest of tseslint's recommended set to oxlint's correctness
category. It does not cover all of it. Confirmed by linting one probe
file against both configs: docs/ (which enumerates the rules) reports
all nine, frontend/ reported four. So ban-ts-comment,
no-empty-object-type, no-namespace, no-require-imports and
no-unsafe-function-type had silently stopped being enforced — a `//
@ts-ignore` or a `namespace` block would have landed unflagged. The ten
rules are now mirrored from docs/.oxlintrc.json, and src/ still passes.
The #6121/#6127 guard was 57 lines of hand-written AST walking with no
test. It now has one: fixtures for the three banned shapes plus an
onNumber()-wrapped control, asserting the rule fires three times and
that .oxlintrc.json still wires it to the right paths. Verified it fails
for the right reason by making walk() enumerate nothing, which is the
silent-death mode the review described — the traversal depends on
Object.keys() seeing AST children as own enumerable properties.
The fixtures deliberately violate the rule, so their oxlint config is
named guard.oxlintrc.json rather than .oxlintrc.json: oxlint discovers
nested configs by directory, which would otherwise turn the fixtures
into three lint errors. The test passes it explicitly with -c.
Also from the review:
- lint and format now cover tools/ as well as src/, so the one piece of
hand-written lint logic in the repo is no longer the least covered
file in it.
- lint-staged runs oxfmt before oxlint --fix. Formatting became a hard
CI gate in this PR while the hook only ran the linter, so a commit
could pass the hook and fail CI on formatting alone.
- .oxfmtrc.json ignores public/, so the artefacts that make gen-check
and make msw-worker-check byte-compare stay safe even if oxfmt is
invoked without a path argument.
- The MDX and generated-reference rationales that .prettierignore
carried are back as comments in docs/.oxfmtrc.json — oxlint and oxfmt
both accept JSONC, so relocating them was unnecessary.
Not applied: the review also suggested restoring ../internal/web/dist to
the ignore lists. Both tools reject `..` patterns outright ("patterns
are resolved within the config file's directory"), and being outside
frontend/ it is unreachable anyway.
726 lines
23 KiB
TypeScript
726 lines
23 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
|
|
import { formValuesToWirePayload, rawOutboundToFormValues } from '@/lib/xray/outbound-form-adapter';
|
|
|
|
// Round-trip parity: wire → form → wire should preserve the legacy
|
|
// Outbound.fromJson(...).toJson() output shape for each protocol's quirks.
|
|
// Spot-checking the cases the modal exercised in v0.x — vmess vnext flatten,
|
|
// vless reverse-wrap, wireguard address csv ↔ array, freedom finalRules
|
|
// emission, blackhole type wrap, dns rule normalization, mux gating.
|
|
|
|
describe('outbound-form-adapter: round-trip', () => {
|
|
it('vmess flattens vnext to address/port/id/security and re-nests', () => {
|
|
const wire = {
|
|
protocol: 'vmess',
|
|
tag: 'outbound-vmess',
|
|
settings: {
|
|
vnext: [
|
|
{
|
|
address: '1.2.3.4',
|
|
port: 443,
|
|
users: [{ id: '11111111-2222-4333-8444-555555555555', security: 'auto' }],
|
|
},
|
|
],
|
|
},
|
|
};
|
|
const form = rawOutboundToFormValues(wire);
|
|
expect(form.protocol).toBe('vmess');
|
|
if (form.protocol === 'vmess') {
|
|
expect(form.settings.address).toBe('1.2.3.4');
|
|
expect(form.settings.port).toBe(443);
|
|
expect(form.settings.id).toBe('11111111-2222-4333-8444-555555555555');
|
|
expect(form.settings.security).toBe('auto');
|
|
}
|
|
const back = formValuesToWirePayload(form);
|
|
expect(back).toMatchObject({
|
|
protocol: 'vmess',
|
|
tag: 'outbound-vmess',
|
|
settings: {
|
|
vnext: [
|
|
{
|
|
address: '1.2.3.4',
|
|
port: 443,
|
|
users: [{ id: '11111111-2222-4333-8444-555555555555', security: 'auto' }],
|
|
},
|
|
],
|
|
},
|
|
});
|
|
});
|
|
|
|
it('vless preserves flat shape and emits reverse only when reverseTag is set', () => {
|
|
const wire = {
|
|
protocol: 'vless',
|
|
tag: 'out-vless',
|
|
settings: {
|
|
address: 'srv.example',
|
|
port: 8443,
|
|
id: '11111111-2222-4333-8444-555555555555',
|
|
flow: 'xtls-rprx-vision',
|
|
encryption: 'none',
|
|
},
|
|
};
|
|
const form = rawOutboundToFormValues(wire);
|
|
expect(form.protocol).toBe('vless');
|
|
if (form.protocol === 'vless') {
|
|
expect(form.settings.reverseTag).toBe('');
|
|
}
|
|
const back = formValuesToWirePayload(form);
|
|
expect(back.settings).not.toHaveProperty('reverse');
|
|
expect(back.settings).toMatchObject({
|
|
address: 'srv.example',
|
|
port: 8443,
|
|
id: '11111111-2222-4333-8444-555555555555',
|
|
flow: 'xtls-rprx-vision',
|
|
encryption: 'none',
|
|
});
|
|
});
|
|
|
|
it('vless preserves a non-none encryption value (post-quantum)', () => {
|
|
const enc = 'mlkem768x25519plus.native.0rtt.G3cdPSd1-NnlpTbWNSM5vHsT5VNzWfFzYSKwbUMnV1Y';
|
|
const wire = {
|
|
protocol: 'vless',
|
|
settings: {
|
|
address: 'srv',
|
|
port: 443,
|
|
id: '11111111-2222-4333-8444-555555555555',
|
|
flow: '',
|
|
encryption: enc,
|
|
},
|
|
};
|
|
const form = rawOutboundToFormValues(wire);
|
|
if (form.protocol === 'vless') {
|
|
expect(form.settings.encryption).toBe(enc);
|
|
}
|
|
expect((formValuesToWirePayload(form).settings as Record<string, unknown>).encryption).toBe(
|
|
enc,
|
|
);
|
|
});
|
|
|
|
it('vless emits reverse + sniffing when reverseTag is set', () => {
|
|
const wire = {
|
|
protocol: 'vless',
|
|
settings: {
|
|
address: 'srv',
|
|
port: 8443,
|
|
id: '11111111-2222-4333-8444-555555555555',
|
|
flow: '',
|
|
encryption: 'none',
|
|
reverse: { tag: 'rev-1', sniffing: { enabled: true, destOverride: ['tls'] } },
|
|
},
|
|
};
|
|
const form = rawOutboundToFormValues(wire);
|
|
if (form.protocol === 'vless') {
|
|
expect(form.settings.reverseTag).toBe('rev-1');
|
|
expect(form.settings.reverseSniffing.enabled).toBe(true);
|
|
expect(form.settings.reverseSniffing.destOverride).toEqual(['tls']);
|
|
}
|
|
const back = formValuesToWirePayload(form);
|
|
const settings = back.settings as Record<string, unknown>;
|
|
expect(settings.reverse).toMatchObject({ tag: 'rev-1' });
|
|
});
|
|
|
|
it('vless does not emit testpre/testseed unless flow is vision', () => {
|
|
const wire = {
|
|
protocol: 'vless',
|
|
settings: {
|
|
address: 'srv',
|
|
port: 443,
|
|
id: '11111111-2222-4333-8444-555555555555',
|
|
flow: '',
|
|
encryption: 'none',
|
|
testpre: 5,
|
|
testseed: [1, 2, 3, 4],
|
|
},
|
|
};
|
|
const back = formValuesToWirePayload(rawOutboundToFormValues(wire));
|
|
expect(back.settings).not.toHaveProperty('testpre');
|
|
expect(back.settings).not.toHaveProperty('testseed');
|
|
});
|
|
|
|
it('trojan flattens servers[0] and re-nests', () => {
|
|
const wire = {
|
|
protocol: 'trojan',
|
|
settings: { servers: [{ address: 's', port: 443, password: 'pw' }] },
|
|
};
|
|
const form = rawOutboundToFormValues(wire);
|
|
if (form.protocol === 'trojan') {
|
|
expect(form.settings).toEqual({ address: 's', port: 443, password: 'pw' });
|
|
}
|
|
expect(formValuesToWirePayload(form).settings).toEqual({
|
|
servers: [{ address: 's', port: 443, password: 'pw' }],
|
|
});
|
|
});
|
|
|
|
it('shadowsocks preserves uot + UoTVersion', () => {
|
|
const wire = {
|
|
protocol: 'shadowsocks',
|
|
settings: {
|
|
servers: [
|
|
{
|
|
address: 's',
|
|
port: 443,
|
|
password: 'pw',
|
|
method: '2022-blake3-aes-128-gcm',
|
|
uot: true,
|
|
UoTVersion: 2,
|
|
},
|
|
],
|
|
},
|
|
};
|
|
const back = formValuesToWirePayload(rawOutboundToFormValues(wire));
|
|
expect(back.settings).toMatchObject({
|
|
servers: [{ uot: true, UoTVersion: 2 }],
|
|
});
|
|
});
|
|
|
|
it('socks emits users:[] when user is empty, users:[{...}] when set', () => {
|
|
const noUser = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'socks',
|
|
settings: { servers: [{ address: 's', port: 1080 }] },
|
|
}),
|
|
);
|
|
expect(noUser.settings).toMatchObject({ servers: [{ users: [] }] });
|
|
|
|
const withUser = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'socks',
|
|
settings: { servers: [{ address: 's', port: 1080, users: [{ user: 'u', pass: 'p' }] }] },
|
|
}),
|
|
);
|
|
expect(withUser.settings).toMatchObject({
|
|
servers: [{ users: [{ user: 'u', pass: 'p' }] }],
|
|
});
|
|
});
|
|
|
|
it('http preserves top-level settings.headers across wire → form → wire (#5519)', () => {
|
|
const headers = { 'X-T5-Auth': '683556433', Host: '153.3.236.22:443' };
|
|
const form = rawOutboundToFormValues({
|
|
protocol: 'http',
|
|
tag: 'h',
|
|
settings: { servers: [{ address: 'a', port: 443, users: [] }], headers },
|
|
});
|
|
expect(form.protocol).toBe('http');
|
|
if (form.protocol === 'http') {
|
|
expect(form.settings.headers).toEqual(headers);
|
|
}
|
|
const back = formValuesToWirePayload(form);
|
|
expect(back.settings).toMatchObject({ headers });
|
|
});
|
|
|
|
it('http omits headers when empty', () => {
|
|
const back = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'http',
|
|
settings: { servers: [{ address: 'a', port: 8080, users: [] }] },
|
|
}),
|
|
);
|
|
expect(back.settings).not.toHaveProperty('headers');
|
|
});
|
|
|
|
it('wireguard csv-joins address and reserved on read, splits on write', () => {
|
|
const wire = {
|
|
protocol: 'wireguard',
|
|
settings: {
|
|
mtu: 1420,
|
|
secretKey: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=',
|
|
address: ['10.0.0.1', 'fd00::1'],
|
|
peers: [
|
|
{ publicKey: 'pk', allowedIPs: ['0.0.0.0/0'], endpoint: 'e:51820', preSharedKey: 'psk' },
|
|
],
|
|
reserved: [1, 2, 3],
|
|
noKernelTun: false,
|
|
},
|
|
};
|
|
const form = rawOutboundToFormValues(wire);
|
|
if (form.protocol === 'wireguard') {
|
|
expect(form.settings.address).toBe('10.0.0.1,fd00::1');
|
|
expect(form.settings.reserved).toBe('1,2,3');
|
|
expect(form.settings.peers[0].psk).toBe('psk');
|
|
}
|
|
const back = formValuesToWirePayload(form);
|
|
expect(back.settings).toMatchObject({
|
|
address: ['10.0.0.1', 'fd00::1'],
|
|
reserved: [1, 2, 3],
|
|
peers: [{ preSharedKey: 'psk' }],
|
|
});
|
|
});
|
|
|
|
it('blackhole wraps type into {response:{type}} and omits when empty', () => {
|
|
const empty = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'blackhole',
|
|
settings: {},
|
|
}),
|
|
);
|
|
expect(empty.settings).toEqual({ response: undefined });
|
|
|
|
const withType = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'blackhole',
|
|
settings: { response: { type: 'http' } },
|
|
}),
|
|
);
|
|
expect(withType.settings).toEqual({ response: { type: 'http' } });
|
|
});
|
|
|
|
it('dns rules normalize qType numeric strings, split domains, carry rCode', () => {
|
|
const wire = {
|
|
protocol: 'dns',
|
|
settings: {
|
|
rewriteNetwork: 'udp',
|
|
rewriteAddress: '1.1.1.1',
|
|
rewritePort: 53,
|
|
rules: [
|
|
{ action: 'direct', qType: 'A,AAAA', domain: ['example.com', 'ext.org'] },
|
|
{ action: 'return', qType: 28, domain: 'blocked.com', rCode: 3 },
|
|
],
|
|
},
|
|
};
|
|
const back = formValuesToWirePayload(rawOutboundToFormValues(wire));
|
|
const settings = back.settings as Record<string, unknown>;
|
|
const rules = settings.rules as Array<Record<string, unknown>>;
|
|
expect(rules[0]).toEqual({
|
|
action: 'direct',
|
|
qType: 'A,AAAA',
|
|
domain: ['example.com', 'ext.org'],
|
|
});
|
|
expect(rules[1]).toEqual({ action: 'return', qType: 28, domain: ['blocked.com'], rCode: 3 });
|
|
});
|
|
|
|
it('dns rules read the legacy qtype wire key for back-compat', () => {
|
|
const wire = {
|
|
protocol: 'dns',
|
|
settings: { rules: [{ action: 'direct', qtype: 'TXT' }] },
|
|
};
|
|
const back = formValuesToWirePayload(rawOutboundToFormValues(wire));
|
|
const rules = (back.settings as Record<string, unknown>).rules as Array<
|
|
Record<string, unknown>
|
|
>;
|
|
expect(rules[0]).toEqual({ action: 'direct', qType: 'TXT' });
|
|
});
|
|
|
|
it('freedom emits domainStrategy/redirect/fragment conditionally', () => {
|
|
const empty = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'freedom',
|
|
settings: {},
|
|
}),
|
|
);
|
|
expect(empty.settings).toEqual({
|
|
domainStrategy: undefined,
|
|
redirect: undefined,
|
|
fragment: undefined,
|
|
noises: undefined,
|
|
finalRules: undefined,
|
|
});
|
|
|
|
const filled = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'freedom',
|
|
settings: {
|
|
domainStrategy: 'UseIPv4',
|
|
redirect: '1.1.1.1',
|
|
userLevel: 3,
|
|
proxyProtocol: 2,
|
|
fragment: { packets: 'tlshello', length: '100-200' },
|
|
noises: [{ type: 'rand', packet: '10-20', delay: '10-16', applyTo: 'ipv4' }],
|
|
},
|
|
}),
|
|
);
|
|
expect(filled.settings).toMatchObject({
|
|
domainStrategy: 'UseIPv4',
|
|
redirect: '1.1.1.1',
|
|
userLevel: 3,
|
|
proxyProtocol: 2,
|
|
fragment: { packets: 'tlshello', length: '100-200' },
|
|
noises: [{ type: 'rand', packet: '10-20', delay: '10-16', applyTo: 'ipv4' }],
|
|
});
|
|
});
|
|
|
|
it('freedom tolerates settings without a fragment object (issue #4686)', () => {
|
|
const values = {
|
|
protocol: 'freedom',
|
|
tag: 'direct',
|
|
settings: {
|
|
domainStrategy: '',
|
|
redirect: '',
|
|
proxyProtocol: 0,
|
|
noises: [],
|
|
finalRules: [
|
|
{ action: 'block', network: '', port: '', ip: ['geoip:private'], blockDelay: '' },
|
|
],
|
|
},
|
|
} as unknown as Parameters<typeof formValuesToWirePayload>[0];
|
|
|
|
expect(() => formValuesToWirePayload(values)).not.toThrow();
|
|
const back = formValuesToWirePayload(values);
|
|
expect((back.settings as { fragment?: unknown }).fragment).toBeUndefined();
|
|
expect((back.settings as { finalRules?: unknown[] }).finalRules).toHaveLength(1);
|
|
});
|
|
|
|
it('freedom omits proxyProtocol when disabled (0)', () => {
|
|
const round = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'freedom',
|
|
settings: { proxyProtocol: 0 },
|
|
}),
|
|
);
|
|
expect((round.settings as { proxyProtocol?: number }).proxyProtocol).toBeUndefined();
|
|
});
|
|
|
|
it('mux is only emitted when enabled AND protocol/network/flow allow it', () => {
|
|
// Disabled mux: omitted
|
|
const disabled = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'vless',
|
|
settings: {
|
|
address: 's',
|
|
port: 443,
|
|
id: '11111111-2222-4333-8444-555555555555',
|
|
flow: '',
|
|
encryption: 'none',
|
|
},
|
|
mux: { enabled: false },
|
|
}),
|
|
);
|
|
expect(disabled).not.toHaveProperty('mux');
|
|
|
|
// Enabled mux on vless without flow: emitted
|
|
const enabled = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'vless',
|
|
settings: {
|
|
address: 's',
|
|
port: 443,
|
|
id: '11111111-2222-4333-8444-555555555555',
|
|
flow: '',
|
|
encryption: 'none',
|
|
},
|
|
mux: { enabled: true, concurrency: 8, xudpConcurrency: 16, xudpProxyUDP443: 'reject' },
|
|
}),
|
|
);
|
|
expect(enabled.mux).toMatchObject({ enabled: true });
|
|
|
|
// Enabled mux on vless with vision flow: gated out
|
|
const withFlow = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'vless',
|
|
settings: {
|
|
address: 's',
|
|
port: 443,
|
|
id: '11111111-2222-4333-8444-555555555555',
|
|
flow: 'xtls-rprx-vision',
|
|
encryption: 'none',
|
|
},
|
|
mux: { enabled: true },
|
|
}),
|
|
);
|
|
expect(withFlow).not.toHaveProperty('mux');
|
|
|
|
// Freedom (non-mux protocol): gated out even if enabled
|
|
const freedom = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'freedom',
|
|
settings: {},
|
|
mux: { enabled: true },
|
|
}),
|
|
);
|
|
expect(freedom).not.toHaveProperty('mux');
|
|
});
|
|
|
|
it('hysteria preserves address/port/version literal 2', () => {
|
|
const back = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'hysteria',
|
|
settings: { address: 'h.example', port: 8443, version: 2 },
|
|
}),
|
|
);
|
|
expect(back.settings).toEqual({ address: 'h.example', port: 8443, version: 2 });
|
|
});
|
|
|
|
it('loopback inboundTag round-trips', () => {
|
|
const back = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'loopback',
|
|
settings: { inboundTag: 'tagged-inbound' },
|
|
}),
|
|
);
|
|
expect(back.settings).toEqual({ inboundTag: 'tagged-inbound' });
|
|
});
|
|
|
|
it('loopback omits sniffing when disabled', () => {
|
|
const form = rawOutboundToFormValues({
|
|
protocol: 'loopback',
|
|
settings: { inboundTag: 'tagged-inbound' },
|
|
});
|
|
if (form.protocol === 'loopback') {
|
|
expect(form.settings.sniffing.enabled).toBe(false);
|
|
}
|
|
const back = formValuesToWirePayload(form);
|
|
expect(back.settings).not.toHaveProperty('sniffing');
|
|
});
|
|
|
|
it('loopback round-trips sniffing when enabled', () => {
|
|
const wire = {
|
|
protocol: 'loopback',
|
|
settings: {
|
|
inboundTag: 'tagged-inbound',
|
|
sniffing: { enabled: true, destOverride: ['tls', 'http'], routeOnly: true },
|
|
},
|
|
};
|
|
const form = rawOutboundToFormValues(wire);
|
|
if (form.protocol === 'loopback') {
|
|
expect(form.settings.sniffing.enabled).toBe(true);
|
|
expect(form.settings.sniffing.destOverride).toEqual(['tls', 'http']);
|
|
expect(form.settings.sniffing.routeOnly).toBe(true);
|
|
}
|
|
const back = formValuesToWirePayload(form);
|
|
const sniffing = (back.settings as Record<string, unknown>).sniffing as Record<string, unknown>;
|
|
expect(sniffing.enabled).toBe(true);
|
|
expect(sniffing.destOverride).toEqual(['tls', 'http']);
|
|
expect(sniffing.routeOnly).toBe(true);
|
|
});
|
|
|
|
it('unknown protocol falls back to vless without throwing', () => {
|
|
const form = rawOutboundToFormValues({ protocol: 'mysterious', settings: {} });
|
|
expect(form.protocol).toBe('vless');
|
|
});
|
|
});
|
|
|
|
describe('outbound-form-adapter: targetStrategy', () => {
|
|
it('round-trips a top-level targetStrategy', () => {
|
|
const back = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'vless',
|
|
settings: {
|
|
address: 's',
|
|
port: 443,
|
|
id: '11111111-2222-4333-8444-555555555555',
|
|
flow: '',
|
|
encryption: 'none',
|
|
},
|
|
targetStrategy: 'ForceIPv6v4',
|
|
}),
|
|
);
|
|
expect(back.targetStrategy).toBe('ForceIPv6v4');
|
|
});
|
|
|
|
it('normalizes wire case to the canonical spelling (core matches case-insensitively)', () => {
|
|
const form = rawOutboundToFormValues({
|
|
protocol: 'freedom',
|
|
settings: {},
|
|
targetStrategy: 'useipv4v6',
|
|
});
|
|
expect(form.targetStrategy).toBe('UseIPv4v6');
|
|
});
|
|
|
|
it('omits targetStrategy when unset and drops unknown values', () => {
|
|
const unset = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'freedom',
|
|
settings: {},
|
|
}),
|
|
);
|
|
expect(unset).not.toHaveProperty('targetStrategy');
|
|
|
|
const invalid = formValuesToWirePayload(
|
|
rawOutboundToFormValues({
|
|
protocol: 'freedom',
|
|
settings: {},
|
|
targetStrategy: 'UseIPv5',
|
|
}),
|
|
);
|
|
expect(invalid).not.toHaveProperty('targetStrategy');
|
|
});
|
|
|
|
it('freedom prefers settings.targetStrategy over domainStrategy and emits the legacy key', () => {
|
|
const form = rawOutboundToFormValues({
|
|
protocol: 'freedom',
|
|
settings: { targetStrategy: 'UseIPv6', domainStrategy: 'UseIPv4' },
|
|
});
|
|
if (form.protocol === 'freedom') {
|
|
expect(form.settings.domainStrategy).toBe('UseIPv6');
|
|
}
|
|
const back = formValuesToWirePayload(form);
|
|
expect(back.settings).toMatchObject({ domainStrategy: 'UseIPv6' });
|
|
expect(back.settings).not.toHaveProperty('targetStrategy');
|
|
});
|
|
});
|
|
|
|
describe('outbound-form-adapter: xhttp xmux toggle', () => {
|
|
const xmuxWire = {
|
|
protocol: 'vless',
|
|
tag: 'out-xhttp',
|
|
settings: {
|
|
address: 's',
|
|
port: 443,
|
|
id: '11111111-2222-4333-8444-555555555555',
|
|
flow: '',
|
|
encryption: 'none',
|
|
},
|
|
streamSettings: {
|
|
network: 'xhttp',
|
|
security: 'none',
|
|
xhttpSettings: {
|
|
path: '/',
|
|
host: '',
|
|
mode: '',
|
|
xPaddingBytes: '100-1000',
|
|
scMaxEachPostBytes: '1000000',
|
|
xmux: {
|
|
maxConcurrency: '11',
|
|
maxConnections: '1',
|
|
hMaxRequestTimes: '1',
|
|
hMaxReusableSecs: '1',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
it('derives enableXmux from a saved xmux object and backfills missing knobs', () => {
|
|
const form = rawOutboundToFormValues(xmuxWire);
|
|
const stream = form.streamSettings as Record<string, unknown>;
|
|
const xhttp = stream.xhttpSettings as Record<string, unknown>;
|
|
expect(xhttp.enableXmux).toBe(true);
|
|
expect(xhttp.xmux).toMatchObject({
|
|
maxConcurrency: '11',
|
|
maxConnections: '1',
|
|
hMaxRequestTimes: '1',
|
|
hMaxReusableSecs: '1',
|
|
cMaxReuseTimes: 0,
|
|
hKeepAlivePeriod: 0,
|
|
});
|
|
});
|
|
|
|
it('round-trips xmux on save, strips enableXmux, and enforces xmux exclusivity', () => {
|
|
const back = formValuesToWirePayload(rawOutboundToFormValues(xmuxWire));
|
|
const xhttp = (back.streamSettings as Record<string, unknown>).xhttpSettings as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
expect(xhttp).not.toHaveProperty('enableXmux');
|
|
const xmux = xhttp.xmux as Record<string, unknown>;
|
|
// xray-core rejects maxConnections + maxConcurrency together; the
|
|
// explicit maxConnections wins and maxConcurrency is dropped.
|
|
expect(xmux).not.toHaveProperty('maxConcurrency');
|
|
expect(xmux).toMatchObject({
|
|
maxConnections: '1',
|
|
hMaxRequestTimes: '1',
|
|
hMaxReusableSecs: '1',
|
|
});
|
|
});
|
|
|
|
it('drops xmux on save when the toggle is off', () => {
|
|
const form = rawOutboundToFormValues(xmuxWire);
|
|
const xhttp = (form.streamSettings as Record<string, unknown>).xhttpSettings as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
xhttp.enableXmux = false;
|
|
const back = formValuesToWirePayload(form);
|
|
const wireXhttp = (back.streamSettings as Record<string, unknown>).xhttpSettings as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
expect(wireXhttp).not.toHaveProperty('xmux');
|
|
});
|
|
|
|
it('keeps a saved maxConcurrency through a load/re-save round-trip', () => {
|
|
const wire = {
|
|
...xmuxWire,
|
|
streamSettings: {
|
|
...xmuxWire.streamSettings,
|
|
xhttpSettings: {
|
|
...xmuxWire.streamSettings.xhttpSettings,
|
|
xmux: { maxConcurrency: '1-2' },
|
|
},
|
|
},
|
|
};
|
|
const form = rawOutboundToFormValues(wire);
|
|
const xhttp = (form.streamSettings as Record<string, unknown>).xhttpSettings as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
const xmux = xhttp.xmux as Record<string, unknown>;
|
|
expect(xmux.maxConcurrency).toBe('1-2');
|
|
expect(xmux.maxConnections).toBe(0);
|
|
|
|
const back = formValuesToWirePayload(form);
|
|
const wireXhttp = (back.streamSettings as Record<string, unknown>).xhttpSettings as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
const wireXmux = wireXhttp.xmux as Record<string, unknown>;
|
|
expect(wireXmux.maxConcurrency).toBe('1-2');
|
|
});
|
|
});
|
|
|
|
describe('outbound-form-adapter: full optional-block round-trip', () => {
|
|
const wire = {
|
|
protocol: 'vless',
|
|
settings: {
|
|
address: '1',
|
|
port: 443,
|
|
id: '1',
|
|
flow: '',
|
|
encryption: 'none',
|
|
reverse: {
|
|
tag: '1',
|
|
sniffing: {
|
|
enabled: true,
|
|
destOverride: ['http', 'tls', 'quic', 'fakedns'],
|
|
metadataOnly: true,
|
|
routeOnly: true,
|
|
ipsExcluded: ['1'],
|
|
domainsExcluded: ['1'],
|
|
},
|
|
},
|
|
},
|
|
tag: '1',
|
|
streamSettings: {
|
|
network: 'tcp',
|
|
tcpSettings: {
|
|
header: {
|
|
type: 'http',
|
|
request: { version: '1.1', method: 'GET', path: ['/'], headers: { '1': ['1'] } },
|
|
response: { version: '1.1', status: '200', reason: 'OK', headers: { '1': ['1'] } },
|
|
},
|
|
},
|
|
security: 'none',
|
|
sockopt: {
|
|
tcpFastOpen: true,
|
|
customSockopt: [{ type: 'int', level: '6', opt: '1', value: '1' }],
|
|
},
|
|
finalmask: {
|
|
tcp: [
|
|
{
|
|
type: 'fragment',
|
|
settings: { packets: '1-3', length: '1', delay: '1', maxSplit: '1' },
|
|
},
|
|
],
|
|
},
|
|
},
|
|
sendThrough: '1',
|
|
mux: { enabled: true, concurrency: 8, xudpConcurrency: 16, xudpProxyUDP443: 'reject' },
|
|
};
|
|
|
|
it('preserves sockopt, finalmask, mux, and reverse excludes', () => {
|
|
const back = formValuesToWirePayload(rawOutboundToFormValues(wire));
|
|
const settings = back.settings as Record<string, unknown>;
|
|
const sniffing = (settings.reverse as Record<string, unknown>).sniffing as Record<
|
|
string,
|
|
unknown
|
|
>;
|
|
expect(sniffing.ipsExcluded).toEqual(['1']);
|
|
expect(sniffing.domainsExcluded).toEqual(['1']);
|
|
|
|
const stream = back.streamSettings as Record<string, unknown>;
|
|
expect(stream.sockopt).toMatchObject({ tcpFastOpen: true });
|
|
expect((stream.sockopt as Record<string, unknown>).customSockopt).toHaveLength(1);
|
|
expect(stream.finalmask).toMatchObject({ tcp: [{ type: 'fragment' }] });
|
|
|
|
expect(back.mux).toMatchObject({ enabled: true });
|
|
});
|
|
});
|