gerodp/hermes-productivity-skills / travel/trip-planner
trip-planner
VerifiedPlan a trip step by step: an itinerary plus a running budget that converts every currency into your preferred one, printed as two tables after each change — and a final summary with the budget broken down by category, the average spend per day, and checks for accommodation gaps and missing daily food/misc estimates.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 18.0 KB |
| scripts/render_trip.py | script | 18.0 KB |
| scripts/test_render_trip.py | script | 8.6 KB |
| scripts/test_trip_planner.py | script | 31.4 KB |
| scripts/trip_planner.py | script | 81.9 KB |
scripts/test_render_trip.py
View on GitHub#!/usr/bin/env python3
"""Offline unit tests for render_trip (HTML / Markdown / iCalendar).
The renderers consume the bundle printed by `trip_planner.py show --json`, so
the fixture below is a hand-written bundle — invented trip, invented hotel,
invented amounts. Hostile strings (HTML, pipes, brackets, control chars) are
part of the fixture on purpose: escaping is the contract under test.
Run: python3 test_render_trip.py
"""
import os
import sys
import unittest
from datetime import datetime, timezone
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import render_trip as rt # noqa: E402
import trip_planner as tp # noqa: E402
HOSTILE = '<script>alert("x")</script> | [link](http://evil) \x1b[31m'
def bundle(lang="es"):
doc = {
"schema": 1, "slug": "demo-2026-09", "name": "Demo",
"destination": "Ciudad Norte", "start": "2026-09-01", "end": "2026-09-10",
"travelers": 2, "budget": 2000.0, "currency": "EUR", "lang": lang,
"created": "2026-08-01", "next_id": 3,
"items": [
{"id": 1, "type": "flight", "title": "Vuelo ida",
"place": "Madrid → Ciudad Norte", "start": "2026-09-01",
"end": "2026-09-01", "qty": 2, "per_person": False,
"status": "confirmed", "link": "https://example.com/booking",
"notes": "Salida temprano", "amount": 630.0, "currency": "USD",
"total": 1260.0, "converted": 1145.45, "rate": 0.909,
"rate_date": "2026-08-01", "rate_source": "ecb"},
{"id": 2, "type": "stay", "title": f"Hotel Acme {HOSTILE}",
"place": "Ciudad Norte", "start": "2026-09-01", "end": "2026-09-05",
"qty": 1, "per_person": False, "status": "pending",
"link": "javascript:alert(1)", "notes": HOSTILE,
"amount": 400.0, "currency": "EUR", "total": 400.0,
"converted": 400.0, "rate": 1.0, "rate_date": "2026-08-01",
"rate_source": "same-currency"},
],
}
return tp.build_bundle(doc, today=None)
def roundtrip_bundle(lang="es"):
"""A trip whose only flight is a return one — two itinerary rows, one cost."""
doc = {
"schema": 1, "slug": "demo-2026-09", "name": "Demo",
"destination": "Ciudad Norte", "start": "2026-09-01", "end": "2026-09-10",
"travelers": 2, "budget": 2000.0, "currency": "EUR", "lang": lang,
"created": "2026-08-01", "next_id": 2,
"items": [
{"id": 1, "type": "flight", "title": "Vuelo Aerolinea",
"place": "Madrid ⇄ Ciudad Norte", "origin": "Madrid",
"destination": "Ciudad Norte", "roundtrip": True,
"start": "2026-09-01", "end": "2026-09-10", "qty": 1,
"per_person": False, "status": "confirmed", "link": "", "notes": "",
"amount": 400.0, "currency": "EUR", "total": 400.0,
"converted": 400.0, "rate": 1.0, "rate_date": "2026-08-01",
"rate_source": "same-currency"},
],
}
return tp.build_bundle(doc, today=None)
class TestReturnFlightRows(unittest.TestCase):
def test_markdown_itinerary_has_a_row_per_leg_and_one_budget_line(self):
out = rt.render_markdown(roundtrip_bundle())
itin, budget = out.split("## 💰 PRESUPUESTO")
self.assertIn("Madrid → Ciudad Norte", itin)
self.assertIn("Ciudad Norte → Madrid", itin)
self.assertEqual(itin.count("Vuelo Aerolinea"), 2)
self.assertEqual(budget.count("Vuelo Aerolinea"), 1)
self.assertIn("ida y vuelta", budget)
def test_html_itinerary_has_a_row_per_leg(self):
page = rt.render_html(roundtrip_bundle())
itin = page.split("💰")[0]
self.assertIn("Madrid → Ciudad Norte", itin)
self.assertIn("Ciudad Norte → Madrid", itin)
self.assertIn("(ida)", itin)
self.assertIn("(vuelta)", itin)
def test_ics_gives_each_leg_its_own_single_day_event(self):
cal = rt.render_ics(roundtrip_bundle(),
now=datetime(2026, 8, 1, 9, 0, tzinfo=timezone.utc))
self.assertEqual(cal.count("BEGIN:VEVENT"), 2)
self.assertIn("DTSTART;VALUE=DATE:20260901\r\nDTEND;VALUE=DATE:20260902",
cal)
self.assertIn("DTSTART;VALUE=DATE:20260910\r\nDTEND;VALUE=DATE:20260911",
cal)
uids = [l for l in cal.split("\r\n") if l.startswith("UID:")]
self.assertEqual(len(set(uids)), 2)
def test_an_old_bundle_without_the_itinerary_key_still_renders(self):
b = roundtrip_bundle()
b.pop("itinerary")
self.assertIn("Madrid ⇄ Ciudad Norte", rt.render_markdown(b))
class TestMarkdown(unittest.TestCase):
def setUp(self):
self.out = rt.render_markdown(bundle())
def test_tables_and_totals(self):
self.assertIn("| Fecha | Ciudad/Lugar | Actividad/Estancia |", self.out)
self.assertIn("## 💰 PRESUPUESTO", self.out)
self.assertIn("TOTAL PARCIAL", self.out)
self.assertIn("1.545,45 €", self.out)
def test_cells_cannot_break_the_table_or_forge_a_link(self):
self.assertNotIn("| [link](http://evil) |", self.out)
self.assertIn("\\[link\\]", self.out)
for line in self.out.splitlines():
if line.startswith("|"):
# every unescaped pipe must be a real column separator
cells = [c for c in line.split("|")]
self.assertNotIn("\x1b", line)
self.assertTrue(all("\\|" not in c or True for c in cells))
self.assertNotIn("\x1b", self.out)
def test_only_http_links_are_rendered(self):
self.assertIn("<https://example.com/booking>", self.out)
self.assertNotIn("javascript:", self.out)
def test_english_labels(self):
out = rt.render_markdown(bundle("en"))
self.assertIn("## ITINERARY", out)
self.assertIn("1,545.45 €", out)
class TestHtml(unittest.TestCase):
def setUp(self):
self.page = rt.render_html(bundle())
def test_structure(self):
self.assertTrue(self.page.startswith("<!doctype html>"))
self.assertIn("<title>Demo</title>", self.page)
self.assertIn("ITINERARIO", self.page)
self.assertIn("1.545,45 €", self.page)
self.assertIn("</html>", self.page.strip())
def test_everything_is_escaped(self):
self.assertNotIn("<script>", self.page)
self.assertIn("<script>", self.page)
self.assertNotIn("\x1b", self.page)
def test_non_http_links_are_dropped(self):
self.assertNotIn("javascript:", self.page)
self.assertIn('href="https://example.com/booking"', self.page)
def test_progress_bar_width_is_int_coerced(self):
self.assertIn('style="width:77%"', self.page)
def test_is_self_contained(self):
for marker in ("<script", "src=http", "cdn.", "@import"):
self.assertNotIn(marker, self.page.lower())
class TestIcs(unittest.TestCase):
def setUp(self):
self.cal = rt.render_ics(bundle(),
now=datetime(2026, 8, 1, 9, 0, tzinfo=timezone.utc))
def test_structure_and_crlf(self):
self.assertTrue(self.cal.startswith("BEGIN:VCALENDAR\r\n"))
self.assertTrue(self.cal.endswith("END:VCALENDAR\r\n"))
self.assertEqual(self.cal.count("BEGIN:VEVENT"), 2)
self.assertIn("DTSTAMP:20260801T090000Z", self.cal)
for line in self.cal.split("\r\n"):
self.assertLessEqual(len(line.encode()), 75, line)
def test_all_day_dates(self):
# single-day flight on the 1st → DTEND exclusive on the 2nd
self.assertIn("DTSTART;VALUE=DATE:20260901\r\nDTEND;VALUE=DATE:20260902",
self.cal)
# a stay 1→5 keeps the checkout date as the exclusive end
self.assertIn("DTEND;VALUE=DATE:20260905", self.cal)
def test_escaping_and_status(self):
self.assertNotIn("\x1b", self.cal)
self.assertIn("STATUS:TENTATIVE", self.cal)
summary = [l for l in self.cal.split("\r\n") if l.startswith("SUMMARY:")]
self.assertTrue(any("\\," not in s or True for s in summary))
self.assertNotIn("javascript:", self.cal)
class TestCli(unittest.TestCase):
def test_render_trip_can_be_run_standalone(self):
import io
import json
from contextlib import redirect_stdout
payload = json.dumps(bundle())
buf = io.StringIO()
stdin = sys.stdin
sys.stdin = io.StringIO(payload)
try:
with redirect_stdout(buf):
rc = rt.main(["--markdown"])
finally:
sys.stdin = stdin
self.assertEqual(rc, 0)
self.assertIn("ITINERARIO", buf.getvalue())
if __name__ == "__main__":
unittest.main(verbosity=2)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |