@serverkgg/bridge 0.1.1 → 0.1.3

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 (121) hide show
  1. package/package.json +3 -2
  2. package/rules/package.md +60 -0
  3. package/src/blog/articleFrontmatter.test.ts +10 -10
  4. package/src/blog/compile.test.ts +9 -9
  5. package/src/bot/botDeploy.test.ts +16 -16
  6. package/src/bot/botEnvironment.test.ts +8 -8
  7. package/src/bot/botIdentity.test.ts +12 -12
  8. package/src/bot/botPanel.test.ts +41 -11
  9. package/src/bot/botPanel.ts +13 -5
  10. package/src/bot/botState.test.ts +3 -3
  11. package/src/bot/botTerminal.test.ts +5 -5
  12. package/src/bot/botVariables.test.ts +8 -8
  13. package/src/bot/detect/botToken.test.ts +6 -6
  14. package/src/bot/detect/detect.test.ts +21 -21
  15. package/src/bot/detect/detectTable.test.ts +5 -5
  16. package/src/bot/detect/envExample.test.ts +2 -2
  17. package/src/bot/detect/envScan.test.ts +4 -4
  18. package/src/bot/detect/inferBotPlatform.test.ts +4 -4
  19. package/src/bot/detect/keys.test.ts +3 -3
  20. package/src/bot/detect/sensitiveKey.test.ts +5 -5
  21. package/src/bot/detect/serverkJson.test.ts +5 -5
  22. package/src/catalogs/curseforge.test.ts +35 -35
  23. package/src/catalogs/thunderstore.test.ts +9 -9
  24. package/src/cli/detectTable.test.ts +3 -3
  25. package/src/cli/link.test.ts +11 -11
  26. package/src/cli/main.ts +8 -0
  27. package/src/cli/rules.test.ts +198 -0
  28. package/src/cli/rules.ts +188 -0
  29. package/src/cli/validate.test.ts +123 -29
  30. package/src/cli/validate.ts +37 -1
  31. package/src/codecs/ini.test.ts +13 -13
  32. package/src/codecs/javaProperties.test.ts +11 -11
  33. package/src/codecs/sourceCfg.test.ts +14 -14
  34. package/src/codecs/xmlProperties.test.ts +10 -10
  35. package/src/context/bridgeContext.ts +6 -1
  36. package/src/core/bridgeAction.ts +2 -0
  37. package/src/core/bridgeActivity.ts +9 -0
  38. package/src/core/bridgeAvailability.ts +10 -0
  39. package/src/core/bridgePort.test.ts +6 -6
  40. package/src/core/bridgeUserError.test.ts +13 -3
  41. package/src/core/bridgeUserError.ts +6 -2
  42. package/src/core/bridgeValue.test.ts +5 -5
  43. package/src/core/describeDownloadFailure.test.ts +58 -0
  44. package/src/core/describeDownloadFailure.ts +69 -0
  45. package/src/core/index.ts +3 -0
  46. package/src/guides/markdown.test.ts +31 -31
  47. package/src/install/installStamp.test.ts +9 -9
  48. package/src/manifest/extension.ts +36 -0
  49. package/src/manifest/index.ts +1 -0
  50. package/src/manifest/manifest.test.ts +208 -90
  51. package/src/manifest/manifest.ts +34 -0
  52. package/src/modules/bridge.ts +8 -1
  53. package/src/modules/bridgeModule.ts +13 -1
  54. package/src/net/loopback.test.ts +10 -10
  55. package/src/panel/bridgeDetail.ts +2 -1
  56. package/src/presence/rosterSync.test.ts +7 -7
  57. package/src/probes/a2s.test.ts +5 -5
  58. package/src/probes/minecraftPing.test.ts +17 -17
  59. package/src/probes/raknetPing.test.ts +13 -13
  60. package/src/protocol/bridgeActivity.ts +54 -0
  61. package/src/protocol/bridgeEvents.ts +30 -0
  62. package/src/protocol/bridgeFrame.ts +10 -1
  63. package/src/protocol/index.ts +1 -0
  64. package/src/rcon/rconAccess.test.ts +20 -20
  65. package/src/rcon/rconAccess.ts +13 -13
  66. package/src/rcon/rconClient.test.ts +49 -49
  67. package/src/rcon/rconFrame.test.ts +14 -14
  68. package/src/rcon/rconIds.test.ts +4 -4
  69. package/src/rcon/rconWriter.test.ts +6 -6
  70. package/src/runtime/bridgeActions.ts +19 -2
  71. package/src/runtime/bridgeActivity.test.ts +318 -0
  72. package/src/runtime/bridgeActivity.ts +268 -0
  73. package/src/runtime/bridgeBackupLease.test.ts +9 -9
  74. package/src/runtime/bridgeConfigReader.test.ts +5 -5
  75. package/src/runtime/bridgeConsoleHandler.test.ts +8 -8
  76. package/src/runtime/bridgeContext.test.ts +11 -5
  77. package/src/runtime/bridgeContext.ts +8 -1
  78. package/src/runtime/bridgeDriver.test.ts +114 -93
  79. package/src/runtime/bridgeDriver.ts +10 -7
  80. package/src/runtime/bridgeEvents.test.ts +15 -15
  81. package/src/runtime/bridgeFiles.test.ts +54 -54
  82. package/src/runtime/bridgeInstall.test.ts +10 -10
  83. package/src/runtime/bridgeLiveConfig.test.ts +6 -6
  84. package/src/runtime/bridgeLog.ts +10 -0
  85. package/src/runtime/bridgePending.test.ts +6 -6
  86. package/src/runtime/bridgeRedaction.test.ts +16 -16
  87. package/src/runtime/bridgeRefusalError.ts +13 -0
  88. package/src/runtime/bridgeRegistry.test.ts +1077 -34
  89. package/src/runtime/bridgeRegistry.ts +464 -65
  90. package/src/runtime/bridgeScopedContext.ts +55 -0
  91. package/src/runtime/bridgeServer.test.ts +424 -24
  92. package/src/runtime/bridgeServer.ts +125 -35
  93. package/src/runtime/bridgeSetup.test.ts +27 -27
  94. package/src/runtime/bridgeSetup.ts +1 -1
  95. package/src/runtime/bridgeSetupHandlers.test.ts +80 -17
  96. package/src/runtime/bridgeSetupHandlers.ts +45 -10
  97. package/src/runtime/bridgeSignal.test.ts +7 -7
  98. package/src/runtime/bridgeSupervisor.test.ts +42 -42
  99. package/src/runtime/serve.ts +45 -3
  100. package/src/steam/avatars.test.ts +13 -13
  101. package/src/steam/steamApp.test.ts +8 -8
  102. package/src/steam/steamcmd.test.ts +44 -13
  103. package/src/steam/steamcmd.ts +27 -4
  104. package/src/steam/steamcmdNarrator.test.ts +4 -4
  105. package/src/steam/workshop.test.ts +5 -5
  106. package/src/utils/changedSettingKeys.test.ts +65 -0
  107. package/src/utils/changedSettingKeys.ts +6 -0
  108. package/src/utils/describeExecFailure.test.ts +34 -0
  109. package/src/utils/describeExecFailure.ts +9 -0
  110. package/src/utils/index.ts +3 -0
  111. package/src/utils/sameSettingValue.test.ts +35 -0
  112. package/src/utils/sameSettingValue.ts +40 -0
  113. package/src/utils/token.test.ts +7 -7
  114. package/src/wine/protonCommand.test.ts +5 -5
  115. package/src/wine/wineCommand.test.ts +6 -6
  116. package/src/wine/winePrefix.test.ts +6 -6
  117. package/src/wire/activity.test.ts +95 -0
  118. package/src/wire/activity.ts +41 -0
  119. package/src/wire/index.ts +1 -0
  120. package/src/wire/panel.test.ts +91 -25
  121. package/src/wire/panel.ts +11 -0
@@ -1,9 +1,9 @@
1
- import { describe, expect, test } from "bun:test";
1
+ import { describe, expect, it } from "bun:test";
2
2
  import { BridgeDesired, BridgeHoldReason, BridgeRuntime } from "../core";
3
3
  import { decideInstall, recountHold } from "./bridgeInstall";
4
4
 
5
5
  describe("decideInstall", () => {
6
- test("starts the game when the install returns nothing and the server wants to run", () => {
6
+ it("starts the game when the install returns nothing and the server wants to run", () => {
7
7
  expect(decideInstall(undefined, BridgeDesired.Running)).toEqual({
8
8
  hold: null,
9
9
  runtime: BridgeRuntime.Starting,
@@ -11,7 +11,7 @@ describe("decideInstall", () => {
11
11
  });
12
12
  });
13
13
 
14
- test("stays stopped when the install returns nothing and the server wants to stay down", () => {
14
+ it("stays stopped when the install returns nothing and the server wants to stay down", () => {
15
15
  expect(decideInstall(undefined, BridgeDesired.Stopped)).toEqual({
16
16
  hold: null,
17
17
  runtime: BridgeRuntime.Stopped,
@@ -19,7 +19,7 @@ describe("decideInstall", () => {
19
19
  });
20
20
  });
21
21
 
22
- test("starts the game when the install answers with no hold", () => {
22
+ it("starts the game when the install answers with no hold", () => {
23
23
  expect(
24
24
  decideInstall(
25
25
  {
@@ -34,7 +34,7 @@ describe("decideInstall", () => {
34
34
  });
35
35
  });
36
36
 
37
- test("holds the game stopped when the install answers with a hold", () => {
37
+ it("holds the game stopped when the install answers with a hold", () => {
38
38
  const hold = {
39
39
  reason: BridgeHoldReason.PendingFiles,
40
40
  count: 2,
@@ -54,7 +54,7 @@ describe("decideInstall", () => {
54
54
  });
55
55
  });
56
56
 
57
- test("keeps the hold when the server was already stopped", () => {
57
+ it("keeps the hold when the server was already stopped", () => {
58
58
  const hold = {
59
59
  reason: BridgeHoldReason.PendingFiles,
60
60
  count: 1,
@@ -76,11 +76,11 @@ describe("decideInstall", () => {
76
76
  });
77
77
 
78
78
  describe("recountHold", () => {
79
- test("leaves a driver without a hold alone", () => {
79
+ it("leaves a driver without a hold alone", () => {
80
80
  expect(recountHold(null, 3)).toBeNull();
81
81
  });
82
82
 
83
- test("moves the count of a pending-files hold to what the driver now lists", () => {
83
+ it("moves the count of a pending-files hold to what the driver now lists", () => {
84
84
  expect(
85
85
  recountHold(
86
86
  {
@@ -95,7 +95,7 @@ describe("recountHold", () => {
95
95
  });
96
96
  });
97
97
 
98
- test("keeps the same hold when the count did not move", () => {
98
+ it("keeps the same hold when the count did not move", () => {
99
99
  const hold = {
100
100
  reason: BridgeHoldReason.PendingFiles,
101
101
  count: 2,
@@ -104,7 +104,7 @@ describe("recountHold", () => {
104
104
  expect(recountHold(hold, 2)).toBe(hold);
105
105
  });
106
106
 
107
- test("clears the hold when nothing is pending any more", () => {
107
+ it("clears the hold when nothing is pending any more", () => {
108
108
  expect(
109
109
  recountHold(
110
110
  {
@@ -1,4 +1,4 @@
1
- import { afterEach, beforeEach, describe, expect, test } from "bun:test";
1
+ import { afterEach, beforeEach, describe, expect, it } from "bun:test";
2
2
  import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
@@ -45,7 +45,7 @@ afterEach(async () => {
45
45
  });
46
46
 
47
47
  describe("the bridge live config reader", () => {
48
- test("answers from the boot snapshot", async () => {
48
+ it("answers from the boot snapshot", async () => {
49
49
  const config = configWith({
50
50
  CURSEFORGE_API_KEY: "boot",
51
51
  });
@@ -58,7 +58,7 @@ describe("the bridge live config reader", () => {
58
58
  expect(secrets.secret("MODRINTH_API_KEY")).toBeNull();
59
59
  });
60
60
 
61
- test("sees a value the agent rewrote into the config", async () => {
61
+ it("sees a value the agent rewrote into the config", async () => {
62
62
  const config = configWith({
63
63
  CURSEFORGE_API_KEY: "boot",
64
64
  });
@@ -80,7 +80,7 @@ describe("the bridge live config reader", () => {
80
80
  expect(secrets.secret("MODRINTH_API_KEY")).toBe("added");
81
81
  });
82
82
 
83
- test("keeps the last good values while the config is mid-write", async () => {
83
+ it("keeps the last good values while the config is mid-write", async () => {
84
84
  const config = configWith({
85
85
  CURSEFORGE_API_KEY: "boot",
86
86
  });
@@ -100,7 +100,7 @@ describe("the bridge live config reader", () => {
100
100
  expect(secrets.secret("CURSEFORGE_API_KEY")).toBe("boot");
101
101
  });
102
102
 
103
- test("re-reads the file at most once per refresh window", async () => {
103
+ it("re-reads the file at most once per refresh window", async () => {
104
104
  const config = configWith({
105
105
  CURSEFORGE_API_KEY: "boot",
106
106
  });
@@ -120,7 +120,7 @@ describe("the bridge live config reader", () => {
120
120
  expect(secrets.secret("CURSEFORGE_API_KEY")).toBe("boot");
121
121
  });
122
122
 
123
- test("sees a variable the customer changed after boot, and the new plan resources", async () => {
123
+ it("sees a variable the customer changed after boot, and the new plan resources", async () => {
124
124
  const config = configWith({});
125
125
 
126
126
  await write(config);
@@ -36,3 +36,13 @@ export const log: BridgeLeveledLogger = Object.assign(
36
36
  export const errorText = (error: unknown) => {
37
37
  return error instanceof Error ? error.message : String(error);
38
38
  };
39
+
40
+ export const errorDetail = (error: unknown) => {
41
+ const text = errorText(error);
42
+
43
+ if (!(error instanceof Error) || error.cause === undefined) {
44
+ return text;
45
+ }
46
+
47
+ return `${text} — ${errorText(error.cause)}`;
48
+ };
@@ -1,4 +1,4 @@
1
- import { describe, expect, test } from "bun:test";
1
+ import { describe, expect, it } from "bun:test";
2
2
  import { BRIDGE_PENDING_FILES_LIMIT, type BridgePendingFile } from "../protocol";
3
3
  import type { BridgeLeveledLogger } from "./bridgeLog";
4
4
  import { pendingResult, rejectedPending, unsupportedPending } from "./bridgePending";
@@ -46,7 +46,7 @@ const recorder = () => {
46
46
  };
47
47
 
48
48
  describe("unsupportedPending", () => {
49
- test("answers the sentinel a driver without a pending module gets", () => {
49
+ it("answers the sentinel a driver without a pending module gets", () => {
50
50
  expect(unsupportedPending()).toEqual({
51
51
  supported: false,
52
52
  staging: "",
@@ -58,7 +58,7 @@ describe("unsupportedPending", () => {
58
58
  });
59
59
 
60
60
  describe("pendingResult", () => {
61
- test("carries the staging path, the extensions and the files the driver listed", () => {
61
+ it("carries the staging path, the extensions and the files the driver listed", () => {
62
62
  const { onLog, warnings } = recorder();
63
63
 
64
64
  expect(
@@ -83,7 +83,7 @@ describe("pendingResult", () => {
83
83
  expect(warnings).toEqual([]);
84
84
  });
85
85
 
86
- test("truncates a list longer than the platform takes and warns instead of throwing", () => {
86
+ it("truncates a list longer than the platform takes and warns instead of throwing", () => {
87
87
  const { onLog, warnings } = recorder();
88
88
 
89
89
  const result = pendingResult(
@@ -104,7 +104,7 @@ describe("pendingResult", () => {
104
104
  });
105
105
 
106
106
  describe("rejectedPending", () => {
107
- test("names every file still pending as what the upload was expected to be", () => {
107
+ it("names every file still pending as what the upload was expected to be", () => {
108
108
  const { onLog } = recorder();
109
109
 
110
110
  const result = rejectedPending(
@@ -127,7 +127,7 @@ describe("rejectedPending", () => {
127
127
  expect(result.files).toHaveLength(2);
128
128
  });
129
129
 
130
- test("leaves an empty expectation when the driver has nothing pending left", () => {
130
+ it("leaves an empty expectation when the driver has nothing pending left", () => {
131
131
  const { onLog } = recorder();
132
132
 
133
133
  expect(
@@ -1,4 +1,4 @@
1
- import { afterEach, beforeEach, describe, expect, test } from "bun:test";
1
+ import { afterEach, beforeEach, describe, expect, it } from "bun:test";
2
2
  import { mkdtemp, rm, writeFile } from "node:fs/promises";
3
3
  import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
@@ -93,7 +93,7 @@ const sourceOf = (initial: Record<string, string>, secrets: Record<string, strin
93
93
  };
94
94
 
95
95
  describe("secretFieldKeys", () => {
96
- test("collects every secret form field once and nothing else", () => {
96
+ it("collects every secret form field once and nothing else", () => {
97
97
  expect(
98
98
  secretFieldKeys(
99
99
  driverWith([
@@ -106,13 +106,13 @@ describe("secretFieldKeys", () => {
106
106
  ]);
107
107
  });
108
108
 
109
- test("finds nothing in a driver with no secret fields", () => {
109
+ it("finds nothing in a driver with no secret fields", () => {
110
110
  expect(secretFieldKeys(driverWith([]))).toEqual([]);
111
111
  });
112
112
  });
113
113
 
114
114
  describe("createBridgeRedaction", () => {
115
- test("is built for every driver and leaves text alone until a secret exists", () => {
115
+ it("is built for every driver and leaves text alone until a secret exists", () => {
116
116
  const { source, seal } = sourceOf({});
117
117
  const redact = createBridgeRedaction([], source);
118
118
 
@@ -125,7 +125,7 @@ describe("createBridgeRedaction", () => {
125
125
  expect(redact(`token ${TOKEN}`)).toBe(`token ${REDACTED}`);
126
126
  });
127
127
 
128
- test("blanks the platform secrets the manifest declares, with the same length floor", () => {
128
+ it("blanks the platform secrets the manifest declares, with the same length floor", () => {
129
129
  const redact = createBridgeRedaction(
130
130
  [],
131
131
  sourceOf(
@@ -140,7 +140,7 @@ describe("createBridgeRedaction", () => {
140
140
  expect(redact("key cf-api-key-0123456789 and short")).toBe(`key ${REDACTED} and short`);
141
141
  });
142
142
 
143
- test("blanks secret fields and platform secrets together", () => {
143
+ it("blanks secret fields and platform secrets together", () => {
144
144
  const redact = createBridgeRedaction(
145
145
  [
146
146
  "BOT_TOKEN",
@@ -158,7 +158,7 @@ describe("createBridgeRedaction", () => {
158
158
  expect(redact(`${TOKEN} cf-api-key-0123456789`)).toBe(`${REDACTED} ${REDACTED}`);
159
159
  });
160
160
 
161
- test("replaces every occurrence of a secret value", () => {
161
+ it("replaces every occurrence of a secret value", () => {
162
162
  const redact = createBridgeRedaction(
163
163
  [
164
164
  "BOT_TOKEN",
@@ -173,7 +173,7 @@ describe("createBridgeRedaction", () => {
173
173
  );
174
174
  });
175
175
 
176
- test("blanks every line of a multi-line secret the process prints one line at a time", () => {
176
+ it("blanks every line of a multi-line secret the process prints one line at a time", () => {
177
177
  const key = [
178
178
  "-----BEGIN PRIVATE KEY-----",
179
179
  "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC7",
@@ -198,7 +198,7 @@ describe("createBridgeRedaction", () => {
198
198
  expect(redact(`whole ${key}`)).toBe(`whole ${REDACTED}`);
199
199
  });
200
200
 
201
- test("leaves a value under eight characters alone", () => {
201
+ it("leaves a value under eight characters alone", () => {
202
202
  const redact = createBridgeRedaction(
203
203
  [
204
204
  "RCON_PASSWORD",
@@ -211,7 +211,7 @@ describe("createBridgeRedaction", () => {
211
211
  expect(redact("the password is hunter2")).toBe("the password is hunter2");
212
212
  });
213
213
 
214
- test("escapes values that look like patterns and prefers the longest overlapping value", () => {
214
+ it("escapes values that look like patterns and prefers the longest overlapping value", () => {
215
215
  const redact = createBridgeRedaction(
216
216
  [
217
217
  "SHORT",
@@ -226,7 +226,7 @@ describe("createBridgeRedaction", () => {
226
226
  expect(redact("x a.b+c*d?-and-more y a.b+c*d? z aXb+c*d?")).toBe(`x ${REDACTED} y ${REDACTED} z aXb+c*d?`);
227
227
  });
228
228
 
229
- test("follows a value saved after it was built and forgets the old one", () => {
229
+ it("follows a value saved after it was built and forgets the old one", () => {
230
230
  const { source, save } = sourceOf({
231
231
  BOT_TOKEN: "old-token-value",
232
232
  });
@@ -250,11 +250,11 @@ describe("createBridgeRedaction", () => {
250
250
  describe("redacting what the bridge reports", () => {
251
251
  const redact = (value: string) => value.split(TOKEN).join(REDACTED);
252
252
 
253
- test("covers both languages of a customer-facing message", () => {
253
+ it("covers both languages of a customer-facing message", () => {
254
254
  expect(redactLocalized(text(`bad ${TOKEN}`), redact)).toEqual(text(`bad ${REDACTED}`));
255
255
  });
256
256
 
257
- test("covers the message and every string field of a log line", () => {
257
+ it("covers the message and every string field of a log line", () => {
258
258
  const lines: unknown[] = [];
259
259
  const record = (level: string) => (message: string, fields?: Record<string, unknown>) => {
260
260
  lines.push({
@@ -345,7 +345,7 @@ describe("redaction over the live config", () => {
345
345
  });
346
346
  });
347
347
 
348
- test("reads the platform secrets from the config the agent wrote", async () => {
348
+ it("reads the platform secrets from the config the agent wrote", async () => {
349
349
  const boot = {
350
350
  ...configWith({}),
351
351
  secrets: {
@@ -360,7 +360,7 @@ describe("redaction over the live config", () => {
360
360
  expect(redact("cf-api-key-0123456789")).toBe(REDACTED);
361
361
  });
362
362
 
363
- test("starts as the identity with no secret anywhere and blanks a secret written after boot", async () => {
363
+ it("starts as the identity with no secret anywhere and blanks a secret written after boot", async () => {
364
364
  const boot = configWith({});
365
365
 
366
366
  await write(boot);
@@ -382,7 +382,7 @@ describe("redaction over the live config", () => {
382
382
  expect(redact(`key ${TOKEN}`)).toBe(`key ${REDACTED}`);
383
383
  });
384
384
 
385
- test("picks up a token the agent writes into the config after boot", async () => {
385
+ it("picks up a token the agent writes into the config after boot", async () => {
386
386
  const boot = configWith({});
387
387
 
388
388
  await write(boot);
@@ -0,0 +1,13 @@
1
+ import type { LocalizedText } from "../core";
2
+ import { BridgeDriverError } from "./bridgeDriver";
3
+
4
+ export class BridgeRefusalError extends BridgeDriverError {
5
+ readonly text: LocalizedText | null;
6
+
7
+ constructor(message: string, text: LocalizedText | null = null) {
8
+ super(message);
9
+
10
+ this.name = "BridgeRefusalError";
11
+ this.text = text;
12
+ }
13
+ }