HassamGani commited on
Commit ·
082d2d4
1
Parent(s): f6fb215
Messy worlds for hard and expert tasks: haystack records, hand-typed values, contract claims, tiered answers
Browse files- README.md +6 -1
- reorgbench/gen/build.py +37 -8
- reorgbench/gen/templates.py +197 -15
- reorgbench/gen/units.py +25 -5
- tests/test_generator.py +15 -0
README.md
CHANGED
|
@@ -181,11 +181,16 @@ The test split is generated from templates registered at run time with `register
|
|
| 181 |
|
| 182 |
**Knobs.** Each seed samples these knobs, and every task is tagged with them so results can be broken down:
|
| 183 |
|
| 184 |
-
- customers in scope (4–64);
|
| 185 |
- most agents per per-customer role;
|
| 186 |
- the changes (up to three) and their order;
|
| 187 |
- traps: closed accounts, already-moved namesakes, look-alike plans or vendors, earlier partial refunds, an old closed copy of a customer's ticket, tickets that claim a seat count the record doesn't have;
|
| 188 |
- whether there's a code change;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
- the target tier.
|
| 190 |
|
| 191 |
Tiers are earned by structure:
|
|
|
|
| 181 |
|
| 182 |
**Knobs.** Each seed samples these knobs, and every task is tagged with them so results can be broken down:
|
| 183 |
|
| 184 |
+
- customers in scope (4–64; expert 32–64);
|
| 185 |
- most agents per per-customer role;
|
| 186 |
- the changes (up to three) and their order;
|
| 187 |
- traps: closed accounts, already-moved namesakes, look-alike plans or vendors, earlier partial refunds, an old closed copy of a customer's ticket, tickets that claim a seat count the record doesn't have;
|
| 188 |
- whether there's a code change;
|
| 189 |
+
- messy records (every hard and expert seed):
|
| 190 |
+
- the job buried among two to three times as many unrelated customers and tickets;
|
| 191 |
+
- the scope field typed in different capitals;
|
| 192 |
+
- customers citing a contract that keeps them where they are (someone has to read each contract; about half hold, and those customers must be left alone);
|
| 193 |
+
- answers that depend on account size: two maintenance windows by seat count, or volume pricing from a price sheet, so each notice needs that customer's seats;
|
| 194 |
- the target tier.
|
| 195 |
|
| 196 |
Tiers are earned by structure:
|
reorgbench/gen/build.py
CHANGED
|
@@ -23,12 +23,12 @@ from ..tasks.spec import (
|
|
| 23 |
)
|
| 24 |
from .units import (
|
| 25 |
Ask, Close, Code, Credit, Move, Notify, Refund, Unit, credits_by, current_says, is_retraction, refunds_on, replies, says,
|
| 26 |
-
rerun_tests, told_and_not_retracted,
|
| 27 |
)
|
| 28 |
from .world import Acct, Ids
|
| 29 |
|
| 30 |
# hire consumers of facts before their providers, so a provider's brief already names who to send to
|
| 31 |
-
HIRE_ORDER = ["support", "finance", "engineer", "procurement", "analyst"]
|
| 32 |
LOOSE = Budgets(round_cap=400, action_cap=4000)
|
| 33 |
LIST_ROWS = "db.query"
|
| 34 |
HARD_BUDGET, STANDARD_BUDGET = 1.5, 3.0
|
|
@@ -49,10 +49,12 @@ class Knobs:
|
|
| 49 |
code: bool = True # add a code change (one more role)
|
| 50 |
budget: float = 3.0 # rounds and actions allowed, as a multiple of the careful oracle's (1.5
|
| 51 |
# makes a task hard if its structure qualifies; otherwise it gets 3.0)
|
|
|
|
| 52 |
|
| 53 |
def tags(self) -> list[str]:
|
| 54 |
return [f"n{self.n}", f"crew{self.crew}", f"changes{len(self.changes)}", f"traps{self.traps}",
|
| 55 |
-
*(c.lower().replace(":", "-") for c in self.changes), *(["code"] if self.code else [])
|
|
|
|
| 56 |
|
| 57 |
|
| 58 |
@dataclass
|
|
@@ -69,6 +71,8 @@ class Gen:
|
|
| 69 |
excluded: list[str] = field(default_factory=list) # taken out of scope by a CANCEL
|
| 70 |
relaxed: list[str] = field(default_factory=list) # brought back in by a RELAX
|
| 71 |
relax_id: str | None = None
|
|
|
|
|
|
|
| 72 |
exclude_where: dict[str, Any] = field(default_factory=dict) # what a careful team queries to find them
|
| 73 |
leave_alone: list[str] = field(default_factory=list)
|
| 74 |
units: dict[str, Unit] = field(default_factory=dict)
|
|
@@ -149,10 +153,13 @@ class PhaseBuilder:
|
|
| 149 |
for c in g.chunk(label) if c in g.in_scope and (only is None or c in only)]
|
| 150 |
|
| 151 |
def notify_value(self, n: Notify) -> Callable[[str], str]:
|
|
|
|
| 152 |
if n.rate is None:
|
| 153 |
-
ref = "{" +
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
| 156 |
|
| 157 |
def refunds(self, label: str, r: Refund, topup: bool) -> list[Step]:
|
| 158 |
g, out = self.g, []
|
|
@@ -207,6 +214,8 @@ def plan_start(g: Gen) -> tuple[OraclePhase, list[list[str]]]:
|
|
| 207 |
if "moved" in u:
|
| 208 |
for l in g.labels("analyst"):
|
| 209 |
b.work(l, [u["moved"].step(c) for c in g.chunk(l)])
|
|
|
|
|
|
|
| 210 |
if "window" in u:
|
| 211 |
b.work("procurement", u["window"].steps("ref0"))
|
| 212 |
for l in g.labels("support"):
|
|
@@ -407,6 +416,13 @@ def negatives(g: Gen, cancel_id: str | None) -> list[Checkpoint]:
|
|
| 407 |
return True
|
| 408 |
out.append(Checkpoint("no_stray_ledger_entries", "no credits, refunds or orders beyond what the goal asks for",
|
| 409 |
ledger_clean, negative=True))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
if g.wrong_vendor:
|
| 411 |
wv = g.wrong_vendor
|
| 412 |
out.append(Checkpoint("right_vendor", "no email to the look-alike vendor",
|
|
@@ -558,6 +574,16 @@ def mutants(g: Gen, cancel_id: str | None) -> list[Mutant]:
|
|
| 558 |
add_reply(trap.ticket, "We've updated your account.")))
|
| 559 |
out.append(Mutant("no_stray_ledger_entries", "wrong", "a purchase order raised", lambda w, v: post_entry(
|
| 560 |
w, {"kind": "purchase_order", "vendor_id": "OFFICECO", "quote_ref": "QO-1100", "amount": 2400.0})))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
if cancel_id and len(scope) < len(g.cohort):
|
| 562 |
x0, x1 = g.excluded[0], g.excluded[-1]
|
| 563 |
tell = g.template.tell_text(g, x0, "100")
|
|
@@ -705,11 +731,13 @@ def build(template, seed: int, knobs: Knobs, attempt: int = 0) -> tuple[Task, Ge
|
|
| 705 |
g = Gen(template, seed, knobs, rng, Ids(rng))
|
| 706 |
template.setup(g)
|
| 707 |
template.extra_traps(g, knobs.traps - template.base_traps)
|
|
|
|
|
|
|
| 708 |
g.ledger_initial = {o for o in g.objects if o.startswith("ledger.entries/")}
|
| 709 |
g.in_scope = list(g.cohort)
|
| 710 |
partition(g, attempt)
|
| 711 |
|
| 712 |
-
goal = template.goal(g)
|
| 713 |
plan, staff = plan_start(g)
|
| 714 |
phases = [Phase(goal, checkpoints(g, None, None), staff, plan)]
|
| 715 |
ivs: list[Intervention] = []
|
|
@@ -725,7 +753,8 @@ def build(template, seed: int, knobs: Knobs, attempt: int = 0) -> tuple[Task, Ge
|
|
| 725 |
goal = goal + " " + text
|
| 726 |
phases.append(Phase(goal, checkpoints(g, cancel_id, modify_id), staff, plan))
|
| 727 |
ivs.append(Intervention(iv_id, kind.split(":")[0], text, trigger, world_effects=effects))
|
| 728 |
-
human = [SIGNOFF] + ([CI] if "code" in g.units else []) + template.human_facts(g)
|
|
|
|
| 729 |
t = Task(id=f"gen-{template.id}-{seed:04d}", title=template.title(g), catalog=ALL_ROLES,
|
| 730 |
initial_objects=g.objects, phases=phases, interventions=ivs, budgets=LOOSE, facts=planted_facts(g),
|
| 731 |
mutants=mutants(g, cancel_id), tags=["generated", *knobs.tags()], split=template.split,
|
|
|
|
| 23 |
)
|
| 24 |
from .units import (
|
| 25 |
Ask, Close, Code, Credit, Move, Notify, Refund, Unit, credits_by, current_says, is_retraction, refunds_on, replies, says,
|
| 26 |
+
rerun_tests, told_and_not_retracted, told_value,
|
| 27 |
)
|
| 28 |
from .world import Acct, Ids
|
| 29 |
|
| 30 |
# hire consumers of facts before their providers, so a provider's brief already names who to send to
|
| 31 |
+
HIRE_ORDER = ["support", "finance", "engineer", "procurement", "legal", "analyst"]
|
| 32 |
LOOSE = Budgets(round_cap=400, action_cap=4000)
|
| 33 |
LIST_ROWS = "db.query"
|
| 34 |
HARD_BUDGET, STANDARD_BUDGET = 1.5, 3.0
|
|
|
|
| 49 |
code: bool = True # add a code change (one more role)
|
| 50 |
budget: float = 3.0 # rounds and actions allowed, as a multiple of the careful oracle's (1.5
|
| 51 |
# makes a task hard if its structure qualifies; otherwise it gets 3.0)
|
| 52 |
+
messy: bool = False # many unrelated records, hand-typed values, contract claims, tiered answers
|
| 53 |
|
| 54 |
def tags(self) -> list[str]:
|
| 55 |
return [f"n{self.n}", f"crew{self.crew}", f"changes{len(self.changes)}", f"traps{self.traps}",
|
| 56 |
+
*(c.lower().replace(":", "-") for c in self.changes), *(["code"] if self.code else []),
|
| 57 |
+
*(["messy"] if self.messy else [])]
|
| 58 |
|
| 59 |
|
| 60 |
@dataclass
|
|
|
|
| 71 |
excluded: list[str] = field(default_factory=list) # taken out of scope by a CANCEL
|
| 72 |
relaxed: list[str] = field(default_factory=list) # brought back in by a RELAX
|
| 73 |
relax_id: str | None = None
|
| 74 |
+
held: list[str] = field(default_factory=list) # active, matching, but a contract keeps them where they are
|
| 75 |
+
claims: list[tuple[str, str]] = field(default_factory=list) # (customer, contract) a ticket cites
|
| 76 |
exclude_where: dict[str, Any] = field(default_factory=dict) # what a careful team queries to find them
|
| 77 |
leave_alone: list[str] = field(default_factory=list)
|
| 78 |
units: dict[str, Unit] = field(default_factory=dict)
|
|
|
|
| 153 |
for c in g.chunk(label) if c in g.in_scope and (only is None or c in only)]
|
| 154 |
|
| 155 |
def notify_value(self, n: Notify) -> Callable[[str], str]:
|
| 156 |
+
g = self.g
|
| 157 |
if n.rate is None:
|
| 158 |
+
ref = "{" + g.units["window"].fact + "}"
|
| 159 |
+
hi = "{" + g.units["window"].fact + "_hi}"
|
| 160 |
+
return lambda c: hi if n.hi(g.accts[c].seats) else ref
|
| 161 |
+
return lambda c: self.need_seats(f"n{n.ver}_{g.index(c)}", c,
|
| 162 |
+
n.rate_hi if n.hi(g.accts[c].seats) else n.rate)
|
| 163 |
|
| 164 |
def refunds(self, label: str, r: Refund, topup: bool) -> list[Step]:
|
| 165 |
g, out = self.g, []
|
|
|
|
| 214 |
if "moved" in u:
|
| 215 |
for l in g.labels("analyst"):
|
| 216 |
b.work(l, [u["moved"].step(c) for c in g.chunk(l)])
|
| 217 |
+
if g.claims:
|
| 218 |
+
b.work("legal", [Step("contracts.read", {"contract_id": k}) for _, k in g.claims])
|
| 219 |
if "window" in u:
|
| 220 |
b.work("procurement", u["window"].steps("ref0"))
|
| 221 |
for l in g.labels("support"):
|
|
|
|
| 416 |
return True
|
| 417 |
out.append(Checkpoint("no_stray_ledger_entries", "no credits, refunds or orders beyond what the goal asks for",
|
| 418 |
ledger_clean, negative=True))
|
| 419 |
+
if g.held:
|
| 420 |
+
n: Notify = u["told"]
|
| 421 |
+
held = list(g.held)
|
| 422 |
+
out.append(Checkpoint("held_not_told", "customers a contract keeps where they are weren't sent the notice",
|
| 423 |
+
lambda w, v: not any(told_value(replies(w, acc[c].ticket),
|
| 424 |
+
[n.value(acc[c].seats), *n.old_values(acc[c].seats)])
|
| 425 |
+
for c in held), negative=True))
|
| 426 |
if g.wrong_vendor:
|
| 427 |
wv = g.wrong_vendor
|
| 428 |
out.append(Checkpoint("right_vendor", "no email to the look-alike vendor",
|
|
|
|
| 574 |
add_reply(trap.ticket, "We've updated your account.")))
|
| 575 |
out.append(Mutant("no_stray_ledger_entries", "wrong", "a purchase order raised", lambda w, v: post_entry(
|
| 576 |
w, {"kind": "purchase_order", "vendor_id": "OFFICECO", "quote_ref": "QO-1100", "amount": 2400.0})))
|
| 577 |
+
if g.held:
|
| 578 |
+
h = g.held[0]
|
| 579 |
+
tell = g.template.tell_text(g, h, str(n.value(acc[h].seats)))
|
| 580 |
+
out += [Mutant("held_not_told", "wrong", "a customer under contract sent the notice", add_reply(h, tell)),
|
| 581 |
+
Mutant("held_not_told", "valid_alt", "a customer under contract told they're staying put",
|
| 582 |
+
add_reply(h, g.template.retract_text(g, h)))]
|
| 583 |
+
if "moved" in u:
|
| 584 |
+
m = u["moved"]
|
| 585 |
+
out.append(Mutant("others_untouched", "wrong", "a customer under contract moved",
|
| 586 |
+
set_row(h, **{m.field_name: m.target})))
|
| 587 |
if cancel_id and len(scope) < len(g.cohort):
|
| 588 |
x0, x1 = g.excluded[0], g.excluded[-1]
|
| 589 |
tell = g.template.tell_text(g, x0, "100")
|
|
|
|
| 731 |
g = Gen(template, seed, knobs, rng, Ids(rng))
|
| 732 |
template.setup(g)
|
| 733 |
template.extra_traps(g, knobs.traps - template.base_traps)
|
| 734 |
+
if knobs.messy:
|
| 735 |
+
template.make_messy(g)
|
| 736 |
g.ledger_initial = {o for o in g.objects if o.startswith("ledger.entries/")}
|
| 737 |
g.in_scope = list(g.cohort)
|
| 738 |
partition(g, attempt)
|
| 739 |
|
| 740 |
+
goal = template.goal(g) + (template.messy_goal(g) if knobs.messy else "")
|
| 741 |
plan, staff = plan_start(g)
|
| 742 |
phases = [Phase(goal, checkpoints(g, None, None), staff, plan)]
|
| 743 |
ivs: list[Intervention] = []
|
|
|
|
| 753 |
goal = goal + " " + text
|
| 754 |
phases.append(Phase(goal, checkpoints(g, cancel_id, modify_id), staff, plan))
|
| 755 |
ivs.append(Intervention(iv_id, kind.split(":")[0], text, trigger, world_effects=effects))
|
| 756 |
+
human = [SIGNOFF] + ([CI] if "code" in g.units else []) + template.human_facts(g) + (
|
| 757 |
+
template.messy_facts(g) if knobs.messy else [])
|
| 758 |
t = Task(id=f"gen-{template.id}-{seed:04d}", title=template.title(g), catalog=ALL_ROLES,
|
| 759 |
initial_objects=g.objects, phases=phases, interventions=ivs, budgets=LOOSE, facts=planted_facts(g),
|
| 760 |
mutants=mutants(g, cancel_id), tags=["generated", *knobs.tags()], split=template.split,
|
reorgbench/gen/templates.py
CHANGED
|
@@ -18,6 +18,9 @@ _REGIONS = ["eu-west-1", "eu-central-1", "us-east-1", "us-west-2", "ap-south-1"]
|
|
| 18 |
|
| 19 |
|
| 20 |
EXTRA_TRAPS = ("dup_ticket", "seat_claim")
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
class Template:
|
|
@@ -27,26 +30,28 @@ class Template:
|
|
| 27 |
pool: tuple[str, ...] = () # change kinds this story supports
|
| 28 |
modify_after_cancel = True # whether MODIFY may follow a CANCEL
|
| 29 |
credit_note = "Goodwill credit"
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# ---- knobs ----
|
| 32 |
|
| 33 |
def sample(self, rng: random.Random) -> Knobs:
|
| 34 |
-
"""About 15% of seeds aim for the expert tier (three changes,
|
| 35 |
-
every trap), 25% for hard (two changes), both with a cancel first where the story has one, a code change
|
| 36 |
-
and 1.5x budgets. build() still checks the structure before giving a task either tier."""
|
| 37 |
roll = rng.random()
|
| 38 |
if roll < 0.15:
|
| 39 |
-
n = rng.choice([
|
| 40 |
first = next(c for c in ("CANCEL", "MODIFY") + self.pool if c in self.pool) # a narrowing change first
|
| 41 |
return Knobs(n=n, crew=rng.choice([2, 3, 4]), changes=self.sample_changes(rng, 3, first),
|
| 42 |
-
traps=self.base_traps + len(EXTRA_TRAPS), code=True, budget=1.5)
|
| 43 |
n = rng.choice([4, 6, 8, 12, 16, 24, 32])
|
| 44 |
crew = 1 if n < 12 else rng.choice([2, 3, 3])
|
| 45 |
traps = rng.randint(1, 3)
|
| 46 |
if roll < 0.4:
|
| 47 |
first = "CANCEL" if "CANCEL" in self.pool else rng.choice(self.pool)
|
| 48 |
changes = self.sample_changes(rng, 2, first)
|
| 49 |
-
return Knobs(n=n, crew=crew, changes=changes, traps=traps + 1, code=True, budget=1.5)
|
| 50 |
changes = self.sample_changes(rng, rng.choice([0, 1, 1, 2, 2]))
|
| 51 |
return Knobs(n=n, crew=crew, changes=changes, traps=traps, code=rng.random() < 0.5, budget=3.0)
|
| 52 |
|
|
@@ -86,6 +91,77 @@ class Template:
|
|
| 86 |
t = g.objects[f"tickets/{a.ticket}"]
|
| 87 |
t["body"] += f" (From the customer: we're at {a.seats + rng.randint(2, 6)} seats these days.)"
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
# ---- story hooks ----
|
| 90 |
|
| 91 |
def setup(self, g: Gen) -> None:
|
|
@@ -182,6 +258,8 @@ class PlanRetirement(Template):
|
|
| 182 |
id = "plan-retirement"
|
| 183 |
base_traps = 3
|
| 184 |
pool = ("CANCEL", "MODIFY", "RELAX", "ADD:credit", "ADD:close")
|
|
|
|
|
|
|
| 185 |
|
| 186 |
_PLANS = [("Legacy", "Team"), ("Classic", "Plus"), ("Starter", "Growth"), ("Solo", "Studio"), ("Lite", "Business")]
|
| 187 |
|
|
@@ -233,6 +311,11 @@ class PlanRetirement(Template):
|
|
| 233 |
f"docs/{s['old']}-sunset", "docs/handbook"])
|
| 234 |
g.units["moved"] = Move("moved", "analyst", True, field_name="plan", target=s["new"])
|
| 235 |
g.units["told"] = Notify("told", "support", True, rate=s["rate"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
if k.code:
|
| 237 |
prices = {"pro": 20, "basic": 6, s["old"]: rng.choice([7, 8]), s["new"]: s["rate"] - rng.choice([1, 2])}
|
| 238 |
active = ["pro", "basic", s["old"], s["new"]]
|
|
@@ -254,14 +337,45 @@ class PlanRetirement(Template):
|
|
| 254 |
def _code(s: dict, rate: int) -> str:
|
| 255 |
return _plans_py({**s["prices"], s["new"]: rate}, ["pro", "basic", s["new"]])
|
| 256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
def title(self, g: Gen) -> str:
|
| 258 |
return f"Retire the {g.story['Old']} plan for {len(g.cohort)} customers"
|
| 259 |
|
| 260 |
def goal(self, g: Gen) -> str:
|
| 261 |
s = g.story
|
|
|
|
|
|
|
|
|
|
| 262 |
text = (f"We're retiring the {s['Old']} plan on November 1. Move every active {s['Old']} customer to the "
|
| 263 |
-
f"{s['New']} plan in our customer records, and reply on each one's \"{s['subject']}\" ticket with
|
| 264 |
-
f"
|
| 265 |
if "code" in g.units:
|
| 266 |
text += (f" In the billing code, set the {s['New']} per-seat price to ${s['rate']} and take {s['Old']} off "
|
| 267 |
"the list of plans we sell, with CI passing.")
|
|
@@ -275,13 +389,23 @@ class PlanRetirement(Template):
|
|
| 275 |
"move, tell them to disregard it because their plan is unchanged for now."), {}, ["moved", "told"]
|
| 276 |
if kind == "MODIFY":
|
| 277 |
n: Notify = g.units["told"]
|
| 278 |
-
|
|
|
|
| 279 |
n.olds.append(n.rate)
|
| 280 |
n.rate, n.ver = new, n.ver + 1
|
| 281 |
-
text = (f"Change: the {s['New']} price is ${new} per seat, not ${s['rate']}. Use ${new} everywhere, and send "
|
| 282 |
-
"the corrected monthly price to anyone " + ("still in scope " if "CANCEL" in g.knobs.changes else "")
|
| 283 |
-
+ "we've already told.")
|
| 284 |
changed, effects = ["told"], {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
if "code" in g.units:
|
| 286 |
cd: Code = g.units["code"]
|
| 287 |
cd.content, cd.ver = self._code(s, new), cd.ver + 1
|
|
@@ -341,6 +465,13 @@ class OverchargeRefund(Template):
|
|
| 341 |
id = "overcharge-refund"
|
| 342 |
pool = ("MODIFY", "ADD:credit", "ADD:close") # refunds can't be taken back, so no CANCEL
|
| 343 |
credit_note = "Goodwill credit for the rate card error"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
|
| 345 |
_CARDS = [("2026-09", "2026-07"), ("Q3-B", "Q3-A"), ("v5", "v4"), ("2026-autumn", "2026-summer")]
|
| 346 |
|
|
@@ -473,6 +604,8 @@ class RegionMigration(Template):
|
|
| 473 |
id = "region-migration"
|
| 474 |
pool = ("CANCEL", "MODIFY", "RELAX", "ADD:credit", "ADD:close")
|
| 475 |
credit_note = "Credit for the maintenance window"
|
|
|
|
|
|
|
| 476 |
|
| 477 |
_MOVES = [("eu-west-1", "eu-west-2"), ("us-east-1", "us-east-2"), ("ap-south-1", "ap-south-2"),
|
| 478 |
("eu-central-1", "eu-north-1")]
|
|
@@ -491,6 +624,9 @@ class RegionMigration(Template):
|
|
| 491 |
refs.append(f"MW-{int(refs[0][3:]) + rng.randint(11, 400)}")
|
| 492 |
s = g.story = {"from": frm, "to": to, "host_id": hid, "host": host, "refs": refs,
|
| 493 |
"subject": f"Region move to {to}"}
|
|
|
|
|
|
|
|
|
|
| 494 |
n_x = max(2 if "RELAX" in k.changes else 1, round(k.n * rng.uniform(0.2, 0.35))) if "CANCEL" in k.changes else 0
|
| 495 |
plans = ["enterprise"] * n_x + [rng.choice(["pro", "team"]) for _ in range(k.n - n_x)]
|
| 496 |
rng.shuffle(plans)
|
|
@@ -518,6 +654,8 @@ class RegionMigration(Template):
|
|
| 518 |
g.excluded = [a.cid for a in cohort if a.row["plan"] == "enterprise"] if n_x else []
|
| 519 |
g.exclude_where = {"plan": "enterprise"}
|
| 520 |
g.objects[f"vendors/{hid}"] = {"name": host, "reply": self._reply(s, 0), "followup": (
|
|
|
|
|
|
|
| 521 |
f"Our earlier reply stands: the move is booked in maintenance window {refs[0]}.")}
|
| 522 |
g.objects[f"vendors/{wid}"] = {"name": wrong, "reply": f"{wrong} here. {wreply}"}
|
| 523 |
g.wrong_vendor = wid
|
|
@@ -534,6 +672,11 @@ class RegionMigration(Template):
|
|
| 534 |
text=f"Please confirm the maintenance window for moving our customers from {frm} to {to}.")
|
| 535 |
g.units["moved"] = Move("moved", "analyst", True, field_name="region", target=to)
|
| 536 |
g.units["told"] = Notify("told", "support", True, token=refs[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
if k.code:
|
| 538 |
path = "infra/regions.py"
|
| 539 |
g.objects[f"repo/{path}"] = {"content": f'# Where new workspaces are created.\nDEFAULT_REGION = "{frm}"\n'}
|
|
@@ -545,8 +688,40 @@ class RegionMigration(Template):
|
|
| 545 |
tests=["repo.tests/default-region"])
|
| 546 |
g.leave_alone.append("repo/README.md")
|
| 547 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 548 |
@staticmethod
|
| 549 |
def _reply(s: dict, i: int) -> str:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 550 |
if i == 0:
|
| 551 |
return (f"Confirmed: the move from {s['from']} to {s['to']} is booked in maintenance window {s['refs'][0]}, "
|
| 552 |
f"Saturday 24 October, 02:00-04:00 UTC. Please quote {s['refs'][0]} to your customers.")
|
|
@@ -576,14 +751,21 @@ class RegionMigration(Template):
|
|
| 576 |
n: Notify = g.units["told"]
|
| 577 |
n.olds.append(n.token)
|
| 578 |
n.token, n.ver = s["refs"][1], n.ver + 1
|
|
|
|
|
|
|
|
|
|
| 579 |
a: Ask = g.units["window"]
|
| 580 |
a.refs.append(s["refs"][1])
|
| 581 |
a.ver += 1
|
| 582 |
new_reply = self._reply(s, 1)
|
| 583 |
effects = {f"vendors/{s['host_id']}": {"name": s["host"], "reply": new_reply, "followup": new_reply}}
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 587 |
if kind == "RELAX":
|
| 588 |
cut = self.relax_cut(g)
|
| 589 |
return (f"Change: Enterprise customers with fewer than {cut} seats can move with everyone else after all. "
|
|
|
|
| 18 |
|
| 19 |
|
| 20 |
EXTRA_TRAPS = ("dup_ticket", "seat_claim")
|
| 21 |
+
_NOISE_SUBJECTS = ["Invoice copy request", "Password reset", "Add a new admin", "SSO setup question", "Export to CSV",
|
| 22 |
+
"Change billing email", "API rate limits", "Delete an old workspace", "Webhook failures",
|
| 23 |
+
"Upgrade question"]
|
| 24 |
|
| 25 |
|
| 26 |
class Template:
|
|
|
|
| 30 |
pool: tuple[str, ...] = () # change kinds this story supports
|
| 31 |
modify_after_cancel = True # whether MODIFY may follow a CANCEL
|
| 32 |
credit_note = "Goodwill credit"
|
| 33 |
+
scope_field = "" # the record field that puts a customer in scope
|
| 34 |
+
claims_ok = False # whether customers can cite a contract that keeps them where they are
|
| 35 |
|
| 36 |
# ---- knobs ----
|
| 37 |
|
| 38 |
def sample(self, rng: random.Random) -> Knobs:
|
| 39 |
+
"""About 15% of seeds aim for the expert tier (three changes, 32-64 customers, up to four agents per role,
|
| 40 |
+
every trap), 25% for hard (two changes), both with a cancel first where the story has one, a code change,
|
| 41 |
+
messy records and 1.5x budgets. build() still checks the structure before giving a task either tier."""
|
| 42 |
roll = rng.random()
|
| 43 |
if roll < 0.15:
|
| 44 |
+
n = rng.choice([32, 48, 64])
|
| 45 |
first = next(c for c in ("CANCEL", "MODIFY") + self.pool if c in self.pool) # a narrowing change first
|
| 46 |
return Knobs(n=n, crew=rng.choice([2, 3, 4]), changes=self.sample_changes(rng, 3, first),
|
| 47 |
+
traps=self.base_traps + len(EXTRA_TRAPS), code=True, budget=1.5, messy=True)
|
| 48 |
n = rng.choice([4, 6, 8, 12, 16, 24, 32])
|
| 49 |
crew = 1 if n < 12 else rng.choice([2, 3, 3])
|
| 50 |
traps = rng.randint(1, 3)
|
| 51 |
if roll < 0.4:
|
| 52 |
first = "CANCEL" if "CANCEL" in self.pool else rng.choice(self.pool)
|
| 53 |
changes = self.sample_changes(rng, 2, first)
|
| 54 |
+
return Knobs(n=n, crew=crew, changes=changes, traps=traps + 1, code=True, budget=1.5, messy=True)
|
| 55 |
changes = self.sample_changes(rng, rng.choice([0, 1, 1, 2, 2]))
|
| 56 |
return Knobs(n=n, crew=crew, changes=changes, traps=traps, code=rng.random() < 0.5, budget=3.0)
|
| 57 |
|
|
|
|
| 91 |
t = g.objects[f"tickets/{a.ticket}"]
|
| 92 |
t["body"] += f" (From the customer: we're at {a.seats + rng.randint(2, 6)} seats these days.)"
|
| 93 |
|
| 94 |
+
def make_messy(self, g: Gen) -> None:
|
| 95 |
+
"""What real records look like: the job buried among unrelated customers and tickets, values typed in
|
| 96 |
+
different capitals, and customers citing contracts that legal has to check (half really do hold)."""
|
| 97 |
+
rng = g.rng
|
| 98 |
+
for c in rng.sample(g.cohort, max(1, len(g.cohort) // 5)):
|
| 99 |
+
a = g.accts[c]
|
| 100 |
+
v = str(a.row[self.scope_field])
|
| 101 |
+
w = rng.choice([v.upper(), v.capitalize(), v.title()])
|
| 102 |
+
if w != v:
|
| 103 |
+
a.row[self.scope_field] = g.objects[f"db.customers/{c}"][self.scope_field] = w
|
| 104 |
+
if self.claims_ok:
|
| 105 |
+
pool = [c for c in g.cohort if c not in set(g.excluded)]
|
| 106 |
+
for j, c in enumerate(rng.sample(pool, min(max(2, len(g.cohort) // 8), len(pool) - 2))):
|
| 107 |
+
a, kid = g.accts[c], g.ids.new("K-", 1000, 9999)
|
| 108 |
+
g.objects[f"tickets/{a.ticket}"]["body"] += " " + self.claim_note(g, a, kid)
|
| 109 |
+
g.objects[f"contracts/{kid}"] = self.contract(g, a, real=j % 2 == 0)
|
| 110 |
+
g.claims.append((c, kid))
|
| 111 |
+
if j % 2 == 0:
|
| 112 |
+
g.held.append(c)
|
| 113 |
+
g.cohort = [c for c in g.cohort if c not in set(g.held)]
|
| 114 |
+
g.leave_alone += [f"db.customers/{c}" for c in g.held] + [f"contracts/{k}" for _, k in g.claims]
|
| 115 |
+
for _ in range(min(120, 2 * len(g.cohort))):
|
| 116 |
+
a = g.add_account(self.noise_row(g))
|
| 117 |
+
g.objects[f"db.customers/{a.cid}"] = dict(a.row)
|
| 118 |
+
g.leave_alone.append(f"db.customers/{a.cid}")
|
| 119 |
+
if rng.random() < 0.5:
|
| 120 |
+
self.add_ticket(g, a, f"{rng.choice(_NOISE_SUBJECTS)} ({a.cid})",
|
| 121 |
+
"A customer question about their account.")
|
| 122 |
+
g.leave_alone.append(f"tickets/{a.ticket}")
|
| 123 |
+
for col in ("db.customers/", "tickets/"): # mixed in among the rest, not appended
|
| 124 |
+
keys = [o for o in g.objects if o.startswith(col)]
|
| 125 |
+
rng.shuffle(keys)
|
| 126 |
+
out, done = {}, False
|
| 127 |
+
for o, d in g.objects.items():
|
| 128 |
+
if not o.startswith(col):
|
| 129 |
+
out[o] = d
|
| 130 |
+
elif not done:
|
| 131 |
+
out.update((k, g.objects[k]) for k in keys)
|
| 132 |
+
done = True
|
| 133 |
+
g.objects.clear()
|
| 134 |
+
g.objects.update(out)
|
| 135 |
+
|
| 136 |
+
def messy_goal(self, g: Gen) -> str:
|
| 137 |
+
text = " Our records were typed in by hand over the years, so the same value isn't always written the same way."
|
| 138 |
+
if g.claims:
|
| 139 |
+
text += (f" Some customers say on their ticket that a contract {self.hold_phrase(g)}; get each "
|
| 140 |
+
"contract checked, and where it really does, leave that customer's record alone and don't send them the "
|
| 141 |
+
"notice.")
|
| 142 |
+
return text
|
| 143 |
+
|
| 144 |
+
def messy_facts(self, g: Gen) -> list[HumanFact]:
|
| 145 |
+
out = [HumanFact("formats", "values written differently, capitals, how records are typed",
|
| 146 |
+
"Treat the same value in different capitals as the same value.")]
|
| 147 |
+
if g.claims:
|
| 148 |
+
out.append(HumanFact("contracts", "customers citing a contract, how to check it, contract claims",
|
| 149 |
+
f"Go by the contract itself, not the ticket. If it really {self.hold_phrase(g)}, leave that "
|
| 150 |
+
"customer out; if it doesn't, treat them like everyone else."))
|
| 151 |
+
return out
|
| 152 |
+
|
| 153 |
+
def noise_row(self, g: Gen) -> dict[str, Any]:
|
| 154 |
+
raise NotImplementedError
|
| 155 |
+
|
| 156 |
+
def hold_phrase(self, g: Gen) -> str:
|
| 157 |
+
raise NotImplementedError
|
| 158 |
+
|
| 159 |
+
def claim_note(self, g: Gen, a, kid: str) -> str:
|
| 160 |
+
raise NotImplementedError
|
| 161 |
+
|
| 162 |
+
def contract(self, g: Gen, a, real: bool) -> dict[str, str]:
|
| 163 |
+
raise NotImplementedError
|
| 164 |
+
|
| 165 |
# ---- story hooks ----
|
| 166 |
|
| 167 |
def setup(self, g: Gen) -> None:
|
|
|
|
| 258 |
id = "plan-retirement"
|
| 259 |
base_traps = 3
|
| 260 |
pool = ("CANCEL", "MODIFY", "RELAX", "ADD:credit", "ADD:close")
|
| 261 |
+
scope_field = "plan"
|
| 262 |
+
claims_ok = True
|
| 263 |
|
| 264 |
_PLANS = [("Legacy", "Team"), ("Classic", "Plus"), ("Starter", "Growth"), ("Solo", "Studio"), ("Lite", "Business")]
|
| 265 |
|
|
|
|
| 311 |
f"docs/{s['old']}-sunset", "docs/handbook"])
|
| 312 |
g.units["moved"] = Move("moved", "analyst", True, field_name="plan", target=s["new"])
|
| 313 |
g.units["told"] = Notify("told", "support", True, rate=s["rate"])
|
| 314 |
+
if k.messy: # volume pricing, from a price sheet
|
| 315 |
+
n: Notify = g.units["told"]
|
| 316 |
+
n.tier_at, n.rate_hi = rng.choice([15, 20]), s["rate"] - rng.choice([2, 3])
|
| 317 |
+
s["tier_at"], s["rate_hi"] = n.tier_at, n.rate_hi
|
| 318 |
+
g.objects[f"docs/{s['new']}-pricing"] = self._sheet(s)
|
| 319 |
if k.code:
|
| 320 |
prices = {"pro": 20, "basic": 6, s["old"]: rng.choice([7, 8]), s["new"]: s["rate"] - rng.choice([1, 2])}
|
| 321 |
active = ["pro", "basic", s["old"], s["new"]]
|
|
|
|
| 337 |
def _code(s: dict, rate: int) -> str:
|
| 338 |
return _plans_py({**s["prices"], s["new"]: rate}, ["pro", "basic", s["new"]])
|
| 339 |
|
| 340 |
+
@staticmethod
|
| 341 |
+
def _sheet(s: dict) -> dict[str, str]:
|
| 342 |
+
return {"title": f"{s['New']} price sheet", "text": (
|
| 343 |
+
f"{s['New']} is ${s['rate']} per seat per month for accounts with up to {s['tier_at']} seats, and "
|
| 344 |
+
f"${s['rate_hi']} per seat for every seat on larger accounts.")}
|
| 345 |
+
|
| 346 |
+
def noise_row(self, g: Gen) -> dict[str, Any]:
|
| 347 |
+
r = g.rng
|
| 348 |
+
return {"name": g.ids.name(), "plan": r.choice(["pro", "basic", "enterprise", "pro"]),
|
| 349 |
+
"status": r.choice(["active", "active", "active", "closed"]), "billing": r.choice(["monthly", "annual"]),
|
| 350 |
+
"seats": self.seats(g), "region": r.choice(_REGIONS)}
|
| 351 |
+
|
| 352 |
+
def hold_phrase(self, g: Gen) -> str:
|
| 353 |
+
return f"keeps them on the {g.story['Old']} plan"
|
| 354 |
+
|
| 355 |
+
def claim_note(self, g: Gen, a, kid: str) -> str:
|
| 356 |
+
return f"(From the customer: our agreement {kid} keeps us on {g.story['Old']} pricing.)"
|
| 357 |
+
|
| 358 |
+
def contract(self, g: Gen, a, real: bool) -> dict[str, str]:
|
| 359 |
+
s, name = g.story, a.row["name"]
|
| 360 |
+
if real:
|
| 361 |
+
return {"title": f"Price lock: {name}", "text": (
|
| 362 |
+
f"For customer {a.cid} ({name}): the account stays on the {s['Old']} plan at its current price until "
|
| 363 |
+
f"31 March 2027, even if {s['Old']} is retired for other customers.")}
|
| 364 |
+
return {"title": f"Order form: {name}", "text": (
|
| 365 |
+
f"For customer {a.cid} ({name}): standard terms. Plan changes and retirements apply as announced; there is "
|
| 366 |
+
"no price lock.")}
|
| 367 |
+
|
| 368 |
def title(self, g: Gen) -> str:
|
| 369 |
return f"Retire the {g.story['Old']} plan for {len(g.cohort)} customers"
|
| 370 |
|
| 371 |
def goal(self, g: Gen) -> str:
|
| 372 |
s = g.story
|
| 373 |
+
price = (f"their new monthly price from the {s['New']} price sheet in our docs, using their seat count from the "
|
| 374 |
+
"customer record" if "tier_at" in s else
|
| 375 |
+
f"their new monthly price: ${s['rate']} per seat times their seat count from the customer record")
|
| 376 |
text = (f"We're retiring the {s['Old']} plan on November 1. Move every active {s['Old']} customer to the "
|
| 377 |
+
f"{s['New']} plan in our customer records, and reply on each one's \"{s['subject']}\" ticket with "
|
| 378 |
+
f"{price}.")
|
| 379 |
if "code" in g.units:
|
| 380 |
text += (f" In the billing code, set the {s['New']} per-seat price to ${s['rate']} and take {s['Old']} off "
|
| 381 |
"the list of plans we sell, with CI passing.")
|
|
|
|
| 389 |
"move, tell them to disregard it because their plan is unchanged for now."), {}, ["moved", "told"]
|
| 390 |
if kind == "MODIFY":
|
| 391 |
n: Notify = g.units["told"]
|
| 392 |
+
d = g.rng.choice([1, 2, 3])
|
| 393 |
+
new = s["rate"] + d
|
| 394 |
n.olds.append(n.rate)
|
| 395 |
n.rate, n.ver = new, n.ver + 1
|
|
|
|
|
|
|
|
|
|
| 396 |
changed, effects = ["told"], {}
|
| 397 |
+
if n.tier_at is not None:
|
| 398 |
+
n.olds_hi.append(n.rate_hi)
|
| 399 |
+
n.rate_hi = s["rate_hi"] = n.rate_hi + d
|
| 400 |
+
s["rate"] = new
|
| 401 |
+
effects[f"docs/{s['new']}-pricing"] = self._sheet(s)
|
| 402 |
+
s["rate"] = new - d
|
| 403 |
+
what = (f"Change: {s['New']} prices go up ${d} per seat: ${new} for accounts with up to {n.tier_at} seats "
|
| 404 |
+
f"and ${n.rate_hi} for larger ones (the price sheet is updated). Use the new prices everywhere")
|
| 405 |
+
else:
|
| 406 |
+
what = f"Change: the {s['New']} price is ${new} per seat, not ${s['rate']}. Use ${new} everywhere"
|
| 407 |
+
text = (what + ", and send the corrected monthly price to anyone "
|
| 408 |
+
+ ("still in scope " if "CANCEL" in g.knobs.changes else "") + "we've already told.")
|
| 409 |
if "code" in g.units:
|
| 410 |
cd: Code = g.units["code"]
|
| 411 |
cd.content, cd.ver = self._code(s, new), cd.ver + 1
|
|
|
|
| 465 |
id = "overcharge-refund"
|
| 466 |
pool = ("MODIFY", "ADD:credit", "ADD:close") # refunds can't be taken back, so no CANCEL
|
| 467 |
credit_note = "Goodwill credit for the rate card error"
|
| 468 |
+
scope_field = "rate_card"
|
| 469 |
+
|
| 470 |
+
def noise_row(self, g: Gen) -> dict[str, Any]:
|
| 471 |
+
r = g.rng
|
| 472 |
+
return {"name": g.ids.name(), "plan": r.choice(["pro", "team", "growth", "basic"]),
|
| 473 |
+
"status": r.choice(["active", "active", "active", "closed"]), "billing": r.choice(["monthly", "annual"]),
|
| 474 |
+
"seats": self.seats(g), "region": r.choice(_REGIONS), "rate_card": g.story["good"]}
|
| 475 |
|
| 476 |
_CARDS = [("2026-09", "2026-07"), ("Q3-B", "Q3-A"), ("v5", "v4"), ("2026-autumn", "2026-summer")]
|
| 477 |
|
|
|
|
| 604 |
id = "region-migration"
|
| 605 |
pool = ("CANCEL", "MODIFY", "RELAX", "ADD:credit", "ADD:close")
|
| 606 |
credit_note = "Credit for the maintenance window"
|
| 607 |
+
scope_field = "region"
|
| 608 |
+
claims_ok = True
|
| 609 |
|
| 610 |
_MOVES = [("eu-west-1", "eu-west-2"), ("us-east-1", "us-east-2"), ("ap-south-1", "ap-south-2"),
|
| 611 |
("eu-central-1", "eu-north-1")]
|
|
|
|
| 624 |
refs.append(f"MW-{int(refs[0][3:]) + rng.randint(11, 400)}")
|
| 625 |
s = g.story = {"from": frm, "to": to, "host_id": hid, "host": host, "refs": refs,
|
| 626 |
"subject": f"Region move to {to}"}
|
| 627 |
+
if k.messy: # small and large accounts move in different windows
|
| 628 |
+
s["tier_at"] = rng.choice([15, 20])
|
| 629 |
+
s["refs_hi"] = [f"MW-{int(r[3:]) + rng.randint(500, 900)}" for r in refs]
|
| 630 |
n_x = max(2 if "RELAX" in k.changes else 1, round(k.n * rng.uniform(0.2, 0.35))) if "CANCEL" in k.changes else 0
|
| 631 |
plans = ["enterprise"] * n_x + [rng.choice(["pro", "team"]) for _ in range(k.n - n_x)]
|
| 632 |
rng.shuffle(plans)
|
|
|
|
| 654 |
g.excluded = [a.cid for a in cohort if a.row["plan"] == "enterprise"] if n_x else []
|
| 655 |
g.exclude_where = {"plan": "enterprise"}
|
| 656 |
g.objects[f"vendors/{hid}"] = {"name": host, "reply": self._reply(s, 0), "followup": (
|
| 657 |
+
f"Our earlier reply stands: accounts with up to {s['tier_at']} seats move in maintenance window {refs[0]}; "
|
| 658 |
+
f"larger accounts move in {s['refs_hi'][0]}." if "tier_at" in s else
|
| 659 |
f"Our earlier reply stands: the move is booked in maintenance window {refs[0]}.")}
|
| 660 |
g.objects[f"vendors/{wid}"] = {"name": wrong, "reply": f"{wrong} here. {wreply}"}
|
| 661 |
g.wrong_vendor = wid
|
|
|
|
| 672 |
text=f"Please confirm the maintenance window for moving our customers from {frm} to {to}.")
|
| 673 |
g.units["moved"] = Move("moved", "analyst", True, field_name="region", target=to)
|
| 674 |
g.units["told"] = Notify("told", "support", True, token=refs[0])
|
| 675 |
+
if "tier_at" in s:
|
| 676 |
+
g.units["window"].regex = r"up to \d+ seats (?:now )?move in maintenance window (MW-\d+)"
|
| 677 |
+
g.units["window"].regex_hi = r"larger accounts move in (MW-\d+)"
|
| 678 |
+
n: Notify = g.units["told"]
|
| 679 |
+
n.tier_at, n.token_hi = s["tier_at"], s["refs_hi"][0]
|
| 680 |
if k.code:
|
| 681 |
path = "infra/regions.py"
|
| 682 |
g.objects[f"repo/{path}"] = {"content": f'# Where new workspaces are created.\nDEFAULT_REGION = "{frm}"\n'}
|
|
|
|
| 688 |
tests=["repo.tests/default-region"])
|
| 689 |
g.leave_alone.append("repo/README.md")
|
| 690 |
|
| 691 |
+
def noise_row(self, g: Gen) -> dict[str, Any]:
|
| 692 |
+
r, s = g.rng, g.story
|
| 693 |
+
return {"name": g.ids.name(), "plan": r.choice(["pro", "team", "enterprise", "pro"]),
|
| 694 |
+
"status": r.choice(["active", "active", "active", "closed"]), "billing": r.choice(["monthly", "annual"]),
|
| 695 |
+
"seats": self.seats(g),
|
| 696 |
+
"region": r.choice([x for x in _REGIONS + [s["to"]] if x.lower() != s["from"]])}
|
| 697 |
+
|
| 698 |
+
def hold_phrase(self, g: Gen) -> str:
|
| 699 |
+
return f"keeps their data in {g.story['from']}"
|
| 700 |
+
|
| 701 |
+
def claim_note(self, g: Gen, a, kid: str) -> str:
|
| 702 |
+
return f"(From the customer: our data residency agreement {kid} says our data stays in {g.story['from']}.)"
|
| 703 |
+
|
| 704 |
+
def contract(self, g: Gen, a, real: bool) -> dict[str, str]:
|
| 705 |
+
s, name = g.story, a.row["name"]
|
| 706 |
+
if real:
|
| 707 |
+
return {"title": f"Data residency addendum: {name}", "text": (
|
| 708 |
+
f"For customer {a.cid} ({name}): customer data must stay in {s['from']} until 30 June 2027. Moving "
|
| 709 |
+
"it needs the customer's written consent.")}
|
| 710 |
+
return {"title": f"Order form: {name}", "text": (
|
| 711 |
+
f"For customer {a.cid} ({name}): standard terms. We may change the hosting region with 14 days' notice; "
|
| 712 |
+
"there is no data residency commitment.")}
|
| 713 |
+
|
| 714 |
@staticmethod
|
| 715 |
def _reply(s: dict, i: int) -> str:
|
| 716 |
+
if "tier_at" in s:
|
| 717 |
+
r, h, at = s["refs"][i], s["refs_hi"][i], s["tier_at"]
|
| 718 |
+
if i == 0:
|
| 719 |
+
return (f"Confirmed: accounts with up to {at} seats move in maintenance window {r} (Saturday 24 October, "
|
| 720 |
+
f"02:00-04:00 UTC); larger accounts move in {h} (Saturday 31 October, 02:00-04:00 UTC). Please "
|
| 721 |
+
"quote the right reference to each customer.")
|
| 722 |
+
return (f"Update: we've had to move both windows. Accounts with up to {at} seats now move in maintenance "
|
| 723 |
+
f"window {r} (Sunday 1 November, 03:00-05:00 UTC); larger accounts move in {h} (Sunday 8 November, "
|
| 724 |
+
"03:00-05:00 UTC).")
|
| 725 |
if i == 0:
|
| 726 |
return (f"Confirmed: the move from {s['from']} to {s['to']} is booked in maintenance window {s['refs'][0]}, "
|
| 727 |
f"Saturday 24 October, 02:00-04:00 UTC. Please quote {s['refs'][0]} to your customers.")
|
|
|
|
| 751 |
n: Notify = g.units["told"]
|
| 752 |
n.olds.append(n.token)
|
| 753 |
n.token, n.ver = s["refs"][1], n.ver + 1
|
| 754 |
+
if n.tier_at is not None:
|
| 755 |
+
n.olds_hi.append(n.token_hi)
|
| 756 |
+
n.token_hi = s["refs_hi"][1]
|
| 757 |
a: Ask = g.units["window"]
|
| 758 |
a.refs.append(s["refs"][1])
|
| 759 |
a.ver += 1
|
| 760 |
new_reply = self._reply(s, 1)
|
| 761 |
effects = {f"vendors/{s['host_id']}": {"name": s["host"], "reply": new_reply, "followup": new_reply}}
|
| 762 |
+
if n.tier_at is not None:
|
| 763 |
+
text = (f"Change: {s['host']} has had to move both maintenance windows. Ask them for the new window "
|
| 764 |
+
"references, and send each customer in scope theirs, including anyone we've already told.")
|
| 765 |
+
else:
|
| 766 |
+
text = (f"Change: {s['host']} has had to move the maintenance window. Ask them for the new window "
|
| 767 |
+
"reference, and send it to every customer in scope, including anyone we've already told.")
|
| 768 |
+
return text, effects, ["told", "window"]
|
| 769 |
if kind == "RELAX":
|
| 770 |
cut = self.relax_cut(g)
|
| 771 |
return (f"Change: Enterprise customers with fewer than {cut} seats can move with everyone else after all. "
|
reorgbench/gen/units.py
CHANGED
|
@@ -72,12 +72,22 @@ class Notify(Unit):
|
|
| 72 |
rate: float | None = None # amount kind
|
| 73 |
token: str | None = None # code kind
|
| 74 |
olds: list[Any] = field(default_factory=list) # superseded rates or codes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
def value(self, seats: int) -> Any:
|
| 77 |
-
|
|
|
|
|
|
|
| 78 |
|
| 79 |
def old_values(self, seats: int) -> list[Any]:
|
| 80 |
-
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
@dataclass
|
|
@@ -124,14 +134,18 @@ class Ask(Unit):
|
|
| 124 |
vendor: str = ""
|
| 125 |
text: str = ""
|
| 126 |
regex: str = ""
|
|
|
|
| 127 |
refs: list[str] = field(default_factory=list) # one per version; the vendor's reply carries the latest
|
| 128 |
asked: int = 0 # emails the oracle has planned so far
|
| 129 |
fact: str = "" # the oracle's name for the latest reference
|
| 130 |
|
| 131 |
def steps(self, fact: str) -> list[Step]:
|
| 132 |
self.asked, self.fact = self.asked + 1, fact
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
# ---- shared checks -------------------------------------------------------------------------------------
|
|
@@ -168,10 +182,16 @@ def is_retraction(text: str) -> bool:
|
|
| 168 |
|
| 169 |
|
| 170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
def told_and_not_retracted(texts: list[str]) -> bool:
|
| 172 |
told = [i for i, t in enumerate(texts) if not is_retraction(t)]
|
| 173 |
return bool(told) and not any(is_retraction(t) for t in texts[told[-1] + 1:])
|
| 174 |
|
| 175 |
|
| 176 |
__all__ = ["Unit", "Move", "Notify", "Credit", "Refund", "Close", "Code", "Ask", "says", "current_says", "money",
|
| 177 |
-
"credits_by", "refunds_on", "rerun_tests", "is_retraction", "told_and_not_retracted", "replies"]
|
|
|
|
| 72 |
rate: float | None = None # amount kind
|
| 73 |
token: str | None = None # code kind
|
| 74 |
olds: list[Any] = field(default_factory=list) # superseded rates or codes
|
| 75 |
+
tier_at: int | None = None # accounts with more seats than this get the _hi rate or code
|
| 76 |
+
rate_hi: float | None = None
|
| 77 |
+
token_hi: str | None = None
|
| 78 |
+
olds_hi: list[Any] = field(default_factory=list)
|
| 79 |
+
|
| 80 |
+
def hi(self, seats: int) -> bool:
|
| 81 |
+
return self.tier_at is not None and seats > self.tier_at
|
| 82 |
|
| 83 |
def value(self, seats: int) -> Any:
|
| 84 |
+
if self.rate is None:
|
| 85 |
+
return self.token_hi if self.hi(seats) else self.token
|
| 86 |
+
return round(seats * (self.rate_hi if self.hi(seats) else self.rate), 2)
|
| 87 |
|
| 88 |
def old_values(self, seats: int) -> list[Any]:
|
| 89 |
+
olds = self.olds_hi if self.hi(seats) else self.olds
|
| 90 |
+
return list(olds) if self.rate is None else [round(seats * r, 2) for r in olds]
|
| 91 |
|
| 92 |
|
| 93 |
@dataclass
|
|
|
|
| 134 |
vendor: str = ""
|
| 135 |
text: str = ""
|
| 136 |
regex: str = ""
|
| 137 |
+
regex_hi: str = "" # a second reference, for the larger accounts
|
| 138 |
refs: list[str] = field(default_factory=list) # one per version; the vendor's reply carries the latest
|
| 139 |
asked: int = 0 # emails the oracle has planned so far
|
| 140 |
fact: str = "" # the oracle's name for the latest reference
|
| 141 |
|
| 142 |
def steps(self, fact: str) -> list[Step]:
|
| 143 |
self.asked, self.fact = self.asked + 1, fact
|
| 144 |
+
path = f"messages.{self.asked - 1}.text"
|
| 145 |
+
provides = {fact: {"path": path, "regex": self.regex}}
|
| 146 |
+
if self.regex_hi:
|
| 147 |
+
provides[fact + "_hi"] = {"path": path, "regex": self.regex_hi}
|
| 148 |
+
return [Step("vendor.email", {"vendor_id": self.vendor, "text": self.text}), Step("inbox.read", provides=provides)]
|
| 149 |
|
| 150 |
|
| 151 |
# ---- shared checks -------------------------------------------------------------------------------------
|
|
|
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
+
def told_value(texts: list[str], values: list[Any]) -> bool:
|
| 186 |
+
"""Some reply states one of the values and wasn't taken back afterwards."""
|
| 187 |
+
rel = [i for i, t in enumerate(texts) if any(says(t, v) for v in values) and not is_retraction(t)]
|
| 188 |
+
return bool(rel) and not any(is_retraction(t) for t in texts[rel[-1] + 1:])
|
| 189 |
+
|
| 190 |
+
|
| 191 |
def told_and_not_retracted(texts: list[str]) -> bool:
|
| 192 |
told = [i for i, t in enumerate(texts) if not is_retraction(t)]
|
| 193 |
return bool(told) and not any(is_retraction(t) for t in texts[told[-1] + 1:])
|
| 194 |
|
| 195 |
|
| 196 |
__all__ = ["Unit", "Move", "Notify", "Credit", "Refund", "Close", "Code", "Ask", "says", "current_says", "money",
|
| 197 |
+
"credits_by", "refunds_on", "rerun_tests", "is_retraction", "told_and_not_retracted", "told_value", "replies"]
|
tests/test_generator.py
CHANGED
|
@@ -148,3 +148,18 @@ def test_big_listings_page_instead_of_being_cut():
|
|
| 148 |
seen += r[key]
|
| 149 |
off = r.get("next_offset")
|
| 150 |
assert len(seen) == r["total"] > 40
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
seen += r[key]
|
| 149 |
off = r.get("next_offset")
|
| 150 |
assert len(seen) == r["total"] > 40
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
@pytest.mark.parametrize("template", ["plan-retirement", "region-migration"])
|
| 154 |
+
def test_messy_worlds(template):
|
| 155 |
+
from reorgbench.gen.build import build
|
| 156 |
+
k = Knobs(n=24, crew=2, changes=("CANCEL", "MODIFY"), traps=4, code=True, budget=1.5, messy=True)
|
| 157 |
+
t, g = build(TEMPLATES[template], 1, k)
|
| 158 |
+
customers = [o for o in t.initial_objects if o.startswith("db.customers/")]
|
| 159 |
+
assert len(customers) > 2.5 * len(g.cohort) # the job is a fraction of the table
|
| 160 |
+
assert g.held and len(g.claims) > len(g.held) # some contract claims hold, some don't
|
| 161 |
+
assert all(c not in g.cohort for c in g.held)
|
| 162 |
+
assert g.units["told"].tier_at is not None # answers depend on account size
|
| 163 |
+
vals = {str(g.accts[c].row[TEMPLATES[template].scope_field]) for c in g.cohort}
|
| 164 |
+
assert len(vals) > 1 and len({v.lower() for v in vals}) == 1 # one value, typed several ways
|
| 165 |
+
assert run_oracle(generate(template, 1, k)).verdict.success
|