@codespar/cli 0.17.0 → 0.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/package.json +1 -1
- package/templates/bills-agent/README.md +1 -1
- package/templates/bills-agent/agents/bills-agent/AGENTS.md +1 -1
- package/templates/bills-agent/agents/bills-agent/CLAUDE.md +1 -1
- package/templates/bills-agent/agents/bills-agent/README.md +6 -5
- package/templates/bills-agent/agents/bills-agent/src/modules/embedded-consent.ts +5 -4
- package/templates/bills-agent/packages/agent-core/README.md +14 -1
- package/templates/bills-agent/packages/agent-core/package.json +1 -1
- package/templates/bills-agent/packages/agent-core/src/agent.ts +39 -1
- package/templates/bills-agent/packages/agent-core/src/api/charge-rail.ts +54 -34
- package/templates/bills-agent/packages/agent-core/src/api/client.ts +28 -5
- package/templates/bills-agent/packages/agent-core/src/api/mandate-status.ts +28 -12
- package/templates/bills-agent/packages/agent-core/src/api/rail.ts +62 -26
- package/templates/bills-agent/packages/agent-core/src/api/sandbox-payer.ts +3 -18
- package/templates/bills-agent/packages/agent-core/src/approval.ts +14 -2
- package/templates/bills-agent/packages/agent-core/src/bundle.ts +35 -3
- package/templates/bills-agent/packages/agent-core/src/channels.ts +49 -3
- package/templates/bills-agent/packages/agent-core/src/check.ts +25 -2
- package/templates/bills-agent/packages/agent-core/src/engine.ts +235 -46
- package/templates/bills-agent/packages/agent-core/src/hash.ts +57 -1
- package/templates/bills-agent/packages/agent-core/src/index.ts +2 -0
- package/templates/bills-agent/packages/agent-core/src/quote.ts +50 -0
- package/templates/bills-agent/packages/agent-core/src/rail.ts +89 -4
- package/templates/bills-agent/packages/agent-core/src/receipt-chain.ts +270 -0
- package/templates/bills-agent/packages/agent-core/src/receipt-verification.ts +194 -18
- package/templates/bills-agent/packages/agent-core/src/revocation.ts +1 -1
- package/templates/bills-agent/packages/agent-core/src/state-machine.ts +10 -1
- package/templates/bills-agent/packages/agent-core/src/stubs/mandate-status.ts +4 -3
- package/templates/bills-agent/packages/agent-core/src/stubs/rail.ts +100 -32
- package/templates/bills-agent/packages/agent-core/src/tools.ts +17 -6
- package/templates/bills-agent/packages/agent-core/src/types.ts +54 -1
- package/templates/bills-agent/packages/agent-core/test/approval-seal.test.ts +233 -0
- package/templates/bills-agent/packages/agent-core/test/attempt-replay.test.ts +265 -0
- package/templates/bills-agent/packages/agent-core/test/composition.test.ts +204 -0
- package/templates/bills-agent/packages/agent-core/test/fixtures/production-receipt-keys.json +1 -0
- package/templates/bills-agent/packages/agent-core/test/helpers.ts +4 -1
- package/templates/bills-agent/packages/agent-core/test/mandate-status.test.ts +85 -9
- package/templates/bills-agent/packages/agent-core/test/quote.test.ts +198 -0
- package/templates/bills-agent/packages/agent-core/test/receipt-chain.test.ts +220 -0
- package/templates/bills-agent/packages/agent-core/test/receipt-read-verification.test.ts +197 -0
- package/templates/bills-agent/packages/agent-core/test/receivables.test.ts +103 -3
- package/templates/bills-agent/packages/agent-runtime/README.md +12 -0
- package/templates/bills-agent/packages/agent-runtime/src/adversarial.ts +32 -2
- package/templates/bills-agent/packages/agent-runtime/src/channels/types.ts +53 -4
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +123 -22
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +30 -20
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +146 -21
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +40 -3
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -1
- package/templates/bills-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +16 -2
- package/templates/bills-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +70 -20
- package/templates/bills-agent/packages/agent-runtime/src/commands/poll.ts +2 -1
- package/templates/bills-agent/packages/agent-runtime/src/commands/resume.ts +8 -2
- package/templates/bills-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +3 -0
- package/templates/bills-agent/packages/agent-runtime/src/commands/start.ts +6 -3
- package/templates/bills-agent/packages/agent-runtime/src/commands/verify.ts +239 -38
- package/templates/bills-agent/packages/agent-runtime/src/commands/webhook.ts +3 -2
- package/templates/bills-agent/packages/agent-runtime/src/index.ts +1 -0
- package/templates/bills-agent/packages/agent-runtime/src/inspect.ts +5 -1
- package/templates/bills-agent/packages/agent-runtime/src/kit.ts +25 -2
- package/templates/bills-agent/packages/agent-runtime/src/scenarios.ts +8 -2
- package/templates/bills-agent/packages/agent-runtime/src/setup.ts +13 -3
- package/templates/bills-agent/packages/agent-runtime/src/terminal.ts +127 -18
- package/templates/bills-agent/packages/agent-runtime/test/verify-cli.test.ts +211 -9
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +45 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-session.test.ts +32 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +182 -0
- package/templates/checkout-agent/LICENSE +21 -0
- package/templates/checkout-agent/README.md +28 -0
- package/templates/checkout-agent/_gitignore +10 -0
- package/templates/checkout-agent/agents/checkout-agent/.env.example +5 -0
- package/templates/checkout-agent/agents/checkout-agent/AGENTS.md +20 -0
- package/templates/checkout-agent/agents/checkout-agent/CLAUDE.md +20 -0
- package/templates/checkout-agent/agents/checkout-agent/README.md +94 -0
- package/templates/checkout-agent/agents/checkout-agent/SYSTEM_PROMPT.md +36 -0
- package/templates/checkout-agent/agents/checkout-agent/agent.yaml +30 -0
- package/templates/checkout-agent/agents/checkout-agent/channels/whatsapp/README.md +28 -0
- package/templates/checkout-agent/agents/checkout-agent/channels/whatsapp/pedido-beatriz.json +11 -0
- package/templates/checkout-agent/agents/checkout-agent/channels/whatsapp/pedido-marina-retomada.json +10 -0
- package/templates/checkout-agent/agents/checkout-agent/channels/whatsapp/pedido-marina.json +11 -0
- package/templates/checkout-agent/agents/checkout-agent/channels/whatsapp/templates.json +49 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap-human.json +12 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap.json +11 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/beneficiary-swap.transcript.jsonl +5 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/coupon-unknown.json +13 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/coupon-unknown.transcript.jsonl +4 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/exfiltration.json +26 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/exfiltration.transcript.jsonl +3 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/false-authority.json +11 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/false-authority.transcript.jsonl +5 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/fractioning.json +12 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/fractioning.transcript.jsonl +5 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/model-total.json +13 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/model-total.transcript.jsonl +5 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/payment-claimed.json +15 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/payment-claimed.transcript.jsonl +7 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/price-injected.json +12 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/price-injected.transcript.jsonl +5 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/prompt-injection.json +13 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/prompt-injection.transcript.jsonl +4 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/quantity-swapped-human.json +16 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/quantity-swapped-human.transcript.jsonl +9 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/quantity-swapped.json +15 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/quantity-swapped.transcript.jsonl +8 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/adversarial/webhook-replay.json +11 -0
- package/templates/checkout-agent/agents/checkout-agent/evals/eval.yaml +11 -0
- package/templates/checkout-agent/agents/checkout-agent/guardrails.json +25 -0
- package/templates/checkout-agent/agents/checkout-agent/mandate.example.json +28 -0
- package/templates/checkout-agent/agents/checkout-agent/package.json +33 -0
- package/templates/checkout-agent/agents/checkout-agent/runbook.md +19 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/beneficiary-not-allowed.json +42 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/beneficiary-not-allowed.transcript.jsonl +4 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cap-exceeded.json +32 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cap-exceeded.transcript.jsonl +4 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-recomposed.json +61 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-recomposed.transcript.jsonl +9 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-replaced.json +61 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/cart-replaced.transcript.jsonl +9 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/charge-expired.json +36 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/charge-expired.transcript.jsonl +6 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/coupon-unknown.json +23 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/coupon-unknown.transcript.jsonl +4 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/escalated-above-threshold.json +72 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/escalated-above-threshold.transcript.jsonl +9 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/happy-path.json +15 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/happy-path.transcript.jsonl +6 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/item-unavailable.json +23 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/item-unavailable.transcript.jsonl +3 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/mandate-revoked.json +42 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/mandate-revoked.transcript.jsonl +12 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/nfse-failed.json +14 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/nfse-failed.transcript.jsonl +9 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/payment-claimed.json +34 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/payment-claimed.transcript.jsonl +7 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/price-injected.json +33 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/price-injected.transcript.jsonl +4 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/prompt-injection.json +32 -0
- package/templates/checkout-agent/agents/checkout-agent/scenarios/prompt-injection.transcript.jsonl +4 -0
- package/templates/checkout-agent/agents/checkout-agent/src/catalog.ts +92 -0
- package/templates/checkout-agent/agents/checkout-agent/src/kit.ts +338 -0
- package/templates/checkout-agent/agents/checkout-agent/src/modules/bolepix-receivables.ts +179 -0
- package/templates/checkout-agent/agents/checkout-agent/src/modules/nfse-invoice.ts +374 -0
- package/templates/checkout-agent/agents/checkout-agent/src/modules/storefront-cart.ts +220 -0
- package/templates/checkout-agent/agents/checkout-agent/src/pricing.ts +297 -0
- package/templates/checkout-agent/agents/checkout-agent/test/adversarial.test.ts +117 -0
- package/templates/checkout-agent/agents/checkout-agent/test/check.test.ts +67 -0
- package/templates/checkout-agent/agents/checkout-agent/test/cli.test.ts +169 -0
- package/templates/checkout-agent/agents/checkout-agent/test/fixtures/order-marina.transcript.jsonl +5 -0
- package/templates/checkout-agent/agents/checkout-agent/test/fixtures/ordered-marina-awaiting-payer.transcript.jsonl +6 -0
- package/templates/checkout-agent/agents/checkout-agent/test/fixtures/tap-falar-agora-marina.transcript.jsonl +2 -0
- package/templates/checkout-agent/agents/checkout-agent/test/nfse.test.ts +170 -0
- package/templates/checkout-agent/agents/checkout-agent/test/pricing.test.ts +138 -0
- package/templates/checkout-agent/agents/checkout-agent/test/scenarios.test.ts +113 -0
- package/templates/checkout-agent/agents/checkout-agent/test/whatsapp.test.ts +171 -0
- package/templates/checkout-agent/agents/checkout-agent/tools.json +68 -0
- package/templates/checkout-agent/agents/checkout-agent/tsconfig.json +10 -0
- package/templates/checkout-agent/package.json +38 -0
- package/templates/checkout-agent/packages/agent-core/README.md +34 -0
- package/templates/checkout-agent/packages/agent-core/package.json +24 -0
- package/templates/checkout-agent/packages/agent-core/src/agent.ts +163 -0
- package/templates/checkout-agent/packages/agent-core/src/api/charge-rail.ts +195 -0
- package/templates/checkout-agent/packages/agent-core/src/api/client.ts +76 -0
- package/templates/checkout-agent/packages/agent-core/src/api/mandate-status.ts +74 -0
- package/templates/checkout-agent/packages/agent-core/src/api/rail.ts +153 -0
- package/templates/checkout-agent/packages/agent-core/src/api/sandbox-payer.ts +43 -0
- package/templates/checkout-agent/packages/agent-core/src/approval.ts +135 -0
- package/templates/checkout-agent/packages/agent-core/src/bundle.ts +191 -0
- package/templates/checkout-agent/packages/agent-core/src/channels.ts +186 -0
- package/templates/checkout-agent/packages/agent-core/src/check.ts +276 -0
- package/templates/checkout-agent/packages/agent-core/src/clock.ts +42 -0
- package/templates/checkout-agent/packages/agent-core/src/engine.ts +1074 -0
- package/templates/checkout-agent/packages/agent-core/src/escalate.ts +85 -0
- package/templates/checkout-agent/packages/agent-core/src/events.ts +40 -0
- package/templates/checkout-agent/packages/agent-core/src/guardrails.ts +45 -0
- package/templates/checkout-agent/packages/agent-core/src/hash.ts +118 -0
- package/templates/checkout-agent/packages/agent-core/src/ids.ts +10 -0
- package/templates/checkout-agent/packages/agent-core/src/index.ts +34 -0
- package/templates/checkout-agent/packages/agent-core/src/mandate.ts +100 -0
- package/templates/checkout-agent/packages/agent-core/src/manifest.ts +76 -0
- package/templates/checkout-agent/packages/agent-core/src/providers/anthropic.ts +76 -0
- package/templates/checkout-agent/packages/agent-core/src/providers/replay.ts +63 -0
- package/templates/checkout-agent/packages/agent-core/src/providers/types.ts +39 -0
- package/templates/checkout-agent/packages/agent-core/src/quote.ts +50 -0
- package/templates/checkout-agent/packages/agent-core/src/rail.ts +186 -0
- package/templates/checkout-agent/packages/agent-core/src/receipt-chain.ts +270 -0
- package/templates/checkout-agent/packages/agent-core/src/receipt-verification.ts +577 -0
- package/templates/checkout-agent/packages/agent-core/src/revocation.ts +30 -0
- package/templates/checkout-agent/packages/agent-core/src/secrets.ts +30 -0
- package/templates/checkout-agent/packages/agent-core/src/state/store.ts +307 -0
- package/templates/checkout-agent/packages/agent-core/src/state-machine.ts +157 -0
- package/templates/checkout-agent/packages/agent-core/src/stubs/charge-rail.ts +195 -0
- package/templates/checkout-agent/packages/agent-core/src/stubs/mandate-status.ts +58 -0
- package/templates/checkout-agent/packages/agent-core/src/stubs/rail.ts +209 -0
- package/templates/checkout-agent/packages/agent-core/src/tools.ts +66 -0
- package/templates/checkout-agent/packages/agent-core/src/types.ts +187 -0
- package/templates/checkout-agent/packages/agent-core/test/approval-seal.test.ts +233 -0
- package/templates/checkout-agent/packages/agent-core/test/approval.test.ts +117 -0
- package/templates/checkout-agent/packages/agent-core/test/attempt-replay.test.ts +265 -0
- package/templates/checkout-agent/packages/agent-core/test/bundle.test.ts +85 -0
- package/templates/checkout-agent/packages/agent-core/test/clock.test.ts +25 -0
- package/templates/checkout-agent/packages/agent-core/test/composition.test.ts +204 -0
- package/templates/checkout-agent/packages/agent-core/test/engine.test.ts +596 -0
- package/templates/checkout-agent/packages/agent-core/test/escalate.test.ts +42 -0
- package/templates/checkout-agent/packages/agent-core/test/fixtures/production-receipt-keys.json +1 -0
- package/templates/checkout-agent/packages/agent-core/test/fixtures/staging-receipt-keys.json +18 -0
- package/templates/checkout-agent/packages/agent-core/test/fixtures/staging-receipt.json +24 -0
- package/templates/checkout-agent/packages/agent-core/test/helpers.ts +142 -0
- package/templates/checkout-agent/packages/agent-core/test/mandate-status.test.ts +229 -0
- package/templates/checkout-agent/packages/agent-core/test/manifest.test.ts +45 -0
- package/templates/checkout-agent/packages/agent-core/test/quote.test.ts +198 -0
- package/templates/checkout-agent/packages/agent-core/test/receipt-chain.test.ts +220 -0
- package/templates/checkout-agent/packages/agent-core/test/receipt-read-verification.test.ts +197 -0
- package/templates/checkout-agent/packages/agent-core/test/receipt-verification.test.ts +316 -0
- package/templates/checkout-agent/packages/agent-core/test/receivables.test.ts +416 -0
- package/templates/checkout-agent/packages/agent-core/test/secrets.test.ts +28 -0
- package/templates/checkout-agent/packages/agent-core/test/state-machine.test.ts +67 -0
- package/templates/checkout-agent/packages/agent-core/test/transitions.type-test.ts +59 -0
- package/templates/checkout-agent/packages/agent-core/tsconfig.json +10 -0
- package/templates/checkout-agent/packages/agent-runtime/README.md +80 -0
- package/templates/checkout-agent/packages/agent-runtime/bin.mjs +32 -0
- package/templates/checkout-agent/packages/agent-runtime/package.json +23 -0
- package/templates/checkout-agent/packages/agent-runtime/src/adversarial.ts +199 -0
- package/templates/checkout-agent/packages/agent-runtime/src/agent.ts +68 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/contact.ts +13 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/index.ts +72 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/rules.ts +120 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/types.ts +173 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +459 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +216 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/evidence.ts +109 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +350 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +180 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/present.ts +47 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +120 -0
- package/templates/checkout-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +127 -0
- package/templates/checkout-agent/packages/agent-runtime/src/cli.ts +98 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/check.ts +15 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/decide.ts +63 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/eval.ts +58 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/inspect.ts +100 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +367 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/poll.ts +145 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/reconcile.ts +42 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/rerun.ts +86 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/resume.ts +49 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +134 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/start.ts +248 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/verify.ts +330 -0
- package/templates/checkout-agent/packages/agent-runtime/src/commands/webhook.ts +40 -0
- package/templates/checkout-agent/packages/agent-runtime/src/default-kit.ts +83 -0
- package/templates/checkout-agent/packages/agent-runtime/src/index.ts +13 -0
- package/templates/checkout-agent/packages/agent-runtime/src/inspect.ts +801 -0
- package/templates/checkout-agent/packages/agent-runtime/src/kit.ts +229 -0
- package/templates/checkout-agent/packages/agent-runtime/src/poll.ts +105 -0
- package/templates/checkout-agent/packages/agent-runtime/src/scenarios.ts +274 -0
- package/templates/checkout-agent/packages/agent-runtime/src/setup.ts +239 -0
- package/templates/checkout-agent/packages/agent-runtime/src/terminal.ts +263 -0
- package/templates/checkout-agent/packages/agent-runtime/src/webhook.ts +131 -0
- package/templates/checkout-agent/packages/agent-runtime/test/inspect.test.ts +336 -0
- package/templates/checkout-agent/packages/agent-runtime/test/verify-cli.test.ts +329 -0
- package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +277 -0
- package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-evidence.test.ts +94 -0
- package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-rules.test.ts +174 -0
- package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-session.test.ts +167 -0
- package/templates/checkout-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +182 -0
- package/templates/checkout-agent/packages/agent-runtime/tsconfig.json +9 -0
- package/templates/checkout-agent/scripts/whatsapp-emulator.mjs +84 -0
- package/templates/checkout-agent/tsconfig.base.json +16 -0
- package/templates/checkout-agent/vitest.config.ts +12 -0
- package/templates/collections-agent/README.md +6 -1
- package/templates/collections-agent/agents/collections-agent/README.md +12 -8
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/README.md +8 -0
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/acordo-1042-retomada.json +10 -0
- package/templates/collections-agent/agents/collections-agent/channels/whatsapp/templates.json +27 -1
- package/templates/collections-agent/agents/collections-agent/src/kit.ts +2 -0
- package/templates/collections-agent/agents/collections-agent/src/modules/bolepix-receivables.ts +12 -2
- package/templates/collections-agent/agents/collections-agent/test/ambiguous-charge.test.ts +55 -0
- package/templates/collections-agent/agents/collections-agent/test/fixtures/tap-emitir-nova-1042.transcript.jsonl +2 -0
- package/templates/collections-agent/agents/collections-agent/test/whatsapp-poll.test.ts +12 -6
- package/templates/collections-agent/agents/collections-agent/test/whatsapp-status-replies.test.ts +148 -0
- package/templates/collections-agent/agents/collections-agent/test/whatsapp.test.ts +5 -0
- package/templates/collections-agent/package.json +1 -0
- package/templates/collections-agent/packages/agent-core/README.md +14 -1
- package/templates/collections-agent/packages/agent-core/package.json +1 -1
- package/templates/collections-agent/packages/agent-core/src/agent.ts +39 -1
- package/templates/collections-agent/packages/agent-core/src/api/charge-rail.ts +54 -34
- package/templates/collections-agent/packages/agent-core/src/api/client.ts +28 -5
- package/templates/collections-agent/packages/agent-core/src/api/mandate-status.ts +28 -12
- package/templates/collections-agent/packages/agent-core/src/api/rail.ts +62 -26
- package/templates/collections-agent/packages/agent-core/src/api/sandbox-payer.ts +3 -18
- package/templates/collections-agent/packages/agent-core/src/approval.ts +14 -2
- package/templates/collections-agent/packages/agent-core/src/bundle.ts +35 -3
- package/templates/collections-agent/packages/agent-core/src/channels.ts +49 -3
- package/templates/collections-agent/packages/agent-core/src/check.ts +25 -2
- package/templates/collections-agent/packages/agent-core/src/engine.ts +235 -46
- package/templates/collections-agent/packages/agent-core/src/hash.ts +57 -1
- package/templates/collections-agent/packages/agent-core/src/index.ts +2 -0
- package/templates/collections-agent/packages/agent-core/src/quote.ts +50 -0
- package/templates/collections-agent/packages/agent-core/src/rail.ts +89 -4
- package/templates/collections-agent/packages/agent-core/src/receipt-chain.ts +270 -0
- package/templates/collections-agent/packages/agent-core/src/receipt-verification.ts +194 -18
- package/templates/collections-agent/packages/agent-core/src/revocation.ts +1 -1
- package/templates/collections-agent/packages/agent-core/src/state-machine.ts +10 -1
- package/templates/collections-agent/packages/agent-core/src/stubs/mandate-status.ts +4 -3
- package/templates/collections-agent/packages/agent-core/src/stubs/rail.ts +100 -32
- package/templates/collections-agent/packages/agent-core/src/tools.ts +17 -6
- package/templates/collections-agent/packages/agent-core/src/types.ts +54 -1
- package/templates/collections-agent/packages/agent-core/test/approval-seal.test.ts +233 -0
- package/templates/collections-agent/packages/agent-core/test/attempt-replay.test.ts +265 -0
- package/templates/collections-agent/packages/agent-core/test/composition.test.ts +204 -0
- package/templates/collections-agent/packages/agent-core/test/fixtures/production-receipt-keys.json +1 -0
- package/templates/collections-agent/packages/agent-core/test/helpers.ts +4 -1
- package/templates/collections-agent/packages/agent-core/test/mandate-status.test.ts +85 -9
- package/templates/collections-agent/packages/agent-core/test/quote.test.ts +198 -0
- package/templates/collections-agent/packages/agent-core/test/receipt-chain.test.ts +220 -0
- package/templates/collections-agent/packages/agent-core/test/receipt-read-verification.test.ts +197 -0
- package/templates/collections-agent/packages/agent-core/test/receivables.test.ts +103 -3
- package/templates/collections-agent/packages/agent-runtime/README.md +12 -0
- package/templates/collections-agent/packages/agent-runtime/src/adversarial.ts +32 -2
- package/templates/collections-agent/packages/agent-runtime/src/channels/types.ts +53 -4
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +123 -22
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +30 -20
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +146 -21
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +40 -3
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -1
- package/templates/collections-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +16 -2
- package/templates/collections-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +70 -20
- package/templates/collections-agent/packages/agent-runtime/src/commands/poll.ts +2 -1
- package/templates/collections-agent/packages/agent-runtime/src/commands/resume.ts +8 -2
- package/templates/collections-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +3 -0
- package/templates/collections-agent/packages/agent-runtime/src/commands/start.ts +6 -3
- package/templates/collections-agent/packages/agent-runtime/src/commands/verify.ts +239 -38
- package/templates/collections-agent/packages/agent-runtime/src/commands/webhook.ts +3 -2
- package/templates/collections-agent/packages/agent-runtime/src/index.ts +1 -0
- package/templates/collections-agent/packages/agent-runtime/src/inspect.ts +5 -1
- package/templates/collections-agent/packages/agent-runtime/src/kit.ts +25 -2
- package/templates/collections-agent/packages/agent-runtime/src/scenarios.ts +8 -2
- package/templates/collections-agent/packages/agent-runtime/src/setup.ts +13 -3
- package/templates/collections-agent/packages/agent-runtime/src/terminal.ts +127 -18
- package/templates/collections-agent/packages/agent-runtime/test/verify-cli.test.ts +211 -9
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +45 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-session.test.ts +32 -0
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +182 -0
- package/templates/collections-agent/scripts/whatsapp-emulator.mjs +84 -0
- package/templates/hello-agent/README.md +1 -1
- package/templates/hello-agent/packages/agent-core/README.md +14 -1
- package/templates/hello-agent/packages/agent-core/package.json +1 -1
- package/templates/hello-agent/packages/agent-core/src/agent.ts +39 -1
- package/templates/hello-agent/packages/agent-core/src/api/charge-rail.ts +54 -34
- package/templates/hello-agent/packages/agent-core/src/api/client.ts +28 -5
- package/templates/hello-agent/packages/agent-core/src/api/mandate-status.ts +28 -12
- package/templates/hello-agent/packages/agent-core/src/api/rail.ts +62 -26
- package/templates/hello-agent/packages/agent-core/src/api/sandbox-payer.ts +3 -18
- package/templates/hello-agent/packages/agent-core/src/approval.ts +14 -2
- package/templates/hello-agent/packages/agent-core/src/bundle.ts +35 -3
- package/templates/hello-agent/packages/agent-core/src/channels.ts +49 -3
- package/templates/hello-agent/packages/agent-core/src/check.ts +25 -2
- package/templates/hello-agent/packages/agent-core/src/engine.ts +235 -46
- package/templates/hello-agent/packages/agent-core/src/hash.ts +57 -1
- package/templates/hello-agent/packages/agent-core/src/index.ts +2 -0
- package/templates/hello-agent/packages/agent-core/src/quote.ts +50 -0
- package/templates/hello-agent/packages/agent-core/src/rail.ts +89 -4
- package/templates/hello-agent/packages/agent-core/src/receipt-chain.ts +270 -0
- package/templates/hello-agent/packages/agent-core/src/receipt-verification.ts +194 -18
- package/templates/hello-agent/packages/agent-core/src/revocation.ts +1 -1
- package/templates/hello-agent/packages/agent-core/src/state-machine.ts +10 -1
- package/templates/hello-agent/packages/agent-core/src/stubs/mandate-status.ts +4 -3
- package/templates/hello-agent/packages/agent-core/src/stubs/rail.ts +100 -32
- package/templates/hello-agent/packages/agent-core/src/tools.ts +17 -6
- package/templates/hello-agent/packages/agent-core/src/types.ts +54 -1
- package/templates/hello-agent/packages/agent-core/test/approval-seal.test.ts +233 -0
- package/templates/hello-agent/packages/agent-core/test/attempt-replay.test.ts +265 -0
- package/templates/hello-agent/packages/agent-core/test/composition.test.ts +204 -0
- package/templates/hello-agent/packages/agent-core/test/fixtures/production-receipt-keys.json +1 -0
- package/templates/hello-agent/packages/agent-core/test/helpers.ts +4 -1
- package/templates/hello-agent/packages/agent-core/test/mandate-status.test.ts +85 -9
- package/templates/hello-agent/packages/agent-core/test/quote.test.ts +198 -0
- package/templates/hello-agent/packages/agent-core/test/receipt-chain.test.ts +220 -0
- package/templates/hello-agent/packages/agent-core/test/receipt-read-verification.test.ts +197 -0
- package/templates/hello-agent/packages/agent-core/test/receivables.test.ts +103 -3
- package/templates/hello-agent/packages/agent-runtime/README.md +12 -0
- package/templates/hello-agent/packages/agent-runtime/src/adversarial.ts +32 -2
- package/templates/hello-agent/packages/agent-runtime/src/channels/types.ts +53 -4
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +123 -22
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +30 -20
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +146 -21
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +40 -3
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -1
- package/templates/hello-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +16 -2
- package/templates/hello-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +70 -20
- package/templates/hello-agent/packages/agent-runtime/src/commands/poll.ts +2 -1
- package/templates/hello-agent/packages/agent-runtime/src/commands/resume.ts +8 -2
- package/templates/hello-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +3 -0
- package/templates/hello-agent/packages/agent-runtime/src/commands/start.ts +6 -3
- package/templates/hello-agent/packages/agent-runtime/src/commands/verify.ts +239 -38
- package/templates/hello-agent/packages/agent-runtime/src/commands/webhook.ts +3 -2
- package/templates/hello-agent/packages/agent-runtime/src/index.ts +1 -0
- package/templates/hello-agent/packages/agent-runtime/src/inspect.ts +5 -1
- package/templates/hello-agent/packages/agent-runtime/src/kit.ts +25 -2
- package/templates/hello-agent/packages/agent-runtime/src/scenarios.ts +8 -2
- package/templates/hello-agent/packages/agent-runtime/src/setup.ts +13 -3
- package/templates/hello-agent/packages/agent-runtime/src/terminal.ts +127 -18
- package/templates/hello-agent/packages/agent-runtime/test/verify-cli.test.ts +211 -9
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +45 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-session.test.ts +32 -0
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +182 -0
- package/templates/kits.lock.json +29 -6
- package/templates/supplier-payments-agent/README.md +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/AGENTS.md +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/CLAUDE.md +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/README.md +11 -9
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/kit.ts +1 -1
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/src/modules/batch-payout.ts +67 -20
- package/templates/supplier-payments-agent/agents/supplier-payments-agent/test/batch.test.ts +504 -5
- package/templates/supplier-payments-agent/packages/agent-core/README.md +14 -1
- package/templates/supplier-payments-agent/packages/agent-core/package.json +1 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/agent.ts +39 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/api/charge-rail.ts +54 -34
- package/templates/supplier-payments-agent/packages/agent-core/src/api/client.ts +28 -5
- package/templates/supplier-payments-agent/packages/agent-core/src/api/mandate-status.ts +28 -12
- package/templates/supplier-payments-agent/packages/agent-core/src/api/rail.ts +62 -26
- package/templates/supplier-payments-agent/packages/agent-core/src/api/sandbox-payer.ts +3 -18
- package/templates/supplier-payments-agent/packages/agent-core/src/approval.ts +14 -2
- package/templates/supplier-payments-agent/packages/agent-core/src/bundle.ts +35 -3
- package/templates/supplier-payments-agent/packages/agent-core/src/channels.ts +49 -3
- package/templates/supplier-payments-agent/packages/agent-core/src/check.ts +25 -2
- package/templates/supplier-payments-agent/packages/agent-core/src/engine.ts +235 -46
- package/templates/supplier-payments-agent/packages/agent-core/src/hash.ts +57 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/index.ts +2 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/quote.ts +50 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/rail.ts +89 -4
- package/templates/supplier-payments-agent/packages/agent-core/src/receipt-chain.ts +270 -0
- package/templates/supplier-payments-agent/packages/agent-core/src/receipt-verification.ts +194 -18
- package/templates/supplier-payments-agent/packages/agent-core/src/revocation.ts +1 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/state-machine.ts +10 -1
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/mandate-status.ts +4 -3
- package/templates/supplier-payments-agent/packages/agent-core/src/stubs/rail.ts +100 -32
- package/templates/supplier-payments-agent/packages/agent-core/src/tools.ts +17 -6
- package/templates/supplier-payments-agent/packages/agent-core/src/types.ts +54 -1
- package/templates/supplier-payments-agent/packages/agent-core/test/approval-seal.test.ts +233 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/attempt-replay.test.ts +265 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/composition.test.ts +204 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/fixtures/production-receipt-keys.json +1 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/helpers.ts +4 -1
- package/templates/supplier-payments-agent/packages/agent-core/test/mandate-status.test.ts +85 -9
- package/templates/supplier-payments-agent/packages/agent-core/test/quote.test.ts +198 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/receipt-chain.test.ts +220 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/receipt-read-verification.test.ts +197 -0
- package/templates/supplier-payments-agent/packages/agent-core/test/receivables.test.ts +103 -3
- package/templates/supplier-payments-agent/packages/agent-runtime/README.md +12 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/adversarial.ts +32 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/types.ts +53 -4
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/cloud-api.ts +123 -22
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/emulator.ts +30 -20
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/index.ts +146 -21
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/open.ts +40 -3
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/run.ts +8 -1
- package/templates/supplier-payments-agent/packages/agent-runtime/src/channels/whatsapp/session.ts +16 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll-whatsapp.ts +70 -20
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/poll.ts +2 -1
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/resume.ts +8 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start-whatsapp.ts +3 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/start.ts +6 -3
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/verify.ts +239 -38
- package/templates/supplier-payments-agent/packages/agent-runtime/src/commands/webhook.ts +3 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/index.ts +1 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/src/inspect.ts +5 -1
- package/templates/supplier-payments-agent/packages/agent-runtime/src/kit.ts +25 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/scenarios.ts +8 -2
- package/templates/supplier-payments-agent/packages/agent-runtime/src/setup.ts +13 -3
- package/templates/supplier-payments-agent/packages/agent-runtime/src/terminal.ts +127 -18
- package/templates/supplier-payments-agent/packages/agent-runtime/test/verify-cli.test.ts +211 -9
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-cloud-api.test.ts +45 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-session.test.ts +32 -0
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-status-replies.test.ts +182 -0
- package/templates/bills-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +0 -204
- package/templates/collections-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +0 -204
- package/templates/hello-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +0 -204
- package/templates/supplier-payments-agent/packages/agent-runtime/test/whatsapp-emulator.integration.test.ts +0 -204
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The timeline `inspect` assembles, against a proof bundle written by hand in
|
|
3
|
+
* the test rather than by the engine: what the command reads is the contract
|
|
4
|
+
* of section 11, so the fixture states that contract instead of inheriting
|
|
5
|
+
* whatever the engine happens to write today.
|
|
6
|
+
*/
|
|
7
|
+
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { tmpdir } from "node:os";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
|
+
import { ProofBundle } from "@codespar/agent-core";
|
|
12
|
+
import { assembleTimeline, redactorFor, renderHtml, renderText, VERIFY_NOTE } from "../src/inspect.js";
|
|
13
|
+
|
|
14
|
+
const ESCOLA = "financeiro@escola-aurora.example.com.br";
|
|
15
|
+
const MASKED = "fi***@escola-aurora.example.com.br";
|
|
16
|
+
const MERCADO = "+5511999990001";
|
|
17
|
+
const AGENT = { type: "agent", agent: "bills-agent@0.1.0", on_behalf_of: "usr_demo_titular" };
|
|
18
|
+
const PERSON = { type: "human", id: "usr_demo_titular", channel: "terminal" };
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A run with two executions: one escalated to a person and settled, one the
|
|
22
|
+
* rail refused. Every file the bundle promises except `verify.json`.
|
|
23
|
+
*/
|
|
24
|
+
function fixtureBundle(): ProofBundle {
|
|
25
|
+
const dir = mkdtempSync(join(tmpdir(), "inspect-fixture-"));
|
|
26
|
+
const bundle = new ProofBundle(dir, "run_fixture_human_abc123");
|
|
27
|
+
|
|
28
|
+
bundle.meta({ run_id: "run_fixture_human_abc123", agent: "bills-agent@0.1.0", mode: "mandate", rail: "stub", mandate_id: "cm_fixture", mandate_version: 3, started_at: "2026-09-23T18:00:00.000Z" });
|
|
29
|
+
|
|
30
|
+
writeFileSync(
|
|
31
|
+
join(bundle.dir, "mandate.snapshot.json"),
|
|
32
|
+
JSON.stringify({
|
|
33
|
+
id: "cm_fixture",
|
|
34
|
+
version: 3,
|
|
35
|
+
status: "active",
|
|
36
|
+
currency: "BRL",
|
|
37
|
+
cap_minor: 7200000,
|
|
38
|
+
per_tx_cap_minor: 250000,
|
|
39
|
+
periodic_cap: { window: "month", cap_minor: 600000 },
|
|
40
|
+
expires_at: "2027-09-23T00:00:00.000Z",
|
|
41
|
+
// As the bundle writes it: already masked.
|
|
42
|
+
beneficiaries: [{ alias: "escola", name: "Escola Aurora", payee: MASKED }],
|
|
43
|
+
merchant_allowlist: [MASKED],
|
|
44
|
+
}),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
writeFileSync(
|
|
48
|
+
join(bundle.dir, "approval.json"),
|
|
49
|
+
JSON.stringify([
|
|
50
|
+
{
|
|
51
|
+
approval_id: "apr_one",
|
|
52
|
+
execution_id: "exe_one",
|
|
53
|
+
mode: "mandate",
|
|
54
|
+
approver: { type: "person", id: "usr_demo_titular", channel: "terminal" },
|
|
55
|
+
approved_at: "2026-09-23T18:00:15.000Z",
|
|
56
|
+
expires_at: "2026-09-23T18:15:15.000Z",
|
|
57
|
+
mandate: { id: "cm_fixture", version: 3 },
|
|
58
|
+
items: [{ alias: "escola", beneficiary: "Escola Aurora", payee: ESCOLA, amount: 185000, currency: "BRL", description: "mensalidade outubro" }],
|
|
59
|
+
items_hash: "sha256:deadbeef",
|
|
60
|
+
// The detail names the payee in free text: masking the field alone would leave the key readable here.
|
|
61
|
+
escalation: { trigger: "amount", detail: `total 185000 is above the threshold for ${ESCOLA}` },
|
|
62
|
+
actor: PERSON,
|
|
63
|
+
signature: { alg: "HMAC-SHA256", key_id: "local-dev-stub", value: "0".repeat(64) },
|
|
64
|
+
},
|
|
65
|
+
]),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
for (const event of [
|
|
69
|
+
{ seq: 1, run_id: "run_fixture_human_abc123", execution_id: "exe_one", type: "execution.drafted", payload: { items: [{ alias: "escola", beneficiary: "Escola Aurora", payee: ESCOLA, amount: 185000, currency: "BRL", description: "mensalidade outubro" }], total: 185000, model_claimed_total: 120000, mode: "mandate" }, at: "2026-09-23T18:00:11.000Z", actor: AGENT },
|
|
70
|
+
{ seq: 2, run_id: "run_fixture_human_abc123", execution_id: "exe_one", type: "execution.model_total_ignored", payload: { detail: "the model stated 120000; the core computed 185000" }, at: "2026-09-23T18:00:11.500Z", actor: AGENT },
|
|
71
|
+
{ seq: 3, run_id: "run_fixture_human_abc123", execution_id: "exe_one", type: "execution.transition", payload: { from: "drafted", to: "awaiting_approval", at: "2026-09-23T18:00:12.000Z", actor: AGENT, reason: "escalated", detail: `amount: above the threshold for ${ESCOLA}` }, at: "2026-09-23T18:00:12.000Z", actor: AGENT },
|
|
72
|
+
{ seq: 4, run_id: "run_fixture_human_abc123", execution_id: "exe_one", type: "approval.created", payload: { approval_id: "apr_one", approver: { type: "person", id: "usr_demo_titular", channel: "terminal" }, items_hash: "sha256:deadbeef", escalation: { trigger: "amount", detail: "x" } }, at: "2026-09-23T18:00:16.000Z", actor: AGENT },
|
|
73
|
+
{ seq: 5, run_id: "run_fixture_human_abc123", execution_id: "exe_one", type: "execution.transition", payload: { from: "awaiting_approval", to: "approved", at: "2026-09-23T18:00:15.000Z", actor: PERSON }, at: "2026-09-23T18:00:15.000Z", actor: PERSON },
|
|
74
|
+
{ seq: 6, run_id: "run_fixture_human_abc123", execution_id: "exe_one", type: "execution.transition", payload: { from: "approved", to: "executing", at: "2026-09-23T18:00:17.000Z", actor: AGENT, detail: "idempotency_key idk_one" }, at: "2026-09-23T18:00:17.000Z", actor: AGENT },
|
|
75
|
+
{ seq: 7, run_id: "run_fixture_human_abc123", execution_id: "exe_one", type: "rail.dispatch", payload: { attempt_id: "att_one_0", payee: ESCOLA, amount: 185000, rail: "stub", idempotency_key: "idk_one" }, at: "2026-09-23T18:00:21.000Z", actor: AGENT },
|
|
76
|
+
{ seq: 8, run_id: "run_fixture_human_abc123", execution_id: "exe_one", type: "rail.outcome", payload: { attempt_id: "att_one_0", status: "settled", transaction_id: "tx_one", receipt_id: "rcpt_one", money_moved: false, sandbox: true }, at: "2026-09-23T18:00:23.000Z", actor: AGENT },
|
|
77
|
+
{ seq: 9, run_id: "run_fixture_human_abc123", execution_id: "exe_one", type: "commerce.payment.succeeded", payload: { attempt_id: "att_one_0", amount: 185000, payee: ESCOLA, receipt_id: "rcpt_one", actor: AGENT }, at: "2026-09-23T18:00:24.000Z", actor: AGENT },
|
|
78
|
+
{ seq: 10, run_id: "run_fixture_human_abc123", execution_id: "exe_one", type: "receipt.saved", payload: { receipt_id: "rcpt_one", path: "receipts/rcpt_one.json" }, at: "2026-09-23T18:00:25.000Z", actor: AGENT },
|
|
79
|
+
{ seq: 11, run_id: "run_fixture_human_abc123", execution_id: "exe_one", type: "execution.transition", payload: { from: "executing", to: "settled", at: "2026-09-23T18:00:26.000Z", actor: AGENT }, at: "2026-09-23T18:00:26.000Z", actor: AGENT },
|
|
80
|
+
|
|
81
|
+
{ seq: 12, run_id: "run_fixture_human_abc123", execution_id: "exe_two", type: "execution.drafted", payload: { items: [{ alias: "mercado", beneficiary: "Mercado do Bairro", payee: MERCADO, amount: 64000, currency: "BRL" }], total: 64000, model_claimed_total: null, mode: "mandate" }, at: "2026-09-23T18:01:00.000Z", actor: AGENT },
|
|
82
|
+
{ seq: 13, run_id: "run_fixture_human_abc123", execution_id: "exe_two", type: "execution.transition", payload: { from: "drafted", to: "approved", at: "2026-09-23T18:01:01.000Z", actor: AGENT, detail: "within the signed allowance" }, at: "2026-09-23T18:01:01.000Z", actor: AGENT },
|
|
83
|
+
{ seq: 14, run_id: "run_fixture_human_abc123", execution_id: "exe_two", type: "execution.transition", payload: { from: "approved", to: "executing", at: "2026-09-23T18:01:02.000Z", actor: AGENT, detail: "idempotency_key idk_two" }, at: "2026-09-23T18:01:02.000Z", actor: AGENT },
|
|
84
|
+
{ seq: 15, run_id: "run_fixture_human_abc123", execution_id: "exe_two", type: "rail.dispatch", payload: { attempt_id: "att_two_0", payee: MERCADO, amount: 64000, rail: "stub", idempotency_key: "idk_two" }, at: "2026-09-23T18:01:03.000Z", actor: AGENT },
|
|
85
|
+
{ seq: 16, run_id: "run_fixture_human_abc123", execution_id: "exe_two", type: "rail.outcome", payload: { attempt_id: "att_two_0", status: "failed", code: "payee_refused", message: `the rail refused ${MERCADO}` }, at: "2026-09-23T18:01:04.000Z", actor: AGENT },
|
|
86
|
+
{ seq: 17, run_id: "run_fixture_human_abc123", execution_id: "exe_two", type: "rail.reconcile", payload: { attempt_id: "att_two_0", found: "failed" }, at: "2026-09-23T18:01:05.000Z", actor: AGENT },
|
|
87
|
+
{ seq: 18, run_id: "run_fixture_human_abc123", execution_id: "exe_two", type: "execution.transition", payload: { from: "executing", to: "failed", at: "2026-09-23T18:01:06.000Z", actor: AGENT, reason: "rail_failed" }, at: "2026-09-23T18:01:06.000Z", actor: AGENT },
|
|
88
|
+
|
|
89
|
+
{ seq: 19, run_id: "run_fixture_human_abc123", execution_id: null, type: "execution.refused_before_draft", payload: { reason: "mandate_revoked", detail: "mandate cm_fixture was revoked" }, at: "2026-09-23T18:02:00.000Z", actor: AGENT },
|
|
90
|
+
{ at: "2026-09-23T18:02:01.000Z", type: "tool.refused", tool: "codespar_transfer", reason: "tool_not_allowed", actor: AGENT },
|
|
91
|
+
]) {
|
|
92
|
+
bundle.event(event as Record<string, unknown>);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
writeFileSync(join(bundle.dir, "receipts", "rcpt_one.json"), JSON.stringify({ receipt_id: "rcpt_one", state: "paid", payment: { amount_minor: 185000, payee: MASKED, money_moved: false, sandbox: true, at: "2026-09-23T18:00:22.000Z" }, actor: AGENT }));
|
|
96
|
+
|
|
97
|
+
bundle.transcript({ at: "2026-09-23T18:00:02.000Z", kind: "user", text: "pague a escola de outubro" });
|
|
98
|
+
bundle.transcript({ at: "2026-09-23T18:00:04.000Z", kind: "tool_call", name: "list_bills", input: {} });
|
|
99
|
+
bundle.transcript({ at: "2026-09-23T18:00:07.000Z", kind: "tool_call", name: "codespar_pay", input: {} });
|
|
100
|
+
bundle.transcript({ at: "2026-09-23T18:00:08.000Z", kind: "tool_result", name: "codespar_transfer", refused: true, content: {} });
|
|
101
|
+
|
|
102
|
+
return bundle;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
describe("the timeline `inspect` assembles from a bundle", () => {
|
|
106
|
+
it("reads the run's mode, rail, mandate and the version it ran under", () => {
|
|
107
|
+
const report = assembleTimeline(fixtureBundle());
|
|
108
|
+
expect(report.run).toMatchObject({ run_id: "run_fixture_human_abc123", agent: "bills-agent@0.1.0", mode: "mandate", rail: "stub", mandate_id: "cm_fixture", mandate_version: 3 });
|
|
109
|
+
expect(report.mandate).toMatchObject({ id: "cm_fixture", version: 3, status: "active", per_tx_cap_minor: 250000, cap_minor: 7200000, periodic_cap: { window: "month", cap_minor: 600000 } });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("names who proposed what, with the total the core computed and the one the model claimed", () => {
|
|
113
|
+
const report = assembleTimeline(fixtureBundle());
|
|
114
|
+
const one = report.executions.find((e) => e.execution_id === "exe_one")!;
|
|
115
|
+
expect(one.proposed_at).toBe("2026-09-23T18:00:11.000Z");
|
|
116
|
+
expect(one.total_minor).toBe(185000);
|
|
117
|
+
expect(one.model_claimed_total).toBe(120000);
|
|
118
|
+
expect(one.items).toEqual([{ beneficiary: "Escola Aurora", payee: MASKED, amount_minor: 185000, currency: "BRL", description: "mensalidade outubro", due_date: null }]);
|
|
119
|
+
expect(one.notes.some((n) => n.type === "execution.model_total_ignored")).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("names who approved it and when, with the items_hash, the mandate version and the escalation trigger", () => {
|
|
123
|
+
const report = assembleTimeline(fixtureBundle());
|
|
124
|
+
const approval = report.executions.find((e) => e.execution_id === "exe_one")!.approval!;
|
|
125
|
+
expect(approval).toMatchObject({ approval_id: "apr_one", approved_at: "2026-09-23T18:00:15.000Z", expires_at: "2026-09-23T18:15:15.000Z", items_hash: "sha256:deadbeef", mandate: { id: "cm_fixture", version: 3 } });
|
|
126
|
+
expect(approval.approver).toEqual({ type: "person", id: "usr_demo_titular", channel: "terminal" });
|
|
127
|
+
expect(approval.escalation?.trigger).toBe("amount");
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it("carries every transition with its actor, in order", () => {
|
|
131
|
+
const report = assembleTimeline(fixtureBundle());
|
|
132
|
+
const one = report.executions.find((e) => e.execution_id === "exe_one")!;
|
|
133
|
+
expect(one.transitions.map((t) => t.to)).toEqual(["awaiting_approval", "approved", "executing", "settled"]);
|
|
134
|
+
expect(one.final_state).toBe("settled");
|
|
135
|
+
expect(one.transitions[0]?.actor).toBe("agent bills-agent@0.1.0 for usr_demo_titular");
|
|
136
|
+
expect(one.transitions[1]?.actor).toBe("usr_demo_titular (person, terminal)");
|
|
137
|
+
expect(one.transitions[0]?.reason).toBe("escalated");
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it("names the call that went out and what the rail answered, per attempt", () => {
|
|
141
|
+
const report = assembleTimeline(fixtureBundle());
|
|
142
|
+
const settled = report.executions.find((e) => e.execution_id === "exe_one")!.attempts[0]!;
|
|
143
|
+
expect(settled).toMatchObject({ attempt_id: "att_one_0", idempotency_key: "idk_one", rail: "stub", amount_minor: 185000, payee: MASKED });
|
|
144
|
+
expect(settled.answer).toMatchObject({ status: "settled", transaction_id: "tx_one", receipt_id: "rcpt_one", money_moved: false, sandbox: true });
|
|
145
|
+
|
|
146
|
+
const refused = report.executions.find((e) => e.execution_id === "exe_two")!.attempts[0]!;
|
|
147
|
+
expect(refused.answer).toMatchObject({ status: "failed", code: "payee_refused" });
|
|
148
|
+
expect(refused.reconciles).toEqual([{ at: "2026-09-23T18:01:05.000Z", found: "failed" }]);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it("lists the receipts that came back, and the events that belong to no execution", () => {
|
|
152
|
+
const report = assembleTimeline(fixtureBundle());
|
|
153
|
+
expect(report.receipts).toEqual([{ receipt_id: "rcpt_one", file: "receipts/rcpt_one.json", state: "paid", amount_minor: 185000, payee: MASKED, money_moved: false, sandbox: true, at: "2026-09-23T18:00:22.000Z" }]);
|
|
154
|
+
expect(report.executions.find((e) => e.execution_id === "exe_one")!.receipts).toEqual(["rcpt_one"]);
|
|
155
|
+
expect(report.run_events.map((e) => e.type)).toEqual(["execution.refused_before_draft", "tool.refused"]);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("reports the conversation as counts and never as text", () => {
|
|
159
|
+
const report = assembleTimeline(fixtureBundle());
|
|
160
|
+
expect(report.conversation).toEqual({ turns: 1, tool_calls: 2, tools: ["list_bills", "codespar_pay"], refused_tools: ["codespar_transfer"] });
|
|
161
|
+
expect(JSON.stringify(report)).not.toContain("pague a escola de outubro");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("says why verify.json is absent instead of pretending it is optional", () => {
|
|
165
|
+
const report = assembleTimeline(fixtureBundle());
|
|
166
|
+
expect(report.verify).toEqual({ present: false, note: VERIFY_NOTE });
|
|
167
|
+
expect(report.verify.note).toContain("codespar audit replay");
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe("masking: inspect never un-masks and never leaks a key it read raw", () => {
|
|
172
|
+
it("no raw payee survives into the report, the text or the HTML", () => {
|
|
173
|
+
const report = assembleTimeline(fixtureBundle());
|
|
174
|
+
for (const rendering of [JSON.stringify(report), renderText(report), renderHtml(report)]) {
|
|
175
|
+
expect(rendering).not.toContain(ESCOLA);
|
|
176
|
+
expect(rendering).not.toContain(MERCADO);
|
|
177
|
+
expect(rendering).toContain(MASKED);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("masks the payee named inside free text, not only the payee field", () => {
|
|
182
|
+
const report = assembleTimeline(fixtureBundle());
|
|
183
|
+
const one = report.executions.find((e) => e.execution_id === "exe_one")!;
|
|
184
|
+
expect(one.approval?.escalation?.detail).toBe(`total 185000 is above the threshold for ${MASKED}`);
|
|
185
|
+
expect(one.transitions[0]?.detail).toBe(`amount: above the threshold for ${MASKED}`);
|
|
186
|
+
const two = report.executions.find((e) => e.execution_id === "exe_two")!;
|
|
187
|
+
expect(two.attempts[0]?.answer?.message).toBe("the rail refused +551***0001");
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("leaves a value the bundle already masked alone", () => {
|
|
191
|
+
const redact = redactorFor([ESCOLA, MERCADO]);
|
|
192
|
+
expect(redact(`paid ${MASKED} today`)).toBe(`paid ${MASKED} today`);
|
|
193
|
+
expect(redact(null)).toBeNull();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe("the renderings", () => {
|
|
198
|
+
it("the terminal rendering shows the whole chain for one execution", () => {
|
|
199
|
+
const text = renderText(assembleTimeline(fixtureBundle()));
|
|
200
|
+
expect(text).toContain("mode mandate · rail stub · mandate cm_fixture v3");
|
|
201
|
+
expect(text).toContain("execution exe_one — settled");
|
|
202
|
+
expect(text).toContain("proposed");
|
|
203
|
+
expect(text).toContain("items_hash sha256:deadbeef");
|
|
204
|
+
expect(text).toContain("escalated by amount");
|
|
205
|
+
expect(text).toContain("idempotency_key idk_one");
|
|
206
|
+
expect(text).toContain("rail says settled");
|
|
207
|
+
expect(text).toContain("receipts/rcpt_one.json");
|
|
208
|
+
expect(text).toContain("outside any execution");
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("the HTML is one standalone file: no script, no fetch, no external src or href", () => {
|
|
212
|
+
const html = renderHtml(assembleTimeline(fixtureBundle()));
|
|
213
|
+
expect(html).toMatch(/^<!doctype html>/);
|
|
214
|
+
expect(html).toContain("</html>");
|
|
215
|
+
expect(html).not.toMatch(/<script/i);
|
|
216
|
+
expect(html).not.toMatch(/(src|href)\s*=\s*["']?(https?:)?\/\//i);
|
|
217
|
+
expect(html).not.toMatch(/https?:\/\//i);
|
|
218
|
+
expect(html).not.toMatch(/<link\b/i);
|
|
219
|
+
expect(html).not.toMatch(/@import/i);
|
|
220
|
+
expect(html).not.toMatch(/url\(/i);
|
|
221
|
+
// Same content as the terminal rendering.
|
|
222
|
+
expect(html).toContain("exe_one");
|
|
223
|
+
expect(html).toContain("sha256:deadbeef");
|
|
224
|
+
expect(html).toContain("rcpt_one");
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it("escapes what it puts in the HTML", () => {
|
|
228
|
+
const bundle = fixtureBundle();
|
|
229
|
+
bundle.event({ at: "2026-09-23T18:03:00.000Z", type: "tool.error", tool: "<img onerror=alert(1)>", message: "boom", actor: AGENT });
|
|
230
|
+
const html = renderHtml(assembleTimeline(bundle));
|
|
231
|
+
expect(html).not.toContain("<img onerror");
|
|
232
|
+
expect(html).toContain("<img onerror=alert(1)>");
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Issue #21. A bundle of a batch holds N timelines, and before this there was
|
|
238
|
+
* nothing in it to compare them against: three lines read as three lines.
|
|
239
|
+
* The header is what makes them "3 of 4", and the fourth is either a line a
|
|
240
|
+
* person denied — an execution with no artifact — or a line that never ran at
|
|
241
|
+
* all, which is the one nothing used to say existed.
|
|
242
|
+
*/
|
|
243
|
+
const BATCH_HASH = "sha256:" + "a1".repeat(32);
|
|
244
|
+
|
|
245
|
+
/** A four-line payroll of which this bundle holds three: line 2 denied, line 3 never drafted. */
|
|
246
|
+
function batchBundle(): ProofBundle {
|
|
247
|
+
const dir = mkdtempSync(join(tmpdir(), "inspect-batch-"));
|
|
248
|
+
const bundle = new ProofBundle(dir, "run_fixture_batch_def456");
|
|
249
|
+
bundle.meta({ run_id: "run_fixture_batch_def456", agent: "supplier-payments-agent@0.1.0", mode: "human", rail: "stub", mandate_id: "cm_fixture", mandate_version: 1 });
|
|
250
|
+
|
|
251
|
+
const binding = (index: number) => ({ ref: "folha-2026-10", batch_hash: BATCH_HASH, index, count: 4 });
|
|
252
|
+
const drafted = (id: string, index: number, at: string) => ({ run_id: "run_fixture_batch_def456", execution_id: id, type: "execution.drafted", payload: { items: [{ beneficiary: `Line ${index}`, payee: `line${index}@exemplo.com.br`, amount: 1000, currency: "BRL" }], total: 1000, model_claimed_total: null, mode: "human", batch: binding(index) }, at, actor: AGENT });
|
|
253
|
+
const moved = (id: string, from: string, to: string, at: string) => ({ run_id: "run_fixture_batch_def456", execution_id: id, type: "execution.transition", payload: { from, to, at, actor: AGENT }, at, actor: AGENT });
|
|
254
|
+
|
|
255
|
+
writeFileSync(
|
|
256
|
+
join(bundle.dir, "approval.json"),
|
|
257
|
+
JSON.stringify(
|
|
258
|
+
[0, 3].map((index) => ({
|
|
259
|
+
approval_id: `apr_line_${index}`,
|
|
260
|
+
execution_id: `exe_line_${index}`,
|
|
261
|
+
mode: "human",
|
|
262
|
+
approver: { type: "person", id: "usr_operator", channel: "terminal" },
|
|
263
|
+
approved_at: "2026-09-23T18:00:10.000Z",
|
|
264
|
+
expires_at: "2026-09-23T18:15:10.000Z",
|
|
265
|
+
mandate: { id: "cm_fixture", version: 1 },
|
|
266
|
+
items: [{ beneficiary: `Line ${index}`, payee: `line${index}@exemplo.com.br`, amount: 1000, currency: "BRL" }],
|
|
267
|
+
items_hash: `sha256:line${index}`,
|
|
268
|
+
batch: binding(index),
|
|
269
|
+
actor: PERSON,
|
|
270
|
+
signature: { alg: "HMAC-SHA256", key_id: "local-dev-stub", value: "0".repeat(64) },
|
|
271
|
+
})),
|
|
272
|
+
),
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
for (const event of [
|
|
276
|
+
drafted("exe_line_0", 0, "2026-09-23T18:00:09.000Z"),
|
|
277
|
+
moved("exe_line_0", "approved", "settled", "2026-09-23T18:00:11.000Z"),
|
|
278
|
+
drafted("exe_line_1", 1, "2026-09-23T18:00:12.000Z"),
|
|
279
|
+
moved("exe_line_1", "awaiting_approval", "denied", "2026-09-23T18:00:13.000Z"),
|
|
280
|
+
drafted("exe_line_3", 3, "2026-09-23T18:00:14.000Z"),
|
|
281
|
+
moved("exe_line_3", "approved", "settled", "2026-09-23T18:00:15.000Z"),
|
|
282
|
+
]) {
|
|
283
|
+
bundle.event(event as unknown as Record<string, unknown>);
|
|
284
|
+
}
|
|
285
|
+
return bundle;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
describe("a batch read back as a set", () => {
|
|
289
|
+
it("counts the lines the list held, the ones attested, and the one that is not here at all", () => {
|
|
290
|
+
const report = assembleTimeline(batchBundle());
|
|
291
|
+
expect(report.batches).toHaveLength(1);
|
|
292
|
+
const batch = report.batches[0]!;
|
|
293
|
+
expect(batch).toMatchObject({ ref: "folha-2026-10", batch_hash: BATCH_HASH, count: 4, attested: 2, missing: [2] });
|
|
294
|
+
// A denied line has an execution and no artifact; line 3 of the list has neither.
|
|
295
|
+
expect(batch.lines.map((l) => [l.index, l.final_state, l.attested])).toEqual([
|
|
296
|
+
[0, "settled", true],
|
|
297
|
+
[1, "denied", false],
|
|
298
|
+
[3, "settled", true],
|
|
299
|
+
]);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("puts the header before the timelines and says which line each execution is", () => {
|
|
303
|
+
const text = renderText(assembleTimeline(batchBundle()));
|
|
304
|
+
expect(text).toContain("batch folha-2026-10 — 2 of 4 line(s) attested · 3 with an execution · no execution for line(s) 3");
|
|
305
|
+
expect(text).toContain(`batch_hash ${BATCH_HASH}`);
|
|
306
|
+
expect(text).toContain("line 3 of 4 — no execution in this bundle");
|
|
307
|
+
expect(text).toContain("execution exe_line_0 — settled · folha-2026-10 line 1 of 4");
|
|
308
|
+
// The header comes first: a reader learns the list held four before reading the three.
|
|
309
|
+
expect(text.indexOf("batch folha-2026-10")).toBeLessThan(text.indexOf("execution exe_line_0"));
|
|
310
|
+
// And the approval line of each timeline names the binding next to the items_hash.
|
|
311
|
+
expect(text).toContain(`line 1 of 4 of batch folha-2026-10 · batch_hash ${BATCH_HASH}`);
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it("the HTML says the same thing and stays one standalone file", () => {
|
|
315
|
+
const html = renderHtml(assembleTimeline(batchBundle()));
|
|
316
|
+
expect(html).toContain("2 of 4 line(s) attested");
|
|
317
|
+
expect(html).toContain("no execution for line(s) 3");
|
|
318
|
+
expect(html).toContain(BATCH_HASH);
|
|
319
|
+
expect(html).not.toMatch(/<script/i);
|
|
320
|
+
expect(html).not.toMatch(/https?:\/\//i);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("reads a binding that cannot be true as no binding, rather than rendering a count nobody should trust", () => {
|
|
324
|
+
const bundle = batchBundle();
|
|
325
|
+
// A bundle is a file somebody may have edited. "line 9 of 4" is not a set.
|
|
326
|
+
bundle.event({ run_id: "run_fixture_batch_def456", execution_id: "exe_line_9", type: "execution.drafted", payload: { items: [], total: 0, model_claimed_total: null, mode: "human", batch: { ref: "folha-2026-10", batch_hash: BATCH_HASH, index: 9, count: 4 } }, at: "2026-09-23T18:00:16.000Z", actor: AGENT });
|
|
327
|
+
const report = assembleTimeline(bundle);
|
|
328
|
+
expect(report.batches[0]!.lines.map((l) => l.index)).toEqual([0, 1, 3]);
|
|
329
|
+
expect(report.executions.find((e) => e.execution_id === "exe_line_9")!.batch).toBeNull();
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("a run with no batch grows no header", () => {
|
|
333
|
+
expect(assembleTimeline(fixtureBundle()).batches).toEqual([]);
|
|
334
|
+
expect(renderText(assembleTimeline(fixtureBundle()))).not.toContain("batch_hash");
|
|
335
|
+
});
|
|
336
|
+
});
|