惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Docker
人人都是产品经理
人人都是产品经理
小众软件
小众软件
博客园 - Franky
WordPress大学
WordPress大学
Jina AI
Jina AI
Google DeepMind News
Google DeepMind News
I
InfoQ
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
F
Fortinet All Blogs
博客园 - 【当耐特】
IT之家
IT之家
G
Google Developers Blog
J
Java Code Geeks
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
有赞技术团队
有赞技术团队
V
Visual Studio Blog
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
月光博客
月光博客
GbyAI
GbyAI
雷峰网
雷峰网

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Three Test Levels for One CLI Subcommand
Deva · 2026-06-19 · via DEV Community

Deva

7 out of 7 tests pass. That number is boring and exactly correct.

Adding a CLI subcommand sounds trivial until you count the actual failure modes: the subparser is not wired up, the func is not registered, the dry run flag is silently swallowed, the argument parser crashes with a useless error. Any of those can bite you. The only way to know they do not is to test at three distinct levels, which is what this commit actually does.

Here is what wiring warmup eval looks like in practice.

The parser registration

argparse subcommands get wired in __main__.py by calling add_parser on the subparsers object, then setting set_defaults(func=cmd_warmup_eval). That last line is the critical one. If you forget it, args.func does not exist and every invocation blows up with an AttributeError that tells you nothing useful. The unit test covering this is two lines but it is the most important one in the file.

The dry run flag

, dry run is just add_argument(', dry run', action='store_true'). Fifteen seconds of work at the parser layer. The real discipline question is whether the flag is actually honored inside cmd_warmup_eval or silently accepted and then ignored. Wiring the flag is not the same as plumbing it through.

The test triangle

Three types, all necessary, none redundant.

Unit tests confirm the command function behaves correctly given controlled inputs, without touching the full argument parser or the shell.

Subparser tests confirm the parser tree is wired correctly: that python m x_engine warmup eval dispatches to cmd_warmup_eval and not to the default error handler. This is where set_defaults either proves itself or does not.

Subprocess acceptance tests confirm the whole thing actually runs when invoked from a shell, including the import chain, the argument parsing, and exit codes. This is the test that mirrors what a real user does. It is also the one that catches the failure mode where unit tests pass fine and then a missing import blows up at runtime because the module structure changed under you.

Skip any of the three and you have false confidence somewhere in the stack.

What I would do differently

The , dry run flag is wired at the parser and passes into cmd_warmup_eval. What the subprocess acceptance test checks is that the command exits cleanly with , dry run. It does not assert that , dry run actually changes behavior versus a live run. That means the flag could be a no op and the test still passes with a green check.

The fix is one extra assertion: capture stdout or a side effect that differs between dry and live modes, and verify the diff. Without it, the test proves the flag is accepted, not that it is respected. Those are different guarantees.

7/7 is the right score. Writing fewer tests would have been faster and worse.