|
1 | 1 | /** Channel recovery replies preserve decisions from the real account lifecycle owner. */ |
2 | 2 | import { randomUUID } from "node:crypto"; |
3 | 3 | import { afterEach, describe, expect, it, vi } from "vitest"; |
| 4 | +import type { WebSocket } from "ws"; |
4 | 5 | import { createDeferred } from "../../test/helpers/promise.js"; |
5 | 6 | import "../secrets/runtime-telegram.test-support.ts"; |
6 | 7 | import type { ChannelGatewayContext } from "../channels/plugins/types.adapters.js"; |
7 | 8 | import type { ChannelPlugin } from "../channels/plugins/types.public.js"; |
8 | | -import { writeConfigFile } from "../config/config.js"; |
| 9 | +import { |
| 10 | + readConfigFileSnapshot, |
| 11 | + resetConfigRuntimeState, |
| 12 | + writeConfigFile, |
| 13 | +} from "../config/config.js"; |
9 | 14 | import { getRuntimeConfigSnapshot } from "../config/runtime-snapshot.js"; |
| 15 | +import type { SecretRef } from "../config/types.secrets.js"; |
| 16 | +import { writeJsonAtomic } from "../infra/json-files.js"; |
10 | 17 | import { setActiveDegradedSecretOwners } from "../secrets/runtime-degraded-state.js"; |
11 | 18 | import { createChannelTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js"; |
12 | 19 | import { withEnvAsync } from "../test-utils/env.js"; |
@@ -92,38 +99,44 @@ describe("channels.start account outcomes", () => { |
92 | 99 | setTestPluginRegistry( |
93 | 100 | createTestRegistry([{ pluginId: "telegram", source: "test", plugin }]), |
94 | 101 | ); |
95 | | - await writeConfigFile({ |
96 | | - gateway: { |
97 | | - mode: "local", |
98 | | - bind: "loopback", |
99 | | - auth: { mode: "none" }, |
100 | | - reload: { mode: "off" }, |
101 | | - }, |
102 | | - secrets: { providers: { default: { source: "env" } } }, |
103 | | - channels: { |
104 | | - telegram: { |
105 | | - enabled: true, |
106 | | - healthMonitor: { enabled: false }, |
107 | | - accounts: { |
108 | | - plaintext: { botToken: "plaintext-channel-token" }, |
109 | | - resolved: { |
110 | | - botToken: { |
111 | | - source: "env", |
112 | | - provider: "default", |
113 | | - id: "BREAKER_RESOLVED_CHANNEL_TOKEN", |
| 102 | + // Authored SecretRefs belong in the source fixture, before runtime config resolution. |
| 103 | + await writeJsonAtomic( |
| 104 | + (await readConfigFileSnapshot()).path, |
| 105 | + { |
| 106 | + gateway: { |
| 107 | + mode: "local", |
| 108 | + bind: "loopback", |
| 109 | + auth: { mode: "none" }, |
| 110 | + reload: { mode: "off" }, |
| 111 | + }, |
| 112 | + secrets: { providers: { default: { source: "env" } } }, |
| 113 | + channels: { |
| 114 | + telegram: { |
| 115 | + enabled: true, |
| 116 | + healthMonitor: { enabled: false }, |
| 117 | + accounts: { |
| 118 | + plaintext: { botToken: "plaintext-channel-token" }, |
| 119 | + resolved: { |
| 120 | + botToken: { |
| 121 | + source: "env", |
| 122 | + provider: "default", |
| 123 | + id: "BREAKER_RESOLVED_CHANNEL_TOKEN", |
| 124 | + } satisfies SecretRef, |
114 | 125 | }, |
115 | | - }, |
116 | | - unavailable: { |
117 | | - botToken: { |
118 | | - source: "env", |
119 | | - provider: "default", |
120 | | - id: "BREAKER_MISSING_CHANNEL_TOKEN", |
| 126 | + unavailable: { |
| 127 | + botToken: { |
| 128 | + source: "env", |
| 129 | + provider: "default", |
| 130 | + id: "BREAKER_MISSING_CHANNEL_TOKEN", |
| 131 | + } satisfies SecretRef, |
121 | 132 | }, |
122 | 133 | }, |
123 | 134 | }, |
124 | 135 | }, |
125 | 136 | }, |
126 | | - }); |
| 137 | + { durable: false, trailingNewline: true }, |
| 138 | + ); |
| 139 | + resetConfigRuntimeState(); |
127 | 140 | const port = await getGatewayTestPort(); |
128 | 141 | server = await startTestGatewayServer(port, { |
129 | 142 | auth: { mode: "none" }, |
|
0 commit comments