dsh-ris-ide 1.7.3 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +21 -7
  2. package/bin/proxy-janitor.mjs +106 -11
  3. package/bin/risd.mjs +284 -0
  4. package/bin/run-with-log.ps1 +43 -5
  5. package/lib/client.js +609 -1178
  6. package/lib/index.js +1124 -55
  7. package/lib/janitor.js +106 -15
  8. package/lib/proxy.js +86 -7
  9. package/lib/proxybridge-bundle.js +798 -0
  10. package/lib/proxybridge-health.js +206 -0
  11. package/lib/redirector.js +1615 -115
  12. package/lib/risd/build.js +91 -0
  13. package/lib/risd/debug.js +374 -0
  14. package/lib/risd/git.js +207 -0
  15. package/lib/risd/leases.js +124 -0
  16. package/lib/risd/lifecycle.js +148 -0
  17. package/lib/risd/log.js +59 -0
  18. package/lib/risd/ping.js +94 -0
  19. package/lib/risd/programs.js +348 -0
  20. package/lib/risd/server.js +1919 -0
  21. package/lib/risd/state.js +137 -0
  22. package/lib/risd/ui.js +1989 -0
  23. package/lib/risd/view.js +79 -0
  24. package/lib/risd-client.js +282 -0
  25. package/lib/standalone/window.html +14 -16
  26. package/lib/startup.js +114 -0
  27. package/package.json +4 -1
  28. package/test/client-build.test.mjs +113 -0
  29. package/test/client-viewer.test.mjs +279 -227
  30. package/test/dsh-origin.test.mjs +140 -0
  31. package/test/dsh-window-refresh.test.mjs +100 -0
  32. package/test/harness.test.mjs +9 -0
  33. package/test/host-noloop.test.mjs +74 -0
  34. package/test/host-tail.test.mjs +21 -4
  35. package/test/host-window.test.mjs +4 -4
  36. package/test/janitor.test.mjs +29 -1
  37. package/test/lifecycle.test.mjs +26 -5
  38. package/test/merge-owners.test.mjs +155 -0
  39. package/test/proxy-restart.test.mjs +39 -0
  40. package/test/proxy-window.test.mjs +45 -0
  41. package/test/proxy.test.mjs +41 -0
  42. package/test/proxybridge-bundle.test.mjs +687 -0
  43. package/test/proxybridge-health.test.mjs +116 -0
  44. package/test/redirector-bundle.test.mjs +391 -0
  45. package/test/redirector.test.mjs +413 -10
  46. package/test/risd-api.test.mjs +514 -0
  47. package/test/risd-bridge-degrade.test.mjs +101 -0
  48. package/test/risd-build.test.mjs +20 -0
  49. package/test/risd-cli-home.test.mjs +50 -0
  50. package/test/risd-client.test.mjs +130 -0
  51. package/test/risd-debug.test.mjs +261 -0
  52. package/test/risd-election.test.mjs +104 -0
  53. package/test/risd-engine.test.mjs +132 -0
  54. package/test/risd-entry.test.mjs +118 -0
  55. package/test/risd-git.test.mjs +109 -0
  56. package/test/risd-handoff.test.mjs +116 -0
  57. package/test/risd-heal.test.mjs +50 -0
  58. package/test/risd-helpers.mjs +108 -0
  59. package/test/risd-host-p2.test.mjs +147 -0
  60. package/test/risd-janitor-guard.test.mjs +46 -0
  61. package/test/risd-lease.test.mjs +83 -0
  62. package/test/risd-lifecycle.test.mjs +210 -0
  63. package/test/risd-log-follow.test.mjs +227 -0
  64. package/test/risd-mode.test.mjs +161 -0
  65. package/test/risd-ping.test.mjs +99 -0
  66. package/test/risd-programs.test.mjs +169 -0
  67. package/test/risd-restart.test.mjs +104 -0
  68. package/test/risd-review-p2.test.mjs +217 -0
  69. package/test/risd-shutdown.test.mjs +97 -0
  70. package/test/risd-teardown.test.mjs +87 -0
  71. package/test/risd-tools.test.mjs +211 -0
  72. package/test/risd-ui.test.mjs +607 -0
  73. package/test/risd-write.test.mjs +170 -0
  74. package/test/startup-reconcile.test.mjs +100 -0
  75. package/test/windows.test.mjs +37 -2
@@ -0,0 +1,155 @@
1
+ /**
2
+ * `mergeConfigs` must preserve a rule's per-workspace `owners` map.
3
+ *
4
+ * `yds` writes the map and later withdraws only its own endpoints from it. The
5
+ * read path (`normalizeConfig`) already kept it; the daemon write path rebuilt each
6
+ * row from a fixed field list and dropped it, so one config round trip broke
7
+ * `yds stop` (review B-P0-2 / D-P0-1). These tests pin the write path.
8
+ */
9
+ import assert from 'node:assert/strict'
10
+ import test from 'node:test'
11
+
12
+ import { mergeConfigs, normalizeConfig, normalizeOwners } from '../lib/proxy.js'
13
+
14
+ // The canonical (normalized) shape: hosts/ports are comma strings.
15
+ const ydsOwners = () => ({
16
+ '/ws/a': { program: 'java', hosts: '10.0.0.1', ports: '3306', enabled: true, shadow: false, direct: false },
17
+ })
18
+
19
+ /** A stored table: one driven (`yds`) row with owners, one user row. */
20
+ function storedConfig() {
21
+ return normalizeConfig({
22
+ socks: { host: '127.0.0.1', port: 1080 },
23
+ listenPort: 7890,
24
+ rules: [
25
+ {
26
+ id: 'yds-java',
27
+ label: 'YonCode java',
28
+ program: 'java',
29
+ hosts: '10.0.0.1',
30
+ ports: '3306',
31
+ enabled: true,
32
+ source: 'yds',
33
+ workspace: '/ws/a',
34
+ owners: ydsOwners(),
35
+ },
36
+ { id: 'user-curl', program: 'curl', hosts: '10.0.0.2', ports: '80', enabled: true, source: 'user', workspace: '/ws/b' },
37
+ ],
38
+ shadows: [],
39
+ })
40
+ }
41
+
42
+ const row = (config, id) => config.rules.find((item) => item.id === id)
43
+
44
+ test('a driven row keeps its owners across the write path when the patch restates them', () => {
45
+ const merged = mergeConfigs(storedConfig(), {
46
+ replaceRulesFrom: 'yds',
47
+ rules: [{
48
+ id: 'yds-java',
49
+ program: 'java',
50
+ hosts: '10.0.0.7',
51
+ ports: '3306',
52
+ enabled: true,
53
+ source: 'yds',
54
+ owners: {
55
+ '/ws/a': { program: 'java', hosts: ['10.0.0.7'], ports: ['3306'], enabled: true },
56
+ '/ws/c': { program: 'java', hosts: ['10.0.0.7'], ports: ['3306'], enabled: true },
57
+ },
58
+ }],
59
+ })
60
+ const owners = row(merged, 'yds-java').owners
61
+ assert.deepEqual(Object.keys(owners).sort(), ['/ws/a', '/ws/c'])
62
+ assert.equal(owners['/ws/a'].hosts, '10.0.0.7', 'arrays are stored as the canonical comma string')
63
+ assert.equal(owners['/ws/a'].program, 'java')
64
+ })
65
+
66
+ test('a whole-source replacement does not inherit owners the patch does not restate', () => {
67
+ const merged = mergeConfigs(storedConfig(), {
68
+ replaceRulesFrom: 'yds',
69
+ rules: [{ id: 'yds-java', program: 'java', hosts: '10.0.0.3', ports: '3306', enabled: true, source: 'yds' }],
70
+ })
71
+ assert.equal(row(merged, 'yds-java').owners, undefined, 'the replacement is a delete-and-recreate, not an edit')
72
+ })
73
+
74
+ test('editing a different row never loses the driven row owners', () => {
75
+ const merged = mergeConfigs(storedConfig(), {
76
+ rules: [{ id: 'user-curl', program: 'curl', hosts: '10.0.0.2', ports: '81', enabled: true, source: 'user' }],
77
+ })
78
+ assert.equal(row(merged, 'user-curl').ports, '81')
79
+ assert.deepEqual(row(merged, 'yds-java').owners, ydsOwners())
80
+ })
81
+
82
+ test('editing the driven row without restating owners inherits the stored map', () => {
83
+ const merged = mergeConfigs(storedConfig(), {
84
+ rules: [{ id: 'yds-java', program: 'java', hosts: '10.0.0.9', ports: '3306', enabled: true, source: 'yds' }],
85
+ })
86
+ assert.equal(row(merged, 'yds-java').hosts, '10.0.0.9')
87
+ assert.deepEqual(row(merged, 'yds-java').owners, ydsOwners(), 'a plain edit is not a withdrawal')
88
+ })
89
+
90
+ test('normalizeOwners whitelists the known fields and drops unusable entries', () => {
91
+ assert.equal(normalizeOwners(null), undefined)
92
+ assert.equal(normalizeOwners([]), undefined)
93
+ assert.equal(normalizeOwners({}), undefined)
94
+ assert.equal(normalizeOwners({ '/ws/x': {} }), undefined, 'an entry without a program is dropped')
95
+ assert.equal(normalizeOwners({ '/ws/x': { program: ' ' } }), undefined)
96
+ assert.equal(normalizeOwners({ '/ws/x': 'nope' }), undefined)
97
+ assert.deepEqual(
98
+ normalizeOwners({ '/ws/x': { program: ' java ', hosts: '1.2.3.4', ports: ['80', '443'], enabled: 1, extra: 'dropped' } }),
99
+ { '/ws/x': { program: 'java', hosts: '1.2.3.4', ports: '80,443', enabled: false, shadow: false, direct: false } },
100
+ )
101
+ })
102
+
103
+ // --- yds upgrade contract (D 段已提交 d305fd5) -----------------------------
104
+ // 1. Rows migrated from before owners existed are filed under the reserved
105
+ // `<legacy>` bucket: it is not a workspace path, so nothing may normalise or
106
+ // drop it, and a workspace stop must never withdraw it.
107
+ test('the reserved <legacy> owner bucket survives both write paths untouched', () => {
108
+ const legacy = { program: 'java', hosts: ['10.0.0.1'], ports: ['3306'], enabled: true }
109
+ const stored = normalizeConfig({
110
+ socks: { host: '127.0.0.1', port: 1080 },
111
+ listenPort: 7890,
112
+ rules: [{ id: 'yds-java', program: 'java', hosts: '10.0.0.1', ports: '3306', enabled: true, source: 'yds', workspace: '/ws/a', owners: { '<legacy>': legacy } }],
113
+ shadows: [],
114
+ })
115
+ assert.deepEqual(Object.keys(row(stored, 'yds-java').owners), ['<legacy>'])
116
+
117
+ const edited = mergeConfigs(stored, {
118
+ rules: [{ id: 'yds-java', program: 'java', hosts: '10.0.0.2', ports: '3306', enabled: true, source: 'yds' }],
119
+ })
120
+ assert.deepEqual(row(edited, 'yds-java').owners, {
121
+ '<legacy>': { program: 'java', hosts: '10.0.0.1', ports: '3306', enabled: true, shadow: false, direct: false },
122
+ })
123
+
124
+ const replaced = mergeConfigs(stored, {
125
+ replaceRulesFrom: 'yds',
126
+ rules: [{ id: 'yds-java', program: 'java', hosts: '10.0.0.2', ports: '3306', enabled: true, source: 'yds', owners: { '<legacy>': legacy } }],
127
+ })
128
+ assert.deepEqual(Object.keys(row(replaced, 'yds-java').owners), ['<legacy>'])
129
+ })
130
+
131
+ // 2. A slug conflict makes the driver suffix the id with a short hash; the id is
132
+ // the dedupe key (`yds\0id`) and must be stored verbatim.
133
+ test('a hashed driven id is preserved verbatim (dedupe key is the id itself)', () => {
134
+ const merged = mergeConfigs(storedConfig(), {
135
+ replaceRulesFrom: 'yds',
136
+ rules: [{ id: 'yds-java-1a2b3c', program: 'java', hosts: '10.0.0.1', ports: '3306', enabled: true, source: 'yds' }],
137
+ })
138
+ const driven = merged.rules.filter((item) => item.source === 'yds')
139
+ assert.deepEqual(driven.map((item) => item.id), ['yds-java-1a2b3c'])
140
+ })
141
+
142
+ // 3. The driver's POST /v1/proxy no longer sends `shadows`; a missing field must
143
+ // keep the stored fallback listeners rather than silently dropping them.
144
+ test('a patch without shadows keeps the stored fallback listeners', () => {
145
+ const stored = normalizeConfig({
146
+ socks: { host: '127.0.0.1', port: 1080 },
147
+ listenPort: 7890,
148
+ rules: [{ id: 'user-curl', program: 'curl', hosts: '10.0.0.2', ports: '80', enabled: true, source: 'user' }],
149
+ shadows: [{ host: '10.0.0.5', port: 3306 }],
150
+ })
151
+ const merged = mergeConfigs(stored, {
152
+ rules: [{ id: 'user-curl', program: 'curl', hosts: '10.0.0.2', ports: '80', enabled: true, source: 'user' }],
153
+ })
154
+ assert.deepEqual(merged.shadows, [{ host: '10.0.0.5', port: 3306, localPort: 3306 }])
155
+ })
@@ -0,0 +1,39 @@
1
+ // The bridge parses its profile when it starts, so a rule-table save can leave old
2
+ // rules intercepting. The daemon page therefore offers "restart bridge" right next
3
+ // to that warning, and both the daemon and the plugin must understand the action.
4
+ import { test } from 'node:test'
5
+ import assert from 'node:assert/strict'
6
+ import { readFileSync } from 'node:fs'
7
+
8
+ const read = (file) => readFileSync(new URL(`../${file}`, import.meta.url), 'utf8')
9
+
10
+ test('the daemon page offers a restart button next to a stale-bridge note', () => {
11
+ const ui = read('lib/risd/ui.js')
12
+ assert.match(ui, /id="bridge-restart"/)
13
+ // The button only appears for notes that say the bridge did not take the new rules.
14
+ assert.match(ui, /未重载\|旧规则/)
15
+ assert.match(ui, /'为什么要重启:'/)
16
+ assert.match(ui, /redirector-restart/)
17
+ })
18
+
19
+ test('the daemon restarts the bridge: stop, settle, start from the new profile', () => {
20
+ const server = read('lib/risd/server.js')
21
+ const at = server.indexOf("action === 'redirector-restart'")
22
+ assert.ok(at > 0, 'daemon must handle redirector-restart')
23
+ const block = server.slice(at, at + 600)
24
+ assert.match(block, /await stopRedirector\(\)/)
25
+ assert.match(block, /setTimeout\(resolve, 300\)/)
26
+ // A page-triggered restart may prompt (it is the user asking); background
27
+ // reconcilers must not (review B-P0-2).
28
+ assert.match(block, /await startRedirectors\(\{ interactive: true \}\)/)
29
+ })
30
+
31
+ test('the plugin forwards the restart action to the daemon and can run it itself', () => {
32
+ const index = read('lib/index.js')
33
+ assert.match(index, /'redirector-restart'/)
34
+ const at = index.indexOf("action === 'redirector-restart'")
35
+ assert.ok(at > 0, 'plugin must handle redirector-restart locally')
36
+ const block = index.slice(at, at + 400)
37
+ assert.match(block, /await stopRedirector\(\)/)
38
+ assert.match(block, /await startRedirectors\(\)/)
39
+ })
@@ -0,0 +1,45 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import { readFileSync } from 'node:fs'
4
+
5
+ const client = readFileSync(new URL('../lib/client.js', import.meta.url), 'utf8')
6
+ const page = readFileSync(new URL('../lib/standalone/window.html', import.meta.url), 'utf8')
7
+
8
+ test('the panel no longer opens a proxy dialog at all', () => {
9
+ // Proxy rules live on the risd page (a machine-level resource, editable without
10
+ // dsh); both console shapes lost their 🌐, so nothing in the plugin opens the
11
+ // in-panel dialog or the standalone proxy window any more.
12
+ assert.doesNotMatch(client, /data-action': 'compact-proxy'/)
13
+ assert.doesNotMatch(client, /setProxyOpen\(true\)|setCompactProxyOpen\(true\)/)
14
+ assert.doesNotMatch(client, /focus-ack/)
15
+ })
16
+
17
+ test('the dead proxy-window opener and its polling hook are gone (review C-P2-7)', () => {
18
+ // These had no caller left once the 🌐 buttons went: keeping them meant a second
19
+ // way to open a proxy document and a second poll of /dsh-ris-ide/proxy that
20
+ // nobody consumed.
21
+ assert.doesNotMatch(client, /openProxyWindow/)
22
+ assert.doesNotMatch(client, /proxyWindowHandles|proxyWindowNameFor/)
23
+ assert.doesNotMatch(client, /proxyRunWatch|proxyRunKey|refreshProxyRun|useProxyRunning/)
24
+ // Nothing in the panel builds a view=proxy URL any more, and the component that
25
+ // rendered it is deleted (D4).
26
+ assert.doesNotMatch(client, /set\('view', 'proxy'\)/)
27
+ assert.doesNotMatch(client, /opts\.view === 'proxy'/)
28
+ })
29
+
30
+ test('the window page no longer forwards the dead `view` parameter', () => {
31
+ // The proxy-only window went with the dialog (D4); keeping the parameter alive
32
+ // meant the page and the client disagreed about a mode nobody could reach.
33
+ assert.doesNotMatch(page, /params\.get\('view'\)/)
34
+ assert.doesNotMatch(page, /view: view,/)
35
+ // D4 deleted the in-panel ProxyDialog together with its standalone rendering.
36
+ assert.doesNotMatch(client, /opts\.view === 'proxy'/)
37
+ assert.doesNotMatch(client, /standalone: true,/)
38
+ })
39
+
40
+ test('no panel button reflects engine state any more', () => {
41
+ // The grey/blue 🌐 indicator went with the buttons; engine state is shown in the
42
+ // risd page's overview instead.
43
+ assert.doesNotMatch(client, /color: proxyRunning === true/)
44
+ assert.doesNotMatch(client, /useProxyRunning\(\{ sessionId: sessionId, cwd: cwd \}\)/)
45
+ })
@@ -342,6 +342,21 @@ test('JSONC config files round-trip through the ONE shared file', () => {
342
342
  }
343
343
  })
344
344
 
345
+ test('merge: replaceAllRules makes the payload the whole table (m10585)', () => {
346
+ const stored = normalizeConfig({
347
+ socks: { host: 'h', port: 1080 },
348
+ rules: [
349
+ { id: 'user-1', program: 'java', hosts: '1.1.1.*', ports: '443', enabled: true },
350
+ { id: 'yds-old', program: 'git', hosts: '1.1.1.1', ports: '1521', enabled: true, source: 'yds' },
351
+ ],
352
+ })
353
+ const merged = mergeConfigs(stored, {
354
+ replaceAllRules: true,
355
+ rules: [{ id: 'yds-new', program: 'java', hosts: '2.2.2.*', ports: '*', enabled: true, source: 'yds' }],
356
+ })
357
+ assert.deepEqual(merged.rules.map((rule) => rule.id), ['yds-new'])
358
+ })
359
+
345
360
  test('merge: yds-owned rows are replaced wholesale, user rows survive', () => {
346
361
  const stored = normalizeConfig({
347
362
  socks: { host: 'h', port: 1080 },
@@ -871,3 +886,29 @@ test('a rule keeps its provider label for the dialog and the profile', () => {
871
886
  assert.equal(config.rules[0].label, 'YonCode java')
872
887
  assert.equal(config.rules[1].label, '', 'an unlabelled row stays empty, not undefined')
873
888
  })
889
+
890
+
891
+ test('a driven rule keeps its per-workspace owners across a config round trip', () => {
892
+ // yds writes one merged row per program with an `owners` map. Rebuilding rules
893
+ // from a fixed field list dropped it, after which `yds stop` could no longer
894
+ // withdraw only its own endpoints (review D-P0-1).
895
+ const owners = {
896
+ '/ws/a': { program: 'java', hosts: '10.0.0.1', ports: '*', enabled: true, shadow: false, direct: false },
897
+ '/ws/b': { program: 'java.exe', hosts: '10.0.0.2,10.0.0.3', ports: '*', enabled: true, shadow: true, direct: false },
898
+ }
899
+ const config = normalizeConfig({
900
+ socks: { host: '127.0.0.1', port: 1080 },
901
+ rules: [{
902
+ id: 'yds-java', label: 'yds java', program: 'java', hosts: '10.0.0.1,10.0.0.2,10.0.0.3', ports: '*',
903
+ enabled: true, shadow: false, direct: false, source: 'yds', workspace: '/ws/b', owners,
904
+ }],
905
+ })
906
+ const rule = config.rules.find((row) => row.id === 'yds-java')
907
+ assert.ok(rule, 'the driven row survives')
908
+ assert.deepEqual(Object.keys(rule.owners), ['/ws/a', '/ws/b'])
909
+ assert.equal(rule.owners['/ws/b'].hosts, '10.0.0.2,10.0.0.3')
910
+ assert.equal(rule.owners['/ws/b'].shadow, true)
911
+ // A row without owners must not gain an empty one.
912
+ const plain = normalizeConfig({ rules: [{ id: 'p', program: 'git', hosts: '*', ports: '*' }] })
913
+ assert.equal(plain.rules[0].owners, undefined)
914
+ })