test: source revision capacity 계측을 추가

This commit is contained in:
2026-08-16 19:03:54 +00:00
parent cfcf57c877
commit a4274c64b6
10 changed files with 252 additions and 53 deletions
+64 -12
View File
@@ -3,6 +3,7 @@ import path from 'node:path';
import { assertRuntimeMetadataFinalized, loadConfig, loadTokens } from './config.js';
import {
activateCapacityCoverage,
cleanupCapacityFixture,
materializeCalibrationConfig,
prepareCapacitySecrets,
@@ -11,16 +12,42 @@ import {
} from './fixture.js';
import { describeDryRun, runLoadTest } from './runner.js';
type Command = 'run' | 'dry-run' | 'validate' | 'prepare' | 'seed' | 'verify-fixture' | 'materialize-calibration' | 'cleanup';
type Command =
| 'run'
| 'dry-run'
| 'validate'
| 'prepare'
| 'seed'
| 'verify-fixture'
| 'activate-coverage'
| 'materialize-calibration'
| 'cleanup';
const usage = (): never => {
process.stderr.write('usage: cli.ts <validate|dry-run|run|prepare|seed|verify-fixture|materialize-calibration|cleanup> --config <file> [--tokens <0600-gitignored-file>] [--output <new-json-file>] [--confirm <load_schema>]\n');
process.stderr.write(
'usage: cli.ts <validate|dry-run|run|prepare|seed|verify-fixture|activate-coverage|materialize-calibration|cleanup> --config <file> [--tokens <0600-gitignored-file>] [--output <new-json-file>] [--confirm <load_schema>]\n'
);
process.exit(64);
};
const parseArguments = (argv: readonly string[]): { command: Command; config: string; tokens?: string; output?: string; confirm?: string } => {
const parseArguments = (
argv: readonly string[]
): { command: Command; config: string; tokens?: string; output?: string; confirm?: string } => {
const command = argv[0];
if (!['run', 'dry-run', 'validate', 'prepare', 'seed', 'verify-fixture', 'materialize-calibration', 'cleanup'].includes(command ?? '')) usage();
if (
![
'run',
'dry-run',
'validate',
'prepare',
'seed',
'verify-fixture',
'activate-coverage',
'materialize-calibration',
'cleanup',
].includes(command ?? '')
)
usage();
const values = new Map<string, string>();
for (let index = 1; index < argv.length; index += 2) {
const flag = argv[index];
@@ -33,10 +60,22 @@ const parseArguments = (argv: readonly string[]): { command: Command; config: st
if (command === 'run' && (!values.get('--tokens') || !values.get('--output'))) usage();
if (command === 'seed' && (!values.get('--tokens') || values.has('--output') || values.has('--confirm'))) usage();
if (command === 'prepare' && (values.has('--tokens') || values.has('--output') || values.has('--confirm'))) usage();
if (command === 'cleanup' && (!values.get('--confirm') || values.has('--tokens') || values.has('--output'))) usage();
if (command === 'verify-fixture' && (values.has('--tokens') || values.has('--output') || values.has('--confirm'))) usage();
if (command === 'materialize-calibration' && (!values.get('--output') || values.has('--tokens') || values.has('--confirm'))) usage();
if (command === 'validate' && (values.has('--tokens') || values.has('--output') || values.has('--confirm'))) usage();
if (command === 'cleanup' && (!values.get('--confirm') || values.has('--tokens') || values.has('--output')))
usage();
if (command === 'verify-fixture' && (values.has('--tokens') || values.has('--output') || values.has('--confirm')))
usage();
if (
command === 'activate-coverage' &&
(!values.get('--confirm') || values.has('--tokens') || values.has('--output'))
)
usage();
if (
command === 'materialize-calibration' &&
(!values.get('--output') || values.has('--tokens') || values.has('--confirm'))
)
usage();
if (command === 'validate' && (values.has('--tokens') || values.has('--output') || values.has('--confirm')))
usage();
if (command === 'dry-run' && (values.has('--output') || values.has('--confirm'))) usage();
if (command === 'run' && values.has('--confirm')) usage();
return {
@@ -73,6 +112,10 @@ const main = async (): Promise<void> => {
process.stdout.write(`${JSON.stringify(await verifyCapacityFixture(config))}\n`);
return;
}
if (args.command === 'activate-coverage') {
process.stdout.write(`${JSON.stringify(await activateCapacityCoverage(config, args.confirm!))}\n`);
return;
}
if (args.command === 'materialize-calibration') {
process.stdout.write(
`${JSON.stringify(
@@ -89,9 +132,13 @@ const main = async (): Promise<void> => {
process.stdout.write(`${JSON.stringify(await cleanupCapacityFixture(config, args.confirm!))}\n`);
return;
}
const tokens = args.tokens ? await loadTokens(args.tokens, workspaceRoot, config.capacity.authenticatedViewers) : null;
const tokens = args.tokens
? await loadTokens(args.tokens, workspaceRoot, config.capacity.authenticatedViewers)
: null;
if (args.command === 'dry-run') {
process.stdout.write(`${JSON.stringify({ valid: true, tokenFileValidated: tokens !== null, configSha256: sha256, plan: describeDryRun(config) }, null, 2)}\n`);
process.stdout.write(
`${JSON.stringify({ valid: true, tokenFileValidated: tokens !== null, configSha256: sha256, plan: describeDryRun(config) }, null, 2)}\n`
);
return;
}
assertRuntimeMetadataFinalized(config);
@@ -99,8 +146,13 @@ const main = async (): Promise<void> => {
await mkdir(path.dirname(output), { recursive: true });
const result = await runLoadTest({ config, configSha256: sha256, tokens: tokens!, workspaceRoot });
await writeFile(output, `${JSON.stringify(result, null, 2)}\n`, { encoding: 'utf8', flag: 'wx', mode: 0o600 });
const failedRequests = result.phases.reduce((total, phase) => total + Object.values(phase.metrics.http.errors).reduce((sum, count) => sum + count, 0), 0);
process.stdout.write(`${JSON.stringify({ completed: true, phases: result.phases.length, failedRequests, outputWritten: true })}\n`);
const failedRequests = result.phases.reduce(
(total, phase) => total + Object.values(phase.metrics.http.errors).reduce((sum, count) => sum + count, 0),
0
);
process.stdout.write(
`${JSON.stringify({ completed: true, phases: result.phases.length, failedRequests, outputWritten: true })}\n`
);
};
main().catch((error: unknown) => {