(content: string)
| 1114 | } |
| 1115 | |
| 1116 | function parseSmokeEnvFile(content: string): Record<string, string> { |
| 1117 | const values: Record<string, string> = {}; |
| 1118 | const lines = content.split(/\r?\n/); |
| 1119 | for (const [index, rawLine] of lines.entries()) { |
| 1120 | const line = rawLine.trim(); |
| 1121 | if (!line || line.startsWith("#")) { |
| 1122 | continue; |
| 1123 | } |
| 1124 | |
| 1125 | const normalizedLine = line.startsWith("export ") ? line.slice("export ".length).trimStart() : line; |
| 1126 | const separatorIndex = normalizedLine.indexOf("="); |
| 1127 | if (separatorIndex <= 0) { |
| 1128 | throw new SmokeCliError({ |
| 1129 | code: "feishu.smoke.invalid_env_file", |
| 1130 | message: `Invalid --env-file line ${index + 1}: expected KEY=value.`, |
| 1131 | reason: "expected_key_value", |
| 1132 | }); |
| 1133 | } |
| 1134 | |
| 1135 | const key = normalizedLine.slice(0, separatorIndex).trim(); |
| 1136 | if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) { |
| 1137 | throw new SmokeCliError({ |
| 1138 | code: "feishu.smoke.invalid_env_file", |
| 1139 | message: `Invalid --env-file line ${index + 1}: invalid env name.`, |
| 1140 | reason: "invalid_env_name", |
| 1141 | }); |
| 1142 | } |
| 1143 | |
| 1144 | values[key] = parseSmokeEnvFileValue(normalizedLine.slice(separatorIndex + 1).trim(), index + 1); |
| 1145 | } |
| 1146 | return values; |
| 1147 | } |
| 1148 | |
| 1149 | function parseSmokeEnvFileValue(value: string, lineNumber: number): string { |
| 1150 | if (!value) { |
no test coverage detected