'use strict'; // 黄金对照业务场景:只经 HTTP,覆盖三角色、跨三天的全部业务域。 // 每一节是一个独立函数,按顺序执行;节内用 ctx 共享上一节产生的 ID。 // s.get/post 默认期望 200;故意的拒绝写 expect。录制时出现非预期状态会拒绝写基线。 const D1 = '2026-11-18', D2 = '2026-11-19', D3 = '2026-11-20'; const START = D1; const PW = { owner: 'golden-owner-pass-2026', assistant: 'golden-assistant-pass-2026', assistant2: 'golden-assistant2-pass-2026', assistant2New: 'golden-assistant2-new-2026', assistantNew: 'golden-assistant-new-pass', staff: 'golden-staff-pass-2026', }; const NAMES = { owner: '麦麦', assistant: '娜娜', assistant2: '小昊' }; const ROLES = ['owner', 'assistant', 'assistant2']; const ACCOUNT = { owner: '麦麦微信', assistant: '助理微信', assistant2: '助理2微信' }; async function loginAll(s, ctx) { for (const role of ROLES) await s.post( role, '/api/login', { name: ctx.loginName[role], password: ctx.password[role] }, { label: 'login-' + role }, ); } // 打开“修改”上下文并按原输入提交修改。 async function editContext(s, actor, route) { return s.get(actor, route); } // 按当前双方应结余额登记一笔实际转账(金额取应结与 100 元的较小者)。 async function transfer(s, date, route, note) { const funds = await s.get('owner', '/api/team-funds?date=' + date, { label: 'team-funds-before-transfer' }); const pair = funds.pairs.find(row => row.due > 0); if (!pair) { s.problems.push('没有可结算的成员往来'); return; } const amount = (Math.min(pair.due, 10000) / 100).toFixed(2); await s.post( 'owner', route, { date, fromMember: pair.fromMember, toMember: pair.toMember, amount, revision: funds.revision, verified: true, note, }, { label: 'transfer' }, ); await s.post( 'owner', route, { date, fromMember: pair.fromMember, toMember: pair.toMember, amount, revision: funds.revision, verified: true, note, }, { label: 'transfer-stale-revision', expect: 409 }, ); } const sections = [ async function setupAndLogin(s, ctx) { await s.day(D1); await s.get(null, '/api/session', { label: 'anonymous-session' }); await s.get(null, '/api/state', { expect: 401, label: 'state-without-login' }); await s.post( null, '/api/setup', { ownerPassword: 'short', assistantPassword: 'short' }, { expect: 400, label: 'setup-short-password' }, ); await s.post('owner', '/api/setup', { ownerPassword: PW.owner, assistantPassword: PW.assistant, assistant2Password: PW.assistant2, }); await s.post( null, '/api/setup', { ownerPassword: PW.owner, assistantPassword: PW.assistant }, { expect: 403, label: 'setup-closed' }, ); await s.get('owner', '/api/session', { label: 'owner-session' }); await s.post('owner', '/api/logout', {}); await s.get('owner', '/api/state', { expect: 401, label: 'state-after-logout' }); await s.post( null, '/api/login', { name: '麦麦', password: 'wrong-password-123' }, { expect: 401, label: 'login-wrong-password' }, ); await s.post(null, '/api/demo-login', { role: 'owner' }, { expect: 401, label: 'demo-login-closed-in-trial' }); ctx.loginName = { owner: '麦麦', assistant: '助理1', assistant2: '助理2' }; ctx.password = { owner: PW.owner, assistant: PW.assistant, assistant2: PW.assistant2 }; await loginAll(s, ctx); await s.post( 'assistant', '/api/login', { name: '娜娜', password: PW.assistant }, { label: 'login-by-display-name' }, ); await s.post( 'assistant2', '/api/login', { member: 'assistant2', password: PW.assistant2 }, { label: 'login-by-member' }, ); for (const role of ROLES) await s.get(role, '/api/state', { label: 'initial-state-' + role }); await s.get(null, '/api/session', { label: 'anonymous-session-after-setup' }); }, async function shopSettingsAndPrinting(s, ctx) { const settings = await s.get('owner', '/api/shop-settings'); await s.get('assistant', '/api/shop-settings', { label: 'assistant-shop-settings' }); await s.post( 'assistant', '/api/shop-settings', { revision: settings.revision, storeName: '越权店名' }, { expect: 403 }, ); const saved = await s.post('owner', '/api/shop-settings', { revision: settings.revision, storeName: '黄金对照珠宝', receiptSubtitle: '黄金对照销售单', contact: '联系电话 000-0000', creditCardRatePermille: 6, feeDefaults: { shipping: '8', certificate: '4', packaging: '3', packagingPayer: 'owner' }, }); await s.post( 'owner', '/api/shop-settings', { revision: settings.revision, storeName: '过期版本' }, { expect: 409, label: 'shop-settings-stale' }, ); await s.post( 'owner', '/api/shop-settings', { revision: saved.shopSettings.revision, creditCardRatePermille: -1 }, { expect: 400, label: 'shop-settings-invalid' }, ); await s.post('owner', '/api/printing', { offsetX: 2, offsetY: 3 }); await s.post('assistant', '/api/printing', { offsetX: 9 }, { expect: 403 }); ctx.settingsRevision = (await s.get('owner', '/api/shop-settings', { label: 'shop-settings-after' })).revision; }, async function pockets(s, ctx) { for (const role of ROLES) await s.get(role, '/api/pockets', { label: 'pockets-' + role }); const created = await s.post('owner', '/api/pockets', { name: '展柜A' }); ctx.pocket = created.pocket; await s.post('assistant', '/api/pockets', { name: '越权货盘' }, { expect: 403 }); const renamed = await s.post('owner', '/api/pockets/' + encodeURIComponent(created.pocket.key) + '/update', { revision: created.pocket.revision, name: '展柜A(主)', }); await s.post( 'owner', '/api/pockets/' + encodeURIComponent(created.pocket.key) + '/update', { revision: created.pocket.revision, name: '过期改名' }, { expect: 409, label: 'pocket-stale' }, ); ctx.pocket = renamed.pocket; }, async function employeesAndPasswords(s, ctx) { const list = await s.get('owner', '/api/employees'); await s.get('assistant', '/api/employees', { expect: 403 }); const created = await s.post('owner', '/api/employees', { revision: list.revision ?? ctx.settingsRevision, label: '临时店员', loginName: 'temp-clerk', password: PW.staff, }); ctx.staff = created.employee; await s.post('staff', '/api/login', { name: 'temp-clerk', password: PW.staff }, { label: 'login-staff' }); await s.get('staff', '/api/state', { label: 'staff-state' }); let current = await s.get('owner', '/api/employees', { label: 'employees-after-create' }); await s.post('owner', '/api/employees/' + ctx.staff.member + '/update', { revision: current.revision, label: '临时店员甲', }); current = await s.get('owner', '/api/employees', { label: 'employees-after-update' }); await s.post('owner', '/api/employees/' + ctx.staff.member + '/deactivate', { revision: current.revision, verified: true, }); await s.get('staff', '/api/state', { expect: 401, label: 'staff-after-deactivate' }); current = await s.get('owner', '/api/employees', { label: 'employees-after-deactivate' }); await s.post('owner', '/api/employees/' + ctx.staff.member + '/reactivate', { revision: current.revision, verified: true, }); current = await s.get('owner', '/api/employees', { label: 'employees-after-reactivate' }); await s.post('owner', '/api/employees/' + ctx.staff.member + '/delete', { revision: current.revision, verified: true, }); await s.get('owner', '/api/employees', { label: 'employees-after-delete' }); await s.get('owner', '/api/team-members'); // 成员密码:老板为小昊设置新密码;店员修改本人密码。 await s.post( 'assistant', '/api/team-members/assistant2/password', { password: PW.assistant2New, verified: true }, { expect: 403 }, ); await s.post( 'owner', '/api/team-members/assistant2/password', { password: 'short', verified: true }, { expect: 400, label: 'member-password-short' }, ); await s.post('owner', '/api/team-members/assistant2/password', { password: PW.assistant2New, verified: true }); ctx.password.assistant2 = PW.assistant2New; await s.post( 'assistant2', '/api/login', { name: '小昊', password: PW.assistant2New }, { label: 'login-assistant2-new-password' }, ); await s.post( 'assistant', '/api/password', { current: 'wrong-current-pass', password: PW.assistantNew }, { expect: 400, label: 'password-wrong-current' }, ); await s.post('assistant', '/api/password', { current: PW.assistant, password: PW.assistantNew }); ctx.password.assistant = PW.assistantNew; await s.get('assistant', '/api/state', { expect: 401, label: 'state-after-own-password-change' }); await s.post( 'assistant', '/api/login', { name: '娜娜', password: PW.assistantNew }, { label: 'login-assistant-new-password' }, ); }, async function openingStock(s, ctx) { await s.post('owner', '/api/stock', { date: D1, kind: 'opening', pocket: '现货', grams: '100', note: '黄金对照起始库存', }); await s.post('owner', '/api/stock', { date: D1, kind: 'opening', pocket: '金料', grams: '50', note: '黄金对照起始金料', }); await s.post('owner', '/api/stock', { date: D1, kind: 'opening', pocket: ctx.pocket.key, grams: '20', note: '展柜起始', }); await s.post('owner', '/api/stock', { date: D1, kind: 'transfer', pocket: '现货', to: '金料', grams: '5', note: '调拨', }); const inc = await s.post('assistant', '/api/stock', { date: D1, kind: 'increase', pocket: '现货', grams: '2.5', note: '娜娜手动入库', }); ctx.assistantMovement = inc; const dec = await s.post('assistant', '/api/stock', { date: D1, kind: 'decrease', pocket: '现货', grams: '0.5', note: '娜娜手动出库', }); ctx.assistantMovement2 = dec; await s.post( 'assistant2', '/api/stock', { date: D1, kind: 'opening', pocket: '现货', grams: '1' }, { expect: 403, label: 'assistant-opening-denied' }, ); await s.get('owner', '/api/inventory', { label: 'inventory-d1' }); const movements = await s.get('owner', '/api/inventory/movements', { label: 'movements-d1' }); const byGroup = group => movements.movements.find(row => row.group_id === group).id; ctx.assistantMovement = { id: byGroup(inc.group) }; ctx.assistantMovement2 = { id: byGroup(dec.group) }; }, async function materialPurchasesD1(s, ctx) { const a = await s.post('assistant', '/api/material-purchases', { date: D1, grams: '10', total: '9000', payer: 'assistant', allocations: [{ member: 'assistant', amount: '9000' }], note: '娜娜购料', }); ctx.purchaseA = a; const o = await s.post('owner', '/api/material-purchases', { date: D1, grams: '20', total: '18200', payer: 'owner', note: '麦麦购料', }); ctx.purchaseO = o; await s.get('owner', '/api/material-pools', { label: 'material-pools-d1' }); await s.get('assistant', '/api/material-pools/' + D1, { label: 'material-pool-detail-assistant' }); await s.get('owner', '/api/material-purchases/' + a.id, { label: 'purchase-detail' }); await s.post( 'assistant', '/api/material-pools/quote', { member: 'assistant', date: D1, entries: [{ lineIndex: 0, poolId: D1, mg: 3000 }] }, { key: null, label: 'material-pool-quote' }, ); }, async function ordersD1(s, ctx) { await s.get('assistant', '/api/paper-number', { label: 'paper-number' }); await s.get('owner', '/api/paper-number?date=' + D1, { label: 'paper-number-date' }); // 1) 按克自动计价 + 附加项目 + 分项成本 + 直接费用(娜娜) const perGram = { date: D1, customer: '对照客户甲', internal_note: '#复购 内部备注', salesperson: '娜娜', payment_account: '助理微信', rounding_mode: 'yuan', discount: '0', lines: [ { name: '足金999', unit: 'g', quantity: '3.250', pocket: '现货', payer: 'assistant', pricingMode: 'auto', goldPrice: '950', laborRate: '30', laborMode: 'gram', pieces: '1', charges: [ { name: '刻字', amount: '20' }, { name: '包装', amount: '5.5' }, ], costParts: { material: '', labor: '40', accessories: '2', other: '0' }, costMaterial: { mode: 'gram', rate: '880' }, costLabor: { mode: 'total' }, costPayers: { material: 'owner', labor: 'assistant' }, }, ], fee_items: [{ key: 'shipping', note: '快递', amount: '12', payer: 'assistant' }], note: '客户单备注', }; ctx.orderPerGram = (await s.post('assistant', '/api/orders/issue', perGram, { label: 'issue-per-gram' })).id; // 2) 按件计价(件工费)+ 整单优惠 + 分位取整(小昊) const perPiece = { date: D1, customer: '对照客户乙', internal_note: '按件内部备注', salesperson: '小昊', payment_account: '助理2支付宝', rounding_mode: 'cent', discount: '15.37', lines: [ { name: '足金999', unit: 'g', quantity: '2', pocket: '现货', payer: 'assistant2', pricingMode: 'auto', goldPrice: '955.55', laborRate: '88', laborMode: 'piece', pieces: '2', cost: '1800', }, { name: '纯银925', unit: '件', quantity: '3', pocket: '', payer: 'assistant2', sale: '99.9', cost: '30' }, ], fee_items: [], }; ctx.orderPerPiece = (await s.post('assistant2', '/api/orders/issue', perPiece, { label: 'issue-per-piece' })).id; // 3) 一口价 + 信用卡收款 + 元取整(麦麦为娜娜开单) const fixed = { date: D1, member: 'assistant', customer: '对照客户丙', internal_note: '一口价备注', salesperson: '麦麦', payment_account: '麦麦信用卡', credit_card_fee_payer: 'owner', rounding_mode: 'yuan', discount: '3', lines: [ { name: '金镶玉吊坠', unit: '件', quantity: '1', pocket: '', payer: 'owner', sale: '2888.4', cost: '1500', priceNote: '一口价', }, ], fee_items: [], }; ctx.orderFixed = (await s.post('owner', '/api/orders/issue', fixed, { label: 'issue-fixed-credit-card' })).id; // 4) 关联日购料池(娜娜) const pooled = { date: D1, customer: '对照客户丁', internal_note: '料池单备注', salesperson: '娜娜', payment_account: '助理现金', rounding_mode: 'cent', discount: '0', lines: [ { name: '足金999', unit: 'g', quantity: '3', pocket: '', payer: 'assistant', pricingMode: 'manual', sale: '3300', costParts: { material: '', labor: '0', accessories: '0', other: '0' }, costMaterial: { mode: 'pool', poolId: D1 }, }, ], fee_items: [], }; ctx.orderPool = (await s.post('assistant', '/api/orders/issue', pooled, { label: 'issue-material-pool' })).id; // 5) 先保存草稿再开单(麦麦) const draft = { date: D1, customer: '对照草稿客户', internal_note: '草稿单备注', salesperson: '麦麦', payment_account: '麦麦现金', lines: [ { name: '足金手镯', unit: 'g', quantity: '10', pocket: ctx.pocket.key, payer: 'owner', sale: '9800', cost: '9000', }, ], fee_items: [], }; const saved = await s.post('owner', '/api/orders', draft, { label: 'save-draft' }); ctx.orderDraft = saved.id; const draftDetail = await s.get('owner', '/api/orders/' + saved.id, { label: 'draft-detail' }); await s.post( 'owner', '/api/orders/issue', { ...draft, id: saved.id, revision: draftDetail.revision }, { label: 'issue-from-draft' }, ); // 6) 小昊第二单:用于取消申请 ctx.orderCancel = ( await s.post( 'assistant2', '/api/orders/issue', { date: D1, customer: '对照取消客户', internal_note: '取消单备注', salesperson: '小昊', payment_account: '助理2现金', rounding_mode: 'cent', lines: [ { name: '足金戒指', unit: 'g', quantity: '1.5', pocket: '现货', payer: 'assistant2', sale: '1500', cost: '1300', }, ], fee_items: [], }, { label: 'issue-to-cancel' }, ) ).id; // 6b) 小昊整单按克黄金:用于订单售后 ctx.orderAfterSale = ( await s.post( 'assistant2', '/api/orders/issue', { date: D1, customer: '对照售后订单客户', internal_note: '售后单备注', salesperson: '小昊', payment_account: '助理2微信', rounding_mode: 'cent', lines: [ { name: '足金手链', unit: 'g', quantity: '5', pocket: '现货', payer: 'assistant2', sale: '5000', costParts: { material: '4400', labor: '100', accessories: '0', other: '0' }, }, ], fee_items: [], }, { label: 'issue-for-after-sale' }, ) ).id; // 7) 娜娜第三单:用于驳回的修改申请与归属变更 ctx.orderReject = ( await s.post( 'assistant', '/api/orders/issue', { date: D1, customer: '对照驳回客户', internal_note: '驳回单备注', salesperson: '娜娜', payment_account: '助理支付宝', rounding_mode: 'cent', lines: [ { name: '足金耳钉', unit: 'g', quantity: '0.8', pocket: '现货', payer: 'assistant', sale: '820', cost: '700', }, ], fee_items: [], }, { label: 'issue-to-reject' }, ) ).id; // 8) 分步生命周期:草稿 → 确认 → 部分收款 → 补收款 → 交付(麦麦) const step = { date: D1, customer: '对照分步客户', internal_note: '分步单备注', salesperson: '麦麦', payment_account: '麦麦支付宝', rounding_mode: 'cent', lines: [ { name: '足金项链', unit: 'g', quantity: '4', pocket: '现货', payer: 'owner', sale: '4000', cost: '3500' }, ], fee_items: [], }; ctx.orderSteps = (await s.post('owner', '/api/orders', step, { label: 'save-draft-steps' })).id; let o = await s.get('owner', '/api/orders/' + ctx.orderSteps, { label: 'steps-draft' }); await s.post('owner', '/api/orders/' + ctx.orderSteps + '/confirm', { date: D1 }, { label: 'steps-confirm' }); o = await s.get('owner', '/api/orders/' + ctx.orderSteps, { label: 'steps-confirmed' }); await s.post( 'owner', '/api/orders/' + ctx.orderSteps + '/receipt', { date: D1, amount: '1000', account: '麦麦支付宝', verified: true, reference: '定金' }, { label: 'steps-receipt-deposit' }, ); await s.post( 'owner', '/api/orders/' + ctx.orderSteps + '/receipt', { date: D1, amount: '99999', account: '麦麦支付宝', verified: true }, { expect: 400, label: 'steps-receipt-too-much' }, ); await s.post( 'owner', '/api/orders/' + ctx.orderSteps + '/receipt', { date: D1, amount: '3000', account: '麦麦信用卡', credit_card_fee_payer: 'owner', verified: true, reference: '尾款', }, { label: 'steps-receipt-balance' }, ); await s.post( 'owner', '/api/orders/' + ctx.orderSteps + '/complete', { date: D1, verified: true }, { label: 'steps-complete' }, ); await s.get('owner', '/api/orders/' + ctx.orderSteps, { label: 'steps-delivered' }); // 校验失败的开单不落库 await s.post( 'assistant', '/api/orders/issue', { ...perGram, lines: [{ ...perGram.lines[0], quantity: '-1' }] }, { expect: 400, label: 'issue-invalid-quantity' }, ); for (const id of [ctx.orderPerGram, ctx.orderPerPiece, ctx.orderFixed, ctx.orderPool, ctx.orderDraft]) await s.get('owner', '/api/orders/' + id, { label: 'order-detail' }); await s.get('assistant', '/api/orders/' + ctx.orderPerGram + '/public', { label: 'order-public' }); await s.get('owner', '/api/order-note-tags'); await s.get('assistant', '/api/order-note-tags', { label: 'order-note-tags-assistant' }); }, async function printing(s, ctx) { const html = await s.getRaw('assistant', '/print/' + ctx.orderPerGram, { label: 'print-order' }); await s.getRaw('owner', '/print/' + ctx.orderFixed + '?mode=customer', { label: 'print-order-mode' }); const status = await s.get('assistant', '/api/print-status/order/' + ctx.orderPerGram); await s.post('assistant', '/api/print-status/order/' + ctx.orderPerGram, { printed: true, revision: status.revision, sourceRevision: status.sourceRevision, }); const after = await s.get('assistant', '/api/print-status/order/' + ctx.orderPerGram, { label: 'print-status-after', }); await s.post( 'assistant', '/api/print-status/order/' + ctx.orderPerGram, { printed: false, revision: after.revision, sourceRevision: after.sourceRevision }, { label: 'print-status-unset' }, ); await s.get('assistant2', '/api/print-status/order/' + ctx.orderPerGram, { expect: 404, label: 'print-status-foreign', }); await s.getRaw('assistant2', '/print/' + ctx.orderPerGram, { expect: 404, label: 'print-foreign' }); return html; }, async function priceLocksD1(s, ctx) { const creation = (extra = {}) => ({ date: D1, member: 'assistant', customer: '对照锁价客户', salesperson: '娜娜', note: '锁价备注', line: { name: '足金999', quantity: '3.000', goldPrice: '900', laborRate: '20', laborMode: 'gram', pieces: '1', charges: [], }, discount: '0', payment: { amount: '2700', account: '助理微信', verified: true }, material: { rate: '850', payer: 'owner', verified: true }, ...extra, }); ctx.lockA = (await s.post('assistant', '/api/price-locks', creation(), { label: 'lock-create' })).id; ctx.lockB = ( await s.post( 'assistant', '/api/price-locks', creation({ customer: '对照锁价客户二', payment: { amount: '1000', account: '助理支付宝', verified: true } }), { label: 'lock-create-2' }, ) ).id; ctx.lockC = ( await s.post( 'assistant2', '/api/price-locks', creation({ member: 'assistant2', salesperson: '小昊', customer: '对照锁价客户三', payment: { amount: '500', account: '助理2微信', verified: true }, material: { rate: '860', payer: 'assistant2', verified: true }, }), { label: 'lock-create-3' }, ) ).id; ctx.lockD = ( await s.post( 'owner', '/api/price-locks', creation({ member: 'owner', salesperson: '麦麦', customer: '对照锁价客户四', payment: { amount: '800', account: '麦麦微信', verified: true }, }), { label: 'lock-create-owner' }, ) ).id; await s.get('assistant', '/api/price-locks', { label: 'price-locks-assistant' }); await s.get('owner', '/api/price-locks?status=all', { label: 'price-locks-owner-all' }); await s.get('assistant', '/api/price-locks/' + ctx.lockA); await s.get('assistant2', '/api/price-locks/' + ctx.lockA + '/edit-context', { expect: 404, label: 'lock-foreign', }); // 当天直接修改(同日店员可直改) const context = await s.get('assistant', '/api/price-locks/' + ctx.lockB + '/edit-context'); await s.post( 'assistant', '/api/price-locks/' + ctx.lockB + '/edit', { ...context.inputs, revision: context.revision, reason: '当天更正收款', verified: true, payment: { ...context.inputs.payment, amount: '1200' }, }, { label: 'lock-edit-same-day' }, ); }, async function afterSalesStandalone(s, ctx) { const created = await s.post('assistant', '/api/after-sales', { date: D1, project: '对照改圈', customer: '对照售后客户', amount: '8.50', payer: 'assistant', }); ctx.afterSale = created.after_sale_id; await s.get('assistant', '/api/after-sales/' + ctx.afterSale); await s.get('assistant2', '/api/after-sales/' + ctx.afterSale, { expect: 404, label: 'after-sale-foreign' }); await s.post( 'owner', '/api/after-sales', { date: D1, project: '对照清洗', customer: '对照售后客户二', amount: '0', payer: 'owner' }, { label: 'after-sale-owner-zero' }, ); await s.post( 'assistant', '/api/after-sales', { date: D1, project: '对照改圈', customer: '对照售后客户', amount: '-1', payer: 'assistant' }, { expect: 400, label: 'after-sale-invalid' }, ); }, async function templates(s, ctx) { const preset = { customer: '', salesperson: '娜娜', payment_account: '助理微信', discount: '0', rounding_mode: 'cent', lines: [ { name: '足金999', unit: 'g', quantity: '1', pocket: '现货', payer: 'assistant', pricingMode: 'auto', goldPrice: '950', laborMode: 'gram', laborRate: '30', pieces: '1', charges: [], costParts: { material: '880', labor: '20', accessories: '0', other: '0' }, }, ], fee_items: [], }; const t = await s.post('owner', '/api/order-templates', { name: '对照常用模板', member: 'assistant', preset }); ctx.template = t.id || t.template?.id; await s.get('owner', '/api/order-templates'); await s.get('assistant', '/api/order-templates', { label: 'order-templates-assistant' }); await s.get('owner', '/api/order-templates/' + ctx.template); const current = await s.get('owner', '/api/order-templates/' + ctx.template, { label: 'template-before-update' }); await s.post('owner', '/api/order-templates/' + ctx.template + '/update', { name: '对照常用模板(改)', member: 'assistant', preset, revision: current.revision, }); const t2 = await s.post( 'assistant', '/api/order-templates', { name: '娜娜自建模板', member: 'assistant', preset }, { label: 'template-assistant' }, ); const id2 = t2.id || t2.template?.id; const c2 = await s.get('assistant', '/api/order-templates/' + id2, { label: 'template2' }); await s.post( 'assistant', '/api/order-templates/' + id2 + '/delete', { revision: c2.revision }, { label: 'template-delete' }, ); await s.get('owner', '/api/order-templates', { label: 'order-templates-final' }); }, async function fundsD1(s, ctx) { const r = await s.post('assistant', '/api/reimbursements', { date: D1, items: [ { name: '对照邮寄', amount: '15', member: 'owner', sourceType: 'independent' }, { name: '对照包装', amount: '6.5', member: 'owner', sourceType: 'independent' }, ], note: '对照报销', }); ctx.reimbursement = r.id; await s.get('assistant', '/api/reimbursements', { label: 'reimbursements-assistant' }); await s.get('owner', '/api/reimbursements?status=pending', { label: 'reimbursements-pending' }); await s.get('assistant', '/api/reimbursement-funding-options?date=' + D1, { label: 'reimbursement-options' }); await s.post( 'assistant', '/api/reimbursements/' + r.id + '/update', { date: D1, items: [ { name: '对照邮寄', amount: '15', member: 'owner', sourceType: 'independent' }, { name: '对照包装', amount: '6.5', member: 'owner', sourceType: 'independent' }, ], note: '补充备注', revision: 1, }, { label: 'reimbursement-update' }, ); await s.post( 'assistant', '/api/reimbursements/' + r.id + '/approve', { revision: 2, verified: true }, { expect: 403, label: 'reimbursement-self-approve' }, ); await s.post('owner', '/api/reimbursements/' + r.id + '/approve', { revision: 2, verified: true }); const r2 = await s.post( 'assistant2', '/api/reimbursements', { date: D1, items: [{ name: '对照快递', amount: '9', member: 'owner', sourceType: 'independent' }] }, { label: 'reimbursement-2' }, ); await s.post( 'owner', '/api/reimbursements/' + r2.id + '/reject', { revision: 1, note: '凭据不全' }, { label: 'reimbursement-reject' }, ); const daily = await s.get('owner', '/api/daily-funds?date=' + D1); await s.get('assistant', '/api/daily-funds?date=' + D1, { label: 'daily-funds-assistant' }); await s.post( 'owner', '/api/daily-funds/confirm', { date: D1, amount: '0', revision: daily.revision ?? 0, sourceRevision: daily.sources?.revision, verified: true }, { expect: 'any', label: 'daily-outlay-confirm' }, ); await transfer(s, D1, '/api/team-funds/transfers', '对照转账'); await s.post( 'assistant', '/api/team-funds/transfers', { date: D1, fromMember: 'assistant', toMember: 'owner', amount: '1', verified: true }, { expect: 403, label: 'transfer-assistant-denied' }, ); await s.get('owner', '/api/team-funds?date=' + D1); await s.get('assistant', '/api/team-funds?date=' + D1, { expect: 403, label: 'team-funds-assistant-denied' }); }, async function peopleAndPrivate(s, ctx) { const pc = await s.get('owner', '/api/people-count?date=' + D1); await s.post('owner', '/api/people-count', { date: D1, count: 12, assistant1Count: 5, assistant2Count: 3, revision: pc.revision, }); await s.get('owner', '/api/people-count-history'); await s.get('assistant', '/api/people-count?date=' + D1, { expect: 403, label: 'people-count-assistant-denied' }); await s.post('owner', '/api/private-operations/people', { date: D1, member: 'assistant', total_count: 100, new_count: 10, revision: 0, }); await s.get('owner', '/api/private-operations', { label: 'private-ops' }); await s.get('owner', '/api/private-operations/people?date=' + D1 + '&member=assistant', { label: 'private-ops-entry', }); await s.get('owner', '/api/private-operations/people-history?member=assistant', { label: 'private-ops-history' }); await s.get('assistant', '/api/private-operations', { expect: 403, label: 'private-ops-assistant-denied' }); }, async function inventoryReviewAndCloseD1(s, ctx) { const inv = await s.get('owner', '/api/inventory', { label: 'inventory-before-review' }); await s.post('owner', '/api/inventory/review', { date: D1, verified: true, revision: inv.revision }); await s.get('owner', '/api/inventory/snapshots'); await s.post( 'assistant', '/api/close', { date: D1, basis: 'orderDate' }, { expect: 403, label: 'close-assistant-denied' }, ); await s.post('owner', '/api/close', { date: D1, basis: 'wrong' }, { expect: 400, label: 'close-invalid-basis' }); await s.post('owner', '/api/close', { date: D1, basis: 'orderDate' }, { label: 'close-d1' }); await s.get('owner', '/api/report?date=' + D1 + '&basis=orderDate', { label: 'report-d1-owner' }); }, // ───────── 第二天:跨天申请与审批 ───────── async function dayTwoLogin(s, ctx) { await s.day(D2); await s.get('owner', '/api/state', { expect: 401, label: 'session-expired-next-day' }); await loginAll(s, ctx); }, async function inventoryApprovals(s, ctx) { const id = ctx.assistantMovement.id || ctx.assistantMovement.movementId; const detail = await s.get('assistant', '/api/inventory/movements/' + id); await s.get('assistant2', '/api/inventory/movements/' + id, { expect: 404, label: 'movement-foreign' }); const req = await s.post( 'assistant', '/api/inventory/movements/' + id + '/update', { ...detail.values, revision: detail.revision, grams: '3', reason: '跨天更正克重' }, { label: 'movement-update-request' }, ); ctx.inventoryRequest = req.requestId; await s.get('assistant', '/api/inventory/changes', { label: 'inventory-changes-assistant' }); const request = await s.get('owner', '/api/inventory/changes/' + req.requestId); await s.post( 'assistant', '/api/inventory/changes/' + req.requestId + '/approve', { revision: request.revision, inventoryRevision: request.inventoryRevision, verified: true }, { expect: 403, label: 'inventory-self-approve' }, ); await s.post( 'owner', '/api/inventory/changes/' + req.requestId + '/approve', { revision: request.revision, inventoryRevision: request.inventoryRevision, verified: true }, { label: 'inventory-approve' }, ); const id2 = ctx.assistantMovement2.id || ctx.assistantMovement2.movementId; const d2 = await s.get('assistant', '/api/inventory/movements/' + id2, { label: 'movement2' }); const del = await s.post( 'assistant', '/api/inventory/movements/' + id2 + '/delete', { revision: d2.revision, reason: '跨天删除申请', verified: true }, { label: 'movement-delete-request' }, ); const r2 = await s.get('owner', '/api/inventory/changes/' + del.requestId, { label: 'inventory-delete-request' }); await s.post( 'owner', '/api/inventory/changes/' + del.requestId + '/reject', { revision: r2.revision, note: '保留原记录' }, { label: 'inventory-reject' }, ); // 当天本人手动库存直接生效 const today = await s.post( 'assistant', '/api/stock', { date: D2, kind: 'increase', pocket: '金料', grams: '1', note: '当天手动入库' }, { label: 'stock-same-day' }, ); const list = await s.get('assistant', '/api/inventory/movements', { label: 'movements-assistant-d2' }); const tid = list.movements.find(row => row.group_id === today.group).id; const td = await s.get('assistant', '/api/inventory/movements/' + tid, { label: 'movement-same-day' }); await s.post( 'assistant', '/api/inventory/movements/' + tid + '/update', { ...td.values, revision: td.revision, grams: '1.2', reason: '当天更正' }, { label: 'movement-update-direct' }, ); // 老板直接删除 const od = await s.get('owner', '/api/inventory/movements/' + tid, { label: 'movement-owner-view' }); await s.post( 'owner', '/api/inventory/movements/' + tid + '/delete', { revision: od.revision, reason: '老板删除', verified: true }, { label: 'movement-delete-owner' }, ); await s.get('owner', '/api/inventory/changes?status=all', { label: 'inventory-changes-all' }); }, async function orderChangesAndApprovals(s, ctx) { const route = '/api/orders/' + ctx.orderPerGram; const info = await s.get('assistant', route + '/edit', { label: 'order-edit-context' }); const body = { ...info.inputs, revision: info.revision, reason: '跨天修改客户名', verified: true, customer: '对照客户甲(改)', }; await s.post('assistant', route + '/edit', body, { expect: 403, label: 'order-edit-cross-day-denied' }); const change = await s.post('assistant', route + '/change', body, { label: 'order-change-request' }); await s.get('assistant', route + '/change', { label: 'order-change-context' }); await s.get('owner', '/api/order-changes', { label: 'order-changes-list' }); const req = await s.get('owner', '/api/order-changes/' + change.requestId, { label: 'order-change-detail' }); await s.post( 'assistant', '/api/order-changes/' + change.requestId + '/approve', { revision: info.revision, verified: true, note: '自批' }, { expect: 403, label: 'order-change-self-approve' }, ); await s.post( 'owner', '/api/order-changes/' + change.requestId + '/approve', { revision: 0, verified: true, note: '旧版本' }, { expect: 409, label: 'order-change-stale' }, ); await s.post( 'owner', '/api/order-changes/' + change.requestId + '/approve', { revision: req.order_revision ?? info.revision, verified: true, note: '凭据已核对' }, { label: 'order-change-approve' }, ); // 驳回的修改申请 const r2 = ctx.orderReject; const info2 = await s.get('assistant', '/api/orders/' + r2 + '/edit', { label: 'order-edit-context-2' }); const ch2 = await s.post( 'assistant', '/api/orders/' + r2 + '/change', { ...info2.inputs, revision: info2.revision, reason: '想改售价', verified: true, lines: info2.inputs.lines.map(l => ({ ...l, sale: '800' })), }, { label: 'order-change-request-2' }, ); await s.post( 'owner', '/api/order-changes/' + ch2.requestId + '/reject', { note: '售价无误' }, { label: 'order-change-reject' }, ); // 补记费用申请(action) const info3 = await s.get('assistant', '/api/orders/' + ctx.orderPool + '/change', { label: 'order-change-actions', }); const exp = await s.post( 'assistant', '/api/orders/' + ctx.orderPool + '/change', { action: 'expense', date: D2, revision: info3.revision, reason: '补记快递', verified: true, amount: '10', payer: 'assistant', note: '补寄快递', }, { label: 'order-expense-request' }, ); await s.post( 'owner', '/api/order-changes/' + exp.requestId + '/approve', { revision: info3.revision, verified: true, note: '核实' }, { label: 'order-expense-approve' }, ); // 老板直接修改历史订单 const oi = await s.get('owner', '/api/orders/' + ctx.orderFixed + '/edit', { label: 'owner-edit-context' }); await s.post( 'owner', '/api/orders/' + ctx.orderFixed + '/edit', { ...oi.inputs, revision: oi.revision, reason: '老板更正备注', verified: true, note: '老板改备注' }, { label: 'owner-edit-order' }, ); // 取消申请 + 批准 const ci = await s.get('assistant2', '/api/orders/' + ctx.orderCancel + '/cancellation', { label: 'cancellation-context', }); const cr = await s.post( 'assistant2', '/api/orders/' + ctx.orderCancel + '/cancellation', { revision: ci.revision, reason: '重复录入' }, { label: 'cancellation-request' }, ); await s.get('owner', '/api/order-cancellations', { label: 'cancellations-list' }); const cd = await s.get('owner', '/api/order-cancellations/' + cr.requestId, { label: 'cancellation-detail' }); await s.post( 'assistant2', '/api/order-cancellations/' + cr.requestId + '/approve', { revision: ci.revision, verified: true, note: '自批' }, { expect: 403, label: 'cancellation-self-approve' }, ); await s.post( 'owner', '/api/order-cancellations/' + cr.requestId + '/approve', { revision: cd.order_revision ?? ci.revision, verified: true, note: '核对原单后确认' }, { label: 'cancellation-approve' }, ); // 取消后的实际退款(麦麦) const cancelled = await s.get('owner', '/api/orders/' + ctx.orderCancel, { label: 'cancelled-order' }); await s.post( 'owner', '/api/orders/' + ctx.orderCancel + '/refund', { date: D2, amount: (cancelled.netReceived / 100).toFixed(2), account: '助理2现金', verified: true, reference: '退回客户', }, { expect: 409, label: 'refund-cancelled-voided' }, ); // 归属变更:老板直接改归属到小昊 const own = await s.get('owner', '/api/orders/' + ctx.orderReject + '/ownership', { label: 'ownership-context' }); await s.post( 'owner', '/api/orders/' + ctx.orderReject + '/ownership', { member: 'assistant2', revision: own.revision, reason: '核实业务归属', verified: true }, { label: 'ownership-direct' }, ); await s.get('assistant', '/api/orders/' + ctx.orderReject, { expect: 404, label: 'order-after-ownership-old-owner', }); await s.get('assistant2', '/api/orders/' + ctx.orderReject, { label: 'order-after-ownership-new-owner' }); // 店员申请归属变更 → 老板驳回 const own2 = await s.get('assistant', '/api/orders/' + ctx.orderFixed + '/ownership', { label: 'ownership-context-assistant', }); const or = await s.post( 'assistant', '/api/orders/' + ctx.orderFixed + '/ownership', { member: 'assistant2', revision: own2.revision, reason: '申请转给小昊', verified: true }, { label: 'ownership-request' }, ); await s.get('owner', '/api/order-ownership-changes', { label: 'ownership-changes-list' }); await s.get('owner', '/api/order-ownership-changes/' + or.requestId, { label: 'ownership-change-detail' }); await s.post( 'owner', '/api/order-ownership-changes/' + or.requestId + '/reject', { note: '不转' }, { label: 'ownership-reject' }, ); const ci2 = await s.get('assistant', '/api/orders/' + ctx.orderPool + '/cancellation', { label: 'cancellation-context-2', }); const cr2 = await s.post( 'assistant', '/api/orders/' + ctx.orderPool + '/cancellation', { revision: ci2.revision, reason: '客户想退' }, { label: 'cancellation-request-2' }, ); await s.post( 'owner', '/api/order-cancellations/' + cr2.requestId + '/reject', { note: '已交付不取消' }, { label: 'cancellation-reject' }, ); }, async function orderAfterSale(s, ctx) { const id = ctx.orderAfterSale, route = '/api/orders/' + id; await s.get('assistant2', route + '/after-sale', { label: 'order-after-sale-context' }); const detail = await s.get('assistant2', route, { label: 'order-before-after-sale' }); const body = { date: D2, revision: detail.revision, verified: true, reason: '客户退回一件', afterSale: { lines: [{ lineIndex: 0, quantity: '1.000', pocket: '金料', disposition: 'scrap' }], refund: { amount: '900', account: '助理2支付宝', payer: 'assistant2' }, deductionReason: '客户确认扣费', expenses: [], }, }; await s.post('assistant2', route + '/after-sale-preview', body, { key: null, label: 'after-sale-preview' }); const req = await s.post( 'assistant2', route + '/change', { ...body, action: 'return' }, { label: 'after-sale-request' }, ); await s.get('owner', '/api/order-changes/' + req.requestId, { label: 'after-sale-request-detail' }); await s.post( 'owner', '/api/order-changes/' + req.requestId + '/approve', { revision: detail.revision, verified: true, note: '实物已收回' }, { label: 'after-sale-approve' }, ); await s.get('assistant2', '/api/returned-stock-lots?date=' + D2, { label: 'returned-stock-lots' }); await s.get('assistant2', route + '/after-sale', { label: 'order-after-sale-after' }); // 售后单修改与审批(独立售后跨天修改需申请) const as = await s.get('assistant', '/api/after-sales/' + ctx.afterSale, { label: 'after-sale-detail-d2' }); const up = await s.post( 'assistant', '/api/after-sales/' + ctx.afterSale + '/update', { ...as.values, revision: as.revision, amount: '9.50', reason: '金额录错' }, { label: 'after-sale-update-request' }, ); await s.get('owner', '/api/after-sales/changes', { label: 'after-sale-changes' }); const rid = up.requestId || up.id; await s.get('owner', '/api/after-sales/changes/' + rid, { label: 'after-sale-change-detail' }); await s.post( 'owner', '/api/after-sales/changes/' + rid + '/approve', { revision: 1, note: '核实', verified: true }, { label: 'after-sale-change-approve' }, ); const as2 = await s.get('assistant', '/api/after-sales/' + ctx.afterSale, { label: 'after-sale-detail-after-approve', }); const up2 = await s.post( 'assistant', '/api/after-sales/' + ctx.afterSale + '/update', { ...as2.values, revision: as2.revision, amount: '12', reason: '再次调整' }, { label: 'after-sale-update-request-2' }, ); await s.post( 'owner', '/api/after-sales/changes/' + (up2.requestId || up2.id) + '/reject', { revision: 1, note: '金额无误' }, { label: 'after-sale-change-reject' }, ); }, async function priceLocksD2(s, ctx) { // 跨天店员修改须申请 → 老板批准 const c = await s.get('assistant', '/api/price-locks/' + ctx.lockA + '/edit-context', { label: 'lock-edit-context-d2', }); await s.post( 'assistant', '/api/price-locks/' + ctx.lockA + '/edit', { ...c.inputs, revision: c.revision, reason: '改客户名', verified: true, customer: '对照锁价客户(改)' }, { expect: 403, label: 'lock-edit-cross-day-denied' }, ); const req = await s.post( 'assistant', '/api/price-locks/' + ctx.lockA + '/change-requests', { ...c.inputs, action: 'edit', revision: c.revision, reason: '改客户名', verified: true, customer: '对照锁价客户(改)', }, { label: 'lock-change-request' }, ); await s.get('owner', '/api/price-lock-changes', { label: 'lock-changes-list' }); const rd = await s.get('owner', '/api/price-lock-changes/' + req.requestId, { label: 'lock-change-detail' }); await s.post( 'owner', '/api/price-lock-changes/' + req.requestId + '/approve', { revision: rd.price_lock_revision ?? c.revision, verified: true, note: '核实' }, { label: 'lock-change-approve' }, ); // 取消申请 → 驳回 const cc = await s.get('assistant2', '/api/price-locks/' + ctx.lockC + '/edit-context', { label: 'lock-c-context', }); const cr = await s.post( 'assistant2', '/api/price-locks/' + ctx.lockC + '/change-requests', { action: 'cancel', revision: cc.revision, reason: '客户不要了', verified: true }, { label: 'lock-cancel-request' }, ); await s.post( 'owner', '/api/price-lock-changes/' + cr.requestId + '/reject', { note: '客户仍要' }, { label: 'lock-cancel-reject' }, ); // 老板直接取消 const dc = await s.get('owner', '/api/price-locks/' + ctx.lockD + '/edit-context', { label: 'lock-d-context' }); await s.post( 'owner', '/api/price-locks/' + ctx.lockD + '/cancel', { revision: dc.revision, reason: '录错作废', verified: true }, { label: 'lock-cancel-owner' }, ); // 交付 const lock = await s.get('assistant', '/api/price-locks/' + ctx.lockA, { label: 'lock-before-deliver' }); await s.post( 'assistant', '/api/price-locks/' + ctx.lockA + '/deliver', { date: D2, revision: lock.revision, verified: true, line: { quantity: '3.100', laborRate: '20', laborMode: 'gram', pieces: '1', charges: [{ name: '服务', amount: '10' }], payer: 'assistant', costParts: { labor: '30', accessories: '0', other: '0' }, costPayers: { material: 'owner', labor: 'assistant' }, }, discount: '0', extraMaterial: { rate: '900', payer: 'assistant', verified: true }, inventory: { pocket: '现货', original: 'receive', extra: 'receive' }, settlement: { amount: '162', account: '助理支付宝', verified: true }, fee_items: [{ key: 'shipping', note: '实际快递', amount: '6', payer: 'owner' }], }, { label: 'lock-deliver' }, ); await s.get('owner', '/api/price-locks?status=all', { label: 'price-locks-after' }); await s.get('assistant', '/api/state', { label: 'state-after-lock-deliver' }); }, // 置换(以旧换新):第二天登记,第三天跨天更正走审批。 // 直接回收放到第三天:已知问题——直接回收与订单售后同时存在时,回收次日起料池读取失败(见 knownIssue 各节与报告)。 async function exchangesD2(s, ctx) { const exchange = (member, extra = {}, ex = {}) => ({ mode: 'exchange', date: D2, customer: '对照换货客户', salesperson: member === 'assistant' ? '娜娜' : '小昊', old_lines: [{ name: 'Au旧料', incoming_weight: '8', melted_weight: '8', purity: '99.9' }], buy_rate: '900', payer: member, payment_account: ACCOUNT[member], verified: true, exchange: { name: '足金对照新货', quantity: '12', pocket: '现货', gold_price: '1000', labor_rate: '20', labor_mode: 'gram', depreciation_rate: '10', cost_material: { mode: 'gram', rate: '900' }, cost_labor: { mode: 'gram', rate: '5' }, cost_payer: member, discount: '0', rounding_mode: 'cent', ...ex, }, ...extra, }); await s.post('assistant2', '/api/recoveries/quote', exchange('assistant2'), { key: null, label: 'exchange-quote' }); ctx.recoveryExchange = ( await s.post('assistant2', '/api/recoveries', exchange('assistant2'), { label: 'recovery-exchange' }) ).id; ctx.recoveryExchange2 = ( await s.post( 'assistant', '/api/recoveries', exchange( 'assistant', { customer: '对照换货客户二', old_lines: [{ name: 'Au旧料', incoming_weight: '5', melted_weight: '4.9', purity: '99' }], }, { quantity: '6', discount: '10', rounding_mode: 'yuan' }, ), { label: 'recovery-exchange-2' }, ) ).id; await s.get('assistant2', '/api/recoveries', { label: 'recoveries-assistant2' }); await s.get('owner', '/api/recoveries', { label: 'recoveries-owner' }); await s.get('assistant2', '/api/recoveries/' + ctx.recoveryExchange, { label: 'recovery-exchange-detail' }); await s.get('assistant', '/api/recoveries/' + ctx.recoveryExchange, { expect: 404, label: 'recovery-foreign' }); await s.getRaw('assistant2', '/print/recoveries/' + ctx.recoveryExchange, { label: 'print-exchange' }); const st = await s.get('assistant2', '/api/print-status/recovery/' + ctx.recoveryExchange, { label: 'print-status-recovery', }); await s.post( 'assistant2', '/api/print-status/recovery/' + ctx.recoveryExchange, { printed: true, revision: st.revision, sourceRevision: st.sourceRevision }, { label: 'print-status-recovery-set' }, ); const detail = await s.get('assistant2', '/api/recoveries/' + ctx.recoveryExchange, { label: 'recovery-exchange-detail-after-print', }); if (detail.order_id) await s.getRaw('assistant2', '/print/' + detail.order_id, { label: 'print-exchange-order' }); // 客户寄存料 await s.post('assistant', '/api/customer-materials', { date: D2, grams: '1.5', memo: '对照寄存袋', verified: true, }); await s.post( 'assistant', '/api/customer-materials', { date: D2, grams: '1.5', memo: '对照寄存袋', verified: false }, { expect: 400, label: 'customer-material-unverified' }, ); for (const role of ROLES) await s.get(role, '/api/customer-materials', { label: 'customer-materials-' + role }); }, async function sameDayD2(s, ctx) { const base = { date: D2, customer: '当天客户', internal_note: '当天单备注', salesperson: '娜娜', payment_account: '助理微信', rounding_mode: 'cent', lines: [ { name: '足金吊坠', unit: 'g', quantity: '2', pocket: '现货', payer: 'assistant', sale: '2100', cost: '1800' }, ], fee_items: [], }; const a = (await s.post('assistant', '/api/orders/issue', base, { label: 'issue-d2' })).id; ctx.orderD2 = a; const info = await s.get('assistant', '/api/orders/' + a + '/edit', { label: 'same-day-edit-context' }); await s.post( 'assistant', '/api/orders/' + a + '/edit', { ...info.inputs, revision: info.revision, reason: '当天改客户', verified: true, customer: '当天客户(改)' }, { label: 'same-day-edit-direct' }, ); const d = await s.get('assistant', '/api/orders/' + a, { label: 'order-d2-detail' }); await s.post( 'assistant', '/api/orders/' + a + '/expense', { date: D2, revision: d.revision, reason: '当天快递', verified: true, amount: '8', payer: 'assistant', note: '当天快递', }, { label: 'same-day-expense' }, ); // 当天店员申请转归属 → 麦麦批准 const own = await s.get('assistant', '/api/orders/' + a + '/ownership', { label: 'ownership-context-same-day' }); const or = await s.post( 'assistant', '/api/orders/' + a + '/ownership', { member: 'assistant2', revision: own.revision, reason: '实际由小昊接待', verified: true }, { label: 'ownership-request-same-day' }, ); const ord = await s.get('owner', '/api/order-ownership-changes/' + or.requestId, { label: 'ownership-request-detail', }); await s.post( 'owner', '/api/order-ownership-changes/' + or.requestId + '/approve', { revision: ord.revision ?? own.revision, verified: true, note: '核实' }, { label: 'ownership-approve' }, ); const b = ( await s.post( 'assistant', '/api/orders/issue', { ...base, customer: '当天取消客户' }, { label: 'issue-d2-cancel' }, ) ).id; const bd = await s.get('assistant', '/api/orders/' + b, { label: 'order-d2-cancel-detail' }); await s.post( 'assistant', '/api/orders/' + b + '/canceltoday', { date: D2, revision: bd.revision, reason: '当天录错', verified: true }, { label: 'cancel-today' }, ); await s.post( 'assistant', '/api/orders/' + ctx.orderPool + '/canceltoday', { date: D2, revision: 1, reason: '跨天不可', verified: true }, { expect: [403, 409], label: 'cancel-today-old-denied' }, ); // 店员不能直接收款旧单(需申请) await s.post( 'owner', '/api/orders/' + ctx.orderFixed + '/settlement', { date: D2, amount: '1', direction: 'toOwner', verified: true }, { expect: 400, label: 'settlement-team-mode-denied' }, ); await s.post( 'assistant', '/api/orders/' + ctx.orderPool + '/receipt', { date: D2, amount: '1', account: '助理微信', verified: true }, { expect: [400, 403, 409], label: 'receipt-denied' }, ); }, async function fundsD2(s, ctx) { await transfer(s, D2, '/api/team-funds/transfer', '对照转账二'); await s.get('owner', '/api/team-funds?date=' + D2, { label: 'team-funds-d2' }); await s.get('owner', '/api/team-profits?month=2026-11', { label: 'team-profits' }); await s.get('owner', '/api/team-profits', { label: 'team-profits-default' }); await s.get('assistant', '/api/team-profits', { expect: 403, label: 'team-profits-denied' }); for (const role of ROLES) await s.get(role, '/api/daily-funds?date=' + D2, { label: 'daily-funds-d2-' + role }); const pc = await s.get('owner', '/api/people-count?date=' + D2, { label: 'people-count-d2' }); await s.post( 'owner', '/api/people-count', { date: D2, assistant1Count: 7, assistant2Count: 4, revision: pc.revision }, { label: 'people-count-d2-save' }, ); await s.get('owner', '/api/people-count-history?from=' + D1 + '&date=' + D2, { label: 'people-count-history-range', }); }, async function materialChanges(s, ctx) { const preview = await s.get('owner', '/api/material-pools/rolling-preview', { label: 'rolling-preview-before-enable', }); await s.post( 'assistant', '/api/material-pools/rolling-enable', { date: D2, revision: preview.revision, verified: true }, { expect: 403, label: 'rolling-enable-denied' }, ); await s.post( 'owner', '/api/material-pools/rolling-enable', { date: D2, revision: preview.revision, verified: true }, { label: 'rolling-enable' }, ); await s.post( 'assistant', '/api/material-purchases', { date: D2, grams: '5', total: '4600', payer: 'assistant', allocations: [{ member: 'assistant', amount: '4600' }], note: '第二天购料', }, { label: 'purchase-d2' }, ); await s.post( 'assistant2', '/api/material-purchases', { date: D2, grams: '4', total: '3700', payer: 'assistant2', allocations: [{ member: 'assistant2', amount: '3700' }], }, { label: 'purchase-d2-xiaohao' }, ); const detail = await s.get('assistant', '/api/material-purchases/' + ctx.purchaseA.id, { label: 'purchase-detail-d2', }); await s.post( 'assistant', '/api/material-purchases/' + ctx.purchaseA.id + '/edit', { date: D1, grams: '11', total: '9900', payer: 'assistant', note: '直接改', revision: detail.purchase.revision }, { expect: [403, 409], label: 'purchase-edit-cross-day-denied' }, ); const req = await s.post( 'assistant', '/api/material-purchases/' + ctx.purchaseA.id + '/change', { date: D1, grams: '11', total: '9900', payer: 'assistant', allocations: [{ member: 'assistant', amount: '9900' }], note: '核对凭据', revision: detail.purchase.revision, action: 'edit', reason: '核对原始购料凭据后申请', verified: true, }, { label: 'purchase-change-request' }, ); ctx.purchaseChange = req.id; await s.get('owner', '/api/material-purchase-changes', { label: 'purchase-changes-list' }); await s.get('assistant', '/api/material-purchase-changes/' + req.id, { label: 'purchase-change-detail' }); await s.post( 'assistant', '/api/material-purchase-changes/' + req.id + '/approve', { revision: 1, verified: true, note: '自批' }, { expect: 403, label: 'purchase-change-self-approve' }, ); await s.post( 'owner', '/api/material-purchase-changes/' + req.id + '/approve', { revision: 1, verified: true, note: '已核对付款凭据' }, { label: 'purchase-change-approve' }, ); const again = await s.get('assistant', '/api/material-purchases/' + ctx.purchaseA.id, { label: 'purchase-detail-after-approve', }); const del = await s.post( 'assistant', '/api/material-purchases/' + ctx.purchaseA.id + '/change', { revision: again.purchase.revision, action: 'delete', reason: '申请删除历史购料', verified: true }, { label: 'purchase-delete-request' }, ); await s.post( 'owner', '/api/material-purchase-changes/' + del.id + '/reject', { note: '购料真实存在' }, { label: 'purchase-change-reject' }, ); const od = await s.get('owner', '/api/material-purchases/' + ctx.purchaseO.id, { label: 'purchase-owner-detail' }); await s.post( 'owner', '/api/material-purchases/' + ctx.purchaseO.id + '/edit', { date: D1, grams: '20', total: '18400', payer: 'owner', note: '老板改价', revision: od.purchase.revision }, { expect: 409, label: 'purchase-edit-owner-frozen' }, ); const p3 = await s.post( 'owner', '/api/material-purchases', { date: D2, grams: '1', total: '900', payer: 'owner', note: '待删除' }, { label: 'purchase-to-delete' }, ); let pd = await s.get('owner', '/api/material-purchases/' + p3.id, { label: 'purchase-to-delete-detail' }); await s.post( 'owner', '/api/material-purchases/' + p3.id + '/edit', { date: D2, grams: '1.5', total: '1380', payer: 'owner', note: '当天改价', revision: pd.purchase.revision }, { label: 'purchase-edit-same-day' }, ); pd = await s.get('owner', '/api/material-purchases/' + p3.id, { label: 'purchase-after-edit' }); await s.post( 'owner', '/api/material-purchases/' + p3.id + '/delete', { revision: pd.purchase.revision, reason: '录错', verified: true }, { label: 'purchase-delete' }, ); await s.post( 'assistant', '/api/material-pools/quote', { member: 'assistant', date: D2, entries: [ { lineIndex: 0, poolId: D2, mg: 2000 }, { lineIndex: 1, poolId: D1, mg: 1000 }, ], }, { key: null, expect: 400, label: 'material-pool-quote-rolling-old-pool' }, ); await s.post( 'assistant', '/api/material-pools/quote', { member: 'assistant', date: D2, entries: [ { lineIndex: 0, poolId: D2, mg: 2000 }, { lineIndex: 1, poolId: D2, mg: 1000 }, ], }, { key: null, expect: 400, label: 'known-issue-material-pool-quote-d2' }, ); // 滚动料池下按当天料池开单 await s.post( 'assistant', '/api/orders/issue', { date: D2, customer: '滚动料池客户', internal_note: '滚动料池备注', salesperson: '娜娜', payment_account: '助理微信', rounding_mode: 'cent', lines: [ { name: '足金999', unit: 'g', quantity: '2', pocket: '', payer: 'assistant', sale: '2200', costParts: { material: '', labor: '0', accessories: '0', other: '0' }, costMaterial: { mode: 'pool', poolId: D2 }, }, ], fee_items: [], }, { label: 'issue-rolling-pool' }, ); await s.get('owner', '/api/material-pools', { label: 'material-pools-rolling' }); const pool = await s.get('owner', '/api/material-pools/' + D1, { label: 'material-pool-detail-owner' }); await s.post( 'owner', '/api/material-pools/' + D1 + '/settlement', { date: D2, amount: '1', direction: 'toOwner', verified: true, revision: pool.revision }, { expect: [400, 409], label: 'material-pool-settlement-team' }, ); await s.get('owner', '/api/material-pools/rolling-preview', { label: 'rolling-preview' }); await s.get('assistant', '/api/material-pools/rolling-preview', { expect: 403, label: 'rolling-preview-denied' }); }, async function securityChecks(s, ctx) { const body = { date: D2, customer: '安全测试', internal_note: '安全测试备注', salesperson: '娜娜', payment_account: '助理微信', rounding_mode: 'cent', lines: [ { name: '足金转运珠', unit: 'g', quantity: '0.5', pocket: '现货', payer: 'assistant', sale: '500', cost: '420', }, ], fee_items: [], }; await s.post('assistant', '/api/orders/issue', body, { noOrigin: true, label: 'csrf-missing-origin', expect: 403 }); await s.post('assistant', '/api/orders/issue', body, { origin: 'https://evil.example', label: 'csrf-wrong-origin', expect: 403, }); await s.post('assistant', '/api/orders/issue', body, { noXRW: true, label: 'csrf-missing-header', expect: 403 }); await s.post('assistant', '/api/orders/issue', body, { contentType: 'text/plain', label: 'csrf-wrong-content-type', expect: 403, }); await s.post('assistant', '/api/orders/issue', '{not json', { label: 'invalid-json', expect: 400 }); const key = 'golden-idempotency-replay-0001'; const first = await s.post('assistant', '/api/orders/issue', body, { key, label: 'idempotent-first' }); const again = await s.post('assistant', '/api/orders/issue', body, { key, label: 'idempotent-replay' }); if (first.id !== again.id) s.problems.push('幂等重放返回了不同订单'); await s.post( 'assistant', '/api/orders/issue', { ...body, customer: '不同内容' }, { key, label: 'idempotent-conflict', expect: 409 }, ); await s.post('assistant', '/api/orders/issue', body, { key: 'short', label: 'idempotency-key-invalid', expect: 400, }); await s.post('assistant', '/api/orders/issue', body, { key: null, label: 'idempotency-key-missing', expect: 400 }); // 跨成员访问 for (const suffix of ['', '/public', '/edit', '/change', '/cancellation', '/ownership', '/after-sale']) await s.get('assistant2', '/api/orders/' + ctx.orderPerGram + suffix, { expect: 404, label: 'foreign-order' + suffix.replace('/', '-'), }); for (const suffix of ['/edit', '/change', '/cancellation', '/canceltoday', '/receipt', '/expense']) await s.post( 'assistant2', '/api/orders/' + ctx.orderPerGram + suffix, { date: D2, revision: 1, reason: '越权', verified: true }, { expect: 404, label: 'foreign-order-post' + suffix.replace('/', '-') }, ); await s.get('assistant', '/api/order-book?member=assistant2', { expect: 403, label: 'order-book-foreign-member' }); await s.get('assistant', '/api/report?member=assistant2', { expect: 403, label: 'report-foreign-member' }); for (const route of [ '/api/export/inventory', '/api/team-funds?date=' + D2, '/api/employees', '/api/material-pools/rolling-preview', '/api/private-operations', '/api/people-count', '/api/people-count-history', ]) await s.get('assistant2', route, { expect: 403, label: 'owner-only-get' }); for (const [route, b] of [ ['/api/backup', {}], ['/api/sync', {}], ['/api/shop-settings', { revision: 0 }], ['/api/printing', { offsetX: 1 }], ['/api/pockets', { name: 'x' }], ['/api/employees', { label: 'x' }], ['/api/team-funds/transfers', {}], ['/api/people-count', { date: D2, revision: 0 }], ['/api/private-operations/people', { date: D2, member: 'assistant', total_count: 1, new_count: 0, revision: 0 }], ['/api/close', { date: D2, basis: 'orderDate' }], ['/api/inventory/review', { date: D2, verified: true, revision: 'x' }], ['/api/team-members/assistant/password', { password: 'x', verified: true }], ]) await s.post('assistant2', route, b, { expect: 403, label: 'owner-only-post' }); await s.get('assistant', '/api/unknown-route', { expect: 404, label: 'unknown-get' }); await s.post('assistant', '/api/unknown-route', {}, { expect: 404, label: 'unknown-post' }); await s.request('assistant', 'PUT', '/api/state', { expect: 405, label: 'method-not-allowed' }); await s.get(null, '/api/orders/' + ctx.orderPerGram, { expect: 401, label: 'anonymous-order' }); await s.get('assistant', '/api/state', { headers: { 'X-Ledger-User': 'someone-else' }, expect: 409, label: 'account-changed-header', }); }, async function reports(s, ctx) { for (const role of ROLES) { await s.get(role, '/api/report?date=' + D2, { label: 'report-d2-' + role }); await s.get(role, '/api/report?date=' + D2 + '&basis=orderDate', { label: 'report-d2-orderdate-' + role }); await s.get(role, '/api/report?from=' + D1 + '&date=' + D2 + '&basis=orderDate', { label: 'report-range-' + role, }); await s.get(role, '/api/order-book?date=' + D2, { label: 'order-book-d2-' + role }); await s.get(role, '/api/order-book?from=' + D1 + '&date=' + D2, { label: 'order-book-range-' + role }); await s.get(role, '/api/inventory', { label: 'inventory-' + role }); await s.get(role, '/api/inventory/movements', { label: 'movements-' + role }); await s.get(role, '/api/inventory/snapshots', { label: 'snapshots-' + role }); await s.get(role, '/api/material-pools', { label: 'material-pools-' + role }); await s.get(role, '/api/price-locks?status=all', { label: 'price-locks-' + role }); await s.get(role, '/api/recoveries', { label: 'recoveries-list-' + role }); await s.get(role, '/api/order-changes?status=all', { label: 'order-changes-all-' + role }); await s.get(role, '/api/order-cancellations?status=all', { label: 'cancellations-all-' + role }); await s.get(role, '/api/order-ownership-changes?status=all', { label: 'ownership-all-' + role }); await s.get(role, '/api/price-lock-changes?status=all', { label: 'lock-changes-all-' + role }); await s.get(role, '/api/recovery-changes?status=all', { label: 'recovery-changes-all-' + role }); await s.get(role, '/api/material-purchase-changes?status=all', { label: 'purchase-changes-all-' + role }); await s.get(role, '/api/after-sales/changes?status=all', { label: 'after-sale-changes-all-' + role }); } const filters = [ 'status=after_sale', 'status=delivered', 'status=cancelled', 'q=对照', 'pocket=现货', 'member=assistant', 'account=助理微信', 'paymentAccount=助理微信', 'basis=orderDate', ]; for (const f of filters) await s.get('owner', '/api/order-book?from=' + D1 + '&date=' + D2 + '&' + f, { label: 'order-book-filter ' + f, expect: [200, 400], }); await s.get('owner', '/api/report?date=' + D2 + '&member=assistant2&basis=orderDate', { label: 'report-member-filter', }); await s.get('owner', '/api/inventory/movements?from=' + D1 + '&date=' + D2 + '&pocket=现货', { label: 'movements-filter', expect: [200, 400], }); await s.getRaw('owner', '/api/inventory/movements/export.xlsx', { label: 'movements-xlsx' }); await s.getRaw('owner', '/api/inventory/movements/export.xlsx?from=' + D1 + '&date=' + D2, { label: 'movements-xlsx-range', expect: [200, 400], }); await s.getRaw('owner', '/api/export/inventory', { label: 'inventory-csv' }); await s.get('owner', '/api/team-funds?date=' + D2, { label: 'team-funds-report' }); }, async function closeAndBackup(s, ctx) { const inv = await s.get('owner', '/api/inventory', { label: 'inventory-before-review-d2' }); await s.post( 'owner', '/api/inventory/review', { date: D2, verified: true, revision: inv.revision }, { label: 'inventory-review-d2' }, ); await s.post('owner', '/api/close', { date: D2, basis: 'orderDate' }, { label: 'close-d2' }); await s.get('owner', '/api/report?date=' + D2 + '&basis=orderDate', { label: 'report-after-close' }); const backup = await s.post('owner', '/api/backup', {}); await s.getRaw('owner', '/api/backup/' + backup.name, { record: 'status', label: 'backup-download' }); await s.getRaw('assistant', '/api/backup/' + backup.name, { record: 'status', expect: 403, label: 'backup-download-denied', }); await s.getRaw('owner', '/api/backup/not-a-backup', { expect: 400, label: 'backup-invalid-name' }); await s.post('owner', '/api/sync', {}, { label: 'sync-disabled' }); }, // ───────── 第三天:最终只读 ───────── async function dayThreeLogin(s, ctx) { await s.day(D3); await loginAll(s, ctx); }, async function recoveryChanges(s, ctx) { // 小昊跨天更正置换旧料 → 申请 → 麦麦批准 const e = await s.get('assistant2', '/api/recoveries/' + ctx.recoveryExchange + '/edit', { label: 'recovery-edit-context', }); const input = { ...e.inputs, revision: e.revision ?? e.record?.revision, reason: '跨天更正旧料克重', verified: true, old_lines: [{ name: 'Au旧料', incoming_weight: '8.2', melted_weight: '8.1', purity: '99.9' }], }; await s.post('assistant2', '/api/recoveries/' + ctx.recoveryExchange + '/quote', input, { key: null, label: 'recovery-edit-quote', }); const up = await s.post('assistant2', '/api/recoveries/' + ctx.recoveryExchange + '/update', input, { label: 'recovery-update-request', }); await s.get('owner', '/api/recovery-changes', { label: 'recovery-changes-list' }); const rid = up.requestId || up.id; const rd = await s.get('owner', '/api/recovery-changes/' + rid, { label: 'recovery-change-detail' }); await s.post( 'assistant2', '/api/recovery-changes/' + rid + '/approve', { revision: rd.recovery_revision ?? rd.revision, verified: true, note: '自批' }, { expect: 403, label: 'recovery-change-self-approve' }, ); await s.post( 'owner', '/api/recovery-changes/' + rid + '/approve', { revision: rd.recovery_revision ?? rd.revision, verified: true, note: '核实' }, { label: 'recovery-change-approve' }, ); // 娜娜跨天取消申请 → 驳回;随后麦麦直接取消 const e2 = await s.get('assistant', '/api/recoveries/' + ctx.recoveryExchange2 + '/edit', { label: 'recovery-edit-context-2', }); const cancel = await s.post( 'assistant', '/api/recoveries/' + ctx.recoveryExchange2 + '/cancel', { revision: e2.revision ?? e2.record?.revision, reason: '客户反悔', verified: true }, { label: 'recovery-cancel-request' }, ); const cid = cancel.requestId || cancel.id; await s.post( 'owner', '/api/recovery-changes/' + cid + '/reject', { revision: cancel.request?.revision, note: '需核实' }, { label: 'recovery-change-reject' }, ); const oe = await s.get('owner', '/api/recoveries/' + ctx.recoveryExchange2 + '/edit', { label: 'recovery-owner-edit-context', }); await s.post( 'owner', '/api/recoveries/' + ctx.recoveryExchange2 + '/cancel', { revision: oe.revision ?? oe.record?.revision, reason: '录错', verified: true }, { label: 'recovery-cancel-owner' }, ); await s.get('owner', '/api/recoveries?status=all', { label: 'recoveries-all' }); await s.get('owner', '/api/recovery-changes?status=all', { label: 'recovery-changes-all' }); }, async function directRecoveriesD3(s, ctx) { const direct = (extra = {}) => ({ mode: 'direct', date: D3, customer: '对照回收客户', salesperson: '娜娜', old_lines: [{ name: 'Au旧料', incoming_weight: '10', melted_weight: '10', purity: '100' }], buy_rate: '900', payer: 'assistant', payment_account: '助理微信', verified: true, ...extra, }); await s.post('assistant', '/api/recoveries/quote', direct(), { key: null, label: 'recovery-quote' }); await s.post('assistant', '/api/recoveries', direct(), { key: null, expect: 400, label: 'recovery-without-key' }); ctx.recoveryDirect = (await s.post('assistant', '/api/recoveries', direct(), { label: 'recovery-direct' })).id; ctx.recoveryOwner = ( await s.post( 'owner', '/api/recoveries', direct({ salesperson: '麦麦', payer: 'owner', payment_account: '麦麦现金', old_lines: [{ name: 'Au旧料', incoming_weight: '3', melted_weight: '3', purity: '100' }], }), { label: 'recovery-owner' }, ) ).id; await s.get('assistant', '/api/recoveries/' + ctx.recoveryDirect, { label: 'recovery-direct-detail' }); await s.getRaw('assistant', '/print/recoveries/' + ctx.recoveryDirect, { label: 'print-recovery' }); // 当天本人直接更正 const e = await s.get('assistant', '/api/recoveries/' + ctx.recoveryDirect + '/edit', { label: 'recovery-direct-edit-context', }); await s.post( 'assistant', '/api/recoveries/' + ctx.recoveryDirect + '/update', { ...e.inputs, revision: e.revision ?? e.record?.revision, reason: '当天更正', verified: true, buy_rate: '905' }, { label: 'recovery-update-same-day' }, ); const oe = await s.get('owner', '/api/recoveries/' + ctx.recoveryOwner + '/edit', { label: 'recovery-owner-direct-edit-context', }); await s.post( 'owner', '/api/recoveries/' + ctx.recoveryOwner + '/cancel', { revision: oe.revision ?? oe.record?.revision, reason: '录错', verified: true }, { label: 'recovery-cancel-owner-direct' }, ); await s.get('owner', '/api/material-pools/' + D3, { label: 'material-pool-after-recovery' }); }, // 已知问题留档:同一天先有直接回收、再办理订单售后时,售后写入因料池批次分配失败而被拒绝(见报告)。 async function knownIssueAfterSaleAfterRecovery(s, ctx) { const id = ( await s.post( 'assistant', '/api/orders/issue', { date: D3, customer: '留档客户', internal_note: '留档备注', salesperson: '娜娜', payment_account: '助理微信', rounding_mode: 'cent', lines: [ { name: '足金手链', unit: 'g', quantity: '2', pocket: '现货', payer: 'assistant', sale: '2000', costParts: { material: '1800', labor: '50', accessories: '0', other: '0' }, }, ], fee_items: [], }, { label: 'issue-known-issue' }, ) ).id; await s.post( 'assistant', '/api/recoveries', { mode: 'direct', date: D3, customer: '留档回收客户', salesperson: '娜娜', old_lines: [{ name: 'Au旧料', incoming_weight: '2', melted_weight: '2', purity: '100' }], buy_rate: '900', payer: 'assistant', payment_account: '助理微信', verified: true, }, { label: 'recovery-known-issue' }, ); const d = await s.get('assistant', '/api/orders/' + id, { label: 'known-issue-order' }); await s.post( 'assistant', '/api/orders/' + id + '/return', { date: D3, revision: d.revision, verified: true, reason: '当天退回', afterSale: { lines: [{ lineIndex: 0, quantity: '1.000', pocket: '现货', disposition: 'stock' }], refund: { amount: '900', account: '助理微信', payer: 'assistant' }, deductionReason: '客户确认', expenses: [], }, }, { expect: 400, label: 'known-issue-after-sale-rejected' }, ); }, async function dayThreeReads(s, ctx) { for (const role of ROLES) { await s.get(role, '/api/state', { label: 'final-state-' + role }); await s.get(role, '/api/session', { label: 'final-session-' + role }); await s.get(role, '/api/report?from=' + D1 + '&date=' + D3, { label: 'final-report-' + role }); await s.get(role, '/api/order-book?from=' + D1 + '&date=' + D3, { label: 'final-order-book-' + role }); } await s.get('owner', '/api/inventory', { label: 'final-inventory' }); await s.get('owner', '/api/daily-funds?date=' + D3, { label: 'final-daily-funds' }); for (const asset of ['/', '/app.js', '/app.css', '/print.js', '/calculations.js']) await s.getRaw(null, asset, { record: 'status', label: 'asset' }); await s.getRaw(null, '/missing.js', { expect: 404, label: 'asset-missing' }); for (const role of ROLES) await s.post(role, '/api/logout', {}, { label: 'logout-' + role }); await s.get('owner', '/api/state', { expect: 401, label: 'state-after-final-logout' }); }, // 第四天:回收次日的主读取仍可用(启用滚动料池后;未启用时见报告中的已知问题)。 async function dayFourReads(s, ctx) { await s.day('2026-11-21'); await s.post( 'owner', '/api/login', { name: ctx.loginName.owner, password: ctx.password.owner }, { label: 'login-owner-d4' }, ); await s.get('owner', '/api/state', { label: 'state-d4' }); await s.get('owner', '/api/material-pools', { label: 'material-pools-d4' }); await s.get('owner', '/api/report?date=2026-11-21', { label: 'report-d4' }); }, ]; async function run(s) { const ctx = {}; const skip = (process.env.GOLDEN_SKIP || '').split(',').filter(Boolean); for (const section of sections) { if (skip.includes(section.name)) continue; s.note('section', { name: section.name }); await section(s, ctx); } } module.exports = { run, START, PW, sections, D1, D2, D3 };