(deps: TestDeps)
| 8312 | } |
| 8313 | |
| 8314 | function createTestCodeCommand(deps: TestDeps): Command { |
| 8315 | const code = new Command('code').description('Inspect and edit generated test code'); |
| 8316 | code |
| 8317 | .command('get <test-id>') |
| 8318 | .description('Print the generated test code') |
| 8319 | .option( |
| 8320 | '--out <path>', |
| 8321 | 'Write the response to this file instead of stdout (text mode: source body; json mode: wire envelope)', |
| 8322 | ) |
| 8323 | .addHelpText('after', GLOBAL_OPTS_HINT) |
| 8324 | .action(async (testId: string, cmdOpts: { out?: string }, command: Command) => { |
| 8325 | await runCodeGet({ ...resolveCommonOptions(command), testId, out: cmdOpts.out }, deps); |
| 8326 | }); |
| 8327 | code |
| 8328 | .command('put <test-id>') |
| 8329 | .description('Replace test code with etag-guarded optimistic concurrency') |
| 8330 | .option('--code-file <path>', 'file containing the new test code (≤ 350 KB)') |
| 8331 | .option( |
| 8332 | '--expected-version <v>', |
| 8333 | 'expected current codeVersion (e.g. v3); sent as `If-Match`. Mutually exclusive with --force.', |
| 8334 | ) |
| 8335 | .option( |
| 8336 | '--force', |
| 8337 | 'send `If-Match: *` to skip the etag check (audit-logged with force: true). Mutually exclusive with --expected-version.', |
| 8338 | false, |
| 8339 | ) |
| 8340 | .option( |
| 8341 | '--language <lang>', |
| 8342 | 'override the stored language (typescript|javascript|python). Defaults to the existing language.', |
| 8343 | ) |
| 8344 | .option( |
| 8345 | '--idempotency-key <token>', |
| 8346 | 'opaque idempotency token (1-256 ASCII chars). Defaults to a UUIDv4 minted per invocation; pin one yourself for safe retries.', |
| 8347 | ) |
| 8348 | .option( |
| 8349 | '--dry-run-simulate-error <code>', |
| 8350 | 'With --dry-run: synthesise an error envelope to preview the error path. Supported: PRECONDITION_FAILED (412).', |
| 8351 | ) |
| 8352 | .addHelpText( |
| 8353 | 'after', |
| 8354 | '\nDry-run note: --dry-run always returns the happy response shape.\n' + |
| 8355 | 'To preview the 412 retry-hint path, combine with --dry-run-simulate-error PRECONDITION_FAILED.\n' + |
| 8356 | '\n' + |
| 8357 | GLOBAL_OPTS_HINT, |
| 8358 | ) |
| 8359 | .action(async (testId: string, cmdOpts: CodePutFlagOpts, command: Command) => { |
| 8360 | const simulateError = cmdOpts.dryRunSimulateError; |
| 8361 | if (simulateError !== undefined && simulateError !== 'PRECONDITION_FAILED') { |
| 8362 | throw localValidationError( |
| 8363 | 'dry-run-simulate-error', |
| 8364 | `unsupported value "${simulateError}"; only PRECONDITION_FAILED is supported`, |
| 8365 | ['PRECONDITION_FAILED'], |
| 8366 | ); |
| 8367 | } |
| 8368 | await runCodePut( |
| 8369 | { |
| 8370 | ...resolveCommonOptions(command), |
| 8371 | testId, |
no test coverage detected