Streamline training tasks and add debugging guide

Reorganize the README checklist: fold the standalone
Ex-command task into earlier tasks, give the outline panel
its own bindings (g o / Ctrl+Shift+O), and add a dedicated
debugging task with breakpoint, stepping, and fault-finding
drills anchored to real lines in the training app.

Annotate the training app sources and tests with Chinese
practice hints (multi-cursor, macro, text-object, and
breakpoint spots).

Drop the redundant root tsconfig, since training/tsconfig.json
already covers src and tests, and remove the stale
LEADERBOARD.md left over from the deleted challenge mode.
This commit is contained in:
2026-09-09 23:54:48 +08:00
parent 715ddb958a
commit 3ff24e1ed5
14 changed files with 69 additions and 135 deletions
+7
View File
@@ -9,6 +9,11 @@ export interface Product {
unitPrice: number;
}
// ═════════════════════════════════════════════════════
// 下面 6 行 PRODUCTS 是练习区:
// 任务1 移动热身 / 任务7 多光标 ga / 任务9 宏 qa
// 每行还兼作 ciw / ci" / di( 的文本对象靶子
// ═════════════════════════════════════════════════════
export const PRODUCTS: Product[] = [
{ id: "apple", name: "Apple", unitPrice: 1.5 },
{ id: "banana", name: "Banana", unitPrice: 0.6 },
@@ -18,6 +23,8 @@ export const PRODUCTS: Product[] = [
{ id: "cheese", name: "Cheese", unitPrice: 9.9 },
];
// 练习:gd 跳回 PRODUCTS、gA 查引用;daf / yaf / cif 函数文本对象
// 光标放到下面函数名上按 ]d / ]m 也能用得上
export function findProduct(id: string): Product {
const product = PRODUCTS.find((p) => p.id === id);
if (!product) {
+1
View File
@@ -56,6 +56,7 @@ function main(argv: string[]): void {
console.log(`order #${id} shipped`);
break;
}
// 任务11:demo = 两单 → 发货 → 报表;调试时启动脚本参数就填 demo
case "demo": {
const one = createOrder([
{ productId: "apple", quantity: 12 },
+1
View File
@@ -18,6 +18,7 @@ export function available(productId: string): number {
return stock.get(productId) ?? 0;
}
// 预占库存:不够就抛 StockError —— cif 改函数体 / ci" 改错误消息的靶子
export function reserve(productId: string, quantity: number): void {
const left = available(productId);
if (quantity > left) {
+7 -6
View File
@@ -36,6 +36,7 @@ const orders: Order[] = [];
let nextId = 1;
export function createOrder(request: OrderRequest[]): Order {
// ← 任务11 调试断点位;cif 改写函数体
const lines: OrderLine[] = [];
for (const { productId, quantity } of request) {
@@ -46,13 +47,13 @@ export function createOrder(request: OrderRequest[]): Order {
name: product.name,
unitPrice: product.unitPrice,
quantity,
net: lineTotal(product, quantity),
net: lineTotal(product, quantity), // Step Into 步入点:跟进 pricing.ts
});
}
const subtotal = round2(lines.reduce((sum, line) => sum + line.net, 0));
const tax = round2(subtotal * TAX_RATE);
const shipping = shippingCost(subtotal);
const subtotal = round2(lines.reduce((sum, line) => sum + line.net, 0)); // ① 折后小计(未税)
const tax = round2(subtotal * TAX_RATE); // ② 税额 = 小计 × 8%(TAX_RATE)
const shipping = shippingCost(subtotal); // ③ 运费:满 50 免,否则 4.99
const order: Order = {
id: nextId++,
@@ -60,7 +61,7 @@ export function createOrder(request: OrderRequest[]): Order {
subtotal,
tax,
shipping,
total: round2(subtotal + tax + shipping),
total: round2(subtotal + tax + shipping), // ④ 总价 = ①+②+③
status: "new",
createdAt: new Date(),
};
@@ -79,7 +80,7 @@ export function listOrders(): Order[] {
export function shipOrder(id: number): Order {
const order = findOrder(id);
if (!order) {
throw new Error(`Order ${id} not found`);
throw new Error(`Order ${id} not found`); // ← ci" 改写这段错误消息的靶子
}
order.status = "shipped";
return order;
+3 -1
View File
@@ -17,6 +17,7 @@ export function round2(value: number): number {
/** 单行折后小计(未税):数量 × 单价,10 件以上 95 折 */
export function lineTotal(product: Product, quantity: number): number {
// cia / daa 参数文本对象练习区
const base = product.unitPrice * quantity;
const discount = quantity >= BULK_DISCOUNT_QTY ? base * BULK_DISCOUNT_RATE : 0;
return round2(base - discount);
@@ -24,5 +25,6 @@ export function lineTotal(product: Product, quantity: number): number {
/** 按“折后未税小计”判断是否免运费 */
export function shippingCost(subtotal: number): number {
return subtotal >= FREE_SHIPPING_THRESHOLD ? 0 : SHIPPING_FEE;
// 任务11 断点:看 subtotal 够不够 50
return subtotal >= FREE_SHIPPING_THRESHOLD ? 0 : SHIPPING_FEE; // ≥50 → 免运费 0,否则 4.99
}
+4
View File
@@ -4,6 +4,10 @@
import type { Order } from "./orders";
// ═══ class Receipt ═══════════════════════════════════════
// 类文本对象练习区:dac / yac / cic(整体删/复制/改类内部)
// 方法跳转:]m [m(方法名)、]M [M(方法结尾);字符串 ci" 靶子也在下面
// ═════════════════════════════════════════════════════════
export class Receipt {
constructor(public readonly order: Order) {}
+1
View File
@@ -34,6 +34,7 @@ export function topSellingProduct(
return best;
}
// 任务11 调试:demo 全流程最终在这里收口(断点 + 调用栈练习位)
export function reportSummary(): string[] {
const best = topSellingProduct();
const lines: string[] = [
+1
View File
@@ -1,3 +1,4 @@
// vitest 单测:catalog 相关用例,练完 ga / 宏之后用 npm run test 验证
import { describe, expect, it } from "vitest";
import { PRODUCTS, findProduct } from "../src/catalog";
+1
View File
@@ -1,3 +1,4 @@
// vitest 单测:任务11 的 f4 调试入口(选个用例跑,就能撞上 src 里的断点)
import { describe, expect, it, beforeEach } from "vitest";
import { createOrder, findOrder, listOrders, shipOrder } from "../src/orders";
import { available } from "../src/inventory";
+1
View File
@@ -1,3 +1,4 @@
// vitest 单测:pricing 相关用例,断点可设在 lineTotal / shippingCost 上
import { describe, expect, it } from "vitest";
import { round2, lineTotal, shippingCost } from "../src/pricing";
import { findProduct } from "../src/catalog";
+1
View File
@@ -1,3 +1,4 @@
// vitest 单测:Receipt 类相关用例,断点可设在 receipt.ts 的方法里
import { describe, expect, it } from "vitest";
import { Receipt } from "../src/receipt";
import { createOrder } from "../src/orders";