| 161 | } |
| 162 | |
| 163 | export const call: LocalCommandCall = async args => { |
| 164 | if ((process.env.NCODE_BUILD_MODE !== 'noumena' && process.env.USER_TYPE !== 'ant')) { |
| 165 | return ok('`/mock-limits` is only available in ANT builds.') |
| 166 | } |
| 167 | |
| 168 | const trimmed = args.trim() |
| 169 | if (trimmed.length === 0) { |
| 170 | return ok(formatStatusWithCurrentScenario()) |
| 171 | } |
| 172 | |
| 173 | const parts = trimmed.split(/\s+/) |
| 174 | const subcommand = parts[0]?.toLowerCase() ?? '' |
| 175 | |
| 176 | if (HELP_ALIASES.has(subcommand)) { |
| 177 | return ok(usageText()) |
| 178 | } |
| 179 | |
| 180 | if (subcommand === 'status') { |
| 181 | return ok(formatStatusWithCurrentScenario()) |
| 182 | } |
| 183 | |
| 184 | if (subcommand === 'scenarios') { |
| 185 | return ok(buildScenarioList()) |
| 186 | } |
| 187 | |
| 188 | if (subcommand === 'clear') { |
| 189 | clearMockHeaders() |
| 190 | return ok('Cleared all mock limits, headers, and overrides.\n\n' + getMockStatus()) |
| 191 | } |
| 192 | |
| 193 | if (subcommand === 'scenario') { |
| 194 | const scenario = parts[1] |
| 195 | if (!scenario) { |
| 196 | return errorWithUsage('Missing scenario name.') |
| 197 | } |
| 198 | if (!isScenarioName(scenario)) { |
| 199 | return errorWithUsage(`Unknown scenario "${scenario}".`) |
| 200 | } |
| 201 | setMockRateLimitScenario(scenario) |
| 202 | return ok( |
| 203 | `Applied scenario: ${scenario} (${getScenarioDescription(scenario)})\n\n${formatStatusWithCurrentScenario()}`, |
| 204 | ) |
| 205 | } |
| 206 | |
| 207 | if (subcommand === 'header') { |
| 208 | const key = parts[1] |
| 209 | const value = parts.slice(2).join(' ') |
| 210 | if (!key) { |
| 211 | return errorWithUsage('Missing header key.') |
| 212 | } |
| 213 | if (!isHeaderKey(key)) { |
| 214 | return errorWithUsage(`Unknown header key "${key}".`) |
| 215 | } |
| 216 | if (value.length === 0) { |
| 217 | return errorWithUsage('Missing header value. Use "clear" to remove a header.') |
| 218 | } |
| 219 | setMockHeader(key, value === 'clear' ? undefined : value) |
| 220 | return ok(`Updated header: ${key}=${value}\n\n${formatStatusWithCurrentScenario()}`) |
nothing calls this directly
no test coverage detected